Krita Source Code Documentation
Loading...
Searching...
No Matches
KisKActionCollection Class Reference

A container for a set of QAction objects. More...

#include <kactioncollection.h>

+ Inheritance diagram for KisKActionCollection:

Signals

QT_MOC_COMPAT void actionHighlighted (QAction *action)
 
void actionHovered (QAction *action)
 
void actionTriggered (QAction *action)
 
void inserted (QAction *action)
 

Public Member Functions

QAction * action (const QString &name) const
 
QAction * action (int index) const
 
const QList< QActionGroup * > actionGroups () const
 
QList< QAction * > actions () const
 
const QList< QAction * > actionsWithoutGroup () const
 
template<class ActionType >
ActionType * add (const QString &name, const QObject *receiver=0, const char *member=0)
 
QAction * addAction (const QString &name, const QObject *receiver=0, const char *member=0)
 
Q_INVOKABLE QAction * addAction (const QString &name, QAction *action)
 
QAction * addAction (KStandardAction::StandardAction actionType, const QObject *receiver=0, const char *member=0)
 
QAction * addAction (KStandardAction::StandardAction actionType, const QString &name, const QObject *receiver=0, const char *member=0)
 
void addActions (const QList< QAction * > &actions)
 
void addAssociatedWidget (QWidget *widget)
 
Q_INVOKABLE QAction * addCategorizedAction (const QString &name, QAction *action, const QString &categoryName)
 
QList< QWidget * > associatedWidgets () const
 
void associateWidget (QWidget *widget) const
 
QList< KisKActionCategory * > categories () const
 
void clear ()
 
void clearAssociatedWidgets ()
 
QString componentDisplayName () const
 
QString componentName () const
 
QString configGroup () const
 
int count () const
 
QKeySequence defaultShortcut (QAction *action) const
 
QList< QKeySequence > defaultShortcuts (QAction *action) const
 
KisKActionCategorygetCategory (const QString &categoryName)
 
bool isEmpty () const
 
bool isShortcutsConfigurable (QAction *action) const
 
 KisKActionCollection (QObject *parent, const QString &cName=QString())
 
const KisKXMLGUIClientparentGUIClient () const
 
void readSettings ()
 
void removeAction (QAction *action)
 
void removeAssociatedWidget (QWidget *widget)
 
void setComponentDisplayName (const QString &displayName)
 
void setComponentName (const QString &componentName)
 
void setConfigGroup (const QString &group)
 
void setDefaultShortcut (QAction *action, const QKeySequence &shortcut)
 
Q_INVOKABLE void setDefaultShortcuts (QAction *action, const QList< QKeySequence > &shortcuts)
 
void setShortcutsConfigurable (QAction *action, bool configurable)
 
QAction * takeAction (QAction *action)
 
void updateShortcuts ()
 
void writeSettings (KConfigGroup *config=0, bool writeScheme=false, QAction *oneAction=0) const
 
 ~KisKActionCollection () override
 

Static Public Member Functions

static const QList< KisKActionCollection * > & allCollections ()
 

Protected Slots

virtual QT_MOC_COMPAT void slotActionHighlighted ()
 
virtual void slotActionTriggered ()
 

Protected Member Functions

void connectNotify (const QMetaMethod &signal) override
 Overridden to perform connections when someone wants to know whether an action was highlighted or triggered.
 

Properties

QString configGroup
 

Private Slots

void slotActionHovered ()
 

Private Member Functions

 KisKActionCollection (const KisKXMLGUIClient *parent)
 

Private Attributes

class KisKActionCollectionPrivate *const d
 

Friends

class KisKActionCollectionPrivate
 
class KisKXMLGUIClient
 

Detailed Description

A container for a set of QAction objects.

KisKActionCollection manages a set of QAction objects. It allows them to be grouped for organized presentation of configuration to the user, saving + loading of configuration, and optionally for automatic plugging into specified widget(s).

Additionally, KisKActionCollection provides several convenience functions for locating named actions, and actions grouped by QActionGroup.

Note
If you create your own action collection and need to assign shortcuts to the actions within, you have to call associateWidget() or addAssociatedWidget() to have them working.

Definition at line 43 of file kactioncollection.h.

Constructor & Destructor Documentation

◆ KisKActionCollection() [1/2]

KisKActionCollection::KisKActionCollection ( QObject * parent,
const QString & cName = QString() )
explicit

Constructor. Allows specification of a component name other than the default application name, where needed (remember to call setComponentDisplayName() too).

Definition at line 89 of file kactioncollection.cpp.

90 : QObject(parent)
92{
93 d->q = this;
95
96 setComponentName(cName);
97}
static QList< KisKActionCollection * > s_allCollections
class KisKActionCollectionPrivate *const d
void setComponentName(const QString &componentName)

