[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 |
|
---|
| 23 | using namespace std;
|
---|
[5000] | 24 | using namespace GnssCenter;
|
---|
[4823] | 25 |
|
---|
| 26 | // Constructor
|
---|
| 27 | ////////////////////////////////////////////////////////////////////////////
|
---|
[4856] | 28 | t_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] | 80 | t_keyword::~t_keyword() {
|
---|
[4823] | 81 | }
|
---|
[4874] | 82 |
|
---|
| 83 | // Create Widget (it will be owned by layout)
|
---|
| 84 | ////////////////////////////////////////////////////////////////////////////
|
---|
[4882] | 85 | QWidget* 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();
|
---|
| 102 | _widget = cmbBox;
|
---|
[4874] | 103 | }
|
---|
[5092] | 104 | else if (widgetType == "lineedit") {
|
---|
[4878] | 105 | t_lineEdit* lineEdit = new t_lineEdit();
|
---|
[4875] | 106 | if (_values.size()) {
|
---|
| 107 | lineEdit->setText(_values[0]);
|
---|
| 108 | }
|
---|
| 109 | _widget = lineEdit;
|
---|
[4874] | 110 | }
|
---|
[5092] | 111 | else if (widgetType == "radiobutton") {
|
---|
[4874] | 112 | _widget = new QRadioButton();
|
---|
| 113 | }
|
---|
[5092] | 114 | else if (widgetType == "selwin") {
|
---|
[4878] | 115 | _widget = new t_selWin();
|
---|
[4874] | 116 | }
|
---|
[5092] | 117 | else if (widgetType == "spinbox") {
|
---|
[4874] | 118 | _widget = new QSpinBox();
|
---|
| 119 | }
|
---|
[5092] | 120 | else if (widgetType == "uniline") {
|
---|
[4882] | 121 | _widget = new t_uniLine(fldMask, this);
|
---|
[4874] | 122 | }
|
---|
| 123 |
|
---|
| 124 | return _widget;
|
---|
| 125 | }
|
---|