1 |
|
---|
2 | /* -------------------------------------------------------------------------
|
---|
3 | * RTNet GUI
|
---|
4 | * -------------------------------------------------------------------------
|
---|
5 | *
|
---|
6 | * Class: t_uniLine
|
---|
7 | *
|
---|
8 | * Purpose: Universal-Line Widget (subclasses QTableWidget)
|
---|
9 | *
|
---|
10 | * Author: L. Mervart
|
---|
11 | *
|
---|
12 | * Created: 08-Jan-2013
|
---|
13 | *
|
---|
14 | * Changes:
|
---|
15 | *
|
---|
16 | * -----------------------------------------------------------------------*/
|
---|
17 |
|
---|
18 | #include "uniline.h"
|
---|
19 | #include "keyword.h"
|
---|
20 |
|
---|
21 | using namespace std;
|
---|
22 | using namespace GnssCenter;
|
---|
23 |
|
---|
24 | static const char* plus_xpm[] = {
|
---|
25 | "16 16 2 1",
|
---|
26 | " c #FFFFFFFFFFFF",
|
---|
27 | ". c #00000000FFFF",
|
---|
28 | " ",
|
---|
29 | " ... ",
|
---|
30 | " ... ",
|
---|
31 | " ... ",
|
---|
32 | " ... ",
|
---|
33 | " ... ",
|
---|
34 | " .............. ",
|
---|
35 | " .............. ",
|
---|
36 | " .............. ",
|
---|
37 | " ... ",
|
---|
38 | " ... ",
|
---|
39 | " ... ",
|
---|
40 | " ... ",
|
---|
41 | " ... ",
|
---|
42 | " ",
|
---|
43 | " "};
|
---|
44 |
|
---|
45 | static const char* minus_xpm[] = {
|
---|
46 | "16 16 2 1",
|
---|
47 | " c #FFFFFFFFFFFF",
|
---|
48 | ". c #00000000FFFF",
|
---|
49 | " ",
|
---|
50 | " ",
|
---|
51 | " ",
|
---|
52 | " ",
|
---|
53 | " ",
|
---|
54 | " ",
|
---|
55 | " .............. ",
|
---|
56 | " .............. ",
|
---|
57 | " .............. ",
|
---|
58 | " ",
|
---|
59 | " ",
|
---|
60 | " ",
|
---|
61 | " ",
|
---|
62 | " ",
|
---|
63 | " ",
|
---|
64 | " "};
|
---|
65 |
|
---|
66 | // Constructor
|
---|
67 | ////////////////////////////////////////////////////////////////////////////////
|
---|
68 | t_uniLine::t_uniLine(const QString& fldMask, const t_keyword* keyword,
|
---|
69 | QWidget* parent) : QTableWidget(parent) {
|
---|
70 |
|
---|
71 | static const QPixmap plusXPM(plus_xpm);
|
---|
72 | static const QPixmap minusXPM(minus_xpm);
|
---|
73 | static const QIcon plusIcon(plusXPM);
|
---|
74 | static const QIcon minusIcon(minusXPM);
|
---|
75 |
|
---|
76 | _keyword = keyword;
|
---|
77 | const QStringList& values = _keyword->values();
|
---|
78 |
|
---|
79 | setRowCount(values.size());
|
---|
80 |
|
---|
81 | QStringList labels = fldMask.split(QRegExp("\\s+"), QString::SkipEmptyParts);
|
---|
82 | if (labels.size() > 0) {
|
---|
83 | setColumnCount(labels.size() + 2);
|
---|
84 | labels << "" << "";
|
---|
85 | setHorizontalHeaderLabels(labels);
|
---|
86 | }
|
---|
87 |
|
---|
88 | for (int iRow = 0; iRow < values.size(); iRow++) {
|
---|
89 | QStringList txt = values.at(iRow).split(QRegExp("\"\\s*\""));
|
---|
90 | if (labels.size() == 0 && iRow == 0) {
|
---|
91 | setColumnCount(txt.size() + 2);
|
---|
92 | }
|
---|
93 | for (int iCol = 0; iCol < txt.size(); iCol++) {
|
---|
94 | setItem(iRow, iCol, new QTableWidgetItem(txt.at(iCol).trimmed()));
|
---|
95 | }
|
---|
96 | setItem(iRow, columnCount()-2, new QTableWidgetItem(plusIcon, QString()));
|
---|
97 | setItem(iRow, columnCount()-1, new QTableWidgetItem(minusIcon, QString()));
|
---|
98 | }
|
---|
99 | connect(this, SIGNAL(itemClicked(QTableWidgetItem*)),
|
---|
100 | this, SLOT(slotItemClicked(QTableWidgetItem*)));
|
---|
101 | }
|
---|
102 |
|
---|
103 | // Destructor
|
---|
104 | ////////////////////////////////////////////////////////////////////////////////
|
---|
105 | t_uniLine::~t_uniLine() {
|
---|
106 | }
|
---|
107 |
|
---|
108 | // Add/Remove Line
|
---|
109 | ////////////////////////////////////////////////////////////////////////////////
|
---|
110 | void t_uniLine::slotItemClicked(QTableWidgetItem* item) {
|
---|
111 |
|
---|
112 | static const QPixmap plusXPM(plus_xpm);
|
---|
113 | static const QPixmap minusXPM(minus_xpm);
|
---|
114 | static const QIcon plusIcon(plusXPM);
|
---|
115 | static const QIcon minusIcon(minusXPM);
|
---|
116 |
|
---|
117 | int iCol = item->column();
|
---|
118 | if (iCol == columnCount()-2) {
|
---|
119 | int iRow = item->row() + 1;
|
---|
120 | insertRow(iRow);
|
---|
121 | setItem(iRow, columnCount()-2, new QTableWidgetItem(plusIcon, QString()));
|
---|
122 | setItem(iRow, columnCount()-1, new QTableWidgetItem(minusIcon, QString()));
|
---|
123 | }
|
---|
124 | else if (iCol == columnCount()-1) {
|
---|
125 | removeRow(item->row());
|
---|
126 | }
|
---|
127 | }
|
---|
128 |
|
---|