File indexing completed on 2024-12-08 03:43:53
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 mergeXML(const QByteArray &xml) 0046 { 0047 setXML(QString::fromLatin1(xml), true); 0048 } 0049 void createActions(const QStringList &actionNames) 0050 { 0051 KActionCollection *coll = actionCollection(); 0052 for (const QString &actionName : actionNames) { 0053 coll->addAction(actionName)->setText(QStringLiteral("Action")); 0054 } 0055 } 0056 0057 // Find a toolbar (created by this guiclient) 0058 KToolBar *toolBarByName(const QString &name) 0059 { 0060 // qDebug() << "containers:" << factory()->containers("ToolBar"); 0061 QWidget *toolBarW = factory()->container(name, this); 0062 if (!toolBarW) { 0063 qWarning() << "No toolbar found with name" << name; 0064 } 0065 Q_ASSERT(toolBarW); 0066 KToolBar *toolBar = qobject_cast<KToolBar *>(toolBarW); 0067 Q_ASSERT(toolBar); 0068 return toolBar; 0069 } 0070 }; 0071 0072 #endif /* TESTGUICLIENT_H */