From d183bbe184d64159bbeeb99375b2bf07f330cd5e Mon Sep 17 00:00:00 2001 From: Volker Hilsheimer Date: Wed, 3 Sep 2025 22:14:50 +0300 Subject: [PATCH] QRM: return the section number as header data for array rows All items in an array have the same type, it's not useful to return the same type name for the header of each column. Instead, just return the section number. Pick-to: 6.10 Change-Id: Ia01e177e363cec55c44fcf3f92b1b3bfc502abe8 Reviewed-by: Artem Dyomin --- src/corelib/itemmodels/qrangemodel_impl.h | 10 +++++++--- tests/manual/corelib/itemmodels/qrangemodel/main.cpp | 11 +++++++++++ 2 files changed, 18 insertions(+), 3 deletions(-) diff --git a/src/corelib/itemmodels/qrangemodel_impl.h b/src/corelib/itemmodels/qrangemodel_impl.h index 20e64bdc295..16e47b207b3 100644 --- a/src/corelib/itemmodels/qrangemodel_impl.h +++ b/src/corelib/itemmodels/qrangemodel_impl.h @@ -1231,9 +1231,13 @@ public: result = QString::fromUtf8(prop.name()); } } else if constexpr (static_column_count >= 1) { - const QMetaType metaType = QRangeModelImplBase::meta_type_at(section); - if (metaType.isValid()) - result = QString::fromUtf8(metaType.name()); + if constexpr (QRangeModelDetails::array_like_v) { + return section; + } else { + const QMetaType metaType = QRangeModelImplBase::meta_type_at(section); + if (metaType.isValid()) + result = QString::fromUtf8(metaType.name()); + } } if (!result.isValid()) result = this->itemModel().QAbstractItemModel::headerData(section, orientation, role); diff --git a/tests/manual/corelib/itemmodels/qrangemodel/main.cpp b/tests/manual/corelib/itemmodels/qrangemodel/main.cpp index f03c68f14b8..8de23be3657 100644 --- a/tests/manual/corelib/itemmodels/qrangemodel/main.cpp +++ b/tests/manual/corelib/itemmodels/qrangemodel/main.cpp @@ -234,6 +234,17 @@ public slots: return new QRangeModel(data); } + QRangeModel *makeListOfArrays() + { + QList> data = { + {0.0}, + {1.1}, + {2.2}, + }; + + return new QRangeModel(std::move(data)); + } + QRangeModel *makeCustomFromEnum() { return new QRangeModel(QMetaEnumerator(Qt::ItemDataRole{}));