kwave  18.07.70
Kwave::MenuNode Class Reference

#include <MenuNode.h>

Inheritance diagram for Kwave::MenuNode:
Inheritance graph
Collaboration diagram for Kwave::MenuNode:
Collaboration graph

Signals

void sigCommand (const QString &command)
 

Public Member Functions

 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 removeChild (Kwave::MenuNode *child)
 
virtual Kwave::MenuSubinsertBranch (const QString &name, const QString &command, const QKeySequence &shortcut, const QString &uid)
 
virtual Kwave::MenuNodeinsertLeaf (const QString &name, const QString &command, const QKeySequence &shortcut, const QString &uid)
 
virtual void insertChild (Kwave::MenuNode *node, Kwave::MenuNode *before)
 
virtual void insertNode (const QString &name, const QString &position, const QString &command, const QKeySequence &shortcut, const QString &uid)
 
virtual Kwave::MenuNodeleafToBranch (Kwave::MenuNode *node)
 
virtual bool specialCommand (const QString &command)
 
virtual void actionSelected ()
 
virtual QHash< QString, Kwave::MenuGroup * > & groupList ()
 
void joinGroup (const QString &group, Kwave::MenuGroup::Mode mode)
 
void leaveGroup (const QString &group)
 

Protected Member Functions

Kwave::MenuNoderootNode ()
 
void emitCommand (const QString &command)
 

Protected Attributes

QList< Kwave::MenuNode * > m_children
 
QStringList m_groups
 

Private Attributes

QString m_uid
 
QKeySequence m_shortcut
 
QString m_name
 
QString m_command
 
Kwave::MenuNodem_parentNode
 

Detailed Description

Base class for the MenuItem, MenuSub and the MenuRoot class.

Definition at line 43 of file MenuNode.h.

Constructor & Destructor Documentation

◆ MenuNode()

Kwave::MenuNode::MenuNode ( Kwave::MenuNode parent,
const QString &  name,
const QString &  command,
const QKeySequence &  shortcut,
const QString &  uid 
)

Constructor.

Parameters
parentpointer to the node's parent (might be 0)
namethe non-localized name of the node
commandthe command to be sent when the node is selected (optional, default=0)
shortcutkeyboard shortcut (optional, default=0)
uidunique id string (optional, default=0)

Definition at line 35 of file MenuNode.cpp.

40  :QObject(), m_children(), m_groups(), m_uid(uid), m_shortcut(shortcut),
42 {
43 }
QStringList m_groups
Definition: MenuNode.h:320
QString m_name
Definition: MenuNode.h:331
Kwave::MenuNode * m_parentNode
Definition: MenuNode.h:337
const QKeySequence & shortcut() const
Definition: MenuNode.h:95
const QString & name() const
Definition: MenuNode.h:74
const QString & command() const
Definition: MenuNode.h:77
QKeySequence m_shortcut
Definition: MenuNode.h:328
QList< Kwave::MenuNode * > m_children
Definition: MenuNode.h:317
QString m_command
Definition: MenuNode.h:334
QString m_uid
Definition: MenuNode.h:325
const QString & uid() const
Definition: MenuNode.h:85

◆ ~MenuNode()

Kwave::MenuNode::~MenuNode ( )
virtual

Destructor. Clears the menu node and cleans up.

See also
clear()

Definition at line 46 of file MenuNode.cpp.

References clear(), leaveGroup(), m_groups, m_parentNode, and removeChild().

47 {
48  // leave all groups
49  QStringList::iterator group = m_groups.begin();
50  while (group != m_groups.end()) {
51  leaveGroup(*group);
52  group = m_groups.begin();
53  }
54 
55  // remove all childs
56  clear();
57 
58  // de-register from our parent
60 }
QStringList m_groups
Definition: MenuNode.h:320
Kwave::MenuNode * m_parentNode
Definition: MenuNode.h:337
virtual void removeChild(Kwave::MenuNode *child)
Definition: MenuNode.cpp:223
virtual void clear()
Definition: MenuNode.cpp:93
void leaveGroup(const QString &group)
Definition: MenuNode.cpp:402
Here is the call graph for this function:

Member Function Documentation

◆ action()

virtual QAction* Kwave::MenuNode::action ( )
inlinevirtual

Returns the corresponding menu action

Reimplemented in Kwave::MenuItem, and Kwave::MenuSub.

Definition at line 80 of file MenuNode.h.

Referenced by Kwave::MenuRoot::hideChild(), Kwave::MenuSub::insertLeaf(), Kwave::MenuGroup::join(), Kwave::MenuGroup::leave(), Kwave::MenuSub::removeChild(), Kwave::MenuRoot::removeChild(), and Kwave::MenuRoot::showChild().

80 { return Q_NULLPTR; }
Here is the caller graph for this function:

◆ actionSelected()

void Kwave::MenuNode::actionSelected ( )
virtual

Called to notify the node that it has been selected.

