[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 | ////////////////////////////////////////////////////////////////////////////
|
---|
[5097] | 28 | t_keyword::t_keyword(QString line, QTextStream& inStream, QStringList& staticLines) {
|
---|
[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 |
|
---|
[5097] | 37 | staticLines << _name;
|
---|
| 38 |
|
---|
[4824] | 39 | if (!_name.isEmpty()) {
|
---|
| 40 | _ok = true;
|
---|
| 41 |
|
---|
[4867] | 42 | if (numVal == 1) {
|
---|
[5101] | 43 | _origValues.append(in.readLine().trimmed());
|
---|
[4824] | 44 | }
|
---|
[4867] | 45 | else if (numVal > 1) {
|
---|
| 46 | for (int ii = 0; ii < numVal; ii++) {
|
---|
[5101] | 47 | _origValues.append(inStream.readLine().trimmed());
|
---|
[4824] | 48 | }
|
---|
| 49 | }
|
---|
| 50 |
|
---|
| 51 | while (inStream.status() == QTextStream::Ok && !inStream.atEnd()) {
|
---|
[5098] | 52 | line = inStream.readLine();
|
---|
[5097] | 53 | staticLines << line;
|
---|
[5098] | 54 | line = line.trimmed();
|
---|
[4824] | 55 | if (line.isEmpty()) {
|
---|
| 56 | break;
|
---|
| 57 | }
|
---|
| 58 | else if (line[0] == '#') {
|
---|
[4867] | 59 | int pos = 0;
|
---|
| 60 | while (true) {
|
---|
| 61 | QRegExp rx("([^#;]*)\\s+=\\s+([^#;]*)");
|
---|
| 62 | pos = rx.indexIn(line, pos);
|
---|
| 63 | if (pos == -1) {
|
---|
| 64 | break;
|
---|
| 65 | }
|
---|
| 66 | else {
|
---|
[4869] | 67 | pos += rx.matchedLength();
|
---|
[4867] | 68 | }
|
---|
| 69 | QString descKey = rx.cap(1).trimmed();
|
---|
| 70 | QString descVal = rx.cap(2).trimmed();
|
---|
[5091] | 71 | _desc[descKey] = descVal;
|
---|
[4867] | 72 | }
|
---|
[4824] | 73 | }
|
---|
| 74 | }
|
---|
[4875] | 75 |
|
---|
| 76 | // Remove leading and trailing double-quotes
|
---|
| 77 | // -----------------------------------------
|
---|
[5101] | 78 | _origValues.replaceInStrings(QRegExp("^\\s*\"|\"\\s*$"), QString());
|
---|
[4824] | 79 | }
|
---|
[4823] | 80 | }
|
---|
| 81 |
|
---|
| 82 | // Destructor
|
---|
| 83 | ////////////////////////////////////////////////////////////////////////////
|
---|
[4856] | 84 | t_keyword::~t_keyword() {
|
---|
[4823] | 85 | }
|
---|
[4874] | 86 |
|
---|
| 87 | // Create Widget (it will be owned by layout)
|
---|
| 88 | ////////////////////////////////////////////////////////////////////////////
|
---|
[4882] | 89 | QWidget* t_keyword::createWidget(const QString& fldMask) {
|
---|
[4874] | 90 |
|
---|
| 91 | if (_widget != 0) {
|
---|
| 92 | // TODO: exception
|
---|
| 93 | }
|
---|
| 94 |
|
---|
[5092] | 95 | QString widgetType = _desc.value("widget");
|
---|
| 96 |
|
---|
| 97 | if (widgetType == "checkbox") {
|
---|
[5091] | 98 | QCheckBox* chBox = new QCheckBox();
|
---|
[5101] | 99 | if (_origValues.size() && _origValues[0] == "1") {
|
---|
[5091] | 100 | chBox->setChecked(true);
|
---|
| 101 | }
|
---|
| 102 | _widget = chBox;
|
---|
[4874] | 103 | }
|
---|
[5092] | 104 | else if (widgetType == "combobox") {
|
---|
[5091] | 105 | QComboBox* cmbBox = new QComboBox();
|
---|
[5093] | 106 | cmbBox->addItems(_desc.value("cards").split(QRegExp("\\s"), QString::SkipEmptyParts));
|
---|
[5101] | 107 | if (_origValues.size()) {
|
---|
| 108 | int index = cmbBox->findText(_origValues[0]);
|
---|
[5093] | 109 | if (index != -1) {
|
---|
| 110 | cmbBox->setCurrentIndex(index);
|
---|
| 111 | }
|
---|
| 112 | }
|
---|
[5091] | 113 | _widget = cmbBox;
|
---|
[4874] | 114 | }
|
---|
[5092] | 115 | else if (widgetType == "lineedit") {
|
---|
[4878] | 116 | t_lineEdit* lineEdit = new t_lineEdit();
|
---|
[5101] | 117 | if (_origValues.size()) {
|
---|
| 118 | lineEdit->setText(_origValues[0]);
|
---|
[4875] | 119 | }
|
---|
| 120 | _widget = lineEdit;
|
---|
[4874] | 121 | }
|
---|
[5092] | 122 | else if (widgetType == "radiobutton") {
|
---|
[5094] | 123 | QRadioButton* radButt = new QRadioButton();
|
---|
[5101] | 124 | if (_origValues.size() && _origValues[0] == "1") {
|
---|
[5094] | 125 | radButt->setChecked(true);
|
---|
| 126 | }
|
---|
| 127 | _widget = radButt;
|
---|
[4874] | 128 | }
|
---|
[5092] | 129 | else if (widgetType == "selwin") {
|
---|
[5096] | 130 | t_selWin* selWin = new t_selWin();
|
---|
[5101] | 131 | if (_origValues.size()) {
|
---|
| 132 | selWin->setFileName(_origValues[0]);
|
---|
[5096] | 133 | }
|
---|
| 134 | _widget = selWin;
|
---|
[4874] | 135 | }
|
---|
[5092] | 136 | else if (widgetType == "spinbox") {
|
---|
[5095] | 137 | QSpinBox* spinBox = new QSpinBox();
|
---|
| 138 | QStringList rangeStr = _desc.value("range").split(QRegExp("\\s"), QString::SkipEmptyParts);
|
---|
| 139 | if (rangeStr.size() >= 1) spinBox->setMinimum(rangeStr[0].toInt());
|
---|
| 140 | if (rangeStr.size() >= 2) spinBox->setMaximum(rangeStr[1].toInt());
|
---|
| 141 | if (rangeStr.size() >= 3) spinBox->setSingleStep(rangeStr[2].toInt());
|
---|
[5109] | 142 | if (_origValues.size()) {
|
---|
| 143 | spinBox->setValue(_origValues[0].toInt());
|
---|
| 144 | }
|
---|
[5095] | 145 | _widget = spinBox;
|
---|
[4874] | 146 | }
|
---|
[5092] | 147 | else if (widgetType == "uniline") {
|
---|
[5107] | 148 | _widget = new t_uniLine(fldMask, _origValues);
|
---|
[4874] | 149 | }
|
---|
| 150 |
|
---|
| 151 | return _widget;
|
---|
| 152 | }
|
---|
[5102] | 153 |
|
---|
| 154 | //
|
---|
| 155 | ////////////////////////////////////////////////////////////////////////////
|
---|
| 156 | QStringList t_keyword::values() const {
|
---|
[5104] | 157 |
|
---|
| 158 | QStringList values;
|
---|
| 159 |
|
---|
| 160 | if (_widget == 0) {
|
---|
| 161 | // TODO: exception
|
---|
| 162 | }
|
---|
| 163 |
|
---|
| 164 | QString widgetType = _desc.value("widget");
|
---|
| 165 |
|
---|
| 166 | if (widgetType == "checkbox") {
|
---|
| 167 | QCheckBox* chBox = static_cast<QCheckBox*>(_widget);
|
---|
[5105] | 168 | if (chBox->isChecked()) {
|
---|
| 169 | values << "1";
|
---|
| 170 | }
|
---|
| 171 | else {
|
---|
| 172 | values << "0";
|
---|
| 173 | }
|
---|
[5104] | 174 | }
|
---|
| 175 | else if (widgetType == "combobox") {
|
---|
| 176 | QComboBox* cmbBox = static_cast<QComboBox*>(_widget);
|
---|
[5105] | 177 | values << cmbBox->currentText();
|
---|
[5104] | 178 | }
|
---|
| 179 | else if (widgetType == "lineedit") {
|
---|
| 180 | t_lineEdit* lineEdit = static_cast<t_lineEdit*>(_widget);
|
---|
[5113] | 181 | if (!lineEdit->text().isEmpty()) {
|
---|
| 182 | values << lineEdit->text();
|
---|
| 183 | }
|
---|
[5104] | 184 | }
|
---|
| 185 | else if (widgetType == "radiobutton") {
|
---|
| 186 | QRadioButton* radButt = static_cast<QRadioButton*>(_widget);
|
---|
[5105] | 187 | if (radButt->isChecked()) {
|
---|
| 188 | values << "1";
|
---|
| 189 | }
|
---|
| 190 | else {
|
---|
| 191 | values << "0";
|
---|
| 192 | }
|
---|
[5104] | 193 | }
|
---|
| 194 | else if (widgetType == "selwin") {
|
---|
| 195 | t_selWin* selWin = static_cast<t_selWin*>(_widget);
|
---|
| 196 | }
|
---|
| 197 | else if (widgetType == "spinbox") {
|
---|
| 198 | QSpinBox* spinBox = static_cast<QSpinBox*>(_widget);
|
---|
[5106] | 199 | values << QString("%1").arg(spinBox->value());
|
---|
[5104] | 200 | }
|
---|
| 201 | else if (widgetType == "uniline") {
|
---|
| 202 | t_uniLine* uniLine = static_cast<t_uniLine*>(_widget);
|
---|
[5110] | 203 | for (int iRow = 0; iRow < uniLine->rowCount(); iRow++) {
|
---|
| 204 | QString rowStr;
|
---|
| 205 | for (int iCol = 0; iCol < uniLine->columnCount()-2; iCol++) {
|
---|
| 206 | QTableWidgetItem* item = uniLine->item(iRow, iCol);
|
---|
| 207 | if (item) {
|
---|
[5111] | 208 | if (iCol != 0) rowStr += " \"";
|
---|
| 209 | rowStr += item->text().trimmed();
|
---|
| 210 | if (iCol != uniLine->columnCount()-3) rowStr += '\"';
|
---|
[5110] | 211 | }
|
---|
| 212 | }
|
---|
| 213 | values << rowStr;
|
---|
| 214 | }
|
---|
[5104] | 215 | }
|
---|
| 216 |
|
---|
| 217 | return values;
|
---|
[5102] | 218 | }
|
---|
| 219 |
|
---|