source: trunk/src/gui/itemviews/qabstractitemview.h@ 5

Last change on this file since 5 was 2, checked in by Dmitry A. Kuminov, 16 years ago

Initially imported qt-all-opensource-src-4.5.1 from Trolltech.

File size: 12.9 KB
Line 
1/****************************************************************************
2**
3** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
4** Contact: Qt Software Information ([email protected])
5**
6** This file is part of the QtGui module of the Qt Toolkit.
7**
8** $QT_BEGIN_LICENSE:LGPL$
9** Commercial Usage
10** Licensees holding valid Qt Commercial licenses may use this file in
11** accordance with the Qt Commercial License Agreement provided with the
12** Software or, alternatively, in accordance with the terms contained in
13** a written agreement between you and Nokia.
14**
15** GNU Lesser General Public License Usage
16** Alternatively, this file may be used under the terms of the GNU Lesser
17** General Public License version 2.1 as published by the Free Software
18** Foundation and appearing in the file LICENSE.LGPL included in the
19** packaging of this file. Please review the following information to
20** ensure the GNU Lesser General Public License version 2.1 requirements
21** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
22**
23** In addition, as a special exception, Nokia gives you certain
24** additional rights. These rights are described in the Nokia Qt LGPL
25** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
26** package.
27**
28** GNU General Public License Usage
29** Alternatively, this file may be used under the terms of the GNU
30** General Public License version 3.0 as published by the Free Software
31** Foundation and appearing in the file LICENSE.GPL included in the
32** packaging of this file. Please review the following information to
33** ensure the GNU General Public License version 3.0 requirements will be
34** met: http://www.gnu.org/copyleft/gpl.html.
35**
36** If you are unsure which license is appropriate for your use, please
37** contact the sales department at [email protected].
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
50QT_BEGIN_HEADER
51
52QT_BEGIN_NAMESPACE
53
54QT_MODULE(Gui)
55
56#ifndef QT_NO_ITEMVIEWS
57
58class QMenu;
59class QDrag;
60class QEvent;
61class QAbstractItemViewPrivate;
62
63class Q_GUI_EXPORT QAbstractItemView : public QAbstractScrollArea
64{
65 Q_OBJECT
66 Q_ENUMS(SelectionMode SelectionBehavior ScrollHint ScrollMode DragDropMode)
67 Q_FLAGS(EditTriggers)
68 Q_PROPERTY(bool autoScroll READ hasAutoScroll WRITE setAutoScroll)
69 Q_PROPERTY(int autoScrollMargin READ autoScrollMargin WRITE setAutoScrollMargin)
70 Q_PROPERTY(EditTriggers editTriggers READ editTriggers WRITE setEditTriggers)
71 Q_PROPERTY(bool tabKeyNavigation READ tabKeyNavigation WRITE setTabKeyNavigation)
72#ifndef QT_NO_DRAGANDDROP
73 Q_PROPERTY(bool showDropIndicator READ showDropIndicator WRITE setDropIndicatorShown)
74 Q_PROPERTY(bool dragEnabled READ dragEnabled WRITE setDragEnabled)
75 Q_PROPERTY(bool dragDropOverwriteMode READ dragDropOverwriteMode WRITE setDragDropOverwriteMode)
76 Q_PROPERTY(DragDropMode dragDropMode READ dragDropMode WRITE setDragDropMode)
77#endif
78 Q_PROPERTY(bool alternatingRowColors READ alternatingRowColors WRITE setAlternatingRowColors)
79 Q_PROPERTY(SelectionMode selectionMode READ selectionMode WRITE setSelectionMode)
80 Q_PROPERTY(SelectionBehavior selectionBehavior READ selectionBehavior WRITE setSelectionBehavior)
81 Q_PROPERTY(QSize iconSize READ iconSize WRITE setIconSize)
82 Q_PROPERTY(Qt::TextElideMode textElideMode READ textElideMode WRITE setTextElideMode)
83 Q_PROPERTY(ScrollMode verticalScrollMode READ verticalScrollMode WRITE setVerticalScrollMode)
84 Q_PROPERTY(ScrollMode horizontalScrollMode READ horizontalScrollMode WRITE setHorizontalScrollMode)
85
86public:
87 enum SelectionMode {
88 NoSelection,
89 SingleSelection,
90 MultiSelection,
91 ExtendedSelection,
92 ContiguousSelection
93 };
94
95 enum SelectionBehavior {
96 SelectItems,
97 SelectRows,
98 SelectColumns
99 };
100
101 enum ScrollHint {
102 EnsureVisible,
103 PositionAtTop,
104 PositionAtBottom,
105 PositionAtCenter
106 };
107
108 enum EditTrigger {
109 NoEditTriggers = 0,
110 CurrentChanged = 1,
111 DoubleClicked = 2,
112 SelectedClicked = 4,
113 EditKeyPressed = 8,
114 AnyKeyPressed = 16,
115 AllEditTriggers = 31
116 };
117
118 Q_DECLARE_FLAGS(EditTriggers, EditTrigger)
119
120 enum ScrollMode {
121 ScrollPerItem,
122 ScrollPerPixel
123 };
124
125 explicit QAbstractItemView(QWidget *parent = 0);
126 ~QAbstractItemView();
127
128 virtual void setModel(QAbstractItemModel *model);
129 QAbstractItemModel *model() const;
130
131 virtual void setSelectionModel(QItemSelectionModel *selectionModel);
132 QItemSelectionModel *selectionModel() const;
133
134 void setItemDelegate(QAbstractItemDelegate *delegate);
135 QAbstractItemDelegate *itemDelegate() const;
136
137 void setSelectionMode(QAbstractItemView::SelectionMode mode);
138 QAbstractItemView::SelectionMode selectionMode() const;
139
140 void setSelectionBehavior(QAbstractItemView::SelectionBehavior behavior);
141 QAbstractItemView::SelectionBehavior selectionBehavior() const;
142
143 QModelIndex currentIndex() const;
144 QModelIndex rootIndex() const;
145
146 void setEditTriggers(EditTriggers triggers);
147 EditTriggers editTriggers() const;
148
149 void setVerticalScrollMode(ScrollMode mode);
150 ScrollMode verticalScrollMode() const;
151
152 void setHorizontalScrollMode(ScrollMode mode);
153 ScrollMode horizontalScrollMode() const;
154
155 void setAutoScroll(bool enable);
156 bool hasAutoScroll() const;
157
158 void setAutoScrollMargin(int margin);
159 int autoScrollMargin() const;
160
161 void setTabKeyNavigation(bool enable);
162 bool tabKeyNavigation() const;
163
164#ifndef QT_NO_DRAGANDDROP
165 void setDropIndicatorShown(bool enable);
166 bool showDropIndicator() const;
167
168 void setDragEnabled(bool enable);
169 bool dragEnabled() const;
170
171 void setDragDropOverwriteMode(bool overwrite);
172 bool dragDropOverwriteMode() const;
173
174 enum DragDropMode {
175 NoDragDrop,
176 DragOnly,
177 DropOnly,
178 DragDrop,
179 InternalMove
180 };
181
182 void setDragDropMode(DragDropMode behavior);
183 DragDropMode dragDropMode() const;
184#endif
185 void setAlternatingRowColors(bool enable);
186 bool alternatingRowColors() const;
187
188 void setIconSize(const QSize &size);
189 QSize iconSize() const;
190
191 void setTextElideMode(Qt::TextElideMode mode);
192 Qt::TextElideMode textElideMode() const;
193
194 virtual void keyboardSearch(const QString &search);
195
196 virtual QRect visualRect(const QModelIndex &index) const = 0;
197 virtual void scrollTo(const QModelIndex &index, ScrollHint hint = EnsureVisible) = 0;
198 virtual QModelIndex indexAt(const QPoint &point) const = 0;
199
200 QSize sizeHintForIndex(const QModelIndex &index) const;
201 virtual int sizeHintForRow(int row) const;
202 virtual int sizeHintForColumn(int column) const;
203
204 void openPersistentEditor(const QModelIndex &index);
205 void closePersistentEditor(const QModelIndex &index);
206
207 void setIndexWidget(const QModelIndex &index, QWidget *widget);
208 QWidget *indexWidget(const QModelIndex &index) const;
209
210 void setItemDelegateForRow(int row, QAbstractItemDelegate *delegate);
211 QAbstractItemDelegate *itemDelegateForRow(int row) const;
212
213 void setItemDelegateForColumn(int column, QAbstractItemDelegate *delegate);
214 QAbstractItemDelegate *itemDelegateForColumn(int column) const;
215
216 QAbstractItemDelegate *itemDelegate(const QModelIndex &index) const;
217
218 virtual QVariant inputMethodQuery(Qt::InputMethodQuery query) const;
219
220#ifdef Q_NO_USING_KEYWORD
221 inline void update() { QAbstractScrollArea::update(); }
222#else
223 using QAbstractScrollArea::update;
224#endif
225
226public Q_SLOTS:
227 virtual void reset();
228 virtual void setRootIndex(const QModelIndex &index);
229 virtual void doItemsLayout();
230 virtual void selectAll();
231 void edit(const QModelIndex &index);
232 void clearSelection();
233 void setCurrentIndex(const QModelIndex &index);
234 void scrollToTop();
235 void scrollToBottom();
236 void update(const QModelIndex &index);
237
238protected Q_SLOTS:
239 virtual void dataChanged(const QModelIndex &topLeft, const QModelIndex &bottomRight);
240 virtual void rowsInserted(const QModelIndex &parent, int start, int end);
241 virtual void rowsAboutToBeRemoved(const QModelIndex &parent, int start, int end);
242 virtual void selectionChanged(const QItemSelection &selected, const QItemSelection &deselected);
243 virtual void currentChanged(const QModelIndex &current, const QModelIndex &previous);
244 virtual void updateEditorData();
245 virtual void updateEditorGeometries();
246 virtual void updateGeometries();
247 virtual void verticalScrollbarAction(int action);
248 virtual void horizontalScrollbarAction(int action);
249 virtual void verticalScrollbarValueChanged(int value);
250 virtual void horizontalScrollbarValueChanged(int value);
251 virtual void closeEditor(QWidget *editor, QAbstractItemDelegate::EndEditHint hint);
252 virtual void commitData(QWidget *editor);
253 virtual void editorDestroyed(QObject *editor);
254
255Q_SIGNALS:
256 void pressed(const QModelIndex &index);
257 void clicked(const QModelIndex &index);
258 void doubleClicked(const QModelIndex &index);
259
260 void activated(const QModelIndex &index);
261 void entered(const QModelIndex &index);
262 void viewportEntered();
263
264protected:
265 QAbstractItemView(QAbstractItemViewPrivate &, QWidget *parent = 0);
266
267 void setHorizontalStepsPerItem(int steps);
268 int horizontalStepsPerItem() const;
269 void setVerticalStepsPerItem(int steps);
270 int verticalStepsPerItem() const;
271
272 enum CursorAction { MoveUp, MoveDown, MoveLeft, MoveRight,
273 MoveHome, MoveEnd, MovePageUp, MovePageDown,
274 MoveNext, MovePrevious };
275 virtual QModelIndex moveCursor(CursorAction cursorAction,
276 Qt::KeyboardModifiers modifiers) = 0;
277
278 virtual int horizontalOffset() const = 0;
279 virtual int verticalOffset() const = 0;
280
281 virtual bool isIndexHidden(const QModelIndex &index) const = 0;
282
283 virtual void setSelection(const QRect &rect, QItemSelectionModel::SelectionFlags command) = 0;
284 virtual QRegion visualRegionForSelection(const QItemSelection &selection) const = 0;
285 virtual QModelIndexList selectedIndexes() const;
286
287 virtual bool edit(const QModelIndex &index, EditTrigger trigger, QEvent *event);
288
289 virtual QItemSelectionModel::SelectionFlags selectionCommand(const QModelIndex &index,
290 const QEvent *event = 0) const;
291
292#ifndef QT_NO_DRAGANDDROP
293 virtual void startDrag(Qt::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 State state() const;
309 void setState(State state);
310
311 void scheduleDelayedItemsLayout();
312 void executeDelayedItemsLayout();
313
314 void setDirtyRegion(const QRegion &region);
315 void scrollDirtyRegion(int dx, int dy);
316 QPoint dirtyRegionOffset() const;
317
318 void startAutoScroll();
319 void stopAutoScroll();
320 void doAutoScroll();
321
322 bool focusNextPrevChild(bool next);
323 bool event(QEvent *event);
324 bool viewportEvent(QEvent *event);
325 void mousePressEvent(QMouseEvent *event);
326 void mouseMoveEvent(QMouseEvent *event);
327 void mouseReleaseEvent(QMouseEvent *event);
328 void mouseDoubleClickEvent(QMouseEvent *event);
329#ifndef QT_NO_DRAGANDDROP
330 void dragEnterEvent(QDragEnterEvent *event);
331 void dragMoveEvent(QDragMoveEvent *event);
332 void dragLeaveEvent(QDragLeaveEvent *event);
333 void dropEvent(QDropEvent *event);
334#endif
335 void focusInEvent(QFocusEvent *event);
336 void focusOutEvent(QFocusEvent *event);
337 void keyPressEvent(QKeyEvent *event);
338 void resizeEvent(QResizeEvent *event);
339 void timerEvent(QTimerEvent *event);
340 void inputMethodEvent(QInputMethodEvent *event);
341
342#ifndef QT_NO_DRAGANDDROP
343 enum DropIndicatorPosition { OnItem, AboveItem, BelowItem, OnViewport };
344 DropIndicatorPosition dropIndicatorPosition() const;
345#endif
346
347private:
348 Q_DECLARE_PRIVATE(QAbstractItemView)
349 Q_DISABLE_COPY(QAbstractItemView)
350 Q_PRIVATE_SLOT(d_func(), void _q_columnsAboutToBeRemoved(const QModelIndex&, int, int))
351 Q_PRIVATE_SLOT(d_func(), void _q_columnsRemoved(const QModelIndex&, int, int))
352 Q_PRIVATE_SLOT(d_func(), void _q_columnsInserted(const QModelIndex&, int, int))
353 Q_PRIVATE_SLOT(d_func(), void _q_rowsRemoved(const QModelIndex&, int, int))
354 Q_PRIVATE_SLOT(d_func(), void _q_modelDestroyed())
355 Q_PRIVATE_SLOT(d_func(), void _q_layoutChanged())
356 Q_PRIVATE_SLOT(d_func(), void _q_fetchMore())
357
358 friend class QTreeViewPrivate; // needed to compile with MSVC
359 friend class QAccessibleItemRow;
360};
361
362Q_DECLARE_OPERATORS_FOR_FLAGS(QAbstractItemView::EditTriggers)
363
364#endif // QT_NO_ITEMVIEWS
365
366QT_END_NAMESPACE
367
368QT_END_HEADER
369
370#endif // QABSTRACTITEMVIEW_H
Note: See TracBrowser for help on using the repository browser.