File indexing completed on 2025-01-18 10:09:35
0001
0002
0003
0004 #ifndef QHEADERVIEW_H
0005 #define QHEADERVIEW_H
0006
0007 #include <QtWidgets/qtwidgetsglobal.h>
0008 #include <QtWidgets/qabstractitemview.h>
0009
0010 QT_REQUIRE_CONFIG(itemviews);
0011
0012 QT_BEGIN_NAMESPACE
0013
0014 class QHeaderViewPrivate;
0015 class QStyleOptionHeader;
0016
0017 class Q_WIDGETS_EXPORT QHeaderView : public QAbstractItemView
0018 {
0019 Q_OBJECT
0020 Q_PROPERTY(bool firstSectionMovable READ isFirstSectionMovable WRITE setFirstSectionMovable)
0021 Q_PROPERTY(bool showSortIndicator READ isSortIndicatorShown WRITE setSortIndicatorShown)
0022 Q_PROPERTY(bool highlightSections READ highlightSections WRITE setHighlightSections)
0023 Q_PROPERTY(bool stretchLastSection READ stretchLastSection WRITE setStretchLastSection)
0024 Q_PROPERTY(bool cascadingSectionResizes READ cascadingSectionResizes
0025 WRITE setCascadingSectionResizes)
0026 Q_PROPERTY(int defaultSectionSize READ defaultSectionSize WRITE setDefaultSectionSize
0027 RESET resetDefaultSectionSize)
0028 Q_PROPERTY(int minimumSectionSize READ minimumSectionSize WRITE setMinimumSectionSize)
0029 Q_PROPERTY(int maximumSectionSize READ maximumSectionSize WRITE setMaximumSectionSize)
0030 Q_PROPERTY(Qt::Alignment defaultAlignment READ defaultAlignment WRITE setDefaultAlignment)
0031 Q_PROPERTY(bool sortIndicatorClearable READ isSortIndicatorClearable
0032 WRITE setSortIndicatorClearable NOTIFY sortIndicatorClearableChanged)
0033
0034 public:
0035
0036 enum ResizeMode
0037 {
0038 Interactive,
0039 Stretch,
0040 Fixed,
0041 ResizeToContents,
0042 Custom = Fixed
0043 };
0044 Q_ENUM(ResizeMode)
0045
0046 explicit QHeaderView(Qt::Orientation orientation, QWidget *parent = nullptr);
0047 virtual ~QHeaderView();
0048
0049 void setModel(QAbstractItemModel *model) override;
0050
0051 Qt::Orientation orientation() const;
0052 int offset() const;
0053 int length() const;
0054 QSize sizeHint() const override;
0055 void setVisible(bool v) override;
0056 int sectionSizeHint(int logicalIndex) const;
0057
0058 int visualIndexAt(int position) const;
0059 int logicalIndexAt(int position) const;
0060
0061 inline int logicalIndexAt(int x, int y) const;
0062 inline int logicalIndexAt(const QPoint &pos) const;
0063
0064 int sectionSize(int logicalIndex) const;
0065 int sectionPosition(int logicalIndex) const;
0066 int sectionViewportPosition(int logicalIndex) const;
0067
0068 void moveSection(int from, int to);
0069 void swapSections(int first, int second);
0070 void resizeSection(int logicalIndex, int size);
0071 void resizeSections(QHeaderView::ResizeMode mode);
0072
0073 bool isSectionHidden(int logicalIndex) const;
0074 void setSectionHidden(int logicalIndex, bool hide);
0075 int hiddenSectionCount() const;
0076
0077 inline void hideSection(int logicalIndex);
0078 inline void showSection(int logicalIndex);
0079
0080 int count() const;
0081 int visualIndex(int logicalIndex) const;
0082 int logicalIndex(int visualIndex) const;
0083
0084 void setSectionsMovable(bool movable);
0085 bool sectionsMovable() const;
0086 void setFirstSectionMovable(bool movable);
0087 bool isFirstSectionMovable() const;
0088
0089 void setSectionsClickable(bool clickable);
0090 bool sectionsClickable() const;
0091
0092 void setHighlightSections(bool highlight);
0093 bool highlightSections() const;
0094
0095 ResizeMode sectionResizeMode(int logicalIndex) const;
0096 void setSectionResizeMode(ResizeMode mode);
0097 void setSectionResizeMode(int logicalIndex, ResizeMode mode);
0098
0099 void setResizeContentsPrecision(int precision);
0100 int resizeContentsPrecision() const;
0101
0102 int stretchSectionCount() const;
0103
0104 void setSortIndicatorShown(bool show);
0105 bool isSortIndicatorShown() const;
0106
0107 void setSortIndicator(int logicalIndex, Qt::SortOrder order);
0108 int sortIndicatorSection() const;
0109 Qt::SortOrder sortIndicatorOrder() const;
0110
0111 void setSortIndicatorClearable(bool clearable);
0112 bool isSortIndicatorClearable() const;
0113
0114 bool stretchLastSection() const;
0115 void setStretchLastSection(bool stretch);
0116
0117 bool cascadingSectionResizes() const;
0118 void setCascadingSectionResizes(bool enable);
0119
0120 int defaultSectionSize() const;
0121 void setDefaultSectionSize(int size);
0122 void resetDefaultSectionSize();
0123
0124 int minimumSectionSize() const;
0125 void setMinimumSectionSize(int size);
0126 int maximumSectionSize() const;
0127 void setMaximumSectionSize(int size);
0128
0129 Qt::Alignment defaultAlignment() const;
0130 void setDefaultAlignment(Qt::Alignment alignment);
0131
0132 void doItemsLayout() override;
0133 bool sectionsMoved() const;
0134 bool sectionsHidden() const;
0135
0136 #ifndef QT_NO_DATASTREAM
0137 QByteArray saveState() const;
0138 bool restoreState(const QByteArray &state);
0139 #endif
0140
0141 void reset() override;
0142
0143 public Q_SLOTS:
0144 void setOffset(int offset);
0145 void setOffsetToSectionPosition(int visualIndex);
0146 void setOffsetToLastSection();
0147 void headerDataChanged(Qt::Orientation orientation, int logicalFirst, int logicalLast);
0148
0149 Q_SIGNALS:
0150 void sectionMoved(int logicalIndex, int oldVisualIndex, int newVisualIndex);
0151 void sectionResized(int logicalIndex, int oldSize, int newSize);
0152 void sectionPressed(int logicalIndex);
0153 void sectionClicked(int logicalIndex);
0154 void sectionEntered(int logicalIndex);
0155 void sectionDoubleClicked(int logicalIndex);
0156 void sectionCountChanged(int oldCount, int newCount);
0157 void sectionHandleDoubleClicked(int logicalIndex);
0158 void geometriesChanged();
0159 void sortIndicatorChanged(int logicalIndex, Qt::SortOrder order);
0160 void sortIndicatorClearableChanged(bool clearable);
0161
0162 protected Q_SLOTS:
0163 void updateSection(int logicalIndex);
0164 void resizeSections();
0165 void sectionsInserted(const QModelIndex &parent, int logicalFirst, int logicalLast);
0166 void sectionsAboutToBeRemoved(const QModelIndex &parent, int logicalFirst, int logicalLast);
0167
0168 protected:
0169 QHeaderView(QHeaderViewPrivate &dd, Qt::Orientation orientation, QWidget *parent = nullptr);
0170 void initialize();
0171
0172 void initializeSections();
0173 void initializeSections(int start, int end);
0174 void currentChanged(const QModelIndex ¤t, const QModelIndex &old) override;
0175
0176 bool event(QEvent *e) override;
0177 void paintEvent(QPaintEvent *e) override;
0178 void mousePressEvent(QMouseEvent *e) override;
0179 void mouseMoveEvent(QMouseEvent *e) override;
0180 void mouseReleaseEvent(QMouseEvent *e) override;
0181 void mouseDoubleClickEvent(QMouseEvent *e) override;
0182 bool viewportEvent(QEvent *e) override;
0183
0184 virtual void paintSection(QPainter *painter, const QRect &rect, int logicalIndex) const;
0185 virtual QSize sectionSizeFromContents(int logicalIndex) const;
0186
0187 int horizontalOffset() const override;
0188 int verticalOffset() const override;
0189 void updateGeometries() override;
0190 void scrollContentsBy(int dx, int dy) override;
0191
0192 void dataChanged(const QModelIndex &topLeft, const QModelIndex &bottomRight,
0193 const QList<int> &roles = QList<int>()) override;
0194 void rowsInserted(const QModelIndex &parent, int start, int end) override;
0195
0196 QRect visualRect(const QModelIndex &index) const override;
0197 void scrollTo(const QModelIndex &index, ScrollHint hint) override;
0198
0199 QModelIndex indexAt(const QPoint &p) const override;
0200 bool isIndexHidden(const QModelIndex &index) const override;
0201
0202 QModelIndex moveCursor(CursorAction, Qt::KeyboardModifiers) override;
0203 void setSelection(const QRect& rect, QItemSelectionModel::SelectionFlags flags) override;
0204 QRegion visualRegionForSelection(const QItemSelection &selection) const override;
0205 virtual void initStyleOptionForIndex(QStyleOptionHeader *option, int logicalIndex) const;
0206 virtual void initStyleOption(QStyleOptionHeader *option) const;
0207
0208 friend class QTableView;
0209 friend class QTreeView;
0210
0211 private:
0212 void initStyleOption(QStyleOptionFrame *option) const override;
0213
0214 Q_DECLARE_PRIVATE(QHeaderView)
0215 Q_DISABLE_COPY(QHeaderView)
0216 };
0217
0218 inline int QHeaderView::logicalIndexAt(int ax, int ay) const
0219 { return orientation() == Qt::Horizontal ? logicalIndexAt(ax) : logicalIndexAt(ay); }
0220 inline int QHeaderView::logicalIndexAt(const QPoint &apos) const
0221 { return logicalIndexAt(apos.x(), apos.y()); }
0222 inline void QHeaderView::hideSection(int alogicalIndex)
0223 { setSectionHidden(alogicalIndex, true); }
0224 inline void QHeaderView::showSection(int alogicalIndex)
0225 { setSectionHidden(alogicalIndex, false); }
0226
0227 QT_END_NAMESPACE
0228
0229 #endif