Showing the changes to interface/src/scripting/WindowScriptingInterface.cpp (1 of 3 files). Show all
Unified · Split
| @@ -42,11 +42,11 @@ QScriptValue WindowScriptingInterface::confirm(const QString& message) { · 41 unmodified lines | ||
| 42 | 42 | return retVal; |
| 43 | 43 | } |
| 44 | 44 | |
| 45 | −QScriptValue WindowScriptingInterface::arrayEdit(const QString& title, QScriptValue array) { | |
| 45 | +QScriptValue WindowScriptingInterface::form(const QString& title, QScriptValue form) { | |
| 46 | 46 | QScriptValue retVal; |
| 47 | − QMetaObject::invokeMethod(this, "showArrayEdit", Qt::BlockingQueuedConnection, | |
| 47 | + QMetaObject::invokeMethod(this, "showForm", Qt::BlockingQueuedConnection, | |
| 48 | 48 | Q_RETURN_ARG(QScriptValue, retVal), |
| 49 | − Q_ARG(const QString&, title), Q_ARG(QScriptValue, array)); | |
| 49 | + Q_ARG(const QString&, title), Q_ARG(QScriptValue, form)); | |
| 50 | 50 | return retVal; |
| 51 | 51 | } |
| 52 | 52 | |
| @@ -82,12 +82,12 @@ QScriptValue WindowScriptingInterface::showConfirm(const QString& message) { · 29 unmodified lines | ||
| 82 | 82 | return QScriptValue(response == QMessageBox::Yes); |
| 83 | 83 | } |
| 84 | 84 | |
| 85 | −/// Display a prompt with an edit box | |
| 85 | +/// Display a form layout with an edit box | |
| 86 | 86 | /// \param const QString& title title to display |
| 87 | −/// \param const QString& defaultText default text in the text box | |
| 88 | −/// \return QScriptValue string text value in text box if the dialog was accepted, `null` otherwise. | |
| 89 | −QScriptValue WindowScriptingInterface::showArrayEdit(const QString& title, QScriptValue array) { | |
| 90 | − if (array.isArray() && array.property("length").toInt32() > 0) { | |
| 87 | +/// \param const QScriptValue form to display (array containing labels and values) | |
| 88 | +/// \return QScriptValue result form (unchanged is dialog canceled) | |
| 89 | +QScriptValue WindowScriptingInterface::showForm(const QString& title, QScriptValue form) { | |
| 90 | + if (form.isArray() && form.property("length").toInt32() > 0) { | |
| 91 | 91 | QDialog* editDialog = new QDialog(Application::getInstance()->getWindow()); |
| 92 | 92 | editDialog->setWindowTitle(title); |
| 93 | 93 | |
| @@ -98,27 +98,29 @@ QScriptValue WindowScriptingInterface::showArrayEdit(const QString& title, QScri · 4 unmodified lines | ||
| 98 | 98 | layout->addWidget(area); |
| 99 | 99 | area->setWidgetResizable(true); |
| 100 | 100 | QWidget* container = new QWidget(); |
| 101 | − QFormLayout* arrayLayout = new QFormLayout(); | |
| 102 | − container->setLayout(arrayLayout); | |
| 103 | − container->setSizePolicy(QSizePolicy::Ignored, QSizePolicy::Preferred); | |
| 101 | + QFormLayout* formLayout = new QFormLayout(); | |
| 102 | + container->setLayout(formLayout); | |
| 103 | + container->sizePolicy().setHorizontalStretch(1); | |
| 104 | + formLayout->setRowWrapPolicy(QFormLayout::DontWrapRows); | |
| 105 | + formLayout->setFieldGrowthPolicy(QFormLayout::ExpandingFieldsGrow); | |
| 106 | + formLayout->setFormAlignment(Qt::AlignHCenter | Qt::AlignTop); | |
| 107 | + formLayout->setLabelAlignment(Qt::AlignLeft); | |
| 108 | + | |
| 104 | 109 | area->setWidget(container); |
| 105 | 110 | |
| 106 | 111 | QVector<QLineEdit*> edits; |
| 107 | − for (int i = 0; i < array.property("length").toInt32(); ++i) { | |
| 108 | − QScriptValue item = array.property(i); | |
| 112 | + for (int i = 0; i < form.property("length").toInt32(); ++i) { | |
| 113 | + QScriptValue item = form.property(i); | |
| 109 | 114 | edits.push_back(new QLineEdit(item.property("value").toString())); |
| 110 | − arrayLayout->addRow(item.property("label").toString(), | |
| 111 | − edits.back()); | |
| 115 | + formLayout->addRow(item.property("label").toString(), edits.back()); | |
| 112 | 116 | } |
| 113 | 117 | QDialogButtonBox* buttons = new QDialogButtonBox(QDialogButtonBox::Ok); |
| 114 | 118 | connect(buttons, SIGNAL(accepted()), editDialog, SLOT(accept())); |
| 115 | 119 | layout->addWidget(buttons); |
| 116 | 120 | |
| 117 | − editDialog->setMinimumSize(600, 600); | |
| 118 | − | |
| 119 | 121 | if (editDialog->exec() == QDialog::Accepted) { |
| 120 | − for (int i = 0; i < array.property("length").toInt32(); ++i) { | |
| 121 | − QScriptValue item = array.property(i); | |
| 122 | + for (int i = 0; i < form.property("length").toInt32(); ++i) { | |
| 123 | + QScriptValue item = form.property(i); | |
| 122 | 124 | QScriptValue value = item.property("value"); |
| 123 | 125 | bool ok = true; |
| 124 | 126 | if (value.isNumber()) { |
| @@ -136,7 +138,7 @@ QScriptValue WindowScriptingInterface::showArrayEdit(const QString& title, QScri · 11 unmodified lines | ||
| 136 | 138 | } |
| 137 | 139 | if (ok) { |
| 138 | 140 | item.setProperty("value", value); |
| 139 | − array.setProperty(i, item); | |
| 141 | + form.setProperty(i, item); | |
| 140 | 142 | } |
| 141 | 143 | } |
| 142 | 144 | } |
| @@ -144,7 +146,7 @@ QScriptValue WindowScriptingInterface::showArrayEdit(const QString& title, QScri · 1 unmodified line | ||
| 144 | 146 | delete editDialog; |
| 145 | 147 | } |
| 146 | 148 | |
| 147 | − return array; | |
| 149 | + return form; | |
| 148 | 150 | } |
| 149 | 151 | |
| 150 | 152 | /// Display a prompt with a text box |