Reimplemented in Kwave::MenuItem.

Definition at line 87 of file MenuNode.cpp.

References emitCommand(), and m_command.

Referenced by Kwave::MenuItem::actionSelected(), and isBranch().

88 {
89  if (m_command.length()) emitCommand(m_command);
90 }
void emitCommand(const QString &command)
Definition: MenuNode.cpp:70
QString m_command
Definition: MenuNode.h:334
Here is the call graph for this function:
Here is the caller graph for this function:

◆ clear()

void Kwave::MenuNode::clear ( )
virtual

Removes all child entries from the menu node (gui) and deletes the MenuNode objects (memory).

Reimplemented in Kwave::MenuList.

Definition at line 93 of file MenuNode.cpp.

References m_children.

Referenced by Kwave::MenuManager::clearNumberedMenu(), isBranch(), ~MenuNode(), and Kwave::MenuRoot::~MenuRoot().

94 {
95  // remove all children
96  while (!m_children.isEmpty()) {
97  Kwave::MenuNode *child = m_children.takeLast();
98  delete child;
99  }
100 }
QList< Kwave::MenuNode * > m_children
Definition: MenuNode.h:317
Here is the caller graph for this function:

◆ command()

const QString& Kwave::MenuNode::command ( ) const
inline

Returns the command of the node.

Definition at line 77 of file MenuNode.h.

References m_command.

Referenced by Kwave::MenuManager::addNumberedMenuEntry(), and leafToBranch().

77 { return m_command; }
QString m_command
Definition: MenuNode.h:334
Here is the caller graph for this function:

◆ emitCommand()

void Kwave::MenuNode::emitCommand ( const QString &  command)
protected

Emits a command if the node is the root node. If it is a client node it will call the root node's emitCommand() function.

See also
emitCommand()
rootNode()

Definition at line 70 of file MenuNode.cpp.

References emitCommand(), parentNode(), rootNode(), and sigCommand().

Referenced by actionSelected(), emitCommand(), and isBranch().

71 {
72  Q_ASSERT(command.length());
73  if (!command.length()) return ;
74 
75  if (!parentNode()) {
76  // no parent -> we are the root node -> we have to emit
77  emit sigCommand(command);
78  } else {
79  // tell the root node to emit
80  Kwave::MenuNode *root = rootNode();
81  Q_ASSERT(root);
82  if (root) root->emitCommand(command);
83  }
84 }
virtual Kwave::MenuNode * parentNode() const
Definition: MenuNode.cpp:103
void emitCommand(const QString &command)
Definition: MenuNode.cpp:70
const QString & command() const
Definition: MenuNode.h:77
void sigCommand(const QString &command)
Kwave::MenuNode * rootNode()
Definition: MenuNode.cpp:109
Here is the call graph for this function:
Here is the caller graph for this function:

◆ findChild()

Kwave::MenuNode * Kwave::MenuNode::findChild ( const QString &  name)

Tries to find a child node by it's name.

Parameters
namenon-localized name of the child node
Returns
pointer to the found node or 0 if not found

Definition at line 211 of file MenuNode.cpp.

References m_children, and name().

Referenced by insertNode(), and isBranch().

212 {
213  Q_ASSERT(name.length());
214 
215  foreach (Kwave::MenuNode *child, m_children) {
216  if (child && (name == child->name()))
217  return child;
218  }
219  return Q_NULLPTR;
220 }
const QString & name() const
Definition: MenuNode.h:74
QList< Kwave::MenuNode * > m_children
Definition: MenuNode.h:317
Here is the call graph for this function:
Here is the caller graph for this function:

◆ findUID()

Kwave::MenuNode * Kwave::MenuNode::findUID ( const QString &  uid)

Tries to find a menu node by it's unique id string. It descends recursively through all child nodes if necessary.

Parameters
uidthe unique id string to be searched
Returns
pointer to the found node or 0 if not found

Definition at line 198 of file MenuNode.cpp.

References findUID(), m_children, and m_uid.

Referenced by Kwave::MenuManager::addNumberedMenuEntry(), Kwave::MenuList::clear(), Kwave::MenuManager::clearNumberedMenu(), findUID(), isBranch(), Kwave::MenuManager::setItemChecked(), Kwave::MenuManager::setItemEnabled(), Kwave::MenuManager::setItemText(), Kwave::MenuManager::setItemVisible(), and specialCommand().

199 {
200  if (m_uid == uid) return this; // found ourself
201 
202  foreach (Kwave::MenuNode *child, m_children) {
203  Kwave::MenuNode *node = (child) ? child->findUID(uid) : Q_NULLPTR;
204  if (node) return node; // found in child
205  }
206 
207  return Q_NULLPTR; // nothing found :-(
208 }
Kwave::MenuNode * findUID(const QString &uid)
Definition: MenuNode.cpp:198
QList< Kwave::MenuNode * > m_children
Definition: MenuNode.h:317
QString m_uid
Definition: MenuNode.h:325
const QString & uid() const
Definition: MenuNode.h:85
Here is the call graph for this function:
Here is the caller graph for this function:

