Changeset 2696b1 for src/UIElements/Views
- Timestamp:
- Jan 28, 2015, 7:07:03 PM (10 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:
- 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)
- Location:
- src/UIElements/Views/Qt4/MoleculeList
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
src/UIElements/Views/Qt4/MoleculeList/QtMoleculeList.cpp
rd2dbb5d r2696b1 36 36 37 37 #include <QModelIndex> 38 #include <QDebug> 38 39 39 40 #include "UIElements/Views/Qt4/MoleculeList/QtMoleculeItem.hpp" … … 76 77 //connect(this,SIGNAL(cellChanged(int,int)),this,SLOT(moleculeChanged(int,int))); 77 78 // 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*))); 79 80 } 80 81 … … 280 281 MoleculeItemBiMap.clear(); 281 282 dirtyItems.clear(); 283 visibilityItems.clear(); 282 284 toBeMovedItems.clear(); 283 285 newItems.clear(); 284 286 toBeRemovedItems.clear(); 285 287 toBeSetOccurrenceItems.clear(); 288 toBeSetVisibilityItems.clear(); 286 289 287 290 for (std::vector<molecule*>::const_iterator iter = molecules.begin(); … … 303 306 bool dirty = false; 304 307 dirty |= !dirtyItems.empty(); 308 dirty |= !visibilityItems.empty(); 305 309 dirty |= !newItems.empty(); 306 310 dirty |= !toBeRemovedItems.empty(); 307 311 dirty |= !toBeSetOccurrenceItems.empty(); 312 dirty |= !toBeSetVisibilityItems.empty(); 308 313 list_accessing = false; 309 314 return dirty; … … 321 326 {} 322 327 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 } 328 void 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 344 void 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 382 void 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); 389 401 } 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 392 416 393 417 void QtMoleculeList::moleculeChanged() { … … 496 520 list_of_items_t dirtyItems_copy = dirtyItems; 497 521 dirtyItems.clear(); 522 list_of_items_t visibilityItems_copy = visibilityItems; 523 visibilityItems.clear(); 498 524 list_of_items_t toBeMovedItems_copy = toBeMovedItems; 499 525 toBeMovedItems.clear(); … … 504 530 std::set<QStandardItem*> toBeSetOccurrenceItems_copy = toBeSetOccurrenceItems; 505 531 toBeSetOccurrenceItems.clear(); 532 std::set<QStandardItem*> toBeSetVisibilityItems_copy = toBeSetVisibilityItems; 533 toBeSetVisibilityItems.clear(); 506 534 list_accessing = false; 507 535 … … 542 570 toBeMovedItems_copy.erase(item); 543 571 } 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 546 588 for (list_of_items_t::const_iterator dirtyiter = dirtyItems_copy.begin(); 547 589 dirtyiter != dirtyItems_copy.end(); ++dirtyiter) { 548 590 LOG(1, "Updating item " << *dirtyiter); 549 591 (*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); 550 601 } 551 602 … … 578 629 } 579 630 580 /// 5a. update the group item's occurrence 631 /// 5a. update the group item's occurrence and visibility 581 632 std::set<int> RowsToRemove; 582 633 for (std::set<QStandardItem*>::const_iterator groupiter = toBeSetOccurrenceItems_copy.begin(); … … 588 639 } 589 640 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 590 657 /// 5b. remove all rows with 0 occurrence starting from last 591 658 for (std::set<int>::reverse_iterator riter = RowsToRemove.rbegin(); -
src/UIElements/Views/Qt4/MoleculeList/QtMoleculeList.hpp
rd2dbb5d r2696b1 55 55 void moleculeChanged(); 56 56 // void visibilityChanged(QStandardItem*, int); 57 void checkForVisibilityChange(QStandardItem*); 57 58 void checkState(); 58 59 … … 91 92 bool areAnyItemsDirty(); 92 93 void addToBeSetOccurrence(QStandardItem *_groupitem); 94 void setVisibilityForMoleculeItem(QtMoleculeItem* _item); 95 void setVisibilityForGroupItem(QStandardItem* _item); 93 96 94 97 void informDirtyState(QtMoleculeItem *_item, const QtMoleculeItem::MoveTypes _type); … … 112 115 //!> list of items that need an update 113 116 list_of_items_t dirtyItems; 117 //!> list of items that need an update of visibility 118 list_of_items_t visibilityItems; 114 119 //!> list of items to molecule's whose formulas has changed and need to be moved 115 120 list_of_items_t toBeMovedItems; … … 120 125 //!> list of group items that need update due to moved molecule items 121 126 std::set<QStandardItem*> toBeSetOccurrenceItems; 127 //!> list of group items that need visibility update due to changed molecule items 128 std::set<QStandardItem*> toBeSetVisibilityItems; 122 129 }; 123 130
Note:
See TracChangeset
for help on using the changeset viewer.