diff options
author | Richard Moe Gustavsen <richard.gustavsen@qt.io> | 2021-08-25 15:45:15 +0200 |
---|---|---|
committer | Qt Cherry-pick Bot <cherrypick_bot@qt-project.org> | 2021-08-26 09:33:04 +0000 |
commit | b655bb28ef7e7175f558fef0c4275273180fa2aa (patch) | |
tree | 1871184c44a1d726f17721ac09b3aa5b9bb11afb | |
parent | b1f7d1380cef500dba25586c0b6e95550e986343 (diff) |
QQuickTableView: issue warning if no selection model is available
Print a meaningful warning if the application creates a
SelectionRectangle, but forgets to assign a SelectionModel
to TableView.
Change-Id: Icdc438f616a58827425cf842c32ba588c406503b
Reviewed-by: Shawn Rutledge <shawn.rutledge@qt.io>
(cherry picked from commit 63af8aa8ad1f078b70cc947974f1ec0c42e628f4)
Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
-rw-r--r-- | src/quick/items/qquicktableview.cpp | 12 | ||||
-rw-r--r-- | src/quick/items/qquicktableview_p_p.h | 2 |
2 files changed, 12 insertions, 2 deletions
diff --git a/src/quick/items/qquicktableview.cpp b/src/quick/items/qquicktableview.cpp index 540f2edfde..be2f778344 100644 --- a/src/quick/items/qquicktableview.cpp +++ b/src/quick/items/qquicktableview.cpp @@ -790,8 +790,12 @@ void QQuickTableViewPrivate::setSelectionStartPos(const QPointF &pos) { if (loadedItems.isEmpty()) return; - if (!selectionModel) + if (!selectionModel) { + if (warnNoSelectionModel) + qmlWarning(q_func()) << "Cannot set selection: no SelectionModel assigned!"; + warnNoSelectionModel = false; return; + } const QAbstractItemModel *qaim = selectionModel->model(); if (!qaim) return; @@ -816,8 +820,12 @@ void QQuickTableViewPrivate::setSelectionEndPos(const QPointF &pos) { if (loadedItems.isEmpty()) return; - if (!selectionModel) + if (!selectionModel) { + if (warnNoSelectionModel) + qmlWarning(q_func()) << "Cannot set selection: no SelectionModel assigned!"; + warnNoSelectionModel = false; return; + } const QAbstractItemModel *qaim = selectionModel->model(); if (!qaim) return; diff --git a/src/quick/items/qquicktableview_p_p.h b/src/quick/items/qquicktableview_p_p.h index 76d5c152da..77b492b707 100644 --- a/src/quick/items/qquicktableview_p_p.h +++ b/src/quick/items/qquicktableview_p_p.h @@ -288,6 +288,8 @@ public: // Consider making it public. bool isTransposed = false; + bool warnNoSelectionModel = true; + QJSValue rowHeightProvider; QJSValue columnWidthProvider; QQuickTableSectionSizeProvider rowHeights; |