qabstractitemview.h

Go to the documentation of this file.
00001 /****************************************************************************
00002 **
00003 ** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
00004 ** All rights reserved.
00005 ** Contact: Nokia Corporation (qt-info@nokia.com)
00006 **
00007 ** This file is part of the QtGui module of the Qt Toolkit.
00008 **
00009 ** $QT_BEGIN_LICENSE:LGPL$
00010 ** Commercial Usage
00011 ** Licensees holding valid Qt Commercial licenses may use this file in
00012 ** accordance with the Qt Commercial License Agreement provided with the
00013 ** Software or, alternatively, in accordance with the terms contained in
00014 ** a written agreement between you and Nokia.
00015 **
00016 ** GNU Lesser General Public License Usage
00017 ** Alternatively, this file may be used under the terms of the GNU Lesser
00018 ** General Public License version 2.1 as published by the Free Software
00019 ** Foundation and appearing in the file LICENSE.LGPL included in the
00020 ** packaging of this file.  Please review the following information to
00021 ** ensure the GNU Lesser General Public License version 2.1 requirements
00022 ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
00023 **
00024 ** In addition, as a special exception, Nokia gives you certain additional
00025 ** rights.  These rights are described in the Nokia Qt LGPL Exception
00026 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this module.
00027 **
00028 ** GNU General Public License Usage
00029 ** Alternatively, this file may be used under the terms of the GNU
00030 ** General Public License version 3.0 as published by the Free Software
00031 ** Foundation and appearing in the file LICENSE.GPL included in the
00032 ** packaging of this file.  Please review the following information to
00033 ** ensure the GNU General Public License version 3.0 requirements will be
00034 ** met: http://www.gnu.org/copyleft/gpl.html.
00035 **
00036 ** If you have questions regarding the use of this file, please contact
00037 ** Nokia at qt-info@nokia.com.
00038 ** $QT_END_LICENSE$
00039 **
00040 ****************************************************************************/
00041 
00042 #ifndef QABSTRACTITEMVIEW_H
00043 #define QABSTRACTITEMVIEW_H
00044 
00045 #include <QtGui/qabstractscrollarea.h>
00046 #include <QtCore/qabstractitemmodel.h>
00047 #include <QtGui/qitemselectionmodel.h>
00048 #include <QtGui/qabstractitemdelegate.h>
00049 
00050 QT_BEGIN_HEADER
00051 
00052 QT_BEGIN_NAMESPACE
00053 
00054 QT_MODULE(Gui)
00055 
00056 #ifndef QT_NO_ITEMVIEWS
00057 
00058 class QMenu;
00059 class QDrag;
00060 class QEvent;
00061 class QAbstractItemViewPrivate;
00062 
00063 class Q_GUI_EXPORT QAbstractItemView : public QAbstractScrollArea
00064 {
00065     Q_OBJECT
00066     Q_ENUMS(SelectionMode SelectionBehavior ScrollHint ScrollMode DragDropMode)
00067     Q_FLAGS(EditTriggers)
00068     Q_PROPERTY(bool autoScroll READ hasAutoScroll WRITE setAutoScroll)
00069     Q_PROPERTY(int autoScrollMargin READ autoScrollMargin WRITE setAutoScrollMargin)
00070     Q_PROPERTY(EditTriggers editTriggers READ editTriggers WRITE setEditTriggers)
00071     Q_PROPERTY(bool tabKeyNavigation READ tabKeyNavigation WRITE setTabKeyNavigation)
00072 #ifndef QT_NO_DRAGANDDROP
00073     Q_PROPERTY(bool showDropIndicator READ showDropIndicator WRITE setDropIndicatorShown)
00074     Q_PROPERTY(bool dragEnabled READ dragEnabled WRITE setDragEnabled)
00075     Q_PROPERTY(bool dragDropOverwriteMode READ dragDropOverwriteMode WRITE setDragDropOverwriteMode)
00076     Q_PROPERTY(DragDropMode dragDropMode READ dragDropMode WRITE setDragDropMode)
00077     Q_PROPERTY(Qt::DropAction defaultDropAction READ defaultDropAction WRITE setDefaultDropAction)
00078 #endif
00079     Q_PROPERTY(bool alternatingRowColors READ alternatingRowColors WRITE setAlternatingRowColors)
00080     Q_PROPERTY(SelectionMode selectionMode READ selectionMode WRITE setSelectionMode)
00081     Q_PROPERTY(SelectionBehavior selectionBehavior READ selectionBehavior WRITE setSelectionBehavior)
00082     Q_PROPERTY(QSize iconSize READ iconSize WRITE setIconSize)
00083     Q_PROPERTY(Qt::TextElideMode textElideMode READ textElideMode WRITE setTextElideMode)
00084     Q_PROPERTY(ScrollMode verticalScrollMode READ verticalScrollMode WRITE setVerticalScrollMode)
00085     Q_PROPERTY(ScrollMode horizontalScrollMode READ horizontalScrollMode WRITE setHorizontalScrollMode)
00086 
00087 public:
00088     enum SelectionMode {
00089         NoSelection,
00090         SingleSelection,
00091         MultiSelection,
00092         ExtendedSelection,
00093         ContiguousSelection
00094     };
00095 
00096     enum SelectionBehavior {
00097         SelectItems,
00098         SelectRows,
00099         SelectColumns
00100     };
00101 
00102     enum ScrollHint {
00103         EnsureVisible,
00104         PositionAtTop,
00105         PositionAtBottom,
00106         PositionAtCenter
00107     };
00108 
00109     enum EditTrigger {
00110         NoEditTriggers = 0,
00111         CurrentChanged = 1,
00112         DoubleClicked = 2,
00113         SelectedClicked = 4,
00114         EditKeyPressed = 8,
00115         AnyKeyPressed = 16,
00116         AllEditTriggers = 31
00117     };
00118 
00119     Q_DECLARE_FLAGS(EditTriggers, EditTrigger)
00120 
00121     enum ScrollMode {
00122         ScrollPerItem,
00123         ScrollPerPixel
00124     };
00125 
00126     explicit QAbstractItemView(QWidget *parent = 0);
00127     ~QAbstractItemView();
00128 
00129     virtual void setModel(QAbstractItemModel *model);
00130     QAbstractItemModel *model() const;
00131 
00132     virtual void setSelectionModel(QItemSelectionModel *selectionModel);
00133     QItemSelectionModel *selectionModel() const;
00134 
00135     void setItemDelegate(QAbstractItemDelegate *delegate);
00136     QAbstractItemDelegate *itemDelegate() const;
00137 
00138     void setSelectionMode(QAbstractItemView::SelectionMode mode);
00139     QAbstractItemView::SelectionMode selectionMode() const;
00140 
00141     void setSelectionBehavior(QAbstractItemView::SelectionBehavior behavior);
00142     QAbstractItemView::SelectionBehavior selectionBehavior() const;
00143 
00144     QModelIndex currentIndex() const;
00145     QModelIndex rootIndex() const;
00146 
00147     void setEditTriggers(EditTriggers triggers);
00148     EditTriggers editTriggers() const;
00149 
00150     void setVerticalScrollMode(ScrollMode mode);
00151     ScrollMode verticalScrollMode() const;
00152 
00153     void setHorizontalScrollMode(ScrollMode mode);
00154     ScrollMode horizontalScrollMode() const;
00155 
00156     void setAutoScroll(bool enable);
00157     bool hasAutoScroll() const;
00158 
00159     void setAutoScrollMargin(int margin);
00160     int autoScrollMargin() const;
00161 
00162     void setTabKeyNavigation(bool enable);
00163     bool tabKeyNavigation() const;
00164 
00165 #ifndef QT_NO_DRAGANDDROP
00166     void setDropIndicatorShown(bool enable);
00167     bool showDropIndicator() const;
00168 
00169     void setDragEnabled(bool enable);
00170     bool dragEnabled() const;
00171 
00172     void setDragDropOverwriteMode(bool overwrite);
00173     bool dragDropOverwriteMode() const;
00174 
00175     enum DragDropMode {
00176         NoDragDrop,
00177         DragOnly,
00178         DropOnly,
00179         DragDrop,
00180         InternalMove
00181     };
00182 
00183     void setDragDropMode(DragDropMode behavior);
00184     DragDropMode dragDropMode() const;
00185 
00186     void setDefaultDropAction(Qt::DropAction dropAction);
00187     Qt::DropAction defaultDropAction() const;
00188 #endif
00189 
00190     void setAlternatingRowColors(bool enable);
00191     bool alternatingRowColors() const;
00192 
00193     void setIconSize(const QSize &size);
00194     QSize iconSize() const;
00195 
00196     void setTextElideMode(Qt::TextElideMode mode);
00197     Qt::TextElideMode textElideMode() const;
00198 
00199     virtual void keyboardSearch(const QString &search);
00200 
00201     virtual QRect visualRect(const QModelIndex &index) const = 0;
00202     virtual void scrollTo(const QModelIndex &index, ScrollHint hint = EnsureVisible) = 0;
00203     virtual QModelIndex indexAt(const QPoint &point) const = 0;
00204 
00205     QSize sizeHintForIndex(const QModelIndex &index) const;
00206     virtual int sizeHintForRow(int row) const;
00207     virtual int sizeHintForColumn(int column) const;
00208 
00209     void openPersistentEditor(const QModelIndex &index);
00210     void closePersistentEditor(const QModelIndex &index);
00211 
00212     void setIndexWidget(const QModelIndex &index, QWidget *widget);
00213     QWidget *indexWidget(const QModelIndex &index) const;
00214 
00215     void setItemDelegateForRow(int row, QAbstractItemDelegate *delegate);
00216     QAbstractItemDelegate *itemDelegateForRow(int row) const;
00217 
00218     void setItemDelegateForColumn(int column, QAbstractItemDelegate *delegate);
00219     QAbstractItemDelegate *itemDelegateForColumn(int column) const;
00220 
00221     QAbstractItemDelegate *itemDelegate(const QModelIndex &index) const;
00222 
00223     virtual QVariant inputMethodQuery(Qt::InputMethodQuery query) const;
00224 
00225 #ifdef Q_NO_USING_KEYWORD
00226     inline void update() { QAbstractScrollArea::update(); }
00227 #else
00228     using QAbstractScrollArea::update;
00229 #endif
00230 
00231 public Q_SLOTS:
00232     virtual void reset();
00233     virtual void setRootIndex(const QModelIndex &index);
00234     virtual void doItemsLayout();
00235     virtual void selectAll();
00236     void edit(const QModelIndex &index);
00237     void clearSelection();
00238     void setCurrentIndex(const QModelIndex &index);
00239     void scrollToTop();
00240     void scrollToBottom();
00241     void update(const QModelIndex &index);
00242 
00243 protected Q_SLOTS:
00244     virtual void dataChanged(const QModelIndex &topLeft, const QModelIndex &bottomRight);
00245     virtual void rowsInserted(const QModelIndex &parent, int start, int end);
00246     virtual void rowsAboutToBeRemoved(const QModelIndex &parent, int start, int end);
00247     virtual void selectionChanged(const QItemSelection &selected, const QItemSelection &deselected);
00248     virtual void currentChanged(const QModelIndex &current, const QModelIndex &previous);
00249     virtual void updateEditorData();
00250     virtual void updateEditorGeometries();
00251     virtual void updateGeometries();
00252     virtual void verticalScrollbarAction(int action);
00253     virtual void horizontalScrollbarAction(int action);
00254     virtual void verticalScrollbarValueChanged(int value);
00255     virtual void horizontalScrollbarValueChanged(int value);
00256     virtual void closeEditor(QWidget *editor, QAbstractItemDelegate::EndEditHint hint);
00257     virtual void commitData(QWidget *editor);
00258     virtual void editorDestroyed(QObject *editor);
00259 
00260 Q_SIGNALS:
00261     void pressed(const QModelIndex &index);
00262     void clicked(const QModelIndex &index);
00263     void doubleClicked(const QModelIndex &index);
00264 
00265     void activated(const QModelIndex &index);
00266     void entered(const QModelIndex &index);
00267     void viewportEntered();
00268 
00269 protected:
00270     QAbstractItemView(QAbstractItemViewPrivate &, QWidget *parent = 0);
00271 
00272     void setHorizontalStepsPerItem(int steps);
00273     int horizontalStepsPerItem() const;
00274     void setVerticalStepsPerItem(int steps);
00275     int verticalStepsPerItem() const;
00276 
00277     enum CursorAction { MoveUp, MoveDown, MoveLeft, MoveRight,
00278                         MoveHome, MoveEnd, MovePageUp, MovePageDown,
00279                         MoveNext, MovePrevious };
00280     virtual QModelIndex moveCursor(CursorAction cursorAction,
00281                                    Qt::KeyboardModifiers modifiers) = 0;
00282 
00283     virtual int horizontalOffset() const = 0;
00284     virtual int verticalOffset() const = 0;
00285 
00286     virtual bool isIndexHidden(const QModelIndex &index) const = 0;
00287 
00288     virtual void setSelection(const QRect &rect, QItemSelectionModel::SelectionFlags command) = 0;
00289     virtual QRegion visualRegionForSelection(const QItemSelection &selection) const = 0;
00290     virtual QModelIndexList selectedIndexes() const;
00291 
00292     virtual bool edit(const QModelIndex &index, EditTrigger trigger, QEvent *event);
00293 
00294     virtual QItemSelectionModel::SelectionFlags selectionCommand(const QModelIndex &index,
00295                                                                  const QEvent *event = 0) const;
00296 
00297 #ifndef QT_NO_DRAGANDDROP
00298     virtual void startDrag(Qt::DropActions supportedActions);
00299 #endif
00300 
00301     virtual QStyleOptionViewItem viewOptions() const;
00302 
00303     enum State {
00304         NoState,
00305         DraggingState,
00306         DragSelectingState,
00307         EditingState,
00308         ExpandingState,
00309         CollapsingState,
00310         AnimatingState
00311     };
00312 
00313     State state() const;
00314     void setState(State state);
00315 
00316     void scheduleDelayedItemsLayout();
00317     void executeDelayedItemsLayout();
00318 
00319     void setDirtyRegion(const QRegion &region);
00320     void scrollDirtyRegion(int dx, int dy);
00321     QPoint dirtyRegionOffset() const;
00322 
00323     void startAutoScroll();
00324     void stopAutoScroll();
00325     void doAutoScroll();
00326 
00327     bool focusNextPrevChild(bool next);
00328     bool event(QEvent *event);
00329     bool viewportEvent(QEvent *event);
00330     void mousePressEvent(QMouseEvent *event);
00331     void mouseMoveEvent(QMouseEvent *event);
00332     void mouseReleaseEvent(QMouseEvent *event);
00333     void mouseDoubleClickEvent(QMouseEvent *event);
00334 #ifndef QT_NO_DRAGANDDROP
00335     void dragEnterEvent(QDragEnterEvent *event);
00336     void dragMoveEvent(QDragMoveEvent *event);
00337     void dragLeaveEvent(QDragLeaveEvent *event);
00338     void dropEvent(QDropEvent *event);
00339 #endif
00340     void focusInEvent(QFocusEvent *event);
00341     void focusOutEvent(QFocusEvent *event);
00342     void keyPressEvent(QKeyEvent *event);
00343     void resizeEvent(QResizeEvent *event);
00344     void timerEvent(QTimerEvent *event);
00345     void inputMethodEvent(QInputMethodEvent *event);
00346 
00347 #ifndef QT_NO_DRAGANDDROP
00348     enum DropIndicatorPosition { OnItem, AboveItem, BelowItem, OnViewport };
00349     DropIndicatorPosition dropIndicatorPosition() const;
00350 #endif
00351 
00352 private:
00353     Q_DECLARE_PRIVATE(QAbstractItemView)
00354     Q_DISABLE_COPY(QAbstractItemView)
00355     Q_PRIVATE_SLOT(d_func(), void _q_columnsAboutToBeRemoved(const QModelIndex&, int, int))
00356     Q_PRIVATE_SLOT(d_func(), void _q_columnsRemoved(const QModelIndex&, int, int))
00357     Q_PRIVATE_SLOT(d_func(), void _q_columnsInserted(const QModelIndex&, int, int))
00358     Q_PRIVATE_SLOT(d_func(), void _q_rowsRemoved(const QModelIndex&, int, int))
00359     Q_PRIVATE_SLOT(d_func(), void _q_modelDestroyed())
00360     Q_PRIVATE_SLOT(d_func(), void _q_layoutChanged())
00361     Q_PRIVATE_SLOT(d_func(), void _q_headerDataChanged())
00362 
00363     friend class QTreeViewPrivate; // needed to compile with MSVC
00364     friend class QAccessibleItemRow;
00365     friend class QListModeViewBase;
00366     friend class QListViewPrivate; // needed to compile for Symbian emulator
00367 };
00368 
00369 Q_DECLARE_OPERATORS_FOR_FLAGS(QAbstractItemView::EditTriggers)
00370 
00371 #endif // QT_NO_ITEMVIEWS
00372 
00373 QT_END_NAMESPACE
00374 
00375 QT_END_HEADER
00376 
00377 #endif // QABSTRACTITEMVIEW_H