Debugger: Create InspectorService only when debugging is enabled
[profile/ivi/qtdeclarative.git] / src / declarative / items / qsgview.cpp
index 1169c59..841c8eb 100644 (file)
@@ -1,4 +1,3 @@
-// Commit: 55c4d94dfea78951f3371d3697a3cb28539b3012
 /****************************************************************************
 **
 ** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
@@ -8,29 +7,29 @@
 ** This file is part of the QtDeclarative module of the Qt Toolkit.
 **
 ** $QT_BEGIN_LICENSE:LGPL$
-** No Commercial Usage
-** This file contains pre-release code and may not be distributed.
-** You may use this file in accordance with the terms and conditions
-** contained in the Technology Preview License Agreement accompanying
-** this package.
-**
 ** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 2.1 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL included in the
-** packaging of this file.  Please review the following information to
-** ensure the GNU Lesser General Public License version 2.1 requirements
-** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+** This file may be used under the terms of the GNU Lesser General Public
+** License version 2.1 as published by the Free Software Foundation and
+** appearing in the file LICENSE.LGPL included in the packaging of this
+** file. Please review the following information to ensure the GNU Lesser
+** General Public License version 2.1 requirements will be met:
+** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
 **
 ** In addition, as a special exception, Nokia gives you certain additional
-** rights.  These rights are described in the Nokia Qt LGPL Exception
+** rights. These rights are described in the Nokia Qt LGPL Exception
 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
 **
-** If you have questions regarding the use of this file, please contact
-** Nokia at qt-info@nokia.com.
-**
-**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU General
+** Public License version 3.0 as published by the Free Software Foundation
+** and appearing in the file LICENSE.GPL included in the packaging of this
+** file. Please review the following information to ensure the GNU General
+** Public License version 3.0 requirements will be met:
+** http://www.gnu.org/copyleft/gpl.html.
 **
+** Other Usage
+** Alternatively, this file may be used in accordance with the terms and
+** conditions contained in a signed written agreement between you and Nokia.
 **
 **
 **
 ****************************************************************************/
 
 #include "qsgview.h"
+#include "qsgview_p.h"
 
 #include "qsgcanvas_p.h"
 #include "qsgitem_p.h"
 #include "qsgitemchangelistener_p.h"
 
 #include <private/qdeclarativedebugtrace_p.h>
+#include <private/qdeclarativeinspectorservice_p.h>
 
 #include <QtDeclarative/qdeclarativeengine.h>
 #include <private/qdeclarativeengine_p.h>
 #include <QtCore/qbasictimer.h>
 
-// XXX todo - This whole class should probably be merged with QDeclarativeView for 
+
+// XXX todo - This whole class should probably be merged with QDeclarativeView for
 // maximum seamlessness
 QT_BEGIN_NAMESPACE
 
 DEFINE_BOOL_CONFIG_OPTION(frameRateDebug, QML_SHOW_FRAMERATE)
 
-class QSGViewPrivate : public QSGCanvasPrivate, 
-                       public QSGItemChangeListener
+void QSGViewPrivate::init()
 {
-    Q_DECLARE_PUBLIC(QSGView)
-public:
-    QSGViewPrivate();
-    ~QSGViewPrivate();
-
-    void execute();
-    void itemGeometryChanged(QSGItem *item, const QRectF &newGeometry, const QRectF &oldGeometry);
-    void initResize();
-    void updateSize();
-    void setRootObject(QObject *);
-
-    void init();
-
-    QSize rootObjectSize() const;
-
-    QPointer<QSGItem> root;
-
-    QUrl source;
+    Q_Q(QSGView);
 
-    QDeclarativeEngine engine;
-    QDeclarativeComponent *component;
-    QBasicTimer resizetimer;
+    QDeclarativeEnginePrivate::get(&engine)->sgContext = QSGCanvasPrivate::context;
 
-    QSGView::ResizeMode resizeMode;
-    QSize initialSize;
-    QElapsedTimer frameTimer;
-};
+    engine.setIncubationController(q->incubationController());
 
-void QSGViewPrivate::init()
-{
-    q_func()->setSizePolicy(QSizePolicy::Preferred,QSizePolicy::Preferred);
-    QDeclarativeEnginePrivate::get(&engine)->sgContext = QSGCanvasPrivate::context;
+    if (QDeclarativeDebugService::isDebuggingEnabled())
+        QDeclarativeInspectorService::instance()->addView(q);
 }
 
 QSGViewPrivate::QSGViewPrivate()
-: root(0), component(0), resizeMode(QSGView::SizeViewToRootObject), initialSize(0,0) 
+    : root(0), component(0), resizeMode(QSGView::SizeViewToRootObject), initialSize(0,0), resized(false)
 {
 }
 
