qmltime: Remove widgets dependency.
To do this easily while retaining the meaning of the -parent flag, we add a private export to QQuickView so that we can set the root object. Change-Id: Iabb2b998816a6fdfcc8417f679c96f04910b8202 Reviewed-by: Simon Hausmann <simon.hausmann@theqtcompany.com> Reviewed-by: Shawn Rutledge <shawn.rutledge@theqtcompany.com> Reviewed-by: Michael Brasser <michael.brasser@live.com>
This commit is contained in:
parent
a05f3ee00c
commit
4c065b497e
|
@ -70,7 +70,7 @@ class QQmlError;
|
||||||
class QQuickItem;
|
class QQuickItem;
|
||||||
class QQmlComponent;
|
class QQmlComponent;
|
||||||
|
|
||||||
class QQuickViewPrivate : public QQuickWindowPrivate,
|
class Q_QUICK_PRIVATE_EXPORT QQuickViewPrivate : public QQuickWindowPrivate,
|
||||||
public QQuickItemChangeListener
|
public QQuickItemChangeListener
|
||||||
{
|
{
|
||||||
Q_DECLARE_PUBLIC(QQuickView)
|
Q_DECLARE_PUBLIC(QQuickView)
|
||||||
|
|
|
@ -33,11 +33,13 @@
|
||||||
#include <QQmlEngine>
|
#include <QQmlEngine>
|
||||||
#include <QQmlComponent>
|
#include <QQmlComponent>
|
||||||
#include <QDebug>
|
#include <QDebug>
|
||||||
#include <QApplication>
|
#include <QGuiApplication>
|
||||||
#include <QTime>
|
#include <QTime>
|
||||||
#include <QQmlContext>
|
#include <QQmlContext>
|
||||||
#include <QGraphicsScene>
|
#include <QQuickView>
|
||||||
#include <QGraphicsRectItem>
|
#include <QQuickItem>
|
||||||
|
|
||||||
|
#include <private/qquickview_p.h>
|
||||||
|
|
||||||
class Timer : public QObject
|
class Timer : public QObject
|
||||||
{
|
{
|
||||||
|
@ -64,22 +66,22 @@ private:
|
||||||
static Timer *m_timer;
|
static Timer *m_timer;
|
||||||
|
|
||||||
bool m_willparent;
|
bool m_willparent;
|
||||||
QGraphicsScene m_scene;
|
QQuickView m_view;
|
||||||
QGraphicsRectItem m_item;
|
QQuickItem *m_item;
|
||||||
};
|
};
|
||||||
QML_DECLARE_TYPE(Timer);
|
QML_DECLARE_TYPE(Timer);
|
||||||
|
|
||||||
Timer *Timer::m_timer = 0;
|
Timer *Timer::m_timer = 0;
|
||||||
|
|
||||||
Timer::Timer()
|
Timer::Timer()
|
||||||
: m_component(0), m_willparent(false)
|
: m_component(0)
|
||||||
|
, m_willparent(false)
|
||||||
|
, m_item(new QQuickItem)
|
||||||
{
|
{
|
||||||
if (m_timer)
|
if (m_timer)
|
||||||
qWarning("Timer: Timer already registered");
|
qWarning("Timer: Timer already registered");
|
||||||
|
QQuickViewPrivate::get(&m_view)->setRootObject(m_item);
|
||||||
m_timer = this;
|
m_timer = this;
|
||||||
|
|
||||||
m_scene.setItemIndexMethod(QGraphicsScene::NoIndex);
|
|
||||||
m_scene.addItem(&m_item);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
QQmlComponent *Timer::component() const
|
QQmlComponent *Timer::component() const
|
||||||
|
@ -102,9 +104,9 @@ void Timer::run(uint iterations)
|
||||||
QQmlContext context(qmlContext(this));
|
QQmlContext context(qmlContext(this));
|
||||||
|
|
||||||
QObject *o = m_component->create(&context);
|
QObject *o = m_component->create(&context);
|
||||||
QGraphicsObject *go = qobject_cast<QGraphicsObject *>(o);
|
QQuickItem *i = qobject_cast<QQuickItem *>(o);
|
||||||
if (m_willparent && go)
|
if (m_willparent && i)
|
||||||
go->setParentItem(&m_item);
|
i->setParentItem(m_item);
|
||||||
delete o;
|
delete o;
|
||||||
|
|
||||||
runTest(&context, iterations);
|
runTest(&context, iterations);
|
||||||
|
@ -126,9 +128,9 @@ void Timer::runTest(QQmlContext *context, uint iterations)
|
||||||
t.start();
|
t.start();
|
||||||
for (uint ii = 0; ii < iterations; ++ii) {
|
for (uint ii = 0; ii < iterations; ++ii) {
|
||||||
QObject *o = m_component->create(context);
|
QObject *o = m_component->create(context);
|
||||||
QGraphicsObject *go = qobject_cast<QGraphicsObject *>(o);
|
QQuickItem *i = qobject_cast<QQuickItem *>(o);
|
||||||
if (m_willparent && go)
|
if (m_willparent && i)
|
||||||
go->setParentItem(&m_item);
|
i->setParentItem(m_item);
|
||||||
delete o;
|
delete o;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -207,7 +209,7 @@ void usage(const char *name)
|
||||||
|
|
||||||
int main(int argc, char ** argv)
|
int main(int argc, char ** argv)
|
||||||
{
|
{
|
||||||
QApplication app(argc, argv);
|
QGuiApplication app(argc, argv);
|
||||||
|
|
||||||
qmlRegisterType<Timer>("QmlTime", 1, 0, "Timer");
|
qmlRegisterType<Timer>("QmlTime", 1, 0, "Timer");
|
||||||
|
|
||||||
|
|
|
@ -1,7 +1,8 @@
|
||||||
CONFIG += testcase
|
CONFIG += testcase
|
||||||
TEMPLATE = app
|
TEMPLATE = app
|
||||||
TARGET = qmltime
|
TARGET = qmltime
|
||||||
QT += qml widgets testlib
|
QT += qml testlib quick
|
||||||
|
QT += quick-private
|
||||||
macx:CONFIG -= app_bundle
|
macx:CONFIG -= app_bundle
|
||||||
|
|
||||||
SOURCES += qmltime.cpp
|
SOURCES += qmltime.cpp
|
||||||
|
|
Loading…
Reference in New Issue