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

#include <kxmlguiclient.h>

+ Inheritance diagram for KisKXMLGUIClient:

Classes

struct  StateChange
 

Public Types

enum  ReverseStateChange { StateNoReverse , StateReverse }
 

Public Member Functions

QAction * action (const char *name) const
 
virtual QAction * action (const QDomElement &element) const
 
virtual KisKActionCollectionactionCollection () const
 
void addStateActionDisabled (const QString &state, const QString &action)
 
void addStateActionEnabled (const QString &state, const QString &action)
 
void beginXMLPlug (QWidget *)
 
QList< KisKXMLGUIClient * > childClients ()
 
KisKXMLGUIBuilderclientBuilder () const
 
virtual QString componentName () const
 
virtual QDomDocument domDocument () const
 
void endXMLPlug ()
 
KisKXMLGUIFactoryfactory () const
 
StateChange getActionsToChangeForState (const QString &state)
 
void insertChildClient (KisKXMLGUIClient *child)
 
 KisKXMLGUIClient ()
 
 KisKXMLGUIClient (KisKXMLGUIClient *parent)
 
virtual QString localXMLFile () const
 
KisKXMLGUIClientparentClient () const
 
void plugActionList (const QString &name, const QList< QAction * > &actionList)
 
void prepareXMLUnplug (QWidget *)
 
void reloadXML ()
 
void removeChildClient (KisKXMLGUIClient *child)
 
void replaceXMLFile (const QString &xmlfile, const QString &localxmlfile, bool merge=false)
 
void setClientBuilder (KisKXMLGUIBuilder *builder)
 
void setFactory (KisKXMLGUIFactory *factory)
 
void setXMLGUIBuildDocument (const QDomDocument &doc)
 
void unplugActionList (const QString &name)
 
virtual QString xmlFile () const
 
QDomDocument xmlguiBuildDocument () const
 
virtual ~KisKXMLGUIClient ()
 

Static Public Member Functions

static QString findMostRecentXMLFile (const QStringList &files, QString &doc)
 

Protected Member Functions

void loadStandardsXmlFile ()
 
virtual void setComponentName (const QString &componentName, const QString &componentDisplayName)
 
void setDOMDocument (const QDomDocument &document, bool merge=false)
 
void setLocalXMLFile (const QString &file)
 
void setXML (const QString &document, bool merge=false)
 
void setXMLFile (const QString &file, bool merge=false, bool setXMLDoc=true)
 
virtual void stateChanged (const QString &newstate, ReverseStateChange reverse=StateNoReverse)
 
virtual void virtual_hook (int id, void *data)
 

Static Protected Member Functions

static QString standardsXmlFileLocation ()
 

Private Attributes

KisKXMLGUIClientPrivate *const d
 

Friends

class KDEPrivate::KisKEditToolBarWidget
 

Detailed Description

A KisKXMLGUIClient can be used with KisKXMLGUIFactory to create a GUI from actions and an XML document, and can be dynamically merged with other KisKXMLGUIClients.

Definition at line 36 of file kxmlguiclient.h.

Member Enumeration Documentation

◆ ReverseStateChange

Enumerator
StateNoReverse 
StateReverse 

Definition at line 252 of file kxmlguiclient.h.

Constructor & Destructor Documentation

◆ KisKXMLGUIClient() [1/2]

KisKXMLGUIClient::KisKXMLGUIClient ( )

Constructs a KisKXMLGUIClient which can be used with a KisKXMLGUIFactory to create a GUI from actions and an XML document, and which can be dynamically merged with other KisKXMLGUIClients.

Definition at line 75 of file kxmlguiclient.cpp.

77{
78}
KisKXMLGUIClientPrivate *const d

◆ KisKXMLGUIClient() [2/2]

KisKXMLGUIClient::KisKXMLGUIClient ( KisKXMLGUIClient * parent)
explicit

Constructs a KisKXMLGUIClient which can be used with a KisKXMLGUIFactory to create a GUI from actions and an XML document, and which can be dynamically merged with other KisKXMLGUIClients.

This constructor takes an additional parent argument, which makes the client a child client of the parent.

Child clients are automatically added to the GUI if the parent is added.

Definition at line 80 of file kxmlguiclient.cpp.

82{
83 parent->insertChildClient(this);
84}
ChildIterator< value_type, is_const > parent(const ChildIterator< value_type, is_const > &it)
Definition KisForest.h:327

◆ ~KisKXMLGUIClient()

KisKXMLGUIClient::~KisKXMLGUIClient ( )
virtual

