Ignore:
Timestamp:
Dec 4, 2010, 11:33:47 PM (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:
0af7ef
Parents:
5813ac
git-author:
Frederik Heber <heber@…> (11/08/10 09:36:45)
git-committer:
Frederik Heber <heber@…> (12/04/10 23:33:47)
Message:

Refactoring of Menu structure for Qt and Text UI done.

  • Menu is now the initialising class for the menu structure.
  • MenuInterface contains virtual declarations of all functions that Menu needs to call.
  • TextMenu and QtMenu are templated classes which contain both Menu and MenuInterface and implement the virtual functions.
  • class TxMenu and its ...MenuItems contain most of the old Menu code for the text-based system. Most of the stuff, such as triggers, are now hidden internally.
  • in ..MainWindow() we basically just construct the desired Menu and call init at the correct time.
Location:
src/UIElements/Menu/TextMenu
Files:
2 added
11 moved

Legend:

Unmodified
Added
Removed
  • src/UIElements/Menu/TextMenu/ActionMenuItem.cpp

    r5813ac rb59da6  
    2222#include <iostream>
    2323
    24 #include "Menu/ActionMenuItem.hpp"
    25 #include "Actions/MethodAction.hpp"
     24#include "Menu/TextMenu/ActionMenuItem.hpp"
     25#include "Actions/Action.hpp"
     26#include "Actions/ActionRegistry.hpp"
    2627
    2728using namespace std;
    2829
    29 ActionMenuItem::ActionMenuItem(char _trigger, const char* _description,Menu* _menu,Action* _action)
     30ActionMenuItem::ActionMenuItem(char _trigger, const std::string &_description,TxMenu* const _menu,const std::string &_ActionName)
    3031: MenuItem(_trigger,_description,_menu),
    31   action(_action)
     32  ActionName(_ActionName)
    3233{
    3334}
     
    3738
    3839void ActionMenuItem::doTrigger() {
     40  Action* action = ActionRegistry::getInstance().getActionByName(ActionName);
    3941  action->call();
    4042}
    4143
    4244bool ActionMenuItem::isActive() {
     45  Action* action = ActionRegistry::getInstance().getActionByName(ActionName);
    4346  return action->isActive();
    4447}
  • src/UIElements/Menu/TextMenu/ActionMenuItem.hpp

    r5813ac rb59da6  
    1111#include <string>
    1212
    13 #include "Menu/MenuItem.hpp"
     13#include "Menu/TextMenu/MenuItem.hpp"
    1414
    1515class Action;
     16class TxMenu;
    1617
    1718/**
     
    2122{
    2223public:
    23   ActionMenuItem(char,const char*,Menu*,Action*);
     24  ActionMenuItem(char,const std::string &,TxMenu* const,const std::string &);
    2425  virtual ~ActionMenuItem();
    2526
     
    2930
    3031private:
    31   Action* action; //!< this action will be called when the trigger matches
     32  const std::string ActionName; //!< this action will be called when the trigger matches
    3233};
    3334
  • src/UIElements/Menu/TextMenu/DisplayMenuItem.cpp

    r5813ac rb59da6  
    2323#include <cmath>
    2424
    25 #include "Menu/DisplayMenuItem.hpp"
     25#include "Menu/TextMenu/DisplayMenuItem.hpp"
    2626#include "Views/StringView.hpp"
    2727
    2828
    29 DisplayMenuItem::DisplayMenuItem(Menu* _menu, StringView *_view):
     29DisplayMenuItem::DisplayMenuItem(TxMenu* const _menu, StringView *_view):
    3030  MenuItem('\0',"",_menu),
    3131  view(_view),
     
    3434}
    3535
    36 DisplayMenuItem::DisplayMenuItem(Menu* _menu, StringView *_view, string _title, char _spacer, int _length ):
     36DisplayMenuItem::DisplayMenuItem(TxMenu* const _menu, StringView *_view, const std::string &_title, char _spacer, int _length ):
    3737  MenuItem('\0',"",_menu),
    3838  view(_view),
     
    5252}
    5353
    54 const string DisplayMenuItem::formatEntry(){
    55   stringstream s;
     54const std::string DisplayMenuItem::formatEntry(){
     55  std::stringstream s;
    5656  if(title.length()>0) {
    5757    int pre = floor((length-title.length())/2.0);
     
    6969
    7070
    71 const string DisplayMenuItem::getDescription(){
    72   return string("");
     71const std::string DisplayMenuItem::getDescription(){
     72  return std::string("");
    7373}
  • src/UIElements/Menu/TextMenu/DisplayMenuItem.hpp

    r5813ac rb59da6  
    99#define DISPLAYMENUITEM_HPP_
    1010
    11 #include "Menu/MenuItem.hpp"
     11#include <string>
     12
     13#include "Menu/TextMenu/MenuItem.hpp"
    1214#include "defs.hpp"
    1315
    1416class StringView;
     17class TxMenu;
    1518
    1619/**
     
    2225{
    2326public:
    24   DisplayMenuItem(Menu* _menu, StringView *_view);
    25   DisplayMenuItem(Menu* _menu, StringView *_view, string _title,
     27  DisplayMenuItem(TxMenu* const _menu, StringView *_view);
     28  DisplayMenuItem(TxMenu* const _menu, StringView *_view, const std::string &_title,
    2629                  char _spacer=STD_MENU_TITLE_SPACER, int _length=STD_MENU_LENGTH);
    2730  virtual ~DisplayMenuItem();
     
    3033  virtual bool checkTrigger(char);
    3134
    32   virtual const string formatEntry();
     35  virtual const std::string formatEntry();
    3336
    34   virtual const string getDescription();
     37  virtual const std::string getDescription();
    3538
    3639private:
    3740  StringView *view;
    38   string title;
     41  std::string title;
    3942  int length;
    4043  char spacer;
  • src/UIElements/Menu/TextMenu/MenuItem.cpp

    r5813ac rb59da6  
    2020#include "Helpers/MemDebug.hpp"
    2121
    22 #include "Menu/MenuItem.hpp"
     22#include "Menu/TextMenu/MenuItem.hpp"
     23#include "Menu/TextMenu/TxMenu.hpp"
    2324#include "Menu/Menu.hpp"
    2425#include <sstream>
    25 #include <iostream>
    2626
    2727/**
     
    2929 * The MenuItem is then added to the menu passed to it.
    3030 */
    31 MenuItem::MenuItem(char _trigger, const char* _description,Menu* menu) :
     31MenuItem::MenuItem(char _trigger, const std::string &_description,TxMenu* const menu) :
    3232  trigger(_trigger),
     33  description(_description),
    3334  added(false)
    3435{
    35   description = new string(_description);
    3636  add_to_menu(menu);
    3737}
    3838
    3939MenuItem::~MenuItem()
    40 {
    41   delete description;
    42 }
     40{}
    4341
    4442/**
     
    5957}
    6058
    61 const string MenuItem::getDescription() {
    62   return *description;
     59const std::string MenuItem::getDescription() {
     60  return description;
    6361}
    6462
     
    6765 * Normal format is: "<trigger> - <description>"
    6866 */
    69 const string MenuItem::formatEntry(){
    70   stringstream s;
     67const std::string MenuItem::formatEntry(){
     68  std::stringstream s;
    7169  s << getTrigger() << " - " << getDescription();
    7270
     
    8078 * TODO: include funtionality to move Items from one menu to another
    8179 */
    82 void MenuItem::add_to_menu(Menu* menu) {
     80void MenuItem::add_to_menu(TxMenu* const menu) {
    8381  if(!wasAdded()) {
    8482    menu->addItem(this);
  • src/UIElements/Menu/TextMenu/MenuItem.hpp

    r5813ac rb59da6  
    1111#include <string>
    1212
    13 using namespace std;
    14 
    15 class Menu;
     13class TxMenu;
    1614
    1715/**
     
    2220class MenuItem {
    2321public:
    24   MenuItem(char,const char*,Menu*);
     22  MenuItem(char,const std::string &,TxMenu* const);
    2523  virtual ~MenuItem();
    2624
     
    2826  virtual bool checkTrigger(char);
    2927
    30   virtual const string formatEntry();
     28  virtual const std::string formatEntry();
    3129
    32   virtual const string getDescription();
     30  virtual const std::string getDescription();
    3331  char getTrigger();
    3432
    35   void add_to_menu(Menu*);
     33  void add_to_menu(TxMenu* const);
    3634  bool wasAdded();
    3735
    3836  virtual bool isActive();
    3937
    40 protected:
    41   void setDescription(string);
    42 
    4338private:
    4439  char trigger;
    45   string *description;
     40  const std::string description;
    4641  bool added;
    4742};
  • src/UIElements/Menu/TextMenu/SeperatorItem.cpp

    r5813ac rb59da6  
    2323#include <sstream>
    2424
    25 #include "Menu/SeperatorItem.hpp"
    26 #include "Menu/Menu.hpp"
     25#include "Menu/TextMenu/SeperatorItem.hpp"
    2726#include "defs.hpp"
    2827
    2928
    30 SeperatorItem::SeperatorItem(Menu* menu):
     29SeperatorItem::SeperatorItem(TxMenu* const menu):
    3130  MenuItem('\0',"",menu),
    3231  spacer(STD_SEPERATOR_SPACER),
     
    3736}
    3837
    39 SeperatorItem::SeperatorItem(Menu* menu,char _spacer, int _length):
     38SeperatorItem::SeperatorItem(TxMenu* const menu,char _spacer, int _length):
    4039  MenuItem('\0',"",menu),
    4140  spacer(_spacer),
     
    5756}
    5857
    59 const string SeperatorItem::getDescription() {
    60   return string("");
     58const std::string SeperatorItem::getDescription() {
     59  return std::string("");
    6160}
    6261
    63 const string SeperatorItem::formatEntry(){
    64   stringstream s;
     62const std::string SeperatorItem::formatEntry(){
     63  std::stringstream s;
    6564  for(int i=0; i<length;i++)
    6665    s << spacer;
  • src/UIElements/Menu/TextMenu/SeperatorItem.hpp

    r5813ac rb59da6  
    99#define SEPERATORITEM_H_
    1010
    11 #include "Menu/MenuItem.hpp"
     11#include <string>
     12
     13#include "Menu/TextMenu/MenuItem.hpp"
     14
     15class TxMenu;
    1216
    1317/**
     
    1923{
    2024public:
    21   SeperatorItem(Menu*);
    22   SeperatorItem(Menu*,char,int);
     25  SeperatorItem(TxMenu* const );
     26  SeperatorItem(TxMenu* const ,char,int);
    2327  virtual ~SeperatorItem();
    2428
     
    2630  virtual bool checkTrigger(char);
    2731
    28   virtual const string getDescription();
     32  virtual const std::string getDescription();
    2933
    30   virtual const string formatEntry();
     34  virtual const std::string formatEntry();
    3135private:
    3236  char spacer;
  • src/UIElements/Menu/TextMenu/SubMenuItem.cpp

    r5813ac rb59da6  
    2020#include "Helpers/MemDebug.hpp"
    2121
    22 #include "SubMenuItem.hpp"
     22#include <iostream>
    2323
    24 SubMenuItem::SubMenuItem(char _trigger,const char* _description,Menu* _parent, Menu* _theMenu) :
     24#include "Menu/TextMenu/SubMenuItem.hpp"
     25#include "Menu/TextMenu/TxMenu.hpp"
     26
     27SubMenuItem::SubMenuItem(char _trigger,const std::string &_description,TxMenu* const _parent, TxMenu* const _instance) :
    2528  MenuItem(_trigger,_description,_parent),
    26   theMenu(_theMenu)
    27 {
    28 }
     29  theMenu(_instance)
     30{}
    2931
    3032SubMenuItem::~SubMenuItem()
    31 {
    32   delete theMenu;
    33 }
     33{}
    3434
    3535void SubMenuItem::doTrigger() {
  • src/UIElements/Menu/TextMenu/TxMenu.cpp

    r5813ac rb59da6  
    77
    88/*
    9  * TextMenu.cpp
     9 * TxMenu.cpp
    1010 *
    1111 *  Created on: Dec 10, 2009
     
    2121
    2222#include <boost/bind.hpp>
     23#include <algorithm>
    2324#include <iostream>
    2425#include <cmath>
    25 #include "Menu/TextMenu.hpp"
    26 #include "Menu/MenuItem.hpp"
     26#include "Actions/Action.hpp"
     27#include "Actions/ActionTraits.hpp"
     28#include "Menu/TextMenu/TxMenu.hpp"
     29#include "Menu/TextMenu/MenuItem.hpp"
    2730#include "Helpers/Assert.hpp"
    2831
     
    3235 * The text will later be displayed using the stream passed to the constructor.
    3336 */
    34 TextMenu::TextMenu(ostream& _outputter, const string _title, char _spacer,int _length) :
     37TxMenu::TxMenu(std::ostream& _outputter, const std::string _title, char _spacer,int _length) :
    3538  defaultItem(0),
    3639  outputter(_outputter),
     
    4245}
    4346
    44 TextMenu::~TextMenu()
     47TxMenu::~TxMenu()
    4548{
    46   for(list<MenuItem*>::iterator it=items.begin(); it != items.end(); it++)
     49  for(std::list<MenuItem*>::iterator it=items.begin(); it != items.end(); it++)
    4750    delete (*it);
    4851}
    4952
    50 
    51 void TextMenu::addItem(MenuItem* item) {
     53void TxMenu::addItem(MenuItem* item) {
    5254  items.push_back(item);
    5355}
    5456
    55 void TextMenu::removeItem(MenuItem* item) {
     57void TxMenu::removeItem(MenuItem* item) {
    5658  items.remove(item);
    5759}
    5860
    59 void TextMenu::doQuit(){
     61void TxMenu::doQuit(){
    6062  quit = true;
    6163}
    6264
    63 bool TextMenu::hasQuit(){
     65bool TxMenu::hasQuit(){
    6466  return quit;
    6567}
    6668
    67 void TextMenu::showEntry(MenuItem* entry){
     69void TxMenu::showEntry(MenuItem* entry){
    6870  if(entry->isActive()==false){
    6971    outputter << "(";
     
    7678}
    7779
    78 void TextMenu::display() {
     80void TxMenu::display() {
    7981  char choice;
    8082  bool somethingChosen = false;
     
    8991          outputter << spacer;
    9092    outputter << '\n';
    91     for_each(items.begin(), items.end(), boost::bind(&TextMenu::showEntry,this,_1));
     93    for_each(items.begin(), items.end(), boost::bind(&TxMenu::showEntry,this,_1));
    9294    outputter.flush();
    9395
    94     cin >> choice;
     96    std::cin >> choice;
    9597
    96     list<MenuItem*>::iterator iter;
     98    std::list<MenuItem*>::iterator iter;
    9799    for(iter = items.begin(); iter!=items.end();iter++){
    98100      if((*iter)->isActive()){
     
    106108      }
    107109      else{
    108         outputter << "Invalid Choice!" <<  endl;
     110        outputter << "Invalid Choice!" <<  std::endl;
    109111      }
    110112    }
     
    112114}
    113115
    114 string TextMenu::getTitle(){
     116std::string TxMenu::getTitle(){
    115117  return title;
    116118}
    117119
    118 void TextMenu::addDefault(MenuItem* _defaultItem) {
     120std::ostream& TxMenu::getOutputter()
     121{
     122  return outputter;
     123}
     124
     125
     126void TxMenu::addDefault(MenuItem* _defaultItem) {
    119127  defaultItem = _defaultItem;
    120128}
     
    122130/****************************** Contained Actions ****************/
    123131
    124 TextMenu::LeaveAction::LeaveAction(TextMenu* _menu, const ActionTraits & LeaveActionTrait) :
    125   Action(LeaveActionTrait, false),
     132TxMenu::LeaveAction::LeaveAction(TxMenu* const _menu, const ActionTraits & LeaveActionTrait) :
     133  Action(LeaveActionTrait, true),
    126134  menu(_menu)
    127135{}
    128136
    129 TextMenu::LeaveAction::~LeaveAction(){}
     137TxMenu::LeaveAction::~LeaveAction(){}
    130138
    131 bool TextMenu::LeaveAction::canUndo(){
     139bool TxMenu::LeaveAction::canUndo(){
    132140  return false;
    133141}
    134142
    135 bool TextMenu::LeaveAction::shouldUndo(){
     143bool TxMenu::LeaveAction::shouldUndo(){
    136144  return false;
    137145}
    138146
    139 void TextMenu::LeaveAction::getParametersfromValueStorage()
     147void TxMenu::LeaveAction::getParametersfromValueStorage()
    140148{}
    141149
    142 Dialog* TextMenu::LeaveAction::fillDialog(Dialog *dialog){
     150Dialog* TxMenu::LeaveAction::fillDialog(Dialog *dialog){
    143151  ASSERT(dialog,"No Dialog given when filling action dialog");
    144152  return dialog;
     
    146154
    147155
    148 Action::state_ptr TextMenu::LeaveAction::performCall(){
     156Action::state_ptr TxMenu::LeaveAction::performCall(){
    149157  menu->doQuit();
    150158  return Action::success;
     
    152160
    153161
    154 Action::state_ptr TextMenu::LeaveAction::performUndo(Action::state_ptr){
     162Action::state_ptr TxMenu::LeaveAction::performUndo(Action::state_ptr){
    155163  ASSERT(0,"Cannot undo leaving a menu");
    156164  return Action::success;
    157165}
    158166
    159 Action::state_ptr TextMenu::LeaveAction::performRedo(Action::state_ptr){
     167Action::state_ptr TxMenu::LeaveAction::performRedo(Action::state_ptr){
    160168  ASSERT(0,"Cannot redo leaving a menu");
    161169  return Action::success;
  • src/UIElements/Menu/TextMenu/TxMenu.hpp

    r5813ac rb59da6  
    11/*
    2  * TextMenu.h
     2 * TxMenu.h
    33 *
    44 *  Created on: Dec 10, 2009
     
    66 */
    77
    8 #ifndef TEXTMENU_H_
    9 #define TEXTMENU_H_
     8#ifndef TXMENU_H_
     9#define TXMENU_H_
    1010
    1111#include <list>
     
    2525 * All Items are displayed and user is prompted for a key. The item corresponding to that key is then activated.
    2626 */
    27 class TextMenu : public Menu
     27class TxMenu
    2828{
    2929public:
    3030  class LeaveAction : public Action {
    3131  public:
    32     LeaveAction(TextMenu*, const ActionTraits &_trait);
     32    LeaveAction(TxMenu* const, const ActionTraits &_trait);
    3333    virtual ~LeaveAction();
    3434
     
    4444    virtual Action::state_ptr performRedo(Action::state_ptr);
    4545
    46     ActionTraits *LeaveActionTrait;
    47     TextMenu* menu;
     46    TxMenu* const menu;
    4847  };
    4948
    50   TextMenu(ostream& _outputter, const string _title, char _spacer=STD_MENU_TITLE_SPACER,int _length=STD_MENU_LENGTH);
    51   virtual ~TextMenu();
     49  TxMenu(std::ostream& _outputter, const std::string _title, char _spacer=STD_MENU_TITLE_SPACER,int _length=STD_MENU_LENGTH);
     50  virtual ~TxMenu();
    5251
    53   virtual void addItem(MenuItem*);
    54   virtual void removeItem(MenuItem*);
    55   virtual void display();
    56   virtual string getTitle();
     52  void addItem(MenuItem*);
     53  void removeItem(MenuItem*);
     54  void display();
     55  std::string getTitle();
     56  std::ostream& getOutputter();
     57  char getSuitableShortForm(std::set <char> &ShortcutList, const std::string name) const;
    5758
    5859  /**
    5960   * Call doQuit if you want to return from this menu.
    6061   */
    61   virtual void doQuit();
     62  void doQuit();
    6263  /**
    6364   * Check whether someone has chosen to quit
    6465   */
    65   virtual bool hasQuit();
     66  bool hasQuit();
    6667
    67   virtual void addDefault(MenuItem*);
     68  void addDefault(MenuItem*);
    6869
    6970protected:
    70   virtual void showEntry(MenuItem*);
     71  void showEntry(MenuItem*);
    7172
    7273private:
    73   list<MenuItem*> items;
     74  std::list<MenuItem*> items;
    7475
    7576  MenuItem* defaultItem;
    7677
    77   ostream& outputter;
    78   string title;
     78  std::ostream& outputter;
     79  std::string title;
    7980  char spacer;
    8081  int length;
     
    8384};
    8485
    85 #endif /* TEXTMENU_H_ */
     86#endif /* TXMENU_H_ */
Note: See TracChangeset for help on using the changeset viewer.