src/gui/itemviews/qheaderview.h

Go to the documentation of this file.
00001 /****************************************************************************
00002 **
00003 ** Copyright (C) 1992-2006 Trolltech ASA. All rights reserved.
00004 **
00005 ** This file is part of the QtGui module of the Qt Toolkit.
00006 **
00007 ** This file may be used under the terms of the GNU General Public
00008 ** License version 2.0 as published by the Free Software Foundation
00009 ** and appearing in the file LICENSE.GPL included in the packaging of
00010 ** this file.  Please review the following information to ensure GNU
00011 ** General Public Licensing requirements will be met:
00012 ** http://www.trolltech.com/products/qt/opensource.html
00013 **
00014 ** If you are unsure which license is appropriate for your use, please
00015 ** review the following information:
00016 ** http://www.trolltech.com/products/qt/licensing.html or contact the
00017 ** sales department at sales@trolltech.com.
00018 **
00019 ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
00020 ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
00021 **
00022 ****************************************************************************/
00023 
00024 #ifndef QHEADERVIEW_H
00025 #define QHEADERVIEW_H
00026 
00027 #include <QtGui/qabstractitemview.h>
00028 
00029 QT_BEGIN_HEADER
00030 
00031 QT_MODULE(Gui)
00032 
00033 #ifndef QT_NO_ITEMVIEWS
00034 
00035 class QHeaderViewPrivate;
00036 
00037 class Q_GUI_EXPORT QHeaderView : public QAbstractItemView
00038 {
00039     Q_OBJECT
00040     Q_PROPERTY(bool showSortIndicator READ isSortIndicatorShown WRITE setSortIndicatorShown)
00041     Q_PROPERTY(bool highlightSections READ highlightSections WRITE setHighlightSections)
00042     Q_PROPERTY(bool stretchLastSection READ stretchLastSection WRITE setStretchLastSection)
00043     Q_PROPERTY(bool cascadingSectionResizes READ cascadingSectionResizes WRITE setCascadingSectionResizes)
00044     Q_PROPERTY(int defaultSectionSize READ defaultSectionSize WRITE setDefaultSectionSize)
00045     Q_PROPERTY(int minimumSectionSize READ minimumSectionSize WRITE setMinimumSectionSize)
00046     Q_PROPERTY(Qt::Alignment defaultAlignment READ defaultAlignment WRITE setDefaultAlignment)
00047     Q_ENUMS(ResizeMode)
00048 
00049 public:
00050 
00051     enum ResizeMode
00052     {
00053         Interactive,
00054         Stretch,
00055         Fixed,
00056         Custom = Fixed,
00057         ResizeToContents
00058     };
00059 
00060     explicit QHeaderView(Qt::Orientation orientation, QWidget *parent = 0);
00061     virtual ~QHeaderView();
00062 
00063     void setModel(QAbstractItemModel *model);
00064 
00065     Qt::Orientation orientation() const;
00066     int offset() const;
00067     int length() const;
00068     QSize sizeHint() const;
00069     int sectionSizeHint(int logicalIndex) const;
00070 
00071     int visualIndexAt(int position) const;
00072     int logicalIndexAt(int position) const;
00073 
00074     inline int logicalIndexAt(int x, int y) const;
00075     inline int logicalIndexAt(const QPoint &pos) const;
00076 
00077     int sectionSize(int logicalIndex) const;
00078     int sectionPosition(int logicalIndex) const;
00079     int sectionViewportPosition(int logicalIndex) const;
00080 
00081     void moveSection(int from, int to);
00082     void swapSections(int first, int second);
00083     void resizeSection(int logicalIndex, int size);
00084     void resizeSections(QHeaderView::ResizeMode mode);
00085 
00086     bool isSectionHidden(int logicalIndex) const;
00087     void setSectionHidden(int logicalIndex, bool hide);
00088     int hiddenSectionCount() const;
00089 
00090     inline void hideSection(int logicalIndex);
00091     inline void showSection(int logicalIndex);
00092 
00093     int count() const;
00094     int visualIndex(int logicalIndex) const;
00095     int logicalIndex(int visualIndex) const;
00096 
00097     void setMovable(bool movable);
00098     bool isMovable() const;
00099 
00100     void setClickable(bool clickable);
00101     bool isClickable() const;
00102 
00103     void setHighlightSections(bool highlight);
00104     bool highlightSections() const;
00105 
00106     void setResizeMode(ResizeMode mode);
00107     void setResizeMode(int logicalIndex, ResizeMode mode);
00108     ResizeMode resizeMode(int logicalIndex) const;
00109     int stretchSectionCount() const;
00110 
00111     void setSortIndicatorShown(bool show);
00112     bool isSortIndicatorShown() const;
00113 
00114     void setSortIndicator(int logicalIndex, Qt::SortOrder order);
00115     int sortIndicatorSection() const;
00116     Qt::SortOrder sortIndicatorOrder() const;
00117 
00118     bool stretchLastSection() const;
00119     void setStretchLastSection(bool stretch);
00120 
00121     bool cascadingSectionResizes() const;
00122     void setCascadingSectionResizes(bool enable);
00123 
00124     int defaultSectionSize() const;
00125     void setDefaultSectionSize(int size);
00126 
00127     int minimumSectionSize() const;
00128     void setMinimumSectionSize(int size);
00129 
00130     Qt::Alignment defaultAlignment() const;
00131     void setDefaultAlignment(Qt::Alignment alignment);
00132 
00133     void doItemsLayout();
00134     bool sectionsMoved() const;
00135     bool sectionsHidden() const;
00136 
00137 public Q_SLOTS:
00138     void setOffset(int offset);
00139     void setOffsetToSectionPosition(int visualIndex);
00140     void headerDataChanged(Qt::Orientation orientation, int logicalFirst, int logicalLast);
00141 
00142 Q_SIGNALS:
00143     void sectionMoved(int logicalIndex, int oldVisualIndex, int newVisualIndex);
00144     void sectionResized(int logicalIndex, int oldSize, int newSize);
00145     void sectionPressed(int logicalIndex);
00146     void sectionClicked(int logicalIndex);
00147     void sectionDoubleClicked(int logicalIndex);
00148     void sectionCountChanged(int oldCount, int newCount);
00149     void sectionHandleDoubleClicked(int logicalIndex);
00150     void sectionAutoResize(int logicalIndex, QHeaderView::ResizeMode mode);
00151     void geometriesChanged();
00152 
00153 protected Q_SLOTS:
00154     void updateSection(int logicalIndex);
00155     void resizeSections();
00156     void sectionsInserted(const QModelIndex &parent, int logicalFirst, int logicalLast);
00157     void sectionsAboutToBeRemoved(const QModelIndex &parent, int logicalFirst, int logicalLast);
00158 
00159 protected:
00160     QHeaderView(QHeaderViewPrivate &dd, Qt::Orientation orientation, QWidget *parent = 0);
00161     void initialize();
00162 
00163     void initializeSections();
00164     void initializeSections(int start, int end);
00165     void currentChanged(const QModelIndex &current, const QModelIndex &old);
00166 
00167     bool event(QEvent *e);
00168     void paintEvent(QPaintEvent *e);
00169     void mousePressEvent(QMouseEvent *e);
00170     void mouseMoveEvent(QMouseEvent *e);
00171     void mouseReleaseEvent(QMouseEvent *e);
00172     void mouseDoubleClickEvent(QMouseEvent *e);
00173     bool viewportEvent(QEvent *e);
00174 
00175     virtual void paintSection(QPainter *painter, const QRect &rect, int logicalIndex) const;
00176     virtual QSize sectionSizeFromContents(int logicalIndex) const;
00177 
00178     int horizontalOffset() const;
00179     int verticalOffset() const;
00180     void updateGeometries();
00181     void scrollContentsBy(int dx, int dy);
00182 
00183     void dataChanged(const QModelIndex &topLeft, const QModelIndex &bottomRight);
00184     void rowsInserted(const QModelIndex &parent, int start, int end);
00185 
00186     QRect visualRect(const QModelIndex &index) const;
00187     void scrollTo(const QModelIndex &index, ScrollHint hint);
00188 
00189     QModelIndex indexAt(const QPoint &p) const;
00190     bool isIndexHidden(const QModelIndex &index) const;
00191 
00192     QModelIndex moveCursor(CursorAction, Qt::KeyboardModifiers);
00193     void setSelection(const QRect&, QItemSelectionModel::SelectionFlags);
00194     QRegion visualRegionForSelection(const QItemSelection &selection) const;
00195 
00196 private:
00197     Q_PRIVATE_SLOT(d_func(), void _q_sectionsRemoved(const QModelIndex &parent, int logicalFirst, int logicalLast))
00198     Q_DECLARE_PRIVATE(QHeaderView)
00199     Q_DISABLE_COPY(QHeaderView)
00200 };
00201 
00202 inline int QHeaderView::logicalIndexAt(int ax, int ay) const
00203 { return orientation() == Qt::Horizontal ? logicalIndexAt(ax) : logicalIndexAt(ay); }
00204 inline int QHeaderView::logicalIndexAt(const QPoint &apos) const
00205 { return logicalIndexAt(apos.x(), apos.y()); }
00206 inline void QHeaderView::hideSection(int alogicalIndex)
00207 { setSectionHidden(alogicalIndex, true); }
00208 inline void QHeaderView::showSection(int alogicalIndex)
00209 { setSectionHidden(alogicalIndex, false); }
00210 
00211 #endif // QT_NO_ITEMVIEWS
00212 
00213 QT_END_HEADER
00214 
00215 #endif // QHEADERVIEW_H

Generated on Thu Mar 15 11:54:47 2007 for Qt 4.2 User's Guide by  doxygen 1.5.1