Ignore:
Timestamp:
Jul 17, 2012, 12:17:26 PM (13 years ago)
Author:
Michael Ankele <ankele@…>
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)
Message:

QtWorldView: removed usage of MoleculeListClass

File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/UIElements/Views/Qt4/QtWorldView.cpp

    r99e8ea r41815a3  
    1919
    2020#include "Views/Qt4/QtWorldView.hpp"
     21
     22#include <QMetaMethod>
    2123
    2224#include <iostream>
     
    5254  setHeaderLabels(header);
    5355
    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
    5664
    5765  dirty = true;
    5866  clearing = false;
     67  selecting = false;
    5968  refill();
    6069
    6170  //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)));
    6372
    6473}
     
    6675QtWorldView::~QtWorldView()
    6776{
    68   molecules->signOff(this);
     77  World::getInstance().signOff(this);//, World::MoleculeInserted);
     78  //World::getInstance().signOff(this, World::MoleculeRemoved);
    6979}
    7080
    7181void QtWorldView::update(Observable *publisher) {
     82
     83  if (selecting)
     84    return;
    7285
    7386  dirty = true;
     
    8093
    8194void QtWorldView::refill() {
    82   int numMolecules = molecules->ListOfMolecules.size();
     95  const std::vector<molecule*> &molecules = World::getInstance().getAllMolecules();
     96
    8397  clear();
    84   molSelection.resize(numMolecules);
    8598
    8699  // list of (unique) formulas in the world
    87100  std::vector<Formula> formula;
    88101
    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++) {
    94105
    95106    // find group if already in list
     
    109120      groupItem->setText(2, QString((*iter)->getFormula().toString().c_str()));
    110121      groupItem->setText(3, "0");
     122      groupItem->setData(0, Qt::UserRole, QVariant(-1));
    111123    }
    112124
     
    116128    molItem->setText(1, QString::number((*iter)->getAtomCount()));
    117129    molItem->setText(2, QString((*iter)->getFormula().toString().c_str()));
    118     const int index = (*iter)->IndexNr;
     130    const int index = (*iter)->getId();
    119131    molItem->setData(0, Qt::UserRole, QVariant(index));
    120132    molItem->setSelected(World::getInstance().isSelected(*iter));
     
    124136    int count = groupItem->text(3).toInt() + 1;
    125137    groupItem->setText(3, QString::number(count));
    126 
    127     //molSelection[i]=nameWidget->isSelected();
    128138  }
    129139  dirty = false;
     
    152162}
    153163
    154 
    155 void QtWorldView::rowSelected(){
     164void QtWorldView::rowsSelected(const QItemSelection & selected, const QItemSelection & deselected){
    156165
    157166  if (clearing)
    158167    return;
     168  if (selecting)
     169    return;
     170  selecting = true;
    159171
    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    }
    164183
    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    }
    167194
    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;
    191196}
Note: See TracChangeset for help on using the changeset viewer.