##// END OF EJS Templates
Bar animations refactored
Marek Rosa -
r2316:74962bdcee07
parent child
Show More
@@ -7,13 +7,7 SOURCES += \
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 \
@@ -22,10 +16,4 PRIVATE_HEADERS += \
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
@@ -27,9 +27,11 Q_DECLARE_METATYPE(QVector<QRectF>)
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()
@@ -47,27 +49,32 QVariant BarAnimation::interpolated(const QVariant &from, const QVariant &to, qr
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
@@ -27,18 +27,16
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
@@ -48,8 +46,14 public:
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
@@ -27,7 +27,7
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
@@ -70,7 +70,13 QRectF AbstractBarChartItem::boundingRect() const
70
70
71 void AbstractBarChartItem::applyLayout(const QVector<QRectF> &layout)
71 void AbstractBarChartItem::applyLayout(const QVector<QRectF> &layout)
72 {
72 {
73 QSizeF size = geometry().size();
74 if (geometry().size().isValid()) {
73 if (m_animation) {
75 if (m_animation) {
76 if (m_layout.count() == 0 || m_oldSize != size) {
77 initializeLayout();
78 m_oldSize = size;
79 }
74 m_animation->setup(m_layout, layout);
80 m_animation->setup(m_layout, layout);
75 presenter()->startAnimation(m_animation);
81 presenter()->startAnimation(m_animation);
76 } else {
82 } else {
@@ -78,8 +84,9 void AbstractBarChartItem::applyLayout(const QVector<QRectF> &layout)
78 update();
84 update();
79 }
85 }
80 }
86 }
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 }
@@ -154,7 +161,7 void AbstractBarChartItem::handleDataStructureChanged()
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));
@@ -41,7 +41,7 QTCOMMERCIALCHART_BEGIN_NAMESPACE
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 {
@@ -55,8 +55,9 public:
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;}
@@ -80,11 +81,12 protected:
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
@@ -30,6 +30,33 HorizontalBarChartItem::HorizontalBarChartItem(QAbstractBarSeries *series, QGrap
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;
@@ -39,27 +66,20 QVector<QRectF> HorizontalBarChartItem::calculateLayout()
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;
@@ -43,6 +43,7 public:
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
@@ -21,7 +21,6
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"
@@ -116,18 +115,6 void QHorizontalBarSeriesPrivate::initializeGraphics(QGraphicsItem* parent)
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
@@ -40,7 +40,6 class QHorizontalBarSeriesPrivate: public QAbstractBarSeriesPrivate
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)
@@ -30,6 +30,33 HorizontalPercentBarChartItem::HorizontalPercentBarChartItem(QAbstractBarSeries
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;
@@ -47,13 +74,13 QVector<QRectF> HorizontalPercentBarChartItem::calculateLayout()
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 }
@@ -44,6 +44,7 public:
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
@@ -20,7 +20,6
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"
@@ -112,17 +111,6 void QHorizontalPercentBarSeriesPrivate::initializeGraphics(QGraphicsItem* paren
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
@@ -40,7 +40,6 class QHorizontalPercentBarSeriesPrivate: public QAbstractBarSeriesPrivate
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)
@@ -30,6 +30,33 HorizontalStackedBarChartItem::HorizontalStackedBarChartItem(QAbstractBarSeries
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;
@@ -64,7 +91,7 QVector<QRectF> HorizontalStackedBarChartItem::calculateLayout()
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;
@@ -43,6 +43,7 public:
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
@@ -20,7 +20,6
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"
@@ -111,17 +110,6 void QHorizontalStackedBarSeriesPrivate::initializeGraphics(QGraphicsItem *paren
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
@@ -40,7 +40,6 class QHorizontalStackedBarSeriesPrivate: public QAbstractBarSeriesPrivate
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)
@@ -28,6 +28,8
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
@@ -853,6 +855,18 void QAbstractBarSeriesPrivate::initializeTheme(int index, ChartTheme* theme, bo
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
@@ -56,6 +56,7 public:
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);
@@ -31,6 +31,34 BarChartItem::BarChartItem(QAbstractBarSeries *series, QGraphicsItem* 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;
@@ -52,7 +80,7 QVector<QRectF> BarChartItem::calculateLayout()
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;
@@ -45,6 +45,7 public:
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
@@ -23,7 +23,6
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
@@ -114,18 +113,6 void QBarSeriesPrivate::initializeGraphics(QGraphicsItem* parent)
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
@@ -41,7 +41,6 class QBarSeriesPrivate: public QAbstractBarSeriesPrivate
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:
@@ -31,6 +31,34 PercentBarChartItem::PercentBarChartItem(QAbstractBarSeries *series, QGraphicsIt
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;
@@ -54,7 +82,7 QVector<QRectF> PercentBarChartItem::calculateLayout()
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 }
@@ -47,6 +47,7 public:
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
@@ -24,7 +24,6
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
@@ -113,17 +112,6 void QPercentBarSeriesPrivate::initializeGraphics(QGraphicsItem* parent)
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
@@ -42,7 +42,6 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 };
@@ -24,7 +24,6
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
@@ -112,17 +111,6 void QStackedBarSeriesPrivate::initializeGraphics(QGraphicsItem* parent)
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
@@ -41,7 +41,6 class QStackedBarSeriesPrivate: public QAbstractBarSeriesPrivate
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)
@@ -31,6 +31,34 StackedBarChartItem::StackedBarChartItem(QAbstractBarSeries *series, QGraphicsIt
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;
@@ -55,16 +83,16 QVector<QRectF> StackedBarChartItem::calculateLayout()
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;
@@ -45,6 +45,8 public:
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
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