References d, KisKActionCollectionPrivate::q, KisKActionCollectionPrivate::s_allCollections, and setComponentName().

◆ ~KisKActionCollection()

KisKActionCollection::~KisKActionCollection ( )
override

Destructor.

Definition at line 110 of file kactioncollection.cpp.

111{
113
114 delete d;
115}

References d, and KisKActionCollectionPrivate::s_allCollections.

◆ KisKActionCollection() [2/2]

KisKActionCollection::KisKActionCollection ( const KisKXMLGUIClient * parent)
private

Definition at line 99 of file kactioncollection.cpp.

100 : QObject(0)
102{
103 d->q = this;
105
107 d->m_componentName = parent->componentName();
108}
const KisKXMLGUIClient * m_parentGUIClient
ChildIterator< value_type, is_const > parent(const ChildIterator< value_type, is_const > &it)
Definition KisForest.h:327

References d, KisKActionCollectionPrivate::m_componentName, KisKActionCollectionPrivate::m_parentGUIClient, KisKActionCollectionPrivate::q, and KisKActionCollectionPrivate::s_allCollections.

Member Function Documentation

◆ action() [1/2]

QAction * KisKActionCollection::action ( const QString & name) const

Get the action with the given name from the action collection.

Parameters
nameName of the QAction
Returns
A pointer to the QAction in the collection which matches the parameters or null if nothing matches.

Definition at line 145 of file kactioncollection.cpp.

146{
147 QAction *action = 0L;
148
149 if (!name.isEmpty()) {
150 action = d->actionByName.value(name);
151 }
152
153 return action;
154}
QMap< QString, QAction * > actionByName
QAction * action(int index) const
const char * name(StandardAction id)

References action(), KisKActionCollectionPrivate::actionByName, and d.

◆ action() [2/2]

QAction * KisKActionCollection::action ( int index) const

Return the QAction* at position "index" in the action collection.

This is equivalent to actions().value(index);

Definition at line 156 of file kactioncollection.cpp.

157{
158 // ### investigate if any apps use this at all
159 return actions().value(index);
160}
QList< QAction * > actions() const

References actions().

◆ actionGroups()

const QList< QActionGroup * > KisKActionCollection::actionGroups ( ) const

Returns the list of all QActionGroups associated with actions in this action collection.

Definition at line 232 of file kactioncollection.cpp.

233{
234 QSet<QActionGroup *> set;
235 Q_FOREACH (QAction *action, d->actions)
236 if (action->actionGroup()) {
237 set.insert(action->actionGroup());
238 }
239 return QList<QActionGroup*>(set.begin(), set.end());
240}

References action(), KisKActionCollectionPrivate::actions, and d.

◆ actionHighlighted

QT_MOC_COMPAT void KisKActionCollection::actionHighlighted ( QAction * action)
signal

Indicates that action was highlighted (hovered over).

Deprecated
Replaced by actionHovered(QAction* action);

◆ actionHovered

void KisKActionCollection::actionHovered ( QAction * action)
signal

Indicates that action was hovered.

◆ actions()

QList< QAction * > KisKActionCollection::actions ( ) const

Returns the list of QActions which belong to this action collection.

The list is guaranteed to be in the same order the action were put into the collection.

Definition at line 217 of file kactioncollection.cpp.

218{
219 return d->actions;
220}

References KisKActionCollectionPrivate::actions, and d.

◆ actionsWithoutGroup()

const QList< QAction * > KisKActionCollection::actionsWithoutGroup ( ) const

Returns the list of QActions without an QAction::actionGroup() which belong to this action collection.

Definition at line 222 of file kactioncollection.cpp.

223{
225 Q_FOREACH (QAction *action, d->actions)
226 if (!action->actionGroup()) {
227 ret.append(action);
228 }
229 return ret;
230}

References action(), KisKActionCollectionPrivate::actions, and d.

◆ actionTriggered

void KisKActionCollection::actionTriggered ( QAction * action)
signal

Indicates that action was triggered

◆ add()

template<class ActionType >
ActionType * KisKActionCollection::add ( const QString & name,
const QObject * receiver = 0,
const char * member = 0 )
inline

Creates a new action under the given name, adds it to the collection and connects the action's triggered(bool) signal to the specified receiver/member. The receiver slot may accept either a bool or no parameters at all (i.e. slotTriggered(bool) or slotTriggered() ). The type of the action is specified by the template parameter ActionType.

NOTE: KDE prior to 4.2 connected the triggered() signal instead of the triggered(bool) signal.

Parameters
nameThe internal name of the action (e.g. "file-open").
receiverThe QObject to connect the triggered(bool) signal to. Leave 0 if no connection is desired.
memberThe SLOT to connect the triggered(bool) signal to. Leave 0 if no connection is desired.
Returns
new action of the given type ActionType.
See also
addAction()

