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

Skip menu "kdelibs-4.14.38 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