aboutsummaryrefslogtreecommitdiffstats
path: root/src/quicktemplates2
diff options
context:
space:
mode:
authorAndy Shaw <andy.shaw@qt.io>2020-03-03 10:48:27 +0100
committerAndy Shaw <andy.shaw@qt.io>2020-03-24 14:17:19 +0100
commitfe3b3c707e2bc41f2e98d315ba72f50d4929e064 (patch)
treee55630303b7f8bacfe7564f5064bba1e94b8751b /src/quicktemplates2
parent62c8ae30880886f3ed17ddc17713db1a7410964e (diff)
HeaderView: Add support for list based models
Change-Id: I411136bd2b9a277d84a7c68c55bb1c317b6cc9d2 Reviewed-by: Mitch Curtis <mitch.curtis@qt.io>
Diffstat (limited to 'src/quicktemplates2')
-rw-r--r--src/quicktemplates2/qquickheaderview.cpp24
-rw-r--r--src/quicktemplates2/qquickheaderview_p_p.h2
2 files changed, 23 insertions, 3 deletions
diff --git a/src/quicktemplates2/qquickheaderview.cpp b/src/quicktemplates2/qquickheaderview.cpp
index 49463944..5c465cc7 100644
--- a/src/quicktemplates2/qquickheaderview.cpp
+++ b/src/quicktemplates2/qquickheaderview.cpp
@@ -151,7 +151,11 @@
This property holds the model role used to display text in each header cell.
- The default value is the \c "display" role.
+ When the model has multiple roles, textRole can be set to determine which
+ role should be displayed.
+
+ If model is a QAbstractItemModel then it will default to "display"; otherwise
+ it is empty.
\sa QAbstractItemModel::roleNames()
*/
@@ -161,7 +165,11 @@
This property holds the model role used to display text in each header cell.
- The default value is the \c "display" role.
+ When the model has multiple roles, textRole can be set to determine which
+ role should be displayed.
+
+ If model is a QAbstractItemModel then it will default to "display"; otherwise
+ it is empty.
\sa QAbstractItemModel::roleNames()
*/
@@ -241,6 +249,18 @@ void QQuickHeaderViewBasePrivate::syncModel()
}
QQuickTableViewPrivate::syncModel();
+
+ isTransposed = false;
+ const auto aim = model->abstractItemModel();
+ if (orientation() == Qt::Horizontal) {
+ // For models that are just a list or a number, and especially not a
+ // table, we transpose the view when the orientation is horizontal.
+ // The model (list) will then be laid out horizontally rather than
+ // vertically, which is the otherwise the default.
+ isTransposed = !aim || aim->columnCount() == 1;
+ }
+ if (m_textRole.isEmpty() && aim)
+ m_textRole = QLatin1String("display");
}
void QQuickHeaderViewBasePrivate::syncSyncView()
diff --git a/src/quicktemplates2/qquickheaderview_p_p.h b/src/quicktemplates2/qquickheaderview_p_p.h
index 961c554b..655c2a58 100644
--- a/src/quicktemplates2/qquickheaderview_p_p.h
+++ b/src/quicktemplates2/qquickheaderview_p_p.h
@@ -112,7 +112,7 @@ protected:
};
QStack<SectionSize> m_hiddenSectionSizes;
bool m_modelExplicitlySetByUser = false;
- QString m_textRole = QStringLiteral("display");
+ QString m_textRole;
};
class QQuickHorizontalHeaderViewPrivate : public QQuickHeaderViewBasePrivate