From 5a66f83b1baa6d1a4baec11a224620b13ac81783 Mon Sep 17 00:00:00 2001 From: Geoff Hutchison Date: Fri, 6 Dec 2024 21:51:58 -0500 Subject: [PATCH] Make sure to update the dipole when the plugins are turned on/off Also fixup some old-style Qt signal-slot behavior Signed-off-by: Geoff Hutchison --- avogadro/qtopengl/glwidget.cpp | 43 ++++++++++++++++++++-------------- avogadro/qtopengl/glwidget.h | 9 +++++-- 2 files changed, 33 insertions(+), 19 deletions(-) diff --git a/avogadro/qtopengl/glwidget.cpp b/avogadro/qtopengl/glwidget.cpp index b76fb3edb1..9a7b3db549 100644 --- a/avogadro/qtopengl/glwidget.cpp +++ b/avogadro/qtopengl/glwidget.cpp @@ -30,10 +30,10 @@ GLWidget::GLWidget(QWidget* p) m_renderTimer(nullptr) { setFocusPolicy(Qt::ClickFocus); - connect(&m_scenePlugins, - SIGNAL(pluginStateChanged(Avogadro::QtGui::ScenePlugin*)), - SLOT(updateScene())); - connect(&m_scenePlugins, SIGNAL(pluginConfigChanged()), SLOT(updateScene())); + connect(&m_scenePlugins, &QtGui::ScenePluginModel::pluginStateChanged, this, + &GLWidget::updateScene); + connect(&m_scenePlugins, &QtGui::ScenePluginModel::pluginConfigChanged, this, + &GLWidget::updateScene); m_renderer.setTextRenderStrategy(new QtTextRenderStrategy); } @@ -48,12 +48,12 @@ void GLWidget::setMolecule(QtGui::Molecule* mol) foreach (QtGui::ToolPlugin* tool, m_tools) tool->setMolecule(m_molecule); - if (m_molecule) { + if (m_molecule != nullptr) { // update properties like dipole rendering QTimer::singleShot(500, m_molecule, &QtGui::Molecule::update); } - connect(m_molecule, SIGNAL(changed(unsigned int)), SLOT(updateScene())); + connect(m_molecule, &QtGui::Molecule::changed, this, &GLWidget::updateScene); } QtGui::Molecule* GLWidget::molecule() @@ -66,6 +66,14 @@ const QtGui::Molecule* GLWidget::molecule() const return m_molecule; } +void GLWidget::updateMolecule() +{ + if (m_molecule != nullptr) { + // update properties like dipole rendering + QTimer::singleShot(500, m_molecule, &QtGui::Molecule::update); + } +} + void GLWidget::updateScene() { // Build up the scene with the scene plugins, creating the appropriate nodes. @@ -130,7 +138,8 @@ void GLWidget::addTool(QtGui::ToolPlugin* tool) if (m_tools.contains(tool)) return; - connect(tool, SIGNAL(updateRequested()), SLOT(requestUpdate())); + connect(tool, &QtGui::ToolPlugin::updateRequested, this, + &GLWidget::requestUpdate); tool->setParent(this); tool->setGLWidget(this); tool->setActiveWidget(this); @@ -157,8 +166,8 @@ void GLWidget::setActiveTool(QtGui::ToolPlugin* tool) return; if (m_activeTool && m_activeTool != m_defaultTool) { - disconnect(m_activeTool, SIGNAL(drawablesChanged()), this, - SLOT(updateScene())); + disconnect(m_activeTool, &QtGui::ToolPlugin::drawablesChanged, this, + &GLWidget::updateScene); } if (tool) @@ -166,8 +175,8 @@ void GLWidget::setActiveTool(QtGui::ToolPlugin* tool) m_activeTool = tool; if (m_activeTool && m_activeTool != m_defaultTool) { - connect(m_activeTool, SIGNAL(drawablesChanged()), this, - SLOT(updateScene())); + connect(m_activeTool, &QtGui::ToolPlugin::drawablesChanged, this, + &GLWidget::updateScene); } } @@ -190,8 +199,8 @@ void GLWidget::setDefaultTool(QtGui::ToolPlugin* tool) return; if (m_defaultTool && m_activeTool != m_defaultTool) { - disconnect(m_defaultTool, SIGNAL(drawablesChanged()), this, - SLOT(updateScene())); + disconnect(m_defaultTool, &QtGui::ToolPlugin::drawablesChanged, this, + &GLWidget::updateScene); } if (tool) @@ -199,8 +208,8 @@ void GLWidget::setDefaultTool(QtGui::ToolPlugin* tool) m_defaultTool = tool; if (m_defaultTool && m_activeTool != m_defaultTool) { - connect(m_defaultTool, SIGNAL(drawablesChanged()), this, - SLOT(updateScene())); + connect(m_defaultTool, &QtGui::ToolPlugin::drawablesChanged, this, + &GLWidget::updateScene); } } @@ -208,8 +217,8 @@ void GLWidget::requestUpdate() { if (!m_renderTimer) { m_renderTimer = new QTimer(this); - connect(m_renderTimer, SIGNAL(timeout()), SLOT(updateTimeout())); - m_renderTimer->setSingleShot(1000 / 30); + connect(m_renderTimer, &QTimer::timeout, this, &GLWidget::updateTimeout); + m_renderTimer->setSingleShot(1000 / 30); // 30 fps m_renderTimer->start(); } } diff --git a/avogadro/qtopengl/glwidget.h b/avogadro/qtopengl/glwidget.h index c1bb8cf696..17e69bd177 100644 --- a/avogadro/qtopengl/glwidget.h +++ b/avogadro/qtopengl/glwidget.h @@ -116,6 +116,11 @@ public slots: */ void updateScene(); + /** + * Request update of molecule properties (e.g., dipole moment) + */ + void updateMolecule(); + /** * Clear the contents of the scene. */ @@ -201,7 +206,7 @@ protected slots: QTimer* m_renderTimer; }; -} // End QtOpenGL namespace -} // End Avogadro namespace +} // namespace QtOpenGL +} // namespace Avogadro #endif // AVOGADRO_QTOPENGL_GLWIDGET_H