Definition at line 415 of file kactioncollection.h.

416 {
417 ActionType *a = new ActionType(this);
418 if (receiver && member) {
419 connect(a, SIGNAL(triggered(bool)), receiver, member);
420 }
421 addAction(name, a);
422 return a;
423 }
Q_INVOKABLE QAction * addAction(const QString &name, QAction *action)

◆ addAction() [1/4]

QAction * KisKActionCollection::addAction ( const QString & name,
const QObject * receiver = 0,
const char * member = 0 )

Creates a new action under the given name to the collection and connects the action's triggered(bool) signal to the specified receiver/member. The newly created action is returned.

NOTE: KDE prior to 4.2 used the triggered() signal instead of the triggered(bool) signal.

Inserting an action that was previously inserted under a different name will replace the old entry, i.e. the action will not be available under the old name anymore but only under the new one.

Inserting an action under a name that is already used for another action will replace the other action in the collection.

Parameters
nameThe name by which the action be retrieved again from the collection.
receiverThe QObject to connect the triggered(bool) signal to. Leave 0 if no connection is desired.
memberThe SLOT to connect the triggered(bool) signal to. Leave 0 if no connection is desired.
Returns
new action of the given type ActionType.

Definition at line 371 of file kactioncollection.cpp.

372{
373 QAction *a = new QAction(this);
374 if (receiver && member) {
375 connect(a, SIGNAL(triggered(bool)), receiver, member);
376 }
377 return addAction(name, a);
378}

References addAction().

◆ addAction() [2/4]

QAction * KisKActionCollection::addAction ( const QString & name,
QAction * action )

Add an action under the given name to the collection.

Inserting an action that was previously inserted under a different name will replace the old entry, i.e. the action will not be available under the old name anymore but only under the new one.

Inserting an action under a name that is already used for another action will replace the other action in the collection (but will not delete it).

Parameters
nameThe name by which the action be retrieved again from the collection.
actionThe action to add.
Returns
the same as the action given as parameter. This is just for convenience (chaining calls) and consistency with the other addAction methods, you can also simply ignore the return value.

Definition at line 247 of file kactioncollection.cpp.

248{
249 if (!action) {
250 return action;
251 }
252
253 const QString objectName = action->objectName();
254 QString indexName = name;
255
256 if (indexName.isEmpty()) {
257 // No name provided. Use the objectName.
258 indexName = objectName;
259
260 } else {
261 // Set the new name
262 action->setObjectName(indexName);
263 }
264
265 // No name provided and the action had no name. Make one up. This will not
266 // work when trying to save shortcuts.
267 if (indexName.isEmpty()) {
268 QTextStream(&indexName) << (void *)action;
269
270 action->setObjectName(indexName);
271 }
272
273 // From now on the objectName has to have a value. Else we cannot safely
274 // remove actions.
275 Q_ASSERT(!action->objectName().isEmpty());
276
277 // look if we already have THIS action under THIS name ;)
278 if (d->actionByName.value(indexName, 0) == action) {
279 // This is not a multi map!
280 Q_ASSERT(d->actionByName.count(indexName) == 1);
281 return action;
282 }
283
284 // Check if we have another action under this name
285 if (QAction *oldAction = d->actionByName.value(indexName)) {
286 takeAction(oldAction);
287 }
288
289 // Check if we have this action under a different name.
290 // Not using takeAction because we don't want to remove it from categories,
291 // and because it has the new name already.
292 const int oldIndex = d->actions.indexOf(action);
293 if (oldIndex != -1) {
294 d->actionByName.remove(d->actionByName.key(action));
295 d->actions.removeAt(oldIndex);
296 }
297
298 // Add action to our lists.
299 d->actionByName.insert(indexName, action);
300 d->actions.append(action);
301
302 Q_FOREACH (QWidget *widget, d->associatedWidgets) {
303 widget->addAction(action);
304 }
305
306 connect(action, SIGNAL(destroyed(QObject*)), SLOT(_k_actionDestroyed(QObject*)));
307
309
310 if (d->connectHovered) {
311 connect(action, SIGNAL(hovered()), SLOT(slotActionHovered()));
312 }
313
314 if (d->connectTriggered) {
315 connect(action, SIGNAL(triggered(bool)), SLOT(slotActionTriggered()));
316 }
317
318 Q_EMIT inserted(action);
319 return action;
320}
void setComponentForAction(QAction *action)
QList< QWidget * > associatedWidgets
void inserted(QAction *action)
QAction * takeAction(QAction *action)
virtual void slotActionTriggered()

References action(), KisKActionCollectionPrivate::actionByName, KisKActionCollectionPrivate::actions, KisKActionCollectionPrivate::associatedWidgets, KisKActionCollectionPrivate::connectHovered, KisKActionCollectionPrivate::connectTriggered, d, inserted(), KisKActionCollectionPrivate::setComponentForAction(), slotActionHovered(), slotActionTriggered(), and takeAction().

