diff --git a/src/corelib/itemmodels/qgenericitemmodel.h b/src/corelib/itemmodels/qgenericitemmodel.h index aa3765e0a6b..5aecbe7e72e 100644 --- a/src/corelib/itemmodels/qgenericitemmodel.h +++ b/src/corelib/itemmodels/qgenericitemmodel.h @@ -183,6 +183,14 @@ void QGenericItemModelImplBase::endMoveRows() { m_itemModel->endMoveRows(); } +QAbstractItemModel &QGenericItemModelImplBase::itemModel() +{ + return *m_itemModel; +} +const QAbstractItemModel &QGenericItemModelImplBase::itemModel() const +{ + return *m_itemModel; +} template > @@ -363,7 +371,7 @@ public: if (row == index.row() && column == index.column()) return index; - if (column < 0 || column >= m_itemModel->columnCount()) + if (column < 0 || column >= itemModel().columnCount()) return {}; if (row == index.row()) @@ -420,7 +428,7 @@ public: QVariant result; if (role != Qt::DisplayRole || orientation != Qt::Horizontal || section < 0 || section >= that().columnCount({})) { - return m_itemModel->QAbstractItemModel::headerData(section, orientation, role); + return itemModel().QAbstractItemModel::headerData(section, orientation, role); } if constexpr (has_metaobject) { @@ -438,7 +446,7 @@ public: result = QString::fromUtf8(metaType.name()); } if (!result.isValid()) - result = m_itemModel->QAbstractItemModel::headerData(section, orientation, role); + result = itemModel().QAbstractItemModel::headerData(section, orientation, role); return result; } @@ -533,7 +541,7 @@ public: readAt(index, readItemData); if (!tried) // no multi-role item found - result = m_itemModel->QAbstractItemModel::itemData(index); + result = itemModel().QAbstractItemModel::itemData(index); } return result; } @@ -697,7 +705,7 @@ public: // setItemData will emit the dataChanged signal Q_ASSERT(!success); emitDataChanged.dismiss(); - success = m_itemModel->QAbstractItemModel::setItemData(index, data); + success = itemModel().QAbstractItemModel::setItemData(index, data); } } return success; @@ -907,8 +915,8 @@ public: } if (sourceRow == destRow || sourceRow == destRow - 1 || count <= 0 - || sourceRow < 0 || sourceRow + count - 1 >= m_itemModel->rowCount(sourceParent) - || destRow < 0 || destRow > m_itemModel->rowCount(destParent)) { + || sourceRow < 0 || sourceRow + count - 1 >= itemModel().rowCount(sourceParent) + || destRow < 0 || destRow > itemModel().rowCount(destParent)) { return false; } @@ -1614,7 +1622,7 @@ protected: // dynamically sized rows all have to have the same column count if constexpr (Base::dynamicColumns() && row_features::has_resize) { if (QGenericItemModelDetails::isValid(empty_row)) - QGenericItemModelDetails::refTo(empty_row).resize(Base::m_itemModel->columnCount()); + QGenericItemModelDetails::refTo(empty_row).resize(this->itemModel().columnCount()); } return empty_row; diff --git a/src/corelib/itemmodels/qgenericitemmodel_impl.h b/src/corelib/itemmodels/qgenericitemmodel_impl.h index 1970e432dbd..35d0e0a5f64 100644 --- a/src/corelib/itemmodels/qgenericitemmodel_impl.h +++ b/src/corelib/itemmodels/qgenericitemmodel_impl.h @@ -605,6 +605,7 @@ private: CallConstFN *callConst_fn; CallTupleFN *call_fn; + QGenericItemModel *m_itemModel; protected: template // type deduction @@ -613,8 +614,6 @@ protected: {} ~QGenericItemModelImplBase() = default; - QGenericItemModel *m_itemModel; - inline QModelIndex createIndex(int row, int column, const void *ptr = nullptr) const; inline void changePersistentIndexList(const QModelIndexList &from, const QModelIndexList &to); inline QHash roleNames() const; @@ -634,6 +633,8 @@ protected: inline bool beginMoveRows(const QModelIndex &sourceParent, int sourceFirst, int sourceLast, const QModelIndex &destParent, int destRow); inline void endMoveRows(); + inline QAbstractItemModel &itemModel(); + inline const QAbstractItemModel &itemModel() const; public: template