##// END OF EJS Templates
Bar animations refactored
Marek Rosa -
r2316:74962bdcee07
parent child
Show More
@@ -1,31 +1,19
1 1 INCLUDEPATH += $$PWD
2 2 DEPENDPATH += $$PWD
3 3
4 4 SOURCES += \
5 5 $$PWD/axisanimation.cpp \
6 6 $$PWD/xyanimation.cpp \
7 7 $$PWD/pieanimation.cpp \
8 8 $$PWD/piesliceanimation.cpp \
9 9 $$PWD/splineanimation.cpp \
10 $$PWD/baranimation.cpp \
11 $$PWD/stackedbaranimation.cpp \
12 $$PWD/percentbaranimation.cpp \
13 $$PWD/abstractbaranimation.cpp \
14 $$PWD/horizontalbaranimation.cpp \
15 $$PWD/horizontalstackedbaranimation.cpp \
16 $$PWD/horizontalpercentbaranimation.cpp
10 $$PWD/baranimation.cpp
17 11
18 12 PRIVATE_HEADERS += \
19 13 $$PWD/axisanimation_p.h \
20 14 $$PWD/chartanimation_p.h \
21 15 $$PWD/xyanimation_p.h \
22 16 $$PWD/pieanimation_p.h \
23 17 $$PWD/piesliceanimation_p.h \
24 18 $$PWD/splineanimation_p.h \
25 $$PWD/baranimation_p.h \
26 $$PWD/stackedbaranimation_p.h \
27 $$PWD/percentbaranimation_p.h \
28 $$PWD/abstractbaranimation_p.h \
29 $$PWD/horizontalbaranimation_p.h \
30 $$PWD/horizontalstackedbaranimation_p.h \
31 $$PWD/horizontalpercentbaranimation_p.h
19 $$PWD/baranimation_p.h
@@ -1,73 +1,80
1 1 /****************************************************************************
2 2 **
3 3 ** Copyright (C) 2012 Digia Plc
4 4 ** All rights reserved.
5 5 ** For any questions to Digia, please use contact form at http://qt.digia.com
6 6 **
7 7 ** This file is part of the Qt Commercial Charts Add-on.
8 8 **
9 9 ** $QT_BEGIN_LICENSE$
10 10 ** Licensees holding valid Qt Commercial licenses may use this file in
11 11 ** accordance with the Qt Commercial License Agreement provided with the
12 12 ** Software or, alternatively, in accordance with the terms contained in
13 13 ** a written agreement between you and Digia.
14 14 **
15 15 ** If you have questions regarding the use of this file, please use
16 16 ** contact form at http://qt.digia.com
17 17 ** $QT_END_LICENSE$
18 18 **
19 19 ****************************************************************************/
20 20
21 21 #include "baranimation_p.h"
22 22 #include "abstractbarchartitem_p.h"
23 23 #include <QTimer>
24 24
25 25 Q_DECLARE_METATYPE(QVector<QRectF>)
26 26
27 27 QTCOMMERCIALCHART_BEGIN_NAMESPACE
28 28
29 29 BarAnimation::BarAnimation(AbstractBarChartItem *item)
30 : AbstractBarAnimation(item)
30 : ChartAnimation(item),
31 m_item(item)
31 32 {
32
33 setDuration(ChartAnimationDuration);
34 setEasingCurve(QEasingCurve::OutQuart);
33 35 }
34 36
35 37 BarAnimation::~BarAnimation()
36 38 {
37 39 }
38 40
39 41 QVariant BarAnimation::interpolated(const QVariant &from, const QVariant &to, qreal progress) const
40 42 {
41 43 QVector<QRectF> startVector = qvariant_cast<QVector<QRectF> >(from);
42 44 QVector<QRectF> endVector = qvariant_cast<QVector<QRectF> >(to);
43 45 QVector<QRectF> result;
44 46
45 47 Q_ASSERT(startVector.count() == endVector.count());
46 48
47 49 for (int i = 0; i < startVector.count(); i++) {
48 50 QRectF start = startVector[i].normalized();
49 51 QRectF end = endVector[i].normalized();
52 qreal x1 = start.left() + progress * (end.left() - start.left());
53 qreal x2 = start.right() + progress * (end.right() - start.right());
54 qreal y1 = start.top() + progress * (end.top() - start.top());
55 qreal y2 = start.bottom() + progress * (end.bottom() - start.bottom());
50 56
51 qreal x = end.left();
52 qreal y;
53 qreal w = end.width();
54 qreal h;
55
56 if (endVector[i].height() < 0) {
57 // Negative bar
58 y = end.top();
59 h = start.height() + ((end.height() - start.height()) * progress);
60 } else {
61 h = startVector[i].height() + ((endVector[i].height() - startVector[i].height()) * progress);
62 y = endVector[i].top() + endVector[i].height() - h;
63 }
64
65 QRectF value(x, y, w, h);
57 QRectF value(QPointF(x1, y1), QPointF(x2, y2));
66 58 result << value.normalized();
67 59 }
68 60 return qVariantFromValue(result);
69 61 }
70 62
63 void BarAnimation::updateCurrentValue(const QVariant &value)
64 {
65 QVector<QRectF> layout = qvariant_cast<QVector<QRectF> >(value);
66 m_item->setLayout(layout);
67 }
68
69 void BarAnimation::setup(const QVector<QRectF> &oldLayout, const QVector<QRectF> &newLayout)
70 {
71 QVariantAnimation::KeyValues value;
72 setKeyValues(value); //workaround for wrong interpolation call
73 setKeyValueAt(0.0, qVariantFromValue(oldLayout));
74 setKeyValueAt(1.0, qVariantFromValue(newLayout));
75 }
76
71 77 #include "moc_baranimation_p.cpp"
72 78
73 79 QTCOMMERCIALCHART_END_NAMESPACE
80
@@ -1,55 +1,59
1 1 /****************************************************************************
2 2 **
3 3 ** Copyright (C) 2012 Digia Plc
4 4 ** All rights reserved.
5 5 ** For any questions to Digia, please use contact form at http://qt.digia.com
6 6 **
7 7 ** This file is part of the Qt Commercial Charts Add-on.
8 8 **
9 9 ** $QT_BEGIN_LICENSE$
10 10 ** Licensees holding valid Qt Commercial licenses may use this file in
11 11 ** accordance with the Qt Commercial License Agreement provided with the
12 12 ** Software or, alternatively, in accordance with the terms contained in
13 13 ** a written agreement between you and Digia.
14 14 **
15 15 ** If you have questions regarding the use of this file, please use
16 16 ** contact form at http://qt.digia.com
17 17 ** $QT_END_LICENSE$
18 18 **
19 19 ****************************************************************************/
20 20
21 21 // W A R N I N G
22 22 // -------------
23 23 //
24 24 // This file is not part of the QtCommercial Chart API. It exists purely as an
25 25 // implementation detail. This header file may change from version to
26 26 // version without notice, or even be removed.
27 27 //
28 28 // We mean it.
29 29
30 #ifndef BARANIMATION_P_H
31 #define BARANIMATION_P_H
30 #ifndef ABSTRACTBARANIMATION_P_H
31 #define ABSTRACTBARANIMATION_P_H
32 32
33 #include "abstractbaranimation_p.h"
34 33 #include "chartanimation_p.h"
35 #include "abstractbarchartitem_p.h"
36 34
37 35 QTCOMMERCIALCHART_BEGIN_NAMESPACE
38 36
39 37 class AbstractBarChartItem;
40 38
41 class BarAnimation : public AbstractBarAnimation
39 class BarAnimation : public ChartAnimation
42 40 {
43 41 Q_OBJECT
44 42
45 43 public:
46 44 BarAnimation(AbstractBarChartItem *item);
47 45 ~BarAnimation();
48 46
49 47 public: // from QVariantAnimation
50 48 virtual QVariant interpolated(const QVariant &from, const QVariant &to, qreal progress) const;
49 virtual void updateCurrentValue(const QVariant &value);
50
51 void setup(const QVector<QRectF> &oldLayout, const QVector<QRectF> &newLayout);
52
53 protected:
54 AbstractBarChartItem *m_item;
51 55 };
52 56
53 57 QTCOMMERCIALCHART_END_NAMESPACE
54 58
55 #endif
59 #endif // ABSTRACTBARANIMATION_P_H
@@ -1,214 +1,221
1 1 /****************************************************************************
2 2 **
3 3 ** Copyright (C) 2012 Digia Plc
4 4 ** All rights reserved.
5 5 ** For any questions to Digia, please use contact form at http://qt.digia.com
6 6 **
7 7 ** This file is part of the Qt Commercial Charts Add-on.
8 8 **
9 9 ** $QT_BEGIN_LICENSE$
10 10 ** Licensees holding valid Qt Commercial licenses may use this file in
11 11 ** accordance with the Qt Commercial License Agreement provided with the
12 12 ** Software or, alternatively, in accordance with the terms contained in
13 13 ** a written agreement between you and Digia.
14 14 **
15 15 ** If you have questions regarding the use of this file, please use
16 16 ** contact form at http://qt.digia.com
17 17 ** $QT_END_LICENSE$
18 18 **
19 19 ****************************************************************************/
20 20
21 21 #include "abstractbarchartitem_p.h"
22 22 #include "bar_p.h"
23 23 #include "qbarset.h"
24 24 #include "qbarset_p.h"
25 25 #include "qabstractbarseries.h"
26 26 #include "qabstractbarseries_p.h"
27 27 #include "qchart.h"
28 28 #include "chartpresenter_p.h"
29 29 #include "charttheme_p.h"
30 #include "abstractbaranimation_p.h"
30 #include "baranimation_p.h"
31 31 #include "chartdataset_p.h"
32 32 #include <QPainter>
33 33
34 34 QTCOMMERCIALCHART_BEGIN_NAMESPACE
35 35
36 36 AbstractBarChartItem::AbstractBarChartItem(QAbstractBarSeries *series, QGraphicsItem* item) :
37 37 ChartItem(series->d_func(),item),
38 38 m_animation(0),
39 39 m_series(series)
40 40 {
41 41
42 42 setFlag(ItemClipsChildrenToShape);
43 43 connect(series->d_func(), SIGNAL(updatedLayout()), this, SLOT(handleLayoutChanged()));
44 44 connect(series->d_func(), SIGNAL(updatedBars()), this, SLOT(handleUpdatedBars()));
45 45 connect(series->d_func(), SIGNAL(labelsVisibleChanged(bool)), this, SLOT(handleLabelsVisibleChanged(bool)));
46 46 connect(series->d_func(), SIGNAL(restructuredBars()), this, SLOT(handleDataStructureChanged()));
47 47 connect(series, SIGNAL(visibleChanged()), this, SLOT(handleVisibleChanged()));
48 48 connect(series, SIGNAL(opacityChanged()), this, SLOT(handleOpacityChanged()));
49 setZValue(ChartPresenter::BarSeriesZValue);
49 setZValue(ChartPresenter::BarSeriesZValue);
50 50 handleDataStructureChanged();
51 51 handleVisibleChanged();
52 52 handleUpdatedBars();
53 53 }
54 54
55 55 AbstractBarChartItem::~AbstractBarChartItem()
56 56 {
57 57 }
58 58
59 59 void AbstractBarChartItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget)
60 60 {
61 61 Q_UNUSED(painter);
62 62 Q_UNUSED(option);
63 63 Q_UNUSED(widget);
64 64 }
65 65
66 66 QRectF AbstractBarChartItem::boundingRect() const
67 67 {
68 68 return m_rect;
69 69 }
70 70
71 71 void AbstractBarChartItem::applyLayout(const QVector<QRectF> &layout)
72 72 {
73 if (m_animation) {
74 m_animation->setup(m_layout, layout);
75 presenter()->startAnimation(m_animation);
76 } else {
77 setLayout(layout);
78 update();
73 QSizeF size = geometry().size();
74 if (geometry().size().isValid()) {
75 if (m_animation) {
76 if (m_layout.count() == 0 || m_oldSize != size) {
77 initializeLayout();
78 m_oldSize = size;
79 }
80 m_animation->setup(m_layout, layout);
81 presenter()->startAnimation(m_animation);
82 } else {
83 setLayout(layout);
84 update();
85 }
79 86 }
80 87 }
81 88
82 void AbstractBarChartItem::setAnimation(AbstractBarAnimation *animation)
89 void AbstractBarChartItem::setAnimation(BarAnimation *animation)
83 90 {
84 91 m_animation = animation;
85 92 }
86 93
87 94 void AbstractBarChartItem::setLayout(const QVector<QRectF> &layout)
88 95 {
89 96 if (layout.count() != m_bars.count())
90 97 return;
91 98
92 99 m_layout = layout;
93 100
94 101 for (int i = 0; i < m_bars.count(); i++) {
95 102 m_bars.at(i)->setRect(layout.at(i));
96 103 QGraphicsSimpleTextItem *label = m_labels.at(i);
97 104 label->setPos(layout.at(i).center() - label->boundingRect().center());
98 105
99 106 }
100 107 }
101 108 //handlers
102 109
103 110 void AbstractBarChartItem::handleDomainUpdated()
104 111 {
105 112 m_domainMinX = domain()->minX();
106 113 m_domainMaxX = domain()->maxX();
107 114 m_domainMinY = domain()->minY();
108 115 m_domainMaxY = domain()->maxY();
109 116
110 117 QRectF rect(QPointF(0,0),domain()->size());
111 118
112 119 if(m_rect != rect){
113 120 prepareGeometryChange();
114 121 m_rect = rect;
115 122 }
116 123
117 124 handleLayoutChanged();
118 125 }
119 126
120 127 void AbstractBarChartItem::handleLayoutChanged()
121 128 {
122 129 if ((m_rect.width() <= 0) || (m_rect.height() <= 0))
123 130 return; // rect size zero.
124 131 QVector<QRectF> layout = calculateLayout();
125 132 applyLayout(layout);
126 133 handleUpdatedBars();
127 134 }
128 135
129 136 void AbstractBarChartItem::handleLabelsVisibleChanged(bool visible)
130 137 {
131 138 foreach (QGraphicsSimpleTextItem *label, m_labels)
132 139 label->setVisible(visible);
133 140 update();
134 141 }
135 142
136 143 void AbstractBarChartItem::handleDataStructureChanged()
137 144 {
138 145 foreach (QGraphicsItem *item, childItems())
139 146 delete item;
140 147
141 148 m_bars.clear();
142 149 m_labels.clear();
143 150 m_layout.clear();
144 151
145 152 // Create new graphic items for bars
146 153 for (int c = 0; c < m_series->d_func()->categoryCount(); c++) {
147 154 for (int s = 0; s < m_series->count(); s++) {
148 155 QBarSet *set = m_series->d_func()->barsetAt(s);
149 156
150 157 // Bars
151 158 Bar *bar = new Bar(set, c, this);
152 159 m_bars.append(bar);
153 160 connect(bar, SIGNAL(clicked(int,QBarSet*)), m_series, SIGNAL(clicked(int,QBarSet*)));
154 161 connect(bar, SIGNAL(hovered(bool,QBarSet*)), m_series, SIGNAL(hovered(bool,QBarSet*)));
155 162 connect(bar, SIGNAL(clicked(int,QBarSet*)), set, SIGNAL(clicked(int)));
156 163 connect(bar, SIGNAL(hovered(bool,QBarSet*)), set, SIGNAL(hovered(bool)));
157 m_layout.append(QRectF(0, 0, 0, 0));
164 // m_layout.append(QRectF(0, 0, 1, 1));
158 165
159 166 // Labels
160 167 m_labels.append(new QGraphicsSimpleTextItem(this));
161 168 }
162 169 }
163 170
164 171 if(themeManager()) themeManager()->updateSeries(m_series);
165 172 handleLayoutChanged();
166 173 handleVisibleChanged();
167 174 }
168 175
169 176 void AbstractBarChartItem::handleVisibleChanged()
170 177 {
171 178 bool visible = m_series->isVisible();
172 179 if (visible)
173 180 handleLabelsVisibleChanged(m_series->isLabelsVisible());
174 181 else
175 182 handleLabelsVisibleChanged(visible);
176 183
177 184 foreach (QGraphicsItem *bar, m_bars)
178 185 bar->setVisible(visible);
179 186 }
180 187
181 188 void AbstractBarChartItem::handleOpacityChanged()
182 189 {
183 190 foreach (QGraphicsItem *item, childItems())
184 191 item->setOpacity(m_series->opacity());
185 192 }
186 193
187 194 void AbstractBarChartItem::handleUpdatedBars()
188 195 {
189 196 // Handle changes in pen, brush, labels etc.
190 197 int categoryCount = m_series->d_func()->categoryCount();
191 198 int setCount = m_series->count();
192 199 int itemIndex(0);
193 200
194 201 for (int category = 0; category < categoryCount; category++) {
195 202 for (int set = 0; set < setCount; set++) {
196 203 QBarSetPrivate *barSet = m_series->d_func()->barsetAt(set)->d_ptr.data();
197 204 Bar *bar = m_bars.at(itemIndex);
198 205 bar->setPen(barSet->m_pen);
199 206 bar->setBrush(barSet->m_brush);
200 207 bar->update();
201 208
202 209 QGraphicsSimpleTextItem *label = m_labels.at(itemIndex);
203 210 label->setText(QString("%1").arg(barSet->value(category)));
204 211 label->setFont(barSet->m_labelFont);
205 212 label->setBrush(barSet->m_labelBrush);
206 213 label->update();
207 214 itemIndex++;
208 215 }
209 216 }
210 217 }
211 218
212 219 #include "moc_abstractbarchartitem_p.cpp"
213 220
214 221 QTCOMMERCIALCHART_END_NAMESPACE
@@ -1,92 +1,94
1 1 /****************************************************************************
2 2 **
3 3 ** Copyright (C) 2012 Digia Plc
4 4 ** All rights reserved.
5 5 ** For any questions to Digia, please use contact form at http://qt.digia.com
6 6 **
7 7 ** This file is part of the Qt Commercial Charts Add-on.
8 8 **
9 9 ** $QT_BEGIN_LICENSE$
10 10 ** Licensees holding valid Qt Commercial licenses may use this file in
11 11 ** accordance with the Qt Commercial License Agreement provided with the
12 12 ** Software or, alternatively, in accordance with the terms contained in
13 13 ** a written agreement between you and Digia.
14 14 **
15 15 ** If you have questions regarding the use of this file, please use
16 16 ** contact form at http://qt.digia.com
17 17 ** $QT_END_LICENSE$
18 18 **
19 19 ****************************************************************************/
20 20
21 21 // W A R N I N G
22 22 // -------------
23 23 //
24 24 // This file is not part of the QtCommercial Chart API. It exists purely as an
25 25 // implementation detail. This header file may change from version to
26 26 // version without notice, or even be removed.
27 27 //
28 28 // We mean it.
29 29
30 30
31 31 #ifndef ABSTRACTBARCHARTITEM_H
32 32 #define ABSTRACTBARCHARTITEM_H
33 33
34 34 #include "chartitem_p.h"
35 35 #include "qabstractbarseries.h"
36 36 #include <QPen>
37 37 #include <QBrush>
38 38
39 39 QTCOMMERCIALCHART_BEGIN_NAMESPACE
40 40
41 41 class Bar;
42 42 class QAxisCategories;
43 43 class QChart;
44 class AbstractBarAnimation;
44 class BarAnimation;
45 45
46 46 class AbstractBarChartItem : public ChartItem
47 47 {
48 48 Q_OBJECT
49 49 public:
50 50 AbstractBarChartItem(QAbstractBarSeries *series, QGraphicsItem* item = 0);
51 51 virtual ~AbstractBarChartItem();
52 52
53 53 public:
54 54 void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget);
55 55 QRectF boundingRect() const;
56 56
57 57 virtual QVector<QRectF> calculateLayout() = 0;
58 virtual void initializeLayout() = 0;
58 59 virtual void applyLayout(const QVector<QRectF> &layout);
59 virtual void setAnimation(AbstractBarAnimation *animation);
60 virtual void setAnimation(BarAnimation *animation);
60 61 void setLayout(const QVector<QRectF> &layout);
61 62 void updateLayout(const QVector<QRectF> &layout);
62 63 QRectF geometry() const { return m_rect;}
63 64
64 65 public Q_SLOTS:
65 66 void handleDomainUpdated();
66 67 void handleLayoutChanged();
67 68 void handleLabelsVisibleChanged(bool visible);
68 69 void handleDataStructureChanged(); // structure of of series has changed, recreate graphic items
69 70 void handleVisibleChanged();
70 71 void handleOpacityChanged();
71 72 virtual void handleUpdatedBars();
72 73
73 74 protected:
74 75
75 76 qreal m_domainMinX;
76 77 qreal m_domainMaxX;
77 78 qreal m_domainMinY;
78 79 qreal m_domainMaxY;
79 80
80 81 QRectF m_rect;
81 82 QVector<QRectF> m_layout;
82 83
83 AbstractBarAnimation *m_animation;
84 BarAnimation *m_animation;
84 85
85 86 QAbstractBarSeries *m_series; // Not owned.
86 87 QList<Bar *> m_bars;
87 88 QList<QGraphicsSimpleTextItem *> m_labels;
89 QSizeF m_oldSize;
88 90 };
89 91
90 92 QTCOMMERCIALCHART_END_NAMESPACE
91 93
92 94 #endif // ABSTRACTBARCHARTITEM_H
@@ -1,70 +1,90
1 1 /****************************************************************************
2 2 **
3 3 ** Copyright (C) 2012 Digia Plc
4 4 ** All rights reserved.
5 5 ** For any questions to Digia, please use contact form at http://qt.digia.com
6 6 **
7 7 ** This file is part of the Qt Commercial Charts Add-on.
8 8 **
9 9 ** $QT_BEGIN_LICENSE$
10 10 ** Licensees holding valid Qt Commercial licenses may use this file in
11 11 ** accordance with the Qt Commercial License Agreement provided with the
12 12 ** Software or, alternatively, in accordance with the terms contained in
13 13 ** a written agreement between you and Digia.
14 14 **
15 15 ** If you have questions regarding the use of this file, please use
16 16 ** contact form at http://qt.digia.com
17 17 ** $QT_END_LICENSE$
18 18 **
19 19 ****************************************************************************/
20 20
21 21 #include "horizontalbarchartitem_p.h"
22 22 #include "qabstractbarseries_p.h"
23 23 #include "qbarset_p.h"
24 24 #include "bar_p.h"
25 25
26 26 QTCOMMERCIALCHART_BEGIN_NAMESPACE
27 27
28 28 HorizontalBarChartItem::HorizontalBarChartItem(QAbstractBarSeries *series, QGraphicsItem* item)
29 29 : AbstractBarChartItem(series, item)
30 30 {
31 31 }
32 32
33 void HorizontalBarChartItem::initializeLayout()
34 {
35 qreal categoryCount = m_series->d_func()->categoryCount();
36 qreal setCount = m_series->count();
37 qreal barWidth = m_series->d_func()->barWidth();
38
39 m_layout.clear();
40 for(int category = 0; category < categoryCount; category++) {
41 for (int set = 0; set < setCount; set++) {
42 QRectF rect;
43 QPointF topLeft;
44 QPointF bottomRight;
45 if (domain()->type() == AbstractDomain::LogXYDomain || domain()->type() == AbstractDomain::LogXLogYDomain) {
46 topLeft = domain()->calculateGeometryPoint(QPointF(domain()->minX(), category - barWidth / 2 + set/setCount * barWidth));
47 bottomRight = domain()->calculateGeometryPoint(QPointF(domain()->minX(), category + barWidth / 2 + (set + 1)/setCount * barWidth));
48 } else {
49 topLeft = domain()->calculateGeometryPoint(QPointF(0, category - barWidth / 2 + set/setCount * barWidth));
50 bottomRight = domain()->calculateGeometryPoint(QPointF(0, category - barWidth / 2 + (set + 1)/setCount * barWidth));
51 }
52
53 rect.setTopLeft(topLeft);
54 rect.setBottomRight(bottomRight);
55 m_layout.append(rect.normalized());
56 }
57 }
58 }
59
33 60 QVector<QRectF> HorizontalBarChartItem::calculateLayout()
34 61 {
35 62 QVector<QRectF> layout;
36 63
37 64 // Use temporary qreals for accuracy
38 65 qreal categoryCount = m_series->d_func()->categoryCount();
39 66 qreal setCount = m_series->count();
40 67 qreal barWidth = m_series->d_func()->barWidth();
41 68
42 int itemIndex(0);
43 69 for(int category = 0; category < categoryCount; category++) {
44 70 for (int set = 0; set < setCount; set++) {
45 71 qreal value = m_series->barSets().at(set)->at(category);
46 72 QRectF rect;
47 73 QPointF topLeft;
48 74 if (domain()->type() == AbstractDomain::LogXYDomain || domain()->type() == AbstractDomain::LogXLogYDomain)
49 topLeft = domain()->calculateGeometryPoint(QPointF(domain()->minX(), category - barWidth / 2 + (set + 1)/(setCount) * barWidth));
75 topLeft = domain()->calculateGeometryPoint(QPointF(domain()->minX(), category - barWidth / 2 + set/setCount * barWidth));
50 76 else
51 topLeft = domain()->calculateGeometryPoint(QPointF(0, category - barWidth / 2 + (set + 1)/(setCount) * barWidth));
77 topLeft = domain()->calculateGeometryPoint(QPointF(0, category - barWidth / 2 + set/setCount * barWidth));
52 78
53 QPointF bottomRight = domain()->calculateGeometryPoint(QPointF(value, category - barWidth / 2 + (set)/(setCount) * barWidth));
79 QPointF bottomRight = domain()->calculateGeometryPoint(QPointF(value, category - barWidth / 2 + (set + 1)/setCount * barWidth));
54 80 rect.setTopLeft(topLeft);
55 81 rect.setBottomRight(bottomRight);
56 layout.append(rect);
57
58 QGraphicsSimpleTextItem *label = m_labels.at(itemIndex);
59 label->setPos(rect.center() - label->boundingRect().center());
60 label->setZValue(200);
61 itemIndex++;
62 label->setBrush(Qt::black);
82 layout.append(rect.normalized());
63 83 }
64 84 }
65 85 return layout;
66 86 }
67 87
68 88 #include "moc_horizontalbarchartitem_p.cpp"
69 89
70 90 QTCOMMERCIALCHART_END_NAMESPACE
@@ -1,50 +1,51
1 1 /****************************************************************************
2 2 **
3 3 ** Copyright (C) 2012 Digia Plc
4 4 ** All rights reserved.
5 5 ** For any questions to Digia, please use contact form at http://qt.digia.com
6 6 **
7 7 ** This file is part of the Qt Commercial Charts Add-on.
8 8 **
9 9 ** $QT_BEGIN_LICENSE$
10 10 ** Licensees holding valid Qt Commercial licenses may use this file in
11 11 ** accordance with the Qt Commercial License Agreement provided with the
12 12 ** Software or, alternatively, in accordance with the terms contained in
13 13 ** a written agreement between you and Digia.
14 14 **
15 15 ** If you have questions regarding the use of this file, please use
16 16 ** contact form at http://qt.digia.com
17 17 ** $QT_END_LICENSE$
18 18 **
19 19 ****************************************************************************/
20 20
21 21 // W A R N I N G
22 22 // -------------
23 23 //
24 24 // This file is not part of the QtCommercial Chart API. It exists purely as an
25 25 // implementation detail. This header file may change from version to
26 26 // version without notice, or even be removed.
27 27 //
28 28 // We mean it.
29 29
30 30 #ifndef HORIZONTALBARCHARTITEM_H
31 31 #define HORIZONTALBARCHARTITEM_H
32 32
33 33 #include "abstractbarchartitem_p.h"
34 34 #include <QGraphicsItem>
35 35
36 36 QTCOMMERCIALCHART_BEGIN_NAMESPACE
37 37
38 38 class HorizontalBarChartItem : public AbstractBarChartItem
39 39 {
40 40 Q_OBJECT
41 41 public:
42 42 HorizontalBarChartItem(QAbstractBarSeries *series, QGraphicsItem* item = 0);
43 43
44 44 private:
45 45 virtual QVector<QRectF> calculateLayout();
46 void initializeLayout();
46 47 };
47 48
48 49 QTCOMMERCIALCHART_END_NAMESPACE
49 50
50 51 #endif // HORIZONTALBARCHARTITEM_H
@@ -1,133 +1,120
1 1 /****************************************************************************
2 2 **
3 3 ** Copyright (C) 2012 Digia Plc
4 4 ** All rights reserved.
5 5 ** For any questions to Digia, please use contact form at http://qt.digia.com
6 6 **
7 7 ** This file is part of the Qt Commercial Charts Add-on.
8 8 **
9 9 ** $QT_BEGIN_LICENSE$
10 10 ** Licensees holding valid Qt Commercial licenses may use this file in
11 11 ** accordance with the Qt Commercial License Agreement provided with the
12 12 ** Software or, alternatively, in accordance with the terms contained in
13 13 ** a written agreement between you and Digia.
14 14 **
15 15 ** If you have questions regarding the use of this file, please use
16 16 ** contact form at http://qt.digia.com
17 17 ** $QT_END_LICENSE$
18 18 **
19 19 ****************************************************************************/
20 20
21 21 #include "qhorizontalbarseries.h"
22 22 #include "qhorizontalbarseries_p.h"
23 23 #include "horizontalbarchartitem_p.h"
24 #include "horizontalbaranimation_p.h"
25 24 #include "qbarcategoryaxis.h"
26 25
27 26 #include "chartdataset_p.h"
28 27 #include "charttheme_p.h"
29 28
30 29
31 30 QTCOMMERCIALCHART_BEGIN_NAMESPACE
32 31
33 32 /*!
34 33 \class QHorizontalBarSeries
35 34 \brief Series for creating horizontal bar chart
36 35 \mainclass
37 36
38 37 QHorizontalBarSeries represents a series of data shown as bars. The purpose of this class is to draw bars
39 38 as groups, where bars in same category are grouped next to each other. QHorizontalBarSeries groups the data
40 39 from sets to categories, which are defined by a QStringList.
41 40
42 41 See the \l {HorizontalBarChart Example} {horizontal bar chart example} to learn how to create a horizontal bar chart.
43 42 \image examples_horizontalbarchart.png
44 43
45 44 \sa QBarSet, QBarSeries, QPercentBarSeries, QAbstractBarSeries, QStackedBarSeries, QHorizontalStackedBarSeries, QHorizontalPercentBarSeries
46 45 */
47 46 /*!
48 47 \qmlclass HorizontalBarSeries QHorizontalBarSeries
49 48 \inherits AbstractBarSeries
50 49
51 50 The following QML shows how to create a simple horizontal bar chart:
52 51 \snippet ../demos/qmlchart/qml/qmlchart/View9.qml 1
53 52 \beginfloatleft
54 53 \image demos_qmlchart9.png
55 54 \endfloat
56 55 \clearfloat
57 56 */
58 57
59 58 /*!
60 59 Constructs empty QHorizontalBarSeries.
61 60 QHorizontalBarSeries is QObject which is a child of a \a parent.
62 61 */
63 62 QHorizontalBarSeries::QHorizontalBarSeries(QObject *parent)
64 63 : QAbstractBarSeries(*new QHorizontalBarSeriesPrivate(this), parent)
65 64 {
66 65 }
67 66
68 67 /*!
69 68 Destructor
70 69 Removes series from chart.
71 70 */
72 71 QHorizontalBarSeries::~QHorizontalBarSeries()
73 72 {
74 73 Q_D(QHorizontalBarSeries);
75 74 if (d->m_chart)
76 75 d->m_chart->removeSeries(this);
77 76 }
78 77
79 78 /*!
80 79 Returns QChartSeries::SeriesTypeHorizontalBar.
81 80 */
82 81 QAbstractSeries::SeriesType QHorizontalBarSeries::type() const
83 82 {
84 83 return QAbstractSeries::SeriesTypeHorizontalBar;
85 84 }
86 85
87 86 ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
88 87
89 88 QHorizontalBarSeriesPrivate::QHorizontalBarSeriesPrivate(QHorizontalBarSeries *q)
90 89 : QAbstractBarSeriesPrivate(q)
91 90 {
92 91
93 92 }
94 93
95 94 void QHorizontalBarSeriesPrivate::initializeDomain()
96 95 {
97 96 qreal minX(domain()->minX());
98 97 qreal minY(domain()->minY());
99 98 qreal maxX(domain()->maxX());
100 99 qreal maxY(domain()->maxY());
101 100
102 101 qreal y = categoryCount();
103 102 minX = qMin(minX, min());
104 103 minY = qMin(minY, - (qreal)0.5);
105 104 maxX = qMax(maxX, max());
106 105 maxY = qMax(maxY, y - (qreal)0.5);
107 106
108 107 domain()->setRange(minX, maxX, minY, maxY);
109 108 }
110 109
111 110 void QHorizontalBarSeriesPrivate::initializeGraphics(QGraphicsItem* parent)
112 111 {
113 112 Q_Q(QHorizontalBarSeries);
114 113 HorizontalBarChartItem *bar = new HorizontalBarChartItem(q,parent);
115 114 m_item.reset(bar);
116 115 QAbstractSeriesPrivate::initializeGraphics(parent);
117 116 }
118 117
119 void QHorizontalBarSeriesPrivate::initializeAnimations(QtCommercialChart::QChart::AnimationOptions options)
120 {
121 HorizontalBarChartItem *bar = static_cast<HorizontalBarChartItem *>(m_item.data());
122 Q_ASSERT(bar);
123 if (options.testFlag(QChart::SeriesAnimations)) {
124 bar->setAnimation(new HorizontalBarAnimation(bar));
125 }else{
126 bar->setAnimation(0);
127 }
128 QAbstractSeriesPrivate::initializeAnimations(options);
129 }
130
131 118 #include "moc_qhorizontalbarseries.cpp"
132 119
133 120 QTCOMMERCIALCHART_END_NAMESPACE
@@ -1,51 +1,50
1 1 /****************************************************************************
2 2 **
3 3 ** Copyright (C) 2012 Digia Plc
4 4 ** All rights reserved.
5 5 ** For any questions to Digia, please use contact form at http://qt.digia.com
6 6 **
7 7 ** This file is part of the Qt Commercial Charts Add-on.
8 8 **
9 9 ** $QT_BEGIN_LICENSE$
10 10 ** Licensees holding valid Qt Commercial licenses may use this file in
11 11 ** accordance with the Qt Commercial License Agreement provided with the
12 12 ** Software or, alternatively, in accordance with the terms contained in
13 13 ** a written agreement between you and Digia.
14 14 **
15 15 ** If you have questions regarding the use of this file, please use
16 16 ** contact form at http://qt.digia.com
17 17 ** $QT_END_LICENSE$
18 18 **
19 19 ****************************************************************************/
20 20
21 21 // W A R N I N G
22 22 // -------------
23 23 //
24 24 // This file is not part of the QtCommercial Chart API. It exists purely as an
25 25 // implementation detail. This header file may change from version to
26 26 // version without notice, or even be removed.
27 27 //
28 28 // We mean it.
29 29
30 30 #ifndef QHORIZONTALBARSERIES_P_H
31 31 #define QHORIZONTALBARSERIES_P_H
32 32
33 33 #include "qabstractbarseries_p.h"
34 34 #include "abstractdomain_p.h"
35 35
36 36 QTCOMMERCIALCHART_BEGIN_NAMESPACE
37 37
38 38 class QHorizontalBarSeriesPrivate: public QAbstractBarSeriesPrivate
39 39 {
40 40 public:
41 41 QHorizontalBarSeriesPrivate(QHorizontalBarSeries *q);
42 42 void initializeGraphics(QGraphicsItem* parent);
43 void initializeAnimations(QtCommercialChart::QChart::AnimationOptions options);
44 43 void initializeDomain();
45 44 private:
46 45 Q_DECLARE_PUBLIC(QHorizontalBarSeries)
47 46 };
48 47
49 48 QTCOMMERCIALCHART_END_NAMESPACE
50 49
51 50 #endif // QHORIZONTALBARSERIES_P_H
@@ -1,95 +1,122
1 1 /****************************************************************************
2 2 **
3 3 ** Copyright (C) 2012 Digia Plc
4 4 ** All rights reserved.
5 5 ** For any questions to Digia, please use contact form at http://qt.digia.com
6 6 **
7 7 ** This file is part of the Qt Commercial Charts Add-on.
8 8 **
9 9 ** $QT_BEGIN_LICENSE$
10 10 ** Licensees holding valid Qt Commercial licenses may use this file in
11 11 ** accordance with the Qt Commercial License Agreement provided with the
12 12 ** Software or, alternatively, in accordance with the terms contained in
13 13 ** a written agreement between you and Digia.
14 14 **
15 15 ** If you have questions regarding the use of this file, please use
16 16 ** contact form at http://qt.digia.com
17 17 ** $QT_END_LICENSE$
18 18 **
19 19 ****************************************************************************/
20 20
21 21 #include "horizontalpercentbarchartitem_p.h"
22 22 #include "qabstractbarseries_p.h"
23 23 #include "qbarset_p.h"
24 24 #include "bar_p.h"
25 25
26 26 QTCOMMERCIALCHART_BEGIN_NAMESPACE
27 27
28 28 HorizontalPercentBarChartItem::HorizontalPercentBarChartItem(QAbstractBarSeries *series, QGraphicsItem* item)
29 29 : AbstractBarChartItem(series, item)
30 30 {
31 31 }
32 32
33 void HorizontalPercentBarChartItem::initializeLayout()
34 {
35 qreal categoryCount = m_series->d_func()->categoryCount();
36 qreal setCount = m_series->count();
37 qreal barWidth = m_series->d_func()->barWidth();
38
39 m_layout.clear();
40 for(int category = 0; category < categoryCount; category++) {
41 for (int set = 0; set < setCount; set++) {
42 QRectF rect;
43 QPointF topLeft;
44 QPointF bottomRight;
45 if (domain()->type() == AbstractDomain::LogXYDomain || domain()->type() == AbstractDomain::LogXLogYDomain) {
46 topLeft = domain()->calculateGeometryPoint(QPointF(domain()->minX(), category - barWidth / 2));
47 bottomRight = domain()->calculateGeometryPoint(QPointF(domain()->minX(), category + barWidth / 2));
48 } else {
49 topLeft = domain()->calculateGeometryPoint(QPointF(0, category - barWidth / 2));
50 bottomRight = domain()->calculateGeometryPoint(QPointF(0, category + barWidth / 2));
51 }
52
53 rect.setTopLeft(topLeft);
54 rect.setBottomRight(bottomRight);
55 m_layout.append(rect.normalized());
56 }
57 }
58 }
59
33 60 QVector<QRectF> HorizontalPercentBarChartItem::calculateLayout()
34 61 {
35 62 QVector<QRectF> layout;
36 63
37 64 // Use temporary qreals for accuracy
38 65 qreal categoryCount = m_series->d_func()->categoryCount();
39 66 qreal setCount = m_series->count();
40 67 qreal barWidth = m_series->d_func()->barWidth();
41 68
42 69 for(int category = 0; category < categoryCount; category++) {
43 70 qreal sum = 0;
44 71 qreal categorySum = m_series->d_func()->categorySum(category);
45 72 for (int set = 0; set < setCount; set++) {
46 73 qreal value = m_series->barSets().at(set)->at(category);
47 74 QRectF rect;
48 75 QPointF topLeft;
49 76 if (domain()->type() == AbstractDomain::LogXYDomain || domain()->type() == AbstractDomain::LogXLogYDomain)
50 topLeft = domain()->calculateGeometryPoint(QPointF(set ? 100 * sum/categorySum : domain()->minX(), category + barWidth/2));
77 topLeft = domain()->calculateGeometryPoint(QPointF(set ? 100 * sum/categorySum : domain()->minX(), category - barWidth/2));
51 78 else
52 topLeft = domain()->calculateGeometryPoint(QPointF(set ? 100 * sum/categorySum : 0, category + barWidth/2));
53 QPointF bottomRight = domain()->calculateGeometryPoint(QPointF(100 * (value + sum)/categorySum, category - barWidth/2));
79 topLeft = domain()->calculateGeometryPoint(QPointF(set ? 100 * sum/categorySum : 0, category - barWidth/2));
80 QPointF bottomRight = domain()->calculateGeometryPoint(QPointF(100 * (value + sum)/categorySum, category + barWidth/2));
54 81 rect.setTopLeft(topLeft);
55 82 rect.setBottomRight(bottomRight);
56 layout.append(rect);
83 layout.append(rect.normalized());
57 84 sum +=value;
58 85 }
59 86 }
60 87 return layout;
61 88 }
62 89
63 90 void HorizontalPercentBarChartItem::handleUpdatedBars()
64 91 {
65 92 // Handle changes in pen, brush, labels etc.
66 93 int categoryCount = m_series->d_func()->categoryCount();
67 94 int setCount = m_series->count();
68 95 int itemIndex(0);
69 96
70 97 for (int category = 0; category < categoryCount; category++) {
71 98 for (int set = 0; set < setCount; set++) {
72 99 QBarSetPrivate *barSet = m_series->d_func()->barsetAt(set)->d_ptr.data();
73 100 Bar *bar = m_bars.at(itemIndex);
74 101 bar->setPen(barSet->m_pen);
75 102 bar->setBrush(barSet->m_brush);
76 103 bar->update();
77 104
78 105 QGraphicsSimpleTextItem *label = m_labels.at(itemIndex);
79 106 int p = m_series->d_func()->percentageAt(set, category) * 100;
80 107 QString vString(QString::number(p));
81 108 vString.truncate(3);
82 109 vString.append("%");
83 110 label->setText(vString);
84 111 label->setFont(barSet->m_labelFont);
85 112 label->setBrush(barSet->m_labelBrush);
86 113 label->update();
87 114 itemIndex++;
88 115 }
89 116 }
90 117 }
91 118
92 119 #include "moc_horizontalpercentbarchartitem_p.cpp"
93 120
94 121 QTCOMMERCIALCHART_END_NAMESPACE
95 122
@@ -1,51 +1,52
1 1 /****************************************************************************
2 2 **
3 3 ** Copyright (C) 2012 Digia Plc
4 4 ** All rights reserved.
5 5 ** For any questions to Digia, please use contact form at http://qt.digia.com
6 6 **
7 7 ** This file is part of the Qt Commercial Charts Add-on.
8 8 **
9 9 ** $QT_BEGIN_LICENSE$
10 10 ** Licensees holding valid Qt Commercial licenses may use this file in
11 11 ** accordance with the Qt Commercial License Agreement provided with the
12 12 ** Software or, alternatively, in accordance with the terms contained in
13 13 ** a written agreement between you and Digia.
14 14 **
15 15 ** If you have questions regarding the use of this file, please use
16 16 ** contact form at http://qt.digia.com
17 17 ** $QT_END_LICENSE$
18 18 **
19 19 ****************************************************************************/
20 20
21 21 // W A R N I N G
22 22 // -------------
23 23 //
24 24 // This file is not part of the QtCommercial Chart API. It exists purely as an
25 25 // implementation detail. This header file may change from version to
26 26 // version without notice, or even be removed.
27 27 //
28 28 // We mean it.
29 29
30 30 #ifndef HORIZONTALPERCENTBARCHARTITEM_P_H
31 31 #define HORIZONTALPERCENTBARCHARTITEM_P_H
32 32
33 33 #include "abstractbarchartitem_p.h"
34 34 #include <QGraphicsItem>
35 35
36 36 QTCOMMERCIALCHART_BEGIN_NAMESPACE
37 37
38 38 class HorizontalPercentBarChartItem : public AbstractBarChartItem
39 39 {
40 40 Q_OBJECT
41 41 public:
42 42 HorizontalPercentBarChartItem(QAbstractBarSeries *series, QGraphicsItem* item = 0);
43 43 void handleUpdatedBars();
44 44
45 45 private:
46 46 virtual QVector<QRectF> calculateLayout();
47 void initializeLayout();
47 48 };
48 49
49 50 QTCOMMERCIALCHART_END_NAMESPACE
50 51
51 52 #endif // HORIZONTALPERCENTBARCHARTITEM_P_H
@@ -1,128 +1,116
1 1 /****************************************************************************
2 2 **
3 3 ** Copyright (C) 2012 Digia Plc
4 4 ** All rights reserved.
5 5 ** For any questions to Digia, please use contact form at http://qt.digia.com
6 6 **
7 7 ** This file is part of the Qt Commercial Charts Add-on.
8 8 **
9 9 ** $QT_BEGIN_LICENSE$
10 10 ** Licensees holding valid Qt Commercial licenses may use this file in
11 11 ** accordance with the Qt Commercial License Agreement provided with the
12 12 ** Software or, alternatively, in accordance with the terms contained in
13 13 ** a written agreement between you and Digia.
14 14 **
15 15 ** If you have questions regarding the use of this file, please use
16 16 ** contact form at http://qt.digia.com
17 17 ** $QT_END_LICENSE$
18 18 **
19 19 ****************************************************************************/
20 20 #include "qhorizontalpercentbarseries.h"
21 21 #include "qhorizontalpercentbarseries_p.h"
22 22 #include "horizontalpercentbarchartitem_p.h"
23 #include "horizontalpercentbaranimation_p.h"
24 23
25 24 #include "chartdataset_p.h"
26 25 #include "charttheme_p.h"
27 26
28 27 QTCOMMERCIALCHART_BEGIN_NAMESPACE
29 28
30 29 /*!
31 30 \class QHorizontalPercentBarSeries
32 31 \brief Series for creating horizontal percent bar chart
33 32 \mainclass
34 33
35 34 QHorizontalPercentBarSeries represents a series of data shown as bars. The purpose of this class is to draw bars
36 35 as groups, where bars in same category are grouped next to each other. QHorizontalPercentBarSeries groups the data
37 36 from sets to categories, which are defined by a QStringList.
38 37
39 38 See the \l {HorizontalPercentBarChart Example} {horizontal percent bar chart example} to learn how to create a horizontal percent bar chart.
40 39 \image examples_horizontalpercentbarchart.png
41 40
42 41 \sa QBarSet, QBarSeries, QPercentBarSeries, QAbstractBarSeries, QStackedBarSeries, QHorizontalStackedBarSeries, QHorizontalBarSeries
43 42 */
44 43 /*!
45 44 \qmlclass HorizontalPercentBarSeries QHorizontalPercentBarSeries
46 45 \inherits QAbstractBarSeries
47 46
48 47 The following QML shows how to create a simple horizontal percent bar chart:
49 48 \snippet ../demos/qmlchart/qml/qmlchart/View11.qml 1
50 49 \beginfloatleft
51 50 \image demos_qmlchart11.png
52 51 \endfloat
53 52 \clearfloat
54 53 */
55 54
56 55 /*!
57 56 Constructs empty QHorizontalPercentBarSeries.
58 57 QHorizontalPercentBarSeries is QObject which is a child of a \a parent.
59 58 */
60 59 QHorizontalPercentBarSeries::QHorizontalPercentBarSeries(QObject *parent) :
61 60 QAbstractBarSeries(*new QHorizontalPercentBarSeriesPrivate(this), parent)
62 61 {
63 62 }
64 63
65 64 /*!
66 65 Returns QChartSeries::SeriesTypeHorizontalPercentBar.
67 66 */
68 67 QAbstractSeries::SeriesType QHorizontalPercentBarSeries::type() const
69 68 {
70 69 return QAbstractSeries::SeriesTypeHorizontalPercentBar;
71 70 }
72 71
73 72 /*!
74 73 Destructor
75 74 Removes series from chart.
76 75 */
77 76 QHorizontalPercentBarSeries::~QHorizontalPercentBarSeries()
78 77 {
79 78 Q_D(QHorizontalPercentBarSeries);
80 79 if (d->m_chart)
81 80 d->m_chart->removeSeries(this);
82 81 }
83 82
84 83 ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
85 84
86 85 QHorizontalPercentBarSeriesPrivate::QHorizontalPercentBarSeriesPrivate(QHorizontalPercentBarSeries *q) : QAbstractBarSeriesPrivate(q)
87 86 {
88 87
89 88 }
90 89
91 90 void QHorizontalPercentBarSeriesPrivate::initializeDomain()
92 91 {
93 92 qreal minX(domain()->minX());
94 93 qreal minY(domain()->minY());
95 94 qreal maxX(domain()->maxX());
96 95 qreal maxY(domain()->maxY());
97 96
98 97 qreal y = categoryCount();
99 98 minX = 0;
100 99 maxX = 100;
101 100 minY = qMin(minY, - (qreal)0.5);
102 101 maxY = qMax(maxY, y - (qreal)0.5);
103 102
104 103 domain()->setRange(minX, maxX, minY, maxY);
105 104 }
106 105
107 106 void QHorizontalPercentBarSeriesPrivate::initializeGraphics(QGraphicsItem* parent)
108 107 {
109 108 Q_Q(QHorizontalPercentBarSeries);
110 109 HorizontalPercentBarChartItem *bar = new HorizontalPercentBarChartItem(q,parent);
111 110 m_item.reset(bar);
112 111 QAbstractSeriesPrivate::initializeGraphics(parent);
113 112 }
114 113
115 void QHorizontalPercentBarSeriesPrivate::initializeAnimations(QtCommercialChart::QChart::AnimationOptions options)
116 {
117 HorizontalPercentBarChartItem *bar = static_cast<HorizontalPercentBarChartItem *>(m_item.data());
118 Q_ASSERT(bar);
119 if (options.testFlag(QChart::SeriesAnimations)) {
120 bar->setAnimation(new HorizontalPercentBarAnimation(bar));
121 }else{
122 bar->setAnimation(0);
123 }
124 QAbstractSeriesPrivate::initializeAnimations(options);
125 }
126 114 #include "moc_qhorizontalpercentbarseries.cpp"
127 115
128 116 QTCOMMERCIALCHART_END_NAMESPACE
@@ -1,51 +1,50
1 1 /****************************************************************************
2 2 **
3 3 ** Copyright (C) 2012 Digia Plc
4 4 ** All rights reserved.
5 5 ** For any questions to Digia, please use contact form at http://qt.digia.com
6 6 **
7 7 ** This file is part of the Qt Commercial Charts Add-on.
8 8 **
9 9 ** $QT_BEGIN_LICENSE$
10 10 ** Licensees holding valid Qt Commercial licenses may use this file in
11 11 ** accordance with the Qt Commercial License Agreement provided with the
12 12 ** Software or, alternatively, in accordance with the terms contained in
13 13 ** a written agreement between you and Digia.
14 14 **
15 15 ** If you have questions regarding the use of this file, please use
16 16 ** contact form at http://qt.digia.com
17 17 ** $QT_END_LICENSE$
18 18 **
19 19 ****************************************************************************/
20 20
21 21 // W A R N I N G
22 22 // -------------
23 23 //
24 24 // This file is not part of the QtCommercial Chart API. It exists purely as an
25 25 // implementation detail. This header file may change from version to
26 26 // version without notice, or even be removed.
27 27 //
28 28 // We mean it.
29 29
30 30 #ifndef QHORIZONTALPERCENTBARSERIES_P_H
31 31 #define QHORIZONTALPERCENTBARSERIES_P_H
32 32
33 33 #include "qabstractbarseries_p.h"
34 34 #include "abstractdomain_p.h"
35 35
36 36 QTCOMMERCIALCHART_BEGIN_NAMESPACE
37 37
38 38 class QHorizontalPercentBarSeriesPrivate: public QAbstractBarSeriesPrivate
39 39 {
40 40 public:
41 41 QHorizontalPercentBarSeriesPrivate(QHorizontalPercentBarSeries *q);
42 42 void initializeGraphics(QGraphicsItem* parent);
43 void initializeAnimations(QtCommercialChart::QChart::AnimationOptions options);
44 43 void initializeDomain();
45 44 private:
46 45 Q_DECLARE_PUBLIC(QHorizontalPercentBarSeries)
47 46 };
48 47
49 48 QTCOMMERCIALCHART_END_NAMESPACE
50 49
51 50 #endif // QHORIZONTALPERCENTBARSERIES_P_H
@@ -1,76 +1,103
1 1 /****************************************************************************
2 2 **
3 3 ** Copyright (C) 2012 Digia Plc
4 4 ** All rights reserved.
5 5 ** For any questions to Digia, please use contact form at http://qt.digia.com
6 6 **
7 7 ** This file is part of the Qt Commercial Charts Add-on.
8 8 **
9 9 ** $QT_BEGIN_LICENSE$
10 10 ** Licensees holding valid Qt Commercial licenses may use this file in
11 11 ** accordance with the Qt Commercial License Agreement provided with the
12 12 ** Software or, alternatively, in accordance with the terms contained in
13 13 ** a written agreement between you and Digia.
14 14 **
15 15 ** If you have questions regarding the use of this file, please use
16 16 ** contact form at http://qt.digia.com
17 17 ** $QT_END_LICENSE$
18 18 **
19 19 ****************************************************************************/
20 20
21 21 #include "horizontalstackedbarchartitem_p.h"
22 22 #include "qabstractbarseries_p.h"
23 23 #include "qbarset_p.h"
24 24 #include "bar_p.h"
25 25
26 26 QTCOMMERCIALCHART_BEGIN_NAMESPACE
27 27
28 28 HorizontalStackedBarChartItem::HorizontalStackedBarChartItem(QAbstractBarSeries *series, QGraphicsItem* item)
29 29 : AbstractBarChartItem(series, item)
30 30 {
31 31 }
32 32
33 void HorizontalStackedBarChartItem::initializeLayout()
34 {
35 qreal categoryCount = m_series->d_func()->categoryCount();
36 qreal setCount = m_series->count();
37 qreal barWidth = m_series->d_func()->barWidth();
38
39 m_layout.clear();
40 for(int category = 0; category < categoryCount; category++) {
41 for (int set = 0; set < setCount; set++) {
42 QRectF rect;
43 QPointF topLeft;
44 QPointF bottomRight;
45 if (domain()->type() == AbstractDomain::LogXYDomain || domain()->type() == AbstractDomain::LogXLogYDomain) {
46 topLeft = domain()->calculateGeometryPoint(QPointF(domain()->minX(), category - barWidth / 2));
47 bottomRight = domain()->calculateGeometryPoint(QPointF(domain()->minX(), category + barWidth / 2));
48 } else {
49 topLeft = domain()->calculateGeometryPoint(QPointF(0, category - barWidth / 2));
50 bottomRight = domain()->calculateGeometryPoint(QPointF(0, category + barWidth / 2));
51 }
52
53 rect.setTopLeft(topLeft);
54 rect.setBottomRight(bottomRight);
55 m_layout.append(rect.normalized());
56 }
57 }
58 }
59
33 60 QVector<QRectF> HorizontalStackedBarChartItem::calculateLayout()
34 61 {
35 62 QVector<QRectF> layout;
36 63
37 64 // Use temporary qreals for accuracy
38 65 qreal categoryCount = m_series->d_func()->categoryCount();
39 66 qreal setCount = m_series->count();
40 67 qreal barWidth = m_series->d_func()->barWidth();
41 68
42 69 for(int category = 0; category < categoryCount; category++) {
43 70 qreal positiveSum = 0;
44 71 qreal negativeSum = 0;
45 72 for (int set = 0; set < setCount; set++) {
46 73 qreal value = m_series->barSets().at(set)->at(category);
47 74 QRectF rect;
48 75 QPointF topLeft;
49 76 QPointF bottomRight;
50 77 if (value < 0) {
51 78 bottomRight = domain()->calculateGeometryPoint(QPointF(value + negativeSum, category - barWidth / 2));
52 79 if (domain()->type() == AbstractDomain::LogXYDomain || domain()->type() == AbstractDomain::LogXLogYDomain)
53 80 topLeft = domain()->calculateGeometryPoint(QPointF(set ? negativeSum : domain()->minX(), category + barWidth / 2));
54 81 else
55 82 topLeft = domain()->calculateGeometryPoint(QPointF(set ? negativeSum : 0, category + barWidth / 2));
56 83 negativeSum += value;
57 84 } else {
58 85 bottomRight = domain()->calculateGeometryPoint(QPointF(value + positiveSum, category - barWidth / 2));
59 86 if (domain()->type() == AbstractDomain::LogXYDomain || domain()->type() == AbstractDomain::LogXLogYDomain)
60 87 topLeft = domain()->calculateGeometryPoint(QPointF(set ? positiveSum : domain()->minX(), category + barWidth / 2));
61 88 else
62 89 topLeft = domain()->calculateGeometryPoint(QPointF(set ? positiveSum : 0, category + barWidth / 2));
63 90 positiveSum += value;
64 91 }
65 92 rect.setTopLeft(topLeft);
66 93 rect.setBottomRight(bottomRight);
67 layout.append(rect);
94 layout.append(rect.normalized());
68 95 }
69 96 }
70 97 return layout;
71 98 }
72 99
73 100 #include "moc_horizontalstackedbarchartitem_p.cpp"
74 101
75 102 QTCOMMERCIALCHART_END_NAMESPACE
76 103
@@ -1,50 +1,51
1 1 /****************************************************************************
2 2 **
3 3 ** Copyright (C) 2012 Digia Plc
4 4 ** All rights reserved.
5 5 ** For any questions to Digia, please use contact form at http://qt.digia.com
6 6 **
7 7 ** This file is part of the Qt Commercial Charts Add-on.
8 8 **
9 9 ** $QT_BEGIN_LICENSE$
10 10 ** Licensees holding valid Qt Commercial licenses may use this file in
11 11 ** accordance with the Qt Commercial License Agreement provided with the
12 12 ** Software or, alternatively, in accordance with the terms contained in
13 13 ** a written agreement between you and Digia.
14 14 **
15 15 ** If you have questions regarding the use of this file, please use
16 16 ** contact form at http://qt.digia.com
17 17 ** $QT_END_LICENSE$
18 18 **
19 19 ****************************************************************************/
20 20
21 21 // W A R N I N G
22 22 // -------------
23 23 //
24 24 // This file is not part of the QtCommercial Chart API. It exists purely as an
25 25 // implementation detail. This header file may change from version to
26 26 // version without notice, or even be removed.
27 27 //
28 28 // We mean it.
29 29
30 30 #ifndef HORIZONTALSTACKEDBARCHARTITEM_P_H
31 31 #define HORIZONTALSTACKEDBARCHARTITEM_P_H
32 32
33 33 #include "abstractbarchartitem_p.h"
34 34 #include <QGraphicsItem>
35 35
36 36 QTCOMMERCIALCHART_BEGIN_NAMESPACE
37 37
38 38 class HorizontalStackedBarChartItem : public AbstractBarChartItem
39 39 {
40 40 Q_OBJECT
41 41 public:
42 42 HorizontalStackedBarChartItem(QAbstractBarSeries *series, QGraphicsItem* item = 0);
43 43
44 44 private:
45 45 virtual QVector<QRectF> calculateLayout();
46 void initializeLayout();
46 47 };
47 48
48 49 QTCOMMERCIALCHART_END_NAMESPACE
49 50
50 51 #endif // HORIZONTALSTACKEDBARCHARTITEM_P_H
@@ -1,127 +1,115
1 1 /****************************************************************************
2 2 **
3 3 ** Copyright (C) 2012 Digia Plc
4 4 ** All rights reserved.
5 5 ** For any questions to Digia, please use contact form at http://qt.digia.com
6 6 **
7 7 ** This file is part of the Qt Commercial Charts Add-on.
8 8 **
9 9 ** $QT_BEGIN_LICENSE$
10 10 ** Licensees holding valid Qt Commercial licenses may use this file in
11 11 ** accordance with the Qt Commercial License Agreement provided with the
12 12 ** Software or, alternatively, in accordance with the terms contained in
13 13 ** a written agreement between you and Digia.
14 14 **
15 15 ** If you have questions regarding the use of this file, please use
16 16 ** contact form at http://qt.digia.com
17 17 ** $QT_END_LICENSE$
18 18 **
19 19 ****************************************************************************/
20 20 #include "qhorizontalstackedbarseries.h"
21 21 #include "qhorizontalstackedbarseries_p.h"
22 22 #include "horizontalstackedbarchartitem_p.h"
23 #include "horizontalstackedbaranimation_p.h"
24 23
25 24 #include "chartdataset_p.h"
26 25 #include "charttheme_p.h"
27 26
28 27 QTCOMMERCIALCHART_BEGIN_NAMESPACE
29 28 /*!
30 29 \class QHorizontalStackedBarSeries
31 30 \brief Series for creating horizontal stacked bar chart
32 31 \mainclass
33 32
34 33 QHorizontalStackedBarSeries represents a series of data shown as bars. The purpose of this class is to draw bars
35 34 as groups, where bars in same category are grouped next to each other. QHorizontalStackedBarSeries groups the data
36 35 from sets to categories, which are defined by a QStringList.
37 36
38 37 See the \l {HorizontalStackedBarChart Example} {horizontal stacked bar chart example} to learn how to create a horizontal stacked bar chart.
39 38 \image examples_horizontalstackedbarchart.png
40 39
41 40 \sa QBarSet, QBarSeries, QPercentBarSeries, QAbstractBarSeries, QStackedBarSeries, QHorizontalPercentBarSeries, QHorizontalBarSeries
42 41 */
43 42 /*!
44 43 \qmlclass HorizontalStackedBarSeries QHorizontalStackedBarSeries
45 44 \inherits QAbstractBarSeries
46 45
47 46 The following QML shows how to create a simple horizontal stacked bar chart:
48 47 \snippet ../demos/qmlchart/qml/qmlchart/View10.qml 1
49 48 \beginfloatleft
50 49 \image demos_qmlchart10.png
51 50 \endfloat
52 51 \clearfloat
53 52 */
54 53
55 54 /*!
56 55 Constructs empty QHorizontalStackedBarSeries.
57 56 QHorizontalStackedBarSeries is QObject which is a child of a \a parent.
58 57 */
59 58 QHorizontalStackedBarSeries::QHorizontalStackedBarSeries(QObject *parent)
60 59 : QAbstractBarSeries(*new QHorizontalStackedBarSeriesPrivate(this), parent)
61 60 {
62 61 }
63 62
64 63 /*!
65 64 Destructor
66 65 Removes series from chart.
67 66 */
68 67 QHorizontalStackedBarSeries::~QHorizontalStackedBarSeries()
69 68 {
70 69 Q_D(QHorizontalStackedBarSeries);
71 70 if (d->m_chart)
72 71 d->m_chart->removeSeries(this);
73 72 }
74 73
75 74 /*!
76 75 Returns QChartSeries::SeriesTypeHorizontalStackedBar.
77 76 */
78 77 QAbstractSeries::SeriesType QHorizontalStackedBarSeries::type() const
79 78 {
80 79 return QAbstractSeries::SeriesTypeHorizontalStackedBar;
81 80 }
82 81
83 82 ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
84 83
85 84 QHorizontalStackedBarSeriesPrivate::QHorizontalStackedBarSeriesPrivate(QHorizontalStackedBarSeries *q) : QAbstractBarSeriesPrivate(q)
86 85 {
87 86
88 87 }
89 88
90 89 void QHorizontalStackedBarSeriesPrivate::initializeDomain()
91 90 {
92 91 qreal minX(domain()->minX());
93 92 qreal minY(domain()->minY());
94 93 qreal maxX(domain()->maxX());
95 94 qreal maxY(domain()->maxY());
96 95
97 96 qreal y = categoryCount();
98 97 minX = qMin(minX, bottom());
99 98 minY = qMin(minY, - (qreal)0.5);
100 99 maxX = qMax(maxX, top());
101 100 maxY = qMax(maxY, y - (qreal)0.5);
102 101
103 102 domain()->setRange(minX, maxX, minY, maxY);
104 103 }
105 104
106 105 void QHorizontalStackedBarSeriesPrivate::initializeGraphics(QGraphicsItem *parent)
107 106 {
108 107 Q_Q(QHorizontalStackedBarSeries);
109 108 HorizontalStackedBarChartItem *bar = new HorizontalStackedBarChartItem(q,parent);
110 109 m_item.reset(bar);
111 110 QAbstractSeriesPrivate::initializeGraphics(parent);
112 111 }
113 112
114 void QHorizontalStackedBarSeriesPrivate::initializeAnimations(QtCommercialChart::QChart::AnimationOptions options)
115 {
116 HorizontalStackedBarChartItem *bar = static_cast<HorizontalStackedBarChartItem *>(m_item.data());
117 Q_ASSERT(bar);
118 if (options.testFlag(QChart::SeriesAnimations)) {
119 bar->setAnimation(new HorizontalStackedBarAnimation(bar));
120 }else{
121 bar->setAnimation(0);
122 }
123 QAbstractSeriesPrivate::initializeAnimations(options);
124 }
125 113 #include "moc_qhorizontalstackedbarseries.cpp"
126 114
127 115 QTCOMMERCIALCHART_END_NAMESPACE
@@ -1,51 +1,50
1 1 /****************************************************************************
2 2 **
3 3 ** Copyright (C) 2012 Digia Plc
4 4 ** All rights reserved.
5 5 ** For any questions to Digia, please use contact form at http://qt.digia.com
6 6 **
7 7 ** This file is part of the Qt Commercial Charts Add-on.
8 8 **
9 9 ** $QT_BEGIN_LICENSE$
10 10 ** Licensees holding valid Qt Commercial licenses may use this file in
11 11 ** accordance with the Qt Commercial License Agreement provided with the
12 12 ** Software or, alternatively, in accordance with the terms contained in
13 13 ** a written agreement between you and Digia.
14 14 **
15 15 ** If you have questions regarding the use of this file, please use
16 16 ** contact form at http://qt.digia.com
17 17 ** $QT_END_LICENSE$
18 18 **
19 19 ****************************************************************************/
20 20
21 21 // W A R N I N G
22 22 // -------------
23 23 //
24 24 // This file is not part of the QtCommercial Chart API. It exists purely as an
25 25 // implementation detail. This header file may change from version to
26 26 // version without notice, or even be removed.
27 27 //
28 28 // We mean it.
29 29
30 30 #ifndef QHORIZONTALSTACKEDBARSERIES_P_H
31 31 #define QHORIZONTALSTACKEDBARSERIES_P_H
32 32
33 33 #include "qabstractbarseries_p.h"
34 34 #include "abstractdomain_p.h"
35 35
36 36 QTCOMMERCIALCHART_BEGIN_NAMESPACE
37 37
38 38 class QHorizontalStackedBarSeriesPrivate: public QAbstractBarSeriesPrivate
39 39 {
40 40 public:
41 41 QHorizontalStackedBarSeriesPrivate(QHorizontalStackedBarSeries *q);
42 42 void initializeGraphics(QGraphicsItem* parent);
43 void initializeAnimations(QtCommercialChart::QChart::AnimationOptions options);
44 43 void initializeDomain();
45 44 private:
46 45 Q_DECLARE_PUBLIC(QHorizontalStackedBarSeries)
47 46 };
48 47
49 48 QTCOMMERCIALCHART_END_NAMESPACE
50 49
51 50 #endif // QHORIZONTALSTACKEDBARSERIES_P_H
@@ -1,859 +1,873
1 1 /****************************************************************************
2 2 **
3 3 ** Copyright (C) 2012 Digia Plc
4 4 ** All rights reserved.
5 5 ** For any questions to Digia, please use contact form at http://qt.digia.com
6 6 **
7 7 ** This file is part of the Qt Commercial Charts Add-on.
8 8 **
9 9 ** $QT_BEGIN_LICENSE$
10 10 ** Licensees holding valid Qt Commercial licenses may use this file in
11 11 ** accordance with the Qt Commercial License Agreement provided with the
12 12 ** Software or, alternatively, in accordance with the terms contained in
13 13 ** a written agreement between you and Digia.
14 14 **
15 15 ** If you have questions regarding the use of this file, please use
16 16 ** contact form at http://qt.digia.com
17 17 ** $QT_END_LICENSE$
18 18 **
19 19 ****************************************************************************/
20 20
21 21 #include "qabstractbarseries.h"
22 22 #include "qabstractbarseries_p.h"
23 23 #include "qbarset.h"
24 24 #include "qbarset_p.h"
25 25 #include "abstractdomain_p.h"
26 26 #include "chartdataset_p.h"
27 27 #include "charttheme_p.h"
28 28 #include "qvalueaxis.h"
29 29 #include "qbarcategoryaxis.h"
30 30 #include "qbarlegendmarker.h"
31 #include "baranimation_p.h"
32 #include "abstractbarchartitem_p.h"
31 33
32 34 QTCOMMERCIALCHART_BEGIN_NAMESPACE
33 35
34 36 /*!
35 37 \class QAbstractBarSeries
36 38 \brief Series for creating a bar chart
37 39 \mainclass
38 40
39 41 QAbstractBarSeries represents a series of data shown as bars. The purpose of this class is to draw bars to
40 42 the position defined by data. Single bar is defined by QPointF, where x value is the x-coordinate of the bar
41 43 and y-value is the height of the bar. The category names are ignored with this series and x-axis
42 44 shows the x-values.
43 45
44 46 See the \l {BarChart Example} {bar chart example} to learn how to create a simple bar chart.
45 47 \image examples_barchart.png
46 48
47 49 \sa QBarSet, QStackedBarSeries, QPercentBarSeries
48 50 */
49 51 /*!
50 52 \qmlclass AbstractBarSeries QAbstractBarSeries
51 53 \inherits QAbstractSeries
52 54
53 55 The following QML shows how to create a simple bar chart:
54 56 \snippet ../demos/qmlchart/qml/qmlchart/View6.qml 1
55 57
56 58 \beginfloatleft
57 59 \image demos_qmlchart6.png
58 60 \endfloat
59 61 \clearfloat
60 62 */
61 63
62 64 /*!
63 65 \property QAbstractBarSeries::barWidth
64 66 The width of the bars of the series. The unit of \a width is the unit of x-axis. The minimum width for bars
65 67 is zero and negative values are treated as zero. Setting the width to zero means that width of the bar on screen
66 68 is one pixel no matter what the scale of x-axis is. Bars wider than zero are scaled with x-axis.
67 69 Note that with QBarSeries this value means the width of one group of bars instead of just one bar.
68 70 \sa QBarSeries
69 71 */
70 72 /*!
71 73 \qmlproperty real AbstractBarSeries::barWidth
72 74 The width of the bars of the series. The unit of width is the unit of x-axis. The minimum width for bars
73 75 is zero and negative values are treated as zero. Setting the width to zero means that width of the bar on screen
74 76 is one pixel no matter what the scale of x-axis is. Bars wider than zero are scaled with x-axis.
75 77 Note that with QBarSeries this value means the width of one group of bars instead of just one bar.
76 78 */
77 79
78 80 /*!
79 81 \property QAbstractBarSeries::count
80 82 Holds the number of sets in series.
81 83 */
82 84 /*!
83 85 \qmlproperty int AbstractBarSeries::count
84 86 Holds the number of sets in series.
85 87 */
86 88
87 89 /*!
88 90 \property QAbstractBarSeries::labelsVisible
89 91 Defines the visibility of the labels in series
90 92 */
91 93 /*!
92 94 \qmlproperty bool AbstractBarSeries::labelsVisible
93 95 Defines the visibility of the labels in series
94 96 */
95 97
96 98 /*!
97 99 \fn void QAbstractBarSeries::clicked(int index, QBarSet *barset)
98 100 The signal is emitted if the user clicks with a mouse on top of QBarSet \a barset.
99 101 Clicked bar inside set is indexed by \a index
100 102 */
101 103 /*!
102 104 \qmlsignal AbstractBarSeries::onClicked(int index, BarSet barset)
103 105 The signal is emitted if the user clicks with a mouse on top of BarSet.
104 106 Clicked bar inside set is indexed by \a index
105 107 */
106 108
107 109 /*!
108 110 \fn void QAbstractBarSeries::hovered(bool status, QBarSet* barset)
109 111
110 112 The signal is emitted if mouse is hovered on top of series.
111 113 Parameter \a barset is the pointer of barset, where hover happened.
112 114 Parameter \a status is true, if mouse entered on top of series, false if mouse left from top of series.
113 115 */
114 116 /*!
115 117 \qmlsignal AbstractBarSeries::onHovered(bool status, BarSet barset)
116 118
117 119 The signal is emitted if mouse is hovered on top of series.
118 120 Parameter \a barset is the pointer of barset, where hover happened.
119 121 Parameter \a status is true, if mouse entered on top of series, false if mouse left from top of series.
120 122 */
121 123
122 124 /*!
123 125 \fn void QAbstractBarSeries::countChanged()
124 126 This signal is emitted when barset count has been changed, for example by append or remove.
125 127 */
126 128 /*!
127 129 \qmlsignal AbstractBarSeries::onCountChanged()
128 130 This signal is emitted when barset count has been changed, for example by append or remove.
129 131 */
130 132
131 133 /*!
132 134 \fn void QAbstractBarSeries::labelsVisibleChanged()
133 135 This signal is emitted when labels visibility have changed.
134 136 \sa isLabelsVisible(), setLabelsVisible()
135 137 */
136 138
137 139 /*!
138 140 \fn void QAbstractBarSeries::barsetsAdded(QList<QBarSet*> sets)
139 141 This signal is emitted when \a sets have been added to the series.
140 142 \sa append(), insert()
141 143 */
142 144 /*!
143 145 \qmlsignal AbstractBarSeries::onBarsetsAdded(BarSet barset)
144 146 Emitted when \a barset has been added to the series.
145 147 */
146 148
147 149 /*!
148 150 \fn void QAbstractBarSeries::barsetsRemoved(QList<QBarSet*> sets)
149 151 This signal is emitted when \a sets have been removed from the series.
150 152 \sa remove()
151 153 */
152 154 /*!
153 155 \qmlsignal AbstractBarSeries::onBarsetsRemoved(BarSet barset)
154 156 Emitted when \a barset has been removed from the series.
155 157 */
156 158
157 159 /*!
158 160 \qmlmethod BarSet AbstractBarSeries::at(int index)
159 161 Returns bar set at \a index. Returns null if the index is not valid.
160 162 */
161 163
162 164 /*!
163 165 \qmlmethod BarSet AbstractBarSeries::append(string label, VariantList values)
164 166 Adds a new bar set with \a label and \a values to \a index. Values is a list of reals.
165 167 For example:
166 168 \code
167 169 myBarSeries.append("set 1", [0, 0.2, 0.2, 0.5, 0.4, 1.5, 0.9]);
168 170 \endcode
169 171 */
170 172
171 173 /*!
172 174 \qmlmethod BarSet AbstractBarSeries::insert(int index, string label, VariantList values)
173 175 Inserts a new bar set with \a label and \a values to \a index. Values can be a list of reals or a list of XYPoints.
174 176 If index is zero or smaller, the new barset is prepended. If the index is count or bigger, the new barset is
175 177 appended.
176 178 \sa AbstractBarSeries::append()
177 179 */
178 180
179 181 /*!
180 182 \qmlmethod bool AbstractBarSeries::remove(BarSet barset)
181 183 Removes the barset from the series. Returns true if successful, false otherwise.
182 184 */
183 185
184 186 /*!
185 187 \qmlmethod AbstractBarSeries::clear()
186 188 Removes all barsets from the series.
187 189 */
188 190
189 191 /*!
190 192 Destructs abstractbarseries and owned barsets.
191 193 */
192 194 QAbstractBarSeries::~QAbstractBarSeries()
193 195 {
194 196
195 197 }
196 198
197 199 /*!
198 200 \internal
199 201 */
200 202 QAbstractBarSeries::QAbstractBarSeries(QAbstractBarSeriesPrivate &o, QObject *parent)
201 203 : QAbstractSeries(o, parent)
202 204 {
203 205 Q_D(QAbstractSeries);
204 206 QObject::connect(this, SIGNAL(countChanged()), d, SIGNAL(countChanged()));
205 207 }
206 208
207 209 /*!
208 210 Sets the width of the bars of the series. The unit of \a width is the unit of x-axis. The minimum width for bars
209 211 is zero and negative values are treated as zero. Setting the width to zero means that width of the bar on screen
210 212 is one pixel no matter what the scale of x-axis is. Bars wider than zero are scaled with x-axis.
211 213 Note that with \link QBarSeries \endlink this value means the width of one group of bars instead of just one bar.
212 214 */
213 215 void QAbstractBarSeries::setBarWidth(qreal width)
214 216 {
215 217 Q_D(QAbstractBarSeries);
216 218 d->setBarWidth(width);
217 219 }
218 220
219 221 /*!
220 222 Returns the width of the bars of the series.
221 223 \sa setBarWidth()
222 224 */
223 225 qreal QAbstractBarSeries::barWidth() const
224 226 {
225 227 Q_D(const QAbstractBarSeries);
226 228 return d->barWidth();
227 229 }
228 230
229 231 /*!
230 232 Adds a set of bars to series. Takes ownership of \a set. If the set is null or is already in series, it won't be appended.
231 233 Returns true, if appending succeeded.
232 234 */
233 235 bool QAbstractBarSeries::append(QBarSet *set)
234 236 {
235 237 Q_D(QAbstractBarSeries);
236 238 bool success = d->append(set);
237 239 if (success) {
238 240 QList<QBarSet *> sets;
239 241 sets.append(set);
240 242 set->setParent(this);
241 243 emit barsetsAdded(sets);
242 244 emit countChanged();
243 245 }
244 246 return success;
245 247 }
246 248
247 249 /*!
248 250 Removes barset from series. Releases ownership of \a set. Deletes the set, if remove
249 251 was successful.
250 252 Returns true, if set was removed.
251 253 */
252 254 bool QAbstractBarSeries::remove(QBarSet *set)
253 255 {
254 256 Q_D(QAbstractBarSeries);
255 257 bool success = d->remove(set);
256 258 if (success) {
257 259 QList<QBarSet *> sets;
258 260 sets.append(set);
259 261 set->setParent(0);
260 262 emit barsetsRemoved(sets);
261 263 emit countChanged();
262 264 delete set;
263 265 set = 0;
264 266 }
265 267 return success;
266 268 }
267 269
268 270 /*!
269 271 Takes a single \a set from the series. Does not delete the barset object.
270 272
271 273 NOTE: The series remains as the barset's parent object. You must set the
272 274 parent object to take full ownership.
273 275
274 276 Returns true if take was successful.
275 277 */
276 278 bool QAbstractBarSeries::take(QBarSet *set)
277 279 {
278 280 Q_D(QAbstractBarSeries);
279 281 bool success = d->remove(set);
280 282 if (success) {
281 283 QList<QBarSet *> sets;
282 284 sets.append(set);
283 285 emit barsetsRemoved(sets);
284 286 emit countChanged();
285 287 }
286 288 return success;
287 289 }
288 290
289 291 /*!
290 292 Adds a list of barsets to series. Takes ownership of \a sets.
291 293 Returns true, if all sets were appended successfully. If any of the sets is null or is already appended to series,
292 294 nothing is appended and function returns false. If any of the sets is in list more than once, nothing is appended
293 295 and function returns false.
294 296 */
295 297 bool QAbstractBarSeries::append(QList<QBarSet *> sets)
296 298 {
297 299 Q_D(QAbstractBarSeries);
298 300 bool success = d->append(sets);
299 301 if (success) {
300 302 emit barsetsAdded(sets);
301 303 emit countChanged();
302 304 }
303 305 return success;
304 306 }
305 307
306 308 /*!
307 309 Insert a set of bars to series at \a index postion. Takes ownership of \a set. If the set is null or is already in series, it won't be appended.
308 310 Returns true, if inserting succeeded.
309 311
310 312 */
311 313 bool QAbstractBarSeries::insert(int index, QBarSet *set)
312 314 {
313 315 Q_D(QAbstractBarSeries);
314 316 bool success = d->insert(index, set);
315 317 if (success) {
316 318 QList<QBarSet *> sets;
317 319 sets.append(set);
318 320 emit barsetsAdded(sets);
319 321 emit countChanged();
320 322 }
321 323 return success;
322 324 }
323 325
324 326 /*!
325 327 Removes all barsets from the series. Deletes removed sets.
326 328 */
327 329 void QAbstractBarSeries::clear()
328 330 {
329 331 Q_D(QAbstractBarSeries);
330 332 QList<QBarSet *> sets = barSets();
331 333 bool success = d->remove(sets);
332 334 if (success) {
333 335 emit barsetsRemoved(sets);
334 336 emit countChanged();
335 337 foreach (QBarSet *set, sets)
336 338 delete set;
337 339 }
338 340 }
339 341
340 342 /*!
341 343 Returns number of sets in series.
342 344 */
343 345 int QAbstractBarSeries::count() const
344 346 {
345 347 Q_D(const QAbstractBarSeries);
346 348 return d->m_barSets.count();
347 349 }
348 350
349 351 /*!
350 352 Returns a list of sets in series. Keeps ownership of sets.
351 353 */
352 354 QList<QBarSet *> QAbstractBarSeries::barSets() const
353 355 {
354 356 Q_D(const QAbstractBarSeries);
355 357 return d->m_barSets;
356 358 }
357 359
358 360 /*!
359 361 Sets the visibility of labels in series to \a visible
360 362 */
361 363 void QAbstractBarSeries::setLabelsVisible(bool visible)
362 364 {
363 365 Q_D(QAbstractBarSeries);
364 366 if (d->m_labelsVisible != visible) {
365 367 d->setLabelsVisible(visible);
366 368 emit labelsVisibleChanged();
367 369 }
368 370 }
369 371
370 372 /*!
371 373 Returns the visibility of labels
372 374 */
373 375 bool QAbstractBarSeries::isLabelsVisible() const
374 376 {
375 377 Q_D(const QAbstractBarSeries);
376 378 return d->m_labelsVisible;
377 379 }
378 380
379 381 ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
380 382
381 383 QAbstractBarSeriesPrivate::QAbstractBarSeriesPrivate(QAbstractBarSeries *q) :
382 384 QAbstractSeriesPrivate(q),
383 385 m_barWidth(0.5), // Default value is 50% of category width
384 386 m_labelsVisible(false),
385 387 m_visible(true)
386 388 {
387 389 }
388 390
389 391 int QAbstractBarSeriesPrivate::categoryCount() const
390 392 {
391 393 // No categories defined. return count of longest set.
392 394 int count = 0;
393 395 for (int i = 0; i < m_barSets.count(); i++) {
394 396 if (m_barSets.at(i)->count() > count)
395 397 count = m_barSets.at(i)->count();
396 398 }
397 399
398 400 return count;
399 401 }
400 402
401 403 void QAbstractBarSeriesPrivate::setBarWidth(qreal width)
402 404 {
403 405 if (width < 0.0)
404 406 width = 0.0;
405 407 m_barWidth = width;
406 408 emit updatedLayout();
407 409 }
408 410
409 411 qreal QAbstractBarSeriesPrivate::barWidth() const
410 412 {
411 413 return m_barWidth;
412 414 }
413 415
414 416 QBarSet *QAbstractBarSeriesPrivate::barsetAt(int index)
415 417 {
416 418 return m_barSets.at(index);
417 419 }
418 420
419 421 void QAbstractBarSeriesPrivate::setVisible(bool visible)
420 422 {
421 423 m_visible = visible;
422 424 emit visibleChanged();
423 425 }
424 426
425 427 void QAbstractBarSeriesPrivate::setLabelsVisible(bool visible)
426 428 {
427 429 m_labelsVisible = visible;
428 430 emit labelsVisibleChanged(visible);
429 431 }
430 432
431 433 qreal QAbstractBarSeriesPrivate::min()
432 434 {
433 435 if (m_barSets.count() <= 0)
434 436 return 0;
435 437
436 438 qreal min = INT_MAX;
437 439
438 440 for (int i = 0; i < m_barSets.count(); i++) {
439 441 int categoryCount = m_barSets.at(i)->count();
440 442 for (int j = 0; j < categoryCount; j++) {
441 443 qreal temp = m_barSets.at(i)->at(j);
442 444 if (temp < min)
443 445 min = temp;
444 446 }
445 447 }
446 448 return min;
447 449 }
448 450
449 451 qreal QAbstractBarSeriesPrivate::max()
450 452 {
451 453 if (m_barSets.count() <= 0)
452 454 return 0;
453 455
454 456 qreal max = INT_MIN;
455 457
456 458 for (int i = 0; i < m_barSets.count(); i++) {
457 459 int categoryCount = m_barSets.at(i)->count();
458 460 for (int j = 0; j < categoryCount; j++) {
459 461 qreal temp = m_barSets.at(i)->at(j);
460 462 if (temp > max)
461 463 max = temp;
462 464 }
463 465 }
464 466
465 467 return max;
466 468 }
467 469
468 470 qreal QAbstractBarSeriesPrivate::valueAt(int set, int category)
469 471 {
470 472 if ((set < 0) || (set >= m_barSets.count()))
471 473 return 0; // No set, no value.
472 474 else if ((category < 0) || (category >= m_barSets.at(set)->count()))
473 475 return 0; // No category, no value.
474 476
475 477 return m_barSets.at(set)->at(category);
476 478 }
477 479
478 480 qreal QAbstractBarSeriesPrivate::percentageAt(int set, int category)
479 481 {
480 482 if ((set < 0) || (set >= m_barSets.count()))
481 483 return 0; // No set, no value.
482 484 else if ((category < 0) || (category >= m_barSets.at(set)->count()))
483 485 return 0; // No category, no value.
484 486
485 487 qreal value = m_barSets.at(set)->at(category);
486 488 qreal sum = categorySum(category);
487 489 if (qFuzzyCompare(sum, 0))
488 490 return 0;
489 491
490 492 return value / sum;
491 493 }
492 494
493 495 qreal QAbstractBarSeriesPrivate::categorySum(int category)
494 496 {
495 497 qreal sum(0);
496 498 int count = m_barSets.count(); // Count sets
497 499 for (int set = 0; set < count; set++) {
498 500 if (category < m_barSets.at(set)->count())
499 501 sum += m_barSets.at(set)->at(category);
500 502 }
501 503 return sum;
502 504 }
503 505
504 506 qreal QAbstractBarSeriesPrivate::absoluteCategorySum(int category)
505 507 {
506 508 qreal sum(0);
507 509 int count = m_barSets.count(); // Count sets
508 510 for (int set = 0; set < count; set++) {
509 511 if (category < m_barSets.at(set)->count())
510 512 sum += qAbs(m_barSets.at(set)->at(category));
511 513 }
512 514 return sum;
513 515 }
514 516
515 517 qreal QAbstractBarSeriesPrivate::maxCategorySum()
516 518 {
517 519 qreal max = INT_MIN;
518 520 int count = categoryCount();
519 521 for (int i = 0; i < count; i++) {
520 522 qreal sum = categorySum(i);
521 523 if (sum > max)
522 524 max = sum;
523 525 }
524 526 return max;
525 527 }
526 528
527 529 qreal QAbstractBarSeriesPrivate::minX()
528 530 {
529 531 if (m_barSets.count() <= 0)
530 532 return 0;
531 533
532 534 qreal min = INT_MAX;
533 535
534 536 for (int i = 0; i < m_barSets.count(); i++) {
535 537 int categoryCount = m_barSets.at(i)->count();
536 538 for (int j = 0; j < categoryCount; j++) {
537 539 qreal temp = m_barSets.at(i)->d_ptr.data()->m_values.at(j).x();
538 540 if (temp < min)
539 541 min = temp;
540 542 }
541 543 }
542 544 return min;
543 545 }
544 546
545 547 qreal QAbstractBarSeriesPrivate::maxX()
546 548 {
547 549 if (m_barSets.count() <= 0)
548 550 return 0;
549 551
550 552 qreal max = INT_MIN;
551 553
552 554 for (int i = 0; i < m_barSets.count(); i++) {
553 555 int categoryCount = m_barSets.at(i)->count();
554 556 for (int j = 0; j < categoryCount; j++) {
555 557 qreal temp = m_barSets.at(i)->d_ptr.data()->m_values.at(j).x();
556 558 if (temp > max)
557 559 max = temp;
558 560 }
559 561 }
560 562
561 563 return max;
562 564 }
563 565
564 566 qreal QAbstractBarSeriesPrivate::categoryTop(int category)
565 567 {
566 568 // Returns top (sum of all positive values) of category.
567 569 // Returns 0, if all values are negative
568 570 qreal top(0);
569 571 int count = m_barSets.count();
570 572 for (int set = 0; set < count; set++) {
571 573 if (category < m_barSets.at(set)->count()) {
572 574 qreal temp = m_barSets.at(set)->at(category);
573 575 if (temp > 0) {
574 576 top += temp;
575 577 }
576 578 }
577 579 }
578 580 return top;
579 581 }
580 582
581 583 qreal QAbstractBarSeriesPrivate::categoryBottom(int category)
582 584 {
583 585 // Returns bottom (sum of all negative values) of category
584 586 // Returns 0, if all values are positive
585 587 qreal bottom(0);
586 588 int count = m_barSets.count();
587 589 for (int set = 0; set < count; set++) {
588 590 if (category < m_barSets.at(set)->count()) {
589 591 qreal temp = m_barSets.at(set)->at(category);
590 592 if (temp < 0) {
591 593 bottom += temp;
592 594 }
593 595 }
594 596 }
595 597 return bottom;
596 598 }
597 599
598 600 qreal QAbstractBarSeriesPrivate::top()
599 601 {
600 602 // Returns top of all categories
601 603 qreal top(0);
602 604 int count = categoryCount();
603 605 for (int i = 0; i < count; i++) {
604 606 qreal temp = categoryTop(i);
605 607 if (temp > top)
606 608 top = temp;
607 609 }
608 610 return top;
609 611 }
610 612
611 613 qreal QAbstractBarSeriesPrivate::bottom()
612 614 {
613 615 // Returns bottom of all categories
614 616 qreal bottom(0);
615 617 int count = categoryCount();
616 618 for (int i = 0; i < count; i++) {
617 619 qreal temp = categoryBottom(i);
618 620 if (temp < bottom)
619 621 bottom = temp;
620 622 }
621 623 return bottom;
622 624 }
623 625
624 626
625 627 void QAbstractBarSeriesPrivate::initializeDomain()
626 628 {
627 629 qreal minX(domain()->minX());
628 630 qreal minY(domain()->minY());
629 631 qreal maxX(domain()->maxX());
630 632 qreal maxY(domain()->maxY());
631 633
632 634 qreal seriesMinX = this->minX();
633 635 qreal seriesMaxX = this->maxX();
634 636 qreal y = max();
635 637 minX = qMin(minX, seriesMinX - (qreal)0.5);
636 638 minY = qMin(minY, y);
637 639 maxX = qMax(maxX, seriesMaxX + (qreal)0.5);
638 640 maxY = qMax(maxY, y);
639 641
640 642 domain()->setRange(minX, maxX, minY, maxY);
641 643 }
642 644
643 645 QList<QLegendMarker*> QAbstractBarSeriesPrivate::createLegendMarkers(QLegend* legend)
644 646 {
645 647 Q_Q(QAbstractBarSeries);
646 648 QList<QLegendMarker*> markers;
647 649
648 650 foreach(QBarSet* set, q->barSets()) {
649 651 QBarLegendMarker* marker = new QBarLegendMarker(q,set,legend);
650 652 markers << marker;
651 653 }
652 654 return markers;
653 655 }
654 656
655 657
656 658 bool QAbstractBarSeriesPrivate::append(QBarSet *set)
657 659 {
658 660 if ((m_barSets.contains(set)) || (set == 0))
659 661 return false; // Fail if set is already in list or set is null.
660 662
661 663 m_barSets.append(set);
662 664 QObject::connect(set->d_ptr.data(), SIGNAL(updatedLayout()), this, SIGNAL(updatedLayout()));
663 665 QObject::connect(set->d_ptr.data(), SIGNAL(updatedBars()), this, SIGNAL(updatedBars()));
664 666 QObject::connect(set->d_ptr.data(), SIGNAL(restructuredBars()), this, SIGNAL(restructuredBars()));
665 667
666 668 emit restructuredBars(); // this notifies barchartitem
667 669 return true;
668 670 }
669 671
670 672 bool QAbstractBarSeriesPrivate::remove(QBarSet *set)
671 673 {
672 674 if (!m_barSets.contains(set))
673 675 return false; // Fail if set is not in list
674 676
675 677 m_barSets.removeOne(set);
676 678 QObject::disconnect(set->d_ptr.data(), SIGNAL(updatedLayout()), this, SIGNAL(updatedLayout()));
677 679 QObject::disconnect(set->d_ptr.data(), SIGNAL(updatedBars()), this, SIGNAL(updatedBars()));
678 680 QObject::disconnect(set->d_ptr.data(), SIGNAL(restructuredBars()), this, SIGNAL(restructuredBars()));
679 681
680 682 emit restructuredBars(); // this notifies barchartitem
681 683 return true;
682 684 }
683 685
684 686 bool QAbstractBarSeriesPrivate::append(QList<QBarSet * > sets)
685 687 {
686 688 foreach (QBarSet *set, sets) {
687 689 if ((set == 0) || (m_barSets.contains(set)))
688 690 return false; // Fail if any of the sets is null or is already appended.
689 691 if (sets.count(set) != 1)
690 692 return false; // Also fail if same set is more than once in given list.
691 693 }
692 694
693 695 foreach (QBarSet *set, sets) {
694 696 m_barSets.append(set);
695 697 QObject::connect(set->d_ptr.data(), SIGNAL(updatedLayout()), this, SIGNAL(updatedLayout()));
696 698 QObject::connect(set->d_ptr.data(), SIGNAL(updatedBars()), this, SIGNAL(updatedBars()));
697 699 QObject::connect(set->d_ptr.data(), SIGNAL(restructuredBars()), this, SIGNAL(restructuredBars()));
698 700 }
699 701
700 702 emit restructuredBars(); // this notifies barchartitem
701 703 return true;
702 704 }
703 705
704 706 bool QAbstractBarSeriesPrivate::remove(QList<QBarSet * > sets)
705 707 {
706 708 if (sets.count() == 0)
707 709 return false;
708 710
709 711 foreach (QBarSet *set, sets) {
710 712 if ((set == 0) || (!m_barSets.contains(set)))
711 713 return false; // Fail if any of the sets is null or is not in series
712 714 if (sets.count(set) != 1)
713 715 return false; // Also fail if same set is more than once in given list.
714 716 }
715 717
716 718 foreach (QBarSet *set, sets) {
717 719 m_barSets.removeOne(set);
718 720 QObject::disconnect(set->d_ptr.data(), SIGNAL(updatedLayout()), this, SIGNAL(updatedLayout()));
719 721 QObject::disconnect(set->d_ptr.data(), SIGNAL(updatedBars()), this, SIGNAL(updatedBars()));
720 722 QObject::disconnect(set->d_ptr.data(), SIGNAL(restructuredBars()), this, SIGNAL(restructuredBars()));
721 723 }
722 724
723 725 emit restructuredBars(); // this notifies barchartitem
724 726
725 727 return true;
726 728 }
727 729
728 730 bool QAbstractBarSeriesPrivate::insert(int index, QBarSet *set)
729 731 {
730 732 if ((m_barSets.contains(set)) || (set == 0))
731 733 return false; // Fail if set is already in list or set is null.
732 734
733 735 m_barSets.insert(index, set);
734 736 QObject::connect(set->d_ptr.data(), SIGNAL(updatedLayout()), this, SIGNAL(updatedLayout()));
735 737 QObject::connect(set->d_ptr.data(), SIGNAL(updatedBars()), this, SIGNAL(updatedBars()));
736 738 QObject::connect(set->d_ptr.data(), SIGNAL(restructuredBars()), this, SIGNAL(restructuredBars()));
737 739
738 740 emit restructuredBars(); // this notifies barchartitem
739 741 return true;
740 742 }
741 743
742 744 void QAbstractBarSeriesPrivate::initializeAxes()
743 745 {
744 746 Q_Q(QAbstractBarSeries);
745 747
746 748 foreach(QAbstractAxis* axis, m_axes) {
747 749
748 750 if (axis->type() == QAbstractAxis::AxisTypeBarCategory) {
749 751 switch (q->type()) {
750 752 case QAbstractSeries::SeriesTypeHorizontalBar:
751 753 case QAbstractSeries::SeriesTypeHorizontalPercentBar:
752 754 case QAbstractSeries::SeriesTypeHorizontalStackedBar:
753 755 if (axis->orientation() == Qt::Vertical)
754 756 populateCategories(qobject_cast<QBarCategoryAxis *>(axis));
755 757 break;
756 758 case QAbstractSeries::SeriesTypeBar:
757 759 case QAbstractSeries::SeriesTypePercentBar:
758 760 case QAbstractSeries::SeriesTypeStackedBar:
759 761 if (axis->orientation() == Qt::Horizontal)
760 762 populateCategories(qobject_cast<QBarCategoryAxis *>(axis));
761 763 break;
762 764 default:
763 765 qWarning() << "Unexpected series type";
764 766 break;
765 767 }
766 768 }
767 769 }
768 770 }
769 771
770 772 QAbstractAxis::AxisType QAbstractBarSeriesPrivate::defaultAxisType(Qt::Orientation orientation) const
771 773 {
772 774 Q_Q(const QAbstractBarSeries);
773 775
774 776 switch (q->type()) {
775 777 case QAbstractSeries::SeriesTypeHorizontalBar:
776 778 case QAbstractSeries::SeriesTypeHorizontalPercentBar:
777 779 case QAbstractSeries::SeriesTypeHorizontalStackedBar:
778 780 if (orientation == Qt::Vertical)
779 781 return QAbstractAxis::AxisTypeBarCategory;
780 782 break;
781 783 case QAbstractSeries::SeriesTypeBar:
782 784 case QAbstractSeries::SeriesTypePercentBar:
783 785 case QAbstractSeries::SeriesTypeStackedBar:
784 786 if (orientation == Qt::Horizontal)
785 787 return QAbstractAxis::AxisTypeBarCategory;
786 788 break;
787 789 default:
788 790 qWarning() << "Unexpected series type";
789 791 break;
790 792 }
791 793 return QAbstractAxis::AxisTypeValue;
792 794
793 795 }
794 796
795 797 void QAbstractBarSeriesPrivate::populateCategories(QBarCategoryAxis *axis)
796 798 {
797 799 QStringList categories;
798 800 if (axis->categories().isEmpty()) {
799 801 for (int i(1); i < categoryCount() + 1; i++)
800 802 categories << QString::number(i);
801 803 axis->append(categories);
802 804 }
803 805 }
804 806
805 807 QAbstractAxis* QAbstractBarSeriesPrivate::createDefaultAxis(Qt::Orientation orientation) const
806 808 {
807 809 Q_UNUSED(orientation);
808 810 return 0;
809 811 }
810 812
811 813 void QAbstractBarSeriesPrivate::initializeTheme(int index, ChartTheme* theme, bool forced)
812 814 {
813 815 const QList<QGradient> gradients = theme->seriesGradients();
814 816
815 817 QBrush brush;
816 818 QPen pen;
817 819
818 820 qreal takeAtPos = 0.5;
819 821 qreal step = 0.2;
820 822 if (m_barSets.count() > 1) {
821 823 step = 1.0 / (qreal) m_barSets.count();
822 824 if (m_barSets.count() % gradients.count())
823 825 step *= gradients.count();
824 826 else
825 827 step *= (gradients.count() - 1);
826 828 }
827 829
828 830 for (int i(0); i < m_barSets.count(); i++) {
829 831 int colorIndex = (index + i) % gradients.count();
830 832 if (i > 0 && i %gradients.count() == 0) {
831 833 // There is no dedicated base color for each sets, generate more colors
832 834 takeAtPos += step;
833 835 if (takeAtPos == 1.0)
834 836 takeAtPos += step;
835 837 takeAtPos -= (int) takeAtPos;
836 838 }
837 839 if (forced || brush == m_barSets.at(i)->brush())
838 840 m_barSets.at(i)->setBrush(ChartThemeManager::colorAt(gradients.at(colorIndex), takeAtPos));
839 841
840 842 // Pick label color from the opposite end of the gradient.
841 843 // 0.3 as a boundary seems to work well.
842 844 if (forced || brush == m_barSets.at(i)->labelBrush()) {
843 845 if (takeAtPos < 0.3)
844 846 m_barSets.at(i)->setLabelBrush(ChartThemeManager::colorAt(gradients.at(index % gradients.size()), 1));
845 847 else
846 848 m_barSets.at(i)->setLabelBrush(ChartThemeManager::colorAt(gradients.at(index % gradients.size()), 0));
847 849 }
848 850
849 851 if (forced || pen == m_barSets.at(i)->pen()) {
850 852 QColor c = ChartThemeManager::colorAt(gradients.at(index % gradients.size()), 0.0);
851 853 m_barSets.at(i)->setPen(c);
852 854 }
853 855 }
854 856 }
855 857
858 void QAbstractBarSeriesPrivate::initializeAnimations(QChart::AnimationOptions options)
859 {
860 AbstractBarChartItem *bar = static_cast<AbstractBarChartItem *>(m_item.data());
861 Q_ASSERT(bar);
862 if (options.testFlag(QChart::SeriesAnimations)) {
863 bar->setAnimation(new BarAnimation(bar));
864 }else{
865 bar->setAnimation(0);
866 }
867 QAbstractSeriesPrivate::initializeAnimations(options);
868 }
869
856 870 #include "moc_qabstractbarseries.cpp"
857 871 #include "moc_qabstractbarseries_p.cpp"
858 872
859 873 QTCOMMERCIALCHART_END_NAMESPACE
@@ -1,112 +1,113
1 1 /****************************************************************************
2 2 **
3 3 ** Copyright (C) 2012 Digia Plc
4 4 ** All rights reserved.
5 5 ** For any questions to Digia, please use contact form at http://qt.digia.com
6 6 **
7 7 ** This file is part of the Qt Commercial Charts Add-on.
8 8 **
9 9 ** $QT_BEGIN_LICENSE$
10 10 ** Licensees holding valid Qt Commercial licenses may use this file in
11 11 ** accordance with the Qt Commercial License Agreement provided with the
12 12 ** Software or, alternatively, in accordance with the terms contained in
13 13 ** a written agreement between you and Digia.
14 14 **
15 15 ** If you have questions regarding the use of this file, please use
16 16 ** contact form at http://qt.digia.com
17 17 ** $QT_END_LICENSE$
18 18 **
19 19 ****************************************************************************/
20 20
21 21 // W A R N I N G
22 22 // -------------
23 23 //
24 24 // This file is not part of the QtCommercial Chart API. It exists purely as an
25 25 // implementation detail. This header file may change from version to
26 26 // version without notice, or even be removed.
27 27 //
28 28 // We mean it.
29 29
30 30 #ifndef QABSTRACTBARSERIES_P_H
31 31 #define QABSTRACTBARSERIES_P_H
32 32
33 33 #include "qabstractbarseries.h"
34 34 #include "qabstractseries_p.h"
35 35 #include <QStringList>
36 36 #include <QAbstractSeries>
37 37
38 38 QTCOMMERCIALCHART_BEGIN_NAMESPACE
39 39
40 40 class QBarModelMapper;
41 41 class QBarCategoryAxis;
42 42 class QLegendMarker;
43 43
44 44 class QAbstractBarSeriesPrivate : public QAbstractSeriesPrivate
45 45 {
46 46 Q_OBJECT
47 47 public:
48 48 QAbstractBarSeriesPrivate(QAbstractBarSeries *parent);
49 49 int categoryCount() const;
50 50
51 51 void setBarWidth(qreal width);
52 52 qreal barWidth() const;
53 53
54 54 void setVisible(bool visible);
55 55 void setLabelsVisible(bool visible);
56 56
57 57 void initializeDomain();
58 58 void initializeAxes();
59 void initializeAnimations(QChart::AnimationOptions options);
59 60 void initializeTheme(int index, ChartTheme* theme, bool forced = false);
60 61
61 62 QList<QLegendMarker*> createLegendMarkers(QLegend *legend);
62 63
63 64 virtual QAbstractAxis::AxisType defaultAxisType(Qt::Orientation orientation) const;
64 65 QAbstractAxis* createDefaultAxis(Qt::Orientation orientation) const;
65 66
66 67 bool append(QBarSet *set);
67 68 bool remove(QBarSet *set);
68 69 bool append(QList<QBarSet *> sets);
69 70 bool remove(QList<QBarSet *> sets);
70 71 bool insert(int index, QBarSet *set);
71 72
72 73 QBarSet *barsetAt(int index);
73 74 qreal min();
74 75 qreal max();
75 76 qreal valueAt(int set, int category);
76 77 qreal percentageAt(int set, int category);
77 78 qreal categorySum(int category);
78 79 qreal absoluteCategorySum(int category);
79 80 qreal maxCategorySum();
80 81 qreal minX();
81 82 qreal maxX();
82 83 qreal categoryTop(int category);
83 84 qreal categoryBottom(int category);
84 85 qreal top();
85 86 qreal bottom();
86 87
87 88 Q_SIGNALS:
88 89 void clicked(int index, QBarSet *barset);
89 90 void updatedBars();
90 91 void updatedLayout();
91 92 void restructuredBars();
92 93 void labelsVisibleChanged(bool visible);
93 94 void visibleChanged();
94 95
95 96 private:
96 97 void populateCategories(QBarCategoryAxis *axis);
97 98
98 99 protected:
99 100 QList<QBarSet *> m_barSets;
100 101 qreal m_barWidth;
101 102 bool m_labelsVisible;
102 103 bool m_visible;
103 104
104 105 private:
105 106 Q_DECLARE_PUBLIC(QAbstractBarSeries)
106 107 friend class HorizontalBarChartItem;
107 108 friend class BarChartItem;
108 109 };
109 110
110 111 QTCOMMERCIALCHART_END_NAMESPACE
111 112
112 113 #endif // QABSTRACTBARSERIES_P_H
@@ -1,63 +1,91
1 1 /****************************************************************************
2 2 **
3 3 ** Copyright (C) 2012 Digia Plc
4 4 ** All rights reserved.
5 5 ** For any questions to Digia, please use contact form at http://qt.digia.com
6 6 **
7 7 ** This file is part of the Qt Commercial Charts Add-on.
8 8 **
9 9 ** $QT_BEGIN_LICENSE$
10 10 ** Licensees holding valid Qt Commercial licenses may use this file in
11 11 ** accordance with the Qt Commercial License Agreement provided with the
12 12 ** Software or, alternatively, in accordance with the terms contained in
13 13 ** a written agreement between you and Digia.
14 14 **
15 15 ** If you have questions regarding the use of this file, please use
16 16 ** contact form at http://qt.digia.com
17 17 ** $QT_END_LICENSE$
18 18 **
19 19 ****************************************************************************/
20 20
21 21 #include "barchartitem_p.h"
22 22 #include "bar_p.h"
23 23 #include "qabstractbarseries_p.h"
24 24 #include "qbarset.h"
25 25 #include "qbarset_p.h"
26 26
27 27 QTCOMMERCIALCHART_BEGIN_NAMESPACE
28 28
29 29 BarChartItem::BarChartItem(QAbstractBarSeries *series, QGraphicsItem* item) :
30 30 AbstractBarChartItem(series, item)
31 31 {
32 32 }
33 33
34 void BarChartItem::initializeLayout()
35 {
36 qreal categoryCount = m_series->d_func()->categoryCount();
37 qreal setCount = m_series->count();
38 qreal barWidth = m_series->d_func()->barWidth();
39
40 m_layout.clear();
41 for(int category = 0; category < categoryCount; category++) {
42 for (int set = 0; set < setCount; set++) {
43 QRectF rect;
44 QPointF topLeft;
45 QPointF bottomRight;
46
47 if (domain()->type() == AbstractDomain::XLogYDomain || domain()->type() == AbstractDomain::LogXLogYDomain) {
48 topLeft = domain()->calculateGeometryPoint(QPointF(category - barWidth / 2 + set/setCount * barWidth, domain()->minY()));
49 bottomRight = domain()->calculateGeometryPoint(QPointF(category + barWidth / 2 + (set + 1)/setCount * barWidth, domain()->minY()));
50 } else {
51 topLeft = domain()->calculateGeometryPoint(QPointF(category - barWidth / 2 + set/setCount * barWidth, 0));
52 bottomRight = domain()->calculateGeometryPoint(QPointF(category - barWidth / 2 + (set + 1)/setCount * barWidth, 0));
53 }
54
55 rect.setTopLeft(topLeft);
56 rect.setBottomRight(bottomRight);
57 m_layout.append(rect.normalized());
58 }
59 }
60 }
61
34 62 QVector<QRectF> BarChartItem::calculateLayout()
35 63 {
36 64 QVector<QRectF> layout;
37 65
38 66 // Use temporary qreals for accuracy
39 67 qreal categoryCount = m_series->d_func()->categoryCount();
40 68 qreal setCount = m_series->count();
41 69 qreal barWidth = m_series->d_func()->barWidth();
42 70
43 71 for(int category = 0; category < categoryCount; category++) {
44 72 for (int set = 0; set < setCount; set++) {
45 73 qreal value = m_series->barSets().at(set)->at(category);
46 74 QRectF rect;
47 75 QPointF topLeft = domain()->calculateGeometryPoint(QPointF(category - barWidth / 2 + (set)/(setCount) * barWidth, value));
48 76 QPointF bottomRight;
49 77 if (domain()->type() == AbstractDomain::XLogYDomain || domain()->type() == AbstractDomain::LogXLogYDomain)
50 78 bottomRight = domain()->calculateGeometryPoint(QPointF(category - barWidth / 2 + (set + 1)/(setCount) * barWidth, domain()->minY()));
51 79 else
52 80 bottomRight = domain()->calculateGeometryPoint(QPointF(category - barWidth / 2 + (set + 1)/(setCount) * barWidth, 0));
53 81 rect.setTopLeft(topLeft);
54 82 rect.setBottomRight(bottomRight);
55 layout.append(rect);
83 layout.append(rect.normalized());
56 84 }
57 85 }
58 86 return layout;
59 87 }
60 88
61 89 #include "moc_barchartitem_p.cpp"
62 90
63 91 QTCOMMERCIALCHART_END_NAMESPACE
@@ -1,52 +1,53
1 1 /****************************************************************************
2 2 **
3 3 ** Copyright (C) 2012 Digia Plc
4 4 ** All rights reserved.
5 5 ** For any questions to Digia, please use contact form at http://qt.digia.com
6 6 **
7 7 ** This file is part of the Qt Commercial Charts Add-on.
8 8 **
9 9 ** $QT_BEGIN_LICENSE$
10 10 ** Licensees holding valid Qt Commercial licenses may use this file in
11 11 ** accordance with the Qt Commercial License Agreement provided with the
12 12 ** Software or, alternatively, in accordance with the terms contained in
13 13 ** a written agreement between you and Digia.
14 14 **
15 15 ** If you have questions regarding the use of this file, please use
16 16 ** contact form at http://qt.digia.com
17 17 ** $QT_END_LICENSE$
18 18 **
19 19 ****************************************************************************/
20 20
21 21 // W A R N I N G
22 22 // -------------
23 23 //
24 24 // This file is not part of the QtCommercial Chart API. It exists purely as an
25 25 // implementation detail. This header file may change from version to
26 26 // version without notice, or even be removed.
27 27 //
28 28 // We mean it.
29 29
30 30
31 31 #ifndef BARCHARTITEM_H
32 32 #define BARCHARTITEM_H
33 33
34 34 #include "abstractbarchartitem_p.h"
35 35 #include "qstackedbarseries.h"
36 36 #include <QGraphicsItem>
37 37
38 38 QTCOMMERCIALCHART_BEGIN_NAMESPACE
39 39
40 40 class BarChartItem : public AbstractBarChartItem
41 41 {
42 42 Q_OBJECT
43 43 public:
44 44 BarChartItem(QAbstractBarSeries *series, QGraphicsItem* item = 0);
45 45
46 46 private:
47 47 virtual QVector<QRectF> calculateLayout();
48 void initializeLayout();
48 49 };
49 50
50 51 QTCOMMERCIALCHART_END_NAMESPACE
51 52
52 53 #endif // BARCHARTITEM_H
@@ -1,132 +1,119
1 1 /****************************************************************************
2 2 **
3 3 ** Copyright (C) 2012 Digia Plc
4 4 ** All rights reserved.
5 5 ** For any questions to Digia, please use contact form at http://qt.digia.com
6 6 **
7 7 ** This file is part of the Qt Commercial Charts Add-on.
8 8 **
9 9 ** $QT_BEGIN_LICENSE$
10 10 ** Licensees holding valid Qt Commercial licenses may use this file in
11 11 ** accordance with the Qt Commercial License Agreement provided with the
12 12 ** Software or, alternatively, in accordance with the terms contained in
13 13 ** a written agreement between you and Digia.
14 14 **
15 15 ** If you have questions regarding the use of this file, please use
16 16 ** contact form at http://qt.digia.com
17 17 ** $QT_END_LICENSE$
18 18 **
19 19 ****************************************************************************/
20 20
21 21 #include "qbarseries.h"
22 22 #include "qbarseries_p.h"
23 23 #include "barchartitem_p.h"
24 24 #include "chartdataset_p.h"
25 25 #include "charttheme_p.h"
26 #include "baranimation_p.h"
27 26 #include "qvalueaxis.h"
28 27 #include "qbarcategoryaxis.h"
29 28
30 29 QTCOMMERCIALCHART_BEGIN_NAMESPACE
31 30
32 31 /*!
33 32 \class QBarSeries
34 33 \brief Series for creating bar chart
35 34 \mainclass
36 35
37 36 QBarSeries represents a series of data shown as bars. The purpose of this class is to draw bars
38 37 as groups, where bars in same category are grouped next to each other. QBarSeries groups the data
39 38 from sets to categories, which are defined by a QStringList.
40 39
41 40 See the \l {BarChart Example} {bar chart example} to learn how to create a grouped bar chart.
42 41 \image examples_barchart.png
43 42
44 43 \sa QBarSet, QPercentBarSeries, QAbstractBarSeries, QStackedBarSeries
45 44 */
46 45 /*!
47 46 \qmlclass BarSeries QBarSeries
48 47 \inherits AbstractBarSeries
49 48
50 49 The following QML shows how to create a simple grouped bar chart:
51 50 \snippet ../demos/qmlchart/qml/qmlchart/View6.qml 1
52 51 \beginfloatleft
53 52 \image demos_qmlchart6.png
54 53 \endfloat
55 54 \clearfloat
56 55 */
57 56
58 57 /*!
59 58 Constructs empty QBarSeries.
60 59 QBarSeries is QObject which is a child of a \a parent.
61 60 */
62 61 QBarSeries::QBarSeries(QObject *parent)
63 62 : QAbstractBarSeries(*new QBarSeriesPrivate(this), parent)
64 63 {
65 64
66 65 }
67 66
68 67 /*!
69 68 Returns QChartSeries::SeriesTypeBar.
70 69 */
71 70 QAbstractSeries::SeriesType QBarSeries::type() const
72 71 {
73 72 return QAbstractSeries::SeriesTypeBar;
74 73 }
75 74
76 75 /*!
77 76 Destructor. Removes series from chart.
78 77 */
79 78 QBarSeries::~QBarSeries()
80 79 {
81 80 Q_D(QBarSeries);
82 81 if (d->m_chart)
83 82 d->m_chart->removeSeries(this);
84 83 }
85 84 ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
86 85
87 86 QBarSeriesPrivate::QBarSeriesPrivate(QBarSeries *q) : QAbstractBarSeriesPrivate(q)
88 87 {
89 88
90 89 }
91 90
92 91 void QBarSeriesPrivate::initializeDomain()
93 92 {
94 93 qreal minX(domain()->minX());
95 94 qreal minY(domain()->minY());
96 95 qreal maxX(domain()->maxX());
97 96 qreal maxY(domain()->maxY());
98 97
99 98 qreal x = categoryCount();
100 99 minX = qMin(minX, - (qreal)0.5);
101 100 minY = qMin(minY, min());
102 101 maxX = qMax(maxX, x - (qreal)0.5);
103 102 maxY = qMax(maxY, max());
104 103
105 104 domain()->setRange(minX, maxX, minY, maxY);
106 105 }
107 106
108 107
109 108 void QBarSeriesPrivate::initializeGraphics(QGraphicsItem* parent)
110 109 {
111 110 Q_Q(QBarSeries);
112 111 BarChartItem *bar = new BarChartItem(q,parent);
113 112 m_item.reset(bar);
114 113 QAbstractSeriesPrivate::initializeGraphics(parent);
115 114 }
116 115
117 void QBarSeriesPrivate::initializeAnimations(QtCommercialChart::QChart::AnimationOptions options)
118 {
119 BarChartItem *bar = static_cast<BarChartItem *>(m_item.data());
120 Q_ASSERT(bar);
121 if (options.testFlag(QChart::SeriesAnimations)) {
122 bar->setAnimation(new BarAnimation(bar));
123 }else{
124 bar->setAnimation(0);
125 }
126 QAbstractSeriesPrivate::initializeAnimations(options);
127 }
128
129 116 #include "moc_qbarseries.cpp"
130 117
131 118 QTCOMMERCIALCHART_END_NAMESPACE
132 119
@@ -1,53 +1,52
1 1 /****************************************************************************
2 2 **
3 3 ** Copyright (C) 2012 Digia Plc
4 4 ** All rights reserved.
5 5 ** For any questions to Digia, please use contact form at http://qt.digia.com
6 6 **
7 7 ** This file is part of the Qt Commercial Charts Add-on.
8 8 **
9 9 ** $QT_BEGIN_LICENSE$
10 10 ** Licensees holding valid Qt Commercial licenses may use this file in
11 11 ** accordance with the Qt Commercial License Agreement provided with the
12 12 ** Software or, alternatively, in accordance with the terms contained in
13 13 ** a written agreement between you and Digia.
14 14 **
15 15 ** If you have questions regarding the use of this file, please use
16 16 ** contact form at http://qt.digia.com
17 17 ** $QT_END_LICENSE$
18 18 **
19 19 ****************************************************************************/
20 20
21 21 // W A R N I N G
22 22 // -------------
23 23 //
24 24 // This file is not part of the QtCommercial Chart API. It exists purely as an
25 25 // implementation detail. This header file may change from version to
26 26 // version without notice, or even be removed.
27 27 //
28 28 // We mean it.
29 29
30 30 #ifndef QBARSERIES_P_H
31 31 #define QBARSERIES_P_H
32 32
33 33 #include "qabstractbarseries_p.h"
34 34 #include "abstractdomain_p.h"
35 35
36 36 QTCOMMERCIALCHART_BEGIN_NAMESPACE
37 37
38 38
39 39 class QBarSeriesPrivate: public QAbstractBarSeriesPrivate
40 40 {
41 41 public:
42 42 QBarSeriesPrivate(QBarSeries *q);
43 43 void initializeGraphics(QGraphicsItem* parent);
44 void initializeAnimations(QtCommercialChart::QChart::AnimationOptions options);
45 44 void initializeDomain();
46 45
47 46 private:
48 47 Q_DECLARE_PUBLIC(QBarSeries)
49 48 };
50 49
51 50 QTCOMMERCIALCHART_END_NAMESPACE
52 51
53 52 #endif // QBARSERIES_P_H
@@ -1,95 +1,123
1 1 /****************************************************************************
2 2 **
3 3 ** Copyright (C) 2012 Digia Plc
4 4 ** All rights reserved.
5 5 ** For any questions to Digia, please use contact form at http://qt.digia.com
6 6 **
7 7 ** This file is part of the Qt Commercial Charts Add-on.
8 8 **
9 9 ** $QT_BEGIN_LICENSE$
10 10 ** Licensees holding valid Qt Commercial licenses may use this file in
11 11 ** accordance with the Qt Commercial License Agreement provided with the
12 12 ** Software or, alternatively, in accordance with the terms contained in
13 13 ** a written agreement between you and Digia.
14 14 **
15 15 ** If you have questions regarding the use of this file, please use
16 16 ** contact form at http://qt.digia.com
17 17 ** $QT_END_LICENSE$
18 18 **
19 19 ****************************************************************************/
20 20
21 21 #include "percentbarchartitem_p.h"
22 22 #include "bar_p.h"
23 23 #include "qabstractbarseries_p.h"
24 24 #include "qbarset.h"
25 25 #include "qbarset_p.h"
26 26
27 27 QTCOMMERCIALCHART_BEGIN_NAMESPACE
28 28
29 29 PercentBarChartItem::PercentBarChartItem(QAbstractBarSeries *series, QGraphicsItem* item) :
30 30 AbstractBarChartItem(series, item)
31 31 {
32 32 }
33 33
34 void PercentBarChartItem::initializeLayout()
35 {
36 qreal categoryCount = m_series->d_func()->categoryCount();
37 qreal setCount = m_series->count();
38 qreal barWidth = m_series->d_func()->barWidth();
39
40 m_layout.clear();
41 for(int category = 0; category < categoryCount; category++) {
42 for (int set = 0; set < setCount; set++) {
43 QRectF rect;
44 QPointF topLeft;
45 QPointF bottomRight;
46
47 if (domain()->type() == AbstractDomain::XLogYDomain || domain()->type() == AbstractDomain::LogXLogYDomain) {
48 topLeft = domain()->calculateGeometryPoint(QPointF(category - barWidth / 2, domain()->minY()));
49 bottomRight = domain()->calculateGeometryPoint(QPointF(category + barWidth / 2, domain()->minY()));
50 } else {
51 topLeft = domain()->calculateGeometryPoint(QPointF(category - barWidth / 2, 0));
52 bottomRight = domain()->calculateGeometryPoint(QPointF(category + barWidth / 2, 0));
53 }
54
55 rect.setTopLeft(topLeft);
56 rect.setBottomRight(bottomRight);
57 m_layout.append(rect.normalized());
58 }
59 }
60 }
61
34 62 QVector<QRectF> PercentBarChartItem::calculateLayout()
35 63 {
36 64 QVector<QRectF> layout;
37 65
38 66 // Use temporary qreals for accuracy
39 67 qreal categoryCount = m_series->d_func()->categoryCount();
40 68 qreal setCount = m_series->count();
41 69 qreal barWidth = m_series->d_func()->barWidth();
42 70
43 71 for(int category = 0; category < categoryCount; category++) {
44 72 qreal sum = 0;
45 73 qreal categorySum = m_series->d_func()->categorySum(category);
46 74 for (int set = 0; set < setCount; set++) {
47 75 qreal value = m_series->barSets().at(set)->at(category);
48 76 QRectF rect;
49 77 QPointF topLeft = domain()->calculateGeometryPoint(QPointF(category - barWidth/2, 100 * (value + sum)/categorySum));
50 78 QPointF bottomRight;
51 79 if (domain()->type() == AbstractDomain::XLogYDomain || domain()->type() == AbstractDomain::LogXLogYDomain)
52 80 bottomRight = domain()->calculateGeometryPoint(QPointF(category + barWidth/2, set ? 100 * sum/categorySum : domain()->minY()));
53 81 else
54 82 bottomRight = domain()->calculateGeometryPoint(QPointF(category + barWidth/2, set ? 100 * sum/categorySum : 0));
55 83 rect.setTopLeft(topLeft);
56 84 rect.setBottomRight(bottomRight);
57 layout.append(rect);
85 layout.append(rect.normalized());
58 86 sum +=value;
59 87 }
60 88 }
61 89 return layout;
62 90 }
63 91
64 92 void PercentBarChartItem::handleUpdatedBars()
65 93 {
66 94 // Handle changes in pen, brush, labels etc.
67 95 int categoryCount = m_series->d_func()->categoryCount();
68 96 int setCount = m_series->count();
69 97 int itemIndex(0);
70 98
71 99 for (int category = 0; category < categoryCount; category++) {
72 100 for (int set = 0; set < setCount; set++) {
73 101 QBarSetPrivate *barSet = m_series->d_func()->barsetAt(set)->d_ptr.data();
74 102 Bar *bar = m_bars.at(itemIndex);
75 103 bar->setPen(barSet->m_pen);
76 104 bar->setBrush(barSet->m_brush);
77 105 bar->update();
78 106
79 107 QGraphicsSimpleTextItem *label = m_labels.at(itemIndex);
80 108 int p = m_series->d_func()->percentageAt(set, category) * 100;
81 109 QString vString(QString::number(p));
82 110 vString.truncate(3);
83 111 vString.append("%");
84 112 label->setText(vString);
85 113 label->setFont(barSet->m_labelFont);
86 114 label->setBrush(barSet->m_labelBrush);
87 115 label->update();
88 116 itemIndex++;
89 117 }
90 118 }
91 119 }
92 120
93 121 #include "moc_percentbarchartitem_p.cpp"
94 122
95 123 QTCOMMERCIALCHART_END_NAMESPACE
@@ -1,54 +1,55
1 1 /****************************************************************************
2 2 **
3 3 ** Copyright (C) 2012 Digia Plc
4 4 ** All rights reserved.
5 5 ** For any questions to Digia, please use contact form at http://qt.digia.com
6 6 **
7 7 ** This file is part of the Qt Commercial Charts Add-on.
8 8 **
9 9 ** $QT_BEGIN_LICENSE$
10 10 ** Licensees holding valid Qt Commercial licenses may use this file in
11 11 ** accordance with the Qt Commercial License Agreement provided with the
12 12 ** Software or, alternatively, in accordance with the terms contained in
13 13 ** a written agreement between you and Digia.
14 14 **
15 15 ** If you have questions regarding the use of this file, please use
16 16 ** contact form at http://qt.digia.com
17 17 ** $QT_END_LICENSE$
18 18 **
19 19 ****************************************************************************/
20 20
21 21 // W A R N I N G
22 22 // -------------
23 23 //
24 24 // This file is not part of the QtCommercial Chart API. It exists purely as an
25 25 // implementation detail. This header file may change from version to
26 26 // version without notice, or even be removed.
27 27 //
28 28 // We mean it.
29 29
30 30
31 31 #ifndef PERCENTBARCHARTITEM_H
32 32 #define PERCENTBARCHARTITEM_H
33 33
34 34 #include "abstractbarchartitem_p.h"
35 35 #include <QGraphicsItem>
36 36
37 37 QTCOMMERCIALCHART_BEGIN_NAMESPACE
38 38
39 39 class QAbstractBarSeries;
40 40
41 41 class PercentBarChartItem : public AbstractBarChartItem
42 42 {
43 43 Q_OBJECT
44 44 public:
45 45 PercentBarChartItem(QAbstractBarSeries *series, QGraphicsItem* item = 0);
46 46 void handleUpdatedBars();
47 47
48 48 private:
49 virtual QVector<QRectF> calculateLayout();
49 virtual QVector<QRectF> calculateLayout();
50 void initializeLayout();
50 51 };
51 52
52 53 QTCOMMERCIALCHART_END_NAMESPACE
53 54
54 55 #endif // PERCENTBARCHARTITEM_H
@@ -1,130 +1,118
1 1 /****************************************************************************
2 2 **
3 3 ** Copyright (C) 2012 Digia Plc
4 4 ** All rights reserved.
5 5 ** For any questions to Digia, please use contact form at http://qt.digia.com
6 6 **
7 7 ** This file is part of the Qt Commercial Charts Add-on.
8 8 **
9 9 ** $QT_BEGIN_LICENSE$
10 10 ** Licensees holding valid Qt Commercial licenses may use this file in
11 11 ** accordance with the Qt Commercial License Agreement provided with the
12 12 ** Software or, alternatively, in accordance with the terms contained in
13 13 ** a written agreement between you and Digia.
14 14 **
15 15 ** If you have questions regarding the use of this file, please use
16 16 ** contact form at http://qt.digia.com
17 17 ** $QT_END_LICENSE$
18 18 **
19 19 ****************************************************************************/
20 20
21 21 #include "qpercentbarseries.h"
22 22 #include "qpercentbarseries_p.h"
23 23 #include "percentbarchartitem_p.h"
24 24 #include "chartdataset_p.h"
25 25 #include "charttheme_p.h"
26 26 #include "qvalueaxis.h"
27 #include "percentbaranimation_p.h"
28 27
29 28 QTCOMMERCIALCHART_BEGIN_NAMESPACE
30 29
31 30 /*!
32 31 \class QPercentBarSeries
33 32 \brief Series for creating percent bar chart
34 33 \mainclass
35 34
36 35 QPercentBarSeries represents a series of data shown as bars. The purpose of this class is to draw bars
37 36 as stacks, where each bar is shown as percentage of all bars in that category.
38 37 QPercentBarSeries groups the data from sets to categories, which are defined by a QStringList.
39 38
40 39 See the \l {PercentbarChart Example} {percent bar chart example} to learn how to create a percent bar chart.
41 40 \image examples_percentbarchart.png
42 41
43 42 \sa QBarSet, QStackedBarSeries, QAbstractBarSeries
44 43 */
45 44 /*!
46 45 \qmlclass PercentBarSeries QPercentBarSeries
47 46 \inherits QAbstractBarSeries
48 47
49 48 The following QML shows how to create a simple percent bar chart:
50 49 \snippet ../demos/qmlchart/qml/qmlchart/View8.qml 1
51 50 \beginfloatleft
52 51 \image demos_qmlchart8.png
53 52 \endfloat
54 53 \clearfloat
55 54 */
56 55
57 56 /*!
58 57 Constructs empty QPercentBarSeries.
59 58 QPercentBarSeries is QObject which is a child of a \a parent.
60 59 */
61 60 QPercentBarSeries::QPercentBarSeries(QObject *parent)
62 61 : QAbstractBarSeries(*new QPercentBarSeriesPrivate(this), parent)
63 62 {
64 63 }
65 64
66 65 /*!
67 66 Destructor. Removes series from chart.
68 67 */
69 68 QPercentBarSeries::~QPercentBarSeries()
70 69 {
71 70 Q_D(QPercentBarSeries);
72 71 if (d->m_chart)
73 72 d->m_chart->removeSeries(this);
74 73 }
75 74
76 75 /*!
77 76 Returns QChartSeries::SeriesTypePercentBar.
78 77 */
79 78 QAbstractSeries::SeriesType QPercentBarSeries::type() const
80 79 {
81 80 return QAbstractSeries::SeriesTypePercentBar;
82 81 }
83 82
84 83 ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
85 84
86 85 QPercentBarSeriesPrivate::QPercentBarSeriesPrivate(QPercentBarSeries *q) : QAbstractBarSeriesPrivate(q)
87 86 {
88 87
89 88 }
90 89
91 90 void QPercentBarSeriesPrivate::initializeDomain()
92 91 {
93 92 qreal minX(domain()->minX());
94 93 qreal minY(domain()->minY());
95 94 qreal maxX(domain()->maxX());
96 95 qreal maxY(domain()->maxY());
97 96
98 97 qreal x = categoryCount();
99 98 minX = qMin(minX, - (qreal)0.5);
100 99 maxX = qMax(maxX, x - (qreal)0.5);
101 100 minY = 0;
102 101 maxY = 100;
103 102
104 103 domain()->setRange(minX, maxX, minY, maxY);
105 104 }
106 105
107 106
108 107 void QPercentBarSeriesPrivate::initializeGraphics(QGraphicsItem* parent)
109 108 {
110 109 Q_Q(QPercentBarSeries);
111 110 PercentBarChartItem *bar = new PercentBarChartItem(q,parent);
112 111 m_item.reset(bar);
113 112 QAbstractSeriesPrivate::initializeGraphics(parent);
114 113 }
115 114
116 void QPercentBarSeriesPrivate::initializeAnimations(QtCommercialChart::QChart::AnimationOptions options)
117 {
118 PercentBarChartItem *bar = static_cast<PercentBarChartItem *>(m_item.data());
119 Q_ASSERT(bar);
120 if (options.testFlag(QChart::SeriesAnimations)) {
121 bar->setAnimation(new PercentBarAnimation(bar));
122 }else{
123 bar->setAnimation(0);
124 }
125 QAbstractSeriesPrivate::initializeAnimations(options);
126 }
127 115 #include "moc_qpercentbarseries.cpp"
128 116
129 117 QTCOMMERCIALCHART_END_NAMESPACE
130 118
@@ -1,52 +1,51
1 1 /****************************************************************************
2 2 **
3 3 ** Copyright (C) 2012 Digia Plc
4 4 ** All rights reserved.
5 5 ** For any questions to Digia, please use contact form at http://qt.digia.com
6 6 **
7 7 ** This file is part of the Qt Commercial Charts Add-on.
8 8 **
9 9 ** $QT_BEGIN_LICENSE$
10 10 ** Licensees holding valid Qt Commercial licenses may use this file in
11 11 ** accordance with the Qt Commercial License Agreement provided with the
12 12 ** Software or, alternatively, in accordance with the terms contained in
13 13 ** a written agreement between you and Digia.
14 14 **
15 15 ** If you have questions regarding the use of this file, please use
16 16 ** contact form at http://qt.digia.com
17 17 ** $QT_END_LICENSE$
18 18 **
19 19 ****************************************************************************/
20 20
21 21 // W A R N I N G
22 22 // -------------
23 23 //
24 24 // This file is not part of the QtCommercial Chart API. It exists purely as an
25 25 // implementation detail. This header file may change from version to
26 26 // version without notice, or even be removed.
27 27 //
28 28 // We mean it.
29 29
30 30 #ifndef QPERCENTBARSERIES_P_H
31 31 #define QPERCENTBARSERIES_P_H
32 32
33 33 #include "qabstractbarseries_p.h"
34 34 #include "abstractdomain_p.h"
35 35
36 36 QTCOMMERCIALCHART_BEGIN_NAMESPACE
37 37
38 38
39 39 class QPercentBarSeriesPrivate: public QAbstractBarSeriesPrivate
40 40 {
41 41 public:
42 42 QPercentBarSeriesPrivate(QPercentBarSeries *q);
43 43 void initializeDomain();
44 44 void initializeGraphics(QGraphicsItem* parent);
45 void initializeAnimations(QtCommercialChart::QChart::AnimationOptions options);
46 45 private:
47 46 Q_DECLARE_PUBLIC(QPercentBarSeries)
48 47 };
49 48
50 49 QTCOMMERCIALCHART_END_NAMESPACE
51 50
52 51 #endif
@@ -1,129 +1,117
1 1 /****************************************************************************
2 2 **
3 3 ** Copyright (C) 2012 Digia Plc
4 4 ** All rights reserved.
5 5 ** For any questions to Digia, please use contact form at http://qt.digia.com
6 6 **
7 7 ** This file is part of the Qt Commercial Charts Add-on.
8 8 **
9 9 ** $QT_BEGIN_LICENSE$
10 10 ** Licensees holding valid Qt Commercial licenses may use this file in
11 11 ** accordance with the Qt Commercial License Agreement provided with the
12 12 ** Software or, alternatively, in accordance with the terms contained in
13 13 ** a written agreement between you and Digia.
14 14 **
15 15 ** If you have questions regarding the use of this file, please use
16 16 ** contact form at http://qt.digia.com
17 17 ** $QT_END_LICENSE$
18 18 **
19 19 ****************************************************************************/
20 20
21 21 #include "qstackedbarseries.h"
22 22 #include "qstackedbarseries_p.h"
23 23 #include "stackedbarchartitem_p.h"
24 24 #include "chartdataset_p.h"
25 25 #include "charttheme_p.h"
26 26 #include "qvalueaxis.h"
27 #include "stackedbaranimation_p.h"
28 27
29 28 QTCOMMERCIALCHART_BEGIN_NAMESPACE
30 29
31 30 /*!
32 31 \class QStackedBarSeries
33 32 \brief Series for creating stacked bar chart
34 33 \mainclass
35 34
36 35 QStackedBarSeries represents a series of data shown as bars. The purpose of this class is to draw bars
37 36 as stacks, where bars in same category are stacked on top of each other.
38 37 QStackedBarSeries groups the data from sets to categories, which are defined by QStringList.
39 38
40 39 See the \l {StackedbarChart Example} {stacked bar chart example} to learn how to create a stacked bar chart.
41 40 \image examples_stackedbarchart.png
42 41
43 42 \sa QBarSet, QPercentBarSeries, QAbstractBarSeries
44 43 */
45 44
46 45 /*!
47 46 \qmlclass StackedBarSeries QStackedBarSeries
48 47 \inherits AbstractBarSeries
49 48
50 49 The following QML shows how to create a simple stacked bar chart:
51 50 \snippet ../demos/qmlchart/qml/qmlchart/View7.qml 1
52 51 \beginfloatleft
53 52 \image demos_qmlchart7.png
54 53 \endfloat
55 54 \clearfloat
56 55 */
57 56
58 57 /*!
59 58 Constructs empty QStackedBarSeries.
60 59 QStackedBarSeries is QObject which is a child of a \a parent.
61 60 */
62 61 QStackedBarSeries::QStackedBarSeries(QObject *parent)
63 62 : QAbstractBarSeries(*new QStackedBarSeriesPrivate(this), parent)
64 63 {
65 64 }
66 65
67 66 /*!
68 67 Destructor. Removes series from chart.
69 68 */
70 69 QStackedBarSeries::~QStackedBarSeries()
71 70 {
72 71 Q_D(QStackedBarSeries);
73 72 if (d->m_chart)
74 73 d->m_chart->removeSeries(this);
75 74 }
76 75 /*!
77 76 Returns QChartSeries::SeriesTypeStackedBar.
78 77 */
79 78 QAbstractSeries::SeriesType QStackedBarSeries::type() const
80 79 {
81 80 return QAbstractSeries::SeriesTypeStackedBar;
82 81 }
83 82
84 83 ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
85 84
86 85 QStackedBarSeriesPrivate::QStackedBarSeriesPrivate(QStackedBarSeries *q) : QAbstractBarSeriesPrivate(q)
87 86 {
88 87
89 88 }
90 89
91 90 void QStackedBarSeriesPrivate::initializeDomain()
92 91 {
93 92 qreal minX(domain()->minX());
94 93 qreal minY(domain()->minY());
95 94 qreal maxX(domain()->maxX());
96 95 qreal maxY(domain()->maxY());
97 96
98 97 qreal x = categoryCount();
99 98 minX = qMin(minX, - (qreal)0.5);
100 99 minY = qMin(minY, bottom());
101 100 maxX = qMax(maxX, x - (qreal)0.5);
102 101 maxY = qMax(maxY, top());
103 102
104 103 domain()->setRange(minX, maxX, minY, maxY);
105 104 }
106 105
107 106 void QStackedBarSeriesPrivate::initializeGraphics(QGraphicsItem* parent)
108 107 {
109 108 Q_Q(QStackedBarSeries);
110 109 StackedBarChartItem *bar = new StackedBarChartItem(q,parent);
111 110 m_item.reset(bar);
112 111 QAbstractSeriesPrivate::initializeGraphics(parent);
113 112 }
114 113
115 void QStackedBarSeriesPrivate::initializeAnimations(QtCommercialChart::QChart::AnimationOptions options)
116 {
117 StackedBarChartItem *bar = static_cast<StackedBarChartItem *>(m_item.data());
118 Q_ASSERT(bar);
119 if (options.testFlag(QChart::SeriesAnimations)) {
120 bar->setAnimation(new StackedBarAnimation(bar));
121 }else{
122 bar->setAnimation(0);
123 }
124 QAbstractSeriesPrivate::initializeAnimations(options);
125 }
126 114 #include "moc_qstackedbarseries.cpp"
127 115
128 116 QTCOMMERCIALCHART_END_NAMESPACE
129 117
@@ -1,52 +1,51
1 1 /****************************************************************************
2 2 **
3 3 ** Copyright (C) 2012 Digia Plc
4 4 ** All rights reserved.
5 5 ** For any questions to Digia, please use contact form at http://qt.digia.com
6 6 **
7 7 ** This file is part of the Qt Commercial Charts Add-on.
8 8 **
9 9 ** $QT_BEGIN_LICENSE$
10 10 ** Licensees holding valid Qt Commercial licenses may use this file in
11 11 ** accordance with the Qt Commercial License Agreement provided with the
12 12 ** Software or, alternatively, in accordance with the terms contained in
13 13 ** a written agreement between you and Digia.
14 14 **
15 15 ** If you have questions regarding the use of this file, please use
16 16 ** contact form at http://qt.digia.com
17 17 ** $QT_END_LICENSE$
18 18 **
19 19 ****************************************************************************/
20 20
21 21 // W A R N I N G
22 22 // -------------
23 23 //
24 24 // This file is not part of the QtCommercial Chart API. It exists purely as an
25 25 // implementation detail. This header file may change from version to
26 26 // version without notice, or even be removed.
27 27 //
28 28 // We mean it.
29 29
30 30 #ifndef QSTACKEDBARSERIES_P_H
31 31 #define QSTACKEDBARSERIES_P_H
32 32
33 33 #include "qabstractbarseries_p.h"
34 34 #include "abstractdomain_p.h"
35 35
36 36 QTCOMMERCIALCHART_BEGIN_NAMESPACE
37 37
38 38
39 39 class QStackedBarSeriesPrivate: public QAbstractBarSeriesPrivate
40 40 {
41 41 public:
42 42 QStackedBarSeriesPrivate(QStackedBarSeries *q);
43 43 void initializeGraphics(QGraphicsItem* parent);
44 void initializeAnimations(QtCommercialChart::QChart::AnimationOptions options);
45 44 void initializeDomain();
46 45 private:
47 46 Q_DECLARE_PUBLIC(QStackedBarSeries)
48 47 };
49 48
50 49 QTCOMMERCIALCHART_END_NAMESPACE
51 50
52 51 #endif
@@ -1,75 +1,103
1 1 /****************************************************************************
2 2 **
3 3 ** Copyright (C) 2012 Digia Plc
4 4 ** All rights reserved.
5 5 ** For any questions to Digia, please use contact form at http://qt.digia.com
6 6 **
7 7 ** This file is part of the Qt Commercial Charts Add-on.
8 8 **
9 9 ** $QT_BEGIN_LICENSE$
10 10 ** Licensees holding valid Qt Commercial licenses may use this file in
11 11 ** accordance with the Qt Commercial License Agreement provided with the
12 12 ** Software or, alternatively, in accordance with the terms contained in
13 13 ** a written agreement between you and Digia.
14 14 **
15 15 ** If you have questions regarding the use of this file, please use
16 16 ** contact form at http://qt.digia.com
17 17 ** $QT_END_LICENSE$
18 18 **
19 19 ****************************************************************************/
20 20
21 21 #include "stackedbarchartitem_p.h"
22 22 #include "bar_p.h"
23 23 #include "qbarset_p.h"
24 24 #include "qabstractbarseries_p.h"
25 25 #include "qbarset.h"
26 26
27 27 QTCOMMERCIALCHART_BEGIN_NAMESPACE
28 28
29 29 StackedBarChartItem::StackedBarChartItem(QAbstractBarSeries *series, QGraphicsItem* item) :
30 30 AbstractBarChartItem(series, item)
31 31 {
32 32 }
33 33
34 void StackedBarChartItem::initializeLayout()
35 {
36 qreal categoryCount = m_series->d_func()->categoryCount();
37 qreal setCount = m_series->count();
38 qreal barWidth = m_series->d_func()->barWidth();
39
40 m_layout.clear();
41 for(int category = 0; category < categoryCount; category++) {
42 for (int set = 0; set < setCount; set++) {
43 QRectF rect;
44 QPointF topLeft;
45 QPointF bottomRight;
46
47 if (domain()->type() == AbstractDomain::XLogYDomain || domain()->type() == AbstractDomain::LogXLogYDomain) {
48 topLeft = domain()->calculateGeometryPoint(QPointF(category - barWidth / 2, domain()->minY()));
49 bottomRight = domain()->calculateGeometryPoint(QPointF(category + barWidth / 2, domain()->minY()));
50 } else {
51 topLeft = domain()->calculateGeometryPoint(QPointF(category - barWidth / 2, 0));
52 bottomRight = domain()->calculateGeometryPoint(QPointF(category + barWidth / 2, 0));
53 }
54
55 rect.setTopLeft(topLeft);
56 rect.setBottomRight(bottomRight);
57 m_layout.append(rect.normalized());
58 }
59 }
60 }
61
34 62 QVector<QRectF> StackedBarChartItem::calculateLayout()
35 63 {
36 64 QVector<QRectF> layout;
37 65 // Use temporary qreals for accuracy
38 66 qreal categoryCount = m_series->d_func()->categoryCount();
39 67 qreal setCount = m_series->count();
40 68 qreal barWidth = m_series->d_func()->barWidth();
41 69
42 70 for(int category = 0; category < categoryCount; category++) {
43 71 qreal positiveSum = 0;
44 72 qreal negativeSum = 0;
45 73 for (int set = 0; set < setCount; set++) {
46 74 qreal value = m_series->barSets().at(set)->at(category);
47 75 QRectF rect;
48 76 QPointF topLeft;
49 77 QPointF bottomRight;
50 78 if (value < 0) {
51 79 bottomRight = domain()->calculateGeometryPoint(QPointF(category - barWidth / 2, value + negativeSum));
52 80 if (domain()->type() == AbstractDomain::XLogYDomain || domain()->type() == AbstractDomain::LogXLogYDomain)
53 81 topLeft = domain()->calculateGeometryPoint(QPointF(category + barWidth / 2, set ? negativeSum : domain()->minY()));
54 82 else
55 83 topLeft = domain()->calculateGeometryPoint(QPointF(category + barWidth / 2, set ? negativeSum : 0));
56 84 negativeSum += value;
57 85 } else {
58 bottomRight = domain()->calculateGeometryPoint(QPointF(category - barWidth / 2, value + positiveSum));
86 topLeft = domain()->calculateGeometryPoint(QPointF(category - barWidth / 2, value + positiveSum));
59 87 if (domain()->type() == AbstractDomain::XLogYDomain || domain()->type() == AbstractDomain::LogXLogYDomain)
60 topLeft = domain()->calculateGeometryPoint(QPointF(category + barWidth / 2, set ? positiveSum : domain()->minY()));
88 bottomRight = domain()->calculateGeometryPoint(QPointF(category + barWidth / 2, set ? positiveSum : domain()->minY()));
61 89 else
62 topLeft = domain()->calculateGeometryPoint(QPointF(category + barWidth / 2, set ? positiveSum : 0));
90 bottomRight = domain()->calculateGeometryPoint(QPointF(category + barWidth / 2, set ? positiveSum : 0));
63 91 positiveSum += value;
64 92 }
65 93 rect.setTopLeft(topLeft);
66 94 rect.setBottomRight(bottomRight);
67 layout.append(rect);
95 layout.append(rect.normalized());
68 96 }
69 97 }
70 98 return layout;
71 99 }
72 100
73 101 #include "moc_stackedbarchartitem_p.cpp"
74 102
75 103 QTCOMMERCIALCHART_END_NAMESPACE
@@ -1,52 +1,54
1 1 /****************************************************************************
2 2 **
3 3 ** Copyright (C) 2012 Digia Plc
4 4 ** All rights reserved.
5 5 ** For any questions to Digia, please use contact form at http://qt.digia.com
6 6 **
7 7 ** This file is part of the Qt Commercial Charts Add-on.
8 8 **
9 9 ** $QT_BEGIN_LICENSE$
10 10 ** Licensees holding valid Qt Commercial licenses may use this file in
11 11 ** accordance with the Qt Commercial License Agreement provided with the
12 12 ** Software or, alternatively, in accordance with the terms contained in
13 13 ** a written agreement between you and Digia.
14 14 **
15 15 ** If you have questions regarding the use of this file, please use
16 16 ** contact form at http://qt.digia.com
17 17 ** $QT_END_LICENSE$
18 18 **
19 19 ****************************************************************************/
20 20
21 21 // W A R N I N G
22 22 // -------------
23 23 //
24 24 // This file is not part of the QtCommercial Chart API. It exists purely as an
25 25 // implementation detail. This header file may change from version to
26 26 // version without notice, or even be removed.
27 27 //
28 28 // We mean it.
29 29
30 30
31 31 #ifndef STACKEDBARCHARTITEM_H
32 32 #define STACKEDBARCHARTITEM_H
33 33
34 34 #include "abstractbarchartitem_p.h"
35 35 #include "qstackedbarseries.h"
36 36 #include <QGraphicsItem>
37 37
38 38 QTCOMMERCIALCHART_BEGIN_NAMESPACE
39 39
40 40 class StackedBarChartItem : public AbstractBarChartItem
41 41 {
42 42 Q_OBJECT
43 43 public:
44 44 StackedBarChartItem(QAbstractBarSeries *series, QGraphicsItem* item =0);
45 45
46 46 private:
47 47 virtual QVector<QRectF> calculateLayout();
48 void initializeLayout();
49
48 50 };
49 51
50 52 QTCOMMERCIALCHART_END_NAMESPACE
51 53
52 54 #endif // STACKEDBARCHARTITEM_H
1 NO CONTENT: file was removed
1 NO CONTENT: file was removed
1 NO CONTENT: file was removed
1 NO CONTENT: file was removed
1 NO CONTENT: file was removed
1 NO CONTENT: file was removed
1 NO CONTENT: file was removed
1 NO CONTENT: file was removed
1 NO CONTENT: file was removed
1 NO CONTENT: file was removed
1 NO CONTENT: file was removed
1 NO CONTENT: file was removed
General Comments 0
You need to be logged in to leave comments. Login now