| 1 | /**************************************************************************** |
| 2 | ** |
| 3 | ** Copyright (C) 2016 The Qt Company Ltd. |
| 4 | ** Contact: https://www.qt.io/licensing/ |
| 5 | ** |
| 6 | ** This file is part of the Qt Charts module of the Qt Toolkit. |
| 7 | ** |
| 8 | ** $QT_BEGIN_LICENSE:GPL$ |
| 9 | ** Commercial License Usage |
| 10 | ** Licensees holding valid commercial Qt licenses may use this file in |
| 11 | ** accordance with the commercial license agreement provided with the |
| 12 | ** Software or, alternatively, in accordance with the terms contained in |
| 13 | ** a written agreement between you and The Qt Company. For licensing terms |
| 14 | ** and conditions see https://www.qt.io/terms-conditions. For further |
| 15 | ** information use the contact form at https://www.qt.io/contact-us. |
| 16 | ** |
| 17 | ** GNU General Public License Usage |
| 18 | ** Alternatively, this file may be used under the terms of the GNU |
| 19 | ** General Public License version 3 or (at your option) any later version |
| 20 | ** approved by the KDE Free Qt Foundation. The licenses are as published by |
| 21 | ** the Free Software Foundation and appearing in the file LICENSE.GPL3 |
| 22 | ** included in the packaging of this file. Please review the following |
| 23 | ** information to ensure the GNU General Public License requirements will |
| 24 | ** be met: https://www.gnu.org/licenses/gpl-3.0.html. |
| 25 | ** |
| 26 | ** $QT_END_LICENSE$ |
| 27 | ** |
| 28 | ****************************************************************************/ |
| 29 | |
| 30 | // W A R N I N G |
| 31 | // ------------- |
| 32 | // |
| 33 | // This file is not part of the Qt Chart API. It exists purely as an |
| 34 | // implementation detail. This header file may change from version to |
| 35 | // version without notice, or even be removed. |
| 36 | // |
| 37 | // We mean it. |
| 38 | |
| 39 | |
| 40 | #ifndef ABSTRACTBARCHARTITEM_H |
| 41 | #define ABSTRACTBARCHARTITEM_H |
| 42 | |
| 43 | #include <private/chartitem_p.h> |
| 44 | #include <QtCharts/QAbstractBarSeries> |
| 45 | #include <QtCharts/private/qchartglobal_p.h> |
| 46 | #include <QtGui/QPen> |
| 47 | #include <QtGui/QBrush> |
| 48 | |
| 49 | QT_CHARTS_BEGIN_NAMESPACE |
| 50 | |
| 51 | class Bar; |
| 52 | class QAxisCategories; |
| 53 | class QChart; |
| 54 | class BarAnimation; |
| 55 | class QBarSetPrivate; |
| 56 | class QAbstractAxis; |
| 57 | |
| 58 | class Q_CHARTS_PRIVATE_EXPORT AbstractBarChartItem : public ChartItem |
| 59 | { |
| 60 | Q_OBJECT |
| 61 | public: |
| 62 | AbstractBarChartItem(QAbstractBarSeries *series, QGraphicsItem* item = 0); |
| 63 | virtual ~AbstractBarChartItem(); |
| 64 | |
| 65 | public: |
| 66 | void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget); |
| 67 | QRectF boundingRect() const; |
| 68 | |
| 69 | virtual QVector<QRectF> calculateLayout() = 0; |
| 70 | void initializeFullLayout(); |
| 71 | virtual void initializeLayout(int set, int category, int layoutIndex, bool resetAnimation) = 0; |
| 72 | virtual void applyLayout(const QVector<QRectF> &layout); |
| 73 | virtual void setAnimation(BarAnimation *animation); |
| 74 | virtual ChartAnimation *animation() const; |
| 75 | void setLayout(const QVector<QRectF> &layout); |
| 76 | QRectF geometry() const { return m_rect;} |
| 77 | void resetAnimation(); |
| 78 | |
| 79 | public Q_SLOTS: |
| 80 | void handleDomainUpdated(); |
| 81 | void handleLayoutChanged(); |
| 82 | void handleLabelsVisibleChanged(bool visible); |
| 83 | void handleDataStructureChanged(); // structure of of series has changed, recreate graphic items |
| 84 | void handleVisibleChanged(); |
| 85 | void handleOpacityChanged(); |
| 86 | void handleUpdatedBars(); |
| 87 | void handleLabelsPositionChanged(); |
| 88 | virtual void positionLabels(); |
| 89 | void handleBarValueChange(int index, QBarSet *barset); |
| 90 | void handleBarValueAdd(int index, int count, QBarSet *barset); |
| 91 | void handleBarValueRemove(int index, int count, QBarSet *barset); |
| 92 | void handleSeriesAdded(QAbstractSeries *series); |
| 93 | void handleSeriesRemoved(QAbstractSeries *series); |
| 94 | |
| 95 | protected: |
| 96 | void positionLabelsVertical(); |
| 97 | void createLabelItems(); |
| 98 | void handleSetStructureChange(); |
| 99 | virtual QString generateLabelText(int set, int category, qreal value); |
| 100 | void updateBarItems(); |
| 101 | virtual void markLabelsDirty(QBarSet *barset, int index, int count); |
| 102 | void calculateSeriesPositionAdjustmentAndWidth(); |
| 103 | |
| 104 | QRectF m_rect; |
| 105 | QVector<QRectF> m_layout; |
| 106 | |
| 107 | BarAnimation *m_animation; |
| 108 | |
| 109 | QAbstractBarSeries *m_series; // Not owned. |
| 110 | QMap<QBarSet *, QList<Bar *> > m_barMap; |
| 111 | QMap<QBarSet *, QHash<int, Bar *> > m_indexForBarMap; |
| 112 | int m_firstCategory; |
| 113 | int m_lastCategory; |
| 114 | int m_categoryCount; |
| 115 | QSizeF m_oldSize; |
| 116 | bool m_labelItemsMissing; |
| 117 | Qt::Orientation m_orientation; |
| 118 | bool m_resetAnimation; |
| 119 | qreal m_seriesPosAdjustment; |
| 120 | qreal m_seriesWidth; |
| 121 | }; |
| 122 | |
| 123 | QT_CHARTS_END_NAMESPACE |
| 124 | |
| 125 | #endif // ABSTRACTBARCHARTITEM_H |
| 126 | |