Ignore:
Timestamp:
Jan 28, 2015, 7:07:01 PM (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:
53c1ff
Parents:
bed759
git-author:
Frederik Heber <heber@…> (01/18/15 13:33:42)
git-committer:
Frederik Heber <heber@…> (01/28/15 19:07:01)
Message:

Added a slew of specific QtMoleculeItem for each of the COLUMNs.

  • all are produced solely by the factory and are very specific.
Location:
src/UIElements/Views/Qt4/MoleculeList
Files:
5 added
4 edited

Legend:

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

    rbed759 r6d1e0a  
    4343#include "CodePatterns/Observer/Notification.hpp"
    4444
     45#include <algorithm>
     46
    4547#include "molecule.hpp"
    4648
    47 // some attributes need to be easier to find for molecules
    48 // these attributes are skipped so far
    49 const int QtMoleculeItem::COLUMNCOUNT = COLUMNTYPES_MAX;
    50 const char *QtMoleculeItem::COLUMNNAMES[QtMoleculeItem::COLUMNCOUNT]={"Name","Visibility", "Atoms","Formula","Occurrence"/*,"Size"*/};
    51 
    52 
    53 QList<QStandardItem *> createMoleculeItemRow(const molecule *_mol)
     49QtMoleculeItem::QtMoleculeItem(
     50     const molecule *_mol,
     51     const channellist_t &_channellist,
     52     const enum MoveTypes _movetype,
     53     const emitDirtyState_t _emitDirtyState) :
     54  Observer("QtMoleculeItem"),
     55  mol(_mol),
     56  movetype(_movetype),
     57  channellist(_channellist),
     58  IsSignedOn(false),
     59  dirty(true),
     60  emitDirtyState(_emitDirtyState)
    5461{
    55   QList<QStandardItem *> molItems;
    56   QStandardItem *mainitem = new QtMoleculeItem(_mol);
    57   mainitem->setText(QString(_mol->getName().c_str()));
    58   mainitem->setFlags(mainitem->flags() | Qt::ItemIsSelectable);
    59   molItems << mainitem;
    60 
    61   QStandardItem *visitem = new QStandardItem();
    62   visitem->setCheckState(Qt::Unchecked);
    63   visitem->setFlags(visitem->flags() | Qt::ItemIsUserCheckable);
    64   molItems << visitem;
    65 
    66   molItems << new QStandardItem(QString::number(_mol->getAtomCount()));
    67   molItems << new QStandardItem(QString(_mol->getFormula().toString().c_str()));
    68   molItems << new QStandardItem(QString(""));
    69   return molItems;
     62  signOnToMolecule();
     63  setFlags(flags() | Qt::ItemIsSelectable);
    7064}
    7165
    72 QtMoleculeItem::QtMoleculeItem(const molecule *_mol) :
    73   Observer("QtMoleculeItem"),
    74   mol(_mol),
    75   IsSignedOn(false)
     66void QtMoleculeItem::signOnToMolecule()
    7667{
    77   mol->signOn(this, molecule::AtomInserted);
    78   mol->signOn(this, molecule::AtomRemoved);
    79   mol->signOn(this, molecule::MoleculeNameChanged);
     68  if (!IsSignedOn)
     69    for (channellist_t::const_iterator channeliter = channellist.begin();
     70        channeliter != channellist.end(); ++channeliter)
     71      mol->signOn(this, *channeliter);
    8072  IsSignedOn = true;
     73}
     74
     75void QtMoleculeItem::signOffFromMolecule()
     76{
     77  if (IsSignedOn)
     78    for (channellist_t::const_iterator channeliter = channellist.begin();
     79        channeliter != channellist.end(); ++channeliter)
     80      mol->signOff(this, *channeliter);
     81  IsSignedOn = false;
    8182}
    8283
    8384QtMoleculeItem::~QtMoleculeItem()
    8485{
    85   if (IsSignedOn) {
    86     mol->signOff(this, molecule::AtomInserted);
    87     mol->signOff(this, molecule::AtomRemoved);
    88     mol->signOff(this, molecule::MoleculeNameChanged);
     86  signOffFromMolecule();
     87}
     88
     89void QtMoleculeItem::updateState()
     90{
     91  if (dirty) {
     92    internal_updateState();
     93    dirty = false;
    8994  }
    9095}
    91 
    9296
    9397void QtMoleculeItem::update(Observable *publisher)
     
    97101{
    98102  if (dynamic_cast<molecule *>(publisher) != NULL) {
    99     switch (notification->getChannelNo()) {
    100       case molecule::AtomInserted:
    101       case molecule::AtomRemoved:
    102       {
    103         // change atomcount
    104         QStandardItem *count_item = parent()->child(index().row(), ATOMCOUNT);
    105         count_item->setText(QString::number(mol->getAtomCount()));
    106 
    107         // change formula
    108         const std::string molecule_formula = mol->getFormula().toString();
    109         QStandardItem *formula_item = parent()->child(index().row(), FORMULA);
    110         formula_item->setText(QString(molecule_formula.c_str()));
    111 
    112         // re-position in model's tree
    113 //        static_cast<QtMoleculeList*>(model())->readdItem(this, molecule_formula);
    114         break;
     103    if (notification->getChannelNo() == molecule::AboutToBeRemoved) {
     104      signOffFromMolecule();
     105      // prevent any remaining updates from accessing the molecule
     106      mol = NULL;
     107      dirty = false;
     108    } else {
     109      channellist_t::const_iterator iter =
     110          std::find(channellist.begin(), channellist.end(), notification->getChannelNo());
     111      if (iter != channellist.end()) {
     112        dirty = true;
     113        emitDirtyState(this, movetype);
     114      } else {
     115        ASSERT(0,
     116            "QtMoleculeItem::recieveNotification() - received notification to channel "
     117            +toString(notification->getChannelNo())+" we are not subscribed to.");
    115118      }
    116       case molecule::MoleculeNameChanged:
    117       {
    118         // change name
    119         QStandardItem *name_item = parent()->child(index().row(), NAME);
    120         name_item->setText(QString(mol->getName().c_str()));
    121         break;
    122       }
    123       default:
    124         ASSERT(0, "QtMoleculeItem::recieveNotification() - cannot get here, not subscribed to channel "
    125             +toString(notification->getChannelNo()));
    126         break;
    127119    }
    128120  }
  • src/UIElements/Views/Qt4/MoleculeList/QtMoleculeItem.hpp

    rbed759 r6d1e0a  
    1919#include "CodePatterns/Observer/Observer.hpp"
    2020
     21#include <boost/function.hpp>
     22#include <list>
    2123#include <string>
    2224
    23 class molecule;
     25#include "molecule.hpp"
    2426
    25 QList<QStandardItem *> createMoleculeItemRow(const molecule *_mol);
    26 
     27/** This class describes the general interface for a specific item in a QtAbstractItemModel
     28 * to contain a specific piece of information about a specific molecule.
     29 *
     30 * To this end, we need a ref to the molecule for updating the information when
     31 * necessary and we need to know the channels we have to listen to know when an
     32 * update is necessary.
     33 *
     34 * This class takes care of of all the rest:
     35 * -# informing QtMoleculeList about required update ("dirty")
     36 * -# relaying updateState() call from QtMoleculeList to the specific internal_updateState()
     37 */
    2738class QtMoleculeItem : public QStandardItem, public Observer
    2839{
    2940public:
    30   QtMoleculeItem(const molecule *_mol);
     41  //!> typedef for a list of notification channels required, to know when to update
     42  typedef std::list<molecule::NotificationType> channellist_t;
     43
     44  //!> enum states whether an item's formula changed or not
     45  enum MoveTypes {
     46    NeedsMove,
     47    DoesNotMove
     48  };
     49
     50  //!> typedef for callback function to model to inform when we need update
     51  typedef const boost::function<void (QtMoleculeItem*, enum MoveTypes)> emitDirtyState_t;
     52
     53  QtMoleculeItem(
     54      const molecule *_mol,
     55      const channellist_t &_channellist,
     56      const enum MoveTypes _movetype,
     57      const emitDirtyState_t _emitDirtyState);
    3158  virtual ~QtMoleculeItem();
    3259
    33   static const int COLUMNCOUNT;
    34   enum {NAME,VISIBILITY,ATOMCOUNT,FORMULA,OCCURRENCE,COLUMNTYPES_MAX} COLUMNTYPES;
    35   static const char *COLUMNNAMES[];
     60  /** Update the state of this item.
     61   *
     62   */
     63  void updateState();
     64
     65private:
     66  void update(Observable *publisher);
     67  void recieveNotification(Observable *publisher, Notification_ptr notification);
     68  void subjectKilled(Observable *publisher);
     69
     70  void signOnToMolecule();
     71  void signOffFromMolecule();
    3672
    3773protected:
    38   virtual void update(Observable *publisher);
    39   virtual void recieveNotification(Observable *publisher, Notification_ptr notification);
    40   virtual void subjectKilled(Observable *publisher);
     74  /** This function needs to be implemented to make the specific update.
     75   *
     76   */
     77  virtual void internal_updateState() = 0;
     78
     79  //!> molecule we are signed on to
     80  const molecule *mol;
    4181
    4282private:
    43   //!> molecule we are signed on to
    44   const molecule *mol;
     83  //!> move type for this specific item, set this when implementing
     84  const enum MoveTypes movetype;
     85
     86  //!> ref to the specific static list of channels we are signed on to
     87  const channellist_t &channellist;
     88
    4589  //!> states whether we are still signed on to molecule
    4690  bool IsSignedOn;
     91
     92  //!> states that this item needs to be updated
     93  bool dirty;
     94
     95  //!> bound callback function to inform model about change
     96  const emitDirtyState_t emitDirtyState;
    4797};
    4898
  • src/UIElements/Views/Qt4/MoleculeList/QtMoleculeItemFactory.cpp

    rbed759 r6d1e0a  
    3333#endif
    3434
     35#include "QtMoleculeItemFactory.hpp"
     36
     37#include "UIElements/Views/Qt4/MoleculeList/QtMoleculeItem.hpp"
     38#include "UIElements/Views/Qt4/MoleculeList/SpecificItems/QtMoleculeItem_atomcount.hpp"
     39#include "UIElements/Views/Qt4/MoleculeList/SpecificItems/QtMoleculeItem_formula.hpp"
     40#include "UIElements/Views/Qt4/MoleculeList/SpecificItems/QtMoleculeItem_name.hpp"
     41#include "UIElements/Views/Qt4/MoleculeList/SpecificItems/QtMoleculeItem_occurrence.hpp"
     42#include "UIElements/Views/Qt4/MoleculeList/SpecificItems/QtMoleculeItem_visibility.hpp"
     43
    3544#include "CodePatterns/MemDebug.hpp"
    3645
    37 #include "QtMoleculeItemFactory.hpp"
     46#include "CodePatterns/Singleton_impl.hpp"
    3847
     48#include <boost/assign.hpp>
    3949
     50#include "molecule.hpp"
    4051
     52using namespace boost::assign;
     53
     54// instantiate static items of specific QtMoleculeItems
     55const QtMoleculeItem::channellist_t QtMoleculeItem_atomcount::channellist_atomcount;
     56const QtMoleculeItem::channellist_t QtMoleculeItem_formula::channellist_formula;
     57const QtMoleculeItem::channellist_t QtMoleculeItem_name::channellist_name;
     58const QtMoleculeItem::channellist_t QtMoleculeItem_occurrence::channellist_occurrence;
     59const QtMoleculeItem::channellist_t QtMoleculeItem_visibility::channellist_visibility;
     60
     61// some attributes need to be easier to find for molecules
     62// these attributes are skipped so far
     63const int
     64QtMoleculeItemFactory::COLUMNCOUNT =
     65    COLUMNTYPES_MAX;
     66const char *
     67QtMoleculeItemFactory::COLUMNNAMES[QtMoleculeItemFactory::COLUMNCOUNT] =
     68    {"Name","Visibility", "Atoms","Formula","Occurrence"/*,"Size"*/};
     69
     70QtMoleculeItemFactory::QtMoleculeItemFactory()
     71{
     72  // fill all the static channels lists
     73  const_cast<QtMoleculeItem::channellist_t &>(
     74      QtMoleculeItem_name::channellist_name) +=
     75          molecule::MoleculeNameChanged;
     76  const_cast<QtMoleculeItem::channellist_t &>(
     77      QtMoleculeItem_atomcount::channellist_atomcount) +=
     78          molecule::AtomInserted,
     79          molecule::AtomRemoved;
     80  const_cast<QtMoleculeItem::channellist_t &>(
     81      QtMoleculeItem_formula::channellist_formula) =
     82          QtMoleculeItem_atomcount::channellist_atomcount;
     83}
     84
     85QList<QStandardItem *>
     86QtMoleculeItemFactory::createMoleculeItems(
     87    const molecule *_mol,
     88    const QtMoleculeItem::emitDirtyState_t &_emitDirtyState)
     89{
     90  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);
     96  return molItems;
     97}
     98
     99QList<QStandardItem *>
     100QtMoleculeItemFactory::createGroupItems(const std::string &_formula)
     101{
     102  QList<QStandardItem *> groupItems;
     103  // fill item list
     104  QStandardItem *mainitem = new QStandardItem(QString(""));
     105  mainitem->setFlags(mainitem->flags() ^ Qt::ItemIsSelectable);
     106  groupItems << mainitem;
     107
     108  QStandardItem *visitem = new QStandardItem;
     109  visitem->setCheckState(Qt::Unchecked);
     110  visitem->setFlags((visitem->flags() | Qt::ItemIsUserCheckable) ^ Qt::ItemIsSelectable);
     111  groupItems << visitem;
     112
     113  QStandardItem *count_item = new QStandardItem(QString::number(0));
     114  count_item->setFlags(count_item->flags() ^ Qt::ItemIsSelectable);
     115  groupItems << count_item;
     116
     117  QStandardItem *formula_item = new QStandardItem(QString(""));
     118  formula_item->setFlags(formula_item->flags() ^ Qt::ItemIsSelectable);
     119  groupItems << formula_item;
     120
     121  QStandardItem *occ_item = new QStandardItem(QString::number(0));
     122  occ_item->setFlags(occ_item->flags() ^ Qt::ItemIsSelectable);
     123  groupItems << occ_item;
     124
     125  return groupItems;
     126}
     127
     128CONSTRUCT_SINGLETON(QtMoleculeItemFactory)
  • src/UIElements/Views/Qt4/MoleculeList/QtMoleculeItemFactory.hpp

    rbed759 r6d1e0a  
    1414#endif
    1515
    16 class QtMoleculeItemFactory
     16#include "CodePatterns/Singleton.hpp"
     17
     18#include <QList>
     19
     20#include <string>
     21
     22class molecule;
     23
     24#include "UIElements/Views/Qt4/MoleculeList/QtMoleculeItem.hpp"
     25
     26/** This class is a factory for a list of QtMoleculeItem's.
     27 *
     28 * QtMoleculeList contains these per row, either a group item which combines
     29 * molecules of the same formula, or a molecule item which represents a single
     30 * molecule.
     31 */
     32class QtMoleculeItemFactory : public Singleton<QtMoleculeItemFactory>
    1733{
     34  //!> grant Singleton access to cstor and dstor.
     35  friend class Singleton<QtMoleculeItemFactory>;
     36private:
     37  // private constructor and destructor due to singleton
     38  QtMoleculeItemFactory();
     39  virtual ~QtMoleculeItemFactory() {}
    1840
     41public:
     42  static const int COLUMNCOUNT;
     43  enum {NAME,VISIBILITY,ATOMCOUNT,FORMULA,OCCURRENCE,COLUMNTYPES_MAX} COLUMNTYPES;
     44  static const char *COLUMNNAMES[];
     45
     46  /** Creates all QtMoleculeItem's that make up the row for a single molecule.
     47   *
     48   * \param _mol ref to molecule which is stored internally
     49   * \param _emitDirtyState callback function to model to inform about required state update
     50   * \return list of prepared items to be appended to a group item
     51   */
     52  QList<QStandardItem *> createMoleculeItems(
     53      const molecule *_mol,
     54      const QtMoleculeItem::emitDirtyState_t &_emitDirtyState);
     55
     56  /** Creates all QtMoleculeItem's that make up a row of a group item.
     57   *
     58   * \param _formula chemical formula which describes all molecules in this group
     59   * \return list of prepared items to be appended to the invisibleRootItem()
     60   */
     61  QList<QStandardItem *> createGroupItems(const std::string &_formula);
    1962};
    2063
Note: See TracChangeset for help on using the changeset viewer.