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
14#ifndef ABSTRACTBARCHARTITEM_H
15#define ABSTRACTBARCHARTITEM_H
16
17#include <private/chartitem_p.h>
18#include <QtCharts/QAbstractBarSeries>
19#include <QtCharts/private/qchartglobal_p.h>
20#include <QtGui/QPen>
21#include <QtGui/QBrush>
22#include <QtCore/QMap>
23#include <QtCore/QList>
24
25QT_BEGIN_NAMESPACE
26
27class Bar;
28class QAxisCategories;
29class QChart;
30class BarAnimation;
31class QBarSetPrivate;
32class QAbstractAxis;
33
34class Q_CHARTS_PRIVATE_EXPORT AbstractBarChartItem : public ChartItem
35{
36 Q_OBJECT
37public:
38 AbstractBarChartItem(QAbstractBarSeries *series, QGraphicsItem* item = 0);
39 virtual ~AbstractBarChartItem();
40
41public:
42 void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) override;
43 QRectF boundingRect() const override;
44
45 virtual QList<QRectF> calculateLayout() = 0;
46 void initializeFullLayout();
47 virtual void initializeLayout(int set, int category, int layoutIndex, bool resetAnimation) = 0;
48 virtual void applyLayout(const QList<QRectF> &layout);
49 virtual void setAnimation(BarAnimation *animation);
50 ChartAnimation *animation() const override;
51 void setLayout(const QList<QRectF> &layout);
52 QRectF geometry() const { return m_rect;}
53 void resetAnimation();
54
55public Q_SLOTS:
56 void handleDomainUpdated() override;
57 void handleLayoutChanged();
58 void handleLabelsVisibleChanged(bool visible);
59 void handleDataStructureChanged(); // structure of of series has changed, recreate graphic items
60 void handleVisibleChanged();
61 void handleOpacityChanged();
62 void handleUpdatedBars();
63 void handleLabelsPositionChanged();
64 virtual void positionLabels();
65 void handleBarValueChange(int index, QBarSet *barset);
66 void handleBarValueAdd(int index, int count, QBarSet *barset);
67 void handleBarValueRemove(int index, int count, QBarSet *barset);
68 void handleSeriesAdded(QAbstractSeries *series);
69 void handleSeriesRemoved(QAbstractSeries *series);
70
71protected:
72 void positionLabelsVertical();
73 void createLabelItems();
74 void handleSetStructureChange();
75 virtual QString generateLabelText(int set, int category, qreal value);
76 void updateBarItems();
77 virtual void markLabelsDirty(QBarSet *barset, int index, int count);
78 void calculateSeriesPositionAdjustmentAndWidth();
79
80 QRectF m_rect;
81 QList<QRectF> m_layout;
82
83 BarAnimation *m_animation;
84
85 QAbstractBarSeries *m_series; // Not owned.
86 QMap<QBarSet *, QList<Bar *> > m_barMap;
87 QMap<QBarSet *, QHash<int, Bar *> > m_indexForBarMap;
88 int m_firstCategory;
89 int m_lastCategory;
90 int m_categoryCount;
91 QSizeF m_oldSize;
92 bool m_labelItemsMissing;
93 Qt::Orientation m_orientation;
94 bool m_resetAnimation;
95 qreal m_seriesPosAdjustment;
96 qreal m_seriesWidth;
97};
98
99QT_END_NAMESPACE
100
101#endif // ABSTRACTBARCHARTITEM_H
102

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