Index: src/UIElements/Views/Qt4/MoleculeList/QtMoleculeItem.cpp
===================================================================
--- src/UIElements/Views/Qt4/MoleculeList/QtMoleculeItem.cpp	(revision bed759c3580c014ab9c1b68a1a4aac91cd7ea811)
+++ src/UIElements/Views/Qt4/MoleculeList/QtMoleculeItem.cpp	(revision 6d1e0a20c242ab6c7b0ace4bf93ff53336b9cc26)
@@ -43,51 +43,55 @@
 #include "CodePatterns/Observer/Notification.hpp"
 
+#include <algorithm>
+
 #include "molecule.hpp"
 
-// some attributes need to be easier to find for molecules
-// these attributes are skipped so far
-const int QtMoleculeItem::COLUMNCOUNT = COLUMNTYPES_MAX;
-const char *QtMoleculeItem::COLUMNNAMES[QtMoleculeItem::COLUMNCOUNT]={"Name","Visibility", "Atoms","Formula","Occurrence"/*,"Size"*/};
-
-
-QList<QStandardItem *> createMoleculeItemRow(const molecule *_mol)
+QtMoleculeItem::QtMoleculeItem(
+     const molecule *_mol,
+     const channellist_t &_channellist,
+     const enum MoveTypes _movetype,
+     const emitDirtyState_t _emitDirtyState) :
+  Observer("QtMoleculeItem"),
+  mol(_mol),
+  movetype(_movetype),
+  channellist(_channellist),
+  IsSignedOn(false),
+  dirty(true),
+  emitDirtyState(_emitDirtyState)
 {
-  QList<QStandardItem *> molItems;
-  QStandardItem *mainitem = new QtMoleculeItem(_mol);
-  mainitem->setText(QString(_mol->getName().c_str()));
-  mainitem->setFlags(mainitem->flags() | Qt::ItemIsSelectable);
-  molItems << mainitem;
-
-  QStandardItem *visitem = new QStandardItem();
-  visitem->setCheckState(Qt::Unchecked);
-  visitem->setFlags(visitem->flags() | Qt::ItemIsUserCheckable);
-  molItems << visitem;
-
-  molItems << new QStandardItem(QString::number(_mol->getAtomCount()));
-  molItems << new QStandardItem(QString(_mol->getFormula().toString().c_str()));
-  molItems << new QStandardItem(QString(""));
-  return molItems;
+  signOnToMolecule();
+  setFlags(flags() | Qt::ItemIsSelectable);
 }
 
-QtMoleculeItem::QtMoleculeItem(const molecule *_mol) :
-  Observer("QtMoleculeItem"),
-  mol(_mol),
-  IsSignedOn(false)
+void QtMoleculeItem::signOnToMolecule()
 {
-  mol->signOn(this, molecule::AtomInserted);
-  mol->signOn(this, molecule::AtomRemoved);
-  mol->signOn(this, molecule::MoleculeNameChanged);
+  if (!IsSignedOn)
+    for (channellist_t::const_iterator channeliter = channellist.begin();
+        channeliter != channellist.end(); ++channeliter)
+      mol->signOn(this, *channeliter);
   IsSignedOn = true;
+}
+
+void QtMoleculeItem::signOffFromMolecule()
+{
+  if (IsSignedOn)
+    for (channellist_t::const_iterator channeliter = channellist.begin();
+        channeliter != channellist.end(); ++channeliter)
+      mol->signOff(this, *channeliter);
+  IsSignedOn = false;
 }
 
 QtMoleculeItem::~QtMoleculeItem()
 {
-  if (IsSignedOn) {
-    mol->signOff(this, molecule::AtomInserted);
-    mol->signOff(this, molecule::AtomRemoved);
-    mol->signOff(this, molecule::MoleculeNameChanged);
+  signOffFromMolecule();
+}
+
+void QtMoleculeItem::updateState()
+{
+  if (dirty) {
+    internal_updateState();
+    dirty = false;
   }
 }
-
 
 void QtMoleculeItem::update(Observable *publisher)
@@ -97,32 +101,20 @@
 {
   if (dynamic_cast<molecule *>(publisher) != NULL) {
-    switch (notification->getChannelNo()) {
-      case molecule::AtomInserted:
-      case molecule::AtomRemoved:
-      {
-        // change atomcount
-        QStandardItem *count_item = parent()->child(index().row(), ATOMCOUNT);
-        count_item->setText(QString::number(mol->getAtomCount()));
-
-        // change formula
-        const std::string molecule_formula = mol->getFormula().toString();
-        QStandardItem *formula_item = parent()->child(index().row(), FORMULA);
-        formula_item->setText(QString(molecule_formula.c_str()));
-
-        // re-position in model's tree
-//        static_cast<QtMoleculeList*>(model())->readdItem(this, molecule_formula);
-        break;
+    if (notification->getChannelNo() == molecule::AboutToBeRemoved) {
+      signOffFromMolecule();
+      // prevent any remaining updates from accessing the molecule
+      mol = NULL;
+      dirty = false;
+    } else {
+      channellist_t::const_iterator iter =
+          std::find(channellist.begin(), channellist.end(), notification->getChannelNo());
+      if (iter != channellist.end()) {
+        dirty = true;
+        emitDirtyState(this, movetype);
+      } else {
+        ASSERT(0,
+            "QtMoleculeItem::recieveNotification() - received notification to channel "
+            +toString(notification->getChannelNo())+" we are not subscribed to.");
       }
-      case molecule::MoleculeNameChanged:
-      {
-        // change name
-        QStandardItem *name_item = parent()->child(index().row(), NAME);
-        name_item->setText(QString(mol->getName().c_str()));
-        break;
-      }
-      default:
-        ASSERT(0, "QtMoleculeItem::recieveNotification() - cannot get here, not subscribed to channel "
-            +toString(notification->getChannelNo()));
-        break;
     }
   }
