##// END OF EJS Templates
horizontal percent barchart & example
sauimone -
r1688:daa1eadf0e06
parent child
Show More
@@ -0,0 +1,6
1 !include( ../examples.pri ) {
2 error( "Couldn't find the examples.pri file!" )
3 }
4
5 TARGET = horizontalpercentbarchart
6 SOURCES += main.cpp
@@ -0,0 +1,95
1 /****************************************************************************
2 **
3 ** Copyright (C) 2012 Digia Plc
4 ** All rights reserved.
5 ** For any questions to Digia, please use contact form at http://qt.digia.com
6 **
7 ** This file is part of the Qt Commercial Charts Add-on.
8 **
9 ** $QT_BEGIN_LICENSE$
10 ** Licensees holding valid Qt Commercial licenses may use this file in
11 ** accordance with the Qt Commercial License Agreement provided with the
12 ** Software or, alternatively, in accordance with the terms contained in
13 ** a written agreement between you and Digia.
14 **
15 ** If you have questions regarding the use of this file, please use
16 ** contact form at http://qt.digia.com
17 ** $QT_END_LICENSE$
18 **
19 ****************************************************************************/
20
21 #include <QApplication>
22 #include <QMainWindow>
23 #include <QChartView>
24 #include <QBarSeries>
25 #include <QBarSet>
26 #include <QLegend>
27 #include <QBarCategoriesAxis>
28 #include <QHorizontalPercentBarSeries>
29
30 QTCOMMERCIALCHART_USE_NAMESPACE
31
32 int main(int argc, char *argv[])
33 {
34 QApplication a(argc, argv);
35
36 //![1]
37 QBarSet *set0 = new QBarSet("Jane");
38 QBarSet *set1 = new QBarSet("John");
39 QBarSet *set2 = new QBarSet("Axel");
40 QBarSet *set3 = new QBarSet("Mary");
41 QBarSet *set4 = new QBarSet("Samantha");
42
43 *set0 << 1 << 2 << 3 << 4 << 5 << 6;
44 *set1 << 5 << 0 << 0 << 4 << 0 << 7;
45 *set2 << 3 << 5 << 8 << 13 << 8 << 5;
46 *set3 << 5 << 6 << 7 << 3 << 4 << 5;
47 *set4 << 9 << 7 << 5 << 3 << 1 << 2;
48 //![1]
49
50 //![2]
51 QHorizontalPercentBarSeries *series = new QHorizontalPercentBarSeries();
52 series->append(set0);
53 series->append(set1);
54 series->append(set2);
55 series->append(set3);
56 series->append(set4);
57
58 //![2]
59
60 //![3]
61 QChart* chart = new QChart();
62 chart->addSeries(series);
63 chart->setTitle("Simple horizontal stacked barchart example");
64 chart->createDefaultAxes();
65 chart->setAnimationOptions(QChart::SeriesAnimations);
66 //![3]
67
68 //![4]
69 QStringList categories;
70 categories << "Jan" << "Feb" << "Mar" << "Apr" << "May" << "Jun";
71 QBarCategoriesAxis* axis = new QBarCategoriesAxis();
72 axis->append(categories);
73 chart->createDefaultAxes();
74 chart->setAxisY(axis,series);
75 //![4]
76
77 //![5]
78 chart->legend()->setVisible(true);
79 chart->legend()->setAlignment(Qt::AlignBottom);
80 //![5]
81
82 //![6]
83 QChartView* chartView = new QChartView(chart);
84 chartView->setRenderHint(QPainter::Antialiasing);
85 //![6]
86
87 //![7]
88 QMainWindow window;
89 window.setCentralWidget(chartView);
90 window.resize(400, 300);
91 window.show();
92 //![7]
93
94 return a.exec();
95 }
@@ -0,0 +1,64
1 /****************************************************************************
2 **
3 ** Copyright (C) 2012 Digia Plc
4 ** All rights reserved.
5 ** For any questions to Digia, please use contact form at http://qt.digia.com
6 **
7 ** This file is part of the Qt Commercial Charts Add-on.
8 **
9 ** $QT_BEGIN_LICENSE$
10 ** Licensees holding valid Qt Commercial licenses may use this file in
11 ** accordance with the Qt Commercial License Agreement provided with the
12 ** Software or, alternatively, in accordance with the terms contained in
13 ** a written agreement between you and Digia.
14 **
15 ** If you have questions regarding the use of this file, please use
16 ** contact form at http://qt.digia.com
17 ** $QT_END_LICENSE$
18 **
19 ****************************************************************************/
20
21 #include "horizontalpercentbaranimation_p.h"
22 #include "abstractbarchartitem_p.h"
23 #include <QTimer>
24
25 Q_DECLARE_METATYPE(QVector<QRectF>)
26
27 QTCOMMERCIALCHART_BEGIN_NAMESPACE
28
29 HorizontalPercentBarAnimation::HorizontalPercentBarAnimation(AbstractBarChartItem *item) :
30 AbstractBarAnimation(item)
31 {
32 }
33
34 HorizontalPercentBarAnimation::~HorizontalPercentBarAnimation()
35 {
36
37 }
38
39
40 QVariant HorizontalPercentBarAnimation::interpolated(const QVariant &from, const QVariant &to, qreal progress) const
41 {
42 QVector<QRectF> startVector = qVariantValue<QVector<QRectF> >(from);
43 QVector<QRectF> endVector = qVariantValue<QVector<QRectF> >(to);
44 QVector<QRectF> result;
45
46 Q_ASSERT(startVector.count() == endVector.count());
47
48 qreal xAxis = m_item->geometry().x();
49
50 for(int i = 0; i < startVector.count(); i++) {
51 qreal h = endVector[i].height();
52 qreal w = endVector[i].width() * progress;
53 qreal x = xAxis + ((endVector[i].left() - xAxis) * progress);
54 qreal y = endVector[i].top();
55
56 QRectF value(x,y,w,h);
57 result << value;
58 }
59 return qVariantFromValue(result);
60 }
61
62 #include "moc_horizontalpercentbaranimation_p.cpp"
63
64 QTCOMMERCIALCHART_END_NAMESPACE
@@ -0,0 +1,52
1 /****************************************************************************
2 **
3 ** Copyright (C) 2012 Digia Plc
4 ** All rights reserved.
5 ** For any questions to Digia, please use contact form at http://qt.digia.com
6 **
7 ** This file is part of the Qt Commercial Charts Add-on.
8 **
9 ** $QT_BEGIN_LICENSE$
10 ** Licensees holding valid Qt Commercial licenses may use this file in
11 ** accordance with the Qt Commercial License Agreement provided with the
12 ** Software or, alternatively, in accordance with the terms contained in
13 ** a written agreement between you and Digia.
14 **
15 ** If you have questions regarding the use of this file, please use
16 ** contact form at http://qt.digia.com
17 ** $QT_END_LICENSE$
18 **
19 ****************************************************************************/
20
21 // W A R N I N G
22 // -------------
23 //
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
26 // version without notice, or even be removed.
27 //
28 // We mean it.
29
30 #ifndef HORIZONTALPERCENTBARANIMATION_P_H
31 #define HORIZONTALPERCENTBARANIMATION_P_H
32
33 #include "abstractbaranimation_p.h"
34 #include "chartanimation_p.h"
35 #include "abstractbarchartitem_p.h"
36
37 QTCOMMERCIALCHART_BEGIN_NAMESPACE
38
39 class HorizontalPercentBarAnimation : public AbstractBarAnimation
40 {
41 Q_OBJECT
42 public:
43 explicit HorizontalPercentBarAnimation(AbstractBarChartItem *item);
44 ~HorizontalPercentBarAnimation();
45
46 virtual QVariant interpolated(const QVariant &from, const QVariant &to, qreal progress) const;
47
48 };
49
50 QTCOMMERCIALCHART_END_NAMESPACE
51
52 #endif // HORIZONTALPERCENTBARANIMATION_P_H
@@ -0,0 +1,102
1 /****************************************************************************
2 **
3 ** Copyright (C) 2012 Digia Plc
4 ** All rights reserved.
5 ** For any questions to Digia, please use contact form at http://qt.digia.com
6 **
7 ** This file is part of the Qt Commercial Charts Add-on.
8 **
9 ** $QT_BEGIN_LICENSE$
10 ** Licensees holding valid Qt Commercial licenses may use this file in
11 ** accordance with the Qt Commercial License Agreement provided with the
12 ** Software or, alternatively, in accordance with the terms contained in
13 ** a written agreement between you and Digia.
14 **
15 ** If you have questions regarding the use of this file, please use
16 ** contact form at http://qt.digia.com
17 ** $QT_END_LICENSE$
18 **
19 ****************************************************************************/
20
21 #include "horizontalpercentbarchartitem_p.h"
22 #include "qabstractbarseries_p.h"
23 #include "qbarset_p.h"
24 #include "bar_p.h"
25 #include <QDebug>
26
27 QTCOMMERCIALCHART_BEGIN_NAMESPACE
28
29 HorizontalPercentBarChartItem::HorizontalPercentBarChartItem(QAbstractBarSeries *series, ChartPresenter *presenter) :
30 AbstractBarChartItem(series, presenter)
31 {
32 }
33
34 QVector<QRectF> HorizontalPercentBarChartItem::calculateLayout()
35 {
36 QVector<QRectF> layout;
37
38 // Use temporary qreals for accuracy
39 qreal categoryCount = m_series->d_func()->categoryCount();
40 qreal setCount = m_series->count();
41 bool barsVisible = m_series->isVisible();
42
43 // Domain:
44 qreal width = geometry().width();
45 qreal height = geometry().height();
46 qreal rangeY = m_domainMaxY - m_domainMinY;
47 qreal rangeX = m_domainMaxX - m_domainMinX;
48 qreal scaleY = (height / rangeY);
49 qreal scaleX = (width / rangeX);
50 qreal barHeight = scaleY * m_series->d_func()->barWidth(); // On horizontal chart barWidth of the barseries means height of the rect.
51
52 int itemIndex(0);
53 for (int category = 0; category < categoryCount; category++) {
54 qreal colSum = m_series->d_func()->categorySum(category);
55 qreal percentage = (100 / colSum);
56 qreal xPos = rangeX * m_domainMinX + geometry().left();
57 for (int set = 0; set < setCount; set++) {
58 QBarSetPrivate* barSet = m_series->d_func()->barsetAt(set)->d_ptr.data();
59
60 qreal yPos = -(barSet->pos(category) - m_domainMinY -0.5) * scaleY + m_rect.bottom() - barHeight/2;
61
62 qreal barWidth = barSet->value(category) * percentage * scaleX;
63 Bar* bar = m_bars.at(itemIndex);
64
65 QRectF rect(xPos, yPos - barHeight, barWidth, barHeight);
66 layout.append(rect);
67 bar->setPen(barSet->m_pen);
68 bar->setBrush(barSet->m_brush);
69 if (qFuzzyIsNull(barHeight)) {
70 bar->setVisible(false);
71 } else {
72 bar->setVisible(barsVisible);
73 }
74
75 QGraphicsSimpleTextItem* label = m_labels.at(itemIndex);
76
77 if (!qFuzzyIsNull(m_series->d_func()->valueAt(set,category))) {
78 int p = m_series->d_func()->percentageAt(set,category) * 100;
79 QString vString(QString::number(p));
80 vString.truncate(3);
81 vString.append("%");
82 label->setText(vString);
83 } else {
84 label->setText(QString(""));
85 }
86
87 label->setPos(xPos + (rect.width()/2 - label->boundingRect().width()/2)
88 ,yPos - barHeight/2 - label->boundingRect().height()/2);
89 label->setFont(barSet->m_labelFont);
90 label->setBrush(barSet->m_labelBrush);
91
92 itemIndex++;
93 xPos += barWidth;
94 }
95 }
96 return layout;
97 }
98
99 #include "moc_horizontalpercentbarchartitem_p.cpp"
100
101 QTCOMMERCIALCHART_END_NAMESPACE
102
@@ -0,0 +1,50
1 /****************************************************************************
2 **
3 ** Copyright (C) 2012 Digia Plc
4 ** All rights reserved.
5 ** For any questions to Digia, please use contact form at http://qt.digia.com
6 **
7 ** This file is part of the Qt Commercial Charts Add-on.
8 **
9 ** $QT_BEGIN_LICENSE$
10 ** Licensees holding valid Qt Commercial licenses may use this file in
11 ** accordance with the Qt Commercial License Agreement provided with the
12 ** Software or, alternatively, in accordance with the terms contained in
13 ** a written agreement between you and Digia.
14 **
15 ** If you have questions regarding the use of this file, please use
16 ** contact form at http://qt.digia.com
17 ** $QT_END_LICENSE$
18 **
19 ****************************************************************************/
20
21 // W A R N I N G
22 // -------------
23 //
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
26 // version without notice, or even be removed.
27 //
28 // We mean it.
29
30 #ifndef HORIZONTALPERCENTBARCHARTITEM_P_H
31 #define HORIZONTALPERCENTBARCHARTITEM_P_H
32
33 #include "abstractbarchartitem_p.h"
34 #include <QGraphicsItem>
35
36 QTCOMMERCIALCHART_BEGIN_NAMESPACE
37
38 class HorizontalPercentBarChartItem : public AbstractBarChartItem
39 {
40 Q_OBJECT
41 public:
42 HorizontalPercentBarChartItem(QAbstractBarSeries *series, ChartPresenter *presenter);
43
44 private:
45 virtual QVector<QRectF> calculateLayout();
46 };
47
48 QTCOMMERCIALCHART_END_NAMESPACE
49
50 #endif // HORIZONTALPERCENTBARCHARTITEM_P_H
@@ -0,0 +1,75
1 #include "qhorizontalpercentbarseries.h"
2 #include "qhorizontalpercentbarseries_p.h"
3 #include "horizontalpercentbarchartitem_p.h"
4 #include "horizontalpercentbaranimation_p.h"
5
6 #include "chartdataset_p.h"
7 #include "charttheme_p.h"
8
9 QTCOMMERCIALCHART_BEGIN_NAMESPACE
10
11 QHorizontalPercentBarSeries::QHorizontalPercentBarSeries(QObject *parent) :
12 QAbstractBarSeries(*new QHorizontalPercentBarSeriesPrivate(this), parent)
13 {
14 }
15
16 QAbstractSeries::SeriesType QHorizontalPercentBarSeries::type() const
17 {
18 return QAbstractSeries::SeriesTypeHorizontalPercentBar;
19 }
20
21
22
23 ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
24
25 QHorizontalPercentBarSeriesPrivate::QHorizontalPercentBarSeriesPrivate(QHorizontalPercentBarSeries *q) : QAbstractBarSeriesPrivate(q)
26 {
27
28 }
29
30 void QHorizontalPercentBarSeriesPrivate::scaleDomain(Domain& domain)
31 {
32 qreal minX(domain.minX());
33 qreal minY(domain.minY());
34 qreal maxX(domain.maxX());
35 qreal maxY(domain.maxY());
36 int tickXCount(domain.tickXCount());
37 int tickYCount(domain.tickYCount());
38
39 qreal y = categoryCount();
40 minX = 0;
41 maxX = 100;
42 minY = qMin(minY, - (qreal)0.5);
43 maxY = qMax(maxY, y - (qreal)0.5);
44 tickYCount = y+1;
45
46 domain.setRange(minX,maxX,minY,maxY,tickXCount,tickYCount);
47 }
48
49 Chart* QHorizontalPercentBarSeriesPrivate::createGraphics(ChartPresenter* presenter)
50 {
51 Q_Q(QHorizontalPercentBarSeries);
52
53 HorizontalPercentBarChartItem* bar = new HorizontalPercentBarChartItem(q,presenter);
54 if(presenter->animationOptions().testFlag(QChart::SeriesAnimations)) {
55 bar->setAnimator(presenter->animator());
56 bar->setAnimation(new HorizontalPercentBarAnimation(bar));
57 }
58 presenter->chartTheme()->decorate(q, presenter->dataSet()->seriesIndex(q));
59 return bar;
60 }
61
62 QAbstractAxis::AxisType QHorizontalPercentBarSeriesPrivate::defaultAxisXType() const
63 {
64 return QAbstractAxis::AxisTypeValues;
65 }
66
67 QAbstractAxis::AxisType QHorizontalPercentBarSeriesPrivate::defaultAxisYType() const
68 {
69 return QAbstractAxis::AxisTypeCategories;
70 }
71
72
73 #include "moc_qhorizontalpercentbarseries.cpp"
74
75 QTCOMMERCIALCHART_END_NAMESPACE
@@ -0,0 +1,44
1 /****************************************************************************
2 **
3 ** Copyright (C) 2012 Digia Plc
4 ** All rights reserved.
5 ** For any questions to Digia, please use contact form at http://qt.digia.com
6 **
7 ** This file is part of the Qt Commercial Charts Add-on.
8 **
9 ** $QT_BEGIN_LICENSE$
10 ** Licensees holding valid Qt Commercial licenses may use this file in
11 ** accordance with the Qt Commercial License Agreement provided with the
12 ** Software or, alternatively, in accordance with the terms contained in
13 ** a written agreement between you and Digia.
14 **
15 ** If you have questions regarding the use of this file, please use
16 ** contact form at http://qt.digia.com
17 ** $QT_END_LICENSE$
18 **
19 ****************************************************************************/
20
21 #ifndef QHORIZONTALPERCENTBARSERIES_H
22 #define QHORIZONTALPERCENTBARSERIES_H
23
24 #include <qabstractbarseries.h>
25
26 QTCOMMERCIALCHART_BEGIN_NAMESPACE
27
28 class QHorizontalPercentBarSeriesPrivate;
29
30 class QTCOMMERCIALCHART_EXPORT QHorizontalPercentBarSeries : public QAbstractBarSeries
31 {
32 Q_OBJECT
33 public:
34 explicit QHorizontalPercentBarSeries(QObject *parent = 0);
35 QAbstractSeries::SeriesType type() const;
36
37 private:
38 Q_DECLARE_PRIVATE(QHorizontalPercentBarSeries)
39 Q_DISABLE_COPY(QHorizontalPercentBarSeries)
40 };
41
42 QTCOMMERCIALCHART_END_NAMESPACE
43
44 #endif // QHORIZONTALPERCENTBARSERIES_H
@@ -0,0 +1,53
1 /****************************************************************************
2 **
3 ** Copyright (C) 2012 Digia Plc
4 ** All rights reserved.
5 ** For any questions to Digia, please use contact form at http://qt.digia.com
6 **
7 ** This file is part of the Qt Commercial Charts Add-on.
8 **
9 ** $QT_BEGIN_LICENSE$
10 ** Licensees holding valid Qt Commercial licenses may use this file in
11 ** accordance with the Qt Commercial License Agreement provided with the
12 ** Software or, alternatively, in accordance with the terms contained in
13 ** a written agreement between you and Digia.
14 **
15 ** If you have questions regarding the use of this file, please use
16 ** contact form at http://qt.digia.com
17 ** $QT_END_LICENSE$
18 **
19 ****************************************************************************/
20
21 // W A R N I N G
22 // -------------
23 //
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
26 // version without notice, or even be removed.
27 //
28 // We mean it.
29
30 #ifndef QHORIZONTALPERCENTBARSERIES_P_H
31 #define QHORIZONTALPERCENTBARSERIES_P_H
32
33 #include "qabstractbarseries_p.h"
34 #include "domain_p.h"
35
36 QTCOMMERCIALCHART_BEGIN_NAMESPACE
37
38 class QHorizontalPercentBarSeriesPrivate: public QAbstractBarSeriesPrivate
39 {
40 public:
41 QHorizontalPercentBarSeriesPrivate(QHorizontalPercentBarSeries* q);
42 Chart* createGraphics(ChartPresenter* presenter);
43 void scaleDomain(Domain& domain);
44 QAbstractAxis::AxisType defaultAxisXType() const;
45 QAbstractAxis::AxisType defaultAxisYType() const;
46
47 private:
48 Q_DECLARE_PUBLIC(QHorizontalPercentBarSeries)
49 };
50
51 QTCOMMERCIALCHART_END_NAMESPACE
52
53 #endif // QHORIZONTALPERCENTBARSERIES_P_H
@@ -1,28 +1,29
1 1 CURRENTLY_BUILDING_COMPONENTS = "examples"
2 2 !include( ../config.pri ) {
3 3 error( "Couldn't find the config.pri file!" )
4 4 }
5 5
6 6 TEMPLATE = subdirs
7 7 SUBDIRS += \
8 8 areachart \
9 9 customchart \
10 10 linechart \
11 11 percentbarchart \
12 12 piechart \
13 13 piechartdrilldown \
14 14 presenterchart \
15 15 scatterchart \
16 16 scatterinteractions \
17 17 splinechart \
18 18 stackedbarchart \
19 19 stackedbarchartdrilldown \
20 20 zoomlinechart \
21 21 modeldata \
22 22 barchart \
23 23 legend \
24 24 barmodelmapper \
25 25 qmlpiechart \
26 26 lineandbar \
27 27 horizontalbarchart \
28 horizontalstackedbarchart
28 horizontalstackedbarchart \
29 horizontalpercentbarchart
@@ -1,32 +1,33
1 1 INCLUDEPATH += $$PWD
2 2 DEPENDPATH += $$PWD
3 3
4 4 SOURCES += \
5 5 $$PWD/axisanimation.cpp \
6 6 $$PWD/chartanimator.cpp \
7 7 $$PWD/xyanimation.cpp \
8 8 $$PWD/pieanimation.cpp \
9 9 $$PWD/piesliceanimation.cpp \
10 10 $$PWD/splineanimation.cpp \
11 11 $$PWD/baranimation.cpp \
12 12 $$PWD/stackedbaranimation.cpp \
13 13 $$PWD/percentbaranimation.cpp \
14 14 $$PWD/abstractbaranimation.cpp \
15 15 $$PWD/horizontalbaranimation.cpp \
16 $$PWD/horizontalstackedbaranimation.cpp
17
16 $$PWD/horizontalstackedbaranimation.cpp \
17 $$PWD/horizontalpercentbaranimation.cpp
18 18
19 19 PRIVATE_HEADERS += \
20 20 $$PWD/axisanimation_p.h \
21 21 $$PWD/chartanimator_p.h \
22 22 $$PWD/chartanimation_p.h \
23 23 $$PWD/xyanimation_p.h \
24 24 $$PWD/pieanimation_p.h \
25 25 $$PWD/piesliceanimation_p.h \
26 26 $$PWD/splineanimation_p.h \
27 27 $$PWD/baranimation_p.h \
28 28 $$PWD/stackedbaranimation_p.h \
29 29 $$PWD/percentbaranimation_p.h \
30 30 $$PWD/abstractbaranimation_p.h \
31 31 $$PWD/horizontalbaranimation_p.h \
32 $$PWD/horizontalstackedbaranimation_p.h
32 $$PWD/horizontalstackedbaranimation_p.h \
33 $$PWD/horizontalpercentbaranimation_p.h
@@ -1,64 +1,64
1 1 /****************************************************************************
2 2 **
3 3 ** Copyright (C) 2012 Digia Plc
4 4 ** All rights reserved.
5 5 ** For any questions to Digia, please use contact form at http://qt.digia.com
6 6 **
7 7 ** This file is part of the Qt Commercial Charts Add-on.
8 8 **
9 9 ** $QT_BEGIN_LICENSE$
10 10 ** Licensees holding valid Qt Commercial licenses may use this file in
11 11 ** accordance with the Qt Commercial License Agreement provided with the
12 12 ** Software or, alternatively, in accordance with the terms contained in
13 13 ** a written agreement between you and Digia.
14 14 **
15 15 ** If you have questions regarding the use of this file, please use
16 16 ** contact form at http://qt.digia.com
17 17 ** $QT_END_LICENSE$
18 18 **
19 19 ****************************************************************************/
20 20
21 21 #include "horizontalstackedbaranimation_p.h"
22 22 #include "abstractbarchartitem_p.h"
23 23 #include <QTimer>
24 24
25 25 Q_DECLARE_METATYPE(QVector<QRectF>)
26 26
27 27 QTCOMMERCIALCHART_BEGIN_NAMESPACE
28 28
29 29 HorizontalStackedBarAnimation::HorizontalStackedBarAnimation(AbstractBarChartItem *item) :
30 30 AbstractBarAnimation(item)
31 31 {
32 32 }
33 33
34 34 HorizontalStackedBarAnimation::~HorizontalStackedBarAnimation()
35 35 {
36 36
37 37 }
38 38
39 39
40 40 QVariant HorizontalStackedBarAnimation::interpolated(const QVariant &from, const QVariant &to, qreal progress) const
41 41 {
42 42 QVector<QRectF> startVector = qVariantValue<QVector<QRectF> >(from);
43 43 QVector<QRectF> endVector = qVariantValue<QVector<QRectF> >(to);
44 44 QVector<QRectF> result;
45 45
46 46 Q_ASSERT(startVector.count() == endVector.count());
47 47
48 48 qreal xAxis = m_item->geometry().x();
49 49
50 50 for(int i = 0; i < startVector.count(); i++) {
51 51 qreal h = endVector[i].height();
52 qreal w = startVector[i].width() + ((endVector[i].width() - startVector[i].width()) * progress);
52 qreal w = endVector[i].width() * progress;
53 53 qreal x = xAxis + ((endVector[i].left() - xAxis) * progress);
54 54 qreal y = endVector[i].top();
55 55
56 56 QRectF value(x,y,w,h);
57 57 result << value;
58 58 }
59 59 return qVariantFromValue(result);
60 60 }
61 61
62 62 #include "moc_horizontalstackedbaranimation_p.cpp"
63 63
64 64 QTCOMMERCIALCHART_END_NAMESPACE
@@ -1,50 +1,55
1 1 INCLUDEPATH += $$PWD
2 2 DEPENDPATH += $$PWD
3 3
4 4 SOURCES += \
5 5 $$PWD/bar.cpp \
6 6 $$PWD/abstractbarchartitem.cpp \
7 7 $$PWD/percentbarchartitem.cpp \
8 8 $$PWD/barchartitem.cpp \
9 9 $$PWD/qabstractbarseries.cpp \
10 10 $$PWD/qbarset.cpp \
11 11 $$PWD/qpercentbarseries.cpp \
12 12 $$PWD/qstackedbarseries.cpp \
13 13 $$PWD/qbarseries.cpp \
14 14 $$PWD/stackedbarchartitem.cpp \
15 15 $$PWD/qbarmodelmapper.cpp \
16 16 $$PWD/qvbarmodelmapper.cpp \
17 17 $$PWD/qhbarmodelmapper.cpp \
18 18 $$PWD/qhorizontalbarseries.cpp \
19 19 $$PWD/horizontalbarchartitem.cpp \
20 20 $$PWD/qhorizontalstackedbarseries.cpp \
21 $$PWD/horizontalstackedbarchartitem.cpp
21 $$PWD/horizontalstackedbarchartitem.cpp \
22 $$PWD/qhorizontalpercentbarseries.cpp \
23 $$PWD/horizontalpercentbarchartitem.cpp
22 24
23 25 PRIVATE_HEADERS += \
24 26 $$PWD/bar_p.h \
25 27 $$PWD/abstractbarchartitem_p.h \
26 28 $$PWD/percentbarchartitem_p.h \
27 29 $$PWD/stackedbarchartitem_p.h \
28 30 $$PWD/barchartitem_p.h \
29 31 $$PWD/qbarset_p.h \
30 32 $$PWD/qabstractbarseries_p.h \
31 33 $$PWD/qstackedbarseries_p.h\
32 34 $$PWD/qpercentbarseries_p.h \
33 35 $$PWD/qbarseries_p.h \
34 36 $$PWD/qbarmodelmapper_p.h \
35 37 $$PWD/qhorizontalbarseries_p.h \
36 38 $$PWD/horizontalbarchartitem_p.h \
37 39 $$PWD/qhorizontalstackedbarseries_p.h \
38 $$PWD/horizontalstackedbarchartitem_p.h
40 $$PWD/horizontalstackedbarchartitem_p.h \
41 $$PWD/qhorizontalpercentbarseries_p.h \
42 $$PWD/horizontalpercentbarchartitem_p.h
39 43
40 44 PUBLIC_HEADERS += \
41 45 $$PWD/qabstractbarseries.h \
42 46 $$PWD/qbarset.h \
43 47 $$PWD/qpercentbarseries.h \
44 48 $$PWD/qstackedbarseries.h \
45 49 $$PWD/qbarseries.h \
46 50 $$PWD/qbarmodelmapper.h \
47 51 $$PWD/qvbarmodelmapper.h \
48 52 $$PWD/qhbarmodelmapper.h \
49 53 $$PWD/qhorizontalbarseries.h \
50 $$PWD/qhorizontalstackedbarseries.h
54 $$PWD/qhorizontalstackedbarseries.h \
55 $$PWD/qhorizontalpercentbarseries.h
@@ -1,84 +1,85
1 1 /****************************************************************************
2 2 **
3 3 ** Copyright (C) 2012 Digia Plc
4 4 ** All rights reserved.
5 5 ** For any questions to Digia, please use contact form at http://qt.digia.com
6 6 **
7 7 ** This file is part of the Qt Commercial Charts Add-on.
8 8 **
9 9 ** $QT_BEGIN_LICENSE$
10 10 ** Licensees holding valid Qt Commercial licenses may use this file in
11 11 ** accordance with the Qt Commercial License Agreement provided with the
12 12 ** Software or, alternatively, in accordance with the terms contained in
13 13 ** a written agreement between you and Digia.
14 14 **
15 15 ** If you have questions regarding the use of this file, please use
16 16 ** contact form at http://qt.digia.com
17 17 ** $QT_END_LICENSE$
18 18 **
19 19 ****************************************************************************/
20 20
21 21 #ifndef ABSTRACTBARSERIES_H
22 22 #define ABSTRACTBARSERIES_H
23 23
24 24 #include <qabstractseries.h>
25 25 #include <QStringList>
26 26
27 27 QTCOMMERCIALCHART_BEGIN_NAMESPACE
28 28
29 29 class QBarSet;
30 30 class QAbstractBarSeriesPrivate;
31 31
32 32 // Container for series
33 33 class QTCOMMERCIALCHART_EXPORT QAbstractBarSeries : public QAbstractSeries
34 34 {
35 35 Q_OBJECT
36 36 Q_PROPERTY(qreal barWidth READ barWidth WRITE setBarWidth)
37 37 Q_PROPERTY(int count READ count NOTIFY countChanged)
38 38 Q_PROPERTY(bool labelsVisible READ isLabelsVisible WRITE setLabelsVisible NOTIFY labelsVisibleChanged)
39 39
40 40 protected:
41 41 explicit QAbstractBarSeries(QObject *parent = 0);
42 42
43 43 public:
44 44 virtual ~QAbstractBarSeries();
45 45
46 46 void setBarWidth(qreal width);
47 47 qreal barWidth() const;
48 48
49 49 bool append(QBarSet *set);
50 50 bool remove(QBarSet *set);
51 51 bool append(QList<QBarSet* > sets);
52 52 bool insert(int index, QBarSet *set);
53 53 int count() const;
54 54 QList<QBarSet*> barSets() const;
55 55 void clear();
56 56
57 57 void setLabelsVisible(bool visible = true);
58 58 bool isLabelsVisible() const;
59 59
60 60 protected:
61 61 explicit QAbstractBarSeries(QAbstractBarSeriesPrivate &d,QObject *parent = 0);
62 62
63 63 Q_SIGNALS:
64 64 void clicked(int index, QBarSet *barset);
65 65 void hovered(bool status, QBarSet *barset);
66 66 void countChanged();
67 67 void labelsVisibleChanged();
68 68
69 69 void barsetsAdded(QList<QBarSet*> sets);
70 70 void barsetsRemoved(QList<QBarSet*> sets);
71 71
72 72 protected:
73 73 Q_DECLARE_PRIVATE(QAbstractBarSeries)
74 74 friend class AbstractBarChartItem;
75 75 friend class PercentBarChartItem;
76 76 friend class StackedBarChartItem;
77 77 friend class BarChartItem;
78 78 friend class HorizontalBarChartItem;
79 79 friend class HorizontalStackedBarChartItem;
80 friend class HorizontalPercentBarChartItem;
80 81 };
81 82
82 83 QTCOMMERCIALCHART_END_NAMESPACE
83 84
84 85 #endif // ABSTRACTBARSERIES_H
@@ -1,117 +1,118
1 1 /****************************************************************************
2 2 **
3 3 ** Copyright (C) 2012 Digia Plc
4 4 ** All rights reserved.
5 5 ** For any questions to Digia, please use contact form at http://qt.digia.com
6 6 **
7 7 ** This file is part of the Qt Commercial Charts Add-on.
8 8 **
9 9 ** $QT_BEGIN_LICENSE$
10 10 ** Licensees holding valid Qt Commercial licenses may use this file in
11 11 ** accordance with the Qt Commercial License Agreement provided with the
12 12 ** Software or, alternatively, in accordance with the terms contained in
13 13 ** a written agreement between you and Digia.
14 14 **
15 15 ** If you have questions regarding the use of this file, please use
16 16 ** contact form at http://qt.digia.com
17 17 ** $QT_END_LICENSE$
18 18 **
19 19 ****************************************************************************/
20 20
21 21 #ifndef QBARSET_H
22 22 #define QBARSET_H
23 23
24 24 #include <qchartglobal.h>
25 25 #include <QPen>
26 26 #include <QBrush>
27 27 #include <QFont>
28 28
29 29 QTCOMMERCIALCHART_BEGIN_NAMESPACE
30 30 class QBarSetPrivate;
31 31
32 32 class QTCOMMERCIALCHART_EXPORT QBarSet : public QObject
33 33 {
34 34 Q_OBJECT
35 35 Q_PROPERTY(QString label READ label WRITE setLabel NOTIFY labelChanged)
36 36 Q_PROPERTY(QPen pen READ pen WRITE setPen NOTIFY penChanged)
37 37 Q_PROPERTY(QBrush brush READ brush WRITE setBrush NOTIFY brushChanged)
38 38 Q_PROPERTY(QBrush labelBrush READ labelBrush WRITE setLabelBrush NOTIFY labelBrushChanged)
39 39 Q_PROPERTY(QFont labelFont READ labelFont WRITE setLabelFont NOTIFY labelFontChanged)
40 40 Q_PROPERTY(QColor color READ color WRITE setColor NOTIFY colorChanged)
41 41 Q_PROPERTY(QColor borderColor READ borderColor WRITE setBorderColor NOTIFY borderColorChanged)
42 42 Q_PROPERTY(QColor labelColor READ labelColor WRITE setLabelColor NOTIFY labelColorChanged)
43 43
44 44 public:
45 45 explicit QBarSet(const QString label, QObject *parent = 0);
46 46 virtual ~QBarSet();
47 47
48 48 void setLabel(const QString label);
49 49 QString label() const;
50 50
51 51 void append(const qreal value);
52 52 void append(const QList<qreal> &values);
53 53
54 54 QBarSet& operator << (const qreal &value);
55 55
56 56 void insert(const int index, const qreal value);
57 57 void remove(const int index, const int count = 1);
58 58 void replace(const int index, const qreal value);
59 59 qreal at(const int index) const;
60 60 qreal operator [] (const int index) const;
61 61 int count() const;
62 62 qreal sum() const;
63 63
64 64 void setPen(const QPen &pen);
65 65 QPen pen() const;
66 66
67 67 void setBrush(const QBrush &brush);
68 68 QBrush brush() const;
69 69
70 70 void setLabelBrush(const QBrush &brush);
71 71 QBrush labelBrush() const;
72 72
73 73 void setLabelFont(const QFont &font);
74 74 QFont labelFont() const;
75 75
76 76 QColor color();
77 77 void setColor(QColor color);
78 78
79 79 QColor borderColor();
80 80 void setBorderColor(QColor color);
81 81
82 82 QColor labelColor();
83 83 void setLabelColor(QColor color);
84 84
85 85 Q_SIGNALS:
86 86 void clicked(int index);
87 87 void hovered(bool status);
88 88 void penChanged();
89 89 void brushChanged();
90 90 void labelChanged();
91 91 void labelBrushChanged();
92 92 void labelFontChanged();
93 93 void colorChanged(QColor color);
94 94 void borderColorChanged(QColor color);
95 95 void labelColorChanged(QColor color);
96 96
97 97 void valuesAdded(int index, int count);
98 98 void valuesRemoved(int index, int count);
99 99 void valueChanged(int index);
100 100
101 101 private:
102 102 QScopedPointer<QBarSetPrivate> d_ptr;
103 103 Q_DISABLE_COPY(QBarSet)
104 104 friend class QAbstractBarSeries;
105 105 friend class BarLegendMarker;
106 106 friend class AbstractBarChartItem;
107 107 friend class QAbstractBarSeriesPrivate;
108 108 friend class StackedBarChartItem;
109 109 friend class PercentBarChartItem;
110 110 friend class BarChartItem;
111 111 friend class HorizontalBarChartItem;
112 112 friend class HorizontalStackedBarChartItem;
113 friend class HorizontalPercentBarChartItem;
113 114 };
114 115
115 116 QTCOMMERCIALCHART_END_NAMESPACE
116 117
117 118 #endif // QBARSET_H
@@ -1,78 +1,78
1 1 #include "qhorizontalbarseries.h"
2 2 #include "qhorizontalbarseries_p.h"
3 3 #include "horizontalbarchartitem_p.h"
4 4 #include "horizontalbaranimation_p.h"
5 5
6 6 #include "chartdataset_p.h"
7 7 #include "charttheme_p.h"
8 8
9 9
10 10 QTCOMMERCIALCHART_BEGIN_NAMESPACE
11 11
12 12 QHorizontalBarSeries::QHorizontalBarSeries(QObject *parent) :
13 13 QAbstractBarSeries(*new QHorizontalBarSeriesPrivate(this), parent)
14 14 {
15 15 }
16 16
17 17 QAbstractSeries::SeriesType QHorizontalBarSeries::type() const
18 18 {
19 19 return QAbstractSeries::SeriesTypeHorizontalBar;
20 20 }
21 21
22 22
23 23
24 24 ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
25 25
26 26 QHorizontalBarSeriesPrivate::QHorizontalBarSeriesPrivate(QHorizontalBarSeries *q) : QAbstractBarSeriesPrivate(q)
27 27 {
28 28
29 29 }
30 30
31 31 void QHorizontalBarSeriesPrivate::scaleDomain(Domain& domain)
32 32 {
33 33 qreal minX(domain.minX());
34 34 qreal minY(domain.minY());
35 35 qreal maxX(domain.maxX());
36 36 qreal maxY(domain.maxY());
37 37 int tickXCount(domain.tickXCount());
38 38 int tickYCount(domain.tickYCount());
39 39
40 40 qreal y = categoryCount();
41 41 qreal x = max();
42 42 minX = qMin(minX, x);
43 minY = qMin(minY, -0.5);
43 minY = qMin(minY, - (qreal)0.5);
44 44 maxX = qMax(maxX, x);
45 maxY = qMax(maxY, y -0.5);
45 maxY = qMax(maxY, y - (qreal)0.5);
46 46 tickYCount = y+1;
47 47
48 48 domain.setRange(minX,maxX,minY,maxY,tickXCount,tickYCount);
49 49 }
50 50
51 51
52 52 Chart* QHorizontalBarSeriesPrivate::createGraphics(ChartPresenter* presenter)
53 53 {
54 54 Q_Q(QHorizontalBarSeries);
55 55
56 56 HorizontalBarChartItem* bar = new HorizontalBarChartItem(q,presenter);
57 57 if(presenter->animationOptions().testFlag(QChart::SeriesAnimations)) {
58 58 bar->setAnimator(presenter->animator());
59 59 bar->setAnimation(new HorizontalBarAnimation(bar));
60 60 }
61 61 presenter->chartTheme()->decorate(q, presenter->dataSet()->seriesIndex(q));
62 62 return bar;
63 63 }
64 64
65 65 QAbstractAxis::AxisType QHorizontalBarSeriesPrivate::defaultAxisXType() const
66 66 {
67 67 return QAbstractAxis::AxisTypeValues;
68 68 }
69 69
70 70 QAbstractAxis::AxisType QHorizontalBarSeriesPrivate::defaultAxisYType() const
71 71 {
72 72 return QAbstractAxis::AxisTypeCategories;
73 73 }
74 74
75 75
76 76 #include "moc_qhorizontalbarseries.cpp"
77 77
78 78 QTCOMMERCIALCHART_END_NAMESPACE
@@ -1,76 +1,76
1 1 #include "qhorizontalstackedbarseries.h"
2 2 #include "qhorizontalstackedbarseries_p.h"
3 3 #include "horizontalstackedbarchartitem_p.h"
4 4 #include "horizontalstackedbaranimation_p.h"
5 5
6 6 #include "chartdataset_p.h"
7 7 #include "charttheme_p.h"
8 8
9 9 QTCOMMERCIALCHART_BEGIN_NAMESPACE
10 10
11 11 QHorizontalStackedBarSeries::QHorizontalStackedBarSeries(QObject *parent) :
12 12 QAbstractBarSeries(*new QHorizontalStackedBarSeriesPrivate(this), parent)
13 13 {
14 14 }
15 15
16 16 QAbstractSeries::SeriesType QHorizontalStackedBarSeries::type() const
17 17 {
18 18 return QAbstractSeries::SeriesTypeHorizontalStackedBar;
19 19 }
20 20
21 21
22 22
23 23 ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
24 24
25 25 QHorizontalStackedBarSeriesPrivate::QHorizontalStackedBarSeriesPrivate(QHorizontalStackedBarSeries *q) : QAbstractBarSeriesPrivate(q)
26 26 {
27 27
28 28 }
29 29
30 30 void QHorizontalStackedBarSeriesPrivate::scaleDomain(Domain& domain)
31 31 {
32 32 qreal minX(domain.minX());
33 33 qreal minY(domain.minY());
34 34 qreal maxX(domain.maxX());
35 35 qreal maxY(domain.maxY());
36 36 int tickXCount(domain.tickXCount());
37 37 int tickYCount(domain.tickYCount());
38 38
39 39 qreal y = categoryCount();
40 40 qreal x = maxCategorySum();
41 41 minX = qMin(minX, x);
42 minY = qMin(minY, -0.5);
42 minY = qMin(minY, - (qreal)0.5);
43 43 maxX = qMax(maxX, x);
44 maxY = qMax(maxY, y -0.5);
44 maxY = qMax(maxY, y - (qreal)0.5);
45 45 tickYCount = y+1;
46 46
47 47 domain.setRange(minX,maxX,minY,maxY,tickXCount,tickYCount);
48 48 }
49 49
50 50 Chart* QHorizontalStackedBarSeriesPrivate::createGraphics(ChartPresenter* presenter)
51 51 {
52 52 Q_Q(QHorizontalStackedBarSeries);
53 53
54 54 HorizontalStackedBarChartItem* bar = new HorizontalStackedBarChartItem(q,presenter);
55 55 if(presenter->animationOptions().testFlag(QChart::SeriesAnimations)) {
56 56 bar->setAnimator(presenter->animator());
57 57 bar->setAnimation(new HorizontalStackedBarAnimation(bar));
58 58 }
59 59 presenter->chartTheme()->decorate(q, presenter->dataSet()->seriesIndex(q));
60 60 return bar;
61 61 }
62 62
63 63 QAbstractAxis::AxisType QHorizontalStackedBarSeriesPrivate::defaultAxisXType() const
64 64 {
65 65 return QAbstractAxis::AxisTypeValues;
66 66 }
67 67
68 68 QAbstractAxis::AxisType QHorizontalStackedBarSeriesPrivate::defaultAxisYType() const
69 69 {
70 70 return QAbstractAxis::AxisTypeCategories;
71 71 }
72 72
73 73
74 74 #include "moc_qhorizontalstackedbarseries.cpp"
75 75
76 76 QTCOMMERCIALCHART_END_NAMESPACE
General Comments 0
You need to be logged in to leave comments. Login now