ICF 3.1.1.10
Technical documentation of ICF Libraries
CCommandTools.h
Go to the documentation of this file.
1/********************************************************************************
2** This file is part of the ICF Framework. Copyright (C) Witold Gantzke & Kirill Lepskiy
3** ICF Framework may be used under the terms of the LGPL License v. 2.1 by the Free Software Foundation.
4********************************************************************************/
5
6#ifndef iqtgui_CCommandTools_included
7#define iqtgui_CCommandTools_included
8
9
10// Qt includes
11#include <QtCore/QtGlobal>
12#include <QtWidgets/QMenu>
13#include <QtWidgets/QMenuBar>
14#include <QtWidgets/QToolBar>
15#include <QtGui/QAction>
16#include <QtGui/QActionGroup>
17
18// ICF includes
20
22
23
24namespace istdgui
25{
26
27
32{
33public:
37 template <class MenuType>
38 static void CreateMenu(const istdgui::CHierarchicalCommand& command, MenuType& result);
39
43 static int SetupToolbar(
44 const istdgui::CHierarchicalCommand& command,
45 QToolBar& result,
46 int prevGroupId = ibase::ICommand::GI_NONE,
47 int* counterPtr = nullptr);
48
52 static int SetupContextMenu(
53 const istdgui::CHierarchicalCommand& command,
54 QWidget& menuOwner,
55 int prevGroupId = ibase::ICommand::GI_NONE,
56 int* counterPtr = nullptr);
57};
58
59
60// protected template methods
61
62template <class MenuType>
63void CCommandTools::CreateMenu(const istdgui::CHierarchicalCommand& command, MenuType& result)
64{
65 int prevGroupId = ibase::ICommand::GI_NONE;
66
67 int childsCount = command.GetChildsCount();
68
69 QMap<int, QActionGroup*> groups;
70
71 for (int i = 0; i < childsCount; ++i){
72 QString text = command.text();
74 dynamic_cast<const istdgui::CHierarchicalCommand*>(command.GetChild(i)));
75
76 if (hierarchicalPtr != nullptr){
77 QString text2 = hierarchicalPtr->text();
78 int groupId = hierarchicalPtr->GetGroupId();
79 int flags = hierarchicalPtr->GetStaticFlags();
80
81 if ((groupId != prevGroupId) && (prevGroupId != ibase::ICommand::GI_NONE)){
82 result.addSeparator();
83 }
84
85 if (groupId != ibase::ICommand::GI_NONE){
86 prevGroupId = groupId;
87 }
88
89 if (hierarchicalPtr->GetChildsCount() > 0){
90 QMenu* newMenuPtr = new QMenu(&result);
91 newMenuPtr->setTitle(hierarchicalPtr->GetName());
92
93 CreateMenu<QMenu>(*hierarchicalPtr, *newMenuPtr);
94
95 result.addMenu(newMenuPtr);
96 }
97 else if ((flags & ibase::ICommand::CF_GLOBAL_MENU) != 0){
98 if ((flags & ibase::ICommand::CF_EXCLUSIVE) != 0){
99 QActionGroup*& groupPtr = groups[hierarchicalPtr->GetGroupId()];
100 if (groupPtr == nullptr){
101 groupPtr = new QActionGroup(&result);
102 groupPtr->setExclusive(true);
103 }
104
105 groupPtr->addAction(hierarchicalPtr);
106 hierarchicalPtr->setCheckable(true);
107 }
108
109 result.addAction(hierarchicalPtr);
110 }
111 }
112 }
113}
114
115
116} // namespace istdgui
117
118
119#endif // !iqtgui_CCommandTools_included
120
121
@ CF_EXCLUSIVE
Enable exclusive selection of this command with other commands in the same node with the same group I...
Definition ICommand.h:67
@ CF_GLOBAL_MENU
Enable to use this command in global application menu.
Definition ICommand.h:42
const QString & GetName() const override
Get the object name.
Helper class to manage menu and toolbar using CHierarchicalCommand.
static int SetupToolbar(const istdgui::CHierarchicalCommand &command, QToolBar &result, int prevGroupId=ibase::ICommand::GI_NONE, int *counterPtr=nullptr)
Fill a toolbar with the commands.
static void CreateMenu(const istdgui::CHierarchicalCommand &command, MenuType &result)
Create menu according to the given commands.
static int SetupContextMenu(const istdgui::CHierarchicalCommand &command, QWidget &menuOwner, int prevGroupId=ibase::ICommand::GI_NONE, int *counterPtr=nullptr)
Fill a context menu of a widget with the commands.
Implementation of hierarchical command based on QAction from Qt.
int GetGroupId() const override
int GetStaticFlags() const override
ibase::ICommand * GetChild(int index) const override
Get child value.
int GetChildsCount() const override
Get number of childs.
Standard GUI specific interfaces and components based on Qt.

© Witold Gantzke and Kirill Lepskiy