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/Qt4/QtMainWindow.cpp

    r5813ac rb59da6  
    3939#include "Actions/ActionRegistry.hpp"
    4040#include "Actions/ValueStorage.hpp"
    41 #include "Menu/MenuDescription.hpp"
    42 #include "Menu/Menu.hpp"
    4341#include "Menu/Qt4/QtMenu.hpp"
    44 #include "Menu/ActionMenuItem.hpp"
    45 #include "Menu/SubMenuItem.hpp"
    4642#include "Views/Qt4/QtWorldView.hpp"
    4743#include "Views/Qt4/GLMoleculeView.hpp"
     
    6056  molecule3dDisplay = new GLMoleculeView();
    6157
    62   MenuBar = menuBar();
    63 
    64   // populate menus and add actions
    65   {
    66     QtMenuReferenceMap NametoTextMenuMap; // contains token to menu reference map
    67     MenuShortcutMap ShortcutMap;
    68     populateMenu(NametoTextMenuMap, ShortcutMap);
    69     populateMenuWithActions(NametoTextMenuMap, ShortcutMap);
    70   }
     58  MainMenu = new QtMenu<QMenuBar>(menuBar(), "");
     59  MainMenu->init();
    7160
    7261  setCentralWidget(splitter1);
     
    9382}
    9483
    95 /** Puts Qt's token, the ampersand, in front of the accelerator char in the menu name.
    96  * \param ShortcutMap map to all already present accelerator keys
    97  * \param MenuName Action of menu
    98  * \param ActionName Action of menu
    99  * \return name with ampersand added at the right place
    100  */
    101 std::string QtMainWindow::getNameWithAccelerator(MenuShortcutMap &ShortcutMap, const std::string &MenuName, const std::string &ActionName) const
    102 {
    103   std::string newname;
    104   bool Inserted = false;
    105   std::pair < MenuShortcutMap::iterator, bool > Inserter;
    106   for (std::string::const_iterator CharRunner = ActionName.begin(); CharRunner != ActionName.end(); ++CharRunner) {
    107     if (!Inserted) {
    108       Inserter = ShortcutMap.insert( std::pair<std::string, char> (MenuName, *CharRunner) );
    109       if (Inserter.second) {
    110         newname += '&';
    111         Inserted = true;
    112       }
    113     }
    114     newname += *CharRunner;
    115   }
    116   return newname;
    117 }
    118 
    119 /** Instantiate all menus.
    120  * \param NametoTextMenuMap lookup for token to menu reference
    121  */
    122 void QtMainWindow::populateMenu(QtMenuReferenceMap &NametoTextMenuMap, MenuShortcutMap &ShortcutMap)
    123 {
    124   // go through all menus and create them
    125   std::map <std::string, int> TopPositions;
    126   TopPositions.insert( std::pair<std::string, int> ("", 0) ); // contains which position was added last
    127   QtMenu *Menu = NULL;
    128   MenuDescription menudescriptions;
    129   std::set <char> ShortcutList;
    130   bool CompleteFlag = false;
    131   while (!CompleteFlag) {
    132     CompleteFlag = true;
    133     for(MenuDescription::const_iterator iter = menudescriptions.getBeginIter(); iter != menudescriptions.getEndIter(); ++iter) {
    134       // skip when already present
    135       if (NametoTextMenuMap.find(iter->first) == NametoTextMenuMap.end()) {
    136         // have some short refs to infos
    137         const std::string &MenuName = iter->first;
    138         const std::string &TopName = iter->second.first;
    139         const int &MenuPosition = iter->second.second;
    140         std::cout << "MenuName is " << MenuName << ", TopName is " << TopName << " and Position is " << MenuPosition << std::endl;
    141 
    142         // is it top level?
    143         if (TopName == "") {
    144           ASSERT(TopPositions.find(TopName) != TopPositions.end(),
    145               "QtMainWindow::QtMainWindow() - "+TopName+" not present in TopPositions.");
    146           if (MenuPosition-1 == TopPositions[TopName]) {
    147             std::cout << "Creating top-level menu " << MenuName << " at position " << MenuPosition << std::endl;
    148             Menu = new QtMenu(getNameWithAccelerator(ShortcutMap, TopName, MenuName).c_str());
    149             MenuBar->addMenu(Menu);
    150             NametoTextMenuMap.insert( pair <std::string, QtMenu *> (MenuName, Menu) );
    151             CompleteFlag = false;
    152             TopPositions[TopName] = MenuPosition;
    153             TopPositions[MenuName] = 0;
    154           }
    155         }
    156         // is it a submenu and the top-level menu is present?
    157         else if (NametoTextMenuMap.find(TopName) != NametoTextMenuMap.end()) {
    158           ASSERT(TopPositions.find(TopName) != TopPositions.end(),
    159               "QtMainWindow::QtMainWindow() - "+TopName+" not present in TopPositions.");
    160           if (MenuPosition-1 == TopPositions[TopName]) {
    161             QtMenu *& TopMenu = NametoTextMenuMap[TopName];
    162             std::cout << "Creating submenu " << MenuName << " to menu " << TopName << " at position " << MenuPosition << std::endl;
    163             Menu = new QtMenu(getNameWithAccelerator(ShortcutMap, TopName, MenuName).c_str());
    164             TopMenu->addMenu(Menu);
    165             NametoTextMenuMap.insert( pair <std::string, QtMenu *> (MenuName, Menu) );
    166             CompleteFlag = false;
    167             TopPositions[TopName] = MenuPosition;
    168           }
    169         }
    170       }
    171     }
    172   }
    173 }
    174 
    175 /** Instantiate all actions within the menus.
    176  * \param NametoTextMenuMap lookup for token to menu reference
    177  * \param ShortcutMap map for all shortcuts within one menu
    178  */
    179 void QtMainWindow::populateMenuWithActions(QtMenuReferenceMap &NametoTextMenuMap, MenuShortcutMap &ShortcutMap)
    180 {
    181   typedef std::multimap <std::string, std::string> MenuMap;
    182 
    183   // go through all menus
    184   MenuDescription md;
    185   MenuMap MenuItems = md.getMenuItemsMap();
    186   QtMenu *Menu = NULL;
    187   Action *ActionItem = NULL;
    188   std::string OldMenuName;
    189   for (MenuMap::const_iterator MenuRunner = MenuItems.begin(); MenuRunner != MenuItems.end(); ++MenuRunner) {
    190     const std::string &ActionName = MenuRunner->second;
    191     const std::string &MenuName = MenuRunner->first;
    192     // add the actions to this menu
    193     std::cout << " Adding " << ActionName << " to submenu " << MenuName << std::endl;
    194     ActionItem = ActionRegistry::getInstance().getActionByName(ActionName);
    195     ASSERT(NametoTextMenuMap.find(MenuName) != NametoTextMenuMap.end(),
    196         "QtMainWindow::populateMenu() - cannot find reference for menu "+MenuName+" in NametoTextMenuMap.");
    197     Menu = NametoTextMenuMap[MenuName];
    198     //ASSERT(ShortcutMap.find(MenuName) != ShortcutMap.end(),
    199       //  "QtMainWindow::populateMenuWithActions() - missing "+MenuName+" in ShortcutMap.");
    200     new ActionMenuItem(
    201         'a',
    202         ActionItem->Traits.getDescription().c_str(),
    203         Menu,
    204         ActionItem);
    205   }
    206 }
Note: See TracChangeset for help on using the changeset viewer.