1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
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
100
101
102
103
104
105
106
#include "UASQuickViewItemSelect.h"
#include <QLabel>
#include <QCheckBox>
UASQuickViewItemSelect::UASQuickViewItemSelect(QWidget *parent) : QWidget(parent)
{
ui.setupUi(this);
currcol = 0;
currrow = 0;
ui.gridLayout->setSpacing(5);
ui.gridLayout->setMargin(0);
}
void UASQuickViewItemSelect::addItem(QString item,bool enabled)
{
QString category = ".";
QString name = item;
if (item.indexOf(":") != -1 && item.indexOf(".") != -1)
{
//Item has a subcateogry
category = item.mid(item.indexOf(":")+1,item.indexOf(".") - item.indexOf(":")-1);
name = item.mid(item.indexOf(".")+1);
}
int col = -1;
if (m_categoryToIndexMap.contains(category))
{
col = m_categoryToIndexMap[category];
}
else
{
m_categoryToIndexMap[category] = currcol++;
col = m_categoryToIndexMap[category];
//New column.
QLabel *titlelabel = new QLabel(this);
titlelabel->setText(category);
titlelabel->show();
ui.gridLayout->addWidget(titlelabel,0,col);
}
QCheckBox *label = new QCheckBox(this);
m_checkboxToValueMap[label] = item;
m_checkBoxList.append(label);
if (enabled)
{
label->setChecked(true);
}
connect(label,SIGNAL(clicked(bool)),this,SLOT(checkBoxClicked(bool)));
label->setText(name);
label->show();
//ui.gridLayout->addWidget(label,currrow,currcol++);
bool breakout = false;
int row = -1;
while (!breakout)
{
if (!ui.gridLayout->itemAtPosition(++row,col) || row > 100)
{
breakout = true;
}
}
//Row is the next invalid object, and col is the proper column.
ui.gridLayout->addWidget(label,row,col);
}
void UASQuickViewItemSelect::resizeEvent(QResizeEvent *event)
{
Q_UNUSED(event);
/*for (int i=0;i<m_checkBoxList.size();i++)
{
ui.gridLayout->removeWidget(m_checkBoxList[i]);
}
int row = 0;
int col = 0;
for (int i=0;i<m_checkBoxList.size();i++)
{
ui.gridLayout->addWidget(m_checkBoxList[i],row,col);
col++;
ui.gridLayout->widget()->width() > this->width();
//need to reduce column number.
}*/
}
void UASQuickViewItemSelect::checkBoxClicked(bool checked)
{
QCheckBox *check = qobject_cast<QCheckBox*>(sender());
if (!check)
{
return;
}
QString checkval = check->text();
if (m_checkboxToValueMap.contains(check))
{
checkval = m_checkboxToValueMap[check];
}
if (checked)
{
emit valueEnabled(checkval);
}
else
{
emit valueDisabled(checkval);
}
}
UASQuickViewItemSelect::~UASQuickViewItemSelect()
{
}