-QSGViewPrivate::~QSGViewPrivate() 
-{ 
-    delete root; 
+QSGViewPrivate::~QSGViewPrivate()
+{
+    if (QDeclarativeDebugService::isDebuggingEnabled())
+        QDeclarativeInspectorService::instance()->removeView(q_func());
+
+    delete root;
 }
 
 void QSGViewPrivate::execute()
@@ -121,7 +101,7 @@ void QSGViewPrivate::execute()
         if (!component->isLoading()) {
             q->continueExecute();
         } else {
-            QObject::connect(component, SIGNAL(statusChanged(QDeclarativeComponent::Status)), 
+            QObject::connect(component, SIGNAL(statusChanged(QDeclarativeComponent::Status)),
                              q, SLOT(continueExecute()));
         }
     }
@@ -137,28 +117,17 @@ void QSGViewPrivate::itemGeometryChanged(QSGItem *resizeItem, const QRectF &newG
     QSGItemChangeListener::itemGeometryChanged(resizeItem, newGeometry, oldGeometry);
 }
 
-QSGView::QSGView(QWidget *parent, Qt::WindowFlags f)
-: QSGCanvas(*(new QSGViewPrivate), parent, f)
-{
-    d_func()->init();
-}
-
-QSGView::QSGView(const QGLFormat &format, QWidget *parent, Qt::WindowFlags f)
-: QSGCanvas(*(new QSGViewPrivate), format, parent, f)
-{
-    d_func()->init();
-}
-
-QSGView::QSGView(const QUrl &source, QWidget *parent, Qt::WindowFlags f)
-: QSGCanvas(*(new QSGViewPrivate), parent, f)
+QSGView::QSGView(QWindow *parent, Qt::WindowFlags f)
+: QSGCanvas(*(new QSGViewPrivate), parent)
 {
+    setWindowFlags(f);
     d_func()->init();
-    setSource(source);
 }
 
-QSGView::QSGView(const QUrl &source, const QGLFormat &format, QWidget *parent, Qt::WindowFlags f)
-: QSGCanvas(*(new QSGViewPrivate), format, parent, f)
+QSGView::QSGView(const QUrl &source, QWindow *parent, Qt::WindowFlags f)
+: QSGCanvas(*(new QSGViewPrivate), parent)
 {
+    setWindowFlags(f);
     d_func()->init();
     setSource(source);
 }
@@ -256,8 +225,6 @@ void QSGViewPrivate::updateSize()
         if (!qFuzzyCompare(q->height(), root->height()))
             root->setHeight(q->height());
     }
-
-    q->updateGeometry();
 }
 
 QSize QSGViewPrivate::rootObjectSize() const
@@ -303,7 +270,7 @@ void QSGView::continueExecute()
 
     QObject *obj = d->component->create();
 
-    if(d->component->isError()) {
+    if (d->component->isError()) {
         QList<QDeclarativeError> errorList = d->component->errors();
         foreach (const QDeclarativeError &error, errorList) {
             qWarning() << error;
@@ -344,13 +311,13 @@ void QSGViewPrivate::setRootObject(QObject *obj)
         delete obj;
         root = 0;
     }
-
     if (root) {
         initialSize = rootObjectSize();
-        if (initialSize != q->size()) {
-            if (!(q->parentWidget() && q->parentWidget()->layout())) {
-                q->resize(initialSize);
-            }
+        if ((resizeMode == QSGView::SizeViewToRootObject || !resized) // ### refactor:  || !q->testAttribute(Qt::WA_Resized)
+             && initialSize != q->size()) {
+
+            q->resize(initialSize);
+            resized = true;
         }
         initResize();
     }
@@ -405,26 +372,10 @@ QSGItem *QSGView::rootObject() const
 void QSGView::resizeEvent(QResizeEvent *e)
 {
     Q_D(QSGView);
-    if (d->resizeMode == SizeRootObjectToView) 
+    if (d->resizeMode == SizeRootObjectToView)
         d->updateSize();
-    
-    QSGCanvas::resizeEvent(e);
-}
-
-/*!
-    \internal
-*/
-void QSGView::paintEvent(QPaintEvent *event)
-{
-    Q_D(QSGView);
-    int time = 0;
-    if (frameRateDebug()) 
-        time = d->frameTimer.restart();
 
-    QSGCanvas::paintEvent(event);
-
-    if (frameRateDebug())
-        qDebug() << "paintEvent:" << d->frameTimer.elapsed() << "time since last frame:" << time;
+    QSGCanvas::resizeEvent(e);
 }
 
 void QSGView::keyPressEvent(QKeyEvent *e)