File indexing completed on 2024-04-21 15:05:44

0001 /*
0002     This file is part of the KDE libraries
0003     SPDX-FileCopyrightText: 2009 David Faure <faure@kde.org>
0004 
0005     SPDX-License-Identifier: LGPL-2.0-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL
0006 */
0007 
0008 #ifndef TESTGUICLIENT_H
0009 #define TESTGUICLIENT_H
0010 
0011 #include <kactioncollection.h>
0012 #include <ktoolbar.h>
0013 #include <kxmlguiclient.h>
0014 #include <kxmlguifactory.h>
0015 
0016 #include <QDebug>
0017 
0018 // because setDOMDocument and setXML are protected
0019 class TestGuiClient : public KXMLGUIClient
0020 {
0021 public:
0022     explicit TestGuiClient(const QByteArray &xml = QByteArray())
0023         : KXMLGUIClient()
0024     {
0025         if (!xml.isNull()) {
0026             setXML(QString::fromLatin1(xml));
0027         }
0028     }
0029     void setXMLFilePublic(const QString &file, bool merge = false, bool setXMLDoc = true)
0030     {
0031         setXMLFile(file, merge, setXMLDoc);
0032     }
0033     void setLocalXMLFilePublic(const QString &file)
0034     {
0035         setLocalXMLFile(file);
0036     }
0037     void createGUI(const QByteArray &xml, bool withUiStandards = false)
0038     {
0039         if (withUiStandards) {
0040             setXMLFile(KXMLGUIClient::standardsXmlFileLocation());
0041         }
0042 
0043         setXML(QString::fromLatin1(xml), true);
0044     }
0045     void createActions(const QStringList &actionNames)
0046     {
0047         KActionCollection *coll = actionCollection();
0048         for (const QString &actionName : actionNames) {
0049             coll->addAction(actionName)->setText(QStringLiteral("Action"));
0050         }
0051     }
0052 
0053     // Find a toolbar (created by this guiclient)
0054     KToolBar *toolBarByName(const QString &name)
0055     {
0056         // qDebug() << "containers:" << factory()->containers("ToolBar");
0057         QWidget *toolBarW = factory()->container(name, this);
0058         if (!toolBarW) {
0059             qWarning() << "No toolbar found with name" << name;
0060         }
0061         Q_ASSERT(toolBarW);
0062         KToolBar *toolBar = qobject_cast<KToolBar *>(toolBarW);
0063         Q_ASSERT(toolBar);
0064         return toolBar;
0065     }
0066 };
0067 
0068 #endif /* TESTGUICLIENT_H */