Index: src/UIElements/Views/Qt4/MoleculeList/QtMoleculeList.hpp
===================================================================
--- src/UIElements/Views/Qt4/MoleculeList/QtMoleculeList.hpp	(revision f62e60b49352956721b98a4106d50c6f681b3f7d)
+++ src/UIElements/Views/Qt4/MoleculeList/QtMoleculeList.hpp	(revision 53c1ffef25e1f1a2be3255d54d76e7406c289ab9)
@@ -14,12 +14,17 @@
 #endif
 
+#include <QtGui/QItemSelection>
 #include <QtGui/QStandardItem>
 #include <QtGui/QStandardItemModel>
+#include <QTimer>
 
 #include <boost/bimap.hpp>
 #include <map>
+#include <set>
 #include <string>
 
 #include "CodePatterns/Observer/Observer.hpp"
+
+#include "UIElements/Views/Qt4/MoleculeList/QtMoleculeItem.hpp"
 
 #include "types.hpp"
@@ -27,4 +32,5 @@
 class molecule;
 class MoleculeListClass;
+class QtMoleculeItem;
 class QtMoleculeListView;
 
@@ -41,10 +47,6 @@
   virtual void recieveNotification(Observable *publisher, Notification_ptr notification);
   virtual void subjectKilled(Observable *publisher);
-//  virtual void paintEvent(QPaintEvent * event);
+
   void refill();
-
-  static const int COLUMNCOUNT;
-  enum {NAME,VISIBILITY,ATOMCOUNT,FORMULA,OCCURRENCE,COLUMNTYPES_MAX} COLUMNTYPES;
-  static const char *COLUMNNAMES[];
 
   QVariant headerData(int section, Qt::Orientation orientation, int role) const;
@@ -53,7 +55,10 @@
   void moleculeChanged();
 //  void visibilityChanged(QStandardItem*, int);
+  void checkState();
+
+  friend class QtMoleculeItem;
 
 //  void rowsSelected(const QItemSelection & selected, const QItemSelection & deselected);
-
+  void readdItem(QtMoleculeItem *_molitem);
 
 signals:
@@ -63,17 +68,33 @@
 
 private:
-  bool dirty;
-  bool clearing;
+
   bool selecting;
   bool changing;
   bool ChangingChildrensVisibility;
+  bool list_accessing;
+
+  //!> informs the view in regular intervals about updates
+  QTimer *update_timer;
+
+  //!> how often per second update is signalled to view
+  static const unsigned int update_times_per_second;
 
   friend class QtMoleculeListView;
-  QStandardItem * MoleculeToItem(const molecule * const _mol);
 
-  void addItem(const molecule * const _mol);
+  QtMoleculeItem * MoleculeToItem(const molecule * const _mol) const;
+  const molecule * const IndexToMolecule(const QModelIndex &_index) const;
+  const molecule * const ItemToMolecule(const QtMoleculeItem * const _item) const;
+
+  void addMolecule(const molecule * const _mol);
   void addGroupItem(QStandardItem *&mainitem, const std::string &_molecule_formula);
-  void addMoleculeItem(QStandardItem *_groupitem, const molecule *_mol, const std::string &molecule_formula);
-  void removeItem(const molecule * const _mol);
+  void addMoleculeItem(QStandardItem *_groupitem, const molecule * const _mol, const std::string &molecule_formula);
+  void removeItem(QtMoleculeItem * const _item);
+  int setOccurrence(QStandardItem * const _groupitem);
+  bool areAnyItemsDirty();
+  void addToBeSetOccurrence(QStandardItem *_groupitem);
+
+  void informDirtyState(QtMoleculeItem *_item, const QtMoleculeItem::MoveTypes _type);
+
+  void updateItemStates();
 
   typedef std::map<std::string, unsigned int> FormulaVisibilityCountMap_t;
@@ -84,6 +105,21 @@
   FormulaTreeItemMap_t formula;
 
-  typedef boost::bimap<const molecule *, QStandardItem*> MoleculeItemBiMap_t;
+  typedef boost::bimap<const molecule *, QtMoleculeItem*> MoleculeItemBiMap_t;
   MoleculeItemBiMap_t MoleculeItemBiMap;
+
+  //!> callback function to hand over to items that inform about requiring update
+  const QtMoleculeItem::emitDirtyState_t callback_DirtyItems;
+
+  typedef std::set<QtMoleculeItem*> list_of_items_t;
+  //!> list of items that need an update
+  list_of_items_t dirtyItems;
+  //!> list of items to molecule's whose formulas has changed and need to be moved
+  list_of_items_t toBeMovedItems;
+  //!> list of items to new molecules which need to be added
+  std::vector<const molecule *> newItems;
+  //!> list of items to molecules that have been removed
+  std::vector<const molecule *> toBeRemovedItems;
+  //!> list of group items that need update due to moved molecule items
+  std::set<QStandardItem*> toBeSetOccurrenceItems;
 };
 
