Index: src/UIElements/Views/Qt4/MoleculeList/QtMoleculeList.cpp
===================================================================
--- src/UIElements/Views/Qt4/MoleculeList/QtMoleculeList.cpp	(revision 24eb6b9e8f3b4ff8f95f2e26c0a57c2296d904de)
+++ src/UIElements/Views/Qt4/MoleculeList/QtMoleculeList.cpp	(revision 5771e66594e586dad5518921119581034d3235d2)
@@ -66,21 +66,25 @@
 using namespace std;
 
-const unsigned int QtMoleculeList::update_times_per_second = 20;
-
 QtMoleculeList::QtMoleculeList(
     QtObservedInstanceBoard *_board,
     QObject *_parent) :
   QStandardItemModel(_parent),
-  update_timer(NULL),
-  board(_board)
+  board(_board),
+  observer(_board)
 {
   setColumnCount(QtMoleculeItemFactory::COLUMNCOUNT);
 
-  resetUpdateTimer();
-
-  connect(this,SIGNAL(itemChanged(QStandardItem*)),this,SLOT(moleculeNameChanged(QStandardItem*)));
-  connect(this, SIGNAL(itemChanged(QStandardItem*)), this, SLOT(checkForVisibilityChange(QStandardItem*)));
-  connect(board, SIGNAL(moleculeInserted(QtObservedMolecule::ptr)), this, SLOT(moleculeInserted(QtObservedMolecule::ptr)));
-  connect(board, SIGNAL(moleculeRemoved(const moleculeId_t)), this, SLOT(moleculeRemoved(const moleculeId_t)));
+  connect(this,SIGNAL(itemChanged(QStandardItem*)),
+      this,SLOT(moleculeNameChanged(QStandardItem*)));
+  connect(this, SIGNAL(itemChanged(QStandardItem*)),
+      this, SLOT(checkForVisibilityChange(QStandardItem*)));
+  connect(&observer, SIGNAL(MoleculeInserted(QtObservedMolecule::ptr)),
+      this, SLOT(moleculeInserted(QtObservedMolecule::ptr)));
+  connect(&observer, SIGNAL(MoleculeRemoved(const moleculeId_t)),
+      this, SLOT(moleculeRemoved(const moleculeId_t)));
+  connect(&observer, SIGNAL(FormulaChanged(const QtObservedMolecule::ptr)),
+      this, SLOT(formulaChanged(const QtObservedMolecule::ptr)));
+  connect(&observer, SIGNAL(NameChanged(const QtObservedMolecule::ptr)),
+      this, SLOT(nameChanged(const QtObservedMolecule::ptr)));
   connect(board, SIGNAL(moleculeIndexChanged(const moleculeId_t,const moleculeId_t)),
       this, SLOT(moleculeIndexChanged(const moleculeId_t, const moleculeId_t)));
@@ -103,20 +107,28 @@
 void QtMoleculeList::moleculeInserted(QtObservedMolecule::ptr _mol)
 {
-  // get ObservedMolecule from board
-  boost::recursive_mutex::scoped_lock lock(listAccessing_mutex);
-  newMolecules.push_back( _mol );
+  LOG(1, "Adding molecule " << _mol->getMolName());
+  // check that World knows the molecule still
+  const std::string formula = addMolecule(_mol);
+  LOG(1, "Adding " << formula << " to toBeSetOccurrence.");
+  setOccurrence(FormulaToGroupItem(formula));
 }
 
 void QtMoleculeList::moleculeRemoved(const moleculeId_t _id)
 {
-  boost::recursive_mutex::scoped_lock lock(map_mutex);
-  KilledItemsPerMolecule_t::iterator iter = KilledItemsPerMolecule.find(_id);
-  if (iter == KilledItemsPerMolecule.end())
-    KilledItemsPerMolecule.insert( std::make_pair(_id, 1));
-  else
-    ++(iter->second);
-  if (iter->second == QtMoleculeItem::COLUMNTYPES_MAX) {
-    boost::recursive_mutex::scoped_lock lock(listAccessing_mutex);
-    removedMolecules.push_back( _id );
+  LOG(1, "Removing molecule " << _id);
+  if (!isMoleculeItemPresent(_id)) {
+    ELOG(1, "QtMoleculeItem to id " << _id << " has disappeared before removal.");
+    return;
+  }
+  QtMoleculeItem *item = MoleculeIdToItem(_id);
+  if (item != NULL) {
+    const std::string formula = item->parent()->text().toStdString();
+    LOG(1, "Adding " << formula << " to toBeSetOccurrence.");
+    const int removeindex = setOccurrence(FormulaToGroupItem(formula));
+    removeMoleculeItem(item);
+    if (removeindex != -1) {
+      LOG(1, "Removing row of group item to " << formula);
+      removeRows(removeindex, 1, invisibleRootItem()->index());
+    }
   }
 }
@@ -183,19 +195,8 @@
     MoleculeItemBiMap.left.erase(iter);
   }
-  exchangeKeys(KilledItemsPerMolecule, _oldid, _newid);
-  exchangeKeysOverAllColumns(dirtyMolItems, _oldid, _newid);
-  exchangeKeysInSet(visibilityMolItems, _oldid, _newid);
-  {
-    std::vector<moleculeId_t>::iterator iter =
-        std::find(removedMolecules.begin(), removedMolecules.end(), _oldid);
-    removedMolecules.erase(iter);
-    removedMolecules.push_back(_newid);
-  }
-  exchangeKeysInSet(toBeMovedItems, _oldid, _newid);
 }
 
 bool QtMoleculeList::isMoleculeItemPresent(const moleculeId_t _molid) const
 {
-  boost::recursive_mutex::scoped_lock lock(map_mutex);
   MoleculeItemBiMap_t::left_const_iterator iter =
       MoleculeItemBiMap.left.find(_molid);
@@ -205,5 +206,4 @@
 QtMoleculeItem * QtMoleculeList::MoleculeIdToItem(const moleculeId_t _molid) const
 {
-  boost::recursive_mutex::scoped_lock lock(map_mutex);
   MoleculeItemBiMap_t::left_const_iterator iter =
       MoleculeItemBiMap.left.find(_molid);
@@ -216,5 +216,4 @@
 const moleculeId_t QtMoleculeList::ItemToMoleculeId(const QtMoleculeItem * const _item) const
 {
-  boost::recursive_mutex::scoped_lock lock(map_mutex);
   const MoleculeItemBiMap_t::right_const_iterator iter =
       MoleculeItemBiMap.right.find(const_cast<QtMoleculeItem * const>(_item));
@@ -237,5 +236,4 @@
 bool QtMoleculeList::isGroupItemPresent(const std::string &_formula) const
 {
-  boost::recursive_mutex::scoped_lock lock(map_mutex);
   FormulaTreeItemBiMap_t::left_const_iterator iter =
       FormulaItemBiMap.left.find(_formula);
@@ -245,5 +243,4 @@
 QStandardItem * QtMoleculeList::FormulaToGroupItem(const std::string &_formula) const
 {
-  boost::recursive_mutex::scoped_lock lock(map_mutex);
   FormulaTreeItemBiMap_t::left_const_iterator iter =
       FormulaItemBiMap.left.find(_formula);
@@ -256,5 +253,4 @@
 const std::string& QtMoleculeList::GroupItemToFormula(const QStandardItem * const _item) const
 {
-  boost::recursive_mutex::scoped_lock lock(map_mutex);
   static std::string emptystring;
   const FormulaTreeItemBiMap_t::right_const_iterator iter =
@@ -275,5 +271,4 @@
 const QModelIndex QtMoleculeList::MoleculeIdToIndex(const moleculeId_t _id) const
 {
-  boost::recursive_mutex::scoped_lock lock(refill_mutex);
   QtMoleculeItem * const item = MoleculeIdToItem(_id);
   ASSERT(item != NULL,
@@ -285,5 +280,4 @@
 const moleculeId_t QtMoleculeList::IndexToMoleculeId(const QModelIndex &_index) const
 {
-  boost::recursive_mutex::scoped_lock lock(refill_mutex);
   QtMoleculeItem * const item = dynamic_cast<QtMoleculeItem *>(itemFromIndex(_index));
   if (item == NULL)
@@ -300,8 +294,5 @@
       QtMoleculeItemFactory::getInstance().createGroupItems(_molecule_formula);
   mainitem = groupItems.front();
-  {
-    boost::recursive_mutex::scoped_lock lock(map_mutex);
-    FormulaItemBiMap.left.insert( std::make_pair(_molecule_formula, mainitem) );
-  }
+  FormulaItemBiMap.left.insert( std::make_pair(_molecule_formula, mainitem) );
   invisibleRootItem()->appendRow(groupItems);
 }
@@ -366,10 +357,8 @@
 void QtMoleculeList::removeMoleculeItem(QtMoleculeItem * const _item)
 {
-  boost::recursive_mutex::scoped_lock lock(refill_mutex);
   const QModelIndex mol_index = indexFromItem(_item);
   QStandardItem *groupitem = _item->parent();
   const QModelIndex group_index = groupitem->index();
   {
-    boost::recursive_mutex::scoped_lock lock(map_mutex);
     MoleculeItemBiMap_t::right_iterator removeiter =
         MoleculeItemBiMap.right.find(_item);
@@ -392,55 +381,17 @@
 }
 
-void QtMoleculeList::resetUpdateTimer()
-{
-  // check timer's presence
-  if (update_timer == NULL) {
-    update_timer = new QTimer(this);
-    connect( update_timer, SIGNAL(timeout()), this, SLOT(checkState()));
-  } else
-    update_timer->stop();
-
-  // activate timer
-  update_timer->start(1000/update_times_per_second);
-}
-
-bool QtMoleculeList::areAnyItemsDirty()
-{
-  // get whether any items are dirty
-  boost::recursive_mutex::scoped_lock lock(listAccessing_mutex);
-  bool dirty = false;
-  dirty |= !dirtyMolItems.empty();
-  dirty |= !visibilityMolItems.empty();
-  dirty |= !dirtyGroupItems.empty();
-  dirty |= !visibilityGroupItems.empty();
-  dirty |= !newMolecules.empty();
-  dirty |= !removedMolecules.empty();
-  dirty |= !toBeMovedItems.empty();
-  return dirty;
-}
-
-void QtMoleculeList::checkState()
-{
-  const bool dirty = areAnyItemsDirty();
-  // update if required
-  if (dirty)
-    updateItemStates();
-}
-
 void QtMoleculeList::checkForVisibilityChange(QStandardItem* _item)
 {
 //  qDebug() << "Item changed called.";
 
-  boost::recursive_mutex::scoped_lock lock(refill_mutex);
   if (_item->index().column() == QtMoleculeItem::VISIBILITY) {
 //    qDebug() << "visibilityItem changed: " << (_item->checkState() ? "checked" : "unchecked");
-    boost::recursive_mutex::scoped_lock lock(listAccessing_mutex);
-    if ((_item->parent() == NULL) || (_item->parent() == invisibleRootItem()))
-      visibilityGroupItems.insert( std::make_pair(
-          GroupItemToFormula(_item->parent()), QtMoleculeItem::VISIBILITY) );
-    else
-      visibilityMolItems.insert(
-          static_cast<QtMoleculeItem *>(_item)->getMoleculeId()
-          );
+    if ((_item->parent() == NULL) || (_item->parent() == invisibleRootItem())) {
+      LOG(1, "Updating visibility of group item " << _item);
+      setVisibilityForGroupItem(_item);
+    } else {
+      LOG(1, "Updating visibility of item " << _item);
+      setVisibilityForMoleculeItem( assert_cast<QtMoleculeItem *>(_item) );
+    }
   }
 }
@@ -448,14 +399,9 @@
 void QtMoleculeList::setVisibilityForMoleculeItem(QtMoleculeItem* _item)
 {
-  if (ChangingChildrensVisibility)
-    return;
-
-  boost::recursive_mutex::scoped_lock lock(refill_mutex);
   const bool visible = _item->checkState();
   const moleculeId_t molid = _item->getMoleculeId();
   std::string molecule_formula("illegal");
   {
-    boost::recursive_mutex::scoped_lock lock(map_mutex);
-    MoleculeFormulaMap_t::const_iterator formulaiter =
+    const MoleculeFormulaMap_t::const_iterator formulaiter =
         MoleculeFormulaMap.find(molid);
     ASSERT( formulaiter != MoleculeFormulaMap.end(),
@@ -476,5 +422,4 @@
   // check whether we have to set the group item
 
-  ChangingChildrensVisibility = true;
   if (visible) {
     ++(FormulaVisibilityCountMap[molecule_formula]);
@@ -489,5 +434,4 @@
       visgroupItem->setCheckState(Qt::Unchecked);
   }
-  ChangingChildrensVisibility = false;
 
   emit moleculesVisibilityChanged(_item->getMoleculeId(), visible);
@@ -496,15 +440,9 @@
 void QtMoleculeList::setVisibilityForGroupItem(QStandardItem* _item)
 {
-  if (ChangingChildrensVisibility)
-    return;
-
-  ChangingChildrensVisibility = true;
-
-  boost::recursive_mutex::scoped_lock lock(refill_mutex);
   // go through all children, but don't enter for groupItem once more
   const bool visible = _item->checkState();
   QStandardItem *groupitem = getSpecificGroupItem(_item, QtMoleculeItem::NAME);
   for (int i=0;i<groupitem->rowCount();++i) {
-    QtMoleculeItem *molItem = dynamic_cast<QtMoleculeItem *>(
+    QtMoleculeItem * const molItem = dynamic_cast<QtMoleculeItem *>(
         groupitem->child(i, QtMoleculeItem::VISIBILITY));
     if (molItem->checkState() != visible) {
@@ -524,6 +462,4 @@
       +" have no entry in visibility count map?");
   countiter->second = visible ? groupitem->rowCount() : 0;
-
-  ChangingChildrensVisibility = false;
 }
 
@@ -559,5 +495,4 @@
 void QtMoleculeList::moleculeNameChanged(QStandardItem* item)
 {
-  boost::recursive_mutex::scoped_lock lock(refill_mutex);
   // obtain molecule id
   if ( item->index().column() == QtMoleculeItem::NAME) {
@@ -568,7 +503,6 @@
     const moleculeId_t molid = iter->second;
     // change the name
-    molecule * const mol = World::getInstance().getMolecule(MoleculeById(molid));
     std::string cellValue = item->text().toStdString();
-    if ((mol->getName() != cellValue) && (!cellValue.empty())) {
+    if (!cellValue.empty()) {
       // create actions such that we may undo
       static MoleCuilder::ActionSequence sequence;
@@ -578,14 +512,15 @@
       AQ.registerAction(makroaction);
       AQ.queueAction("change-single-molecule-name", MoleCuilder::Action::NonInteractive);
-    } else if(cellValue=="") {
-      item->setText(QString(mol->getName().c_str()));
+    } else {
+      assert_cast<QtMoleculeItem *>(item)->updateState();
     }
-}
-}
-
+  }
+}
 
 int QtMoleculeList::setOccurrence(QStandardItem * const _groupitem)
 {
-  boost::recursive_mutex::scoped_lock lock(refill_mutex);
+  ASSERT( _groupitem != NULL,
+      "QtMoleculeList::setOccurrence() - group item at "+toString(_groupitem)
+      +" is NULL");
   QModelIndex modelindex = _groupitem->index();
   ASSERT( modelindex.isValid(),
@@ -604,5 +539,4 @@
   if (count == 0) {
     // we have to remove the group item completely
-    boost::recursive_mutex::scoped_lock lock(map_mutex);
     const std::string molecule_formula = _groupitem->text().toStdString();
     FormulaItemBiMap.left.erase(molecule_formula);
@@ -615,7 +549,8 @@
 }
 
-std::string QtMoleculeList::readdItem(QtMoleculeItem *_molitem)
-{
-  boost::recursive_mutex::scoped_lock lock(refill_mutex);
+void QtMoleculeList::moveItem(
+    QtMoleculeItem *_molitem,
+    const std::string &_new_formula)
+{
   // use takeRows of molecule ..
   QStandardItem *groupitem = _molitem->parent();
@@ -626,12 +561,11 @@
   QStandardItem *formulaitem =
       _molitem->parent()->child(_molitem->index().row(), QtMoleculeItem::FORMULA);
-  const std::string molecule_formula = formulaitem->text().toStdString();
   QList<QStandardItem *> mol_row = _molitem->parent()->takeRow(_molitem->index().row());
   // ..  and re-add where new formula fits
-  if (!isGroupItemPresent(molecule_formula)) {
+  if (!isGroupItemPresent(_new_formula)) {
     // add new group item and formula entry
-     addGroupItem(groupitem, molecule_formula);
+     addGroupItem(groupitem, _new_formula);
   } else {
-    groupitem = FormulaToGroupItem(molecule_formula);
+    groupitem = FormulaToGroupItem(_new_formula);
   }
   ASSERT( groupitem != NULL,
@@ -639,179 +573,48 @@
   // finally add again
   groupitem->appendRow(mol_row);
-
-  return molecule_formula;
-}
-
-void QtMoleculeList::updateItemStates()
-{
-  /// copy lists such that new signals for dirty/.. may come in right away
-  // TODO: if we had move semantics ...
-  listAccessing_mutex.lock();
-  list_of_molecule_items_t dirtyMolItems_copy = dirtyMolItems;
-  dirtyMolItems.clear();
-  list_of_molecules_t visibilityMolItems_copy = visibilityMolItems;
-  visibilityMolItems.clear();
-  list_of_group_items_t dirtyGroupItems_copy = dirtyGroupItems;
-  dirtyGroupItems.clear();
-  list_of_group_items_t visibilityGroupItems_copy = visibilityGroupItems;
-  visibilityGroupItems.clear();
-  std::vector<QtObservedMolecule::ptr> newMolecules_copy = newMolecules;
-  newMolecules.clear();
-  std::vector<moleculeId_t> removedMolecules_copy = removedMolecules;
-  removedMolecules.clear();
-  list_of_molecules_t toBeMovedItems_copy = toBeMovedItems;
-  toBeMovedItems.clear();
-  listAccessing_mutex.unlock();
-
-  // wait till initial refill has been executed
-  boost::recursive_mutex::scoped_lock lock(refill_mutex);
-
-//  LOG(1, "Starting update.");
-
-  // remove removedMolecules from other lists.
-  for (std::vector<moleculeId_t>::const_iterator removeiter = removedMolecules_copy.begin();
-      removeiter != removedMolecules_copy.end(); ++removeiter) {
-    for (unsigned int i=0;i< QtMoleculeItem::COLUMNTYPES_MAX; ++i)
-        dirtyMolItems_copy.erase( std::make_pair(*removeiter,(QtMoleculeItem::COLUMNTYPES)i) );
-    toBeMovedItems_copy.erase(*removeiter);
-    visibilityMolItems_copy.erase(*removeiter);
-  }
-
-  /// 1a. do the update for each dirty item
-  for (list_of_molecule_items_t::const_iterator dirtyiter = dirtyMolItems_copy.begin();
-      dirtyiter != dirtyMolItems_copy.end(); ++dirtyiter) {
-    if (!isMoleculeItemPresent(dirtyiter->first))
-      continue;
-    QtMoleculeItem * const mol_item =
-        getSpecificMoleculeItem(
-            MoleculeIdToItem(dirtyiter->first),
-            dirtyiter->second);
-//    LOG(1, "Updating item " << mol_item);
-    mol_item->updateState();
-  }
-
-  /// 1b. do the visibility update for each dirty item
-  for (list_of_molecules_t::const_iterator visiter = visibilityMolItems_copy.begin();
-      visiter != visibilityMolItems_copy.end(); ++visiter) {
-    if (!isMoleculeItemPresent(*visiter))
-      continue;
-    QtMoleculeItem * const visitem =
-      getSpecificMoleculeItem(
-          MoleculeIdToItem(*visiter),
-          QtMoleculeItem::VISIBILITY );
-//    LOG(1, "Updating visibility of item " << visitem);
-    setVisibilityForMoleculeItem(visitem);
-  }
-
-  /// 2. move all items that need to be moved
-  typedef std::set<std::string> formulas_t;
-  formulas_t toBeSetOccurrence;
-  for (list_of_molecules_t::const_iterator moveiter = toBeMovedItems_copy.begin();
-      moveiter != toBeMovedItems_copy.end(); ++moveiter) {
-    boost::recursive_mutex::scoped_lock lock(map_mutex);
-//    LOG(1, "Moving item " << molitem);
-    MoleculeFormulaMap_t::iterator formulaiter =
-        MoleculeFormulaMap.find(*moveiter);
-    ASSERT( formulaiter != MoleculeFormulaMap.end(),
-        "QtMoleculeList::updateItemStates() - formula of molecule "
-        +toString(*moveiter)+" unknown.");
-//    LOG(1, "Adding " << formulaiter->second << " to toBeSetOccurrence.");
-    toBeSetOccurrence.insert( formulaiter->second );
-    if (!isMoleculeItemPresent(*moveiter))
-      continue;
-    QtMoleculeItem *const molitem = MoleculeIdToItem(*moveiter);
-    LOG(1, "Moving item " << molitem);
+}
+
+
+void QtMoleculeList::formulaChanged(const QtObservedMolecule::ptr _mol)
+{
+  // we need the id as identifier to the items
+  const moleculeId_t molid = _mol->getMolIndex();
+  LOG(3, "DEBUG: Moving item to id " << molid);
+  const MoleculeFormulaMap_t::iterator formulaiter =
+      MoleculeFormulaMap.find(molid);
+  ASSERT( formulaiter != MoleculeFormulaMap.end(),
+      "QtMoleculeList::updateItemStates() - formula of molecule "
+      +toString(molid)+" unknown.");
+  // we get old formula from stored map and new formula from the ObservedMolecule
+  const std::string old_formula = formulaiter->second;
+  const std::string new_formula = _mol->getMolFormula();
+
+  // then we move the item if necessary
+  if (old_formula != new_formula) {
+    QtMoleculeItem *const molitem = MoleculeIdToItem(molid);
+    LOG(3, "DEBUG: Moving item " << molitem);
     // remove from formula<->molecule bimap with old formula
-    LOG(1, "Removing " << formulaiter->second << " for " << formulaiter->first << " from MoleculeFormulaMap.");
+    LOG(4, "DEBUG: Removing " << old_formula << " for " << formulaiter->first << " from MoleculeFormulaMap.");
     MoleculeFormulaMap.erase( formulaiter );
-    const std::string formula = readdItem(molitem);
-    // and add to formula<->molecule bimap with updated formula
-    LOG(1, "Adding " << formula << " for " << *moveiter << " to MoleculeFormulaMap.");
-    MoleculeFormulaMap.insert( std::make_pair(*moveiter, formula) );
-//      LOG(1, "Adding " << formula << " to toBeSetOccurrence.");
-    toBeSetOccurrence.insert( formula );
-  }
-
-  /// 3. remove all items whose molecules have been removed
-  for (std::vector<moleculeId_t>::const_iterator removeiter = removedMolecules_copy.begin();
-      removeiter != removedMolecules_copy.end(); ++removeiter) {
-//    LOG(1, "Removing molecule " << *removeiter);
-    if (!isMoleculeItemPresent(*removeiter))
-      continue;
-    QtMoleculeItem *item = MoleculeIdToItem(*removeiter);
-    if (item != NULL) {
-      const std::string formula = item->parent()->text().toStdString();
-//      LOG(1, "Adding " << formula << " to toBeSetOccurrence.");
-      toBeSetOccurrence.insert( formula );
-      removeMoleculeItem(item);
-      KilledItemsPerMolecule.erase( *removeiter );
+    moveItem(molitem, new_formula);
+    // changing occurrences for old_formula with possible removal
+    const int removeindex = setOccurrence( FormulaToGroupItem(old_formula) );
+    if (removeindex != -1) {
+      LOG(3, "DEBUG: Removing row of group item to " << old_formula);
+      removeRows(removeindex, 1, invisibleRootItem()->index());
     }
-  }
-
-  // throw out items that we added by an update() while we are in this function
-  listAccessing_mutex.lock();
-  for (std::vector<moleculeId_t>::const_iterator removeiter = removedMolecules_copy.begin();
-      removeiter != removedMolecules_copy.end(); ++removeiter) {
-    for (unsigned int i=0;i< QtMoleculeItem::COLUMNTYPES_MAX; ++i)
-        dirtyMolItems.erase( std::make_pair(*removeiter,(QtMoleculeItem::COLUMNTYPES)i) );
-    toBeMovedItems.erase(*removeiter);
-    visibilityMolItems.erase(*removeiter);
-  }
-  listAccessing_mutex.unlock();
-  // after that it is not a problem as items have been removed (hence signOff() was called)
-
-  /// 4. instantiate all new items
-  for (std::vector<QtObservedMolecule::ptr>::iterator moliter = newMolecules_copy.begin();
-      moliter != newMolecules_copy.end(); ++moliter) {
-//   LOG(1, "Adding molecule " << ObservedMolecule->getMoleculeName());
-    // check that World knows the molecule still
-    const std::string formula = addMolecule(*moliter);
-//      LOG(1, "Adding " << formula << " to toBeSetOccurrence.");
-    toBeSetOccurrence.insert( formula );
-  }
-
-  /// 5a. update the group item's occurrence and visibility
-  std::set<int> RowsToRemove;
-  for (std::set<std::string>::const_iterator groupiter = toBeSetOccurrence.begin();
-      groupiter != toBeSetOccurrence.end(); ++groupiter) {
-//    LOG(1, "Updating group item's occurence " << *groupiter);
-    QStandardItem *groupitem = FormulaToGroupItem(*groupiter);
-    const int index = setOccurrence(groupitem);
-    if (index != -1) {
-//      LOG(1, "Removing row of group item " << groupitem);
-      RowsToRemove.insert(index);
-    }
-  }
-  toBeSetOccurrence.clear();
-
-  // remove all visibility updates whose row is removed
-  for (list_of_group_items_t::iterator visiter = visibilityGroupItems_copy.begin();
-      visiter != visibilityGroupItems_copy.end(); ) {
-      QStandardItem * const groupitem = FormulaToGroupItem(visiter->first);
-    if (RowsToRemove.count(groupitem->index().row()) != 0) {
-//      LOG(1, "Removing vis item " << *visiter << " because of removed group item.");
-      visibilityGroupItems_copy.erase(visiter++);
-    } else
-      ++visiter;
-  }
-
-  // update visibility of all group items
-  for (list_of_group_items_t::iterator visiter = visibilityGroupItems_copy.begin();
-      visiter != visibilityGroupItems_copy.end(); ++visiter) {
-//    LOG(1, "Updating visibility of item " << *visiter);
-    QStandardItem * const groupitem =
-        getSpecificGroupItem(FormulaToGroupItem(visiter->first),
-        visiter->second);
-    setVisibilityForGroupItem(groupitem);
-  }
-
-  /// 5b. remove all rows with 0 occurrence starting from last
-  for (std::set<int>::reverse_iterator riter = RowsToRemove.rbegin();
-      riter != RowsToRemove.rend(); ++riter) {
-//    LOG(1, "Removing group item at row " << *riter);
-    removeRows(*riter, 1, invisibleRootItem()->index());
-  }
-
-  // and done
-//  LOG(1, "Done with update.");
-}
+    // and add to formula<->molecule bimap with updated new_formula
+    LOG(4, "DEBUG: Adding " << new_formula << " for " << molid << " to MoleculeFormulaMap.");
+    MoleculeFormulaMap.insert( std::make_pair(molid, new_formula) );
+    const int addindex = setOccurrence( FormulaToGroupItem(new_formula) );
+    ASSERT( addindex == -1,
+        "QtMoleculeList::formulaChanged() - add mol to new formula "+
+        toString(new_formula)+" made the row to be removed?");
+  }
+}
+
+void QtMoleculeList::nameChanged(const QtObservedMolecule::ptr _mol)
+{
+  // nothing to do, item updates itself
+  LOG(3, "DEBUG: QtMoleculeList got nameChangd for id " << _mol->getMolIndex());
+}
