diff --git a/avogadro/qtgui/jsonwidget.cpp b/avogadro/qtgui/jsonwidget.cpp index 9d4302803d..b04e502ee4 100644 --- a/avogadro/qtgui/jsonwidget.cpp +++ b/avogadro/qtgui/jsonwidget.cpp @@ -209,26 +209,27 @@ void JsonWidget::buildOptionGui() // Add remaining keys at bottom. // look for "order" key to determine order - QStringList keys; + QMap 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(