From d76f95d30b1c174323bfca982336d96f3a2cebe2 Mon Sep 17 00:00:00 2001 From: Joona Petrell Date: Thu, 22 Jul 2010 13:23:39 +1000 Subject: Make rootContext and engine pointers in QDeclarativeView API const Task-number: QTBUG-12322 Reviewed-by: Aaron Kennedy (cherry picked from commit 0b83a2161261be525f01359397ab1c8c34827749) --- src/declarative/qml/qdeclarativeengine.cpp | 4 ++-- src/declarative/qml/qdeclarativeengine.h | 2 +- src/declarative/util/qdeclarativeview.cpp | 19 ++++++++++--------- src/declarative/util/qdeclarativeview.h | 4 ++-- 4 files changed, 15 insertions(+), 14 deletions(-) diff --git a/src/declarative/qml/qdeclarativeengine.cpp b/src/declarative/qml/qdeclarativeengine.cpp index 559cad1..a31448f 100644 --- a/src/declarative/qml/qdeclarativeengine.cpp +++ b/src/declarative/qml/qdeclarativeengine.cpp @@ -545,9 +545,9 @@ void QDeclarativeEngine::clearComponentCache() component instances should be added to sub-contexts parented to the root context. */ -QDeclarativeContext *QDeclarativeEngine::rootContext() +QDeclarativeContext *QDeclarativeEngine::rootContext() const { - Q_D(QDeclarativeEngine); + Q_D(const QDeclarativeEngine); return d->rootContext; } diff --git a/src/declarative/qml/qdeclarativeengine.h b/src/declarative/qml/qdeclarativeengine.h index 01487f5..d971d80 100644 --- a/src/declarative/qml/qdeclarativeengine.h +++ b/src/declarative/qml/qdeclarativeengine.h @@ -74,7 +74,7 @@ public: QDeclarativeEngine(QObject *p = 0); virtual ~QDeclarativeEngine(); - QDeclarativeContext *rootContext(); + QDeclarativeContext *rootContext() const; void clearComponentCache(); diff --git a/src/declarative/util/qdeclarativeview.cpp b/src/declarative/util/qdeclarativeview.cpp index 12a8d3a..c3948c1 100644 --- a/src/declarative/util/qdeclarativeview.cpp +++ b/src/declarative/util/qdeclarativeview.cpp @@ -132,7 +132,7 @@ class QDeclarativeViewPrivate : public QGraphicsViewPrivate, public QDeclarative public: QDeclarativeViewPrivate() : root(0), declarativeItemRoot(0), graphicsWidgetRoot(0), component(0), resizeMode(QDeclarativeView::SizeViewToRootObject), initialSize(0,0) {} - ~QDeclarativeViewPrivate() { delete root; } + ~QDeclarativeViewPrivate() { delete root; delete engine; } void execute(); void itemGeometryChanged(QDeclarativeItem *item, const QRectF &newGeometry, const QRectF &oldGeometry); void initResize(); @@ -145,7 +145,7 @@ public: QUrl source; - QDeclarativeEngine engine; + QDeclarativeEngine* engine; QDeclarativeComponent *component; QBasicTimer resizetimer; @@ -170,7 +170,7 @@ void QDeclarativeViewPrivate::execute() component = 0; } if (!source.isEmpty()) { - component = new QDeclarativeComponent(&engine, source, q); + component = new QDeclarativeComponent(engine, source, q); if (!component->isLoading()) { q->continueExecute(); } else { @@ -274,6 +274,7 @@ QDeclarativeView::QDeclarativeView(const QUrl &source, QWidget *parent) void QDeclarativeViewPrivate::init() { Q_Q(QDeclarativeView); + engine = new QDeclarativeEngine(); q->setScene(&scene); q->setOptimizationFlags(QGraphicsView::DontSavePainterState); @@ -337,10 +338,10 @@ QUrl QDeclarativeView::source() const Returns a pointer to the QDeclarativeEngine used for instantiating QML Components. */ -QDeclarativeEngine* QDeclarativeView::engine() +QDeclarativeEngine* QDeclarativeView::engine() const { - Q_D(QDeclarativeView); - return &d->engine; + Q_D(const QDeclarativeView); + return d->engine; } /*! @@ -350,10 +351,10 @@ QDeclarativeEngine* QDeclarativeView::engine() arranged hierarchically and this hierarchy is managed by the QDeclarativeEngine. */ -QDeclarativeContext* QDeclarativeView::rootContext() +QDeclarativeContext* QDeclarativeView::rootContext() const { - Q_D(QDeclarativeView); - return d->engine.rootContext(); + Q_D(const QDeclarativeView); + return d->engine->rootContext(); } /*! diff --git a/src/declarative/util/qdeclarativeview.h b/src/declarative/util/qdeclarativeview.h index cdcf134..d3e4948 100644 --- a/src/declarative/util/qdeclarativeview.h +++ b/src/declarative/util/qdeclarativeview.h @@ -75,8 +75,8 @@ public: QUrl source() const; void setSource(const QUrl&); - QDeclarativeEngine* engine(); - QDeclarativeContext* rootContext(); + QDeclarativeEngine* engine() const; + QDeclarativeContext* rootContext() const; QGraphicsObject *rootObject() const; -- cgit v0.12