36 #include <QtCore/QDebug>
43 using namespace Core::Internal;
160 m_data = ((m_data & ~
EA_Mask) | ea);
165 return (m_data &
EA_Mask) == ea;
178 int pos = ((grpid << 16) | 0xFFFF);
179 return beforeAction(pos, &prevKey);
190 if (!group.isEmpty())
192 if (!m_groups.contains(grpid) && !am->
defaultGroups().contains(grpid))
193 qWarning() <<
"*** addAction(): Unknown group: " << group;
194 int pos = ((grpid << 16) | 0xFFFF);
207 if (!group.isEmpty())
209 if (!m_groups.contains(grpid) && !am->
defaultGroups().contains(grpid))
210 qWarning() <<
"*** addMenu(): Unknown group: " << group;
211 int pos = ((grpid << 16) | 0xFFFF);
232 return (action->
action() !=
nullptr);
240 QAction *ba = beforeAction(pos, &prevKey);
243 pos = calcPosition(pos, prevKey);
252 m_commands.append(action);
253 m_posmap.insert(pos, action->
id());
262 QAction *ba = beforeAction(pos, &prevKey);
265 pos = calcPosition(pos, prevKey);
272 m_subContainers.append(menu);
273 m_posmap.insert(pos, menu->
id());
277 QAction *ActionContainerPrivate::beforeAction(
int pos,
int *prevKey)
const
285 QMap<int, int>::const_iterator
i = m_posmap.constBegin();
286 while (i != m_posmap.constEnd()) {
291 (*prevKey) = i.key();
298 if (Command *cmd = am->
command(baId))
299 return cmd->action();
301 if (QMenu *
menu = container->menu())
302 return menu->menuAction();
307 int ActionContainerPrivate::calcPosition(
int pos,
int prevKey)
const
309 int grp = (pos & 0xFFFF0000);
313 int prevgrp = (prevKey & 0xFFFF0000);
318 return grp + (prevKey & 0xFFFF) + 10;
340 qVariantSetValue<MenuActionContainer *>(v,
this);
342 m_menu->menuAction()->setData(v);
352 m_menu->insertAction(before, action);
357 m_menu->insertMenu(before, menu);
375 bool hasitems =
false;
378 if (container ==
this) {
379 qWarning() << Q_FUNC_INFO <<
"container" << (this->
menu() ? this->
menu()->title() :
"")
380 <<
"contains itself as subcontainer";
383 if (container->
update()) {
398 m_menu->setVisible(hasitems);
400 m_menu->setEnabled(hasitems);
436 m_menuBar->insertAction(before, action);
441 m_menuBar->insertMenu(before, menu);
449 bool hasitems =
false;
451 for (
int i = 0; i < actions.size(); ++
i) {
452 if (actions.at(i)->isVisible()) {
459 m_menuBar->setVisible(hasitems);
461 m_menuBar->setEnabled(hasitems);
static UniqueIDManager * instance()
virtual void insertAction(QAction *before, QAction *action)=0
bool canBeAddedToMenu() const
int uniqueIdentifier(const QString &id)
void setMenuBar(QMenuBar *menuBar)
QMenuBar * menuBar() const
virtual bool canBeAddedToMenu() const =0
CommandLocation location() const
void insertMenu(QAction *before, QMenu *menu)
void insertAction(QAction *before, QAction *action)
void setLocation(const CommandLocation &location)
virtual QAction * action() const =0
QAction * insertLocation(const QString &group) const
QList< Command * > commands() const
Command * command(int uid) const
void addAction(Command *action, const QString &group=QString())
void setMenu(QMenu *menu)
void addMenu(ActionContainer *menu, const QString &group=QString())
void insertAction(QAction *before, QAction *action)
static ActionManagerPrivate * instance()
QList< CommandLocation > locations() const
QList< ActionContainer * > subContainers() const
virtual void insertMenu(QAction *before, QMenu *menu)=0
void appendGroup(const QString &group)
void setLocations(const QList< CommandLocation > &locations)
bool canAddAction(Command *action) const
virtual bool isActive() const =0
MenuBarActionContainer(int id)
void insertMenu(QAction *before, QMenu *menu)
Q_DECLARE_METATYPE(Core::Internal::MenuActionContainer *) using namespace Core
ActionContainer * actionContainer(int uid) const
bool hasEmptyAction(EmptyAction ea) const
virtual int id() const =0
const char *const G_DEFAULT_TWO
void setEmptyAction(EmptyAction ea)
QMenuBar * menuBar() const
virtual int id() const =0
QList< int > defaultGroups() const
MenuActionContainer(int id)
The class Command represents an action like a menu item, tool button, or shortcut. You don't create Command objects directly, instead use {ActionManager::registerAction()} to register an action and retrieve a Command. The Command object represents the user visible action and its properties. If multiple actions are registered with the same ID (but different contexts) the returned Command is the shared one between these actions.
The ActionContainer class represents a menu or menu bar in the Tau Labs GCS.
bool canBeAddedToMenu() const