[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;
|
---|
[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();
|
---|
[4868] | 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 | }
|
---|
[4867] | 91 | }
|
---|
[4824] | 92 | }
|
---|
| 93 | }
|
---|
[4875] | 94 |
|
---|
| 95 | // Remove leading and trailing double-quotes
|
---|
| 96 | // -----------------------------------------
|
---|
[4881] | 97 | _values.replaceInStrings(QRegExp("^\\s*\"|\"\\s*$"), QString());
|
---|
[4824] | 98 | }
|
---|
[4823] | 99 | }
|
---|
| 100 |
|
---|
| 101 | // Destructor
|
---|
| 102 | ////////////////////////////////////////////////////////////////////////////
|
---|
[4856] | 103 | t_keyword::~t_keyword() {
|
---|
[4823] | 104 | }
|
---|
[4874] | 105 |
|
---|
| 106 | // Create Widget (it will be owned by layout)
|
---|
| 107 | ////////////////////////////////////////////////////////////////////////////
|
---|
[4882] | 108 | QWidget* t_keyword::createWidget(const QString& fldMask) {
|
---|
[4874] | 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) {
|
---|
[4878] | 121 | t_lineEdit* lineEdit = new t_lineEdit();
|
---|
[4875] | 122 | if (_values.size()) {
|
---|
| 123 | lineEdit->setText(_values[0]);
|
---|
| 124 | }
|
---|
| 125 | _widget = lineEdit;
|
---|
[4874] | 126 | }
|
---|
| 127 | else if (_type == radiobutton) {
|
---|
| 128 | _widget = new QRadioButton();
|
---|
| 129 | }
|
---|
| 130 | else if (_type == selwin) {
|
---|
[4878] | 131 | _widget = new t_selWin();
|
---|
[4874] | 132 | }
|
---|
| 133 | else if (_type == spinbox) {
|
---|
| 134 | _widget = new QSpinBox();
|
---|
| 135 | }
|
---|
| 136 | else if (_type == uniline) {
|
---|
[4882] | 137 | _widget = new t_uniLine(fldMask, this);
|
---|
[4874] | 138 | }
|
---|
| 139 |
|
---|
| 140 | return _widget;
|
---|
| 141 | }
|
---|