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
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;
[4867]31 _widget = 0; // do not delete (it is owned by layout)
[4824]32
[4867]33 int numVal = 0;
[4824]34 QTextStream in(line.toAscii(), QIODevice::ReadOnly);
[4867]35 in >> _name >> numVal;
[4824]36
37 if (!_name.isEmpty()) {
38 _ok = true;
39
[4867]40 if (numVal == 1) {
41 _values.append(in.readLine().trimmed());
[4824]42 }
[4867]43 else if (numVal > 1) {
44 for (int ii = 0; ii < numVal; ii++) {
45 _values.append(inStream.readLine().trimmed());
[4824]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] == '#') {
[4867]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 {
[4869]63 pos += rx.matchedLength();
[4867]64 }
65 QString descKey = rx.cap(1).trimmed();
66 QString descVal = rx.cap(2).trimmed();
[5091]67 _desc[descKey] = descVal;
[4867]68 }
[4824]69 }
70 }
[4875]71
72 // Remove leading and trailing double-quotes
73 // -----------------------------------------
[4881]74 _values.replaceInStrings(QRegExp("^\\s*\"|\"\\s*$"), QString());
[4824]75 }
[4823]76}
77
78// Destructor
79////////////////////////////////////////////////////////////////////////////
[4856]80t_keyword::~t_keyword() {
[4823]81}
[4874]82
83// Create Widget (it will be owned by layout)
84////////////////////////////////////////////////////////////////////////////
[4882]85QWidget* t_keyword::createWidget(const QString& fldMask) {
[4874]86
87 if (_widget != 0) {
88 // TODO: exception
89 }
90
[5092]91 QString widgetType = _desc.value("widget");
92
93 if (widgetType == "checkbox") {
[5091]94 QCheckBox* chBox = new QCheckBox();
95 if (_values.size() && _values[0] == "1") {
96 chBox->setChecked(true);
97 }
98 _widget = chBox;
[4874]99 }
[5092]100 else if (widgetType == "combobox") {
[5091]101 QComboBox* cmbBox = new QComboBox();
[5093]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 }
[5091]109 _widget = cmbBox;
[4874]110 }
[5092]111 else if (widgetType == "lineedit") {
[4878]112 t_lineEdit* lineEdit = new t_lineEdit();
[4875]113 if (_values.size()) {
114 lineEdit->setText(_values[0]);
115 }
116 _widget = lineEdit;
[4874]117 }
[5092]118 else if (widgetType == "radiobutton") {
[5094]119 QRadioButton* radButt = new QRadioButton();
120 if (_values.size() && _values[0] == "1") {
121 radButt->setChecked(true);
122 }
123 _widget = radButt;
[4874]124 }
[5092]125 else if (widgetType == "selwin") {
[4878]126 _widget = new t_selWin();
[4874]127 }
[5092]128 else if (widgetType == "spinbox") {
[4874]129 _widget = new QSpinBox();
130 }
[5092]131 else if (widgetType == "uniline") {
[4882]132 _widget = new t_uniLine(fldMask, this);
[4874]133 }
134
135 return _widget;
136}
Note: See TracBrowser for help on using the repository browser.