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 |
|
---|
23 | using namespace std;
|
---|
24 | using namespace GnssCenter;
|
---|
25 |
|
---|
26 | // Constructor
|
---|
27 | ////////////////////////////////////////////////////////////////////////////
|
---|
28 | t_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 | ////////////////////////////////////////////////////////////////////////////
|
---|
80 | t_keyword::~t_keyword() {
|
---|
81 | }
|
---|
82 |
|
---|
83 | // Create Widget (it will be owned by layout)
|
---|
84 | ////////////////////////////////////////////////////////////////////////////
|
---|
85 | QWidget* 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 | QSpinBox* spinBox = new QSpinBox();
|
---|
130 | QStringList rangeStr = _desc.value("range").split(QRegExp("\\s"), QString::SkipEmptyParts);
|
---|
131 | if (rangeStr.size() >= 1) spinBox->setMinimum(rangeStr[0].toInt());
|
---|
132 | if (rangeStr.size() >= 2) spinBox->setMaximum(rangeStr[1].toInt());
|
---|
133 | if (rangeStr.size() >= 3) spinBox->setSingleStep(rangeStr[2].toInt());
|
---|
134 | _widget = spinBox;
|
---|
135 | }
|
---|
136 | else if (widgetType == "uniline") {
|
---|
137 | _widget = new t_uniLine(fldMask, this);
|
---|
138 | }
|
---|
139 |
|
---|
140 | return _widget;
|
---|
141 | }
|
---|