Destructs the KisKXMLGUIClient.

If the client was in a factory, the factory is NOT informed about the client being removed. This is a feature, it makes window destruction fast (the xmlgui is not updated for every client being deleted), but if you want to simply remove one client and to keep using the window, make sure to call factory->removeClient(client) before deleting the client.

Definition at line 86 of file kxmlguiclient.cpp.

87{
88 if (d->m_parent) {
90 }
91
92 if (d->m_factory) {
93 qWarning() << this << "deleted without having been removed from the factory first. This will leak standalone popupmenus and could lead to crashes.";
94 d->m_factory->forgetClient(this);
95 }
96
97 Q_FOREACH (KisKXMLGUIClient *client, d->m_children) {
98 if (d->m_factory) {
99 d->m_factory->forgetClient(client);
100 }
101 assert(client->d->m_parent == this);
102 client->d->m_parent = 0;
103 }
104
105 delete d->m_actionCollection;
106 delete d;
107}
QList< KisKXMLGUIClient * > m_children
QPointer< KisKXMLGUIFactory > m_factory
KisKActionCollection * m_actionCollection
KisKXMLGUIClient * m_parent
void removeChildClient(KisKXMLGUIClient *child)

References d, KisKXMLGUIClientPrivate::m_actionCollection, KisKXMLGUIClientPrivate::m_children, KisKXMLGUIClientPrivate::m_factory, KisKXMLGUIClientPrivate::m_parent, and removeChildClient().

Member Function Documentation

◆ action() [1/2]

QAction * KisKXMLGUIClient::action ( const char * name) const

Retrieves an action of the client by name. If not found, it looks in its child clients. This method is provided for convenience, as it uses actionCollection() to get the action object.

Definition at line 109 of file kxmlguiclient.cpp.

110{
111 QAction *act = actionCollection()->action(QLatin1String(name));
112 if (!act) {
113 Q_FOREACH (KisKXMLGUIClient *client, d->m_children) {
114 act = client->actionCollection()->action(QLatin1String(name));
115 if (act) {
116 break;
117 }
118 }
119 }
120 return act;
121}
QAction * action(int index) const
virtual KisKActionCollection * actionCollection() const

References KisKActionCollection::action(), actionCollection(), d, and KisKXMLGUIClientPrivate::m_children.

◆ action() [2/2]

QAction * KisKXMLGUIClient::action ( const QDomElement & element) const
virtual

Retrieves an action for a given QDomElement. The default implementation uses the "name" attribute to query the action object via the other action() method.

Definition at line 132 of file kxmlguiclient.cpp.

133{
134 return actionCollection()->action(element.attribute(QStringLiteral("name")));
135}

References KisKActionCollection::action(), and actionCollection().

◆ actionCollection()

KisKActionCollection * KisKXMLGUIClient::actionCollection ( ) const
virtual

Retrieves the entire action collection for the GUI client.

Reimplemented in KDEPrivate::KisKEditToolBarWidget.

Definition at line 123 of file kxmlguiclient.cpp.

124{
125 if (!d->m_actionCollection) {
127 d->m_actionCollection->setObjectName(QStringLiteral("KisKXMLGUIClient-KisKActionCollection"));
128 }
129 return d->m_actionCollection;
130}
A container for a set of QAction objects.

References d, and KisKXMLGUIClientPrivate::m_actionCollection.

◆ addStateActionDisabled()

void KisKXMLGUIClient::addStateActionDisabled ( const QString & state,
const QString & action )

Definition at line 739 of file kxmlguiclient.cpp.

741{
742 StateChange stateChange = getActionsToChangeForState(state);
743
744 stateChange.actionsToDisable.append(action);
745 //qDebug(260) << "KisKXMLGUIClient::addStateActionDisabled( " << state << ", " << action << ")";
746
747 d->m_actionsStateMap.insert(state, stateChange);
748}
QMap< QString, KisKXMLGUIClient::StateChange > m_actionsStateMap
StateChange getActionsToChangeForState(const QString &state)
QAction * action(const char *name) const

References action(), KisKXMLGUIClient::StateChange::actionsToDisable, d, getActionsToChangeForState(), and KisKXMLGUIClientPrivate::m_actionsStateMap.

◆ addStateActionEnabled()

void KisKXMLGUIClient::addStateActionEnabled ( const QString & state,
const QString & action )

Definition at line 728 of file kxmlguiclient.cpp.

