kwave  18.07.70
Kwave::MenuRoot Class Reference

#include <MenuRoot.h>

Inheritance diagram for Kwave::MenuRoot:
Inheritance graph
Collaboration diagram for Kwave::MenuRoot:
Collaboration graph

Public Member Functions

 MenuRoot (QMenuBar &bar)
 
virtual ~MenuRoot () Q_DECL_OVERRIDE
 
virtual void insertNode (const QString &name, const QString &position, const QString &command, const QKeySequence &shortcut, const QString &uid) Q_DECL_OVERRIDE
 
virtual Kwave::MenuSubinsertBranch (const QString &name, const QString &command, const QKeySequence &shortcut, const QString &uid) Q_DECL_OVERRIDE
 
virtual Kwave::MenuNodeinsertLeaf (const QString &name, const QString &command, const QKeySequence &shortcut, const QString &uid) Q_DECL_OVERRIDE
 
virtual void removeChild (Kwave::MenuNode *child) Q_DECL_OVERRIDE
 
virtual bool specialCommand (const QString &command) Q_DECL_OVERRIDE
 
virtual QHash< QString, Kwave::MenuGroup * > & groupList () Q_DECL_OVERRIDE
 
- Public Member Functions inherited from Kwave::MenuNode
 MenuNode (Kwave::MenuNode *parent, const QString &name, const QString &command, const QKeySequence &shortcut, const QString &uid)
 
virtual ~MenuNode ()
 
const QString path () const
 
const QString & name () const
 
const QString & command () const
 
virtual QAction * action ()
 
const QString & uid () const
 
void setUID (const QString &uid)
 
const QKeySequence & shortcut () const
 
virtual void setShortcut (const QKeySequence &shortcut)
 
virtual const QIcon icon ()
 
virtual void setIcon (const QIcon &icon)
 
virtual bool isBranch () const
 
virtual void clear ()
 
virtual Kwave::MenuNodeparentNode () const
 
virtual void setVisible (bool visible)
 
virtual bool isEnabled ()
 
virtual void setEnabled (bool enable)
 
virtual void setChecked (bool check)
 
virtual void setText (const QString &text)
 
Kwave::MenuNodefindUID (const QString &uid)
 
Kwave::MenuNodefindChild (const QString &name)
 
virtual void insertChild (Kwave::MenuNode *node, Kwave::MenuNode *before)
 
virtual Kwave::MenuNodeleafToBranch (Kwave::MenuNode *node)
 
virtual void actionSelected ()
 
void joinGroup (const QString &group, Kwave::MenuGroup::Mode mode)
 
void leaveGroup (const QString &group)
 

Static Public Member Functions

static void deleteLater (Kwave::MenuNode *node)
 

Protected Member Functions

void showChild (Kwave::MenuSub *child)
 
void hideChild (Kwave::MenuSub *child)
 
- Protected Member Functions inherited from Kwave::MenuNode
Kwave::MenuNoderootNode ()
 
void emitCommand (const QString &command)
 

Private Attributes

QMenuBar & m_menu_bar
 
QHash< QString, Kwave::MenuGroup * > m_group_list
 

Static Private Attributes

static QList< Kwave::MenuNode * > m_garbage
 

Friends

class MenuSub
 

Additional Inherited Members

- Signals inherited from Kwave::MenuNode
void sigCommand (const QString &command)
 
- Protected Attributes inherited from Kwave::MenuNode
QList< Kwave::MenuNode * > m_children
 
QStringList m_groups
 

Detailed Description

This is the class for the root of a Menu (e.g. a MenuBar) that contains all toplevel menus of a menu hierarchy.

Author
Thomas Eschenbacher

Definition at line 39 of file MenuRoot.h.

Constructor & Destructor Documentation

◆ MenuRoot()

Kwave::MenuRoot::MenuRoot ( QMenuBar &  bar)
explicit

Constructor.

Parameters
barreference to a QMenuBar

Definition at line 38 of file MenuRoot.cpp.

39  :Kwave::MenuNode(Q_NULLPTR, _("(root)"), QString(), 0, QString()),
40  m_menu_bar(bar), m_group_list()
41 {
42 }
QHash< QString, Kwave::MenuGroup * > m_group_list
Definition: MenuRoot.h:155
#define _(m)
Definition: memcpy.c:66
QMenuBar & m_menu_bar
Definition: MenuRoot.h:152

