Changeset 3054f4a for src/UIElements
- Timestamp:
- Apr 20, 2016, 8:51:51 AM (9 years ago)
- Branches:
- Action_Thermostats, Add_AtomRandomPerturbation, Add_FitFragmentPartialChargesAction, Add_RotateAroundBondAction, Add_SelectAtomByNameAction, Added_ParseSaveFragmentResults, AddingActions_SaveParseParticleParameters, Adding_Graph_to_ChangeBondActions, Adding_MD_integration_tests, Adding_ParticleName_to_Atom, Adding_StructOpt_integration_tests, AtomFragments, Automaking_mpqc_open, AutomationFragmentation_failures, Candidate_v1.5.4, Candidate_v1.6.0, Candidate_v1.6.1, ChangeBugEmailaddress, ChangingTestPorts, ChemicalSpaceEvaluator, CombiningParticlePotentialParsing, Combining_Subpackages, Debian_Package_split, Debian_package_split_molecuildergui_only, Disabling_MemDebug, Docu_Python_wait, EmpiricalPotential_contain_HomologyGraph, EmpiricalPotential_contain_HomologyGraph_documentation, Enable_parallel_make_install, Enhance_userguide, Enhanced_StructuralOptimization, Enhanced_StructuralOptimization_continued, Example_ManyWaysToTranslateAtom, Exclude_Hydrogens_annealWithBondGraph, FitPartialCharges_GlobalError, Fix_BoundInBox_CenterInBox_MoleculeActions, Fix_ChargeSampling_PBC, Fix_ChronosMutex, Fix_FitPartialCharges, Fix_FitPotential_needs_atomicnumbers, Fix_ForceAnnealing, Fix_IndependentFragmentGrids, Fix_ParseParticles, Fix_ParseParticles_split_forward_backward_Actions, Fix_PopActions, Fix_QtFragmentList_sorted_selection, Fix_Restrictedkeyset_FragmentMolecule, Fix_StatusMsg, Fix_StepWorldTime_single_argument, Fix_Verbose_Codepatterns, Fix_fitting_potentials, Fixes, ForceAnnealing_goodresults, ForceAnnealing_oldresults, ForceAnnealing_tocheck, ForceAnnealing_with_BondGraph, ForceAnnealing_with_BondGraph_continued, ForceAnnealing_with_BondGraph_continued_betteresults, ForceAnnealing_with_BondGraph_contraction-expansion, FragmentAction_writes_AtomFragments, FragmentMolecule_checks_bonddegrees, GeometryObjects, Gui_Fixes, Gui_displays_atomic_force_velocity, ImplicitCharges, IndependentFragmentGrids, IndependentFragmentGrids_IndividualZeroInstances, IndependentFragmentGrids_IntegrationTest, IndependentFragmentGrids_Sole_NN_Calculation, JobMarket_RobustOnKillsSegFaults, JobMarket_StableWorkerPool, JobMarket_unresolvable_hostname_fix, MoreRobust_FragmentAutomation, ODR_violation_mpqc_open, PartialCharges_OrthogonalSummation, PdbParser_setsAtomName, PythonUI_with_named_parameters, QtGui_reactivate_TimeChanged_changes, Recreated_GuiChecks, Rewrite_FitPartialCharges, RotateToPrincipalAxisSystem_UndoRedo, SaturateAtoms_findBestMatching, SaturateAtoms_singleDegree, StoppableMakroAction, Subpackage_CodePatterns, Subpackage_JobMarket, Subpackage_LinearAlgebra, Subpackage_levmar, Subpackage_mpqc_open, Subpackage_vmg, Switchable_LogView, ThirdParty_MPQC_rebuilt_buildsystem, TrajectoryDependenant_MaxOrder, TremoloParser_IncreasedPrecision, TremoloParser_MultipleTimesteps, TremoloParser_setsAtomName, Ubuntu_1604_changes, stable
- Children:
- 0a558d
- Parents:
- 1a58ce
- git-author:
- Frederik Heber <heber@…> (03/21/16 21:13:43)
- git-committer:
- Frederik Heber <heber@…> (04/20/16 08:51:51)
- Location:
- src/UIElements
- Files:
-
- 15 edited
Legend:
- Unmodified
- Added
- Removed
-
src/UIElements/Qt4/InstanceBoard/QtObservedInstanceBoard.cpp
r1a58ce r3054f4a 276 276 } 277 277 278 QtObservedAtom::ptr QtObservedInstanceBoard::getObservedAtom(ObservedValue_Index_t _id) 279 { 280 return atomObservedValues.get(_id); 281 } 282 278 283 QtObservedMolecule::ptr QtObservedInstanceBoard::getObservedMolecule(const moleculeId_t _id) 279 284 { 280 285 return moleculeObservedValues.get(moleculeids_lookup.left.at(_id)); 286 } 287 288 QtObservedMolecule::ptr QtObservedInstanceBoard::getObservedMolecule(ObservedValue_Index_t _id) 289 { 290 return moleculeObservedValues.get(_id); 281 291 } 282 292 -
src/UIElements/Qt4/InstanceBoard/QtObservedInstanceBoard.hpp
r1a58ce r3054f4a 84 84 85 85 QtObservedAtom::ptr getObservedAtom(const atomId_t _id); 86 QtObservedAtom::ptr getObservedAtom(ObservedValue_Index_t _id); 86 87 QtObservedMolecule::ptr getObservedMolecule(const moleculeId_t _id); 88 QtObservedMolecule::ptr getObservedMolecule(ObservedValue_Index_t _id); 87 89 void markObservedAtomAsConnected(ObservedValue_Index_t _id); 88 90 void markObservedAtomAsDisconnected(ObservedValue_Index_t _id); -
src/UIElements/Views/Qt4/ElementList/QtElementList.cpp
r1a58ce r3054f4a 104 104 connect(&atomobserver, SIGNAL(AtomInserted(const QtObservedAtom::ptr)), 105 105 this, SLOT(addAtomElement(const QtObservedAtom::ptr))); 106 connect(&atomobserver, SIGNAL(AtomRemoved( const atomId_t)),107 this, SLOT(removeAtomElement( const atomId_t)));106 connect(&atomobserver, SIGNAL(AtomRemoved(ObservedValue_Index_t)), 107 this, SLOT(removeAtomElement(ObservedValue_Index_t))); 108 108 connect(this,SIGNAL(itemSelectionChanged()),this,SLOT(rowSelected())); 109 109 // connect(this,SIGNAL(changed()),this,SLOT(update())); … … 120 120 const atomicNumber_t newelement = _atom->getAtomElement(); 121 121 atomicNumber_t oldelement = -1; 122 const atomId_t atomid = _atom->getAtomIndex();122 const ObservedValue_Index_t atomid = _atom->getIndex(); 123 123 QTreeWidgetItem *newtreeItem = topLevelItem(newelement-1); 124 124 ASSERT( newtreeItem != NULL, … … 168 168 } 169 169 170 void QtElementList::removeAtomElement( const atomId_t _atomid)170 void QtElementList::removeAtomElement(ObservedValue_Index_t _id) 171 171 { 172 172 boost::recursive_mutex::scoped_lock lock(refill_mutex); 173 173 174 const AtomElementMap_t::iterator iter = AtomElementMap.find(_ atomid);174 const AtomElementMap_t::iterator iter = AtomElementMap.find(_id); 175 175 ASSERT (iter != AtomElementMap.end(), 176 "QtElementList::addAtomElement() - atom #"+toString(_ atomid)176 "QtElementList::addAtomElement() - atom #"+toString(_id) 177 177 +" is not present in elementlookup map."); 178 178 if (iter != AtomElementMap.end()) { -
src/UIElements/Views/Qt4/ElementList/QtElementList.hpp
r1a58ce r3054f4a 46 46 void changeElement(const QtObservedAtom::ptr _atom); 47 47 void addAtomElement(const QtObservedAtom::ptr _atom); 48 void removeAtomElement( const atomId_t _atom);48 void removeAtomElement(ObservedValue_Index_t _id); 49 49 50 50 private: 51 51 std::vector<bool> elementSelection; //!< needed to determine when a selection changes 52 typedef std::map< const atomId_t, atomicNumber_t> AtomElementMap_t;52 typedef std::map<ObservedValue_Index_t, atomicNumber_t> AtomElementMap_t; 53 53 AtomElementMap_t AtomElementMap; 54 54 bool dirty; -
src/UIElements/Views/Qt4/ElementList/QtObservedAtomObserver.cpp
r1a58ce r3054f4a 47 47 connect(_board, SIGNAL(atomInserted(QtObservedAtom::ptr)), 48 48 this, SLOT(atomInserted(QtObservedAtom::ptr))); 49 connect(_board, SIGNAL(atomRemoved( const atomId_t)),50 this, SLOT(atomRemoved( const atomId_t)));49 connect(_board, SIGNAL(atomRemoved(ObservedValue_Index_t)), 50 this, SLOT(atomRemoved(ObservedValue_Index_t))); 51 51 } 52 52 … … 63 63 } 64 64 65 void QtObservedAtomObserver::atomRemoved( const atomId_t _atomid)65 void QtObservedAtomObserver::atomRemoved(ObservedValue_Index_t _index) 66 66 { 67 const QtObservedAtom::ptr walker = board->getObservedAtom(_ atomid);67 const QtObservedAtom::ptr walker = board->getObservedAtom(_index); 68 68 disconnect( walker.get(), SIGNAL(elementChanged()), this, SLOT(elementChanged())); 69 emit AtomRemoved(_ atomid);69 emit AtomRemoved(_index); 70 70 } 71 71 -
src/UIElements/Views/Qt4/ElementList/QtObservedAtomObserver.hpp
r1a58ce r3054f4a 44 44 // relayed signals 45 45 void AtomInserted(const QtObservedAtom::ptr _atom); 46 void AtomRemoved( const atomId_t _atomid);46 void AtomRemoved(ObservedValue_Index_t _index); 47 47 48 48 private slots: … … 51 51 52 52 void atomInserted(const QtObservedAtom::ptr _atom); 53 void atomRemoved( const atomId_t _atomid);53 void atomRemoved(ObservedValue_Index_t _index); 54 54 55 55 private: -
src/UIElements/Views/Qt4/MoleculeList/QtMoleculeItem.hpp
r1a58ce r3054f4a 60 60 * \return id of the observed molecule 61 61 */ 62 virtual const moleculeId_t getMoleculeId() const63 { return -1; }62 virtual ObservedValue_Index_t getMoleculeIndex() const 63 { return NULL; } 64 64 }; 65 65 -
src/UIElements/Views/Qt4/MoleculeList/QtMoleculeList.cpp
r1a58ce r3054f4a 81 81 connect(&observer, SIGNAL(MoleculeInserted(QtObservedMolecule::ptr)), 82 82 this, SLOT(moleculeInserted(QtObservedMolecule::ptr))); 83 connect(&observer, SIGNAL(MoleculeRemoved( const moleculeId_t)),84 this, SLOT(moleculeRemoved( const moleculeId_t)));83 connect(&observer, SIGNAL(MoleculeRemoved(ObservedValue_Index_t)), 84 this, SLOT(moleculeRemoved(ObservedValue_Index_t))); 85 85 connect(&observer, SIGNAL(FormulaChanged(const QtObservedMolecule::ptr)), 86 86 this, SLOT(formulaChanged(const QtObservedMolecule::ptr))); … … 89 89 connect(&observer, SIGNAL(AtomCountChanged(const QtObservedMolecule::ptr)), 90 90 this, SLOT(atomcountChanged(const QtObservedMolecule::ptr))); 91 connect(board, SIGNAL(moleculeIndexChanged(const moleculeId_t,const moleculeId_t)),92 this, SLOT(moleculeIndexChanged(const moleculeId_t, const moleculeId_t)));93 91 } 94 92 … … 116 114 } 117 115 118 void QtMoleculeList::moleculeRemoved( const moleculeId_t _id)116 void QtMoleculeList::moleculeRemoved(ObservedValue_Index_t _id) 119 117 { 120 118 LOG(1, "Removing molecule " << _id); … … 136 134 } 137 135 138 template<class T> 139 void exchangeKeys( 140 T &_container, 141 const moleculeId_t _oldid, 142 const moleculeId_t _newid) 143 { 144 typename T::iterator iter = _container.find(_oldid); 145 ASSERT(_container.find(_newid) == _container.end(), 146 "exchangeKeys() - new id "+toString(_newid) 147 +" already exists in container."); 148 _container.insert( std::make_pair(_newid, iter->second) ); 149 _container.erase(iter); 150 } 151 152 template<class T> 153 void exchangeKeysInSet( 154 T &_container, 155 const moleculeId_t _oldid, 156 const moleculeId_t _newid) 157 { 158 typename T::iterator iter = _container.find(_oldid); 159 ASSERT(_container.find(_newid) == _container.end(), 160 "exchangeKeys() - new id "+toString(_newid) 161 +" already exists in container."); 162 _container.insert( _newid ); 163 _container.erase(iter); 164 } 165 166 template<class T> 167 void exchangeKeysOverAllColumns( 168 T &_container, 169 const moleculeId_t _oldid, 170 const moleculeId_t _newid) 171 { 172 for (int i=0;i<QtMoleculeItem::COLUMNTYPES_MAX;++i) { 173 typename T::iterator iter = 174 _container.find( std::make_pair(_oldid, (enum QtMoleculeItem::COLUMNTYPES)i) ); 175 if (iter == _container.end()) 176 continue; 177 ASSERT(_container.find( std::make_pair(_newid,(enum QtMoleculeItem::COLUMNTYPES)i) ) == _container.end(), 178 "exchangeKeys() - new id "+toString(_newid) 179 +" already exists in container."); 180 _container.insert( std::make_pair(_newid, (enum QtMoleculeItem::COLUMNTYPES)i) ); 181 _container.erase(iter); 182 } 183 } 184 185 void QtMoleculeList::moleculeIndexChanged( 186 const moleculeId_t _oldid, 187 const moleculeId_t _newid) 188 { 189 // go through all list and change keys 190 exchangeKeys(MoleculeFormulaMap, _oldid, _newid); 191 { 192 MoleculeItemBiMap_t::left_iterator iter = MoleculeItemBiMap.left.find(_oldid); 193 ASSERT(MoleculeItemBiMap.left.count(_newid), 194 "QtMoleculeList::moleculeIndexChanged() - new id "+toString(_newid) 195 +" already exists in MoleculeItemBiMap."); 196 MoleculeItemBiMap.left.insert( std::make_pair(_newid, iter->second) ); 197 MoleculeItemBiMap.left.erase(iter); 198 } 199 } 200 201 bool QtMoleculeList::isMoleculeItemPresent(const moleculeId_t _molid) const 136 bool QtMoleculeList::isMoleculeItemPresent(ObservedValue_Index_t _molid) const 202 137 { 203 138 MoleculeItemBiMap_t::left_const_iterator iter = … … 206 141 } 207 142 208 QtMoleculeItem * QtMoleculeList::MoleculeIdToItem( const moleculeId_t _molid) const143 QtMoleculeItem * QtMoleculeList::MoleculeIdToItem(ObservedValue_Index_t _molid) const 209 144 { 210 145 MoleculeItemBiMap_t::left_const_iterator iter = … … 212 147 ASSERT( iter != MoleculeItemBiMap.left.end(), 213 148 "QtMoleculeList::MoleculeIdToItem() - could not find item to id " 214 +toString( _molid));149 +toString(observer.getIdtoIndex(_molid))); 215 150 return iter->second; 216 151 } 217 152 218 const moleculeId_t QtMoleculeList::ItemToMoleculeId(const QtMoleculeItem * const _item) const153 ObservedValue_Index_t QtMoleculeList::ItemToMoleculeId(const QtMoleculeItem * const _item) const 219 154 { 220 155 const MoleculeItemBiMap_t::right_const_iterator iter = … … 223 158 return iter->second; 224 159 else 225 return -1;160 return NULL; 226 161 } 227 162 … … 271 206 } 272 207 273 const QModelIndex QtMoleculeList::MoleculeIdToIndex( const moleculeId_t _id) const208 const QModelIndex QtMoleculeList::MoleculeIdToIndex(ObservedValue_Index_t _id) const 274 209 { 275 210 QtMoleculeItem * const item = MoleculeIdToItem(_id); 276 211 ASSERT(item != NULL, 277 212 "QtMoleculeList::MoleculeIdToIndex() - could not find item to " 278 +toString( _id));213 +toString(observer.getIdtoIndex(_id))); 279 214 return indexFromItem(item); 280 215 } 281 216 282 const moleculeId_t QtMoleculeList::IndexToMoleculeId(const QModelIndex &_index) const217 ObservedValue_Index_t QtMoleculeList::IndexToMoleculeId(const QModelIndex &_index) const 283 218 { 284 219 QtMoleculeItem * const item = dynamic_cast<QtMoleculeItem *>(itemFromIndex(_index)); 285 220 if (item == NULL) 286 return -1;221 return NULL; 287 222 else 288 223 return ItemToMoleculeId(item); … … 311 246 ASSERT( mol_item != NULL, 312 247 "QtMoleculeList::createMoleculeItems() - item from factory was not a QtMoleculeItem?"); 313 MoleculeItemBiMap.left.insert( std::make_pair(_ObservedMolecule->get MolIndex(), mol_item) );248 MoleculeItemBiMap.left.insert( std::make_pair(_ObservedMolecule->getIndex(), mol_item) ); 314 249 315 250 QStandardItem *formulaitem = molItems.at(QtMoleculeItem::FORMULA); … … 320 255 LOG(1, "Adding " << _molecule_formula << " for " 321 256 << _ObservedMolecule->getMolIndex() << " to MoleculeFormulaMap."); 322 MoleculeFormulaMap.insert( std::make_pair( _ObservedMolecule->get MolIndex(), _molecule_formula) );257 MoleculeFormulaMap.insert( std::make_pair( _ObservedMolecule->getIndex(), _molecule_formula) ); 323 258 // LOG(1, "Inserting molecule " << _molid << ": " << _molecule_formula); 324 259 return molItems; … … 375 310 ASSERT( removeformulaiter != MoleculeFormulaMap.end(), 376 311 "QtMoleculeList::removeMoleculeItem() - could not find id " 377 +toString( removeiter->second)+" in MoleculeFormulaMap.");312 +toString(observer.getIdtoIndex(removeiter->second))+" in MoleculeFormulaMap."); 378 313 LOG(1, "Removing " << removeformulaiter->second << " for " 379 314 << removeformulaiter->first << " from MoleculeFormulaMap."); … … 404 339 { 405 340 const bool visible = _item->checkState(); 406 const moleculeId_t molid = _item->getMoleculeId();341 const ObservedValue_Index_t molid = _item->getMoleculeIndex(); 407 342 std::string molecule_formula("illegal"); 408 343 { … … 411 346 ASSERT( formulaiter != MoleculeFormulaMap.end(), 412 347 "QtMoleculeList::setVisibilityForMoleculeItem() - formula of molecule " 413 +toString( molid)+" unknown.");348 +toString(observer.getIdtoIndex(molid))+" unknown."); 414 349 molecule_formula = formulaiter->second; 415 350 } … … 422 357 QStandardItem *visgroupItem = getSpecificGroupItem(groupItem, QtMoleculeItem::VISIBILITY); 423 358 ASSERT( groupItem != NULL, 424 "QtMoleculeList::setVisibilityForMoleculeItem() - item with id"425 +toString( _item->getMoleculeId())+" has not parent?");359 "QtMoleculeList::setVisibilityForMoleculeItem() - item to " 360 +toString(observer.getIdtoIndex(molid))+" has not parent?"); 426 361 // check whether we have to set the group item 427 362 … … 439 374 } 440 375 441 emit moleculesVisibilityChanged( _item->getMoleculeId(), visible);376 emit moleculesVisibilityChanged(molid, visible); 442 377 } 443 378 … … 454 389 455 390 // emit signal 456 emit moleculesVisibilityChanged(molItem->getMoleculeI d(), visible);391 emit moleculesVisibilityChanged(molItem->getMoleculeIndex(), visible); 457 392 } 458 393 } … … 505 440 ASSERT( iter != MoleculeItemBiMap.right.end(), 506 441 "QtMoleculeList::moleculeChanged() - name of unknown molecule changed."); 507 const moleculeId_t molid = iter->second; 442 const ObservedValue_Index_t index = iter->second; 443 const moleculeId_t molid = board->getMoleculeIdToIndex(index); 508 444 // change the name 509 445 std::string cellValue = item->text().toStdString(); … … 517 453 AQ.queueAction("change-single-molecule-name", MoleCuilder::Action::NonInteractive); 518 454 } else { 519 board->getObservedMolecule( 520 assert_cast<QtMoleculeItem *>(item)->getMoleculeId()); 455 const QtObservedMolecule::ptr mol = board->getObservedMolecule(index); 456 if (mol) { 457 QtMoleculeItem * const molitem = assert_cast<QtMoleculeItem *>(item); 458 molitem->updateState(mol); 459 } 521 460 } 522 461 } … … 578 517 { 579 518 // we need the id as identifier to the item 580 const moleculeId_t molid = _mol->getMolIndex();519 const ObservedValue_Index_t molid = _mol->getIndex(); 581 520 LOG(3, "DEBUG: QtMoleculeList got formulaChanged for id " << molid); 582 521 QtMoleculeItem *const molitem = MoleculeIdToItem(molid); … … 589 528 } 590 529 591 LOG(3, "DEBUG: Moving item to id " << molid);530 LOG(3, "DEBUG: Moving item to id " << observer.getIdtoIndex(molid)); 592 531 const MoleculeFormulaMap_t::iterator formulaiter = 593 532 MoleculeFormulaMap.find(molid); 594 533 ASSERT( formulaiter != MoleculeFormulaMap.end(), 595 534 "QtMoleculeList::updateItemStates() - formula of molecule " 596 +toString( molid)+" unknown.");535 +toString(observer.getIdtoIndex(molid))+" unknown."); 597 536 // we get old formula from stored map and new formula from the ObservedMolecule 598 537 const std::string old_formula = formulaiter->second; … … 625 564 { 626 565 // we need the id as identifier to the items 627 const moleculeId_t molid = _mol->getMolIndex();566 const ObservedValue_Index_t molid = _mol->getIndex(); 628 567 LOG(3, "DEBUG: QtMoleculeList got atomcountChanged for id " << molid); 629 568 QtMoleculeItem *const molitem = MoleculeIdToItem(molid); … … 638 577 { 639 578 // we need the id as identifier to the items 640 const moleculeId_t molid = _mol->getMolIndex();579 const ObservedValue_Index_t molid = _mol->getIndex(); 641 580 LOG(3, "DEBUG: QtMoleculeList got nameChanged for id " << molid); 642 581 QtMoleculeItem *const molitem = MoleculeIdToItem(molid); -
src/UIElements/Views/Qt4/MoleculeList/QtMoleculeList.hpp
r1a58ce r3054f4a 56 56 57 57 signals: 58 void moleculesVisibilityChanged( const moleculeId_t, bool);58 void moleculesVisibilityChanged(ObservedValue_Index_t, bool); 59 59 60 60 private slots: 61 61 void moleculeInserted(QtObservedMolecule::ptr _mol); 62 void moleculeRemoved(const moleculeId_t _id); 63 void moleculeIndexChanged(const moleculeId_t _oldid, const moleculeId_t _newid); 62 void moleculeRemoved(ObservedValue_Index_t _id); 64 63 65 64 private: 66 65 friend class QtMoleculeListView; 67 66 68 bool isMoleculeItemPresent( const moleculeId_t _molid) const;69 QtMoleculeItem * MoleculeIdToItem( const moleculeId_t _molid) const;70 const moleculeId_t ItemToMoleculeId(const QtMoleculeItem * const _item) const;71 const QModelIndex MoleculeIdToIndex( const moleculeId_t _id) const;72 const moleculeId_t IndexToMoleculeId(const QModelIndex &_index) const;67 bool isMoleculeItemPresent(ObservedValue_Index_t _id) const; 68 QtMoleculeItem * MoleculeIdToItem(ObservedValue_Index_t _id) const; 69 ObservedValue_Index_t ItemToMoleculeId(const QtMoleculeItem * const _item) const; 70 const QModelIndex MoleculeIdToIndex(ObservedValue_Index_t _id) const; 71 ObservedValue_Index_t IndexToMoleculeId(const QModelIndex &_index) const; 73 72 QtMoleculeItem * getSpecificMoleculeItem( 74 73 const QtMoleculeItem * const _item, … … 107 106 FormulaTreeItemBiMap_t FormulaItemBiMap; 108 107 109 typedef std::map< moleculeId_t, std::string> MoleculeFormulaMap_t;108 typedef std::map<ObservedValue_Index_t, std::string> MoleculeFormulaMap_t; 110 109 //!> map of (unique) formulas in the world 111 110 MoleculeFormulaMap_t MoleculeFormulaMap; 112 111 113 typedef boost::bimap< moleculeId_t, QtMoleculeItem*> MoleculeItemBiMap_t;112 typedef boost::bimap<ObservedValue_Index_t, QtMoleculeItem*> MoleculeItemBiMap_t; 114 113 MoleculeItemBiMap_t MoleculeItemBiMap; 115 116 typedef std::set< moleculeId_t > list_of_molecules_t;117 typedef std::set< std::pair<moleculeId_t, QtMoleculeItem::COLUMNTYPES> > list_of_molecule_items_t;118 typedef std::set< std::pair<std::string, QtMoleculeItem::COLUMNTYPES> > list_of_group_items_t;119 114 120 115 //!> listens to all QtObservedMolecule and relays important events to us -
src/UIElements/Views/Qt4/MoleculeList/QtMoleculeListView.cpp
r1a58ce r3054f4a 42 42 #include "CodePatterns/MemDebug.hpp" 43 43 44 #include "CodePatterns/Observer/Notification.hpp"45 46 44 #include "Actions/SelectionAction/Molecules/MoleculeByIdAction.hpp" 47 45 #include "Actions/SelectionAction/Molecules/NotMoleculeByIdAction.hpp" 48 #include "MoleculeObserver.hpp"49 46 #include "molecule.hpp" 50 47 #include "World.hpp" … … 52 49 QtMoleculeListView::QtMoleculeListView(QWidget * _parent) : 53 50 QTreeView(_parent), 54 Observer("QtMoleculeListView"),55 51 selecting(false) 56 52 { … … 58 54 59 55 qRegisterMetaType<QItemSelection>("QItemSelection"); 60 61 MoleculeObserver::getInstance().signOn(this, molecule::SelectionChanged);62 56 } 63 57 64 58 QtMoleculeListView::~QtMoleculeListView() 65 59 { 66 MoleculeObserver::getInstance().signOff(this, molecule::SelectionChanged);67 60 } 68 61 … … 74 67 selectionModel(), SIGNAL(selectionChanged(const QItemSelection &, const QItemSelection &)), 75 68 this, SLOT(rowsSelected(const QItemSelection &, const QItemSelection &)), Qt::DirectConnection); 76 } 77 78 void QtMoleculeListView::update(Observable *publisher) 79 {}69 70 connect(&_moleculelist->observer, SIGNAL(SelectionChanged(QtObservedMolecule::ptr)), 71 this, SLOT(selectionChanged(QtObservedMolecule::ptr))); 72 } 80 73 81 74 QModelIndex QtMoleculeListView::setIndexToLastColumn(const QModelIndex &_index) const … … 110 103 foreach (index, items) 111 104 if ((index.column() == 0) && (selectionModel()->isSelected(index))) { 112 const moleculeId_t mol_id = moleculelist->IndexToMoleculeId(index); 105 const moleculeId_t mol_id = moleculelist->observer.getIdtoIndex( 106 moleculelist->IndexToMoleculeId(index)); 113 107 const molecule * const mol = const_cast<const World &>(World::getInstance()). 114 108 getMolecule(MoleculeById(mol_id)); … … 134 128 foreach (index, items) 135 129 if ((index.column() == 0) && (!selectionModel()->isSelected(index))) { 136 const moleculeId_t mol_id = moleculelist->IndexToMoleculeId(index); 130 const moleculeId_t mol_id = moleculelist->observer.getIdtoIndex( 131 moleculelist->IndexToMoleculeId(index)); 137 132 const molecule * const mol = const_cast<const World &>(World::getInstance()). 138 133 getMolecule(MoleculeById(mol_id)); … … 154 149 } 155 150 156 void QtMoleculeListView::MoleculeSelected(const moleculeId_t _id) 151 void QtMoleculeListView::selectionChanged(const QtObservedMolecule::ptr _molecule) 152 { 153 if (_molecule->getMolSelected()) 154 MoleculeSelected(_molecule->getIndex()); 155 else 156 MoleculeUnselected(_molecule->getIndex()); 157 } 158 159 void QtMoleculeListView::MoleculeSelected(ObservedValue_Index_t _id) 157 160 { 158 161 if (selecting) … … 166 169 // ASSERT( !selectionModel()->isSelected(index), 167 170 // "QtMoleculeListView::MoleculeSelected() - row to molecule " 168 // +toString( _id)+" is already selected.");171 // +toString(mol->getMolIndex())+" is already selected."); 169 172 170 173 // select the full row … … 176 179 } 177 180 178 void QtMoleculeListView::MoleculeUnselected( const moleculeId_t _id)181 void QtMoleculeListView::MoleculeUnselected(ObservedValue_Index_t _id) 179 182 { 180 183 if (selecting) … … 188 191 // ASSERT( selectionModel()->isSelected(index), 189 192 // "QtMoleculeListView::MoleculeSelected() - row to molecule " 190 // +toString( _id)+" is already unselected.");193 // +toString(mol->getMolIndex())+" is already unselected."); 191 194 192 195 // unselect the full row … … 197 200 selecting = false; 198 201 } 199 200 201 void QtMoleculeListView::recieveNotification(Observable *publisher, Notification_ptr notification)202 {203 if (dynamic_cast<World *>(publisher) != NULL) {204 switch (notification->getChannelNo()) {205 case World::SelectionChanged:206 {207 // obtain molecule selection from World and go through our selection step by step208 const std::vector<const molecule *> selectedMolecules =209 const_cast<const World &>(World::getInstance()).getSelectedMolecules();210 QItemSelection currently_selected = selectionModel()->selection();211 QtMoleculeList *moleculelist = static_cast<QtMoleculeList *>(model());212 QItemSelection selected;213 QItemSelection deselected;214 std::set<QModelIndex> already_selected_indices;215 for (std::vector<const molecule *>::const_iterator iter = selectedMolecules.begin();216 iter != selectedMolecules.end(); ++iter) {217 if (moleculelist->isMoleculeItemPresent((*iter)->getId())) {218 QtMoleculeItem *item = moleculelist->MoleculeIdToItem((*iter)->getId());219 QModelIndex mol_index = item->index();220 if (!currently_selected.contains(mol_index))221 selected.select(mol_index, setIndexToLastColumn(mol_index));222 else223 already_selected_indices.insert(mol_index);224 }225 }226 {227 QModelIndex mol_index;228 foreach(mol_index, currently_selected.indexes()) {229 std::set<QModelIndex>::const_iterator iter =230 already_selected_indices.find(mol_index);231 if (iter == already_selected_indices.end())232 deselected.select(mol_index, setIndexToLastColumn(mol_index));233 }234 }235 selecting = true;236 if (!selected.indexes().empty())237 selectionModel()->select(selected, QItemSelectionModel::Select);238 if (!deselected.indexes().empty())239 selectionModel()->select(deselected, QItemSelectionModel::Deselect);240 selecting = false;241 break;242 }243 default:244 ASSERT(0, "QtMoleculeListView::recieveNotification() - cannot get here, not subscribed to World's channel "245 +toString(notification->getChannelNo()));246 break;247 }248 } else if (dynamic_cast<molecule*>(publisher) != NULL) {249 const molecule * const mol = dynamic_cast<molecule *>(publisher);250 switch (notification->getChannelNo()) {251 case molecule::SelectionChanged:252 {253 if (mol->getSelected())254 MoleculeSelected(mol->getId());255 else256 MoleculeUnselected(mol->getId());257 break;258 }259 default:260 ASSERT(0, "QtMoleculeListView::recieveNotification() - cannot get here, not subscribed to mol's channel "261 +toString(notification->getChannelNo()));262 break;263 }264 } else {265 ASSERT(0,266 "QtMoleculeListView::recieveNotification() - cannot get here, unknown publisher "+toString(publisher));267 }268 }269 270 void QtMoleculeListView::subjectKilled(Observable *publisher)271 {} -
src/UIElements/Views/Qt4/MoleculeList/QtMoleculeListView.hpp
r1a58ce r3054f4a 17 17 #include <QTreeView> 18 18 19 #include " CodePatterns/Observer/Observer.hpp"19 #include "types.hpp" 20 20 21 #include "types.hpp" 21 #include "UIElements/Qt4/InstanceBoard/ObservedValue_types.hpp" 22 #include "UIElements/Qt4/InstanceBoard/QtObservedMolecule.hpp" 22 23 23 24 class QtMoleculeList; 24 25 25 class QtMoleculeListView : public QTreeView , public Observer26 class QtMoleculeListView : public QTreeView 26 27 { 27 28 Q_OBJECT … … 35 36 public slots: 36 37 void rowsSelected(const QItemSelection&, const QItemSelection&); 37 38 protected: 39 virtual void update(Observable *publisher); 40 virtual void recieveNotification(Observable *publisher, Notification_ptr notification); 41 virtual void subjectKilled(Observable *publisher); 38 void selectionChanged(const QtObservedMolecule::ptr _molecule); 42 39 43 40 private: 44 void MoleculeSelected( const moleculeId_t _id);45 void MoleculeUnselected( const moleculeId_t _id);41 void MoleculeSelected(ObservedValue_Index_t _id); 42 void MoleculeUnselected(ObservedValue_Index_t _id); 46 43 47 44 QModelIndex setIndexToLastColumn(const QModelIndex &_index) const; -
src/UIElements/Views/Qt4/MoleculeList/QtObservedMoleculeObserver.cpp
r1a58ce r3054f4a 47 47 connect(_board, SIGNAL(moleculeInserted(QtObservedMolecule::ptr)), 48 48 this, SLOT(moleculeInserted(QtObservedMolecule::ptr))); 49 connect(_board, SIGNAL(moleculeRemoved( const moleculeId_t)),50 this, SLOT(moleculeRemoved( const moleculeId_t)));49 connect(_board, SIGNAL(moleculeRemoved(ObservedValue_Index_t)), 50 this, SLOT(moleculeRemoved(ObservedValue_Index_t))); 51 51 } 52 52 … … 60 60 } 61 61 62 void QtObservedMoleculeObserver::moleculeRemoved( const moleculeId_t _moleculeid)62 void QtObservedMoleculeObserver::moleculeRemoved(ObservedValue_Index_t _index) 63 63 { 64 const QtObservedMolecule::ptr mol = board->getObservedMolecule(_ moleculeid);64 const QtObservedMolecule::ptr mol = board->getObservedMolecule(_index); 65 65 disconnect( mol.get(), SIGNAL(atomcountChanged()), this, SLOT(atomcountChanged())); 66 66 disconnect( mol.get(), SIGNAL(formulaChanged()), this, SLOT(formulaChanged())); 67 67 disconnect( mol.get(), SIGNAL(nameChanged()), this, SLOT(nameChanged())); 68 68 disconnect( mol.get(), SIGNAL(selectedChanged()), this, SLOT(selectionChanged())); 69 emit MoleculeRemoved(_ moleculeid);69 emit MoleculeRemoved(_index); 70 70 } 71 71 -
src/UIElements/Views/Qt4/MoleculeList/QtObservedMoleculeObserver.hpp
r1a58ce r3054f4a 47 47 // relayed signals 48 48 void MoleculeInserted(const QtObservedMolecule::ptr _molecule); 49 void MoleculeRemoved( const moleculeId_t _molid);49 void MoleculeRemoved(ObservedValue_Index_t _index); 50 50 51 51 private slots: … … 57 57 58 58 void moleculeInserted(const QtObservedMolecule::ptr _molecule); 59 void moleculeRemoved( const moleculeId_t _molid);59 void moleculeRemoved(ObservedValue_Index_t _index); 60 60 61 61 private: -
src/UIElements/Views/Qt4/MoleculeList/SpecificItems/QtMoleculeItem_name.hpp
r1a58ce r3054f4a 28 28 QtMoleculeItem_name( 29 29 QtObservedMolecule::ptr &_ObservedMolecule) : 30 id(_ObservedMolecule->get MolIndex())30 id(_ObservedMolecule->getIndex()) 31 31 { 32 32 // cannot call pure virtual function in QtMoleculeItem's cstor … … 50 50 * \return id of the observed molecule 51 51 */ 52 const moleculeId_t getMoleculeId() const52 ObservedValue_Index_t getMoleculeIndex() const 53 53 { return id; } 54 54 55 55 private: 56 const moleculeId_t id;56 const ObservedValue_Index_t id; 57 57 }; 58 58 -
src/UIElements/Views/Qt4/MoleculeList/SpecificItems/QtMoleculeItem_visibility.hpp
r1a58ce r3054f4a 28 28 QtMoleculeItem_visibility( 29 29 QtObservedMolecule::ptr &_ObservedMolecule) : 30 id(_ObservedMolecule->get MolIndex())30 id(_ObservedMolecule->getIndex()) 31 31 { 32 32 setFlags(flags() | Qt::ItemIsUserCheckable); … … 50 50 * \return id of the observed molecule 51 51 */ 52 const moleculeId_t getMoleculeId() const52 ObservedValue_Index_t getMoleculeIndex() const 53 53 { return id; } 54 54 55 55 private: 56 const moleculeId_t id;56 const ObservedValue_Index_t id; 57 57 }; 58 58
Note:
See TracChangeset
for help on using the changeset viewer.