◆ addAction() [3/4]

QAction * KisKActionCollection::addAction ( KStandardAction::StandardAction actionType,
const QObject * receiver = 0,
const char * member = 0 )

Creates a new standard action, adds it to the collection and connects the action's triggered(bool) signal to the specified receiver/member. The newly created action is also returned.

Note: Using KStandardAction::OpenRecent will cause a different signal than triggered(bool) to be used, see KStandardAction for more information.

The action can be retrieved later from the collection by its standard name as per KStandardAction::stdName.

Parameters
actionTypeThe standard action type of the action to create.
receiverThe QObject to connect the triggered(bool) signal to. Leave 0 if no connection is desired.
memberThe SLOT to connect the triggered(bool) signal to. Leave 0 if no connection is desired.
Returns
new action of the given type ActionType.

Definition at line 350 of file kactioncollection.cpp.

351{
352 QAction *action = KStandardAction::create(actionType, receiver, member, this);
353 return action;
354}
QAction * create(StandardAction id, const QObject *recvr, const char *slot, QObject *parent)

References action(), and KStandardAction::create().

◆ addAction() [4/4]

QAction * KisKActionCollection::addAction ( KStandardAction::StandardAction actionType,
const QString & name,
const QObject * receiver = 0,
const char * member = 0 )

Creates a new standard action, adds to the collection under the given name and connects the action's triggered(bool) signal to the specified receiver/member. The newly created action is also returned.

Note: Using KStandardAction::OpenRecent will cause a different signal than triggered(bool) to be used, see KStandardAction for more information.

The action can be retrieved later from the collection by the specified name.

Parameters
actionTypeThe standard action type of the action to create.
nameThe name by which the action be retrieved again from the collection.
receiverThe QObject to connect the triggered(bool) signal to. Leave 0 if no connection is desired.
memberThe SLOT to connect the triggered(bool) signal to. Leave 0 if no connection is desired.
Returns
new action of the given type ActionType.

Definition at line 356 of file kactioncollection.cpp.

358{
359 // pass 0 as parent, because if the parent is a KisKActionCollection KStandardAction::create automatically
360 // adds the action to it under the default name. We would trigger the
361 // warning about renaming the action then.
362 QAction *action = KStandardAction::create(actionType, receiver, member, 0);
363 // Give it a parent for gc.
364 action->setParent(this);
365 // Remove the name to get rid of the "rename action" warning above
366 action->setObjectName(name);
367 // And now add it with the desired name.
368 return addAction(name, action);
369}

References action(), addAction(), and KStandardAction::create().

◆ addActions()

void KisKActionCollection::addActions ( const QList< QAction * > & actions)

Adds a list of actions to the collection.

The objectName of the actions is used as their internal name in the collection.

Uses addAction(QString, QAction*).

Parameters
actionsthe list of the actions to add.
See also
addAction()
Since
5.0

Definition at line 322 of file kactioncollection.cpp.

323{
324 Q_FOREACH (QAction *action, actions) {
325 addAction(action->objectName(), action);
326 }
327}

References action(), actions(), and addAction().

◆ addAssociatedWidget()

void KisKActionCollection::addAssociatedWidget ( QWidget * widget)

Associate all actions in this collection to the given widget, including any actions added after this association is made.

This does not change the action's shortcut context, so if you need to have the actions only trigger when the widget has focus, you'll need to set the shortcut context on each action to Qt::WidgetShortcut (or better still, Qt::WidgetWithChildrenShortcut with Qt 4.4+)

Definition at line 654 of file kactioncollection.cpp.

655{
656 if (!d->associatedWidgets.contains(widget)) {
657 widget->addActions(actions());
658
659 d->associatedWidgets.append(widget);
660 connect(widget, SIGNAL(destroyed(QObject*)), this, SLOT(_k_associatedWidgetDestroyed(QObject*)));
661 }
662}

References actions(), KisKActionCollectionPrivate::associatedWidgets, and d.

◆ addCategorizedAction()

QAction * KisKActionCollection::addCategorizedAction ( const QString & name,
QAction * action,
const QString & categoryName )

Adds a new action to the collection in category category.

The category will be created if it does not already exist.

Definition at line 242 of file kactioncollection.cpp.

243{
244 return getCategory(categoryName)->addAction(name, action);
245}
QAction * addAction(const QString &name, QAction *action)
KisKActionCategory * getCategory(const QString &categoryName)

References action(), KisKActionCategory::addAction(), and getCategory().

◆ allCollections()

const QList< KisKActionCollection * > & KisKActionCollection::allCollections ( )
static

Access the list of all action collections in existence for this app

Definition at line 640 of file kactioncollection.cpp.

