##// END OF EJS Templates
horizontal barchart & example
sauimone -
r1681:77439ba76361
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 = horizontalbarchart
6 SOURCES += main.cpp
@@ -0,0 +1,94
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 <QHorizontalBarSeries>
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 QHorizontalBarSeries *series = new QHorizontalBarSeries();
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 barchart example");
64 chart->createDefaultAxes();
65 //![3]
66
67 //![4]
68 QStringList categories;
69 categories << "Jan" << "Feb" << "Mar" << "Apr" << "May" << "Jun";
70 QBarCategoriesAxis* axis = new QBarCategoriesAxis();
71 axis->append(categories);
72 chart->createDefaultAxes();
73 chart->setAxisY(axis,series);
74 //![4]
75
76 //![5]
77 chart->legend()->setVisible(true);
78 chart->legend()->setAlignment(Qt::AlignBottom);
79 //![5]
80
81 //![6]
82 QChartView* chartView = new QChartView(chart);
83 chartView->setRenderHint(QPainter::Antialiasing);
84 //![6]
85
86 //![7]
87 QMainWindow window;
88 window.setCentralWidget(chartView);
89 window.resize(400, 300);
90 window.show();
91 //![7]
92
93 return a.exec();
94 }
@@ -0,0 +1,51
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 "horizontalbaranimation_p.h"
22 #include "abstractbarchartitem_p.h"
23 #include <QTimer>
24
25 Q_DECLARE_METATYPE(QVector<QRectF>)
26
27 QTCOMMERCIALCHART_BEGIN_NAMESPACE
28
29 HorizontalBarAnimation::HorizontalBarAnimation(AbstractBarChartItem *item) :
30 AbstractBarAnimation(item)
31 {
32 }
33
34 HorizontalBarAnimation::~HorizontalBarAnimation()
35 {
36
37 }
38
39
40 QVariant HorizontalBarAnimation::interpolated(const QVariant &from, const QVariant &to, qreal progress) const
41 {
42 // TODO:
43 Q_UNUSED(from);
44 Q_UNUSED(to);
45 Q_UNUSED(progress);
46 return to;
47 }
48
49 #include "moc_horizontalbaranimation_p.cpp"
50
51 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 HORIZONTALBARANIMATION_P_H
31 #define HORIZONTALBARANIMATION_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 HorizontalBarAnimation : public AbstractBarAnimation
40 {
41 Q_OBJECT
42 public:
43 explicit HorizontalBarAnimation(AbstractBarChartItem *item);
44 ~HorizontalBarAnimation();
45
46 virtual QVariant interpolated(const QVariant &from, const QVariant &to, qreal progress) const;
47
48 };
49
50 QTCOMMERCIALCHART_END_NAMESPACE
51
52 #endif // HORIZONTALBARANIMATION_P_H
@@ -1,26 +1,27
1 CURRENTLY_BUILDING_COMPONENTS = "examples"
1 CURRENTLY_BUILDING_COMPONENTS = "examples"
2 !include( ../config.pri ) {
2 !include( ../config.pri ) {
3 error( "Couldn't find the config.pri file!" )
3 error( "Couldn't find the config.pri file!" )
4 }
4 }
5
5
6 TEMPLATE = subdirs
6 TEMPLATE = subdirs
7 SUBDIRS += \
7 SUBDIRS += \
8 areachart \
8 areachart \
9 customchart \
9 customchart \
10 linechart \
10 linechart \
11 percentbarchart \
11 percentbarchart \
12 piechart \
12 piechart \
13 piechartdrilldown \
13 piechartdrilldown \
14 presenterchart \
14 presenterchart \
15 scatterchart \
15 scatterchart \
16 scatterinteractions \
16 scatterinteractions \
17 splinechart \
17 splinechart \
18 stackedbarchart \
18 stackedbarchart \
19 stackedbarchartdrilldown \
19 stackedbarchartdrilldown \
20 zoomlinechart \
20 zoomlinechart \
21 modeldata \
21 modeldata \
22 barchart \
22 barchart \
23 legend \
23 legend \
24 barmodelmapper \
24 barmodelmapper \
25 qmlpiechart \
25 qmlpiechart \
26 lineandbar
26 lineandbar \
27 horizontalbarchart
@@ -1,28 +1,30
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/chartanimator.cpp \
6 $$PWD/chartanimator.cpp \
7 $$PWD/xyanimation.cpp \
7 $$PWD/xyanimation.cpp \
8 $$PWD/pieanimation.cpp \
8 $$PWD/pieanimation.cpp \
9 $$PWD/piesliceanimation.cpp \
9 $$PWD/piesliceanimation.cpp \
10 $$PWD/splineanimation.cpp \
10 $$PWD/splineanimation.cpp \
11 $$PWD/baranimation.cpp \
11 $$PWD/baranimation.cpp \
12 $$PWD/stackedbaranimation.cpp \
12 $$PWD/stackedbaranimation.cpp \
13 $$PWD/percentbaranimation.cpp \
13 $$PWD/percentbaranimation.cpp \
14 $$PWD/abstractbaranimation.cpp
14 $$PWD/abstractbaranimation.cpp \
15 $$PWD/horizontalbaranimation.cpp
15
16
16
17
17 PRIVATE_HEADERS += \
18 PRIVATE_HEADERS += \
18 $$PWD/axisanimation_p.h \
19 $$PWD/axisanimation_p.h \
19 $$PWD/chartanimator_p.h \
20 $$PWD/chartanimator_p.h \
20 $$PWD/chartanimation_p.h \
21 $$PWD/chartanimation_p.h \
21 $$PWD/xyanimation_p.h \
22 $$PWD/xyanimation_p.h \
22 $$PWD/pieanimation_p.h \
23 $$PWD/pieanimation_p.h \
23 $$PWD/piesliceanimation_p.h \
24 $$PWD/piesliceanimation_p.h \
24 $$PWD/splineanimation_p.h \
25 $$PWD/splineanimation_p.h \
25 $$PWD/baranimation_p.h \
26 $$PWD/baranimation_p.h \
26 $$PWD/stackedbaranimation_p.h \
27 $$PWD/stackedbaranimation_p.h \
27 $$PWD/percentbaranimation_p.h \
28 $$PWD/percentbaranimation_p.h \
28 $$PWD/abstractbaranimation_p.h
29 $$PWD/abstractbaranimation_p.h \
30 $$PWD/horizontalbaranimation_p.h
@@ -1,96 +1,96
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 "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 #include "qbarset_p.h"
26 #include "qbarset_p.h"
27
27
28 QTCOMMERCIALCHART_BEGIN_NAMESPACE
28 QTCOMMERCIALCHART_BEGIN_NAMESPACE
29
29
30 BarChartItem::BarChartItem(QAbstractBarSeries *series, ChartPresenter *presenter) :
30 BarChartItem::BarChartItem(QAbstractBarSeries *series, ChartPresenter *presenter) :
31 AbstractBarChartItem(series, presenter)
31 AbstractBarChartItem(series, presenter)
32 {
32 {
33 }
33 }
34
34
35 QVector<QRectF> BarChartItem::calculateLayout()
35 QVector<QRectF> BarChartItem::calculateLayout()
36 {
36 {
37 QVector<QRectF> layout;
37 QVector<QRectF> layout;
38
38
39 // Use temporary qreals for accuracy
39 // Use temporary qreals for accuracy
40 qreal categoryCount = m_series->d_func()->categoryCount();
40 qreal categoryCount = m_series->d_func()->categoryCount();
41 qreal setCount = m_series->count();
41 qreal setCount = m_series->count();
42 bool barsVisible = m_series->isVisible();
42 bool barsVisible = m_series->isVisible();
43
43
44 // Domain:
44 // Domain:
45 qreal width = geometry().width();
45 qreal width = geometry().width();
46 qreal height = geometry().height();
46 qreal height = geometry().height();
47 qreal rangeY = m_domainMaxY - m_domainMinY;
47 qreal rangeY = m_domainMaxY - m_domainMinY;
48 qreal rangeX = m_domainMaxX - m_domainMinX;
48 qreal rangeX = m_domainMaxX - m_domainMinX;
49 qreal scaleY = (height / rangeY);
49 qreal scaleY = (height / rangeY);
50 qreal scaleX = (width / rangeX);
50 qreal scaleX = (width / rangeX);
51 qreal barWidth = (scaleX / setCount) * m_series->d_func()->barWidth();
51 qreal barWidth = (scaleX / setCount) * m_series->d_func()->barWidth();
52
52
53 int itemIndex(0);
53 int itemIndex(0);
54 for (int category = 0; category < categoryCount; category++) {
54 for (int category = 0; category < categoryCount; category++) {
55 qreal yPos = height + scaleY * m_domainMinY + geometry().topLeft().y();
55 qreal yPos = height + scaleY * m_domainMinY + geometry().topLeft().y();
56 for (int set = 0; set < setCount; set++) {
56 for (int set = 0; set < setCount; set++) {
57 QBarSetPrivate* barSet = m_series->d_func()->barsetAt(set)->d_ptr.data();
57 QBarSetPrivate* barSet = m_series->d_func()->barsetAt(set)->d_ptr.data();
58
58
59 qreal xPos = (barSet->at(category).x() - m_domainMinX) * scaleX + m_rect.left();
59 qreal xPos = (barSet->pos(category) - m_domainMinX) * scaleX + m_rect.left();
60 xPos -= setCount*barWidth/2;
60 xPos -= setCount*barWidth/2;
61 xPos += set*barWidth;
61 xPos += set*barWidth;
62 qreal barHeight = barSet->at(category).y() * scaleY;
62 qreal barHeight = barSet->value(category) * scaleY;
63 Bar* bar = m_bars.at(itemIndex);
63 Bar* bar = m_bars.at(itemIndex);
64
64
65 QRectF rect(xPos, yPos - barHeight, barWidth, barHeight);
65 QRectF rect(xPos, yPos - barHeight, barWidth, barHeight);
66 layout.append(rect);
66 layout.append(rect);
67 bar->setPen(barSet->m_pen);
67 bar->setPen(barSet->m_pen);
68 bar->setBrush(barSet->m_brush);
68 bar->setBrush(barSet->m_brush);
69 if (qFuzzyIsNull(barHeight)) {
69 if (qFuzzyIsNull(barHeight)) {
70 bar->setVisible(false);
70 bar->setVisible(false);
71 } else {
71 } else {
72 bar->setVisible(barsVisible);
72 bar->setVisible(barsVisible);
73 }
73 }
74
74
75 QGraphicsSimpleTextItem* label = m_labels.at(itemIndex);
75 QGraphicsSimpleTextItem* label = m_labels.at(itemIndex);
76
76
77 if (!qFuzzyIsNull(barSet->at(category).y())) {
77 if (!qFuzzyIsNull(barSet->value(category))) {
78 label->setText(QString::number(barSet->at(category).y()));
78 label->setText(QString::number(barSet->value(category)));
79 } else {
79 } else {
80 label->setText(QString(""));
80 label->setText(QString(""));
81 }
81 }
82
82
83 label->setPos(xPos + (rect.width()/2 - label->boundingRect().width()/2)
83 label->setPos(xPos + (rect.width()/2 - label->boundingRect().width()/2)
84 ,yPos - barHeight/2 - label->boundingRect().height()/2);
84 ,yPos - barHeight/2 - label->boundingRect().height()/2);
85 label->setFont(barSet->m_labelFont);
85 label->setFont(barSet->m_labelFont);
86 label->setBrush(barSet->m_labelBrush);
86 label->setBrush(barSet->m_labelBrush);
87
87
88 itemIndex++;
88 itemIndex++;
89 }
89 }
90 }
90 }
91 return layout;
91 return layout;
92 }
92 }
93
93
94 #include "moc_barchartitem_p.cpp"
94 #include "moc_barchartitem_p.cpp"
95
95
96 QTCOMMERCIALCHART_END_NAMESPACE
96 QTCOMMERCIALCHART_END_NAMESPACE
@@ -1,19 +1,96
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
1 #include "horizontalbarchartitem_p.h"
21 #include "horizontalbarchartitem_p.h"
22 #include "qabstractbarseries_p.h"
23 #include "qbarset_p.h"
24 #include "bar_p.h"
25 #include <QDebug>
2
26
3 QTCOMMERCIALCHART_BEGIN_NAMESPACE
27 QTCOMMERCIALCHART_BEGIN_NAMESPACE
4
28
5 HorizontalBarChartitem::HorizontalBarChartitem(QAbstractBarSeries *series, ChartPresenter *presenter) :
29 HorizontalBarChartItem::HorizontalBarChartItem(QAbstractBarSeries *series, ChartPresenter *presenter) :
6 AbstractBarChartItem(series, presenter)
30 AbstractBarChartItem(series, presenter)
7 {
31 {
8 }
32 }
9
33
10 QVector<QRectF> HorizontalBarChartitem::calculateLayout()
34 QVector<QRectF> HorizontalBarChartItem::calculateLayout()
11 {
35 {
12 // TODO:
13 QVector<QRectF> layout;
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 / setCount) * 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 xPos = scaleX * m_domainMinX + geometry().left();
55 for (int set = 0; set < setCount; set++) {
56 QBarSetPrivate* barSet = m_series->d_func()->barsetAt(set)->d_ptr.data();
57
58 qreal yPos = m_rect.bottom() -(barSet->pos(category) + m_domainMinY + 1) * scaleY;
59 yPos += setCount*barHeight/2;
60 yPos -= set*barHeight;
61
62 qreal barWidth = barSet->value(category) * 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(barSet->value(category))) {
78 label->setText(QString::number(barSet->value(category)));
79 } else {
80 label->setText(QString(""));
81 }
82
83 label->setPos(xPos + (rect.width()/2 - label->boundingRect().width()/2)
84 ,yPos - barHeight/2 - label->boundingRect().height()/2);
85 label->setFont(barSet->m_labelFont);
86 label->setBrush(barSet->m_labelBrush);
87
88 itemIndex++;
89 }
90 }
14 return layout;
91 return layout;
15 }
92 }
16
93
17 #include "moc_horizontalbarchartitem_p.cpp"
94 #include "moc_horizontalbarchartitem_p.cpp"
18
95
19 QTCOMMERCIALCHART_END_NAMESPACE
96 QTCOMMERCIALCHART_END_NAMESPACE
@@ -1,23 +1,51
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
1 #ifndef HORIZONTALBARCHARTITEM_H
30 #ifndef HORIZONTALBARCHARTITEM_H
2 #define HORIZONTALBARCHARTITEM_H
31 #define HORIZONTALBARCHARTITEM_H
3
32
4 #include "abstractbarchartitem_p.h"
33 #include "abstractbarchartitem_p.h"
5 #include "qstackedbarseries.h"
34 #include "qstackedbarseries.h"
6 #include <QGraphicsItem>
35 #include <QGraphicsItem>
7
36
8 QTCOMMERCIALCHART_BEGIN_NAMESPACE
37 QTCOMMERCIALCHART_BEGIN_NAMESPACE
9
38
10
39 class HorizontalBarChartItem : public AbstractBarChartItem
11 class HorizontalBarChartitem : public AbstractBarChartItem
12 {
40 {
13 Q_OBJECT
41 Q_OBJECT
14 public:
42 public:
15 HorizontalBarChartitem(QAbstractBarSeries *series, ChartPresenter *presenter);
43 HorizontalBarChartItem(QAbstractBarSeries *series, ChartPresenter *presenter);
16
44
17 private:
45 private:
18 virtual QVector<QRectF> calculateLayout();
46 virtual QVector<QRectF> calculateLayout();
19 };
47 };
20
48
21 QTCOMMERCIALCHART_END_NAMESPACE
49 QTCOMMERCIALCHART_END_NAMESPACE
22
50
23 #endif // HORIZONTALBARCHARTITEM_H
51 #endif // HORIZONTALBARCHARTITEM_H
@@ -1,102 +1,102
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 "chartanimator_p.h"
25 #include "chartanimator_p.h"
26 #include "qbarset_p.h"
26 #include "qbarset_p.h"
27
27
28 QTCOMMERCIALCHART_BEGIN_NAMESPACE
28 QTCOMMERCIALCHART_BEGIN_NAMESPACE
29
29
30 PercentBarChartItem::PercentBarChartItem(QAbstractBarSeries *series, ChartPresenter *presenter) :
30 PercentBarChartItem::PercentBarChartItem(QAbstractBarSeries *series, ChartPresenter *presenter) :
31 AbstractBarChartItem(series, presenter)
31 AbstractBarChartItem(series, presenter)
32 {
32 {
33 }
33 }
34
34
35 QVector<QRectF> PercentBarChartItem::calculateLayout()
35 QVector<QRectF> PercentBarChartItem::calculateLayout()
36 {
36 {
37 QVector<QRectF> layout;
37 QVector<QRectF> layout;
38
38
39 // Use temporary qreals for accuracy
39 // Use temporary qreals for accuracy
40 qreal categoryCount = m_series->d_func()->categoryCount();
40 qreal categoryCount = m_series->d_func()->categoryCount();
41 qreal setCount = m_series->count();
41 qreal setCount = m_series->count();
42 bool barsVisible = m_series->isVisible();
42 bool barsVisible = m_series->isVisible();
43
43
44 // Domain:
44 // Domain:
45 qreal width = geometry().width();
45 qreal width = geometry().width();
46 qreal height = geometry().height();
46 qreal height = geometry().height();
47 qreal rangeY = m_domainMaxY - m_domainMinY;
47 qreal rangeY = m_domainMaxY - m_domainMinY;
48 qreal rangeX = m_domainMaxX - m_domainMinX;
48 qreal rangeX = m_domainMaxX - m_domainMinX;
49 qreal scaleY = (height / rangeY);
49 qreal scaleY = (height / rangeY);
50 qreal scaleX = (width / rangeX);
50 qreal scaleX = (width / rangeX);
51 qreal barWidth = scaleX * m_series->d_func()->barWidth();
51 qreal barWidth = scaleX * m_series->d_func()->barWidth();
52
52
53 int itemIndex(0);
53 int itemIndex(0);
54 for (int category = 0; category < categoryCount; category++) {
54 for (int category = 0; category < categoryCount; category++) {
55 qreal colSum = m_series->d_func()->categorySum(category);
55 qreal colSum = m_series->d_func()->categorySum(category);
56 qreal percentage = (100 / colSum);
56 qreal percentage = (100 / colSum);
57 qreal yPos = height + scaleY * m_domainMinY + geometry().topLeft().y();
57 qreal yPos = height + scaleY * m_domainMinY + geometry().topLeft().y();
58 for (int set=0; set < setCount; set++) {
58 for (int set=0; set < setCount; set++) {
59 QBarSetPrivate* barSet = m_series->d_func()->barsetAt(set)->d_ptr.data();
59 QBarSetPrivate* barSet = m_series->d_func()->barsetAt(set)->d_ptr.data();
60
60
61 qreal xPos = (barSet->at(category).x() - m_domainMinX) * scaleX + m_rect.left() - barWidth/2;
61 qreal xPos = (barSet->pos(category) - m_domainMinX) * scaleX + m_rect.left() - barWidth/2;
62
62
63 qreal barHeight = barSet->at(category).y() * percentage * scaleY;
63 qreal barHeight = barSet->value(category) * percentage * scaleY;
64 Bar* bar = m_bars.at(itemIndex);
64 Bar* bar = m_bars.at(itemIndex);
65 bar->setPen(barSet->m_pen);
65 bar->setPen(barSet->m_pen);
66 bar->setBrush(barSet->m_brush);
66 bar->setBrush(barSet->m_brush);
67 if (qFuzzyIsNull(barHeight)) {
67 if (qFuzzyIsNull(barHeight)) {
68 bar->setVisible(false);
68 bar->setVisible(false);
69 } else {
69 } else {
70 bar->setVisible(barsVisible);
70 bar->setVisible(barsVisible);
71 }
71 }
72
72
73 QRectF rect(xPos, yPos-barHeight, barWidth, barHeight);
73 QRectF rect(xPos, yPos-barHeight, barWidth, barHeight);
74 layout.append(rect);
74 layout.append(rect);
75
75
76 QGraphicsSimpleTextItem* label = m_labels.at(itemIndex);
76 QGraphicsSimpleTextItem* label = m_labels.at(itemIndex);
77
77
78 if (!qFuzzyIsNull(m_series->d_func()->valueAt(set,category))) {
78 if (!qFuzzyIsNull(m_series->d_func()->valueAt(set,category))) {
79 int p = m_series->d_func()->percentageAt(set,category) * 100;
79 int p = m_series->d_func()->percentageAt(set,category) * 100;
80 QString vString(QString::number(p));
80 QString vString(QString::number(p));
81 vString.truncate(3);
81 vString.truncate(3);
82 vString.append("%");
82 vString.append("%");
83 label->setText(vString);
83 label->setText(vString);
84 } else {
84 } else {
85 label->setText(QString(""));
85 label->setText(QString(""));
86 }
86 }
87
87
88 label->setPos(xPos + (rect.width()/2 - label->boundingRect().width()/2)
88 label->setPos(xPos + (rect.width()/2 - label->boundingRect().width()/2)
89 ,yPos - barHeight/2 - label->boundingRect().height()/2);
89 ,yPos - barHeight/2 - label->boundingRect().height()/2);
90 label->setFont(barSet->m_labelFont);
90 label->setFont(barSet->m_labelFont);
91 label->setBrush(barSet->m_labelBrush);
91 label->setBrush(barSet->m_labelBrush);
92
92
93 itemIndex++;
93 itemIndex++;
94 yPos -= barHeight;
94 yPos -= barHeight;
95 }
95 }
96 }
96 }
97 return layout;
97 return layout;
98 }
98 }
99
99
100 #include "moc_percentbarchartitem_p.cpp"
100 #include "moc_percentbarchartitem_p.cpp"
101
101
102 QTCOMMERCIALCHART_END_NAMESPACE
102 QTCOMMERCIALCHART_END_NAMESPACE
@@ -1,737 +1,737
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 "domain_p.h"
25 #include "domain_p.h"
26 #include "legendmarker_p.h"
26 #include "legendmarker_p.h"
27 #include "chartdataset_p.h"
27 #include "chartdataset_p.h"
28 #include "charttheme_p.h"
28 #include "charttheme_p.h"
29 #include "chartanimator_p.h"
29 #include "chartanimator_p.h"
30 #include "qvaluesaxis.h"
30 #include "qvaluesaxis.h"
31 #include "qbarcategoriesaxis.h"
31 #include "qbarcategoriesaxis.h"
32
32
33 QTCOMMERCIALCHART_BEGIN_NAMESPACE
33 QTCOMMERCIALCHART_BEGIN_NAMESPACE
34
34
35 /*!
35 /*!
36 \class QAbstractBarSeries
36 \class QAbstractBarSeries
37 \brief Series for creating a bar chart
37 \brief Series for creating a bar chart
38 \mainclass
38 \mainclass
39
39
40 QAbstractBarSeries represents a series of data shown as bars. The purpose of this class is to draw bars to
40 QAbstractBarSeries represents a series of data shown as bars. The purpose of this class is to draw bars to
41 the position defined by data. Single bar is defined by QPointF, where x value is the x-coordinate of the bar
41 the position defined by data. Single bar is defined by QPointF, where x value is the x-coordinate of the bar
42 and y-value is the height of the bar. The category names are ignored with this series and x-axis
42 and y-value is the height of the bar. The category names are ignored with this series and x-axis
43 shows the x-values.
43 shows the x-values.
44
44
45 See the \l {BarChart Example} {bar chart example} to learn how to create a simple bar chart.
45 See the \l {BarChart Example} {bar chart example} to learn how to create a simple bar chart.
46 \image examples_barchart.png
46 \image examples_barchart.png
47
47
48 \sa QBarSet, QStackedBarSeries, QPercentBarSeries
48 \sa QBarSet, QStackedBarSeries, QPercentBarSeries
49 */
49 */
50 /*!
50 /*!
51 \qmlclass AbstractBarSeries QAbstractBarSeries
51 \qmlclass AbstractBarSeries QAbstractBarSeries
52 \inherits QAbstractSeries
52 \inherits QAbstractSeries
53
53
54 The following QML shows how to create a simple bar chart:
54 The following QML shows how to create a simple bar chart:
55 \snippet ../demos/qmlchart/qml/qmlchart/View6.qml 1
55 \snippet ../demos/qmlchart/qml/qmlchart/View6.qml 1
56
56
57 \beginfloatleft
57 \beginfloatleft
58 \image demos_qmlchart6.png
58 \image demos_qmlchart6.png
59 \endfloat
59 \endfloat
60 \clearfloat
60 \clearfloat
61 */
61 */
62
62
63 /*!
63 /*!
64 \property QAbstractBarSeries::barWidth
64 \property QAbstractBarSeries::barWidth
65 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 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 is zero and negative values are treated as zero. Setting the width to zero means that width of the bar on screen
66 is zero and negative values are treated as zero. Setting the width to zero means that width of the bar on screen
67 is one pixel no matter what the scale of x-axis is. Bars wider than zero are scaled with x-axis.
67 is one pixel no matter what the scale of x-axis is. Bars wider than zero are scaled with x-axis.
68 Note that with QBarSeries this value means the width of one group of bars instead of just one bar.
68 Note that with QBarSeries this value means the width of one group of bars instead of just one bar.
69 \sa QBarSeries
69 \sa QBarSeries
70 */
70 */
71 /*!
71 /*!
72 \qmlproperty real AbstractBarSeries::barWidth
72 \qmlproperty real AbstractBarSeries::barWidth
73 The width of the bars of the series. The unit of width is the unit of x-axis. The minimum width for bars
73 The width of the bars of the series. The unit of width is the unit of x-axis. The minimum width for bars
74 is zero and negative values are treated as zero. Setting the width to zero means that width of the bar on screen
74 is zero and negative values are treated as zero. Setting the width to zero means that width of the bar on screen
75 is one pixel no matter what the scale of x-axis is. Bars wider than zero are scaled with x-axis.
75 is one pixel no matter what the scale of x-axis is. Bars wider than zero are scaled with x-axis.
76 Note that with QBarSeries this value means the width of one group of bars instead of just one bar.
76 Note that with QBarSeries this value means the width of one group of bars instead of just one bar.
77 */
77 */
78
78
79 /*!
79 /*!
80 \property QAbstractBarSeries::count
80 \property QAbstractBarSeries::count
81 Holds the number of sets in series.
81 Holds the number of sets in series.
82 */
82 */
83 /*!
83 /*!
84 \qmlproperty int AbstractBarSeries::count
84 \qmlproperty int AbstractBarSeries::count
85 Holds the number of sets in series.
85 Holds the number of sets in series.
86 */
86 */
87
87
88 /*!
88 /*!
89 \property QAbstractBarSeries::labelsVisible
89 \property QAbstractBarSeries::labelsVisible
90 Defines the visibility of the labels in series
90 Defines the visibility of the labels in series
91 */
91 */
92 /*!
92 /*!
93 \qmlproperty bool AbstractBarSeries::labelsVisible
93 \qmlproperty bool AbstractBarSeries::labelsVisible
94 Defines the visibility of the labels in series
94 Defines the visibility of the labels in series
95 */
95 */
96
96
97 /*!
97 /*!
98 \fn void QAbstractBarSeries::clicked(int index, QBarSet *barset)
98 \fn void QAbstractBarSeries::clicked(int index, QBarSet *barset)
99 The signal is emitted if the user clicks with a mouse on top of QBarSet \a barset.
99 The signal is emitted if the user clicks with a mouse on top of QBarSet \a barset.
100 Clicked bar inside set is indexed by \a index
100 Clicked bar inside set is indexed by \a index
101 */
101 */
102 /*!
102 /*!
103 \qmlsignal AbstractBarSeries::onClicked(int index, BarSet barset)
103 \qmlsignal AbstractBarSeries::onClicked(int index, BarSet barset)
104 The signal is emitted if the user clicks with a mouse on top of BarSet.
104 The signal is emitted if the user clicks with a mouse on top of BarSet.
105 Clicked bar inside set is indexed by \a index
105 Clicked bar inside set is indexed by \a index
106 */
106 */
107
107
108 /*!
108 /*!
109 \fn void QAbstractBarSeries::hovered(bool status, QBarSet* barset)
109 \fn void QAbstractBarSeries::hovered(bool status, QBarSet* barset)
110
110
111 The signal is emitted if mouse is hovered on top of series.
111 The signal is emitted if mouse is hovered on top of series.
112 Parameter \a barset is the pointer of barset, where hover happened.
112 Parameter \a barset is the pointer of barset, where hover happened.
113 Parameter \a status is true, if mouse entered on top of series, false if mouse left from top of series.
113 Parameter \a status is true, if mouse entered on top of series, false if mouse left from top of series.
114 */
114 */
115 /*!
115 /*!
116 \qmlsignal AbstractBarSeries::onHovered(bool status, BarSet barset)
116 \qmlsignal AbstractBarSeries::onHovered(bool status, BarSet barset)
117
117
118 The signal is emitted if mouse is hovered on top of series.
118 The signal is emitted if mouse is hovered on top of series.
119 Parameter \a barset is the pointer of barset, where hover happened.
119 Parameter \a barset is the pointer of barset, where hover happened.
120 Parameter \a status is true, if mouse entered on top of series, false if mouse left from top of series.
120 Parameter \a status is true, if mouse entered on top of series, false if mouse left from top of series.
121 */
121 */
122
122
123 /*!
123 /*!
124 \fn void QAbstractBarSeries::countChanged()
124 \fn void QAbstractBarSeries::countChanged()
125 This signal is emitted when barset count has been changed, for example by append or remove.
125 This signal is emitted when barset count has been changed, for example by append or remove.
126 */
126 */
127 /*!
127 /*!
128 \qmlsignal AbstractBarSeries::onCountChanged()
128 \qmlsignal AbstractBarSeries::onCountChanged()
129 This signal is emitted when barset count has been changed, for example by append or remove.
129 This signal is emitted when barset count has been changed, for example by append or remove.
130 */
130 */
131
131
132 /*!
132 /*!
133 \fn void QAbstractBarSeries::labelsVisibleChanged()
133 \fn void QAbstractBarSeries::labelsVisibleChanged()
134 This signal is emitted when labels visibility have changed.
134 This signal is emitted when labels visibility have changed.
135 \sa isLabelsVisible(), setLabelsVisible()
135 \sa isLabelsVisible(), setLabelsVisible()
136 */
136 */
137
137
138 /*!
138 /*!
139 \fn void QAbstractBarSeries::barsetsAdded(QList<QBarSet*> sets)
139 \fn void QAbstractBarSeries::barsetsAdded(QList<QBarSet*> sets)
140 This signal is emitted when \a sets have been added to the series.
140 This signal is emitted when \a sets have been added to the series.
141 \sa append(), insert()
141 \sa append(), insert()
142 */
142 */
143 /*!
143 /*!
144 \qmlsignal AbstractBarSeries::onAdded(BarSet barset)
144 \qmlsignal AbstractBarSeries::onAdded(BarSet barset)
145 Emitted when \a barset has been added to the series.
145 Emitted when \a barset has been added to the series.
146 */
146 */
147
147
148 /*!
148 /*!
149 \fn void QAbstractBarSeries::barsetsRemoved(QList<QBarSet*> sets)
149 \fn void QAbstractBarSeries::barsetsRemoved(QList<QBarSet*> sets)
150 This signal is emitted when \a sets have been removed from the series.
150 This signal is emitted when \a sets have been removed from the series.
151 \sa remove()
151 \sa remove()
152 */
152 */
153 /*!
153 /*!
154 \qmlsignal AbstractBarSeries::onRemoved(BarSet barset)
154 \qmlsignal AbstractBarSeries::onRemoved(BarSet barset)
155 Emitted when \a barset has been removed from the series.
155 Emitted when \a barset has been removed from the series.
156 */
156 */
157
157
158 /*!
158 /*!
159 \qmlmethod BarSet AbstractBarSeries::at(int index)
159 \qmlmethod BarSet AbstractBarSeries::at(int index)
160 Returns bar set at \a index. Returns null if the index is not valid.
160 Returns bar set at \a index. Returns null if the index is not valid.
161 */
161 */
162
162
163 /*!
163 /*!
164 \qmlmethod BarSet AbstractBarSeries::append(string label, VariantList values)
164 \qmlmethod BarSet AbstractBarSeries::append(string label, VariantList values)
165 Adds 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.
165 Adds 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.
166 For example:
166 For example:
167 \code
167 \code
168 myBarSeries.append("set 1", [0, 0.2, 0.2, 0.5, 0.4, 1.5, 0.9]);
168 myBarSeries.append("set 1", [0, 0.2, 0.2, 0.5, 0.4, 1.5, 0.9]);
169 myBarSeries.append("set 2", [Qt.point(0, 1), Qt.point(2, 2.5), Qt.point(3.5, 2.2)]);
169 myBarSeries.append("set 2", [Qt.point(0, 1), Qt.point(2, 2.5), Qt.point(3.5, 2.2)]);
170 \endcode
170 \endcode
171 */
171 */
172
172
173 /*!
173 /*!
174 \qmlmethod BarSet AbstractBarSeries::insert(int index, string label, VariantList values)
174 \qmlmethod BarSet AbstractBarSeries::insert(int index, string label, VariantList values)
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.
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.
176 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
177 appended.
177 appended.
178 \sa AbstractBarSeries::append()
178 \sa AbstractBarSeries::append()
179 */
179 */
180
180
181 /*!
181 /*!
182 \qmlmethod bool AbstractBarSeries::remove(BarSet barset)
182 \qmlmethod bool AbstractBarSeries::remove(BarSet barset)
183 Removes the barset from the series. Returns true if successfull, false otherwise.
183 Removes the barset from the series. Returns true if successfull, false otherwise.
184 */
184 */
185
185
186 /*!
186 /*!
187 \qmlmethod AbstractBarSeries::clear()
187 \qmlmethod AbstractBarSeries::clear()
188 Removes all barsets from the series.
188 Removes all barsets from the series.
189 */
189 */
190
190
191 /*!
191 /*!
192 Constructs empty QAbstractBarSeries.
192 Constructs empty QAbstractBarSeries.
193 QAbstractBarSeries is QObject which is a child of a \a parent.
193 QAbstractBarSeries is QObject which is a child of a \a parent.
194 */
194 */
195 QAbstractBarSeries::QAbstractBarSeries(QObject *parent) :
195 QAbstractBarSeries::QAbstractBarSeries(QObject *parent) :
196 QAbstractSeries(*new QAbstractBarSeriesPrivate(this),parent)
196 QAbstractSeries(*new QAbstractBarSeriesPrivate(this),parent)
197 {
197 {
198 }
198 }
199
199
200 /*!
200 /*!
201 Destructs abstractbarseries and owned barsets.
201 Destructs abstractbarseries and owned barsets.
202 */
202 */
203 QAbstractBarSeries::~QAbstractBarSeries()
203 QAbstractBarSeries::~QAbstractBarSeries()
204 {
204 {
205 Q_D(QAbstractBarSeries);
205 Q_D(QAbstractBarSeries);
206 if(d->m_dataset){
206 if(d->m_dataset){
207 d->m_dataset->removeSeries(this);
207 d->m_dataset->removeSeries(this);
208 }
208 }
209 }
209 }
210
210
211 /*!
211 /*!
212 \internal
212 \internal
213 */
213 */
214 QAbstractBarSeries::QAbstractBarSeries(QAbstractBarSeriesPrivate &d, QObject *parent) :
214 QAbstractBarSeries::QAbstractBarSeries(QAbstractBarSeriesPrivate &d, QObject *parent) :
215 QAbstractSeries(d,parent)
215 QAbstractSeries(d,parent)
216 {
216 {
217 }
217 }
218
218
219 /*!
219 /*!
220 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
220 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
221 is zero and negative values are treated as zero. Setting the width to zero means that width of the bar on screen
221 is zero and negative values are treated as zero. Setting the width to zero means that width of the bar on screen
222 is one pixel no matter what the scale of x-axis is. Bars wider than zero are scaled with x-axis.
222 is one pixel no matter what the scale of x-axis is. Bars wider than zero are scaled with x-axis.
223 Note that with \link QBarSeries \endlink this value means the width of one group of bars instead of just one bar.
223 Note that with \link QBarSeries \endlink this value means the width of one group of bars instead of just one bar.
224 */
224 */
225 void QAbstractBarSeries::setBarWidth(qreal width)
225 void QAbstractBarSeries::setBarWidth(qreal width)
226 {
226 {
227 Q_D(QAbstractBarSeries);
227 Q_D(QAbstractBarSeries);
228 d->setBarWidth(width);
228 d->setBarWidth(width);
229 }
229 }
230
230
231 /*!
231 /*!
232 Returns the width of the bars of the series.
232 Returns the width of the bars of the series.
233 \sa setBarWidth()
233 \sa setBarWidth()
234 */
234 */
235 qreal QAbstractBarSeries::barWidth() const
235 qreal QAbstractBarSeries::barWidth() const
236 {
236 {
237 Q_D(const QAbstractBarSeries);
237 Q_D(const QAbstractBarSeries);
238 return d->barWidth();
238 return d->barWidth();
239 }
239 }
240
240
241 /*!
241 /*!
242 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.
242 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.
243 Returns true, if appending succeeded.
243 Returns true, if appending succeeded.
244 */
244 */
245 bool QAbstractBarSeries::append(QBarSet *set)
245 bool QAbstractBarSeries::append(QBarSet *set)
246 {
246 {
247 Q_D(QAbstractBarSeries);
247 Q_D(QAbstractBarSeries);
248 bool success = d->append(set);
248 bool success = d->append(set);
249 if (success) {
249 if (success) {
250 QList<QBarSet*> sets;
250 QList<QBarSet*> sets;
251 sets.append(set);
251 sets.append(set);
252 emit barsetsAdded(sets);
252 emit barsetsAdded(sets);
253 emit countChanged();
253 emit countChanged();
254 }
254 }
255 return success;
255 return success;
256 }
256 }
257
257
258 /*!
258 /*!
259 Removes a set of bars from series. Releases ownership of \a set. Doesn't delete \a set.
259 Removes a set of bars from series. Releases ownership of \a set. Doesn't delete \a set.
260 Returns true, if set was removed.
260 Returns true, if set was removed.
261 */
261 */
262 bool QAbstractBarSeries::remove(QBarSet *set)
262 bool QAbstractBarSeries::remove(QBarSet *set)
263 {
263 {
264 Q_D(QAbstractBarSeries);
264 Q_D(QAbstractBarSeries);
265 bool success = d->remove(set);
265 bool success = d->remove(set);
266 if (success) {
266 if (success) {
267 QList<QBarSet*> sets;
267 QList<QBarSet*> sets;
268 sets.append(set);
268 sets.append(set);
269 emit barsetsRemoved(sets);
269 emit barsetsRemoved(sets);
270 emit countChanged();
270 emit countChanged();
271 }
271 }
272 return success;
272 return success;
273 }
273 }
274
274
275 /*!
275 /*!
276 Adds a list of barsets to series. Takes ownership of \a sets.
276 Adds a list of barsets to series. Takes ownership of \a sets.
277 Returns true, if all sets were appended succesfully. If any of the sets is null or is already appended to series,
277 Returns true, if all sets were appended succesfully. If any of the sets is null or is already appended to series,
278 nothing is appended and function returns false. If any of the sets is in list more than once, nothing is appended
278 nothing is appended and function returns false. If any of the sets is in list more than once, nothing is appended
279 and function returns false.
279 and function returns false.
280 */
280 */
281 bool QAbstractBarSeries::append(QList<QBarSet* > sets)
281 bool QAbstractBarSeries::append(QList<QBarSet* > sets)
282 {
282 {
283 Q_D(QAbstractBarSeries);
283 Q_D(QAbstractBarSeries);
284 bool success = d->append(sets);
284 bool success = d->append(sets);
285 if (success) {
285 if (success) {
286 emit barsetsAdded(sets);
286 emit barsetsAdded(sets);
287 emit countChanged();
287 emit countChanged();
288 }
288 }
289 return success;
289 return success;
290 }
290 }
291
291
292 /*!
292 /*!
293 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.
293 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.
294 Returns true, if inserting succeeded.
294 Returns true, if inserting succeeded.
295
295
296 */
296 */
297 bool QAbstractBarSeries::insert(int index, QBarSet *set)
297 bool QAbstractBarSeries::insert(int index, QBarSet *set)
298 {
298 {
299 Q_D(QAbstractBarSeries);
299 Q_D(QAbstractBarSeries);
300 bool success = d->insert(index, set);
300 bool success = d->insert(index, set);
301 if (success) {
301 if (success) {
302 QList<QBarSet*> sets;
302 QList<QBarSet*> sets;
303 sets.append(set);
303 sets.append(set);
304 emit barsetsAdded(sets);
304 emit barsetsAdded(sets);
305 emit countChanged();
305 emit countChanged();
306 }
306 }
307 return success;
307 return success;
308 }
308 }
309
309
310 /*!
310 /*!
311 Removes all of the bar sets from the series
311 Removes all of the bar sets from the series
312 */
312 */
313 void QAbstractBarSeries::clear()
313 void QAbstractBarSeries::clear()
314 {
314 {
315 Q_D(QAbstractBarSeries);
315 Q_D(QAbstractBarSeries);
316 QList<QBarSet *> sets = barSets();
316 QList<QBarSet *> sets = barSets();
317 bool success = d->remove(sets);
317 bool success = d->remove(sets);
318 if (success) {
318 if (success) {
319 emit barsetsRemoved(sets);
319 emit barsetsRemoved(sets);
320 emit countChanged();
320 emit countChanged();
321 }
321 }
322 }
322 }
323
323
324 /*!
324 /*!
325 Returns number of sets in series.
325 Returns number of sets in series.
326 */
326 */
327 int QAbstractBarSeries::count() const
327 int QAbstractBarSeries::count() const
328 {
328 {
329 Q_D(const QAbstractBarSeries);
329 Q_D(const QAbstractBarSeries);
330 return d->m_barSets.count();
330 return d->m_barSets.count();
331 }
331 }
332
332
333 /*!
333 /*!
334 Returns a list of sets in series. Keeps ownership of sets.
334 Returns a list of sets in series. Keeps ownership of sets.
335 */
335 */
336 QList<QBarSet*> QAbstractBarSeries::barSets() const
336 QList<QBarSet*> QAbstractBarSeries::barSets() const
337 {
337 {
338 Q_D(const QAbstractBarSeries);
338 Q_D(const QAbstractBarSeries);
339 return d->m_barSets;
339 return d->m_barSets;
340 }
340 }
341
341
342 /*!
342 /*!
343 Sets the visibility of labels in series to \a visible
343 Sets the visibility of labels in series to \a visible
344 */
344 */
345 void QAbstractBarSeries::setLabelsVisible(bool visible)
345 void QAbstractBarSeries::setLabelsVisible(bool visible)
346 {
346 {
347 Q_D(QAbstractBarSeries);
347 Q_D(QAbstractBarSeries);
348 if (d->m_labelsVisible != visible) {
348 if (d->m_labelsVisible != visible) {
349 d->setLabelsVisible(visible);
349 d->setLabelsVisible(visible);
350 emit labelsVisibleChanged();
350 emit labelsVisibleChanged();
351 }
351 }
352 }
352 }
353
353
354 /*!
354 /*!
355 Returns the visibility of labels
355 Returns the visibility of labels
356 */
356 */
357 bool QAbstractBarSeries::isLabelsVisible() const
357 bool QAbstractBarSeries::isLabelsVisible() const
358 {
358 {
359 Q_D(const QAbstractBarSeries);
359 Q_D(const QAbstractBarSeries);
360 return d->m_labelsVisible;
360 return d->m_labelsVisible;
361 }
361 }
362
362
363 ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
363 ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
364
364
365 QAbstractBarSeriesPrivate::QAbstractBarSeriesPrivate(QAbstractBarSeries *q) :
365 QAbstractBarSeriesPrivate::QAbstractBarSeriesPrivate(QAbstractBarSeries *q) :
366 QAbstractSeriesPrivate(q),
366 QAbstractSeriesPrivate(q),
367 m_barWidth(0.5), // Default value is 50% of category width
367 m_barWidth(0.5), // Default value is 50% of category width
368 m_labelsVisible(false),
368 m_labelsVisible(false),
369 m_visible(true)
369 m_visible(true)
370 {
370 {
371 }
371 }
372
372
373 int QAbstractBarSeriesPrivate::categoryCount() const
373 int QAbstractBarSeriesPrivate::categoryCount() const
374 {
374 {
375 // No categories defined. return count of longest set.
375 // No categories defined. return count of longest set.
376 int count = 0;
376 int count = 0;
377 for (int i=0; i<m_barSets.count(); i++) {
377 for (int i=0; i<m_barSets.count(); i++) {
378 if (m_barSets.at(i)->count() > count) {
378 if (m_barSets.at(i)->count() > count) {
379 count = m_barSets.at(i)->count();
379 count = m_barSets.at(i)->count();
380 }
380 }
381 }
381 }
382
382
383 return count;
383 return count;
384 }
384 }
385
385
386 void QAbstractBarSeriesPrivate::setBarWidth(qreal width)
386 void QAbstractBarSeriesPrivate::setBarWidth(qreal width)
387 {
387 {
388 if (width < 0.0) {
388 if (width < 0.0) {
389 width = 0.0;
389 width = 0.0;
390 }
390 }
391 m_barWidth = width;
391 m_barWidth = width;
392 emit updatedBars();
392 emit updatedBars();
393 }
393 }
394
394
395 qreal QAbstractBarSeriesPrivate::barWidth() const
395 qreal QAbstractBarSeriesPrivate::barWidth() const
396 {
396 {
397 return m_barWidth;
397 return m_barWidth;
398 }
398 }
399
399
400 QBarSet* QAbstractBarSeriesPrivate::barsetAt(int index)
400 QBarSet* QAbstractBarSeriesPrivate::barsetAt(int index)
401 {
401 {
402 return m_barSets.at(index);
402 return m_barSets.at(index);
403 }
403 }
404
404
405 void QAbstractBarSeriesPrivate::setVisible(bool visible)
405 void QAbstractBarSeriesPrivate::setVisible(bool visible)
406 {
406 {
407 m_visible = visible;
407 m_visible = visible;
408 emit updatedBars();
408 emit updatedBars();
409 }
409 }
410
410
411 void QAbstractBarSeriesPrivate::setLabelsVisible(bool visible)
411 void QAbstractBarSeriesPrivate::setLabelsVisible(bool visible)
412 {
412 {
413 m_labelsVisible = visible;
413 m_labelsVisible = visible;
414 emit labelsVisibleChanged(visible);
414 emit labelsVisibleChanged(visible);
415 }
415 }
416
416
417 qreal QAbstractBarSeriesPrivate::min()
417 qreal QAbstractBarSeriesPrivate::min()
418 {
418 {
419 if (m_barSets.count() <= 0) {
419 if (m_barSets.count() <= 0) {
420 return 0;
420 return 0;
421 }
421 }
422 qreal min = INT_MAX;
422 qreal min = INT_MAX;
423
423
424 for (int i = 0; i < m_barSets.count(); i++) {
424 for (int i = 0; i < m_barSets.count(); i++) {
425 int categoryCount = m_barSets.at(i)->count();
425 int categoryCount = m_barSets.at(i)->count();
426 for (int j = 0; j < categoryCount; j++) {
426 for (int j = 0; j < categoryCount; j++) {
427 qreal temp = m_barSets.at(i)->at(j);
427 qreal temp = m_barSets.at(i)->at(j);
428 if (temp < min)
428 if (temp < min)
429 min = temp;
429 min = temp;
430 }
430 }
431 }
431 }
432 return min;
432 return min;
433 }
433 }
434
434
435 qreal QAbstractBarSeriesPrivate::max()
435 qreal QAbstractBarSeriesPrivate::max()
436 {
436 {
437 if (m_barSets.count() <= 0) {
437 if (m_barSets.count() <= 0) {
438 return 0;
438 return 0;
439 }
439 }
440 qreal max = INT_MIN;
440 qreal max = INT_MIN;
441
441
442 for (int i = 0; i < m_barSets.count(); i++) {
442 for (int i = 0; i < m_barSets.count(); i++) {
443 int categoryCount = m_barSets.at(i)->count();
443 int categoryCount = m_barSets.at(i)->count();
444 for (int j = 0; j < categoryCount; j++) {
444 for (int j = 0; j < categoryCount; j++) {
445 qreal temp = m_barSets.at(i)->at(j);
445 qreal temp = m_barSets.at(i)->at(j);
446 if (temp > max)
446 if (temp > max)
447 max = temp;
447 max = temp;
448 }
448 }
449 }
449 }
450
450
451 return max;
451 return max;
452 }
452 }
453
453
454 qreal QAbstractBarSeriesPrivate::valueAt(int set, int category)
454 qreal QAbstractBarSeriesPrivate::valueAt(int set, int category)
455 {
455 {
456 if ((set < 0) || (set >= m_barSets.count())) {
456 if ((set < 0) || (set >= m_barSets.count())) {
457 // No set, no value.
457 // No set, no value.
458 return 0;
458 return 0;
459 } else if ((category < 0) || (category >= m_barSets.at(set)->count())) {
459 } else if ((category < 0) || (category >= m_barSets.at(set)->count())) {
460 // No category, no value.
460 // No category, no value.
461 return 0;
461 return 0;
462 }
462 }
463
463
464 return m_barSets.at(set)->at(category);
464 return m_barSets.at(set)->at(category);
465 }
465 }
466
466
467 qreal QAbstractBarSeriesPrivate::percentageAt(int set, int category)
467 qreal QAbstractBarSeriesPrivate::percentageAt(int set, int category)
468 {
468 {
469 if ((set < 0) || (set >= m_barSets.count())) {
469 if ((set < 0) || (set >= m_barSets.count())) {
470 // No set, no value.
470 // No set, no value.
471 return 0;
471 return 0;
472 } else if ((category < 0) || (category >= m_barSets.at(set)->count())) {
472 } else if ((category < 0) || (category >= m_barSets.at(set)->count())) {
473 // No category, no value.
473 // No category, no value.
474 return 0;
474 return 0;
475 }
475 }
476
476
477 qreal value = m_barSets.at(set)->at(category);
477 qreal value = m_barSets.at(set)->at(category);
478 qreal sum = categorySum(category);
478 qreal sum = categorySum(category);
479 if ( qFuzzyIsNull(sum) ) {
479 if ( qFuzzyIsNull(sum) ) {
480 return 0;
480 return 0;
481 }
481 }
482
482
483 return value / sum;
483 return value / sum;
484 }
484 }
485
485
486 qreal QAbstractBarSeriesPrivate::categorySum(int category)
486 qreal QAbstractBarSeriesPrivate::categorySum(int category)
487 {
487 {
488 qreal sum(0);
488 qreal sum(0);
489 int count = m_barSets.count(); // Count sets
489 int count = m_barSets.count(); // Count sets
490 for (int set = 0; set < count; set++) {
490 for (int set = 0; set < count; set++) {
491 if (category < m_barSets.at(set)->count())
491 if (category < m_barSets.at(set)->count())
492 sum += m_barSets.at(set)->at(category);
492 sum += m_barSets.at(set)->at(category);
493 }
493 }
494 return sum;
494 return sum;
495 }
495 }
496
496
497 qreal QAbstractBarSeriesPrivate::absoluteCategorySum(int category)
497 qreal QAbstractBarSeriesPrivate::absoluteCategorySum(int category)
498 {
498 {
499 qreal sum(0);
499 qreal sum(0);
500 int count = m_barSets.count(); // Count sets
500 int count = m_barSets.count(); // Count sets
501 for (int set = 0; set < count; set++) {
501 for (int set = 0; set < count; set++) {
502 if (category < m_barSets.at(set)->count())
502 if (category < m_barSets.at(set)->count())
503 sum += qAbs(m_barSets.at(set)->at(category));
503 sum += qAbs(m_barSets.at(set)->at(category));
504 }
504 }
505 return sum;
505 return sum;
506 }
506 }
507
507
508 qreal QAbstractBarSeriesPrivate::maxCategorySum()
508 qreal QAbstractBarSeriesPrivate::maxCategorySum()
509 {
509 {
510 qreal max = INT_MIN;
510 qreal max = INT_MIN;
511 int count = categoryCount();
511 int count = categoryCount();
512 for (int i = 0; i < count; i++) {
512 for (int i = 0; i < count; i++) {
513 qreal sum = categorySum(i);
513 qreal sum = categorySum(i);
514 if (sum > max)
514 if (sum > max)
515 max = sum;
515 max = sum;
516 }
516 }
517 return max;
517 return max;
518 }
518 }
519
519
520 qreal QAbstractBarSeriesPrivate::minX()
520 qreal QAbstractBarSeriesPrivate::minX()
521 {
521 {
522 if (m_barSets.count() <= 0) {
522 if (m_barSets.count() <= 0) {
523 return 0;
523 return 0;
524 }
524 }
525 qreal min = INT_MAX;
525 qreal min = INT_MAX;
526
526
527 for (int i = 0; i < m_barSets.count(); i++) {
527 for (int i = 0; i < m_barSets.count(); i++) {
528 int categoryCount = m_barSets.at(i)->count();
528 int categoryCount = m_barSets.at(i)->count();
529 for (int j = 0; j < categoryCount; j++) {
529 for (int j = 0; j < categoryCount; j++) {
530 qreal temp = m_barSets.at(i)->d_ptr.data()->m_values.at(j).x();
530 qreal temp = m_barSets.at(i)->d_ptr.data()->m_values.at(j).x();
531 if (temp < min)
531 if (temp < min)
532 min = temp;
532 min = temp;
533 }
533 }
534 }
534 }
535 return min;
535 return min;
536 }
536 }
537
537
538 qreal QAbstractBarSeriesPrivate::maxX()
538 qreal QAbstractBarSeriesPrivate::maxX()
539 {
539 {
540 if (m_barSets.count() <= 0) {
540 if (m_barSets.count() <= 0) {
541 return 0;
541 return 0;
542 }
542 }
543 qreal max = INT_MIN;
543 qreal max = INT_MIN;
544
544
545 for (int i = 0; i < m_barSets.count(); i++) {
545 for (int i = 0; i < m_barSets.count(); i++) {
546 int categoryCount = m_barSets.at(i)->count();
546 int categoryCount = m_barSets.at(i)->count();
547 for (int j = 0; j < categoryCount; j++) {
547 for (int j = 0; j < categoryCount; j++) {
548 qreal temp = m_barSets.at(i)->d_ptr.data()->m_values.at(j).x();
548 qreal temp = m_barSets.at(i)->d_ptr.data()->m_values.at(j).x();
549 if (temp > max)
549 if (temp > max)
550 max = temp;
550 max = temp;
551 }
551 }
552 }
552 }
553
553
554 return max;
554 return max;
555 }
555 }
556
556
557
557
558 void QAbstractBarSeriesPrivate::scaleDomain(Domain& domain)
558 void QAbstractBarSeriesPrivate::scaleDomain(Domain& domain)
559 {
559 {
560 qreal minX(domain.minX());
560 qreal minX(domain.minX());
561 qreal minY(domain.minY());
561 qreal minY(domain.minY());
562 qreal maxX(domain.maxX());
562 qreal maxX(domain.maxX());
563 qreal maxY(domain.maxY());
563 qreal maxY(domain.maxY());
564 int tickXCount(domain.tickXCount());
564 int tickXCount(domain.tickXCount());
565 int tickYCount(domain.tickYCount());
565 int tickYCount(domain.tickYCount());
566
566
567 qreal seriesMinX = this->minX();
567 qreal seriesMinX = this->minX();
568 qreal seriesMaxX = this->maxX();
568 qreal seriesMaxX = this->maxX();
569 qreal y = max();
569 qreal y = max();
570 minX = qMin(minX, seriesMinX - (qreal)0.5);
570 minX = qMin(minX, seriesMinX - (qreal)0.5);
571 minY = qMin(minY, y);
571 minY = qMin(minY, y);
572 maxX = qMax(maxX, seriesMaxX + (qreal)0.5);
572 maxX = qMax(maxX, seriesMaxX + (qreal)0.5);
573 maxY = qMax(maxY, y);
573 maxY = qMax(maxY, y);
574 tickXCount = categoryCount()+1;
574 tickXCount = categoryCount()+1;
575
575
576 domain.setRange(minX,maxX,minY,maxY,tickXCount,tickYCount);
576 domain.setRange(minX,maxX,minY,maxY,tickXCount,tickYCount);
577 }
577 }
578
578
579 Chart* QAbstractBarSeriesPrivate::createGraphics(ChartPresenter* presenter)
579 Chart* QAbstractBarSeriesPrivate::createGraphics(ChartPresenter* presenter)
580 {
580 {
581 Q_UNUSED(presenter);
581 Q_UNUSED(presenter);
582 qWarning() << "QAbstractBarSeriesPrivate::createGraphics called";
582 qWarning() << "QAbstractBarSeriesPrivate::createGraphics called";
583 return 0;
583 return 0;
584 }
584 }
585
585
586 QList<LegendMarker*> QAbstractBarSeriesPrivate::createLegendMarker(QLegend* legend)
586 QList<LegendMarker*> QAbstractBarSeriesPrivate::createLegendMarker(QLegend* legend)
587 {
587 {
588 Q_Q(QAbstractBarSeries);
588 Q_Q(QAbstractBarSeries);
589 QList<LegendMarker*> markers;
589 QList<LegendMarker*> markers;
590 foreach(QBarSet* set, q->barSets()) {
590 foreach(QBarSet* set, q->barSets()) {
591 BarLegendMarker* marker = new BarLegendMarker(q,set,legend);
591 BarLegendMarker* marker = new BarLegendMarker(q,set,legend);
592 markers << marker;
592 markers << marker;
593 }
593 }
594
594
595 return markers;
595 return markers;
596 }
596 }
597
597
598 bool QAbstractBarSeriesPrivate::append(QBarSet *set)
598 bool QAbstractBarSeriesPrivate::append(QBarSet *set)
599 {
599 {
600 Q_Q(QAbstractBarSeries);
600 Q_Q(QAbstractBarSeries);
601 if ((m_barSets.contains(set)) || (set == 0)) {
601 if ((m_barSets.contains(set)) || (set == 0)) {
602 // Fail if set is already in list or set is null.
602 // Fail if set is already in list or set is null.
603 return false;
603 return false;
604 }
604 }
605 m_barSets.append(set);
605 m_barSets.append(set);
606 QObject::connect(set->d_ptr.data(), SIGNAL(updatedBars()), this, SIGNAL(updatedBars()));
606 QObject::connect(set->d_ptr.data(), SIGNAL(updatedBars()), this, SIGNAL(updatedBars()));
607 QObject::connect(set->d_ptr.data(), SIGNAL(restructuredBars()), this, SIGNAL(restructuredBars()));
607 QObject::connect(set->d_ptr.data(), SIGNAL(restructuredBars()), this, SIGNAL(restructuredBars()));
608 emit restructuredBars(); // this notifies barchartitem
608 emit restructuredBars(); // this notifies barchartitem
609 if (m_dataset) {
609 if (m_dataset) {
610 m_dataset->updateSeries(q); // this notifies legend
610 m_dataset->updateSeries(q); // this notifies legend
611 }
611 }
612 return true;
612 return true;
613 }
613 }
614
614
615 bool QAbstractBarSeriesPrivate::remove(QBarSet *set)
615 bool QAbstractBarSeriesPrivate::remove(QBarSet *set)
616 {
616 {
617 Q_Q(QAbstractBarSeries);
617 Q_Q(QAbstractBarSeries);
618 if (!m_barSets.contains(set)) {
618 if (!m_barSets.contains(set)) {
619 // Fail if set is not in list
619 // Fail if set is not in list
620 return false;
620 return false;
621 }
621 }
622 m_barSets.removeOne(set);
622 m_barSets.removeOne(set);
623 QObject::disconnect(set->d_ptr.data(), SIGNAL(updatedBars()), this, SIGNAL(updatedBars()));
623 QObject::disconnect(set->d_ptr.data(), SIGNAL(updatedBars()), this, SIGNAL(updatedBars()));
624 QObject::disconnect(set->d_ptr.data(), SIGNAL(restructuredBars()), this, SIGNAL(restructuredBars()));
624 QObject::disconnect(set->d_ptr.data(), SIGNAL(restructuredBars()), this, SIGNAL(restructuredBars()));
625 emit restructuredBars(); // this notifies barchartitem
625 emit restructuredBars(); // this notifies barchartitem
626 if (m_dataset) {
626 if (m_dataset) {
627 m_dataset->updateSeries(q); // this notifies legend
627 m_dataset->updateSeries(q); // this notifies legend
628 }
628 }
629 return true;
629 return true;
630 }
630 }
631
631
632 bool QAbstractBarSeriesPrivate::append(QList<QBarSet* > sets)
632 bool QAbstractBarSeriesPrivate::append(QList<QBarSet* > sets)
633 {
633 {
634 Q_Q(QAbstractBarSeries);
634 Q_Q(QAbstractBarSeries);
635 foreach (QBarSet* set, sets) {
635 foreach (QBarSet* set, sets) {
636 if ((set == 0) || (m_barSets.contains(set))) {
636 if ((set == 0) || (m_barSets.contains(set))) {
637 // Fail if any of the sets is null or is already appended.
637 // Fail if any of the sets is null or is already appended.
638 return false;
638 return false;
639 }
639 }
640 if (sets.count(set) != 1) {
640 if (sets.count(set) != 1) {
641 // Also fail if same set is more than once in given list.
641 // Also fail if same set is more than once in given list.
642 return false;
642 return false;
643 }
643 }
644 }
644 }
645
645
646 foreach (QBarSet* set, sets) {
646 foreach (QBarSet* set, sets) {
647 m_barSets.append(set);
647 m_barSets.append(set);
648 QObject::connect(set->d_ptr.data(), SIGNAL(updatedBars()), this, SIGNAL(updatedBars()));
648 QObject::connect(set->d_ptr.data(), SIGNAL(updatedBars()), this, SIGNAL(updatedBars()));
649 QObject::connect(set->d_ptr.data(), SIGNAL(restructuredBars()), this, SIGNAL(restructuredBars()));
649 QObject::connect(set->d_ptr.data(), SIGNAL(restructuredBars()), this, SIGNAL(restructuredBars()));
650 }
650 }
651 emit restructuredBars(); // this notifies barchartitem
651 emit restructuredBars(); // this notifies barchartitem
652 if (m_dataset) {
652 if (m_dataset) {
653 m_dataset->updateSeries(q); // this notifies legend
653 m_dataset->updateSeries(q); // this notifies legend
654 }
654 }
655 return true;
655 return true;
656 }
656 }
657
657
658 bool QAbstractBarSeriesPrivate::remove(QList<QBarSet* > sets)
658 bool QAbstractBarSeriesPrivate::remove(QList<QBarSet* > sets)
659 {
659 {
660 Q_Q(QAbstractBarSeries);
660 Q_Q(QAbstractBarSeries);
661 if (sets.count() == 0) {
661 if (sets.count() == 0) {
662 return false;
662 return false;
663 }
663 }
664 foreach (QBarSet* set, sets) {
664 foreach (QBarSet* set, sets) {
665 if ((set == 0) || (!m_barSets.contains(set))) {
665 if ((set == 0) || (!m_barSets.contains(set))) {
666 // Fail if any of the sets is null or is not in series
666 // Fail if any of the sets is null or is not in series
667 return false;
667 return false;
668 }
668 }
669 if (sets.count(set) != 1) {
669 if (sets.count(set) != 1) {
670 // Also fail if same set is more than once in given list.
670 // Also fail if same set is more than once in given list.
671 return false;
671 return false;
672 }
672 }
673 }
673 }
674
674
675 foreach (QBarSet* set, sets) {
675 foreach (QBarSet* set, sets) {
676 m_barSets.removeOne(set);
676 m_barSets.removeOne(set);
677 QObject::disconnect(set->d_ptr.data(), SIGNAL(updatedBars()), this, SIGNAL(updatedBars()));
677 QObject::disconnect(set->d_ptr.data(), SIGNAL(updatedBars()), this, SIGNAL(updatedBars()));
678 QObject::disconnect(set->d_ptr.data(), SIGNAL(restructuredBars()), this, SIGNAL(restructuredBars()));
678 QObject::disconnect(set->d_ptr.data(), SIGNAL(restructuredBars()), this, SIGNAL(restructuredBars()));
679 }
679 }
680
680
681 emit restructuredBars(); // this notifies barchartitem
681 emit restructuredBars(); // this notifies barchartitem
682 if (m_dataset) {
682 if (m_dataset) {
683 m_dataset->updateSeries(q); // this notifies legend
683 m_dataset->updateSeries(q); // this notifies legend
684 }
684 }
685 return true;
685 return true;
686 }
686 }
687
687
688 bool QAbstractBarSeriesPrivate::insert(int index, QBarSet *set)
688 bool QAbstractBarSeriesPrivate::insert(int index, QBarSet *set)
689 {
689 {
690 Q_Q(QAbstractBarSeries);
690 Q_Q(QAbstractBarSeries);
691 if ((m_barSets.contains(set)) || (set == 0)) {
691 if ((m_barSets.contains(set)) || (set == 0)) {
692 // Fail if set is already in list or set is null.
692 // Fail if set is already in list or set is null.
693 return false;
693 return false;
694 }
694 }
695 m_barSets.insert(index, set);
695 m_barSets.insert(index, set);
696 QObject::connect(set->d_ptr.data(), SIGNAL(updatedBars()), this, SIGNAL(updatedBars()));
696 QObject::connect(set->d_ptr.data(), SIGNAL(updatedBars()), this, SIGNAL(updatedBars()));
697 QObject::connect(set->d_ptr.data(), SIGNAL(restructuredBars()), this, SIGNAL(restructuredBars()));
697 QObject::connect(set->d_ptr.data(), SIGNAL(restructuredBars()), this, SIGNAL(restructuredBars()));
698 emit restructuredBars(); // this notifies barchartitem
698 emit restructuredBars(); // this notifies barchartitem
699 if (m_dataset) {
699 if (m_dataset) {
700 m_dataset->updateSeries(q); // this notifies legend
700 m_dataset->updateSeries(q); // this notifies legend
701 }
701 }
702 return true;
702 return true;
703 }
703 }
704
704
705 void QAbstractBarSeriesPrivate::initializeAxisX(QAbstractAxis* axis)
705 void QAbstractBarSeriesPrivate::initializeAxisX(QAbstractAxis* axis)
706 {
706 {
707 if(axis->type()==QAbstractAxis::AxisTypeCategories)
707 if(axis->type()==QAbstractAxis::AxisTypeCategories)
708 {
708 {
709 QBarCategoriesAxis* cataxis = qobject_cast<QBarCategoriesAxis*>(axis);
709 QBarCategoriesAxis* cataxis = qobject_cast<QBarCategoriesAxis*>(axis);
710 Q_ASSERT(cataxis);
710 Q_ASSERT(cataxis);
711 QStringList categories;
711 QStringList categories;
712 for (int i(1); i < categoryCount()+1; i++)
712 for (int i(1); i < categoryCount()+1; i++)
713 categories << QString::number(i);
713 categories << QString::number(i);
714 cataxis->append(categories);
714 cataxis->append(categories);
715 }
715 }
716 }
716 }
717
717
718 void QAbstractBarSeriesPrivate::initializeAxisY(QAbstractAxis* axis)
718 void QAbstractBarSeriesPrivate::initializeAxisY(QAbstractAxis* axis)
719 {
719 {
720 Q_UNUSED(axis)
720 Q_UNUSED(axis)
721 }
721 }
722
722
723 QAbstractAxis::AxisType QAbstractBarSeriesPrivate::defaultAxisXType() const
723 QAbstractAxis::AxisType QAbstractBarSeriesPrivate::defaultAxisXType() const
724 {
724 {
725 return QAbstractAxis::AxisTypeCategories;
725 return QAbstractAxis::AxisTypeNoAxis;
726 }
726 }
727
727
728 QAbstractAxis::AxisType QAbstractBarSeriesPrivate::defaultAxisYType() const
728 QAbstractAxis::AxisType QAbstractBarSeriesPrivate::defaultAxisYType() const
729 {
729 {
730 return QAbstractAxis::AxisTypeValues;
730 return QAbstractAxis::AxisTypeNoAxis;
731 }
731 }
732
732
733 #include "moc_qabstractbarseries.cpp"
733 #include "moc_qabstractbarseries.cpp"
734 #include "moc_qabstractbarseries_p.cpp"
734 #include "moc_qabstractbarseries_p.cpp"
735
735
736
736
737 QTCOMMERCIALCHART_END_NAMESPACE
737 QTCOMMERCIALCHART_END_NAMESPACE
@@ -1,82 +1,83
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 #ifndef ABSTRACTBARSERIES_H
21 #ifndef ABSTRACTBARSERIES_H
22 #define ABSTRACTBARSERIES_H
22 #define ABSTRACTBARSERIES_H
23
23
24 #include <qabstractseries.h>
24 #include <qabstractseries.h>
25 #include <QStringList>
25 #include <QStringList>
26
26
27 QTCOMMERCIALCHART_BEGIN_NAMESPACE
27 QTCOMMERCIALCHART_BEGIN_NAMESPACE
28
28
29 class QBarSet;
29 class QBarSet;
30 class QAbstractBarSeriesPrivate;
30 class QAbstractBarSeriesPrivate;
31
31
32 // Container for series
32 // Container for series
33 class QTCOMMERCIALCHART_EXPORT QAbstractBarSeries : public QAbstractSeries
33 class QTCOMMERCIALCHART_EXPORT QAbstractBarSeries : public QAbstractSeries
34 {
34 {
35 Q_OBJECT
35 Q_OBJECT
36 Q_PROPERTY(qreal barWidth READ barWidth WRITE setBarWidth)
36 Q_PROPERTY(qreal barWidth READ barWidth WRITE setBarWidth)
37 Q_PROPERTY(int count READ count NOTIFY countChanged)
37 Q_PROPERTY(int count READ count NOTIFY countChanged)
38 Q_PROPERTY(bool labelsVisible READ isLabelsVisible WRITE setLabelsVisible NOTIFY labelsVisibleChanged)
38 Q_PROPERTY(bool labelsVisible READ isLabelsVisible WRITE setLabelsVisible NOTIFY labelsVisibleChanged)
39
39
40 protected:
40 protected:
41 explicit QAbstractBarSeries(QObject *parent = 0);
41 explicit QAbstractBarSeries(QObject *parent = 0);
42
42
43 public:
43 public:
44 virtual ~QAbstractBarSeries();
44 virtual ~QAbstractBarSeries();
45
45
46 void setBarWidth(qreal width);
46 void setBarWidth(qreal width);
47 qreal barWidth() const;
47 qreal barWidth() const;
48
48
49 bool append(QBarSet *set);
49 bool append(QBarSet *set);
50 bool remove(QBarSet *set);
50 bool remove(QBarSet *set);
51 bool append(QList<QBarSet* > sets);
51 bool append(QList<QBarSet* > sets);
52 bool insert(int index, QBarSet *set);
52 bool insert(int index, QBarSet *set);
53 int count() const;
53 int count() const;
54 QList<QBarSet*> barSets() const;
54 QList<QBarSet*> barSets() const;
55 void clear();
55 void clear();
56
56
57 void setLabelsVisible(bool visible = true);
57 void setLabelsVisible(bool visible = true);
58 bool isLabelsVisible() const;
58 bool isLabelsVisible() const;
59
59
60 protected:
60 protected:
61 explicit QAbstractBarSeries(QAbstractBarSeriesPrivate &d,QObject *parent = 0);
61 explicit QAbstractBarSeries(QAbstractBarSeriesPrivate &d,QObject *parent = 0);
62
62
63 Q_SIGNALS:
63 Q_SIGNALS:
64 void clicked(int index, QBarSet *barset);
64 void clicked(int index, QBarSet *barset);
65 void hovered(bool status, QBarSet *barset);
65 void hovered(bool status, QBarSet *barset);
66 void countChanged();
66 void countChanged();
67 void labelsVisibleChanged();
67 void labelsVisibleChanged();
68
68
69 void barsetsAdded(QList<QBarSet*> sets);
69 void barsetsAdded(QList<QBarSet*> sets);
70 void barsetsRemoved(QList<QBarSet*> sets);
70 void barsetsRemoved(QList<QBarSet*> sets);
71
71
72 protected:
72 protected:
73 Q_DECLARE_PRIVATE(QAbstractBarSeries)
73 Q_DECLARE_PRIVATE(QAbstractBarSeries)
74 friend class AbstractBarChartItem;
74 friend class AbstractBarChartItem;
75 friend class PercentBarChartItem;
75 friend class PercentBarChartItem;
76 friend class StackedBarChartItem;
76 friend class StackedBarChartItem;
77 friend class BarChartItem;
77 friend class BarChartItem;
78 friend class HorizontalBarChartItem;
78 };
79 };
79
80
80 QTCOMMERCIALCHART_END_NAMESPACE
81 QTCOMMERCIALCHART_END_NAMESPACE
81
82
82 #endif // ABSTRACTBARSERIES_H
83 #endif // ABSTRACTBARSERIES_H
@@ -1,119 +1,129
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 "chartanimator_p.h"
26 #include "chartanimator_p.h"
27 #include "baranimation_p.h"
27 #include "baranimation_p.h"
28 #include "qvaluesaxis.h"
28 #include "qvaluesaxis.h"
29
29
30 QTCOMMERCIALCHART_BEGIN_NAMESPACE
30 QTCOMMERCIALCHART_BEGIN_NAMESPACE
31
31
32 /*!
32 /*!
33 \class QBarSeries
33 \class QBarSeries
34 \brief Series for creating bar chart
34 \brief Series for creating bar chart
35 \mainclass
35 \mainclass
36
36
37 QBarSeries represents a series of data shown as bars. The purpose of this class is to draw bars
37 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
38 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.
39 from sets to categories, which are defined by a QStringList.
40
40
41 See the \l {BarChart Example} {bar chart example} to learn how to create a grouped bar chart.
41 See the \l {BarChart Example} {bar chart example} to learn how to create a grouped bar chart.
42 \image examples_barchart.png
42 \image examples_barchart.png
43
43
44 \sa QBarSet, QPercentBarSeries, QAbstractBarSeries, QStackedBarSeries
44 \sa QBarSet, QPercentBarSeries, QAbstractBarSeries, QStackedBarSeries
45 */
45 */
46 /*!
46 /*!
47 \qmlclass BarSeries QBarSeries
47 \qmlclass BarSeries QBarSeries
48 \inherits AbstractBarSeries
48 \inherits AbstractBarSeries
49
49
50 The following QML shows how to create a simple grouped bar chart:
50 The following QML shows how to create a simple grouped bar chart:
51 \snippet ../demos/qmlchart/qml/qmlchart/View6.qml 1
51 \snippet ../demos/qmlchart/qml/qmlchart/View6.qml 1
52 \beginfloatleft
52 \beginfloatleft
53 \image demos_qmlchart6.png
53 \image demos_qmlchart6.png
54 \endfloat
54 \endfloat
55 \clearfloat
55 \clearfloat
56 */
56 */
57
57
58 /*!
58 /*!
59 Constructs empty QBarSeries.
59 Constructs empty QBarSeries.
60 QBarSeries is QObject which is a child of a \a parent.
60 QBarSeries is QObject which is a child of a \a parent.
61 */
61 */
62 QBarSeries::QBarSeries(QObject *parent)
62 QBarSeries::QBarSeries(QObject *parent)
63 : QAbstractBarSeries(*new QBarSeriesPrivate(this), parent)
63 : QAbstractBarSeries(*new QBarSeriesPrivate(this), parent)
64 {
64 {
65 }
65 }
66
66
67 /*!
67 /*!
68 Returns QChartSeries::SeriesTypeBar.
68 Returns QChartSeries::SeriesTypeBar.
69 */
69 */
70 QAbstractSeries::SeriesType QBarSeries::type() const
70 QAbstractSeries::SeriesType QBarSeries::type() const
71 {
71 {
72 return QAbstractSeries::SeriesTypeBar;
72 return QAbstractSeries::SeriesTypeBar;
73 }
73 }
74
74
75 ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
75 ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
76
76
77 QBarSeriesPrivate::QBarSeriesPrivate(QBarSeries *q) : QAbstractBarSeriesPrivate(q)
77 QBarSeriesPrivate::QBarSeriesPrivate(QBarSeries *q) : QAbstractBarSeriesPrivate(q)
78 {
78 {
79
79
80 }
80 }
81
81
82 void QBarSeriesPrivate::scaleDomain(Domain& domain)
82 void QBarSeriesPrivate::scaleDomain(Domain& domain)
83 {
83 {
84 qreal minX(domain.minX());
84 qreal minX(domain.minX());
85 qreal minY(domain.minY());
85 qreal minY(domain.minY());
86 qreal maxX(domain.maxX());
86 qreal maxX(domain.maxX());
87 qreal maxY(domain.maxY());
87 qreal maxY(domain.maxY());
88 int tickXCount(domain.tickXCount());
88 int tickXCount(domain.tickXCount());
89 int tickYCount(domain.tickYCount());
89 int tickYCount(domain.tickYCount());
90
90
91 qreal x = categoryCount();
91 qreal x = categoryCount();
92 qreal y = max();
92 qreal y = max();
93 minX = qMin(minX, - (qreal)0.5);
93 minX = qMin(minX, - (qreal)0.5);
94 minY = qMin(minY, y);
94 minY = qMin(minY, y);
95 maxX = qMax(maxX, x - (qreal)0.5);
95 maxX = qMax(maxX, x - (qreal)0.5);
96 maxY = qMax(maxY, y);
96 maxY = qMax(maxY, y);
97 tickXCount = x+1;
97 tickXCount = x+1;
98
98
99 domain.setRange(minX,maxX,minY,maxY,tickXCount,tickYCount);
99 domain.setRange(minX,maxX,minY,maxY,tickXCount,tickYCount);
100 }
100 }
101
101
102
102
103 Chart* QBarSeriesPrivate::createGraphics(ChartPresenter* presenter)
103 Chart* QBarSeriesPrivate::createGraphics(ChartPresenter* presenter)
104 {
104 {
105 Q_Q(QBarSeries);
105 Q_Q(QBarSeries);
106
106
107 BarChartItem* bar = new BarChartItem(q,presenter);
107 BarChartItem* bar = new BarChartItem(q,presenter);
108 if(presenter->animationOptions().testFlag(QChart::SeriesAnimations)) {
108 if(presenter->animationOptions().testFlag(QChart::SeriesAnimations)) {
109 bar->setAnimator(presenter->animator());
109 bar->setAnimator(presenter->animator());
110 bar->setAnimation(new BarAnimation(bar));
110 bar->setAnimation(new BarAnimation(bar));
111 }
111 }
112 presenter->chartTheme()->decorate(q, presenter->dataSet()->seriesIndex(q));
112 presenter->chartTheme()->decorate(q, presenter->dataSet()->seriesIndex(q));
113 return bar;
113 return bar;
114 }
114 }
115
115
116 QAbstractAxis::AxisType QBarSeriesPrivate::defaultAxisXType() const
117 {
118 return QAbstractAxis::AxisTypeCategories;
119 }
120
121 QAbstractAxis::AxisType QBarSeriesPrivate::defaultAxisYType() const
122 {
123 return QAbstractAxis::AxisTypeValues;
124 }
125
116 #include "moc_qbarseries.cpp"
126 #include "moc_qbarseries.cpp"
117
127
118 QTCOMMERCIALCHART_END_NAMESPACE
128 QTCOMMERCIALCHART_END_NAMESPACE
119
129
@@ -1,45 +1,44
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 #ifndef QBARSERIES_H
21 #ifndef QBARSERIES_H
22 #define QBARSERIES_H
22 #define QBARSERIES_H
23
23
24 #include <QStringList>
25 #include <qabstractbarseries.h>
24 #include <qabstractbarseries.h>
26
25
27 QTCOMMERCIALCHART_BEGIN_NAMESPACE
26 QTCOMMERCIALCHART_BEGIN_NAMESPACE
28
27
29 class QBarSeriesPrivate;
28 class QBarSeriesPrivate;
30
29
31 class QTCOMMERCIALCHART_EXPORT QBarSeries : public QAbstractBarSeries
30 class QTCOMMERCIALCHART_EXPORT QBarSeries : public QAbstractBarSeries
32 {
31 {
33 Q_OBJECT
32 Q_OBJECT
34 public:
33 public:
35 explicit QBarSeries(QObject *parent = 0);
34 explicit QBarSeries(QObject *parent = 0);
36 QAbstractSeries::SeriesType type() const;
35 QAbstractSeries::SeriesType type() const;
37
36
38 private:
37 private:
39 Q_DECLARE_PRIVATE(QBarSeries)
38 Q_DECLARE_PRIVATE(QBarSeries)
40 Q_DISABLE_COPY(QBarSeries)
39 Q_DISABLE_COPY(QBarSeries)
41 };
40 };
42
41
43 QTCOMMERCIALCHART_END_NAMESPACE
42 QTCOMMERCIALCHART_END_NAMESPACE
44
43
45 #endif // QBARSERIES_H
44 #endif // QBARSERIES_H
@@ -1,52 +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 #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 "domain_p.h"
34 #include "domain_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 Chart* createGraphics(ChartPresenter* presenter);
43 Chart* createGraphics(ChartPresenter* presenter);
44 void scaleDomain(Domain& domain);
44 void scaleDomain(Domain& domain);
45
45
46 QAbstractAxis::AxisType defaultAxisXType() const;
47 QAbstractAxis::AxisType defaultAxisYType() const;
48
46 private:
49 private:
47 Q_DECLARE_PUBLIC(QBarSeries)
50 Q_DECLARE_PUBLIC(QBarSeries)
48 };
51 };
49
52
50 QTCOMMERCIALCHART_END_NAMESPACE
53 QTCOMMERCIALCHART_END_NAMESPACE
51
54
52 #endif // QBARSERIES_P_H
55 #endif // QBARSERIES_P_H
@@ -1,627 +1,635
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 "qbarset.h"
21 #include "qbarset.h"
22 #include "qbarset_p.h"
22 #include "qbarset_p.h"
23
23
24 QTCOMMERCIALCHART_BEGIN_NAMESPACE
24 QTCOMMERCIALCHART_BEGIN_NAMESPACE
25
25
26 /*!
26 /*!
27 \class QBarSet
27 \class QBarSet
28 \brief Building block for different bar charts
28 \brief Building block for different bar charts
29
29
30 QBarSet represents one set of bars. Set of bars contains one data value for each category.
30 QBarSet represents one set of bars. Set of bars contains one data value for each category.
31 First value of set is assumed to belong to first category, second to second category and so on.
31 First value of set is assumed to belong to first category, second to second category and so on.
32 If set has fewer values than there are categories, then the missing values are assumed to be
32 If set has fewer values than there are categories, then the missing values are assumed to be
33 at the end of set. For missing values in middle of a set, numerical value of zero is used.
33 at the end of set. For missing values in middle of a set, numerical value of zero is used.
34
34
35 \mainclass
35 \mainclass
36
36
37 \sa QAbstractBarSeries, QBarSeries, QStackedBarSeries, QPercentBarSeries
37 \sa QAbstractBarSeries, QBarSeries, QStackedBarSeries, QPercentBarSeries
38 */
38 */
39 /*!
39 /*!
40 \qmlclass BarSet QBarSet
40 \qmlclass BarSet QBarSet
41
41
42 BarSet represents one set of bars. Set of bars contains one data value for each category.
42 BarSet represents one set of bars. Set of bars contains one data value for each category.
43 First value of set is assumed to belong to first category, second to second category and so on.
43 First value of set is assumed to belong to first category, second to second category and so on.
44 If set has fewer values than there are categories, then the missing values are assumed to be
44 If set has fewer values than there are categories, then the missing values are assumed to be
45 at the end of set. For missing values in middle of a set, numerical value of zero is used.
45 at the end of set. For missing values in middle of a set, numerical value of zero is used.
46 \sa AbstractBarSeries, BarSeries, StackedBarSeries, PercentBarSeries
46 \sa AbstractBarSeries, BarSeries, StackedBarSeries, PercentBarSeries
47 */
47 */
48
48
49 /*!
49 /*!
50 \property QBarSet::label
50 \property QBarSet::label
51 Defines the label of the barSet.
51 Defines the label of the barSet.
52 */
52 */
53 /*!
53 /*!
54 \qmlproperty string BarSet::label
54 \qmlproperty string BarSet::label
55 Defines the label of the barSet.
55 Defines the label of the barSet.
56 */
56 */
57
57
58 /*!
58 /*!
59 \property QBarSet::pen
59 \property QBarSet::pen
60 \brief Defines the pen used by the barSet.
60 \brief Defines the pen used by the barSet.
61 */
61 */
62
62
63 /*!
63 /*!
64 \property QBarSet::brush
64 \property QBarSet::brush
65 \brief Defines the brush used by the barSet.
65 \brief Defines the brush used by the barSet.
66 */
66 */
67
67
68 /*!
68 /*!
69 \property QBarSet::labelBrush
69 \property QBarSet::labelBrush
70 \brief Defines the brush used by the barSet's label.
70 \brief Defines the brush used by the barSet's label.
71 */
71 */
72
72
73 /*!
73 /*!
74 \property QBarSet::labelFont
74 \property QBarSet::labelFont
75 \brief Defines the font used by the barSet's label.
75 \brief Defines the font used by the barSet's label.
76 */
76 */
77
77
78 /*!
78 /*!
79 \qmlproperty Font BarSet::labelFont
79 \qmlproperty Font BarSet::labelFont
80 Defines the font used by the barSet's label.
80 Defines the font used by the barSet's label.
81
81
82 See the \l {Font} {QML Font Element} for detailed documentation.
82 See the \l {Font} {QML Font Element} for detailed documentation.
83 */
83 */
84
84
85 /*!
85 /*!
86 \property QBarSet::color
86 \property QBarSet::color
87 The fill (brush) color of the bar set.
87 The fill (brush) color of the bar set.
88 */
88 */
89 /*!
89 /*!
90 \qmlproperty color BarSet::color
90 \qmlproperty color BarSet::color
91 The fill (brush) color of the bar set.
91 The fill (brush) color of the bar set.
92 */
92 */
93
93
94 /*!
94 /*!
95 \property QBarSet::borderColor
95 \property QBarSet::borderColor
96 The line (pen) color of the bar set.
96 The line (pen) color of the bar set.
97 */
97 */
98 /*!
98 /*!
99 \qmlproperty color BarSet::borderColor
99 \qmlproperty color BarSet::borderColor
100 The line (pen) color of the bar set.
100 The line (pen) color of the bar set.
101 */
101 */
102
102
103 /*!
103 /*!
104 \property QBarSet::labelColor
104 \property QBarSet::labelColor
105 The text (label) color of the bar set.
105 The text (label) color of the bar set.
106 */
106 */
107 /*!
107 /*!
108 \qmlproperty color BarSet::labelColor
108 \qmlproperty color BarSet::labelColor
109 The text (label) color of the bar set.
109 The text (label) color of the bar set.
110 */
110 */
111
111
112 /*!
112 /*!
113 \fn void QBarSet::clicked(int index)
113 \fn void QBarSet::clicked(int index)
114
114
115 The signal is emitted if the user clicks with a mouse on top of barset.
115 The signal is emitted if the user clicks with a mouse on top of barset.
116 Clicked bar inside set is indexed by \a index
116 Clicked bar inside set is indexed by \a index
117 */
117 */
118
118
119 /*!
119 /*!
120 \fn void QBarSet::hovered(bool status)
120 \fn void QBarSet::hovered(bool status)
121
121
122 The signal is emitted if mouse is hovered on top of barset.
122 The signal is emitted if mouse is hovered on top of barset.
123 Parameter \a status is true, if mouse entered on top of barset, false if mouse left from top of barset.
123 Parameter \a status is true, if mouse entered on top of barset, false if mouse left from top of barset.
124 */
124 */
125
125
126
126
127 /*!
127 /*!
128 \fn void QBarSet::labelChanged()
128 \fn void QBarSet::labelChanged()
129 This signal is emitted when the label of the barSet has changed.
129 This signal is emitted when the label of the barSet has changed.
130 \sa label
130 \sa label
131 */
131 */
132 /*!
132 /*!
133 \qmlsignal BarSet::onLabelChanged()
133 \qmlsignal BarSet::onLabelChanged()
134 This signal is emitted when the label of the barSet has changed.
134 This signal is emitted when the label of the barSet has changed.
135 */
135 */
136
136
137 /*!
137 /*!
138 \fn void QBarSet::penChanged()
138 \fn void QBarSet::penChanged()
139 This signal is emitted when the pen of the barSet has changed.
139 This signal is emitted when the pen of the barSet has changed.
140 \sa pen
140 \sa pen
141 */
141 */
142
142
143 /*!
143 /*!
144 \fn void QBarSet::brushChanged()
144 \fn void QBarSet::brushChanged()
145 This signal is emitted when the brush of the barSet has changed.
145 This signal is emitted when the brush of the barSet has changed.
146 \sa brush
146 \sa brush
147 */
147 */
148
148
149 /*!
149 /*!
150 \fn void QBarSet::labelBrushChanged()
150 \fn void QBarSet::labelBrushChanged()
151 This signal is emitted when the brush of the barSet's label has changed.
151 This signal is emitted when the brush of the barSet's label has changed.
152 \sa labelBrush
152 \sa labelBrush
153 */
153 */
154
154
155 /*!
155 /*!
156 \fn void QBarSet::labelFontChanged()
156 \fn void QBarSet::labelFontChanged()
157 This signal is emitted when the font of the barSet's label has changed.
157 This signal is emitted when the font of the barSet's label has changed.
158 \sa labelBrush
158 \sa labelBrush
159 */
159 */
160
160
161 /*!
161 /*!
162 \fn void QBarSet::colorChanged(QColor)
162 \fn void QBarSet::colorChanged(QColor)
163 This signal is emitted when the fill (brush) color of the set has changed to \a color.
163 This signal is emitted when the fill (brush) color of the set has changed to \a color.
164 */
164 */
165 /*!
165 /*!
166 \qmlsignal BarSet::onColorChanged(color color)
166 \qmlsignal BarSet::onColorChanged(color color)
167 This signal is emitted when the fill (brush) color of the set has changed to \a color.
167 This signal is emitted when the fill (brush) color of the set has changed to \a color.
168 */
168 */
169
169
170 /*!
170 /*!
171 \fn void QBarSet::borderColorChanged(QColor)
171 \fn void QBarSet::borderColorChanged(QColor)
172 This signal is emitted when the line (pen) color of the set has changed to \a color.
172 This signal is emitted when the line (pen) color of the set has changed to \a color.
173 */
173 */
174 /*!
174 /*!
175 \qmlsignal BarSet::onBorderColorChanged(color color)
175 \qmlsignal BarSet::onBorderColorChanged(color color)
176 This signal is emitted when the line (pen) color of the set has changed to \a color.
176 This signal is emitted when the line (pen) color of the set has changed to \a color.
177 */
177 */
178
178
179 /*!
179 /*!
180 \fn void QBarSet::labelColorChanged(QColor)
180 \fn void QBarSet::labelColorChanged(QColor)
181 This signal is emitted when the text (label) color of the set has changed to \a color.
181 This signal is emitted when the text (label) color of the set has changed to \a color.
182 */
182 */
183 /*!
183 /*!
184 \qmlsignal BarSet::onLabelColorChanged(color color)
184 \qmlsignal BarSet::onLabelColorChanged(color color)
185 This signal is emitted when the text (label) color of the set has changed to \a color.
185 This signal is emitted when the text (label) color of the set has changed to \a color.
186 */
186 */
187
187
188 /*!
188 /*!
189 \fn void QBarSet::valuesAdded(int index, int count)
189 \fn void QBarSet::valuesAdded(int index, int count)
190 This signal is emitted when new values have been added to the set.
190 This signal is emitted when new values have been added to the set.
191 Parameter \a index indicates the position of the first inserted value.
191 Parameter \a index indicates the position of the first inserted value.
192 Parameter \a count is the number of iserted values.
192 Parameter \a count is the number of iserted values.
193 \sa append(), insert()
193 \sa append(), insert()
194 */
194 */
195 /*!
195 /*!
196 \qmlsignal BarSet::onValuesAdded(int index, int count)
196 \qmlsignal BarSet::onValuesAdded(int index, int count)
197 This signal is emitted when new values have been added to the set.
197 This signal is emitted when new values have been added to the set.
198 Parameter \a index indicates the position of the first inserted value.
198 Parameter \a index indicates the position of the first inserted value.
199 Parameter \a count is the number of iserted values.
199 Parameter \a count is the number of iserted values.
200 */
200 */
201
201
202 /*!
202 /*!
203 \fn void QBarSet::valuesRemoved(int index, int count)
203 \fn void QBarSet::valuesRemoved(int index, int count)
204 This signal is emitted values have been removed from the set.
204 This signal is emitted values have been removed from the set.
205 Parameter \a index indicates the position of the first removed value.
205 Parameter \a index indicates the position of the first removed value.
206 Parameter \a count is the number of removed values.
206 Parameter \a count is the number of removed values.
207 \sa remove()
207 \sa remove()
208 */
208 */
209 /*!
209 /*!
210 \qmlsignal BarSet::onValuesRemoved(int index, int count)
210 \qmlsignal BarSet::onValuesRemoved(int index, int count)
211 This signal is emitted values have been removed from the set.
211 This signal is emitted values have been removed from the set.
212 Parameter \a index indicates the position of the first removed value.
212 Parameter \a index indicates the position of the first removed value.
213 Parameter \a count is the number of removed values.
213 Parameter \a count is the number of removed values.
214 */
214 */
215
215
216 /*!
216 /*!
217 \fn void QBarSet::valueChanged(int index)
217 \fn void QBarSet::valueChanged(int index)
218 This signal is emitted values the value in the set has been modified.
218 This signal is emitted values the value in the set has been modified.
219 Parameter \a index indicates the position of the modified value.
219 Parameter \a index indicates the position of the modified value.
220 \sa at()
220 \sa at()
221 */
221 */
222 /*!
222 /*!
223 \qmlsignal BarSet::onValueChanged(int index)
223 \qmlsignal BarSet::onValueChanged(int index)
224 This signal is emitted values the value in the set has been modified.
224 This signal is emitted values the value in the set has been modified.
225 Parameter \a index indicates the position of the modified value.
225 Parameter \a index indicates the position of the modified value.
226 */
226 */
227
227
228 /*!
228 /*!
229 \qmlproperty int BarSet::count
229 \qmlproperty int BarSet::count
230 The count of values on the barset
230 The count of values on the barset
231 */
231 */
232
232
233 /*!
233 /*!
234 \qmlproperty QVariantList BarSet::values
234 \qmlproperty QVariantList BarSet::values
235 The values of the barset. You can set either a list of reals or a list of points as values. If you set a list of
235 The values of the barset. You can set either a list of reals or a list of points as values. If you set a list of
236 reals as values, the values are automatically completed to points by using the index of a value as it's
236 reals as values, the values are automatically completed to points by using the index of a value as it's
237 x-coordinate. For example:
237 x-coordinate. For example:
238 \code
238 \code
239 myBarSet1.values = [0, 5, 1, 5];
239 myBarSet1.values = [0, 5, 1, 5];
240 myBarSet2.values = [Qt.point(0, 1), Qt.point(1, 5), Qt.point(2.2, 4.3)];
240 myBarSet2.values = [Qt.point(0, 1), Qt.point(1, 5), Qt.point(2.2, 4.3)];
241 \endcode
241 \endcode
242 */
242 */
243
243
244 /*!
244 /*!
245 Constructs QBarSet with a label of \a label and with parent of \a parent
245 Constructs QBarSet with a label of \a label and with parent of \a parent
246 */
246 */
247 QBarSet::QBarSet(const QString label, QObject *parent)
247 QBarSet::QBarSet(const QString label, QObject *parent)
248 : QObject(parent)
248 : QObject(parent)
249 ,d_ptr(new QBarSetPrivate(label,this))
249 ,d_ptr(new QBarSetPrivate(label,this))
250 {
250 {
251 }
251 }
252
252
253 /*!
253 /*!
254 Destroys the barset
254 Destroys the barset
255 */
255 */
256 QBarSet::~QBarSet()
256 QBarSet::~QBarSet()
257 {
257 {
258 // NOTE: d_ptr destroyed by QObject
258 // NOTE: d_ptr destroyed by QObject
259 }
259 }
260
260
261 /*!
261 /*!
262 Sets new \a label for set.
262 Sets new \a label for set.
263 */
263 */
264 void QBarSet::setLabel(const QString label)
264 void QBarSet::setLabel(const QString label)
265 {
265 {
266 d_ptr->m_label = label;
266 d_ptr->m_label = label;
267 emit labelChanged();
267 emit labelChanged();
268 }
268 }
269
269
270 /*!
270 /*!
271 Returns label of the set.
271 Returns label of the set.
272 */
272 */
273 QString QBarSet::label() const
273 QString QBarSet::label() const
274 {
274 {
275 return d_ptr->m_label;
275 return d_ptr->m_label;
276 }
276 }
277
277
278 /*!
278 /*!
279 Appends new value \a value to the end of set.
279 Appends new value \a value to the end of set.
280 */
280 */
281 void QBarSet::append(const qreal value)
281 void QBarSet::append(const qreal value)
282 {
282 {
283 // Convert to QPointF
283 // Convert to QPointF
284 int index = d_ptr->m_values.count();
284 int index = d_ptr->m_values.count();
285 d_ptr->append(QPointF(d_ptr->m_values.count(), value));
285 d_ptr->append(QPointF(d_ptr->m_values.count(), value));
286 emit valuesAdded(index, 1);
286 emit valuesAdded(index, 1);
287 }
287 }
288
288
289 /*!
289 /*!
290 Appends a list of reals to set. Works like append with single real value. The \a values in list
290 Appends a list of reals to set. Works like append with single real value. The \a values in list
291 are appended to end of barset
291 are appended to end of barset
292 \sa append()
292 \sa append()
293 */
293 */
294 void QBarSet::append(const QList<qreal> &values)
294 void QBarSet::append(const QList<qreal> &values)
295 {
295 {
296 int index = d_ptr->m_values.count();
296 int index = d_ptr->m_values.count();
297 d_ptr->append(values);
297 d_ptr->append(values);
298 emit valuesAdded(index, values.count());
298 emit valuesAdded(index, values.count());
299 }
299 }
300
300
301 /*!
301 /*!
302 Convinience operator. Same as append, with real \a value.
302 Convinience operator. Same as append, with real \a value.
303 \sa append()
303 \sa append()
304 */
304 */
305 QBarSet& QBarSet::operator << (const qreal &value)
305 QBarSet& QBarSet::operator << (const qreal &value)
306 {
306 {
307 append(value);
307 append(value);
308 return *this;
308 return *this;
309 }
309 }
310
310
311 /*!
311 /*!
312 Inserts new \a value on the \a index position.
312 Inserts new \a value on the \a index position.
313 The value that is currently at this postion is moved to postion index + 1
313 The value that is currently at this postion is moved to postion index + 1
314 \sa remove()
314 \sa remove()
315 */
315 */
316 void QBarSet::insert(const int index, const qreal value)
316 void QBarSet::insert(const int index, const qreal value)
317 {
317 {
318 d_ptr->insert(index, value);
318 d_ptr->insert(index, value);
319 emit valuesAdded(index,1);
319 emit valuesAdded(index,1);
320 }
320 }
321
321
322 /*!
322 /*!
323 Removes \a count number of values from the set starting at \a index.
323 Removes \a count number of values from the set starting at \a index.
324 \sa insert()
324 \sa insert()
325 */
325 */
326 void QBarSet::remove(const int index, const int count)
326 void QBarSet::remove(const int index, const int count)
327 {
327 {
328 int removedCount = d_ptr->remove(index,count);
328 int removedCount = d_ptr->remove(index,count);
329 if (removedCount > 0) {
329 if (removedCount > 0) {
330 emit valuesRemoved(index,removedCount);
330 emit valuesRemoved(index,removedCount);
331 }
331 }
332 return;
332 return;
333 }
333 }
334
334
335 /*!
335 /*!
336 Sets a new value \a value to set, indexed by \a index
336 Sets a new value \a value to set, indexed by \a index
337 */
337 */
338 void QBarSet::replace(const int index, const qreal value)
338 void QBarSet::replace(const int index, const qreal value)
339 {
339 {
340 if (index >= 0 && index < d_ptr->m_values.count()) {
340 if (index >= 0 && index < d_ptr->m_values.count()) {
341 d_ptr->replace(index,value);
341 d_ptr->replace(index,value);
342 emit valueChanged(index);
342 emit valueChanged(index);
343 }
343 }
344 }
344 }
345
345
346
346
347 /*!
347 /*!
348 Returns value of set indexed by \a index.
348 Returns value of set indexed by \a index.
349 If the index is out of bounds 0.0 is returned.
349 If the index is out of bounds 0.0 is returned.
350 */
350 */
351 qreal QBarSet::at(const int index) const
351 qreal QBarSet::at(const int index) const
352 {
352 {
353 if (index < 0 || index >= d_ptr->m_values.count()) {
353 if (index < 0 || index >= d_ptr->m_values.count()) {
354 return 0;
354 return 0;
355 }
355 }
356
356
357 return d_ptr->m_values.at(index).y();
357 return d_ptr->m_values.at(index).y();
358 }
358 }
359
359
360 /*!
360 /*!
361 Returns value of set indexed by \a index.
361 Returns value of set indexed by \a index.
362 If the index is out of bounds 0.0 is returned.
362 If the index is out of bounds 0.0 is returned.
363 */
363 */
364 qreal QBarSet::operator [](const int index) const
364 qreal QBarSet::operator [](const int index) const
365 {
365 {
366 return at(index);
366 return at(index);
367 }
367 }
368
368
369 /*!
369 /*!
370 Returns count of values in set.
370 Returns count of values in set.
371 */
371 */
372 int QBarSet::count() const
372 int QBarSet::count() const
373 {
373 {
374 return d_ptr->m_values.count();
374 return d_ptr->m_values.count();
375 }
375 }
376
376
377 /*!
377 /*!
378 Returns sum of all values in barset.
378 Returns sum of all values in barset.
379 */
379 */
380 qreal QBarSet::sum() const
380 qreal QBarSet::sum() const
381 {
381 {
382 qreal total(0);
382 qreal total(0);
383 for (int i=0; i < d_ptr->m_values.count(); i++) {
383 for (int i=0; i < d_ptr->m_values.count(); i++) {
384 total += d_ptr->m_values.at(i).y();
384 total += d_ptr->m_values.at(i).y();
385 }
385 }
386 return total;
386 return total;
387 }
387 }
388
388
389 /*!
389 /*!
390 Sets pen for set. Bars of this set are drawn using \a pen
390 Sets pen for set. Bars of this set are drawn using \a pen
391 */
391 */
392 void QBarSet::setPen(const QPen &pen)
392 void QBarSet::setPen(const QPen &pen)
393 {
393 {
394 if(d_ptr->m_pen!=pen){
394 if(d_ptr->m_pen!=pen){
395 d_ptr->m_pen = pen;
395 d_ptr->m_pen = pen;
396 emit d_ptr->updatedBars();
396 emit d_ptr->updatedBars();
397 emit penChanged();
397 emit penChanged();
398 }
398 }
399 }
399 }
400
400
401 /*!
401 /*!
402 Returns pen of the set.
402 Returns pen of the set.
403 */
403 */
404 QPen QBarSet::pen() const
404 QPen QBarSet::pen() const
405 {
405 {
406 return d_ptr->m_pen;
406 return d_ptr->m_pen;
407 }
407 }
408
408
409 /*!
409 /*!
410 Sets brush for the set. Bars of this set are drawn using \a brush
410 Sets brush for the set. Bars of this set are drawn using \a brush
411 */
411 */
412 void QBarSet::setBrush(const QBrush &brush)
412 void QBarSet::setBrush(const QBrush &brush)
413 {
413 {
414 if(d_ptr->m_brush!=brush){
414 if(d_ptr->m_brush!=brush){
415 d_ptr->m_brush = brush;
415 d_ptr->m_brush = brush;
416 emit d_ptr->updatedBars();
416 emit d_ptr->updatedBars();
417 emit brushChanged();
417 emit brushChanged();
418 }
418 }
419 }
419 }
420
420
421 /*!
421 /*!
422 Returns brush of the set.
422 Returns brush of the set.
423 */
423 */
424 QBrush QBarSet::brush() const
424 QBrush QBarSet::brush() const
425 {
425 {
426 return d_ptr->m_brush;
426 return d_ptr->m_brush;
427 }
427 }
428
428
429 /*!
429 /*!
430 Sets \a brush of the values that are drawn on top of this barset
430 Sets \a brush of the values that are drawn on top of this barset
431 */
431 */
432 void QBarSet::setLabelBrush(const QBrush &brush)
432 void QBarSet::setLabelBrush(const QBrush &brush)
433 {
433 {
434 if(d_ptr->m_labelBrush!=brush){
434 if(d_ptr->m_labelBrush!=brush){
435 d_ptr->m_labelBrush = brush;
435 d_ptr->m_labelBrush = brush;
436 emit d_ptr->updatedBars();
436 emit d_ptr->updatedBars();
437 emit labelBrushChanged();
437 emit labelBrushChanged();
438 }
438 }
439 }
439 }
440
440
441 /*!
441 /*!
442 Returns brush of the values that are drawn on top of this barset
442 Returns brush of the values that are drawn on top of this barset
443 */
443 */
444 QBrush QBarSet::labelBrush() const
444 QBrush QBarSet::labelBrush() const
445 {
445 {
446 return d_ptr->m_labelBrush;
446 return d_ptr->m_labelBrush;
447 }
447 }
448
448
449 /*!
449 /*!
450 Sets the \a font for values that are drawn on top of this barset
450 Sets the \a font for values that are drawn on top of this barset
451 */
451 */
452 void QBarSet::setLabelFont(const QFont &font)
452 void QBarSet::setLabelFont(const QFont &font)
453 {
453 {
454 if(d_ptr->m_labelFont!=font) {
454 if(d_ptr->m_labelFont!=font) {
455 d_ptr->m_labelFont = font;
455 d_ptr->m_labelFont = font;
456 emit d_ptr->updatedBars();
456 emit d_ptr->updatedBars();
457 emit labelFontChanged();
457 emit labelFontChanged();
458 }
458 }
459
459
460 }
460 }
461
461
462 /*!
462 /*!
463 Returns the pen for values that are drawn on top of this barset
463 Returns the pen for values that are drawn on top of this barset
464 */
464 */
465 QFont QBarSet::labelFont() const
465 QFont QBarSet::labelFont() const
466 {
466 {
467 return d_ptr->m_labelFont;
467 return d_ptr->m_labelFont;
468 }
468 }
469
469
470 /*!
470 /*!
471 Returns the color of the brush of barset.
471 Returns the color of the brush of barset.
472 */
472 */
473 QColor QBarSet::color()
473 QColor QBarSet::color()
474 {
474 {
475 return brush().color();
475 return brush().color();
476 }
476 }
477
477
478 /*!
478 /*!
479 Sets the \a color of brush for this barset
479 Sets the \a color of brush for this barset
480 */
480 */
481 void QBarSet::setColor(QColor color)
481 void QBarSet::setColor(QColor color)
482 {
482 {
483 QBrush b = brush();
483 QBrush b = brush();
484 if (b.color() != color) {
484 if (b.color() != color) {
485 b.setColor(color);
485 b.setColor(color);
486 setBrush(b);
486 setBrush(b);
487 emit colorChanged(color);
487 emit colorChanged(color);
488 }
488 }
489 }
489 }
490
490
491 /*!
491 /*!
492 Returns the color of pen of this barset
492 Returns the color of pen of this barset
493 */
493 */
494 QColor QBarSet::borderColor()
494 QColor QBarSet::borderColor()
495 {
495 {
496 return pen().color();
496 return pen().color();
497 }
497 }
498
498
499 /*!
499 /*!
500 Sets the color of pen for this barset
500 Sets the color of pen for this barset
501 */
501 */
502 void QBarSet::setBorderColor(QColor color)
502 void QBarSet::setBorderColor(QColor color)
503 {
503 {
504 QPen p = pen();
504 QPen p = pen();
505 if (p.color() != color) {
505 if (p.color() != color) {
506 p.setColor(color);
506 p.setColor(color);
507 setPen(p);
507 setPen(p);
508 emit borderColorChanged(color);
508 emit borderColorChanged(color);
509 }
509 }
510 }
510 }
511
511
512 /*!
512 /*!
513 Returns the color of labels of this barset
513 Returns the color of labels of this barset
514 */
514 */
515 QColor QBarSet::labelColor()
515 QColor QBarSet::labelColor()
516 {
516 {
517 return labelBrush().color();
517 return labelBrush().color();
518 }
518 }
519
519
520 /*!
520 /*!
521 Sets the color of labels for this barset
521 Sets the color of labels for this barset
522 */
522 */
523 void QBarSet::setLabelColor(QColor color)
523 void QBarSet::setLabelColor(QColor color)
524 {
524 {
525 QBrush b = labelBrush();
525 QBrush b = labelBrush();
526 if (b.color() != color) {
526 if (b.color() != color) {
527 b.setColor(color);
527 b.setColor(color);
528 setLabelBrush(b);
528 setLabelBrush(b);
529 emit labelColorChanged(color);
529 emit labelColorChanged(color);
530 }
530 }
531 }
531 }
532
532
533 ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
533 ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
534
534
535 QBarSetPrivate::QBarSetPrivate(const QString label, QBarSet *parent) : QObject(parent),
535 QBarSetPrivate::QBarSetPrivate(const QString label, QBarSet *parent) : QObject(parent),
536 q_ptr(parent),
536 q_ptr(parent),
537 m_label(label)
537 m_label(label)
538 {
538 {
539 }
539 }
540
540
541 QBarSetPrivate::~QBarSetPrivate()
541 QBarSetPrivate::~QBarSetPrivate()
542 {
542 {
543 }
543 }
544
544
545 void QBarSetPrivate::append(QPointF value)
545 void QBarSetPrivate::append(QPointF value)
546 {
546 {
547 m_values.append(value);
547 m_values.append(value);
548 emit restructuredBars();
548 emit restructuredBars();
549 }
549 }
550
550
551 void QBarSetPrivate::append(QList<QPointF> values)
551 void QBarSetPrivate::append(QList<QPointF> values)
552 {
552 {
553 for (int i=0; i<values.count(); i++) {
553 for (int i=0; i<values.count(); i++) {
554 m_values.append(values.at(i));
554 m_values.append(values.at(i));
555 }
555 }
556 emit restructuredBars();
556 emit restructuredBars();
557 }
557 }
558
558
559 void QBarSetPrivate::append(QList<qreal> values)
559 void QBarSetPrivate::append(QList<qreal> values)
560 {
560 {
561 int index = m_values.count();
561 int index = m_values.count();
562 for (int i=0; i<values.count(); i++) {
562 for (int i=0; i<values.count(); i++) {
563 m_values.append(QPointF(index,values.at(i)));
563 m_values.append(QPointF(index,values.at(i)));
564 index++;
564 index++;
565 }
565 }
566 emit restructuredBars();
566 emit restructuredBars();
567 }
567 }
568
568
569 void QBarSetPrivate::insert(const int index, const qreal value)
569 void QBarSetPrivate::insert(const int index, const qreal value)
570 {
570 {
571 m_values.insert(index, QPointF(index, value));
571 m_values.insert(index, QPointF(index, value));
572 emit restructuredBars();
572 emit restructuredBars();
573 }
573 }
574
574
575 void QBarSetPrivate::insert(const int index, const QPointF value)
575 void QBarSetPrivate::insert(const int index, const QPointF value)
576 {
576 {
577 m_values.insert(index, value);
577 m_values.insert(index, value);
578 emit restructuredBars();
578 emit restructuredBars();
579 }
579 }
580
580
581 int QBarSetPrivate::remove(const int index, const int count)
581 int QBarSetPrivate::remove(const int index, const int count)
582 {
582 {
583 int removeCount = count;
583 int removeCount = count;
584
584
585 if ((index <0) || (m_values.count() == 0)) {
585 if ((index <0) || (m_values.count() == 0)) {
586 // Invalid index or not values in list, remove nothing.
586 // Invalid index or not values in list, remove nothing.
587 return 0;
587 return 0;
588 } else if ((index + count) > m_values.count()) {
588 } else if ((index + count) > m_values.count()) {
589 // Trying to remove more items than list has. Limit amount to be removed.
589 // Trying to remove more items than list has. Limit amount to be removed.
590 removeCount = m_values.count() - index;
590 removeCount = m_values.count() - index;
591 }
591 }
592
592
593 int c = 0;
593 int c = 0;
594 while (c < removeCount) {
594 while (c < removeCount) {
595 m_values.removeAt(index);
595 m_values.removeAt(index);
596 c++;
596 c++;
597 }
597 }
598 emit restructuredBars();
598 emit restructuredBars();
599 return removeCount;
599 return removeCount;
600 }
600 }
601
601
602 void QBarSetPrivate::replace(const int index, const qreal value)
602 void QBarSetPrivate::replace(const int index, const qreal value)
603 {
603 {
604 m_values.replace(index,QPointF(index,value));
604 m_values.replace(index,QPointF(index,value));
605 emit updatedBars();
605 emit updatedBars();
606 }
606 }
607
607
608 void QBarSetPrivate::replace(const int index, const QPointF value)
608 void QBarSetPrivate::replace(const int index, const QPointF value)
609 {
609 {
610 m_values.replace(index,value);
610 m_values.replace(index,value);
611 emit updatedBars();
611 emit updatedBars();
612 }
612 }
613
613
614 QPointF QBarSetPrivate::at(const int index)
614 qreal QBarSetPrivate::pos(const int index)
615 {
615 {
616 if (index < 0 || index >= m_values.count()) {
616 if (index < 0 || index >= m_values.count()) {
617 return QPointF(0,0);
617 return 0;
618 }
618 }
619
619
620 return m_values.at(index);
620 return m_values.at(index).x();
621 }
621 }
622
622
623 qreal QBarSetPrivate::value(const int index)
624 {
625 if (index < 0 || index >= m_values.count()) {
626 return 0;
627 }
628
629 return m_values.at(index).y();
630 }
623
631
624 #include "moc_qbarset.cpp"
632 #include "moc_qbarset.cpp"
625 #include "moc_qbarset_p.cpp"
633 #include "moc_qbarset_p.cpp"
626
634
627 QTCOMMERCIALCHART_END_NAMESPACE
635 QTCOMMERCIALCHART_END_NAMESPACE
@@ -1,115 +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
20
21 #ifndef QBARSET_H
21 #ifndef QBARSET_H
22 #define QBARSET_H
22 #define QBARSET_H
23
23
24 #include <qchartglobal.h>
24 #include <qchartglobal.h>
25 #include <QPen>
25 #include <QPen>
26 #include <QBrush>
26 #include <QBrush>
27 #include <QFont>
27 #include <QFont>
28
28
29 QTCOMMERCIALCHART_BEGIN_NAMESPACE
29 QTCOMMERCIALCHART_BEGIN_NAMESPACE
30 class QBarSetPrivate;
30 class QBarSetPrivate;
31
31
32 class QTCOMMERCIALCHART_EXPORT QBarSet : public QObject
32 class QTCOMMERCIALCHART_EXPORT QBarSet : public QObject
33 {
33 {
34 Q_OBJECT
34 Q_OBJECT
35 Q_PROPERTY(QString label READ label WRITE setLabel NOTIFY labelChanged)
35 Q_PROPERTY(QString label READ label WRITE setLabel NOTIFY labelChanged)
36 Q_PROPERTY(QPen pen READ pen WRITE setPen NOTIFY penChanged)
36 Q_PROPERTY(QPen pen READ pen WRITE setPen NOTIFY penChanged)
37 Q_PROPERTY(QBrush brush READ brush WRITE setBrush NOTIFY brushChanged)
37 Q_PROPERTY(QBrush brush READ brush WRITE setBrush NOTIFY brushChanged)
38 Q_PROPERTY(QBrush labelBrush READ labelBrush WRITE setLabelBrush NOTIFY labelBrushChanged)
38 Q_PROPERTY(QBrush labelBrush READ labelBrush WRITE setLabelBrush NOTIFY labelBrushChanged)
39 Q_PROPERTY(QFont labelFont READ labelFont WRITE setLabelFont NOTIFY labelFontChanged)
39 Q_PROPERTY(QFont labelFont READ labelFont WRITE setLabelFont NOTIFY labelFontChanged)
40 Q_PROPERTY(QColor color READ color WRITE setColor NOTIFY colorChanged)
40 Q_PROPERTY(QColor color READ color WRITE setColor NOTIFY colorChanged)
41 Q_PROPERTY(QColor borderColor READ borderColor WRITE setBorderColor NOTIFY borderColorChanged)
41 Q_PROPERTY(QColor borderColor READ borderColor WRITE setBorderColor NOTIFY borderColorChanged)
42 Q_PROPERTY(QColor labelColor READ labelColor WRITE setLabelColor NOTIFY labelColorChanged)
42 Q_PROPERTY(QColor labelColor READ labelColor WRITE setLabelColor NOTIFY labelColorChanged)
43
43
44 public:
44 public:
45 explicit QBarSet(const QString label, QObject *parent = 0);
45 explicit QBarSet(const QString label, QObject *parent = 0);
46 virtual ~QBarSet();
46 virtual ~QBarSet();
47
47
48 void setLabel(const QString label);
48 void setLabel(const QString label);
49 QString label() const;
49 QString label() const;
50
50
51 void append(const qreal value);
51 void append(const qreal value);
52 void append(const QList<qreal> &values);
52 void append(const QList<qreal> &values);
53
53
54 QBarSet& operator << (const qreal &value);
54 QBarSet& operator << (const qreal &value);
55
55
56 void insert(const int index, const qreal value);
56 void insert(const int index, const qreal value);
57 void remove(const int index, const int count = 1);
57 void remove(const int index, const int count = 1);
58 void replace(const int index, const qreal value);
58 void replace(const int index, const qreal value);
59 qreal at(const int index) const;
59 qreal at(const int index) const;
60 qreal operator [] (const int index) const;
60 qreal operator [] (const int index) const;
61 int count() const;
61 int count() const;
62 qreal sum() const;
62 qreal sum() const;
63
63
64 void setPen(const QPen &pen);
64 void setPen(const QPen &pen);
65 QPen pen() const;
65 QPen pen() const;
66
66
67 void setBrush(const QBrush &brush);
67 void setBrush(const QBrush &brush);
68 QBrush brush() const;
68 QBrush brush() const;
69
69
70 void setLabelBrush(const QBrush &brush);
70 void setLabelBrush(const QBrush &brush);
71 QBrush labelBrush() const;
71 QBrush labelBrush() const;
72
72
73 void setLabelFont(const QFont &font);
73 void setLabelFont(const QFont &font);
74 QFont labelFont() const;
74 QFont labelFont() const;
75
75
76 QColor color();
76 QColor color();
77 void setColor(QColor color);
77 void setColor(QColor color);
78
78
79 QColor borderColor();
79 QColor borderColor();
80 void setBorderColor(QColor color);
80 void setBorderColor(QColor color);
81
81
82 QColor labelColor();
82 QColor labelColor();
83 void setLabelColor(QColor color);
83 void setLabelColor(QColor color);
84
84
85 Q_SIGNALS:
85 Q_SIGNALS:
86 void clicked(int index);
86 void clicked(int index);
87 void hovered(bool status);
87 void hovered(bool status);
88 void penChanged();
88 void penChanged();
89 void brushChanged();
89 void brushChanged();
90 void labelChanged();
90 void labelChanged();
91 void labelBrushChanged();
91 void labelBrushChanged();
92 void labelFontChanged();
92 void labelFontChanged();
93 void colorChanged(QColor color);
93 void colorChanged(QColor color);
94 void borderColorChanged(QColor color);
94 void borderColorChanged(QColor color);
95 void labelColorChanged(QColor color);
95 void labelColorChanged(QColor color);
96
96
97 void valuesAdded(int index, int count);
97 void valuesAdded(int index, int count);
98 void valuesRemoved(int index, int count);
98 void valuesRemoved(int index, int count);
99 void valueChanged(int index);
99 void valueChanged(int index);
100
100
101 private:
101 private:
102 QScopedPointer<QBarSetPrivate> d_ptr;
102 QScopedPointer<QBarSetPrivate> d_ptr;
103 Q_DISABLE_COPY(QBarSet)
103 Q_DISABLE_COPY(QBarSet)
104 friend class QAbstractBarSeries;
104 friend class QAbstractBarSeries;
105 friend class BarLegendMarker;
105 friend class BarLegendMarker;
106 friend class AbstractBarChartItem;
106 friend class AbstractBarChartItem;
107 friend class QAbstractBarSeriesPrivate;
107 friend class QAbstractBarSeriesPrivate;
108 friend class StackedBarChartItem;
108 friend class StackedBarChartItem;
109 friend class PercentBarChartItem;
109 friend class PercentBarChartItem;
110 friend class BarChartItem;
110 friend class BarChartItem;
111 friend class HorizontalBarChartItem;
111 };
112 };
112
113
113 QTCOMMERCIALCHART_END_NAMESPACE
114 QTCOMMERCIALCHART_END_NAMESPACE
114
115
115 #endif // QBARSET_H
116 #endif // QBARSET_H
@@ -1,80 +1,81
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 QBARSET_P_H
30 #ifndef QBARSET_P_H
31 #define QBARSET_P_H
31 #define QBARSET_P_H
32
32
33 #include "qbarset.h"
33 #include "qbarset.h"
34 #include <QMap>
34 #include <QMap>
35 #include <QPen>
35 #include <QPen>
36 #include <QBrush>
36 #include <QBrush>
37 #include <QFont>
37 #include <QFont>
38
38
39 QTCOMMERCIALCHART_BEGIN_NAMESPACE
39 QTCOMMERCIALCHART_BEGIN_NAMESPACE
40
40
41 class QBarSetPrivate : public QObject
41 class QBarSetPrivate : public QObject
42 {
42 {
43 Q_OBJECT
43 Q_OBJECT
44
44
45 public:
45 public:
46 QBarSetPrivate(const QString label, QBarSet *parent);
46 QBarSetPrivate(const QString label, QBarSet *parent);
47 ~QBarSetPrivate();
47 ~QBarSetPrivate();
48
48
49 void append(QPointF value);
49 void append(QPointF value);
50 void append(QList<QPointF> values);
50 void append(QList<QPointF> values);
51 void append(QList<qreal> values);
51 void append(QList<qreal> values);
52
52
53 void insert(const int index, const qreal value);
53 void insert(const int index, const qreal value);
54 void insert(const int index, const QPointF value);
54 void insert(const int index, const QPointF value);
55 int remove(const int index, const int count);
55 int remove(const int index, const int count);
56
56
57 void replace(const int index, const qreal value);
57 void replace(const int index, const qreal value);
58 void replace(const int index, const QPointF value);
58 void replace(const int index, const QPointF value);
59
59
60 QPointF at(const int index);
60 qreal pos(const int index);
61 qreal value(const int index);
61
62
62 Q_SIGNALS:
63 Q_SIGNALS:
63 void restructuredBars();
64 void restructuredBars();
64 void updatedBars();
65 void updatedBars();
65
66
66 public:
67 public:
67 QBarSet * const q_ptr;
68 QBarSet * const q_ptr;
68 QString m_label;
69 QString m_label;
69 QList<QPointF> m_values;
70 QList<QPointF> m_values;
70 QPen m_pen;
71 QPen m_pen;
71 QBrush m_brush;
72 QBrush m_brush;
72 QBrush m_labelBrush;
73 QBrush m_labelBrush;
73 QFont m_labelFont;
74 QFont m_labelFont;
74
75
75 friend class QBarSet;
76 friend class QBarSet;
76 };
77 };
77
78
78 QTCOMMERCIALCHART_END_NAMESPACE
79 QTCOMMERCIALCHART_END_NAMESPACE
79
80
80 #endif // QBARSETPRIVATE_P_H
81 #endif // QBARSETPRIVATE_P_H
@@ -1,69 +1,79
1 #include "qhorizontalbarseries.h"
1 #include "qhorizontalbarseries.h"
2 #include "qhorizontalbarseries_p.h"
2 #include "qhorizontalbarseries_p.h"
3 #include "horizontalbarchartitem_p.h"
4 #include "horizontalbaranimation_p.h"
5
6 #include "chartdataset_p.h"
7 #include "charttheme_p.h"
8
9
3 QTCOMMERCIALCHART_BEGIN_NAMESPACE
10 QTCOMMERCIALCHART_BEGIN_NAMESPACE
4
11
5 QHorizontalBarSeries::QHorizontalBarSeries(QObject *parent) :
12 QHorizontalBarSeries::QHorizontalBarSeries(QObject *parent) :
6 QAbstractBarSeries(parent)
13 QAbstractBarSeries(*new QHorizontalBarSeriesPrivate(this), parent)
7 {
14 {
8 }
15 }
9
16
10 QAbstractSeries::SeriesType QHorizontalBarSeries::type() const
17 QAbstractSeries::SeriesType QHorizontalBarSeries::type() const
11 {
18 {
12 return QAbstractSeries::SeriesTypeHorizontalBar;
19 return QAbstractSeries::SeriesTypeHorizontalBar;
13 }
20 }
14
21
15
22
16
23
17 ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
24 ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
18
25
19 QHorizontalBarSeriesPrivate::QHorizontalBarSeriesPrivate(QHorizontalBarSeries *q) : QAbstractBarSeriesPrivate(q)
26 QHorizontalBarSeriesPrivate::QHorizontalBarSeriesPrivate(QHorizontalBarSeries *q) : QAbstractBarSeriesPrivate(q)
20 {
27 {
21
28
22 }
29 }
23
30
24 void QHorizontalBarSeriesPrivate::scaleDomain(Domain& domain)
31 void QHorizontalBarSeriesPrivate::scaleDomain(Domain& domain)
25 {
32 {
26 // TODO:
33 // TODO:
27 Q_UNUSED(domain);
28 /*
29 qreal minX(domain.minX());
34 qreal minX(domain.minX());
30 qreal minY(domain.minY());
35 qreal minY(domain.minY());
31 qreal maxX(domain.maxX());
36 qreal maxX(domain.maxX());
32 qreal maxY(domain.maxY());
37 qreal maxY(domain.maxY());
33 int tickXCount(domain.tickXCount());
38 int tickXCount(domain.tickXCount());
34 int tickYCount(domain.tickYCount());
39 int tickYCount(domain.tickYCount());
35
40
36 qreal x = categoryCount();
41 qreal y = categoryCount();
37 qreal y = max();
42 qreal x = max();
38 minX = qMin(minX, -0.5);
43 minX = qMin(minX, x);
39 minY = qMin(minY, y);
44 minY = qMin(minY, -0.5);
40 maxX = qMax(maxX, x - 0.5);
45 maxX = qMax(maxX, x);
41 maxY = qMax(maxY, y);
46 maxY = qMax(maxY, y -0.5);
42 tickXCount = x+1;
47 tickYCount = y+1;
43
48
44 domain.setRange(minX,maxX,minY,maxY,tickXCount,tickYCount);
49 domain.setRange(minX,maxX,minY,maxY,tickXCount,tickYCount);
45 */
46 }
50 }
47
51
48
52
49 Chart* QHorizontalBarSeriesPrivate::createGraphics(ChartPresenter* presenter)
53 Chart* QHorizontalBarSeriesPrivate::createGraphics(ChartPresenter* presenter)
50 {
54 {
51 // TODO:
52 Q_UNUSED(presenter);
53 return 0;
54 /*
55 Q_Q(QHorizontalBarSeries);
55 Q_Q(QHorizontalBarSeries);
56
56
57 GroupedBarChartItem* bar = new GroupedBarChartItem(q,presenter);
57 HorizontalBarChartItem* bar = new HorizontalBarChartItem(q,presenter);
58 if(presenter->animationOptions().testFlag(QChart::SeriesAnimations)) {
58 if(presenter->animationOptions().testFlag(QChart::SeriesAnimations)) {
59 presenter->animator()->addAnimation(bar);
59 bar->setAnimator(presenter->animator());
60 bar->setAnimation(new HorizontalBarAnimation(bar));
60 }
61 }
61 presenter->chartTheme()->decorate(q, presenter->dataSet()->seriesIndex(q));
62 presenter->chartTheme()->decorate(q, presenter->dataSet()->seriesIndex(q));
62 return bar;
63 return bar;
63 */
64 }
65
66 QAbstractAxis::AxisType QHorizontalBarSeriesPrivate::defaultAxisXType() const
67 {
68 return QAbstractAxis::AxisTypeValues;
69 }
70
71 QAbstractAxis::AxisType QHorizontalBarSeriesPrivate::defaultAxisYType() const
72 {
73 return QAbstractAxis::AxisTypeValues;
64 }
74 }
65
75
66
76
67 #include "moc_qhorizontalbarseries.cpp"
77 #include "moc_qhorizontalbarseries.cpp"
68
78
69 QTCOMMERCIALCHART_END_NAMESPACE
79 QTCOMMERCIALCHART_END_NAMESPACE
@@ -1,24 +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
1 #ifndef QHORIZONTALBARSERIES_H
21 #ifndef QHORIZONTALBARSERIES_H
2 #define QHORIZONTALBARSERIES_H
22 #define QHORIZONTALBARSERIES_H
3
23
4 #include <qabstractbarseries.h>
24 #include <qabstractbarseries.h>
5
25
6 QTCOMMERCIALCHART_BEGIN_NAMESPACE
26 QTCOMMERCIALCHART_BEGIN_NAMESPACE
7
27
8 class QHorizontalBarSeriesPrivate;
28 class QHorizontalBarSeriesPrivate;
9
29
10 class QTCOMMERCIALCHART_EXPORT QHorizontalBarSeries : public QAbstractBarSeries
30 class QTCOMMERCIALCHART_EXPORT QHorizontalBarSeries : public QAbstractBarSeries
11 {
31 {
12 Q_OBJECT
32 Q_OBJECT
13 public:
33 public:
14 explicit QHorizontalBarSeries(QObject *parent = 0);
34 explicit QHorizontalBarSeries(QObject *parent = 0);
15 QAbstractSeries::SeriesType type() const;
35 QAbstractSeries::SeriesType type() const;
16
36
17 private:
37 private:
18 Q_DECLARE_PRIVATE(QHorizontalBarSeries)
38 Q_DECLARE_PRIVATE(QHorizontalBarSeries)
19 Q_DISABLE_COPY(QHorizontalBarSeries)
39 Q_DISABLE_COPY(QHorizontalBarSeries)
20 };
40 };
21
41
22 QTCOMMERCIALCHART_END_NAMESPACE
42 QTCOMMERCIALCHART_END_NAMESPACE
23
43
24 #endif // QHORIZONTALBARSERIES_H
44 #endif // QHORIZONTALBARSERIES_H
@@ -1,51 +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 #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 "domain_p.h"
34 #include "domain_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 Chart* createGraphics(ChartPresenter* presenter);
42 Chart* createGraphics(ChartPresenter* presenter);
43 void scaleDomain(Domain& domain);
43 void scaleDomain(Domain& domain);
44 QAbstractAxis::AxisType defaultAxisXType() const;
45 QAbstractAxis::AxisType defaultAxisYType() const;
44
46
45 private:
47 private:
46 Q_DECLARE_PUBLIC(QHorizontalBarSeries)
48 Q_DECLARE_PUBLIC(QHorizontalBarSeries)
47 };
49 };
48
50
49 QTCOMMERCIALCHART_END_NAMESPACE
51 QTCOMMERCIALCHART_END_NAMESPACE
50
52
51 #endif // QHORIZONTALBARSERIES_P_H
53 #endif // QHORIZONTALBARSERIES_P_H
@@ -1,118 +1,128
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 "chartanimator_p.h"
26 #include "chartanimator_p.h"
27 #include "qvaluesaxis.h"
27 #include "qvaluesaxis.h"
28 #include "percentbaranimation_p.h"
28 #include "percentbaranimation_p.h"
29
29
30 QTCOMMERCIALCHART_BEGIN_NAMESPACE
30 QTCOMMERCIALCHART_BEGIN_NAMESPACE
31
31
32 /*!
32 /*!
33 \class QPercentBarSeries
33 \class QPercentBarSeries
34 \brief Series for creating percent bar chart
34 \brief Series for creating percent bar chart
35 \mainclass
35 \mainclass
36
36
37 QPercentBarSeries represents a series of data shown as bars. The purpose of this class is to draw bars
37 QPercentBarSeries represents a series of data shown as bars. The purpose of this class is to draw bars
38 as stacks, where each bar is shown as percentage of all bars in that category.
38 as stacks, where each bar is shown as percentage of all bars in that category.
39 QPercentBarSeries groups the data from sets to categories, which are defined by a QStringList.
39 QPercentBarSeries groups the data from sets to categories, which are defined by a QStringList.
40
40
41 See the \l {PercentbarChart Example} {percent bar chart example} to learn how to create a percent bar chart.
41 See the \l {PercentbarChart Example} {percent bar chart example} to learn how to create a percent bar chart.
42 \image examples_percentbarchart.png
42 \image examples_percentbarchart.png
43
43
44 \sa QBarSet, QStackedBarSeries, QAbstractBarSeries
44 \sa QBarSet, QStackedBarSeries, QAbstractBarSeries
45 */
45 */
46 /*!
46 /*!
47 \qmlclass PercentBarSeries QPercentBarSeries
47 \qmlclass PercentBarSeries QPercentBarSeries
48 \inherits QAbstractBarSeries
48 \inherits QAbstractBarSeries
49
49
50 The following QML shows how to create a simple percent bar chart:
50 The following QML shows how to create a simple percent bar chart:
51 \snippet ../demos/qmlchart/qml/qmlchart/View8.qml 1
51 \snippet ../demos/qmlchart/qml/qmlchart/View8.qml 1
52 \beginfloatleft
52 \beginfloatleft
53 \image demos_qmlchart8.png
53 \image demos_qmlchart8.png
54 \endfloat
54 \endfloat
55 \clearfloat
55 \clearfloat
56 */
56 */
57
57
58 /*!
58 /*!
59 Constructs empty QPercentBarSeries.
59 Constructs empty QPercentBarSeries.
60 QPercentBarSeries is QObject which is a child of a \a parent.
60 QPercentBarSeries is QObject which is a child of a \a parent.
61 */
61 */
62 QPercentBarSeries::QPercentBarSeries(QObject *parent)
62 QPercentBarSeries::QPercentBarSeries(QObject *parent)
63 : QAbstractBarSeries(*new QPercentBarSeriesPrivate(this), parent)
63 : QAbstractBarSeries(*new QPercentBarSeriesPrivate(this), parent)
64 {
64 {
65 }
65 }
66
66
67 /*!
67 /*!
68 Returns QChartSeries::SeriesTypePercentBar.
68 Returns QChartSeries::SeriesTypePercentBar.
69 */
69 */
70 QAbstractSeries::SeriesType QPercentBarSeries::type() const
70 QAbstractSeries::SeriesType QPercentBarSeries::type() const
71 {
71 {
72 return QAbstractSeries::SeriesTypePercentBar;
72 return QAbstractSeries::SeriesTypePercentBar;
73 }
73 }
74
74
75 ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
75 ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
76
76
77 QPercentBarSeriesPrivate::QPercentBarSeriesPrivate(QPercentBarSeries *q) : QAbstractBarSeriesPrivate(q)
77 QPercentBarSeriesPrivate::QPercentBarSeriesPrivate(QPercentBarSeries *q) : QAbstractBarSeriesPrivate(q)
78 {
78 {
79
79
80 }
80 }
81
81
82 void QPercentBarSeriesPrivate::scaleDomain(Domain& domain)
82 void QPercentBarSeriesPrivate::scaleDomain(Domain& domain)
83 {
83 {
84 qreal minX(domain.minX());
84 qreal minX(domain.minX());
85 qreal minY(domain.minY());
85 qreal minY(domain.minY());
86 qreal maxX(domain.maxX());
86 qreal maxX(domain.maxX());
87 qreal maxY(domain.maxY());
87 qreal maxY(domain.maxY());
88 int tickXCount(domain.tickXCount());
88 int tickXCount(domain.tickXCount());
89 int tickYCount(domain.tickYCount());
89 int tickYCount(domain.tickYCount());
90
90
91 qreal x = categoryCount();
91 qreal x = categoryCount();
92 minX = qMin(minX, - (qreal)0.5);
92 minX = qMin(minX, - (qreal)0.5);
93 maxX = qMax(maxX, x - (qreal)0.5);
93 maxX = qMax(maxX, x - (qreal)0.5);
94 minY = 0;
94 minY = 0;
95 maxY = 100;
95 maxY = 100;
96 tickXCount = x+1;
96 tickXCount = x+1;
97
97
98 domain.setRange(minX,maxX,minY,maxY,tickXCount,tickYCount);
98 domain.setRange(minX,maxX,minY,maxY,tickXCount,tickYCount);
99 }
99 }
100
100
101
101
102 Chart* QPercentBarSeriesPrivate::createGraphics(ChartPresenter* presenter)
102 Chart* QPercentBarSeriesPrivate::createGraphics(ChartPresenter* presenter)
103 {
103 {
104 Q_Q(QPercentBarSeries);
104 Q_Q(QPercentBarSeries);
105
105
106 PercentBarChartItem* bar = new PercentBarChartItem(q,presenter);
106 PercentBarChartItem* bar = new PercentBarChartItem(q,presenter);
107 if(presenter->animationOptions().testFlag(QChart::SeriesAnimations)) {
107 if(presenter->animationOptions().testFlag(QChart::SeriesAnimations)) {
108 bar->setAnimator(presenter->animator());
108 bar->setAnimator(presenter->animator());
109 bar->setAnimation(new PercentBarAnimation(bar));
109 bar->setAnimation(new PercentBarAnimation(bar));
110 }
110 }
111 presenter->chartTheme()->decorate(q, presenter->dataSet()->seriesIndex(q));
111 presenter->chartTheme()->decorate(q, presenter->dataSet()->seriesIndex(q));
112 return bar;
112 return bar;
113 }
113 }
114
114
115 QAbstractAxis::AxisType QPercentBarSeriesPrivate::defaultAxisXType() const
116 {
117 return QAbstractAxis::AxisTypeCategories;
118 }
119
120 QAbstractAxis::AxisType QPercentBarSeriesPrivate::defaultAxisYType() const
121 {
122 return QAbstractAxis::AxisTypeValues;
123 }
124
115 #include "moc_qpercentbarseries.cpp"
125 #include "moc_qpercentbarseries.cpp"
116
126
117 QTCOMMERCIALCHART_END_NAMESPACE
127 QTCOMMERCIALCHART_END_NAMESPACE
118
128
@@ -1,51 +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 #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 "domain_p.h"
34 #include "domain_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 scaleDomain(Domain& domain);
43 void scaleDomain(Domain& domain);
44 Chart* createGraphics(ChartPresenter* presenter);
44 Chart* createGraphics(ChartPresenter* presenter);
45 QAbstractAxis::AxisType defaultAxisXType() const;
46 QAbstractAxis::AxisType defaultAxisYType() const;
47
45 private:
48 private:
46 Q_DECLARE_PUBLIC(QPercentBarSeries)
49 Q_DECLARE_PUBLIC(QPercentBarSeries)
47 };
50 };
48
51
49 QTCOMMERCIALCHART_END_NAMESPACE
52 QTCOMMERCIALCHART_END_NAMESPACE
50
53
51 #endif
54 #endif
@@ -1,121 +1,131
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 "chartanimator_p.h"
26 #include "chartanimator_p.h"
27 #include "qvaluesaxis.h"
27 #include "qvaluesaxis.h"
28 #include "stackedbaranimation_p.h"
28 #include "stackedbaranimation_p.h"
29
29
30 QTCOMMERCIALCHART_BEGIN_NAMESPACE
30 QTCOMMERCIALCHART_BEGIN_NAMESPACE
31
31
32 /*!
32 /*!
33 \class QStackedBarSeries
33 \class QStackedBarSeries
34 \brief Series for creating stacked bar chart
34 \brief Series for creating stacked bar chart
35 \mainclass
35 \mainclass
36
36
37 QStackedBarSeries represents a series of data shown as bars. The purpose of this class is to draw bars
37 QStackedBarSeries represents a series of data shown as bars. The purpose of this class is to draw bars
38 as stacks, where bars in same category are stacked on top of each other.
38 as stacks, where bars in same category are stacked on top of each other.
39 QStackedBarSeries groups the data from sets to categories, which are defined by QStringList.
39 QStackedBarSeries groups the data from sets to categories, which are defined by QStringList.
40
40
41 See the \l {StackedbarChart Example} {stacked bar chart example} to learn how to create a stacked bar chart.
41 See the \l {StackedbarChart Example} {stacked bar chart example} to learn how to create a stacked bar chart.
42 \image examples_stackedbarchart.png
42 \image examples_stackedbarchart.png
43
43
44 \sa QBarSet, QPercentBarSeries, QAbstractBarSeries
44 \sa QBarSet, QPercentBarSeries, QAbstractBarSeries
45 */
45 */
46
46
47 /*!
47 /*!
48 \qmlclass StackedBarSeries QStackedBarSeries
48 \qmlclass StackedBarSeries QStackedBarSeries
49 \inherits AbstractBarSeries
49 \inherits AbstractBarSeries
50
50
51 The following QML shows how to create a simple stacked bar chart:
51 The following QML shows how to create a simple stacked bar chart:
52 \snippet ../demos/qmlchart/qml/qmlchart/View7.qml 1
52 \snippet ../demos/qmlchart/qml/qmlchart/View7.qml 1
53 \beginfloatleft
53 \beginfloatleft
54 \image demos_qmlchart7.png
54 \image demos_qmlchart7.png
55 \endfloat
55 \endfloat
56 \clearfloat
56 \clearfloat
57 */
57 */
58
58
59 /*!
59 /*!
60 Constructs empty QStackedBarSeries.
60 Constructs empty QStackedBarSeries.
61 QStackedBarSeries is QObject which is a child of a \a parent.
61 QStackedBarSeries is QObject which is a child of a \a parent.
62 */
62 */
63 QStackedBarSeries::QStackedBarSeries(QObject *parent)
63 QStackedBarSeries::QStackedBarSeries(QObject *parent)
64 : QAbstractBarSeries(*new QStackedBarSeriesPrivate(this), parent)
64 : QAbstractBarSeries(*new QStackedBarSeriesPrivate(this), parent)
65 {
65 {
66 }
66 }
67
67
68 /*!
68 /*!
69 Returns QChartSeries::SeriesTypeStackedBar.
69 Returns QChartSeries::SeriesTypeStackedBar.
70 */
70 */
71 QAbstractSeries::SeriesType QStackedBarSeries::type() const
71 QAbstractSeries::SeriesType QStackedBarSeries::type() const
72 {
72 {
73 return QAbstractSeries::SeriesTypeStackedBar;
73 return QAbstractSeries::SeriesTypeStackedBar;
74 }
74 }
75
75
76 ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
76 ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
77
77
78 QStackedBarSeriesPrivate::QStackedBarSeriesPrivate(QStackedBarSeries *q) : QAbstractBarSeriesPrivate(q)
78 QStackedBarSeriesPrivate::QStackedBarSeriesPrivate(QStackedBarSeries *q) : QAbstractBarSeriesPrivate(q)
79 {
79 {
80
80
81 }
81 }
82
82
83 void QStackedBarSeriesPrivate::scaleDomain(Domain& domain)
83 void QStackedBarSeriesPrivate::scaleDomain(Domain& domain)
84 {
84 {
85 qreal minX(domain.minX());
85 qreal minX(domain.minX());
86 qreal minY(domain.minY());
86 qreal minY(domain.minY());
87 qreal maxX(domain.maxX());
87 qreal maxX(domain.maxX());
88 qreal maxY(domain.maxY());
88 qreal maxY(domain.maxY());
89 int tickXCount(domain.tickXCount());
89 int tickXCount(domain.tickXCount());
90 int tickYCount(domain.tickYCount());
90 int tickYCount(domain.tickYCount());
91
91
92 qreal x = categoryCount();
92 qreal x = categoryCount();
93 qreal y = maxCategorySum();
93 qreal y = maxCategorySum();
94 minX = qMin(minX, - (qreal)0.5);
94 minX = qMin(minX, - (qreal)0.5);
95 minY = qMin(minY, y);
95 minY = qMin(minY, y);
96 maxX = qMax(maxX, x - (qreal)0.5);
96 maxX = qMax(maxX, x - (qreal)0.5);
97 maxY = qMax(maxY, y);
97 maxY = qMax(maxY, y);
98 tickXCount = x+1;
98 tickXCount = x+1;
99
99
100 domain.setRange(minX,maxX,minY,maxY,tickXCount,tickYCount);
100 domain.setRange(minX,maxX,minY,maxY,tickXCount,tickYCount);
101 }
101 }
102
102
103
103
104 Chart* QStackedBarSeriesPrivate::createGraphics(ChartPresenter* presenter)
104 Chart* QStackedBarSeriesPrivate::createGraphics(ChartPresenter* presenter)
105 {
105 {
106 Q_Q(QStackedBarSeries);
106 Q_Q(QStackedBarSeries);
107
107
108 StackedBarChartItem* bar = new StackedBarChartItem(q,presenter);
108 StackedBarChartItem* bar = new StackedBarChartItem(q,presenter);
109 if(presenter->animationOptions().testFlag(QChart::SeriesAnimations)) {
109 if(presenter->animationOptions().testFlag(QChart::SeriesAnimations)) {
110 bar->setAnimator(presenter->animator());
110 bar->setAnimator(presenter->animator());
111 bar->setAnimation(new StackedBarAnimation(bar));
111 bar->setAnimation(new StackedBarAnimation(bar));
112 }
112 }
113 presenter->chartTheme()->decorate(q, presenter->dataSet()->seriesIndex(q));
113 presenter->chartTheme()->decorate(q, presenter->dataSet()->seriesIndex(q));
114 return bar;
114 return bar;
115 }
115 }
116
116
117 QAbstractAxis::AxisType QStackedBarSeriesPrivate::defaultAxisXType() const
118 {
119 return QAbstractAxis::AxisTypeCategories;
120 }
121
122 QAbstractAxis::AxisType QStackedBarSeriesPrivate::defaultAxisYType() const
123 {
124 return QAbstractAxis::AxisTypeValues;
125 }
126
117
127
118 #include "moc_qstackedbarseries.cpp"
128 #include "moc_qstackedbarseries.cpp"
119
129
120 QTCOMMERCIALCHART_END_NAMESPACE
130 QTCOMMERCIALCHART_END_NAMESPACE
121
131
@@ -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 #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 "domain_p.h"
34 #include "domain_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 Chart* createGraphics(ChartPresenter* presenter);
43 Chart* createGraphics(ChartPresenter* presenter);
44 void scaleDomain(Domain& domain);
44 void scaleDomain(Domain& domain);
45 QAbstractAxis::AxisType defaultAxisXType() const;
46 QAbstractAxis::AxisType defaultAxisYType() const;
45
47
46 private:
48 private:
47 Q_DECLARE_PUBLIC(QStackedBarSeries)
49 Q_DECLARE_PUBLIC(QStackedBarSeries)
48 };
50 };
49
51
50 QTCOMMERCIALCHART_END_NAMESPACE
52 QTCOMMERCIALCHART_END_NAMESPACE
51
53
52 #endif
54 #endif
@@ -1,95 +1,95
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 #include "chartanimator_p.h"
26 #include "chartanimator_p.h"
27
27
28 QTCOMMERCIALCHART_BEGIN_NAMESPACE
28 QTCOMMERCIALCHART_BEGIN_NAMESPACE
29
29
30 StackedBarChartItem::StackedBarChartItem(QAbstractBarSeries *series, ChartPresenter *presenter) :
30 StackedBarChartItem::StackedBarChartItem(QAbstractBarSeries *series, ChartPresenter *presenter) :
31 AbstractBarChartItem(series, presenter)
31 AbstractBarChartItem(series, presenter)
32 {
32 {
33 }
33 }
34
34
35 QVector<QRectF> StackedBarChartItem::calculateLayout()
35 QVector<QRectF> StackedBarChartItem::calculateLayout()
36 {
36 {
37 QVector<QRectF> layout;
37 QVector<QRectF> layout;
38 // Use temporary qreals for accuracy
38 // Use temporary qreals for accuracy
39 qreal categoryCount = m_series->d_func()->categoryCount();
39 qreal categoryCount = m_series->d_func()->categoryCount();
40 qreal setCount = m_series->count();
40 qreal setCount = m_series->count();
41 bool barsVisible = m_series->isVisible();
41 bool barsVisible = m_series->isVisible();
42
42
43 // Domain:
43 // Domain:
44 qreal width = geometry().width();
44 qreal width = geometry().width();
45 qreal height = geometry().height();
45 qreal height = geometry().height();
46 qreal rangeY = m_domainMaxY - m_domainMinY;
46 qreal rangeY = m_domainMaxY - m_domainMinY;
47 qreal rangeX = m_domainMaxX - m_domainMinX;
47 qreal rangeX = m_domainMaxX - m_domainMinX;
48 qreal scaleY = (height / rangeY);
48 qreal scaleY = (height / rangeY);
49 qreal scaleX = (width / rangeX);
49 qreal scaleX = (width / rangeX);
50 qreal barWidth = scaleX * m_series->d_func()->barWidth();
50 qreal barWidth = scaleX * m_series->d_func()->barWidth();
51
51
52 int itemIndex(0);
52 int itemIndex(0);
53 for (int category = 0; category < categoryCount; category++) {
53 for (int category = 0; category < categoryCount; category++) {
54 qreal yPos = height + rangeY * m_domainMinY + geometry().topLeft().y();
54 qreal yPos = height + rangeY * m_domainMinY + geometry().topLeft().y();
55 for (int set=0; set < setCount; set++) {
55 for (int set=0; set < setCount; set++) {
56 QBarSetPrivate* barSet = m_series->d_func()->barsetAt(set)->d_ptr.data();
56 QBarSetPrivate* barSet = m_series->d_func()->barsetAt(set)->d_ptr.data();
57
57
58 qreal xPos = (barSet->at(category).x() - m_domainMinX) * scaleX + m_rect.left() - barWidth/2;
58 qreal xPos = (barSet->pos(category) - m_domainMinX) * scaleX + m_rect.left() - barWidth/2;
59
59
60 qreal barHeight = barSet->at(category).y() * scaleY;
60 qreal barHeight = barSet->value(category) * scaleY;
61 Bar* bar = m_bars.at(itemIndex);
61 Bar* bar = m_bars.at(itemIndex);
62 bar->setPen(barSet->m_pen);
62 bar->setPen(barSet->m_pen);
63 bar->setBrush(barSet->m_brush);
63 bar->setBrush(barSet->m_brush);
64 if (qFuzzyIsNull(barHeight)) {
64 if (qFuzzyIsNull(barHeight)) {
65 bar->setVisible(false);
65 bar->setVisible(false);
66 } else {
66 } else {
67 bar->setVisible(barsVisible);
67 bar->setVisible(barsVisible);
68 }
68 }
69
69
70 QRectF rect(xPos, yPos-barHeight, barWidth, barHeight);
70 QRectF rect(xPos, yPos-barHeight, barWidth, barHeight);
71 layout.append(rect);
71 layout.append(rect);
72
72
73 QGraphicsSimpleTextItem* label = m_labels.at(itemIndex);
73 QGraphicsSimpleTextItem* label = m_labels.at(itemIndex);
74
74
75 if (!qFuzzyIsNull(barSet->at(category).y())) {
75 if (!qFuzzyIsNull(barSet->value(category))) {
76 label->setText(QString::number(barSet->at(category).y()));
76 label->setText(QString::number(barSet->value(category)));
77 } else {
77 } else {
78 label->setText(QString(""));
78 label->setText(QString(""));
79 }
79 }
80
80
81 label->setPos(xPos + (rect.width()/2 - label->boundingRect().width()/2)
81 label->setPos(xPos + (rect.width()/2 - label->boundingRect().width()/2)
82 ,yPos - barHeight/2 - label->boundingRect().height()/2);
82 ,yPos - barHeight/2 - label->boundingRect().height()/2);
83 label->setFont(barSet->m_labelFont);
83 label->setFont(barSet->m_labelFont);
84 label->setBrush(barSet->m_labelBrush);
84 label->setBrush(barSet->m_labelBrush);
85 itemIndex++;
85 itemIndex++;
86 yPos -= barHeight;
86 yPos -= barHeight;
87 }
87 }
88 }
88 }
89
89
90 return layout;
90 return layout;
91 }
91 }
92
92
93 #include "moc_stackedbarchartitem_p.cpp"
93 #include "moc_stackedbarchartitem_p.cpp"
94
94
95 QTCOMMERCIALCHART_END_NAMESPACE
95 QTCOMMERCIALCHART_END_NAMESPACE
General Comments 0
You need to be logged in to leave comments. Login now