Krita Source Code Documentation
Loading...
Searching...
No Matches
KisKXMLGUI::ContainerNode Struct Reference

#include <kxmlguifactory_p.h>

Public Member Functions

void adjustMergingIndices (int offset, const MergingIndexList::Iterator &it)
 
int calcMergingIndex (const QString &mergingName, MergingIndexList::Iterator &it, BuildState &state, bool ignoreDefaultMergingIndex)
 
void clearChildren ()
 
 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())
 
bool destruct (QDomElement element, BuildState &state)
 
void destructChildren (const QDomElement &element, BuildState &state)
 
ContainerClientfindChildContainerClient (KisKXMLGUIClient *currentGUIClient, const QString &groupName, const MergingIndexList::Iterator &mergingIdx)
 
ContainerNodefindContainer (const QString &_name, bool tag)
 
ContainerNodefindContainer (const QString &name, const QString &tagName, const QList< QWidget * > *excludeList, KisKXMLGUIClient *currClient)
 
ContainerNodefindContainerNode (QWidget *container)
 
MergingIndexList::Iterator findIndex (const QString &name)
 
void plugActionList (BuildState &state)
 
void plugActionList (BuildState &state, const MergingIndexList::Iterator &mergingIdxIt)
 
void removeChild (ContainerNode *child)
 
void removeChild (QMutableListIterator< ContainerNode * > &childIterator)
 
void reset ()
 
void unplugActionList (BuildState &state)
 
void unplugActionList (BuildState &state, const MergingIndexList::Iterator &mergingIdxIt)
 
void unplugActions (BuildState &state)
 
void unplugClient (ContainerClient *client)
 
 ~ContainerNode ()
 

Static Public Member Functions

static QDomElement findElementForChild (const QDomElement &baseElement, ContainerNode *childNode)
 

Public Attributes

KisKXMLGUIBuilderbuilder
 
QStringList builderContainerTags
 
QStringList builderCustomTags
 
QList< ContainerNode * > children
 
KisKXMLGUIClientclient
 
ContainerClientList clients
 
QWidget * container
 
QAction * containerAction
 
QString groupName
 
int index
 
MergingIndexList mergingIndices
 
QString mergingName
 
QString name
 
ContainerNodeparent
 
QString tagName
 

Detailed Description

Definition at line 94 of file kxmlguifactory_p.h.

Constructor & Destructor Documentation

◆ ContainerNode()

ContainerNode::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() )

Definition at line 45 of file kxmlguifactory_p.cpp.

51 : parent(_parent), client(_client), builder(_builder),
52 builderCustomTags(customTags), builderContainerTags(containerTags),
53 container(_container), containerAction(_containerAction), tagName(_tagName), name(_name),
54 groupName(_groupName), index(0), mergingName(_mergingName)
55{
56 if (parent) {
57 parent->children.append(this);
58 }
59}
QList< ContainerNode * > children
KisKXMLGUIBuilder * builder

References children, and parent.

◆ ~ContainerNode()

ContainerNode::~ContainerNode ( )

Definition at line 61 of file kxmlguifactory_p.cpp.

62{
63 qDeleteAll(children);
64 qDeleteAll(clients);
65}
ContainerClientList clients

References children, and clients.

Member Function Documentation

◆ adjustMergingIndices()

void ContainerNode::adjustMergingIndices ( int offset,
const MergingIndexList::Iterator & it )

Definition at line 312 of file kxmlguifactory_p.cpp.

314{
315 MergingIndexList::Iterator mergingIt = it;
316 MergingIndexList::Iterator mergingEnd = mergingIndices.end();
317
318 for (; mergingIt != mergingEnd; ++mergingIt) {
319 (*mergingIt).value += offset;
320 }
321
322 index += offset;
323}
MergingIndexList mergingIndices

References index, and mergingIndices.

◆ calcMergingIndex()

int ContainerNode::calcMergingIndex ( const QString & mergingName,
MergingIndexList::Iterator & it,
BuildState & state,
bool ignoreDefaultMergingIndex )

Definition at line 491 of file kxmlguifactory_p.cpp.

495{
496 MergingIndexList::Iterator mergingIt;
497
498 if (mergingName.isEmpty()) {
499 mergingIt = findIndex(state.clientName);
500 } else {
501 mergingIt = findIndex(mergingName);
502 }
503
504 MergingIndexList::Iterator mergingEnd = mergingIndices.end();
505 it = mergingEnd;
506
507 if ((mergingIt == mergingEnd && state.currentDefaultMergingIt == mergingEnd) ||
508 ignoreDefaultMergingIndex) {
509 return index;
510 }
511
512 if (mergingIt != mergingEnd) {
513 it = mergingIt;
514 } else {
515 it = state.currentDefaultMergingIt;
516 }
517
518 return (*it).value;
519}
MergingIndexList::Iterator currentDefaultMergingIt
MergingIndexList::Iterator findIndex(const QString &name)

References KisKXMLGUI::BuildState::clientName, KisKXMLGUI::BuildState::currentDefaultMergingIt, findIndex(), index, mergingIndices, and mergingName.

◆ clearChildren()

void KisKXMLGUI::ContainerNode::clearChildren ( )
inline

Definition at line 125 of file kxmlguifactory_p.h.

126 {
127 qDeleteAll(children);
128 children.clear();
129 }

References children.

◆ destruct()

bool ContainerNode::destruct ( QDomElement element,
BuildState & state )

Definition at line 325 of file kxmlguifactory_p.cpp.

326{
327 destructChildren(element, state);
328
329 unplugActions(state);
330
331 // remove all merging indices the client defined
332 QMutableListIterator<MergingIndex> cmIt = mergingIndices;
333 while (cmIt.hasNext())
334 if (cmIt.next().clientName == state.clientName) {
335 cmIt.remove();
336 }
337
338 // ### check for merging index count, too?
339 if (clients.count() == 0 && children.count() == 0 && container &&
340 client == state.guiClient) {
341 QWidget *parentContainer = 0L;
342
343 if (parent && parent->container) {
344 parentContainer = parent->container;
345 }
346
347 assert(builder);
348
349 builder->removeContainer(container, parentContainer, element, containerAction);
350
351 client = 0L;
352
353 return true;
354 }
355
356 if (client == state.guiClient) {
357 client = 0L;
358 }
359
360 return false;
361
362}
virtual void removeContainer(QWidget *container, QWidget *parent, QDomElement &element, QAction *containerAction)
KisKXMLGUIClient * guiClient
void unplugActions(BuildState &state)
void destructChildren(const QDomElement &element, BuildState &state)

References builder, children, client, KisKXMLGUI::BuildState::clientName, clients, container, containerAction, destructChildren(), KisKXMLGUI::BuildState::guiClient, mergingIndices, parent, KisKXMLGUIBuilder::removeContainer(), and unplugActions().

◆ destructChildren()

void ContainerNode::destructChildren ( const QDomElement & element,
BuildState & state )

Definition at line 364 of file kxmlguifactory_p.cpp.

365{
366 QMutableListIterator<ContainerNode *> childIt = children;
367 while (childIt.hasNext()) {
368 ContainerNode *childNode = childIt.peekNext();
369
370 QDomElement childElement = findElementForChild(element, childNode);
371
372 // destruct returns true in case the container really got deleted
373 if (childNode->destruct(childElement, state)) {
374 removeChild(childIt);
375 } else {
376 childIt.next();
377 }
378 }
379}
void removeChild(ContainerNode *child)
static QDomElement findElementForChild(const QDomElement &baseElement, ContainerNode *childNode)
bool destruct(QDomElement element, BuildState &state)

References children, destruct(), findElementForChild(), and removeChild().

◆ findChildContainerClient()

ContainerClient * ContainerNode::findChildContainerClient ( KisKXMLGUIClient * currentGUIClient,
const QString & groupName,
const MergingIndexList::Iterator & mergingIdx )

Definition at line 185 of file kxmlguifactory_p.cpp.

188{
189 if (!clients.isEmpty()) {
190 Q_FOREACH (ContainerClient *client, clients)
191 if (client->client == currentGUIClient) {
192 if (groupName.isEmpty()) {
193 return client;
194 }
195
196 if (groupName == client->groupName) {
197 return client;
198 }
199 }
200 }
201
203 client->client = currentGUIClient;
204 client->groupName = groupName;
205
206 if (mergingIdx != mergingIndices.end()) {
207 client->mergingName = (*mergingIdx).mergingName;
208 }
209
210 clients.append(client);
211
212 return client;
213}

References client, clients, groupName, and mergingIndices.

◆ findContainer() [1/2]

ContainerNode * ContainerNode::findContainer ( const QString & _name,
bool tag )

Definition at line 117 of file kxmlguifactory_p.cpp.

118{
119 if ((tag && tagName == _name) ||
120 (!tag && name == _name)) {
121 return this;
122 }
123
124 Q_FOREACH (ContainerNode *child, children) {
125 ContainerNode *res = child->findContainer(_name, tag);
126 if (res) {
127 return res;
128 }
129 }
130
131 return 0;
132}
ContainerNode * findContainer(const QString &_name, bool tag)

References children, findContainer(), name, and tagName.

◆ findContainer() [2/2]

ContainerNode * ContainerNode::findContainer ( const QString & name,
const QString & tagName,
const QList< QWidget * > * excludeList,
KisKXMLGUIClient * currClient )

Definition at line 139 of file kxmlguifactory_p.cpp.

142{
143 ContainerNode *res = 0L;
144 ContainerNodeList::ConstIterator nIt = children.constBegin();
145
146 if (!name.isEmpty()) {
147 for (; nIt != children.constEnd(); ++nIt)
148 if ((*nIt)->name == name &&
149 !excludeList->contains((*nIt)->container)) {
150 res = *nIt;
151 break;
152 }
153
154 return res;
155 }
156
157 if (!tagName.isEmpty())
158 for (; nIt != children.constEnd(); ++nIt) {
159 if ((*nIt)->tagName == tagName &&
160 !excludeList->contains((*nIt)->container)
161 /*
162 * It is a bad idea to also compare the client, because
163 * we don't want to do so in situations like these:
164 *
165 * <MenuBar>
166 * <Menu>
167 * ...
168 *
169 * other client:
170 * <MenuBar>
171 * <Menu>
172 * ...
173 *
174 && (*nIt)->client == currClient )
175 */
176 ) {
177 res = *nIt;
178 break;
179 }
180 }
181
182 return res;
183}

References children, name, and tagName.

◆ findContainerNode()

ContainerNode * ContainerNode::findContainerNode ( QWidget * container)

Definition at line 102 of file kxmlguifactory_p.cpp.

103{
104 Q_FOREACH (ContainerNode *child, children)
105 if (child->container == container) {
106 return child;
107 }
108
109 return 0L;
110}

References children, and container.

◆ findElementForChild()

QDomElement ContainerNode::findElementForChild ( const QDomElement & baseElement,
ContainerNode * childNode )
static

Definition at line 381 of file kxmlguifactory_p.cpp.

383{
384 // ### slow
385 for (QDomNode n = baseElement.firstChild(); !n.isNull();
386 n = n.nextSibling()) {
387 QDomElement e = n.toElement();
388 if (e.tagName().toLower() == childNode->tagName &&
389 e.attribute(QStringLiteral("name")) == childNode->name) {
390 return e;
391 }
392 }
393
394 return QDomElement();
395}

References name, and tagName.

◆ findIndex()

MergingIndexList::Iterator ContainerNode::findIndex ( const QString & name)

Definition at line 87 of file kxmlguifactory_p.cpp.

88{
89 MergingIndexList::Iterator it(mergingIndices.begin());
90 MergingIndexList::Iterator end(mergingIndices.end());
91 for (; it != end; ++it)
92 if ((*it).mergingName == name) {
93 return it;
94 }
95 return it;
96}

References mergingIndices, and name.

◆ plugActionList() [1/2]

void ContainerNode::plugActionList ( BuildState & state)

Definition at line 215 of file kxmlguifactory_p.cpp.

216{
217 MergingIndexList::Iterator mIt(mergingIndices.begin());
218 MergingIndexList::Iterator mEnd(mergingIndices.end());
219 for (; mIt != mEnd; ++mIt) {
220 plugActionList(state, mIt);
221 }
222
223 Q_FOREACH (ContainerNode *child, children) {
224 child->plugActionList(state);
225 }
226}
void plugActionList(BuildState &state)

References children, mergingIndices, and plugActionList().

◆ plugActionList() [2/2]

void ContainerNode::plugActionList ( BuildState & state,
const MergingIndexList::Iterator & mergingIdxIt )

Definition at line 228 of file kxmlguifactory_p.cpp.

229{
230 static const QString &tagActionList = QString::fromLatin1("actionlist");
231
232 MergingIndex mergingIdx = *mergingIdxIt;
233
234 QString k(mergingIdx.mergingName);
235
236 if (k.indexOf(tagActionList) == -1) {
237 return;
238 }
239
240 k = k.mid(tagActionList.length());
241
242 if (mergingIdx.clientName != state.clientName) {
243 return;
244 }
245
246 if (k != state.actionListName) {
247 return;
248 }
249
251 QString(),
252 mergingIndices.end());
253
254 client->actionLists.insert(k, state.actionList);
255
256 state.actionList.plug(container, mergingIdx.value);
257
258 adjustMergingIndices(state.actionList.count(), mergingIdxIt);
259}
void plug(QWidget *container, int index) const
ContainerClient * findChildContainerClient(KisKXMLGUIClient *currentGUIClient, const QString &groupName, const MergingIndexList::Iterator &mergingIdx)
void adjustMergingIndices(int offset, const MergingIndexList::Iterator &it)

References KisKXMLGUI::BuildState::actionList, KisKXMLGUI::BuildState::actionListName, adjustMergingIndices(), client, KisKXMLGUI::MergingIndex::clientName, KisKXMLGUI::BuildState::clientName, container, findChildContainerClient(), KisKXMLGUI::BuildState::guiClient, mergingIndices, KisKXMLGUI::MergingIndex::mergingName, KisKXMLGUI::ActionList::plug(), and KisKXMLGUI::MergingIndex::value.

◆ removeChild() [1/2]

void ContainerNode::removeChild ( ContainerNode * child)

Definition at line 67 of file kxmlguifactory_p.cpp.

68{
69 MergingIndexList::Iterator mergingIt = findIndex(child->mergingName);
70 adjustMergingIndices(-1, mergingIt);
71 children.removeAll(child);
72 delete child;
73}

References adjustMergingIndices(), children, findIndex(), and mergingName.

◆ removeChild() [2/2]

void ContainerNode::removeChild ( QMutableListIterator< ContainerNode * > & childIterator)

Definition at line 75 of file kxmlguifactory_p.cpp.

76{
77 MergingIndexList::Iterator mergingIt = findIndex(childIterator.peekNext()->mergingName);
78 adjustMergingIndices(-1, mergingIt);
79 delete childIterator.next();
80 childIterator.remove();
81}

References adjustMergingIndices(), and findIndex().

◆ reset()

void ContainerNode::reset ( )

Definition at line 480 of file kxmlguifactory_p.cpp.

481{
482 Q_FOREACH (ContainerNode *child, children) {
483 child->reset();
484 }
485
486 if (client) {
487 client->setFactory(0L);
488 }
489}
void setFactory(KisKXMLGUIFactory *factory)

References children, client, reset(), and KisKXMLGUIClient::setFactory().

◆ unplugActionList() [1/2]

void ContainerNode::unplugActionList ( BuildState & state)

Definition at line 261 of file kxmlguifactory_p.cpp.

262{
263 MergingIndexList::Iterator mIt(mergingIndices.begin());
264 MergingIndexList::Iterator mEnd(mergingIndices.end());
265 for (; mIt != mEnd; ++mIt) {
266 unplugActionList(state, mIt);
267 }
268
269 Q_FOREACH (ContainerNode *child, children) {
270 child->unplugActionList(state);
271 }
272}
void unplugActionList(BuildState &state)

References children, mergingIndices, and unplugActionList().

◆ unplugActionList() [2/2]

void ContainerNode::unplugActionList ( BuildState & state,
const MergingIndexList::Iterator & mergingIdxIt )

Definition at line 274 of file kxmlguifactory_p.cpp.

275{
276 static const QString &tagActionList = QString::fromLatin1("actionlist");
277
278 MergingIndex mergingIdx = *mergingIdxIt;
279
280 QString k = mergingIdx.mergingName;
281
282 if (k.indexOf(tagActionList) == -1) {
283 return;
284 }
285
286 k = k.mid(tagActionList.length());
287
288 if (mergingIdx.clientName != state.clientName) {
289 return;
290 }
291
292 if (k != state.actionListName) {
293 return;
294 }
295
297 QString(),
298 mergingIndices.end());
299
300 ActionListMap::Iterator lIt(client->actionLists.find(k));
301 if (lIt == client->actionLists.end()) {
302 return;
303 }
304
305 lIt.value().unplug(container);
306
307 adjustMergingIndices(-int(lIt.value().count()), mergingIdxIt);
308
309 client->actionLists.erase(lIt);
310}

References KisKXMLGUI::BuildState::actionListName, adjustMergingIndices(), client, KisKXMLGUI::MergingIndex::clientName, KisKXMLGUI::BuildState::clientName, container, findChildContainerClient(), KisKXMLGUI::BuildState::guiClient, mergingIndices, and KisKXMLGUI::MergingIndex::mergingName.

◆ unplugActions()

void ContainerNode::unplugActions ( BuildState & state)

Definition at line 397 of file kxmlguifactory_p.cpp.

398{
399 if (!container) {
400 return;
401 }
402
403 QMutableListIterator<ContainerClient *> clientIt(clients);
404
405 /*
406 Disabled because it means in KisToolBar::saveState isHidden is always true then,
407 which is clearly wrong.
408
409 if ( clients.count() == 1 && clientIt.current()->client == client &&
410 client == state.guiClient )
411 container->hide(); // this container is going to die, that's for sure.
412 // in this case let's just hide it, which makes the
413 // destruction faster
414 */
415
416 while (clientIt.hasNext())
417 //only unplug the actions of the client we want to remove, as the container might be owned
418 //by a different client
419 if (clientIt.peekNext()->client == state.guiClient) {
420 unplugClient(clientIt.peekNext());
421 delete clientIt.next();
422 clientIt.remove();
423 } else {
424 clientIt.next();
425 }
426}
void unplugClient(ContainerClient *client)

References clients, container, KisKXMLGUI::BuildState::guiClient, and unplugClient().

◆ unplugClient()

void ContainerNode::unplugClient ( ContainerClient * client)

Definition at line 428 of file kxmlguifactory_p.cpp.

