File indexing completed on 2024-05-12 16:39:56

0001 /* This file is part of the KDE project
0002    Copyright (C) 2012-2013 Jarosław Staniek <staniek@kde.org>
0003 
0004    This program is free software; you can redistribute it and/or
0005    modify it under the terms of the GNU Library General Public
0006    License as published by the Free Software Foundation; either
0007    version 2 of the License, or (at your option) any later version.
0008 
0009    This program is distributed in the hope that it will be useful,
0010    but WITHOUT ANY WARRANTY; without even the implied warranty of
0011    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
0012    Library General Public License for more details.
0013 
0014    You should have received a copy of the GNU Library General Public License
0015    along with this program; see the file COPYING.  If not, write to
0016    the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
0017  * Boston, MA 02110-1301, USA.
0018 */
0019 
0020 #include "KexiTester.h"
0021 
0022 #include <QDebug>
0023 #include <QMap>
0024 #include <QWidget>
0025 
0026 #ifndef COMPILING_TESTS
0027 # undef kexiTester
0028 #endif
0029 
0030 KexiTestObject::KexiTestObject(QObject *object, const QString &name)
0031  : m_object(object), m_name(name)
0032 {
0033 }
0034 
0035 class Q_DECL_HIDDEN KexiTester::Private
0036 {
0037 public:
0038     Private() {}
0039     QMap<QString, QObject*> objects;
0040 };
0041 
0042 KexiTester::KexiTester()
0043     : QObject(), d(new Private)
0044 {
0045 }
0046 
0047 KexiTester::~KexiTester()
0048 {
0049     delete d;
0050 }
0051 
0052 //! @internal
0053 class KexiTesterInternal : public KexiTester
0054 {
0055     Q_OBJECT
0056 public:
0057     KexiTesterInternal() {}
0058     Private* dPtr() { return d; }
0059 };
0060 
0061 Q_GLOBAL_STATIC(KexiTesterInternal, g_kexiTester)
0062 
0063 QObject *KexiTester::object(const QString &name) const
0064 {
0065     return d->objects.value(name);
0066 }
0067 
0068 QWidget *KexiTester::widget(const QString &name) const
0069 {
0070     QObject *o = object(name);
0071     return qobject_cast<QWidget*>(o);
0072 }
0073 
0074 KexiTester& kexiTester()
0075 {
0076     return *g_kexiTester;
0077 }
0078 
0079 KEXIUTILS_EXPORT KexiTester& operator<<(KexiTester& tester, const KexiTestObject &object)
0080 {
0081     if (!object.m_object) {
0082         qWarning() << "No object provided";
0083         return tester;
0084     }
0085     QString realName = object.m_name;
0086     if (realName.isEmpty()) {
0087         realName = object.m_object->objectName();
0088     }
0089     if (realName.isEmpty()) {
0090         qWarning() << "No name for object provided, won't add";
0091         return tester;
0092     }
0093     g_kexiTester->dPtr()->objects.insert(realName, object.m_object);
0094     return tester;
0095 }
0096 
0097 #include "KexiTester.moc"