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

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