79 QAction *
createCommand(
int id,
const QString &title = QString(), QWidget *context =
nullptr);
117 template <
typename T>
118 void connectCommand(
int id, T method);
120 template <
typename T>
121 void connectCommand(
int id, T *
object,
void (T::*method)());
123 template <
typename T>
124 void connectCommand(
int id, T *
object,
void (T::*method)(
unsigned int));
126 template <
typename T>
127 void connectCommandRange(
int first,
int last, T *
object,
void (T::*method)(
unsigned int));
130 template <
typename T>
131 void connectCommandUpdater(
int id, T method);
133 template <
typename T>
134 void connectCommandUpdater(
int id, T *
object,
void (T::*method)(QAction *));
136 template <
typename T>
137 void connectCommandRangeUpdater(
int first,
int last, T *
object,
void (T::*method)(QAction *));
140 template <
typename Func>
141 void visitCommands(Func fn);
150 QMenu *
createMenu(
const QString &title, QWidget *parent =
nullptr);
162 QToolBar *
createToolBar(
int id,
const QString &title, QWidget *context =
nullptr);
164 void addToolBar(
int id, QToolBar *toolBar, QWidget *context =
nullptr);
184 void updateAllMenus();
185 void triggerUpdate(QAction *action)
const;
187 QTimer *m_updateTimer;
188 QHash<int, QAction *> m_actions;
189 QHash<int, QToolBar *> m_toolbars;
190 QSignalMapper *m_actionMapper;
191 QHash<int, std::function<void()>> m_actionSlots;
192 QHash<int, QVector<std::function<void()>>> m_actionUpdates;
198 m_actionSlots[id] = method;
211 (
object->*method)(
id);
217 for (
int id = first;
id <= last; ++id)
224 m_actionUpdates[id].append([
this,
id, method] {
225 method(m_actions.value(
id));
233 (
object->*method)(action);
240 for (
int id = first;
id <= last; ++id)
244template <
typename Func>
247 for (
const auto action : m_actions)
The KCommandManager class emulates the way MFC command handling.
Definition kcommandmanager.h:63
void visitCommands(Func fn)
Visits each command in the command manager and applies the given function.
Definition kcommandmanager.h:245
void connectCommandUpdater(int id, T method)
Connects an update handler to the command with the given id.
Definition kcommandmanager.h:222
void addToolBar(int id, QToolBar *toolBar, QWidget *context=nullptr)
Adds an existing toolbar, to manage the update of the toolbar items.
void addMenu(QMenu *menu)
Adds an existing menu, to manage the update of the menu items.
QAction * findOrCreateCommand(int id, const QString &title=QString(), QWidget *context=nullptr)
Find or create a command object.
void triggerCommandAsync(int id) const
Triggers the command with the given id asynchronously.
void commandUpdated()
Emitted when commands have been updated.
KCommandManager(QObject *parent=nullptr)
QAction * command(int id)
Returns the command with the given id, or nullptr if it doesn't exist.
void updateAllToolBars()
Updates the state of the commands on all toolbars.
void connectCommand(int id, T method)
Connects a command handler to the command with the given id.
Definition kcommandmanager.h:196
void connectCommandRangeUpdater(int first, int last, T *object, void(T::*method)(QAction *))
Connects an update handler to a range of commands.
Definition kcommandmanager.h:238
QToolBar * createToolBar(int id, const QString &title, QWidget *context=nullptr)
Creates a toolbar with the given title.
void triggerCommand(int id) const
Triggers the command with the given id.
bool hasCommand(int id) const
Returns true if a command with the given id exists.
QMenu * createMenu(QWidget *parent=nullptr)
Creates a menu with the given title.
void stopUpdateTimer()
Stops the update timer.
void connectCommandRange(int first, int last, T *object, void(T::*method)(unsigned int))
Connects a command handler to a range of commands.
Definition kcommandmanager.h:215
QMenu * createMenu(const QString &title, QWidget *parent=nullptr)
Creates a menu with the given title.
QWidgetAction * createWidgetCommand(int id, QWidget *defaultWidget, QWidget *context=nullptr)
Create a Widget command object.
void setCommandChecked(int id, bool checked)
Checks or unchecks the command with the given id.
void clearAllCommands()
Removes all commands.
QAction * createCommand(int id, const QString &title=QString(), QWidget *context=nullptr)
Create a command object.
void startUpdateTimer()
Starts the update timer.
void setCommandEnabled(int id, bool enabled)
Enables or disables the command with the given id.
QToolBar * toolBar(int id) const
Returns the toolbar with the given id.
void removeCommand(int id)
Returns the command with the given id.
#define KDWINUTILS_EXPORT
Definition kdwinutils_export.h:31
#define KDWINUTILS_BEGIN_NAMESPACE
Definition kdwinutils_global.h:27
#define KDWINUTILS_END_NAMESPACE
Definition kdwinutils_global.h:28