From bcbaf0b8102188b5fc5e56133960ba0c2e4a8a41 Mon Sep 17 00:00:00 2001 From: Geoff Hutchison Date: Mon, 11 Sep 2023 16:58:25 -0400 Subject: [PATCH 1/2] Fixup mechanism to register script commands - now called by the app Previous code would ignore the signals, sent before the app connected Signed-off-by: Geoff Hutchison --- avogadro/qtgui/extensionplugin.h | 6 ++++++ avogadro/qtgui/toolplugin.h | 6 ++++++ avogadro/qtplugins/spectra/spectra.cpp | 23 +++++++++++++---------- avogadro/qtplugins/spectra/spectra.h | 2 ++ 4 files changed, 27 insertions(+), 10 deletions(-) diff --git a/avogadro/qtgui/extensionplugin.h b/avogadro/qtgui/extensionplugin.h index dcc85c2143..72c3e82fa8 100644 --- a/avogadro/qtgui/extensionplugin.h +++ b/avogadro/qtgui/extensionplugin.h @@ -74,6 +74,12 @@ class AVOGADROQTGUI_EXPORT ExtensionPlugin : public QObject */ virtual QList fileFormats() const; + /** + * If the extension plugin has script commands, this method + * should be implemented to emit the registerCommand signals. + */ + virtual void registerCommands() {} + public slots: /** * Called when the current molecule changes. diff --git a/avogadro/qtgui/toolplugin.h b/avogadro/qtgui/toolplugin.h index b5756f3df8..5bf161c1a6 100644 --- a/avogadro/qtgui/toolplugin.h +++ b/avogadro/qtgui/toolplugin.h @@ -103,6 +103,12 @@ class AVOGADROQTGUI_EXPORT ToolPlugin : public QObject virtual bool handleCommand(const QString& command, const QVariantMap& options); + /** + * Called by the app to tell the tool to register commands. + * If the tool has commands, it should emit the registerCommand signals. + */ + virtual void registerCommands() {} + signals: /** * Emitted when draw() needs to be called again due to updates. diff --git a/avogadro/qtplugins/spectra/spectra.cpp b/avogadro/qtplugins/spectra/spectra.cpp index f4d5541cb8..d893d4e0be 100644 --- a/avogadro/qtplugins/spectra/spectra.cpp +++ b/avogadro/qtplugins/spectra/spectra.cpp @@ -27,16 +27,6 @@ Spectra::Spectra(QObject* p) action->setText(tr("Vibrational Modes…")); connect(action, SIGNAL(triggered()), SLOT(openDialog())); m_actions.push_back(action); - - emit registerCommand("showVibrations", - tr("Show the vibrational modes dialog.")); - emit registerCommand("setVibrationalMode", tr("Set the vibrational mode.")); - emit registerCommand("setVibrationalAmplitude", - tr("Set the vibrational amplitude.")); - emit registerCommand("startVibrationAnimation", - tr("Start the vibrational animation.")); - emit registerCommand("stopVibrationAnimation", - tr("Stop the vibrational animation.")); } Spectra::~Spectra() {} @@ -68,6 +58,19 @@ void Spectra::setMolecule(QtGui::Molecule* mol) openDialog(); } +void Spectra::registerCommands() +{ + emit registerCommand("showVibrations", + tr("Show the vibrational modes dialog.")); + emit registerCommand("setVibrationalMode", tr("Set the vibrational mode.")); + emit registerCommand("setVibrationalAmplitude", + tr("Set the vibrational amplitude.")); + emit registerCommand("startVibrationAnimation", + tr("Start the vibrational animation.")); + emit registerCommand("stopVibrationAnimation", + tr("Stop the vibrational animation.")); +} + bool Spectra::handleCommand(const QString& command, const QVariantMap& options) { if (m_molecule == nullptr) diff --git a/avogadro/qtplugins/spectra/spectra.h b/avogadro/qtplugins/spectra/spectra.h index 8f1f51730f..588210a66a 100644 --- a/avogadro/qtplugins/spectra/spectra.h +++ b/avogadro/qtplugins/spectra/spectra.h @@ -45,6 +45,8 @@ class Spectra : public QtGui::ExtensionPlugin bool handleCommand(const QString& command, const QVariantMap& options) override; + void registerCommands() override; + public slots: void setMode(int mode); void setAmplitude(int amplitude); From af8af39411936753df77b38183c8160eb67facdf Mon Sep 17 00:00:00 2001 From: Geoff Hutchison Date: Mon, 11 Sep 2023 18:42:28 -0400 Subject: [PATCH 2/2] Fix formatting Signed-off-by: Geoff Hutchison --- avogadro/qtgui/extensionplugin.h | 2 +- avogadro/qtgui/toolplugin.h | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/avogadro/qtgui/extensionplugin.h b/avogadro/qtgui/extensionplugin.h index 72c3e82fa8..edf86b231a 100644 --- a/avogadro/qtgui/extensionplugin.h +++ b/avogadro/qtgui/extensionplugin.h @@ -77,7 +77,7 @@ class AVOGADROQTGUI_EXPORT ExtensionPlugin : public QObject /** * If the extension plugin has script commands, this method * should be implemented to emit the registerCommand signals. - */ + */ virtual void registerCommands() {} public slots: diff --git a/avogadro/qtgui/toolplugin.h b/avogadro/qtgui/toolplugin.h index 5bf161c1a6..a730a345a8 100644 --- a/avogadro/qtgui/toolplugin.h +++ b/avogadro/qtgui/toolplugin.h @@ -106,7 +106,7 @@ class AVOGADROQTGUI_EXPORT ToolPlugin : public QObject /** * Called by the app to tell the tool to register commands. * If the tool has commands, it should emit the registerCommand signals. - */ + */ virtual void registerCommands() {} signals: