qtreeview.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 QTREEVIEW_H
00043 #define QTREEVIEW_H
00044 
00045 #include <QtGui/qabstractitemview.h>
00046 
00047 QT_BEGIN_HEADER
00048 
00049 QT_BEGIN_NAMESPACE
00050 
00051 QT_MODULE(Gui)
00052 
00053 #ifndef QT_NO_TREEVIEW
00054 
00055 class QTreeViewPrivate;
00056 class QHeaderView;
00057 
00058 class Q_GUI_EXPORT QTreeView : public QAbstractItemView
00059 {
00060     Q_OBJECT
00061     Q_PROPERTY(int autoExpandDelay READ autoExpandDelay WRITE setAutoExpandDelay)
00062     Q_PROPERTY(int indentation READ indentation WRITE setIndentation)
00063     Q_PROPERTY(bool rootIsDecorated READ rootIsDecorated WRITE setRootIsDecorated)
00064     Q_PROPERTY(bool uniformRowHeights READ uniformRowHeights WRITE setUniformRowHeights)
00065     Q_PROPERTY(bool itemsExpandable READ itemsExpandable WRITE setItemsExpandable)
00066     Q_PROPERTY(bool sortingEnabled READ isSortingEnabled WRITE setSortingEnabled)
00067     Q_PROPERTY(bool animated READ isAnimated WRITE setAnimated)
00068     Q_PROPERTY(bool allColumnsShowFocus READ allColumnsShowFocus WRITE setAllColumnsShowFocus)
00069     Q_PROPERTY(bool wordWrap READ wordWrap WRITE setWordWrap)
00070     Q_PROPERTY(bool headerHidden READ isHeaderHidden WRITE setHeaderHidden)
00071     Q_PROPERTY(bool expandsOnDoubleClick READ expandsOnDoubleClick WRITE setExpandsOnDoubleClick)
00072 
00073 public:
00074     explicit QTreeView(QWidget *parent = 0);
00075     ~QTreeView();
00076 
00077     void setModel(QAbstractItemModel *model);
00078     void setRootIndex(const QModelIndex &index);
00079     void setSelectionModel(QItemSelectionModel *selectionModel);
00080 
00081     QHeaderView *header() const;
00082     void setHeader(QHeaderView *header);
00083 
00084     int autoExpandDelay() const;
00085     void setAutoExpandDelay(int delay);
00086 
00087     int indentation() const;
00088     void setIndentation(int i);
00089 
00090     bool rootIsDecorated() const;
00091     void setRootIsDecorated(bool show);
00092 
00093     bool uniformRowHeights() const;
00094     void setUniformRowHeights(bool uniform);
00095 
00096     bool itemsExpandable() const;
00097     void setItemsExpandable(bool enable);
00098 
00099     bool expandsOnDoubleClick() const;
00100     void setExpandsOnDoubleClick(bool enable);
00101 
00102     int columnViewportPosition(int column) const;
00103     int columnWidth(int column) const;
00104     void setColumnWidth(int column, int width);
00105     int columnAt(int x) const;
00106 
00107     bool isColumnHidden(int column) const;
00108     void setColumnHidden(int column, bool hide);
00109 
00110     bool isHeaderHidden() const;
00111     void setHeaderHidden(bool hide);
00112 
00113     bool isRowHidden(int row, const QModelIndex &parent) const;
00114     void setRowHidden(int row, const QModelIndex &parent, bool hide);
00115 
00116     bool isFirstColumnSpanned(int row, const QModelIndex &parent) const;
00117     void setFirstColumnSpanned(int row, const QModelIndex &parent, bool span);
00118 
00119     bool isExpanded(const QModelIndex &index) const;
00120     void setExpanded(const QModelIndex &index, bool expand);
00121 
00122     void setSortingEnabled(bool enable);
00123     bool isSortingEnabled() const;
00124 
00125     void setAnimated(bool enable);
00126     bool isAnimated() const;
00127 
00128     void setAllColumnsShowFocus(bool enable);
00129     bool allColumnsShowFocus() const;
00130 
00131     void setWordWrap(bool on);
00132     bool wordWrap() const;
00133 
00134     void keyboardSearch(const QString &search);
00135 
00136     QRect visualRect(const QModelIndex &index) const;
00137     void scrollTo(const QModelIndex &index, ScrollHint hint = EnsureVisible);
00138     QModelIndex indexAt(const QPoint &p) const;
00139     QModelIndex indexAbove(const QModelIndex &index) const;
00140     QModelIndex indexBelow(const QModelIndex &index) const;
00141 
00142     void doItemsLayout();
00143     void reset();
00144 
00145     void sortByColumn(int column, Qt::SortOrder order);
00146 
00147     void dataChanged(const QModelIndex &topLeft, const QModelIndex &bottomRight);
00148     void selectAll();
00149 
00150 Q_SIGNALS:
00151     void expanded(const QModelIndex &index);
00152     void collapsed(const QModelIndex &index);
00153 
00154 public Q_SLOTS:
00155     void hideColumn(int column);
00156     void showColumn(int column);
00157     void expand(const QModelIndex &index);
00158     void collapse(const QModelIndex &index);
00159     void resizeColumnToContents(int column);
00160     void sortByColumn(int column);
00161     void expandAll();
00162     void collapseAll();
00163     void expandToDepth(int depth);
00164 
00165 protected Q_SLOTS:
00166     void columnResized(int column, int oldSize, int newSize);
00167     void columnCountChanged(int oldCount, int newCount);
00168     void columnMoved();
00169     void reexpand();
00170     void rowsRemoved(const QModelIndex &parent, int first, int last);
00171 
00172 protected:
00173     QTreeView(QTreeViewPrivate &dd, QWidget *parent = 0);
00174     void scrollContentsBy(int dx, int dy);
00175     void rowsInserted(const QModelIndex &parent, int start, int end);
00176     void rowsAboutToBeRemoved(const QModelIndex &parent, int start, int end);
00177 
00178     QModelIndex moveCursor(CursorAction cursorAction, Qt::KeyboardModifiers modifiers);
00179     int horizontalOffset() const;
00180     int verticalOffset() const;
00181 
00182     void setSelection(const QRect &rect, QItemSelectionModel::SelectionFlags command);
00183     QRegion visualRegionForSelection(const QItemSelection &selection) const;
00184     QModelIndexList selectedIndexes() const;
00185 
00186     void timerEvent(QTimerEvent *event);
00187     void paintEvent(QPaintEvent *event);
00188 
00189     void drawTree(QPainter *painter, const QRegion &region) const;
00190     virtual void drawRow(QPainter *painter,
00191                          const QStyleOptionViewItem &options,
00192                          const QModelIndex &index) const;
00193     virtual void drawBranches(QPainter *painter,
00194                               const QRect &rect,
00195                               const QModelIndex &index) const;
00196 
00197     void mousePressEvent(QMouseEvent *event);
00198     void mouseReleaseEvent(QMouseEvent *event);
00199     void mouseDoubleClickEvent(QMouseEvent *event);
00200     void mouseMoveEvent(QMouseEvent *event);
00201     void keyPressEvent(QKeyEvent *event);
00202 #ifndef QT_NO_DRAGANDDROP
00203     void dragMoveEvent(QDragMoveEvent *event);
00204 #endif
00205     bool viewportEvent(QEvent *event);
00206 
00207     void updateGeometries();
00208 
00209     int sizeHintForColumn(int column) const;
00210     int indexRowSizeHint(const QModelIndex &index) const;
00211     int rowHeight(const QModelIndex &index) const;
00212 
00213     void horizontalScrollbarAction(int action);
00214 
00215     bool isIndexHidden(const QModelIndex &index) const;
00216     void selectionChanged(const QItemSelection &selected,
00217                           const QItemSelection &deselected);
00218     void currentChanged(const QModelIndex &current, const QModelIndex &previous);
00219 
00220 private:
00221     friend class QAccessibleItemView;
00222     int visualIndex(const QModelIndex &index) const;
00223 
00224     Q_DECLARE_PRIVATE(QTreeView)
00225     Q_DISABLE_COPY(QTreeView)
00226 #ifndef QT_NO_ANIMATION
00227     Q_PRIVATE_SLOT(d_func(), void _q_endAnimatedOperation())
00228 #endif //QT_NO_ANIMATION
00229     Q_PRIVATE_SLOT(d_func(), void _q_modelAboutToBeReset())
00230     Q_PRIVATE_SLOT(d_func(), void _q_sortIndicatorChanged(int column, Qt::SortOrder order))
00231 };
00232 
00233 #endif // QT_NO_TREEVIEW
00234 
00235 QT_END_NAMESPACE
00236 
00237 QT_END_HEADER
00238 
00239 #endif // QTREEVIEW_H