diff options
| author | Fabian Kosmale <fabian.kosmale@qt.io> | 2024-07-18 09:30:09 +0200 |
|---|---|---|
| committer | Fabian Kosmale <fabian.kosmale@qt.io> | 2024-07-18 15:23:43 +0200 |
| commit | 16b49089c69187d2a82f42874cd6253ca656e3ca (patch) | |
| tree | 29b90ea783b26dc5654013148d8cbbcee7035e7a | |
| parent | f4ea7af462a4b6cd9fc8bb6e57c8d0224881e9ab (diff) | |
(List|Grid)ViewAttached: Narrow down the view type
The classes tried to reuse as much functionality as possible by putting
it into the common base class, QQuickItemViewAttached. That however
meant that the view property could only have the type QQuickItemView,
confusing tooling.
This change moves the property to the derived classes, and changes the
type to the derived type (matching what is already documented).
This is safe (API stability wise) because QQuickItemViewAttached does
not exist as its own type in QML, and the C++ type exists only in a
private header.
Fixes: QTBUG-124412
Pick-to: 6.8
Change-Id: Ic613d2afce311d974072913a110a601ce2ee0251
Reviewed-by: Mitch Curtis <mitch.curtis@qt.io>
| -rw-r--r-- | src/quick/items/qquickgridview_p.h | 10 | ||||
| -rw-r--r-- | src/quick/items/qquickitemview_p.h | 10 | ||||
| -rw-r--r-- | src/quick/items/qquicklistview.cpp | 2 | ||||
| -rw-r--r-- | src/quick/items/qquicklistview_p.h | 11 | ||||
| -rw-r--r-- | tests/auto/qml/qmllint/data/itemViewAttached.qml | 16 | ||||
| -rw-r--r-- | tests/auto/qml/qmllint/tst_qmllint.cpp | 1 |
6 files changed, 38 insertions, 12 deletions
diff --git a/src/quick/items/qquickgridview_p.h b/src/quick/items/qquickgridview_p.h index 1f9698a706..3c53db5397 100644 --- a/src/quick/items/qquickgridview_p.h +++ b/src/quick/items/qquickgridview_p.h @@ -92,10 +92,20 @@ protected: class QQuickGridViewAttached : public QQuickItemViewAttached { Q_OBJECT + Q_PROPERTY(QQuickGridView *view READ view NOTIFY viewChanged FINAL) public: QQuickGridViewAttached(QObject *parent) : QQuickItemViewAttached(parent) {} ~QQuickGridViewAttached() {} + QQuickGridView *view() const { return m_view; } + void setView(QQuickGridView *view) { + if (view != m_view) { + m_view = view; + Q_EMIT viewChanged(); + } + } +private: + QPointer<QQuickGridView> m_view; }; diff --git a/src/quick/items/qquickitemview_p.h b/src/quick/items/qquickitemview_p.h index cecbf094cb..5db7d5ed1d 100644 --- a/src/quick/items/qquickitemview_p.h +++ b/src/quick/items/qquickitemview_p.h @@ -287,7 +287,6 @@ class Q_QUICK_EXPORT QQuickItemViewAttached : public QObject { Q_OBJECT - Q_PROPERTY(QQuickItemView *view READ view NOTIFY viewChanged FINAL) Q_PROPERTY(bool isCurrentItem READ isCurrentItem NOTIFY currentItemChanged FINAL) Q_PROPERTY(bool delayRemove READ delayRemove WRITE setDelayRemove NOTIFY delayRemoveChanged FINAL) @@ -300,14 +299,6 @@ public: : QObject(parent), m_isCurrent(false), m_delayRemove(false) {} ~QQuickItemViewAttached() {} - QQuickItemView *view() const { return m_view; } - void setView(QQuickItemView *view) { - if (view != m_view) { - m_view = view; - Q_EMIT viewChanged(); - } - } - bool isCurrentItem() const { return m_isCurrent; } void setIsCurrentItem(bool c) { if (m_isCurrent != c) { @@ -382,7 +373,6 @@ Q_SIGNALS: void reused(); public: - QPointer<QQuickItemView> m_view; bool m_isCurrent : 1; bool m_delayRemove : 1; diff --git a/src/quick/items/qquicklistview.cpp b/src/quick/items/qquicklistview.cpp index bc07c12521..9701507b14 100644 --- a/src/quick/items/qquicklistview.cpp +++ b/src/quick/items/qquicklistview.cpp @@ -1110,7 +1110,7 @@ QQuickItem * QQuickListViewPrivate::getSectionItem(const QString §ion) sectionItem->setParentItem(contentItem); } // sections are not controlled by FxListItemSG, so apply attached properties here - QQuickItemViewAttached *attached = static_cast<QQuickItemViewAttached*>(qmlAttachedPropertiesObject<QQuickListView>(sectionItem)); + auto *attached = static_cast<QQuickListViewAttached*>(qmlAttachedPropertiesObject<QQuickListView>(sectionItem)); attached->setView(q); } else if (!reuseExistingContext) { delete context; diff --git a/src/quick/items/qquicklistview_p.h b/src/quick/items/qquicklistview_p.h index 4651bc689f..c8d81b5884 100644 --- a/src/quick/items/qquicklistview_p.h +++ b/src/quick/items/qquicklistview_p.h @@ -174,14 +174,23 @@ protected: class Q_QUICK_EXPORT QQuickListViewAttached : public QQuickItemViewAttached { Q_OBJECT - + Q_PROPERTY(QQuickListView *view READ view NOTIFY viewChanged FINAL) public: QQuickListViewAttached(QObject *parent) : QQuickItemViewAttached(parent), m_sectionItem(nullptr) {} ~QQuickListViewAttached() {} + QQuickListView *view() const { return m_view; } + void setView(QQuickListView *view) { + if (view != m_view) { + m_view = view; + Q_EMIT viewChanged(); + } + } public: QPointer<QQuickItem> m_sectionItem; +private: + QPointer<QQuickListView> m_view; }; diff --git a/tests/auto/qml/qmllint/data/itemViewAttached.qml b/tests/auto/qml/qmllint/data/itemViewAttached.qml new file mode 100644 index 0000000000..75d24ad313 --- /dev/null +++ b/tests/auto/qml/qmllint/data/itemViewAttached.qml @@ -0,0 +1,16 @@ +import QtQuick + +Item { + + ListView { + delegate: Text { + text: ListView.view.highlightResizeDuration + } + } + + GridView { + delegate: Text { + text: GridView.view.cellHeight + } + } +} diff --git a/tests/auto/qml/qmllint/tst_qmllint.cpp b/tests/auto/qml/qmllint/tst_qmllint.cpp index 6f107247c8..52559277f1 100644 --- a/tests/auto/qml/qmllint/tst_qmllint.cpp +++ b/tests/auto/qml/qmllint/tst_qmllint.cpp @@ -1357,6 +1357,7 @@ void TestQmllint::cleanQmlCode_data() QTest::newRow("dontCheckJSTypes") << QStringLiteral("dontCheckJSTypes.qml"); QTest::newRow("jsonObjectIsRecognized") << QStringLiteral("jsonObjectIsRecognized.qml"); QTest::newRow("jsonArrayIsRecognized") << QStringLiteral("jsonArrayIsRecognized.qml"); + QTest::newRow("itemviewattached") << QStringLiteral("itemViewAttached.qml"); } void TestQmllint::cleanQmlCode() |
