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:
2050b2
Parents:
d2dbb5d
git-author:
Frederik Heber <heber@…> (01/22/15 23:05:47)
git-committer:
Frederik Heber <heber@…> (01/28/15 19:07:03)
Message:

Visibility checkstate is working for molecule and group item.

  • signals are emitted and states are correctly changed, tested on amylose molecule in a box filled with ~3000 water molecules.
Location:
src/UIElements/Views/Qt4/MoleculeList
Files:
2 edited

Legend:

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

    rd2dbb5d r2696b1  
    3636
    3737#include <QModelIndex>
     38#include <QDebug>
    3839
    3940#include "UIElements/Views/Qt4/MoleculeList/QtMoleculeItem.hpp"
     
    7677  //connect(this,SIGNAL(cellChanged(int,int)),this,SLOT(moleculeChanged(int,int)));
    7778//  connect(selectionModel(),SIGNAL(selectionChanged(QItemSelection, QItemSelection)),this,SLOT(rowsSelected(QItemSelection, QItemSelection)));
    78 //  connect(this, SIGNAL(itemChanged(QStandardItem*, int)), this, SLOT(visibilityChanged(QStandardItem*, int)));
     79  connect(this, SIGNAL(itemChanged(QStandardItem*)), this, SLOT(checkForVisibilityChange(QStandardItem*)));
    7980}
    8081
     
    280281  MoleculeItemBiMap.clear();
    281282  dirtyItems.clear();
     283  visibilityItems.clear();
    282284  toBeMovedItems.clear();
    283285  newItems.clear();
    284286  toBeRemovedItems.clear();
    285287  toBeSetOccurrenceItems.clear();
     288  toBeSetVisibilityItems.clear();
    286289
    287290  for (std::vector<molecule*>::const_iterator iter = molecules.begin();
     
    303306  bool dirty = false;
    304307  dirty |= !dirtyItems.empty();
     308  dirty |= !visibilityItems.empty();
    305309  dirty |= !newItems.empty();
    306310  dirty |= !toBeRemovedItems.empty();
    307311  dirty |= !toBeSetOccurrenceItems.empty();
     312  dirty |= !toBeSetVisibilityItems.empty();
    308313  list_accessing = false;
    309314  return dirty;
     
    321326{}
    322327
    323 /*
    324 void QtMoleculeList::visibilityChanged(QStandardItem* item, int column)
    325 {
    326   if ((!changing) && (!clearing) && (!ChangingChildrensVisibility))
    327     if (column == QtMoleculeItemFactory::VISIBILITY) {
    328       const moleculeId_t molid = item->data(0, Qt::UserRole).toInt();
    329       const bool visible = item->checkState(QtMoleculeItemFactory::VISIBILITY);
    330       if (molid != (unsigned int)-1) { // molecule item
    331         World::MoleculeConstIterator moliter =
    332             const_cast<const World &>(World::getInstance()).getMoleculeIter(MoleculeById(molid));
    333         const molecule * const _molecule = *moliter;
    334         ASSERT( _molecule != NULL,
    335             "QtMoleculeList::visibilityChanged() - molecule with id "
    336             +toString(molid)+" is not known to World.");
    337         const std::string &molecule_formula = _molecule->getFormula().toString();
    338         ASSERT( FormulaVisibilityCountMap.count(molecule_formula) != 0,
    339             "QtMoleculeList::visibilityChanged() - molecule with formula " +molecule_formula
    340             +" is not present in FormulaVisibilityCountMap.");
    341 
    342         // get parent
    343         QTreeWidgetItem *groupItem = item->parent();
    344         ASSERT( groupItem != NULL,
    345             "QtMoleculeList::visibilityChanged() - item with id "+toString(molid)
    346             +" has not parent?");
    347         // check whether we have to set the group item
    348 
    349         ChangingChildrensVisibility = true;
    350         if (visible) {
    351           ++(FormulaVisibilityCountMap[molecule_formula]);
    352           // compare with occurence/total number of molecules
    353           if (FormulaVisibilityCountMap[molecule_formula] ==
    354               (unsigned int)(groupItem->text(OCCURRENCE).toInt()))
    355             groupItem->setCheckState(QtMoleculeItemFactory::VISIBILITY, Qt::Checked);
    356         } else {
    357           --(FormulaVisibilityCountMap[molecule_formula]);
    358           // none selected anymore?
    359           if (FormulaVisibilityCountMap[molecule_formula] == 0)
    360             groupItem->setCheckState(QtMoleculeItemFactory::VISIBILITY, Qt::Unchecked);
    361         }
    362         ChangingChildrensVisibility = false;
    363 
    364         emit moleculesVisibilityChanged(molid, visible);
    365 
    366       } else { // group item
    367 
    368         // go through all children, but don't enter for groupItem once more
    369         ChangingChildrensVisibility = true;
    370         for (int i=0;i<item->childCount();++i) {
    371           QTreeWidgetItem *molItem = item->child(i);
    372           const moleculeId_t molid = molItem->data(0, Qt::UserRole).toInt();
    373           ASSERT( molid != (unsigned int)-1,
    374               "QtMoleculeList::visibilityChanged() - to child with index"
    375               +toString(i)+" there is no molecule?");
    376           molItem->setCheckState(QtMoleculeItemFactory::VISIBILITY, visible ? Qt::Checked : Qt::Unchecked);
    377 
    378           // emit signal
    379           emit moleculesVisibilityChanged(molid, visible);
    380         }
    381         // set current number of visible children
    382         const std::string molecule_formula =
    383             item->text(FORMULA).toStdString();
    384         FormulaVisibilityCountMap[molecule_formula] =
    385             visible ? item->text(QtMoleculeItemFactory::OCCURRENCE).toInt() : 0;
    386 
    387         ChangingChildrensVisibility = false;
    388       }
     328void QtMoleculeList::checkForVisibilityChange(QStandardItem* _item)
     329{
     330  qDebug() << "Item changed called.";
     331
     332  if (_item->index().column() == QtMoleculeItemFactory::VISIBILITY) {
     333    qDebug() << "visibilityItem changed: " << (_item->checkState() ? "checked" : "unchecked");
     334    while(list_accessing);
     335    list_accessing = true;
     336    if ((_item->parent() == NULL) || (_item->parent() == invisibleRootItem()))
     337      toBeSetVisibilityItems.insert( _item );
     338    else
     339      visibilityItems.insert( dynamic_cast<QtMoleculeItem *>(_item) );
     340    list_accessing = false;
     341  }
     342}
     343
     344void QtMoleculeList::setVisibilityForMoleculeItem(QtMoleculeItem* _item)
     345{
     346  if (ChangingChildrensVisibility)
     347    return;
     348
     349  const bool visible = _item->checkState();
     350  const std::string &molecule_formula = _item->getMolecule()->getFormula().toString();
     351  ASSERT( FormulaVisibilityCountMap.count(molecule_formula) != 0,
     352      "QtMoleculeList::setVisibilityForMoleculeItem() - molecule with formula " +molecule_formula
     353      +" is not present in FormulaVisibilityCountMap.");
     354
     355  // get parent
     356  QStandardItem *groupItem = _item->parent();
     357  QStandardItem *visgroupItem =
     358      invisibleRootItem()->child(groupItem->index().row(), QtMoleculeItemFactory::VISIBILITY);
     359  ASSERT( groupItem != NULL,
     360      "QtMoleculeList::setVisibilityForMoleculeItem() - item with id "
     361      +toString(_item->getMolecule()->getId())+" has not parent?");
     362  // check whether we have to set the group item
     363
     364  ChangingChildrensVisibility = true;
     365  if (visible) {
     366    ++(FormulaVisibilityCountMap[molecule_formula]);
     367    // compare with occurence/total number of molecules
     368    if (FormulaVisibilityCountMap[molecule_formula] ==
     369        (unsigned int)(groupItem->rowCount()))
     370      visgroupItem->setCheckState(Qt::Checked);
     371  } else {
     372    --(FormulaVisibilityCountMap[molecule_formula]);
     373    // none selected anymore?
     374    if (FormulaVisibilityCountMap[molecule_formula] == 0)
     375      visgroupItem->setCheckState(Qt::Unchecked);
     376  }
     377  ChangingChildrensVisibility = false;
     378
     379  emit moleculesVisibilityChanged(_item->getMolecule()->getId(), visible);
     380}
     381
     382void QtMoleculeList::setVisibilityForGroupItem(QStandardItem* _item)
     383{
     384  if (ChangingChildrensVisibility)
     385    return;
     386
     387  ChangingChildrensVisibility = true;
     388
     389  // go through all children, but don't enter for groupItem once more
     390  const bool visible = _item->checkState();
     391  QStandardItem *groupitem = invisibleRootItem()->child(
     392      _item->index().row(), QtMoleculeItemFactory::NAME);
     393  for (int i=0;i<groupitem->rowCount();++i) {
     394    QtMoleculeItem *molItem = dynamic_cast<QtMoleculeItem *>(
     395        groupitem->child(i, QtMoleculeItemFactory::VISIBILITY));
     396    if (molItem->checkState() != visible) {
     397      molItem->setCheckState(visible ? Qt::Checked : Qt::Unchecked);
     398
     399      // emit signal
     400      emit moleculesVisibilityChanged(molItem->getMolecule()->getId(), visible);
    389401    }
    390 }
    391 */
     402  }
     403  // set current number of visible children
     404  const std::string molecule_formula =
     405      invisibleRootItem()->child(_item->row(), QtMoleculeItemFactory::NAME)->text().toStdString();
     406  FormulaVisibilityCountMap_t::iterator countiter =
     407      FormulaVisibilityCountMap.find(molecule_formula);
     408  ASSERT( countiter != FormulaVisibilityCountMap.end(),
     409      "QtMoleculeList::setVisibilityForGroupItem() - molecules "+molecule_formula
     410      +" have no entry in visibility count map?");
     411  countiter->second = visible ? groupitem->rowCount() : 0;
     412
     413  ChangingChildrensVisibility = false;
     414}
     415
    392416
    393417void QtMoleculeList::moleculeChanged() {
     
    496520  list_of_items_t dirtyItems_copy = dirtyItems;
    497521  dirtyItems.clear();
     522  list_of_items_t visibilityItems_copy = visibilityItems;
     523  visibilityItems.clear();
    498524  list_of_items_t toBeMovedItems_copy = toBeMovedItems;
    499525  toBeMovedItems.clear();
     
    504530  std::set<QStandardItem*> toBeSetOccurrenceItems_copy = toBeSetOccurrenceItems;
    505531  toBeSetOccurrenceItems.clear();
     532  std::set<QStandardItem*> toBeSetVisibilityItems_copy = toBeSetVisibilityItems;
     533  toBeSetVisibilityItems.clear();
    506534  list_accessing = false;
    507535
     
    542570    toBeMovedItems_copy.erase(item);
    543571  }
    544 
    545   /// 1. do the update for each dirty item
     572  for (list_of_items_t::iterator visiter = visibilityItems_copy.begin();
     573      visiter != visibilityItems_copy.end(); ) {
     574    QtMoleculeItem * const _item = dynamic_cast<QtMoleculeItem *>(
     575        (*visiter)->parent()->child(
     576            (*visiter)->index().row(),
     577            QtMoleculeItemFactory::NAME));
     578    const molecule *mol = ItemToMolecule(_item);
     579    if (std::binary_search(
     580            toBeRemovedItems_copy.begin(), toBeRemovedItems_copy.end(),
     581            mol))
     582      visibilityItems_copy.erase(visiter++);
     583    else
     584      ++visiter;
     585  }
     586
     587  /// 1a. do the update for each dirty item
    546588  for (list_of_items_t::const_iterator dirtyiter = dirtyItems_copy.begin();
    547589      dirtyiter != dirtyItems_copy.end(); ++dirtyiter) {
    548590    LOG(1, "Updating item " << *dirtyiter);
    549591    (*dirtyiter)->updateState();
     592  }
     593
     594  /// 1b. do the visibility update for each dirty item
     595  for (list_of_items_t::const_iterator visiter = visibilityItems_copy.begin();
     596      visiter != visibilityItems_copy.end(); ++visiter) {
     597    LOG(1, "Updating visibility of item " << *visiter);
     598    ASSERT(((*visiter)->parent() != NULL) && ((*visiter)->parent() != invisibleRootItem()),
     599        "QtMoleculeList::updateItemStates() - a group item ended up in visibilityItems.");
     600    setVisibilityForMoleculeItem(*visiter);
    550601  }
    551602
     
    578629  }
    579630
    580   /// 5a. update the group item's occurrence
     631  /// 5a. update the group item's occurrence and visibility
    581632  std::set<int> RowsToRemove;
    582633  for (std::set<QStandardItem*>::const_iterator groupiter = toBeSetOccurrenceItems_copy.begin();
     
    588639  }
    589640
     641  // remove all visibility updates whose row is removed
     642  for (std::set<QStandardItem*>::iterator visiter = toBeSetVisibilityItems_copy.begin();
     643      visiter != toBeSetVisibilityItems_copy.end(); ) {
     644    if (RowsToRemove.count((*visiter)->index().row()) != 0)
     645      toBeSetVisibilityItems_copy.erase(visiter++);
     646    else
     647      ++visiter;
     648  }
     649
     650  // update visibility of all group items
     651  for (std::set<QStandardItem*>::iterator visiter = toBeSetVisibilityItems_copy.begin();
     652      visiter != toBeSetVisibilityItems_copy.end(); ++visiter) {
     653    LOG(1, "Updating visibility of item " << *visiter);
     654    setVisibilityForGroupItem(*visiter);
     655  }
     656
    590657  /// 5b. remove all rows with 0 occurrence starting from last
    591658  for (std::set<int>::reverse_iterator riter = RowsToRemove.rbegin();
  • src/UIElements/Views/Qt4/MoleculeList/QtMoleculeList.hpp

    rd2dbb5d r2696b1  
    5555  void moleculeChanged();
    5656//  void visibilityChanged(QStandardItem*, int);
     57  void checkForVisibilityChange(QStandardItem*);
    5758  void checkState();
    5859
     
    9192  bool areAnyItemsDirty();
    9293  void addToBeSetOccurrence(QStandardItem *_groupitem);
     94  void setVisibilityForMoleculeItem(QtMoleculeItem* _item);
     95  void setVisibilityForGroupItem(QStandardItem* _item);
    9396
    9497  void informDirtyState(QtMoleculeItem *_item, const QtMoleculeItem::MoveTypes _type);
     
    112115  //!> list of items that need an update
    113116  list_of_items_t dirtyItems;
     117  //!> list of items that need an update of visibility
     118  list_of_items_t visibilityItems;
    114119  //!> list of items to molecule's whose formulas has changed and need to be moved
    115120  list_of_items_t toBeMovedItems;
     
    120125  //!> list of group items that need update due to moved molecule items
    121126  std::set<QStandardItem*> toBeSetOccurrenceItems;
     127  //!> list of group items that need visibility update due to changed molecule items
     128  std::set<QStandardItem*> toBeSetVisibilityItems;
    122129};
    123130
Note: See TracChangeset for help on using the changeset viewer.