Skip to content

Commit

Permalink
Make sure to update the dipole when the plugins are turned on/off
Browse files Browse the repository at this point in the history
Also fixup some old-style Qt signal-slot behavior

Signed-off-by: Geoff Hutchison <[email protected]>
  • Loading branch information
ghutchis committed Dec 7, 2024
1 parent ae8c2ce commit 5a66f83
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 19 deletions.
43 changes: 26 additions & 17 deletions avogadro/qtopengl/glwidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand All @@ -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()
Expand All @@ -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.
Expand Down Expand Up @@ -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);
Expand All @@ -157,17 +166,17 @@ 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)
addTool(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);
}
}

Expand All @@ -190,26 +199,26 @@ 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)
addTool(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);
}
}

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();
}
}
Expand Down
9 changes: 7 additions & 2 deletions avogadro/qtopengl/glwidget.h
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*/
Expand Down Expand Up @@ -201,7 +206,7 @@ protected slots:
QTimer* m_renderTimer;
};

} // End QtOpenGL namespace
} // End Avogadro namespace
} // namespace QtOpenGL
} // namespace Avogadro

#endif // AVOGADRO_QTOPENGL_GLWIDGET_H

1 comment on commit 5a66f83

@github-actions
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ERROR: clang-format-diff detected formatting issues. See the artifact for a patch or run clang-format on your branch.

Please sign in to comment.