Changeset 6770fa for src/UIElements/Views
- Timestamp:
- Jan 27, 2015, 5:18:30 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:
- 8ccf3b
- Parents:
- 0a5beb
- git-author:
- Frederik Heber <heber@…> (12/12/14 19:43:05)
- git-committer:
- Frederik Heber <heber@…> (01/27/15 17:18:30)
- Location:
- src/UIElements/Views/Qt4
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
src/UIElements/Views/Qt4/QtMoleculeList.cpp
r0a5beb r6770fa 40 40 41 41 #include "CodePatterns/MemDebug.hpp" 42 43 #include "CodePatterns/Observer/Notification.hpp" 42 44 43 45 #include "Atom/atom.hpp" … … 76 78 clearing = false; 77 79 selecting = false; 80 changing = false; 78 81 ChangingChildrensVisibility = false; 79 82 refill(); … … 96 99 } 97 100 98 void QtMoleculeList::recieveNotification(Observable *publisher, Notification_ptr notification) { 101 void QtMoleculeList::recieveNotification(Observable *publisher, Notification_ptr notification) 102 { 103 if (dynamic_cast<World *>(publisher) != NULL) { 104 switch (notification->getChannelNo()) { 105 case World::MoleculeInserted: 106 { 107 const molecule * const mol = World::getInstance().lastChanged<molecule>(); 108 addItem(mol); 109 break; 110 } 111 case World::MoleculeRemoved: 112 { 113 const molecule * const mol = World::getInstance().lastChanged<molecule>(); 114 removeItem(mol); 115 break; 116 } 117 default: 118 ASSERT(0, "QtMoleculeList::recieveNotification() - cannot get here, not subscribed to channel " 119 +toString(notification->getChannelNo())); 120 break; 121 } 122 } 99 123 100 124 if (selecting) … … 104 128 } 105 129 130 void QtMoleculeList::addGroupItem( 131 QTreeWidgetItem *&_groupItem, 132 const std::string &_molecule_formula) 133 { 134 _groupItem = new QTreeWidgetItem(this); 135 formula.insert( std::make_pair(_molecule_formula, _groupItem) ); 136 // fill item 137 _groupItem->setText(NAME, QString("default")); 138 _groupItem->setFlags((_groupItem->flags() | Qt::ItemIsUserCheckable) ^ Qt::ItemIsSelectable); 139 _groupItem->setCheckState(VISIBILITY, Qt::Unchecked); 140 _groupItem->setText(ATOMCOUNT, QString::number(0)); 141 _groupItem->setText(FORMULA, QString("")); 142 _groupItem->setText(OCCURRENCE, "0"); 143 _groupItem->setData(0, Qt::UserRole, QVariant(-1)); 144 } 145 146 void QtMoleculeList::addMoleculeItem( 147 QTreeWidgetItem *&_groupItem, 148 const molecule *_mol, 149 const std::string &_molecule_formula) 150 { 151 QTreeWidgetItem *molItem = new QTreeWidgetItem(_groupItem); 152 molItem->setText(NAME, QString(_mol->getName().c_str())); 153 molItem->setFlags(molItem->flags() | Qt::ItemIsUserCheckable | Qt::ItemIsSelectable); 154 molItem->setCheckState(VISIBILITY, Qt::Unchecked); 155 molItem->setText(ATOMCOUNT, QString::number(_mol->getAtomCount())); 156 molItem->setText(FORMULA, QString(_molecule_formula.c_str())); 157 const int index = _mol->getId(); 158 molItem->setData(0, Qt::UserRole, QVariant(index)); 159 molItem->setSelected(World::getInstance().isSelected(_mol)); 160 } 161 162 void QtMoleculeList::addItem(const molecule *_mol) 163 { 164 if (changing) 165 return; 166 changing = true; 167 // find group if already in list 168 QTreeWidgetItem *groupItem = NULL; 169 170 const std::string &molecule_formula = _mol->getFormula().toString(); 171 FormulaTreeItemMap_t::const_iterator formulaiter = 172 formula.find(molecule_formula); 173 174 // new molecule type -> create new group 175 if (formulaiter == formula.end()){ 176 // insert new formula entry into visibility 177 #ifndef NDEBUG 178 std::pair< FormulaVisibilityCountMap_t::iterator, bool> visibilityinserter = 179 #endif 180 FormulaVisibilityCountMap.insert( 181 std::make_pair( molecule_formula, (unsigned int)0) ); 182 ASSERT( visibilityinserter.second, 183 "QtMoleculeList::refill() - molecule with formula " 184 +molecule_formula+" already in FormulaVisibilityCountMap."); 185 186 // create item and place into Map with formula as key 187 addGroupItem(groupItem, molecule_formula); 188 } else { 189 groupItem = formulaiter->second; 190 } 191 ASSERT( groupItem != NULL, 192 "QtMoleculeList::addItem() - item with id "+toString(_mol->getId()) 193 +" has not parent?"); 194 195 // add molecule 196 addMoleculeItem(groupItem, _mol, molecule_formula); 197 198 // increase group occurrence 199 int count = groupItem->text(OCCURRENCE).toInt() + 1; 200 groupItem->setText(OCCURRENCE, QString::number(count)); 201 202 changing = false; 203 } 204 205 void QtMoleculeList::removeItem(const molecule *_mol) 206 { 207 if (changing) 208 return; 209 changing = true; 210 211 dirty = true; 212 // TODO: We have to get some Model into the Table in order to "find" items right 213 // away 214 // QTreeWidgetItem *molItem = itemFromIndex(mol->getId()); 215 // delete molItem1; 216 217 changing = false; 218 } 106 219 107 220 void QtMoleculeList::refill() { … … 117 230 iter++) { 118 231 119 // find group if already in list 120 QTreeWidgetItem *groupItem = NULL; 121 const std::string &molecule_formula = (*iter)->getFormula().toString(); 122 FormulaTreeItemMap_t::const_iterator formulaiter = 123 formula.find(molecule_formula); 124 125 // new molecule type -> create new group 126 if (formulaiter == formula.end()){ 127 // insert new formula entry into visibility 128 #ifndef NDEBUG 129 std::pair< FormulaVisibilityCountMap_t::iterator, bool> visibilityinserter = 130 #endif 131 FormulaVisibilityCountMap.insert( 132 std::make_pair( molecule_formula, (unsigned int)0) ); 133 ASSERT( visibilityinserter.second, 134 "QtMoleculeList::refill() - molecule with formula " 135 +molecule_formula+" already in FormulaVisibilityCountMap."); 136 137 // create item and place into Map with formula as key 138 groupItem = new QTreeWidgetItem(this); 139 formula.insert( std::make_pair(molecule_formula, groupItem) ); 140 // fill item 141 groupItem->setText(NAME, QString("default")); 142 groupItem->setFlags((groupItem->flags() | Qt::ItemIsUserCheckable) ^ Qt::ItemIsSelectable); 143 groupItem->setCheckState(VISIBILITY, Qt::Unchecked); 144 groupItem->setText(ATOMCOUNT, QString::number(0)); 145 groupItem->setText(FORMULA, QString("")); 146 groupItem->setText(OCCURRENCE, "0"); 147 groupItem->setData(0, Qt::UserRole, QVariant(-1)); 148 } else { 149 groupItem = formulaiter->second; 150 } 151 152 // add molecule 153 QTreeWidgetItem *molItem = new QTreeWidgetItem(groupItem); 154 molItem->setText(NAME, QString((*iter)->getName().c_str())); 155 molItem->setFlags(molItem->flags() | Qt::ItemIsUserCheckable | Qt::ItemIsSelectable); 156 molItem->setCheckState(VISIBILITY, Qt::Unchecked); 157 molItem->setText(ATOMCOUNT, QString::number((*iter)->getAtomCount())); 158 molItem->setText(FORMULA, QString(molecule_formula.c_str())); 159 const int index = (*iter)->getId(); 160 molItem->setData(0, Qt::UserRole, QVariant(index)); 161 molItem->setSelected(World::getInstance().isSelected(*iter)); 162 163 // increase group occurrence 164 int count = groupItem->text(OCCURRENCE).toInt() + 1; 165 groupItem->setText(OCCURRENCE, QString::number(count)); 232 addItem(*iter); 166 233 } 167 234 dirty = false; … … 181 248 void QtMoleculeList::visibilityChanged(QTreeWidgetItem* item, int column) 182 249 { 183 if ((!c learing) && (!ChangingChildrensVisibility))250 if ((!changing) && (!clearing) && (!ChangingChildrensVisibility)) 184 251 if (column == VISIBILITY) { 185 252 const moleculeId_t molid = item->data(0, Qt::UserRole).toInt(); 186 253 const bool visible = item->checkState(VISIBILITY); 187 254 if (molid != (unsigned int)-1) { // molecule item 188 const molecule * const _molecule = 189 World::getInstance().getMolecule(MoleculeById(molid)); 255 World::MoleculeConstIterator moliter = 256 const_cast<const World &>(World::getInstance()).getMoleculeIter(MoleculeById(molid)); 257 const molecule * const _molecule = *moliter; 190 258 ASSERT( _molecule != NULL, 191 259 "QtMoleculeList::visibilityChanged() - molecule with id " -
src/UIElements/Views/Qt4/QtMoleculeList.hpp
r0a5beb r6770fa 60 60 bool clearing; 61 61 bool selecting; 62 bool changing; 62 63 bool ChangingChildrensVisibility; 64 65 void addItem(const molecule *_mol); 66 void addGroupItem(QTreeWidgetItem *&_groupItem, const std::string &_molecule_formula); 67 void addMoleculeItem(QTreeWidgetItem *&_groupItem, const molecule *_mol, const std::string &molecule_formula); 68 void removeItem(const molecule *_mol); 63 69 64 70 typedef std::map<std::string, unsigned int> FormulaVisibilityCountMap_t;
Note:
See TracChangeset
for help on using the changeset viewer.