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.
File:
1 edited

Legend:

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

    r5813ac rb59da6  
    2020#include "Helpers/MemDebug.hpp"
    2121
    22 #include "Menu.hpp"
     22#include <iostream>
    2323
    24 Menu::Menu()
     24#include "Actions/ActionRegistry.hpp"
     25#include "Actions/Action.hpp"
     26#include "Actions/ActionTraits.hpp"
     27#include "Menu/Menu.hpp"
     28
     29/** Constructor of class Menu.
     30 * \param &_name name of menu
     31 */
     32Menu::Menu(const std::string &_name) :
     33  MenuInterface(_name),
     34  name(_name),
     35  TopPosition(0),
     36  LastItem(NoItem)
     37{}
     38
     39/** Destructor of class Menu.
     40 *
     41 */
     42Menu::~Menu()
     43{}
     44
     45/** Initialiser for class Menu.
     46 * Fills menus with items.
     47 */
     48void Menu::init()
    2549{
    26   // TODO Auto-generated constructor stub
    27 
     50  populate();
     51  populateActions();
    2852}
    2953
    30 Menu::~Menu()
     54/** Initializing function.
     55 * Inserts Menus and Actions obtained from MenuDescription and
     56 * ActionRegistry.
     57 */
     58void Menu::populate()
    3159{
    32   // TODO Auto-generated destructor stub
     60  // go through all menus and create them
     61
     62  bool CompleteFlag = false;  // indicates whether all menus have been added
     63  bool PossibleMissingFlag = false; // indicates whether a separator is missing
     64  while (!CompleteFlag) {
     65    CompleteFlag = true;
     66    PossibleMissingFlag = false;
     67    for(MenuDescription::const_iterator iter = menudescriptions.getBeginIter();
     68        iter != menudescriptions.getEndIter();
     69        ++iter) {
     70      // skip when already present
     71      if (!isPresent(iter->first)) {
     72        // have some short refs to infos
     73        const std::string &MenuName = iter->first;
     74        const std::string &TopName = iter->second.first;
     75        const int &MenuPosition = iter->second.second;
     76        std::cout << "MenuName is " << MenuName
     77            << ", TopName is " << TopName
     78            << " and Position is " << MenuPosition
     79            << std::endl;
     80
     81        // does it belong to us?
     82        if (TopName == name) {
     83          if (MenuPosition-1 == TopPosition) {
     84            Menu::addSubmenu(MenuName, MenuPosition);
     85            CompleteFlag = false;
     86          }
     87          // is there a menuposition specified that we have not reached yet?
     88          if (MenuPosition-1 > TopPosition)
     89            PossibleMissingFlag = true;
     90        }
     91      }
     92    }
     93    if (PossibleMissingFlag && (CompleteFlag)) {
     94      Menu::addSeparator();
     95      CompleteFlag = false; // pass once more as there should be a menu to come
     96    }
     97  }
    3398}
     99
     100/** Fills this menu with all Actions that belong to it.
     101 */
     102void Menu::populateActions()
     103{
     104  // go through all actions and add those beloning to this menu
     105  ActionRegistry &AR = ActionRegistry::getInstance();
     106  for (ActionRegistry::const_iterator iter = AR.getBeginIter();
     107      iter != AR.getEndIter();
     108      ++iter) {
     109    const std::string &MenuName = iter->second->Traits.getMenuName();
     110    if (MenuName == name) {
     111      const std::string &ActionName = iter->first;
     112      Menu::addAction(ActionName);
     113    }
     114  }
     115}
     116
     117void Menu::addAction(const std::string &ActionName)
     118{
     119  LastItem = ActionItem;
     120  addActionItem(ActionName, ActionName);
     121}
     122
     123void Menu::addSeparator()
     124{
     125  std::cout << "Creating separator at position " << TopPosition << std::endl;
     126  ASSERT( LastItem != SeparatorItem,
     127      "Menu::populate() - adding another separator after a separator!");
     128  LastItem = SeparatorItem;
     129  addSeparatorItem();
     130  TopPosition++;
     131}
     132
     133void Menu::addSubmenu(const std::string &MenuName, const int MenuPosition)
     134{
     135  std::cout << "Creating top-level menu " << MenuName
     136      << " at position " << TopPosition << std::endl;
     137  ASSERT (!isPresent(MenuName),
     138      "Menu::addSubmenu() - trying to add menu "+MenuName+" with already present token!");
     139  addSubmenuItem(MenuName, menudescriptions.getDescription(MenuName));
     140  DuplicatesList.insert(MenuName);
     141  LastItem = MenuItem;
     142  TopPosition = MenuPosition;
     143}
     144
     145bool Menu::isPresent(const std::string &token)
     146{
     147  return (DuplicatesList.find(token) != DuplicatesList.end());
     148}
Note: See TracChangeset for help on using the changeset viewer.