Krita Source Code Documentation
Loading...
Searching...
No Matches
KisActionsSnapshot.cpp
Go to the documentation of this file.
1/*
2 * SPDX-FileCopyrightText: 2016 Dmitry Kazakov <dimula73@gmail.com>
3 *
4 * SPDX-License-Identifier: GPL-2.0-or-later
5 */
6
8
10#include "./kactioncollection.h"
11
12#include "kis_debug.h"
13
14//#define ACTIONS_CHECKSUM_SANITY_CHECK
15
16
18{
19 QMap<QString, KisKActionCollection*> actionCollections;
20
22 qDeleteAll(actionCollections);
23 qDeleteAll(fakeActions);
24 }
25
28};
29
31 : m_d(new Private)
32{
34 m_d->nonRegisteredShortcuts = QSet<QString>(registeredShortcutIds.begin(), registeredShortcutIds.end());
35}
36
40
41void KisActionsSnapshot::addAction(const QString &name, QAction *action)
42{
43 m_d->nonRegisteredShortcuts.remove(name);
45
46 if (!cat.isValid()) {
47 warnKrita << "WARNING: Uncategorized action" << name << "Dropping...";
48 return;
49 }
50
51#ifdef ACTIONS_CHECKSUM_SANITY_CHECK
52 if (!KisActionRegistry::instance()->sanityCheckPropertized(action->objectName())) {
53 warnKrita << "WARNING: action" << name << "was not propertized!" << ppVar(action->property("isShortcutConfigurable").toBool());
54 }
55#endif /* ACTIONS_CHECKSUM_SANITY_CHECK */
56
57 KisKActionCollection *collection = m_d->actionCollections[cat.componentName];
58
59 if (!collection) {
60 collection = new KisKActionCollection(0, cat.componentName);
61 m_d->actionCollections.insert(cat.componentName, collection);
62 }
63
64 collection->addCategorizedAction(name, action, cat.categoryName);
65}
66
67QMap<QString, KisKActionCollection *> KisActionsSnapshot::actionCollections()
68{
73 if (m_d->nonRegisteredShortcuts.size() > 4 &&
74 m_d->nonRegisteredShortcuts.size() < 160) {
75
76 warnKrita << "WARNING: The following shortcuts are not registered in the collection, "
77 "they might have wrong shortcuts in the end:";
78 Q_FOREACH (const QString &str, m_d->nonRegisteredShortcuts) {
79 warnKrita << str;
80 }
81 warnKrita << "=== end ===";
82 }
83
84 // try to workaround non-registered shortcuts by faking them manually
85 Q_FOREACH (const QString &str, m_d->nonRegisteredShortcuts) {
86 QAction *action = KisActionRegistry::instance()->makeQAction(str, 0);
87 m_d->fakeActions << action;
88 addAction(action->objectName(), action);
89 }
90
91 return m_d->actionCollections;
92}
93
QList< QString > registeredShortcutIds() const
QAction * makeQAction(const QString &name, QObject *parent=0)
ActionCategory fetchActionCategory(const QString &name) const
static KisActionRegistry * instance()
QMap< QString, KisKActionCollection * > actionCollections()
const QScopedPointer< Private > m_d
void addAction(const QString &name, QAction *action)
registers the action in the snapshot and sorts it into a proper category. The action is not owned by ...
A container for a set of QAction objects.
Q_INVOKABLE QAction * addCategorizedAction(const QString &name, QAction *action, const QString &categoryName)
#define warnKrita
Definition kis_debug.h:87
#define ppVar(var)
Definition kis_debug.h:155
QMap< QString, KisKActionCollection * > actionCollections