4#ifndef QITEMSELECTIONMODEL_H
5#define QITEMSELECTIONMODEL_H
7#include <QtCore/qglobal.h>
9#include <QtCore/qabstractitemmodel.h>
10#include <QtCore/qlist.h>
11#include <QtCore/qset.h>
21 QItemSelectionRange() =
default;
22 QItemSelectionRange(
const QModelIndex &topL,
const QModelIndex &bottomR) : tl(topL), br(bottomR) {}
23 explicit QItemSelectionRange(
const QModelIndex &index) : tl(index), br(tl) {}
25 void swap(QItemSelectionRange &other)
noexcept
31 inline int top()
const {
return tl.row(); }
32 inline int left()
const {
return tl.column(); }
33 inline int bottom()
const {
return br.row(); }
34 inline int right()
const {
return br.column(); }
35 inline int width()
const {
return br.column() - tl.column() + 1; }
36 inline int height()
const {
return br.row() - tl.row() + 1; }
38 inline const QPersistentModelIndex &topLeft()
const {
return tl; }
39 inline const QPersistentModelIndex &bottomRight()
const {
return br; }
40 inline QModelIndex parent()
const {
return tl.parent(); }
41 inline const QAbstractItemModel *model()
const {
return tl.model(); }
43 inline bool contains(
const QModelIndex &index)
const
45 return contains(index.row(), index.column(), index.parent());
48 inline bool contains(
int row,
int column,
const QModelIndex &parentIndex)
const
50 return (br.row() >= row && br.column() >= column &&
51 tl.row() <= row && tl.column() <= column &&
52 parent() == parentIndex);
55 bool intersects(
const QItemSelectionRange &other)
const;
56 QItemSelectionRange intersected(
const QItemSelectionRange &other)
const;
58#if QT_CORE_REMOVED_SINCE(6
, 8
)
59 inline bool operator==(
const QItemSelectionRange &other)
const
60 {
return comparesEqual(*
this, other); }
61 inline bool operator!=(
const QItemSelectionRange &other)
const
62 {
return !operator==(other); }
64 inline bool isValid()
const
66 return (tl.isValid() && br.isValid() && tl.parent() == br.parent()
67 && top() <= bottom() && left() <= right());
72 QModelIndexList indexes()
const;
75 friend bool comparesEqual(
const QItemSelectionRange &lhs,
76 const QItemSelectionRange &rhs)
noexcept
78 return comparesEqual(lhs.tl, rhs.tl) && comparesEqual(lhs.br, rhs.br);
80 Q_DECLARE_EQUALITY_COMPARABLE(QItemSelectionRange)
81 QPersistentModelIndex tl, br;
86class QItemSelectionModelPrivate;
88class Q_CORE_EXPORT QItemSelectionModel :
public QObject
91 Q_PROPERTY(QAbstractItemModel *model READ model WRITE setModel NOTIFY modelChanged
92 BINDABLE bindableModel)
93 Q_PROPERTY(
bool hasSelection READ hasSelection NOTIFY selectionChanged STORED
false
95 Q_PROPERTY(QModelIndex currentIndex READ currentIndex NOTIFY currentChanged STORED
false
97 Q_PROPERTY(QItemSelection selection READ selection NOTIFY selectionChanged STORED
false
99 Q_PROPERTY(QModelIndexList selectedIndexes READ selectedIndexes NOTIFY selectionChanged
100 STORED
false DESIGNABLE
false)
102 Q_DECLARE_PRIVATE(QItemSelectionModel)
115 SelectCurrent = Select | Current,
116 ToggleCurrent = Toggle | Current,
117 ClearAndSelect = Clear | Select
120 Q_DECLARE_FLAGS(SelectionFlags, SelectionFlag)
121 Q_FLAG(SelectionFlags)
123 explicit QItemSelectionModel(QAbstractItemModel *model =
nullptr);
124 explicit QItemSelectionModel(QAbstractItemModel *model, QObject *parent);
125 virtual ~QItemSelectionModel();
127 QModelIndex currentIndex()
const;
129 Q_INVOKABLE
bool isSelected(
const QModelIndex &index)
const;
130 Q_INVOKABLE
bool isRowSelected(
int row,
const QModelIndex &parent = QModelIndex())
const;
131 Q_INVOKABLE
bool isColumnSelected(
int column,
const QModelIndex &parent = QModelIndex())
const;
133 Q_INVOKABLE
bool rowIntersectsSelection(
int row,
const QModelIndex &parent = QModelIndex())
const;
134 Q_INVOKABLE
bool columnIntersectsSelection(
int column,
const QModelIndex &parent = QModelIndex())
const;
136 bool hasSelection()
const;
138 QModelIndexList selectedIndexes()
const;
139 Q_INVOKABLE QModelIndexList selectedRows(
int column = 0)
const;
140 Q_INVOKABLE QModelIndexList selectedColumns(
int row = 0)
const;
141 const QItemSelection selection()
const;
143 const QAbstractItemModel *model()
const;
144 QAbstractItemModel *model();
145 QBindable<QAbstractItemModel *> bindableModel();
147 void setModel(QAbstractItemModel *model);
150 virtual void setCurrentIndex(
const QModelIndex &index, QItemSelectionModel::SelectionFlags command);
151 virtual void select(
const QModelIndex &index, QItemSelectionModel::SelectionFlags command);
152 virtual void select(
const QItemSelection &selection, QItemSelectionModel::SelectionFlags command);
153 virtual void clear();
154 virtual void reset();
156 void clearSelection();
157 virtual void clearCurrentIndex();
160 void selectionChanged(
const QItemSelection &selected,
const QItemSelection &deselected);
161 void currentChanged(
const QModelIndex ¤t,
const QModelIndex &previous);
162 void currentRowChanged(
const QModelIndex ¤t,
const QModelIndex &previous);
163 void currentColumnChanged(
const QModelIndex ¤t,
const QModelIndex &previous);
164 void modelChanged(QAbstractItemModel *model);
167 QItemSelectionModel(QItemSelectionModelPrivate &dd, QAbstractItemModel *model);
168 void emitSelectionChanged(
const QItemSelection &newSelection,
const QItemSelection &oldSelection);
171 Q_DISABLE_COPY(QItemSelectionModel)
174Q_DECLARE_OPERATORS_FOR_FLAGS(QItemSelectionModel::SelectionFlags)
178class QItemSelection :
public QList<QItemSelectionRange>
181 using QList<QItemSelectionRange>::QList;
182 Q_CORE_EXPORT QItemSelection(
const QModelIndex &topLeft,
const QModelIndex &bottomRight);
186 Q_CORE_EXPORT
void select(
const QModelIndex &topLeft,
const QModelIndex &bottomRight);
187 Q_CORE_EXPORT
bool contains(
const QModelIndex &index)
const;
188 Q_CORE_EXPORT QModelIndexList indexes()
const;
189 Q_CORE_EXPORT
void merge(
const QItemSelection &other, QItemSelectionModel::SelectionFlags command);
190 Q_CORE_EXPORT
static void split(
const QItemSelectionRange &range,
191 const QItemSelectionRange &other,
192 QItemSelection *result);
194Q_DECLARE_SHARED(QItemSelection)
196#ifndef QT_NO_DEBUG_STREAM
197Q_CORE_EXPORT
QDebug operator<<(QDebug,
const QItemSelectionRange &);
202QT_DECL_METATYPE_EXTERN(QItemSelectionRange, Q_CORE_EXPORT)
203QT_DECL_METATYPE_EXTERN(QItemSelection, Q_CORE_EXPORT)
The QAbstractProxyModel class provides a base class for proxy item models that can do sorting,...
QT_REQUIRE_CONFIG(proxymodel)
Q_DECLARE_TYPEINFO(QByteArrayView, Q_PRIMITIVE_TYPE)
Q_CORE_EXPORT QDebug operator<<(QDebug debug, QDir::Filters filters)
QT_REQUIRE_CONFIG(itemmodel)