Changeset ca1535


Ignore:
Timestamp:
Feb 12, 2016, 11:15:39 PM (9 years ago)
Author:
Frederik Heber <heber@…>
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)
Message:

All QtMoleculeItem now heed QtObservedMolecule and QtMoleculeList takes InstanceBoard.

Location:
src/UIElements
Files:
12 edited

Legend:

Unmodified
Added
Removed
  • src/UIElements/Qt4/QtMainWindow.cpp

    r1b6415a rca1535  
    109109
    110110  QtMoleculeListView *moleculeListView = new QtMoleculeListView(worldTab);
    111   moleculeList = new QtMoleculeList;
     111  moleculeList = new QtMoleculeList(InstanceBoard);
    112112  moleculeListView->setModel(moleculeList);
    113113  moleculeListView->setSelectionChangedAgent(selectionagent);
  • src/UIElements/Views/Qt4/MoleculeList/QtMoleculeItem.cpp

    r1b6415a rca1535  
    3535#include "QtMoleculeItem.hpp"
    3636
    37 #include <QModelIndex>
    38 
    3937#include "UIElements/Views/Qt4/MoleculeList/QtMoleculeList.hpp"
    4038
    4139#include "CodePatterns/MemDebug.hpp"
    4240
    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 
    5641QtMoleculeItem::QtMoleculeItem(
    57      const moleculeId_t _molid,
    58      const channellist_t &_channellist,
     42    QtObservedMolecule::ptr &_ObservedMolecule,
    5943     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),
    6446  movetype(_movetype),
    65   channellist(_channellist),
    66   owner(NULL),
    6747  dirty(true),
    68   emitDirtyState(_emitDirtyState),
    69   emitSubjectKilledState(_emitSubjectKilledState)
     48  emitDirtyState(_emitDirtyState)
    7049{
    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();
    7550  setFlags(flags() | Qt::ItemIsSelectable);
    76 }
    77 
    78 void QtMoleculeItem::signOnToMolecule()
    79 {
    80   // count the number of threads entering the function
    81   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     } else
    97       owner_mutex.unlock();
    98   }
    99 }
    100 
    101 void QtMoleculeItem::signOffFromMolecule()
    102 {
    103   // prevent via owner that another thread enters the function again
    104   // (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   }
    12151}
    12252
    12353QtMoleculeItem::~QtMoleculeItem()
    12454{
    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();
    12955}
    13056
     
    13662  }
    13763}
    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 molecule
    148       //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() const
    173 {
    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  
    1717#include <QStandardItem>
    1818
    19 #include "CodePatterns/Observer/Observer.hpp"
    20 
    2119#include <boost/function.hpp>
    2220#include <boost/thread/recursive_mutex.hpp>
     
    2422#include <string>
    2523
    26 #include "molecule.hpp"
     24#include "UIElements/Qt4/InstanceBoard/QtObservedMolecule.hpp"
    2725
    2826/** This class describes the general interface for a specific item in a QtAbstractItemModel
     
    3735 * -# relaying updateState() call from QtMoleculeList to the specific internal_updateState()
    3836 */
    39 class QtMoleculeItem : public QStandardItem, public Observer
     37class QtMoleculeItem : public QStandardItem
    4038{
    4139public:
    42   //!> typedef for a list of notification channels required, to know when to update
    43   typedef Observable::channels_t channellist_t;
    44 
    4540  //!> enum states whether an item's formula changed or not
    4641  enum MoveTypes {
     
    5853      const enum MoveTypes)> emitDirtyState_t;
    5954
    60   //!> typedef for callback function to model to inform when our subjectKilled() was called
    61   typedef const boost::function<void (const moleculeId_t _id)> emitSubjectKilledState_t;
    62 
    6355  QtMoleculeItem(
    64       const moleculeId_t _molid,
    65       const channellist_t &_channellist,
     56      QtObservedMolecule::ptr &_ObservedMolecule,
    6657      const enum MoveTypes _movetype,
    67       const emitDirtyState_t _emitDirtyState,
    68       const emitSubjectKilledState_t _emitSubjectKilledState);
     58      const emitDirtyState_t _emitDirtyState);
    6959  virtual ~QtMoleculeItem();
    7060
     
    7464  void updateState();
    7565
    76   /** Const getter to this item's molecule.
    77    *
    78    * \return const ref to \a mol
    79    */
    80   const molecule * const getMolecule() const;
    81 
    82   /** Getter for the id of the molecule this item is associated to
    83    *
    84    * \return id of molecule
    85    */
    86   moleculeId_t getMoleculeId() const
    87   { return molid; }
    88 
    8966  /** Returns the type of this QtMoleculeItem, i.e. the column in QtMoleculeList.
    9067   *
     
    9370  virtual QtMoleculeItem::COLUMNTYPES getType() const = 0;
    9471
    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; }
    9978
    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(); }
    10385
    10486protected:
     
    10890  virtual void internal_updateState() = 0;
    10991
    110   //!> molecule we are signed on to
    111   const moleculeId_t molid;
     92  //!> ptr to ObservedMolecule we follow
     93  const QtObservedMolecule::ptr ObservedMolecule;
    11294
    11395private:
    11496  //!> move type for this specific item, set this when implementing
    11597  const enum MoveTypes movetype;
    116 
    117   //!> ref to the specific static list of channels we are signed on to
    118   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;
    12298
    12399  //!> states that this item needs to be updated
     
    126102  //!> bound callback function to inform model about change
    127103  const emitDirtyState_t emitDirtyState;
    128 
    129   //!> bound callback function to inform model about change
    130   const emitSubjectKilledState_t emitSubjectKilledState;
    131 
    132   //!> this protects the signing on and off
    133   mutable boost::recursive_mutex owner_mutex;
    134104};
    135105
  • src/UIElements/Views/Qt4/MoleculeList/QtMoleculeItemFactory.cpp

    r1b6415a rca1535  
    4646#include "CodePatterns/Singleton_impl.hpp"
    4747
    48 #include <boost/assign.hpp>
    49 
    50 #include "molecule.hpp"
    51 
    52 using namespace boost::assign;
    53 
    54 // instantiate static items of specific QtMoleculeItems
    55 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 
    6148// some attributes need to be easier to find for molecules
    6249// these attributes are skipped so far
     
    7057QtMoleculeItemFactory::QtMoleculeItemFactory()
    7158{
    72   // fill all the static channels lists
    73   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 empty
    84 //  const_cast<QtMoleculeItem::channellist_t &>(
    85 //      QtMoleculeItem_occurrence::channellist_occurrence);
    86 //  const_cast<QtMoleculeItem::channellist_t &>(
    87 //      QtMoleculeItem_visibility::channellist_visibility);
    8859}
    8960
    9061QList<QStandardItem *>
    9162QtMoleculeItemFactory::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)
    9565{
    9666  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);
    10272  return molItems;
    10373}
  • src/UIElements/Views/Qt4/MoleculeList/QtMoleculeItemFactory.hpp

    r1b6415a rca1535  
    2020#include <string>
    2121
    22 class molecule;
     22#include "UIElements/Views/Qt4/MoleculeList/QtMoleculeItem.hpp"
    2323
    24 #include "UIElements/Views/Qt4/MoleculeList/QtMoleculeItem.hpp"
     24#include "UIElements/Qt4/InstanceBoard/QtObservedMolecule.hpp"
    2525
    2626/** This class is a factory for a list of QtMoleculeItem's.
     
    4545  /** Creates all QtMoleculeItem's that make up the row for a single molecule.
    4646   *
    47    * \param _molid id of molecule
     47   * \param _ObservedMolecule observed representation of the molecule
    4848   * \param _emitDirtyState callback function to model to inform about required state update
    49    * \param _emitSubjectKilledState callback function to model to inform about called subjectKilled()
    5049   * \return list of prepared items to be appended to a group item
    5150   */
    5251  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);
    5654
    5755  /** Creates all QtMoleculeItem's that make up a row of a group item.
  • src/UIElements/Views/Qt4/MoleculeList/QtMoleculeList.cpp

    r1b6415a rca1535  
    4040#include "UIElements/Views/Qt4/MoleculeList/QtMoleculeItem.hpp"
    4141#include "UIElements/Views/Qt4/MoleculeList/QtMoleculeItemFactory.hpp"
     42#include "UIElements/Qt4/InstanceBoard/QtObservedInstanceBoard.hpp"
    4243
    4344#include <boost/bind.hpp>
     
    6768const unsigned int QtMoleculeList::update_times_per_second = 20;
    6869
    69 QtMoleculeList::QtMoleculeList() :
    70   Observer("QtMoleculeList"),
    71   ChangingChildrensVisibility(false),
     70QtMoleculeList::QtMoleculeList(
     71    QtObservedInstanceBoard *_board) :
    7272  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))
    7575{
    7676  setColumnCount(QtMoleculeItemFactory::COLUMNCOUNT);
    7777
    78   World::getInstance().signOn(this, World::MoleculeInserted);
    79 
    80   refill();
     78  resetUpdateTimer();
    8179
    8280  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)));
    8486}
    8587
    8688QtMoleculeList::~QtMoleculeList()
    87 {
    88   World::getInstance().signOff(this, World::MoleculeInserted);
    89 }
     89{}
    9090
    9191QVariant QtMoleculeList::headerData(int section, Qt::Orientation orientation, int role) const
     
    100100}
    101101
    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)
     102void 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
     110void QtMoleculeList::moleculeRemoved(const moleculeId_t _id)
    206111{
    207112  boost::recursive_mutex::scoped_lock lock(map_mutex);
     
    217122}
    218123
    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   }
     124template<class T>
     125void 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
     138template<class T>
     139void 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
     152template<class T>
     153void 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
     171void 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
     197bool 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
     205QtMoleculeItem * 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
     216const 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
     227QtMoleculeItem * 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
     237bool 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
     245QStandardItem * 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
     256const 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
     268QStandardItem * 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
     275const 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
     285const 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);
    237293}
    238294
     
    252308
    253309QList<QStandardItem *> QtMoleculeList::createMoleculeItems(
    254     const moleculeId_t _molid,
     310    QtObservedMolecule::ptr &_ObservedMolecule,
    255311    std::string &_molecule_formula)
    256312{
    257313  QList<QStandardItem *> molItems =
    258314      QtMoleculeItemFactory::getInstance().createMoleculeItems(
    259           _molid,
    260           callback_DirtyItems,
    261           callback_subjectKilledItems);
     315          _ObservedMolecule,
     316          callback_DirtyItems);
    262317  QtMoleculeItem *mol_item = dynamic_cast<QtMoleculeItem *>(molItems.front());
    263318  ASSERT( mol_item != NULL,
    264319      "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) );
    269321
    270322  QStandardItem *formulaitem = molItems.at(QtMoleculeItem::FORMULA);
     
    272324      "QtMoleculeList::createMoleculeItems() - Formula item not created by factory?");
    273325  _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) );
    279330//  LOG(1, "Inserting molecule " << _molid << ": " << _molecule_formula);
    280331  return molItems;
    281332}
    282333
    283 std::string QtMoleculeList::addMolecule(const molecule * const _mol)
    284 {
    285   const moleculeId_t molid = _mol->getId();
     334std::string QtMoleculeList::addMolecule(QtObservedMolecule::ptr &_ObservedMolecule)
     335{
    286336  // find group if already in list
    287337  QStandardItem *groupItem = NULL;
     
    289339  // create molecule items and obtain the molecule's formula
    290340  std::string molecule_formula;
    291   QList<QStandardItem *> molItems = createMoleculeItems(molid, molecule_formula);
     341  QList<QStandardItem *> molItems = createMoleculeItems(_ObservedMolecule, molecule_formula);
    292342
    293343  // new molecule type -> create new group
     
    309359  }
    310360  ASSERT( groupItem != NULL,
    311       "QtMoleculeList::addMolecule() - item with id "+toString(molid)
     361      "QtMoleculeList::addMolecule() - item with id "+toString(_ObservedMolecule->getMolIndex())
    312362      +" has no parent?");
    313363  groupItem->appendRow(molItems);
     
    344394}
    345395
    346 void QtMoleculeList::refill()
     396void QtMoleculeList::resetUpdateTimer()
    347397{
    348398  // check timer's presence
     
    352402  } else
    353403    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);
    384404
    385405  // activate timer
     
    409429    updateItemStates();
    410430}
    411 
    412 void QtMoleculeList::subjectKilled(Observable *publisher)
    413 {}
    414431
    415432void QtMoleculeList::checkForVisibilityChange(QStandardItem* _item)
     
    660677  list_of_group_items_t visibilityGroupItems_copy = visibilityGroupItems;
    661678  visibilityGroupItems.clear();
    662   std::vector<moleculeId_t> newMolecules_copy = newMolecules;
     679  std::vector<QtObservedMolecule::ptr> newMolecules_copy = newMolecules;
    663680  newMolecules.clear();
    664681  std::vector<moleculeId_t> removedMolecules_copy = removedMolecules;
     
    726743    QtMoleculeItem *const molitem = MoleculeIdToItem(*moveiter);
    727744    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) );
    737752//      LOG(1, "Adding " << formula << " to toBeSetOccurrence.");
    738       toBeSetOccurrence.insert( formula );
    739     }
     753    toBeSetOccurrence.insert( formula );
    740754  }
    741755
     
    769783
    770784  /// 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();
    772786      moliter != newMolecules_copy.end(); ++moliter) {
    773787//    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);
    779790//      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 );
    785792  }
    786793
  • src/UIElements/Views/Qt4/MoleculeList/QtMoleculeList.hpp

    r1b6415a rca1535  
    2525#include <string>
    2626
    27 #include "CodePatterns/Observer/Observer.hpp"
    28 
    2927#include "UIElements/Views/Qt4/MoleculeList/QtMoleculeItem.hpp"
     28#include "UIElements/Qt4/InstanceBoard/QtObservedMolecule.hpp"
    3029
    3130#include "types.hpp"
    3231
    33 class molecule;
    3432class QtMoleculeItem;
    3533class QtMoleculeListView;
     34class QtObservedInstanceBoard;
    3635
    37 class QtMoleculeList : public QStandardItemModel, public Observer
     36class QtMoleculeList : public QStandardItemModel
    3837{
    3938  Q_OBJECT
    4039
    4140public:
    42   QtMoleculeList();
     41  QtMoleculeList(QtObservedInstanceBoard *_board);
    4342  virtual ~QtMoleculeList();
    4443
    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();
    5145
    5246  QVariant headerData(int section, Qt::Orientation orientation, int role) const;
     
    7064  bool ChangingChildrensVisibility;
    7165
     66private 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
     71private:
    7272  mutable boost::recursive_mutex listAccessing_mutex;
    7373  mutable boost::recursive_mutex refill_mutex;
     
    9797      const enum QtMoleculeItem::COLUMNTYPES _type) const;
    9898
    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);
    102107  void removeMoleculeItem(QtMoleculeItem * const _item);
    103108  int setOccurrence(QStandardItem * const _groupitem);
     
    111116      const QtMoleculeItem::MoveTypes _movetype);
    112117
    113   void receiveSubjectKilled(const moleculeId_t _id);
     118  void updateItemStates();
    114119
    115   void updateItemStates();
     120  //!> reference to InstanceBoard
     121  QtObservedInstanceBoard *board;
    116122
    117123  typedef std::map<std::string, unsigned int> FormulaVisibilityCountMap_t;
     
    132138  const QtMoleculeItem::emitDirtyState_t callback_DirtyItems;
    133139
    134   //!> callback function to hand over to items that inform about called subjectKilled()
    135   const QtMoleculeItem::emitSubjectKilledState_t callback_subjectKilledItems;
    136 
    137140  typedef std::map<moleculeId_t, unsigned int> KilledItemsPerMolecule_t;
    138141  //!> takes note of how many items have already been killed for a specific row/molecule
     
    142145  typedef std::set< std::pair<moleculeId_t, QtMoleculeItem::COLUMNTYPES> > list_of_molecule_items_t;
    143146  typedef std::set< std::pair<std::string, QtMoleculeItem::COLUMNTYPES> > list_of_group_items_t;
     147
    144148  //!> list of molecule items that need an update
    145149  list_of_molecule_items_t dirtyMolItems;
     
    151155  list_of_group_items_t visibilityGroupItems;
    152156  //!> list of new molecules which need to be added
    153   std::vector<moleculeId_t> newMolecules;
     157  std::vector<QtObservedMolecule::ptr> newMolecules;
    154158  //!> list of molecules that have been removed
    155159  std::vector<moleculeId_t> removedMolecules;
  • src/UIElements/Views/Qt4/MoleculeList/SpecificItems/QtMoleculeItem_atomcount.hpp

    r1b6415a rca1535  
    1616#include "UIElements/Views/Qt4/MoleculeList/QtMoleculeItem.hpp"
    1717
    18 #include "CodePatterns/ObservedValue.hpp"
    19 
    20 #include "Descriptors/MoleculeIdDescriptor.hpp"
    21 #include "molecule.hpp"
    22 #include "World.hpp"
    23 
    2418class QtMoleculeItemFactory;
    2519
     
    3327
    3428  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)
    4632  {
    47     signOnToMolecule();
    4833    // cannot call pure virtual function in QtMoleculeItem's cstor
    4934    internal_updateState();
    50   }
    51 
    52   ~QtMoleculeItem_atomcount()
    53   {
    54     signOffFromMolecule();
    55   }
    56 
    57   int updateAtomCount() const
    58   {
    59     const molecule * const mol = getMolecule();
    60     if (mol != NULL)
    61       return mol->getAtomCount();
    62     else
    63       return -1;
    6435  }
    6536
     
    6940  void internal_updateState()
    7041  {
    71     setText(QString::number(atomcount.get()));
     42    setText(QString::number(ObservedMolecule->getAtomCount()));
    7243  }
    7344
    7445  QtMoleculeItem::COLUMNTYPES getType() const
    7546  { return QtMoleculeItem::ATOMCOUNT; }
    76 
    77   //!> notification channels of molecule specific to this molecule item, required for update
    78   static const QtMoleculeItem::channellist_t channellist_atomcount;
    79 
    80   //!> temporary value for molecule
    81   const molecule * const molref;
    82 
    83   //!> contains visibility state
    84   ObservedValue<int> atomcount;
    8547};
    8648
  • src/UIElements/Views/Qt4/MoleculeList/SpecificItems/QtMoleculeItem_formula.hpp

    r1b6415a rca1535  
    1818#include <string>
    1919
    20 #include "CodePatterns/ObservedValue.hpp"
    21 
    22 #include "Descriptors/MoleculeIdDescriptor.hpp"
    23 #include "Formula.hpp"
    24 #include "molecule.hpp"
    25 #include "World.hpp"
    26 
    2720class QtMoleculeItemFactory;
    2821
     
    3629
    3730  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)
    4934  {
    50     signOnToMolecule();
    5135    // cannot call pure virtual function in QtMoleculeItem's cstor
    5236    internal_updateState();
    53   }
    54 
    55   ~QtMoleculeItem_formula()
    56   {
    57     signOffFromMolecule();
    58   }
    59 
    60   std::string updateFormula() const
    61   {
    62     const molecule * const mol = getMolecule();
    63     if (mol != NULL)
    64       return mol->getFormula().toString();
    65     else
    66       return std::string();
    6737  }
    6838
     
    7242  void internal_updateState()
    7343  {
    74     setText(QString(formula.get().c_str()));
     44    setText(QString(ObservedMolecule->getMolFormula().c_str()));
    7545  }
    7646
    7747  QtMoleculeItem::COLUMNTYPES getType() const
    7848  { return QtMoleculeItem::FORMULA; }
    79 
    80   //!> notification channels of molecule specific to this molecule item, required for update
    81   static const QtMoleculeItem::channellist_t channellist_formula;
    82 
    83   //!> temporary value for molecule
    84   const molecule * const molref;
    85 
    86   //!> contains visibility state
    87   ObservedValue<std::string> formula;
    8849};
    8950
  • src/UIElements/Views/Qt4/MoleculeList/SpecificItems/QtMoleculeItem_name.hpp

    r1b6415a rca1535  
    1616#include "UIElements/Views/Qt4/MoleculeList/QtMoleculeItem.hpp"
    1717
    18 #include "CodePatterns/ObservedValue.hpp"
    19 
    20 #include "Descriptors/MoleculeIdDescriptor.hpp"
    21 #include "molecule.hpp"
    22 #include "World.hpp"
    23 
    2418class QtMoleculeItemFactory;
    2519
     
    3327
    3428  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)
    4632  {
    47     signOnToMolecule();
    4833    // cannot call pure virtual function in QtMoleculeItem's cstor
    4934    internal_updateState();
    50   }
    51 
    52   ~QtMoleculeItem_name()
    53   {
    54     signOffFromMolecule();
    55   }
    56 
    57   std::string updateName() const
    58   {
    59     const molecule * const mol = getMolecule();
    60     if (mol != NULL)
    61       return mol->getName();
    62     else
    63       return std::string();
    6435  }
    6536
     
    6940  void internal_updateState()
    7041  {
    71     setText(QString(name.get().c_str()));
     42    setText(QString(ObservedMolecule->getMolName().c_str()));
    7243  }
    7344
    7445  QtMoleculeItem::COLUMNTYPES getType() const
    7546  { return QtMoleculeItem::NAME; }
    76 
    77   //!> notification channels of molecule specific to this molecule item, required for update
    78   static const QtMoleculeItem::channellist_t channellist_name;
    79 
    80   //!> temporary value for molecule
    81   const molecule * const molref;
    82 
    83   //!> contains visibility state
    84   ObservedValue<std::string> name;
    8547};
    8648
  • src/UIElements/Views/Qt4/MoleculeList/SpecificItems/QtMoleculeItem_occurrence.hpp

    r1b6415a rca1535  
    2727
    2828  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)
    3332  {
    34     signOnToMolecule();
    3533    // cannot call pure virtual function in QtMoleculeItem's cstor
    3634    internal_updateState();
    37   }
    38 
    39   ~QtMoleculeItem_occurrence()
    40   {
    41     signOffFromMolecule();
    4235  }
    4336
     
    5245  QtMoleculeItem::COLUMNTYPES getType() const
    5346  { return QtMoleculeItem::OCCURRENCE; }
    54 
    55   //!> notification channels of molecule specific to this molecule item, required for update
    56   static const QtMoleculeItem::channellist_t channellist_occurrence;
    5747};
    5848
  • src/UIElements/Views/Qt4/MoleculeList/SpecificItems/QtMoleculeItem_visibility.hpp

    r1b6415a rca1535  
    2727
    2828  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)
    3332  {
    34     signOnToMolecule();
    3533    setFlags(flags() | Qt::ItemIsUserCheckable);
    3634    setCheckState(Qt::Unchecked);
    3735    // cannot call pure virtual function in QtMoleculeItem's cstor
    3836    internal_updateState();
    39   }
    40 
    41   ~QtMoleculeItem_visibility()
    42   {
    43     signOffFromMolecule();
    4437  }
    4538
     
    5245  QtMoleculeItem::COLUMNTYPES getType() const
    5346  { return QtMoleculeItem::VISIBILITY; }
    54 
    55   //!> notification channels of molecule specific to this molecule item, required for update
    56   static const QtMoleculeItem::channellist_t channellist_visibility;
    5747};
    5848
Note: See TracChangeset for help on using the changeset viewer.