[prev in list] [next in list] [prev in thread] [next in thread] 

List:       kde-commits
Subject:    [kalzium/frameworks] src/tools: Add workaround for broken QtGui::Molecule copy constructor
From:       Andreas Cord-Landwehr <cordlandwehr () kde ! org>
Date:       2016-10-30 22:38:16
Message-ID: E1c0yk4-0002vd-Sz () code ! kde ! org
[Download RAW message or body]

Git commit 2665958aa5d6cf804f2e71fe2f452b5555f2805f by Andreas Cord-Landwehr.
Committed on 30/10/2016 at 22:29.
Pushed by cordlandwehr into branch 'frameworks'.

Add workaround for broken QtGui::Molecule copy constructor

Pull request with fix for it is pending:
https://github.com/OpenChemistry/avogadrolibs/pull/113

M  +8    -13   src/tools/moleculeview.cpp
M  +6    -0    src/tools/moleculeview.h

http://commits.kde.org/kalzium/2665958aa5d6cf804f2e71fe2f452b5555f2805f

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

[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic