summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndreas Cord-Landwehr <cordlandwehr@kde.org>2016-10-30 22:29:13 (GMT)
committerAndreas Cord-Landwehr <cordlandwehr@kde.org>2016-10-30 22:29:13 (GMT)
commit2665958aa5d6cf804f2e71fe2f452b5555f2805f (patch)
treefe90f2ab0a171f8bd8d564ea95cbe56c516fa515
parent877408c4ab8a6c2138322f5de5cec1acb8d02048 (diff)
Add workaround for broken QtGui::Molecule copy constructor
Pull request with fix for it is pending: https://github.com/OpenChemistry/avogadrolibs/pull/113
-rw-r--r--src/tools/moleculeview.cpp21
-rw-r--r--src/tools/moleculeview.h6
2 files changed, 14 insertions, 13 deletions
diff --git a/src/tools/moleculeview.cpp b/src/tools/moleculeview.cpp
index 652bea4..5cb7a48 100644
--- a/src/tools/moleculeview.cpp
+++ b/src/tools/moleculeview.cpp
@@ -164,23 +164,18 @@ void MoleculeDialog::loadMolecule(const QString &filename)
return;
}
- // workaround for missing copy-constructor: fixed in Avogadro2 > 0.9
- Avogadro::QtGui::Molecule tmpMol;
- tmpMol = *IoWrapper::readMolecule(filename);
- auto molecule = new Avogadro::QtGui::Molecule(tmpMol);
-
- // Check that a valid molecule object was returned
- if (!molecule) {
- qCritical() << "Could not load molecule, aborting.";
- return;
- }
+ // 1. workaround for missing copy-constructor: fixed in Avogadro2 > 0.9
+ // 2. another workaround for broken copy-constructor that does not
+ // initialize the m_undoMolecule private member variable;
+ // this molecule should be created on the heap instead of the stack
+ m_molecule = *IoWrapper::readMolecule(filename);
- if (molecule->atomCount() != 0) {
+ if (m_molecule.atomCount() != 0) {
disconnect(ui.glWidget->molecule(), 0, this, 0);
- ui.glWidget->setMolecule(molecule);
+ ui.glWidget->setMolecule(&m_molecule);
ui.glWidget->update();
slotUpdateStatistics();
- connect(molecule, &Avogadro::QtGui::Molecule::changed,
+ connect(&m_molecule, &Avogadro::QtGui::Molecule::changed,
this, &MoleculeDialog::slotUpdateStatistics);
}
ui.glWidget->resetCamera();
diff --git a/src/tools/moleculeview.h b/src/tools/moleculeview.h
index 2a9909a..9b29ab4 100644
--- a/src/tools/moleculeview.h
+++ b/src/tools/moleculeview.h
@@ -16,6 +16,7 @@
#define MOLECULEVIEW_H
#include <kdialog.h>
+#include <avogadro/qtgui/molecule.h>
#include "ui_moleculeviewerwidget.h"
@@ -92,6 +93,11 @@ private slots:
/// Clears the view
void clearAllElementsInEditor();
+
+private:
+ // workaround for broken copy-operator of QtGui::Molecule
+ // whould be removed after next Avogadro release greater 0.9
+ Avogadro::QtGui::Molecule m_molecule;
};
#endif // MOLECULEVIEW_H