dialogList.cpp 2.16 KB
Newer Older
Sylvain Thery's avatar
Sylvain Thery committed
1
2
3
4
5
6
7
8
9
10
11
12
13
14
#include "dialogList.h"
#include "Utils/cgognStream.h"


namespace CGoGN
{

namespace SCHNApps
{

ListPopUp::ListPopUp(const QString& name, QWidget* parent):
	QDialog(parent)
{
	setWindowTitle(name);
Sylvain Thery's avatar
Sylvain Thery committed
15
	setWindowFlags(windowFlags() | Qt::FramelessWindowHint | Qt::WindowStaysOnTopHint);
Sylvain Thery's avatar
Sylvain Thery committed
16
17
	m_layout = new QVBoxLayout(this);
	setLayout(m_layout);
Sylvain Thery's avatar
Sylvain Thery committed
18
	m_layout->setContentsMargins(1, 1, 1, 1);
Sylvain Thery's avatar
Sylvain Thery committed
19
	m_list_items = new QListWidget();
Sylvain Thery's avatar
Sylvain Thery committed
20
21
22
23
24

	QSizePolicy test;
	test.setHorizontalPolicy(QSizePolicy::Preferred);
	m_list_items->setSizePolicy(test);

Sylvain Thery's avatar
Sylvain Thery committed
25
26
27
28
29
30
31
32
	m_list_items->setSelectionMode(QAbstractItemView::NoSelection);
	m_layout->addWidget(m_list_items);
}

ListPopUp::~ListPopUp()
{
}

Sylvain Thery's avatar
Sylvain Thery committed
33
34
35
36
37
QSize ListPopUp::sizeHint() const
{
	return QSize(150,150);
}

Sylvain Thery's avatar
Sylvain Thery committed
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
QListWidget* ListPopUp::list()
{
	return m_list_items;
}


QListWidgetItem* ListPopUp::addItem(const QString& str, Qt::CheckState checked)
{
	QListWidgetItem* item = new QListWidgetItem(str, m_list_items);
	item->setCheckState(checked);
	return item;
}

QListWidgetItem* ListPopUp::getItem(unsigned int row)
{
	return m_list_items->item(row);
}

unsigned int ListPopUp::nbItems()
{
	return m_list_items->count();
}

QListWidgetItem* ListPopUp::findItem(const QString& str)
{
	QList<QListWidgetItem*> items = m_list_items->findItems(str, Qt::MatchExactly);
	if(!items.empty())
		return items[0];
	return NULL;
}

bool ListPopUp::removeItem(const QString& str)
{
	QList<QListWidgetItem*> items = m_list_items->findItems(str, Qt::MatchExactly);
	if(items.empty())
		return false;
	m_list_items->takeItem(m_list_items->row(items[0]));
	return true;
}

void ListPopUp::check(const QString& str, Qt::CheckState ck)
{
	QList<QListWidgetItem*> items = m_list_items->findItems(str, Qt::MatchExactly);
	if(!items.empty())
		items[0]->setCheckState(ck);
	else
		CGoGNerr<< "ListPopUp::check()"<< str.toStdString()<< " not in list"<< CGoGNendl;
}

 bool ListPopUp::isChecked(const QString& str)
{
	QList<QListWidgetItem*> items = m_list_items->findItems(str, Qt::MatchExactly);
	if(!items.empty())
		return (items[0]->checkState() == Qt::Checked);
	CGoGNerr<< "ListPopUp::isChecked()"<< str.toStdString()<< " not in list"<< CGoGNendl;
	return false;
}


} // namespace SCHNApps

} // namespace CGoGN