Changeset 6d1e0a for src/UIElements/Views
- Timestamp:
- Jan 28, 2015, 7:07:01 PM (10 years ago)
- Branches:
- Action_Thermostats, Add_AtomRandomPerturbation, Add_FitFragmentPartialChargesAction, Add_RotateAroundBondAction, Add_SelectAtomByNameAction, Added_ParseSaveFragmentResults, AddingActions_SaveParseParticleParameters, Adding_Graph_to_ChangeBondActions, Adding_MD_integration_tests, Adding_ParticleName_to_Atom, Adding_StructOpt_integration_tests, AtomFragments, Automaking_mpqc_open, AutomationFragmentation_failures, Candidate_v1.5.4, Candidate_v1.6.0, Candidate_v1.6.1, ChangeBugEmailaddress, ChangingTestPorts, ChemicalSpaceEvaluator, CombiningParticlePotentialParsing, Combining_Subpackages, Debian_Package_split, Debian_package_split_molecuildergui_only, Disabling_MemDebug, Docu_Python_wait, EmpiricalPotential_contain_HomologyGraph, EmpiricalPotential_contain_HomologyGraph_documentation, Enable_parallel_make_install, Enhance_userguide, Enhanced_StructuralOptimization, Enhanced_StructuralOptimization_continued, Example_ManyWaysToTranslateAtom, Exclude_Hydrogens_annealWithBondGraph, FitPartialCharges_GlobalError, Fix_BoundInBox_CenterInBox_MoleculeActions, Fix_ChargeSampling_PBC, Fix_ChronosMutex, Fix_FitPartialCharges, Fix_FitPotential_needs_atomicnumbers, Fix_ForceAnnealing, Fix_IndependentFragmentGrids, Fix_ParseParticles, Fix_ParseParticles_split_forward_backward_Actions, Fix_PopActions, Fix_QtFragmentList_sorted_selection, Fix_Restrictedkeyset_FragmentMolecule, Fix_StatusMsg, Fix_StepWorldTime_single_argument, Fix_Verbose_Codepatterns, Fix_fitting_potentials, Fixes, ForceAnnealing_goodresults, ForceAnnealing_oldresults, ForceAnnealing_tocheck, ForceAnnealing_with_BondGraph, ForceAnnealing_with_BondGraph_continued, ForceAnnealing_with_BondGraph_continued_betteresults, ForceAnnealing_with_BondGraph_contraction-expansion, FragmentAction_writes_AtomFragments, FragmentMolecule_checks_bonddegrees, GeometryObjects, Gui_Fixes, Gui_displays_atomic_force_velocity, ImplicitCharges, IndependentFragmentGrids, IndependentFragmentGrids_IndividualZeroInstances, IndependentFragmentGrids_IntegrationTest, IndependentFragmentGrids_Sole_NN_Calculation, JobMarket_RobustOnKillsSegFaults, JobMarket_StableWorkerPool, JobMarket_unresolvable_hostname_fix, MoreRobust_FragmentAutomation, ODR_violation_mpqc_open, PartialCharges_OrthogonalSummation, PdbParser_setsAtomName, PythonUI_with_named_parameters, QtGui_reactivate_TimeChanged_changes, Recreated_GuiChecks, Rewrite_FitPartialCharges, RotateToPrincipalAxisSystem_UndoRedo, SaturateAtoms_findBestMatching, SaturateAtoms_singleDegree, StoppableMakroAction, Subpackage_CodePatterns, Subpackage_JobMarket, Subpackage_LinearAlgebra, Subpackage_levmar, Subpackage_mpqc_open, Subpackage_vmg, Switchable_LogView, ThirdParty_MPQC_rebuilt_buildsystem, TrajectoryDependenant_MaxOrder, TremoloParser_IncreasedPrecision, TremoloParser_MultipleTimesteps, TremoloParser_setsAtomName, Ubuntu_1604_changes, stable
- Children:
- 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)
- Location:
- src/UIElements/Views/Qt4/MoleculeList
- Files:
-
- 5 added
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
src/UIElements/Views/Qt4/MoleculeList/QtMoleculeItem.cpp
rbed759 r6d1e0a 43 43 #include "CodePatterns/Observer/Notification.hpp" 44 44 45 #include <algorithm> 46 45 47 #include "molecule.hpp" 46 48 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) 49 QtMoleculeItem::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) 54 61 { 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); 70 64 } 71 65 72 QtMoleculeItem::QtMoleculeItem(const molecule *_mol) : 73 Observer("QtMoleculeItem"), 74 mol(_mol), 75 IsSignedOn(false) 66 void QtMoleculeItem::signOnToMolecule() 76 67 { 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); 80 72 IsSignedOn = true; 73 } 74 75 void 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; 81 82 } 82 83 83 84 QtMoleculeItem::~QtMoleculeItem() 84 85 { 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 89 void QtMoleculeItem::updateState() 90 { 91 if (dirty) { 92 internal_updateState(); 93 dirty = false; 89 94 } 90 95 } 91 92 96 93 97 void QtMoleculeItem::update(Observable *publisher) … … 97 101 { 98 102 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."); 115 118 } 116 case molecule::MoleculeNameChanged:117 {118 // change name119 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;127 119 } 128 120 } -
src/UIElements/Views/Qt4/MoleculeList/QtMoleculeItem.hpp
rbed759 r6d1e0a 19 19 #include "CodePatterns/Observer/Observer.hpp" 20 20 21 #include <boost/function.hpp> 22 #include <list> 21 23 #include <string> 22 24 23 class molecule; 25 #include "molecule.hpp" 24 26 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 */ 27 38 class QtMoleculeItem : public QStandardItem, public Observer 28 39 { 29 40 public: 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); 31 58 virtual ~QtMoleculeItem(); 32 59 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 65 private: 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(); 36 72 37 73 protected: 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; 41 81 42 82 private: 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 45 89 //!> states whether we are still signed on to molecule 46 90 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; 47 97 }; 48 98 -
src/UIElements/Views/Qt4/MoleculeList/QtMoleculeItemFactory.cpp
rbed759 r6d1e0a 33 33 #endif 34 34 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 35 44 #include "CodePatterns/MemDebug.hpp" 36 45 37 #include " QtMoleculeItemFactory.hpp"46 #include "CodePatterns/Singleton_impl.hpp" 38 47 48 #include <boost/assign.hpp> 39 49 50 #include "molecule.hpp" 40 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 61 // some attributes need to be easier to find for molecules 62 // these attributes are skipped so far 63 const int 64 QtMoleculeItemFactory::COLUMNCOUNT = 65 COLUMNTYPES_MAX; 66 const char * 67 QtMoleculeItemFactory::COLUMNNAMES[QtMoleculeItemFactory::COLUMNCOUNT] = 68 {"Name","Visibility", "Atoms","Formula","Occurrence"/*,"Size"*/}; 69 70 QtMoleculeItemFactory::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 85 QList<QStandardItem *> 86 QtMoleculeItemFactory::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 99 QList<QStandardItem *> 100 QtMoleculeItemFactory::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 128 CONSTRUCT_SINGLETON(QtMoleculeItemFactory) -
src/UIElements/Views/Qt4/MoleculeList/QtMoleculeItemFactory.hpp
rbed759 r6d1e0a 14 14 #endif 15 15 16 class QtMoleculeItemFactory 16 #include "CodePatterns/Singleton.hpp" 17 18 #include <QList> 19 20 #include <string> 21 22 class 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 */ 32 class QtMoleculeItemFactory : public Singleton<QtMoleculeItemFactory> 17 33 { 34 //!> grant Singleton access to cstor and dstor. 35 friend class Singleton<QtMoleculeItemFactory>; 36 private: 37 // private constructor and destructor due to singleton 38 QtMoleculeItemFactory(); 39 virtual ~QtMoleculeItemFactory() {} 18 40 41 public: 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); 19 62 }; 20 63
Note:
See TracChangeset
for help on using the changeset viewer.