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

Last change on this file since 5097 was 5097, checked in by mervart, 11 years ago
File size: 3.9 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 _values.append(in.readLine().trimmed());
44 }
45 else if (numVal > 1) {
46 for (int ii = 0; ii < numVal; ii++) {
47 _values.append(inStream.readLine().trimmed());
48 }
49 }
50
51 while (inStream.status() == QTextStream::Ok && !inStream.atEnd()) {
52 line = inStream.readLine().trimmed();
53 staticLines << line;
54 if (line.isEmpty()) {
55 break;
56 }
57 else if (line[0] == '#') {
58 int pos = 0;
59 while (true) {
60 QRegExp rx("([^#;]*)\\s+=\\s+([^#;]*)");
61 pos = rx.indexIn(line, pos);
62 if (pos == -1) {
63 break;
64 }
65 else {
66 pos += rx.matchedLength();
67 }
68 QString descKey = rx.cap(1).trimmed();
69 QString descVal = rx.cap(2).trimmed();
70 _desc[descKey] = descVal;
71 }
72 }
73 }
74
75 // Remove leading and trailing double-quotes
76 // -----------------------------------------
77 _values.replaceInStrings(QRegExp("^\\s*\"|\"\\s*$"), QString());
78 }
79}
80
81// Destructor
82////////////////////////////////////////////////////////////////////////////
83t_keyword::~t_keyword() {
84}
85
86// Create Widget (it will be owned by layout)
87////////////////////////////////////////////////////////////////////////////
88QWidget* t_keyword::createWidget(const QString& fldMask) {
89
90 if (_widget != 0) {
91 // TODO: exception
92 }
93
94 QString widgetType = _desc.value("widget");
95
96 if (widgetType == "checkbox") {
97 QCheckBox* chBox = new QCheckBox();
98 if (_values.size() && _values[0] == "1") {
99 chBox->setChecked(true);
100 }
101 _widget = chBox;
102 }
103 else if (widgetType == "combobox") {
104 QComboBox* cmbBox = new QComboBox();
105 cmbBox->addItems(_desc.value("cards").split(QRegExp("\\s"), QString::SkipEmptyParts));
106 if (_values.size()) {
107 int index = cmbBox->findText(_values[0]);
108 if (index != -1) {
109 cmbBox->setCurrentIndex(index);
110 }
111 }
112 _widget = cmbBox;
113 }
114 else if (widgetType == "lineedit") {
115 t_lineEdit* lineEdit = new t_lineEdit();
116 if (_values.size()) {
117 lineEdit->setText(_values[0]);
118 }
119 _widget = lineEdit;
120 }
121 else if (widgetType == "radiobutton") {
122 QRadioButton* radButt = new QRadioButton();
123 if (_values.size() && _values[0] == "1") {
124 radButt->setChecked(true);
125 }
126 _widget = radButt;
127 }
128 else if (widgetType == "selwin") {
129 t_selWin* selWin = new t_selWin();
130 if (_values.size()) {
131 selWin->setFileName(_values[0]);
132 }
133 _widget = selWin;
134 }
135 else if (widgetType == "spinbox") {
136 QSpinBox* spinBox = new QSpinBox();
137 QStringList rangeStr = _desc.value("range").split(QRegExp("\\s"), QString::SkipEmptyParts);
138 if (rangeStr.size() >= 1) spinBox->setMinimum(rangeStr[0].toInt());
139 if (rangeStr.size() >= 2) spinBox->setMaximum(rangeStr[1].toInt());
140 if (rangeStr.size() >= 3) spinBox->setSingleStep(rangeStr[2].toInt());
141 _widget = spinBox;
142 }
143 else if (widgetType == "uniline") {
144 _widget = new t_uniLine(fldMask, this);
145 }
146
147 return _widget;
148}
Note: See TracBrowser for help on using the repository browser.