Changeset 3054f4a for src/UIElements


Ignore:
Timestamp:
Apr 20, 2016, 8:51:51 AM (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:
0a558d
Parents:
1a58ce
git-author:
Frederik Heber <heber@…> (03/21/16 21:13:43)
git-committer:
Frederik Heber <heber@…> (04/20/16 08:51:51)
Message:

QtObserved...Observed now get index on ...Removed() signal.

Location:
src/UIElements
Files:
15 edited

Legend:

Unmodified
Added
Removed
  • src/UIElements/Qt4/InstanceBoard/QtObservedInstanceBoard.cpp

    r1a58ce r3054f4a  
    276276}
    277277
     278QtObservedAtom::ptr QtObservedInstanceBoard::getObservedAtom(ObservedValue_Index_t _id)
     279{
     280  return atomObservedValues.get(_id);
     281}
     282
    278283QtObservedMolecule::ptr QtObservedInstanceBoard::getObservedMolecule(const moleculeId_t _id)
    279284{
    280285  return moleculeObservedValues.get(moleculeids_lookup.left.at(_id));
     286}
     287
     288QtObservedMolecule::ptr QtObservedInstanceBoard::getObservedMolecule(ObservedValue_Index_t _id)
     289{
     290  return moleculeObservedValues.get(_id);
    281291}
    282292
  • src/UIElements/Qt4/InstanceBoard/QtObservedInstanceBoard.hpp

    r1a58ce r3054f4a  
    8484
    8585  QtObservedAtom::ptr getObservedAtom(const atomId_t _id);
     86  QtObservedAtom::ptr getObservedAtom(ObservedValue_Index_t _id);
    8687  QtObservedMolecule::ptr getObservedMolecule(const moleculeId_t _id);
     88  QtObservedMolecule::ptr getObservedMolecule(ObservedValue_Index_t _id);
    8789  void markObservedAtomAsConnected(ObservedValue_Index_t _id);
    8890  void markObservedAtomAsDisconnected(ObservedValue_Index_t _id);
  • src/UIElements/Views/Qt4/ElementList/QtElementList.cpp

    r1a58ce r3054f4a  
    104104  connect(&atomobserver, SIGNAL(AtomInserted(const QtObservedAtom::ptr)),
    105105      this, SLOT(addAtomElement(const QtObservedAtom::ptr)));
    106   connect(&atomobserver, SIGNAL(AtomRemoved(const atomId_t)),
    107       this, SLOT(removeAtomElement(const atomId_t)));
     106  connect(&atomobserver, SIGNAL(AtomRemoved(ObservedValue_Index_t)),
     107      this, SLOT(removeAtomElement(ObservedValue_Index_t)));
    108108  connect(this,SIGNAL(itemSelectionChanged()),this,SLOT(rowSelected()));
    109109//  connect(this,SIGNAL(changed()),this,SLOT(update()));
     
    120120  const atomicNumber_t newelement = _atom->getAtomElement();
    121121  atomicNumber_t oldelement = -1;
    122   const atomId_t atomid = _atom->getAtomIndex();
     122  const ObservedValue_Index_t atomid = _atom->getIndex();
    123123  QTreeWidgetItem *newtreeItem = topLevelItem(newelement-1);
    124124  ASSERT( newtreeItem != NULL,
     
    168168}
    169169
    170 void QtElementList::removeAtomElement(const atomId_t _atomid)
     170void QtElementList::removeAtomElement(ObservedValue_Index_t _id)
    171171{
    172172  boost::recursive_mutex::scoped_lock lock(refill_mutex);
    173173
    174   const AtomElementMap_t::iterator iter = AtomElementMap.find(_atomid);
     174  const AtomElementMap_t::iterator iter = AtomElementMap.find(_id);
    175175  ASSERT (iter != AtomElementMap.end(),
    176       "QtElementList::addAtomElement() - atom #"+toString(_atomid)
     176      "QtElementList::addAtomElement() - atom #"+toString(_id)
    177177      +" is not present in elementlookup map.");
    178178  if (iter != AtomElementMap.end()) {
  • src/UIElements/Views/Qt4/ElementList/QtElementList.hpp

    r1a58ce r3054f4a  
    4646  void changeElement(const QtObservedAtom::ptr _atom);
    4747  void addAtomElement(const QtObservedAtom::ptr _atom);
    48   void removeAtomElement(const atomId_t _atom);
     48  void removeAtomElement(ObservedValue_Index_t _id);
    4949
    5050private:
    5151  std::vector<bool> elementSelection; //!< needed to determine when a selection changes
    52   typedef std::map<const atomId_t, atomicNumber_t> AtomElementMap_t;
     52  typedef std::map<ObservedValue_Index_t, atomicNumber_t> AtomElementMap_t;
    5353  AtomElementMap_t AtomElementMap;
    5454  bool dirty;
  • src/UIElements/Views/Qt4/ElementList/QtObservedAtomObserver.cpp

    r1a58ce r3054f4a  
    4747    connect(_board, SIGNAL(atomInserted(QtObservedAtom::ptr)),
    4848        this, SLOT(atomInserted(QtObservedAtom::ptr)));
    49     connect(_board, SIGNAL(atomRemoved(const atomId_t)),
    50         this, SLOT(atomRemoved(const atomId_t)));
     49    connect(_board, SIGNAL(atomRemoved(ObservedValue_Index_t)),
     50        this, SLOT(atomRemoved(ObservedValue_Index_t)));
    5151}
    5252
     
    6363}
    6464
    65 void QtObservedAtomObserver::atomRemoved(const atomId_t _atomid)
     65void QtObservedAtomObserver::atomRemoved(ObservedValue_Index_t _index)
    6666{
    67   const QtObservedAtom::ptr walker = board->getObservedAtom(_atomid);
     67  const QtObservedAtom::ptr walker = board->getObservedAtom(_index);
    6868  disconnect( walker.get(), SIGNAL(elementChanged()), this, SLOT(elementChanged()));
    69   emit AtomRemoved(_atomid);
     69  emit AtomRemoved(_index);
    7070}
    7171
  • src/UIElements/Views/Qt4/ElementList/QtObservedAtomObserver.hpp

    r1a58ce r3054f4a  
    4444  // relayed signals
    4545  void AtomInserted(const QtObservedAtom::ptr _atom);
    46   void AtomRemoved(const atomId_t _atomid);
     46  void AtomRemoved(ObservedValue_Index_t _index);
    4747
    4848private slots:
     
    5151
    5252  void atomInserted(const QtObservedAtom::ptr _atom);
    53   void atomRemoved(const atomId_t _atomid);
     53  void atomRemoved(ObservedValue_Index_t _index);
    5454
    5555private:
  • src/UIElements/Views/Qt4/MoleculeList/QtMoleculeItem.hpp

    r1a58ce r3054f4a  
    6060   * \return id of the observed molecule
    6161   */
    62   virtual const moleculeId_t getMoleculeId() const
    63   { return -1; }
     62  virtual ObservedValue_Index_t getMoleculeIndex() const
     63  { return NULL; }
    6464};
    6565
  • src/UIElements/Views/Qt4/MoleculeList/QtMoleculeList.cpp

    r1a58ce r3054f4a  
    8181  connect(&observer, SIGNAL(MoleculeInserted(QtObservedMolecule::ptr)),
    8282      this, SLOT(moleculeInserted(QtObservedMolecule::ptr)));
    83   connect(&observer, SIGNAL(MoleculeRemoved(const moleculeId_t)),
    84       this, SLOT(moleculeRemoved(const moleculeId_t)));
     83  connect(&observer, SIGNAL(MoleculeRemoved(ObservedValue_Index_t)),
     84      this, SLOT(moleculeRemoved(ObservedValue_Index_t)));
    8585  connect(&observer, SIGNAL(FormulaChanged(const QtObservedMolecule::ptr)),
    8686      this, SLOT(formulaChanged(const QtObservedMolecule::ptr)));
     
    8989  connect(&observer, SIGNAL(AtomCountChanged(const QtObservedMolecule::ptr)),
    9090      this, SLOT(atomcountChanged(const QtObservedMolecule::ptr)));
    91   connect(board, SIGNAL(moleculeIndexChanged(const moleculeId_t,const moleculeId_t)),
    92       this, SLOT(moleculeIndexChanged(const moleculeId_t, const moleculeId_t)));
    9391}
    9492
     
    116114}
    117115
    118 void QtMoleculeList::moleculeRemoved(const moleculeId_t _id)
     116void QtMoleculeList::moleculeRemoved(ObservedValue_Index_t _id)
    119117{
    120118  LOG(1, "Removing molecule " << _id);
     
    136134}
    137135
    138 template<class T>
    139 void exchangeKeys(
    140     T &_container,
    141     const moleculeId_t _oldid,
    142     const moleculeId_t _newid)
    143 {
    144   typename T::iterator iter = _container.find(_oldid);
    145   ASSERT(_container.find(_newid) == _container.end(),
    146       "exchangeKeys() - new id "+toString(_newid)
    147       +" already exists in container.");
    148   _container.insert( std::make_pair(_newid, iter->second) );
    149   _container.erase(iter);
    150 }
    151 
    152 template<class T>
    153 void exchangeKeysInSet(
    154     T &_container,
    155     const moleculeId_t _oldid,
    156     const moleculeId_t _newid)
    157 {
    158   typename T::iterator iter = _container.find(_oldid);
    159   ASSERT(_container.find(_newid) == _container.end(),
    160       "exchangeKeys() - new id "+toString(_newid)
    161       +" already exists in container.");
    162   _container.insert( _newid );
    163   _container.erase(iter);
    164 }
    165 
    166 template<class T>
    167 void exchangeKeysOverAllColumns(
    168     T &_container,
    169     const moleculeId_t _oldid,
    170     const moleculeId_t _newid)
    171 {
    172   for (int i=0;i<QtMoleculeItem::COLUMNTYPES_MAX;++i) {
    173     typename T::iterator iter =
    174         _container.find( std::make_pair(_oldid, (enum QtMoleculeItem::COLUMNTYPES)i) );
    175     if (iter == _container.end())
    176       continue;
    177     ASSERT(_container.find( std::make_pair(_newid,(enum QtMoleculeItem::COLUMNTYPES)i) ) == _container.end(),
    178         "exchangeKeys() - new id "+toString(_newid)
    179         +" already exists in container.");
    180     _container.insert( std::make_pair(_newid, (enum QtMoleculeItem::COLUMNTYPES)i) );
    181     _container.erase(iter);
    182   }
    183 }
    184 
    185 void QtMoleculeList::moleculeIndexChanged(
    186     const moleculeId_t _oldid,
    187     const moleculeId_t _newid)
    188 {
    189   // go through all list and change keys
    190   exchangeKeys(MoleculeFormulaMap, _oldid, _newid);
    191   {
    192     MoleculeItemBiMap_t::left_iterator iter = MoleculeItemBiMap.left.find(_oldid);
    193     ASSERT(MoleculeItemBiMap.left.count(_newid),
    194         "QtMoleculeList::moleculeIndexChanged() - new id "+toString(_newid)
    195         +" already exists in MoleculeItemBiMap.");
    196     MoleculeItemBiMap.left.insert( std::make_pair(_newid, iter->second) );
    197     MoleculeItemBiMap.left.erase(iter);
    198   }
    199 }
    200 
    201 bool QtMoleculeList::isMoleculeItemPresent(const moleculeId_t _molid) const
     136bool QtMoleculeList::isMoleculeItemPresent(ObservedValue_Index_t _molid) const
    202137{
    203138  MoleculeItemBiMap_t::left_const_iterator iter =
     
    206141}
    207142
    208 QtMoleculeItem * QtMoleculeList::MoleculeIdToItem(const moleculeId_t _molid) const
     143QtMoleculeItem * QtMoleculeList::MoleculeIdToItem(ObservedValue_Index_t _molid) const
    209144{
    210145  MoleculeItemBiMap_t::left_const_iterator iter =
     
    212147  ASSERT( iter != MoleculeItemBiMap.left.end(),
    213148      "QtMoleculeList::MoleculeIdToItem() - could not find item to id "
    214       +toString(_molid));
     149      +toString(observer.getIdtoIndex(_molid)));
    215150  return iter->second;
    216151}
    217152
    218 const moleculeId_t QtMoleculeList::ItemToMoleculeId(const QtMoleculeItem * const _item) const
     153ObservedValue_Index_t QtMoleculeList::ItemToMoleculeId(const QtMoleculeItem * const _item) const
    219154{
    220155  const MoleculeItemBiMap_t::right_const_iterator iter =
     
    223158    return iter->second;
    224159  else
    225     return -1;
     160    return NULL;
    226161}
    227162
     
    271206}
    272207
    273 const QModelIndex QtMoleculeList::MoleculeIdToIndex(const moleculeId_t _id) const
     208const QModelIndex QtMoleculeList::MoleculeIdToIndex(ObservedValue_Index_t _id) const
    274209{
    275210  QtMoleculeItem * const item = MoleculeIdToItem(_id);
    276211  ASSERT(item != NULL,
    277212      "QtMoleculeList::MoleculeIdToIndex() - could not find item to "
    278       +toString(_id));
     213      +toString(observer.getIdtoIndex(_id)));
    279214  return indexFromItem(item);
    280215}
    281216
    282 const moleculeId_t QtMoleculeList::IndexToMoleculeId(const QModelIndex &_index) const
     217ObservedValue_Index_t QtMoleculeList::IndexToMoleculeId(const QModelIndex &_index) const
    283218{
    284219  QtMoleculeItem * const item = dynamic_cast<QtMoleculeItem *>(itemFromIndex(_index));
    285220  if (item == NULL)
    286     return -1;
     221    return NULL;
    287222  else
    288223    return ItemToMoleculeId(item);
     
    311246  ASSERT( mol_item != NULL,
    312247      "QtMoleculeList::createMoleculeItems() - item from factory was not a QtMoleculeItem?");
    313   MoleculeItemBiMap.left.insert( std::make_pair(_ObservedMolecule->getMolIndex(), mol_item) );
     248  MoleculeItemBiMap.left.insert( std::make_pair(_ObservedMolecule->getIndex(), mol_item) );
    314249
    315250  QStandardItem *formulaitem = molItems.at(QtMoleculeItem::FORMULA);
     
    320255  LOG(1, "Adding " << _molecule_formula << " for "
    321256      << _ObservedMolecule->getMolIndex() << " to MoleculeFormulaMap.");
    322   MoleculeFormulaMap.insert( std::make_pair( _ObservedMolecule->getMolIndex(), _molecule_formula) );
     257  MoleculeFormulaMap.insert( std::make_pair( _ObservedMolecule->getIndex(), _molecule_formula) );
    323258//  LOG(1, "Inserting molecule " << _molid << ": " << _molecule_formula);
    324259  return molItems;
     
    375310      ASSERT( removeformulaiter != MoleculeFormulaMap.end(),
    376311          "QtMoleculeList::removeMoleculeItem() - could not find id "
    377           +toString(removeiter->second)+" in MoleculeFormulaMap.");
     312          +toString(observer.getIdtoIndex(removeiter->second))+" in MoleculeFormulaMap.");
    378313      LOG(1, "Removing " << removeformulaiter->second << " for "
    379314          << removeformulaiter->first << " from MoleculeFormulaMap.");
     
    404339{
    405340  const bool visible = _item->checkState();
    406   const moleculeId_t molid = _item->getMoleculeId();
     341  const ObservedValue_Index_t molid = _item->getMoleculeIndex();
    407342  std::string molecule_formula("illegal");
    408343  {
     
    411346    ASSERT( formulaiter != MoleculeFormulaMap.end(),
    412347        "QtMoleculeList::setVisibilityForMoleculeItem() - formula of molecule "
    413         +toString(molid)+" unknown.");
     348        +toString(observer.getIdtoIndex(molid))+" unknown.");
    414349    molecule_formula = formulaiter->second;
    415350  }
     
    422357  QStandardItem *visgroupItem = getSpecificGroupItem(groupItem, QtMoleculeItem::VISIBILITY);
    423358  ASSERT( groupItem != NULL,
    424       "QtMoleculeList::setVisibilityForMoleculeItem() - item with id "
    425       +toString(_item->getMoleculeId())+" has not parent?");
     359      "QtMoleculeList::setVisibilityForMoleculeItem() - item to "
     360      +toString(observer.getIdtoIndex(molid))+" has not parent?");
    426361  // check whether we have to set the group item
    427362
     
    439374  }
    440375
    441   emit moleculesVisibilityChanged(_item->getMoleculeId(), visible);
     376  emit moleculesVisibilityChanged(molid, visible);
    442377}
    443378
     
    454389
    455390      // emit signal
    456       emit moleculesVisibilityChanged(molItem->getMoleculeId(), visible);
     391      emit moleculesVisibilityChanged(molItem->getMoleculeIndex(), visible);
    457392    }
    458393  }
     
    505440    ASSERT( iter != MoleculeItemBiMap.right.end(),
    506441        "QtMoleculeList::moleculeChanged() - name of unknown molecule changed.");
    507     const moleculeId_t molid = iter->second;
     442    const ObservedValue_Index_t index = iter->second;
     443    const moleculeId_t molid = board->getMoleculeIdToIndex(index);
    508444    // change the name
    509445    std::string cellValue = item->text().toStdString();
     
    517453      AQ.queueAction("change-single-molecule-name", MoleCuilder::Action::NonInteractive);
    518454    } else {
    519       board->getObservedMolecule(
    520           assert_cast<QtMoleculeItem *>(item)->getMoleculeId());
     455      const QtObservedMolecule::ptr mol = board->getObservedMolecule(index);
     456      if (mol) {
     457        QtMoleculeItem * const molitem = assert_cast<QtMoleculeItem *>(item);
     458        molitem->updateState(mol);
     459      }
    521460    }
    522461  }
     
    578517{
    579518  // we need the id as identifier to the item
    580   const moleculeId_t molid = _mol->getMolIndex();
     519  const ObservedValue_Index_t molid = _mol->getIndex();
    581520  LOG(3, "DEBUG: QtMoleculeList got formulaChanged for id " << molid);
    582521  QtMoleculeItem *const molitem = MoleculeIdToItem(molid);
     
    589528  }
    590529
    591   LOG(3, "DEBUG: Moving item to id " << molid);
     530  LOG(3, "DEBUG: Moving item to id " << observer.getIdtoIndex(molid));
    592531  const MoleculeFormulaMap_t::iterator formulaiter =
    593532      MoleculeFormulaMap.find(molid);
    594533  ASSERT( formulaiter != MoleculeFormulaMap.end(),
    595534      "QtMoleculeList::updateItemStates() - formula of molecule "
    596       +toString(molid)+" unknown.");
     535      +toString(observer.getIdtoIndex(molid))+" unknown.");
    597536  // we get old formula from stored map and new formula from the ObservedMolecule
    598537  const std::string old_formula = formulaiter->second;
     
    625564{
    626565  // we need the id as identifier to the items
    627   const moleculeId_t molid = _mol->getMolIndex();
     566  const ObservedValue_Index_t molid = _mol->getIndex();
    628567  LOG(3, "DEBUG: QtMoleculeList got atomcountChanged for id " << molid);
    629568  QtMoleculeItem *const molitem = MoleculeIdToItem(molid);
     
    638577{
    639578  // we need the id as identifier to the items
    640   const moleculeId_t molid = _mol->getMolIndex();
     579  const ObservedValue_Index_t molid = _mol->getIndex();
    641580  LOG(3, "DEBUG: QtMoleculeList got nameChanged for id " << molid);
    642581  QtMoleculeItem *const molitem = MoleculeIdToItem(molid);
  • src/UIElements/Views/Qt4/MoleculeList/QtMoleculeList.hpp

    r1a58ce r3054f4a  
    5656
    5757signals:
    58   void moleculesVisibilityChanged(const moleculeId_t, bool);
     58  void moleculesVisibilityChanged(ObservedValue_Index_t, bool);
    5959
    6060private slots:
    6161  void moleculeInserted(QtObservedMolecule::ptr _mol);
    62   void moleculeRemoved(const moleculeId_t _id);
    63   void moleculeIndexChanged(const moleculeId_t _oldid, const moleculeId_t _newid);
     62  void moleculeRemoved(ObservedValue_Index_t _id);
    6463
    6564private:
    6665  friend class QtMoleculeListView;
    6766
    68   bool isMoleculeItemPresent(const moleculeId_t _molid) const;
    69   QtMoleculeItem * MoleculeIdToItem(const moleculeId_t _molid) const;
    70   const moleculeId_t ItemToMoleculeId(const QtMoleculeItem * const _item) const;
    71   const QModelIndex MoleculeIdToIndex(const moleculeId_t _id) const;
    72   const moleculeId_t IndexToMoleculeId(const QModelIndex &_index) const;
     67  bool isMoleculeItemPresent(ObservedValue_Index_t _id) const;
     68  QtMoleculeItem * MoleculeIdToItem(ObservedValue_Index_t _id) const;
     69  ObservedValue_Index_t ItemToMoleculeId(const QtMoleculeItem * const _item) const;
     70  const QModelIndex MoleculeIdToIndex(ObservedValue_Index_t _id) const;
     71  ObservedValue_Index_t IndexToMoleculeId(const QModelIndex &_index) const;
    7372  QtMoleculeItem * getSpecificMoleculeItem(
    7473      const QtMoleculeItem * const _item,
     
    107106  FormulaTreeItemBiMap_t FormulaItemBiMap;
    108107
    109   typedef std::map<moleculeId_t, std::string> MoleculeFormulaMap_t;
     108  typedef std::map<ObservedValue_Index_t, std::string> MoleculeFormulaMap_t;
    110109  //!> map of (unique) formulas in the world
    111110  MoleculeFormulaMap_t MoleculeFormulaMap;
    112111
    113   typedef boost::bimap<moleculeId_t, QtMoleculeItem*> MoleculeItemBiMap_t;
     112  typedef boost::bimap<ObservedValue_Index_t, QtMoleculeItem*> MoleculeItemBiMap_t;
    114113  MoleculeItemBiMap_t MoleculeItemBiMap;
    115 
    116   typedef std::set< moleculeId_t > list_of_molecules_t;
    117   typedef std::set< std::pair<moleculeId_t, QtMoleculeItem::COLUMNTYPES> > list_of_molecule_items_t;
    118   typedef std::set< std::pair<std::string, QtMoleculeItem::COLUMNTYPES> > list_of_group_items_t;
    119114
    120115  //!> listens to all QtObservedMolecule and relays important events to us
  • src/UIElements/Views/Qt4/MoleculeList/QtMoleculeListView.cpp

    r1a58ce r3054f4a  
    4242#include "CodePatterns/MemDebug.hpp"
    4343
    44 #include "CodePatterns/Observer/Notification.hpp"
    45 
    4644#include "Actions/SelectionAction/Molecules/MoleculeByIdAction.hpp"
    4745#include "Actions/SelectionAction/Molecules/NotMoleculeByIdAction.hpp"
    48 #include "MoleculeObserver.hpp"
    4946#include "molecule.hpp"
    5047#include "World.hpp"
     
    5249QtMoleculeListView::QtMoleculeListView(QWidget * _parent) :
    5350  QTreeView(_parent),
    54   Observer("QtMoleculeListView"),
    5551  selecting(false)
    5652{
     
    5854
    5955  qRegisterMetaType<QItemSelection>("QItemSelection");
    60 
    61   MoleculeObserver::getInstance().signOn(this, molecule::SelectionChanged);
    6256}
    6357
    6458QtMoleculeListView::~QtMoleculeListView()
    6559{
    66   MoleculeObserver::getInstance().signOff(this, molecule::SelectionChanged);
    6760}
    6861
     
    7467      selectionModel(), SIGNAL(selectionChanged(const QItemSelection &, const QItemSelection &)),
    7568      this, SLOT(rowsSelected(const QItemSelection &, const QItemSelection &)), Qt::DirectConnection);
    76 }
    77 
    78 void QtMoleculeListView::update(Observable *publisher)
    79 {}
     69
     70  connect(&_moleculelist->observer, SIGNAL(SelectionChanged(QtObservedMolecule::ptr)),
     71      this, SLOT(selectionChanged(QtObservedMolecule::ptr)));
     72}
    8073
    8174QModelIndex QtMoleculeListView::setIndexToLastColumn(const QModelIndex &_index) const
     
    110103    foreach (index, items)
    111104      if ((index.column() == 0) && (selectionModel()->isSelected(index))) {
    112         const moleculeId_t mol_id = moleculelist->IndexToMoleculeId(index);
     105        const moleculeId_t mol_id = moleculelist->observer.getIdtoIndex(
     106            moleculelist->IndexToMoleculeId(index));
    113107        const molecule * const mol = const_cast<const World &>(World::getInstance()).
    114108            getMolecule(MoleculeById(mol_id));
     
    134128    foreach (index, items)
    135129      if ((index.column() == 0) && (!selectionModel()->isSelected(index))) {
    136         const moleculeId_t mol_id = moleculelist->IndexToMoleculeId(index);
     130        const moleculeId_t mol_id = moleculelist->observer.getIdtoIndex(
     131            moleculelist->IndexToMoleculeId(index));
    137132        const molecule * const mol = const_cast<const World &>(World::getInstance()).
    138133            getMolecule(MoleculeById(mol_id));
     
    154149}
    155150
    156 void QtMoleculeListView::MoleculeSelected(const moleculeId_t _id)
     151void QtMoleculeListView::selectionChanged(const QtObservedMolecule::ptr _molecule)
     152{
     153  if (_molecule->getMolSelected())
     154    MoleculeSelected(_molecule->getIndex());
     155  else
     156    MoleculeUnselected(_molecule->getIndex());
     157}
     158
     159void QtMoleculeListView::MoleculeSelected(ObservedValue_Index_t _id)
    157160{
    158161  if (selecting)
     
    166169//    ASSERT( !selectionModel()->isSelected(index),
    167170//        "QtMoleculeListView::MoleculeSelected() - row to molecule "
    168 //        +toString(_id)+" is already selected.");
     171//        +toString(mol->getMolIndex())+" is already selected.");
    169172
    170173    // select the full row
     
    176179}
    177180
    178 void QtMoleculeListView::MoleculeUnselected(const moleculeId_t _id)
     181void QtMoleculeListView::MoleculeUnselected(ObservedValue_Index_t _id)
    179182{
    180183  if (selecting)
     
    188191//    ASSERT( selectionModel()->isSelected(index),
    189192//        "QtMoleculeListView::MoleculeSelected() - row to molecule "
    190 //        +toString(_id)+" is already unselected.");
     193//        +toString(mol->getMolIndex())+" is already unselected.");
    191194
    192195    // unselect the full row
     
    197200  selecting = false;
    198201}
    199 
    200 
    201 void QtMoleculeListView::recieveNotification(Observable *publisher, Notification_ptr notification)
    202 {
    203   if (dynamic_cast<World *>(publisher) != NULL) {
    204     switch (notification->getChannelNo()) {
    205       case World::SelectionChanged:
    206       {
    207         // obtain molecule selection from World and go through our selection step by step
    208         const std::vector<const molecule *> selectedMolecules =
    209             const_cast<const World &>(World::getInstance()).getSelectedMolecules();
    210         QItemSelection currently_selected = selectionModel()->selection();
    211         QtMoleculeList *moleculelist = static_cast<QtMoleculeList *>(model());
    212         QItemSelection selected;
    213         QItemSelection deselected;
    214         std::set<QModelIndex> already_selected_indices;
    215         for (std::vector<const molecule *>::const_iterator iter = selectedMolecules.begin();
    216             iter != selectedMolecules.end(); ++iter) {
    217           if (moleculelist->isMoleculeItemPresent((*iter)->getId())) {
    218             QtMoleculeItem *item = moleculelist->MoleculeIdToItem((*iter)->getId());
    219             QModelIndex mol_index = item->index();
    220             if (!currently_selected.contains(mol_index))
    221                 selected.select(mol_index, setIndexToLastColumn(mol_index));
    222             else
    223               already_selected_indices.insert(mol_index);
    224           }
    225         }
    226         {
    227           QModelIndex mol_index;
    228           foreach(mol_index, currently_selected.indexes()) {
    229             std::set<QModelIndex>::const_iterator iter =
    230                 already_selected_indices.find(mol_index);
    231             if (iter == already_selected_indices.end())
    232               deselected.select(mol_index, setIndexToLastColumn(mol_index));
    233           }
    234         }
    235         selecting = true;
    236         if (!selected.indexes().empty())
    237           selectionModel()->select(selected, QItemSelectionModel::Select);
    238         if (!deselected.indexes().empty())
    239           selectionModel()->select(deselected, QItemSelectionModel::Deselect);
    240         selecting = false;
    241         break;
    242       }
    243       default:
    244         ASSERT(0, "QtMoleculeListView::recieveNotification() - cannot get here, not subscribed to World's channel "
    245             +toString(notification->getChannelNo()));
    246         break;
    247     }
    248   } else if (dynamic_cast<molecule*>(publisher) != NULL) {
    249     const molecule * const mol = dynamic_cast<molecule *>(publisher);
    250     switch (notification->getChannelNo()) {
    251       case molecule::SelectionChanged:
    252       {
    253         if (mol->getSelected())
    254           MoleculeSelected(mol->getId());
    255         else
    256           MoleculeUnselected(mol->getId());
    257         break;
    258       }
    259       default:
    260         ASSERT(0, "QtMoleculeListView::recieveNotification() - cannot get here, not subscribed to mol's channel "
    261             +toString(notification->getChannelNo()));
    262         break;
    263     }
    264   } else {
    265     ASSERT(0,
    266         "QtMoleculeListView::recieveNotification() - cannot get here, unknown publisher "+toString(publisher));
    267   }
    268 }
    269 
    270 void QtMoleculeListView::subjectKilled(Observable *publisher)
    271 {}
  • src/UIElements/Views/Qt4/MoleculeList/QtMoleculeListView.hpp

    r1a58ce r3054f4a  
    1717#include <QTreeView>
    1818
    19 #include "CodePatterns/Observer/Observer.hpp"
     19#include "types.hpp"
    2020
    21 #include "types.hpp"
     21#include "UIElements/Qt4/InstanceBoard/ObservedValue_types.hpp"
     22#include "UIElements/Qt4/InstanceBoard/QtObservedMolecule.hpp"
    2223
    2324class QtMoleculeList;
    2425
    25 class QtMoleculeListView : public QTreeView, public Observer
     26class QtMoleculeListView : public QTreeView
    2627{
    2728  Q_OBJECT
     
    3536public slots:
    3637  void rowsSelected(const QItemSelection&, const QItemSelection&);
    37 
    38 protected:
    39   virtual void update(Observable *publisher);
    40   virtual void recieveNotification(Observable *publisher, Notification_ptr notification);
    41   virtual void subjectKilled(Observable *publisher);
     38  void selectionChanged(const QtObservedMolecule::ptr _molecule);
    4239
    4340private:
    44   void MoleculeSelected(const moleculeId_t _id);
    45   void MoleculeUnselected(const moleculeId_t _id);
     41  void MoleculeSelected(ObservedValue_Index_t _id);
     42  void MoleculeUnselected(ObservedValue_Index_t _id);
    4643
    4744  QModelIndex setIndexToLastColumn(const QModelIndex &_index) const;
  • src/UIElements/Views/Qt4/MoleculeList/QtObservedMoleculeObserver.cpp

    r1a58ce r3054f4a  
    4747    connect(_board, SIGNAL(moleculeInserted(QtObservedMolecule::ptr)),
    4848        this, SLOT(moleculeInserted(QtObservedMolecule::ptr)));
    49     connect(_board, SIGNAL(moleculeRemoved(const moleculeId_t)),
    50         this, SLOT(moleculeRemoved(const moleculeId_t)));
     49    connect(_board, SIGNAL(moleculeRemoved(ObservedValue_Index_t)),
     50        this, SLOT(moleculeRemoved(ObservedValue_Index_t)));
    5151}
    5252
     
    6060}
    6161
    62 void QtObservedMoleculeObserver::moleculeRemoved(const moleculeId_t _moleculeid)
     62void QtObservedMoleculeObserver::moleculeRemoved(ObservedValue_Index_t _index)
    6363{
    64   const QtObservedMolecule::ptr mol = board->getObservedMolecule(_moleculeid);
     64  const QtObservedMolecule::ptr mol = board->getObservedMolecule(_index);
    6565  disconnect( mol.get(), SIGNAL(atomcountChanged()), this, SLOT(atomcountChanged()));
    6666  disconnect( mol.get(), SIGNAL(formulaChanged()), this, SLOT(formulaChanged()));
    6767  disconnect( mol.get(), SIGNAL(nameChanged()), this, SLOT(nameChanged()));
    6868  disconnect( mol.get(), SIGNAL(selectedChanged()), this, SLOT(selectionChanged()));
    69   emit MoleculeRemoved(_moleculeid);
     69  emit MoleculeRemoved(_index);
    7070}
    7171
  • src/UIElements/Views/Qt4/MoleculeList/QtObservedMoleculeObserver.hpp

    r1a58ce r3054f4a  
    4747  // relayed signals
    4848  void MoleculeInserted(const QtObservedMolecule::ptr _molecule);
    49   void MoleculeRemoved(const moleculeId_t _molid);
     49  void MoleculeRemoved(ObservedValue_Index_t _index);
    5050
    5151private slots:
     
    5757
    5858  void moleculeInserted(const QtObservedMolecule::ptr _molecule);
    59   void moleculeRemoved(const moleculeId_t _molid);
     59  void moleculeRemoved(ObservedValue_Index_t _index);
    6060
    6161private:
  • src/UIElements/Views/Qt4/MoleculeList/SpecificItems/QtMoleculeItem_name.hpp

    r1a58ce r3054f4a  
    2828  QtMoleculeItem_name(
    2929      QtObservedMolecule::ptr &_ObservedMolecule) :
    30         id(_ObservedMolecule->getMolIndex())
     30        id(_ObservedMolecule->getIndex())
    3131  {
    3232    // cannot call pure virtual function in QtMoleculeItem's cstor
     
    5050   * \return id of the observed molecule
    5151   */
    52   const moleculeId_t getMoleculeId() const
     52  ObservedValue_Index_t getMoleculeIndex() const
    5353  { return id; }
    5454
    5555private:
    56   const moleculeId_t id;
     56  const ObservedValue_Index_t id;
    5757};
    5858
  • src/UIElements/Views/Qt4/MoleculeList/SpecificItems/QtMoleculeItem_visibility.hpp

    r1a58ce r3054f4a  
    2828  QtMoleculeItem_visibility(
    2929      QtObservedMolecule::ptr &_ObservedMolecule) :
    30         id(_ObservedMolecule->getMolIndex())
     30        id(_ObservedMolecule->getIndex())
    3131  {
    3232    setFlags(flags() | Qt::ItemIsUserCheckable);
     
    5050   * \return id of the observed molecule
    5151   */
    52   const moleculeId_t getMoleculeId() const
     52  ObservedValue_Index_t getMoleculeIndex() const
    5353  { return id; }
    5454
    5555private:
    56   const moleculeId_t id;
     56  const ObservedValue_Index_t id;
    5757};
    5858
Note: See TracChangeset for help on using the changeset viewer.