- Main Page
- Related Pages
- Modules
- Namespaces
- Classes
- Files
- Directories
- Examples

- File List
- File Members

# qheaderview.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 QHEADERVIEW_H
    00043 #define QHEADERVIEW_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_ITEMVIEWS
    00054
    00055 class QHeaderViewPrivate;
    00056 class QStyleOptionHeader;
    00057
    00058 class Q_GUI_EXPORT QHeaderView : public QAbstractItemView
    00059 {
    00060     Q_OBJECT
    00061     Q_PROPERTY(bool showSortIndicator READ isSortIndicatorShown WRITE setSortIndicatorShown)
    00062     Q_PROPERTY(bool highlightSections READ highlightSections WRITE setHighlightSections)
    00063     Q_PROPERTY(bool stretchLastSection READ stretchLastSection WRITE setStretchLastSection)
    00064     Q_PROPERTY(bool cascadingSectionResizes READ cascadingSectionResizes WRITE setCascadingSectionResizes)
    00065     Q_PROPERTY(int defaultSectionSize READ defaultSectionSize WRITE setDefaultSectionSize)
    00066     Q_PROPERTY(int minimumSectionSize READ minimumSectionSize WRITE setMinimumSectionSize)
    00067     Q_PROPERTY(Qt::Alignment defaultAlignment READ defaultAlignment WRITE setDefaultAlignment)
    00068     Q_ENUMS(ResizeMode)
    00069
    00070 public:
    00071
    00072     enum ResizeMode
    00073     {
    00074         Interactive,
    00075         Stretch,
    00076         Fixed,
    00077         ResizeToContents,
    00078         Custom = Fixed
    00079     };
    00080
    00081     explicit QHeaderView(Qt::Orientation orientation, QWidget *parent = 0);
    00082     virtual ~QHeaderView();
    00083
    00084     void setModel(QAbstractItemModel *model);
    00085
    00086     Qt::Orientation orientation() const;
    00087     int offset() const;
    00088     int length() const;
    00089     QSize sizeHint() const;
    00090     int sectionSizeHint(int logicalIndex) const;
    00091
    00092     int visualIndexAt(int position) const;
    00093     int logicalIndexAt(int position) const;
    00094
    00095     inline int logicalIndexAt(int x, int y) const;
    00096     inline int logicalIndexAt(const QPoint &pos) const;
    00097
    00098     int sectionSize(int logicalIndex) const;
    00099     int sectionPosition(int logicalIndex) const;
    00100     int sectionViewportPosition(int logicalIndex) const;
    00101
    00102     void moveSection(int from, int to);
    00103     void swapSections(int first, int second);
    00104     void resizeSection(int logicalIndex, int size);
    00105     void resizeSections(QHeaderView::ResizeMode mode);
    00106
    00107     bool isSectionHidden(int logicalIndex) const;
    00108     void setSectionHidden(int logicalIndex, bool hide);
    00109     int hiddenSectionCount() const;
    00110
    00111     inline void hideSection(int logicalIndex);
    00112     inline void showSection(int logicalIndex);
    00113
    00114     int count() const;
    00115     int visualIndex(int logicalIndex) const;
    00116     int logicalIndex(int visualIndex) const;
    00117
    00118     void setMovable(bool movable);
    00119     bool isMovable() const;
    00120
    00121     void setClickable(bool clickable);
    00122     bool isClickable() const;
    00123
    00124     void setHighlightSections(bool highlight);
    00125     bool highlightSections() const;
    00126
    00127     void setResizeMode(ResizeMode mode);
    00128     void setResizeMode(int logicalIndex, ResizeMode mode);
    00129     ResizeMode resizeMode(int logicalIndex) const;
    00130     int stretchSectionCount() const;
    00131
    00132     void setSortIndicatorShown(bool show);
    00133     bool isSortIndicatorShown() const;
    00134
    00135     void setSortIndicator(int logicalIndex, Qt::SortOrder order);
    00136     int sortIndicatorSection() const;
    00137     Qt::SortOrder sortIndicatorOrder() const;
    00138
    00139     bool stretchLastSection() const;
    00140     void setStretchLastSection(bool stretch);
    00141
    00142     bool cascadingSectionResizes() const;
    00143     void setCascadingSectionResizes(bool enable);
    00144
    00145     int defaultSectionSize() const;
    00146     void setDefaultSectionSize(int size);
    00147
    00148     int minimumSectionSize() const;
    00149     void setMinimumSectionSize(int size);
    00150
    00151     Qt::Alignment defaultAlignment() const;
    00152     void setDefaultAlignment(Qt::Alignment alignment);
    00153
    00154     void doItemsLayout();
    00155     bool sectionsMoved() const;
    00156     bool sectionsHidden() const;
    00157
    00158 #ifndef QT_NO_DATASTREAM
    00159     QByteArray saveState() const;
    00160     bool restoreState(const QByteArray &state);
    00161 #endif
    00162
    00163     void reset();
    00164
    00165 public Q_SLOTS:
    00166     void setOffset(int offset);
    00167     void setOffsetToSectionPosition(int visualIndex);
    00168     void setOffsetToLastSection();
    00169     void headerDataChanged(Qt::Orientation orientation, int logicalFirst, int logicalLast);
    00170
    00171 Q_SIGNALS:
    00172     void sectionMoved(int logicalIndex, int oldVisualIndex, int newVisualIndex);
    00173     void sectionResized(int logicalIndex, int oldSize, int newSize);
    00174     void sectionPressed(int logicalIndex);
    00175     void sectionClicked(int logicalIndex);
    00176     void sectionEntered(int logicalIndex);
    00177     void sectionDoubleClicked(int logicalIndex);
    00178     void sectionCountChanged(int oldCount, int newCount);
    00179     void sectionHandleDoubleClicked(int logicalIndex);
    00180     void sectionAutoResize(int logicalIndex, QHeaderView::ResizeMode mode);
    00181     void geometriesChanged();
    00182     void sortIndicatorChanged(int logicalIndex, Qt::SortOrder order);
    00183
    00184 protected Q_SLOTS:
    00185     void updateSection(int logicalIndex);
    00186     void resizeSections();
    00187     void sectionsInserted(const QModelIndex &parent, int logicalFirst, int logicalLast);
    00188     void sectionsAboutToBeRemoved(const QModelIndex &parent, int logicalFirst, int logicalLast);
    00189
    00190 protected:
    00191     QHeaderView(QHeaderViewPrivate &dd, Qt::Orientation orientation, QWidget *parent = 0);
    00192     void initialize();
    00193
    00194     void initializeSections();
    00195     void initializeSections(int start, int end);
    00196     void currentChanged(const QModelIndex &current, const QModelIndex &old);
    00197
    00198     bool event(QEvent *e);
    00199     void paintEvent(QPaintEvent *e);
    00200     void mousePressEvent(QMouseEvent *e);
    00201     void mouseMoveEvent(QMouseEvent *e);
    00202     void mouseReleaseEvent(QMouseEvent *e);
    00203     void mouseDoubleClickEvent(QMouseEvent *e);
    00204     bool viewportEvent(QEvent *e);
    00205
    00206     virtual void paintSection(QPainter *painter, const QRect &rect, int logicalIndex) const;
    00207     virtual QSize sectionSizeFromContents(int logicalIndex) const;
    00208
    00209     int horizontalOffset() const;
    00210     int verticalOffset() const;
    00211     void updateGeometries();
    00212     void scrollContentsBy(int dx, int dy);
    00213
    00214     void dataChanged(const QModelIndex &topLeft, const QModelIndex &bottomRight);
    00215     void rowsInserted(const QModelIndex &parent, int start, int end);
    00216
    00217     QRect visualRect(const QModelIndex &index) const;
    00218     void scrollTo(const QModelIndex &index, ScrollHint hint);
    00219
    00220     QModelIndex indexAt(const QPoint &p) const;
    00221     bool isIndexHidden(const QModelIndex &index) const;
    00222
    00223     QModelIndex moveCursor(CursorAction, Qt::KeyboardModifiers);
    00224     void setSelection(const QRect& rect, QItemSelectionModel::SelectionFlags flags);
    00225     QRegion visualRegionForSelection(const QItemSelection &selection) const;
    00226     void initStyleOption(QStyleOptionHeader *option) const;
    00227
    00228 private:
    00229     Q_PRIVATE_SLOT(d_func(), void _q_sectionsRemoved(const QModelIndex &parent, int logicalFirst, int logicalLast))
    00230     Q_PRIVATE_SLOT(d_func(), void _q_layoutAboutToBeChanged())
    00231     Q_DECLARE_PRIVATE(QHeaderView)
    00232     Q_DISABLE_COPY(QHeaderView)
    00233 };
    00234
    00235 inline int QHeaderView::logicalIndexAt(int ax, int ay) const
    00236 { return orientation() == Qt::Horizontal ? logicalIndexAt(ax) : logicalIndexAt(ay); }
    00237 inline int QHeaderView::logicalIndexAt(const QPoint &apos) const
    00238 { return logicalIndexAt(apos.x(), apos.y()); }
    00239 inline void QHeaderView::hideSection(int alogicalIndex)
    00240 { setSectionHidden(alogicalIndex, true); }
    00241 inline void QHeaderView::showSection(int alogicalIndex)
    00242 { setSectionHidden(alogicalIndex, false); }
    00243
    00244 #endif // QT_NO_ITEMVIEWS
    00245
    00246 QT_END_NAMESPACE
    00247
    00248 QT_END_HEADER
    00249
    00250 #endif // QHEADERVIEW_H