source: ntrip/trunk/GnssCenter/inpedit/keyword.cpp@ 10206

Last change on this file since 10206 was 5115, checked in by mervart, 12 years ago
File size: 6.0 KB
Line 
1
2/* -------------------------------------------------------------------------
3 * RTNet GUI
4 * -------------------------------------------------------------------------
5 *
6 * Class: t_keyword
7 *
8 * Purpose: Keyword in RTNet Input File
9 *
10 * Author: L. Mervart
11 *
12 * Created: 05-Jan-2013
13 *
14 * Changes:
15 *
16 * -----------------------------------------------------------------------*/
17
18#include "keyword.h"
19#include "lineedit.h"
20#include "selwin.h"
21#include "uniline.h"
22
23using namespace std;
24using namespace GnssCenter;
25
26// Constructor
27////////////////////////////////////////////////////////////////////////////
28t_keyword::t_keyword(QString line, QTextStream& inStream, QStringList& staticLines) {
29
30 _ok = false;
31 _widget = 0; // do not delete (it is owned by layout)
32
33 int numVal = 0;
34 QTextStream in(line.toAscii(), QIODevice::ReadOnly);
35 in >> _name >> numVal;
36
37 staticLines << _name;
38
39 if (!_name.isEmpty()) {
40 _ok = true;
41
42 if (numVal == 1) {
43 _origValues.append(in.readLine().trimmed());
44 }
45 else if (numVal > 1) {
46 for (int ii = 0; ii < numVal; ii++) {
47 _origValues.append(inStream.readLine().trimmed());
48 }
49 }
50
51 while (inStream.status() == QTextStream::Ok && !inStream.atEnd()) {
52 line = inStream.readLine();
53 staticLines << line;
54 line = line.trimmed();
55 if (line.isEmpty()) {
56 break;
57 }
58 else if (line[0] == '#') {
59 int pos = 0;
60 while (true) {
61 QRegExp rx("([^#;]*)\\s+=\\s+([^#;]*)");
62 pos = rx.indexIn(line, pos);
63 if (pos == -1) {
64 break;
65 }
66 else {
67 pos += rx.matchedLength();
68 }
69 QString descKey = rx.cap(1).trimmed();
70 QString descVal = rx.cap(2).trimmed();
71 _desc[descKey] = descVal;
72 }
73 }
74 }
75
76 // Remove leading and trailing double-quotes
77 // -----------------------------------------
78 _origValues.replaceInStrings(QRegExp("^\\s*\"|\"\\s*$"), QString());
79 }
80}
81
82// Destructor
83////////////////////////////////////////////////////////////////////////////
84t_keyword::~t_keyword() {
85}
86
87// Create Widget (it will be owned by layout)
88////////////////////////////////////////////////////////////////////////////
89QWidget* t_keyword::createWidget(const QString& fldMask) {
90
91 if (_widget != 0) {
92 // TODO: exception
93 }
94
95 QString widgetType = _desc.value("widget");
96
97 if (widgetType == "checkbox") {
98 QCheckBox* chBox = new QCheckBox();
99 if (_origValues.size() && _origValues[0] == "1") {
100 chBox->setChecked(true);
101 }
102 _widget = chBox;
103 }
104 else if (widgetType == "combobox") {
105 QComboBox* cmbBox = new QComboBox();
106 cmbBox->addItems(_desc.value("cards").split(QRegExp("\\s"), QString::SkipEmptyParts));
107 if (_origValues.size()) {
108 int index = cmbBox->findText(_origValues[0]);
109 if (index != -1) {
110 cmbBox->setCurrentIndex(index);
111 }
112 }
113 _widget = cmbBox;
114 }
115 else if (widgetType == "lineedit") {
116 t_lineEdit* lineEdit = new t_lineEdit();
117 if (_origValues.size()) {
118 lineEdit->setText(_origValues[0]);
119 }
120 _widget = lineEdit;
121 }
122 else if (widgetType == "radiobutton") {
123 QRadioButton* radButt = new QRadioButton();
124 if (_origValues.size() && _origValues[0] == "1") {
125 radButt->setChecked(true);
126 }
127 _widget = radButt;
128 }
129 else if (widgetType == "selwin") {
130 t_selWin::Mode mode = t_selWin::File;
131 if (_desc.value("seldir") == "true") {
132 mode = t_selWin::Directory;
133 }
134 else if (_desc.value("maxfiles").toInt() > 1) {
135 mode = t_selWin::Files;
136 }
137 t_selWin* selWin = new t_selWin(mode);
138 selWin->setFileNames(_origValues);
139 _widget = selWin;
140 }
141 else if (widgetType == "spinbox") {
142 QSpinBox* spinBox = new QSpinBox();
143 QStringList rangeStr = _desc.value("range").split(QRegExp("\\s"), QString::SkipEmptyParts);
144 if (rangeStr.size() >= 1) spinBox->setMinimum(rangeStr[0].toInt());
145 if (rangeStr.size() >= 2) spinBox->setMaximum(rangeStr[1].toInt());
146 if (rangeStr.size() >= 3) spinBox->setSingleStep(rangeStr[2].toInt());
147 if (_origValues.size()) {
148 spinBox->setValue(_origValues[0].toInt());
149 }
150 _widget = spinBox;
151 }
152 else if (widgetType == "uniline") {
153 _widget = new t_uniLine(fldMask, _origValues);
154 }
155
156 return _widget;
157}
158
159//
160////////////////////////////////////////////////////////////////////////////
161QStringList t_keyword::values() const {
162
163 if (_widget == 0) {
164 return _origValues;
165 }
166
167 QStringList values;
168
169 QString widgetType = _desc.value("widget");
170
171 if (widgetType == "checkbox") {
172 QCheckBox* chBox = static_cast<QCheckBox*>(_widget);
173 if (chBox->isChecked()) {
174 values << "1";
175 }
176 else {
177 values << "0";
178 }
179 }
180 else if (widgetType == "combobox") {
181 QComboBox* cmbBox = static_cast<QComboBox*>(_widget);
182 values << cmbBox->currentText();
183 }
184 else if (widgetType == "lineedit") {
185 t_lineEdit* lineEdit = static_cast<t_lineEdit*>(_widget);
186 if (!lineEdit->text().isEmpty()) {
187 values << lineEdit->text();
188 }
189 }
190 else if (widgetType == "radiobutton") {
191 QRadioButton* radButt = static_cast<QRadioButton*>(_widget);
192 if (radButt->isChecked()) {
193 values << "1";
194 }
195 else {
196 values << "0";
197 }
198 }
199 else if (widgetType == "selwin") {
200 t_selWin* selWin = static_cast<t_selWin*>(_widget);
201 values << selWin->fileNames();
202 }
203 else if (widgetType == "spinbox") {
204 QSpinBox* spinBox = static_cast<QSpinBox*>(_widget);
205 values << QString("%1").arg(spinBox->value());
206 }
207 else if (widgetType == "uniline") {
208 t_uniLine* uniLine = static_cast<t_uniLine*>(_widget);
209 for (int iRow = 0; iRow < uniLine->rowCount(); iRow++) {
210 QString rowStr;
211 for (int iCol = 0; iCol < uniLine->columnCount()-2; iCol++) {
212 QTableWidgetItem* item = uniLine->item(iRow, iCol);
213 if (item) {
214 if (iCol != 0) rowStr += " \"";
215 rowStr += item->text().trimmed();
216 if (iCol != uniLine->columnCount()-3) rowStr += '\"';
217 }
218 }
219 values << rowStr;
220 }
221 }
222
223 return values;
224}
225
Note: See TracBrowser for help on using the repository browser.