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 76 of file kxmlguiclient.cpp.

78{
79}
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 81 of file kxmlguiclient.cpp.

83{
84 parent->insertChildClient(this);
85}
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 87 of file kxmlguiclient.cpp.

88{
89 if (d->m_parent) {
91 }
92
93 if (d->m_factory) {
94 qWarning() << this << "deleted without having been removed from the factory first. This will leak standalone popupmenus and could lead to crashes.";
95 d->m_factory->forgetClient(this);
96 }
97
98 Q_FOREACH (KisKXMLGUIClient *client, d->m_children) {
99 if (d->m_factory) {
100 d->m_factory->forgetClient(client);
101 }
102 assert(client->d->m_parent == this);
103 client->d->m_parent = 0;
104 }
105
106 delete d->m_actionCollection;
107 delete d;
108}
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 110 of file kxmlguiclient.cpp.

111{
112 QAction *act = actionCollection()->action(QLatin1String(name));
113 if (!act) {
114 Q_FOREACH (KisKXMLGUIClient *client, d->m_children) {
115 act = client->actionCollection()->action(QLatin1String(name));
116 if (act) {
117 break;
118 }
119 }
120 }
121 return act;
122}
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 133 of file kxmlguiclient.cpp.

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

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 124 of file kxmlguiclient.cpp.

125{
126 if (!d->m_actionCollection) {
128 d->m_actionCollection->setObjectName(QStringLiteral("KisKXMLGUIClient-KisKActionCollection"));
129 }
130 return d->m_actionCollection;
131}
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 732 of file kxmlguiclient.cpp.

734{
735 StateChange stateChange = getActionsToChangeForState(state);
736
737 stateChange.actionsToDisable.append(action);
738 //qDebug(260) << "KisKXMLGUIClient::addStateActionDisabled( " << state << ", " << action << ")";
739
740 d->m_actionsStateMap.insert(state, stateChange);
741}
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 721 of file kxmlguiclient.cpp.

723{
724 StateChange stateChange = getActionsToChangeForState(state);
725
726 stateChange.actionsToEnable.append(action);
727 //qDebug(260) << "KisKXMLGUIClient::addStateActionEnabled( " << state << ", " << action << ")";
728
729 d->m_actionsStateMap.insert(state, stateChange);
730}

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

◆ beginXMLPlug()

void KisKXMLGUIClient::beginXMLPlug ( QWidget * w)

Definition at line 779 of file kxmlguiclient.cpp.

780{
782 foreach (KisKXMLGUIClient *client, d->m_children) {
783 client->beginXMLPlug(w);
784 }
785}
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 681 of file kxmlguiclient.cpp.

682{
683 return d->m_children;
684}

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 691 of file kxmlguiclient.cpp.

692{
693 return d->m_builder;
694}
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 138 of file kxmlguiclient.cpp.

139{
140 return d->m_componentName;
141}

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 143 of file kxmlguiclient.cpp.

144{
145 return d->m_doc;
146}

References d, and KisKXMLGUIClientPrivate::m_doc.

◆ endXMLPlug()

void KisKXMLGUIClient::endXMLPlug ( )

Definition at line 787 of file kxmlguiclient.cpp.

788{
789}

◆ 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 647 of file kxmlguiclient.cpp.

648{
649 return d->m_factory;
650}

References d, and KisKXMLGUIClientPrivate::m_factory.

◆ findMostRecentXMLFile()

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

Definition at line 714 of file kxmlguiclient.cpp.

715{
716 KXmlGuiVersionHandler versionHandler(files);
717 doc = versionHandler.finalDocument();
718 return versionHandler.finalFile();
719}

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

◆ getActionsToChangeForState()

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

Definition at line 743 of file kxmlguiclient.cpp.

744{
745 return d->m_actionsStateMap[state];
746}

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 657 of file kxmlguiclient.cpp.

658{
659 if (child->d->m_parent) {
660 child->d->m_parent->removeChildClient(child);
661 }
662 d->m_children.append(child);
663 child->d->m_parent = this;
664}

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 203 of file kxmlguiclient.cpp.

204{
206}
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 153 of file kxmlguiclient.cpp.

154{
155 if (!d->m_localXMLFile.isEmpty()) {
156 return d->m_localXMLFile;
157 }
158
159 if (!QDir::isRelativePath(d->m_xmlFile)) {
160 return QString(); // can't save anything here
161 }
162
163 if (d->m_xmlFile.isEmpty()) { // setXMLFile not called at all, can't save. Use case: ToolBarHandler
164 return QString();
165 }
166
167 return QStandardPaths::writableLocation(QStandardPaths::AppDataLocation) + QStringLiteral("/kxmlgui5/") +
168 componentName() + QLatin1Char('/') + d->m_xmlFile;
169}
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 652 of file kxmlguiclient.cpp.

