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 | return retVal; | 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 | QScriptValue retVal; | 46 | QScriptValue retVal; |
| 47 | QMetaObject::invokeMethod(this, "showArrayEdit", Qt::BlockingQueuedConnection, | 47 | QMetaObject::invokeMethod(this, "showForm", Qt::BlockingQueuedConnection, |
| 48 | Q_RETURN_ARG(QScriptValue, retVal), | 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 | return retVal; | 50 | return retVal; |
| 51 | } | 51 | } |
| 52 | 52 | ||
| @@ -82,12 +82,12 @@ QScriptValue WindowScriptingInterface::showConfirm(const QString& message) { · 29 unmodified lines | |||
| 82 | return QScriptValue(response == QMessageBox::Yes); | 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 | /// \param const QString& title title to display | 86 | /// \param const QString& title title to display |
| 87 | /// \param const QString& defaultText default text in the text box | 87 | /// \param const QScriptValue form to display (array containing labels and values) |
| 88 | /// \return QScriptValue string text value in text box if the dialog was accepted, `null` otherwise. | 88 | /// \return QScriptValue result form (unchanged is dialog canceled) |
| 89 | QScriptValue WindowScriptingInterface::showArrayEdit(const QString& title, QScriptValue array) { | 89 | QScriptValue WindowScriptingInterface::showForm(const QString& title, QScriptValue form) { |
| 90 | if (array.isArray() && array.property("length").toInt32() > 0) { | 90 | if (form.isArray() && form.property("length").toInt32() > 0) { |
| 91 | QDialog* editDialog = new QDialog(Application::getInstance()->getWindow()); | 91 | QDialog* editDialog = new QDialog(Application::getInstance()->getWindow()); |
| 92 | editDialog->setWindowTitle(title); | 92 | editDialog->setWindowTitle(title); |
| 93 | 93 | ||
| @@ -98,27 +98,29 @@ QScriptValue WindowScriptingInterface::showArrayEdit(const QString& title, QScri · 4 unmodified lines | |||
| 98 | layout->addWidget(area); | 98 | layout->addWidget(area); |
| 99 | area->setWidgetResizable(true); | 99 | area->setWidgetResizable(true); |
| 100 | QWidget* container = new QWidget(); | 100 | QWidget* container = new QWidget(); |
| 101 | QFormLayout* arrayLayout = new QFormLayout(); | 101 | QFormLayout* formLayout = new QFormLayout(); |
| 102 | container->setLayout(arrayLayout); | 102 | container->setLayout(formLayout); |
| 103 | container->setSizePolicy(QSizePolicy::Ignored, QSizePolicy::Preferred); | 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 | area->setWidget(container); | 109 | area->setWidget(container); |
| 105 | 110 | ||
| 106 | QVector<QLineEdit*> edits; | 111 | QVector<QLineEdit*> edits; |
| 107 | for (int i = 0; i < array.property("length").toInt32(); ++i) { | 112 | for (int i = 0; i < form.property("length").toInt32(); ++i) { |
| 108 | QScriptValue item = array.property(i); | 113 | QScriptValue item = form.property(i); |
| 109 | edits.push_back(new QLineEdit(item.property("value").toString())); | 114 | edits.push_back(new QLineEdit(item.property("value").toString())); |
| 110 | arrayLayout->addRow(item.property("label").toString(), | 115 | formLayout->addRow(item.property("label").toString(), edits.back()); |
| 111 | edits.back()); | ||
| 112 | } | 116 | } |
| 113 | QDialogButtonBox* buttons = new QDialogButtonBox(QDialogButtonBox::Ok); | 117 | QDialogButtonBox* buttons = new QDialogButtonBox(QDialogButtonBox::Ok); |
| 114 | connect(buttons, SIGNAL(accepted()), editDialog, SLOT(accept())); | 118 | connect(buttons, SIGNAL(accepted()), editDialog, SLOT(accept())); |
| 115 | layout->addWidget(buttons); | 119 | layout->addWidget(buttons); |
| 116 | 120 | ||
| 117 | editDialog->setMinimumSize(600, 600); | ||
| 118 | |||
| 119 | if (editDialog->exec() == QDialog::Accepted) { | 121 | if (editDialog->exec() == QDialog::Accepted) { |
| 120 | for (int i = 0; i < array.property("length").toInt32(); ++i) { | 122 | for (int i = 0; i < form.property("length").toInt32(); ++i) { |
| 121 | QScriptValue item = array.property(i); | 123 | QScriptValue item = form.property(i); |
| 122 | QScriptValue value = item.property("value"); | 124 | QScriptValue value = item.property("value"); |
| 123 | bool ok = true; | 125 | bool ok = true; |
| 124 | if (value.isNumber()) { | 126 | if (value.isNumber()) { |
| @@ -136,7 +138,7 @@ QScriptValue WindowScriptingInterface::showArrayEdit(const QString& title, QScri · 11 unmodified lines | |||
| 136 | } | 138 | } |
| 137 | if (ok) { | 139 | if (ok) { |
| 138 | item.setProperty("value", value); | 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 | delete editDialog; | 146 | delete editDialog; |
| 145 | } | 147 | } |
| 146 | 148 | ||
| 147 | return array; | 149 | return form; |
| 148 | } | 150 | } |
| 149 | 151 | ||
| 150 | /// Display a prompt with a text box | 152 | /// Display a prompt with a text box |