From c701c3e899d15b86ad7a65f2daca64472715047e Mon Sep 17 00:00:00 2001 From: Geoff Hutchison Date: Tue, 17 Oct 2023 21:35:55 -0400 Subject: [PATCH] Switch to using CJSON as the default format with obabel Signed-off-by: Geoff Hutchison --- avogadro/qtplugins/openbabel/openbabel.cpp | 24 ++++++++++++---------- 1 file changed, 13 insertions(+), 11 deletions(-) diff --git a/avogadro/qtplugins/openbabel/openbabel.cpp b/avogadro/qtplugins/openbabel/openbabel.cpp index fc00590de3..c461ccc73d 100644 --- a/avogadro/qtplugins/openbabel/openbabel.cpp +++ b/avogadro/qtplugins/openbabel/openbabel.cpp @@ -38,7 +38,7 @@ namespace Avogadro::QtPlugins { OpenBabel::OpenBabel(QObject* p) : ExtensionPlugin(p), m_molecule(nullptr), m_process(new OBProcess(this)), m_readFormatsPending(true), m_writeFormatsPending(true), - m_defaultFormat("cml"), m_progress(nullptr) + m_defaultFormat("cjson"), m_progress(nullptr) { auto* action = new QAction(this); action->setEnabled(true); @@ -126,7 +126,7 @@ QList OpenBabel::fileFormats() const std::vector fmime; // Simple lambda to replace toSet in QList - auto toSet = [&] (const QList& list) { + auto toSet = [&](const QList& list) { return QSet(list.begin(), list.end()); }; @@ -259,9 +259,9 @@ void OpenBabel::handleReadFormatUpdate(const QMultiMap& fmts) emit fileFormatsReady(); // Update the default format if cjson is available - if (m_readFormats.contains("Chemical JSON") && - m_writeFormats.contains("Chemical JSON")) { - m_defaultFormat = "cjson"; + if (!m_readFormats.contains("Chemical JSON") && + !m_writeFormats.contains("Chemical JSON")) { + m_defaultFormat = "cml"; } } } @@ -294,9 +294,9 @@ void OpenBabel::handleWriteFormatUpdate(const QMultiMap& fmts) emit fileFormatsReady(); // Update the default format if cjson is available - if (m_readFormats.contains("Chemical JSON") && - m_writeFormats.contains("Chemical JSON")) { - m_defaultFormat = "cjson"; + if (!m_readFormats.contains("Chemical JSON") && + !m_writeFormats.contains("Chemical JSON")) { + m_defaultFormat = "cml"; } } } @@ -313,7 +313,8 @@ void OpenBabel::refreshForceFields() proc->queryForceFields(); } -void OpenBabel::handleForceFieldsUpdate(const QMultiMap& ffMap) +void OpenBabel::handleForceFieldsUpdate( + const QMultiMap& ffMap) { auto* proc = qobject_cast(sender()); if (proc) @@ -334,7 +335,8 @@ void OpenBabel::refreshCharges() proc->queryCharges(); } -void OpenBabel::handleChargesUpdate(const QMultiMap& chargeMap) +void OpenBabel::handleChargesUpdate( + const QMultiMap& chargeMap) { auto* proc = qobject_cast(sender()); if (proc) @@ -860,4 +862,4 @@ QString OpenBabel::autoDetectForceField() const return result; } -} // namespace Avogadro +} // namespace Avogadro::QtPlugins