653{
654 return d->m_parent;
655}

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 696 of file kxmlguiclient.cpp.

697{
698 if (!d->m_factory) {
699 return;
700 }
701
702 d->m_factory->plugActionList(this, name, actionList);
703}

References d, and KisKXMLGUIClientPrivate::m_factory.

◆ prepareXMLUnplug()

void KisKXMLGUIClient::prepareXMLUnplug ( QWidget * w)

Definition at line 791 of file kxmlguiclient.cpp.

792{
794 foreach (KisKXMLGUIClient *client, d->m_children) {
795 client->prepareXMLUnplug(w);
796 }
797}
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 171 of file kxmlguiclient.cpp.

172{
173 // TODO: this method can't be used for the KXmlGuiWindow, since it doesn't merge in ui_standards.xmlgui!
174 // -> KDE5: load ui_standards_rc in setXMLFile using a flag, and remember that flag?
175 // and then KisKEditToolBar can use reloadXML.
176 QString file(xmlFile());
177 if (!file.isEmpty()) {
178 setXMLFile(file);
179 }
180}
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 666 of file kxmlguiclient.cpp.

667{
668 assert(d->m_children.contains(child));
669 d->m_children.removeAll(child);
670 child->d->m_parent = 0;
671}

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 273 of file kxmlguiclient.cpp.

274{
275 if (!QDir::isAbsolutePath(xmlfile)) {
276 qWarning() << "xml file" << xmlfile << "is not an absolute path";
277 }
278
279 setLocalXMLFile(localxmlfile);
280 setXMLFile(xmlfile, merge);
281}
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 686 of file kxmlguiclient.cpp.

687{
688 d->m_builder = builder;
689}

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 182 of file kxmlguiclient.cpp.

183{
186 actionCollection()->setComponentDisplayName(componentDisplayName);
187 if (d->m_builder) {
189 }
190}
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 335 of file kxmlguiclient.cpp.

336{
337 if (merge && !d->m_doc.isNull()) {
338 QDomElement base = d->m_doc.documentElement();
339
340 QDomElement e = document.documentElement();
341
342 // merge our original (global) xml with our new one
343 d->mergeXML(base, e, actionCollection());
344
345 // reassign our pointer as mergeXML might have done something
346 // strange to it
347 base = d->m_doc.documentElement();
348
349 //qDebug(260) << "Result of xmlgui merging:" << d->m_doc.toString();
350
351 // we want some sort of failsafe.. just in case
352 if (base.isNull()) {
353 d->m_doc = document;
354 }
355 } else {
356 d->m_doc = document;
357 }
358
359 setXMLGUIBuildDocument(QDomDocument());
360}
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 642 of file kxmlguiclient.cpp.

643{
645}
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 268 of file kxmlguiclient.cpp.

269{
271}

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 313 of file kxmlguiclient.cpp.

314{
315 QDomDocument doc;
316 QString errorMsg;
317 int errorLine, errorColumn;
318 // QDomDocument raises a parse error on empty document, but we accept no app-specific document,
319 // in which case you only get ui_standards.xmlgui layout.
320 bool result = document.isEmpty() || doc.setContent(document, &errorMsg, &errorLine, &errorColumn);
321 if (result) {
323 setDOMDocument(doc, merge);
324 } else {
325#ifdef NDEBUG
326 qCritical() << "Error parsing XML document:" << errorMsg << "at line" << errorLine << "column" << errorColumn;
327 setDOMDocument(QDomDocument(), merge); // otherwise empty menus from ui_standards.xmlgui stay around
328#else
329 qCritical() << "Error parsing XML document:" << errorMsg << "at line" << errorLine << "column" << errorColumn;
330 abort();
331#endif
332 }
333}
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 208 of file kxmlguiclient.cpp.

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

633{
634 d->m_buildDocument = doc;
635}

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 192 of file kxmlguiclient.cpp.

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

◆ 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 748 of file kxmlguiclient.cpp.

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

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 705 of file kxmlguiclient.cpp.

706{
707 if (!d->m_factory) {
708 return;
709 }
710
711 d->m_factory->unplugActionList(this, name);
712}

References d, and KisKXMLGUIClientPrivate::m_factory.

◆ virtual_hook()

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

Definition at line 799 of file kxmlguiclient.cpp.

800{
801 /*BASE::virtual_hook( id, data );*/
802}

◆ 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 148 of file kxmlguiclient.cpp.

149{
150 return d->m_xmlFile;
151}

References d, and KisKXMLGUIClientPrivate::m_xmlFile.

◆ xmlguiBuildDocument()

QDomDocument KisKXMLGUIClient::xmlguiBuildDocument ( ) const

Definition at line 637 of file kxmlguiclient.cpp.

638{
639 return d->m_buildDocument;
640}

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: