Ignore:
Timestamp:
Jul 25, 2015, 1:02:11 PM (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:
ea73ce
Parents:
9d4f964
git-author:
Frederik Heber <heber@…> (06/17/15 22:06:29)
git-committer:
Frederik Heber <heber@…> (07/25/15 13:02:11)
Message:

FIX: QtMoleculeItem would not correctly signOff prior to molecule being destroyed.

Location:
src/UIElements/Views/Qt4/MoleculeList
Files:
5 edited

Legend:

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

    r9d4f964 r7d0ddb  
    143143{
    144144  const molecule * const mol = const_cast<const World &>(World::getInstance()).getMolecule(MoleculeById(molid));
    145   ASSERT (mol != NULL,
    146       "QtMoleculeItem::getMolecule() - mol with "+toString(molid)+" is gone.");
     145//  ASSERT (mol != NULL,
     146//      "QtMoleculeItem::getMolecule() - mol with "+toString(molid)+" is gone.");
    147147  return mol;
    148148}
  • src/UIElements/Views/Qt4/MoleculeList/QtMoleculeItem.hpp

    r9d4f964 r7d0ddb  
    6969  const molecule * const getMolecule() const;
    7070
     71  /** Getter for the id of the molecule this item is associated to
     72   *
     73   * \return id of molecule
     74   */
     75  moleculeId_t getMoleculeId() const
     76  { return molid; }
     77
    7178private:
    7279  void update(Observable *publisher);
  • src/UIElements/Views/Qt4/MoleculeList/QtMoleculeItemFactory.cpp

    r9d4f964 r7d0ddb  
    7272  // fill all the static channels lists
    7373  const_cast<QtMoleculeItem::channellist_t &>(
    74       QtMoleculeItem_name::channellist_name) +=
    75           molecule::MoleculeNameChanged;
    76   const_cast<QtMoleculeItem::channellist_t &>(
    7774      QtMoleculeItem_atomcount::channellist_atomcount) +=
     75          molecule::AboutToBeRemoved,
    7876          molecule::AtomInserted,
    7977          molecule::AtomRemoved;
    8078  const_cast<QtMoleculeItem::channellist_t &>(
    8179      QtMoleculeItem_formula::channellist_formula) +=
     80          molecule::AboutToBeRemoved,
    8281          molecule::FormulaChanged;
     82  const_cast<QtMoleculeItem::channellist_t &>(
     83      QtMoleculeItem_name::channellist_name) +=
     84          molecule::AboutToBeRemoved,
     85          molecule::MoleculeNameChanged;
     86  const_cast<QtMoleculeItem::channellist_t &>(
     87      QtMoleculeItem_occurrence::channellist_occurrence) +=
     88          molecule::AboutToBeRemoved;
     89  const_cast<QtMoleculeItem::channellist_t &>(
     90      QtMoleculeItem_visibility::channellist_visibility) +=
     91          molecule::AboutToBeRemoved;
    8392}
    8493
  • src/UIElements/Views/Qt4/MoleculeList/QtMoleculeList.cpp

    r9d4f964 r7d0ddb  
    6161QtMoleculeList::QtMoleculeList() :
    6262  Observer("QtMoleculeList"),
    63   changing(false),
    6463  ChangingChildrensVisibility(false),
    65   list_accessing(false),
    6664  update_timer(NULL),
    6765  callback_DirtyItems(boost::bind(&QtMoleculeList::informDirtyState, this, _1, _2))
     
    138136      {
    139137        const molecule * const mol = World::getInstance().lastChanged<molecule>();
    140         while(list_accessing);
    141         list_accessing = true;
     138        listAccessing_mutex.lock();
    142139        newItems.push_back( mol );
    143         list_accessing = false;
     140        listAccessing_mutex.unlock();
    144141        break;
    145142      }
     
    148145        const molecule * const mol = World::getInstance().lastChanged<molecule>();
    149146
    150         while(list_accessing);
    151         list_accessing = true;
     147        listAccessing_mutex.lock();
    152148        toBeRemovedItems.push_back( mol ); // remove in any case, as we also got insert
    153         list_accessing = false;
     149        listAccessing_mutex.unlock();
    154150
    155151        const QtMoleculeItem *mol_item = MoleculeIdToItem(mol->getId());
     
    186182    QStandardItem *_groupitem)
    187183{
    188   while (list_accessing);
    189   list_accessing = true;
     184  listAccessing_mutex.lock();
    190185  toBeSetOccurrenceItems.insert( _groupitem );
    191   list_accessing = false;
     186  listAccessing_mutex.unlock();
    192187}
    193188
     
    271266    update_timer->stop();
    272267
    273   changing = true;
     268  refill_mutex.lock();
    274269
    275270  const std::vector<const molecule*> &molecules =
     
    294289    addMolecule(*iter);
    295290
    296   changing = false;
     291  refill_mutex.unlock();
    297292
    298293  // activate timer
     
    303298{
    304299  // get whether any items are dirty
    305   while (list_accessing);
    306   list_accessing = true;
     300  listAccessing_mutex.lock();
    307301  bool dirty = false;
    308302  dirty |= !dirtyItems.empty();
     
    312306  dirty |= !toBeSetOccurrenceItems.empty();
    313307  dirty |= !toBeSetVisibilityItems.empty();
    314   list_accessing = false;
     308  listAccessing_mutex.unlock();
    315309  return dirty;
    316310}
     
    333327  if (_item->index().column() == QtMoleculeItemFactory::VISIBILITY) {
    334328//    qDebug() << "visibilityItem changed: " << (_item->checkState() ? "checked" : "unchecked");
    335     while(list_accessing);
    336     list_accessing = true;
     329    listAccessing_mutex.lock();
    337330    if ((_item->parent() == NULL) || (_item->parent() == invisibleRootItem()))
    338331      toBeSetVisibilityItems.insert( _item );
    339332    else
    340333      visibilityItems.insert( dynamic_cast<QtMoleculeItem *>(_item) );
    341     list_accessing = false;
     334    listAccessing_mutex.unlock();
    342335  }
    343336}
     
    349342
    350343  const bool visible = _item->checkState();
    351   const std::string &molecule_formula = _item->getMolecule()->getFormula().toString();
    352   ASSERT( FormulaVisibilityCountMap.count(molecule_formula) != 0,
    353       "QtMoleculeList::setVisibilityForMoleculeItem() - molecule with formula " +molecule_formula
    354       +" is not present in FormulaVisibilityCountMap.");
     344  const molecule * const mol = _item->getMolecule();
     345  std::string molecule_formula;
     346  if (mol != NULL) {
     347    molecule_formula = mol->getFormula().toString();
     348    ASSERT( FormulaVisibilityCountMap.count(molecule_formula) != 0,
     349        "QtMoleculeList::setVisibilityForMoleculeItem() - molecule with formula " +molecule_formula
     350        +" is not present in FormulaVisibilityCountMap.");
     351  }
    355352
    356353  // get parent
     
    360357  ASSERT( groupItem != NULL,
    361358      "QtMoleculeList::setVisibilityForMoleculeItem() - item with id "
    362       +toString(_item->getMolecule()->getId())+" has not parent?");
     359      +toString(_item->getMoleculeId())+" has not parent?");
    363360  // check whether we have to set the group item
    364361
     
    469466    addToBeSetOccurrence(groupitem);
    470467  // ..  and re-add where new formula fits
    471   const std::string molecule_formula = _molitem->getMolecule()->getFormula().toString();
    472   FormulaTreeItemMap_t::iterator iter = formula.find(molecule_formula);
    473   if (iter == formula.end()) {
    474     // add new group item and formula entry
    475      addGroupItem(groupitem, molecule_formula);
    476   } else {
    477     groupitem = iter->second;
    478   }
    479   ASSERT( groupitem != NULL,
    480       "QtMoleculeList::readdItem() - failed to create a sensible new groupitem");
    481   // finally add again
    482   groupitem->appendRow(mol_row);
     468  const molecule * const mol = _molitem->getMolecule();
     469  std::string molecule_formula;
     470  if (mol != NULL) {
     471    molecule_formula = mol->getFormula().toString();
     472    FormulaTreeItemMap_t::iterator iter = formula.find(molecule_formula);
     473    if (iter == formula.end()) {
     474      // add new group item and formula entry
     475       addGroupItem(groupitem, molecule_formula);
     476    } else {
     477      groupitem = iter->second;
     478    }
     479    ASSERT( groupitem != NULL,
     480        "QtMoleculeList::readdItem() - failed to create a sensible new groupitem");
     481    // finally add again
     482    groupitem->appendRow(mol_row);
     483  }
    483484  // call setOccurrence on the new group later
    484485  addToBeSetOccurrence(groupitem);
     
    489490    const QtMoleculeItem::MoveTypes _type)
    490491{
    491   while (list_accessing);
    492   list_accessing = true;
    493 
     492  refill_mutex.lock();
     493
     494  listAccessing_mutex.lock();
    494495  dirtyItems.insert(_item);
     496  listAccessing_mutex.unlock();
    495497  if (_type == QtMoleculeItem::NeedsMove) {
    496498    // we have to convert whatever item raised the dirty signal to the first
     
    500502    QtMoleculeItem *mol_item =
    501503        dynamic_cast<QtMoleculeItem *>(group_item->child(_item->row(), 0));
     504    listAccessing_mutex.lock();
    502505    toBeMovedItems.insert(mol_item);
     506    listAccessing_mutex.unlock();
    503507//    // add group item, too
    504508//    toBeSetOccurrenceItems.insert(group_item);
    505509  }
    506510
    507   list_accessing = false;
     511  refill_mutex.unlock();
    508512}
    509513
     
    511515{
    512516  // wait till initial refill has been executed
    513   if (changing)
    514     return;
    515 
    516   changing = true;
     517  refill_mutex.lock();
    517518
    518519  /// copy lists such that new signals for dirty/.. may come in right away
    519520  // TODO: if we had move semantics ...
    520   while (list_accessing);
    521   list_accessing = true;
     521  listAccessing_mutex.lock();
    522522  list_of_items_t dirtyItems_copy = dirtyItems;
    523523  dirtyItems.clear();
     
    534534  std::set<QStandardItem*> toBeSetVisibilityItems_copy = toBeSetVisibilityItems;
    535535  toBeSetVisibilityItems.clear();
    536   list_accessing = false;
     536  listAccessing_mutex.unlock();
    537537
    538538  /// first check consistency among the sets:
     
    667667
    668668  // and done
    669   changing = false;
    670 }
     669  refill_mutex.unlock();
     670}
  • src/UIElements/Views/Qt4/MoleculeList/QtMoleculeList.hpp

    r9d4f964 r7d0ddb  
    1717#include <QtGui/QStandardItem>
    1818#include <QtGui/QStandardItemModel>
     19#include <QMutex>
    1920#include <QTimer>
    2021
     
    6970private:
    7071
    71   bool changing;
    7272  bool ChangingChildrensVisibility;
    73   bool list_accessing;
     73
     74  QMutex listAccessing_mutex;
     75  QMutex refill_mutex;
    7476
    7577  //!> informs the view in regular intervals about updates
Note: See TracChangeset for help on using the changeset viewer.