History

- Edit -> Model List menu option - Combo items can be JS objects now, write a toString() function for each JS object to describe them

Thijs Wenker committed 12 years ago

Commit eed6e2e1 parent 36e78922 files · +172 −128Browse files

Showing the changes to interface/src/scripting/WindowScriptingInterface.cpp (1 of 2 files). Show all

Unified · Split

interface/src/scripting/WindowScriptingInterface.cpp+21−7
@@ -265,7 +265,11 @@ QScriptValue WindowScriptingInterface::doPeekNonBlockingFormResult(QScriptValue · 264 unmodified lines
265265 _form.setProperty(i, item);
266266 } else if (item.property("options").isArray()) {
267267 c += 1;
268− item.setProperty("value", _combos.at(c)->currentText());
268+ item.setProperty("value",
269+ _combos.at(c)->currentIndex() < item.property("options").property("length").toInt32() ?
270+ item.property("options").property(_combos.at(c)->currentIndex()) :
271+ array.engine()->undefinedValue()
272+ );
269273 _form.setProperty(i, item);
270274 } else {
271275 e += 1;
@@ -318,7 +322,11 @@ QScriptValue WindowScriptingInterface::doGetNonBlockingFormResult(QScriptValue a · 46 unmodified lines
318322 _form.setProperty(i, item);
319323 } else if (item.property("options").isArray()) {
320324 c += 1;
321− item.setProperty("value", _combos.at(c)->currentText());
325+ item.setProperty("value",
326+ _combos.at(c)->currentIndex() < item.property("options").property("length").toInt32() ?
327+ item.property("options").property(_combos.at(c)->currentIndex()) :
328+ array.engine()->undefinedValue()
329+ );
322330 _form.setProperty(i, item);
323331 } else {
324332 e += 1;
@@ -349,6 +357,7 @@ QScriptValue WindowScriptingInterface::doGetNonBlockingFormResult(QScriptValue a · 24 unmodified lines
349357 _form = QScriptValue();
350358 _edits.clear();
351359 _directories.clear();
360+ _combos.clear();
352361
353362 array = _form;
354363 return (_formResult == QDialog::Accepted);
@@ -391,8 +400,12 @@ QScriptValue WindowScriptingInterface::showForm(const QString& title, QScriptVal · 36 unmodified lines
391400 form.setProperty(i, item);
392401 } else if (item.property("options").isArray()) {
393402 c += 1;
394− item.setProperty("value", _combos.at(c)->currentText());
395− _form.setProperty(i, item);
403+ item.setProperty("value",
404+ _combos.at(c)->currentIndex() < item.property("options").property("length").toInt32() ?
405+ item.property("options").property(_combos.at(c)->currentIndex()) :
406+ form.engine()->undefinedValue()
407+ );
408+ form.setProperty(i, item);
396409 } else {
397410 e += 1;
398411 bool ok = true;
@@ -418,6 +431,7 @@ QScriptValue WindowScriptingInterface::showForm(const QString& title, QScriptVal · 19 unmodified lines
418431 }
419432
420433 delete editDialog;
434+ _combos.clear();
421435 _edits.clear();
422436 _directories.clear();
423437 return (result == QDialog::Accepted);
@@ -498,9 +512,9 @@ QDialog* WindowScriptingInterface::createForm(const QString& title, QScriptValue · 74 unmodified lines
498512 } else if (item.property("options").isArray()) {
499513 QComboBox* combo = new QComboBox();
500514 combo->setMinimumWidth(200);
501− QStringList options = item.property("options").toVariant().toStringList();
502− for (QStringList::const_iterator it = options.begin(); it != options.end(); it += 1) {
503− combo->addItem(*it);
515+ qint32 options_count = item.property("options").property("length").toInt32();// .toJsonArray();
516+ for (qint32 i = 0; i < options_count; i++) {
517+ combo->addItem(item.property("options").property(i).toString());
504518 }
505519 _combos.push_back(combo);
506520 formLayout->addRow(new QLabel(item.property("label").toString()), combo);