◆ groupList()

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

Returns a reference to the list of groups. It recursively calls all parent node's groupList() function until it reaches the root node of the menu structure that holds the list of groups and overwrites this function.

Returns
reference to the list of groups

Reimplemented in Kwave::MenuRoot.

Definition at line 370 of file MenuNode.cpp.

References groupList(), and m_parentNode.

Referenced by groupList(), isBranch(), isEnabled(), joinGroup(), leaveGroup(), Kwave::MenuGroup::MenuGroup(), and Kwave::MenuGroup::~MenuGroup().

371 {
372  static QHash<QString, Kwave::MenuGroup *> _empty_list;
373  Q_ASSERT(m_parentNode);
374  return (m_parentNode) ? m_parentNode->groupList() : _empty_list;
375 }
virtual QHash< QString, Kwave::MenuGroup * > & groupList()
Definition: MenuNode.cpp:370
Kwave::MenuNode * m_parentNode
Definition: MenuNode.h:337
Here is the call graph for this function:
Here is the caller graph for this function:

◆ icon()

const QIcon Kwave::MenuNode::icon ( )
virtual

Returns the menu nodes' icon.

Reimplemented in Kwave::MenuSub, and Kwave::MenuItem.

Definition at line 115 of file MenuNode.cpp.

Referenced by leafToBranch(), setShortcut(), and specialCommand().

116 {
117  static QIcon dummy;
118  Q_ASSERT(dummy.isNull());
119  return dummy;
120 }
Here is the caller graph for this function:

◆ insertBranch()

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

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

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 in Kwave::MenuRoot, and Kwave::MenuSub.

Definition at line 230 of file MenuNode.cpp.

Referenced by insertNode(), isBranch(), and leafToBranch().

234 {
235  Q_UNUSED(name);
236  Q_UNUSED(command);
237  Q_UNUSED(shortcut);
238  Q_UNUSED(uid);
239  return Q_NULLPTR;
240 }
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
Here is the caller graph for this function:

◆ insertChild()

void Kwave::MenuNode::insertChild ( Kwave::MenuNode node,
Kwave::MenuNode before 
)
virtual

Registers a node as a child of the current node.

Parameters
nodepointer to the child node
beforethe node before which the node should be inserted (optional, can be null for "append")

Definition at line 181 of file MenuNode.cpp.

References m_children.

Referenced by Kwave::MenuSub::insertBranch(), Kwave::MenuRoot::insertBranch(), Kwave::MenuSub::insertLeaf(), Kwave::MenuRoot::insertLeaf(), isBranch(), and specialCommand().

183 {
184  if (!node) return;
185  if (before && m_children.contains(before))
186  m_children.insert(m_children.indexOf(before), node);
187  else
188  m_children.append(node);
189 }
QList< Kwave::MenuNode * > m_children
Definition: MenuNode.h:317
Here is the caller graph for this function:

◆ insertLeaf()

Kwave::MenuNode * Kwave::MenuNode::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 in Kwave::MenuRoot, Kwave::MenuSub, and Kwave::MenuList.

Definition at line 243 of file MenuNode.cpp.

Referenced by Kwave::MenuManager::addNumberedMenuEntry(), Kwave::MenuList::insertLeaf(), insertNode(), and isBranch().

247 {
248  Q_UNUSED(name);
249  Q_UNUSED(command);
250  Q_UNUSED(shortcut);
251  Q_UNUSED(uid);
252  return Q_NULLPTR;
253 }
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
Here is the caller graph for this function:

◆ insertNode()

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

Inserts a new child node into the structure. If the specified position contains a path that doesn't completely exist, all missing branches will be appended.

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 in Kwave::MenuRoot.

Definition at line 256 of file MenuNode.cpp.

References findChild(), insertBranch(), insertLeaf(), insertNode(), isBranch(), leafToBranch(), setShortcut(), setUID(), and specialCommand().

Referenced by Kwave::MenuRoot::insertNode(), insertNode(), and isBranch().