References KisKActionCollectionPrivate::s_allCollections.

◆ associatedWidgets()

QList< QWidget * > KisKActionCollection::associatedWidgets ( ) const

Return a list of all associated widgets.

Definition at line 720 of file kactioncollection.cpp.

721{
722 return d->associatedWidgets;
723}

References KisKActionCollectionPrivate::associatedWidgets, and d.

◆ associateWidget()

void KisKActionCollection::associateWidget ( QWidget * widget) const

Associate all actions in this collection to the given widget. Unlike addAssociatedWidget, this method only adds all current actions in the collection to the given widget. Any action added after this call will not be added to the given widget automatically. So this is just a shortcut for a foreach loop and a widget->addAction call.

Definition at line 645 of file kactioncollection.cpp.

646{
647 Q_FOREACH (QAction *action, actions()) {
648 if (!widget->actions().contains(action)) {
649 widget->addAction(action);
650 }
651 }
652}

References action(), and actions().

◆ categories()

QList< KisKActionCategory * > KisKActionCollection::categories ( ) const

Returns the KActionCategories inside this collection

Definition at line 118 of file kactioncollection.cpp.

119{
120 return this->findChildren<KisKActionCategory *>();
121}

◆ clear()

void KisKActionCollection::clear ( )

Clears the entire action collection, deleting all actions.

Definition at line 138 of file kactioncollection.cpp.

139{
140 d->actionByName.clear();
141 qDeleteAll(d->actions);
142 d->actions.clear();
143}

References KisKActionCollectionPrivate::actionByName, KisKActionCollectionPrivate::actions, and d.

◆ clearAssociatedWidgets()

void KisKActionCollection::clearAssociatedWidgets ( )

Clear all associated widgets and remove the actions from those widgets.

Definition at line 725 of file kactioncollection.cpp.

726{
727 Q_FOREACH (QWidget *widget, d->associatedWidgets)
728 Q_FOREACH (QAction *action, actions()) {
729 widget->removeAction(action);
730 }
731
732 d->associatedWidgets.clear();
733}

References action(), actions(), KisKActionCollectionPrivate::associatedWidgets, and d.

◆ componentDisplayName()

QString KisKActionCollection::componentDisplayName ( ) const

The display name for the associated component.

Definition at line 201 of file kactioncollection.cpp.

202{
203 if (!d->m_componentDisplayName.isEmpty()) {
205 }
206 if (!QGuiApplication::applicationDisplayName().isEmpty()) {
207 return QGuiApplication::applicationDisplayName();
208 }
209 return QCoreApplication::applicationName();
210}

References d, isEmpty(), and KisKActionCollectionPrivate::m_componentDisplayName.

◆ componentName()

QString KisKActionCollection::componentName ( ) const

The component name with which this class is associated.

Definition at line 191 of file kactioncollection.cpp.

192{
193 return d->m_componentName;
194}

References d, and KisKActionCollectionPrivate::m_componentName.

◆ configGroup()

QString KisKActionCollection::configGroup ( ) const

Returns the KConfig group with which settings will be loaded and saved.

Definition at line 414 of file kactioncollection.cpp.

415{
416 return d->configGroup;
417}

References KisKActionCollectionPrivate::configGroup, and d.

◆ connectNotify()

void KisKActionCollection::connectNotify ( const QMetaMethod & signal)
overrideprotected

Overridden to perform connections when someone wants to know whether an action was highlighted or triggered.

Definition at line 613 of file kactioncollection.cpp.

614{
616 return;
617 }
618
619 if (signal.methodSignature() == "actionHighlighted(QAction*)" ||
620 signal.methodSignature() == "actionHovered(QAction*)") {
621 if (!d->connectHovered) {
622 d->connectHovered = true;
623 Q_FOREACH (QAction *action, actions()) {
624 connect(action, SIGNAL(hovered()), SLOT(slotActionHovered()));
625 }
626 }
627
628 } else if (signal.methodSignature() == "actionTriggered(QAction*)") {
629 if (!d->connectTriggered) {
630 d->connectTriggered = true;
631 Q_FOREACH (QAction *action, actions()) {
632 connect(action, SIGNAL(triggered(bool)), SLOT(slotActionTriggered()));
633 }
634 }
635 }
636
637 QObject::connectNotify(signal);
638}

References action(), actions(), KisKActionCollectionPrivate::connectHovered, KisKActionCollectionPrivate::connectTriggered, d, slotActionHovered(), and slotActionTriggered().

◆ count()

int KisKActionCollection::count ( ) const

Returns the number of actions in the collection.

This is equivalent to actions().count().

Definition at line 162 of file kactioncollection.cpp.

163{
164 return d->actions.count();
165}

References KisKActionCollectionPrivate::actions, and d.

◆ defaultShortcut()

QKeySequence KisKActionCollection::defaultShortcut ( QAction * action) const

