Ignore:
Timestamp:
Jan 28, 2015, 7:07:03 PM (10 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:
2696b1
Parents:
53c1ff
git-author:
Frederik Heber <heber@…> (01/18/15 20:01:55)
git-committer:
Frederik Heber <heber@…> (01/28/15 19:07:03)
Message:

Moved rowsSelected() over to QtMoleculeListView.

File:
1 edited

Legend:

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

    r53c1ff rd2dbb5d  
    3636
    3737#include "UIElements/Views/Qt4/MoleculeList/QtMoleculeList.hpp"
     38#include "UIElements/Views/Qt4/MoleculeList/QtMoleculeItemFactory.hpp"
    3839
    3940#include "CodePatterns/MemDebug.hpp"
     
    4142#include "CodePatterns/Observer/Notification.hpp"
    4243
     44#include "Actions/SelectionAction/Molecules/MoleculeByIdAction.hpp"
     45#include "Actions/SelectionAction/Molecules/NotMoleculeByIdAction.hpp"
     46
    4347#include "World.hpp"
    4448
    4549QtMoleculeListView::QtMoleculeListView(QWidget * _parent) :
    46 QTreeView(_parent),
    47   Observer("QtMoleculeListView")
     50  QTreeView(_parent),
     51  Observer("QtMoleculeListView"),
     52  selecting(false)
    4853{
    4954  setSelectionMode(QAbstractItemView::MultiSelection);
     
    6065{
    6166  QTreeView::setModel(_moleculelist);
     67  // clicking a molecule means calling SelectionAction
    6268  connect(
    6369      selectionModel(), SIGNAL(selectionChanged(const QItemSelection &, const QItemSelection &)),
    64       _moleculelist, SLOT(rowsSelected(const QItemSelection &, const QItemSelection &)));
     70      this, SLOT(rowsSelected(const QItemSelection &, const QItemSelection &)));
    6571}
    6672
    6773void QtMoleculeListView::update(Observable *publisher)
    6874{}
     75
     76QModelIndex QtMoleculeListView::setIndexToLastColumn(const QModelIndex &_index) const
     77{
     78  QModelIndex return_index;
     79  QModelIndex parent_index = _index.parent();
     80  ASSERT (parent_index.isValid(),
     81      "QtMoleculeListView::setIndexToLastColumn() - _index has no valid parent.");
     82    return_index = parent_index.child(_index.row(), QtMoleculeItemFactory::OCCURRENCE);
     83//    return_index =
     84//        model()->invisibleRootItem()->child(
     85//            _index.row(),
     86//            QtMoleculeItemFactory::OCCURRENCE)->index();
     87  return return_index;
     88}
     89
     90void QtMoleculeListView::rowsSelected(
     91    const QItemSelection& selected, const QItemSelection& deselected)
     92{
     93  if (selecting)
     94    return;
     95
     96  selecting = true;
     97
     98  // Select all molecules which belong to newly selected rows.
     99  QtMoleculeList *moleculelist = dynamic_cast<QtMoleculeList *>(model());
     100  QModelIndex index;
     101  {
     102    QModelIndexList items = selected.indexes();
     103    molids_t ids;
     104    ids.reserve(items.size());
     105    foreach (index, items)
     106      if ((index.column() == 0) && (selectionModel()->isSelected(index))) {
     107        const molecule *mol = moleculelist->IndexToMolecule(index);
     108        if (mol == NULL) // means we are looking at deselection because of removal
     109          continue;
     110        int mol_id = mol->getId();
     111        // check for invalid molecule
     112        if (mol_id < 0)
     113          continue;
     114        // means we are looking at deselection because of removal (in World)
     115        if (World::getInstance().getMolecule(MoleculeById(mol_id)) != mol)
     116          continue;
     117        if (!World::getInstance().isSelected(mol))
     118            ids.push_back(mol_id);
     119        //std::cout << "select molecule" << std::endl;
     120      }
     121    if (!ids.empty())
     122      MoleCuilder::SelectionMoleculeById(ids);
     123  }
     124
     125  // Unselect all molecules which belong to newly unselected rows.
     126  {
     127    QModelIndexList items = deselected.indexes();
     128    molids_t ids;
     129    ids.reserve(items.size());
     130    foreach (index, items)
     131    if ((index.column() == 0) && (!selectionModel()->isSelected(index))) {
     132        const molecule *mol = moleculelist->IndexToMolecule(index);
     133        if (mol == NULL) // means we are looking at deselection because of removal
     134          continue;
     135        int mol_id = mol->getId();
     136        // check for invalid molecule
     137        if (mol_id < 0)
     138          continue;
     139        // means we are looking at deselection because of removal (in World)
     140        if (World::getInstance().getMolecule(MoleculeById(mol_id)) != mol)
     141          continue;
     142        if (World::getInstance().isSelected(mol))
     143            ids.push_back(mol_id);
     144        //std::cout << "unselect molecule" << std::endl;
     145      }
     146    if (!ids.empty())
     147      MoleCuilder::SelectionNotMoleculeById(ids);
     148  }
     149
     150  selecting = false;
     151}
    69152
    70153void QtMoleculeListView::recieveNotification(Observable *publisher, Notification_ptr notification)
     
    83166        std::set<QModelIndex> already_selected_indices;
    84167        for (std::vector<molecule *>::const_iterator iter = selectedMolecules.begin();
    85             iter != selectedMolecules.begin(); ++iter) {
     168            iter != selectedMolecules.end(); ++iter) {
    86169          QModelIndex mol_index = moleculelist->MoleculeToItem(*iter)->index();
    87170          if (!currently_selected.contains(mol_index))
    88               selected.select(mol_index, mol_index);
     171              selected.select(mol_index, setIndexToLastColumn(mol_index));
    89172          else
    90173            already_selected_indices.insert(mol_index);
     
    96179                already_selected_indices.find(mol_index);
    97180            if (iter == already_selected_indices.end())
    98               deselected.select(mol_index, mol_index);
     181              deselected.select(mol_index, setIndexToLastColumn(mol_index));
    99182          }
    100183        }
    101         selectionChanged(selected, deselected);
     184        selecting = true;
     185        if (!selected.indexes().empty())
     186          selectionModel()->select(selected, QItemSelectionModel::Select);
     187        if (!deselected.indexes().empty())
     188          selectionModel()->select(deselected, QItemSelectionModel::Deselect);
     189        selecting = false;
    102190        break;
    103191      }
Note: See TracChangeset for help on using the changeset viewer.