261 {
262  int pos = 0;
263 
264  if (!position.length()) {
265  qWarning("MenuNode::insertNode: no position!");
266  return;
267  }
268 
269  // at start of the parsing process ?
270  if (!name.length()) {
271  // split off the first token, separated by a slash
272  pos = position.indexOf(QLatin1Char('/'));
273  if (pos < 0) pos = position.length();
274  }
275 
276  QString n = position.left(pos);
277  QString p = position;
278  p.remove(0, pos + 1);
279 
280  if ((n.length()) && (specialCommand(n))) {
281  // no new branch, only a special command
282  return;
283  }
284 
285  if ((!p.length()) || (p[0] == QLatin1Char('#'))) {
286  // end of the tree
287  Kwave::MenuNode *sub = findChild(n);
288  if (sub) {
289  // a leaf with this name already exists
290  // -> maybe we want to set new properties
291  if (!shortcut.isEmpty()) sub->setShortcut(shortcut);
292 
293  if (uid.length()) sub->setUID(uid);
294 
295  } else {
296  // insert a new leaf
297  sub = insertLeaf(n, command, shortcut, uid);
298  if (!sub) return;
299  }
300 
301  if (p[0] == QLatin1Char('#')) sub->specialCommand(p);
302 
303  } else {
304  // somewhere in the tree
305  Kwave::MenuNode *sub = findChild(n);
306  if (!sub) {
307  sub = insertBranch(n, command, shortcut, uid);
308  } else if ( !sub->isBranch() && (p[0] != QLatin1Char('#'))) {
309  // remove the "leaf" and insert a branch with
310  // the same properties
311  sub = leafToBranch(sub);
312  } else if (!p.length() || (p[0] == QLatin1Char('#')) ) {
313  // branch already exists and we are at the end of parsing
314  // -> maybe we want to set new properties
315  if (!shortcut.isEmpty()) sub->setShortcut(shortcut);
316  if (uid.length()) sub->setUID(uid);
317  }
318 
319  if (sub) {
320  sub->insertNode(QString(), p, command, shortcut, uid);
321  } else {
322  qDebug("MenuNode::insertNode: branch failed!");
323  }
324  }
325 }
virtual bool isBranch() const
Definition: MenuNode.h:119
void setUID(const QString &uid)
Definition: MenuNode.cpp:192
virtual Kwave::MenuNode * leafToBranch(Kwave::MenuNode *node)
Definition: MenuNode.cpp:328
const QKeySequence & shortcut() const
Definition: MenuNode.h:95
virtual bool specialCommand(const QString &command)
Definition: MenuNode.cpp:421
const QString & name() const
Definition: MenuNode.h:74
const QString & command() const
Definition: MenuNode.h:77
Kwave::MenuNode * findChild(const QString &name)
Definition: MenuNode.cpp:211
const QString & uid() const
Definition: MenuNode.h:85
virtual Kwave::MenuNode * insertLeaf(const QString &name, const QString &command, const QKeySequence &shortcut, const QString &uid)
Definition: MenuNode.cpp:243
virtual Kwave::MenuSub * insertBranch(const QString &name, const QString &command, const QKeySequence &shortcut, const QString &uid)
Definition: MenuNode.cpp:230
virtual void setShortcut(const QKeySequence &shortcut)
Definition: MenuNode.h:100
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:

◆ isBranch()

virtual bool Kwave::MenuNode::isBranch ( ) const
inlinevirtual

Returns true if the node is a branch, false if it is a leaf. (overwritten in MenuSub etc.)

Reimplemented in Kwave::MenuSub, and Kwave::MenuList.

Definition at line 119 of file MenuNode.h.

References actionSelected(), clear(), emitCommand(), findChild(), findUID(), groupList(), insertBranch(), insertChild(), insertLeaf(), insertNode(), isEnabled(), joinGroup(), leafToBranch(), leaveGroup(), parentNode(), removeChild(), rootNode(), setChecked(), setEnabled(), setText(), setVisible(), sigCommand(), and specialCommand().

Referenced by insertNode(), and specialCommand().

119 { return false; }
Here is the call graph for this function:
Here is the caller graph for this function:

◆ isEnabled()

bool Kwave::MenuNode::isEnabled ( )
virtual

Returns true if the node is enabled.

Reimplemented in Kwave::MenuSub, and Kwave::MenuItem.

Definition at line 130 of file MenuNode.cpp.

References DBG, groupList(), Kwave::MenuGroup::isEnabled(), isEnabled(), m_groups, m_parentNode, name(), and rootNode().

Referenced by isBranch(), Kwave::MenuItem::isEnabled(), Kwave::MenuSub::isEnabled(), isEnabled(), and leafToBranch().

131 {
132  // evaluate our own (individual) enable and our parent's enable state
134  return false;
135 
136  // find out if all our groups are enabled
137  QHash<QString, Kwave::MenuGroup *> &groups = groupList();
138  Kwave::MenuNode *root = rootNode();
139  if (root) {
140  foreach (const QString &group_name, m_groups) {
141  if (groups.contains(group_name)) {
142  Kwave::MenuGroup *group = groups[group_name];
143  if (group && !group->isEnabled()) {
144  qDebug("MenuNode(%s).isEnabled(): group %s is disabled",
145  DBG(name()), DBG(group_name));
146  return false;
147  }
148  }
149  }
150  }
151 
152  // if we get here, everything is enabled
153  return true;
154 }
QStringList m_groups
Definition: MenuNode.h:320
virtual QHash< QString, Kwave::MenuGroup * > & groupList()
Definition: MenuNode.cpp:370
Kwave::MenuNode * m_parentNode
Definition: MenuNode.h:337
virtual bool isEnabled() const
Definition: MenuGroup.h:82
const QString & name() const
Definition: MenuNode.h:74
virtual bool isEnabled()
Definition: MenuNode.cpp:130
#define DBG(qs)
Definition: String.h:55
Kwave::MenuNode * rootNode()
Definition: MenuNode.cpp:109
Here is the call graph for this function:
Here is the caller graph for this function:

◆ joinGroup()

void Kwave::MenuNode::joinGroup ( const QString &  group,
Kwave::MenuGroup::Mode  mode 
)

Adds the node to a group. If it is already a member of the group this function will do nothing.

Parameters
groupname of the group
modethe mode of the group (normal or exclusive)

Definition at line 378 of file MenuNode.cpp.

References groupList(), Kwave::MenuGroup::join(), m_groups, and rootNode().

Referenced by isBranch(), leafToBranch(), Kwave::MenuItem::specialCommand(), and specialCommand().

380 {
381  if (m_groups.contains(group))
382  return; // already joined
383 
384  QHash<QString, Kwave::MenuGroup *> &group_list = groupList();
385  Kwave::MenuGroup *grp = Q_NULLPTR;
386  if (group_list.contains(group)) {
387  grp = group_list[group];
388  } else {
389  // group does not already exist, create a new one
390  grp = new(std::nothrow) Kwave::MenuGroup(rootNode(), group, mode);
391  if (grp) group_list.insert(group, grp);
392  }
393 
394  // remember that we now belong to the given group
395  m_groups.append(group);
396 
397  // register this node as a child of the group
398  if (grp) grp->join(this);
399 }
QStringList m_groups
Definition: MenuNode.h:320
virtual void join(Kwave::MenuNode *node)
Definition: MenuGroup.cpp:62
virtual QHash< QString, Kwave::MenuGroup * > & groupList()
Definition: MenuNode.cpp:370
Kwave::MenuNode * rootNode()
Definition: MenuNode.cpp:109
Here is the call graph for this function:
Here is the caller graph for this function:

◆ leafToBranch()

Kwave::MenuNode * Kwave::MenuNode::leafToBranch ( Kwave::MenuNode node)
virtual

Converts a child node from leaf to branch type by removing the leaf and inserting a branch with the same properties instead.

Parameters
nodethe child node to be converted
Returns
pointer to the new branch node

Definition at line 328 of file MenuNode.cpp.

References command(), Kwave::MenuRoot::deleteLater(), icon(), insertBranch(), isEnabled(), joinGroup(), m_groups, name(), Kwave::MenuGroup::NORMAL, removeChild(), Kwave::MenuSub::setEnabled(), Kwave::MenuSub::setIcon(), shortcut(), and uid().

Referenced by insertNode(), isBranch(), and specialCommand().

329 {
330  Q_ASSERT(node);
331  Q_ASSERT(node != this);
332 
333  if (!node || (node == this)) return Q_NULLPTR;
334 
335  // get the old properties
336  bool old_enable = node->isEnabled();
337  QKeySequence old_shortcut = node->shortcut();
338  QString old_uid = node->uid();
339  QIcon old_icon = node->icon();
340  QString name = node->name();
341  QString command = node->command();
342  QStringList old_groups = node->m_groups;
343 
344  // remove the old child node
345  removeChild(node);
346 
347  // insert the new branch
348  Kwave::MenuSub *sub = insertBranch(name, command, old_shortcut, old_uid);
349  if (sub) {
350  // join it to the same groups
351  foreach (const QString &group, old_groups)
352  sub->joinGroup(group, Kwave::MenuGroup::NORMAL);
353 
354  // set the old icon
355  if (!old_icon.isNull()) sub->setIcon(old_icon);
356 
357  // set the "enable"
358  sub->setEnabled(old_enable);
359  }
360 
361  // free the old node later.
362  // IMPORTANT: we must not call "delete node" now, because we get called
363  // through leafToBranch(this) !
365 
366  return sub;
367 }
QStringList m_groups
Definition: MenuNode.h:320
void joinGroup(const QString &group, Kwave::MenuGroup::Mode mode)
Definition: MenuNode.cpp:378
const QKeySequence & shortcut() const
Definition: MenuNode.h:95
virtual const QIcon icon()
Definition: MenuNode.cpp:115
virtual void setIcon(const QIcon &icon) Q_DECL_OVERRIDE
Definition: MenuSub.cpp:92
virtual void removeChild(Kwave::MenuNode *child)
Definition: MenuNode.cpp:223
const QString & name() const
Definition: MenuNode.h:74
const QString & command() const
Definition: MenuNode.h:77
virtual bool isEnabled()
Definition: MenuNode.cpp:130
static void deleteLater(Kwave::MenuNode *node)
Definition: MenuRoot.cpp:177
const QString & uid() const
Definition: MenuNode.h:85
virtual Kwave::MenuSub * insertBranch(const QString &name, const QString &command, const QKeySequence &shortcut, const QString &uid)
Definition: MenuNode.cpp:230
virtual void setEnabled(bool enable) Q_DECL_OVERRIDE
Definition: MenuSub.cpp:80
Here is the call graph for this function:
Here is the caller graph for this function:

◆ leaveGroup()

void Kwave::MenuNode::leaveGroup ( const QString &  group)

Removes the node from a group (opposite of joinGroup).

Parameters
groupname of the group

Definition at line 402 of file MenuNode.cpp.

References groupList(), Kwave::MenuGroup::isEmpty(), Kwave::MenuGroup::leave(), and m_groups.

Referenced by isBranch(), and ~MenuNode().

403 {
404  QHash<QString, Kwave::MenuGroup *> &group_list = groupList();
405  Kwave::MenuGroup *grp = (group_list.contains(group)) ?
406  group_list.value(group) : Q_NULLPTR;
407 
408  // remove the group from our list
409  m_groups.removeAll(group);
410 
411  // remove ourself from the group
412  if (grp) {
413  grp->leave(this);
414 
415  // clean up the group if nobody uses it any more
416  if (grp->isEmpty()) delete grp;
417  }
418 }
QStringList m_groups
Definition: MenuNode.h:320
virtual QHash< QString, Kwave::MenuGroup * > & groupList()
Definition: MenuNode.cpp:370
virtual bool isEmpty() const
Definition: MenuGroup.h:87
virtual void leave(Kwave::MenuNode *node)
Definition: MenuGroup.cpp:72
Here is the call graph for this function:
Here is the caller graph for this function:

◆ name()

const QString& Kwave::MenuNode::name ( ) const
inline

◆ parentNode()

Kwave::MenuNode * Kwave::MenuNode::parentNode ( ) const
virtual

returns a pointer to the menu's parent node

Definition at line 103 of file MenuNode.cpp.

References m_parentNode.

Referenced by Kwave::MenuManager::addNumberedMenuEntry(), Kwave::MenuList::clear(), emitCommand(), Kwave::MenuList::insertLeaf(), isBranch(), Kwave::MenuSub::setVisible(), and specialCommand().

104 {
105  return m_parentNode;
106 }
Kwave::MenuNode * m_parentNode
Definition: MenuNode.h:337
Here is the caller graph for this function:

◆ path()

const QString Kwave::MenuNode::path ( ) const

Returns the path of this menu entry

Definition at line 63 of file MenuNode.cpp.

References _, m_name, m_parentNode, and path().

Referenced by Kwave::MenuItem::MenuItem(), Kwave::MenuSub::MenuSub(), and path().

64 {
65  return (m_parentNode) ?
66  (m_parentNode->path() + _("/") + m_name) : QString();
67 }
const QString path() const
Definition: MenuNode.cpp:63
QString m_name
Definition: MenuNode.h:331
Kwave::MenuNode * m_parentNode
Definition: MenuNode.h:337
#define _(m)
Definition: memcpy.c:66
Here is the call graph for this function:
Here is the caller graph for this function:

◆ removeChild()

void Kwave::MenuNode::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 in Kwave::MenuRoot, and Kwave::MenuSub.

Definition at line 223 of file MenuNode.cpp.

References m_children.

Referenced by Kwave::MenuList::clear(), isBranch(), leafToBranch(), Kwave::MenuSub::removeChild(), Kwave::MenuRoot::removeChild(), and ~MenuNode().

224 {
225  if (child && !m_children.isEmpty())
226  m_children.removeAll(child);
227 }
QList< Kwave::MenuNode * > m_children
Definition: MenuNode.h:317
Here is the caller graph for this function:

◆ rootNode()

Kwave::MenuNode * Kwave::MenuNode::rootNode ( )
protected

Returns the address of the root node of the menu structure.

Definition at line 109 of file MenuNode.cpp.

References m_parentNode, and rootNode().

Referenced by emitCommand(), isBranch(), isEnabled(), joinGroup(), rootNode(), and Kwave::MenuSub::setVisible().

110 {
111  return (m_parentNode) ? m_parentNode->rootNode() : this;
112 }
Kwave::MenuNode * m_parentNode
Definition: MenuNode.h:337
Kwave::MenuNode * rootNode()
Definition: MenuNode.cpp:109
Here is the call graph for this function:
Here is the caller graph for this function:

◆ setChecked()

void Kwave::MenuNode::setChecked ( bool  check)
virtual

Sets/removes the checkmark from the current menu node.

Parameters
checktrue to set the mark, false to remove

Reimplemented in Kwave::MenuItem.

Definition at line 169 of file MenuNode.cpp.

Referenced by isBranch(), Kwave::MenuGroup::selectItem(), and Kwave::MenuManager::setItemChecked().

170 {
171  Q_UNUSED(check);
172 }
Here is the caller graph for this function:

