Skip to content

Commit

Permalink
Merge pull request #1503 from ghutchis/sort-user-option-order
Browse files Browse the repository at this point in the history
If userOptions specifies an order, use that to sort the form
  • Loading branch information
ghutchis authored Dec 5, 2023
2 parents f276a10 + b8ae295 commit 34b34ea
Showing 1 changed file with 18 additions and 1 deletion.
19 changes: 18 additions & 1 deletion avogadro/qtgui/jsonwidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -208,12 +208,29 @@ void JsonWidget::buildOptionGui()
}

// Add remaining keys at bottom.
// look for "order" key to determine order
QMap<int, QString> keys;
int order = 0;
for (QJsonObject::const_iterator it = userOptions.constBegin(),
itEnd = userOptions.constEnd();
it != itEnd; ++it) {
addOptionRow(it.key(), it.key(), it.value());
if (it.value().isObject()) {
QJsonObject obj = it.value().toObject();
if (obj.contains("order") && obj.value("order").isDouble()) {
order = obj.value("order").toInt();
keys.insert(order, it.key());
} else { // object doesn't contain "order"
keys.insert(order++, it.key());
}
} else {
keys.insert(order++, it.key());
}
}

// now loop over keys and add them
for (QString key : std::as_const(keys))
addOptionRow(key, key, userOptions.take(key));

// Make connections for standard options:
if (auto* combo = qobject_cast<QComboBox*>(
m_widgets.value("Calculation Type", nullptr))) {
Expand Down

0 comments on commit 34b34ea

Please sign in to comment.