diff options
author | Volker Hilsheimer <volker.hilsheimer@qt.io> | 2020-11-04 12:34:56 +0100 |
---|---|---|
committer | Volker Hilsheimer <volker.hilsheimer@qt.io> | 2020-11-04 13:06:55 +0100 |
commit | bdc14837191dc81452fa7fbba20ba0a29e5fbebd (patch) | |
tree | f4b763d9e84083773eab7f989d8bdf99540219d5 /src/quicktemplates2 | |
parent | 67ae5055366b7397ee282b1ddc77e3a9e8f12d17 (diff) |
Fix QQuickHeaderView models to pass model tester
Following 72e0d699cec09458ca9325035d477d4899e8e47b in qtbase, the model
tester exercises additional code paths to verify correct row/columnCount
implementations for flat models.
This revealed a few bugs in the models used in QQuickHeaderView and the
unit test:
* neither QHeaderDataProxyModel nor the test models handled a valid
parent index for calls to row/columnCount
* QHeaderDataProxyModel::sibling passed the index on as parent
Change-Id: I612e18030d837275614d61ce8987c93fff7f20a9
Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
Diffstat (limited to 'src/quicktemplates2')
-rw-r--r-- | src/quicktemplates2/qquickheaderview.cpp | 11 |
1 files changed, 8 insertions, 3 deletions
diff --git a/src/quicktemplates2/qquickheaderview.cpp b/src/quicktemplates2/qquickheaderview.cpp index 8593fa0f..8671ac63 100644 --- a/src/quicktemplates2/qquickheaderview.cpp +++ b/src/quicktemplates2/qquickheaderview.cpp @@ -364,18 +364,22 @@ QModelIndex QHeaderDataProxyModel::parent(const QModelIndex &child) const return QModelIndex(); } -QModelIndex QHeaderDataProxyModel::sibling(int row, int column, const QModelIndex &idx) const +QModelIndex QHeaderDataProxyModel::sibling(int row, int column, const QModelIndex &) const { - return index(row, column, idx); + return index(row, column); } int QHeaderDataProxyModel::rowCount(const QModelIndex &parent) const { + if (parent.isValid()) + return 0; return m_model.isNull() ? -1 : (m_orientation == Qt::Horizontal ? 1 : m_model->rowCount(parent)); } int QHeaderDataProxyModel::columnCount(const QModelIndex &parent) const { + if (parent.isValid()) + return 0; return m_model.isNull() ? -1 : (m_orientation == Qt::Vertical ? 1 : m_model->columnCount(parent)); } @@ -401,7 +405,8 @@ bool QHeaderDataProxyModel::setData(const QModelIndex &index, const QVariant &va bool QHeaderDataProxyModel::hasChildren(const QModelIndex &parent) const { - Q_UNUSED(parent); + if (!parent.isValid()) + return rowCount(parent) > 0 && columnCount(parent) > 0; return false; } |