• Skip to content
  • Skip to link menu
  • KDE API Reference
  • kdelibs-4.8.5 API Reference
  • KDE Home
  • Contact Us
 

KDEUI

  • kdeui
  • actions
kactioncollection.cpp
Go to the documentation of this file.
1 /* This file is part of the KDE libraries
2  Copyright (C) 1999 Reginald Stadlbauer <reggie@kde.org>
3  (C) 1999 Simon Hausmann <hausmann@kde.org>
4  (C) 2000 Nicolas Hadacek <haadcek@kde.org>
5  (C) 2000 Kurt Granroth <granroth@kde.org>
6  (C) 2000 Michael Koch <koch@kde.org>
7  (C) 2001 Holger Freyther <freyther@kde.org>
8  (C) 2002 Ellis Whitehead <ellis@kde.org>
9  (C) 2002 Joseph Wenninger <jowenn@kde.org>
10  (C) 2005-2007 Hamish Rodda <rodda@kde.org>
11 
12  This library is free software; you can redistribute it and/or
13  modify it under the terms of the GNU Library General Public
14  License version 2 as published by the Free Software Foundation.
15 
16  This library is distributed in the hope that it will be useful,
17  but WITHOUT ANY WARRANTY; without even the implied warranty of
18  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
19  Library General Public License for more details.
20 
21  You should have received a copy of the GNU Library General Public License
22  along with this library; see the file COPYING.LIB. If not, write to
23  the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
24  Boston, MA 02110-1301, USA.
25 */
26 
27 #include "kactioncollection.h"
28 #include "kactioncategory.h"
29 #include <kauthorized.h>
30 #include "kxmlguiclient.h"
31 #include "kxmlguifactory.h"
32 
33 #include "kdebug.h"
34 #include "kglobal.h"
35 #include "kaction.h"
36 #include "kaction_p.h"
37 
38 #include <QtXml/QDomDocument>
39 #include <QtCore/QSet>
40 #include <QtCore/QMap>
41 #include <QtCore/QList>
42 #include <QtGui/QAction>
43 
44 #include <stdio.h>
45 #include "kcomponentdata.h"
46 #include "kconfiggroup.h"
47 
48 class KActionCollectionPrivate
49 {
50 public:
51  KActionCollectionPrivate()
52  {
53  q = 0;
54  m_parentGUIClient = 0L;
55 
56  configIsGlobal = false;
57 
58  connectHovered = connectTriggered = false;
59 
60  configGroup = "Shortcuts";
61  }
62 
63  void setComponentForAction(KAction *kaction)
64  { kaction->d->maybeSetComponentData(m_componentData); }
65 
66  static QList<KActionCollection*> s_allCollections;
67 
68  void _k_associatedWidgetDestroyed(QObject *obj);
69  void _k_actionDestroyed(QObject *obj);
70 
71  bool writeKXMLGUIConfigFile();
72 
73  KComponentData m_componentData;
74 
77  QAction *unlistAction(QAction*);
78 
79  QMap<QString, QAction*> actionByName;
80  QList<QAction*> actions;
81 
82  const KXMLGUIClient *m_parentGUIClient;
83 
84  QString configGroup;
85  bool configIsGlobal : 1;
86 
87  bool connectTriggered : 1;
88  bool connectHovered : 1;
89 
90  KActionCollection *q;
91 
92  QList<QWidget*> associatedWidgets;
93 };
94 
95 QList<KActionCollection*> KActionCollectionPrivate::s_allCollections;
96 
97 KActionCollection::KActionCollection(QObject *parent, const KComponentData &cData)
98  : QObject( parent )
99  , d(new KActionCollectionPrivate)
100 {
101  d->q = this;
102  KActionCollectionPrivate::s_allCollections.append(this);
103 
104  setComponentData(cData);
105 }
106 
107 KActionCollection::KActionCollection( const KXMLGUIClient *parent )
108  : QObject( 0 )
109  , d(new KActionCollectionPrivate)
110 {
111  d->q = this;
112  KActionCollectionPrivate::s_allCollections.append(this);
113 
114  d->m_parentGUIClient=parent;
115  d->m_componentData = parent->componentData();
116 }
117 
118 KActionCollection::~KActionCollection()
119 {
120  KActionCollectionPrivate::s_allCollections.removeAll(this);
121 
122  delete d;
123 }
124 
125 void KActionCollection::clear()
126 {
127  d->actionByName.clear();
128  qDeleteAll(d->actions);
129  d->actions.clear();
130 }
131 
132 QAction* KActionCollection::action( const QString& name ) const
133 {
134  QAction* action = 0L;
135 
136  if ( !name.isEmpty() )
137  action = d->actionByName.value (name);
138 
139  return action;
140 }
141 
142 QAction* KActionCollection::action( int index ) const
143 {
144  // ### investigate if any apps use this at all
145  return actions().value(index);
146 }
147 
148 int KActionCollection::count() const
149 {
150  return d->actions.count();
151 }
152 
153 bool KActionCollection::isEmpty() const
154 {
155  return count() == 0;
156 }
157 
158 void KActionCollection::setComponentData(const KComponentData &cData)
159 {
160  if (count() > 0) {
161  // Its component name is part of an action's signature in the context of
162  // global shortcuts and the semantics of changing an existing action's
163  // signature are, as it seems, impossible to get right.
164  // As of now this only matters for global shortcuts. We could
165  // thus relax the requirement and only refuse to change the component data
166  // if we have actions with global shortcuts in this collection.
167  kWarning(129) << "this does not work on a KActionCollection containing actions!";
168  }
169 
170  if (cData.isValid()) {
171  d->m_componentData = cData;
172  } else {
173  d->m_componentData = KGlobal::mainComponent();
174  }
175 }
176 
177 KComponentData KActionCollection::componentData() const
178 {
179  return d->m_componentData;
180 }
181 
182 const KXMLGUIClient *KActionCollection::parentGUIClient() const
183 {
184  return d->m_parentGUIClient;
185 }
186 
187 QList<QAction*> KActionCollection::actions() const
188 {
189  return d->actions;
190 }
191 
192 const QList< QAction* > KActionCollection::actionsWithoutGroup( ) const
193 {
194  QList<QAction*> ret;
195  foreach (QAction* action, d->actions)
196  if (!action->actionGroup())
197  ret.append(action);
198  return ret;
199 }
200 
201 const QList< QActionGroup * > KActionCollection::actionGroups( ) const
202 {
203  QSet<QActionGroup*> set;
204  foreach (QAction* action, d->actions)
205  if (action->actionGroup())
206  set.insert(action->actionGroup());
207  return set.toList();
208 }
209 
210 KAction *KActionCollection::addAction(const QString &name, KAction *action)
211 {
212  QAction* ret = addAction(name, static_cast<QAction*>(action));
213  Q_ASSERT(ret == action);
214  Q_UNUSED(ret); // fix compiler warning in release mode
215  return action;
216 }
217 
218 QAction *KActionCollection::addAction(const QString &name, QAction *action)
219 {
220  if (!action)
221  return action;
222 
223  const QString objectName = action->objectName();
224  QString indexName = name;
225 
226  if (indexName.isEmpty()) {
227  // No name provided. Use the objectName.
228  indexName = objectName;
229 
230  } else {
231 
232  // A name was provided. Check against objectName.
233  if ((!objectName.isEmpty()) && (objectName != indexName)) {
234  // The user specified a new name and the action already has a
235  // different one. The objectName is used for saving shortcut
236  // settings to disk. Both for local and global shortcuts.
237  KAction *kaction = qobject_cast<KAction*>(action);
238  kDebug(125) << "Registering action " << objectName << " under new name " << indexName;
239  // If there is a global shortcuts it's a very bad idea.
240  if (kaction && kaction->isGlobalShortcutEnabled()) {
241  // In debug mode assert
242  Q_ASSERT(!kaction->isGlobalShortcutEnabled());
243  // In release mode keep the old name
244  kError() << "Changing action name from " << objectName << " to " << indexName << "\nignored because of active global shortcut.";
245  indexName = objectName;
246  }
247  }
248 
249  // Set the new name
250  action->setObjectName(indexName);
251  }
252 
253  // No name provided and the action had no name. Make one up. This will not
254  // work when trying to save shortcuts. Both local and global shortcuts.
255  if( indexName.isEmpty() ) {
256  indexName = indexName.sprintf("unnamed-%p", (void*)action);
257  action->setObjectName(indexName);
258  }
259 
260  // From now on the objectName has to have a value. Else we cannot safely
261  // remove actions.
262  Q_ASSERT(!action->objectName().isEmpty());
263 
264  // look if we already have THIS action under THIS name ;)
265  if (d->actionByName.value(indexName, 0) == action ) {
266  // This is not a multi map!
267  Q_ASSERT( d->actionByName.count(indexName)==1);
268  return action;
269  }
270 
271  if (!KAuthorized::authorizeKAction(indexName)) {
272  // Disable this action
273  action->setEnabled(false);
274  action->setVisible(false);
275  action->blockSignals(true);
276  }
277 
278  // Check if we have another action under this name
279  if (QAction *oldAction = d->actionByName.value(indexName)) {
280  takeAction(oldAction);
281  }
282 
283  // Check if we have this action under a different name.
284  // Not using takeAction because we don't want to remove it from categories,
285  // and because it has the new name already.
286  const int oldIndex = d->actions.indexOf(action);
287  if (oldIndex != -1) {
288  d->actionByName.remove(d->actionByName.key(action));
289  d->actions.removeAt(oldIndex);
290  }
291 
292  // Add action to our lists.
293  d->actionByName.insert(indexName, action);
294  d->actions.append(action);
295 
296  foreach (QWidget* widget, d->associatedWidgets) {
297  widget->addAction(action);
298  }
299 
300  connect(action, SIGNAL(destroyed(QObject*)), SLOT(_k_actionDestroyed(QObject*)));
301 
302  // only our private class is a friend of KAction
303  if (KAction *kaction = dynamic_cast<KAction *>(action)) {
304  d->setComponentForAction(kaction);
305  }
306 
307  if (d->connectHovered)
308  connect(action, SIGNAL(hovered()), SLOT(slotActionHovered()));
309 
310  if (d->connectTriggered)
311  connect(action, SIGNAL(triggered(bool)), SLOT(slotActionTriggered()));
312 
313  emit inserted( action );
314  return action;
315 }
316 
317 void KActionCollection::removeAction( QAction* action )
318 {
319  delete takeAction( action );
320 }
321 
322 QAction* KActionCollection::takeAction(QAction *action)
323 {
324  if (!d->unlistAction(action))
325  return NULL;
326 
327  // Remove the action from all widgets
328  foreach (QWidget* widget, d->associatedWidgets) {
329  widget->removeAction(action);
330  }
331 
332  action->disconnect(this);
333 
334  emit removed( action ); //deprecated
335  return action;
336 }
337 
338 KAction *KActionCollection::addAction(KStandardAction::StandardAction actionType, const QObject *receiver, const char *member)
339 {
340  KAction *action = KStandardAction::create(actionType, receiver, member, this);
341  return action;
342 }
343 
344 KAction *KActionCollection::addAction(KStandardAction::StandardAction actionType, const QString &name,
345  const QObject *receiver, const char *member)
346 {
347  // pass 0 as parent, because if the parent is a KActionCollection KStandardAction::create automatically
348  // adds the action to it under the default name. We would trigger the
349  // warning about renaming the action then.
350  KAction *action = KStandardAction::create(actionType, receiver, member, 0);
351  // Give it a parent for gc.
352  action->setParent(this);
353  // Remove the name to get rid of the "rename action" warning above
354  action->setObjectName(name);
355  // And now add it with the desired name.
356  return addAction(name, action);
357 }
358 
359 KAction *KActionCollection::addAction(const QString &name, const QObject *receiver, const char *member)
360 {
361  KAction *a = new KAction(this);
362  if (receiver && member)
363  connect(a, SIGNAL(triggered(bool)), receiver, member);
364  return addAction(name, a);
365 }
366 
367 QString KActionCollection::configGroup( ) const
368 {
369  return d->configGroup;
370 }
371 
372 void KActionCollection::setConfigGroup( const QString & group )
373 {
374  d->configGroup = group;
375 }
376 
377 bool KActionCollection::configIsGlobal() const
378 {
379  return d->configIsGlobal;
380 }
381 
382 void KActionCollection::setConfigGlobal( bool global )
383 {
384  d->configIsGlobal = global;
385 }
386 
387 void KActionCollection::importGlobalShortcuts( KConfigGroup* config )
388 {
389  Q_ASSERT(config);
390  if( !config || !config->exists()) {
391  return;
392  }
393 
394  for (QMap<QString, QAction *>::ConstIterator it = d->actionByName.constBegin();
395  it != d->actionByName.constEnd(); ++it) {
396  KAction *kaction = qobject_cast<KAction*>(it.value());
397  if (!kaction)
398  continue;
399 
400  QString actionName = it.key();
401 
402  if( kaction->isShortcutConfigurable() ) {
403  QString entry = config->readEntry(actionName, QString());
404  if( !entry.isEmpty() ) {
405  kaction->setGlobalShortcut( KShortcut(entry), KAction::ActiveShortcut, KAction::NoAutoloading );
406  } else {
407  kaction->setGlobalShortcut( kaction->shortcut(KAction::DefaultShortcut), KAction::ActiveShortcut, KAction::NoAutoloading );
408  }
409  }
410  }
411 }
412 
413 
414 void KActionCollection::readSettings( KConfigGroup* config )
415 {
416  KConfigGroup cg( KGlobal::config(), configGroup() );
417  if( !config )
418  config = &cg;
419 
420  if( !config->exists()) {
421  return;
422  }
423 
424  for (QMap<QString, QAction *>::ConstIterator it = d->actionByName.constBegin();
425  it != d->actionByName.constEnd(); ++it) {
426  KAction *kaction = qobject_cast<KAction*>(it.value());
427  if (!kaction)
428  continue;
429 
430 
431  if( kaction->isShortcutConfigurable() ) {
432  QString actionName = it.key();
433  QString entry = config->readEntry(actionName, QString());
434  if( !entry.isEmpty() ) {
435  kaction->setShortcut( KShortcut(entry), KAction::ActiveShortcut );
436  } else {
437  kaction->setShortcut( kaction->shortcut(KAction::DefaultShortcut) );
438  }
439  }
440  }
441 
442  //kDebug(125) << " done";
443 }
444 
445 void KActionCollection::exportGlobalShortcuts( KConfigGroup* config, bool writeAll ) const
446 {
447  Q_ASSERT(config);
448  if (!config) {
449  return;
450  }
451 
452  QList<QAction*> writeActions = actions();
453 
454  for (QMap<QString, QAction *>::ConstIterator it = d->actionByName.constBegin();
455  it != d->actionByName.constEnd(); ++it) {
456 
457  KAction *kaction = qobject_cast<KAction*>(it.value());
458  if (!kaction)
459  continue;
460  QString actionName = it.key();
461 
462  // If the action name starts with unnamed- spit out a warning. That name
463  // will change at will and will break loading writing
464  if (actionName.startsWith(QLatin1String("unnamed-"))) {
465  kError() << "Skipped exporting Shortcut for action without name " << kaction->text() << "!";
466  continue;
467  }
468 
469  if( kaction->isShortcutConfigurable() && kaction->isGlobalShortcutEnabled() ) {
470  bool bConfigHasAction = !config->readEntry( actionName, QString() ).isEmpty();
471  bool bSameAsDefault = (kaction->globalShortcut() == kaction->globalShortcut(KAction::DefaultShortcut));
472  // If we're using a global config or this setting
473  // differs from the default, then we want to write.
474  KConfigGroup::WriteConfigFlags flags = KConfigGroup::Persistent;
475  if (configIsGlobal())
476  flags |= KConfigGroup::Global;
477  if( writeAll || !bSameAsDefault ) {
478  QString s = kaction->globalShortcut().toString();
479  if( s.isEmpty() )
480  s = "none";
481  kDebug(125) << "\twriting " << actionName << " = " << s;
482  config->writeEntry( actionName, s, flags );
483  }
484  // Otherwise, this key is the same as default
485  // but exists in config file. Remove it.
486  else if( bConfigHasAction ) {
487  kDebug(125) << "\tremoving " << actionName << " because == default";
488  config->deleteEntry( actionName, flags );
489  }
490  }
491  }
492 
493  config->sync();
494 }
495 
496 
497 bool KActionCollectionPrivate::writeKXMLGUIConfigFile()
498 {
499  const KXMLGUIClient *kxmlguiClient = q->parentGUIClient();
500  // return false if there is no KXMLGUIClient
501  if (!kxmlguiClient || kxmlguiClient->xmlFile().isEmpty()) {
502  return false;
503  }
504 
505  kDebug(129) << "xmlFile=" << kxmlguiClient->xmlFile();
506 
507  QString attrShortcut = QLatin1String("shortcut");
508 
509  // Read XML file
510  QString sXml(KXMLGUIFactory::readConfigFile(kxmlguiClient->xmlFile(), q->componentData()));
511  QDomDocument doc;
512  doc.setContent( sXml );
513 
514  // Process XML data
515 
516  // Get hold of ActionProperties tag
517  QDomElement elem = KXMLGUIFactory::actionPropertiesElement( doc );
518 
519  // now, iterate through our actions
520  for (QMap<QString, QAction *>::ConstIterator it = actionByName.constBegin();
521  it != actionByName.constEnd(); ++it) {
522  KAction *kaction = qobject_cast<KAction*>(it.value());
523  if (!kaction) {
524  continue;
525  }
526 
527  QString actionName = it.key();
528 
529  // If the action name starts with unnamed- spit out a warning and ignore
530  // it. That name will change at will and will break loading writing
531  if (actionName.startsWith(QLatin1String("unnamed-"))) {
532  kError() << "Skipped writing shortcut for action " << actionName << "(" << kaction->text() << ")!";
533  continue;
534  }
535 
536  bool bSameAsDefault = (kaction->shortcut() == kaction->shortcut(KAction::DefaultShortcut));
537  kDebug(129) << "name = " << actionName
538  << " shortcut = " << kaction->shortcut(KAction::ActiveShortcut).toString()
539  << " globalshortcut = " << kaction->globalShortcut(KAction::ActiveShortcut).toString()
540  << " def = " << kaction->shortcut(KAction::DefaultShortcut).toString();
541 
542  // now see if this element already exists
543  // and create it if necessary (unless bSameAsDefault)
544  QDomElement act_elem = KXMLGUIFactory::findActionByName( elem, actionName, !bSameAsDefault );
545  if ( act_elem.isNull() )
546  continue;
547 
548  if( bSameAsDefault ) {
549  act_elem.removeAttribute( attrShortcut );
550  //kDebug(129) << "act_elem.attributes().count() = " << act_elem.attributes().count();
551  if( act_elem.attributes().count() == 1 )
552  elem.removeChild( act_elem );
553  } else {
554  act_elem.setAttribute( attrShortcut, kaction->shortcut().toString() );
555  }
556  }
557 
558  // Write back to XML file
559  KXMLGUIFactory::saveConfigFile(doc, kxmlguiClient->localXMLFile(), q->componentData());
560  return true;
561 }
562 
563 
564 void KActionCollection::writeSettings( KConfigGroup* config, bool writeAll, QAction* oneAction ) const
565 {
566  // If the caller didn't provide a config group we try to save the KXMLGUI
567  // Configuration file. If that succeeds we are finished.
568  if (config==0 && d->writeKXMLGUIConfigFile() ) {
569  return;
570  }
571 
572  KConfigGroup cg(KGlobal::config() , configGroup() );
573  if (!config) {
574  config = &cg;
575  }
576 
577  QList<QAction*> writeActions;
578  if (oneAction) {
579  writeActions.append(oneAction);
580  } else {
581  writeActions = actions();
582  }
583 
584 
585  for (QMap<QString, QAction *>::ConstIterator it = d->actionByName.constBegin();
586  it != d->actionByName.constEnd(); ++it) {
587 
588  // Get the action. We only handle KActions so skip QActions
589  KAction *kaction = qobject_cast<KAction*>(it.value());
590  if (!kaction) {
591  continue;
592  }
593 
594  QString actionName = it.key();
595 
596  // If the action name starts with unnamed- spit out a warning and ignore
597  // it. That name will change at will and will break loading writing
598  if (actionName.startsWith(QLatin1String("unnamed-"))) {
599  kError() << "Skipped saving Shortcut for action without name " << kaction->text() << "!";
600  continue;
601  }
602 
603  // Write the shortcut
604  if( kaction->isShortcutConfigurable() ) {
605  bool bConfigHasAction = !config->readEntry( actionName, QString() ).isEmpty();
606  bool bSameAsDefault = (kaction->shortcut() == kaction->shortcut(KAction::DefaultShortcut));
607  // If we're using a global config or this setting
608  // differs from the default, then we want to write.
609  KConfigGroup::WriteConfigFlags flags = KConfigGroup::Persistent;
610 
611  // Honor the configIsGlobal() setting
612  if (configIsGlobal()) {
613  flags |= KConfigGroup::Global;
614  }
615 
616  if( writeAll || !bSameAsDefault ) {
617  // We are instructed to write all shortcuts or the shortcut is
618  // not set to its default value. Write it
619  QString s = kaction->shortcut().toString();
620  if( s.isEmpty() )
621  s = "none";
622  kDebug(125) << "\twriting " << actionName << " = " << s;
623  config->writeEntry( actionName, s, flags );
624 
625  } else if( bConfigHasAction ) {
626  // Otherwise, this key is the same as default but exists in
627  // config file. Remove it.
628  kDebug(125) << "\tremoving " << actionName << " because == default";
629  config->deleteEntry( actionName, flags );
630  }
631  }
632  }
633 
634  config->sync();
635 }
636 
637 void KActionCollection::slotActionTriggered( )
638 {
639  QAction* action = qobject_cast<QAction*>(sender());
640  if (action)
641  emit actionTriggered(action);
642 }
643 
644 void KActionCollection::slotActionHighlighted( )
645 {
646  slotActionHovered();
647 }
648 
649 void KActionCollection::slotActionHovered( )
650 {
651  QAction* action = qobject_cast<QAction*>(sender());
652  if (action) {
653  emit actionHighlighted(action);
654  emit actionHovered(action);
655  }
656 }
657 
658 
659 void KActionCollectionPrivate::_k_actionDestroyed( QObject *obj )
660 {
661  // obj isn't really a QAction anymore. So make sure we don't do fancy stuff
662  // with it.
663  QAction *action = static_cast<QAction*>(obj);
664 
665  if (!unlistAction(action))
666  return;
667 
668  //HACK the object we emit is partly destroyed
669  emit q->removed(action); //deprecated. remove in KDE5
670 }
671 
672 void KActionCollection::connectNotify ( const char * signal )
673 {
674  if (d->connectHovered && d->connectTriggered)
675  return;
676 
677  if (QMetaObject::normalizedSignature(SIGNAL(actionHighlighted(QAction*))) == signal ||
678  QMetaObject::normalizedSignature(SIGNAL(actionHovered(QAction*))) == signal) {
679  if (!d->connectHovered) {
680  d->connectHovered = true;
681  foreach (QAction* action, actions())
682  connect(action, SIGNAL(hovered()), SLOT(slotActionHovered()));
683  }
684 
685  } else if (QMetaObject::normalizedSignature(SIGNAL(actionTriggered(QAction*))) == signal) {
686  if (!d->connectTriggered) {
687  d->connectTriggered = true;
688  foreach (QAction* action, actions())
689  connect(action, SIGNAL(triggered(bool)), SLOT(slotActionTriggered()));
690  }
691  }
692 
693  QObject::connectNotify(signal);
694 }
695 
696 const QList< KActionCollection * >& KActionCollection::allCollections( )
697 {
698  return KActionCollectionPrivate::s_allCollections;
699 }
700 
701 void KActionCollection::associateWidget(QWidget* widget) const
702 {
703  foreach (QAction* action, actions()) {
704  if (!widget->actions().contains(action))
705  widget->addAction(action);
706  }
707 }
708 
709 void KActionCollection::addAssociatedWidget(QWidget * widget)
710 {
711  if (!d->associatedWidgets.contains(widget)) {
712  widget->addActions(actions());
713 
714  d->associatedWidgets.append(widget);
715  connect(widget, SIGNAL(destroyed(QObject*)), this, SLOT(_k_associatedWidgetDestroyed(QObject*)));
716  }
717 }
718 
719 void KActionCollection::removeAssociatedWidget(QWidget * widget)
720 {
721  foreach (QAction* action, actions())
722  widget->removeAction(action);
723 
724  d->associatedWidgets.removeAll(widget);
725  disconnect(widget, SIGNAL(destroyed(QObject*)), this, SLOT(_k_associatedWidgetDestroyed(QObject*)));
726 }
727 
728 
729 QAction *KActionCollectionPrivate::unlistAction(QAction* action)
730 {
731  // ATTENTION:
732  // This method is called with an QObject formerly known as a QAction
733  // during _k_actionDestroyed(). So don't do fancy stuff here that needs a
734  // real QAction!
735 
736  // Get the index for the action
737  int index = actions.indexOf(action);
738 
739  // Action not found.
740  if (index==-1) return NULL;
741 
742  // An action collection can't have the same action twice.
743  Q_ASSERT(actions.indexOf(action,index+1)==-1);
744 
745  // Get the actions name
746  const QString name = action->objectName();
747 
748  // Remove the action
749  actionByName.remove(name);
750  actions.removeAt(index);
751 
752  // Remove the action from the categories. Should be only one
753  QList<KActionCategory*> categories = q->findChildren<KActionCategory*>();
754  foreach (KActionCategory *category, categories) {
755  category->unlistAction(action);
756  }
757 
758  return action;
759 }
760 
761 
762 QList< QWidget * > KActionCollection::associatedWidgets() const
763 {
764  return d->associatedWidgets;
765 }
766 
767 void KActionCollection::clearAssociatedWidgets()
768 {
769  foreach (QWidget* widget, d->associatedWidgets)
770  foreach (QAction* action, actions())
771  widget->removeAction(action);
772 
773  d->associatedWidgets.clear();
774 }
775 
776 void KActionCollectionPrivate::_k_associatedWidgetDestroyed(QObject *obj)
777 {
778  associatedWidgets.removeAll(static_cast<QWidget*>(obj));
779 }
780 
781 /* vim: et sw=2 ts=2
782  */
783 
784 #include "kactioncollection.moc"
This file is part of the KDE documentation.
Documentation copyright © 1996-2013 The KDE developers.
Generated on Thu Feb 21 2013 11:06:42 by doxygen 1.8.1 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

KDEUI

Skip menu "KDEUI"
  • Main Page
  • Namespace List
  • Namespace Members
  • Alphabetical List
  • Class List
  • Class Hierarchy
  • Class Members
  • File List
  • File Members
  • Modules
  • Related Pages

kdelibs-4.8.5 API Reference

Skip menu "kdelibs-4.8.5 API Reference"
  • DNSSD
  • Interfaces
  •   KHexEdit
  •   KMediaPlayer
  •   KSpeech
  •   KTextEditor
  • kconf_update
  • KDE3Support
  •   KUnitTest
  • KDECore
  • KDED
  • KDEsu
  • KDEUI
  • KDEWebKit
  • KDocTools
  • KFile
  • KHTML
  • KImgIO
  • KInit
  • kio
  • KIOSlave
  • KJS
  •   KJS-API
  •   WTF
  • kjsembed
  • KNewStuff
  • KParts
  • KPty
  • Kross
  • KUnitConversion
  • KUtils
  • Nepomuk
  • Plasma
  • Solid
  • Sonnet
  • ThreadWeaver
Report problems with this website to our bug tracking system.
Contact the specific authors with questions and comments about the page contents.

KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal