Krita Source Code Documentation
Loading...
Searching...
No Matches
KisKXMLGUI::BuildHelper Class Reference

#include <kxmlguifactory_p.h>

Public Member Functions

void build (const QDomElement &element)
 
 BuildHelper (BuildState &state, ContainerNode *node)
 

Private Member Functions

int calcMergingIndex (const QDomElement &element, MergingIndexList::Iterator &it, QString &group)
 
QWidget * createContainer (QWidget *parent, int index, const QDomElement &element, QAction *&containerAction, KisKXMLGUIBuilder **builder)
 
bool processActionElement (const QDomElement &e, int idx)
 
void processActionOrCustomElement (const QDomElement &e, bool isActionTag)
 
void processContainerElement (const QDomElement &e, const QString &tag, const QString &name)
 
bool processCustomElement (const QDomElement &e, int idx)
 
void processElement (const QDomElement &element)
 
void processMergeElement (const QString &tag, const QString &name, const QDomElement &e)
 
void processStateElement (const QDomElement &element)
 

Private Attributes

ContainerClientcontainerClient
 
QList< QWidget * > containerList
 
QStringList containerTags
 
QStringList customTags
 
bool ignoreDefaultMergingIndex
 
BuildStatem_state
 
ContainerNodeparentNode
 

Detailed Description

Definition at line 170 of file kxmlguifactory_p.h.

Constructor & Destructor Documentation

◆ BuildHelper()

BuildHelper::BuildHelper ( BuildState & state,
ContainerNode * node )

Definition at line 544 of file kxmlguifactory_p.cpp.

546 parentNode(node)
547{
548 // create a list of supported container and custom tags
551
555 }
556
560 }
561
562 m_state.currentDefaultMergingIt = parentNode->findIndex(QStringLiteral("<default>"));
564 m_state, /*ignoreDefaultMergingIndex*/ false);
565}
ContainerClient * containerClient
MergingIndexList::Iterator currentDefaultMergingIt
QStringList clientBuilderContainerTags
QStringList clientBuilderCustomTags
KisKXMLGUIBuilder * builder
KisKXMLGUIBuilder * clientBuilder
MergingIndexList::Iterator currentClientMergingIt
MergingIndexList::Iterator findIndex(const QString &name)
int calcMergingIndex(const QString &mergingName, MergingIndexList::Iterator &it, BuildState &state, bool ignoreDefaultMergingIndex)
KisKXMLGUIBuilder * builder

References KisKXMLGUI::ContainerNode::builder, KisKXMLGUI::BuildState::builder, KisKXMLGUI::ContainerNode::builderContainerTags, KisKXMLGUI::BuildState::builderContainerTags, KisKXMLGUI::ContainerNode::builderCustomTags, KisKXMLGUI::BuildState::builderCustomTags, KisKXMLGUI::ContainerNode::calcMergingIndex(), KisKXMLGUI::BuildState::clientBuilder, KisKXMLGUI::BuildState::clientBuilderContainerTags, KisKXMLGUI::BuildState::clientBuilderCustomTags, containerTags, KisKXMLGUI::BuildState::currentClientMergingIt, KisKXMLGUI::BuildState::currentDefaultMergingIt, customTags, KisKXMLGUI::ContainerNode::findIndex(), m_state, and parentNode.

Member Function Documentation

◆ build()

void BuildHelper::build ( const QDomElement & element)

Definition at line 567 of file kxmlguifactory_p.cpp.

568{
569 for (QDomNode n = element.firstChild(); !n.isNull(); n = n.nextSibling()) {
570 QDomElement e = n.toElement();
571 if (e.isNull()) {
572 continue;
573 }
575 }
576}
void processElement(const QDomElement &element)

References processElement().

◆ calcMergingIndex()

int BuildHelper::calcMergingIndex ( const QDomElement & element,
MergingIndexList::Iterator & it,
QString & group )
private

Definition at line 521 of file kxmlguifactory_p.cpp.

522{
523 const QLatin1String attrGroup("group");
524
525 bool haveGroup = false;
526 group = element.attribute(attrGroup);
527 if (!group.isEmpty()) {
528 group.prepend(attrGroup);
529 haveGroup = true;
530 }
531
532 int idx;
533 if (haveGroup) {
536 idx = parentNode->index;
537 } else {
539 }
540
541 return idx;
542}
float value(const T *src, size_t ch)
MergingIndexList mergingIndices

References KisKXMLGUI::ContainerNode::calcMergingIndex(), KisKXMLGUI::BuildState::currentClientMergingIt, ignoreDefaultMergingIndex, KisKXMLGUI::ContainerNode::index, m_state, KisKXMLGUI::ContainerNode::mergingIndices, parentNode, and value().

◆ createContainer()

QWidget * BuildHelper::createContainer ( QWidget * parent,
int index,
const QDomElement & element,
QAction *& containerAction,
KisKXMLGUIBuilder ** builder )
private

Definition at line 839 of file kxmlguifactory_p.cpp.

842{
843 QWidget *res = 0L;
844
846 res = m_state.clientBuilder->createContainer(parent, index, element, containerAction);
847
848 if (res) {
849 *builder = m_state.clientBuilder;
850 return res;
851 }
852 }
853
855
857
858 res = m_state.builder->createContainer(parent, index, element, containerAction);
859
860 m_state.builder->setBuilderClient(oldClient);
861
862 if (res) {
863 *builder = m_state.builder;
864 }
865
866 return res;
867}
virtual QWidget * createContainer(QWidget *parent, int index, const QDomElement &element, QAction *&containerAction)
void setBuilderClient(KisKXMLGUIClient *client)
KisKXMLGUIClient * builderClient() const
KisKXMLGUIClient * guiClient

References KisKXMLGUI::BuildState::builder, KisKXMLGUIBuilder::builderClient(), KisKXMLGUI::BuildState::clientBuilder, KisKXMLGUIBuilder::createContainer(), KisKXMLGUI::BuildState::guiClient, m_state, and KisKXMLGUIBuilder::setBuilderClient().

◆ processActionElement()

bool BuildHelper::processActionElement ( const QDomElement & e,
int idx )
private

Definition at line 624 of file kxmlguifactory_p.cpp.

625{
626 assert(m_state.guiClient);
627
628 // look up the action and plug it in
629 QAction *action = m_state.guiClient->action(e);
630
631 //qDebug(260) << "BuildHelper::processActionElement " << e.attribute( "name" ) << " -> " << action << " (in " << m_state.guiClient->actionCollection() << ")";
632 if (!action) {
633 return false;
634 }
635
636 QAction *before = 0L;
637 if (idx >= 0 && idx < parentNode->container->actions().count()) {
638 before = parentNode->container->actions()[idx];
639 }
640
641 parentNode->container->insertAction(before, action);
642
643 // save a reference to the plugged action, in order to properly unplug it afterwards.
644 containerClient->actions.append(action);
645
646 return true;
647}
QAction * action(const char *name) const

References KisKXMLGUIClient::action(), KisKXMLGUI::ContainerClient::actions, KisKXMLGUI::ContainerNode::container, containerClient, KisKXMLGUI::BuildState::guiClient, m_state, and parentNode.

◆ processActionOrCustomElement()

void BuildHelper::processActionOrCustomElement ( const QDomElement & e,
bool isActionTag )
private

Definition at line 597 of file kxmlguifactory_p.cpp.

598{
599 if (!parentNode->container) {
600 return;
601 }
602
603 MergingIndexList::Iterator it(m_state.currentClientMergingIt);
604
605 QString group;
606 int idx = calcMergingIndex(e, it, group);
607
609
610 bool guiElementCreated = false;
611 if (isActionTag) {
612 guiElementCreated = processActionElement(e, idx);
613 } else {
614 guiElementCreated = processCustomElement(e, idx);
615 }
616
617 if (guiElementCreated)
618 // adjust any following merging indices and the current running index for the container
619 {
621 }
622}
bool processActionElement(const QDomElement &e, int idx)
bool processCustomElement(const QDomElement &e, int idx)
int calcMergingIndex(const QDomElement &element, MergingIndexList::Iterator &it, QString &group)
ContainerClient * findChildContainerClient(KisKXMLGUIClient *currentGUIClient, const QString &groupName, const MergingIndexList::Iterator &mergingIdx)
void adjustMergingIndices(int offset, const MergingIndexList::Iterator &it)

References KisKXMLGUI::ContainerNode::adjustMergingIndices(), calcMergingIndex(), KisKXMLGUI::ContainerNode::container, containerClient, KisKXMLGUI::BuildState::currentClientMergingIt, KisKXMLGUI::ContainerNode::findChildContainerClient(), KisKXMLGUI::BuildState::guiClient, m_state, parentNode, processActionElement(), and processCustomElement().

◆ processContainerElement()

void BuildHelper::processContainerElement ( const QDomElement & e,
const QString & tag,
const QString & name )
private

Definition at line 773 of file kxmlguifactory_p.cpp.

775{
776 ContainerNode *containerNode = parentNode->findContainer(name, tag,
779
780 if (!containerNode) {
781 MergingIndexList::Iterator it(m_state.currentClientMergingIt);
782 QString group;
783
784 int idx = calcMergingIndex(e, it, group);
785
786 QAction *containerAction;
787
788 KisKXMLGUIBuilder *builder;
789
790 QWidget *container = createContainer(parentNode->container, idx, e, containerAction, &builder);
791
792 // no container? (probably some <text> tag or so ;-)
793 if (!container) {
794 return;
795 }
796
798
799 assert(!parentNode->findContainerNode(container));
800
801 containerList.append(container);
802
803 QString mergingName;
804 if (it != parentNode->mergingIndices.end()) {
805 mergingName = (*it).mergingName;
806 }
807
810 if (builder != m_state.builder) {
813 }
814
815 containerNode = new ContainerNode(container, tag, name, parentNode,
816 m_state.guiClient, builder, containerAction,
817 mergingName, group, cusTags, conTags);
818 } else {
819 if (tag == QStringLiteral("toolbar")) {
820 KisToolBar *bar = qobject_cast<KisToolBar *>(containerNode->container);
821 if (bar) {
822 if (m_state.guiClient && !m_state.guiClient->xmlFile().isEmpty()) {
824 }
825 } else {
826 qWarning() << "toolbar container is not a KisToolBar";
827 }
828 }
829 }
830
831 BuildHelper(m_state, containerNode).build(e);
832
833 // and re-calculate running values, for better performance
834 m_state.currentDefaultMergingIt = parentNode->findIndex(QStringLiteral("<default>"));
837}
virtual QString xmlFile() const
BuildHelper(BuildState &state, ContainerNode *node)
QWidget * createContainer(QWidget *parent, int index, const QDomElement &element, QAction *&containerAction, KisKXMLGUIBuilder **builder)
QList< QWidget * > containerList
Floatable toolbar with auto resize.
Definition ktoolbar.h:47
void addXMLGUIClient(KisKXMLGUIClient *client)
Definition ktoolbar.cpp:845
ContainerNode * findContainerNode(QWidget *container)
ContainerNode * findContainer(const QString &_name, bool tag)

References KisToolBar::addXMLGUIClient(), KisKXMLGUI::ContainerNode::adjustMergingIndices(), KisKXMLGUI::BuildState::builder, KisKXMLGUI::BuildState::builderContainerTags, KisKXMLGUI::BuildState::builderCustomTags, BuildHelper(), calcMergingIndex(), KisKXMLGUI::ContainerNode::calcMergingIndex(), KisKXMLGUI::BuildState::clientBuilderContainerTags, KisKXMLGUI::BuildState::clientBuilderCustomTags, KisKXMLGUI::ContainerNode::container, containerList, createContainer(), KisKXMLGUI::BuildState::currentClientMergingIt, KisKXMLGUI::BuildState::currentDefaultMergingIt, KisKXMLGUI::ContainerNode::findContainer(), KisKXMLGUI::ContainerNode::findContainerNode(), KisKXMLGUI::ContainerNode::findIndex(), KisKXMLGUI::BuildState::guiClient, ignoreDefaultMergingIndex, m_state, KisKXMLGUI::ContainerNode::mergingIndices, parentNode, and KisKXMLGUIClient::xmlFile().

◆ processCustomElement()

bool BuildHelper::processCustomElement ( const QDomElement & e,
int idx )
private

Definition at line 649 of file kxmlguifactory_p.cpp.

650{
651 assert(parentNode->builder);
652
653 QAction *action = parentNode->builder->createCustomElement(parentNode->container, idx, e);
654 if (!action) {
655 return false;
656 }
657
658 containerClient->customElements.append(action);
659 return true;
660}
virtual QAction * createCustomElement(QWidget *parent, int index, const QDomElement &element)
QList< QAction * > customElements

References KisKXMLGUI::ContainerNode::builder, KisKXMLGUI::ContainerNode::container, containerClient, KisKXMLGUIBuilder::createCustomElement(), KisKXMLGUI::ContainerClient::customElements, and parentNode.

◆ processElement()

void BuildHelper::processElement ( const QDomElement & element)
private

Definition at line 578 of file kxmlguifactory_p.cpp.

579{
580 QString tag(e.tagName().toLower());
581 QString currName(e.attribute(QStringLiteral("name")));
582
583 bool isActionTag = (tag == QStringLiteral("action"));
584
585 if (isActionTag || customTags.indexOf(tag) != -1) {
586 processActionOrCustomElement(e, isActionTag);
587 } else if (containerTags.indexOf(tag) != -1) {
588 processContainerElement(e, tag, currName);
589 } else if (tag == QStringLiteral("merge") || tag == QLatin1String("definegroup")
590 || tag == QStringLiteral("actionlist")) {
591 processMergeElement(tag, currName, e);
592 } else if (tag == QStringLiteral("state")) {
594 }
595}
void processActionOrCustomElement(const QDomElement &e, bool isActionTag)
void processStateElement(const QDomElement &element)
void processMergeElement(const QString &tag, const QString &name, const QDomElement &e)
void processContainerElement(const QDomElement &e, const QString &tag, const QString &name)

References containerTags, customTags, processActionOrCustomElement(), processContainerElement(), processMergeElement(), and processStateElement().

◆ processMergeElement()

void BuildHelper::processMergeElement ( const QString & tag,
const QString & name,
const QDomElement & e )
private

Definition at line 706 of file kxmlguifactory_p.cpp.

707{
708 const QLatin1String tagDefineGroup("definegroup");
709 const QLatin1String tagActionList("actionlist");
710 const QLatin1String defaultMergingName("<default>");
711 const QLatin1String attrGroup("group");
712
713 QString mergingName(name);
714 if (mergingName.isEmpty()) {
715 if (tag == tagDefineGroup) {
716 qCritical() << "cannot define group without name!" << Qt::endl;
717 return;
718 }
719 if (tag == tagActionList) {
720 qCritical() << "cannot define actionlist without name!" << Qt::endl;
721 return;
722 }
723 mergingName = defaultMergingName;
724 }
725
726 if (tag == tagDefineGroup) {
727 mergingName.prepend(attrGroup); //avoid possible name clashes by prepending
728 }
729 // "group" to group definitions
730 else if (tag == tagActionList) {
731 mergingName.prepend(tagActionList);
732 }
733
734 if (parentNode->findIndex(mergingName) != parentNode->mergingIndices.end()) {
735 return; //do not allow the redefinition of merging indices!
736 }
737
738 MergingIndexList::Iterator mIt(parentNode->mergingIndices.end());
739
740 QString group(e.attribute(attrGroup));
741 if (!group.isEmpty()) {
742 group.prepend(attrGroup);
743 }
744
745 // calculate the index of the new merging index. Usually this does not need any calculation,
746 // we just want the last available index (i.e. append) . But in case the <Merge> tag appears
747 // "inside" another <Merge> tag from a previously build client, then we have to use the
748 // "parent's" index. That's why we call calcMergingIndex here.
749 MergingIndex newIdx;
751 newIdx.mergingName = mergingName;
753
754 // if that merging index is "inside" another one, then append it right after the "parent" .
755 if (mIt != parentNode->mergingIndices.end()) {
756 parentNode->mergingIndices.insert(++mIt, newIdx);
757 } else {
758 parentNode->mergingIndices.append(newIdx);
759 }
760
761 if (mergingName == defaultMergingName)
762
763 {
765 }
766
767 // re-calculate the running default and client merging indices.
771}

References KisKXMLGUI::ContainerNode::calcMergingIndex(), KisKXMLGUI::MergingIndex::clientName, KisKXMLGUI::BuildState::clientName, KisKXMLGUI::BuildState::currentClientMergingIt, KisKXMLGUI::BuildState::currentDefaultMergingIt, KisKXMLGUI::ContainerNode::findIndex(), ignoreDefaultMergingIndex, m_state, KisKXMLGUI::ContainerNode::mergingIndices, KisKXMLGUI::MergingIndex::mergingName, parentNode, and KisKXMLGUI::MergingIndex::value.

◆ processStateElement()

void BuildHelper::processStateElement ( const QDomElement & element)
private

Definition at line 662 of file kxmlguifactory_p.cpp.

663{
664 QString stateName = element.attribute(QStringLiteral("name"));
665
666 if (stateName.isNull() || !stateName.length()) {
667 return;
668 }
669
670 for (QDomNode n = element.firstChild(); !n.isNull(); n = n.nextSibling()) {
671 QDomElement e = n.toElement();
672 if (e.isNull()) {
673 continue;
674 }
675
676 QString tagName = e.tagName().toLower();
677
678 if (tagName != QStringLiteral("enable") && tagName != QLatin1String("disable")) {
679 continue;
680 }
681
682 bool processingActionsToEnable = (tagName == QStringLiteral("enable"));
683
684 // process action names
685 for (QDomNode n2 = n.firstChild(); !n2.isNull(); n2 = n2.nextSibling()) {
686 QDomElement actionEl = n2.toElement();
687 if (actionEl.tagName().toLower() != QStringLiteral("action")) {
688 continue;
689 }
690
691 QString actionName = actionEl.attribute(QStringLiteral("name"));
692 if (actionName.isEmpty()) {
693 return;
694 }
695
696 if (processingActionsToEnable) {
697 m_state.guiClient->addStateActionEnabled(stateName, actionName);
698 } else {
699 m_state.guiClient->addStateActionDisabled(stateName, actionName);
700 }
701
702 }
703 }
704}
void addStateActionEnabled(const QString &state, const QString &action)
void addStateActionDisabled(const QString &state, const QString &action)

References KisKXMLGUIClient::addStateActionDisabled(), KisKXMLGUIClient::addStateActionEnabled(), KisKXMLGUI::BuildState::guiClient, and m_state.

Member Data Documentation

◆ containerClient

ContainerClient* KisKXMLGUI::BuildHelper::containerClient
private

Definition at line 202 of file kxmlguifactory_p.h.

◆ containerList

QList<QWidget *> KisKXMLGUI::BuildHelper::containerList
private

Definition at line 200 of file kxmlguifactory_p.h.

◆ containerTags

QStringList KisKXMLGUI::BuildHelper::containerTags
private

Definition at line 198 of file kxmlguifactory_p.h.

◆ customTags

QStringList KisKXMLGUI::BuildHelper::customTags
private

Definition at line 197 of file kxmlguifactory_p.h.

◆ ignoreDefaultMergingIndex

bool KisKXMLGUI::BuildHelper::ignoreDefaultMergingIndex
private

Definition at line 204 of file kxmlguifactory_p.h.

◆ m_state

BuildState& KisKXMLGUI::BuildHelper::m_state
private

Definition at line 206 of file kxmlguifactory_p.h.

◆ parentNode

ContainerNode* KisKXMLGUI::BuildHelper::parentNode
private

Definition at line 208 of file kxmlguifactory_p.h.


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