Krita Source Code Documentation
Loading...
Searching...
No Matches
kxmlguifactory_p.h
Go to the documentation of this file.
1/* This file is part of the KDE libraries
2 SPDX-FileCopyrightText: 2001 Simon Hausmann <hausmann@kde.org>
3
4 SPDX-License-Identifier: LGPL-2.0-or-later
5*/
6#ifndef kxmlguifactory_p_h
7#define kxmlguifactory_p_h
8
9#include <QStringList>
10#include <QMap>
11#include <QDomElement>
12#include <QStack>
13#include <QAction>
14
15class QWidget;
18
19namespace KisKXMLGUI
20{
21
22struct BuildState;
23
24class ActionList : public QList<QAction *>
25{
26public:
29 : QList<QAction *>(rhs)
30 {}
32 {
34 return *this;
35 }
36
37 void plug(QWidget *container, int index) const;
38 void unplug(QWidget *container) const;
39};
40
41typedef QMap< QString, ActionList > ActionListMap;
42
43/*
44 * This structure is used to know to which client certain actions and custom elements
45 * (i.e. menu separators) belong.
46 * We do not only use a ContainerClient per GUIClient but also per merging group.
47 *
48 * groupName : Used for grouped merging. Specifies the group name to which these actions/elements
49 * belong to.
50 * actionLists : maps from action list name to action list.
51 * mergingName : The (named) merging point.
52 *
53 * A ContainerClient always belongs to a ContainerNode.
54 */
64
65struct ContainerNode;
66
68 int value; // the actual index value, used as index for plug() or createContainer() calls
69 QString mergingName; // the name of the merging index (i.e. the name attribute of the
70 // Merge or DefineGroup tag)
71 QString clientName; // the name of the client that defined this index
72};
74
75/*
76 * Here we store detailed information about a container, its clients (client=a guiclient having actions
77 * plugged into the container), child nodes, naming information (tagname and name attribute) and
78 * merging index information, to plug/insert new actions/items a the correct position.
79 *
80 * The builder variable is needed for using the proper GUIBuilder for destruction ( to use the same for
81 * con- and destruction ). The builderCustomTags and builderContainerTags variables are cached values
82 * of what the corresponding methods of the GUIBuilder which built the container return. The stringlists
83 * is shared all over the place, so there's no need to worry about memory consumption for these
84 * variables :-)
85 *
86 * The mergingIndices list contains the merging indices ;-) , as defined by <Merge>, <DefineGroup>
87 * or by <ActionList> tags. The order of these index structures within the mergingIndices list
88 * is (and has to be) identical with the order in the DOM tree.
89 *
90 * Beside the merging indices we have the "real" index of the container. It points to the next free
91 * position.
92 * (used when no merging index is used for a certain action, custom element or sub-container)
93 */
95 ContainerNode(QWidget *_container, const QString &_tagName, const QString &_name,
96 ContainerNode *_parent = 0L, KisKXMLGUIClient *_client = 0L,
97 KisKXMLGUIBuilder *_builder = 0L, QAction *containerAction = 0,
98 const QString &_mergingName = QString(),
99 const QString &groupName = QString(),
100 const QStringList &customTags = QStringList(),
101 const QStringList &containerTags = QStringList());
103
109 QWidget *container;
111
112 QString tagName;
113 QString name;
114
115 QString groupName; //is empty if the container is in no group
116
119
120 int index;
122
123 QString mergingName;
124
126 {
127 qDeleteAll(children);
128 children.clear();
129 }
130 void removeChild(ContainerNode *child);
131 // Removes the child referred to by childIterator.next()
132 void removeChild(QMutableListIterator<ContainerNode *> &childIterator);
133
134 MergingIndexList::Iterator findIndex(const QString &name);
136 ContainerNode *findContainer(const QString &_name, bool tag);
137 ContainerNode *findContainer(const QString &name, const QString &tagName,
138 const QList<QWidget *> *excludeList,
139 KisKXMLGUIClient *currClient);
140
142 const QString &groupName,
143 const MergingIndexList::Iterator &mergingIdx);
144
145 void plugActionList(BuildState &state);
146 void plugActionList(BuildState &state, const MergingIndexList::Iterator &mergingIdxIt);
147
148 void unplugActionList(BuildState &state);
149 void unplugActionList(BuildState &state, const MergingIndexList::Iterator &mergingIdxIt);
150
151 void adjustMergingIndices(int offset, const MergingIndexList::Iterator &it);
152
153 bool destruct(QDomElement element, BuildState &state);
154 void destructChildren(const QDomElement &element, BuildState &state);
155 static QDomElement findElementForChild(const QDomElement &baseElement,
156 ContainerNode *childNode);
157 void unplugActions(BuildState &state);
159
160 void reset();
161
162 int calcMergingIndex(const QString &mergingName,
163 MergingIndexList::Iterator &it,
164 BuildState &state,
165 bool ignoreDefaultMergingIndex);
166};
167
169
171{
172public:
173 BuildHelper(BuildState &state,
174 ContainerNode *node);
175
176 void build(const QDomElement &element);
177
178private:
179 void processElement(const QDomElement &element);
180
181 void processActionOrCustomElement(const QDomElement &e, bool isActionTag);
182 bool processActionElement(const QDomElement &e, int idx);
183 bool processCustomElement(const QDomElement &e, int idx);
184
185 void processStateElement(const QDomElement &element);
186
187 void processMergeElement(const QString &tag, const QString &name, const QDomElement &e);
188
189 void processContainerElement(const QDomElement &e, const QString &tag,
190 const QString &name);
191
192 QWidget *createContainer(QWidget *parent, int index, const QDomElement &element,
193 QAction *&containerAction, KisKXMLGUIBuilder **builder);
194
195 int calcMergingIndex(const QDomElement &element, MergingIndexList::Iterator &it, QString &group);
196
199
201
203
205
207
209};
210
234
236
237}
238
239#endif
240
QList< QString > QStringList
ActionList & operator=(const QList< QAction * > &rhs)
void unplug(QWidget *container) const
ActionList(const QList< QAction * > &rhs)
void plug(QWidget *container, int index) const
void processActionOrCustomElement(const QDomElement &e, bool isActionTag)
void processStateElement(const QDomElement &element)
bool processActionElement(const QDomElement &e, int idx)
BuildHelper(BuildState &state, ContainerNode *node)
QWidget * createContainer(QWidget *parent, int index, const QDomElement &element, QAction *&containerAction, KisKXMLGUIBuilder **builder)
bool processCustomElement(const QDomElement &e, int idx)
void processElement(const QDomElement &element)
void build(const QDomElement &element)
QList< QWidget * > containerList
void processMergeElement(const QString &tag, const QString &name, const QDomElement &e)
int calcMergingIndex(const QDomElement &element, MergingIndexList::Iterator &it, QString &group)
ContainerClient * containerClient
void processContainerElement(const QDomElement &e, const QString &tag, const QString &name)
QMap< QString, ActionList > ActionListMap
QList< ContainerNode * > ContainerNodeList
QList< ContainerClient * > ContainerClientList
QStack< BuildState > BuildStateStack
QList< MergingIndex > MergingIndexList
MergingIndexList::Iterator currentDefaultMergingIt
QStringList clientBuilderContainerTags
QStringList clientBuilderCustomTags
KisKXMLGUIBuilder * builder
KisKXMLGUIClient * guiClient
KisKXMLGUIBuilder * clientBuilder
MergingIndexList::Iterator currentClientMergingIt
QList< QAction * > customElements
ContainerNode * findContainerNode(QWidget *container)
void unplugActionList(BuildState &state)
MergingIndexList::Iterator findIndex(const QString &name)
MergingIndexList mergingIndices
void removeChild(ContainerNode *child)
static QDomElement findElementForChild(const QDomElement &baseElement, ContainerNode *childNode)
ContainerClient * findChildContainerClient(KisKXMLGUIClient *currentGUIClient, const QString &groupName, const MergingIndexList::Iterator &mergingIdx)
void unplugActions(BuildState &state)
void plugActionList(BuildState &state)
int calcMergingIndex(const QString &mergingName, MergingIndexList::Iterator &it, BuildState &state, bool ignoreDefaultMergingIndex)
ContainerClientList clients
ContainerNode * findContainer(const QString &_name, bool tag)
QList< ContainerNode * > children
void destructChildren(const QDomElement &element, BuildState &state)
void adjustMergingIndices(int offset, const MergingIndexList::Iterator &it)
bool destruct(QDomElement element, BuildState &state)
void unplugClient(ContainerClient *client)
KisKXMLGUIBuilder * builder
ContainerNode(QWidget *_container, const QString &_tagName, const QString &_name, ContainerNode *_parent=0L, KisKXMLGUIClient *_client=0L, KisKXMLGUIBuilder *_builder=0L, QAction *containerAction=0, const QString &_mergingName=QString(), const QString &groupName=QString(), const QStringList &customTags=QStringList(), const QStringList &containerTags=QStringList())