| 1 | /*
|
|---|
| 2 | * Project: MoleCuilder
|
|---|
| 3 | * Description: creates and alters molecular systems
|
|---|
| 4 | * Copyright (C) 2010-2012 University of Bonn. All rights reserved.
|
|---|
| 5 | *
|
|---|
| 6 | *
|
|---|
| 7 | * This file is part of MoleCuilder.
|
|---|
| 8 | *
|
|---|
| 9 | * MoleCuilder is free software: you can redistribute it and/or modify
|
|---|
| 10 | * it under the terms of the GNU General Public License as published by
|
|---|
| 11 | * the Free Software Foundation, either version 2 of the License, or
|
|---|
| 12 | * (at your option) any later version.
|
|---|
| 13 | *
|
|---|
| 14 | * MoleCuilder is distributed in the hope that it will be useful,
|
|---|
| 15 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|---|
| 16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|---|
| 17 | * GNU General Public License for more details.
|
|---|
| 18 | *
|
|---|
| 19 | * You should have received a copy of the GNU General Public License
|
|---|
| 20 | * along with MoleCuilder. If not, see <http://www.gnu.org/licenses/>.
|
|---|
| 21 | */
|
|---|
| 22 |
|
|---|
| 23 | /*
|
|---|
| 24 | * QtMoleculeList.cpp
|
|---|
| 25 | *
|
|---|
| 26 | * Created on: Jan 21, 2010
|
|---|
| 27 | * Author: crueger
|
|---|
| 28 | */
|
|---|
| 29 |
|
|---|
| 30 | // include config.h
|
|---|
| 31 | #ifdef HAVE_CONFIG_H
|
|---|
| 32 | #include <config.h>
|
|---|
| 33 | #endif
|
|---|
| 34 |
|
|---|
| 35 | #include "QtMoleculeList.hpp"
|
|---|
| 36 |
|
|---|
| 37 | #include <QModelIndex>
|
|---|
| 38 | #include <QDebug>
|
|---|
| 39 |
|
|---|
| 40 | #include "UIElements/Views/Qt4/MoleculeList/QtMoleculeItem.hpp"
|
|---|
| 41 | #include "UIElements/Views/Qt4/MoleculeList/QtMoleculeItemFactory.hpp"
|
|---|
| 42 |
|
|---|
| 43 | #include <boost/bind.hpp>
|
|---|
| 44 | #include <boost/thread/locks.hpp>
|
|---|
| 45 | #include <iostream>
|
|---|
| 46 |
|
|---|
| 47 | #include "CodePatterns/MemDebug.hpp"
|
|---|
| 48 |
|
|---|
| 49 | #include "CodePatterns/Log.hpp"
|
|---|
| 50 | #include "CodePatterns/Observer/Notification.hpp"
|
|---|
| 51 |
|
|---|
| 52 | #include "Atom/atom.hpp"
|
|---|
| 53 | #include "Descriptors/MoleculeIdDescriptor.hpp"
|
|---|
| 54 | #include "Formula.hpp"
|
|---|
| 55 | #include "molecule.hpp"
|
|---|
| 56 | #include "MoleculeListClass.hpp"
|
|---|
| 57 |
|
|---|
| 58 | using namespace std;
|
|---|
| 59 |
|
|---|
| 60 | const unsigned int QtMoleculeList::update_times_per_second = 20;
|
|---|
| 61 |
|
|---|
| 62 | QtMoleculeList::QtMoleculeList() :
|
|---|
| 63 | Observer("QtMoleculeList"),
|
|---|
| 64 | ChangingChildrensVisibility(false),
|
|---|
| 65 | update_timer(NULL),
|
|---|
| 66 | callback_DirtyItems(boost::bind(&QtMoleculeList::informDirtyState, this, _1, _2, _3))
|
|---|
| 67 | {
|
|---|
| 68 | setColumnCount(QtMoleculeItemFactory::COLUMNCOUNT);
|
|---|
| 69 |
|
|---|
| 70 | World::getInstance().signOn(this, World::MoleculeInserted);
|
|---|
| 71 | World::getInstance().signOn(this, World::MoleculeRemoved);
|
|---|
| 72 |
|
|---|
| 73 | refill();
|
|---|
| 74 |
|
|---|
| 75 | // qRegisterMetaType<QItemSelection>("QItemSelection");
|
|---|
| 76 | //connect(this,SIGNAL(cellChanged(int,int)),this,SLOT(moleculeChanged(int,int)));
|
|---|
| 77 | // connect(selectionModel(),SIGNAL(selectionChanged(QItemSelection, QItemSelection)),this,SLOT(rowsSelected(QItemSelection, QItemSelection)));
|
|---|
| 78 | connect(this, SIGNAL(itemChanged(QStandardItem*)), this, SLOT(checkForVisibilityChange(QStandardItem*)), Qt::DirectConnection);
|
|---|
| 79 | }
|
|---|
| 80 |
|
|---|
| 81 | QtMoleculeList::~QtMoleculeList()
|
|---|
| 82 | {
|
|---|
| 83 | World::getInstance().signOff(this, World::MoleculeInserted);
|
|---|
| 84 | World::getInstance().signOff(this, World::MoleculeRemoved);
|
|---|
| 85 | }
|
|---|
| 86 |
|
|---|
| 87 | QVariant QtMoleculeList::headerData(int section, Qt::Orientation orientation, int role) const
|
|---|
| 88 | {
|
|---|
| 89 | if (role == Qt::DisplayRole) {
|
|---|
| 90 | if (orientation == Qt::Horizontal) {
|
|---|
| 91 | if (section < QtMoleculeItem::COLUMNTYPES_MAX)
|
|---|
| 92 | return QString(QtMoleculeItemFactory::COLUMNNAMES[section]);
|
|---|
| 93 | }
|
|---|
| 94 | }
|
|---|
| 95 | return QVariant();
|
|---|
| 96 | }
|
|---|
| 97 |
|
|---|
| 98 | void QtMoleculeList::update(Observable *publisher) {
|
|---|
| 99 | ASSERT(0,
|
|---|
| 100 | "QtMoleculeList::update() - we did not sign up for any global updates.");
|
|---|
| 101 | }
|
|---|
| 102 |
|
|---|
| 103 | bool QtMoleculeList::isMoleculeItemPresent(const moleculeId_t _molid) const
|
|---|
| 104 | {
|
|---|
| 105 | boost::recursive_mutex::scoped_lock lock(map_mutex);
|
|---|
| 106 | MoleculeItemBiMap_t::left_const_iterator iter =
|
|---|
| 107 | MoleculeItemBiMap.left.find(_molid);
|
|---|
| 108 | return ( iter != MoleculeItemBiMap.left.end());
|
|---|
| 109 | }
|
|---|
| 110 |
|
|---|
| 111 | QtMoleculeItem * QtMoleculeList::MoleculeIdToItem(const moleculeId_t _molid) const
|
|---|
| 112 | {
|
|---|
| 113 | boost::recursive_mutex::scoped_lock lock(map_mutex);
|
|---|
| 114 | MoleculeItemBiMap_t::left_const_iterator iter =
|
|---|
| 115 | MoleculeItemBiMap.left.find(_molid);
|
|---|
| 116 | ASSERT( iter != MoleculeItemBiMap.left.end(),
|
|---|
| 117 | "QtMoleculeList::MoleculeIdToItem() - could not find item to id "
|
|---|
| 118 | +toString(_molid));
|
|---|
| 119 | return iter->second;
|
|---|
| 120 | }
|
|---|
| 121 |
|
|---|
| 122 | const moleculeId_t QtMoleculeList::ItemToMoleculeId(const QtMoleculeItem * const _item) const
|
|---|
| 123 | {
|
|---|
| 124 | boost::recursive_mutex::scoped_lock lock(map_mutex);
|
|---|
| 125 | const MoleculeItemBiMap_t::right_const_iterator iter =
|
|---|
| 126 | MoleculeItemBiMap.right.find(const_cast<QtMoleculeItem * const>(_item));
|
|---|
| 127 | if (iter != MoleculeItemBiMap.right.end())
|
|---|
| 128 | return iter->second;
|
|---|
| 129 | else
|
|---|
| 130 | return -1;
|
|---|
| 131 | }
|
|---|
| 132 |
|
|---|
| 133 | QtMoleculeItem * QtMoleculeList::getSpecificMoleculeItem(
|
|---|
| 134 | const QtMoleculeItem * const _item,
|
|---|
| 135 | const enum QtMoleculeItem::COLUMNTYPES _type) const
|
|---|
| 136 | {
|
|---|
| 137 | QStandardItem *parent_item = _item->parent();
|
|---|
| 138 | ASSERT( parent_item != NULL,
|
|---|
| 139 | "QtMoleculeList::getSpecificMoleculeItem() - parent of molecule item is NULL");
|
|---|
| 140 | return static_cast<QtMoleculeItem *>(parent_item->child(_item->index().row(), _type));
|
|---|
| 141 | }
|
|---|
| 142 |
|
|---|
| 143 | bool QtMoleculeList::isGroupItemPresent(const std::string &_formula) const
|
|---|
| 144 | {
|
|---|
| 145 | boost::recursive_mutex::scoped_lock lock(map_mutex);
|
|---|
| 146 | FormulaTreeItemBiMap_t::left_const_iterator iter =
|
|---|
| 147 | FormulaItemBiMap.left.find(_formula);
|
|---|
| 148 | return ( iter != FormulaItemBiMap.left.end());
|
|---|
| 149 | }
|
|---|
| 150 |
|
|---|
| 151 | QStandardItem * QtMoleculeList::FormulaToGroupItem(const std::string &_formula) const
|
|---|
| 152 | {
|
|---|
| 153 | boost::recursive_mutex::scoped_lock lock(map_mutex);
|
|---|
| 154 | FormulaTreeItemBiMap_t::left_const_iterator iter =
|
|---|
| 155 | FormulaItemBiMap.left.find(_formula);
|
|---|
| 156 | ASSERT( iter != FormulaItemBiMap.left.end(),
|
|---|
| 157 | "QtMoleculeList::FormulaToGroupItem() - could not find item to formula "
|
|---|
| 158 | +toString(_formula));
|
|---|
| 159 | return iter->second;
|
|---|
| 160 | }
|
|---|
| 161 |
|
|---|
| 162 | const std::string& QtMoleculeList::GroupItemToFormula(const QStandardItem * const _item) const
|
|---|
| 163 | {
|
|---|
| 164 | boost::recursive_mutex::scoped_lock lock(map_mutex);
|
|---|
| 165 | static std::string emptystring;
|
|---|
| 166 | const FormulaTreeItemBiMap_t::right_const_iterator iter =
|
|---|
| 167 | FormulaItemBiMap.right.find(const_cast<QStandardItem * const>(_item));
|
|---|
| 168 | if (iter != FormulaItemBiMap.right.end())
|
|---|
| 169 | return iter->second;
|
|---|
| 170 | else
|
|---|
| 171 | return emptystring;
|
|---|
| 172 | }
|
|---|
| 173 |
|
|---|
| 174 | QStandardItem * QtMoleculeList::getSpecificGroupItem(
|
|---|
| 175 | const QStandardItem * const _item,
|
|---|
| 176 | const enum QtMoleculeItem::COLUMNTYPES _type) const
|
|---|
| 177 | {
|
|---|
| 178 | return invisibleRootItem()->child(_item->index().row(), _type);
|
|---|
| 179 | }
|
|---|
| 180 |
|
|---|
| 181 |
|
|---|
| 182 | const moleculeId_t QtMoleculeList::IndexToMoleculeId(const QModelIndex &_index) const
|
|---|
| 183 | {
|
|---|
| 184 | boost::recursive_mutex::scoped_lock lock(refill_mutex);
|
|---|
| 185 | QtMoleculeItem * const item = dynamic_cast<QtMoleculeItem *>(itemFromIndex(_index));
|
|---|
| 186 | if (item == NULL)
|
|---|
| 187 | return -1;
|
|---|
| 188 | else
|
|---|
| 189 | return ItemToMoleculeId(item);
|
|---|
| 190 | }
|
|---|
| 191 |
|
|---|
| 192 | void QtMoleculeList::recieveNotification(Observable *publisher, Notification_ptr notification)
|
|---|
| 193 | {
|
|---|
| 194 | if (dynamic_cast<World *>(publisher) != NULL) {
|
|---|
| 195 | switch (notification->getChannelNo()) {
|
|---|
| 196 | case World::MoleculeInserted:
|
|---|
| 197 | {
|
|---|
| 198 | boost::recursive_mutex::scoped_lock lock(listAccessing_mutex);
|
|---|
| 199 | const moleculeId_t molid = const_cast<const World &>(World::getInstance()).lastChangedMolId();
|
|---|
| 200 | if (molid != (unsigned int )-1)
|
|---|
| 201 | newMolecules.push_back( molid );
|
|---|
| 202 | break;
|
|---|
| 203 | }
|
|---|
| 204 | case World::MoleculeRemoved:
|
|---|
| 205 | {
|
|---|
| 206 | boost::recursive_mutex::scoped_lock lock(listAccessing_mutex);
|
|---|
| 207 | const moleculeId_t molid = const_cast<const World &>(World::getInstance()).lastChangedMolId();
|
|---|
| 208 | if (molid != (unsigned int )-1)
|
|---|
| 209 | removedMolecules.push_back( molid ); // remove in any case, as we also got insert
|
|---|
| 210 | break;
|
|---|
| 211 | }
|
|---|
| 212 | default:
|
|---|
| 213 | ASSERT(0, "QtMoleculeList::recieveNotification() - cannot get here, not subscribed to channel "
|
|---|
| 214 | +toString(notification->getChannelNo()));
|
|---|
| 215 | break;
|
|---|
| 216 | }
|
|---|
| 217 | }
|
|---|
| 218 | }
|
|---|
| 219 |
|
|---|
| 220 | void QtMoleculeList::addGroupItem(
|
|---|
| 221 | QStandardItem *&mainitem,
|
|---|
| 222 | const std::string &_molecule_formula)
|
|---|
| 223 | {
|
|---|
| 224 | QList<QStandardItem *> groupItems =
|
|---|
| 225 | QtMoleculeItemFactory::getInstance().createGroupItems(_molecule_formula);
|
|---|
| 226 | mainitem = groupItems.front();
|
|---|
| 227 | {
|
|---|
| 228 | boost::recursive_mutex::scoped_lock lock(map_mutex);
|
|---|
| 229 | FormulaItemBiMap.left.insert( std::make_pair(_molecule_formula, mainitem) );
|
|---|
| 230 | }
|
|---|
| 231 | invisibleRootItem()->appendRow(groupItems);
|
|---|
| 232 | }
|
|---|
| 233 |
|
|---|
| 234 | void QtMoleculeList::addMoleculeItem(
|
|---|
| 235 | QStandardItem *_groupitem,
|
|---|
| 236 | const moleculeId_t _molid,
|
|---|
| 237 | const std::string &_molecule_formula)
|
|---|
| 238 | {
|
|---|
| 239 | QList<QStandardItem *> molItems =
|
|---|
| 240 | QtMoleculeItemFactory::getInstance().createMoleculeItems(_molid, callback_DirtyItems);
|
|---|
| 241 | QtMoleculeItem *mol_item = dynamic_cast<QtMoleculeItem *>(molItems.front());
|
|---|
| 242 | ASSERT( mol_item != NULL,
|
|---|
| 243 | "QtMoleculeList::addMoleculeItem() - item from factory was not a QtMoleculeItem?");
|
|---|
| 244 | {
|
|---|
| 245 | boost::recursive_mutex::scoped_lock lock(map_mutex);
|
|---|
| 246 | MoleculeItemBiMap.left.insert( std::make_pair(_molid, mol_item) );
|
|---|
| 247 | LOG(1, "Adding" << _molecule_formula << " for " << _molid << " to MoleculeFormulaMap.");
|
|---|
| 248 | MoleculeFormulaMap.insert( std::make_pair( _molid, _molecule_formula) );
|
|---|
| 249 | }
|
|---|
| 250 | // LOG(1, "Inserting molecule " << _mol->getId() << ": " << _mol);
|
|---|
| 251 | _groupitem->appendRow(molItems);
|
|---|
| 252 | }
|
|---|
| 253 |
|
|---|
| 254 | std::string QtMoleculeList::addMolecule(const molecule * const _mol)
|
|---|
| 255 | {
|
|---|
| 256 | // find group if already in list
|
|---|
| 257 | QStandardItem *groupItem = NULL;
|
|---|
| 258 |
|
|---|
| 259 | const std::string molecule_formula = _mol->getFormula().toString();
|
|---|
| 260 |
|
|---|
| 261 | // new molecule type -> create new group
|
|---|
| 262 | if (!isGroupItemPresent(molecule_formula)){
|
|---|
| 263 | // insert new formula entry into visibility
|
|---|
| 264 | #ifndef NDEBUG
|
|---|
| 265 | std::pair< FormulaVisibilityCountMap_t::iterator, bool> visibilityinserter =
|
|---|
| 266 | #endif
|
|---|
| 267 | FormulaVisibilityCountMap.insert(
|
|---|
| 268 | std::make_pair( molecule_formula, (unsigned int)0) );
|
|---|
| 269 | ASSERT( visibilityinserter.second,
|
|---|
| 270 | "QtMoleculeList::refill() - molecule with formula "
|
|---|
| 271 | +molecule_formula+" already in FormulaVisibilityCountMap.");
|
|---|
| 272 |
|
|---|
| 273 | // create item and place into Map with formula as key
|
|---|
| 274 | addGroupItem(groupItem, molecule_formula);
|
|---|
| 275 | } else {
|
|---|
| 276 | groupItem = FormulaToGroupItem(molecule_formula);
|
|---|
| 277 | }
|
|---|
| 278 | ASSERT( groupItem != NULL,
|
|---|
| 279 | "QtMoleculeList::addMolecule() - item with id "+toString(_mol->getId())
|
|---|
| 280 | +" has no parent?");
|
|---|
| 281 |
|
|---|
| 282 | // add molecule
|
|---|
| 283 | addMoleculeItem(groupItem, _mol->getId(), molecule_formula);
|
|---|
| 284 |
|
|---|
| 285 | return molecule_formula;
|
|---|
| 286 | }
|
|---|
| 287 |
|
|---|
| 288 | void QtMoleculeList::removeMoleculeItem(QtMoleculeItem * const _item)
|
|---|
| 289 | {
|
|---|
| 290 | boost::recursive_mutex::scoped_lock lock(refill_mutex);
|
|---|
| 291 | const QModelIndex mol_index = indexFromItem(_item);
|
|---|
| 292 | QStandardItem *groupitem = _item->parent();
|
|---|
| 293 | const QModelIndex group_index = groupitem->index();
|
|---|
| 294 | {
|
|---|
| 295 | boost::recursive_mutex::scoped_lock lock(map_mutex);
|
|---|
| 296 | MoleculeItemBiMap_t::right_iterator removeiter =
|
|---|
| 297 | MoleculeItemBiMap.right.find(_item);
|
|---|
| 298 | ASSERT( removeiter != MoleculeItemBiMap.right.end(),
|
|---|
| 299 | "QtMoleculeList::removeMoleculeItem() - could not find item in MoleculeBiMap.");
|
|---|
| 300 | // LOG(1, "Erasing molecule " << (removeiter->second));
|
|---|
| 301 | {
|
|---|
| 302 | MoleculeFormulaMap_t::iterator removeformulaiter =
|
|---|
| 303 | MoleculeFormulaMap.find(removeiter->second);
|
|---|
| 304 | ASSERT( removeformulaiter != MoleculeFormulaMap.end(),
|
|---|
| 305 | "QtMoleculeList::removeMoleculeItem() - could not find id "
|
|---|
| 306 | +toString(removeiter->second)+" in MoleculeFormulaMap.");
|
|---|
| 307 | LOG(1, "Removing " << removeformulaiter->second << " for "
|
|---|
| 308 | << removeformulaiter->first << " from MoleculeFormulaMap.");
|
|---|
| 309 | MoleculeFormulaMap.erase( removeformulaiter );
|
|---|
| 310 | }
|
|---|
| 311 | MoleculeItemBiMap.right.erase(removeiter);
|
|---|
| 312 | }
|
|---|
| 313 | removeRows(mol_index.row(), 1, group_index);
|
|---|
| 314 | }
|
|---|
| 315 |
|
|---|
| 316 | void QtMoleculeList::refill()
|
|---|
| 317 | {
|
|---|
| 318 | // check timer's presence
|
|---|
| 319 | if (update_timer == NULL) {
|
|---|
| 320 | update_timer = new QTimer(this);
|
|---|
| 321 | connect( update_timer, SIGNAL(timeout()), this, SLOT(checkState()));
|
|---|
| 322 | } else
|
|---|
| 323 | update_timer->stop();
|
|---|
| 324 |
|
|---|
| 325 | {
|
|---|
| 326 | boost::recursive_mutex::scoped_lock refill_lock(refill_mutex);
|
|---|
| 327 | boost::recursive_mutex::scoped_lock listAccessing_lock(listAccessing_mutex);
|
|---|
| 328 |
|
|---|
| 329 | // LOG(1, "Clearing list.");
|
|---|
| 330 |
|
|---|
| 331 | clear();
|
|---|
| 332 | FormulaVisibilityCountMap.clear();
|
|---|
| 333 | {
|
|---|
| 334 | boost::recursive_mutex::scoped_lock lock(map_mutex);
|
|---|
| 335 | FormulaItemBiMap.clear();
|
|---|
| 336 | MoleculeFormulaMap.clear();
|
|---|
| 337 | MoleculeItemBiMap.clear();
|
|---|
| 338 | }
|
|---|
| 339 | dirtyMolItems.clear();
|
|---|
| 340 | visibilityMolItems.clear();
|
|---|
| 341 | visibilityGroupItems.clear();
|
|---|
| 342 | newMolecules.clear();
|
|---|
| 343 | removedMolecules.clear();
|
|---|
| 344 | toBeMovedItems.clear();
|
|---|
| 345 | }
|
|---|
| 346 |
|
|---|
| 347 | const std::vector<const molecule*> &molecules =
|
|---|
| 348 | const_cast<const World &>(World::getInstance()).getAllMolecules();
|
|---|
| 349 | for (std::vector<const molecule*>::const_iterator iter = molecules.begin();
|
|---|
| 350 | iter != molecules.end();
|
|---|
| 351 | iter++)
|
|---|
| 352 | addMolecule(*iter);
|
|---|
| 353 |
|
|---|
| 354 | // activate timer
|
|---|
| 355 | update_timer->start(1000/update_times_per_second);
|
|---|
| 356 | }
|
|---|
| 357 |
|
|---|
| 358 | bool QtMoleculeList::areAnyItemsDirty()
|
|---|
| 359 | {
|
|---|
| 360 | // get whether any items are dirty
|
|---|
| 361 | boost::recursive_mutex::scoped_lock lock(listAccessing_mutex);
|
|---|
| 362 | bool dirty = false;
|
|---|
| 363 | dirty |= !dirtyMolItems.empty();
|
|---|
| 364 | dirty |= !visibilityMolItems.empty();
|
|---|
| 365 | dirty |= !dirtyGroupItems.empty();
|
|---|
| 366 | dirty |= !visibilityGroupItems.empty();
|
|---|
| 367 | dirty |= !newMolecules.empty();
|
|---|
| 368 | dirty |= !removedMolecules.empty();
|
|---|
| 369 | dirty |= !toBeMovedItems.empty();
|
|---|
| 370 | return dirty;
|
|---|
| 371 | }
|
|---|
| 372 |
|
|---|
| 373 | void QtMoleculeList::checkState()
|
|---|
| 374 | {
|
|---|
| 375 | const bool dirty = areAnyItemsDirty();
|
|---|
| 376 | // update if required
|
|---|
| 377 | if (dirty)
|
|---|
| 378 | updateItemStates();
|
|---|
| 379 | }
|
|---|
| 380 |
|
|---|
| 381 | void QtMoleculeList::subjectKilled(Observable *publisher)
|
|---|
| 382 | {}
|
|---|
| 383 |
|
|---|
| 384 | void QtMoleculeList::checkForVisibilityChange(QStandardItem* _item)
|
|---|
| 385 | {
|
|---|
| 386 | // qDebug() << "Item changed called.";
|
|---|
| 387 |
|
|---|
| 388 | boost::recursive_mutex::scoped_lock lock(refill_mutex);
|
|---|
| 389 | if (_item->index().column() == QtMoleculeItem::VISIBILITY) {
|
|---|
| 390 | // qDebug() << "visibilityItem changed: " << (_item->checkState() ? "checked" : "unchecked");
|
|---|
| 391 | boost::recursive_mutex::scoped_lock lock(listAccessing_mutex);
|
|---|
| 392 | if ((_item->parent() == NULL) || (_item->parent() == invisibleRootItem()))
|
|---|
| 393 | visibilityGroupItems.insert( std::make_pair(
|
|---|
| 394 | GroupItemToFormula(_item->parent()), QtMoleculeItem::VISIBILITY) );
|
|---|
| 395 | else
|
|---|
| 396 | visibilityMolItems.insert(
|
|---|
| 397 | static_cast<QtMoleculeItem *>(_item)->getMoleculeId()
|
|---|
| 398 | );
|
|---|
| 399 | }
|
|---|
| 400 | }
|
|---|
| 401 |
|
|---|
| 402 | void QtMoleculeList::setVisibilityForMoleculeItem(QtMoleculeItem* _item)
|
|---|
| 403 | {
|
|---|
| 404 | if (ChangingChildrensVisibility)
|
|---|
| 405 | return;
|
|---|
| 406 |
|
|---|
| 407 | boost::recursive_mutex::scoped_lock lock(refill_mutex);
|
|---|
| 408 | const bool visible = _item->checkState();
|
|---|
| 409 | const moleculeId_t molid = _item->getMoleculeId();
|
|---|
| 410 | std::string molecule_formula("illegal");
|
|---|
| 411 | {
|
|---|
| 412 | boost::recursive_mutex::scoped_lock lock(map_mutex);
|
|---|
| 413 | MoleculeFormulaMap_t::const_iterator formulaiter =
|
|---|
| 414 | MoleculeFormulaMap.find(molid);
|
|---|
| 415 | ASSERT( formulaiter != MoleculeFormulaMap.end(),
|
|---|
| 416 | "QtMoleculeList::setVisibilityForMoleculeItem() - formula of molecule "
|
|---|
| 417 | +toString(molid)+" unknown.");
|
|---|
| 418 | molecule_formula = formulaiter->second;
|
|---|
| 419 | }
|
|---|
| 420 | ASSERT( FormulaVisibilityCountMap.count(molecule_formula) != 0,
|
|---|
| 421 | "QtMoleculeList::setVisibilityForMoleculeItem() - molecule with formula " +molecule_formula
|
|---|
| 422 | +" is not present in FormulaVisibilityCountMap.");
|
|---|
| 423 |
|
|---|
| 424 | // get parent
|
|---|
| 425 | QStandardItem *groupItem = _item->parent();
|
|---|
| 426 | QStandardItem *visgroupItem = getSpecificGroupItem(groupItem, QtMoleculeItem::VISIBILITY);
|
|---|
| 427 | ASSERT( groupItem != NULL,
|
|---|
| 428 | "QtMoleculeList::setVisibilityForMoleculeItem() - item with id "
|
|---|
| 429 | +toString(_item->getMoleculeId())+" has not parent?");
|
|---|
| 430 | // check whether we have to set the group item
|
|---|
| 431 |
|
|---|
| 432 | ChangingChildrensVisibility = true;
|
|---|
| 433 | if (visible) {
|
|---|
| 434 | ++(FormulaVisibilityCountMap[molecule_formula]);
|
|---|
| 435 | // compare with occurence/total number of molecules
|
|---|
| 436 | if (FormulaVisibilityCountMap[molecule_formula] ==
|
|---|
| 437 | (unsigned int)(groupItem->rowCount()))
|
|---|
| 438 | visgroupItem->setCheckState(Qt::Checked);
|
|---|
| 439 | } else {
|
|---|
| 440 | --(FormulaVisibilityCountMap[molecule_formula]);
|
|---|
| 441 | // none selected anymore?
|
|---|
| 442 | if (FormulaVisibilityCountMap[molecule_formula] == 0)
|
|---|
| 443 | visgroupItem->setCheckState(Qt::Unchecked);
|
|---|
| 444 | }
|
|---|
| 445 | ChangingChildrensVisibility = false;
|
|---|
| 446 |
|
|---|
| 447 | emit moleculesVisibilityChanged(_item->getMolecule()->getId(), visible);
|
|---|
| 448 | }
|
|---|
| 449 |
|
|---|
| 450 | void QtMoleculeList::setVisibilityForGroupItem(QStandardItem* _item)
|
|---|
| 451 | {
|
|---|
| 452 | if (ChangingChildrensVisibility)
|
|---|
| 453 | return;
|
|---|
| 454 |
|
|---|
| 455 | ChangingChildrensVisibility = true;
|
|---|
| 456 |
|
|---|
| 457 | boost::recursive_mutex::scoped_lock lock(refill_mutex);
|
|---|
| 458 | // go through all children, but don't enter for groupItem once more
|
|---|
| 459 | const bool visible = _item->checkState();
|
|---|
| 460 | QStandardItem *groupitem = getSpecificGroupItem(_item, QtMoleculeItem::NAME);
|
|---|
| 461 | for (int i=0;i<groupitem->rowCount();++i) {
|
|---|
| 462 | QtMoleculeItem *molItem = dynamic_cast<QtMoleculeItem *>(
|
|---|
| 463 | groupitem->child(i, QtMoleculeItem::VISIBILITY));
|
|---|
| 464 | if (molItem->checkState() != visible) {
|
|---|
| 465 | molItem->setCheckState(visible ? Qt::Checked : Qt::Unchecked);
|
|---|
| 466 |
|
|---|
| 467 | // emit signal
|
|---|
| 468 | emit moleculesVisibilityChanged(molItem->getMolecule()->getId(), visible);
|
|---|
| 469 | }
|
|---|
| 470 | }
|
|---|
| 471 | // set current number of visible children
|
|---|
| 472 | const std::string molecule_formula =
|
|---|
| 473 | GroupItemToFormula( getSpecificGroupItem(_item, QtMoleculeItem::NAME) );
|
|---|
| 474 | FormulaVisibilityCountMap_t::iterator countiter =
|
|---|
| 475 | FormulaVisibilityCountMap.find(molecule_formula);
|
|---|
| 476 | ASSERT( countiter != FormulaVisibilityCountMap.end(),
|
|---|
| 477 | "QtMoleculeList::setVisibilityForGroupItem() - molecules "+molecule_formula
|
|---|
| 478 | +" have no entry in visibility count map?");
|
|---|
| 479 | countiter->second = visible ? groupitem->rowCount() : 0;
|
|---|
| 480 |
|
|---|
| 481 | ChangingChildrensVisibility = false;
|
|---|
| 482 | }
|
|---|
| 483 |
|
|---|
| 484 |
|
|---|
| 485 | void QtMoleculeList::moleculeChanged() {
|
|---|
| 486 | /*int idx = verticalHeaderItem(row)->data(Qt::UserRole).toInt();
|
|---|
| 487 | molecule *mol = molecules->ReturnIndex(idx);
|
|---|
| 488 | string cellValue = item(row,QtMoleculeItem::NAME)->text().toStdString();
|
|---|
| 489 | if(mol->getName() != cellValue && cellValue !="") {
|
|---|
| 490 | mol->setName(cellValue);
|
|---|
| 491 | }
|
|---|
| 492 | else if(cellValue==""){
|
|---|
| 493 | item(row,QtMoleculeItem::NAME)->setText(QString(mol->getName().c_str()));
|
|---|
| 494 | }*/
|
|---|
| 495 | }
|
|---|
| 496 |
|
|---|
| 497 |
|
|---|
| 498 | int QtMoleculeList::setOccurrence(QStandardItem * const _groupitem)
|
|---|
| 499 | {
|
|---|
| 500 | boost::recursive_mutex::scoped_lock lock(refill_mutex);
|
|---|
| 501 | QModelIndex modelindex = _groupitem->index();
|
|---|
| 502 | ASSERT( modelindex.isValid(),
|
|---|
| 503 | "QtMoleculeList::setOccurrence() - groupitem not associated to model anymore.");
|
|---|
| 504 | const int index = modelindex.row();
|
|---|
| 505 | QStandardItem *parent_item =
|
|---|
| 506 | _groupitem->parent() == NULL ? invisibleRootItem() : _groupitem->parent();
|
|---|
| 507 | ASSERT( parent_item != NULL,
|
|---|
| 508 | "QtMoleculeList::setOccurrence() - group item at "+toString(index)
|
|---|
| 509 | +" does not have a parent?");
|
|---|
| 510 | QStandardItem *occ_item = parent_item->child(index, QtMoleculeItem::OCCURRENCE);
|
|---|
| 511 | ASSERT( occ_item != NULL,
|
|---|
| 512 | "QtMoleculeList::setOccurrence() - group item at "+toString(index)
|
|---|
| 513 | +" does not have an occurrence?");
|
|---|
| 514 | const int count = _groupitem->rowCount();
|
|---|
| 515 | if (count == 0) {
|
|---|
| 516 | // we have to remove the group item completely
|
|---|
| 517 | boost::recursive_mutex::scoped_lock lock(map_mutex);
|
|---|
| 518 | const std::string molecule_formula = _groupitem->text().toStdString();
|
|---|
| 519 | FormulaItemBiMap.left.erase(molecule_formula);
|
|---|
| 520 | FormulaVisibilityCountMap.erase(molecule_formula);
|
|---|
| 521 | return index;
|
|---|
| 522 | } else {
|
|---|
| 523 | occ_item->setText(QString::number(count));
|
|---|
| 524 | return -1;
|
|---|
| 525 | }
|
|---|
| 526 | }
|
|---|
| 527 |
|
|---|
| 528 | std::string QtMoleculeList::readdItem(QtMoleculeItem *_molitem)
|
|---|
| 529 | {
|
|---|
| 530 | boost::recursive_mutex::scoped_lock lock(refill_mutex);
|
|---|
| 531 | // use takeRows of molecule ..
|
|---|
| 532 | QStandardItem *groupitem = _molitem->parent();
|
|---|
| 533 | ASSERT( groupitem != NULL,
|
|---|
| 534 | "QtMoleculeList::readdItem() - mol item at "+toString(_molitem->index().row())
|
|---|
| 535 | +" does not have a groupitem?");
|
|---|
| 536 | const molecule * const mol = _molitem->getMolecule();
|
|---|
| 537 | QList<QStandardItem *> mol_row = _molitem->parent()->takeRow(_molitem->index().row());
|
|---|
| 538 | // .. and re-add where new formula fits
|
|---|
| 539 | std::string molecule_formula;
|
|---|
| 540 | if (mol != NULL) {
|
|---|
| 541 | molecule_formula = mol->getFormula().toString();
|
|---|
| 542 | if (!isGroupItemPresent(molecule_formula)) {
|
|---|
| 543 | // add new group item and formula entry
|
|---|
| 544 | addGroupItem(groupitem, molecule_formula);
|
|---|
| 545 | } else {
|
|---|
| 546 | groupitem = FormulaToGroupItem(molecule_formula);
|
|---|
| 547 | }
|
|---|
| 548 | ASSERT( groupitem != NULL,
|
|---|
| 549 | "QtMoleculeList::readdItem() - failed to create a sensible new groupitem");
|
|---|
| 550 | // finally add again
|
|---|
| 551 | groupitem->appendRow(mol_row);
|
|---|
| 552 | } else {
|
|---|
| 553 | for (QList<QStandardItem *>::iterator iter = mol_row.begin();
|
|---|
| 554 | iter != mol_row.end(); ++iter)
|
|---|
| 555 | delete *iter;
|
|---|
| 556 | }
|
|---|
| 557 |
|
|---|
| 558 | return molecule_formula;
|
|---|
| 559 | }
|
|---|
| 560 |
|
|---|
| 561 | void QtMoleculeList::informDirtyState(
|
|---|
| 562 | const moleculeId_t _id,
|
|---|
| 563 | const QtMoleculeItem::COLUMNTYPES _type,
|
|---|
| 564 | const QtMoleculeItem::MoveTypes _movetype)
|
|---|
| 565 | {
|
|---|
| 566 | listAccessing_mutex.lock();
|
|---|
| 567 | dirtyMolItems.insert( std::make_pair(_id, _type) );
|
|---|
| 568 | listAccessing_mutex.unlock();
|
|---|
| 569 |
|
|---|
| 570 | if (_movetype == QtMoleculeItem::NeedsMove) {
|
|---|
| 571 | // we have to convert whatever item raised the dirty signal to the first
|
|---|
| 572 | // item in the row as otherwise multiple items in the row are selected
|
|---|
| 573 | // as to be moved, i.e. the same row is moved multiple times
|
|---|
| 574 | listAccessing_mutex.lock();
|
|---|
| 575 | toBeMovedItems.insert(_id);
|
|---|
| 576 | listAccessing_mutex.unlock();
|
|---|
| 577 | }
|
|---|
| 578 | }
|
|---|
| 579 |
|
|---|
| 580 | void QtMoleculeList::updateItemStates()
|
|---|
| 581 | {
|
|---|
| 582 | /// copy lists such that new signals for dirty/.. may come in right away
|
|---|
| 583 | // TODO: if we had move semantics ...
|
|---|
| 584 | listAccessing_mutex.lock();
|
|---|
| 585 | list_of_molecule_items_t dirtyMolItems_copy = dirtyMolItems;
|
|---|
| 586 | dirtyMolItems.clear();
|
|---|
| 587 | list_of_molecules_t visibilityMolItems_copy = visibilityMolItems;
|
|---|
| 588 | visibilityMolItems.clear();
|
|---|
| 589 | list_of_group_items_t dirtyGroupItems_copy = dirtyGroupItems;
|
|---|
| 590 | dirtyGroupItems.clear();
|
|---|
| 591 | list_of_group_items_t visibilityGroupItems_copy = visibilityGroupItems;
|
|---|
| 592 | visibilityGroupItems.clear();
|
|---|
| 593 | std::vector<moleculeId_t> newMolecules_copy = newMolecules;
|
|---|
| 594 | newMolecules.clear();
|
|---|
| 595 | std::vector<moleculeId_t> removedMolecules_copy = removedMolecules;
|
|---|
| 596 | removedMolecules.clear();
|
|---|
| 597 | list_of_molecules_t toBeMovedItems_copy = toBeMovedItems;
|
|---|
| 598 | toBeMovedItems.clear();
|
|---|
| 599 | listAccessing_mutex.unlock();
|
|---|
| 600 |
|
|---|
| 601 | /// first check consistency among the sets:
|
|---|
| 602 | /// -# if we remove an item, we don't have to update it before anymore
|
|---|
| 603 | /// -# if we remove an item, we don't have to move it before anymore
|
|---|
| 604 | /// -# if we remove an item, we don't have to change its visibility
|
|---|
| 605 | /// -# don't add molecule that are also removed
|
|---|
| 606 |
|
|---|
| 607 | // remove molecules added and removed immediately in both lists
|
|---|
| 608 | // note that newMolecules are all those where a moleculeInserted callback
|
|---|
| 609 | // has been received but not action has been taken (i.e. it is not contained
|
|---|
| 610 | // in any other list so far), toBeRemoved is inserted on moleculeRemoved
|
|---|
| 611 | // and other lists (toBeSetOccurrenceItems) are only filled if the molecule
|
|---|
| 612 | // item has already been instantiated.
|
|---|
| 613 | {
|
|---|
| 614 | std::vector<moleculeId_t> addedremoved;
|
|---|
| 615 | std::sort(newMolecules_copy.begin(), newMolecules_copy.end());
|
|---|
| 616 | std::sort(removedMolecules_copy.begin(), removedMolecules_copy.end());
|
|---|
| 617 | std::set_intersection(
|
|---|
| 618 | newMolecules_copy.begin(), newMolecules_copy.end(),
|
|---|
| 619 | removedMolecules_copy.begin(), removedMolecules_copy.end(),
|
|---|
| 620 | std::back_inserter(addedremoved));
|
|---|
| 621 | {
|
|---|
| 622 | std::vector<moleculeId_t>::iterator removeiter = std::set_difference(
|
|---|
| 623 | newMolecules_copy.begin(), newMolecules_copy.end(),
|
|---|
| 624 | addedremoved.begin(), addedremoved.end(),
|
|---|
| 625 | newMolecules_copy.begin());
|
|---|
| 626 | newMolecules_copy.erase(removeiter, newMolecules_copy.end());
|
|---|
| 627 | }
|
|---|
| 628 | {
|
|---|
| 629 | std::vector<moleculeId_t>::iterator removeiter = std::set_difference(
|
|---|
| 630 | removedMolecules_copy.begin(), removedMolecules_copy.end(),
|
|---|
| 631 | addedremoved.begin(), addedremoved.end(),
|
|---|
| 632 | removedMolecules_copy.begin());
|
|---|
| 633 | removedMolecules_copy.erase(removeiter, removedMolecules_copy.end());
|
|---|
| 634 | }
|
|---|
| 635 | }
|
|---|
| 636 |
|
|---|
| 637 | // wait till initial refill has been executed
|
|---|
| 638 | boost::recursive_mutex::scoped_lock lock(refill_mutex);
|
|---|
| 639 |
|
|---|
| 640 | // LOG(1, "Starting update.");
|
|---|
| 641 |
|
|---|
| 642 | // remove removedMolecules from other lists.
|
|---|
| 643 | for (std::vector<moleculeId_t>::const_iterator removeiter = removedMolecules_copy.begin();
|
|---|
| 644 | removeiter != removedMolecules_copy.end(); ++removeiter) {
|
|---|
| 645 | for (unsigned int i=0;i< QtMoleculeItem::COLUMNTYPES_MAX; ++i)
|
|---|
| 646 | dirtyMolItems_copy.erase( std::make_pair(*removeiter,(QtMoleculeItem::COLUMNTYPES)i) );
|
|---|
| 647 | toBeMovedItems_copy.erase(*removeiter);
|
|---|
| 648 | visibilityMolItems_copy.erase(*removeiter);
|
|---|
| 649 | }
|
|---|
| 650 |
|
|---|
| 651 | /// 1a. do the update for each dirty item
|
|---|
| 652 | for (list_of_molecule_items_t::const_iterator dirtyiter = dirtyMolItems_copy.begin();
|
|---|
| 653 | dirtyiter != dirtyMolItems_copy.end(); ++dirtyiter) {
|
|---|
| 654 | if (!isMoleculeItemPresent(dirtyiter->first))
|
|---|
| 655 | continue;
|
|---|
| 656 | QtMoleculeItem * const mol_item =
|
|---|
| 657 | getSpecificMoleculeItem(
|
|---|
| 658 | MoleculeIdToItem(dirtyiter->first),
|
|---|
| 659 | dirtyiter->second);
|
|---|
| 660 | // LOG(1, "Updating item " << mol_item);
|
|---|
| 661 | mol_item->updateState();
|
|---|
| 662 | }
|
|---|
| 663 |
|
|---|
| 664 | /// 1b. do the visibility update for each dirty item
|
|---|
| 665 | for (list_of_molecules_t::const_iterator visiter = visibilityMolItems_copy.begin();
|
|---|
| 666 | visiter != visibilityMolItems_copy.end(); ++visiter) {
|
|---|
| 667 | if (!isMoleculeItemPresent(*visiter))
|
|---|
| 668 | continue;
|
|---|
| 669 | QtMoleculeItem * const visitem =
|
|---|
| 670 | getSpecificMoleculeItem(
|
|---|
| 671 | MoleculeIdToItem(*visiter),
|
|---|
| 672 | QtMoleculeItem::VISIBILITY );
|
|---|
| 673 | // LOG(1, "Updating visibility of item " << visitem);
|
|---|
| 674 | setVisibilityForMoleculeItem(visitem);
|
|---|
| 675 | }
|
|---|
| 676 |
|
|---|
| 677 | /// 2. move all items that need to be moved
|
|---|
| 678 | typedef std::set<std::string> formulas_t;
|
|---|
| 679 | formulas_t toBeSetOccurrence;
|
|---|
| 680 | for (list_of_molecules_t::const_iterator moveiter = toBeMovedItems_copy.begin();
|
|---|
| 681 | moveiter != toBeMovedItems_copy.end(); ++moveiter) {
|
|---|
| 682 | boost::recursive_mutex::scoped_lock lock(map_mutex);
|
|---|
| 683 | // LOG(1, "Moving item " << molitem);
|
|---|
| 684 | MoleculeFormulaMap_t::iterator formulaiter =
|
|---|
| 685 | MoleculeFormulaMap.find(*moveiter);
|
|---|
| 686 | ASSERT( formulaiter != MoleculeFormulaMap.end(),
|
|---|
| 687 | "QtMoleculeList::updateItemStates() - formula of molecule "
|
|---|
| 688 | +toString(*moveiter)+" unknown.");
|
|---|
| 689 | // LOG(1, "Adding " << formulaiter->second << " to toBeSetOccurrence.");
|
|---|
| 690 | toBeSetOccurrence.insert( formulaiter->second );
|
|---|
| 691 | if (!isMoleculeItemPresent(*moveiter))
|
|---|
| 692 | continue;
|
|---|
| 693 | QtMoleculeItem *const molitem = MoleculeIdToItem(*moveiter);
|
|---|
| 694 | LOG(1, "Moving item " << molitem);
|
|---|
| 695 | const molecule *mol = molitem->getMolecule();
|
|---|
| 696 | if (mol == NULL) {
|
|---|
| 697 | // removeMolecule will remove also from formula<->molecule bimap
|
|---|
| 698 | removeMoleculeItem(molitem);
|
|---|
| 699 | } else {
|
|---|
| 700 | // remove from formula<->molecule bimap with old formula
|
|---|
| 701 | LOG(1, "Removing " << formulaiter->second << " for " << formulaiter->first << " from MoleculeFormulaMap.");
|
|---|
| 702 | MoleculeFormulaMap.erase( formulaiter );
|
|---|
| 703 | const std::string formula = readdItem(molitem);
|
|---|
| 704 | // and add to formula<->molecule bimap with updated formula
|
|---|
| 705 | LOG(1, "Adding " << formula << " for " << *moveiter << " to MoleculeFormulaMap.");
|
|---|
| 706 | MoleculeFormulaMap.insert( std::make_pair(*moveiter, formula) );
|
|---|
| 707 | // LOG(1, "Adding " << formula << " to toBeSetOccurrence.");
|
|---|
| 708 | toBeSetOccurrence.insert( formula );
|
|---|
| 709 | }
|
|---|
| 710 | }
|
|---|
| 711 |
|
|---|
| 712 | // throw out items that we added by an update() while we are in this function
|
|---|
| 713 | listAccessing_mutex.lock();
|
|---|
| 714 | for (std::vector<moleculeId_t>::const_iterator removeiter = removedMolecules_copy.begin();
|
|---|
| 715 | removeiter != removedMolecules_copy.end(); ++removeiter) {
|
|---|
| 716 | for (unsigned int i=0;i< QtMoleculeItem::COLUMNTYPES_MAX; ++i)
|
|---|
| 717 | dirtyMolItems.erase( std::make_pair(*removeiter,(QtMoleculeItem::COLUMNTYPES)i) );
|
|---|
| 718 | toBeMovedItems.erase(*removeiter);
|
|---|
| 719 | visibilityMolItems.erase(*removeiter);
|
|---|
| 720 | }
|
|---|
| 721 | listAccessing_mutex.unlock();
|
|---|
| 722 | // after that it is not a problem as items have been removed (hence signOff() was called)
|
|---|
| 723 |
|
|---|
| 724 | /// 3. remove all items whose molecules have been removed
|
|---|
| 725 | for (std::vector<moleculeId_t>::const_iterator removeiter = removedMolecules_copy.begin();
|
|---|
| 726 | removeiter != removedMolecules_copy.end(); ++removeiter) {
|
|---|
| 727 | // LOG(1, "Removing molecule " << *removeiter);
|
|---|
| 728 | if (!isMoleculeItemPresent(*removeiter))
|
|---|
| 729 | continue;
|
|---|
| 730 | QtMoleculeItem *item = MoleculeIdToItem(*removeiter);
|
|---|
| 731 | if (item != NULL) {
|
|---|
| 732 | const std::string formula = item->parent()->text().toStdString();
|
|---|
| 733 | // LOG(1, "Adding " << formula << " to toBeSetOccurrence.");
|
|---|
| 734 | toBeSetOccurrence.insert( formula );
|
|---|
| 735 | removeMoleculeItem(item);
|
|---|
| 736 | }
|
|---|
| 737 | }
|
|---|
| 738 |
|
|---|
| 739 | /// 4. instantiate all new items
|
|---|
| 740 | for (std::vector<moleculeId_t>::const_iterator moliter = newMolecules_copy.begin();
|
|---|
| 741 | moliter != newMolecules_copy.end(); ++moliter) {
|
|---|
| 742 | // LOG(1, "Adding molecule " << *moliter);
|
|---|
| 743 | // check that World knows the molecule still
|
|---|
| 744 | const molecule * const mol = const_cast<const World &>(World::getInstance()).
|
|---|
| 745 | getMolecule(MoleculeById(*moliter));
|
|---|
| 746 | if ((mol != NULL) && (mol->getId() == *moliter)) {
|
|---|
| 747 | const std::string formula = addMolecule(mol);;
|
|---|
| 748 | // LOG(1, "Adding " << formula << " to toBeSetOccurrence.");
|
|---|
| 749 | toBeSetOccurrence.insert( formula );
|
|---|
| 750 | } else {
|
|---|
| 751 | ELOG(2, "Molecule " << *moliter
|
|---|
| 752 | << " disappeared before we could render it in QtMoleculeList.");
|
|---|
| 753 | }
|
|---|
| 754 | }
|
|---|
| 755 |
|
|---|
| 756 | /// 5a. update the group item's occurrence and visibility
|
|---|
| 757 | std::set<int> RowsToRemove;
|
|---|
| 758 | for (std::set<std::string>::const_iterator groupiter = toBeSetOccurrence.begin();
|
|---|
| 759 | groupiter != toBeSetOccurrence.end(); ++groupiter) {
|
|---|
| 760 | // LOG(1, "Updating group item's occurence " << *groupiter);
|
|---|
| 761 | QStandardItem *groupitem = FormulaToGroupItem(*groupiter);
|
|---|
| 762 | const int index = setOccurrence(groupitem);
|
|---|
| 763 | if (index != -1) {
|
|---|
| 764 | // LOG(1, "Removing row of group item " << groupitem);
|
|---|
| 765 | RowsToRemove.insert(index);
|
|---|
| 766 | }
|
|---|
| 767 | }
|
|---|
| 768 | toBeSetOccurrence.clear();
|
|---|
| 769 |
|
|---|
| 770 | // remove all visibility updates whose row is removed
|
|---|
| 771 | for (list_of_group_items_t::iterator visiter = visibilityGroupItems_copy.begin();
|
|---|
| 772 | visiter != visibilityGroupItems_copy.end(); ) {
|
|---|
| 773 | QStandardItem * const groupitem = FormulaToGroupItem(visiter->first);
|
|---|
| 774 | if (RowsToRemove.count(groupitem->index().row()) != 0) {
|
|---|
| 775 | // LOG(1, "Removing vis item " << *visiter << " because of removed group item.");
|
|---|
| 776 | visibilityGroupItems_copy.erase(visiter++);
|
|---|
| 777 | } else
|
|---|
| 778 | ++visiter;
|
|---|
| 779 | }
|
|---|
| 780 |
|
|---|
| 781 | // update visibility of all group items
|
|---|
| 782 | for (list_of_group_items_t::iterator visiter = visibilityGroupItems_copy.begin();
|
|---|
| 783 | visiter != visibilityGroupItems_copy.end(); ++visiter) {
|
|---|
| 784 | // LOG(1, "Updating visibility of item " << *visiter);
|
|---|
| 785 | QStandardItem * const groupitem =
|
|---|
| 786 | getSpecificGroupItem(FormulaToGroupItem(visiter->first),
|
|---|
| 787 | visiter->second);
|
|---|
| 788 | setVisibilityForGroupItem(groupitem);
|
|---|
| 789 | }
|
|---|
| 790 |
|
|---|
| 791 | /// 5b. remove all rows with 0 occurrence starting from last
|
|---|
| 792 | for (std::set<int>::reverse_iterator riter = RowsToRemove.rbegin();
|
|---|
| 793 | riter != RowsToRemove.rend(); ++riter) {
|
|---|
| 794 | // LOG(1, "Removing group item at row " << *riter);
|
|---|
| 795 | removeRows(*riter, 1, invisibleRootItem()->index());
|
|---|
| 796 | }
|
|---|
| 797 |
|
|---|
| 798 | // and done
|
|---|
| 799 | // LOG(1, "Done with update.");
|
|---|
| 800 | }
|
|---|