Ignore:
Timestamp:
Jan 12, 2015, 10:10:30 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:
52cd7b
Parents:
867473
git-author:
Frederik Heber <heber@…> (12/12/14 18:41:27)
git-committer:
Frederik Heber <heber@…> (01/12/15 22:10:30)
Message:

Undo/Redobuttons are grayed out when respective Action not possible.

Location:
src/UIElements/Views/Qt4
Files:
3 edited

Legend:

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

    r867473 rc01fec  
    2828 */
    2929
    30 
    31 
    32 
    3330// include config.h
    3431#ifdef HAVE_CONFIG_H
     
    3633#endif
    3734
    38 
    3935#include "QtToolBar.hpp"
    4036
    4137#include "CodePatterns/MemDebug.hpp"
    4238
     39#include "CodePatterns/Observer/Notification.hpp"
     40
     41#include "Actions/ActionQueue.hpp"
     42
    4343QtToolBar::QtToolBar(QWidget * _parent) :
    44   QToolBar(_parent)
     44  QToolBar(_parent),
     45  Observer("QToolBar"),
     46  ActionQueue_observing(false),
     47  undoaction(addActionItem("undo", "undo the last Action", "edit-undo")),
     48  redoaction(addActionItem("redo", "redo the last Action", "edit-redo"))
    4549{
    46   addActionItem("undo", "undo the last Action", "edit-undo");
    47   addActionItem("redo", "redo the last Action", "edit-redo");
     50  // gray out undo/redo buttons initially
     51  undoaction->setEnabled(false);
     52  redoaction->setEnabled(false);
     53
     54  // sign in
     55  MoleCuilder::ActionQueue::getInstance().signOn(this, MoleCuilder::ActionQueue::ActionQueued);
     56  ActionQueue_observing = true;
    4857}
    4958
     
    5160QtToolBar::~QtToolBar()
    5261{
     62  // sign off
     63  if (ActionQueue_observing)
     64    MoleCuilder::ActionQueue::getInstance().signOff(this, MoleCuilder::ActionQueue::ActionQueued);
    5365}
    5466
    5567
    56 void QtToolBar::addActionItem(const std::string &token, const std::string &description, const std::string &icon_name)
     68QAction * QtToolBar::addActionItem(
     69    const std::string &token,
     70    const std::string &description,
     71    const std::string &icon_name)
    5772{
    5873  QAction *action = addAction(QString(description.c_str()));
     
    6378  plumbing.push_back(pipe);
    6479  present_actions.insert( token );
     80  return action;
    6581}
    6682
     
    7288}
    7389
     90void QtToolBar::update(Observable *publisher)
     91{
     92  ASSERT(0, "QtToolBar::update() - this should never be called, we are only subscribed to channels.");
     93}
     94
     95void QtToolBar::subjectKilled(Observable *publisher)
     96{
     97  ActionQueue_observing = false;
     98}
     99
     100void QtToolBar::recieveNotification(Observable *publisher, Notification_ptr notification)
     101{
     102  if (dynamic_cast<MoleCuilder::ActionQueue *>(publisher) != NULL) {
     103    switch(notification->getChannelNo()) {
     104      case MoleCuilder::ActionQueue::ActionQueued:
     105        undoaction->setEnabled(MoleCuilder::ActionQueue::getInstance().canUndo());
     106        redoaction->setEnabled(MoleCuilder::ActionQueue::getInstance().canRedo());
     107        break;
     108      default:
     109        ASSERT(0, "QtToolBar::recieveNotification() - cannot get here, not subscribed to channel "
     110            +toString(notification->getChannelNo()));
     111        break;
     112    }
     113  } else {
     114    ASSERT(0, "QtToolBar::recieveNotification() - cannot get here, we are only subscribed to ActionQueue.");
     115  }
     116}
  • src/UIElements/Views/Qt4/QtToolBar.hpp

    r867473 rc01fec  
    2727
    2828
    29 class QtToolBar : public QToolBar
     29class QtToolBar : public QToolBar, public Observer
    3030{
    3131  Q_OBJECT
     
    3939   * @param description description to appear as tooltip
    4040   * @param icon_name name of icon
     41   * @return ref to newly created action
    4142   */
    42   void addActionItem(const std::string &token, const std::string &description, const std::string &icon_name);
     43  QAction * addActionItem(
     44      const std::string &token,
     45      const std::string &description,
     46      const std::string &icon_name);
    4347
    4448  /** Function to add a set of favorite actions.
     
    5761  const present_actions_t & getPresentActions() const
    5862  { return present_actions; }
     63
     64  void update(Observable *publisher);
     65  void subjectKilled(Observable *publisher);
     66  void recieveNotification(Observable *publisher, Notification_ptr notification);
    5967
    6068private:
     
    105113  //!> set of already present action icons
    106114  present_actions_t present_actions;
     115
     116  //!> sign in to ActionQueue?
     117  bool ActionQueue_observing;
     118  //!> ref to undoaction to gray out
     119  QAction *undoaction;
     120  //!> ref to redoaction to gray out
     121  QAction *redoaction;
    107122};
    108123
  • src/UIElements/Views/Qt4/QtToolBar_QtFavoriteActions.cpp

    r867473 rc01fec  
    4646#include "CodePatterns/Assert.hpp"
    4747#include "CodePatterns/Log.hpp"
    48 #include "CodePatterns/Observer/Observer.hpp"
    4948
    5049#include "Actions/Action.hpp"
Note: See TracChangeset for help on using the changeset viewer.