Changeset ca1535
- Timestamp:
- Feb 12, 2016, 11:15:39 PM (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:
- deb5ee
- Parents:
- 1b6415a
- git-author:
- Frederik Heber <heber@…> (10/29/15 22:21:30)
- git-committer:
- Frederik Heber <heber@…> (02/12/16 23:15:39)
- Location:
- src/UIElements
- Files:
-
- 12 edited
Legend:
- Unmodified
- Added
- Removed
-
src/UIElements/Qt4/QtMainWindow.cpp
r1b6415a rca1535 109 109 110 110 QtMoleculeListView *moleculeListView = new QtMoleculeListView(worldTab); 111 moleculeList = new QtMoleculeList ;111 moleculeList = new QtMoleculeList(InstanceBoard); 112 112 moleculeListView->setModel(moleculeList); 113 113 moleculeListView->setSelectionChangedAgent(selectionagent); -
src/UIElements/Views/Qt4/MoleculeList/QtMoleculeItem.cpp
r1b6415a rca1535 35 35 #include "QtMoleculeItem.hpp" 36 36 37 #include <QModelIndex>38 39 37 #include "UIElements/Views/Qt4/MoleculeList/QtMoleculeList.hpp" 40 38 41 39 #include "CodePatterns/MemDebug.hpp" 42 40 43 #include "CodePatterns/Assert.hpp"44 #include "CodePatterns/toString.hpp"45 46 #include "CodePatterns/Observer/Notification.hpp"47 48 #include <algorithm>49 50 #include <boost/thread/locks.hpp>51 52 #include "Descriptors/MoleculeIdDescriptor.hpp"53 #include "molecule.hpp"54 #include "World.hpp"55 56 41 QtMoleculeItem::QtMoleculeItem( 57 const moleculeId_t _molid, 58 const channellist_t &_channellist, 42 QtObservedMolecule::ptr &_ObservedMolecule, 59 43 const enum MoveTypes _movetype, 60 const emitDirtyState_t _emitDirtyState, 61 const emitSubjectKilledState_t _emitSubjectKilledState) : 62 Observer("QtMoleculeItem"), 63 molid(_molid), 44 const emitDirtyState_t _emitDirtyState) : 45 ObservedMolecule(_ObservedMolecule), 64 46 movetype(_movetype), 65 channellist(_channellist),66 owner(NULL),67 47 dirty(true), 68 emitDirtyState(_emitDirtyState), 69 emitSubjectKilledState(_emitSubjectKilledState) 48 emitDirtyState(_emitDirtyState) 70 49 { 71 // BUG: We cannot sign on here as then and again we catch "pure virtual function called"72 // this makes no sense as both the Observer part (which also has a recievedNotification())73 // nor QtMoleculeItem's vtable have been fully created.74 // signOnToMolecule();75 50 setFlags(flags() | Qt::ItemIsSelectable); 76 }77 78 void QtMoleculeItem::signOnToMolecule()79 {80 // count the number of threads entering the function81 std::cout << "QtMoleculeItem::signOnToMolecule() called for " << this << std::endl;82 const molecule * const mol = const_cast<const World &>(World::getInstance()).83 getMolecule(MoleculeById(molid));84 if (mol != NULL) {85 owner_mutex.lock();86 if (owner == NULL) {87 owner_mutex.unlock();88 const Observable *owner_copy = static_cast<const Observable *>(mol);89 for (channellist_t::const_iterator channeliter = channellist.begin();90 channeliter != channellist.end(); ++channeliter)91 owner_copy->signOn(this, *channeliter);92 owner_mutex.lock();93 owner = owner_copy;94 owner_mutex.unlock();95 std::cout << "QtMoleculeItem " << this << " has signed on to " << owner << std::endl;96 } else97 owner_mutex.unlock();98 }99 }100 101 void QtMoleculeItem::signOffFromMolecule()102 {103 // prevent via owner that another thread enters the function again104 // (re-entrancy)105 const Observable *owner_copy;106 {107 boost::recursive_mutex::scoped_lock lock(owner_mutex);108 if (owner != NULL) {109 owner_copy = owner;110 owner = NULL;111 }112 }113 std::cout << "QtMoleculeItem::signOffFromMolecule() called for " << this << std::endl;114 if (owner_copy != NULL) {115 for (channellist_t::const_iterator channeliter = channellist.begin();116 channeliter != channellist.end(); ++channeliter)117 owner_copy->signOff(this, *channeliter);118 std::cout << "QtMoleculeItem " << this << " has signed off from " << owner_copy << std::endl;119 owner_copy = NULL;120 }121 51 } 122 52 123 53 QtMoleculeItem::~QtMoleculeItem() 124 54 { 125 // BUG: We cannot sign off here as then and again we catch "pure virtual function called"126 // this makes no sense as neither the Observer part (which also has a recievedNotification())127 // nor QtMoleculeItem's vtable have yet been destroyed.128 signOffFromMolecule();129 55 } 130 56 … … 136 62 } 137 63 } 138 139 void QtMoleculeItem::update(Observable *publisher)140 {}141 142 void QtMoleculeItem::recieveNotification(Observable *publisher, Notification_ptr notification)143 {144 if (dynamic_cast<molecule *>(publisher) != NULL) {145 if (notification->getChannelNo() == molecule::AboutToBeRemoved) {146 signOffFromMolecule();147 // prevent any remaining updates from accessing the molecule148 //molid = -1;149 dirty = false;150 } else {151 channellist_t::const_iterator iter =152 std::find(channellist.begin(), channellist.end(), notification->getChannelNo());153 if (iter != channellist.end()) {154 dirty = true;155 emitDirtyState(getMoleculeId(), getType(), movetype);156 } else {157 ASSERT(0,158 "QtMoleculeItem::recieveNotification() - received notification to channel "159 +toString(notification->getChannelNo())+" we are not subscribed to.");160 }161 }162 }163 }164 165 void QtMoleculeItem::subjectKilled(Observable *publisher)166 {167 // signOffFromMolecule();168 dirty = false;169 emitSubjectKilledState(getMoleculeId());170 }171 172 const molecule * const QtMoleculeItem::getMolecule() const173 {174 const molecule * const mol = const_cast<const World &>(World::getInstance()).getMolecule(MoleculeById(molid));175 // ASSERT (mol != NULL,176 // "QtMoleculeItem::getMolecule() - mol with "+toString(molid)+" is gone.");177 return mol;178 } -
src/UIElements/Views/Qt4/MoleculeList/QtMoleculeItem.hpp
r1b6415a rca1535 17 17 #include <QStandardItem> 18 18 19 #include "CodePatterns/Observer/Observer.hpp"20 21 19 #include <boost/function.hpp> 22 20 #include <boost/thread/recursive_mutex.hpp> … … 24 22 #include <string> 25 23 26 #include " molecule.hpp"24 #include "UIElements/Qt4/InstanceBoard/QtObservedMolecule.hpp" 27 25 28 26 /** This class describes the general interface for a specific item in a QtAbstractItemModel … … 37 35 * -# relaying updateState() call from QtMoleculeList to the specific internal_updateState() 38 36 */ 39 class QtMoleculeItem : public QStandardItem , public Observer37 class QtMoleculeItem : public QStandardItem 40 38 { 41 39 public: 42 //!> typedef for a list of notification channels required, to know when to update43 typedef Observable::channels_t channellist_t;44 45 40 //!> enum states whether an item's formula changed or not 46 41 enum MoveTypes { … … 58 53 const enum MoveTypes)> emitDirtyState_t; 59 54 60 //!> typedef for callback function to model to inform when our subjectKilled() was called61 typedef const boost::function<void (const moleculeId_t _id)> emitSubjectKilledState_t;62 63 55 QtMoleculeItem( 64 const moleculeId_t _molid, 65 const channellist_t &_channellist, 56 QtObservedMolecule::ptr &_ObservedMolecule, 66 57 const enum MoveTypes _movetype, 67 const emitDirtyState_t _emitDirtyState, 68 const emitSubjectKilledState_t _emitSubjectKilledState); 58 const emitDirtyState_t _emitDirtyState); 69 59 virtual ~QtMoleculeItem(); 70 60 … … 74 64 void updateState(); 75 65 76 /** Const getter to this item's molecule.77 *78 * \return const ref to \a mol79 */80 const molecule * const getMolecule() const;81 82 /** Getter for the id of the molecule this item is associated to83 *84 * \return id of molecule85 */86 moleculeId_t getMoleculeId() const87 { return molid; }88 89 66 /** Returns the type of this QtMoleculeItem, i.e. the column in QtMoleculeList. 90 67 * … … 93 70 virtual QtMoleculeItem::COLUMNTYPES getType() const = 0; 94 71 95 private: 96 void update(Observable *publisher); 97 void recieveNotification(Observable *publisher, Notification_ptr notification); 98 void subjectKilled(Observable *publisher); 72 /** Getter to the observed molecule in this item. 73 * 74 * \return const ref to ObservedMolecule for this item 75 */ 76 const QtObservedMolecule::ptr& getMolecule() const 77 { return ObservedMolecule; } 99 78 100 protected: 101 void signOnToMolecule(); 102 void signOffFromMolecule(); 79 /** Getter for the id of the observed molecule for this item. 80 * 81 * \return id of the observed molecule 82 */ 83 const moleculeId_t getMoleculeId() const 84 { return ObservedMolecule->getMolIndex(); } 103 85 104 86 protected: … … 108 90 virtual void internal_updateState() = 0; 109 91 110 //!> molecule we are signed on to111 const moleculeId_t molid;92 //!> ptr to ObservedMolecule we follow 93 const QtObservedMolecule::ptr ObservedMolecule; 112 94 113 95 private: 114 96 //!> move type for this specific item, set this when implementing 115 97 const enum MoveTypes movetype; 116 117 //!> ref to the specific static list of channels we are signed on to118 const channellist_t &channellist;119 120 //!> the Observable we are signed on, also indicates whether we are sign on (not NULL)121 const Observable * owner;122 98 123 99 //!> states that this item needs to be updated … … 126 102 //!> bound callback function to inform model about change 127 103 const emitDirtyState_t emitDirtyState; 128 129 //!> bound callback function to inform model about change130 const emitSubjectKilledState_t emitSubjectKilledState;131 132 //!> this protects the signing on and off133 mutable boost::recursive_mutex owner_mutex;134 104 }; 135 105 -
src/UIElements/Views/Qt4/MoleculeList/QtMoleculeItemFactory.cpp
r1b6415a rca1535 46 46 #include "CodePatterns/Singleton_impl.hpp" 47 47 48 #include <boost/assign.hpp>49 50 #include "molecule.hpp"51 52 using namespace boost::assign;53 54 // instantiate static items of specific QtMoleculeItems55 const QtMoleculeItem::channellist_t QtMoleculeItem_atomcount::channellist_atomcount;56 const QtMoleculeItem::channellist_t QtMoleculeItem_formula::channellist_formula;57 const QtMoleculeItem::channellist_t QtMoleculeItem_name::channellist_name;58 const QtMoleculeItem::channellist_t QtMoleculeItem_occurrence::channellist_occurrence;59 const QtMoleculeItem::channellist_t QtMoleculeItem_visibility::channellist_visibility;60 61 48 // some attributes need to be easier to find for molecules 62 49 // these attributes are skipped so far … … 70 57 QtMoleculeItemFactory::QtMoleculeItemFactory() 71 58 { 72 // fill all the static channels lists73 const_cast<QtMoleculeItem::channellist_t &>(74 QtMoleculeItem_atomcount::channellist_atomcount) +=75 molecule::AtomInserted,76 molecule::AtomRemoved;77 const_cast<QtMoleculeItem::channellist_t &>(78 QtMoleculeItem_formula::channellist_formula) +=79 molecule::FormulaChanged;80 const_cast<QtMoleculeItem::channellist_t &>(81 QtMoleculeItem_name::channellist_name) +=82 molecule::MoleculeNameChanged;83 // the following ones don't have an ObservedValue, hence list may be left empty84 // const_cast<QtMoleculeItem::channellist_t &>(85 // QtMoleculeItem_occurrence::channellist_occurrence);86 // const_cast<QtMoleculeItem::channellist_t &>(87 // QtMoleculeItem_visibility::channellist_visibility);88 59 } 89 60 90 61 QList<QStandardItem *> 91 62 QtMoleculeItemFactory::createMoleculeItems( 92 const moleculeId_t _molid, 93 const QtMoleculeItem::emitDirtyState_t &_emitDirtyState, 94 const QtMoleculeItem::emitSubjectKilledState_t &_emitSubjectKilledState) 63 QtObservedMolecule::ptr &_ObservedMolecule, 64 const QtMoleculeItem::emitDirtyState_t &_emitDirtyState) 95 65 { 96 66 QList<QStandardItem *> molItems; 97 molItems << new QtMoleculeItem_name(_ molid, _emitDirtyState, _emitSubjectKilledState);98 molItems << new QtMoleculeItem_visibility(_ molid, _emitDirtyState, _emitSubjectKilledState);99 molItems << new QtMoleculeItem_atomcount(_ molid, _emitDirtyState, _emitSubjectKilledState);100 molItems << new QtMoleculeItem_formula(_ molid, _emitDirtyState, _emitSubjectKilledState);101 molItems << new QtMoleculeItem_occurrence(_ molid, _emitDirtyState, _emitSubjectKilledState);67 molItems << new QtMoleculeItem_name(_ObservedMolecule, _emitDirtyState); 68 molItems << new QtMoleculeItem_visibility(_ObservedMolecule, _emitDirtyState); 69 molItems << new QtMoleculeItem_atomcount(_ObservedMolecule, _emitDirtyState); 70 molItems << new QtMoleculeItem_formula(_ObservedMolecule, _emitDirtyState); 71 molItems << new QtMoleculeItem_occurrence(_ObservedMolecule, _emitDirtyState); 102 72 return molItems; 103 73 } -
src/UIElements/Views/Qt4/MoleculeList/QtMoleculeItemFactory.hpp
r1b6415a rca1535 20 20 #include <string> 21 21 22 class molecule; 22 #include "UIElements/Views/Qt4/MoleculeList/QtMoleculeItem.hpp" 23 23 24 #include "UIElements/ Views/Qt4/MoleculeList/QtMoleculeItem.hpp"24 #include "UIElements/Qt4/InstanceBoard/QtObservedMolecule.hpp" 25 25 26 26 /** This class is a factory for a list of QtMoleculeItem's. … … 45 45 /** Creates all QtMoleculeItem's that make up the row for a single molecule. 46 46 * 47 * \param _ molid id ofmolecule47 * \param _ObservedMolecule observed representation of the molecule 48 48 * \param _emitDirtyState callback function to model to inform about required state update 49 * \param _emitSubjectKilledState callback function to model to inform about called subjectKilled()50 49 * \return list of prepared items to be appended to a group item 51 50 */ 52 51 QList<QStandardItem *> createMoleculeItems( 53 const moleculeId_t _molid, 54 const QtMoleculeItem::emitDirtyState_t &_emitDirtyState, 55 const QtMoleculeItem::emitSubjectKilledState_t &_emitSubjectKilledState); 52 QtObservedMolecule::ptr &_ObservedMolecule, 53 const QtMoleculeItem::emitDirtyState_t &_emitDirtyState); 56 54 57 55 /** Creates all QtMoleculeItem's that make up a row of a group item. -
src/UIElements/Views/Qt4/MoleculeList/QtMoleculeList.cpp
r1b6415a rca1535 40 40 #include "UIElements/Views/Qt4/MoleculeList/QtMoleculeItem.hpp" 41 41 #include "UIElements/Views/Qt4/MoleculeList/QtMoleculeItemFactory.hpp" 42 #include "UIElements/Qt4/InstanceBoard/QtObservedInstanceBoard.hpp" 42 43 43 44 #include <boost/bind.hpp> … … 67 68 const unsigned int QtMoleculeList::update_times_per_second = 20; 68 69 69 QtMoleculeList::QtMoleculeList() : 70 Observer("QtMoleculeList"), 71 ChangingChildrensVisibility(false), 70 QtMoleculeList::QtMoleculeList( 71 QtObservedInstanceBoard *_board) : 72 72 update_timer(NULL), 73 callback_DirtyItems(boost::bind(&QtMoleculeList::informDirtyState, this, _1, _2, _3)),74 callback_ subjectKilledItems(boost::bind(&QtMoleculeList::receiveSubjectKilled, this, _1))73 board(_board), 74 callback_DirtyItems(boost::bind(&QtMoleculeList::informDirtyState, this, _1, _2, _3)) 75 75 { 76 76 setColumnCount(QtMoleculeItemFactory::COLUMNCOUNT); 77 77 78 World::getInstance().signOn(this, World::MoleculeInserted); 79 80 refill(); 78 resetUpdateTimer(); 81 79 82 80 connect(this,SIGNAL(itemChanged(QStandardItem*)),this,SLOT(moleculeNameChanged(QStandardItem*))); 83 connect(this, SIGNAL(itemChanged(QStandardItem*)), this, SLOT(checkForVisibilityChange(QStandardItem*)), Qt::DirectConnection); 81 connect(this, SIGNAL(itemChanged(QStandardItem*)), this, SLOT(checkForVisibilityChange(QStandardItem*))); 82 connect(board, SIGNAL(moleculeInserted(const moleculeId_t)), this, SLOT(moleculeInserted(const moleculeId_t))); 83 connect(board, SIGNAL(moleculeRemoved(const moleculeId_t)), this, SLOT(moleculeRemoved(const moleculeId_t))); 84 connect(board, SIGNAL(moleculeIndexChanged(const moleculeId_t,const moleculeId_t)), 85 this, SLOT(moleculeIndexChanged(const moleculeId_t, const moleculeId_t))); 84 86 } 85 87 86 88 QtMoleculeList::~QtMoleculeList() 87 { 88 World::getInstance().signOff(this, World::MoleculeInserted); 89 } 89 {} 90 90 91 91 QVariant QtMoleculeList::headerData(int section, Qt::Orientation orientation, int role) const … … 100 100 } 101 101 102 void QtMoleculeList::update(Observable *publisher) { 103 ASSERT(0, 104 "QtMoleculeList::update() - we did not sign up for any global updates."); 105 } 106 107 bool QtMoleculeList::isMoleculeItemPresent(const moleculeId_t _molid) const 108 { 109 boost::recursive_mutex::scoped_lock lock(map_mutex); 110 MoleculeItemBiMap_t::left_const_iterator iter = 111 MoleculeItemBiMap.left.find(_molid); 112 return ( iter != MoleculeItemBiMap.left.end()); 113 } 114 115 QtMoleculeItem * QtMoleculeList::MoleculeIdToItem(const moleculeId_t _molid) const 116 { 117 boost::recursive_mutex::scoped_lock lock(map_mutex); 118 MoleculeItemBiMap_t::left_const_iterator iter = 119 MoleculeItemBiMap.left.find(_molid); 120 ASSERT( iter != MoleculeItemBiMap.left.end(), 121 "QtMoleculeList::MoleculeIdToItem() - could not find item to id " 122 +toString(_molid)); 123 return iter->second; 124 } 125 126 const moleculeId_t QtMoleculeList::ItemToMoleculeId(const QtMoleculeItem * const _item) const 127 { 128 boost::recursive_mutex::scoped_lock lock(map_mutex); 129 const MoleculeItemBiMap_t::right_const_iterator iter = 130 MoleculeItemBiMap.right.find(const_cast<QtMoleculeItem * const>(_item)); 131 if (iter != MoleculeItemBiMap.right.end()) 132 return iter->second; 133 else 134 return -1; 135 } 136 137 QtMoleculeItem * QtMoleculeList::getSpecificMoleculeItem( 138 const QtMoleculeItem * const _item, 139 const enum QtMoleculeItem::COLUMNTYPES _type) const 140 { 141 QStandardItem *parent_item = _item->parent(); 142 ASSERT( parent_item != NULL, 143 "QtMoleculeList::getSpecificMoleculeItem() - parent of molecule item is NULL"); 144 return static_cast<QtMoleculeItem *>(parent_item->child(_item->index().row(), _type)); 145 } 146 147 bool QtMoleculeList::isGroupItemPresent(const std::string &_formula) const 148 { 149 boost::recursive_mutex::scoped_lock lock(map_mutex); 150 FormulaTreeItemBiMap_t::left_const_iterator iter = 151 FormulaItemBiMap.left.find(_formula); 152 return ( iter != FormulaItemBiMap.left.end()); 153 } 154 155 QStandardItem * QtMoleculeList::FormulaToGroupItem(const std::string &_formula) const 156 { 157 boost::recursive_mutex::scoped_lock lock(map_mutex); 158 FormulaTreeItemBiMap_t::left_const_iterator iter = 159 FormulaItemBiMap.left.find(_formula); 160 ASSERT( iter != FormulaItemBiMap.left.end(), 161 "QtMoleculeList::FormulaToGroupItem() - could not find item to formula " 162 +toString(_formula)); 163 return iter->second; 164 } 165 166 const std::string& QtMoleculeList::GroupItemToFormula(const QStandardItem * const _item) const 167 { 168 boost::recursive_mutex::scoped_lock lock(map_mutex); 169 static std::string emptystring; 170 const FormulaTreeItemBiMap_t::right_const_iterator iter = 171 FormulaItemBiMap.right.find(const_cast<QStandardItem * const>(_item)); 172 if (iter != FormulaItemBiMap.right.end()) 173 return iter->second; 174 else 175 return emptystring; 176 } 177 178 QStandardItem * QtMoleculeList::getSpecificGroupItem( 179 const QStandardItem * const _item, 180 const enum QtMoleculeItem::COLUMNTYPES _type) const 181 { 182 return invisibleRootItem()->child(_item->index().row(), _type); 183 } 184 185 const QModelIndex QtMoleculeList::MoleculeIdToIndex(const moleculeId_t _id) const 186 { 187 boost::recursive_mutex::scoped_lock lock(refill_mutex); 188 QtMoleculeItem * const item = MoleculeIdToItem(_id); 189 ASSERT(item != NULL, 190 "QtMoleculeList::MoleculeIdToIndex() - could not find item to " 191 +toString(_id)); 192 return indexFromItem(item); 193 } 194 195 const moleculeId_t QtMoleculeList::IndexToMoleculeId(const QModelIndex &_index) const 196 { 197 boost::recursive_mutex::scoped_lock lock(refill_mutex); 198 QtMoleculeItem * const item = dynamic_cast<QtMoleculeItem *>(itemFromIndex(_index)); 199 if (item == NULL) 200 return -1; 201 else 202 return ItemToMoleculeId(item); 203 } 204 205 void QtMoleculeList::receiveSubjectKilled(const moleculeId_t _id) 102 void QtMoleculeList::moleculeInserted(const moleculeId_t _id) 103 { 104 // get ObservedMolecule from board 105 QtObservedMolecule::ptr ObservedMolecule = board->getObservedMolecule(_id); 106 boost::recursive_mutex::scoped_lock lock(listAccessing_mutex); 107 newMolecules.push_back( ObservedMolecule ); 108 } 109 110 void QtMoleculeList::moleculeRemoved(const moleculeId_t _id) 206 111 { 207 112 boost::recursive_mutex::scoped_lock lock(map_mutex); … … 217 122 } 218 123 219 void QtMoleculeList::recieveNotification(Observable *publisher, Notification_ptr notification) 220 { 221 if (dynamic_cast<World *>(publisher) != NULL) { 222 switch (notification->getChannelNo()) { 223 case World::MoleculeInserted: 224 { 225 boost::recursive_mutex::scoped_lock lock(listAccessing_mutex); 226 const moleculeId_t molid = const_cast<const World &>(World::getInstance()).lastChangedMolId(); 227 if (molid != (unsigned int )-1) 228 newMolecules.push_back( molid ); 229 break; 230 } 231 default: 232 ASSERT(0, "QtMoleculeList::recieveNotification() - cannot get here, not subscribed to channel " 233 +toString(notification->getChannelNo())); 234 break; 235 } 236 } 124 template<class T> 125 void exchangeKeys( 126 T &_container, 127 const moleculeId_t _oldid, 128 const moleculeId_t _newid) 129 { 130 typename T::iterator iter = _container.find(_oldid); 131 ASSERT(_container.find(_newid) == _container.end(), 132 "exchangeKeys() - new id "+toString(_newid) 133 +" already exists in container."); 134 _container.insert( std::make_pair(_newid, iter->second) ); 135 _container.erase(iter); 136 } 137 138 template<class T> 139 void exchangeKeysInSet( 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( _newid ); 149 _container.erase(iter); 150 } 151 152 template<class T> 153 void exchangeKeysOverAllColumns( 154 T &_container, 155 const moleculeId_t _oldid, 156 const moleculeId_t _newid) 157 { 158 for (int i=0;i<QtMoleculeItem::COLUMNTYPES_MAX;++i) { 159 typename T::iterator iter = 160 _container.find( std::make_pair(_oldid, (enum QtMoleculeItem::COLUMNTYPES)i) ); 161 if (iter == _container.end()) 162 continue; 163 ASSERT(_container.find( std::make_pair(_newid,(enum QtMoleculeItem::COLUMNTYPES)i) ) == _container.end(), 164 "exchangeKeys() - new id "+toString(_newid) 165 +" already exists in container."); 166 _container.insert( std::make_pair(_newid, (enum QtMoleculeItem::COLUMNTYPES)i) ); 167 _container.erase(iter); 168 } 169 } 170 171 void QtMoleculeList::moleculeIndexChanged( 172 const moleculeId_t _oldid, 173 const moleculeId_t _newid) 174 { 175 // go through all list and change keys 176 exchangeKeys(MoleculeFormulaMap, _oldid, _newid); 177 { 178 MoleculeItemBiMap_t::left_iterator iter = MoleculeItemBiMap.left.find(_oldid); 179 ASSERT(MoleculeItemBiMap.left.count(_newid), 180 "QtMoleculeList::moleculeIndexChanged() - new id "+toString(_newid) 181 +" already exists in MoleculeItemBiMap."); 182 MoleculeItemBiMap.left.insert( std::make_pair(_newid, iter->second) ); 183 MoleculeItemBiMap.left.erase(iter); 184 } 185 exchangeKeys(KilledItemsPerMolecule, _oldid, _newid); 186 exchangeKeysOverAllColumns(dirtyMolItems, _oldid, _newid); 187 exchangeKeysInSet(visibilityMolItems, _oldid, _newid); 188 { 189 std::vector<moleculeId_t>::iterator iter = 190 std::find(removedMolecules.begin(), removedMolecules.end(), _oldid); 191 removedMolecules.erase(iter); 192 removedMolecules.push_back(_newid); 193 } 194 exchangeKeysInSet(toBeMovedItems, _oldid, _newid); 195 } 196 197 bool QtMoleculeList::isMoleculeItemPresent(const moleculeId_t _molid) const 198 { 199 boost::recursive_mutex::scoped_lock lock(map_mutex); 200 MoleculeItemBiMap_t::left_const_iterator iter = 201 MoleculeItemBiMap.left.find(_molid); 202 return ( iter != MoleculeItemBiMap.left.end()); 203 } 204 205 QtMoleculeItem * QtMoleculeList::MoleculeIdToItem(const moleculeId_t _molid) const 206 { 207 boost::recursive_mutex::scoped_lock lock(map_mutex); 208 MoleculeItemBiMap_t::left_const_iterator iter = 209 MoleculeItemBiMap.left.find(_molid); 210 ASSERT( iter != MoleculeItemBiMap.left.end(), 211 "QtMoleculeList::MoleculeIdToItem() - could not find item to id " 212 +toString(_molid)); 213 return iter->second; 214 } 215 216 const moleculeId_t QtMoleculeList::ItemToMoleculeId(const QtMoleculeItem * const _item) const 217 { 218 boost::recursive_mutex::scoped_lock lock(map_mutex); 219 const MoleculeItemBiMap_t::right_const_iterator iter = 220 MoleculeItemBiMap.right.find(const_cast<QtMoleculeItem * const>(_item)); 221 if (iter != MoleculeItemBiMap.right.end()) 222 return iter->second; 223 else 224 return -1; 225 } 226 227 QtMoleculeItem * QtMoleculeList::getSpecificMoleculeItem( 228 const QtMoleculeItem * const _item, 229 const enum QtMoleculeItem::COLUMNTYPES _type) const 230 { 231 QStandardItem *parent_item = _item->parent(); 232 ASSERT( parent_item != NULL, 233 "QtMoleculeList::getSpecificMoleculeItem() - parent of molecule item is NULL"); 234 return static_cast<QtMoleculeItem *>(parent_item->child(_item->index().row(), _type)); 235 } 236 237 bool QtMoleculeList::isGroupItemPresent(const std::string &_formula) const 238 { 239 boost::recursive_mutex::scoped_lock lock(map_mutex); 240 FormulaTreeItemBiMap_t::left_const_iterator iter = 241 FormulaItemBiMap.left.find(_formula); 242 return ( iter != FormulaItemBiMap.left.end()); 243 } 244 245 QStandardItem * QtMoleculeList::FormulaToGroupItem(const std::string &_formula) const 246 { 247 boost::recursive_mutex::scoped_lock lock(map_mutex); 248 FormulaTreeItemBiMap_t::left_const_iterator iter = 249 FormulaItemBiMap.left.find(_formula); 250 ASSERT( iter != FormulaItemBiMap.left.end(), 251 "QtMoleculeList::FormulaToGroupItem() - could not find item to formula " 252 +toString(_formula)); 253 return iter->second; 254 } 255 256 const std::string& QtMoleculeList::GroupItemToFormula(const QStandardItem * const _item) const 257 { 258 boost::recursive_mutex::scoped_lock lock(map_mutex); 259 static std::string emptystring; 260 const FormulaTreeItemBiMap_t::right_const_iterator iter = 261 FormulaItemBiMap.right.find(const_cast<QStandardItem * const>(_item)); 262 if (iter != FormulaItemBiMap.right.end()) 263 return iter->second; 264 else 265 return emptystring; 266 } 267 268 QStandardItem * QtMoleculeList::getSpecificGroupItem( 269 const QStandardItem * const _item, 270 const enum QtMoleculeItem::COLUMNTYPES _type) const 271 { 272 return invisibleRootItem()->child(_item->index().row(), _type); 273 } 274 275 const QModelIndex QtMoleculeList::MoleculeIdToIndex(const moleculeId_t _id) const 276 { 277 boost::recursive_mutex::scoped_lock lock(refill_mutex); 278 QtMoleculeItem * const item = MoleculeIdToItem(_id); 279 ASSERT(item != NULL, 280 "QtMoleculeList::MoleculeIdToIndex() - could not find item to " 281 +toString(_id)); 282 return indexFromItem(item); 283 } 284 285 const moleculeId_t QtMoleculeList::IndexToMoleculeId(const QModelIndex &_index) const 286 { 287 boost::recursive_mutex::scoped_lock lock(refill_mutex); 288 QtMoleculeItem * const item = dynamic_cast<QtMoleculeItem *>(itemFromIndex(_index)); 289 if (item == NULL) 290 return -1; 291 else 292 return ItemToMoleculeId(item); 237 293 } 238 294 … … 252 308 253 309 QList<QStandardItem *> QtMoleculeList::createMoleculeItems( 254 const moleculeId_t _molid,310 QtObservedMolecule::ptr &_ObservedMolecule, 255 311 std::string &_molecule_formula) 256 312 { 257 313 QList<QStandardItem *> molItems = 258 314 QtMoleculeItemFactory::getInstance().createMoleculeItems( 259 _molid, 260 callback_DirtyItems, 261 callback_subjectKilledItems); 315 _ObservedMolecule, 316 callback_DirtyItems); 262 317 QtMoleculeItem *mol_item = dynamic_cast<QtMoleculeItem *>(molItems.front()); 263 318 ASSERT( mol_item != NULL, 264 319 "QtMoleculeList::createMoleculeItems() - item from factory was not a QtMoleculeItem?"); 265 { 266 boost::recursive_mutex::scoped_lock lock(map_mutex); 267 MoleculeItemBiMap.left.insert( std::make_pair(_molid, mol_item) ); 268 } 320 MoleculeItemBiMap.left.insert( std::make_pair(_ObservedMolecule->getMolIndex(), mol_item) ); 269 321 270 322 QStandardItem *formulaitem = molItems.at(QtMoleculeItem::FORMULA); … … 272 324 "QtMoleculeList::createMoleculeItems() - Formula item not created by factory?"); 273 325 _molecule_formula = formulaitem->text().toStdString(); 274 { 275 boost::recursive_mutex::scoped_lock lock(map_mutex); 276 LOG(1, "Adding " << _molecule_formula << " for " << _molid << " to MoleculeFormulaMap."); 277 MoleculeFormulaMap.insert( std::make_pair( _molid, _molecule_formula) ); 278 } 326 327 LOG(1, "Adding " << _molecule_formula << " for " 328 << _ObservedMolecule->getMolIndex() << " to MoleculeFormulaMap."); 329 MoleculeFormulaMap.insert( std::make_pair( _ObservedMolecule->getMolIndex(), _molecule_formula) ); 279 330 // LOG(1, "Inserting molecule " << _molid << ": " << _molecule_formula); 280 331 return molItems; 281 332 } 282 333 283 std::string QtMoleculeList::addMolecule(const molecule * const _mol) 284 { 285 const moleculeId_t molid = _mol->getId(); 334 std::string QtMoleculeList::addMolecule(QtObservedMolecule::ptr &_ObservedMolecule) 335 { 286 336 // find group if already in list 287 337 QStandardItem *groupItem = NULL; … … 289 339 // create molecule items and obtain the molecule's formula 290 340 std::string molecule_formula; 291 QList<QStandardItem *> molItems = createMoleculeItems( molid, molecule_formula);341 QList<QStandardItem *> molItems = createMoleculeItems(_ObservedMolecule, molecule_formula); 292 342 293 343 // new molecule type -> create new group … … 309 359 } 310 360 ASSERT( groupItem != NULL, 311 "QtMoleculeList::addMolecule() - item with id "+toString( molid)361 "QtMoleculeList::addMolecule() - item with id "+toString(_ObservedMolecule->getMolIndex()) 312 362 +" has no parent?"); 313 363 groupItem->appendRow(molItems); … … 344 394 } 345 395 346 void QtMoleculeList::re fill()396 void QtMoleculeList::resetUpdateTimer() 347 397 { 348 398 // check timer's presence … … 352 402 } else 353 403 update_timer->stop(); 354 355 {356 boost::recursive_mutex::scoped_lock refill_lock(refill_mutex);357 boost::recursive_mutex::scoped_lock listAccessing_lock(listAccessing_mutex);358 359 // LOG(1, "Clearing list.");360 361 clear();362 FormulaVisibilityCountMap.clear();363 {364 boost::recursive_mutex::scoped_lock lock(map_mutex);365 FormulaItemBiMap.clear();366 MoleculeFormulaMap.clear();367 MoleculeItemBiMap.clear();368 KilledItemsPerMolecule.clear();369 }370 dirtyMolItems.clear();371 visibilityMolItems.clear();372 visibilityGroupItems.clear();373 newMolecules.clear();374 removedMolecules.clear();375 toBeMovedItems.clear();376 }377 378 const std::vector<const molecule*> &molecules =379 const_cast<const World &>(World::getInstance()).getAllMolecules();380 for (std::vector<const molecule*>::const_iterator iter = molecules.begin();381 iter != molecules.end();382 iter++)383 addMolecule(*iter);384 404 385 405 // activate timer … … 409 429 updateItemStates(); 410 430 } 411 412 void QtMoleculeList::subjectKilled(Observable *publisher)413 {}414 431 415 432 void QtMoleculeList::checkForVisibilityChange(QStandardItem* _item) … … 660 677 list_of_group_items_t visibilityGroupItems_copy = visibilityGroupItems; 661 678 visibilityGroupItems.clear(); 662 std::vector< moleculeId_t> newMolecules_copy = newMolecules;679 std::vector<QtObservedMolecule::ptr> newMolecules_copy = newMolecules; 663 680 newMolecules.clear(); 664 681 std::vector<moleculeId_t> removedMolecules_copy = removedMolecules; … … 726 743 QtMoleculeItem *const molitem = MoleculeIdToItem(*moveiter); 727 744 LOG(1, "Moving item " << molitem); 728 const molecule *mol = molitem->getMolecule(); 729 if (mol != NULL) { 730 // remove from formula<->molecule bimap with old formula 731 LOG(1, "Removing " << formulaiter->second << " for " << formulaiter->first << " from MoleculeFormulaMap."); 732 MoleculeFormulaMap.erase( formulaiter ); 733 const std::string formula = readdItem(molitem); 734 // and add to formula<->molecule bimap with updated formula 735 LOG(1, "Adding " << formula << " for " << *moveiter << " to MoleculeFormulaMap."); 736 MoleculeFormulaMap.insert( std::make_pair(*moveiter, formula) ); 745 // remove from formula<->molecule bimap with old formula 746 LOG(1, "Removing " << formulaiter->second << " for " << formulaiter->first << " from MoleculeFormulaMap."); 747 MoleculeFormulaMap.erase( formulaiter ); 748 const std::string formula = readdItem(molitem); 749 // and add to formula<->molecule bimap with updated formula 750 LOG(1, "Adding " << formula << " for " << *moveiter << " to MoleculeFormulaMap."); 751 MoleculeFormulaMap.insert( std::make_pair(*moveiter, formula) ); 737 752 // LOG(1, "Adding " << formula << " to toBeSetOccurrence."); 738 toBeSetOccurrence.insert( formula ); 739 } 753 toBeSetOccurrence.insert( formula ); 740 754 } 741 755 … … 769 783 770 784 /// 4. instantiate all new items 771 for (std::vector< moleculeId_t>::const_iterator moliter = newMolecules_copy.begin();785 for (std::vector<QtObservedMolecule::ptr>::iterator moliter = newMolecules_copy.begin(); 772 786 moliter != newMolecules_copy.end(); ++moliter) { 773 787 // LOG(1, "Adding molecule " << *moliter); 774 // check that World knows the molecule still 775 const molecule * const mol = const_cast<const World &>(World::getInstance()). 776 getMolecule(MoleculeById(*moliter)); 777 if ((mol != NULL) && (mol->getId() == *moliter)) { 778 const std::string formula = addMolecule(mol);; 788 // check that World knows the molecule still 789 const std::string formula = addMolecule(*moliter); 779 790 // LOG(1, "Adding " << formula << " to toBeSetOccurrence."); 780 toBeSetOccurrence.insert( formula ); 781 } else { 782 ELOG(2, "Molecule " << *moliter 783 << " disappeared before we could render it in QtMoleculeList."); 784 } 791 toBeSetOccurrence.insert( formula ); 785 792 } 786 793 -
src/UIElements/Views/Qt4/MoleculeList/QtMoleculeList.hpp
r1b6415a rca1535 25 25 #include <string> 26 26 27 #include "CodePatterns/Observer/Observer.hpp"28 29 27 #include "UIElements/Views/Qt4/MoleculeList/QtMoleculeItem.hpp" 28 #include "UIElements/Qt4/InstanceBoard/QtObservedMolecule.hpp" 30 29 31 30 #include "types.hpp" 32 31 33 class molecule;34 32 class QtMoleculeItem; 35 33 class QtMoleculeListView; 34 class QtObservedInstanceBoard; 36 35 37 class QtMoleculeList : public QStandardItemModel , public Observer36 class QtMoleculeList : public QStandardItemModel 38 37 { 39 38 Q_OBJECT 40 39 41 40 public: 42 QtMoleculeList( );41 QtMoleculeList(QtObservedInstanceBoard *_board); 43 42 virtual ~QtMoleculeList(); 44 43 45 protected: 46 virtual void update(Observable *publisher); 47 virtual void recieveNotification(Observable *publisher, Notification_ptr notification); 48 virtual void subjectKilled(Observable *publisher); 49 50 void refill(); 44 void resetUpdateTimer(); 51 45 52 46 QVariant headerData(int section, Qt::Orientation orientation, int role) const; … … 70 64 bool ChangingChildrensVisibility; 71 65 66 private slots: 67 void moleculeInserted(const moleculeId_t _id); 68 void moleculeRemoved(const moleculeId_t _id); 69 void moleculeIndexChanged(const moleculeId_t _oldid, const moleculeId_t _newid); 70 71 private: 72 72 mutable boost::recursive_mutex listAccessing_mutex; 73 73 mutable boost::recursive_mutex refill_mutex; … … 97 97 const enum QtMoleculeItem::COLUMNTYPES _type) const; 98 98 99 std::string addMolecule(const molecule * const _mol); 100 void addGroupItem(QStandardItem *&mainitem, const std::string &_molecule_formula); 101 QList<QStandardItem *> createMoleculeItems(const moleculeId_t _molid, std::string &molecule_formula); 99 std::string addMolecule( 100 QtObservedMolecule::ptr &_ObservedMolecule); 101 void addGroupItem( 102 QStandardItem *&mainitem, 103 const std::string &_molecule_formula); 104 QList<QStandardItem *> createMoleculeItems( 105 QtObservedMolecule::ptr &_ObservedMolecule, 106 std::string &molecule_formula); 102 107 void removeMoleculeItem(QtMoleculeItem * const _item); 103 108 int setOccurrence(QStandardItem * const _groupitem); … … 111 116 const QtMoleculeItem::MoveTypes _movetype); 112 117 113 void receiveSubjectKilled(const moleculeId_t _id);118 void updateItemStates(); 114 119 115 void updateItemStates(); 120 //!> reference to InstanceBoard 121 QtObservedInstanceBoard *board; 116 122 117 123 typedef std::map<std::string, unsigned int> FormulaVisibilityCountMap_t; … … 132 138 const QtMoleculeItem::emitDirtyState_t callback_DirtyItems; 133 139 134 //!> callback function to hand over to items that inform about called subjectKilled()135 const QtMoleculeItem::emitSubjectKilledState_t callback_subjectKilledItems;136 137 140 typedef std::map<moleculeId_t, unsigned int> KilledItemsPerMolecule_t; 138 141 //!> takes note of how many items have already been killed for a specific row/molecule … … 142 145 typedef std::set< std::pair<moleculeId_t, QtMoleculeItem::COLUMNTYPES> > list_of_molecule_items_t; 143 146 typedef std::set< std::pair<std::string, QtMoleculeItem::COLUMNTYPES> > list_of_group_items_t; 147 144 148 //!> list of molecule items that need an update 145 149 list_of_molecule_items_t dirtyMolItems; … … 151 155 list_of_group_items_t visibilityGroupItems; 152 156 //!> list of new molecules which need to be added 153 std::vector< moleculeId_t> newMolecules;157 std::vector<QtObservedMolecule::ptr> newMolecules; 154 158 //!> list of molecules that have been removed 155 159 std::vector<moleculeId_t> removedMolecules; -
src/UIElements/Views/Qt4/MoleculeList/SpecificItems/QtMoleculeItem_atomcount.hpp
r1b6415a rca1535 16 16 #include "UIElements/Views/Qt4/MoleculeList/QtMoleculeItem.hpp" 17 17 18 #include "CodePatterns/ObservedValue.hpp"19 20 #include "Descriptors/MoleculeIdDescriptor.hpp"21 #include "molecule.hpp"22 #include "World.hpp"23 24 18 class QtMoleculeItemFactory; 25 19 … … 33 27 34 28 QtMoleculeItem_atomcount( 35 const moleculeId_t _molid, 36 const emitDirtyState_t &_emitDirtyState, 37 const emitSubjectKilledState_t &_emitSubjectKilledState) : 38 QtMoleculeItem(_molid, channellist_atomcount, QtMoleculeItem::NeedsMove, _emitDirtyState, _emitSubjectKilledState), 39 molref(getMolecule()), 40 atomcount( 41 molref, 42 boost::bind(&QtMoleculeItem_atomcount::updateAtomCount, this), 43 "MoleculeItem_atomcount_"+toString(_molid), 44 updateAtomCount(), 45 channellist_atomcount) 29 QtObservedMolecule::ptr &_ObservedMolecule, 30 const emitDirtyState_t &_emitDirtyState) : 31 QtMoleculeItem(_ObservedMolecule, QtMoleculeItem::NeedsMove, _emitDirtyState) 46 32 { 47 signOnToMolecule();48 33 // cannot call pure virtual function in QtMoleculeItem's cstor 49 34 internal_updateState(); 50 }51 52 ~QtMoleculeItem_atomcount()53 {54 signOffFromMolecule();55 }56 57 int updateAtomCount() const58 {59 const molecule * const mol = getMolecule();60 if (mol != NULL)61 return mol->getAtomCount();62 else63 return -1;64 35 } 65 36 … … 69 40 void internal_updateState() 70 41 { 71 setText(QString::number( atomcount.get()));42 setText(QString::number(ObservedMolecule->getAtomCount())); 72 43 } 73 44 74 45 QtMoleculeItem::COLUMNTYPES getType() const 75 46 { return QtMoleculeItem::ATOMCOUNT; } 76 77 //!> notification channels of molecule specific to this molecule item, required for update78 static const QtMoleculeItem::channellist_t channellist_atomcount;79 80 //!> temporary value for molecule81 const molecule * const molref;82 83 //!> contains visibility state84 ObservedValue<int> atomcount;85 47 }; 86 48 -
src/UIElements/Views/Qt4/MoleculeList/SpecificItems/QtMoleculeItem_formula.hpp
r1b6415a rca1535 18 18 #include <string> 19 19 20 #include "CodePatterns/ObservedValue.hpp"21 22 #include "Descriptors/MoleculeIdDescriptor.hpp"23 #include "Formula.hpp"24 #include "molecule.hpp"25 #include "World.hpp"26 27 20 class QtMoleculeItemFactory; 28 21 … … 36 29 37 30 QtMoleculeItem_formula( 38 const moleculeId_t _molid, 39 const emitDirtyState_t &_emitDirtyState, 40 const emitSubjectKilledState_t &_emitSubjectKilledState) : 41 QtMoleculeItem(_molid, channellist_formula, QtMoleculeItem::NeedsMove, _emitDirtyState, _emitSubjectKilledState), 42 molref(getMolecule()), 43 formula( 44 molref, 45 boost::bind(&QtMoleculeItem_formula::updateFormula, this), 46 "MoleculeItem_formula_"+toString(_molid), 47 updateFormula(), 48 channellist_formula) 31 QtObservedMolecule::ptr &_ObservedMolecule, 32 const emitDirtyState_t &_emitDirtyState) : 33 QtMoleculeItem(_ObservedMolecule, QtMoleculeItem::NeedsMove, _emitDirtyState) 49 34 { 50 signOnToMolecule();51 35 // cannot call pure virtual function in QtMoleculeItem's cstor 52 36 internal_updateState(); 53 }54 55 ~QtMoleculeItem_formula()56 {57 signOffFromMolecule();58 }59 60 std::string updateFormula() const61 {62 const molecule * const mol = getMolecule();63 if (mol != NULL)64 return mol->getFormula().toString();65 else66 return std::string();67 37 } 68 38 … … 72 42 void internal_updateState() 73 43 { 74 setText(QString( formula.get().c_str()));44 setText(QString(ObservedMolecule->getMolFormula().c_str())); 75 45 } 76 46 77 47 QtMoleculeItem::COLUMNTYPES getType() const 78 48 { return QtMoleculeItem::FORMULA; } 79 80 //!> notification channels of molecule specific to this molecule item, required for update81 static const QtMoleculeItem::channellist_t channellist_formula;82 83 //!> temporary value for molecule84 const molecule * const molref;85 86 //!> contains visibility state87 ObservedValue<std::string> formula;88 49 }; 89 50 -
src/UIElements/Views/Qt4/MoleculeList/SpecificItems/QtMoleculeItem_name.hpp
r1b6415a rca1535 16 16 #include "UIElements/Views/Qt4/MoleculeList/QtMoleculeItem.hpp" 17 17 18 #include "CodePatterns/ObservedValue.hpp"19 20 #include "Descriptors/MoleculeIdDescriptor.hpp"21 #include "molecule.hpp"22 #include "World.hpp"23 24 18 class QtMoleculeItemFactory; 25 19 … … 33 27 34 28 QtMoleculeItem_name( 35 const moleculeId_t _molid, 36 const emitDirtyState_t &_emitDirtyState, 37 const emitSubjectKilledState_t &_emitSubjectKilledState) : 38 QtMoleculeItem(_molid, channellist_name, QtMoleculeItem::DoesNotMove, _emitDirtyState, _emitSubjectKilledState), 39 molref(getMolecule()), 40 name( 41 molref, 42 boost::bind(&QtMoleculeItem_name::updateName, this), 43 "MoleculeItem_name_"+toString(_molid), 44 updateName(), 45 channellist_name) 29 QtObservedMolecule::ptr &_ObservedMolecule, 30 const emitDirtyState_t &_emitDirtyState) : 31 QtMoleculeItem(_ObservedMolecule, QtMoleculeItem::DoesNotMove, _emitDirtyState) 46 32 { 47 signOnToMolecule();48 33 // cannot call pure virtual function in QtMoleculeItem's cstor 49 34 internal_updateState(); 50 }51 52 ~QtMoleculeItem_name()53 {54 signOffFromMolecule();55 }56 57 std::string updateName() const58 {59 const molecule * const mol = getMolecule();60 if (mol != NULL)61 return mol->getName();62 else63 return std::string();64 35 } 65 36 … … 69 40 void internal_updateState() 70 41 { 71 setText(QString( name.get().c_str()));42 setText(QString(ObservedMolecule->getMolName().c_str())); 72 43 } 73 44 74 45 QtMoleculeItem::COLUMNTYPES getType() const 75 46 { return QtMoleculeItem::NAME; } 76 77 //!> notification channels of molecule specific to this molecule item, required for update78 static const QtMoleculeItem::channellist_t channellist_name;79 80 //!> temporary value for molecule81 const molecule * const molref;82 83 //!> contains visibility state84 ObservedValue<std::string> name;85 47 }; 86 48 -
src/UIElements/Views/Qt4/MoleculeList/SpecificItems/QtMoleculeItem_occurrence.hpp
r1b6415a rca1535 27 27 28 28 QtMoleculeItem_occurrence( 29 const moleculeId_t _molid, 30 const emitDirtyState_t &_emitDirtyState, 31 const emitSubjectKilledState_t &_emitSubjectKilledState) : 32 QtMoleculeItem(_molid, channellist_occurrence, QtMoleculeItem::DoesNotMove, _emitDirtyState, _emitSubjectKilledState) 29 QtObservedMolecule::ptr &_ObservedMolecule, 30 const emitDirtyState_t &_emitDirtyState) : 31 QtMoleculeItem(_ObservedMolecule, QtMoleculeItem::DoesNotMove, _emitDirtyState) 33 32 { 34 signOnToMolecule();35 33 // cannot call pure virtual function in QtMoleculeItem's cstor 36 34 internal_updateState(); 37 }38 39 ~QtMoleculeItem_occurrence()40 {41 signOffFromMolecule();42 35 } 43 36 … … 52 45 QtMoleculeItem::COLUMNTYPES getType() const 53 46 { return QtMoleculeItem::OCCURRENCE; } 54 55 //!> notification channels of molecule specific to this molecule item, required for update56 static const QtMoleculeItem::channellist_t channellist_occurrence;57 47 }; 58 48 -
src/UIElements/Views/Qt4/MoleculeList/SpecificItems/QtMoleculeItem_visibility.hpp
r1b6415a rca1535 27 27 28 28 QtMoleculeItem_visibility( 29 const moleculeId_t _molid, 30 const emitDirtyState_t &_emitDirtyState, 31 const emitSubjectKilledState_t &_emitSubjectKilledState) : 32 QtMoleculeItem(_molid, channellist_visibility, QtMoleculeItem::DoesNotMove, _emitDirtyState, _emitSubjectKilledState) 29 QtObservedMolecule::ptr &_ObservedMolecule, 30 const emitDirtyState_t &_emitDirtyState) : 31 QtMoleculeItem(_ObservedMolecule, QtMoleculeItem::DoesNotMove, _emitDirtyState) 33 32 { 34 signOnToMolecule();35 33 setFlags(flags() | Qt::ItemIsUserCheckable); 36 34 setCheckState(Qt::Unchecked); 37 35 // cannot call pure virtual function in QtMoleculeItem's cstor 38 36 internal_updateState(); 39 }40 41 ~QtMoleculeItem_visibility()42 {43 signOffFromMolecule();44 37 } 45 38 … … 52 45 QtMoleculeItem::COLUMNTYPES getType() const 53 46 { return QtMoleculeItem::VISIBILITY; } 54 55 //!> notification channels of molecule specific to this molecule item, required for update56 static const QtMoleculeItem::channellist_t channellist_visibility;57 47 }; 58 48
Note:
See TracChangeset
for help on using the changeset viewer.