Showing the changes to interface/src/scripting/WindowScriptingInterface.cpp (1 of 1 file). Show all
Unified · Split
| @@ -94,11 +94,14 @@ QScriptValue WindowScriptingInterface::showConfirm(const QString& message) { · 93 unmodified lines | ||
| 94 | 94 | /// Display a form layout with an edit box |
| 95 | 95 | /// \param const QString& title title to display |
| 96 | 96 | /// \param const QScriptValue form to display (array containing labels and values) |
| 97 | −/// \return QScriptValue result form (unchanged is dialog canceled) | |
| 97 | +/// \return QScriptValue `true` if 'OK' was clicked, `false` otherwise | |
| 98 | 98 | QScriptValue WindowScriptingInterface::showForm(const QString& title, QScriptValue form) { |
| 99 | + | |
| 99 | 100 | if (form.isArray() && form.property("length").toInt32() > 0) { |
| 100 | 101 | QDialog* editDialog = new QDialog(Application::getInstance()->getWindow()); |
| 101 | 102 | editDialog->setWindowTitle(title); |
| 103 | + | |
| 104 | + bool cancelButton = false; | |
| 102 | 105 | |
| 103 | 106 | QVBoxLayout* layout = new QVBoxLayout(); |
| 104 | 107 | editDialog->setLayout(layout); |
| @@ -120,42 +123,60 @@ QScriptValue WindowScriptingInterface::showForm(const QString& title, QScriptVal · 15 unmodified lines | ||
| 120 | 123 | QVector<QLineEdit*> edits; |
| 121 | 124 | for (int i = 0; i < form.property("length").toInt32(); ++i) { |
| 122 | 125 | QScriptValue item = form.property(i); |
| 123 | − edits.push_back(new QLineEdit(item.property("value").toString())); | |
| 124 | − formLayout->addRow(item.property("label").toString(), edits.back()); | |
| 126 | + | |
| 127 | + if (item.property("button").toString() != "") { | |
| 128 | + cancelButton = cancelButton || item.property("button").toString().toLower() == "cancel"; | |
| 129 | + } else { | |
| 130 | + edits.push_back(new QLineEdit(item.property("value").toString())); | |
| 131 | + formLayout->addRow(item.property("label").toString(), edits.back()); | |
| 132 | + } | |
| 125 | 133 | } |
| 126 | − QDialogButtonBox* buttons = new QDialogButtonBox(QDialogButtonBox::Ok); | |
| 134 | + | |
| 135 | + QDialogButtonBox* buttons = new QDialogButtonBox( | |
| 136 | + QDialogButtonBox::Ok | |
| 137 | + | (cancelButton ? QDialogButtonBox::Cancel : QDialogButtonBox::NoButton) | |
| 138 | + ); | |
| 127 | 139 | connect(buttons, SIGNAL(accepted()), editDialog, SLOT(accept())); |
| 140 | + connect(buttons, SIGNAL(rejected()), editDialog, SLOT(reject())); | |
| 128 | 141 | layout->addWidget(buttons); |
| 129 | 142 | |
| 130 | − if (editDialog->exec() == QDialog::Accepted) { | |
| 143 | + int result = editDialog->exec(); | |
| 144 | + if (result == QDialog::Accepted) { | |
| 145 | + int j = -1; | |
| 131 | 146 | for (int i = 0; i < form.property("length").toInt32(); ++i) { |
| 132 | 147 | QScriptValue item = form.property(i); |
| 133 | 148 | QScriptValue value = item.property("value"); |
| 134 | 149 | bool ok = true; |
| 135 | − if (value.isNumber()) { | |
| 136 | − value = edits.at(i)->text().toDouble(&ok); | |
| 137 | − } else if (value.isString()) { | |
| 138 | − value = edits.at(i)->text(); | |
| 139 | − } else if (value.isBool()) { | |
| 140 | − if (edits.at(i)->text() == "true") { | |
| 141 | − value = true; | |
| 142 | − } else if (edits.at(i)->text() == "false") { | |
| 143 | − value = false; | |
| 144 | − } else { | |
| 145 | − ok = false; | |
| 150 | + qDebug() << "item.property(""button"").toString() = " << item.property("button").toString(); | |
| 151 | + if (item.property("button").toString() == "") { | |
| 152 | + j += 1; | |
| 153 | + if (value.isNumber()) { | |
| 154 | + value = edits.at(j)->text().toDouble(&ok); | |
| 155 | + } else if (value.isString()) { | |
| 156 | + value = edits.at(j)->text(); | |
| 157 | + } else if (value.isBool()) { | |
| 158 | + if (edits.at(j)->text() == "true") { | |
| 159 | + value = true; | |
| 160 | + } else if (edits.at(j)->text() == "false") { | |
| 161 | + value = false; | |
| 162 | + } else { | |
| 163 | + ok = false; | |
| 164 | + } | |
| 165 | + } | |
| 166 | + if (ok) { | |
| 167 | + item.setProperty("value", value); | |
| 168 | + form.setProperty(i, item); | |
| 146 | 169 | } |
| 147 | − } | |
| 148 | − if (ok) { | |
| 149 | − item.setProperty("value", value); | |
| 150 | − form.setProperty(i, item); | |
| 151 | 170 | } |
| 152 | 171 | } |
| 153 | 172 | } |
| 154 | 173 | |
| 155 | 174 | delete editDialog; |
| 175 | + | |
| 176 | + return (result == QDialog::Accepted); | |
| 156 | 177 | } |
| 157 | 178 | |
| 158 | − return form; | |
| 179 | + return false; | |
| 159 | 180 | } |
| 160 | 181 | |
| 161 | 182 | /// Display a prompt with a text box |