1 /****************************************************************************
2 **
3 ** DQt - D bindings for the Qt Toolkit
4 **
5 ** GNU Lesser General Public License Usage
6 ** This file may be used under the terms of the GNU Lesser
7 ** General Public License version 3 as published by the Free Software
8 ** Foundation and appearing in the file LICENSE.LGPL3 included in the
9 ** packaging of this file. Please review the following information to
10 ** ensure the GNU Lesser General Public License version 3 requirements
11 ** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
12 **
13 ****************************************************************************/
14 module qt.widgets.abstractitemview;
15 extern(C++):
16 
17 import qt.config;
18 import qt.core.abstractitemmodel;
19 import qt.core.coreevent;
20 import qt.core.flags;
21 import qt.core.itemselectionmodel;
22 import qt.core.namespace;
23 import qt.core.object;
24 import qt.core.point;
25 import qt.core.rect;
26 import qt.core.size;
27 import qt.core.string;
28 import qt.core.variant;
29 import qt.core.vector;
30 import qt.gui.event;
31 import qt.gui.region;
32 import qt.helpers;
33 import qt.widgets.abstractitemdelegate;
34 import qt.widgets.abstractscrollarea;
35 import qt.widgets.styleoption;
36 import qt.widgets.widget;
37 
38 extern(C++, class) struct tst_QAbstractItemView;
39 extern(C++, class) struct tst_QTreeView;
40 
41 /+ QT_REQUIRE_CONFIG(itemviews);
42 
43 
44 class QMenu;
45 class QDrag;
46 class QEvent; +/
47 extern(C++, class) struct QAbstractItemViewPrivate;
48 
49 class /+ Q_WIDGETS_EXPORT +/ QAbstractItemView : QAbstractScrollArea
50 {
51     mixin(Q_OBJECT);
52     /+ Q_PROPERTY(bool autoScroll READ hasAutoScroll WRITE setAutoScroll)
53     Q_PROPERTY(int autoScrollMargin READ autoScrollMargin WRITE setAutoScrollMargin)
54     Q_PROPERTY(EditTriggers editTriggers READ editTriggers WRITE setEditTriggers)
55     Q_PROPERTY(bool tabKeyNavigation READ tabKeyNavigation WRITE setTabKeyNavigation)
56 #if QT_CONFIG(draganddrop)
57     Q_PROPERTY(bool showDropIndicator READ showDropIndicator WRITE setDropIndicatorShown)
58     Q_PROPERTY(bool dragEnabled READ dragEnabled WRITE setDragEnabled)
59     Q_PROPERTY(bool dragDropOverwriteMode READ dragDropOverwriteMode WRITE setDragDropOverwriteMode)
60     Q_PROPERTY(DragDropMode dragDropMode READ dragDropMode WRITE setDragDropMode)
61     Q_PROPERTY(Qt::DropAction defaultDropAction READ defaultDropAction WRITE setDefaultDropAction)
62 #endif
63     Q_PROPERTY(bool alternatingRowColors READ alternatingRowColors WRITE setAlternatingRowColors)
64     Q_PROPERTY(SelectionMode selectionMode READ selectionMode WRITE setSelectionMode)
65     Q_PROPERTY(SelectionBehavior selectionBehavior READ selectionBehavior WRITE setSelectionBehavior)
66     Q_PROPERTY(QSize iconSize READ iconSize WRITE setIconSize NOTIFY iconSizeChanged)
67     Q_PROPERTY(Qt::TextElideMode textElideMode READ textElideMode WRITE setTextElideMode)
68     Q_PROPERTY(ScrollMode verticalScrollMode READ verticalScrollMode WRITE setVerticalScrollMode RESET resetVerticalScrollMode)
69     Q_PROPERTY(ScrollMode horizontalScrollMode READ horizontalScrollMode WRITE setHorizontalScrollMode RESET resetHorizontalScrollMode) +/
70 
71 public:
72     enum SelectionMode {
73         NoSelection,
74         SingleSelection,
75         MultiSelection,
76         ExtendedSelection,
77         ContiguousSelection
78     }
79     /+ Q_ENUM(SelectionMode) +/
80 
81     enum SelectionBehavior {
82         SelectItems,
83         SelectRows,
84         SelectColumns
85     }
86     /+ Q_ENUM(SelectionBehavior) +/
87 
88     enum ScrollHint {
89         EnsureVisible,
90         PositionAtTop,
91         PositionAtBottom,
92         PositionAtCenter
93     }
94     /+ Q_ENUM(ScrollHint) +/
95 
96     enum EditTrigger {
97         NoEditTriggers = 0,
98         CurrentChanged = 1,
99         DoubleClicked = 2,
100         SelectedClicked = 4,
101         EditKeyPressed = 8,
102         AnyKeyPressed = 16,
103         AllEditTriggers = 31
104     }
105 
106     /+ Q_DECLARE_FLAGS(EditTriggers, EditTrigger) +/
107 alias EditTriggers = QFlags!(EditTrigger);    /+ Q_FLAG(EditTriggers) +/
108 
109     enum ScrollMode {
110         ScrollPerItem,
111         ScrollPerPixel
112     }
113     /+ Q_ENUM(ScrollMode) +/
114 
115     /+ explicit +/this(QWidget parent = null);
116     ~this();
117 
118     /+ virtual +/ void setModel(QAbstractItemModel model);
119     final QAbstractItemModel model() const;
120 
121     /+ virtual +/ void setSelectionModel(QItemSelectionModel selectionModel);
122     final QItemSelectionModel selectionModel() const;
123 
124     final void setItemDelegate(QAbstractItemDelegate delegate_);
125     final QAbstractItemDelegate itemDelegate() const;
126 
127     final void setSelectionMode(QAbstractItemView.SelectionMode mode);
128     final QAbstractItemView.SelectionMode selectionMode() const;
129 
130     final void setSelectionBehavior(QAbstractItemView.SelectionBehavior behavior);
131     final QAbstractItemView.SelectionBehavior selectionBehavior() const;
132 
133     final QModelIndex currentIndex() const;
134     final QModelIndex rootIndex() const;
135 
136     final void setEditTriggers(EditTriggers triggers);
137     final EditTriggers editTriggers() const;
138 
139     final void setVerticalScrollMode(ScrollMode mode);
140     final ScrollMode verticalScrollMode() const;
141     final void resetVerticalScrollMode();
142 
143     final void setHorizontalScrollMode(ScrollMode mode);
144     final ScrollMode horizontalScrollMode() const;
145     final void resetHorizontalScrollMode();
146 
147     final void setAutoScroll(bool enable);
148     final bool hasAutoScroll() const;
149 
150     final void setAutoScrollMargin(int margin);
151     final int autoScrollMargin() const;
152 
153     final void setTabKeyNavigation(bool enable);
154     final bool tabKeyNavigation() const;
155 
156 /+ #if QT_CONFIG(draganddrop) +/
157     final void setDropIndicatorShown(bool enable);
158     final bool showDropIndicator() const;
159 
160     final void setDragEnabled(bool enable);
161     final bool dragEnabled() const;
162 
163     final void setDragDropOverwriteMode(bool overwrite);
164     final bool dragDropOverwriteMode() const;
165 
166     enum DragDropMode {
167         NoDragDrop,
168         DragOnly,
169         DropOnly,
170         DragDrop,
171         InternalMove
172     }
173     /+ Q_ENUM(DragDropMode) +/
174 
175     final void setDragDropMode(DragDropMode behavior);
176     final DragDropMode dragDropMode() const;
177 
178     final void setDefaultDropAction(/+ Qt:: +/qt.core.namespace.DropAction dropAction);
179     final /+ Qt:: +/qt.core.namespace.DropAction defaultDropAction() const;
180 /+ #endif +/
181 
182     final void setAlternatingRowColors(bool enable);
183     final bool alternatingRowColors() const;
184 
185     final void setIconSize(ref const(QSize) size);
186     final QSize iconSize() const;
187 
188     final void setTextElideMode(/+ Qt:: +/qt.core.namespace.TextElideMode mode);
189     final /+ Qt:: +/qt.core.namespace.TextElideMode textElideMode() const;
190 
191     /+ virtual +/ void keyboardSearch(ref const(QString) search);
192 
193     /+ virtual +/ abstract QRect visualRect(ref const(QModelIndex) index) const;
194     /+ virtual +/ abstract void scrollTo(ref const(QModelIndex) index, ScrollHint hint = ScrollHint.EnsureVisible);
195     /+ virtual +/ abstract QModelIndex indexAt(ref const(QPoint) point) const;
196 
197     final QSize sizeHintForIndex(ref const(QModelIndex) index) const;
198     /+ virtual +/ int sizeHintForRow(int row) const;
199     /+ virtual +/ int sizeHintForColumn(int column) const;
200 
201     final void openPersistentEditor(ref const(QModelIndex) index);
202     final void closePersistentEditor(ref const(QModelIndex) index);
203     final bool isPersistentEditorOpen(ref const(QModelIndex) index) const;
204 
205     final void setIndexWidget(ref const(QModelIndex) index, QWidget widget);
206     final QWidget indexWidget(ref const(QModelIndex) index) const;
207 
208     final void setItemDelegateForRow(int row, QAbstractItemDelegate delegate_);
209     final QAbstractItemDelegate itemDelegateForRow(int row) const;
210 
211     final void setItemDelegateForColumn(int column, QAbstractItemDelegate delegate_);
212     final QAbstractItemDelegate itemDelegateForColumn(int column) const;
213 
214     final QAbstractItemDelegate itemDelegate(ref const(QModelIndex) index) const;
215 
216     /+ virtual +/ override QVariant inputMethodQuery(/+ Qt:: +/qt.core.namespace.InputMethodQuery query) const;
217 
218     /+ using QAbstractScrollArea::update; +/
219 
220 public /+ Q_SLOTS +/:
221     /+ virtual +/ @QSlot void reset();
222     /+ virtual +/ @QSlot void setRootIndex(ref const(QModelIndex) index);
223     /+ virtual +/ @QSlot void doItemsLayout();
224     /+ virtual +/ @QSlot void selectAll();
225     @QSlot final void edit(ref const(QModelIndex) index);
226     @QSlot final void clearSelection();
227     @QSlot final void setCurrentIndex(ref const(QModelIndex) index);
228     @QSlot final void scrollToTop();
229     @QSlot final void scrollToBottom();
230     @QSlot final void update(ref const(QModelIndex) index);
231 
232 protected /+ Q_SLOTS +/:
233     /+ virtual +/ @QSlot void dataChanged(ref const(QModelIndex) topLeft, ref const(QModelIndex) bottomRight, ref const(QVector!(int)) roles = globalInitVar!(QVector!(int)));
234     /+ virtual +/ @QSlot void rowsInserted(ref const(QModelIndex) parent, int start, int end);
235     /+ virtual +/ @QSlot void rowsAboutToBeRemoved(ref const(QModelIndex) parent, int start, int end);
236     /+ virtual +/ @QSlot void selectionChanged(ref const(QItemSelection) selected, ref const(QItemSelection) deselected);
237     /+ virtual +/ @QSlot void currentChanged(ref const(QModelIndex) current, ref const(QModelIndex) previous);
238     /+ virtual +/ @QSlot void updateEditorData();
239     /+ virtual +/ @QSlot void updateEditorGeometries();
240     /+ virtual +/ @QSlot void updateGeometries();
241     /+ virtual +/ @QSlot void verticalScrollbarAction(int action);
242     /+ virtual +/ @QSlot void horizontalScrollbarAction(int action);
243     /+ virtual +/ @QSlot void verticalScrollbarValueChanged(int value);
244     /+ virtual +/ @QSlot void horizontalScrollbarValueChanged(int value);
245     /+ virtual +/ @QSlot void closeEditor(QWidget editor, QAbstractItemDelegate.EndEditHint hint);
246     /+ virtual +/ @QSlot void commitData(QWidget editor);
247     /+ virtual +/ @QSlot void editorDestroyed(QObject editor);
248 
249 /+ Q_SIGNALS +/public:
250     @QSignal final void pressed(ref const(QModelIndex) index);
251     @QSignal final void clicked(ref const(QModelIndex) index);
252     @QSignal final void doubleClicked(ref const(QModelIndex) index);
253 
254     @QSignal final void activated(ref const(QModelIndex) index);
255     @QSignal final void entered(ref const(QModelIndex) index);
256     @QSignal final void viewportEntered();
257 
258     @QSignal final void iconSizeChanged(ref const(QSize) size);
259 
260 protected:
261     this(ref QAbstractItemViewPrivate , QWidget parent = null);
262 
263 /+ #if QT_DEPRECATED_SINCE(5, 13) +/
264     /+ QT_DEPRECATED +/ final void setHorizontalStepsPerItem(int steps);
265     /+ QT_DEPRECATED +/ final int horizontalStepsPerItem() const;
266     /+ QT_DEPRECATED +/ final void setVerticalStepsPerItem(int steps);
267     /+ QT_DEPRECATED +/ final int verticalStepsPerItem() const;
268 /+ #endif +/
269 
270     enum CursorAction { MoveUp, MoveDown, MoveLeft, MoveRight,
271                         MoveHome, MoveEnd, MovePageUp, MovePageDown,
272                         MoveNext, MovePrevious }
273     /+ virtual +/ abstract QModelIndex moveCursor(CursorAction cursorAction,
274                                        /+ Qt:: +/qt.core.namespace.KeyboardModifiers modifiers);
275 
276     /+ virtual +/ abstract int horizontalOffset() const;
277     /+ virtual +/ abstract int verticalOffset() const;
278 
279     /+ virtual +/ abstract bool isIndexHidden(ref const(QModelIndex) index) const;
280 
281     /+ virtual +/ abstract void setSelection(ref const(QRect) rect, QItemSelectionModel.SelectionFlags command);
282     /+ virtual +/ abstract QRegion visualRegionForSelection(ref const(QItemSelection) selection) const;
283     /+ virtual +/ QModelIndexList selectedIndexes() const;
284 
285     /+ virtual +/ bool edit(ref const(QModelIndex) index, EditTrigger trigger, QEvent event);
286 
287     mixin(mangleWindows("?selectionCommand@QAbstractItemView@@MEBA?AV?$QFlags@W4SelectionFlag@QItemSelectionModel@@@@AEBVQModelIndex@@PEBVQEvent@@@Z", q{
288     /+ virtual +/ QItemSelectionModel.SelectionFlags selectionCommand(ref const(QModelIndex) index,
289                                                                      const(QEvent) event = null) const;
290     }));
291 
292 /+ #if QT_CONFIG(draganddrop) +/
293     /+ virtual +/ void startDrag(/+ Qt:: +/qt.core.namespace.DropActions supportedActions);
294 /+ #endif +/
295 
296     /+ virtual +/ QStyleOptionViewItem viewOptions() const;
297 
298     enum State {
299         NoState,
300         DraggingState,
301         DragSelectingState,
302         EditingState,
303         ExpandingState,
304         CollapsingState,
305         AnimatingState
306     }
307 
308     final State state() const;
309     final void setState(State state);
310 
311     final void scheduleDelayedItemsLayout();
312     final void executeDelayedItemsLayout();
313 
314     final void setDirtyRegion(ref const(QRegion) region);
315     final void scrollDirtyRegion(int dx, int dy);
316     final QPoint dirtyRegionOffset() const;
317 
318     final void startAutoScroll();
319     final void stopAutoScroll();
320     final void doAutoScroll();
321 
322     override bool focusNextPrevChild(bool next);
323     override bool event(QEvent event);
324     override bool viewportEvent(QEvent event);
325     override void mousePressEvent(QMouseEvent event);
326     override void mouseMoveEvent(QMouseEvent event);
327     override void mouseReleaseEvent(QMouseEvent event);
328     override void mouseDoubleClickEvent(QMouseEvent event);
329 /+ #if QT_CONFIG(draganddrop) +/
330     override void dragEnterEvent(QDragEnterEvent event);
331     override void dragMoveEvent(QDragMoveEvent event);
332     override void dragLeaveEvent(QDragLeaveEvent event);
333     override void dropEvent(QDropEvent event);
334 /+ #endif +/
335     override void focusInEvent(QFocusEvent event);
336     override void focusOutEvent(QFocusEvent event);
337     override void keyPressEvent(QKeyEvent event);
338     override void resizeEvent(QResizeEvent event);
339     override void timerEvent(QTimerEvent event);
340     override void inputMethodEvent(QInputMethodEvent event);
341     override bool eventFilter(QObject object, QEvent event);
342 
343 /+ #if QT_CONFIG(draganddrop) +/
344     enum DropIndicatorPosition { OnItem, AboveItem, BelowItem, OnViewport }
345     final DropIndicatorPosition dropIndicatorPosition() const;
346 /+ #endif +/
347 
348     override QSize viewportSizeHint() const;
349 
350 private:
351     /+ Q_DECLARE_PRIVATE(QAbstractItemView) +/
352     /+ Q_DISABLE_COPY(QAbstractItemView) +/
353     /+ Q_PRIVATE_SLOT(d_func(), void _q_columnsAboutToBeRemoved(const QModelIndex&, int, int))
354     Q_PRIVATE_SLOT(d_func(), void _q_columnsRemoved(const QModelIndex&, int, int))
355     Q_PRIVATE_SLOT(d_func(), void _q_columnsInserted(const QModelIndex&, int, int))
356     Q_PRIVATE_SLOT(d_func(), void _q_rowsInserted(const QModelIndex&, int, int))
357     Q_PRIVATE_SLOT(d_func(), void _q_rowsRemoved(const QModelIndex&, int, int))
358     Q_PRIVATE_SLOT(d_func(), void _q_columnsMoved(const QModelIndex&, int, int, const QModelIndex&, int))
359     Q_PRIVATE_SLOT(d_func(), void _q_rowsMoved(const QModelIndex&, int, int, const QModelIndex&, int))
360     Q_PRIVATE_SLOT(d_func(), void _q_modelDestroyed())
361     Q_PRIVATE_SLOT(d_func(), void _q_layoutChanged())
362     Q_PRIVATE_SLOT(d_func(), void _q_headerDataChanged())
363 #if QT_CONFIG(gestures) && QT_CONFIG(scroller)
364     Q_PRIVATE_SLOT(d_func(), void _q_scrollerStateChanged())
365 #endif +/
366 
367     /+ friend class ::tst_QAbstractItemView; +/
368     /+ friend class ::tst_QTreeView; +/
369     /+ friend class QTreeViewPrivate; +/ // needed to compile with MSVC
370     /+ friend class QListModeViewBase; +/
371     /+ friend class QListViewPrivate; +/
372     /+ friend class QAbstractSlider; +/
373 }
374 /+pragma(inline, true) QFlags!(QAbstractItemView.EditTriggers.enum_type) operator |(QAbstractItemView.EditTriggers.enum_type f1, QAbstractItemView.EditTriggers.enum_type f2)/+noexcept+/{return QFlags!(QAbstractItemView.EditTriggers.enum_type)(f1)|f2;}+/
375 /+pragma(inline, true) QFlags!(QAbstractItemView.EditTriggers.enum_type) operator |(QAbstractItemView.EditTriggers.enum_type f1, QFlags!(QAbstractItemView.EditTriggers.enum_type) f2)/+noexcept+/{return f2|f1;}+/
376 /+pragma(inline, true) QIncompatibleFlag operator |(QAbstractItemView.EditTriggers.enum_type f1, int f2)/+noexcept+/{return QIncompatibleFlag(int(f1)|f2);}+/
377 
378 /+ Q_DECLARE_OPERATORS_FOR_FLAGS(QAbstractItemView::EditTriggers) +/