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

#include <kactioncategory.h>

+ Inheritance diagram for KisKActionCategory:

Public Member Functions

 KisKActionCategory (const QString &text, KisKActionCollection *parent=0)
 
 ~KisKActionCategory () override
 

Properties

QString text
 

Adding Actions

Add a action to the category.

This methods are provided for your convenience. They call the corresponding method of KisKActionCollection.

class KisKActionCollectionPrivate
 KisKActionCollection needs access to some of our helper methods.
 
KisKActionCategoryPrivate *const d
 Implementation details.
 
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)
 
QAction * addAction (const QString &name, const QObject *receiver=0, const char *member=0)
 
template<class ActionType >
ActionType * add (const QString &name, const QObject *receiver=0, const char *member=0)
 
const QList< QAction * > actions () const
 
KisKActionCollectioncollection () const
 
QString text () const
 
void setText (const QString &text)
 
void unlistAction (QAction *action)
 
void addAction (QAction *action)
 

Detailed Description

Categorize actions for KShortcutsEditor.

KisKActionCategory provides a second level to organize the actions in KShortcutsEditor.

The first possibility is using more than one action collection. Each actions collection becomes a top level node.

  • action collection 1
    • first action
    • second action
    • third action
  • action collection 2
    • first action
    • second action
    • third action

Using KisKActionCategory it's possible to group the actions of one collection.

  • action collection 1
    • first action
    • first category
      • action 1 in category
      • action 2 in category
    • second action

Usage

The usage is analog to action collections. Just create a category and use it instead of the collection to create the actions.

The synchronization between KisKActionCollection and KisKActionCategory is done internally. There is for example no need to remove actions from a category. It is done implicitly if the action is removed from the associated collection.

KisKActionCategory *file = new KisKActionCategory(i18n("File"), actionCollection());
file->addAction(
KStandardAction::New, //< see KStandardAction
this, //< Receiver
SLOT(fileNew())); //< SLOT
... more actions added to file ...
KisKActionCategory *edit = new KisKActionCategory(i18n("Edit"), actionCollection());
edit->addAction(
KStandardAction::Copy, //< see KStandardAction
this, //< Receiver
SLOT(fileNew())); //< SLOT
...
const QList< QAction * > actions() const
KisKActionCategory(const QString &text, KisKActionCollection *parent=0)

Definition at line 80 of file kactioncategory.h.

Constructor & Destructor Documentation

◆ KisKActionCategory()

KisKActionCategory::KisKActionCategory ( const QString & text,
KisKActionCollection * parent = 0 )
explicit

Default constructor

Definition at line 26 of file kactioncategory.cpp.

27 : QObject(parent)
28 , d(new KisKActionCategoryPrivate(this))
29{
30 d->text = text;
31}
KisKActionCategoryPrivate *const d
Implementation details.
QString text
The text for this category.

References d, KisKActionCategoryPrivate::text, and text.

◆ ~KisKActionCategory()

KisKActionCategory::~KisKActionCategory ( )
override

Destructor

Definition at line 33 of file kactioncategory.cpp.

34{
35 delete d;
36}

References d.

Member Function Documentation

◆ actions()

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

Returns the actions belonging to this category

Definition at line 38 of file kactioncategory.cpp.

39{
40 return d->actions;
41}
QList< QAction * > actions
List of actions.

References KisKActionCategoryPrivate::actions, and d.

◆ add()

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

Definition at line 125 of file kactioncategory.h.

129 {
130 ActionType *action = collection()->add<ActionType>(name, receiver, member);
131 addAction(action);
132 return action;
133 }
KisKActionCollection * collection() const
QAction * addAction(const QString &name, QAction *action)
ActionType * add(const QString &name, const QObject *receiver=0, const char *member=0)
const char * name(StandardAction id)

◆ addAction() [1/5]

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

Definition at line 71 of file kactioncategory.cpp.

75{
76 QAction *action = collection()->addAction(name, receiver, member);
77 addAction(action);
78 return action;
79}
Q_INVOKABLE QAction * addAction(const QString &name, QAction *action)

References addAction(), KisKActionCollection::addAction(), and collection().

◆ addAction() [2/5]

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

Definition at line 43 of file kactioncategory.cpp.

44{
45 collection()->addAction(name, action);
46 addAction(action);
47 return action;
48}

References addAction(), KisKActionCollection::addAction(), and collection().

◆ addAction() [3/5]

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

Definition at line 50 of file kactioncategory.cpp.

54{
55 QAction *action = collection()->addAction(actionType, receiver, member);
56 addAction(action);
57 return action;
58}

References addAction(), KisKActionCollection::addAction(), and collection().

◆ addAction() [4/5]

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

Definition at line 60 of file kactioncategory.cpp.

65{
66 QAction *action = collection()->addAction(actionType, name, receiver, member);
67 addAction(action);
68 return action;
69}

References addAction(), KisKActionCollection::addAction(), and collection().

◆ addAction() [5/5]

void KisKActionCategory::addAction ( QAction * action)
private

Add action to category

Definition at line 81 of file kactioncategory.cpp.

82{
83 // Only add the action if wasn't added earlier.
84 if (!d->actions.contains(action)) {
85 d->actions.append(action);
86 }
87}

References KisKActionCategoryPrivate::actions, and d.

◆ collection()

KisKActionCollection * KisKActionCategory::collection ( ) const

The action collection this category is associated with.

Definition at line 89 of file kactioncategory.cpp.

90{
91 return qobject_cast<KisKActionCollection *>(parent());
92}
ChildIterator< value_type, is_const > parent(const ChildIterator< value_type, is_const > &it)
Definition KisForest.h:327

◆ setText()

void KisKActionCategory::setText ( const QString & text)

Set the action categories descriptive text.

Definition at line 99 of file kactioncategory.cpp.

100{
101 d->text = text;
102}

References d, KisKActionCategoryPrivate::text, and text.

◆ text()

QString KisKActionCategory::text ( ) const

The action categories descriptive text

Definition at line 94 of file kactioncategory.cpp.

95{
96 return d->text;
97}

References d, and KisKActionCategoryPrivate::text.

◆ unlistAction()

void KisKActionCategory::unlistAction ( QAction * action)
private

Remove \action from this category if found.

Definition at line 104 of file kactioncategory.cpp.

105{
106 // ATTENTION:
107 // This method is called from KisKActionCollection with an QObject formerly
108 // known as a QAction during _k_actionDestroyed(). So don't do fancy stuff
109 // here that needs a real QAction!
110
111 // Get the index for the action
112 int index = d->actions.indexOf(action);
113
114 // Action not found.
115 if (index == -1) {
116 return;
117 }
118
119 // Remove the action
120 d->actions.takeAt(index);
121}

References KisKActionCategoryPrivate::actions, and d.

Friends And Related Symbol Documentation

◆ KisKActionCollectionPrivate

friend class KisKActionCollectionPrivate
friend

KisKActionCollection needs access to some of our helper methods.

Definition at line 169 of file kactioncategory.h.

Member Data Documentation

◆ d

KisKActionCategoryPrivate* const KisKActionCategory::d
private

Implementation details.

Definition at line 172 of file kactioncategory.h.

Property Documentation

◆ text

QString KisKActionCategory::text
readwrite

Definition at line 84 of file kactioncategory.h.


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