aboutsummaryrefslogtreecommitdiffstats
path: root/tests/auto/quick/qquickgridview
diff options
context:
space:
mode:
authorNils Jeisecke <jeisecke@saltation.de>2013-10-07 11:55:12 +0200
committerThe Qt Project <gerrit-noreply@qt-project.org>2014-02-26 09:19:23 +0100
commit1061c7e5cfae88a336f1327cc20b2d8a0a3c6015 (patch)
tree058e8a07c1da7671ac8fcd9c91b91b386d106a2e /tests/auto/quick/qquickgridview
parent7d25db8ff452926e58b7a66608666b35c194fc69 (diff)
Make GridView/ListView attached "view" property available to all delegate types
This is useful for accessing the view (e.g. "width", "cellWidth", ... properties) from within section (ListView only), header, footer and highlight delegate components. A typical usecase are components that are used in multiple views and therefore cannot use the views's id for access. The only attached property valid for those non-item delegates is "view". This has been added to the documentation. Change-Id: I33d976da778be23ed531a3b193ceee95ed9800d2 Task-number: QTBUG-32836 Reviewed-by: Alan Alpert <aalpert@blackberry.com>
Diffstat (limited to 'tests/auto/quick/qquickgridview')
-rw-r--r--tests/auto/quick/qquickgridview/data/attachedProperties.qml74
-rw-r--r--tests/auto/quick/qquickgridview/tst_qquickgridview.cpp31
2 files changed, 105 insertions, 0 deletions
diff --git a/tests/auto/quick/qquickgridview/data/attachedProperties.qml b/tests/auto/quick/qquickgridview/data/attachedProperties.qml
new file mode 100644
index 0000000000..5fbd2db716
--- /dev/null
+++ b/tests/auto/quick/qquickgridview/data/attachedProperties.qml
@@ -0,0 +1,74 @@
+/****************************************************************************
+**
+** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies).
+** Contact: http://www.qt-project.org/legal
+**
+** This file is part of the test suite of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Digia Plc and its Subsidiary(-ies) nor the names
+** of its contributors may be used to endorse or promote products derived
+** from this software without specific prior written permission.
+**
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+import QtQuick 2.0
+
+GridView {
+ width: 100
+ height: 100
+
+ Component.onCompleted: currentIndex = 0
+
+ model: ListModel {
+ ListElement {
+ name: "A"
+ }
+ ListElement {
+ name: "B"
+ }
+ }
+
+ delegate: Text {
+ width: GridView.view.width
+ text: model.name
+ }
+
+ header: Rectangle {
+ width: GridView.view.width
+ }
+
+ footer: Rectangle {
+ width: GridView.view.width
+ }
+
+ highlight: Rectangle {
+ width: GridView.view.width
+ }
+}
diff --git a/tests/auto/quick/qquickgridview/tst_qquickgridview.cpp b/tests/auto/quick/qquickgridview/tst_qquickgridview.cpp
index 2ee98c6c61..f4eec18690 100644
--- a/tests/auto/quick/qquickgridview/tst_qquickgridview.cpp
+++ b/tests/auto/quick/qquickgridview/tst_qquickgridview.cpp
@@ -136,6 +136,7 @@ private slots:
void onAdd_data();
void onRemove();
void onRemove_data();
+ void attachedProperties_QTBUG_32836();
void columnCount();
void margins();
void creationContext();
@@ -4041,6 +4042,36 @@ void tst_QQuickGridView::onRemove_data()
QTest::newRow("ten items, remove 4-10") << 10 << 4 << 6;
}
+void tst_QQuickGridView::attachedProperties_QTBUG_32836()
+{
+ QQuickView *window = createView();
+
+ window->setSource(testFileUrl("attachedProperties.qml"));
+ window->show();
+ qApp->processEvents();
+
+ QQuickGridView *gridview = qobject_cast<QQuickGridView*>(window->rootObject());
+ QVERIFY(gridview != 0);
+
+ QQuickItem *header = gridview->headerItem();
+ QVERIFY(header);
+ QCOMPARE(header->width(), gridview->width());
+
+ QQuickItem *footer = gridview->footerItem();
+ QVERIFY(footer);
+ QCOMPARE(footer->width(), gridview->width());
+
+ QQuickItem *highlight = gridview->highlightItem();
+ QVERIFY(highlight);
+ QCOMPARE(highlight->width(), gridview->width());
+
+ QQuickItem *currentItem = gridview->currentItem();
+ QVERIFY(currentItem);
+ QCOMPARE(currentItem->width(), gridview->width());
+
+ delete window;
+}
+
void tst_QQuickGridView::columnCount()
{
QQuickView window;