Clear stringCache explicitly instead of asserting its emptiness.
authorDmitry Volosnykh <dmitry.volosnykh@gmail.com>
Thu, 21 May 2015 07:52:49 +0000 (10:52 +0300)
committerDmitry Volosnykh <dmitry.volosnykh@gmail.com>
Thu, 25 Jun 2015 21:51:21 +0000 (21:51 +0000)
This assumption does not hold when PathView's path.pathElements list is
updated with new contents at runtime.

Task-number: QTBUG-46255
Change-Id: I6b0d7ee8ee2d67ca0138eacdf0ad221338f788e4
Reviewed-by: Alan Alpert <aalpert@blackberry.com>
src/qml/qml/qqmlpropertycache.cpp
tests/auto/qml/qml.pro
tests/auto/qml/qqmlopenmetaobject/qqmlopenmetaobject.pro [new file with mode: 0644]
tests/auto/qml/qqmlopenmetaobject/tst_qqmlopenmetaobject.cpp [new file with mode: 0644]
tests/auto/quick/qquickpathview/data/customAttribute.qml [new file with mode: 0644]
tests/auto/quick/qquickpathview/tst_qquickpathview.cpp

index 168d038f9e5b3e406b79e18d1fcb426b4f794326..294f3ccdf9beed658076c4de2652fd0e46dce20b 100644 (file)
@@ -837,7 +837,7 @@ void QQmlPropertyCache::updateRecur(const QMetaObject *metaObject)
 void QQmlPropertyCache::update(const QMetaObject *metaObject)
 {
     Q_ASSERT(metaObject);
-    Q_ASSERT(stringCache.isEmpty());
+    stringCache.clear();
 
     // Preallocate enough space in the index caches for all the properties/methods/signals that
     // are not cached in a parent cache so that the caches never need to be reallocated as this
@@ -862,7 +862,6 @@ void QQmlPropertyCache::update(const QMetaObject *metaObject)
 */
 void QQmlPropertyCache::invalidate(const QMetaObject *metaObject)
 {
-    stringCache.clear();
     propertyIndexCache.clear();
     methodIndexCache.clear();
     signalHandlerIndexCache.clear();
index d9d31ae2679cb8f3e67fa05ef68e66fd759f1b1e..6f1bea6d9291802aad54894fb6ea3a7d61ae90f2 100644 (file)
@@ -36,6 +36,7 @@ PRIVATETESTS += \
     qqmldirparser \
     qqmlglobal \
     qqmllanguage \
+    qqmlopenmetaobject \
     qqmlproperty \
     qqmlpropertycache \
     qqmlpropertymap \
diff --git a/tests/auto/qml/qqmlopenmetaobject/qqmlopenmetaobject.pro b/tests/auto/qml/qqmlopenmetaobject/qqmlopenmetaobject.pro
new file mode 100644 (file)
index 0000000..c81394e
--- /dev/null
@@ -0,0 +1,9 @@
+CONFIG += testcase
+TARGET = tst_qqmlopenmetaobject
+osx:CONFIG -= app_bundle
+
+SOURCES += tst_qqmlopenmetaobject.cpp
+
+CONFIG += parallel_test
+QT += core-private gui-private qml-private testlib
+DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0
diff --git a/tests/auto/qml/qqmlopenmetaobject/tst_qqmlopenmetaobject.cpp b/tests/auto/qml/qqmlopenmetaobject/tst_qqmlopenmetaobject.cpp
new file mode 100644 (file)
index 0000000..429f45b
--- /dev/null
@@ -0,0 +1,69 @@
+/****************************************************************************
+**
+** Copyright (C) 2015 The Qt Company Ltd.
+** Contact: http://www.qt.io/licensing/
+**
+** This file is part of the test suite of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL21$
+** Commercial License Usage
+** Licensees holding valid commercial Qt licenses may use this file in
+** accordance with the commercial license agreement provided with the
+** Software or, alternatively, in accordance with the terms contained in
+** a written agreement between you and The Qt Company. For licensing terms
+** and conditions see http://www.qt.io/terms-conditions. For further
+** information use the contact form at http://www.qt.io/contact-us.
+**
+** 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 or version 3 as published by the Free
+** Software Foundation and appearing in the file LICENSE.LGPLv21 and
+** LICENSE.LGPLv3 included in the packaging of this file. Please review the
+** following information to ensure the GNU Lesser General Public License
+** requirements will be met: https://www.gnu.org/licenses/lgpl.html and
+** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** As a special exception, The Qt Company gives you certain additional
+** rights. These rights are described in The Qt Company LGPL Exception
+** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <qtest.h>
+#include <private/qqmlopenmetaobject_p.h>
+#include <QtQml/qqmlengine.h>
+
+class tst_qqmlopenmetaobject : public QObject
+{
+    Q_OBJECT
+public:
+    tst_qqmlopenmetaobject() {}
+
+private slots:
+    void createProperties();
+};
+
+class CustomObject: public QObject
+{
+    Q_OBJECT
+public:
+    CustomObject(QObject *parent = 0)
+        : QObject(parent) {}
+};
+
+void tst_qqmlopenmetaobject::createProperties()
+{
+    QQmlEngine engine;
+    CustomObject object;
+    const QQmlRefPointer<QQmlOpenMetaObjectType> mot = new QQmlOpenMetaObjectType(object.metaObject(), &engine);
+    QQmlOpenMetaObject *const mo = new QQmlOpenMetaObject(&object, mot);
+    mo->setCached(true);
+    mot->createProperty("customProperty");
+    QVERIFY(true);
+}
+
+QTEST_MAIN(tst_qqmlopenmetaobject)
+
+#include "tst_qqmlopenmetaobject.moc"
diff --git a/tests/auto/quick/qquickpathview/data/customAttribute.qml b/tests/auto/quick/qquickpathview/data/customAttribute.qml
new file mode 100644 (file)
index 0000000..bd4c9fd
--- /dev/null
@@ -0,0 +1,58 @@
+import QtQuick 2.4
+
+PathView {
+    width: 200
+    height: 600
+
+    pathItemCount: 7
+
+    model: ListModel {
+        ListElement { color: "salmon" }
+        ListElement { color: "seagreen" }
+        ListElement { color: "navy" }
+        ListElement { color: "goldenrod" }
+    }
+    path: Path {
+        startX: width / 2; startY: -100
+        PathAttribute { name: "BEGIN" }
+
+        PathLine { relativeX: 0; y: height / 2 }
+        PathAttribute { name: "BEGIN" }
+
+        PathLine { relativeX: 0; y: height + 100 }
+        PathAttribute { name: "BEGIN" }
+    }
+    delegate: Rectangle {
+        width: 200
+        height: 200
+        color: model.color
+        opacity: PathView.transparency
+    }
+
+    Component {
+        id: attributeComponent
+        PathAttribute {}
+    }
+
+    function addAttribute(name, values) {
+        var valueIndex = 0
+        var elements = []
+        for (var i = 0; i < path.pathElements.length; ++i) {
+            elements.push(path.pathElements[i])
+
+            if (path.pathElements[i].name === "BEGIN") {
+                if (values[valueIndex] !== undefined) {
+                    var attribute = attributeComponent.createObject(this, { "name": name, "value": values[valueIndex] })
+                    elements.push(attribute)
+                }
+                ++valueIndex
+            }
+        }
+
+        console.log("??")
+        path.pathElements = elements
+        console.log("!!")
+    }
+
+    Component.onCompleted: addAttribute("transparency", [0, 1, 0])
+}
index 0910f6cb2e434d223fac5e495ec19e476f36e695..5636b312af8b2cff589b83a1f1c0c0a56029fcde 100644 (file)
@@ -141,6 +141,7 @@ private slots:
     void flickableDelegate();
     void jsArrayChange();
     void qtbug42716();
+    void addCustomAttribute();
 };
 
 class TestObject : public QObject
@@ -2371,6 +2372,13 @@ void tst_QQuickPathView::qtbug42716()
     QVERIFY(!itemMiss);
 }
 
+void tst_QQuickPathView::addCustomAttribute()
+{
+    const QScopedPointer<QQuickView> window(createView());
+    window->setSource(testFileUrl("customAttribute.qml"));
+    window->show();
+}
+
 QTEST_MAIN(tst_QQuickPathView)
 
 #include "tst_qquickpathview.moc"