Changeset ffb9ad for src/UIElements


Ignore:
Timestamp:
Nov 9, 2010, 3:38:03 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:
5813ac
Parents:
e262c7
git-author:
Frederik Heber <heber@…> (11/01/10 20:29:58)
git-committer:
Frederik Heber <heber@…> (11/09/10 15:38:03)
Message:

FIX: Menu entries are again correctly added to QtGui part.

Location:
src/UIElements
Files:
5 edited

Legend:

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

    re262c7 rffb9ad  
    1313 */
    1414
     15#include <iostream>
    1516#include <map>
    1617#include <string>
     
    2425MenuDescription::MenuDescription()
    2526{
    26   // put each menu into set
    27   MenuSet.insert("analysis");
    28   MenuSet.insert("atom");
    29   MenuSet.insert("command");
    30   MenuSet.insert("fragmentation");
    31   MenuSet.insert("molecule");
    32   MenuSet.insert("parser");
    33   MenuSet.insert("selection");
    34   MenuSet.insert("tesselation");
    35   MenuSet.insert("world");
     27  // put each menu into its place, "" means top level
     28  MenuPositionMap["analysis"] = TopPosition("tools",1);
     29  MenuPositionMap["atom"] = TopPosition("edit",1);
     30  MenuPositionMap["command"] = TopPosition("",3);
     31  MenuPositionMap["edit"] = TopPosition("",2);
     32  MenuPositionMap["fragmentation"] = TopPosition("tools",3);
     33  MenuPositionMap["molecule"] = TopPosition("edit",2);
     34  MenuPositionMap["parser"] = TopPosition("edit",3);
     35  MenuPositionMap["selection"] = TopPosition("edit",4);
     36  MenuPositionMap["tesselation"] = TopPosition("tools",2);
     37  MenuPositionMap["tools"] = TopPosition("",4);
     38  MenuPositionMap["world"] = TopPosition("",1);
    3639
    3740  // put menu description into each menu category
     
    3942  MenuDescriptionsMap["atom"] = "Edit atoms";
    4043  MenuDescriptionsMap["command"] = "Configuration";
     44  MenuDescriptionsMap["edit"] = "Edit";
    4145  MenuDescriptionsMap["fragmentation"] = "Fragmentation";
    4246  MenuDescriptionsMap["molecule"] = "Parse files into system";
     
    4448  MenuDescriptionsMap["selection"] = "Select atoms/molecules";
    4549  MenuDescriptionsMap["tesselation"] = "Tesselate molecules";
     50  MenuDescriptionsMap["tools"] = "Various tools";
    4651  MenuDescriptionsMap["world"] = "Edit world";
    4752
     
    4954  MenuNameMap["analysis"] = "Analysis";
    5055  MenuNameMap["atom"] = "Atoms";
    51   MenuNameMap["command"] = "configuration options";
     56  MenuNameMap["command"] = "Configuration";
     57  MenuNameMap["edit"] = "Edit";
    5258  MenuNameMap["fragmentation"] = "Fragmentation";
    5359  MenuNameMap["molecule"] = "Molecules";
     
    5561  MenuNameMap["selection"] = "Selection";
    5662  MenuNameMap["tesselation"] = "Tesselation";
     63  MenuNameMap["tools"] = "Tools";
    5764  MenuNameMap["world"] = "Globals";
    5865}
     
    97104  ActionRegistry &AR = ActionRegistry::getInstance();
    98105  for (ActionRegistry::const_iterator iter = AR.getBeginIter();iter != AR.getEndIter();++iter) {
     106    std::cout << "Inserting " << (iter->second)->getName() << " into menu " << (iter->second)->Traits.getMenuName() << std::endl;
    99107    result.insert( std::pair<std::string, std::string> ((iter->second)->Traits.getMenuName(), (iter->second)->getName()));
    100108  }
     
    108116MenuDescription::iterator MenuDescription::getBeginIter()
    109117{
    110   return MenuSet.begin();
     118  return MenuPositionMap.begin();
    111119}
    112120
     
    116124MenuDescription::iterator MenuDescription::getEndIter()
    117125{
    118   return MenuSet.end();
     126  return MenuPositionMap.end();
    119127}
    120128
     
    124132MenuDescription::const_iterator MenuDescription::getBeginIter() const
    125133{
    126   return MenuSet.begin();
     134  return MenuPositionMap.begin();
    127135}
    128136
     
    132140MenuDescription::const_iterator MenuDescription::getEndIter() const
    133141{
    134   return MenuSet.end();
     142  return MenuPositionMap.end();
    135143}
    136144
  • src/UIElements/Menu/MenuDescription.hpp

    re262c7 rffb9ad  
    2525  ~MenuDescription();
    2626
    27   typedef std::set<std::string>::iterator iterator;
    28   typedef std::set<std::string>::const_iterator const_iterator ;
     27  typedef std::pair<std::string, int> TopPosition;
     28  typedef std::map<std::string, TopPosition> IterableMap;
     29  typedef IterableMap::iterator iterator;
     30  typedef IterableMap::const_iterator const_iterator ;
     31  typedef std::map<std::string, std::string> TextMap;
    2932
    3033  // getter for description
     
    4144
    4245private:
    43   std::set<std::string> MenuSet;
    44   std::map<std::string, std::string> MenuDescriptionsMap;
    45   std::map<std::string, std::string> MenuNameMap;
     46  TextMap MenuDescriptionsMap;
     47  IterableMap MenuPositionMap;
     48  TextMap MenuNameMap;
    4649  std::multimap <std::string, std::string> MenuItemMap;
    4750};
  • src/UIElements/Qt4/QtMainWindow.cpp

    re262c7 rffb9ad  
    4343#include "Menu/Qt4/QtMenu.hpp"
    4444#include "Menu/ActionMenuItem.hpp"
     45#include "Menu/SubMenuItem.hpp"
    4546#include "Views/Qt4/QtWorldView.hpp"
    4647#include "Views/Qt4/GLMoleculeView.hpp"
     
    4849#include "Views/Qt4/QtStatusBar.hpp"
    4950
    50 using namespace std;
    51 
    5251QtMainWindow::QtMainWindow(QApplication *_theApp) :
    5352    theApp(_theApp)
     
    6362  MenuBar = menuBar();
    6463
    65   std::map <std::string, QtMenu *> NametoTextMenuMap;
    66   // go through all menus and create them
    67   QtMenu *Menu = NULL;
    68   MenuDescription menudescriptions;
    69   for(MenuDescription::const_iterator iter = menudescriptions.getBeginIter(); iter != menudescriptions.getEndIter(); ++iter) {
    70     cout << "Creating menu " << *iter << endl;
    71     Menu = new QtMenu(menudescriptions.getName(*iter).c_str());
    72     MenuBar->addMenu(Menu);
    73     NametoTextMenuMap.insert( pair <std::string, QtMenu *> (menudescriptions.getName(*iter), Menu) );
    74     //new SubMenuItem(getSuitableShortForm(menudescriptions.getName(iter->first.c_str())),menudescriptions.getName(iter->first.c_str()),main_menu,Menu);
    75   }
    76 
    77   // go through all actions and add them to its menu
    78   for (std::map <std::string, QtMenu *>::iterator MenuRunner = NametoTextMenuMap.begin(); MenuRunner != NametoTextMenuMap.end(); ++MenuRunner) {
    79     cout << "Creating Action " << MenuRunner->first << " in menu " << MenuRunner->second << endl;
    80     populateMenu(MenuRunner->second, MenuRunner->first);
     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);
    8170  }
    8271
     
    9786{
    9887  menuBar()->clear();
    99   delete editMoleculesMenu;
    10088}
    10189
     
    10593}
    10694
    107 char QtMainWindow::getSuitableShortForm(set <char> &ShortcutList, const std::string name) const
    108 {
    109   for (std::string::const_iterator CharRunner = name.begin(); CharRunner != name.end(); ++CharRunner) {
    110     if (ShortcutList.find(*CharRunner) == ShortcutList.end())
    111       return *CharRunner;
    112   }
    113   DoeLog(1) && (eLog() << Verbose(1) << "Could not find a suitable shortform for TextWindow::getSuitableShortForm()." << endl);
    114   return ((char)(ShortcutList.size() % 10) + '0');
    115 }
    116 
    117 void QtMainWindow::populateMenu(QtMenu* Menu, const  std::string &MenuName)
    118 {
     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 */
     101std::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 */
     122void 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 */
     179void 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;
    119187  Action *ActionItem = NULL;
    120   set <char> ShortcutList;
    121   // through all actions for this menu
    122   MenuDescription md;
    123   std::multimap <std::string, std::string> MenuItems = md.getMenuItemsMap();
    124   std::pair < std::multimap <std::string, std::string>::iterator, std::multimap <std::string, std::string>::iterator > MenuActions = MenuItems.equal_range(MenuName);
    125   for (std::multimap <std::string, std::string>::const_iterator MenuRunner = MenuActions.first; MenuRunner != MenuActions.second; ++MenuRunner) {
    126     cout << " Adding " << MenuRunner->second << " to submenu " << MenuName << endl;
    127     ActionItem = ActionRegistry::getInstance().getActionByName(MenuRunner->second);
    128     new ActionMenuItem(getSuitableShortForm(ShortcutList, MenuRunner->second),ActionItem->Traits.getDescription().c_str(),Menu,ActionItem);
    129   }
    130   // finally add default quit item
    131   //Action *returnFromAction = new TextMenu::LeaveAction(Menu);
    132   //MenuItem *returnFromItem = new ActionMenuItem('q',"return to Main menu",Menu,returnFromAction);
    133   //Menu->addDefault(returnFromItem);
    134 }
     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}
  • src/UIElements/Qt4/QtMainWindow.hpp

    re262c7 rffb9ad  
    1212#include <QtGui/QMainWindow>
    1313
     14#include <map>
    1415#include <set>
    1516
     
    3132  virtual void display();
    3233
    33   char getSuitableShortForm(std::set <char> &ShortcutList, const std::string name) const;
    34   void populateMenu(QtMenu* Menu, const  std::string &MenuName);
    3534
    3635private:
     36  typedef std::map <std::string, QtMenu *> QtMenuReferenceMap;
     37  typedef std::map <std::string, char> MenuShortcutMap;
     38
     39  void populateMenu(QtMenuReferenceMap &NametoTextMenuMap, MenuShortcutMap &ShortcutMap);
     40  void populateMenuWithActions(QtMenuReferenceMap &NametoTextMenuMap, MenuShortcutMap &ShortcutMap);
     41  std::string getNameWithAccelerator(MenuShortcutMap &ShortcutMap, const std::string &MenuName, const std::string &ActionName) const;
     42
    3743  // All kinds of QTStuff used in this window
    3844  QApplication *theApp;
    3945  QtWorldView *worldDisplay;
    40   QtMenu *editMoleculesMenu;
    4146  GLMoleculeView *molecule3dDisplay;
    4247  QtMoleculeView *moleculeDisplay;
  • src/UIElements/TextUI/TextWindow.cpp

    re262c7 rffb9ad  
    8181  MenuDescription menudescriptions;
    8282  for(MenuDescription::const_iterator iter = menudescriptions.getBeginIter(); iter != menudescriptions.getEndIter(); ++iter) {
    83     TextMenu *Menu = new TextMenu((ostream &)std::cout, menudescriptions.getDescription(*iter));
    84     NametoTextMenuMap.insert( pair <std::string, TextMenu *> (*iter, Menu) );
    85     new SubMenuItem(getSuitableShortForm(ShortcutList,*iter),menudescriptions.getDescription(*iter).c_str(),main_menu,Menu);
     83    const std::string &MenuName = iter->first;
     84    TextMenu *Menu = new TextMenu((ostream &)std::cout, menudescriptions.getDescription(MenuName));
     85    NametoTextMenuMap.insert( pair <std::string, TextMenu *> (MenuName, Menu) );
     86    new SubMenuItem(getSuitableShortForm(ShortcutList,MenuName),menudescriptions.getDescription(MenuName).c_str(),main_menu,Menu);
    8687  }
    8788
Note: See TracChangeset for help on using the changeset viewer.