source: src/UIElements/Menu/Qt4/QtMenu.hpp@ ad7270

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
Last change on this file since ad7270 was ad7270, checked in by Frederik Heber <heber@…>, 14 years ago

Reduced initial verbosity of code.

FIX:

  • initUI() - no more admonishing of missing bond length table.

The following messages have been placed in comments:

  • Registering of Action/Options.
  • Looking for KnownTypes.
  • Stating MenuNames, Separators and submenu creations.
  • No more listing of parsed elements.
  • No more listing of thermostats.

The following messages have been added:

  • prepended scanning arguments in CommandLineParser::scan...().
  • prepended running arguments in CommandLineWindow::display().
  • additional new line after ProgamHeader().
  • correct CommandLine UI setting to occur before arguments are parsed.
  • changed verbosity levels of CommandLineParser::scanforSequenceOfArguments(), also all use DoLog(), i.e. global verbosity makes them be listed again.

NOTE:

  • MemDebug: as delete NULL is safe, we do not warn when this occurs. Also, in Qt this happens a lot.

TESTFIX:

  • setting global verbosity to 1, messed with Standard_Options/1. There we set verbosity to 9 to avoid this in the future.
  • Property mode set to 100644
File size: 3.1 KB
Line 
1/*
2 * QtMenu.hpp
3 *
4 * Created on: Nov 5, 2010
5 * Author: heber
6 */
7
8#ifndef MENUINTERFACEQT_HPP_
9#define MENUINTERFACEQT_HPP_
10
11#include <Qt/qaction.h>
12
13#include <iostream>
14#include <list>
15#include <map>
16#include <string>
17
18#include "Menu/Menu.hpp"
19#include "Menu/MenuInterface.hpp"
20#include "Menu/Qt4/QtMenuPipe.hpp"
21
22/** QtMenu is a specialization of MenuInterface to Qt-like menus.
23 * I.e. with this interface we can access QMenu and QMenuBar.
24 * (The latter is the reason why we have to add this additional wrapping layer).
25 */
26template <class T>
27class QtMenu : virtual public MenuInterface, public Menu
28{
29public:
30 explicit QtMenu(const std::string &_token) :
31 MenuInterface(_token),
32 Menu(_token),
33 MenuInstance(new T(QString(getNameWithAccelerator(_token).c_str()))),
34 deleteMenu(true)
35 {}
36
37 QtMenu(T *_Menu, const std::string &_token) :
38 MenuInterface(_token),
39 Menu(_token),
40 MenuInstance(_Menu),
41 deleteMenu(false)
42 {}
43
44 virtual ~QtMenu()
45 {
46 for(std::list<QtMenuPipe*>::iterator it=plumbing.begin(); it != plumbing.end(); it++)
47 delete (*it);
48
49 if (deleteMenu)
50 delete MenuInstance;
51 }
52
53 T * const getMenuInstance()
54 {
55 return MenuInstance;
56 }
57
58protected:
59 // We need to have a reference of the Menu, as Qt returns reference to added menu as well
60 T *MenuInstance;
61
62 /** Puts Qt's token, the ampersand, in front of the accelerator char in the menu name.
63 * \param ActionName Action of menu
64 * \return name with ampersand added at the right place
65 */
66 std::string getNameWithAccelerator(const std::string &ActionName)
67 {
68 std::string newname;
69 bool Inserted = false;
70 std::pair < MenuShortcutMap::iterator, bool > Inserter;
71 for (std::string::const_iterator CharRunner = ActionName.begin();
72 CharRunner != ActionName.end();
73 ++CharRunner) {
74// std::cout << "Current char is " << *CharRunner << std::endl;
75 if (!Inserted) {
76 Inserter = ShortcutMap.insert(
77 std::pair<char, std::string > (*CharRunner, ActionName)
78 );
79 if (Inserter.second) {
80// std::cout << "Accelerator is " << *CharRunner << std::endl;
81 newname += '&';
82 Inserted = true;
83 }
84 }
85 newname += *CharRunner;
86 }
87 return newname;
88 }
89
90private:
91 bool deleteMenu;
92 std::list<QtMenuPipe*> plumbing;
93
94 typedef std::map <char, std::string> MenuShortcutMap;
95 MenuShortcutMap ShortcutMap;
96
97 virtual void addActionItem(const std::string &token, const std::string &description)
98 {
99 QAction *action = MenuInstance->addAction(QString(getNameWithAccelerator(description).c_str()));
100 QtMenuPipe *pipe = new QtMenuPipe(token,action);
101 QObject::connect(action, SIGNAL(triggered()),pipe,SLOT(called()));
102 plumbing.push_back(pipe);
103 }
104
105 virtual void addSeparatorItem()
106 {
107 MenuInstance->addSeparator();
108 }
109
110 virtual void addSubmenuItem(const std::string &token, const std::string &description)
111 {
112 QMenu *Menu = MenuInstance->addMenu(QString(token.c_str()));
113 QtMenu<QMenu> *NewMenu = new QtMenu<QMenu>(Menu, token);
114 NewMenu->init();
115 }
116
117};
118
119#endif /* MENUINTERFACEQT_HPP_ */
Note: See TracBrowser for help on using the repository browser.