Remove "All rights reserved" line from license headers.
[profile/ivi/qtdeclarative.git] / src / declarative / qml / qdeclarativecontext.cpp
index d7a6424..709af9e 100644 (file)
@@ -1,8 +1,7 @@
 /****************************************************************************
 **
-** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
-** All rights reserved.
-** Contact: Nokia Corporation (qt-info@nokia.com)
+** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: http://www.qt-project.org/
 **
 ** This file is part of the QtDeclarative module of the Qt Toolkit.
 **
 **
 **
 **
+**
 ** $QT_END_LICENSE$
 **
 ****************************************************************************/
 
 #include "qdeclarativecontext.h"
 #include "qdeclarativecontext_p.h"
+#include "qdeclarativecomponentattached_p.h"
 
 #include "qdeclarativecomponent_p.h"
 #include "qdeclarativeexpression_p.h"
@@ -511,32 +512,24 @@ QObject *QDeclarativeContextPrivate::context_at(QDeclarativeListProperty<QObject
 
 QDeclarativeContextData::QDeclarativeContextData()
 : parent(0), engine(0), isInternal(false), ownedByParent(false), isJSContext(false), 
-  isPragmaLibraryContext(false), publicContext(0), activeVMEData(0), propertyNames(0), contextObject(0),
-  imports(0), childContexts(0), nextChild(0), prevChild(0), expressions(0), contextObjects(0), 
-  contextGuards(0), idValues(0), idValueCount(0), linkedContext(0), componentAttached(0), 
-  v4bindings(0), v8bindings(0)
+  isPragmaLibraryContext(false), unresolvedNames(false), publicContext(0), activeVMEData(0),
+  propertyNames(0), contextObject(0), imports(0), childContexts(0), nextChild(0), prevChild(0),
+  expressions(0), contextObjects(0), contextGuards(0), idValues(0), idValueCount(0), linkedContext(0),
+  componentAttached(0), v4bindings(0), v8bindings(0)
 {
 }
 
 QDeclarativeContextData::QDeclarativeContextData(QDeclarativeContext *ctxt)
 : parent(0), engine(0), isInternal(false), ownedByParent(false), isJSContext(false), 
-  isPragmaLibraryContext(false), publicContext(ctxt), activeVMEData(0), propertyNames(0),
-  contextObject(0), imports(0), childContexts(0), nextChild(0), prevChild(0), expressions(0), 
-  contextObjects(0), contextGuards(0), idValues(0), idValueCount(0), linkedContext(0), 
+  isPragmaLibraryContext(false), unresolvedNames(false), publicContext(ctxt), activeVMEData(0),
+  propertyNames(0), contextObject(0), imports(0), childContexts(0), nextChild(0), prevChild(0),
+  expressions(0), contextObjects(0), contextGuards(0), idValues(0), idValueCount(0), linkedContext(0),
   componentAttached(0), v4bindings(0), v8bindings(0)
 {
 }
 
 void QDeclarativeContextData::invalidate()
 {
-    while (childContexts) {
-        if (childContexts->ownedByParent) {
-            childContexts->destroy();
-        } else {
-            childContexts->invalidate();
-        }
-    }
-
     while (componentAttached) {
         QDeclarativeComponentAttached *a = componentAttached;
         componentAttached = a->next;
@@ -548,6 +541,14 @@ void QDeclarativeContextData::invalidate()
         emit a->destruction();
     }
 
+    while (childContexts) {
+        if (childContexts->ownedByParent) {
+            childContexts->destroy();
+        } else {
+            childContexts->invalidate();
+        }
+    }
+
     if (prevChild) {
         *prevChild = nextChild;
         if (nextChild) nextChild->prevChild = prevChild;
@@ -664,26 +665,31 @@ void QDeclarativeContextData::refreshExpressionsRecursive(QDeclarativeAbstractEx
         expression->refresh();
 }
 
-void QDeclarativeContextData::refreshExpressionsRecursive()
+static inline bool expressions_to_run(QDeclarativeContextData *ctxt, bool isGlobalRefresh)
+{
+    return ctxt->expressions && (!isGlobalRefresh || ctxt->unresolvedNames);
+}
+
+void QDeclarativeContextData::refreshExpressionsRecursive(bool isGlobal)
 {
     // For efficiency, we try and minimize the number of guards we have to create
-    if (expressions && (nextChild || childContexts)) {
+    if (expressions_to_run(this, isGlobal) && (nextChild || childContexts)) {
         QDeclarativeGuardedContextData guard(this);
 
         if (childContexts)
-            childContexts->refreshExpressionsRecursive();
+            childContexts->refreshExpressionsRecursive(isGlobal);
 
         if (guard.isNull()) return;
 
         if (nextChild)
-            nextChild->refreshExpressionsRecursive();
+            nextChild->refreshExpressionsRecursive(isGlobal);
 
         if (guard.isNull()) return;
 
-        if (expressions)
+        if (expressions_to_run(this, isGlobal))
             refreshExpressionsRecursive(expressions);
 
-    } else if (expressions) {
+    } else if (expressions_to_run(this, isGlobal)) {
 
         refreshExpressionsRecursive(expressions);
 
@@ -691,18 +697,18 @@ void QDeclarativeContextData::refreshExpressionsRecursive()
 
         QDeclarativeGuardedContextData guard(this);
 
-        childContexts->refreshExpressionsRecursive();
+        childContexts->refreshExpressionsRecursive(isGlobal);
 
         if (!guard.isNull() && nextChild)
-            nextChild->refreshExpressionsRecursive();
+            nextChild->refreshExpressionsRecursive(isGlobal);
 
     } else if (nextChild) {
 
-        nextChild->refreshExpressionsRecursive();
+        nextChild->refreshExpressionsRecursive(isGlobal);
 
     } else if (childContexts) {
 
-        childContexts->refreshExpressionsRecursive();
+        childContexts->refreshExpressionsRecursive(isGlobal);
 
     }
 }
@@ -712,22 +718,24 @@ void QDeclarativeContextData::refreshExpressionsRecursive()
 // *structure* (not values) changes.
 void QDeclarativeContextData::refreshExpressions()
 {
+    bool isGlobal = (parent == 0);
+
     // For efficiency, we try and minimize the number of guards we have to create
-    if (expressions && childContexts) {
+    if (expressions_to_run(this, isGlobal) && childContexts) {
         QDeclarativeGuardedContextData guard(this);
 
-        childContexts->refreshExpressionsRecursive();
+        childContexts->refreshExpressionsRecursive(isGlobal);
 
-        if (!guard.isNull() && expressions)
+        if (!guard.isNull() && expressions_to_run(this, isGlobal))
             refreshExpressionsRecursive(expressions);
 
-    } else if (expressions) {
+    } else if (expressions_to_run(this, isGlobal)) {
 
         refreshExpressionsRecursive(expressions);
 
     } else if (childContexts) {
 
-        childContexts->refreshExpressionsRecursive();
+        childContexts->refreshExpressionsRecursive(isGlobal);
 
     }
 }