Get the default primary shortcut for the given action.

Parameters
actionthe action for which the default primary shortcut should be returned.
Returns
the default primary shortcut of the given action
Since
5.0

Definition at line 380 of file kactioncollection.cpp.

381{
383 return shortcuts.isEmpty() ? QKeySequence() : shortcuts.first();
384}
QList< QKeySequence > defaultShortcuts(QAction *action) const

References action(), and defaultShortcuts().

◆ defaultShortcuts()

QList< QKeySequence > KisKActionCollection::defaultShortcuts ( QAction * action) const

Get the default shortcuts for the given action.

Parameters
actionthe action for which the default shortcuts should be returned.
Returns
the default shortcuts of the given action
Since
5.0

Definition at line 386 of file kactioncollection.cpp.

387{
388 return action->property("defaultShortcuts").value<QList<QKeySequence> >();
389}

References action().

◆ getCategory()

KisKActionCategory * KisKActionCollection::getCategory ( const QString & categoryName)

Gets a category with name name inside this collection.

Creates a new category if one does not exist.

Definition at line 123 of file kactioncollection.cpp.

123 {
124 KisKActionCategory *category = 0;
125 foreach (KisKActionCategory *c, categories()) {
126 if (c->text() == name) {
127 category = c;
128 }
129 }
130
131 if (category == 0) {
132 category = new KisKActionCategory(name, this);
133 }
134 return category;
135}
QList< KisKActionCategory * > categories() const

References categories(), and KisKActionCategory::text.

◆ inserted

void KisKActionCollection::inserted ( QAction * action)
signal

Indicates that action was inserted into this action collection.

◆ isEmpty()

bool KisKActionCollection::isEmpty ( ) const

Returns whether the action collection is empty or not.

Definition at line 167 of file kactioncollection.cpp.

168{
169 return count() == 0;
170}

References count().

◆ isShortcutsConfigurable()

bool KisKActionCollection::isShortcutsConfigurable ( QAction * action) const

Returns true if the given action's shortcuts may be configured by the user.

Parameters
actionthe action for the hint should be verified.
Since
5.0

Definition at line 402 of file kactioncollection.cpp.

403{
404 // Considered as true by default
405 const QVariant value = action->property("isShortcutConfigurable");
406 return value.isValid() ? value.toBool() : true;
407}
float value(const T *src, size_t ch)

References action(), and value().

◆ parentGUIClient()

const KisKXMLGUIClient * KisKActionCollection::parentGUIClient ( ) const

The parent KisKXMLGUIClient, or null if not available.

Definition at line 212 of file kactioncollection.cpp.

213{
214 return d->m_parentGUIClient;
215}

References d, and KisKActionCollectionPrivate::m_parentGUIClient.

◆ readSettings()

void KisKActionCollection::readSettings ( )

Read all key associations from config.

If config is zero, read all key associations from the application's configuration file KSharedConfig::openConfig(), in the group set by setConfigGroup().

Definition at line 435 of file kactioncollection.cpp.

436{
437 auto ar = KisActionRegistry::instance();
438 ar->loadCustomShortcuts();
439
440 for (QMap<QString, QAction *>::ConstIterator it = d->actionByName.constBegin();
441 it != d->actionByName.constEnd(); ++it) {
442 QAction *action = it.value();
443 if (!action) {
444 continue;
445 }
446
448 QString actionName = it.key();
449 ar->updateShortcut(actionName, action);
450 }
451 }
452}
static KisActionRegistry * instance()
bool isShortcutsConfigurable(QAction *action) const

References action(), KisKActionCollectionPrivate::actionByName, d, KisActionRegistry::instance(), and isShortcutsConfigurable().

◆ removeAction()

void KisKActionCollection::removeAction ( QAction * action)

Removes an action from the collection and deletes it.

Parameters
actionThe action to remove.

Definition at line 329 of file kactioncollection.cpp.

330{
331 delete takeAction(action);
332}

References action(), and takeAction().

◆ removeAssociatedWidget()

void KisKActionCollection::removeAssociatedWidget ( QWidget * widget)

Remove an association between all actions in this collection and the given widget, i.e. remove those actions from the widget, and stop associating newly added actions as well.

Definition at line 664 of file kactioncollection.cpp.

665{
666 Q_FOREACH (QAction *action, actions()) {
667 widget->removeAction(action);
668 }
669
670 d->associatedWidgets.removeAll(widget);
671 disconnect(widget, SIGNAL(destroyed(QObject*)), this, SLOT(_k_associatedWidgetDestroyed(QObject*)));
672}

References action(), actions(), KisKActionCollectionPrivate::associatedWidgets, and d.

◆ setComponentDisplayName()

void KisKActionCollection::setComponentDisplayName ( const QString & displayName)

