Skip to content

Commit

Permalink
Use a map to sort by order if available
Browse files Browse the repository at this point in the history
Signed-off-by: Geoff Hutchison <[email protected]>
  • Loading branch information
ghutchis committed Dec 5, 2023
1 parent ea531ac commit b8ae295
Showing 1 changed file with 8 additions and 7 deletions.
15 changes: 8 additions & 7 deletions avogadro/qtgui/jsonwidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -209,26 +209,27 @@ void JsonWidget::buildOptionGui()

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

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

// Make connections for standard options:
if (auto* combo = qobject_cast<QComboBox*>(
Expand Down

0 comments on commit b8ae295

Please sign in to comment.