730{
731 StateChange stateChange = getActionsToChangeForState(state);
732
733 stateChange.actionsToEnable.append(action);
734 //qDebug(260) << "KisKXMLGUIClient::addStateActionEnabled( " << state << ", " << action << ")";
735
736 d->m_actionsStateMap.insert(state, stateChange);
737}

References action(), KisKXMLGUIClient::StateChange::actionsToEnable, d, getActionsToChangeForState(), and KisKXMLGUIClientPrivate::m_actionsStateMap.

◆ beginXMLPlug()

void KisKXMLGUIClient::beginXMLPlug ( QWidget * w)

Definition at line 786 of file kxmlguiclient.cpp.

787{
789 foreach (KisKXMLGUIClient *client, d->m_children) {
790 client->beginXMLPlug(w);
791 }
792}
void addAssociatedWidget(QWidget *widget)
void beginXMLPlug(QWidget *)

References actionCollection(), KisKActionCollection::addAssociatedWidget(), beginXMLPlug(), d, and KisKXMLGUIClientPrivate::m_children.

◆ childClients()

QList< KisKXMLGUIClient * > KisKXMLGUIClient::childClients ( )

Retrieves a list of all child clients.

Definition at line 688 of file kxmlguiclient.cpp.

689{
690 return d->m_children;
691}

References d, and KisKXMLGUIClientPrivate::m_children.

◆ clientBuilder()

KisKXMLGUIBuilder * KisKXMLGUIClient::clientBuilder ( ) const

Retrieves the client's GUI builder or 0 if no client specific builder has been assigned via setClientBuilder()

Definition at line 698 of file kxmlguiclient.cpp.

699{
700 return d->m_builder;
701}
KisKXMLGUIBuilder * m_builder

References d, and KisKXMLGUIClientPrivate::m_builder.

◆ componentName()

QString KisKXMLGUIClient::componentName ( ) const
virtual
Returns
The component name for this GUI client.

Definition at line 137 of file kxmlguiclient.cpp.

138{
139 return d->m_componentName;
140}

References d, and KisKXMLGUIClientPrivate::m_componentName.

◆ domDocument()

QDomDocument KisKXMLGUIClient::domDocument ( ) const
virtual
Returns
The parsed XML in a QDomDocument, set by setXMLFile() or setXML(). This document describes the layout of the GUI.

Definition at line 142 of file kxmlguiclient.cpp.

143{
144 return d->m_doc;
145}

References d, and KisKXMLGUIClientPrivate::m_doc.

◆ endXMLPlug()

void KisKXMLGUIClient::endXMLPlug ( )

Definition at line 794 of file kxmlguiclient.cpp.

795{
796}

◆ factory()

KisKXMLGUIFactory * KisKXMLGUIClient::factory ( ) const