Set the component display name associated with this action collection. (e.g. for the toolbar editor) KXmlGuiClient::setComponentName takes care of calling this.

Definition at line 196 of file kactioncollection.cpp.

197{
198 d->m_componentDisplayName = displayName;
199}

References d, and KisKActionCollectionPrivate::m_componentDisplayName.

◆ setComponentName()

void KisKActionCollection::setComponentName ( const QString & componentName)

Set the componentName associated with this action collection.

Warning
Don't call this method on a KisKActionCollection that contains actions. This is not supported.
Parameters
componentNamethe name which is to be associated with this action collection, or QString() to indicate the app name. This is used to load/save settings into XML files. KXmlGuiClient::setComponentName takes care of calling this.

Definition at line 172 of file kactioncollection.cpp.

173{
174 if (count() > 0) {
175 // Its component name is part of an action's signature in the context of
176 // global shortcuts and the semantics of changing an existing action's
177 // signature are, as it seems, impossible to get right.
178 // As of now this only matters for global shortcuts. We could
179 // thus relax the requirement and only refuse to change the component data
180 // if we have actions with global shortcuts in this collection.
181 qWarning() << "this does not work on a KisKActionCollection containing actions!";
182 }
183
184 if (!cName.isEmpty()) {
185 d->m_componentName = cName;
186 } else {
187 d->m_componentName = QCoreApplication::applicationName();
188 }
189}

References count(), d, and KisKActionCollectionPrivate::m_componentName.

◆ setConfigGroup()

void KisKActionCollection::setConfigGroup ( const QString & group)

Sets group as the KConfig group with which settings will be loaded and saved.

Definition at line 419 of file kactioncollection.cpp.

420{
421 d->configGroup = group;
422}

References KisKActionCollectionPrivate::configGroup, and d.

◆ setDefaultShortcut()

void KisKActionCollection::setDefaultShortcut ( QAction * action,
const QKeySequence & shortcut )

Set the default shortcut for the given action. Since 5.2, this also calls action->setShortcut(shortcut), i.e. the default shortcut is made active initially.

Parameters
actionthe action for which the default shortcut should be set.
shortcutthe shortcut to use for the given action in its specified shortcutContext()
Since
5.0

Definition at line 391 of file kactioncollection.cpp.

392{
394}
Q_INVOKABLE void setDefaultShortcuts(QAction *action, const QList< QKeySequence > &shortcuts)

References action(), and setDefaultShortcuts().

◆ setDefaultShortcuts()

void KisKActionCollection::setDefaultShortcuts ( QAction * action,
const QList< QKeySequence > & shortcuts )

Set the default shortcuts for the given action. Since 5.2, this also calls action->setShortcuts(shortcuts), i.e. the default shortcut is made active initially.

Parameters
actionthe action for which the default shortcut should be set.
shortcutsthe shortcuts to use for the given action in its specified shortcutContext()
Since
5.0

Definition at line 396 of file kactioncollection.cpp.

397{
398 action->setShortcuts(shortcuts);
399 action->setProperty("defaultShortcuts", QVariant::fromValue(shortcuts));
400}

References action().

◆ setShortcutsConfigurable()

void KisKActionCollection::setShortcutsConfigurable ( QAction * action,
bool configurable )

Indicate whether the user may configure the action's shortcuts.

Parameters
actionthe action for the hint should be verified.
configurableset to true if the shortcuts of the given action may be configured by the user, otherwise false.
Since
5.0

Definition at line 409 of file kactioncollection.cpp.

410{
411 action->setProperty("isShortcutConfigurable", configurable);
412}

References action().

◆ slotActionHighlighted

void KisKActionCollection::slotActionHighlighted ( )
protectedvirtualslot

Definition at line 594 of file kactioncollection.cpp.

595{
597}

References slotActionHovered().

◆ slotActionHovered

void KisKActionCollection::slotActionHovered ( )
privateslot

Definition at line 599 of file kactioncollection.cpp.

600{
601 QAction *action = qobject_cast<QAction *>(sender());
602 if (action) {
604 Q_EMIT actionHovered(action);
605 }
606}
QT_MOC_COMPAT void actionHighlighted(QAction *action)
void actionHovered(QAction *action)

References action(), actionHighlighted(), and actionHovered().

◆ slotActionTriggered

void KisKActionCollection::slotActionTriggered ( )
protectedvirtualslot

Definition at line 586 of file kactioncollection.cpp.

587{
588 QAction *action = qobject_cast<QAction *>(sender());
589 if (action) {
590 Q_EMIT actionTriggered(action);
591 }
592}
void actionTriggered(QAction *action)

References action(), and actionTriggered().

◆ takeAction()

QAction * KisKActionCollection::takeAction ( QAction * action)

Removes an action from the collection.

Parameters
actionthe action to remove.

Definition at line 334 of file kactioncollection.cpp.

