Warning, file /include/QtCore/qitemselectionmodel.h was not indexed
or was modified since last indexation (in which case cross-reference links may be missing, inaccurate or erroneous).
0001
0002
0003
0004
0005 #ifndef QITEMSELECTIONMODEL_H
0006 #define QITEMSELECTIONMODEL_H
0007
0008 #include <QtCore/qglobal.h>
0009
0010 #include <QtCore/qabstractitemmodel.h>
0011 #include <QtCore/qlist.h>
0012 #include <QtCore/qset.h>
0013
0014 QT_REQUIRE_CONFIG(itemmodel);
0015
0016 QT_BEGIN_NAMESPACE
0017
0018 class Q_CORE_EXPORT QItemSelectionRange
0019 {
0020
0021 public:
0022 QItemSelectionRange() = default;
0023 QItemSelectionRange(const QModelIndex &topL, const QModelIndex &bottomR) : tl(topL), br(bottomR) {}
0024 explicit QItemSelectionRange(const QModelIndex &index) : tl(index), br(tl) {}
0025
0026 void swap(QItemSelectionRange &other) noexcept
0027 {
0028 tl.swap(other.tl);
0029 br.swap(other.br);
0030 }
0031
0032 inline int top() const { return tl.row(); }
0033 inline int left() const { return tl.column(); }
0034 inline int bottom() const { return br.row(); }
0035 inline int right() const { return br.column(); }
0036 inline int width() const { return br.column() - tl.column() + 1; }
0037 inline int height() const { return br.row() - tl.row() + 1; }
0038
0039 inline const QPersistentModelIndex &topLeft() const { return tl; }
0040 inline const QPersistentModelIndex &bottomRight() const { return br; }
0041 inline QModelIndex parent() const { return tl.parent(); }
0042 inline const QAbstractItemModel *model() const { return tl.model(); }
0043
0044 inline bool contains(const QModelIndex &index) const
0045 {
0046 return contains(index.row(), index.column(), index.parent());
0047 }
0048
0049 inline bool contains(int row, int column, const QModelIndex &parentIndex) const
0050 {
0051 return (br.row() >= row && br.column() >= column &&
0052 tl.row() <= row && tl.column() <= column &&
0053 parent() == parentIndex);
0054 }
0055
0056 bool intersects(const QItemSelectionRange &other) const;
0057 QItemSelectionRange intersected(const QItemSelectionRange &other) const;
0058
0059 #if QT_CORE_REMOVED_SINCE(6, 8)
0060 inline bool operator==(const QItemSelectionRange &other) const
0061 { return comparesEqual(*this, other); }
0062 inline bool operator!=(const QItemSelectionRange &other) const
0063 { return !operator==(other); }
0064 #endif
0065 inline bool isValid() const
0066 {
0067 return (tl.isValid() && br.isValid() && tl.parent() == br.parent()
0068 && top() <= bottom() && left() <= right());
0069 }
0070
0071 bool isEmpty() const;
0072
0073 QModelIndexList indexes() const;
0074
0075 private:
0076 friend bool comparesEqual(const QItemSelectionRange &lhs,
0077 const QItemSelectionRange &rhs) noexcept
0078 {
0079 return comparesEqual(lhs.tl, rhs.tl) && comparesEqual(lhs.br, rhs.br);
0080 }
0081 Q_DECLARE_EQUALITY_COMPARABLE(QItemSelectionRange)
0082 QPersistentModelIndex tl, br;
0083 };
0084 Q_DECLARE_TYPEINFO(QItemSelectionRange, Q_RELOCATABLE_TYPE);
0085
0086 class QItemSelection;
0087 class QItemSelectionModelPrivate;
0088
0089 class Q_CORE_EXPORT QItemSelectionModel : public QObject
0090 {
0091 Q_OBJECT
0092 Q_PROPERTY(QAbstractItemModel *model READ model WRITE setModel NOTIFY modelChanged
0093 BINDABLE bindableModel)
0094 Q_PROPERTY(bool hasSelection READ hasSelection NOTIFY selectionChanged STORED false
0095 DESIGNABLE false)
0096 Q_PROPERTY(QModelIndex currentIndex READ currentIndex NOTIFY currentChanged STORED false
0097 DESIGNABLE false)
0098 Q_PROPERTY(QItemSelection selection READ selection NOTIFY selectionChanged STORED false
0099 DESIGNABLE false)
0100 Q_PROPERTY(QModelIndexList selectedIndexes READ selectedIndexes NOTIFY selectionChanged
0101 STORED false DESIGNABLE false)
0102
0103 Q_DECLARE_PRIVATE(QItemSelectionModel)
0104
0105 public:
0106
0107 enum SelectionFlag {
0108 NoUpdate = 0x0000,
0109 Clear = 0x0001,
0110 Select = 0x0002,
0111 Deselect = 0x0004,
0112 Toggle = 0x0008,
0113 Current = 0x0010,
0114 Rows = 0x0020,
0115 Columns = 0x0040,
0116 SelectCurrent = Select | Current,
0117 ToggleCurrent = Toggle | Current,
0118 ClearAndSelect = Clear | Select
0119 };
0120
0121 Q_DECLARE_FLAGS(SelectionFlags, SelectionFlag)
0122 Q_FLAG(SelectionFlags)
0123
0124 explicit QItemSelectionModel(QAbstractItemModel *model = nullptr);
0125 explicit QItemSelectionModel(QAbstractItemModel *model, QObject *parent);
0126 virtual ~QItemSelectionModel();
0127
0128 QModelIndex currentIndex() const;
0129
0130 Q_INVOKABLE bool isSelected(const QModelIndex &index) const;
0131 Q_INVOKABLE bool isRowSelected(int row, const QModelIndex &parent = QModelIndex()) const;
0132 Q_INVOKABLE bool isColumnSelected(int column, const QModelIndex &parent = QModelIndex()) const;
0133
0134 Q_INVOKABLE bool rowIntersectsSelection(int row, const QModelIndex &parent = QModelIndex()) const;
0135 Q_INVOKABLE bool columnIntersectsSelection(int column, const QModelIndex &parent = QModelIndex()) const;
0136
0137 bool hasSelection() const;
0138
0139 QModelIndexList selectedIndexes() const;
0140 Q_INVOKABLE QModelIndexList selectedRows(int column = 0) const;
0141 Q_INVOKABLE QModelIndexList selectedColumns(int row = 0) const;
0142 const QItemSelection selection() const;
0143
0144 const QAbstractItemModel *model() const;
0145 QAbstractItemModel *model();
0146 QBindable<QAbstractItemModel *> bindableModel();
0147
0148 void setModel(QAbstractItemModel *model);
0149
0150 public Q_SLOTS:
0151 virtual void setCurrentIndex(const QModelIndex &index, QItemSelectionModel::SelectionFlags command);
0152 virtual void select(const QModelIndex &index, QItemSelectionModel::SelectionFlags command);
0153 virtual void select(const QItemSelection &selection, QItemSelectionModel::SelectionFlags command);
0154 virtual void clear();
0155 virtual void reset();
0156
0157 void clearSelection();
0158 virtual void clearCurrentIndex();
0159
0160 Q_SIGNALS:
0161 void selectionChanged(const QItemSelection &selected, const QItemSelection &deselected);
0162 void currentChanged(const QModelIndex ¤t, const QModelIndex &previous);
0163 void currentRowChanged(const QModelIndex ¤t, const QModelIndex &previous);
0164 void currentColumnChanged(const QModelIndex ¤t, const QModelIndex &previous);
0165 void modelChanged(QAbstractItemModel *model);
0166
0167 protected:
0168 QItemSelectionModel(QItemSelectionModelPrivate &dd, QAbstractItemModel *model);
0169 void emitSelectionChanged(const QItemSelection &newSelection, const QItemSelection &oldSelection);
0170
0171 private:
0172 Q_DISABLE_COPY(QItemSelectionModel)
0173 };
0174
0175 Q_DECLARE_OPERATORS_FOR_FLAGS(QItemSelectionModel::SelectionFlags)
0176
0177
0178
0179 class QItemSelection : public QList<QItemSelectionRange>
0180 {
0181 public:
0182 using QList<QItemSelectionRange>::QList;
0183 Q_CORE_EXPORT QItemSelection(const QModelIndex &topLeft, const QModelIndex &bottomRight);
0184
0185
0186
0187 Q_CORE_EXPORT void select(const QModelIndex &topLeft, const QModelIndex &bottomRight);
0188 Q_CORE_EXPORT bool contains(const QModelIndex &index) const;
0189 Q_CORE_EXPORT QModelIndexList indexes() const;
0190 Q_CORE_EXPORT void merge(const QItemSelection &other, QItemSelectionModel::SelectionFlags command);
0191 Q_CORE_EXPORT static void split(const QItemSelectionRange &range,
0192 const QItemSelectionRange &other,
0193 QItemSelection *result);
0194 };
0195 Q_DECLARE_SHARED(QItemSelection)
0196
0197 #ifndef QT_NO_DEBUG_STREAM
0198 Q_CORE_EXPORT QDebug operator<<(QDebug, const QItemSelectionRange &);
0199 #endif
0200
0201 QT_END_NAMESPACE
0202
0203 QT_DECL_METATYPE_EXTERN(QItemSelectionRange, Q_CORE_EXPORT)
0204 QT_DECL_METATYPE_EXTERN(QItemSelection, Q_CORE_EXPORT)
0205
0206 #endif