◆ ~MenuRoot()

Kwave::MenuRoot::~MenuRoot ( )
virtual

Destructor

Definition at line 45 of file MenuRoot.cpp.

References Kwave::MenuNode::clear().

46 {
47  clear();
48 }
virtual void clear()
Definition: MenuNode.cpp:93
Here is the call graph for this function:

Member Function Documentation

◆ deleteLater()

void Kwave::MenuRoot::deleteLater ( Kwave::MenuNode node)
static

replacement for QObject::deleteLater(...), which does not work in this context

Definition at line 177 of file MenuRoot.cpp.

References m_garbage.

Referenced by Kwave::MenuNode::leafToBranch().

178 {
179  if (node) m_garbage.append(node);
180 }
static QList< Kwave::MenuNode * > m_garbage
Definition: MenuRoot.h:158
Here is the caller graph for this function:

◆ groupList()

QHash< QString, Kwave::MenuGroup * > & Kwave::MenuRoot::groupList ( )
virtual

Returns a pointer to the list of groups

Reimplemented from Kwave::MenuNode.

Definition at line 51 of file MenuRoot.cpp.

References m_group_list.

Referenced by hideChild(), removeChild(), Kwave::MenuManager::selectItem(), Kwave::MenuManager::setItemEnabled(), and showChild().

52 {
53  return m_group_list;
54 }
QHash< QString, Kwave::MenuGroup * > m_group_list
Definition: MenuRoot.h:155
Here is the caller graph for this function:

◆ hideChild()

void Kwave::MenuRoot::hideChild ( Kwave::MenuSub child)
protected

Makes a child node invisible, by removing it from the menu bar

Parameters
childpointer to the child node (normally a MenuSub)

Definition at line 110 of file MenuRoot.cpp.

References Kwave::MenuNode::action(), Kwave::MenuSub::action(), groupList(), Kwave::MenuNode::m_children, m_menu_bar, and Kwave::MenuNode::name().

Referenced by Kwave::MenuSub::setVisible().

111 {
112  Q_ASSERT(child);
113  if (!child) return;
114  if (!m_children.contains(child)) return;
115  if (groupList().contains(child->name())) return;
116 
117  QAction *action = child->action();
118  if (action) m_menu_bar.removeAction(action);
119 }
virtual QHash< QString, Kwave::MenuGroup * > & groupList() Q_DECL_OVERRIDE
Definition: MenuRoot.cpp:51
const QString & name() const
Definition: MenuNode.h:74
QList< Kwave::MenuNode * > m_children
Definition: MenuNode.h:317
virtual QAction * action() Q_DECL_OVERRIDE
Definition: MenuSub.h:102
QMenuBar & m_menu_bar
Definition: MenuRoot.h:152
virtual QAction * action()
Definition: MenuNode.h:80
Here is the call graph for this function:
Here is the caller graph for this function:

◆ insertBranch()

Kwave::MenuSub * Kwave::MenuRoot::insertBranch ( const QString &  name,
const QString &  command,
const QKeySequence &  shortcut,
const QString &  uid 
)
virtual

Inserts a new branch node into the menu structure.