335{
336 if (!d->unlistAction(action)) {
337 return 0;
338 }
339
340 // Remove the action from all widgets
341 Q_FOREACH (QWidget *widget, d->associatedWidgets) {
342 widget->removeAction(action);
343 }
344
345 action->disconnect(this);
346
347 return action;
348}
QAction * unlistAction(QObject *)

References action(), KisKActionCollectionPrivate::associatedWidgets, d, and KisKActionCollectionPrivate::unlistAction().

◆ updateShortcuts()

void KisKActionCollection::updateShortcuts ( )

Update shortcuts from the KisActionRegistry.

Definition at line 424 of file kactioncollection.cpp.

425{
426 auto actionRegistry = KisActionRegistry::instance();
427
428 for (QMap<QString, QAction *>::ConstIterator it = d->actionByName.constBegin();
429 it != d->actionByName.constEnd(); ++it) {
430 actionRegistry->updateShortcut(it.key(), it.value());
431 }
432}

References KisKActionCollectionPrivate::actionByName, d, and KisActionRegistry::instance().

◆ writeSettings()

void KisKActionCollection::writeSettings ( KConfigGroup * config = 0,
bool writeScheme = false,
QAction * oneAction = 0 ) const

Write the current configurable key associations. If is nonzero, use that configuration group.

Otherwise, the output file is determined as follows. If this action collection belongs to a KXMLGuiClient the setting are saved to the kxmlgui definition file. If not the settings are written to the applications config file.

Note
oneAction() and writeDefaults() have no meaning for the kxmlgui configuration file.
Parameters
configConfig object to save to, or null (see above)
writeSchemeset to true if we export all settings as new shortcut scheme
oneActionpass an action here if you just want to save the values for one action, eg. if you know that action is the only one which has changed.

Definition at line 517 of file kactioncollection.cpp.

520{
521 // If the caller didn't provide a config group we try to save the KisKXMLGUI
522 // Configuration file. (This will work if the parentGUI was set and has a
523 // valid configuration file.)
524 if (config == 0 && d->writeKisKXMLGUIConfigFile()) {
525 return;
526 }
527
528
529 KConfigGroup cg(KSharedConfig::openConfig(), configGroup());
530 if (!config) {
531 config = &cg;
532 }
533
534 QList<QAction *> writeActions;
535 if (oneAction) {
536 writeActions.append(oneAction);
537 } else {
538 writeActions = actions();
539 }
540
541 for (QMap<QString, QAction *>::ConstIterator it = d->actionByName.constBegin();
542 it != d->actionByName.constEnd(); ++it) {
543
544 QAction *action = it.value();
545 if (!action) {
546 continue;
547 }
548
549 QString actionName = it.key();
550
551 // If the action name starts with unnamed- spit out a warning and ignore
552 // it. That name will change at will and will break loading writing
553 if (actionName.startsWith(QLatin1String("unnamed-"))) {
554 qCritical() << "Skipped saving shortcut for action without name " \
555 << action->text() << "!";
556 continue;
557 }
558
559 // Write the shortcut
561 bool bConfigHasAction = !config->readEntry(actionName, QString()).isEmpty();
562 bool bSameAsDefault = (action->shortcuts() == defaultShortcuts(action));
563 // If the current shortcut differs from the default, we want to write.
564
565 KConfigGroup::WriteConfigFlags flags = KConfigGroup::Persistent;
566
567 if (writeScheme || !bSameAsDefault) {
568 // We are instructed to write all shortcuts or the shortcut is
569 // not set to its default value. Write it
570 QString s = QKeySequence::listToString(action->shortcuts());
571 if (s.isEmpty()) {
572 s = QStringLiteral("none");
573 }
574 config->writeEntry(actionName, s, flags);
575 } else if (bConfigHasAction) {
576 // This key is the same as default but exists in config file.
577 // Remove it.
578 config->deleteEntry(actionName, flags);
579 }
580 }
581 }
582
583 config->sync();
584}

References action(), KisKActionCollectionPrivate::actionByName, actions(), configGroup, d, defaultShortcuts(), isShortcutsConfigurable(), and KisKActionCollectionPrivate::writeKisKXMLGUIConfigFile().

Friends And Related Symbol Documentation

◆ KisKActionCollectionPrivate

friend class KisKActionCollectionPrivate
friend

Definition at line 489 of file kactioncollection.h.

◆ KisKXMLGUIClient

friend class KisKXMLGUIClient
friend

Definition at line 45 of file kactioncollection.h.

Member Data Documentation

◆ d

class KisKActionCollectionPrivate* const KisKActionCollection::d
private

Definition at line 490 of file kactioncollection.h.

Property Documentation

◆ configGroup

QString KisKActionCollection::configGroup
readwrite

Definition at line 49 of file kactioncollection.h.


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