File indexing completed on 2026-01-07 10:16:27
0001
0002
0003
0004
0005 #ifndef QRANGEMODEL_H
0006 #define QRANGEMODEL_H
0007
0008 #include <QtCore/qrangemodel_impl.h>
0009
0010 QT_BEGIN_NAMESPACE
0011
0012 class QRangeModelPrivate;
0013
0014 class Q_CORE_EXPORT QRangeModel : public QAbstractItemModel
0015 {
0016 Q_OBJECT
0017 Q_PROPERTY(QHash<int, QByteArray> roleNames READ roleNames WRITE setRoleNames RESET resetRoleNames
0018 NOTIFY roleNamesChanged FINAL)
0019
0020 public:
0021 enum class RowCategory {
0022 Default,
0023 MultiRoleItem,
0024 };
0025
0026 template <typename T>
0027 struct RowOptions {};
0028
0029 template <typename Range,
0030 QRangeModelDetails::if_table_range<Range> = true>
0031 explicit QRangeModel(Range &&range, QObject *parent = nullptr)
0032 : QRangeModel(new QGenericTableItemModelImpl<Range>(std::forward<Range>(range), this), parent)
0033 {}
0034
0035 template <typename Range,
0036 QRangeModelDetails::if_tree_range<Range> = true>
0037 explicit QRangeModel(Range &&range, QObject *parent = nullptr)
0038 : QRangeModel(std::forward<Range>(range), QRangeModelDetails::DefaultTreeProtocol<Range>{},
0039 parent)
0040 {}
0041
0042 template <typename Range, typename Protocol,
0043 QRangeModelDetails::if_tree_range<Range, Protocol> = true>
0044 explicit QRangeModel(Range &&range, Protocol &&protocol, QObject *parent = nullptr)
0045 : QRangeModel(new QGenericTreeItemModelImpl<Range, Protocol>(std::forward<Range>(range),
0046 std::forward<Protocol>(protocol),
0047 this),
0048 parent)
0049 {}
0050
0051 ~QRangeModel() override;
0052
0053 QModelIndex index(int row, int column, const QModelIndex &parent = {}) const final;
0054 QModelIndex parent(const QModelIndex &child) const final;
0055 QModelIndex sibling(int row, int column, const QModelIndex &index) const final;
0056 int rowCount(const QModelIndex &parent = {}) const final;
0057 int columnCount(const QModelIndex &parent = {}) const final;
0058 Qt::ItemFlags flags(const QModelIndex &index) const override;
0059 QVariant headerData(int section, Qt::Orientation orientation,
0060 int role = Qt::DisplayRole) const override;
0061 bool setHeaderData(int section, Qt::Orientation orientation, const QVariant &data,
0062 int role = Qt::EditRole) override;
0063 QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const override;
0064 bool setData(const QModelIndex &index, const QVariant &data, int role = Qt::EditRole) override;
0065 QMap<int, QVariant> itemData(const QModelIndex &index) const override;
0066 bool setItemData(const QModelIndex &index, const QMap<int, QVariant> &data) override;
0067 bool clearItemData(const QModelIndex &index) override;
0068 bool insertColumns(int column, int count, const QModelIndex &parent = {}) final;
0069 bool removeColumns(int column, int count, const QModelIndex &parent = {}) final;
0070 bool moveColumns(const QModelIndex &sourceParent, int sourceColumn, int count,
0071 const QModelIndex &destParent, int destColumn) final;
0072 bool insertRows(int row, int count, const QModelIndex &parent = {}) final;
0073 bool removeRows(int row, int count, const QModelIndex &parent = {}) final;
0074 bool moveRows(const QModelIndex &sourceParent, int sourceRow, int count,
0075 const QModelIndex &destParent, int destRow) final;
0076
0077 QHash<int, QByteArray> roleNames() const override;
0078 void setRoleNames(const QHash<int, QByteArray> &names);
0079 void resetRoleNames();
0080
0081 bool canFetchMore(const QModelIndex &parent) const override;
0082 void fetchMore(const QModelIndex &parent) override;
0083
0084 bool hasChildren(const QModelIndex &parent = QModelIndex()) const final;
0085 QModelIndex buddy(const QModelIndex &index) const override;
0086 bool canDropMimeData(const QMimeData *data, Qt::DropAction action, int row, int column,
0087 const QModelIndex &parent) const override;
0088 bool dropMimeData(const QMimeData *data, Qt::DropAction action, int row, int column,
0089 const QModelIndex &parent) override;
0090 QMimeData *mimeData(const QModelIndexList &indexes) const override;
0091 QStringList mimeTypes() const override;
0092 QModelIndexList match(const QModelIndex &start, int role, const QVariant &value, int hits,
0093 Qt::MatchFlags flags) const override;
0094 void multiData(const QModelIndex &index, QModelRoleDataSpan roleDataSpan) const override;
0095 void sort(int column, Qt::SortOrder order = Qt::AscendingOrder) override;
0096 QSize span(const QModelIndex &index) const override;
0097 Qt::DropActions supportedDragActions() const override;
0098 Qt::DropActions supportedDropActions() const override;
0099
0100 Q_SIGNALS:
0101 void roleNamesChanged();
0102
0103 protected Q_SLOTS:
0104 void resetInternalData() override;
0105
0106 protected:
0107 bool event(QEvent *) override;
0108 bool eventFilter(QObject *, QEvent *) override;
0109
0110 private:
0111 Q_DISABLE_COPY_MOVE(QRangeModel)
0112 Q_DECLARE_PRIVATE(QRangeModel)
0113
0114 explicit QRangeModel(QRangeModelImplBase *impl, QObject *parent);
0115 friend class QRangeModelImplBase;
0116 };
0117
0118
0119 QModelIndex QRangeModelImplBase::createIndex(int row, int column, const void *ptr) const
0120 {
0121 return m_rangeModel->createIndex(row, column, ptr);
0122 }
0123 void QRangeModelImplBase::changePersistentIndexList(const QModelIndexList &from,
0124 const QModelIndexList &to)
0125 {
0126 m_rangeModel->changePersistentIndexList(from, to);
0127 }
0128 void QRangeModelImplBase::dataChanged(const QModelIndex &from, const QModelIndex &to,
0129 const QList<int> &roles)
0130 {
0131 m_rangeModel->dataChanged(from, to, roles);
0132 }
0133 void QRangeModelImplBase::beginInsertColumns(const QModelIndex &parent, int start, int count)
0134 {
0135 m_rangeModel->beginInsertColumns(parent, start, count);
0136 }
0137 void QRangeModelImplBase::endInsertColumns()
0138 {
0139 m_rangeModel->endInsertColumns();
0140 }
0141 void QRangeModelImplBase::beginRemoveColumns(const QModelIndex &parent, int start, int count)
0142 {
0143 m_rangeModel->beginRemoveColumns(parent, start, count);
0144 }
0145 void QRangeModelImplBase::endRemoveColumns()
0146 {
0147 m_rangeModel->endRemoveColumns();
0148 }
0149 bool QRangeModelImplBase::beginMoveColumns(const QModelIndex &sourceParent, int sourceFirst,
0150 int sourceLast, const QModelIndex &destParent,
0151 int destColumn)
0152 {
0153 return m_rangeModel->beginMoveColumns(sourceParent, sourceFirst, sourceLast,
0154 destParent, destColumn);
0155 }
0156 void QRangeModelImplBase::endMoveColumns()
0157 {
0158 m_rangeModel->endMoveColumns();
0159 }
0160
0161 void QRangeModelImplBase::beginInsertRows(const QModelIndex &parent, int start, int count)
0162 {
0163 m_rangeModel->beginInsertRows(parent, start, count);
0164 }
0165 void QRangeModelImplBase::endInsertRows()
0166 {
0167 m_rangeModel->endInsertRows();
0168 }
0169 void QRangeModelImplBase::beginRemoveRows(const QModelIndex &parent, int start, int count)
0170 {
0171 m_rangeModel->beginRemoveRows(parent, start, count);
0172 }
0173 void QRangeModelImplBase::endRemoveRows()
0174 {
0175 m_rangeModel->endRemoveRows();
0176 }
0177 bool QRangeModelImplBase::beginMoveRows(const QModelIndex &sourceParent, int sourceFirst,
0178 int sourceLast,
0179 const QModelIndex &destParent, int destRow)
0180 {
0181 return m_rangeModel->beginMoveRows(sourceParent, sourceFirst, sourceLast, destParent, destRow);
0182 }
0183 void QRangeModelImplBase::endMoveRows()
0184 {
0185 m_rangeModel->endMoveRows();
0186 }
0187 QAbstractItemModel &QRangeModelImplBase::itemModel()
0188 {
0189 return *m_rangeModel;
0190 }
0191 const QAbstractItemModel &QRangeModelImplBase::itemModel() const
0192 {
0193 return *m_rangeModel;
0194 }
0195
0196
0197
0198 namespace QRangeModelDetails
0199 {
0200 template <typename T>
0201 struct QRangeModelRowOptions : QRangeModel::RowOptions<T> {};
0202 }
0203
0204 QT_END_NAMESPACE
0205
0206
0207 #endif