- 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)
- File:
-
- 1 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 }
Note:
See TracChangeset
for help on using the changeset viewer.