pqHeaderView.h
Go to the documentation of this file.
1 // SPDX-FileCopyrightText: Copyright (c) Kitware Inc.
2 // SPDX-FileCopyrightText: Copyright (c) Sandia Corporation
3 // SPDX-License-Identifier: BSD-3-Clause
4 #ifndef pqHeaderView_h
5 #define pqHeaderView_h
6 
7 #include "pqWidgetsModule.h" // for exports
8 #include <QHeaderView>
9 #include <QPoint> // for QPoint
10 #include <QRect> // for QRect
11 
12 #include <utility> // for std::pair
13 #include <vector> // for std::vector
14 
33 class PQWIDGETS_EXPORT pqHeaderView : public QHeaderView
34 {
35  Q_OBJECT
36  typedef QHeaderView Superclass;
37  Q_PROPERTY(bool showCustomIndicator READ isCustomIndicatorShown WRITE setCustomIndicatorShown);
38 
39 public:
40  pqHeaderView(Qt::Orientation orientation, QWidget* parent = nullptr);
41  ~pqHeaderView() override;
42 
44 
51  void setToggleCheckStateOnSectionClick(bool val) { this->ToggleCheckStateOnSectionClick = val; }
52  bool toggleCheckStateOnSectionClick() const { return this->ToggleCheckStateOnSectionClick; }
54 
56 
64  bool isCustomIndicatorShown() const { return this->CustomIndicatorShown; }
65  void setCustomIndicatorShown(bool val);
67 
69 
76  void addCustomIndicatorIcon(const QIcon& icon, const QString& role);
77  void removeCustomIndicatorIcon(const QString& role);
78  QIcon customIndicatorIcon(const QString& role) const;
80 
87  QRect lastCheckRect() const { return this->CheckRect; }
88 
89 Q_SIGNALS:
90  void customIndicatorClicked(int section, const QPoint& pt, const QString& role);
91 
92 protected:
93  void paintSection(QPainter* painter, const QRect& rect, int logicalIndex) const override;
94  void mousePressEvent(QMouseEvent* event) override;
95  void mouseReleaseEvent(QMouseEvent* event) override;
96 
97 private:
98  Q_DISABLE_COPY(pqHeaderView);
99 
100  // return true if we handled the event.
101  bool mouseClickEvent(QMouseEvent* event);
102 
103  bool ToggleCheckStateOnSectionClick;
104  QPoint PressPosition;
105  mutable QRect CheckRect;
106 
107  bool CustomIndicatorShown;
108 
109  // we keep as a vector since order of addition of icons is important.
110  std::vector<std::pair<QIcon, QString>> CustomIndicatorIcons;
111  mutable std::vector<std::pair<QRect, QString>> CustomIndicatorRects;
112 };
113 
114 #endif
bool toggleCheckStateOnSectionClick() const
For checkable section, this property controls if clicks on the entire section should be treated as a ...
Definition: pqHeaderView.h:52
pqHeaderView extends QHeaderView to add support for Qt::CheckStateRole.
Definition: pqHeaderView.h:33
void setToggleCheckStateOnSectionClick(bool val)
For checkable section, this property controls if clicks on the entire section should be treated as a ...
Definition: pqHeaderView.h:51
QRect lastCheckRect() const
For testing purposes only.
Definition: pqHeaderView.h:87
#define PQWIDGETS_EXPORT
bool isCustomIndicatorShown() const
This property holds if a custom indicator is shown for sections.
Definition: pqHeaderView.h:64