1// Copyright (C) 2016 The Qt Company Ltd.
2// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only
3
4// W A R N I N G
5// -------------
6//
7// This file is not part of the Qt Chart API. It exists purely as an
8// implementation detail. This header file may change from version to
9// version without notice, or even be removed.
10//
11// We mean it.
12
13#ifndef BAR_H
14#define BAR_H
15
16#include <QtCharts/QChartGlobal>
17#include <QtCharts/private/qchartglobal_p.h>
18#include <QtWidgets/QGraphicsRectItem>
19#include <QtWidgets/QGraphicsTextItem>
20
21QT_BEGIN_NAMESPACE
22
23class QBarSet;
24
25// Single visual bar item of chart
26class Q_CHARTS_PRIVATE_EXPORT Bar : public QObject, public QGraphicsRectItem
27{
28 Q_OBJECT
29public:
30 Bar(QBarSet *barset, QGraphicsItem *parent = 0);
31 ~Bar();
32
33public:
34 void mousePressEvent(QGraphicsSceneMouseEvent *event) override;
35 void hoverEnterEvent(QGraphicsSceneHoverEvent *event) override;
36 void hoverLeaveEvent(QGraphicsSceneHoverEvent *event) override;
37 void mouseReleaseEvent(QGraphicsSceneMouseEvent *event) override;
38 void mouseDoubleClickEvent(QGraphicsSceneMouseEvent *event) override;
39
40 void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget = 0) override;
41 void setVisualsDirty(bool dirty) { m_visualsDirty = dirty; }
42 bool visualsDirty() const { return m_visualsDirty; }
43 void setLabelDirty(bool dirty) { m_labelDirty = dirty; }
44 bool labelDirty() const { return m_labelDirty; }
45
46 void setLabelItem(QGraphicsTextItem *labelItem) { m_labelItem = labelItem; }
47 QGraphicsTextItem *labelItem() const { return m_labelItem; }
48
49 void setIndex(int index) { m_index = index; }
50 int index() const { return m_index; }
51 void setLayoutIndex(int index) { m_layoutIndex = index; }
52 int layoutIndex() const { return m_layoutIndex; }
53
54Q_SIGNALS:
55 void clicked(int index, QBarSet *barset);
56 void hovered(bool status, int index, QBarSet *barset);
57 void pressed(int index, QBarSet *barset);
58 void released(int index, QBarSet *barset);
59 void doubleClicked(int index, QBarSet *barset);
60
61private:
62 int m_index;
63 int m_layoutIndex;
64 QBarSet *m_barset;
65 QGraphicsTextItem *m_labelItem;
66 bool m_hovering;
67 bool m_mousePressed;
68 bool m_visualsDirty;
69 bool m_labelDirty;
70};
71
72QT_END_NAMESPACE
73
74#endif // BAR_H
75

source code of qtcharts/src/charts/barchart/bar_p.h