From df5c428f2772d58bff3d6eaf9cfedf6697280d90 Mon Sep 17 00:00:00 2001 From: Geoff Hutchison Date: Wed, 18 Oct 2023 22:32:35 -0400 Subject: [PATCH] Minor fix for scripting orbital rendering - allow integers Signed-off-by: Geoff Hutchison --- avogadro/qtplugins/surfaces/surfaces.cpp | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/avogadro/qtplugins/surfaces/surfaces.cpp b/avogadro/qtplugins/surfaces/surfaces.cpp index 59ce8e13b9..3aed3eaef7 100644 --- a/avogadro/qtplugins/surfaces/surfaces.cpp +++ b/avogadro/qtplugins/surfaces/surfaces.cpp @@ -154,8 +154,14 @@ bool Surfaces::handleCommand(const QString& command, const QVariantMap& options) homo = m_basis->homo(); if (options.contains("orbital")) { // check if options contains "homo" or "lumo" - bool string = options["orbital"].canConvert(); - if (string) { + bool ok = false; + if (options["orbital"].canConvert()) { + // internally, we count orbitals from zero + // if the conversion worked, ok = true + // and we'll skip the next conditional + index = options.value("orbital").toInt(&ok) - 1; + } + if (!ok && options["orbital"].canConvert()) { // should be something like "homo-1" or "lumo+2" QString name = options["orbital"].toString(); QString expression, modifier; @@ -181,9 +187,6 @@ bool Surfaces::handleCommand(const QString& command, const QVariantMap& options) index = index + n; } index = index - 1; // start from zero - } else { - // internally, we count orbitals from zero - index = options.value("index").toInt() - 1; } } bool beta = false;