22 QItemSelectionRange() =
default;
23 QItemSelectionRange(
const QModelIndex &topL,
const QModelIndex &bottomR) : tl(topL), br(bottomR) {}
24 explicit QItemSelectionRange(
const QModelIndex &index) : tl(index), br(tl) {}
26 void swap(QItemSelectionRange &other)
noexcept
32 inline int top()
const {
return tl.row(); }
33 inline int left()
const {
return tl.column(); }
34 inline int bottom()
const {
return br.row(); }
35 inline int right()
const {
return br.column(); }
36 inline int width()
const {
return br.column() - tl.column() + 1; }
37 inline int height()
const {
return br.row() - tl.row() + 1; }
39 inline const QPersistentModelIndex &topLeft()
const {
return tl; }
40 inline const QPersistentModelIndex &bottomRight()
const {
return br; }
41 inline QModelIndex parent()
const {
return tl.parent(); }
42 inline const QAbstractItemModel *model()
const {
return tl.model(); }
44 inline bool contains(
const QModelIndex &index)
const
46 return contains(index.row(), index.column(), index.parent());
49 inline bool contains(
int row,
int column,
const QModelIndex &parentIndex)
const
51 return (br.row() >= row && br.column() >= column &&
52 tl.row() <= row && tl.column() <= column &&
53 parent() == parentIndex);
56 bool intersects(
const QItemSelectionRange &other)
const;
57 QItemSelectionRange intersected(
const QItemSelectionRange &other)
const;
59#if QT_CORE_REMOVED_SINCE(6
, 8
)
60 inline bool operator==(
const QItemSelectionRange &other)
const
61 {
return comparesEqual(*
this, other); }
62 inline bool operator!=(
const QItemSelectionRange &other)
const
63 {
return !operator==(other); }
65 inline bool isValid()
const
67 return (tl.isValid() && br.isValid() && tl.parent() == br.parent()
68 && top() <= bottom() && left() <= right());
73 QModelIndexList indexes()
const;
76 friend bool comparesEqual(
const QItemSelectionRange &lhs,
77 const QItemSelectionRange &rhs)
noexcept
79 return comparesEqual(lhs.tl, rhs.tl) && comparesEqual(lhs.br, rhs.br);
81 Q_DECLARE_EQUALITY_COMPARABLE(QItemSelectionRange)
82 QPersistentModelIndex tl, br;
92 Q_PROPERTY(QAbstractItemModel *model READ model WRITE setModel NOTIFY modelChanged
93 BINDABLE bindableModel)
94 Q_PROPERTY(
bool hasSelection READ hasSelection NOTIFY selectionChanged STORED
false
96 Q_PROPERTY(QModelIndex currentIndex READ currentIndex NOTIFY currentChanged STORED
false
98 Q_PROPERTY(QItemSelection selection READ selection NOTIFY selectionChanged STORED
false
100 Q_PROPERTY(QModelIndexList selectedIndexes READ selectedIndexes NOTIFY selectionChanged
101 STORED
false DESIGNABLE
false)
103 Q_DECLARE_PRIVATE(QItemSelectionModel)
116 SelectCurrent = Select | Current,
117 ToggleCurrent = Toggle | Current,
118 ClearAndSelect = Clear | Select
121 Q_DECLARE_FLAGS(SelectionFlags, SelectionFlag)
122 Q_FLAG(SelectionFlags)
124 explicit QItemSelectionModel(QAbstractItemModel *model =
nullptr);
125 explicit QItemSelectionModel(QAbstractItemModel *model, QObject *parent);
126 virtual ~QItemSelectionModel();
128 QModelIndex currentIndex()
const;
130 Q_INVOKABLE
bool isSelected(
const QModelIndex &index)
const;
131 Q_INVOKABLE
bool isRowSelected(
int row,
const QModelIndex &parent = QModelIndex())
const;
132 Q_INVOKABLE
bool isColumnSelected(
int column,
const QModelIndex &parent = QModelIndex())
const;
134 Q_INVOKABLE
bool rowIntersectsSelection(
int row,
const QModelIndex &parent = QModelIndex())
const;
135 Q_INVOKABLE
bool columnIntersectsSelection(
int column,
const QModelIndex &parent = QModelIndex())
const;
137 bool hasSelection()
const;
139 QModelIndexList selectedIndexes()
const;
140 Q_INVOKABLE QModelIndexList selectedRows(
int column = 0)
const;
141 Q_INVOKABLE QModelIndexList selectedColumns(
int row = 0)
const;
142 const QItemSelection selection()
const;
144 const QAbstractItemModel *model()
const;
145 QAbstractItemModel *model();
146 QBindable<QAbstractItemModel *> bindableModel();
148 void setModel(QAbstractItemModel *model);
151 virtual void setCurrentIndex(
const QModelIndex &index, QItemSelectionModel::SelectionFlags command);
152 virtual void select(
const QModelIndex &index, QItemSelectionModel::SelectionFlags command);
153 virtual void select(
const QItemSelection &selection, QItemSelectionModel::SelectionFlags command);
154 virtual void clear();
155 virtual void reset();
157 void clearSelection();
158 virtual void clearCurrentIndex();
161 void selectionChanged(
const QItemSelection &selected,
const QItemSelection &deselected);
162 void currentChanged(
const QModelIndex ¤t,
const QModelIndex &previous);
163 void currentRowChanged(
const QModelIndex ¤t,
const QModelIndex &previous);
164 void currentColumnChanged(
const QModelIndex ¤t,
const QModelIndex &previous);
165 void modelChanged(QAbstractItemModel *model);
168 QItemSelectionModel(QItemSelectionModelPrivate &dd, QAbstractItemModel *model);
169 void emitSelectionChanged(
const QItemSelection &newSelection,
const QItemSelection &oldSelection);
172 Q_DISABLE_COPY(QItemSelectionModel)
179class QItemSelection :
public QList<QItemSelectionRange>
182 using QList<QItemSelectionRange>::QList;
183 Q_CORE_EXPORT QItemSelection(
const QModelIndex &topLeft,
const QModelIndex &bottomRight);
187 Q_CORE_EXPORT
void select(
const QModelIndex &topLeft,
const QModelIndex &bottomRight);
188 Q_CORE_EXPORT
bool contains(
const QModelIndex &index)
const;
189 Q_CORE_EXPORT QModelIndexList indexes()
const;
190 Q_CORE_EXPORT
void merge(
const QItemSelection &other, QItemSelectionModel::SelectionFlags command);
191 Q_CORE_EXPORT
static void split(
const QItemSelectionRange &range,
192 const QItemSelectionRange &other,
193 QItemSelection *result);