Parameters
namenon-localized name of the node
commandthe command template used for creating commands of submenus (leafes) that don't have an own command but contain data for their parent's command. Should contain a s that will be replaced by some data from a child entry. (this is used for menus with data selection lists like "recent files) If not used, pass 0.
shortcutkeyboard shortcut, 0 if unused
uidunique id string (might be 0)
Returns
pointer to the new branch node

Reimplemented from Kwave::MenuNode.

Definition at line 73 of file MenuRoot.cpp.

References Kwave::MenuNode::insertChild(), and m_menu_bar.

77 {
78  QMenu *menu = m_menu_bar.addMenu(name);
79  Q_ASSERT(menu);
80  if (!menu) return Q_NULLPTR;
81 
82  Kwave::MenuSub *sub = new(std::nothrow)
83  Kwave::MenuSub(this, menu, name, command, shortcut, uid);
84  Q_ASSERT(sub);
85  if (!sub) return Q_NULLPTR;
86 
87  insertChild(sub, Q_NULLPTR);
88 
89  return sub;
90 }
const QKeySequence & shortcut() const
Definition: MenuNode.h:95
virtual void insertChild(Kwave::MenuNode *node, Kwave::MenuNode *before)
Definition: MenuNode.cpp:181
const QString & name() const
Definition: MenuNode.h:74
const QString & command() const
Definition: MenuNode.h:77
const QString & uid() const
Definition: MenuNode.h:85
QMenuBar & m_menu_bar
Definition: MenuRoot.h:152
Here is the call graph for this function:

◆ insertLeaf()

Kwave::MenuNode * Kwave::MenuRoot::insertLeaf ( const QString &  name,
const QString &  command,
const QKeySequence &  shortcut,
const QString &  uid 
)
virtual

Inserts a new leaf node into the menu structure. The new node normally is (derived from) MenuItem.

Parameters
namenon-localized name of the node
commandthe command to be sent when the node is selected (might be 0)
shortcutkeyboard shortcut, 0 if unused
uidunique id string (might be 0)
Returns
pointer to the new leaf node

Reimplemented from Kwave::MenuNode.

Definition at line 93 of file MenuRoot.cpp.

References Kwave::MenuItem::action(), Kwave::MenuNode::insertChild(), and m_menu_bar.

97 {
98  Kwave::MenuItem *item = new(std::nothrow)
100  Q_ASSERT(item);
101  if (!item) return Q_NULLPTR;
102 
103  insertChild(item, Q_NULLPTR);
104  m_menu_bar.addAction(item->action());
105 
106  return item;
107 }
const QKeySequence & shortcut() const
Definition: MenuNode.h:95
virtual void insertChild(Kwave::MenuNode *node, Kwave::MenuNode *before)
Definition: MenuNode.cpp:181
const QString & name() const
Definition: MenuNode.h:74
const QString & command() const
Definition: MenuNode.h:77
const QString & uid() const
Definition: MenuNode.h:85
QMenuBar & m_menu_bar
Definition: MenuRoot.h:152
virtual QAction * action() Q_DECL_OVERRIDE
Definition: MenuItem.h:122
Here is the call graph for this function:

◆ insertNode()

void Kwave::MenuRoot::insertNode ( const QString &  name,
const QString &  position,
const QString &  command,
const QKeySequence &  shortcut,
const QString &  uid 
)
virtual

overloaded version from MenuNode, which does a cleanup of the "garbage collector" afterwards.

See also
MenuNode::insertNode()
Parameters
namenon-localized name of the first node (might be 0)
positionpath consiting of several node names separated by a '/'. All strings are non-localized.
commandthe command to be sent when the node is selected (might be 0)
shortcutkeyboard shortcut, 0 if unused
uidunique id string (might be 0)

Reimplemented from Kwave::MenuNode.

Definition at line 57 of file MenuRoot.cpp.

References Kwave::MenuNode::insertNode(), and m_garbage.

Referenced by Kwave::MenuManager::executeCommand().

62 {
64 
65  // now delete all leafs that have been converted to branches
66  while (!m_garbage.isEmpty()) {
67  Kwave::MenuNode *node = m_garbage.takeFirst();
68  if (node) delete node;
69  }
70 }
static QList< Kwave::MenuNode * > m_garbage
Definition: MenuRoot.h:158
const QKeySequence & shortcut() const
Definition: MenuNode.h:95
const QString & name() const
Definition: MenuNode.h:74
const QString & command() const
Definition: MenuNode.h:77
const QString & uid() const
Definition: MenuNode.h:85
virtual void insertNode(const QString &name, const QString &position, const QString &command, const QKeySequence &shortcut, const QString &uid)
Definition: MenuNode.cpp:256
Here is the call graph for this function:
Here is the caller graph for this function:

◆ removeChild()

void Kwave::MenuRoot::removeChild ( Kwave::MenuNode child)
virtual

Removes a child node of the current node. If the child was not found or is already removed this does nothing.

Parameters
childpointer to the child node

Reimplemented from Kwave::MenuNode.

Definition at line 146 of file MenuRoot.cpp.

References Kwave::MenuNode::action(), groupList(), Kwave::MenuNode::m_children, m_menu_bar, Kwave::MenuNode::name(), and Kwave::MenuNode::removeChild().

147 {
148  Q_ASSERT(child);
149  if (!child) return;
150  if (!m_children.contains(child)) return;
151 
152  QHash<QString, Kwave::MenuGroup *> &group_list = groupList();
153  if (!group_list.contains(child->name())) {
154  // only remove what has been added to the menu bar,
155  // but not menu groups
156  QAction *action = child->action();
157  if (action) m_menu_bar.removeAction(action);
158  }
160 }
virtual QHash< QString, Kwave::MenuGroup * > & groupList() Q_DECL_OVERRIDE
Definition: MenuRoot.cpp:51
virtual void removeChild(Kwave::MenuNode *child)
Definition: MenuNode.cpp:223
const QString & name() const
Definition: MenuNode.h:74
QList< Kwave::MenuNode * > m_children
Definition: MenuNode.h:317
QMenuBar & m_menu_bar
Definition: MenuRoot.h:152
virtual QAction * action()
Definition: MenuNode.h:80
Here is the call graph for this function:

◆ showChild()

void Kwave::MenuRoot::showChild ( Kwave::MenuSub child)
protected

Makes a child node visible, by adding it to the menu bar

Parameters
childpointer to the child node (normally a MenuSub)

Definition at line 122 of file MenuRoot.cpp.

References Kwave::MenuNode::action(), groupList(), Kwave::MenuNode::m_children, m_menu_bar, Kwave::MenuSub::menu(), and Kwave::MenuNode::name().

Referenced by Kwave::MenuSub::setVisible().

123 {
124  Q_ASSERT(child);
125  if (!child) return;
126  if (!m_children.contains(child)) return;
127  if (groupList().contains(child->name())) return;
128 
129  // find the menu bar entry after which we can insert
130  QAction *action_before = Q_NULLPTR;
131  QListIterator<Kwave::MenuNode *> it(m_children);
132  it.toBack();
133  while (it.hasPrevious()) {
134  Kwave::MenuNode *c = it.previous();
135  if (c == child) break;
136  if (c) action_before = c->action();
137  }
138 
139  if (action_before)
140  m_menu_bar.insertMenu(action_before, child->menu());
141  else
142  m_menu_bar.addMenu(child->menu());
143 }
virtual QHash< QString, Kwave::MenuGroup * > & groupList() Q_DECL_OVERRIDE
Definition: MenuRoot.cpp:51
const QString & name() const
Definition: MenuNode.h:74
virtual QMenu * menu()
Definition: MenuSub.h:150
QList< Kwave::MenuNode * > m_children
Definition: MenuNode.h:317
QMenuBar & m_menu_bar
Definition: MenuRoot.h:152
virtual QAction * action()
Definition: MenuNode.h:80
Here is the call graph for this function:
Here is the caller graph for this function:

◆ specialCommand()

bool Kwave::MenuRoot::specialCommand ( const QString &  command)
virtual

Handles/interprets special menu commands.

Parameters
commandname of a menu node or command
Returns
true if the name was recognized as a command and handled

Reimplemented from Kwave::MenuNode.

Definition at line 163 of file MenuRoot.cpp.

References _, m_menu_bar, and Kwave::MenuNode::specialCommand().

164 {
165  Q_ASSERT(command.length());
166  if (!command.length()) return false;
167 
168  if (command == _("#separator")) {
169  m_menu_bar.addSeparator();
170  return true;
171  }
172 
174 }
virtual bool specialCommand(const QString &command)
Definition: MenuNode.cpp:421
const QString & command() const
Definition: MenuNode.h:77
#define _(m)
Definition: memcpy.c:66
QMenuBar & m_menu_bar
Definition: MenuRoot.h:152
Here is the call graph for this function:

Friends And Related Function Documentation

◆ MenuSub

friend class MenuSub
friend

Definition at line 135 of file MenuRoot.h.

Member Data Documentation

◆ m_garbage

QList< Kwave::MenuNode * > Kwave::MenuRoot::m_garbage
staticprivate

list of nodes to delete, as deleteLater() does not work :-(

garbage collector for menu nodes

Definition at line 158 of file MenuRoot.h.

Referenced by deleteLater(), and insertNode().

◆ m_group_list

QHash<QString, Kwave::MenuGroup *> Kwave::MenuRoot::m_group_list
private

list of menu groups

Definition at line 155 of file MenuRoot.h.

Referenced by groupList().

◆ m_menu_bar

QMenuBar& Kwave::MenuRoot::m_menu_bar
private

reference to a QMenuBar

Definition at line 152 of file MenuRoot.h.

Referenced by hideChild(), insertBranch(), insertLeaf(), removeChild(), showChild(), and specialCommand().


The documentation for this class was generated from the following files: