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

Last change on this file since 5091 was 5091, checked in by mervart, 11 years ago
File size: 3.7 KB
RevLine 
[4823]1
2/* -------------------------------------------------------------------------
3 * RTNet GUI
4 * -------------------------------------------------------------------------
5 *
[4856]6 * Class: t_keyword
[4823]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
[4866]18#include "keyword.h"
[4878]19#include "lineedit.h"
20#include "selwin.h"
21#include "uniline.h"
[4823]22
23using namespace std;
[5000]24using namespace GnssCenter;
[4823]25
26// Constructor
27////////////////////////////////////////////////////////////////////////////
[4856]28t_keyword::t_keyword(QString line, QTextStream& inStream) {
[4824]29
30 _ok = false;
[4868]31 _type = e_type_max;
[4867]32 _widget = 0; // do not delete (it is owned by layout)
[4824]33
[4867]34 int numVal = 0;
[4824]35 QTextStream in(line.toAscii(), QIODevice::ReadOnly);
[4867]36 in >> _name >> numVal;
[4824]37
38 if (!_name.isEmpty()) {
39 _ok = true;
40
[4867]41 if (numVal == 1) {
42 _values.append(in.readLine().trimmed());
[4824]43 }
[4867]44 else if (numVal > 1) {
45 for (int ii = 0; ii < numVal; ii++) {
46 _values.append(inStream.readLine().trimmed());
[4824]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] == '#') {
[4867]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 {
[4869]64 pos += rx.matchedLength();
[4867]65 }
66 QString descKey = rx.cap(1).trimmed();
67 QString descVal = rx.cap(2).trimmed();
[5091]68 _desc[descKey] = descVal;
[4868]69 if (descKey == "widget") {
70 if (descVal == "checkbox") {
71 _type = checkbox;
72 }
73 else if (descVal == "combobox") {
74 _type = combobox;
75 }
76 else if (descVal == "lineedit") {
77 _type = lineedit;
78 }
79 else if (descVal == "radiobutton") {
80 _type = radiobutton;
81 }
82 else if (descVal == "selwin") {
83 _type = selwin;
84 }
85 else if (descVal == "spinbox") {
86 _type = spinbox;
87 }
88 else if (descVal == "uniline") {
89 _type = uniline;
90 }
91 }
[4867]92 }
[4824]93 }
94 }
[4875]95
96 // Remove leading and trailing double-quotes
97 // -----------------------------------------
[4881]98 _values.replaceInStrings(QRegExp("^\\s*\"|\"\\s*$"), QString());
[4824]99 }
[4823]100}
101
102// Destructor
103////////////////////////////////////////////////////////////////////////////
[4856]104t_keyword::~t_keyword() {
[4823]105}
[4874]106
107// Create Widget (it will be owned by layout)
108////////////////////////////////////////////////////////////////////////////
[4882]109QWidget* t_keyword::createWidget(const QString& fldMask) {
[4874]110
111 if (_widget != 0) {
112 // TODO: exception
113 }
114
115 if (_type == checkbox) {
[5091]116 QCheckBox* chBox = new QCheckBox();
117 if (_values.size() && _values[0] == "1") {
118 chBox->setChecked(true);
119 }
120 _widget = chBox;
[4874]121 }
122 else if (_type == combobox) {
[5091]123 QComboBox* cmbBox = new QComboBox();
124 _widget = cmbBox;
[4874]125 }
126 else if (_type == lineedit) {
[4878]127 t_lineEdit* lineEdit = new t_lineEdit();
[4875]128 if (_values.size()) {
129 lineEdit->setText(_values[0]);
130 }
131 _widget = lineEdit;
[4874]132 }
133 else if (_type == radiobutton) {
134 _widget = new QRadioButton();
135 }
136 else if (_type == selwin) {
[4878]137 _widget = new t_selWin();
[4874]138 }
139 else if (_type == spinbox) {
140 _widget = new QSpinBox();
141 }
142 else if (_type == uniline) {
[4882]143 _widget = new t_uniLine(fldMask, this);
[4874]144 }
145
146 return _widget;
147}
Note: See TracBrowser for help on using the repository browser.