aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/declarative/items/qsgitemview.cpp4
-rw-r--r--src/declarative/items/qsglistview.cpp4
-rw-r--r--src/declarative/items/qsgvisualdatamodel.cpp4
-rw-r--r--tests/auto/declarative/qsggridview/data/ComponentView.qml14
-rw-r--r--tests/auto/declarative/qsggridview/data/creationContext.qml5
-rw-r--r--tests/auto/declarative/qsggridview/tst_qsggridview.cpp24
-rw-r--r--tests/auto/declarative/qsglistview/data/ComponentView.qml16
-rw-r--r--tests/auto/declarative/qsglistview/data/creationContext.qml5
-rw-r--r--tests/auto/declarative/qsglistview/tst_qsglistview.cpp24
-rw-r--r--tests/auto/declarative/qsgpathview/data/ComponentView.qml17
-rw-r--r--tests/auto/declarative/qsgpathview/data/creationContext.qml5
-rw-r--r--tests/auto/declarative/qsgpathview/tst_qsgpathview.cpp16
12 files changed, 133 insertions, 5 deletions
diff --git a/src/declarative/items/qsgitemview.cpp b/src/declarative/items/qsgitemview.cpp
index b34ed8227a..9415f9eda9 100644
--- a/src/declarative/items/qsgitemview.cpp
+++ b/src/declarative/items/qsgitemview.cpp
@@ -1624,7 +1624,9 @@ QSGItem *QSGItemViewPrivate::createComponentItem(QDeclarativeComponent *componen
QSGItem *item = 0;
if (component) {
- QDeclarativeContext *context = new QDeclarativeContext(qmlContext(q));
+ QDeclarativeContext *creationContext = component->creationContext();
+ QDeclarativeContext *context = new QDeclarativeContext(
+ creationContext ? creationContext : qmlContext(q));
QObject *nobj = component->create(context);
if (nobj) {
QDeclarative_setParent_noEvent(context, nobj);
diff --git a/src/declarative/items/qsglistview.cpp b/src/declarative/items/qsglistview.cpp
index 7f9ce3ac8b..beeeda45e9 100644
--- a/src/declarative/items/qsglistview.cpp
+++ b/src/declarative/items/qsglistview.cpp
@@ -832,7 +832,9 @@ QSGItem * QSGListViewPrivate::getSectionItem(const QString &section)
QDeclarativeContext *context = QDeclarativeEngine::contextForObject(sectionItem)->parentContext();
context->setContextProperty(QLatin1String("section"), section);
} else {
- QDeclarativeContext *context = new QDeclarativeContext(qmlContext(q));
+ QDeclarativeContext *creationContext = sectionCriteria->delegate()->creationContext();
+ QDeclarativeContext *context = new QDeclarativeContext(
+ creationContext ? creationContext : qmlContext(q));
context->setContextProperty(QLatin1String("section"), section);
QObject *nobj = sectionCriteria->delegate()->beginCreate(context);
if (nobj) {
diff --git a/src/declarative/items/qsgvisualdatamodel.cpp b/src/declarative/items/qsgvisualdatamodel.cpp
index f5c86b8faf..e0d353a93f 100644
--- a/src/declarative/items/qsgvisualdatamodel.cpp
+++ b/src/declarative/items/qsgvisualdatamodel.cpp
@@ -939,7 +939,9 @@ QObject *QSGVisualDataModelPrivate::object(Compositor::Group group, int index, b
if (!cacheItem->object) {
QObject *data = m_adaptorModel->data(it.modelIndex());
- QDeclarativeContext *rootContext = new QDeclarativeContext(m_context);
+ QDeclarativeContext *creationContext = m_delegate->creationContext();
+ QDeclarativeContext *rootContext = new QDeclarativeContext(
+ creationContext ? creationContext : m_context.data());
QDeclarativeContext *ctxt = rootContext;
if (m_adaptorModel->flags() & QSGVisualAdaptorModel::ProxiedObject) {
if (QSGVisualAdaptorModelProxyInterface *proxy = qobject_cast<QSGVisualAdaptorModelProxyInterface *>(data)) {
diff --git a/tests/auto/declarative/qsggridview/data/ComponentView.qml b/tests/auto/declarative/qsggridview/data/ComponentView.qml
new file mode 100644
index 0000000000..12ab6c92d1
--- /dev/null
+++ b/tests/auto/declarative/qsggridview/data/ComponentView.qml
@@ -0,0 +1,14 @@
+import QtQuick 2.0
+
+GridView {
+ id: view
+
+ property string title
+
+ width: 100; height: 100;
+
+ model: 1
+ delegate: Text { objectName: "listItem"; text: view.title }
+ header: Text { objectName: "header"; text: view.title }
+ footer: Text { objectName: "footer"; text: view.title }
+}
diff --git a/tests/auto/declarative/qsggridview/data/creationContext.qml b/tests/auto/declarative/qsggridview/data/creationContext.qml
new file mode 100644
index 0000000000..79a682788b
--- /dev/null
+++ b/tests/auto/declarative/qsggridview/data/creationContext.qml
@@ -0,0 +1,5 @@
+import QtQuick 2.0
+
+ComponentView {
+ title: "Hello!"
+}
diff --git a/tests/auto/declarative/qsggridview/tst_qsggridview.cpp b/tests/auto/declarative/qsggridview/tst_qsggridview.cpp
index 24471e901f..a5b7c5b70d 100644
--- a/tests/auto/declarative/qsggridview/tst_qsggridview.cpp
+++ b/tests/auto/declarative/qsggridview/tst_qsggridview.cpp
@@ -64,7 +64,7 @@ class tst_QSGGridView : public QObject
public:
tst_QSGGridView();
-private slots:
+//private slots:
void initTestCase();
void cleanupTestCase();
void items();
@@ -107,6 +107,8 @@ private slots:
void testQtQuick11Attributes_data();
void columnCount();
void margins();
+private slots:
+ void creationContext();
private:
QSGView *createView();
@@ -2926,6 +2928,26 @@ void tst_QSGGridView::margins()
}
}
+void tst_QSGGridView::creationContext()
+{
+ QSGView canvas;
+ canvas.setGeometry(0,0,240,320);
+ canvas.setSource(QUrl::fromLocalFile(SRCDIR "/data/creationContext.qml"));
+ qApp->processEvents();
+
+ QSGItem *rootItem = qobject_cast<QSGItem *>(canvas.rootObject());
+ QVERIFY(rootItem);
+ QVERIFY(rootItem->property("count").toInt() > 0);
+
+ QSGItem *item;
+ QVERIFY(item = rootItem->findChild<QSGItem *>("listItem"));
+ QCOMPARE(item->property("text").toString(), QString("Hello!"));
+ QVERIFY(item = rootItem->findChild<QSGItem *>("header"));
+ QCOMPARE(item->property("text").toString(), QString("Hello!"));
+ QVERIFY(item = rootItem->findChild<QSGItem *>("footer"));
+ QCOMPARE(item->property("text").toString(), QString("Hello!"));
+}
+
QSGView *tst_QSGGridView::createView()
{
QSGView *canvas = new QSGView(0);
diff --git a/tests/auto/declarative/qsglistview/data/ComponentView.qml b/tests/auto/declarative/qsglistview/data/ComponentView.qml
new file mode 100644
index 0000000000..3e87be8799
--- /dev/null
+++ b/tests/auto/declarative/qsglistview/data/ComponentView.qml
@@ -0,0 +1,16 @@
+import QtQuick 2.0
+
+ListView {
+ id: view
+
+ property string title
+
+ width: 100; height: 100;
+
+ model: 1
+ delegate: Text { objectName: "listItem"; text: view.title }
+ header: Text { objectName: "header"; text: view.title }
+ footer: Text { objectName: "footer"; text: view.title }
+ section.delegate: Text { objectName: "section"; text: view.title }
+ section.property: "modelData"
+}
diff --git a/tests/auto/declarative/qsglistview/data/creationContext.qml b/tests/auto/declarative/qsglistview/data/creationContext.qml
new file mode 100644
index 0000000000..79a682788b
--- /dev/null
+++ b/tests/auto/declarative/qsglistview/data/creationContext.qml
@@ -0,0 +1,5 @@
+import QtQuick 2.0
+
+ComponentView {
+ title: "Hello!"
+}
diff --git a/tests/auto/declarative/qsglistview/tst_qsglistview.cpp b/tests/auto/declarative/qsglistview/tst_qsglistview.cpp
index 6e8b247848..cca6cd30c2 100644
--- a/tests/auto/declarative/qsglistview/tst_qsglistview.cpp
+++ b/tests/auto/declarative/qsglistview/tst_qsglistview.cpp
@@ -134,6 +134,7 @@ private slots:
void rightToLeft();
void test_mirroring();
void margins();
+ void creationContext();
private:
template <class T> void items();
@@ -3712,6 +3713,28 @@ void tst_QSGListView::qAbstractItemModel_clear()
clear<TestModel2>();
}
+void tst_QSGListView::creationContext()
+{
+ QSGView canvas;
+ canvas.setGeometry(0,0,240,320);
+ canvas.setSource(QUrl::fromLocalFile(SRCDIR "/data/creationContext.qml"));
+ qApp->processEvents();
+
+ QSGItem *rootItem = qobject_cast<QSGItem *>(canvas.rootObject());
+ QVERIFY(rootItem);
+ QVERIFY(rootItem->property("count").toInt() > 0);
+
+ QSGItem *item;
+ QVERIFY(item = rootItem->findChild<QSGItem *>("listItem"));
+ QCOMPARE(item->property("text").toString(), QString("Hello!"));
+ QVERIFY(item = rootItem->findChild<QSGItem *>("header"));
+ QCOMPARE(item->property("text").toString(), QString("Hello!"));
+ QVERIFY(item = rootItem->findChild<QSGItem *>("footer"));
+ QCOMPARE(item->property("text").toString(), QString("Hello!"));
+ QVERIFY(item = rootItem->findChild<QSGItem *>("section"));
+ QCOMPARE(item->property("text").toString(), QString("Hello!"));
+}
+
QSGView *tst_QSGListView::createView()
{
QSGView *canvas = new QSGView(0);
@@ -3794,7 +3817,6 @@ void tst_QSGListView::dumpTree(QSGItem *parent, int depth)
}
}
-
QTEST_MAIN(tst_QSGListView)
#include "tst_qsglistview.moc"
diff --git a/tests/auto/declarative/qsgpathview/data/ComponentView.qml b/tests/auto/declarative/qsgpathview/data/ComponentView.qml
new file mode 100644
index 0000000000..b61033d375
--- /dev/null
+++ b/tests/auto/declarative/qsgpathview/data/ComponentView.qml
@@ -0,0 +1,17 @@
+import QtQuick 2.0
+
+PathView {
+ id: view
+
+ property string title
+
+ width: 100; height: 100;
+
+ model: 1
+ delegate: Text { objectName: "listItem"; text: view.title }
+
+ path: Path {
+ startX: 25; startY: 25;
+ PathLine { x: 75; y: 75 }
+ }
+}
diff --git a/tests/auto/declarative/qsgpathview/data/creationContext.qml b/tests/auto/declarative/qsgpathview/data/creationContext.qml
new file mode 100644
index 0000000000..79a682788b
--- /dev/null
+++ b/tests/auto/declarative/qsgpathview/data/creationContext.qml
@@ -0,0 +1,5 @@
+import QtQuick 2.0
+
+ComponentView {
+ title: "Hello!"
+}
diff --git a/tests/auto/declarative/qsgpathview/tst_qsgpathview.cpp b/tests/auto/declarative/qsgpathview/tst_qsgpathview.cpp
index 1a7368ecff..6dd2a57be6 100644
--- a/tests/auto/declarative/qsgpathview/tst_qsgpathview.cpp
+++ b/tests/auto/declarative/qsgpathview/tst_qsgpathview.cpp
@@ -111,6 +111,7 @@ private slots:
void treeModel();
void changePreferredHighlight();
void missingPercent();
+ void creationContext();
private:
QSGView *createView();
@@ -1066,6 +1067,21 @@ void tst_QSGPathView::changePreferredHighlight()
delete canvas;
}
+void tst_QSGPathView::creationContext()
+{
+ QSGView canvas;
+ canvas.setGeometry(0,0,240,320);
+ canvas.setSource(QUrl::fromLocalFile(SRCDIR "/data/creationContext.qml"));
+
+ QSGItem *rootItem = qobject_cast<QSGItem *>(canvas.rootObject());
+ QVERIFY(rootItem);
+ QVERIFY(rootItem->property("count").toInt() > 0);
+
+ QSGItem *item;
+ QVERIFY(item = findItem<QSGItem>(rootItem, "listItem", 0));
+ QCOMPARE(item->property("text").toString(), QString("Hello!"));
+}
+
QSGView *tst_QSGPathView::createView()
{
QSGView *canvas = new QSGView(0);