2008-11-04 00:08:39 +01:00
|
|
|
/*
|
|
|
|
* Copyright (C) 2008 Gilles CHAUVIN <gcnweb+kde@gmail.com>
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License either version 2, or
|
|
|
|
* (at your option) any later version as published by the Free Software
|
|
|
|
* Foundation.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public
|
|
|
|
* License along with this program; if not, write to the
|
|
|
|
* Free Software Foundation, Inc.,
|
|
|
|
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "testengine.h"
|
|
|
|
|
|
|
|
#include <QtCore/QBitArray>
|
|
|
|
#include <QtCore/QDate>
|
|
|
|
#include <QtCore/QLocale>
|
|
|
|
#include <QtCore/QUrl>
|
2012-02-02 10:35:53 +01:00
|
|
|
#include <QBitmap>
|
|
|
|
#include <QBrush>
|
|
|
|
#include <QCursor>
|
|
|
|
#include <QFont>
|
|
|
|
#include <QIcon>
|
|
|
|
#include <QPalette>
|
|
|
|
#include <QPen>
|
|
|
|
#include <QSizePolicy>
|
|
|
|
#include <QTextFormat>
|
2008-11-04 00:08:39 +01:00
|
|
|
|
|
|
|
Q_DECLARE_METATYPE(TestEngine::MyUserType)
|
|
|
|
|
|
|
|
TestEngine::TestEngine(QObject *parent, const QVariantList &args)
|
|
|
|
: Plasma::DataEngine(parent, args)
|
|
|
|
{
|
|
|
|
} // ctor()
|
|
|
|
|
|
|
|
TestEngine::~TestEngine()
|
|
|
|
{
|
|
|
|
} // dtor()
|
|
|
|
|
|
|
|
void TestEngine::init()
|
|
|
|
{
|
2016-02-29 00:08:05 +01:00
|
|
|
QString dsn(QStringLiteral("TestEngine"));
|
2014-04-26 01:45:47 +02:00
|
|
|
|
2008-11-04 00:08:39 +01:00
|
|
|
// QVariant::Invalid
|
|
|
|
// QVariant::BitArray
|
2016-02-29 00:08:05 +01:00
|
|
|
setData(dsn, QStringLiteral("QBitArray"), QVariant(QBitArray(97, false)));
|
2008-11-04 00:08:39 +01:00
|
|
|
// QVariant::Bitmap
|
2016-02-29 00:08:05 +01:00
|
|
|
setData(dsn, QStringLiteral("QBitmap"), QVariant(QBitmap(12, 57)));
|
2008-11-04 00:08:39 +01:00
|
|
|
// QVariant::Bool
|
2016-02-29 00:08:05 +01:00
|
|
|
setData(dsn, QStringLiteral("bool"), QVariant((bool)true));
|
2008-11-04 00:08:39 +01:00
|
|
|
// QVariant::Brush
|
2016-02-29 00:08:05 +01:00
|
|
|
setData(dsn, QStringLiteral("QBrush"), QVariant(QBrush(Qt::SolidPattern)));
|
2008-11-04 00:08:39 +01:00
|
|
|
// QVariant::ByteArray
|
|
|
|
QByteArray byteArray;
|
2014-04-26 01:45:47 +02:00
|
|
|
for (int i = 0; i < 256; ++i) {
|
2008-11-04 00:08:39 +01:00
|
|
|
byteArray.append(i);
|
|
|
|
}
|
2016-02-29 00:08:05 +01:00
|
|
|
setData(dsn, QStringLiteral("QByteArray1"), QVariant(byteArray));
|
|
|
|
setData(dsn, QStringLiteral("QByteArray2"), QVariant(QByteArray("KDE4")));
|
2008-11-04 00:08:39 +01:00
|
|
|
// QVariant::Char
|
2016-02-29 00:08:05 +01:00
|
|
|
setData(dsn, QStringLiteral("QChar"), QVariant(QChar(0x4B)));
|
2008-11-04 00:08:39 +01:00
|
|
|
// QVariant::Color
|
2016-02-29 00:08:05 +01:00
|
|
|
setData(dsn, QStringLiteral("QColor"), QVariant(QColor("#031337")));
|
2008-11-04 00:08:39 +01:00
|
|
|
// QVariant::Cursor
|
2016-02-29 00:08:05 +01:00
|
|
|
setData(dsn, QStringLiteral("QCursor"), QVariant(QCursor(Qt::ArrowCursor)));
|
2008-11-04 00:08:39 +01:00
|
|
|
// QVariant::Date
|
2016-02-29 00:08:05 +01:00
|
|
|
setData(dsn, QStringLiteral("QDate"), QVariant(QDate(2008, 1, 11)));
|
2008-11-04 00:08:39 +01:00
|
|
|
// QVariant::DateTime
|
2016-02-29 00:08:05 +01:00
|
|
|
setData(dsn, QStringLiteral("QDateTime"), QVariant(QDateTime(QDate(2008, 1, 11), QTime(12, 34, 56))));
|
2008-11-04 00:08:39 +01:00
|
|
|
// QVariant::Double
|
2016-02-29 00:08:05 +01:00
|
|
|
setData(dsn, QStringLiteral("double"), QVariant((double)12.34));
|
2008-11-04 00:08:39 +01:00
|
|
|
// QVariant::Font
|
2016-02-29 00:08:05 +01:00
|
|
|
setData(dsn, QStringLiteral("QFont"), QVariant(QFont()));
|
2008-11-04 00:08:39 +01:00
|
|
|
// QVariant::Icon
|
2016-02-29 00:08:05 +01:00
|
|
|
setData(dsn, QStringLiteral("QIcon"), QVariant(QIcon(QPixmap(12, 34))));
|
2008-11-04 00:08:39 +01:00
|
|
|
// QVariant::Image
|
2016-02-29 00:08:05 +01:00
|
|
|
setData(dsn, QStringLiteral("QImage"), QVariant(QImage(56, 78, QImage::Format_Mono)));
|
2008-11-04 00:08:39 +01:00
|
|
|
// QVariant::Int
|
2016-02-29 00:08:05 +01:00
|
|
|
setData(dsn, QStringLiteral("int"), QVariant((int) - 4321));
|
2008-11-04 00:08:39 +01:00
|
|
|
// QVariant::KeySequence (???)
|
|
|
|
// QVariant::Line
|
2016-02-29 00:08:05 +01:00
|
|
|
setData(dsn, QStringLiteral("QLine"), QVariant(QLine(12, 34, 56, 78)));
|
2008-11-04 00:08:39 +01:00
|
|
|
// QVariant::LineF
|
2016-02-29 00:08:05 +01:00
|
|
|
setData(dsn, QStringLiteral("QLineF"), QVariant(QLineF(1.2, 3.4, 5.6, 7.8)));
|
2008-11-04 00:08:39 +01:00
|
|
|
// QVariant::List
|
|
|
|
QList<QVariant> list;
|
2016-02-29 00:08:05 +01:00
|
|
|
list << QStringLiteral("KDE4") << QBrush() << QPen();
|
|
|
|
setData(dsn, QStringLiteral("QList"), QVariant(list));
|
2008-11-04 00:08:39 +01:00
|
|
|
// QVariant::Locale
|
2016-02-29 00:08:05 +01:00
|
|
|
setData(dsn, QStringLiteral("QLocale"), QVariant(QLocale(QStringLiteral("fr_FR"))));
|
2008-11-04 00:08:39 +01:00
|
|
|
// QVariant::LongLong
|
2016-02-29 00:08:05 +01:00
|
|
|
setData(dsn, QStringLiteral("qlonglong"), QVariant((qlonglong) - 4321));
|
2008-11-04 00:08:39 +01:00
|
|
|
// QVariant::Map
|
|
|
|
QMap<QString, QVariant> map;
|
2014-04-26 01:45:47 +02:00
|
|
|
for (int i = 0; i < 123; ++i) {
|
2016-02-29 00:08:05 +01:00
|
|
|
QString key = QStringLiteral("key%1").arg(i);
|
|
|
|
QString val = QStringLiteral("value%1").arg(i);
|
2008-11-04 00:08:39 +01:00
|
|
|
map[key] = val;
|
|
|
|
}
|
2016-02-29 00:08:05 +01:00
|
|
|
setData(dsn, QStringLiteral("QMap"), QVariant(map));
|
2008-11-04 00:08:39 +01:00
|
|
|
// QVariant::Matrix
|
2016-02-29 00:08:05 +01:00
|
|
|
setData(dsn, QStringLiteral("QMatrix"), QVariant(QMatrix()));
|
2008-11-04 00:08:39 +01:00
|
|
|
// QVariant::Transform
|
2016-02-29 00:08:05 +01:00
|
|
|
setData(dsn, QStringLiteral("QTransform"), QVariant(QTransform()));
|
2008-11-04 00:08:39 +01:00
|
|
|
// QVariant::Palette
|
2016-02-29 00:08:05 +01:00
|
|
|
setData(dsn, QStringLiteral("QPalette"), QVariant(QPalette()));
|
2008-11-04 00:08:39 +01:00
|
|
|
// QVariant::Pen
|
2016-02-29 00:08:05 +01:00
|
|
|
setData(dsn, QStringLiteral("QPen"), QVariant(QPen(Qt::SolidLine)));
|
2008-11-04 00:08:39 +01:00
|
|
|
// QVariant::Pixmap
|
2016-02-29 00:08:05 +01:00
|
|
|
setData(dsn, QStringLiteral("QPixmap"), QVariant(QPixmap(12, 34)));
|
2008-11-04 00:08:39 +01:00
|
|
|
// QVariant::Point
|
2016-02-29 00:08:05 +01:00
|
|
|
setData(dsn, QStringLiteral("QPoint"), QVariant(QPoint(12, 34)));
|
2008-11-04 00:08:39 +01:00
|
|
|
// QVariant::PointArray (obsoloted in Qt4, see QPolygon)
|
|
|
|
// QVariant::PointF
|
2016-02-29 00:08:05 +01:00
|
|
|
setData(dsn, QStringLiteral("QPointF"), QVariant(QPointF(12.34, 56.78)));
|
2008-11-04 00:08:39 +01:00
|
|
|
// QVariant::Polygon
|
2016-02-29 00:08:05 +01:00
|
|
|
setData(dsn, QStringLiteral("QPolygon"), QVariant(QPolygon(42)));
|
2008-11-04 00:08:39 +01:00
|
|
|
// QVariant::Rect
|
2016-02-29 00:08:05 +01:00
|
|
|
setData(dsn, QStringLiteral("QRect"), QVariant(QRect(12, 34, 56, 78)));
|
2008-11-04 00:08:39 +01:00
|
|
|
// QVariant::RectF
|
2016-02-29 00:08:05 +01:00
|
|
|
setData(dsn, QStringLiteral("QRectF"), QVariant(QRectF(1.2, 3.4, 5.6, 7.8)));
|
2008-11-04 00:08:39 +01:00
|
|
|
// QVariant::RegExp
|
2017-12-02 15:12:40 +01:00
|
|
|
setData(dsn, QStringLiteral("QRegExp"), QVariant(QRegExp(QStringLiteral("^KDE4$"))));
|
2008-11-04 00:08:39 +01:00
|
|
|
// QVariant::Region
|
2016-02-29 00:08:05 +01:00
|
|
|
setData(dsn, QStringLiteral("QRegion"), QVariant(QRegion(10, 20, 30, 40)));
|
2008-11-04 00:08:39 +01:00
|
|
|
// QVariant::Size
|
2016-02-29 00:08:05 +01:00
|
|
|
setData(dsn, QStringLiteral("QSize"), QVariant(QSize(12, 34)));
|
2008-11-04 00:08:39 +01:00
|
|
|
// QVariant::SizeF
|
2016-02-29 00:08:05 +01:00
|
|
|
setData(dsn, QStringLiteral("QSizeF"), QVariant(QSizeF(12.34, 56.78)));
|
2008-11-04 00:08:39 +01:00
|
|
|
// QVariant::SizePolicy
|
2016-02-29 00:08:05 +01:00
|
|
|
setData(dsn, QStringLiteral("QSizePolicy"), QVariant(QSizePolicy()));
|
2008-11-04 00:08:39 +01:00
|
|
|
// QVariant::String
|
2016-02-29 00:08:05 +01:00
|
|
|
setData(dsn, QStringLiteral("QString"), QVariant(QStringLiteral("KDE4 ROCKS!")));
|
2008-11-04 00:08:39 +01:00
|
|
|
// QVariant::StringList
|
|
|
|
QStringList stringList;
|
2016-02-29 00:08:05 +01:00
|
|
|
stringList << QStringLiteral("K") << QStringLiteral("D") << QStringLiteral("E") << QStringLiteral("4");
|
|
|
|
setData(dsn, QStringLiteral("QStringList"), QVariant(stringList));
|
2008-11-04 00:08:39 +01:00
|
|
|
// QVariant::TextFormat
|
2016-02-29 00:08:05 +01:00
|
|
|
setData(dsn, QStringLiteral("QTextFormat"), QVariant(QTextFormat()));
|
2008-11-04 00:08:39 +01:00
|
|
|
// QVariant::TextLength
|
2016-02-29 00:08:05 +01:00
|
|
|
setData(dsn, QStringLiteral("QTextLength"), QVariant(QTextLength()));
|
2008-11-04 00:08:39 +01:00
|
|
|
// QVariant::Time
|
2016-02-29 00:08:05 +01:00
|
|
|
setData(dsn, QStringLiteral("QTime"), QVariant(QTime(12, 34, 56)));
|
2008-11-04 00:08:39 +01:00
|
|
|
// QVariant::UInt
|
2016-02-29 00:08:05 +01:00
|
|
|
setData(dsn, QStringLiteral("uint"), QVariant((uint)4321));
|
2008-11-04 00:08:39 +01:00
|
|
|
// QVariant::ULongLong
|
2016-02-29 00:08:05 +01:00
|
|
|
setData(dsn, QStringLiteral("qulonglong"), QVariant((qulonglong)4321));
|
2008-11-04 00:08:39 +01:00
|
|
|
// QVariant::Url
|
2016-02-29 00:08:05 +01:00
|
|
|
setData(dsn, QStringLiteral("QUrl"), QVariant(QUrl(QStringLiteral("http://user:password@example.com:80/test.php?param1=foo¶m2=bar"))));
|
2008-11-04 00:08:39 +01:00
|
|
|
// QVariant::UserType
|
|
|
|
MyUserType userType;
|
|
|
|
QVariant v;
|
|
|
|
v.setValue(userType);
|
2016-02-29 00:08:05 +01:00
|
|
|
setData(dsn, QStringLiteral("UserType"), v);
|
2008-11-04 00:08:39 +01:00
|
|
|
} // init()
|
|
|
|
|
|
|
|
bool TestEngine::sourceRequestEvent(const QString &source)
|
|
|
|
{
|
|
|
|
// Nothing to do...
|
|
|
|
Q_UNUSED(source)
|
|
|
|
return true;
|
|
|
|
} // sourceRequestEvent()
|
|
|
|
|
2014-04-25 13:21:09 +02:00
|
|
|
K_EXPORT_PLASMA_DATAENGINE_WITH_JSON(org.kde.examples.plasma_engine_testengine, TestEngine, "plasma-dataengine-testengine.desktop")
|
2008-11-04 00:08:39 +01:00
|
|
|
|
2014-04-25 13:21:09 +02:00
|
|
|
#include "testengine.moc"
|