Changeset 5d4b73 for src/UIElements/Menu


Ignore:
Timestamp:
Dec 5, 2010, 12:17:34 AM (14 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:
589112
Parents:
41e15b (diff), d754bb (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the (diff) links above to see all the changes relative to each parent.
Message:

Merge branch 'MenuStructureChange' into stable

Location:
src/UIElements/Menu
Files:
2 added
4 edited
2 moved

Legend:

Unmodified
Added
Removed
  • src/UIElements/Menu/Menu.hpp

    r41e15b r5d4b73  
    2121 * Note that this Class is never to be used directly but only via derived
    2222 * specializations.
     23 *
     24 * Note that we do not call member function init() directly in the constructor
     25 * to allow for something to be add to the menu beforehand which is necessary
     26 * for the TextMenu for example.
     27 *
     28 * <h1>Howto</h1>
     29 *
     30 * First, derive your own menu class, see QtMenu or TextMenu for example. These
     31 * have been templated because of the two Qt classes QMenu and QMenuBar to be
     32 * addressable in a unified manner. TextMenu does not actually need to be a
     33 * template but it does not hurt either.
     34 *
     35 * Basically, the structure is as follows:
     36 *  -# Menu implements the initialization: it goes through MenuDescription's and
     37 *     ActionRegistry's contents and adds MenuItem's and Action's as requested.
     38 *  -# It does so by calling virtual functions defined in MenuInterface. These
     39 *     allow for adding of specific type of items: separators, Actions, menus
     40 *  -# Your derived Menu implements add these specific adders, basically just as
     41 *     wrappers. If you really have another UI type, implement its Menu
     42 *     functionality separately, such as TxMenu does.
     43 *  -# It also inherits both Menu and virtually MenuInterface such that it
     44 *     contains initializing and adding functionality
     45 *
     46 *  Note that MenuInterface is inherited by both Menu and your class and hence has
     47 *  to be declared as a "virtual" base class for both.
    2348 */
    2449class Menu : virtual public MenuInterface
  • src/UIElements/Menu/TextMenu/SeparatorMenuItem.cpp

    r41e15b r5d4b73  
    77
    88/*
    9  * SeperatorItem.cpp
     9 * SeparatorMenuItem.cpp
    1010 *
    1111 *  Created on: Dec 11, 2009
     
    2323#include <sstream>
    2424
    25 #include "Menu/TextMenu/SeperatorItem.hpp"
     25#include "Menu/TextMenu/SeparatorMenuItem.hpp"
    2626#include "defs.hpp"
    2727
    2828
    29 SeperatorItem::SeperatorItem(TxMenu* const menu):
     29SeparatorMenuItem::SeparatorMenuItem(TxMenu* const menu):
    3030  MenuItem('\0',"",menu),
    3131  spacer(STD_SEPERATOR_SPACER),
     
    3636}
    3737
    38 SeperatorItem::SeperatorItem(TxMenu* const menu,char _spacer, int _length):
     38SeparatorMenuItem::SeparatorMenuItem(TxMenu* const menu,char _spacer, int _length):
    3939  MenuItem('\0',"",menu),
    4040  spacer(_spacer),
     
    4545}
    4646
    47 SeperatorItem::~SeperatorItem()
     47SeparatorMenuItem::~SeparatorMenuItem()
    4848{
    4949  // TODO Auto-generated destructor stub
     
    5151
    5252
    53 void SeperatorItem::doTrigger(){}
    54 bool SeperatorItem::checkTrigger(char){
     53void SeparatorMenuItem::doTrigger(){}
     54bool SeparatorMenuItem::checkTrigger(char){
    5555  return false;
    5656}
    5757
    58 const std::string SeperatorItem::getDescription() {
     58const std::string SeparatorMenuItem::getDescription() {
    5959  return std::string("");
    6060}
    6161
    62 const std::string SeperatorItem::formatEntry(){
     62const std::string SeparatorMenuItem::formatEntry(){
    6363  std::stringstream s;
    6464  for(int i=0; i<length;i++)
  • src/UIElements/Menu/TextMenu/SeparatorMenuItem.hpp

    r41e15b r5d4b73  
    11/*
    2  * SeperatorItem.h
     2 * SeparatorMenuItem.h
    33 *
    44 *  Created on: Dec 11, 2009
     
    66 */
    77
    8 #ifndef SEPERATORITEM_H_
    9 #define SEPERATORITEM_H_
     8#ifndef SEPARATORITEM_H_
     9#define SEPARATORITEM_H_
    1010
    1111#include <string>
     
    1616
    1717/**
    18  * Produce a Seperator within a Menu.
     18 * Produce a Separator within a Menu.
    1919 *
    2020 * All triggers are ignored for this Item.
    2121 */
    22 class SeperatorItem : public MenuItem
     22class SeparatorMenuItem : public MenuItem
    2323{
    2424public:
    25   SeperatorItem(TxMenu* const );
    26   SeperatorItem(TxMenu* const ,char,int);
    27   virtual ~SeperatorItem();
     25  SeparatorMenuItem(TxMenu* const );
     26  SeparatorMenuItem(TxMenu* const ,char,int);
     27  virtual ~SeparatorMenuItem();
    2828
    2929  virtual void doTrigger();
     
    3838};
    3939
    40 #endif /* SEPERATORITEM_H_ */
     40#endif /* SEPARATORITEM_H_ */
  • src/UIElements/Menu/TextMenu/TextMenu.hpp

    r41e15b r5d4b73  
    1212#include <string>
    1313
     14#include "Helpers/MemDebug.hpp"
     15
    1416#include "Helpers/Log.hpp"
    1517#include "Helpers/Verbose.hpp"
     
    1921#include "Actions/ActionRegistry.hpp"
    2022#include "Actions/ActionTraits.hpp"
    21 #include "Menu/TextMenu/TxMenu.hpp"
     23#include "Menu/TextMenu/TxMenuLeaveAction.hpp"
    2224#include "Menu/TextMenu/ActionMenuItem.hpp"
    23 #include "Menu/TextMenu/SeperatorItem.hpp"
     25#include "Menu/TextMenu/SeparatorMenuItem.hpp"
    2426#include "Menu/TextMenu/SubMenuItem.hpp"
    2527
    2628/** TextMenu is a specialization of MenuInterface to access TxMenu-like menus.
     29 *
     30 * Basically, this class is to be used in the MainWindow class of the TextUI.
     31 * There, we simply instantiate the class and call init() in order to add all
     32 * MenuItem's from MenuDescriptions and Action's ActionRegistry.
     33 *
    2734 * \sa QtMenu.
    2835 */
     
    3138{
    3239public:
     40  /** Constructor for class TextMenu.
     41   * Initializes outputter and token and takes note whether to delete the
     42   * MenuInstance or not.
     43   */
    3344  TextMenu(std::ostream &_outputter, const std::string &_token) :
    3445    MenuInterface(_token),
     
    4657  {}
    4758
     59  /** Destructor of MenuInstance.
     60   *
     61   */
    4862  virtual ~TextMenu()
    4963  {
     
    5266  }
    5367
     68  /** Display this MenuInstance.
     69   *
     70   */
    5471  void display()
    5572  {
     
    5774  }
    5875
     76  /** Returns a pointer to the contained/wrapped MenuInstance.
     77   * \return pointer to template class pointer
     78   */
    5979  T * const getMenuInstance()
    6080  {
     
    6282  }
    6383
     84  /** Reserves a specific trigger key such that it is not used during init().
     85   * \param trigger trigger key
     86   * \param &name token given for reference.
     87   */
    6488  void reserveShortcut(char trigger, const std::string &name)
    6589  {
     
    78102  MenuShortcutMap ShortcutMap;
    79103
     104  /** Adds an ActionItem by simply creating a new one.
     105   * \param &token token of Action (token in ActionRegistry)
     106   * \param &description descriptive text to be shown
     107   */
    80108  virtual void addActionItem(const std::string &token, const std::string &description)
    81109  {
     
    83111  }
    84112
     113  /** Adds a (dead) separator item.
     114   *
     115   */
    85116  virtual void addSeparatorItem()
    86117  {
    87     new SeperatorItem(MenuInstance);
     118    new SeparatorMenuItem(MenuInstance);
    88119  }
    89120
     121  /** Adds a Menu to this current Menu.
     122   * We also create here a leave action for this submenu to be able to return
     123   * to the current one again
     124   * \param &token token of the menu
     125   * \param &description descriptive text
     126   */
    90127  virtual void addSubmenuItem(const std::string &token, const std::string &description)
    91128  {
     
    102139  }
    103140
     141  /** Return the next available trigger key suitable to this name.
     142   * This function is used internally to make sure that each key is unique to
     143   * each Action/Menu. The chosen trigger key is also stored in an internal ShortcutMap.
     144   * \param &name text shown in menu
     145   * \return trigger key
     146   */
    104147  char getSuitableShortForm(const std::string &name)
    105148  {
  • src/UIElements/Menu/TextMenu/TxMenu.cpp

    r41e15b r5d4b73  
    2424#include <iostream>
    2525#include <cmath>
    26 #include "Actions/Action.hpp"
    27 #include "Actions/ActionTraits.hpp"
    2826#include "Menu/TextMenu/TxMenu.hpp"
    2927#include "Menu/TextMenu/MenuItem.hpp"
    30 #include "Helpers/Assert.hpp"
    3128
    3229
    33 /**
     30/** Constructor for class TxMenu.
     31 *
    3432 * produce a text menu with a given title.
    3533 * The text will later be displayed using the stream passed to the constructor.
     34 * \param &_outputter output stream to use for displaying the text
     35 * \param _title title of this menu
     36 * \param _spacer key to separate trigger key from descriptive text shown
     37 * \param _length maximum length of the descriptive text
    3638 */
    3739TxMenu::TxMenu(std::ostream& _outputter, const std::string _title, char _spacer,int _length) :
     
    4547}
    4648
     49/** Destructor for class TxMenu.
     50 *
     51 */
    4752TxMenu::~TxMenu()
    4853{
     
    5156}
    5257
     58/** Adds an MenuItem to the internal list.
     59 * \param *item item to add
     60 */
    5361void TxMenu::addItem(MenuItem* item) {
    5462  items.push_back(item);
    5563}
    5664
     65/** Removes an MenuItem to the internal list.
     66 * \param *item item to remove
     67 */
    5768void TxMenu::removeItem(MenuItem* item) {
    5869  items.remove(item);
    5970}
    6071
     72/** Function to quit this TxMenu.
     73 */
    6174void TxMenu::doQuit(){
    6275  quit = true;
    6376}
    6477
     78/** Return the current state of quitting.
     79 * \return quit boolean
     80 */
    6581bool TxMenu::hasQuit(){
    6682  return quit;
    6783}
    6884
     85/** Display in a formatted manner a given entry of this menu.
     86 * \param *entry MenuItem to show
     87 */
    6988void TxMenu::showEntry(MenuItem* entry){
    7089  if(entry->isActive()==false){
     
    7897}
    7998
     99/** Display this menu.
     100 *
     101 */
    80102void TxMenu::display() {
    81103  char choice;
     
    114136}
    115137
     138/**  Return the internally stored title of the menu.
     139 * \return title string
     140 */
    116141std::string TxMenu::getTitle(){
    117142  return title;
    118143}
    119144
     145/**  Return the internally stored outputter of the menu.
     146 * \return output stream reference
     147 */
    120148std::ostream& TxMenu::getOutputter()
    121149{
     
    123151}
    124152
    125 
     153/** Add a default item to the menu.
     154 * \param *_defaultItem MenuItem to act as default item.
     155 */
    126156void TxMenu::addDefault(MenuItem* _defaultItem) {
    127157  defaultItem = _defaultItem;
    128158}
    129159
    130 /****************************** Contained Actions ****************/
    131 
    132 TxMenu::LeaveAction::LeaveAction(TxMenu* const _menu, const ActionTraits & LeaveActionTrait) :
    133   Action(LeaveActionTrait, true),
    134   menu(_menu)
    135 {}
    136 
    137 TxMenu::LeaveAction::~LeaveAction(){}
    138 
    139 bool TxMenu::LeaveAction::canUndo(){
    140   return false;
    141 }
    142 
    143 bool TxMenu::LeaveAction::shouldUndo(){
    144   return false;
    145 }
    146 
    147 void TxMenu::LeaveAction::getParametersfromValueStorage()
    148 {}
    149 
    150 Dialog* TxMenu::LeaveAction::fillDialog(Dialog *dialog){
    151   ASSERT(dialog,"No Dialog given when filling action dialog");
    152   return dialog;
    153 }
    154 
    155 
    156 Action::state_ptr TxMenu::LeaveAction::performCall(){
    157   menu->doQuit();
    158   return Action::success;
    159 }
    160 
    161 
    162 Action::state_ptr TxMenu::LeaveAction::performUndo(Action::state_ptr){
    163   ASSERT(0,"Cannot undo leaving a menu");
    164   return Action::success;
    165 }
    166 
    167 Action::state_ptr TxMenu::LeaveAction::performRedo(Action::state_ptr){
    168   ASSERT(0,"Cannot redo leaving a menu");
    169   return Action::success;
    170 }
  • src/UIElements/Menu/TextMenu/TxMenu.hpp

    r41e15b r5d4b73  
    1414
    1515#include "Menu/Menu.hpp"
    16 #include "Actions/Action.hpp"
    17 #include "Actions/ActionTraits.hpp"
    1816#include "defs.hpp"
    1917
    2018class MenuItem;
    2119
    22 /**
    23  * Used to produce any kind of text menu
     20/** Menu for the TextUI.
    2421 *
    25  * All Items are displayed and user is prompted for a key. The item corresponding to that key is then activated.
     22 * Used to produce any kind of text menu. This is a generic text menu user
     23 * interface, i.e. we have a list of MenuItem's, which can either be
     24 * -# Action's
     25 * -# Displayers
     26 * -# Separators
     27 * -# other Menu's
     28 *
     29 * In this manner we have a tree structure, the (sub)menus generating new
     30 * branches, the rest making up the leaves.
     31 *
     32 * All Items are displayed via a given output stream and user is prompted
     33 * for a key. The item corresponding to that key is then activated.
    2634 */
    2735class TxMenu
    2836{
    2937public:
    30   class LeaveAction : public Action {
    31   public:
    32     LeaveAction(TxMenu* const, const ActionTraits &_trait);
    33     virtual ~LeaveAction();
    34 
    35     bool canUndo();
    36     bool shouldUndo();
    37 
    38   protected:
    39     virtual Dialog* fillDialog(Dialog *dialog);
    40   private:
    41     virtual void getParametersfromValueStorage();
    42     virtual Action::state_ptr performCall();
    43     virtual Action::state_ptr performUndo(Action::state_ptr);
    44     virtual Action::state_ptr performRedo(Action::state_ptr);
    45 
    46     TxMenu* const menu;
    47   };
     38  class LeaveAction;
    4839
    4940  TxMenu(std::ostream& _outputter, const std::string _title, char _spacer=STD_MENU_TITLE_SPACER,int _length=STD_MENU_LENGTH);
Note: See TracChangeset for help on using the changeset viewer.