-
Notifications
You must be signed in to change notification settings - Fork 0
/
VariableListWidget.cpp
112 lines (84 loc) · 2.53 KB
/
VariableListWidget.cpp
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
107
108
109
110
111
112
//
#include <QtGui>
//#include "FnData.h"
//#include "FnWord.h"
#include "VariableListWidget.h"
/////////////////////////////////////////////////////////
VariableListWidget::VariableListWidget(const VariableList & variableList,
QWidget *parent)
: QTableWidget(parent)
{
// constructor of variable table
// make variable table
setRowCount(0);
setColumnCount(0);
setColumnCount(2);
// set headers for columns
QTableWidgetItem *nameItem = new QTableWidgetItem;
QTableWidgetItem *varItem = new QTableWidgetItem;
nameItem->setText(tr("Variable List:"));
varItem->setText(tr("Value:"));
setHorizontalHeaderItem(0,nameItem);
setHorizontalHeaderItem(1,varItem);
setSortingEnabled(false);
// control geometry
setMinimumWidth(300);
horizontalHeader()->setResizeMode(QHeaderView::Stretch);
// fill list
updateList(variableList);
// add connections
connect(this,SIGNAL(itemActivated(QTableWidgetItem*)),
this,SLOT(itemValue(QTableWidgetItem*)));
}
/////////////////////////////////////////////////////////
// PUBLIC SLOTS
void VariableListWidget::updateList(const VariableList & variableList)
{
// updates variable dialog
int row = 0;
QTableWidgetItem *nameItem;
QTableWidgetItem *varItem;
clearContents();
VariableListIterator i(variableList);
while (i.hasNext()) {
i.next();
if (i.value().type() == Element || i.value().type() == Integer)
row++;
}
setRowCount(row);
i.toFront();
row = 0;
while (i.hasNext()) {
i.next();
if (i.value().type() == Element || i.value().type() == Integer) {
nameItem = item(row,0);
if (!nameItem) {
nameItem = new QTableWidgetItem;
setItem(row,0,nameItem);
}
nameItem->setText(i.key());
nameItem->setTextAlignment(Qt::AlignLeft);
nameItem->setTextAlignment(Qt::AlignVCenter);
nameItem->setFlags(Qt::ItemIsSelectable | Qt::ItemIsEnabled);
varItem = item(row,1);
if (!varItem) {
varItem = new QTableWidgetItem;
setItem(row,1,varItem);
}
varItem->setText(i.value().toOutput());
varItem->setTextAlignment(Qt::AlignLeft);
varItem->setTextAlignment(Qt::AlignVCenter);
varItem->setFlags(Qt::ItemIsSelectable | Qt::ItemIsEnabled);
row++;
}
}
}
/////////////////////////////////////////////////////////
// PRIVATE SLOTS
void VariableListWidget::itemValue(QTableWidgetItem *item)
{
if (item->column() == 0)
emit echoValue(item->text() + "_");
if (item->column() == 1)
emit echoValue(item->text());
}