Changeset 41815a3 for src/UIElements/Views
- Timestamp:
- Jul 17, 2012, 12:17:26 PM (13 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:
- 6966b7
- Parents:
- 99e8ea
- git-author:
- Michael Ankele <ankele@…> (06/14/12 15:40:01)
- git-committer:
- Michael Ankele <ankele@…> (07/17/12 12:17:26)
- Location:
- src/UIElements/Views/Qt4
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
src/UIElements/Views/Qt4/QtWorldView.cpp
r99e8ea r41815a3 19 19 20 20 #include "Views/Qt4/QtWorldView.hpp" 21 22 #include <QMetaMethod> 21 23 22 24 #include <iostream> … … 52 54 setHeaderLabels(header); 53 55 54 molecules = World::getInstance().getMolecules(); 55 molecules->signOn(this); 56 World::getInstance().signOn(this);//, World::MoleculeInserted); 57 //World::getInstance().signOn(this, World::MoleculeRemoved); 58 59 60 //for (int i=0;i<metaObject()->methodCount();i++) 61 // std::cout << metaObject()->method(i).signature() << " - " << metaObject()->method(i).methodType() << "\n"; 62 63 56 64 57 65 dirty = true; 58 66 clearing = false; 67 selecting = false; 59 68 refill(); 60 69 61 70 //connect(this,SIGNAL(cellChanged(int,int)),this,SLOT(moleculeChanged(int,int))); 62 connect( this,SIGNAL(itemSelectionChanged()),this,SLOT(rowSelected()));71 connect(selectionModel(),SIGNAL(selectionChanged(QItemSelection, QItemSelection)),this,SLOT(rowsSelected(QItemSelection, QItemSelection))); 63 72 64 73 } … … 66 75 QtWorldView::~QtWorldView() 67 76 { 68 molecules->signOff(this); 77 World::getInstance().signOff(this);//, World::MoleculeInserted); 78 //World::getInstance().signOff(this, World::MoleculeRemoved); 69 79 } 70 80 71 81 void QtWorldView::update(Observable *publisher) { 82 83 if (selecting) 84 return; 72 85 73 86 dirty = true; … … 80 93 81 94 void QtWorldView::refill() { 82 int numMolecules = molecules->ListOfMolecules.size(); 95 const std::vector<molecule*> &molecules = World::getInstance().getAllMolecules(); 96 83 97 clear(); 84 molSelection.resize(numMolecules);85 98 86 99 // list of (unique) formulas in the world 87 100 std::vector<Formula> formula; 88 101 89 int i; 90 MoleculeList::iterator iter; 91 for(iter = molecules->ListOfMolecules.begin(),i=0; 92 iter != molecules->ListOfMolecules.end(); 93 ++i,++iter) { 102 for (std::vector<molecule*>::const_iterator iter = molecules.begin(); 103 iter != molecules.end(); 104 iter++) { 94 105 95 106 // find group if already in list … … 109 120 groupItem->setText(2, QString((*iter)->getFormula().toString().c_str())); 110 121 groupItem->setText(3, "0"); 122 groupItem->setData(0, Qt::UserRole, QVariant(-1)); 111 123 } 112 124 … … 116 128 molItem->setText(1, QString::number((*iter)->getAtomCount())); 117 129 molItem->setText(2, QString((*iter)->getFormula().toString().c_str())); 118 const int index = (*iter)-> IndexNr;130 const int index = (*iter)->getId(); 119 131 molItem->setData(0, Qt::UserRole, QVariant(index)); 120 132 molItem->setSelected(World::getInstance().isSelected(*iter)); … … 124 136 int count = groupItem->text(3).toInt() + 1; 125 137 groupItem->setText(3, QString::number(count)); 126 127 //molSelection[i]=nameWidget->isSelected();128 138 } 129 139 dirty = false; … … 152 162 } 153 163 154 155 void QtWorldView::rowSelected(){ 164 void QtWorldView::rowsSelected(const QItemSelection & selected, const QItemSelection & deselected){ 156 165 157 166 if (clearing) 158 167 return; 168 if (selecting) 169 return; 170 selecting = true; 159 171 160 // lookup all molecules in the treeWidget 161 for (int i=0;i<topLevelItemCount();i++){ 162 QTreeWidgetItem *top = topLevelItem(i); 163 for (int j=0;j<top->childCount();j++){ 172 // Select all molecules which belong to newly selected rows. 173 QModelIndex index; 174 QModelIndexList items = selected.indexes(); 175 foreach (index, items) 176 if (index.column() == 0){ 177 int mol_id = model()->data(index, Qt::UserRole).toInt(); 178 if (mol_id < 0) 179 continue; 180 //std::cout << "select molecule" << std::endl; 181 MoleCuilder::SelectionMoleculeById(mol_id); 182 } 164 183 165 // molecules are 1 level below the top 166 QTreeWidgetItem *molItem = top->child(j); 184 // Unselect all molecules which belong to newly unselected rows. 185 items = deselected.indexes(); 186 foreach (index, items) 187 if (index.column() == 0){ 188 int mol_id = model()->data(index, Qt::UserRole).toInt(); 189 if (mol_id < 0) 190 continue; 191 //std::cout << "unselect molecule" << std::endl; 192 MoleCuilder::SelectionNotMoleculeById(mol_id); 193 } 167 194 168 // molecule index stored as user data 169 int index = molItem->data(0, Qt::UserRole).toInt(); 170 molecule *mol = molecules->ReturnIndex(index); 171 ASSERT(mol, "QtWorldView::rowSelected()"); 172 173 // selection changed by user? 174 bool molSelectedWorld = World::getInstance().isSelected(mol); 175 bool molSelectedList = molItem->isSelected(); 176 //std::cout << molSelectedWorld << " " << molSelectedList << std::endl; 177 178 if (molSelectedWorld != molSelectedList){ 179 180 // apply new selection state 181 if (molSelectedList){ 182 //std::cout << "select molecule" << std::endl; 183 MoleCuilder::SelectionMoleculeById(mol->getId()); 184 }else{ 185 //std::cout << "unselect molecule" << std::endl; 186 MoleCuilder::SelectionNotMoleculeById(mol->getId()); 187 } 188 } 189 } 190 } 195 selecting = false; 191 196 } -
src/UIElements/Views/Qt4/QtWorldView.hpp
r99e8ea r41815a3 42 42 void moleculeChanged(); 43 43 44 void row Selected();44 void rowsSelected(const QItemSelection & selected, const QItemSelection & deselected); 45 45 46 46 signals: … … 49 49 50 50 private: 51 std::vector<bool> molSelection; //!< needed to determine when a selection changes52 MoleculeListClass *molecules;53 51 bool dirty; 54 52 bool clearing; 53 bool selecting; 55 54 }; 56 55
Note:
See TracChangeset
for help on using the changeset viewer.