Qt 4.8
qabstractitemview.h
Go to the documentation of this file.
1 /****************************************************************************
2 **
3 ** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies).
4 ** Contact: http://www.qt-project.org/legal
5 **
6 ** This file is part of the QtGui module of the Qt Toolkit.
7 **
8 ** $QT_BEGIN_LICENSE:LGPL$
9 ** Commercial License Usage
10 ** Licensees holding valid commercial Qt licenses may use this file in
11 ** accordance with the commercial license agreement provided with the
12 ** Software or, alternatively, in accordance with the terms contained in
13 ** a written agreement between you and Digia. For licensing terms and
14 ** conditions see http://qt.digia.com/licensing. For further information
15 ** use the contact form at http://qt.digia.com/contact-us.
16 **
17 ** GNU Lesser General Public License Usage
18 ** Alternatively, this file may be used under the terms of the GNU Lesser
19 ** General Public License version 2.1 as published by the Free Software
20 ** Foundation and appearing in the file LICENSE.LGPL included in the
21 ** packaging of this file. Please review the following information to
22 ** ensure the GNU Lesser General Public License version 2.1 requirements
23 ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
24 **
25 ** In addition, as a special exception, Digia gives you certain additional
26 ** rights. These rights are described in the Digia Qt LGPL Exception
27 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
28 **
29 ** GNU General Public License Usage
30 ** Alternatively, this file may be used under the terms of the GNU
31 ** General Public License version 3.0 as published by the Free Software
32 ** Foundation and appearing in the file LICENSE.GPL included in the
33 ** packaging of this file. Please review the following information to
34 ** ensure the GNU General Public License version 3.0 requirements will be
35 ** met: http://www.gnu.org/copyleft/gpl.html.
36 **
37 **
38 ** $QT_END_LICENSE$
39 **
40 ****************************************************************************/
41 
42 #ifndef QABSTRACTITEMVIEW_H
43 #define QABSTRACTITEMVIEW_H
44 
45 #include <QtGui/qabstractscrollarea.h>
46 #include <QtCore/qabstractitemmodel.h>
47 #include <QtGui/qitemselectionmodel.h>
48 #include <QtGui/qabstractitemdelegate.h>
49 
51 
53 
54 QT_MODULE(Gui)
55 
56 #ifndef QT_NO_ITEMVIEWS
57 
58 class QMenu;
59 class QDrag;
60 class QEvent;
62 
64 {
65  Q_OBJECT
67  Q_FLAGS(EditTriggers)
68  bool autoScroll;
69  int autoScrollMargin;
70  EditTriggers editTriggers;
71  bool tabKeyNavigation;
72 #ifndef QT_NO_DRAGANDDROP
76  DragDropMode dragDropMode;
78 #endif
86 
87 public:
93  ContiguousSelection
94  };
95 
99  SelectColumns
100  };
101 
102  enum ScrollHint {
106  PositionAtCenter
107  };
108 
109  enum EditTrigger {
110  NoEditTriggers = 0,
111  CurrentChanged = 1,
112  DoubleClicked = 2,
113  SelectedClicked = 4,
114  EditKeyPressed = 8,
115  AnyKeyPressed = 16,
116  AllEditTriggers = 31
117  };
118 
119  Q_DECLARE_FLAGS(EditTriggers, EditTrigger)
120 
121  enum ScrollMode {
123  ScrollPerPixel
124  };
125 
126  explicit QAbstractItemView(QWidget *parent = 0);
128 
129  virtual void setModel(QAbstractItemModel *model);
130  QAbstractItemModel *model() const;
131 
132  virtual void setSelectionModel(QItemSelectionModel *selectionModel);
133  QItemSelectionModel *selectionModel() const;
134 
135  void setItemDelegate(QAbstractItemDelegate *delegate);
136  QAbstractItemDelegate *itemDelegate() const;
137 
138  void setSelectionMode(QAbstractItemView::SelectionMode mode);
139  QAbstractItemView::SelectionMode selectionMode() const;
140 
141  void setSelectionBehavior(QAbstractItemView::SelectionBehavior behavior);
142  QAbstractItemView::SelectionBehavior selectionBehavior() const;
143 
144  QModelIndex currentIndex() const;
145  QModelIndex rootIndex() const;
146 
147  void setEditTriggers(EditTriggers triggers);
148  EditTriggers editTriggers() const;
149 
150  void setVerticalScrollMode(ScrollMode mode);
151  ScrollMode verticalScrollMode() const;
152 
153  void setHorizontalScrollMode(ScrollMode mode);
154  ScrollMode horizontalScrollMode() const;
155 
156  void setAutoScroll(bool enable);
157  bool hasAutoScroll() const;
158 
159  void setAutoScrollMargin(int margin);
160  int autoScrollMargin() const;
161 
162  void setTabKeyNavigation(bool enable);
163  bool tabKeyNavigation() const;
164 
165 #ifndef QT_NO_DRAGANDDROP
166  void setDropIndicatorShown(bool enable);
167  bool showDropIndicator() const;
168 
169  void setDragEnabled(bool enable);
170  bool dragEnabled() const;
171 
172  void setDragDropOverwriteMode(bool overwrite);
173  bool dragDropOverwriteMode() const;
174 
175  enum DragDropMode {
180  InternalMove
181  };
182 
183  void setDragDropMode(DragDropMode behavior);
184  DragDropMode dragDropMode() const;
185 
186  void setDefaultDropAction(Qt::DropAction dropAction);
187  Qt::DropAction defaultDropAction() const;
188 #endif
189 
190  void setAlternatingRowColors(bool enable);
191  bool alternatingRowColors() const;
192 
193  void setIconSize(const QSize &size);
194  QSize iconSize() const;
195 
196  void setTextElideMode(Qt::TextElideMode mode);
197  Qt::TextElideMode textElideMode() const;
198 
199  virtual void keyboardSearch(const QString &search);
200 
201  virtual QRect visualRect(const QModelIndex &index) const = 0;
202  virtual void scrollTo(const QModelIndex &index, ScrollHint hint = EnsureVisible) = 0;
203  virtual QModelIndex indexAt(const QPoint &point) const = 0;
204 
205  QSize sizeHintForIndex(const QModelIndex &index) const;
206  virtual int sizeHintForRow(int row) const;
207  virtual int sizeHintForColumn(int column) const;
208 
209  void openPersistentEditor(const QModelIndex &index);
210  void closePersistentEditor(const QModelIndex &index);
211 
212  void setIndexWidget(const QModelIndex &index, QWidget *widget);
213  QWidget *indexWidget(const QModelIndex &index) const;
214 
215  void setItemDelegateForRow(int row, QAbstractItemDelegate *delegate);
216  QAbstractItemDelegate *itemDelegateForRow(int row) const;
217 
218  void setItemDelegateForColumn(int column, QAbstractItemDelegate *delegate);
219  QAbstractItemDelegate *itemDelegateForColumn(int column) const;
220 
221  QAbstractItemDelegate *itemDelegate(const QModelIndex &index) const;
222 
223  virtual QVariant inputMethodQuery(Qt::InputMethodQuery query) const;
224 
225 #ifdef Q_NO_USING_KEYWORD
226  inline void update() { QAbstractScrollArea::update(); }
227 #else
229 #endif
230 
231 public Q_SLOTS:
232  virtual void reset();
233  virtual void setRootIndex(const QModelIndex &index);
234  virtual void doItemsLayout();
235  virtual void selectAll();
236  void edit(const QModelIndex &index);
237  void clearSelection();
238  void setCurrentIndex(const QModelIndex &index);
239  void scrollToTop();
240  void scrollToBottom();
241  void update(const QModelIndex &index);
242 
243 protected Q_SLOTS:
244  virtual void dataChanged(const QModelIndex &topLeft, const QModelIndex &bottomRight);
245  virtual void rowsInserted(const QModelIndex &parent, int start, int end);
246  virtual void rowsAboutToBeRemoved(const QModelIndex &parent, int start, int end);
247  virtual void selectionChanged(const QItemSelection &selected, const QItemSelection &deselected);
248  virtual void currentChanged(const QModelIndex &current, const QModelIndex &previous);
249  virtual void updateEditorData();
250  virtual void updateEditorGeometries();
251  virtual void updateGeometries();
252  virtual void verticalScrollbarAction(int action);
253  virtual void horizontalScrollbarAction(int action);
254  virtual void verticalScrollbarValueChanged(int value);
255  virtual void horizontalScrollbarValueChanged(int value);
256  virtual void closeEditor(QWidget *editor, QAbstractItemDelegate::EndEditHint hint);
257  virtual void commitData(QWidget *editor);
258  virtual void editorDestroyed(QObject *editor);
259 
260 Q_SIGNALS:
261  void pressed(const QModelIndex &index);
262  void clicked(const QModelIndex &index);
263  void doubleClicked(const QModelIndex &index);
264 
265  void activated(const QModelIndex &index);
266  void entered(const QModelIndex &index);
267  void viewportEntered();
268 
269 protected:
271 
272  void setHorizontalStepsPerItem(int steps);
273  int horizontalStepsPerItem() const;
274  void setVerticalStepsPerItem(int steps);
275  int verticalStepsPerItem() const;
276 
277  enum CursorAction { MoveUp, MoveDown, MoveLeft, MoveRight,
278  MoveHome, MoveEnd, MovePageUp, MovePageDown,
279  MoveNext, MovePrevious };
280  virtual QModelIndex moveCursor(CursorAction cursorAction,
281  Qt::KeyboardModifiers modifiers) = 0;
282 
283  virtual int horizontalOffset() const = 0;
284  virtual int verticalOffset() const = 0;
285 
286  virtual bool isIndexHidden(const QModelIndex &index) const = 0;
287 
288  virtual void setSelection(const QRect &rect, QItemSelectionModel::SelectionFlags command) = 0;
289  virtual QRegion visualRegionForSelection(const QItemSelection &selection) const = 0;
290  virtual QModelIndexList selectedIndexes() const;
291 
292  virtual bool edit(const QModelIndex &index, EditTrigger trigger, QEvent *event);
293 
294  virtual QItemSelectionModel::SelectionFlags selectionCommand(const QModelIndex &index,
295  const QEvent *event = 0) const;
296 
297 #ifndef QT_NO_DRAGANDDROP
298  virtual void startDrag(Qt::DropActions supportedActions);
299 #endif
300 
301  virtual QStyleOptionViewItem viewOptions() const;
302 
303  enum State {
310  AnimatingState
311  };
312 
313  State state() const;
314  void setState(State state);
315 
316  void scheduleDelayedItemsLayout();
317  void executeDelayedItemsLayout();
318 
319  void setDirtyRegion(const QRegion &region);
320  void scrollDirtyRegion(int dx, int dy);
321  QPoint dirtyRegionOffset() const;
322 
323  void startAutoScroll();
324  void stopAutoScroll();
325  void doAutoScroll();
326 
327  bool focusNextPrevChild(bool next);
328  bool event(QEvent *event);
329  bool viewportEvent(QEvent *event);
334 #ifndef QT_NO_DRAGANDDROP
338  void dropEvent(QDropEvent *event);
339 #endif
346 
347 #ifndef QT_NO_DRAGANDDROP
348  enum DropIndicatorPosition { OnItem, AboveItem, BelowItem, OnViewport };
349  DropIndicatorPosition dropIndicatorPosition() const;
350 #endif
351 
352 private:
355  Q_PRIVATE_SLOT(d_func(), void _q_columnsAboutToBeRemoved(const QModelIndex&, int, int))
356  Q_PRIVATE_SLOT(d_func(), void _q_columnsRemoved(const QModelIndex&, int, int))
357  Q_PRIVATE_SLOT(d_func(), void _q_columnsInserted(const QModelIndex&, int, int))
358  Q_PRIVATE_SLOT(d_func(), void _q_rowsInserted(const QModelIndex&, int, int))
359  Q_PRIVATE_SLOT(d_func(), void _q_rowsRemoved(const QModelIndex&, int, 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 
364  friend class QTreeViewPrivate; // needed to compile with MSVC
367  friend class QListViewPrivate; // needed to compile for Symbian emulator
368 };
369 
371 
372 #endif // QT_NO_ITEMVIEWS
373 
375 
377 
378 #endif // QABSTRACTITEMVIEW_H
The QVariant class acts like a union for the most common Qt data types.
Definition: qvariant.h:92
bool dragEnabled
whether the view supports dragging of its own items
SelectionMode
This enum indicates how the view responds to user selections:
The QAbstractItemDelegate class is used to display and edit data items from a model.
The QKeyEvent class describes a key event.
Definition: qevent.h:224
The QItemSelectionModel class keeps track of a view&#39;s selected items.
#define QT_END_NAMESPACE
This macro expands to.
Definition: qglobal.h:90
The QDrag class provides support for MIME-based drag and drop data transfer.
Definition: qdrag.h:61
EventRef event
QPointer< QWidget > widget
virtual void inputMethodEvent(QInputMethodEvent *)
This event handler, for event event, can be reimplemented in a subclass to receive Input Method compo...
Definition: qwidget.cpp:9668
#define QT_MODULE(x)
Definition: qglobal.h:2783
void dragMoveEvent(QDragMoveEvent *)
This event handler can be reimplemented in a subclass to receive drag move events (passed in event)...
#define QT_BEGIN_HEADER
Definition: qglobal.h:136
#define Q_DECLARE_FLAGS(Flags, Enum)
The Q_DECLARE_FLAGS() macro expands to.
Definition: qglobal.h:2348
void mouseReleaseEvent(QMouseEvent *)
This event handler can be reimplemented in a subclass to receive mouse release events for the viewpor...
#define Q_GUI_EXPORT
Definition: qglobal.h:1450
Q_CORE_EXPORT QTextStream & reset(QTextStream &s)
Qt::TextElideMode textElideMode
the position of the "..." in elided text.
TextElideMode
Definition: qnamespace.h:263
virtual void timerEvent(QTimerEvent *)
This event handler can be reimplemented in a subclass to receive timer events for the object...
Definition: qobject.cpp:1294
The QWidget class is the base class of all user interface objects.
Definition: qwidget.h:150
void dragEnterEvent(QDragEnterEvent *)
This event handler can be reimplemented in a subclass to receive drag enter events (passed in event)...
ScrollMode verticalScrollMode
how the view scrolls its contents in the vertical direction
#define Q_DISABLE_COPY(Class)
Disables the use of copy constructors and assignment operators for the given Class.
Definition: qglobal.h:2523
#define Q_PRIVATE_SLOT(d, signature)
Definition: qobjectdefs.h:73
The QAbstractScrollArea widget provides a scrolling area with on-demand scroll bars.
DropIndicatorPosition
This enum indicates the position of the drop indicator in relation to the index at the current mouse ...
#define Q_SLOTS
Definition: qobjectdefs.h:71
virtual QVariant inputMethodQuery(Qt::InputMethodQuery) const
This method is only relevant for input widgets.
Definition: qwidget.cpp:9683
The QString class provides a Unicode character string.
Definition: qstring.h:83
The QDragMoveEvent class provides an event which is sent while a drag and drop action is in progress...
Definition: qevent.h:530
The QObject class is the base class of all Qt objects.
Definition: qobject.h:111
#define Q_SIGNALS
Definition: qobjectdefs.h:72
virtual void focusOutEvent(QFocusEvent *)
This event handler can be reimplemented in a subclass to receive keyboard focus events (focus lost) f...
Definition: qwidget.cpp:9457
SelectionMode selectionMode
which selection mode the view operates in
static QCursor * moveCursor
Definition: qdnd_x11.cpp:254
#define Q_ENUMS(x)
Definition: qobjectdefs.h:84
void update()
Updates the widget unless updates are disabled or the widget is hidden.
Definition: qwidget.cpp:10883
void resizeEvent(QResizeEvent *)
This event handler can be reimplemented in a subclass to receive resize events (passed in event)...
bool dragDropOverwriteMode
the view&#39;s drag and drop behavior
#define QT_BEGIN_NAMESPACE
This macro expands to.
Definition: qglobal.h:89
#define Q_DECLARE_OPERATORS_FOR_FLAGS(Flags)
The Q_DECLARE_OPERATORS_FOR_FLAGS() macro declares global operator|() functions for Flags...
Definition: qglobal.h:2355
ScrollMode horizontalScrollMode
how the view scrolls its contents in the horizontal direction
void mousePressEvent(QMouseEvent *)
This event handler can be reimplemented in a subclass to receive mouse press events for the viewport(...
The QResizeEvent class contains event parameters for resize events.
Definition: qevent.h:349
Qt::DropAction defaultDropAction
the drop action that will be used by default in QAbstractItemView::drag()
The QDragLeaveEvent class provides an event that is sent to a widget when a drag and drop action leav...
Definition: qevent.h:577
The QRegion class specifies a clip region for a painter.
Definition: qregion.h:68
DropAction
Definition: qnamespace.h:1597
The State element defines configurations of objects and properties.
DragDropMode
Describes the various drag and drop events the view can act upon.
#define Q_OBJECT
Definition: qobjectdefs.h:157
The QAbstractItemModel class provides the abstract interface for item model classes.
The QMouseEvent class contains parameters that describe a mouse event.
Definition: qevent.h:85
virtual bool viewportEvent(QEvent *)
The main event handler for the scrolling area (the viewport() widget).
InputMethodQuery
Definition: qnamespace.h:1541
The QInputMethodEvent class provides parameters for input method events.
Definition: qevent.h:431
The QAbstractItemView class provides the basic functionality for item view classes.
The QItemSelection class manages information about selected items in a model.
The QDropEvent class provides an event which is sent when a drag and drop action is completed...
Definition: qevent.h:476
The QMenu class provides a menu widget for use in menu bars, context menus, and other popup menus...
Definition: qmenu.h:72
The QTimerEvent class contains parameters that describe a timer event.
Definition: qcoreevent.h:341
The QDragEnterEvent class provides an event which is sent to a widget when a drag and drop action ent...
Definition: qevent.h:555
The QPoint class defines a point in the plane using integer precision.
Definition: qpoint.h:53
virtual bool focusNextPrevChild(bool next)
Finds a new widget to give the keyboard focus to, as appropriate for Tab and Shift+Tab, and returns true if it can find a new widget, or false if it can&#39;t.
Definition: qwidget.cpp:6836
The QModelIndex class is used to locate data in a data model.
void dropEvent(QDropEvent *)
This event handler can be reimplemented in a subclass to receive drop events (passed in event)...
The QRect class defines a rectangle in the plane using integer precision.
Definition: qrect.h:58
void dragLeaveEvent(QDragLeaveEvent *)
This event handler can be reimplemented in a subclass to receive drag leave events (passed in event)...
bool showDropIndicator
whether the drop indicator is shown when dragging items and dropping.
DragDropMode dragDropMode
the drag and drop event the view will act upon
quint16 index
EndEditHint
This enum describes the different hints that the delegate can give to the model and view components t...
EditTrigger
This enum describes actions which will initiate item editing.
bool event(QEvent *)
Reimplemented Function
The QSize class defines the size of a two-dimensional object using integer point precision.
Definition: qsize.h:53
void keyPressEvent(QKeyEvent *)
This function is called with key event e when key presses occur.
#define Q_FLAGS(x)
Definition: qobjectdefs.h:85
#define Q_DECLARE_PRIVATE(Class)
Definition: qglobal.h:2467
CursorAction
This enum describes the different ways to navigate between items,.
QSize iconSize
the size of items&#39; icons
The QStyleOptionViewItem class is used to describe the parameters used to draw an item in a view widg...
Definition: qstyleoption.h:539
#define class
static const KeyPair *const end
bool alternatingRowColors
whether to draw the background using alternating colors
SelectionBehavior selectionBehavior
which selection behavior the view uses
The QEvent class is the base class of all event classes.
Definition: qcoreevent.h:56
#define QT_END_HEADER
Definition: qglobal.h:137
virtual void focusInEvent(QFocusEvent *)
This event handler can be reimplemented in a subclass to receive keyboard focus events (focus receive...
Definition: qwidget.cpp:9431
void mouseDoubleClickEvent(QMouseEvent *)
This event handler can be reimplemented in a subclass to receive mouse double click events for the vi...
The QFocusEvent class contains event parameters for widget focus events.
Definition: qevent.h:275
void mouseMoveEvent(QMouseEvent *)
This event handler can be reimplemented in a subclass to receive mouse move events for the viewport()...
static void visualRect(QRectF *geom, Qt::LayoutDirection dir, const QRectF &contentsRect)