Ignore:
Timestamp:
Apr 20, 2016, 8:51:51 AM (9 years ago)
Author:
Frederik Heber <heber@…>
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)
Message:

QtObserved...Observed now get index on ...Removed() signal.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/UIElements/Views/Qt4/MoleculeList/QtMoleculeListView.cpp

    r1a58ce r3054f4a  
    4242#include "CodePatterns/MemDebug.hpp"
    4343
    44 #include "CodePatterns/Observer/Notification.hpp"
    45 
    4644#include "Actions/SelectionAction/Molecules/MoleculeByIdAction.hpp"
    4745#include "Actions/SelectionAction/Molecules/NotMoleculeByIdAction.hpp"
    48 #include "MoleculeObserver.hpp"
    4946#include "molecule.hpp"
    5047#include "World.hpp"
     
    5249QtMoleculeListView::QtMoleculeListView(QWidget * _parent) :
    5350  QTreeView(_parent),
    54   Observer("QtMoleculeListView"),
    5551  selecting(false)
    5652{
     
    5854
    5955  qRegisterMetaType<QItemSelection>("QItemSelection");
    60 
    61   MoleculeObserver::getInstance().signOn(this, molecule::SelectionChanged);
    6256}
    6357
    6458QtMoleculeListView::~QtMoleculeListView()
    6559{
    66   MoleculeObserver::getInstance().signOff(this, molecule::SelectionChanged);
    6760}
    6861
     
    7467      selectionModel(), SIGNAL(selectionChanged(const QItemSelection &, const QItemSelection &)),
    7568      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}
    8073
    8174QModelIndex QtMoleculeListView::setIndexToLastColumn(const QModelIndex &_index) const
     
    110103    foreach (index, items)
    111104      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));
    113107        const molecule * const mol = const_cast<const World &>(World::getInstance()).
    114108            getMolecule(MoleculeById(mol_id));
     
    134128    foreach (index, items)
    135129      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));
    137132        const molecule * const mol = const_cast<const World &>(World::getInstance()).
    138133            getMolecule(MoleculeById(mol_id));
     
    154149}
    155150
    156 void QtMoleculeListView::MoleculeSelected(const moleculeId_t _id)
     151void QtMoleculeListView::selectionChanged(const QtObservedMolecule::ptr _molecule)
     152{
     153  if (_molecule->getMolSelected())
     154    MoleculeSelected(_molecule->getIndex());
     155  else
     156    MoleculeUnselected(_molecule->getIndex());
     157}
     158
     159void QtMoleculeListView::MoleculeSelected(ObservedValue_Index_t _id)
    157160{
    158161  if (selecting)
     
    166169//    ASSERT( !selectionModel()->isSelected(index),
    167170//        "QtMoleculeListView::MoleculeSelected() - row to molecule "
    168 //        +toString(_id)+" is already selected.");
     171//        +toString(mol->getMolIndex())+" is already selected.");
    169172
    170173    // select the full row
     
    176179}
    177180
    178 void QtMoleculeListView::MoleculeUnselected(const moleculeId_t _id)
     181void QtMoleculeListView::MoleculeUnselected(ObservedValue_Index_t _id)
    179182{
    180183  if (selecting)
     
    188191//    ASSERT( selectionModel()->isSelected(index),
    189192//        "QtMoleculeListView::MoleculeSelected() - row to molecule "
    190 //        +toString(_id)+" is already unselected.");
     193//        +toString(mol->getMolIndex())+" is already unselected.");
    191194
    192195    // unselect the full row
     
    197200  selecting = false;
    198201}
    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 step
    208         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             else
    223               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         else
    256           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.