Retrieves a pointer to the KisKXMLGUIFactory this client is associated with (will return 0 if the client's GUI has not been built by a KisKXMLGUIFactory.

Definition at line 654 of file kxmlguiclient.cpp.

655{
656 return d->m_factory;
657}

References d, and KisKXMLGUIClientPrivate::m_factory.

◆ findMostRecentXMLFile()

QString KisKXMLGUIClient::findMostRecentXMLFile ( const QStringList & files,
QString & doc )
static

Definition at line 721 of file kxmlguiclient.cpp.

722{
723 KXmlGuiVersionHandler versionHandler(files);
724 doc = versionHandler.finalDocument();
725 return versionHandler.finalFile();
726}

References KXmlGuiVersionHandler::finalDocument(), and KXmlGuiVersionHandler::finalFile().

◆ getActionsToChangeForState()

KisKXMLGUIClient::StateChange KisKXMLGUIClient::getActionsToChangeForState ( const QString & state)

Definition at line 750 of file kxmlguiclient.cpp.

751{
752 return d->m_actionsStateMap[state];
753}

References d, and KisKXMLGUIClientPrivate::m_actionsStateMap.

◆ insertChildClient()

void KisKXMLGUIClient::insertChildClient ( KisKXMLGUIClient * child)

Use this method to make a client a child client of another client. Usually you don't need to call this method, as it is called automatically when using the second constructor, which takes a parent argument.

Definition at line 664 of file kxmlguiclient.cpp.

665{
666 if (child->d->m_parent) {
667 child->d->m_parent->removeChildClient(child);
668 }
669 d->m_children.append(child);
670 child->d->m_parent = this;
671}

References d, KisKXMLGUIClientPrivate::m_children, KisKXMLGUIClientPrivate::m_parent, and removeChildClient().

◆ loadStandardsXmlFile()

void KisKXMLGUIClient::loadStandardsXmlFile ( )
protected

Load the ui_standards.xmlgui file. Usually followed by setXMLFile(xmlFile, true), for merging.

Since
4.6

Definition at line 202 of file kxmlguiclient.cpp.

203{
205}
static QString standardsXmlFileLocation()
void setXML(const QString &document, bool merge=false)
static QString readConfigFile(const QString &filename, const QString &componentName=QString())

References KisKXMLGUIFactory::readConfigFile(), setXML(), and standardsXmlFileLocation().

◆ localXMLFile()

QString KisKXMLGUIClient::localXMLFile ( ) const
virtual

Definition at line 152 of file kxmlguiclient.cpp.

153{
154 if (!d->m_localXMLFile.isEmpty()) {
155 return d->m_localXMLFile;
156 }
157
158 if (!QDir::isRelativePath(d->m_xmlFile)) {
159 return QString(); // can't save anything here
160 }
161
162 if (d->m_xmlFile.isEmpty()) { // setXMLFile not called at all, can't save. Use case: ToolBarHandler
163 return QString();
164 }
165
166 return QStandardPaths::writableLocation(QStandardPaths::AppDataLocation) + QStringLiteral("/kxmlgui5/") +
167 componentName() + QLatin1Char('/') + d->m_xmlFile;
168}
virtual QString componentName() const

References componentName(), d, KisKXMLGUIClientPrivate::m_localXMLFile, and KisKXMLGUIClientPrivate::m_xmlFile.

◆ parentClient()

KisKXMLGUIClient * KisKXMLGUIClient::parentClient ( ) const

KisKXMLGUIClients can form a simple child/parent object tree. This method returns a pointer to the parent client or 0 if it has no parent client assigned.

Definition at line 659 of file kxmlguiclient.cpp.

660{
661 return d->m_parent;
662}

References d, and KisKXMLGUIClientPrivate::m_parent.

◆ plugActionList()

void KisKXMLGUIClient::plugActionList ( const QString & name,
const QList< QAction * > & actionList )

ActionLists are a way for XMLGUI to support dynamic lists of actions. E.g. if you are writing a file manager, and there is a menu file whose contents depend on the mimetype of the file that is selected, then you can achieve this using ActionLists. It works as follows: In your xxxui.xmlgui file ( the one that you set in setXMLFile() / pass to setupGUI() ), you put a tag <ActionList name="xxx">.

Example:

<gui name="xxx_part" version="1">
<MenuBar>
<Menu name="file">
... <!-- some useful actions-->
<ActionList name="xxx_file_actionlist" />
... <!-- even more useful actions-->
</Menu>
...
</MenuBar>
</gui>

This tag will get expanded to a list of actions. In the example above ( a file manager with a dynamic file menu ), you would call

QList<QAction*> file_actions;
for( ... )
if( ... )
file_actions.append( cool_action );
unplugActionList( "xxx_file_actionlist" );
plugActionList( "xxx_file_actionlist", file_actions );
void unplugActionList(const QString &name)
void plugActionList(const QString &name, const QList< QAction * > &actionList)

every time a file is selected, unselected or ...

Note
You should not call createGUI() after calling this function. In fact, that would remove the newly added actionlists again...
Forgetting to call unplugActionList() before plugActionList() would leave the previous actions in the menu too..
See also
unplugActionList()

Definition at line 703 of file kxmlguiclient.cpp.

704{
705 if (!d->m_factory) {
706 return;
707 }
708
709 d->m_factory->plugActionList(this, name, actionList);
710}

References d, and KisKXMLGUIClientPrivate::m_factory.

◆ prepareXMLUnplug()

void KisKXMLGUIClient::prepareXMLUnplug ( QWidget * w)

Definition at line 798 of file kxmlguiclient.cpp.

799{
801 foreach (KisKXMLGUIClient *client, d->m_children) {
802 client->prepareXMLUnplug(w);
803 }
804}
void removeAssociatedWidget(QWidget *widget)
void prepareXMLUnplug(QWidget *)

References actionCollection(), d, KisKXMLGUIClientPrivate::m_children, prepareXMLUnplug(), and KisKActionCollection::removeAssociatedWidget().

◆ reloadXML()

void KisKXMLGUIClient::reloadXML ( )

Forces this client to re-read its XML resource file. This is intended to be used when you know that the resource file has changed and you will soon be rebuilding the GUI. This will only have an effect if the client is then removed and re-added to the factory.

This method is only for child clients, do not call it for a mainwindow! For a mainwindow, use loadStandardsXmlFile + setXmlFile(xmlFile()) instead.

Definition at line 170 of file kxmlguiclient.cpp.

171{
172 // TODO: this method can't be used for the KXmlGuiWindow, since it doesn't merge in ui_standards.xmlgui!
173 // -> KDE5: load ui_standards_rc in setXMLFile using a flag, and remember that flag?
174 // and then KisKEditToolBar can use reloadXML.
175 QString file(xmlFile());
176 if (!file.isEmpty()) {
177 setXMLFile(file);
178 }
179}
virtual QString xmlFile() const
void setXMLFile(const QString &file, bool merge=false, bool setXMLDoc=true)

References setXMLFile(), and xmlFile().

◆ removeChildClient()

void KisKXMLGUIClient::removeChildClient ( KisKXMLGUIClient * child)

Removes the given child from the client's children list.

Definition at line 673 of file kxmlguiclient.cpp.

674{
675 assert(d->m_children.contains(child));
676 d->m_children.removeAll(child);
677 child->d->m_parent = 0;
678}

References d, KisKXMLGUIClientPrivate::m_children, and KisKXMLGUIClientPrivate::m_parent.

◆ replaceXMLFile()

void KisKXMLGUIClient::replaceXMLFile ( const QString & xmlfile,
const QString & localxmlfile,
bool merge = false )

Sets a new xmlFile() and localXMLFile(). The purpose of this public method is to allow non-inherited objects to replace the ui definition of an embedded client with a customized version. It corresponds to the usual calls to setXMLFile() and setLocalXMLFile().

Parameters
xmlfileThe xml file to use. Contrary to setXMLFile(), this must be an absolute file path.
localxmlfileThe local xml file to set. This should be the full path to a writeable file, usually using QStandardPaths::writableLocation. You can set this to QString(), but no user changes to shortcuts / toolbars will be possible in this case.
See also
setLocalXMLFile()
Parameters
mergeWhether to merge with the global document
Note
If in any doubt whether you need this or not, use setXMLFile() and setLocalXMLFile(), instead of this function.
Just like setXMLFile(), this function has to be called before the client is added to a KisKXMLGUIFactory in order to have an effect.
Since
4.4

Definition at line 272 of file kxmlguiclient.cpp.

273{
274 if (!QDir::isAbsolutePath(xmlfile)) {
275 qWarning() << "xml file" << xmlfile << "is not an absolute path";
276 }
277
278 setLocalXMLFile(localxmlfile);
279 setXMLFile(xmlfile, merge);
280}
void setLocalXMLFile(const QString &file)

References setLocalXMLFile(), and setXMLFile().

◆ setClientBuilder()

void KisKXMLGUIClient::setClientBuilder ( KisKXMLGUIBuilder * builder)

A client can have an own KisKXMLGUIBuilder. Use this method to assign your builder instance to the client (so that the KisKXMLGUIFactory can use it when building the client's GUI)

Client specific guibuilders are useful if you want to create custom container widgets for your GUI.

Definition at line 693 of file kxmlguiclient.cpp.

694{
695 d->m_builder = builder;
696}

References d, and KisKXMLGUIClientPrivate::m_builder.

◆ setComponentName()

void KisKXMLGUIClient::setComponentName ( const QString & componentName,
const QString & componentDisplayName )
protectedvirtual

Sets the component name for this part.

Call this first in the inherited class constructor. (At least before setXMLFile().)

Parameters
componentNamethe name of the directory where the XMLGUI files will be found
componentDisplayNamea user-visible name (e.g. for the toolbar editor)

Definition at line 181 of file kxmlguiclient.cpp.

182{
185 actionCollection()->setComponentDisplayName(componentDisplayName);
186 if (d->m_builder) {
188 }
189}
void setComponentDisplayName(const QString &displayName)
void setComponentName(const QString &componentName)
void setBuilderClient(KisKXMLGUIClient *client)

References actionCollection(), componentName(), d, KisKXMLGUIClientPrivate::m_builder, KisKXMLGUIClientPrivate::m_componentName, KisKXMLGUIBuilder::setBuilderClient(), KisKActionCollection::setComponentDisplayName(), and KisKActionCollection::setComponentName().

◆ setDOMDocument()

void KisKXMLGUIClient::setDOMDocument ( const QDomDocument & document,
bool merge = false )
protected

Sets the Document for the part, describing the layout of the GUI.

Call this in the Part-inherited class constructor if you don't call setXMLFile or setXML.

WARNING: using this method is not recommended. Many code paths lead to reloading from the XML file on disk. And editing toolbars requires that the result is written to disk anyway, and loaded from there the next time.

For application-specific changes to a client's XML, it is a better idea to save the modified dom document to an app/default-client.xml and define a local-xml-file to something specific like app/local-client.xml, using replaceXMLFile. See kdepimlibs/kontactinterface/plugin.cpp for an example.

Definition at line 342 of file kxmlguiclient.cpp.

343{
344 if (merge && !d->m_doc.isNull()) {
345 QDomElement base = d->m_doc.documentElement();
346
347 QDomElement e = document.documentElement();
348
349 // merge our original (global) xml with our new one
350 d->mergeXML(base, e, actionCollection());
351
352 // reassign our pointer as mergeXML might have done something
353 // strange to it
354 base = d->m_doc.documentElement();
355
356 //qDebug(260) << "Result of xmlgui merging:" << d->m_doc.toString();
357
358 // we want some sort of failsafe.. just in case
359 if (base.isNull()) {
360 d->m_doc = document;
361 }
362 } else {
363 d->m_doc = document;
364 }
365
366 setXMLGUIBuildDocument(QDomDocument());
367}
bool mergeXML(QDomElement &base, QDomElement &additive, KisKActionCollection *actionCollection)
void setXMLGUIBuildDocument(const QDomDocument &doc)

References actionCollection(), d, KisKXMLGUIClientPrivate::m_doc, KisKXMLGUIClientPrivate::mergeXML(), and setXMLGUIBuildDocument().

◆ setFactory()

void KisKXMLGUIClient::setFactory ( KisKXMLGUIFactory * factory)

This method is called by the KisKXMLGUIFactory as soon as the client is added to the KisKXMLGUIFactory's GUI.

Definition at line 649 of file kxmlguiclient.cpp.

650{
652}
KisKXMLGUIFactory * factory() const

References d, factory(), and KisKXMLGUIClientPrivate::m_factory.

◆ setLocalXMLFile()

void KisKXMLGUIClient::setLocalXMLFile ( const QString & file)
protected

Set the full path to the "local" xml file, the one used for saving toolbar and shortcut changes. You normally don't need to call this, if you pass a simple filename to setXMLFile.

Definition at line 267 of file kxmlguiclient.cpp.

268{
270}

References d, and KisKXMLGUIClientPrivate::m_localXMLFile.

◆ setXML()

void KisKXMLGUIClient::setXML ( const QString & document,
bool merge = false )
protected

Sets the XML for the part.

Call this in the Part-inherited class constructor if you don't call setXMLFile().

Definition at line 312 of file kxmlguiclient.cpp.

313{
314 QDomDocument doc;
315 // QDomDocument raises a parse error on empty document, but we accept no app-specific document,
316 // in which case you only get ui_standards.xmlgui layout.
317#if QT_VERSION < QT_VERSION_CHECK(6, 5, 0)
318 QString errorMsg;
319 int errorLine, errorColumn;
320 bool result = document.isEmpty() || doc.setContent(document, &errorMsg, &errorLine, &errorColumn);
321 if (result) {
322#else
323 QDomDocument::ParseResult result = doc.setContent(document);
324 if (document.isEmpty() || result) {
325#endif
327 setDOMDocument(doc, merge);
328 } else {
329#if QT_VERSION < QT_VERSION_CHECK(6, 5, 0)
330 qCritical() << "Error parsing XML document:" << errorMsg << "at line" << errorLine << "column" << errorColumn;
331#else
332 qCritical() << "Error parsing XML document:" << result.errorMessage << "at line" << result.errorLine << "column" << result.errorColumn;
333#endif
334#ifdef NDEBUG
335 setDOMDocument(QDomDocument(), merge); // otherwise empty menus from ui_standards.xmlgui stay around
336#else
337 abort();
338#endif
339 }
340}
void setDOMDocument(const QDomDocument &document, bool merge=false)
static void propagateTranslationDomain(QDomDocument &doc, const QStringList tagNames)

References d, KisKXMLGUIClientPrivate::m_textTagNames, propagateTranslationDomain(), and setDOMDocument().

◆ setXMLFile()

void KisKXMLGUIClient::setXMLFile ( const QString & file,
bool merge = false,
bool setXMLDoc = true )
protected

Sets the name of the rc file containing the XML for the part.

Call this in the inherited class constructor, for parts and plugins. NOTE: for mainwindows, don't call this, pass the name of the xml file to KXmlGuiWindow::setupGUI() or KXmlGuiWindow::createGUI().

Parameters
fileEither an absolute path for the file, or simply the filename. See below for details. If you pass an absolute path here, make sure to also call setLocalXMLFile, otherwise toolbar editing won't work.
mergeWhether to merge with the global document.
setXMLDocSpecify whether to call setXML. Default is true.

The preferred way to call this method is with a simple filename for the file argument.

Since KF 5.1, the file will then be assumed to be installed in DATADIR/kxmlgui5/, under a directory named after the component name. You should use ${KisKXMLGUI_INSTALL_DIR}/componentname in your CMakeLists.txt file, to install the .xmlgui file(s).

Since KF 5.4, the file will then be assumed to be installed in a Qt resource in :/kxmlgui5/, under a directory named after the component name.

Compatibility notes: Fallback lookups exist to older locations: DATADIR/componentname/file and DATADIR/file. The latter was there so that setXMLFile("componentname/filename") worked (but this was undocumented). Do not do this anymore after porting to KisKXMLGUI_INSTALL_DIR, use setComponentName("componentname") and setXMLFile("filename").

Definition at line 207 of file kxmlguiclient.cpp.

208{
209 // store our xml file name
210 if (!_file.isNull()) {
211 d->m_xmlFile = _file;
212 }
213
214 if (!setXMLDoc) {
215 return;
216 }
217
218 QString file = _file;
219 QStringList allFiles;
220 if (!QDir::isRelativePath(file)) {
221 allFiles.append(file);
222 } else {
223 const QString filter = componentName() + QLatin1Char('/') + _file;
224
225 // files on filesystem
226 allFiles << QStandardPaths::locateAll(QStandardPaths::AppDataLocation, QStringLiteral("kxmlgui5/") + filter); // KF >= 5.1
227
228 // KF >= 5.4 (resource file)
229 const QString qrcFile(QStringLiteral(":/kxmlgui5/") + filter);
230 if (QFile::exists(qrcFile)) {
231 allFiles << qrcFile;
232 }
233
234 // then compat locations
235 const QStringList compatFiles =
236 QStandardPaths::locateAll(QStandardPaths::AppDataLocation, filter) + // kdelibs4, KF 5.0
237 QStandardPaths::locateAll(QStandardPaths::AppDataLocation, _file); // kdelibs4, KF 5.0, caller passes component name
238
239 if (allFiles.isEmpty() && !compatFiles.isEmpty()) {
240 qWarning() << "kxmlguiclient: KisKXMLGUI file found at deprecated location" << compatFiles << "-- please use ${KisKXMLGUI_INSTALL_DIR} to install this file instead.";
241 }
242 allFiles += compatFiles;
243 }
244 if (allFiles.isEmpty() && !_file.isEmpty()) {
245 // if a non-empty file gets passed and we can't find it,
246 // inform the developer using some debug output
247 qWarning() << "cannot find .xmlgui file" << _file << "for component" << componentName();
248 }
249
250 // make sure to merge the settings from any file specified by setLocalXMLFile()
251 if (!d->m_localXMLFile.isEmpty() && !file.endsWith(QStringLiteral("ui_standards.xmlgui"))) {
252 const bool exists = QDir::isRelativePath(d->m_localXMLFile) || QFile::exists(d->m_localXMLFile);
253 if (exists && !allFiles.contains(d->m_localXMLFile)) {
254 allFiles.prepend(d->m_localXMLFile);
255 }
256 }
257
258 QString doc;
259 if (!allFiles.isEmpty()) {
260 file = findMostRecentXMLFile(allFiles, doc);
261 }
262
263 // Always call setXML, even on error, so that we don't keep all ui_standards.xmlgui menus.
264 setXML(doc, merge);
265}
static QString findMostRecentXMLFile(const QStringList &files, QString &doc)

References componentName(), d, findMostRecentXMLFile(), KisKXMLGUIClientPrivate::m_localXMLFile, KisKXMLGUIClientPrivate::m_xmlFile, and setXML().

◆ setXMLGUIBuildDocument()

void KisKXMLGUIClient::setXMLGUIBuildDocument ( const QDomDocument & doc)

Definition at line 639 of file kxmlguiclient.cpp.

640{
641 d->m_buildDocument = doc;
642}

References d, and KisKXMLGUIClientPrivate::m_buildDocument.

◆ standardsXmlFileLocation()

QString KisKXMLGUIClient::standardsXmlFileLocation ( )
staticprotected

Return the full path to the ui_standards.xmlgui, might return a resource path.

Returns
full path to ui_standards.xmlgui, always non-empty.
Since
5.16

Definition at line 191 of file kxmlguiclient.cpp.

192{
193 QString file = QStandardPaths::locate(QStandardPaths::GenericConfigLocation, QStringLiteral("ui/ui_standards.xmlgui"));
194 if (file.isEmpty()) {
195 // fallback to resource, to allow to use the rc file compiled into this framework, must exist!
196 file = QStringLiteral(":/kxmlgui5/ui_standards.xmlgui");
197 Q_ASSERT(QFile::exists(file));
198 }
199 return file;
200}

◆ stateChanged()

void KisKXMLGUIClient::stateChanged ( const QString & newstate,
KisKXMLGUIClient::ReverseStateChange reverse = StateNoReverse )
protectedvirtual

Actions can collectively be assigned a "State". To accomplish this the respective actions are tagged as <enable> or <disable> in a <State> </State> group of the XMLfile. During program execution the programmer can call stateChanged() to set actions to a defined state.

Parameters
newstateName of a State in the XMLfile.
reverseIf the flag reverse is set to StateReverse, the State is reversed. (actions to be enabled will be disabled and action to be disabled will be enabled) Default is reverse=false.

Definition at line 755 of file kxmlguiclient.cpp.

756{
757 StateChange stateChange = getActionsToChangeForState(newstate);
758
759 bool setTrue = (reverse == StateNoReverse);
760 bool setFalse = !setTrue;
761
762 // Enable actions which need to be enabled...
763 //
764 for (QStringList::const_iterator it = stateChange.actionsToEnable.constBegin();
765 it != stateChange.actionsToEnable.constEnd(); ++it) {
766
767 QAction *action = actionCollection()->action(*it);
768 if (action) {
769 action->setEnabled(setTrue);
770 }
771 }
772
773 // and disable actions which need to be disabled...
774 //
775 for (QStringList::const_iterator it = stateChange.actionsToDisable.constBegin();
776 it != stateChange.actionsToDisable.constEnd(); ++it) {
777
778 QAction *action = actionCollection()->action(*it);
779 if (action) {
780 action->setEnabled(setFalse);
781 }
782 }
783
784}

References action(), KisKActionCollection::action(), actionCollection(), KisKXMLGUIClient::StateChange::actionsToDisable, KisKXMLGUIClient::StateChange::actionsToEnable, getActionsToChangeForState(), and StateNoReverse.

◆ unplugActionList()

void KisKXMLGUIClient::unplugActionList ( const QString & name)

Unplugs the action list name from the XMLGUI. Calling this removes the specified action list, i.e. this is the complement to plugActionList(). See plugActionList() for a more detailed example.

See also
plugActionList()

Definition at line 712 of file kxmlguiclient.cpp.

713{
714 if (!d->m_factory) {
715 return;
716 }
717
718 d->m_factory->unplugActionList(this, name);
719}

References d, and KisKXMLGUIClientPrivate::m_factory.

◆ virtual_hook()

void KisKXMLGUIClient::virtual_hook ( int id,
void * data )
protectedvirtual

Definition at line 806 of file kxmlguiclient.cpp.

807{
808 /*BASE::virtual_hook( id, data );*/
809}

◆ xmlFile()

QString KisKXMLGUIClient::xmlFile ( ) const
virtual

This will return the name of the XML file as set by setXMLFile(). If setXML() is used directly, then this will return 0.

The filename that this returns is obvious for components as each component has exactly one XML file. In non-components, however, there are usually two: the global file and the local file. This function doesn't really care about that, though. It will always return the last XML file set. This, in almost all cases, will be the local XML file.

Returns
The name of the XML file or QString()

Definition at line 147 of file kxmlguiclient.cpp.

148{
149 return d->m_xmlFile;
150}

References d, and KisKXMLGUIClientPrivate::m_xmlFile.

◆ xmlguiBuildDocument()

QDomDocument KisKXMLGUIClient::xmlguiBuildDocument ( ) const

Definition at line 644 of file kxmlguiclient.cpp.

645{
646 return d->m_buildDocument;
647}

References d, and KisKXMLGUIClientPrivate::m_buildDocument.

Friends And Related Symbol Documentation

◆ KDEPrivate::KisKEditToolBarWidget

friend class KDEPrivate::KisKEditToolBarWidget
friend

Definition at line 38 of file kxmlguiclient.h.

Member Data Documentation

◆ d

KisKXMLGUIClientPrivate* const KisKXMLGUIClient::d
private

Definition at line 395 of file kxmlguiclient.h.


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