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