1 /* 2 * DQt - D bindings for the Qt Toolkit 3 * 4 * GNU Lesser General Public License Usage 5 * This file may be used under the terms of the GNU Lesser 6 * General Public License version 3 as published by the Free Software 7 * Foundation and appearing in the file LICENSE.LGPL3 included in the 8 * packaging of this file. Please review the following information to 9 * ensure the GNU Lesser General Public License version 3 requirements 10 * will be met: https://www.gnu.org/licenses/lgpl-3.0.html. 11 */ 12 module qt.core.itemselectionmodel; 13 extern(C++): 14 15 import qt.config; 16 import qt.core.abstractitemmodel; 17 import qt.core.flags; 18 import qt.core.list; 19 import qt.core.object; 20 import qt.core.property; 21 import qt.core.typeinfo; 22 import qt.helpers; 23 24 /+ QT_REQUIRE_CONFIG(itemmodel); +/ 25 26 27 /// Binding for C++ class [QItemSelectionRange](https://doc.qt.io/qt-6/qitemselectionrange.html). 28 @Q_RELOCATABLE_TYPE extern(C++, class) struct /+ Q_CORE_EXPORT +/ QItemSelectionRange 29 { 30 31 public: 32 /+ QItemSelectionRange() = default; +/ 33 this(ref const(QModelIndex) topL, ref const(QModelIndex) bottomR) 34 { 35 this.tl = topL; 36 this.br = bottomR; 37 } 38 /+ explicit +/this(ref const(QModelIndex) index) 39 { 40 this.tl = index; 41 this.br = tl; 42 } 43 44 /+ void swap(QItemSelectionRange &other) noexcept 45 { 46 qSwap(tl, other.tl); 47 qSwap(br, other.br); 48 } +/ 49 50 pragma(inline, true) int top() const { return tl.row(); } 51 pragma(inline, true) int left() const { return tl.column(); } 52 pragma(inline, true) int bottom() const { return br.row(); } 53 pragma(inline, true) int right() const { return br.column(); } 54 pragma(inline, true) int width() const { return br.column() - tl.column() + 1; } 55 pragma(inline, true) int height() const { return br.row() - tl.row() + 1; } 56 57 pragma(inline, true) ref const(QPersistentModelIndex) topLeft() const return { return tl; } 58 pragma(inline, true) ref const(QPersistentModelIndex) bottomRight() const return { return br; } 59 pragma(inline, true) QModelIndex parent() const { return tl.parent(); } 60 pragma(inline, true) const(QAbstractItemModel) model() const { return tl.model(); } 61 62 pragma(inline, true) bool contains(ref const(QModelIndex) index) const 63 { 64 return (parent() == index.parent() 65 && tl.row() <= index.row() && tl.column() <= index.column() 66 && br.row() >= index.row() && br.column() >= index.column()); 67 } 68 69 pragma(inline, true) bool contains(int row, int column, ref const(QModelIndex) parentIndex) const 70 { 71 return (parent() == parentIndex 72 && tl.row() <= row && tl.column() <= column 73 && br.row() >= row && br.column() >= column); 74 } 75 76 bool intersects(ref const(QItemSelectionRange) other) const; 77 QItemSelectionRange intersected(ref const(QItemSelectionRange) other) const; 78 79 80 /+pragma(inline, true) bool operator ==(ref const(QItemSelectionRange) other) const 81 { return (tl == other.tl && br == other.br); }+/ 82 /+pragma(inline, true) bool operator !=(ref const(QItemSelectionRange) other) const 83 { return !operator==(other); }+/ 84 85 pragma(inline, true) bool isValid() const 86 { 87 return (tl.isValid() && br.isValid() && tl.parent() == br.parent() 88 && top() <= bottom() && left() <= right()); 89 } 90 91 bool isEmpty() const; 92 93 QModelIndexList indexes() const; 94 95 private: 96 QPersistentModelIndex tl; QPersistentModelIndex br; 97 mixin(CREATE_CONVENIENCE_WRAPPERS); 98 } 99 /+ Q_DECLARE_TYPEINFO(QItemSelectionRange, Q_RELOCATABLE_TYPE); +/ 100 101 extern(C++, class) struct QItemSelectionModelPrivate; 102 103 /// Binding for C++ class [QItemSelectionModel](https://doc.qt.io/qt-6/qitemselectionmodel.html). 104 class /+ Q_CORE_EXPORT +/ QItemSelectionModel : QObject 105 { 106 mixin(Q_OBJECT); 107 /+ Q_PROPERTY(QAbstractItemModel *model READ model WRITE setModel NOTIFY modelChanged 108 BINDABLE bindableModel) 109 Q_PROPERTY(bool hasSelection READ hasSelection NOTIFY selectionChanged STORED false 110 DESIGNABLE false) 111 Q_PROPERTY(QModelIndex currentIndex READ currentIndex NOTIFY currentChanged STORED false 112 DESIGNABLE false) 113 Q_PROPERTY(QItemSelection selection READ selection NOTIFY selectionChanged STORED false 114 DESIGNABLE false) 115 Q_PROPERTY(QModelIndexList selectedIndexes READ selectedIndexes NOTIFY selectionChanged 116 STORED false DESIGNABLE false) 117 118 Q_DECLARE_PRIVATE(QItemSelectionModel) +/ 119 120 public: 121 122 enum SelectionFlag { 123 NoUpdate = 0x0000, 124 Clear = 0x0001, 125 Select = 0x0002, 126 Deselect = 0x0004, 127 Toggle = 0x0008, 128 Current = 0x0010, 129 Rows = 0x0020, 130 Columns = 0x0040, 131 SelectCurrent = SelectionFlag.Select | SelectionFlag.Current, 132 ToggleCurrent = SelectionFlag.Toggle | SelectionFlag.Current, 133 ClearAndSelect = SelectionFlag.Clear | SelectionFlag.Select 134 } 135 136 /+ Q_DECLARE_FLAGS(SelectionFlags, SelectionFlag) +/ 137 alias SelectionFlags = QFlags!(SelectionFlag); /+ Q_FLAG(SelectionFlags) +/ 138 139 /+ explicit +/this(QAbstractItemModel model = null); 140 /+ explicit +/this(QAbstractItemModel model, QObject parent); 141 /+ virtual +/~this(); 142 143 final QModelIndex currentIndex() const; 144 145 @QInvokable final bool isSelected(ref const(QModelIndex) index) const; 146 @QInvokable final bool isRowSelected(int row, ref const(QModelIndex) parent = globalInitVar!QModelIndex) const; 147 @QInvokable final bool isColumnSelected(int column, ref const(QModelIndex) parent = globalInitVar!QModelIndex) const; 148 149 @QInvokable final bool rowIntersectsSelection(int row, ref const(QModelIndex) parent = globalInitVar!QModelIndex) const; 150 @QInvokable final bool columnIntersectsSelection(int column, ref const(QModelIndex) parent = globalInitVar!QModelIndex) const; 151 152 final bool hasSelection() const; 153 154 final QModelIndexList selectedIndexes() const; 155 @QInvokable final QModelIndexList selectedRows(int column = 0) const; 156 @QInvokable final QModelIndexList selectedColumns(int row = 0) const; 157 mixin(mangleWindows("?selection@QItemSelectionModel@@QEBA?BVQItemSelection@@XZ", q{ 158 final const(QItemSelection) selection() const; 159 })); 160 161 mixin(changeWindowsMangling(q{mangleClassesTailConst}, q{ 162 final const(QAbstractItemModel) model() const; 163 })); 164 final QAbstractItemModel model(); 165 final QBindable!(QAbstractItemModel) bindableModel(); 166 167 final void setModel(QAbstractItemModel model); 168 169 public /+ Q_SLOTS +/: 170 /+ virtual +/ @QSlot void setCurrentIndex(ref const(QModelIndex) index, SelectionFlags command); 171 /+ virtual +/ @QSlot void select(ref const(QModelIndex) index, SelectionFlags command); 172 /+ virtual +/ @QSlot void select(ref const(QItemSelection) selection, SelectionFlags command); 173 /+ virtual +/ @QSlot void clear(); 174 /+ virtual +/ @QSlot void reset(); 175 176 @QSlot final void clearSelection(); 177 /+ virtual +/ @QSlot void clearCurrentIndex(); 178 179 /+ Q_SIGNALS +/public: 180 @QSignal final void selectionChanged(ref const(QItemSelection) selected, ref const(QItemSelection) deselected); 181 @QSignal final void currentChanged(ref const(QModelIndex) current, ref const(QModelIndex) previous); 182 @QSignal final void currentRowChanged(ref const(QModelIndex) current, ref const(QModelIndex) previous); 183 @QSignal final void currentColumnChanged(ref const(QModelIndex) current, ref const(QModelIndex) previous); 184 @QSignal final void modelChanged(QAbstractItemModel model); 185 186 protected: 187 this(ref QItemSelectionModelPrivate dd, QAbstractItemModel model); 188 final void emitSelectionChanged(ref const(QItemSelection) newSelection, ref const(QItemSelection) oldSelection); 189 190 private: 191 /+ Q_DISABLE_COPY(QItemSelectionModel) +/ 192 /+ Q_PRIVATE_SLOT(d_func(), void _q_columnsAboutToBeRemoved(const QModelIndex&, int, int)) 193 Q_PRIVATE_SLOT(d_func(), void _q_rowsAboutToBeRemoved(const QModelIndex&, int, int)) 194 Q_PRIVATE_SLOT(d_func(), void _q_columnsAboutToBeInserted(const QModelIndex&, int, int)) 195 Q_PRIVATE_SLOT(d_func(), void _q_rowsAboutToBeInserted(const QModelIndex&, int, int)) 196 Q_PRIVATE_SLOT(d_func(), void _q_layoutAboutToBeChanged(const QList<QPersistentModelIndex> &parents = QList<QPersistentModelIndex>(), QAbstractItemModel::LayoutChangeHint hint = QAbstractItemModel::NoHint)) 197 Q_PRIVATE_SLOT(d_func(), void _q_layoutChanged(const QList<QPersistentModelIndex> &parents = QList<QPersistentModelIndex>(), QAbstractItemModel::LayoutChangeHint hint = QAbstractItemModel::NoHint)) 198 Q_PRIVATE_SLOT(d_func(), void _q_modelDestroyed()) +/ 199 mixin(CREATE_CONVENIENCE_WRAPPERS); 200 } 201 /+pragma(inline, true) QFlags!(QItemSelectionModel.SelectionFlags.enum_type) operator |(QItemSelectionModel.SelectionFlags.enum_type f1, QItemSelectionModel.SelectionFlags.enum_type f2)/+noexcept+/{return QFlags!(QItemSelectionModel.SelectionFlags.enum_type)(f1)|f2;}+/ 202 /+pragma(inline, true) QFlags!(QItemSelectionModel.SelectionFlags.enum_type) operator |(QItemSelectionModel.SelectionFlags.enum_type f1, QFlags!(QItemSelectionModel.SelectionFlags.enum_type) f2)/+noexcept+/{return f2|f1;}+/ 203 /+pragma(inline, true) QFlags!(QItemSelectionModel.SelectionFlags.enum_type) operator &(QItemSelectionModel.SelectionFlags.enum_type f1, QItemSelectionModel.SelectionFlags.enum_type f2)/+noexcept+/{return QFlags!(QItemSelectionModel.SelectionFlags.enum_type)(f1)&f2;}+/ 204 /+pragma(inline, true) QFlags!(QItemSelectionModel.SelectionFlags.enum_type) operator &(QItemSelectionModel.SelectionFlags.enum_type f1, QFlags!(QItemSelectionModel.SelectionFlags.enum_type) f2)/+noexcept+/{return f2&f1;}+/ 205 /+pragma(inline, true) void operator +(QItemSelectionModel.SelectionFlags.enum_type f1, QItemSelectionModel.SelectionFlags.enum_type f2)/+noexcept+/;+/ 206 /+pragma(inline, true) void operator +(QItemSelectionModel.SelectionFlags.enum_type f1, QFlags!(QItemSelectionModel.SelectionFlags.enum_type) f2)/+noexcept+/;+/ 207 /+pragma(inline, true) void operator +(int f1, QFlags!(QItemSelectionModel.SelectionFlags.enum_type) f2)/+noexcept+/;+/ 208 /+pragma(inline, true) void operator -(QItemSelectionModel.SelectionFlags.enum_type f1, QItemSelectionModel.SelectionFlags.enum_type f2)/+noexcept+/;+/ 209 /+pragma(inline, true) void operator -(QItemSelectionModel.SelectionFlags.enum_type f1, QFlags!(QItemSelectionModel.SelectionFlags.enum_type) f2)/+noexcept+/;+/ 210 /+pragma(inline, true) void operator -(int f1, QFlags!(QItemSelectionModel.SelectionFlags.enum_type) f2)/+noexcept+/;+/ 211 /+pragma(inline, true) QIncompatibleFlag operator |(QItemSelectionModel.SelectionFlags.enum_type f1, int f2)/+noexcept+/{return QIncompatibleFlag(int(f1)|f2);}+/ 212 /+pragma(inline, true) void operator +(int f1, QItemSelectionModel.SelectionFlags.enum_type f2)/+noexcept+/;+/ 213 /+pragma(inline, true) void operator +(QItemSelectionModel.SelectionFlags.enum_type f1, int f2)/+noexcept+/;+/ 214 /+pragma(inline, true) void operator -(int f1, QItemSelectionModel.SelectionFlags.enum_type f2)/+noexcept+/;+/ 215 /+pragma(inline, true) void operator -(QItemSelectionModel.SelectionFlags.enum_type f1, int f2)/+noexcept+/;+/ 216 217 /+ Q_DECLARE_OPERATORS_FOR_FLAGS(QItemSelectionModel::SelectionFlags) +/ 218 // We export each out-of-line method individually to prevent MSVC from 219 // exporting the whole QList class. 220 /// Binding for C++ class [QItemSelection](https://doc.qt.io/qt-6/qitemselection.html). 221 @Q_RELOCATABLE_TYPE extern(C++, class) struct QItemSelection 222 { 223 public QList!(QItemSelectionRange) base0; 224 alias base0 this; 225 public: 226 /+ using QList<QItemSelectionRange>::QList; +/ 227 /+ Q_CORE_EXPORT +/this(ref const(QModelIndex) topLeft, ref const(QModelIndex) bottomRight); 228 229 // reusing QList::swap() here is OK! 230 231 /+ Q_CORE_EXPORT +/ void select(ref const(QModelIndex) topLeft, ref const(QModelIndex) bottomRight); 232 /+ Q_CORE_EXPORT +/ bool contains(ref const(QModelIndex) index) const; 233 /+ Q_CORE_EXPORT +/ QModelIndexList indexes() const; 234 /+ Q_CORE_EXPORT +/ void merge(ref const(QItemSelection) other, QItemSelectionModel.SelectionFlags command); 235 /+ Q_CORE_EXPORT +/ static void split(ref const(QItemSelectionRange) range, 236 ref const(QItemSelectionRange) other, 237 QItemSelection* result); 238 mixin(CREATE_CONVENIENCE_WRAPPERS); 239 } 240 /+ Q_DECLARE_SHARED(QItemSelection) 241 242 #ifndef QT_NO_DEBUG_STREAM 243 Q_CORE_EXPORT QDebug operator<<(QDebug, const QItemSelectionRange &); 244 #endif 245 246 247 Q_DECLARE_METATYPE(QItemSelectionRange) 248 Q_DECLARE_METATYPE(QItemSelection) +/ 249