Ignore:
Timestamp:
Jun 23, 2015, 6:29:02 AM (10 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:
6b474e
Parents:
704d59
git-author:
Frederik Heber <heber@…> (05/22/15 21:14:50)
git-committer:
Frederik Heber <heber@…> (06/23/15 06:29:02)
Message:

QtMoleculeItem now uses moleculeId_t instead molecule*.

Location:
src/UIElements/Views/Qt4/MoleculeList
Files:
12 edited

Legend:

Unmodified
Added
Removed
  • src/UIElements/Views/Qt4/MoleculeList/QtMoleculeItem.cpp

    r704d59 r69b434  
    4141#include "CodePatterns/MemDebug.hpp"
    4242
     43#include "CodePatterns/Assert.hpp"
     44#include "CodePatterns/toString.hpp"
     45
    4346#include "CodePatterns/Observer/Notification.hpp"
    4447
    4548#include <algorithm>
    4649
     50#include "Descriptors/MoleculeIdDescriptor.hpp"
    4751#include "molecule.hpp"
     52#include "World.hpp"
    4853
    4954QtMoleculeItem::QtMoleculeItem(
    50      const molecule * const _mol,
     55     const moleculeId_t _molid,
    5156     const channellist_t &_channellist,
    5257     const enum MoveTypes _movetype,
    5358     const emitDirtyState_t _emitDirtyState) :
    5459  Observer("QtMoleculeItem"),
    55   mol(_mol),
     60  molid(_molid),
    5661  movetype(_movetype),
    5762  channellist(_channellist),
     
    6671void QtMoleculeItem::signOnToMolecule()
    6772{
    68   if (!IsSignedOn)
    69     for (channellist_t::const_iterator channeliter = channellist.begin();
    70         channeliter != channellist.end(); ++channeliter)
    71       mol->signOn(this, *channeliter);
    72   IsSignedOn = true;
     73  const molecule *mol = World::getInstance().getMolecule(MoleculeById(molid));
     74  if (mol != NULL) {
     75    if (!IsSignedOn)
     76      for (channellist_t::const_iterator channeliter = channellist.begin();
     77          channeliter != channellist.end(); ++channeliter)
     78        mol->signOn(this, *channeliter);
     79    IsSignedOn = true;
     80  }
    7381}
    7482
    7583void QtMoleculeItem::signOffFromMolecule()
    7684{
    77   if (IsSignedOn)
    78     for (channellist_t::const_iterator channeliter = channellist.begin();
    79         channeliter != channellist.end(); ++channeliter)
    80       mol->signOff(this, *channeliter);
     85  const molecule *mol = World::getInstance().getMolecule(MoleculeById(molid));
     86  if (mol != NULL) {
     87    if (IsSignedOn)
     88      for (channellist_t::const_iterator channeliter = channellist.begin();
     89          channeliter != channellist.end(); ++channeliter)
     90        mol->signOff(this, *channeliter);
     91  }
    8192  IsSignedOn = false;
    8293}
     
    104115      signOffFromMolecule();
    105116      // prevent any remaining updates from accessing the molecule
    106       //mol = NULL;
     117      //molid = -1;
    107118      dirty = false;
    108119    } else {
     
    126137  dirty = false;
    127138}
     139
     140const molecule * const QtMoleculeItem::getMolecule() const
     141{
     142  const molecule * mol = World::getInstance().getMolecule(MoleculeById(molid));
     143  ASSERT (mol != NULL,
     144      "QtMoleculeItem::getMolecule() - mol with "+toString(molid)+" is gone.");
     145  return mol;
     146}
  • src/UIElements/Views/Qt4/MoleculeList/QtMoleculeItem.hpp

    r704d59 r69b434  
    5252
    5353  QtMoleculeItem(
    54       const molecule * const _mol,
     54      const moleculeId_t _molid,
    5555      const channellist_t &_channellist,
    5656      const enum MoveTypes _movetype,
     
    6767   * \return const ref to \a mol
    6868   */
    69   const molecule * const getMolecule() const
    70   { return mol; }
     69  const molecule * const getMolecule() const;
    7170
    7271private:
     
    8584
    8685  //!> molecule we are signed on to
    87   const molecule * const mol;
     86  const moleculeId_t molid;
    8887
    8988private:
  • src/UIElements/Views/Qt4/MoleculeList/QtMoleculeItemFactory.cpp

    r704d59 r69b434  
    8585QList<QStandardItem *>
    8686QtMoleculeItemFactory::createMoleculeItems(
    87     const molecule * const _mol,
     87    const moleculeId_t _molid,
    8888    const QtMoleculeItem::emitDirtyState_t &_emitDirtyState)
    8989{
    9090  QList<QStandardItem *> molItems;
    91   molItems << new QtMoleculeItem_name(_mol, _emitDirtyState);
    92   molItems << new QtMoleculeItem_visibility(_mol, _emitDirtyState);
    93   molItems << new QtMoleculeItem_atomcount(_mol, _emitDirtyState);
    94   molItems << new QtMoleculeItem_formula(_mol, _emitDirtyState);
    95   molItems << new QtMoleculeItem_occurrence(_mol, _emitDirtyState);
     91  molItems << new QtMoleculeItem_name(_molid, _emitDirtyState);
     92  molItems << new QtMoleculeItem_visibility(_molid, _emitDirtyState);
     93  molItems << new QtMoleculeItem_atomcount(_molid, _emitDirtyState);
     94  molItems << new QtMoleculeItem_formula(_molid, _emitDirtyState);
     95  molItems << new QtMoleculeItem_occurrence(_molid, _emitDirtyState);
    9696  return molItems;
    9797}
  • src/UIElements/Views/Qt4/MoleculeList/QtMoleculeItemFactory.hpp

    r704d59 r69b434  
    4646  /** Creates all QtMoleculeItem's that make up the row for a single molecule.
    4747   *
    48    * \param _mol ref to molecule which is stored internally
     48   * \param _molid id of molecule
    4949   * \param _emitDirtyState callback function to model to inform about required state update
    5050   * \return list of prepared items to be appended to a group item
    5151   */
    5252  QList<QStandardItem *> createMoleculeItems(
    53       const molecule * const _mol,
     53      const moleculeId_t _molid,
    5454      const QtMoleculeItem::emitDirtyState_t &_emitDirtyState);
    5555
  • src/UIElements/Views/Qt4/MoleculeList/QtMoleculeList.cpp

    r704d59 r69b434  
    102102}
    103103
    104 QtMoleculeItem * QtMoleculeList::MoleculeToItem(const molecule * const _mol) const
     104QtMoleculeItem * QtMoleculeList::MoleculeIdToItem(const moleculeId_t _molid) const
    105105{
    106106  MoleculeItemBiMap_t::left_const_iterator iter =
    107       MoleculeItemBiMap.left.find(_mol);
     107      MoleculeItemBiMap.left.find(_molid);
    108108  if( iter != MoleculeItemBiMap.left.end())
    109109    return iter->second;
     
    112112}
    113113
    114 const molecule * const QtMoleculeList::ItemToMolecule(const QtMoleculeItem * const _item) const
     114const moleculeId_t QtMoleculeList::ItemToMoleculeId(const QtMoleculeItem * const _item) const
    115115{
    116116  const MoleculeItemBiMap_t::right_const_iterator iter =
     
    119119    return iter->second;
    120120  else
    121       return NULL;
    122 }
    123 
    124 const molecule * const QtMoleculeList::IndexToMolecule(const QModelIndex &_index) const
     121    return -1;
     122}
     123
     124const moleculeId_t QtMoleculeList::IndexToMoleculeId(const QModelIndex &_index) const
    125125{
    126126  QtMoleculeItem * const item = dynamic_cast<QtMoleculeItem *>(itemFromIndex(_index));
    127127  if (item == NULL)
    128     return NULL;
     128    return -1;
    129129  else
    130     return ItemToMolecule(item);
     130    return ItemToMoleculeId(item);
    131131}
    132132
     
    153153        list_accessing = false;
    154154
    155         const QtMoleculeItem *mol_item = MoleculeToItem(mol);
     155        const QtMoleculeItem *mol_item = MoleculeIdToItem(mol->getId());
    156156        if (mol_item != NULL) {
    157157          QStandardItem *parent_item = mol_item->parent();
     
    194194void QtMoleculeList::addMoleculeItem(
    195195    QStandardItem *_groupitem,
    196     const molecule * const _mol,
     196    const moleculeId_t _molid,
    197197    const std::string &_molecule_formula)
    198198{
    199199  QList<QStandardItem *> molItems =
    200       QtMoleculeItemFactory::getInstance().createMoleculeItems(_mol, callback_DirtyItems);
     200      QtMoleculeItemFactory::getInstance().createMoleculeItems(_molid, callback_DirtyItems);
    201201  QtMoleculeItem *mol_item = dynamic_cast<QtMoleculeItem *>(molItems.front());
    202202  ASSERT( mol_item != NULL,
    203203      "QtMoleculeList::addMoleculeItem() - item from factory was not a QtMoleculeItem?");
    204   MoleculeItemBiMap.left.insert( std::make_pair(_mol, mol_item) );
     204  MoleculeItemBiMap.left.insert( std::make_pair(_molid, mol_item) );
    205205//  LOG(1, "Inserting molecule " << _mol->getId() << ": " << _mol);
    206206  _groupitem->appendRow(molItems);
     
    242242
    243243  // add molecule
    244   addMoleculeItem(groupItem, _mol, molecule_formula);
     244  addMoleculeItem(groupItem, _mol->getId(), molecule_formula);
    245245}
    246246
     
    567567  for (std::vector<const molecule *>::iterator removeiter = toBeRemovedItems_copy.begin();
    568568      removeiter != toBeRemovedItems_copy.end(); ++removeiter) {
    569     QtMoleculeItem *item = MoleculeToItem(*removeiter);
     569    QtMoleculeItem *item = MoleculeIdToItem((*removeiter)->getId());
    570570    dirtyItems_copy.erase(item);
    571571    toBeMovedItems_copy.erase(item);
     
    577577            (*visiter)->index().row(),
    578578            QtMoleculeItemFactory::NAME));
    579     const molecule *mol = ItemToMolecule(_item);
     579    const moleculeId_t molid = ItemToMoleculeId(_item);
     580    const molecule *mol = World::getInstance().getMolecule(MoleculeById(molid));
    580581    if (std::binary_search(
    581582            toBeRemovedItems_copy.begin(), toBeRemovedItems_copy.end(),
     
    613614      removeiter != toBeRemovedItems_copy.end(); ++removeiter) {
    614615//    LOG(1, "Removing molecule " << *removeiter); // cannot access directly, molecule is gone
    615     QtMoleculeItem *item = MoleculeToItem(*removeiter);
     616    QtMoleculeItem *item = MoleculeIdToItem((*removeiter)->getId());
    616617    if (item != NULL)
    617618      removeItem(item);
  • src/UIElements/Views/Qt4/MoleculeList/QtMoleculeList.hpp

    r704d59 r69b434  
    8181  friend class QtMoleculeListView;
    8282
    83   QtMoleculeItem * MoleculeToItem(const molecule * const _mol) const;
    84   const molecule * const IndexToMolecule(const QModelIndex &_index) const;
    85   const molecule * const ItemToMolecule(const QtMoleculeItem * const _item) const;
     83  QtMoleculeItem * MoleculeIdToItem(const moleculeId_t _molid) const;
     84  const moleculeId_t IndexToMoleculeId(const QModelIndex &_index) const;
     85  const moleculeId_t ItemToMoleculeId(const QtMoleculeItem * const _item) const;
    8686
    8787  void addMolecule(const molecule * const _mol);
    8888  void addGroupItem(QStandardItem *&mainitem, const std::string &_molecule_formula);
    89   void addMoleculeItem(QStandardItem *_groupitem, const molecule * const _mol, const std::string &molecule_formula);
     89  void addMoleculeItem(QStandardItem *_groupitem, const moleculeId_t _molid, const std::string &molecule_formula);
    9090  void removeItem(QtMoleculeItem * const _item);
    9191  int setOccurrence(QStandardItem * const _groupitem);
     
    106106  FormulaTreeItemMap_t formula;
    107107
    108   typedef boost::bimap<const molecule *, QtMoleculeItem*> MoleculeItemBiMap_t;
     108  typedef boost::bimap<moleculeId_t, QtMoleculeItem*> MoleculeItemBiMap_t;
    109109  MoleculeItemBiMap_t MoleculeItemBiMap;
    110110
  • src/UIElements/Views/Qt4/MoleculeList/QtMoleculeListView.cpp

    r704d59 r69b434  
    105105    foreach (index, items)
    106106      if ((index.column() == 0) && (selectionModel()->isSelected(index))) {
    107         const molecule *mol = moleculelist->IndexToMolecule(index);
    108         if (mol == NULL) // means we are looking at deselection because of removal
    109           continue;
    110         int mol_id = mol->getId();
     107        const moleculeId_t mol_id = moleculelist->IndexToMoleculeId(index);
     108        const molecule * const mol = World::getInstance().getMolecule(MoleculeById(mol_id));
    111109        // check for invalid molecule
    112110        if (mol_id < 0)
    113111          continue;
    114112        // means we are looking at deselection because of removal (in World)
    115         if (World::getInstance().getMolecule(MoleculeById(mol_id)) != mol)
     113        if (mol == NULL)
    116114          continue;
    117115        if (!World::getInstance().isSelected(mol))
     
    129127    ids.reserve(items.size());
    130128    foreach (index, items)
    131     if ((index.column() == 0) && (!selectionModel()->isSelected(index))) {
    132         const molecule *mol = moleculelist->IndexToMolecule(index);
    133         if (mol == NULL) // means we are looking at deselection because of removal
    134           continue;
    135         int mol_id = mol->getId();
     129      if ((index.column() == 0) && (!selectionModel()->isSelected(index))) {
     130        const moleculeId_t mol_id = moleculelist->IndexToMoleculeId(index);
     131        const molecule * const mol = World::getInstance().getMolecule(MoleculeById(mol_id));
    136132        // check for invalid molecule
    137133        if (mol_id < 0)
    138134          continue;
    139135        // means we are looking at deselection because of removal (in World)
    140         if (World::getInstance().getMolecule(MoleculeById(mol_id)) != mol)
     136        if (mol == NULL)
    141137          continue;
    142138        if (World::getInstance().isSelected(mol))
     
    167163        for (std::vector<molecule *>::const_iterator iter = selectedMolecules.begin();
    168164            iter != selectedMolecules.end(); ++iter) {
    169           QtMoleculeItem *item = moleculelist->MoleculeToItem(*iter);
     165          QtMoleculeItem *item = moleculelist->MoleculeIdToItem((*iter)->getId());
    170166          if (item != NULL) {
    171167            QModelIndex mol_index = item->index();
  • src/UIElements/Views/Qt4/MoleculeList/SpecificItems/QtMoleculeItem_atomcount.hpp

    r704d59 r69b434  
    1616#include "UIElements/Views/Qt4/MoleculeList/QtMoleculeItem.hpp"
    1717
     18#include "Descriptors/MoleculeIdDescriptor.hpp"
    1819#include "molecule.hpp"
     20#include "World.hpp"
    1921
    2022class QtMoleculeItemFactory;
     
    2931
    3032  QtMoleculeItem_atomcount(
    31       const molecule * const _mol,
     33      const moleculeId_t _molid,
    3234      emitDirtyState_t _emitDirtyState) :
    33         QtMoleculeItem(_mol, channellist_atomcount, QtMoleculeItem::NeedsMove, _emitDirtyState)
     35        QtMoleculeItem(_molid, channellist_atomcount, QtMoleculeItem::NeedsMove, _emitDirtyState)
    3436  {
    3537    // cannot call pure virtual function in QtMoleculeItem's cstor
     
    4244  void internal_updateState()
    4345  {
    44     setText(QString::number(mol->getAtomCount()));
     46    const molecule * mol = World::getInstance().getMolecule(MoleculeById(molid));
     47    if (mol != NULL)
     48      setText(QString::number(mol->getAtomCount()));
     49    else
     50      setText(QString::number(-1));
    4551  }
    4652
  • src/UIElements/Views/Qt4/MoleculeList/SpecificItems/QtMoleculeItem_formula.hpp

    r704d59 r69b434  
    1818#include <string>
    1919
     20#include "Descriptors/MoleculeIdDescriptor.hpp"
    2021#include "Formula.hpp"
    2122#include "molecule.hpp"
     23#include "World.hpp"
    2224
    2325class QtMoleculeItemFactory;
     
    3234
    3335  QtMoleculeItem_formula(
    34       const molecule * const _mol,
     36      const moleculeId_t _molid,
    3537      emitDirtyState_t _emitDirtyState) :
    36         QtMoleculeItem(_mol, channellist_formula, QtMoleculeItem::NeedsMove, _emitDirtyState)
     38        QtMoleculeItem(_molid, channellist_formula, QtMoleculeItem::NeedsMove, _emitDirtyState)
    3739  {
    3840    // cannot call pure virtual function in QtMoleculeItem's cstor
     
    4547  void internal_updateState()
    4648  {
    47     setText(QString(mol->getFormula().toString().c_str()));
     49    const molecule * mol = World::getInstance().getMolecule(MoleculeById(molid));
     50    if (mol != NULL)
     51      setText(QString(mol->getFormula().toString().c_str()));
     52    else
     53      setText(QString(""));
    4854  }
    4955
  • src/UIElements/Views/Qt4/MoleculeList/SpecificItems/QtMoleculeItem_name.hpp

    r704d59 r69b434  
    1616#include "UIElements/Views/Qt4/MoleculeList/QtMoleculeItem.hpp"
    1717
     18#include "Descriptors/MoleculeIdDescriptor.hpp"
    1819#include "molecule.hpp"
     20#include "World.hpp"
    1921
    2022class QtMoleculeItemFactory;
     
    2931
    3032  QtMoleculeItem_name(
    31       const molecule * const _mol,
     33      const moleculeId_t _molid,
    3234      emitDirtyState_t _emitDirtyState) :
    33         QtMoleculeItem(_mol, channellist_name, QtMoleculeItem::DoesNotMove, _emitDirtyState)
     35        QtMoleculeItem(_molid, channellist_name, QtMoleculeItem::DoesNotMove, _emitDirtyState)
    3436  {
    3537    // cannot call pure virtual function in QtMoleculeItem's cstor
     
    4244  void internal_updateState()
    4345  {
    44     setText(QString(mol->getName().c_str()));
     46    const molecule * mol = World::getInstance().getMolecule(MoleculeById(molid));
     47    if (mol != NULL)
     48      setText(QString(mol->getName().c_str()));
     49    else
     50      setText(QString("to be removed"));
    4551  }
    4652
  • src/UIElements/Views/Qt4/MoleculeList/SpecificItems/QtMoleculeItem_occurrence.hpp

    r704d59 r69b434  
    2727
    2828  QtMoleculeItem_occurrence(
    29       const molecule * const _mol,
     29      const moleculeId_t _molid,
    3030      emitDirtyState_t _emitDirtyState) :
    31         QtMoleculeItem(_mol, channellist_occurrence, QtMoleculeItem::DoesNotMove, _emitDirtyState)
     31        QtMoleculeItem(_molid, channellist_occurrence, QtMoleculeItem::DoesNotMove, _emitDirtyState)
    3232  {
    3333    // cannot call pure virtual function in QtMoleculeItem's cstor
  • src/UIElements/Views/Qt4/MoleculeList/SpecificItems/QtMoleculeItem_visibility.hpp

    r704d59 r69b434  
    2727
    2828  QtMoleculeItem_visibility(
    29       const molecule * const _mol,
     29      const moleculeId_t _molid,
    3030      emitDirtyState_t _emitDirtyState) :
    31         QtMoleculeItem(_mol, channellist_visibility, QtMoleculeItem::DoesNotMove, _emitDirtyState)
     31        QtMoleculeItem(_molid, channellist_visibility, QtMoleculeItem::DoesNotMove, _emitDirtyState)
    3232  {
    3333    setFlags(flags() | Qt::ItemIsUserCheckable);
Note: See TracChangeset for help on using the changeset viewer.