◆ setEnabled()

void Kwave::MenuNode::setEnabled ( bool  enable)
virtual

Enables/disables the current menu node.

Parameters
enabletrue to enable the item, false to disable

Reimplemented in Kwave::MenuSub, and Kwave::MenuItem.

Definition at line 163 of file MenuNode.cpp.

Referenced by isBranch(), Kwave::MenuGroup::setEnabled(), Kwave::MenuManager::setItemEnabled(), and specialCommand().

164 {
165  Q_UNUSED(enable);
166 }
Here is the caller graph for this function:

◆ setIcon()

void Kwave::MenuNode::setIcon ( const QIcon &  icon)
virtual

Sets a new icon of a menu node.

Parameters
iconQIcon with the icon

Reimplemented in Kwave::MenuSub, and Kwave::MenuItem.

Definition at line 123 of file MenuNode.cpp.

References DBG, and name().

Referenced by setShortcut(), and specialCommand().

124 {
125  qWarning("MenuNode(%s)::setIcon(%p)",
126  DBG(name()), reinterpret_cast<const void *>(&icon));
127 }
virtual const QIcon icon()
Definition: MenuNode.cpp:115
const QString & name() const
Definition: MenuNode.h:74
#define DBG(qs)
Definition: String.h:55
Here is the call graph for this function:
Here is the caller graph for this function:

◆ setShortcut()

virtual void Kwave::MenuNode::setShortcut ( const QKeySequence &  shortcut)
inlinevirtual

Sets the bitmask of the keyboard shortcut.

Definition at line 100 of file MenuNode.h.

References icon(), m_shortcut, setIcon(), and shortcut().

Referenced by insertNode().

100  {
102  }
const QKeySequence & shortcut() const
Definition: MenuNode.h:95
QKeySequence m_shortcut
Definition: MenuNode.h:328
Here is the call graph for this function:
Here is the caller graph for this function:

◆ setText()

void Kwave::MenuNode::setText ( const QString &  text)
virtual

Sets the visible text of an item to a new value. (Only useful for a MenuItem)

Parameters
textthe new text

Reimplemented in Kwave::MenuItem.

Definition at line 175 of file MenuNode.cpp.

Referenced by isBranch(), and Kwave::MenuManager::setItemText().

176 {
177  Q_UNUSED(text);
178 }
Here is the caller graph for this function:

◆ setUID()

void Kwave::MenuNode::setUID ( const QString &  uid)

Sets the unique id string of the node

Definition at line 192 of file MenuNode.cpp.

References m_uid, and uid().

Referenced by insertNode(), and uid().

193 {
194  m_uid = uid;
195 }
QString m_uid
Definition: MenuNode.h:325
const QString & uid() const
Definition: MenuNode.h:85
Here is the call graph for this function:
Here is the caller graph for this function:

◆ setVisible()

void Kwave::MenuNode::setVisible ( bool  visible)
virtual

Shows/hides the current menu node.

Parameters
visibletrue to show the item, false to hide

Reimplemented in Kwave::MenuSub, and Kwave::MenuItem.

Definition at line 157 of file MenuNode.cpp.

Referenced by isBranch(), and Kwave::MenuManager::setItemVisible().

158 {
159  Q_UNUSED(visible);
160 }
Here is the caller graph for this function:

◆ shortcut()

const QKeySequence& Kwave::MenuNode::shortcut ( ) const
inline

Returns the bitmask of the keyboard shortcut.

Definition at line 95 of file MenuNode.h.

References m_shortcut.

Referenced by Kwave::MenuList::isBranch(), leafToBranch(), and setShortcut().

95 { return m_shortcut; }
QKeySequence m_shortcut
Definition: MenuNode.h:328
Here is the caller graph for this function:

◆ sigCommand

void Kwave::MenuNode::sigCommand ( const QString &  command)
signal

Will be emitted if the command of the menu node should be executed. It will only be emitted by the root node, client nodes call the root node's emitCommand() function.

See also
emitCommand()
rootNode()

Referenced by emitCommand(), and isBranch().

Here is the caller graph for this function:

◆ specialCommand()

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

Handles/interpretes special menu commands.

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

Reimplemented in Kwave::MenuRoot, Kwave::MenuSub, and Kwave::MenuItem.

Definition at line 421 of file MenuNode.cpp.

References _, Kwave::Parser::command(), DBG, findUID(), Kwave::Parser::firstParam(), icon(), insertChild(), isBranch(), joinGroup(), leafToBranch(), name(), Kwave::Parser::nextParam(), Kwave::MenuGroup::NORMAL, parentNode(), setEnabled(), setIcon(), and uid().

Referenced by insertNode(), isBranch(), Kwave::MenuItem::specialCommand(), Kwave::MenuSub::specialCommand(), and Kwave::MenuRoot::specialCommand().

422 {
423  Kwave::Parser parser(command);
424 
425  if (parser.command() == _("#icon")) {
426  // --- give the item an icon ---
427  const QString &icon_name = parser.firstParam();
428  if ( icon_name.length()) {
429  // try to load from standard dirs
430  QIcon icon = QIcon::fromTheme( icon_name );
431  if (!icon.isNull()) {
432  setIcon(icon);
433  } else {
434  qWarning("MenuNode '%s': icon '%s' not found !",
435  DBG(name()), DBG( icon_name ));
436  }
437  }
438  return true;
439  }
440 
441  if (parser.command() == _("#listmenu")) {
442  // make sure that the current node is a sub menu
443  Kwave::MenuNode *parent = parentNode();
444  Kwave::MenuNode *sub = (parent && !isBranch()) ?
445  parent->leafToBranch(this) : this;
446  if (!sub) return false;
447 
448  // append a placeholder for inserting the list
449  // (if it does not already exist)
450  const QString uid = parser.firstParam();
451  const QString cmd = parser.nextParam();
452  if (!sub->findUID(uid)) {
453  Kwave::MenuList *placeholder =
454  new(std::nothrow) Kwave::MenuList(sub, cmd, uid);
455  Q_ASSERT(placeholder);
456  if (!placeholder) return false;
457 
458  sub->insertChild(placeholder, Q_NULLPTR);
459  }
460  return true;
461  }
462 
463  if (parser.command() == _("#group")) {
464  QString group = parser.firstParam();
465  while (group.length()) {
467  group = parser.nextParam();
468  }
469  return true;
470  }
471 
472  if (command == _("#disabled")) {
473  // disable the node
474  setEnabled(false);
475  return true;
476  }
477 
478  if (command == _("#enabled")) {
479  // enable the node
480  setEnabled(true);
481  return true;
482  }
483 
484  return false;
485 }
virtual Kwave::MenuNode * parentNode() const
Definition: MenuNode.cpp:103
void joinGroup(const QString &group, Kwave::MenuGroup::Mode mode)
Definition: MenuNode.cpp:378
virtual bool isBranch() const
Definition: MenuNode.h:119
virtual Kwave::MenuNode * leafToBranch(Kwave::MenuNode *node)
Definition: MenuNode.cpp:328
virtual void setIcon(const QIcon &icon)
Definition: MenuNode.cpp:123
Kwave::MenuNode * findUID(const QString &uid)
Definition: MenuNode.cpp:198
virtual const QIcon icon()
Definition: MenuNode.cpp:115
virtual void insertChild(Kwave::MenuNode *node, Kwave::MenuNode *before)
Definition: MenuNode.cpp:181
virtual void setEnabled(bool enable)
Definition: MenuNode.cpp:163
const QString & name() const
Definition: MenuNode.h:74
const QString & command() const
Definition: MenuNode.h:77
#define _(m)
Definition: memcpy.c:66
const QString & uid() const
Definition: MenuNode.h:85
#define DBG(qs)
Definition: String.h:55
Here is the call graph for this function:
Here is the caller graph for this function:

◆ uid()

const QString& Kwave::MenuNode::uid ( ) const
inline

Returns the unique id string of the node.

Definition at line 85 of file MenuNode.h.

References m_uid, and setUID().

Referenced by Kwave::MenuSub::insertLeaf(), leafToBranch(), Kwave::MenuGroup::selectItem(), setUID(), and specialCommand().

85 { return m_uid; }
QString m_uid
Definition: MenuNode.h:325
Here is the call graph for this function:
Here is the caller graph for this function:

Member Data Documentation

◆ m_children

QList<Kwave::MenuNode *> Kwave::MenuNode::m_children
protected

◆ m_command

QString Kwave::MenuNode::m_command
private

command to be sent when the node is activated (optional)

Definition at line 334 of file MenuNode.h.

Referenced by actionSelected(), and command().

◆ m_groups

QStringList Kwave::MenuNode::m_groups
protected

list of group names the item belongs to

Definition at line 320 of file MenuNode.h.

Referenced by isEnabled(), joinGroup(), leafToBranch(), leaveGroup(), and ~MenuNode().

◆ m_name

QString Kwave::MenuNode::m_name
private

name of the node (non-localized)

Definition at line 331 of file MenuNode.h.

Referenced by name(), and path().

◆ m_parentNode

Kwave::MenuNode* Kwave::MenuNode::m_parentNode
private

parent of this entry

Definition at line 337 of file MenuNode.h.

Referenced by groupList(), isEnabled(), parentNode(), path(), rootNode(), and ~MenuNode().

◆ m_shortcut

QKeySequence Kwave::MenuNode::m_shortcut
private

bitmask of the keyboard shortcut

Definition at line 328 of file MenuNode.h.

Referenced by setShortcut(), and shortcut().

◆ m_uid

QString Kwave::MenuNode::m_uid
private

unique id string

Definition at line 325 of file MenuNode.h.

Referenced by findUID(), setUID(), and uid().


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