- Timestamp:
- Apr 20, 2016, 8:51:51 AM (9 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:
- 0a558d
- Parents:
- 1a58ce
- git-author:
- Frederik Heber <heber@…> (03/21/16 21:13:43)
- git-committer:
- Frederik Heber <heber@…> (04/20/16 08:51:51)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
src/UIElements/Views/Qt4/MoleculeList/QtMoleculeListView.cpp
r1a58ce r3054f4a 42 42 #include "CodePatterns/MemDebug.hpp" 43 43 44 #include "CodePatterns/Observer/Notification.hpp"45 46 44 #include "Actions/SelectionAction/Molecules/MoleculeByIdAction.hpp" 47 45 #include "Actions/SelectionAction/Molecules/NotMoleculeByIdAction.hpp" 48 #include "MoleculeObserver.hpp"49 46 #include "molecule.hpp" 50 47 #include "World.hpp" … … 52 49 QtMoleculeListView::QtMoleculeListView(QWidget * _parent) : 53 50 QTreeView(_parent), 54 Observer("QtMoleculeListView"),55 51 selecting(false) 56 52 { … … 58 54 59 55 qRegisterMetaType<QItemSelection>("QItemSelection"); 60 61 MoleculeObserver::getInstance().signOn(this, molecule::SelectionChanged);62 56 } 63 57 64 58 QtMoleculeListView::~QtMoleculeListView() 65 59 { 66 MoleculeObserver::getInstance().signOff(this, molecule::SelectionChanged);67 60 } 68 61 … … 74 67 selectionModel(), SIGNAL(selectionChanged(const QItemSelection &, const QItemSelection &)), 75 68 this, SLOT(rowsSelected(const QItemSelection &, const QItemSelection &)), Qt::DirectConnection); 76 } 77 78 void QtMoleculeListView::update(Observable *publisher) 79 {}69 70 connect(&_moleculelist->observer, SIGNAL(SelectionChanged(QtObservedMolecule::ptr)), 71 this, SLOT(selectionChanged(QtObservedMolecule::ptr))); 72 } 80 73 81 74 QModelIndex QtMoleculeListView::setIndexToLastColumn(const QModelIndex &_index) const … … 110 103 foreach (index, items) 111 104 if ((index.column() == 0) && (selectionModel()->isSelected(index))) { 112 const moleculeId_t mol_id = moleculelist->IndexToMoleculeId(index); 105 const moleculeId_t mol_id = moleculelist->observer.getIdtoIndex( 106 moleculelist->IndexToMoleculeId(index)); 113 107 const molecule * const mol = const_cast<const World &>(World::getInstance()). 114 108 getMolecule(MoleculeById(mol_id)); … … 134 128 foreach (index, items) 135 129 if ((index.column() == 0) && (!selectionModel()->isSelected(index))) { 136 const moleculeId_t mol_id = moleculelist->IndexToMoleculeId(index); 130 const moleculeId_t mol_id = moleculelist->observer.getIdtoIndex( 131 moleculelist->IndexToMoleculeId(index)); 137 132 const molecule * const mol = const_cast<const World &>(World::getInstance()). 138 133 getMolecule(MoleculeById(mol_id)); … … 154 149 } 155 150 156 void QtMoleculeListView::MoleculeSelected(const moleculeId_t _id) 151 void QtMoleculeListView::selectionChanged(const QtObservedMolecule::ptr _molecule) 152 { 153 if (_molecule->getMolSelected()) 154 MoleculeSelected(_molecule->getIndex()); 155 else 156 MoleculeUnselected(_molecule->getIndex()); 157 } 158 159 void QtMoleculeListView::MoleculeSelected(ObservedValue_Index_t _id) 157 160 { 158 161 if (selecting) … … 166 169 // ASSERT( !selectionModel()->isSelected(index), 167 170 // "QtMoleculeListView::MoleculeSelected() - row to molecule " 168 // +toString( _id)+" is already selected.");171 // +toString(mol->getMolIndex())+" is already selected."); 169 172 170 173 // select the full row … … 176 179 } 177 180 178 void QtMoleculeListView::MoleculeUnselected( const moleculeId_t _id)181 void QtMoleculeListView::MoleculeUnselected(ObservedValue_Index_t _id) 179 182 { 180 183 if (selecting) … … 188 191 // ASSERT( selectionModel()->isSelected(index), 189 192 // "QtMoleculeListView::MoleculeSelected() - row to molecule " 190 // +toString( _id)+" is already unselected.");193 // +toString(mol->getMolIndex())+" is already unselected."); 191 194 192 195 // unselect the full row … … 197 200 selecting = false; 198 201 } 199 200 201 void QtMoleculeListView::recieveNotification(Observable *publisher, Notification_ptr notification)202 {203 if (dynamic_cast<World *>(publisher) != NULL) {204 switch (notification->getChannelNo()) {205 case World::SelectionChanged:206 {207 // obtain molecule selection from World and go through our selection step by step208 const std::vector<const molecule *> selectedMolecules =209 const_cast<const World &>(World::getInstance()).getSelectedMolecules();210 QItemSelection currently_selected = selectionModel()->selection();211 QtMoleculeList *moleculelist = static_cast<QtMoleculeList *>(model());212 QItemSelection selected;213 QItemSelection deselected;214 std::set<QModelIndex> already_selected_indices;215 for (std::vector<const molecule *>::const_iterator iter = selectedMolecules.begin();216 iter != selectedMolecules.end(); ++iter) {217 if (moleculelist->isMoleculeItemPresent((*iter)->getId())) {218 QtMoleculeItem *item = moleculelist->MoleculeIdToItem((*iter)->getId());219 QModelIndex mol_index = item->index();220 if (!currently_selected.contains(mol_index))221 selected.select(mol_index, setIndexToLastColumn(mol_index));222 else223 already_selected_indices.insert(mol_index);224 }225 }226 {227 QModelIndex mol_index;228 foreach(mol_index, currently_selected.indexes()) {229 std::set<QModelIndex>::const_iterator iter =230 already_selected_indices.find(mol_index);231 if (iter == already_selected_indices.end())232 deselected.select(mol_index, setIndexToLastColumn(mol_index));233 }234 }235 selecting = true;236 if (!selected.indexes().empty())237 selectionModel()->select(selected, QItemSelectionModel::Select);238 if (!deselected.indexes().empty())239 selectionModel()->select(deselected, QItemSelectionModel::Deselect);240 selecting = false;241 break;242 }243 default:244 ASSERT(0, "QtMoleculeListView::recieveNotification() - cannot get here, not subscribed to World's channel "245 +toString(notification->getChannelNo()));246 break;247 }248 } else if (dynamic_cast<molecule*>(publisher) != NULL) {249 const molecule * const mol = dynamic_cast<molecule *>(publisher);250 switch (notification->getChannelNo()) {251 case molecule::SelectionChanged:252 {253 if (mol->getSelected())254 MoleculeSelected(mol->getId());255 else256 MoleculeUnselected(mol->getId());257 break;258 }259 default:260 ASSERT(0, "QtMoleculeListView::recieveNotification() - cannot get here, not subscribed to mol's channel "261 +toString(notification->getChannelNo()));262 break;263 }264 } else {265 ASSERT(0,266 "QtMoleculeListView::recieveNotification() - cannot get here, unknown publisher "+toString(publisher));267 }268 }269 270 void QtMoleculeListView::subjectKilled(Observable *publisher)271 {}
Note:
See TracChangeset
for help on using the changeset viewer.