diff options
author | Mitch Curtis <mitch.curtis@qt.io> | 2016-12-14 13:49:26 +0100 |
---|---|---|
committer | Mitch Curtis <mitch.curtis@qt.io> | 2016-12-20 11:51:24 +0000 |
commit | 7b7322c497042b738507108bcd54fa37694392d9 (patch) | |
tree | 48645d4ea2b64179b84777f46b9b3710eab2d50a | |
parent | ddba1d1281c4a50dacacbd5478716fe55f984058 (diff) |
ListView, GridView: fix missing keyNavigationEnabled property
Before this patch, this code:
import QtQuick 2.7
ListView {
keyNavigationEnabled: true
}
Would cause this error:
"ListView.keyNavigationEnabled" is not available in QtQuick 2.7.
This is because ItemView was missing a revision:
qmlRegisterUncreatableType<QQuickItemView, 7>(
uri, 2, 7, "ItemView", QQuickItemView::tr("ItemView is an abstract base class"));
Task-number: QTBUG-57621
Change-Id: Ia00cb7446a0d83278760f3aa361db5a864661bc6
Reviewed-by: Robin Burchell <robin.burchell@viroteck.net>
5 files changed, 35 insertions, 4 deletions
diff --git a/src/quick/items/qquickitemsmodule.cpp b/src/quick/items/qquickitemsmodule.cpp index 8dd4a96b62..0296ebe88c 100644 --- a/src/quick/items/qquickitemsmodule.cpp +++ b/src/quick/items/qquickitemsmodule.cpp @@ -298,8 +298,10 @@ static void qt_quickitems_defineModule(const char *uri, int major, int minor) qmlRegisterType<QQuickGrid, 1>(uri, 2, 1, "Grid"); #endif #if QT_CONFIG(quick_itemview) - qmlRegisterUncreatableType<QQuickItemView, 1>(uri, 2, 1, "ItemView", QQuickItemView::tr("ItemView is an abstract base class")); - qmlRegisterUncreatableType<QQuickItemView, 2>(uri, 2, 3, "ItemView", QQuickItemView::tr("ItemView is an abstract base class")); + const char *itemViewName = "ItemView"; + const QString itemViewMessage = QQuickItemView::tr("ItemView is an abstract base class"); + qmlRegisterUncreatableType<QQuickItemView, 1>(uri, 2, 1, itemViewName, itemViewMessage); + qmlRegisterUncreatableType<QQuickItemView, 2>(uri, 2, 3, itemViewName, itemViewMessage); #endif #if QT_CONFIG(quick_listview) qmlRegisterType<QQuickListView, 1>(uri, 2, 1, "ListView"); @@ -361,6 +363,9 @@ static void qt_quickitems_defineModule(const char *uri, int major, int minor) #if QT_CONFIG(quick_pathview) qmlRegisterType<QQuickPathView, 7>(uri, 2, 7, "PathView"); #endif +#if QT_CONFIG(quick_itemview) + qmlRegisterUncreatableType<QQuickItemView, 7>(uri, 2, 7, itemViewName, itemViewMessage); +#endif qmlRegisterUncreatableType<QQuickMouseEvent, 7>(uri, 2, 7, nullptr, QQuickMouseEvent::tr("MouseEvent is only available within handlers in MouseArea")); diff --git a/tests/auto/quick/qquickgridview/data/keyNavigationEnabled.qml b/tests/auto/quick/qquickgridview/data/keyNavigationEnabled.qml new file mode 100644 index 0000000000..868611760e --- /dev/null +++ b/tests/auto/quick/qquickgridview/data/keyNavigationEnabled.qml @@ -0,0 +1,12 @@ +import QtQuick 2.7 + +GridView { + width: 405 + height: 200 + cellWidth: width / 9 + cellHeight: height / 2 + // Ensure that the property is available in QML. + onKeyNavigationEnabledChanged: {} + model: 18 + delegate: Rectangle { objectName: "delegate"; width: 10; height: 10; color: "green" } +} diff --git a/tests/auto/quick/qquickgridview/tst_qquickgridview.cpp b/tests/auto/quick/qquickgridview/tst_qquickgridview.cpp index 07c03a57d7..1acc36c9b0 100644 --- a/tests/auto/quick/qquickgridview/tst_qquickgridview.cpp +++ b/tests/auto/quick/qquickgridview/tst_qquickgridview.cpp @@ -6568,7 +6568,7 @@ void tst_QQuickGridView::QTBUG_45640() void tst_QQuickGridView::keyNavigationEnabled() { QScopedPointer<QQuickView> window(createView()); - window->setSource(testFileUrl("gridview4.qml")); + window->setSource(testFileUrl("keyNavigationEnabled.qml")); window->show(); window->requestActivate(); QVERIFY(QTest::qWaitForWindowActive(window.data())); diff --git a/tests/auto/quick/qquicklistview/data/keyNavigationEnabled.qml b/tests/auto/quick/qquicklistview/data/keyNavigationEnabled.qml new file mode 100644 index 0000000000..943b0aadbd --- /dev/null +++ b/tests/auto/quick/qquicklistview/data/keyNavigationEnabled.qml @@ -0,0 +1,14 @@ +import QtQuick 2.7 + +ListView { + width: 400 + height: 400 + model: 100 + // Ensure that the property is available in QML. + onKeyNavigationEnabledChanged: {} + delegate: Rectangle { + height: 40 + width: 400 + color: index % 2 ? "lightsteelblue" : "lightgray" + } +} diff --git a/tests/auto/quick/qquicklistview/tst_qquicklistview.cpp b/tests/auto/quick/qquicklistview/tst_qquicklistview.cpp index 61ba2caaf7..4816d9c341 100644 --- a/tests/auto/quick/qquicklistview/tst_qquicklistview.cpp +++ b/tests/auto/quick/qquicklistview/tst_qquicklistview.cpp @@ -8271,7 +8271,7 @@ void tst_QQuickListView::QTBUG_48044_currentItemNotVisibleAfterTransition() void tst_QQuickListView::keyNavigationEnabled() { QScopedPointer<QQuickView> window(createView()); - window->setSource(testFileUrl("simplelistview.qml")); + window->setSource(testFileUrl("keyNavigationEnabled.qml")); window->show(); window->requestActivate(); QVERIFY(QTest::qWaitForWindowActive(window.data())); |