429{
430 assert(builder);
431
432 // now quickly remove all custom elements (i.e. separators) and unplug all actions
433
434 QList<QAction *>::ConstIterator custIt = client->customElements.constBegin();
435 QList<QAction *>::ConstIterator custEnd = client->customElements.constEnd();
436 for (; custIt != custEnd; ++custIt) {
438 }
439
440 KisToolBar *bar = qobject_cast<KisToolBar *>(container);
441 if (bar) {
442 bar->removeXMLGUIClient(client->client);
443 }
444
445 client->actions.unplug(container);
446
447 // now adjust all merging indices
448
449 MergingIndexList::Iterator mergingIt = findIndex(client->mergingName);
450
451 adjustMergingIndices(- int(client->actions.count()
452 + client->customElements.count()),
453 mergingIt);
454
455 // unplug all actionlists
456
457 ActionListMap::ConstIterator alIt = client->actionLists.constBegin();
458 ActionListMap::ConstIterator alEnd = client->actionLists.constEnd();
459 for (; alIt != alEnd; ++alIt) {
460 alIt.value().unplug(container);
461
462 // construct the merging index key (i.e. like named merging) , find the
463 // corresponding merging index and adjust all indices
464 QString mergingKey = alIt.key();
465 mergingKey.prepend(QStringLiteral("actionlist"));
466
467 MergingIndexList::Iterator mIt = findIndex(mergingKey);
468 if (mIt == mergingIndices.end()) {
469 continue;
470 }
471
472 adjustMergingIndices(-int(alIt.value().count()), mIt);
473
474 // remove the actionlists' merging index
475 // ### still needed? we clean up below anyway?
476 mergingIndices.erase(mIt);
477 }
478}
virtual void removeCustomElement(QWidget *parent, QAction *action)
Floatable toolbar with auto resize.
Definition ktoolbar.h:47
void removeXMLGUIClient(KisKXMLGUIClient *client)
Definition ktoolbar.cpp:850

References adjustMergingIndices(), builder, client, container, findIndex(), mergingIndices, KisKXMLGUIBuilder::removeCustomElement(), and KisToolBar::removeXMLGUIClient().

Member Data Documentation

◆ builder

KisKXMLGUIBuilder* KisKXMLGUI::ContainerNode::builder

Definition at line 106 of file kxmlguifactory_p.h.

◆ builderContainerTags

QStringList KisKXMLGUI::ContainerNode::builderContainerTags

Definition at line 108 of file kxmlguifactory_p.h.

◆ builderCustomTags

QStringList KisKXMLGUI::ContainerNode::builderCustomTags

Definition at line 107 of file kxmlguifactory_p.h.

◆ children

QList<ContainerNode *> KisKXMLGUI::ContainerNode::children

Definition at line 118 of file kxmlguifactory_p.h.

◆ client

KisKXMLGUIClient* KisKXMLGUI::ContainerNode::client

Definition at line 105 of file kxmlguifactory_p.h.

◆ clients

ContainerClientList KisKXMLGUI::ContainerNode::clients

Definition at line 117 of file kxmlguifactory_p.h.

◆ container

QWidget* KisKXMLGUI::ContainerNode::container

Definition at line 109 of file kxmlguifactory_p.h.

◆ containerAction

QAction* KisKXMLGUI::ContainerNode::containerAction

Definition at line 110 of file kxmlguifactory_p.h.

◆ groupName

QString KisKXMLGUI::ContainerNode::groupName

Definition at line 115 of file kxmlguifactory_p.h.

◆ index

int KisKXMLGUI::ContainerNode::index

Definition at line 120 of file kxmlguifactory_p.h.

◆ mergingIndices

MergingIndexList KisKXMLGUI::ContainerNode::mergingIndices

Definition at line 121 of file kxmlguifactory_p.h.

◆ mergingName

QString KisKXMLGUI::ContainerNode::mergingName

Definition at line 123 of file kxmlguifactory_p.h.

◆ name

QString KisKXMLGUI::ContainerNode::name

Definition at line 113 of file kxmlguifactory_p.h.

◆ parent

ContainerNode* KisKXMLGUI::ContainerNode::parent

Definition at line 104 of file kxmlguifactory_p.h.

◆ tagName

QString KisKXMLGUI::ContainerNode::tagName

Definition at line 112 of file kxmlguifactory_p.h.


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