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

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