##// END OF EJS Templates
Renamed QSeries to QAbstractSeries
Tero Ahola -
r988:8a36a6921f5a
parent child
Show More
@@ -1,54 +1,54
1 1 /****************************************************************************
2 2 **
3 3 ** Copyright (C) 2012 Digia Plc
4 4 ** All rights reserved.
5 5 ** For any questions to Digia, please use contact form at http://qt.digia.com
6 6 **
7 7 ** This file is part of the Qt Commercial Charts Add-on.
8 8 **
9 9 ** $QT_BEGIN_LICENSE$
10 10 ** Licensees holding valid Qt Commercial licenses may use this file in
11 11 ** accordance with the Qt Commercial License Agreement provided with the
12 12 ** Software or, alternatively, in accordance with the terms contained in
13 13 ** a written agreement between you and Digia.
14 14 **
15 15 ** If you have questions regarding the use of this file, please use
16 16 ** contact form at http://qt.digia.com
17 17 ** $QT_END_LICENSE$
18 18 **
19 19 ****************************************************************************/
20 20 #include "drilldownchart.h"
21 21 #include "drilldownslice.h"
22 22
23 23 QTCOMMERCIALCHART_USE_NAMESPACE
24 24
25 25 DrilldownChart::DrilldownChart(QGraphicsItem *parent, Qt::WindowFlags wFlags)
26 26 :QChart(parent, wFlags),
27 27 m_currentSeries(0)
28 28 {
29 29
30 30 }
31 31
32 32 DrilldownChart::~DrilldownChart()
33 33 {
34 34
35 35 }
36 36
37 void DrilldownChart::changeSeries(QSeries* series)
37 void DrilldownChart::changeSeries(QAbstractSeries* series)
38 38 {
39 39 // NOTE: if the series is owned by the chart it will be deleted
40 40 // here the "window" owns the series...
41 41 if (m_currentSeries)
42 42 removeSeries(m_currentSeries);
43 43 m_currentSeries = series;
44 44 addSeries(series);
45 45 setTitle(series->name());
46 46 }
47 47
48 48 void DrilldownChart::handleSliceClicked(QPieSlice* slice)
49 49 {
50 50 DrilldownSlice* drilldownSlice = static_cast<DrilldownSlice*>(slice);
51 51 changeSeries(drilldownSlice->drilldownSeries());
52 52 }
53 53
54 54 #include "moc_drilldownchart.cpp"
@@ -1,47 +1,47
1 1 /****************************************************************************
2 2 **
3 3 ** Copyright (C) 2012 Digia Plc
4 4 ** All rights reserved.
5 5 ** For any questions to Digia, please use contact form at http://qt.digia.com
6 6 **
7 7 ** This file is part of the Qt Commercial Charts Add-on.
8 8 **
9 9 ** $QT_BEGIN_LICENSE$
10 10 ** Licensees holding valid Qt Commercial licenses may use this file in
11 11 ** accordance with the Qt Commercial License Agreement provided with the
12 12 ** Software or, alternatively, in accordance with the terms contained in
13 13 ** a written agreement between you and Digia.
14 14 **
15 15 ** If you have questions regarding the use of this file, please use
16 16 ** contact form at http://qt.digia.com
17 17 ** $QT_END_LICENSE$
18 18 **
19 19 ****************************************************************************/
20 20 #ifndef DRILLDOWNCHART_H
21 21 #define DRILLDOWNCHART_H
22 22
23 23 #include <QChart>
24 24
25 25 QTCOMMERCIALCHART_BEGIN_NAMESPACE
26 class QSeries;
26 class QAbstractSeries;
27 27 class QPieSlice;
28 28 QTCOMMERCIALCHART_END_NAMESPACE
29 29
30 30 QTCOMMERCIALCHART_USE_NAMESPACE
31 31
32 32 class DrilldownChart : public QChart
33 33 {
34 34 Q_OBJECT
35 35 public:
36 36 explicit DrilldownChart(QGraphicsItem *parent = 0, Qt::WindowFlags wFlags = 0);
37 37 ~DrilldownChart();
38 void changeSeries(QSeries* series);
38 void changeSeries(QAbstractSeries* series);
39 39
40 40 public Q_SLOTS:
41 41 void handleSliceClicked(QPieSlice* slice);
42 42
43 43 private:
44 QSeries* m_currentSeries;
44 QAbstractSeries* m_currentSeries;
45 45 };
46 46
47 47 #endif // DRILLDOWNCHART_H
@@ -1,70 +1,70
1 1 /****************************************************************************
2 2 **
3 3 ** Copyright (C) 2012 Digia Plc
4 4 ** All rights reserved.
5 5 ** For any questions to Digia, please use contact form at http://qt.digia.com
6 6 **
7 7 ** This file is part of the Qt Commercial Charts Add-on.
8 8 **
9 9 ** $QT_BEGIN_LICENSE$
10 10 ** Licensees holding valid Qt Commercial licenses may use this file in
11 11 ** accordance with the Qt Commercial License Agreement provided with the
12 12 ** Software or, alternatively, in accordance with the terms contained in
13 13 ** a written agreement between you and Digia.
14 14 **
15 15 ** If you have questions regarding the use of this file, please use
16 16 ** contact form at http://qt.digia.com
17 17 ** $QT_END_LICENSE$
18 18 **
19 19 ****************************************************************************/
20 20
21 21 #include "drilldownslice.h"
22 22
23 23 QTCOMMERCIALCHART_USE_NAMESPACE
24 24
25 DrilldownSlice::DrilldownSlice(qreal value, QString prefix, QSeries* drilldownSeries)
25 DrilldownSlice::DrilldownSlice(qreal value, QString prefix, QAbstractSeries* drilldownSeries)
26 26 :m_drilldownSeries(drilldownSeries),
27 27 m_prefix(prefix)
28 28 {
29 29 setValue(value);
30 30 updateLabel();
31 31 setLabelFont(QFont("Arial", 8));
32 32 connect(this, SIGNAL(changed()), this, SLOT(updateLabel()));
33 33 connect(this, SIGNAL(hoverEnter()), this, SLOT(showHighlight()));
34 34 connect(this, SIGNAL(hoverLeave()), this, SLOT(hideHighlight()));
35 35 }
36 36
37 37 DrilldownSlice::~DrilldownSlice()
38 38 {
39 39
40 40 }
41 41
42 QSeries* DrilldownSlice::drilldownSeries() const
42 QAbstractSeries* DrilldownSlice::drilldownSeries() const
43 43 {
44 44 return m_drilldownSeries;
45 45 }
46 46
47 47 void DrilldownSlice::updateLabel()
48 48 {
49 49 QString label = m_prefix;
50 50 label += " $";
51 51 label += QString::number(this->value());
52 52 label += ", ";
53 53 label += QString::number(this->percentage()*100, 'f', 1);
54 54 label += "%";
55 55 setLabel(label);
56 56 }
57 57
58 58 void DrilldownSlice::showHighlight()
59 59 {
60 60 setExploded();
61 61 setLabelVisible();
62 62 }
63 63
64 64 void DrilldownSlice::hideHighlight()
65 65 {
66 66 setExploded(false);
67 67 setLabelVisible(false);
68 68 }
69 69
70 70 #include "moc_drilldownslice.cpp"
@@ -1,50 +1,50
1 1 /****************************************************************************
2 2 **
3 3 ** Copyright (C) 2012 Digia Plc
4 4 ** All rights reserved.
5 5 ** For any questions to Digia, please use contact form at http://qt.digia.com
6 6 **
7 7 ** This file is part of the Qt Commercial Charts Add-on.
8 8 **
9 9 ** $QT_BEGIN_LICENSE$
10 10 ** Licensees holding valid Qt Commercial licenses may use this file in
11 11 ** accordance with the Qt Commercial License Agreement provided with the
12 12 ** Software or, alternatively, in accordance with the terms contained in
13 13 ** a written agreement between you and Digia.
14 14 **
15 15 ** If you have questions regarding the use of this file, please use
16 16 ** contact form at http://qt.digia.com
17 17 ** $QT_END_LICENSE$
18 18 **
19 19 ****************************************************************************/
20 20 #ifndef DRILLDOWNSLICE_H
21 21 #define DRILLDOWNSLICE_H
22 22
23 23 #include <QPieSlice>
24 24
25 25 QTCOMMERCIALCHART_BEGIN_NAMESPACE
26 class QSeries;
26 class QAbstractSeries;
27 27 QTCOMMERCIALCHART_END_NAMESPACE
28 28
29 29 QTCOMMERCIALCHART_USE_NAMESPACE
30 30
31 31 class DrilldownSlice : public QPieSlice
32 32 {
33 33 Q_OBJECT
34 34
35 35 public:
36 DrilldownSlice(qreal value, QString prefix, QSeries* drilldownSeries);
36 DrilldownSlice(qreal value, QString prefix, QAbstractSeries* drilldownSeries);
37 37 virtual ~DrilldownSlice();
38 QSeries* drilldownSeries() const;
38 QAbstractSeries* drilldownSeries() const;
39 39
40 40 public Q_SLOTS:
41 41 void updateLabel();
42 42 void showHighlight();
43 43 void hideHighlight();
44 44
45 45 private:
46 QSeries* m_drilldownSeries;
46 QAbstractSeries* m_drilldownSeries;
47 47 QString m_prefix;
48 48 };
49 49
50 50 #endif // DRILLDOWNSLICE_H
@@ -1,116 +1,116
1 1 /****************************************************************************
2 2 **
3 3 ** Copyright (C) 2012 Digia Plc
4 4 ** All rights reserved.
5 5 ** For any questions to Digia, please use contact form at http://qt.digia.com
6 6 **
7 7 ** This file is part of the Qt Commercial Charts Add-on.
8 8 **
9 9 ** $QT_BEGIN_LICENSE$
10 10 ** Licensees holding valid Qt Commercial licenses may use this file in
11 11 ** accordance with the Qt Commercial License Agreement provided with the
12 12 ** Software or, alternatively, in accordance with the terms contained in
13 13 ** a written agreement between you and Digia.
14 14 **
15 15 ** If you have questions regarding the use of this file, please use
16 16 ** contact form at http://qt.digia.com
17 17 ** $QT_END_LICENSE$
18 18 **
19 19 ****************************************************************************/
20 20
21 21 #include "chartview.h"
22 22 #include <QLineSeries>
23 23 #include <QScatterSeries>
24 24 #include <QSplineSeries>
25 25 #include <QAreaSeries>
26 26 #include <QTime>
27 27
28 28 ChartView::ChartView(QChart* chart,QWidget* parent):QChartView(chart,parent),
29 29 m_index(-1),m_chart(chart)
30 30 {
31 31 m_chart->setTitle("Charts presenter");
32 32 QObject::connect(&m_timer,SIGNAL(timeout()),this,SLOT(handleTimeout()));
33 33 m_timer.setInterval(3000);
34 34
35 35 //![1]
36 36 QLineSeries* series0 = new QLineSeries();
37 37 QPen blue(Qt::blue);
38 38 blue.setWidth(3);
39 39 series0->setPen(blue);
40 40
41 41 QScatterSeries* series1 = new QScatterSeries();
42 42 QPen red(Qt::red);
43 43 red.setWidth(3);
44 44 series1->setPen(red);
45 45 series1->setBrush(Qt::white);
46 46
47 47 QSplineSeries* series2 = new QSplineSeries();
48 48 QPen green(Qt::green);
49 49 green.setWidth(3);
50 50 series2->setPen(green);
51 51
52 52 QAreaSeries* series3 = new QAreaSeries(series0);
53 53 QPen yellow(Qt::black);
54 54 yellow.setWidth(3);
55 55 series3->setPen(yellow);
56 56 series3->setBrush(Qt::yellow);
57 57 //![1]
58 58
59 59 //![2]
60 60 int numPoints = 10;
61 61
62 62 for (int x = 0; x <= numPoints; ++x) {
63 63 qreal y = qrand() % 100;
64 64 series0->append(x,y);
65 65 series1->append(x,y);
66 66 series2->append(x,y);
67 67 }
68 68 //![2]
69 69
70 70 //![3]
71 71 m_series<<series0;
72 72 m_titles<< m_chart->title()+": LineChart";
73 73 m_series<<series1;
74 74 m_titles<< m_chart->title()+": ScatterChart";
75 75 m_series<<series2;
76 76 m_titles<< m_chart->title()+": SplineChart";
77 77 m_series<<series3;
78 78 m_titles<< m_chart->title()+": AreaChart";
79 79 //![3]
80 80
81 81 //![4]
82 foreach (QSeries* series, m_series) {
82 foreach (QAbstractSeries* series, m_series) {
83 83 QObject::connect(series,SIGNAL(clicked(QPointF)),this,SLOT(handlePointClicked(QPointF)));
84 84 }
85 85 //![4]
86 86 m_timer.start();
87 87 handleTimeout();
88 88 }
89 89
90 90 ChartView::~ChartView()
91 91 {
92 92 if(m_series.size()==0) return;
93 93 m_chart->removeSeries(m_series.at(m_index));
94 94 m_series.removeLast(); //remove QAreaSeries instance since they will be deleted when QLineSeries instance is gone
95 95 qDeleteAll(m_series);
96 96 }
97 97
98 98 //![5]
99 99 void ChartView::handleTimeout()
100 100 {
101 101 if(m_series.size()==0) return;
102 102 if(m_index>=0)
103 103 m_chart->removeSeries(m_series.at(m_index));
104 104 m_index++;
105 105 m_index=m_index%m_series.size();
106 106 m_chart->addSeries(m_series.at(m_index));
107 107 m_chart->setTitle(m_titles.at(m_index));
108 108 }
109 109 //![5]
110 110
111 111 //![6]
112 112 void ChartView::handlePointClicked(const QPointF& point)
113 113 {
114 114 m_chart->setTitle(m_titles.at(m_index) + QString(" x: %1 y: %2").arg(point.x()).arg(point.y()));
115 115 }
116 116 //![6]
@@ -1,50 +1,50
1 1 /****************************************************************************
2 2 **
3 3 ** Copyright (C) 2012 Digia Plc
4 4 ** All rights reserved.
5 5 ** For any questions to Digia, please use contact form at http://qt.digia.com
6 6 **
7 7 ** This file is part of the Qt Commercial Charts Add-on.
8 8 **
9 9 ** $QT_BEGIN_LICENSE$
10 10 ** Licensees holding valid Qt Commercial licenses may use this file in
11 11 ** accordance with the Qt Commercial License Agreement provided with the
12 12 ** Software or, alternatively, in accordance with the terms contained in
13 13 ** a written agreement between you and Digia.
14 14 **
15 15 ** If you have questions regarding the use of this file, please use
16 16 ** contact form at http://qt.digia.com
17 17 ** $QT_END_LICENSE$
18 18 **
19 19 ****************************************************************************/
20 20
21 21 #ifndef CHARTVIEW_H_
22 22 #define CHARTVIEW_H_
23 23
24 24 #include <QChartView>
25 25 #include <QTimer>
26 26
27 27 QTCOMMERCIALCHART_USE_NAMESPACE
28 28
29 29 //![1]
30 30 class ChartView: public QChartView
31 31 {
32 32 Q_OBJECT
33 33 public:
34 34 ChartView(QChart* chart,QWidget* parent = 0);
35 35 virtual ~ChartView();
36 36
37 37 public slots:
38 38 void handleTimeout();
39 39 void handlePointClicked(const QPointF& point);
40 40
41 41 private:
42 42 QTimer m_timer;
43 QList<QSeries*> m_series;
43 QList<QAbstractSeries *> m_series;
44 44 QStringList m_titles;
45 45 int m_index;
46 46 QChart *m_chart;
47 47 };
48 48 //![1]
49 49
50 50 #endif /* CHARTVIEW_H_ */
@@ -1,50 +1,50
1 1 /****************************************************************************
2 2 **
3 3 ** Copyright (C) 2012 Digia Plc
4 4 ** All rights reserved.
5 5 ** For any questions to Digia, please use contact form at http://qt.digia.com
6 6 **
7 7 ** This file is part of the Qt Commercial Charts Add-on.
8 8 **
9 9 ** $QT_BEGIN_LICENSE$
10 10 ** Licensees holding valid Qt Commercial licenses may use this file in
11 11 ** accordance with the Qt Commercial License Agreement provided with the
12 12 ** Software or, alternatively, in accordance with the terms contained in
13 13 ** a written agreement between you and Digia.
14 14 **
15 15 ** If you have questions regarding the use of this file, please use
16 16 ** contact form at http://qt.digia.com
17 17 ** $QT_END_LICENSE$
18 18 **
19 19 ****************************************************************************/
20 20
21 21 #include "drilldownchart.h"
22 22 #include <QChartAxis>
23 23
24 24 QTCOMMERCIALCHART_USE_NAMESPACE
25 25
26 26 DrilldownChart::DrilldownChart(QGraphicsItem *parent, Qt::WindowFlags wFlags)
27 27 : QChart(parent, wFlags)
28 28 ,m_currentSeries(0)
29 29 {
30 30 }
31 31
32 void DrilldownChart::changeSeries(QSeries* series)
32 void DrilldownChart::changeSeries(QAbstractSeries *series)
33 33 {
34 34 if (m_currentSeries)
35 35 removeSeries(m_currentSeries);
36 36 m_currentSeries = series;
37 37 addSeries(series);
38 38 setTitle(series->name());
39 39 axisY()->setNiceNumbersEnabled(true);
40 40 }
41 41
42 42 void DrilldownChart::handleClicked(QBarSet *barset, QString category, Qt::MouseButtons button)
43 43 {
44 44 Q_UNUSED(barset)
45 45 Q_UNUSED(button)
46 46 DrilldownBarSeries* series = static_cast<DrilldownBarSeries*> (sender());
47 47 changeSeries(series->drilldownSeries(category));
48 48 }
49 49
50 50 #include "moc_drilldownchart.cpp"
@@ -1,46 +1,46
1 1 /****************************************************************************
2 2 **
3 3 ** Copyright (C) 2012 Digia Plc
4 4 ** All rights reserved.
5 5 ** For any questions to Digia, please use contact form at http://qt.digia.com
6 6 **
7 7 ** This file is part of the Qt Commercial Charts Add-on.
8 8 **
9 9 ** $QT_BEGIN_LICENSE$
10 10 ** Licensees holding valid Qt Commercial licenses may use this file in
11 11 ** accordance with the Qt Commercial License Agreement provided with the
12 12 ** Software or, alternatively, in accordance with the terms contained in
13 13 ** a written agreement between you and Digia.
14 14 **
15 15 ** If you have questions regarding the use of this file, please use
16 16 ** contact form at http://qt.digia.com
17 17 ** $QT_END_LICENSE$
18 18 **
19 19 ****************************************************************************/
20 20
21 21 #ifndef DRILLDOWNCHART_H
22 22 #define DRILLDOWNCHART_H
23 23
24 24 #include <QChart>
25 25 #include "drilldownseries.h"
26 26
27 27 QTCOMMERCIALCHART_USE_NAMESPACE
28 28
29 29 //! [2]
30 30 class DrilldownChart : public QChart
31 31 {
32 32 Q_OBJECT
33 33 public:
34 34 explicit DrilldownChart(QGraphicsItem *parent = 0, Qt::WindowFlags wFlags = 0);
35 35
36 void changeSeries(QSeries* series);
36 void changeSeries(QAbstractSeries *series);
37 37
38 38 public Q_SLOTS:
39 39 void handleClicked(QBarSet *barset, QString category, Qt::MouseButtons button);
40 40
41 41 private:
42 QSeries* m_currentSeries;
42 QAbstractSeries* m_currentSeries;
43 43 };
44 44 //! [2]
45 45
46 46 #endif // DRILLDOWNCHART_H
@@ -1,70 +1,70
1 1 /****************************************************************************
2 2 **
3 3 ** Copyright (C) 2012 Digia Plc
4 4 ** All rights reserved.
5 5 ** For any questions to Digia, please use contact form at http://qt.digia.com
6 6 **
7 7 ** This file is part of the Qt Commercial Charts Add-on.
8 8 **
9 9 ** $QT_BEGIN_LICENSE$
10 10 ** Licensees holding valid Qt Commercial licenses may use this file in
11 11 ** accordance with the Qt Commercial License Agreement provided with the
12 12 ** Software or, alternatively, in accordance with the terms contained in
13 13 ** a written agreement between you and Digia.
14 14 **
15 15 ** If you have questions regarding the use of this file, please use
16 16 ** contact form at http://qt.digia.com
17 17 ** $QT_END_LICENSE$
18 18 **
19 19 ****************************************************************************/
20 20
21 21 #include "declarativeareaseries.h"
22 22 #include "declarativechart.h"
23 23 #include "qchart.h"
24 24 #include "qlineseries.h"
25 25
26 26 QTCOMMERCIALCHART_BEGIN_NAMESPACE
27 27
28 28 DeclarativeAreaSeries::DeclarativeAreaSeries(QObject *parent) :
29 29 QAreaSeries(new QLineSeries(parent), new QLineSeries(parent))
30 30 {
31 31 }
32 32
33 QSeries *DeclarativeAreaSeries::series()
33 QAbstractSeries *DeclarativeAreaSeries::series()
34 34 {
35 35 return this;
36 36 }
37 37
38 38 QDeclarativeListProperty<DeclarativeXyPoint> DeclarativeAreaSeries::points()
39 39 {
40 40 return QDeclarativeListProperty<DeclarativeXyPoint>(this, 0, &DeclarativeAreaSeries::appendPoints);
41 41 }
42 42
43 43 QDeclarativeListProperty<DeclarativeXyPoint> DeclarativeAreaSeries::lowerPoints()
44 44 {
45 45 return QDeclarativeListProperty<DeclarativeXyPoint>(this, 0, &DeclarativeAreaSeries::appendLowerPoints);
46 46 }
47 47
48 48 void DeclarativeAreaSeries::appendPoints(QDeclarativeListProperty<DeclarativeXyPoint> *list,
49 49 DeclarativeXyPoint *element)
50 50 {
51 51 QAreaSeries *series = qobject_cast<QAreaSeries *>(list->object);
52 52 if (series) {
53 53 QLineSeries *upper = series->upperSeries();
54 54 upper->append(element->x(), element->y());
55 55 }
56 56 }
57 57
58 58 void DeclarativeAreaSeries::appendLowerPoints(QDeclarativeListProperty<DeclarativeXyPoint> *list,
59 59 DeclarativeXyPoint *element)
60 60 {
61 61 QAreaSeries *series = qobject_cast<QAreaSeries *>(list->object);
62 62 if (series) {
63 63 QLineSeries *lower = series->lowerSeries();
64 64 lower->append(element->x(), element->y());
65 65 }
66 66 }
67 67
68 68 #include "moc_declarativeareaseries.cpp"
69 69
70 70 QTCOMMERCIALCHART_END_NAMESPACE
@@ -1,53 +1,53
1 1 /****************************************************************************
2 2 **
3 3 ** Copyright (C) 2012 Digia Plc
4 4 ** All rights reserved.
5 5 ** For any questions to Digia, please use contact form at http://qt.digia.com
6 6 **
7 7 ** This file is part of the Qt Commercial Charts Add-on.
8 8 **
9 9 ** $QT_BEGIN_LICENSE$
10 10 ** Licensees holding valid Qt Commercial licenses may use this file in
11 11 ** accordance with the Qt Commercial License Agreement provided with the
12 12 ** Software or, alternatively, in accordance with the terms contained in
13 13 ** a written agreement between you and Digia.
14 14 **
15 15 ** If you have questions regarding the use of this file, please use
16 16 ** contact form at http://qt.digia.com
17 17 ** $QT_END_LICENSE$
18 18 **
19 19 ****************************************************************************/
20 20
21 21 #ifndef DECLARATIVEAREASERIES_H
22 22 #define DECLARATIVEAREASERIES_H
23 23
24 24 #include "qchartglobal.h"
25 25 #include "qareaseries.h"
26 26 #include "declarativexyseries.h"
27 27
28 28 QTCOMMERCIALCHART_BEGIN_NAMESPACE
29 29
30 30 class DeclarativeAreaSeries : public QAreaSeries, public DeclarativeXySeries
31 31 {
32 32 Q_OBJECT
33 33 Q_PROPERTY(QDeclarativeListProperty<DeclarativeXyPoint> points READ points)
34 34 Q_PROPERTY(QDeclarativeListProperty<DeclarativeXyPoint> lowerPoints READ lowerPoints)
35 35
36 36 public:
37 37 explicit DeclarativeAreaSeries(QObject *parent = 0);
38 38
39 39 public:
40 QSeries *series();
40 QAbstractSeries *series();
41 41 QDeclarativeListProperty<DeclarativeXyPoint> points();
42 42 QDeclarativeListProperty<DeclarativeXyPoint> lowerPoints();
43 43
44 44 public Q_SLOTS:
45 45 static void appendPoints(QDeclarativeListProperty<DeclarativeXyPoint> *list,
46 46 DeclarativeXyPoint *element);
47 47 static void appendLowerPoints(QDeclarativeListProperty<DeclarativeXyPoint> *list,
48 48 DeclarativeXyPoint *element);
49 49 };
50 50
51 51 QTCOMMERCIALCHART_END_NAMESPACE
52 52
53 53 #endif // DECLARATIVEAREASERIES_H
@@ -1,45 +1,45
1 1 /****************************************************************************
2 2 **
3 3 ** Copyright (C) 2012 Digia Plc
4 4 ** All rights reserved.
5 5 ** For any questions to Digia, please use contact form at http://qt.digia.com
6 6 **
7 7 ** This file is part of the Qt Commercial Charts Add-on.
8 8 **
9 9 ** $QT_BEGIN_LICENSE$
10 10 ** Licensees holding valid Qt Commercial licenses may use this file in
11 11 ** accordance with the Qt Commercial License Agreement provided with the
12 12 ** Software or, alternatively, in accordance with the terms contained in
13 13 ** a written agreement between you and Digia.
14 14 **
15 15 ** If you have questions regarding the use of this file, please use
16 16 ** contact form at http://qt.digia.com
17 17 ** $QT_END_LICENSE$
18 18 **
19 19 ****************************************************************************/
20 20
21 21 #include "declarativelineseries.h"
22 22 #include "declarativechart.h"
23 23 #include "qchart.h"
24 24 #include "qlineseries.h"
25 25
26 26 QTCOMMERCIALCHART_BEGIN_NAMESPACE
27 27
28 28 DeclarativeLineSeries::DeclarativeLineSeries(QObject *parent) :
29 29 QLineSeries(parent)
30 30 {
31 31 }
32 32
33 QSeries *DeclarativeLineSeries::series()
33 QAbstractSeries *DeclarativeLineSeries::series()
34 34 {
35 35 return this;
36 36 }
37 37
38 38 QDeclarativeListProperty<DeclarativeXyPoint> DeclarativeLineSeries::points()
39 39 {
40 40 return QDeclarativeListProperty<DeclarativeXyPoint>(this, 0, &DeclarativeXySeries::appendPoints);
41 41 }
42 42
43 43 #include "moc_declarativelineseries.cpp"
44 44
45 45 QTCOMMERCIALCHART_END_NAMESPACE
@@ -1,46 +1,46
1 1 /****************************************************************************
2 2 **
3 3 ** Copyright (C) 2012 Digia Plc
4 4 ** All rights reserved.
5 5 ** For any questions to Digia, please use contact form at http://qt.digia.com
6 6 **
7 7 ** This file is part of the Qt Commercial Charts Add-on.
8 8 **
9 9 ** $QT_BEGIN_LICENSE$
10 10 ** Licensees holding valid Qt Commercial licenses may use this file in
11 11 ** accordance with the Qt Commercial License Agreement provided with the
12 12 ** Software or, alternatively, in accordance with the terms contained in
13 13 ** a written agreement between you and Digia.
14 14 **
15 15 ** If you have questions regarding the use of this file, please use
16 16 ** contact form at http://qt.digia.com
17 17 ** $QT_END_LICENSE$
18 18 **
19 19 ****************************************************************************/
20 20
21 21 #ifndef DECLARATIVELINESERIES_H
22 22 #define DECLARATIVELINESERIES_H
23 23
24 24 #include "qchartglobal.h"
25 25 #include "qlineseries.h"
26 26 #include "declarativexyseries.h"
27 27 #include <QDeclarativeParserStatus>
28 28
29 29 QTCOMMERCIALCHART_BEGIN_NAMESPACE
30 30
31 31 class DeclarativeLineSeries : public QLineSeries, public DeclarativeXySeries
32 32 {
33 33 Q_OBJECT
34 34 Q_PROPERTY(QDeclarativeListProperty<DeclarativeXyPoint> points READ points)
35 35
36 36 public:
37 37 explicit DeclarativeLineSeries(QObject *parent = 0);
38 38
39 39 public:
40 QSeries *series();
40 QAbstractSeries *series();
41 41 QDeclarativeListProperty<DeclarativeXyPoint> points();
42 42 };
43 43
44 44 QTCOMMERCIALCHART_END_NAMESPACE
45 45
46 46 #endif // DECLARATIVELINESERIES_H
@@ -1,45 +1,45
1 1 /****************************************************************************
2 2 **
3 3 ** Copyright (C) 2012 Digia Plc
4 4 ** All rights reserved.
5 5 ** For any questions to Digia, please use contact form at http://qt.digia.com
6 6 **
7 7 ** This file is part of the Qt Commercial Charts Add-on.
8 8 **
9 9 ** $QT_BEGIN_LICENSE$
10 10 ** Licensees holding valid Qt Commercial licenses may use this file in
11 11 ** accordance with the Qt Commercial License Agreement provided with the
12 12 ** Software or, alternatively, in accordance with the terms contained in
13 13 ** a written agreement between you and Digia.
14 14 **
15 15 ** If you have questions regarding the use of this file, please use
16 16 ** contact form at http://qt.digia.com
17 17 ** $QT_END_LICENSE$
18 18 **
19 19 ****************************************************************************/
20 20
21 21 #include "declarativescatterseries.h"
22 22 #include "declarativechart.h"
23 23 #include "qchart.h"
24 24 #include "qscatterseries.h"
25 25
26 26 QTCOMMERCIALCHART_BEGIN_NAMESPACE
27 27
28 28 DeclarativeScatterSeries::DeclarativeScatterSeries(QObject *parent) :
29 29 QScatterSeries(parent)
30 30 {
31 31 }
32 32
33 QSeries *DeclarativeScatterSeries::series()
33 QAbstractSeries *DeclarativeScatterSeries::series()
34 34 {
35 35 return this;
36 36 }
37 37
38 38 QDeclarativeListProperty<DeclarativeXyPoint> DeclarativeScatterSeries::points()
39 39 {
40 40 return QDeclarativeListProperty<DeclarativeXyPoint>(this, 0, &DeclarativeXySeries::appendPoints);
41 41 }
42 42
43 43 #include "moc_declarativescatterseries.cpp"
44 44
45 45 QTCOMMERCIALCHART_END_NAMESPACE
@@ -1,46 +1,46
1 1 /****************************************************************************
2 2 **
3 3 ** Copyright (C) 2012 Digia Plc
4 4 ** All rights reserved.
5 5 ** For any questions to Digia, please use contact form at http://qt.digia.com
6 6 **
7 7 ** This file is part of the Qt Commercial Charts Add-on.
8 8 **
9 9 ** $QT_BEGIN_LICENSE$
10 10 ** Licensees holding valid Qt Commercial licenses may use this file in
11 11 ** accordance with the Qt Commercial License Agreement provided with the
12 12 ** Software or, alternatively, in accordance with the terms contained in
13 13 ** a written agreement between you and Digia.
14 14 **
15 15 ** If you have questions regarding the use of this file, please use
16 16 ** contact form at http://qt.digia.com
17 17 ** $QT_END_LICENSE$
18 18 **
19 19 ****************************************************************************/
20 20
21 21 #ifndef DECLARATIVESCATTERSERIES_H
22 22 #define DECLARATIVESCATTERSERIES_H
23 23
24 24 #include "qchartglobal.h"
25 25 #include "qscatterseries.h"
26 26 #include "declarativexyseries.h"
27 27 #include <QDeclarativeParserStatus>
28 28
29 29 QTCOMMERCIALCHART_BEGIN_NAMESPACE
30 30
31 31 class DeclarativeScatterSeries : public QScatterSeries, public DeclarativeXySeries
32 32 {
33 33 Q_OBJECT
34 34 Q_PROPERTY(QDeclarativeListProperty<DeclarativeXyPoint> points READ points)
35 35
36 36 public:
37 37 explicit DeclarativeScatterSeries(QObject *parent = 0);
38 38
39 39 public:
40 QSeries *series();
40 QAbstractSeries *series();
41 41 QDeclarativeListProperty<DeclarativeXyPoint> points();
42 42 };
43 43
44 44 QTCOMMERCIALCHART_END_NAMESPACE
45 45
46 46 #endif // DECLARATIVESCATTERSERIES_H
@@ -1,44 +1,44
1 1 /****************************************************************************
2 2 **
3 3 ** Copyright (C) 2012 Digia Plc
4 4 ** All rights reserved.
5 5 ** For any questions to Digia, please use contact form at http://qt.digia.com
6 6 **
7 7 ** This file is part of the Qt Commercial Charts Add-on.
8 8 **
9 9 ** $QT_BEGIN_LICENSE$
10 10 ** Licensees holding valid Qt Commercial licenses may use this file in
11 11 ** accordance with the Qt Commercial License Agreement provided with the
12 12 ** Software or, alternatively, in accordance with the terms contained in
13 13 ** a written agreement between you and Digia.
14 14 **
15 15 ** If you have questions regarding the use of this file, please use
16 16 ** contact form at http://qt.digia.com
17 17 ** $QT_END_LICENSE$
18 18 **
19 19 ****************************************************************************/
20 20
21 21 #include "declarativesplineseries.h"
22 22 #include "declarativechart.h"
23 23 #include "qchart.h"
24 24
25 25 QTCOMMERCIALCHART_BEGIN_NAMESPACE
26 26
27 27 DeclarativeSplineSeries::DeclarativeSplineSeries(QObject *parent) :
28 28 QSplineSeries(parent)
29 29 {
30 30 }
31 31
32 QSeries *DeclarativeSplineSeries::series()
32 QAbstractSeries *DeclarativeSplineSeries::series()
33 33 {
34 34 return this;
35 35 }
36 36
37 37 QDeclarativeListProperty<DeclarativeXyPoint> DeclarativeSplineSeries::points()
38 38 {
39 39 return QDeclarativeListProperty<DeclarativeXyPoint>(this, 0, &DeclarativeXySeries::appendPoints);
40 40 }
41 41
42 42 #include "moc_declarativesplineseries.cpp"
43 43
44 44 QTCOMMERCIALCHART_END_NAMESPACE
@@ -1,46 +1,46
1 1 /****************************************************************************
2 2 **
3 3 ** Copyright (C) 2012 Digia Plc
4 4 ** All rights reserved.
5 5 ** For any questions to Digia, please use contact form at http://qt.digia.com
6 6 **
7 7 ** This file is part of the Qt Commercial Charts Add-on.
8 8 **
9 9 ** $QT_BEGIN_LICENSE$
10 10 ** Licensees holding valid Qt Commercial licenses may use this file in
11 11 ** accordance with the Qt Commercial License Agreement provided with the
12 12 ** Software or, alternatively, in accordance with the terms contained in
13 13 ** a written agreement between you and Digia.
14 14 **
15 15 ** If you have questions regarding the use of this file, please use
16 16 ** contact form at http://qt.digia.com
17 17 ** $QT_END_LICENSE$
18 18 **
19 19 ****************************************************************************/
20 20
21 21 #ifndef DECLARATIVESPLINESERIES_H
22 22 #define DECLARATIVESPLINESERIES_H
23 23
24 24 #include "qchartglobal.h"
25 25 #include "qsplineseries.h"
26 26 #include "declarativexyseries.h"
27 27 #include <QDeclarativeParserStatus>
28 28
29 29 QTCOMMERCIALCHART_BEGIN_NAMESPACE
30 30
31 31 class DeclarativeSplineSeries : public QSplineSeries, public DeclarativeXySeries
32 32 {
33 33 Q_OBJECT
34 34 Q_PROPERTY(QDeclarativeListProperty<DeclarativeXyPoint> points READ points)
35 35
36 36 public:
37 37 explicit DeclarativeSplineSeries(QObject *parent = 0);
38 38
39 39 public:
40 QSeries *series();
40 QAbstractSeries *series();
41 41 QDeclarativeListProperty<DeclarativeXyPoint> points();
42 42 };
43 43
44 44 QTCOMMERCIALCHART_END_NAMESPACE
45 45
46 46 #endif // DECLARATIVESPLINESERIES_H
@@ -1,60 +1,60
1 1 /****************************************************************************
2 2 **
3 3 ** Copyright (C) 2012 Digia Plc
4 4 ** All rights reserved.
5 5 ** For any questions to Digia, please use contact form at http://qt.digia.com
6 6 **
7 7 ** This file is part of the Qt Commercial Charts Add-on.
8 8 **
9 9 ** $QT_BEGIN_LICENSE$
10 10 ** Licensees holding valid Qt Commercial licenses may use this file in
11 11 ** accordance with the Qt Commercial License Agreement provided with the
12 12 ** Software or, alternatively, in accordance with the terms contained in
13 13 ** a written agreement between you and Digia.
14 14 **
15 15 ** If you have questions regarding the use of this file, please use
16 16 ** contact form at http://qt.digia.com
17 17 ** $QT_END_LICENSE$
18 18 **
19 19 ****************************************************************************/
20 20
21 21 //#include "DeclarativeXySeries.h"
22 22 #include "declarativexyseries.h"
23 23 #include "qxyseries.h"
24 24 #include "declarativechart.h"
25 25
26 26 QTCOMMERCIALCHART_BEGIN_NAMESPACE
27 27
28 28 DeclarativeXySeries::DeclarativeXySeries()
29 29 {
30 30 }
31 31
32 32 DeclarativeXySeries::~DeclarativeXySeries()
33 33 {
34 34 }
35 35
36 36 void DeclarativeXySeries::classBegin()
37 37 {
38 38 }
39 39
40 40 void DeclarativeXySeries::componentComplete()
41 41 {
42 QSeries *thisObj = reinterpret_cast<QSeries *>(series());
42 QAbstractSeries *thisObj = reinterpret_cast<QAbstractSeries *>(series());
43 43 DeclarativeChart *declarativeChart = qobject_cast<DeclarativeChart *>(thisObj->parent());
44 44
45 45 if (declarativeChart) {
46 46 QChart *chart = qobject_cast<QChart *>(declarativeChart->m_chart);
47 47 Q_ASSERT(chart);
48 48 chart->addSeries(thisObj);
49 49 }
50 50 }
51 51
52 52 void DeclarativeXySeries::appendPoints(QDeclarativeListProperty<DeclarativeXyPoint> *list,
53 53 DeclarativeXyPoint *element)
54 54 {
55 55 QXYSeries *series = qobject_cast<QXYSeries *>(list->object);
56 56 if (series)
57 57 series->append(element->x(), element->y());
58 58 }
59 59
60 60 QTCOMMERCIALCHART_END_NAMESPACE
@@ -1,57 +1,57
1 1 /****************************************************************************
2 2 **
3 3 ** Copyright (C) 2012 Digia Plc
4 4 ** All rights reserved.
5 5 ** For any questions to Digia, please use contact form at http://qt.digia.com
6 6 **
7 7 ** This file is part of the Qt Commercial Charts Add-on.
8 8 **
9 9 ** $QT_BEGIN_LICENSE$
10 10 ** Licensees holding valid Qt Commercial licenses may use this file in
11 11 ** accordance with the Qt Commercial License Agreement provided with the
12 12 ** Software or, alternatively, in accordance with the terms contained in
13 13 ** a written agreement between you and Digia.
14 14 **
15 15 ** If you have questions regarding the use of this file, please use
16 16 ** contact form at http://qt.digia.com
17 17 ** $QT_END_LICENSE$
18 18 **
19 19 ****************************************************************************/
20 20
21 21 #ifndef DECLARATIVE_XY_SERIES_H
22 22 #define DECLARATIVE_XY_SERIES_H
23 23
24 24 #include "qchartglobal.h"
25 25 #include "declarativexypoint.h"
26 26 #include <QDeclarativeParserStatus>
27 27 #include <QDeclarativeListProperty>
28 28
29 29 QTCOMMERCIALCHART_BEGIN_NAMESPACE
30 30
31 31 class QChart;
32 class QSeries;
32 class QAbstractSeries;
33 33
34 34 class DeclarativeXySeries : public QDeclarativeParserStatus
35 35 {
36 36 Q_INTERFACES(QDeclarativeParserStatus)
37 37
38 38 public:
39 39 explicit DeclarativeXySeries();
40 40 ~DeclarativeXySeries();
41 41
42 42 public: // from QDeclarativeParserStatus
43 43 virtual void classBegin();
44 44 virtual void componentComplete();
45 45
46 46 public:
47 virtual QSeries *series() = 0;
47 virtual QAbstractSeries *series() = 0;
48 48 virtual QDeclarativeListProperty<DeclarativeXyPoint> points() = 0;
49 49
50 50 public Q_SLOTS:
51 51 static void appendPoints(QDeclarativeListProperty<DeclarativeXyPoint> *list,
52 52 DeclarativeXyPoint *element);
53 53 };
54 54
55 55 QTCOMMERCIALCHART_END_NAMESPACE
56 56
57 57 #endif // DECLARATIVE_XY_SERIES_H
@@ -1,282 +1,282
1 1 /****************************************************************************
2 2 **
3 3 ** Copyright (C) 2012 Digia Plc
4 4 ** All rights reserved.
5 5 ** For any questions to Digia, please use contact form at http://qt.digia.com
6 6 **
7 7 ** This file is part of the Qt Commercial Charts Add-on.
8 8 **
9 9 ** $QT_BEGIN_LICENSE$
10 10 ** Licensees holding valid Qt Commercial licenses may use this file in
11 11 ** accordance with the Qt Commercial License Agreement provided with the
12 12 ** Software or, alternatively, in accordance with the terms contained in
13 13 ** a written agreement between you and Digia.
14 14 **
15 15 ** If you have questions regarding the use of this file, please use
16 16 ** contact form at http://qt.digia.com
17 17 ** $QT_END_LICENSE$
18 18 **
19 19 ****************************************************************************/
20 20
21 21 #include "qareaseries.h"
22 22 #include "qareaseries_p.h"
23 23 #include "qlineseries.h"
24 24 #include "areachartitem_p.h"
25 25 #include "legendmarker_p.h"
26 26 #include "domain_p.h"
27 27 #include "chartdataset_p.h"
28 28 #include "charttheme_p.h"
29 29 #include "chartanimator_p.h"
30 30
31 31 QTCOMMERCIALCHART_BEGIN_NAMESPACE
32 32
33 33 /*!
34 34 \class QAreaSeries
35 35 \brief The QAreaSeries class is used for making area charts.
36 36
37 37 \mainclass
38 38
39 39 An area chart is used to show quantitative data. It is based on line chart, in the way that area between axis and the line
40 40 is emphasized with color. Since the area chart is based on line chart, QAreaSeries constructor needs QLineSeries instance,
41 41 which defines "upper" boundary of the area. "Lower" boundary is defined by default by axis X. Instead of axis X "lower" boundary can be specified by other line.
42 42 In that case QAreaSeries should be initiated with two QLineSerie instances. Please note terms "upper" and "lower" boundary can be misleading in cases
43 43 where "lower" boundary had bigger values than the "upper" one, however the main point that area between these two boundary lines will be filled.
44 44
45 45 \image areachart.png
46 46
47 47 Creating basic area chart is simple:
48 48 \code
49 49 QLineSeries* lineSeries = new QLineSeries();
50 50 series->append(0, 6);
51 51 series->append(2, 4);
52 52 QAreaSeries* areaSeries = new QAreaSeries(lineSeries);
53 53 ...
54 54 chartView->addSeries(areaSeries);
55 55 \endcode
56 56 */
57 57
58 58 /*!
59 59 \fn virtual QSeriesType QAreaSeries::type() const
60 60 \brief Returns type of series.
61 \sa QSeries, QSeriesType
61 \sa QAbstractSeries, QSeriesType
62 62 */
63 63
64 64 /*!
65 65 \fn QLineSeries* QAreaSeries::upperSeries() const
66 66 \brief Returns upperSeries used to define one of area boundaries.
67 67 */
68 68
69 69 /*!
70 70 \fn QLineSeries* QAreaSeries::lowerSeries() const
71 71 \brief Returns lowerSeries used to define one of area boundaries. Note if QAreaSeries where counstucted wihtout a\ lowerSeries
72 72 this function return Null pointer.
73 73 */
74 74
75 75 /*!
76 76 \fn QPen QAreaSeries::pen() const
77 77 \brief Returns the pen used to draw line for this series.
78 78 \sa setPen()
79 79 */
80 80
81 81 /*!
82 82 \fn QPen QAreaSeries::brush() const
83 83 \brief Returns the brush used to draw line for this series.
84 84 \sa setBrush()
85 85 */
86 86
87 87 /*!
88 88 \fn bool QAreaSeries::pointsVisible() const
89 89 \brief Returns if the points are drawn for this series.
90 90 \sa setPointsVisible()
91 91 */
92 92
93 93 /*!
94 94 \fn void QAreaSeries::clicked(const QPointF& point)
95 95 \brief Signal is emitted when user clicks the \a point on area chart.
96 96 */
97 97
98 98 /*!
99 99 \fn void QAreaSeries::selected()
100 100
101 101 The signal is emitted if the user selects/deselects the XY series. The logic for maintaining selections should be
102 102 implemented by the user of QAreaSeries API.
103 103 */
104 104
105 105 /*!
106 106 \fn void QAreaSeriesPrivate::updated()
107 107 \brief \internal
108 108 */
109 109
110 110 /*!
111 111 Constructs area series object which is a child of \a upperSeries. Area will be spanned between \a
112 112 upperSeries line and \a lowerSeries line. If no \a lowerSeries is passed to constructor, area is specified by axis x (y=0) instead.
113 113 When series object is added to QChartView or QChart instance ownerships is transferred.
114 114 */
115 115 QAreaSeries::QAreaSeries(QLineSeries *upperSeries, QLineSeries *lowerSeries)
116 : QSeries(*new QAreaSeriesPrivate(upperSeries,lowerSeries,this),upperSeries)
116 : QAbstractSeries(*new QAreaSeriesPrivate(upperSeries,lowerSeries,this),upperSeries)
117 117 {
118 118 }
119 119
120 120 /*!
121 121 Destroys the object. Series added to QChartView or QChart instances are owned by those,
122 122 and are deleted when mentioned object are destroyed.
123 123 */
124 124 QAreaSeries::~QAreaSeries()
125 125 {
126 126 }
127 127
128 128
129 QSeries::QSeriesType QAreaSeries::type() const
129 QAbstractSeries::QSeriesType QAreaSeries::type() const
130 130 {
131 return QSeries::SeriesTypeArea;
131 return QAbstractSeries::SeriesTypeArea;
132 132 }
133 133
134 134 QLineSeries* QAreaSeries::upperSeries() const
135 135 {
136 136 Q_D(const QAreaSeries);
137 137 return d->m_upperSeries;
138 138 }
139 139
140 140 QLineSeries* QAreaSeries::lowerSeries() const
141 141 {
142 142 Q_D(const QAreaSeries);
143 143 return d->m_lowerSeries;
144 144 }
145 145
146 146 /*!
147 147 Sets \a pen used for drawing area outline.
148 148 */
149 149 void QAreaSeries::setPen(const QPen &pen)
150 150 {
151 151 Q_D(QAreaSeries);
152 152 if (d->m_pen != pen) {
153 153 d->m_pen = pen;
154 154 emit d->updated();
155 155 }
156 156 }
157 157
158 158 QPen QAreaSeries::pen() const
159 159 {
160 160 Q_D(const QAreaSeries);
161 161 return d->m_pen;
162 162 }
163 163
164 164 /*!
165 165 Sets \a brush used for filling the area.
166 166 */
167 167 void QAreaSeries::setBrush(const QBrush &brush)
168 168 {
169 169 Q_D(QAreaSeries);
170 170 if (d->m_brush != brush) {
171 171 d->m_brush = brush;
172 172 emit d->updated();
173 173 }
174 174 }
175 175
176 176 QBrush QAreaSeries::brush() const
177 177 {
178 178 Q_D(const QAreaSeries);
179 179 return d->m_brush;
180 180 }
181 181 /*!
182 182 Sets if data points are \a visible and should be drawn on line.
183 183 */
184 184 void QAreaSeries::setPointsVisible(bool visible)
185 185 {
186 186 Q_D(QAreaSeries);
187 187 if (d->m_pointsVisible != visible) {
188 188 d->m_pointsVisible = visible;
189 189 emit d->updated();
190 190 }
191 191 }
192 192
193 193 bool QAreaSeries::pointsVisible() const
194 194 {
195 195 Q_D(const QAreaSeries);
196 196 return d->m_pointsVisible;
197 197 }
198 198
199 199 bool QAreaSeries::setModel(QAbstractItemModel* model)
200 200 {
201 201 Q_UNUSED(model);
202 202 qWarning()<<"Not implemented";
203 203 return false;
204 204 }
205 205
206 206 QAbstractItemModel* QAreaSeries::model() const
207 207 {
208 208 return 0;
209 209 }
210 210
211 211 ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
212 212
213 213 QAreaSeriesPrivate::QAreaSeriesPrivate(QLineSeries *upperSeries, QLineSeries *lowerSeries,QAreaSeries* q) :
214 QSeriesPrivate(q),
214 QAbstractSeriesPrivate(q),
215 215 m_upperSeries(upperSeries),
216 216 m_lowerSeries(lowerSeries),
217 217 m_pointsVisible(false)
218 218 {
219 219 }
220 220
221 221 void QAreaSeriesPrivate::scaleDomain(Domain& domain)
222 222 {
223 223 Q_Q(QAreaSeries);
224 224
225 225 qreal minX(domain.minX());
226 226 qreal minY(domain.minY());
227 227 qreal maxX(domain.maxX());
228 228 qreal maxY(domain.maxY());
229 229 int tickXCount(domain.tickXCount());
230 230 int tickYCount(domain.tickYCount());
231 231
232 232 QLineSeries* upperSeries = q->upperSeries();
233 233 QLineSeries* lowerSeries = q->lowerSeries();
234 234
235 235 for (int i = 0; i < upperSeries->count(); i++)
236 236 {
237 237 qreal x = upperSeries->x(i);
238 238 qreal y = upperSeries->y(i);
239 239 minX = qMin(minX, x);
240 240 minY = qMin(minY, y);
241 241 maxX = qMax(maxX, x);
242 242 maxY = qMax(maxY, y);
243 243 }
244 244 if(lowerSeries) {
245 245 for (int i = 0; i < lowerSeries->count(); i++)
246 246 {
247 247 qreal x = lowerSeries->x(i);
248 248 qreal y = lowerSeries->y(i);
249 249 minX = qMin(minX, x);
250 250 minY = qMin(minY, y);
251 251 maxX = qMax(maxX, x);
252 252 maxY = qMax(maxY, y);
253 253 }}
254 254
255 255 domain.setRangeX(minX,maxX,tickXCount);
256 256 domain.setRangeY(minY,maxY,tickYCount);
257 257 }
258 258
259 259 Chart* QAreaSeriesPrivate::createGraphics(ChartPresenter* presenter)
260 260 {
261 261 Q_Q(QAreaSeries);
262 262
263 263 AreaChartItem* area = new AreaChartItem(q,presenter);
264 264 if(presenter->animationOptions().testFlag(QChart::SeriesAnimations)) {
265 265 presenter->animator()->addAnimation(area->upperLineItem());
266 266 if(q->lowerSeries()) presenter->animator()->addAnimation(area->lowerLineItem());
267 267 }
268 268 presenter->chartTheme()->decorate(q, presenter->dataSet()->seriesIndex(q));
269 269 return area;
270 270 }
271 271
272 272 QList<LegendMarker*> QAreaSeriesPrivate::createLegendMarker(QLegend* legend)
273 273 {
274 274 Q_Q(QAreaSeries);
275 275 QList<LegendMarker*> list;
276 276 return list << new AreaLegendMarker(q,legend);
277 277 }
278 278
279 279 #include "moc_qareaseries.cpp"
280 280 #include "moc_qareaseries_p.cpp"
281 281
282 282 QTCOMMERCIALCHART_END_NAMESPACE
@@ -1,71 +1,71
1 1 /****************************************************************************
2 2 **
3 3 ** Copyright (C) 2012 Digia Plc
4 4 ** All rights reserved.
5 5 ** For any questions to Digia, please use contact form at http://qt.digia.com
6 6 **
7 7 ** This file is part of the Qt Commercial Charts Add-on.
8 8 **
9 9 ** $QT_BEGIN_LICENSE$
10 10 ** Licensees holding valid Qt Commercial licenses may use this file in
11 11 ** accordance with the Qt Commercial License Agreement provided with the
12 12 ** Software or, alternatively, in accordance with the terms contained in
13 13 ** a written agreement between you and Digia.
14 14 **
15 15 ** If you have questions regarding the use of this file, please use
16 16 ** contact form at http://qt.digia.com
17 17 ** $QT_END_LICENSE$
18 18 **
19 19 ****************************************************************************/
20 20
21 21 #ifndef QAREASERIES_H
22 22 #define QAREASERIES_H
23 23
24 24 #include <qchartglobal.h>
25 #include <qseries.h>
25 #include <qabstractseries.h>
26 26 #include <QPen>
27 27 #include <QBrush>
28 28
29 29 QTCOMMERCIALCHART_BEGIN_NAMESPACE
30 30 class QLineSeries;
31 31 class QAreaSeriesPrivate;
32 32
33 class QTCOMMERCIALCHART_EXPORT QAreaSeries : public QSeries
33 class QTCOMMERCIALCHART_EXPORT QAreaSeries : public QAbstractSeries
34 34 {
35 35 Q_OBJECT
36 36 public:
37 37 explicit QAreaSeries(QLineSeries *upperSeries, QLineSeries *lowerSeries = 0);
38 38 ~QAreaSeries();
39 39
40 40 public:
41 QSeries::QSeriesType type() const;
41 QAbstractSeries::QSeriesType type() const;
42 42
43 43 QLineSeries* upperSeries() const;
44 44 QLineSeries* lowerSeries() const;
45 45
46 46 void setPen(const QPen &pen);
47 47 QPen pen() const;
48 48
49 49 void setBrush(const QBrush &brush);
50 50 QBrush brush() const;
51 51
52 52 void setPointsVisible(bool visible = true);
53 53 bool pointsVisible() const;
54 54
55 55 bool setModel(QAbstractItemModel* model);
56 56 QAbstractItemModel* model() const;
57 57
58 58 Q_SIGNALS:
59 59 void clicked(const QPointF &point);
60 60 void selected();
61 61
62 62 private:
63 63 Q_DECLARE_PRIVATE(QAreaSeries);
64 64 Q_DISABLE_COPY(QAreaSeries);
65 65 friend class AreaLegendMarker;
66 66 friend class AreaChartItem;
67 67 };
68 68
69 69 QTCOMMERCIALCHART_END_NAMESPACE
70 70
71 71 #endif
@@ -1,65 +1,65
1 1 /****************************************************************************
2 2 **
3 3 ** Copyright (C) 2012 Digia Plc
4 4 ** All rights reserved.
5 5 ** For any questions to Digia, please use contact form at http://qt.digia.com
6 6 **
7 7 ** This file is part of the Qt Commercial Charts Add-on.
8 8 **
9 9 ** $QT_BEGIN_LICENSE$
10 10 ** Licensees holding valid Qt Commercial licenses may use this file in
11 11 ** accordance with the Qt Commercial License Agreement provided with the
12 12 ** Software or, alternatively, in accordance with the terms contained in
13 13 ** a written agreement between you and Digia.
14 14 **
15 15 ** If you have questions regarding the use of this file, please use
16 16 ** contact form at http://qt.digia.com
17 17 ** $QT_END_LICENSE$
18 18 **
19 19 ****************************************************************************/
20 20
21 21 // W A R N I N G
22 22 // -------------
23 23 //
24 24 // This file is not part of the QtCommercial Chart API. It exists purely as an
25 25 // implementation detail. This header file may change from version to
26 26 // version without notice, or even be removed.
27 27 //
28 28 // We mean it.
29 29
30 30 #ifndef QAREASERIES_P_H
31 31 #define QAREASERIES_P_H
32 32
33 #include "qseries_p.h"
33 #include "qabstractseries_p.h"
34 34
35 35 QTCOMMERCIALCHART_BEGIN_NAMESPACE
36 36
37 37 class QAreaSeries;
38 38
39 class QAreaSeriesPrivate: public QSeriesPrivate
39 class QAreaSeriesPrivate: public QAbstractSeriesPrivate
40 40 {
41 41 Q_OBJECT
42 42
43 43 public:
44 44 QAreaSeriesPrivate(QLineSeries *upperSeries, QLineSeries *lowerSeries,QAreaSeries* q);
45 45
46 46 void scaleDomain(Domain& domain);
47 47 Chart* createGraphics(ChartPresenter* presenter);
48 48 QList<LegendMarker*> createLegendMarker(QLegend* legend);
49 49
50 50 Q_SIGNALS:
51 51 void updated();
52 52
53 53 protected:
54 54 QBrush m_brush;
55 55 QPen m_pen;
56 56 QLineSeries* m_upperSeries;
57 57 QLineSeries* m_lowerSeries;
58 58 bool m_pointsVisible;
59 59 private:
60 60 Q_DECLARE_PUBLIC(QAreaSeries);
61 61 };
62 62
63 63 QTCOMMERCIALCHART_END_NAMESPACE
64 64
65 65 #endif
@@ -1,78 +1,78
1 1 /****************************************************************************
2 2 **
3 3 ** Copyright (C) 2012 Digia Plc
4 4 ** All rights reserved.
5 5 ** For any questions to Digia, please use contact form at http://qt.digia.com
6 6 **
7 7 ** This file is part of the Qt Commercial Charts Add-on.
8 8 **
9 9 ** $QT_BEGIN_LICENSE$
10 10 ** Licensees holding valid Qt Commercial licenses may use this file in
11 11 ** accordance with the Qt Commercial License Agreement provided with the
12 12 ** Software or, alternatively, in accordance with the terms contained in
13 13 ** a written agreement between you and Digia.
14 14 **
15 15 ** If you have questions regarding the use of this file, please use
16 16 ** contact form at http://qt.digia.com
17 17 ** $QT_END_LICENSE$
18 18 **
19 19 ****************************************************************************/
20 20
21 21 #ifndef BARCHARTMODEL_H
22 22 #define BARCHARTMODEL_H
23 23
24 24 #include <QObject>
25 25 #include <QStringList>
26 26 #include "qchartglobal.h"
27 #include <qseries.h>
27 #include <qabstractseries.h>
28 28
29 29 QTCOMMERCIALCHART_BEGIN_NAMESPACE
30 30
31 31 // Model for bar chart. Internal class.
32 32 // TODO: Implement as QAbstractItemModel?
33 33
34 34 class QBarSet;
35 35
36 36 class BarChartModel : public QObject //, public QAbstractItemModel
37 37 {
38 38 Q_OBJECT
39 39 public:
40 40 explicit BarChartModel(QStringList categories, QObject *parent = 0);
41 41
42 42 QStringList category();
43 43 void appendBarSet(QBarSet *set);
44 44 void removeBarSet(QBarSet *set);
45 45 void insertBarSet(int i, QBarSet *set);
46 46 void insertCategory(int i, QString category);
47 47 void removeCategory(int i);
48 48 QBarSet *barsetAt(int index) const;
49 49 QList<QBarSet *> barSets() const;
50 50
51 51 int barsetCount() const; // Number of sets in model
52 52 int categoryCount() const; // Number of categories
53 53
54 54 qreal max() const; // Maximum value of all sets
55 55 qreal min() const; // Minimum value of all sets
56 56 qreal valueAt(int set, int category) const;
57 57 qreal percentageAt(int set, int category) const;
58 58
59 59 qreal categorySum(int category) const;
60 60 qreal absoluteCategorySum(int category) const;
61 61 qreal maxCategorySum() const; // returns maximum sum of sets in all categories.
62 62
63 63 QString categoryName(int category);
64 64
65 65 Q_SIGNALS:
66 66 void modelUpdated();
67 67
68 68 public Q_SLOTS:
69 69
70 70 private:
71 71
72 72 QList<QBarSet *> m_dataModel;
73 73 QStringList m_category;
74 74 };
75 75
76 76 QTCOMMERCIALCHART_END_NAMESPACE
77 77
78 78 #endif // BARCHARTMODEL_H
@@ -1,526 +1,527
1 1 /****************************************************************************
2 2 **
3 3 ** Copyright (C) 2012 Digia Plc
4 4 ** All rights reserved.
5 5 ** For any questions to Digia, please use contact form at http://qt.digia.com
6 6 **
7 7 ** This file is part of the Qt Commercial Charts Add-on.
8 8 **
9 9 ** $QT_BEGIN_LICENSE$
10 10 ** Licensees holding valid Qt Commercial licenses may use this file in
11 11 ** accordance with the Qt Commercial License Agreement provided with the
12 12 ** Software or, alternatively, in accordance with the terms contained in
13 13 ** a written agreement between you and Digia.
14 14 **
15 15 ** If you have questions regarding the use of this file, please use
16 16 ** contact form at http://qt.digia.com
17 17 ** $QT_END_LICENSE$
18 18 **
19 19 ****************************************************************************/
20 20
21 21 #include "qbarseries.h"
22 22 #include "qbarseries_p.h"
23 23 #include "qbarset.h"
24 24 #include "qbarset_p.h"
25 25 #include "barchartmodel_p.h"
26 26 #include "domain_p.h"
27 27 #include "legendmarker_p.h"
28 28 #include "chartdataset_p.h"
29 29 #include "charttheme_p.h"
30 30 #include "chartanimator_p.h"
31 31
32 32 #include <QAbstractItemModel>
33 33 #include <QModelIndex>
34 34
35 35 QTCOMMERCIALCHART_BEGIN_NAMESPACE
36 36
37 37 /*!
38 38 \class QBarSeries
39 39 \brief part of QtCommercial chart API.
40 40
41 41 QBarSeries represents a series of data shown as bars. One QBarSeries can contain multiple
42 42 QBarSet data sets. QBarSeries groups the data from sets to categories, which are defined
43 43 by QStringList.
44 44
45 45 \mainclass
46 46
47 47 \sa QBarSet, QStackedBarSeries, QPercentBarSeries
48 48 */
49 49
50 50 /*!
51 51 \fn void QBarSeries::clicked(QBarSet *barset, QString category, Qt::MouseButtons button)
52 52
53 53 The signal is emitted if the user clicks with a mouse \a button on top of QBarSet \a barset of category \a category
54 54 contained by the series.
55 55 */
56 56
57 57 /*!
58 58 \fn void QBarSeries::selected()
59 59
60 60 The signal is emitted if the user selects/deselects the series. The logic for storing selections should be
61 61 implemented by the user of QBarSeries API.
62 62 */
63 63
64 64 /*!
65 65 \fn void QBarSeries::hovered(QBarSet* barset, bool status)
66 66
67 67 The signal is emitted if mouse is hovered on top of series.
68 68 Parameter \a barset is the pointer of barset, where hover happened.
69 69 Parameter \a status is true, if mouse entered on top of series, false if mouse left from top of series.
70 70 */
71 71
72 72 /*!
73 73 Constructs empty QBarSeries. Parameter \a categories defines the categories for chart.
74 74 QBarSeries is QObject which is a child of a \a parent.
75 75 */
76 76 QBarSeries::QBarSeries(QBarCategories categories, QObject *parent) :
77 QSeries(*new QBarSeriesPrivate(categories, this),parent)
77 QAbstractSeries(*new QBarSeriesPrivate(categories, this),parent)
78 78 {
79 79 }
80 80
81 81 /*!
82 82 Destructs barseries and owned barsets.
83 83 */
84 84 QBarSeries::~QBarSeries()
85 85 {
86 86 // NOTE: d_ptr destroyed by QObject
87 87 }
88 88
89 89 /*!
90 90 \internal
91 91 */
92 92 QBarSeries::QBarSeries(QBarSeriesPrivate &d, QObject *parent) :
93 QSeries(d,parent)
93 QAbstractSeries(d,parent)
94 94 {
95 95 }
96 96
97 97 /*!
98 98 Returns the type of series. Derived classes override this.
99 99 */
100 QSeries::QSeriesType QBarSeries::type() const
100 QAbstractSeries::QSeriesType QBarSeries::type() const
101 101 {
102 return QSeries::SeriesTypeBar;
102 return QAbstractSeries::SeriesTypeBar;
103 103 }
104 104
105 105 /*!
106 106 Adds a set of bars to series. Takes ownership of \a set.
107 107 Connects the clicked(QString, Qt::MouseButtons) signal
108 108 of \a set to this series
109 109 */
110 110 void QBarSeries::appendBarSet(QBarSet *set)
111 111 {
112 112 Q_D(QBarSeries);
113 113 d->m_internalModel->appendBarSet(set);
114 114 QObject::connect(set->d_ptr.data(), SIGNAL(valueChanged()), d, SLOT(barsetChanged()));
115 115 emit d->restructuredBars();
116 116 }
117 117
118 118 /*!
119 119 Removes a set of bars from series. Releases ownership of \a set. Doesn't delete \a set.
120 120 Disconnects the clicked(QString, Qt::MouseButtons) signal
121 121 of \a set from this series
122 122 */
123 123 void QBarSeries::removeBarSet(QBarSet *set)
124 124 {
125 125 Q_D(QBarSeries);
126 126 d->m_internalModel->removeBarSet(set);
127 127 emit d->restructuredBars();
128 128 }
129 129
130 130 /*!
131 131 Adds a list of barsets to series. Takes ownership of \a sets.
132 132 Connects the clicked(QString, Qt::MouseButtons) signals
133 133 of \a sets to this series
134 134 */
135 135 void QBarSeries::appendBarSets(QList<QBarSet* > sets)
136 136 {
137 137 Q_D(QBarSeries);
138 138 foreach (QBarSet* barset, sets) {
139 139 d->m_internalModel->appendBarSet(barset);
140 140 QObject::connect(barset, SIGNAL(valueChanged()), this, SLOT(barsetChanged()));
141 141 }
142 142 emit d->restructuredBars();
143 143
144 144 }
145 145
146 146 /*!
147 147 Removes a list of barsets from series. Releases ownership of \a sets. Doesn't delete \a sets.
148 148 Disconnects the clicked(QString, Qt::MouseButtons) signal
149 149 of \a sets from this series
150 150 */
151 151 void QBarSeries::removeBarSets(QList<QBarSet* > sets)
152 152 {
153 153 Q_D(QBarSeries);
154 154
155 155 foreach (QBarSet* barset, sets) {
156 156 d->m_internalModel->removeBarSet(barset);
157 157 }
158 158 emit d->restructuredBars();
159 159 }
160 160
161 161 /*!
162 162 Inserts new \a set on the \a i position.
163 163 The barset that is currently at this postion is moved to postion i + 1
164 164 */
165 165 void QBarSeries::insertBarSet(int i, QBarSet *set)
166 166 {
167 167 Q_D(QBarSeries);
168 168 d->m_internalModel->insertBarSet(i, set);
169 169 emit d->barsetChanged();
170 170 }
171 171
172 172 /*!
173 173 Inserts new \a category on the \a i position.
174 174 The category that is currently at this postion is moved to postion i + 1
175 175 \sa removeCategory()
176 176 */
177 177 void QBarSeries::insertCategory(int i, QString category)
178 178 {
179 179 Q_D(QBarSeries);
180 180 d->m_internalModel->insertCategory(i, category);
181 181 }
182 182
183 183 /*!
184 184 Removes the category specified by \a i
185 185 \sa insertCategory()
186 186 */
187 187 void QBarSeries::removeCategory(int i)
188 188 {
189 189 Q_D(QBarSeries);
190 190 d->m_internalModel->removeCategory(i);
191 191 }
192 192
193 193 /*!
194 194 Returns number of sets in series.
195 195 */
196 196 int QBarSeries::barsetCount() const
197 197 {
198 198 Q_D(const QBarSeries);
199 199 return d->m_internalModel->barsetCount();
200 200 }
201 201
202 202 /*!
203 203 Returns number of categories in series
204 204 */
205 205 int QBarSeries::categoryCount() const
206 206 {
207 207 Q_D(const QBarSeries);
208 208 return d->m_internalModel->categoryCount();
209 209 }
210 210
211 211 /*!
212 212 Returns a list of sets in series. Keeps ownership of sets.
213 213 */
214 214 QList<QBarSet*> QBarSeries::barSets() const
215 215 {
216 216 Q_D(const QBarSeries);
217 217 return d->m_internalModel->barSets();
218 218 }
219 219
220 220 /*!
221 221 \fn bool QBarSeries::setModel(QAbstractItemModel *model)
222 222 Sets the \a model to be used as a data source
223 223 */
224 224 bool QBarSeries::setModel(QAbstractItemModel *model)
225 225 {
226 226 Q_D(QBarSeries);
227 227 return d->setModel(model);
228 228 }
229 229
230 230 /*!
231 231 \fn bool QBarSeries::setModelMapping(int categories, int bottomBoundry, int topBoundry, Qt::Orientation orientation)
232 232 Sets column/row specified by \a categories to be used as a list of bar series categories.
233 233 Parameter \a bottomBoundry indicates the column/row where the first bar set is located in the model.
234 234 Parameter \a topBoundry indicates the column/row where the last bar set is located in the model.
235 235 All the columns/rows inbetween those two values are also used as data for bar sets.
236 236 The \a orientation parameter specifies whether the data is in columns or in rows.
237 237 */
238 238 void QBarSeries::setModelMapping(int categories, int bottomBoundary, int topBoundary, Qt::Orientation orientation)
239 239 {
240 240 Q_D(QBarSeries);
241 241 d->setModelMapping(categories,bottomBoundary,topBoundary,orientation);
242 242 }
243 243
244 244 /*!
245 245 Returns the bar categories of the series.
246 246 */
247 247 QBarCategories QBarSeries::categories() const
248 248 {
249 249 Q_D(const QBarSeries);
250 250
251 251 QBarCategories categories;
252 252 int count = d->m_internalModel->categoryCount();
253 253 for (int i=1; i <= count; i++) {
254 254 categories.insert(i, d->m_internalModel->categoryName(i - 1));
255 255 }
256 256 return categories;
257 257
258 258 }
259 259
260 260 /*!
261 261 Sets the visibility of labels in series to \a visible
262 262 */
263 263 void QBarSeries::setLabelsVisible(bool visible)
264 264 {
265 265 foreach (QBarSet* s, barSets()) {
266 266 s->setLabelsVisible(visible);
267 267 }
268 268 }
269 269
270 270 ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
271 271
272 QBarSeriesPrivate::QBarSeriesPrivate(QBarCategories categories, QBarSeries *q) : QSeriesPrivate(q),
272 QBarSeriesPrivate::QBarSeriesPrivate(QBarCategories categories, QBarSeries *q) :
273 QAbstractSeriesPrivate(q),
273 274 m_internalModel(new BarChartModel(categories,this)),
274 275 m_model(0),
275 276 m_mapCategories(-1),
276 277 m_mapBarBottom(-1),
277 278 m_mapBarTop(-1),
278 279 m_mapFirst(0),
279 280 m_mapCount(0),
280 281 m_mapOrientation(Qt::Vertical)
281 282 {
282 283 }
283 284
284 285 QBarSet* QBarSeriesPrivate::barsetAt(int index)
285 286 {
286 287 return m_internalModel->barsetAt(index);
287 288 }
288 289
289 290 QString QBarSeriesPrivate::categoryName(int category)
290 291 {
291 292 return m_internalModel->categoryName(category);
292 293 }
293 294
294 295 qreal QBarSeriesPrivate::min()
295 296 {
296 297 return m_internalModel->min();
297 298 }
298 299
299 300 qreal QBarSeriesPrivate::max()
300 301 {
301 302 return m_internalModel->max();
302 303 }
303 304
304 305 qreal QBarSeriesPrivate::valueAt(int set, int category)
305 306 {
306 307 return m_internalModel->valueAt(set, category);
307 308 }
308 309
309 310 qreal QBarSeriesPrivate::percentageAt(int set, int category)
310 311 {
311 312 return m_internalModel->percentageAt(set, category);
312 313 }
313 314
314 315 qreal QBarSeriesPrivate::categorySum(int category)
315 316 {
316 317 return m_internalModel->categorySum(category);
317 318 }
318 319
319 320 qreal QBarSeriesPrivate::absoluteCategorySum(int category)
320 321 {
321 322 return m_internalModel->absoluteCategorySum(category);
322 323 }
323 324
324 325 qreal QBarSeriesPrivate::maxCategorySum()
325 326 {
326 327 return m_internalModel->maxCategorySum();
327 328 }
328 329
329 330 BarChartModel& QBarSeriesPrivate::modelInternal()
330 331 {
331 332 return *m_internalModel;
332 333 }
333 334
334 335 bool QBarSeriesPrivate::setModel(QAbstractItemModel *model)
335 336 {
336 337 // disconnect signals from old model
337 338 if(m_model)
338 339 {
339 340 disconnect(m_model, 0, this, 0);
340 341 m_mapCategories = -1;
341 342 m_mapBarBottom = -1;
342 343 m_mapBarTop = -1;
343 344 m_mapFirst = 0;
344 345 m_mapCount = 0;
345 346 m_mapOrientation = Qt::Vertical;
346 347 }
347 348
348 349 // set new model
349 350 if(model)
350 351 {
351 352 m_model = model;
352 353 return true;
353 354 }
354 355 else
355 356 {
356 357 m_model = 0;
357 358 return false;
358 359 }
359 360 }
360 361
361 362 void QBarSeriesPrivate::setModelMapping(int categories, int bottomBoundry, int topBoundry, Qt::Orientation orientation)
362 363 {
363 364 Q_Q(QBarSeries);
364 365
365 366 if (m_model == 0)
366 367 return;
367 368
368 369 m_mapCategories = categories;
369 370 m_mapBarBottom = bottomBoundry;
370 371 m_mapBarTop = topBoundry;
371 372 // m_mapFirst = 1;
372 373 m_mapOrientation = orientation;
373 374
374 375 // connect the signals
375 376 if (m_mapOrientation == Qt::Vertical) {
376 377 m_mapCount = m_model->rowCount() - m_mapFirst;
377 378 connect(m_model,SIGNAL(dataChanged(QModelIndex,QModelIndex)),
378 379 this, SLOT(modelUpdated(QModelIndex,QModelIndex)));
379 380 connect(m_model,SIGNAL(rowsInserted(QModelIndex,int,int)),
380 381 this, SLOT(modelDataAdded(QModelIndex,int,int)));
381 382 connect(m_model, SIGNAL(rowsRemoved(QModelIndex,int,int)),
382 383 this, SLOT(modelDataRemoved(QModelIndex,int,int)));
383 384 } else {
384 385 m_mapCount = m_model->columnCount() - m_mapFirst;
385 386 connect(m_model,SIGNAL(dataChanged(QModelIndex,QModelIndex)),
386 387 this, SLOT(modelUpdated(QModelIndex,QModelIndex)));
387 388 connect(m_model,SIGNAL(columnsInserted(QModelIndex,int,int)),
388 389 this, SLOT(modelDataAdded(QModelIndex,int,int)));
389 390 connect(m_model, SIGNAL(columnsRemoved(QModelIndex,int,int)),
390 391 this, SLOT(modelDataRemoved(QModelIndex,int,int)));
391 392 }
392 393
393 394 // create the initial bars
394 395 delete m_internalModel;
395 396 if (m_mapOrientation == Qt::Vertical) {
396 397 QStringList categories;
397 398 for (int k = m_mapFirst; k < m_mapFirst + m_mapCount; k++)
398 399 categories << m_model->data(m_model->index(k, m_mapCategories), Qt::DisplayRole).toString();
399 400 m_internalModel = new BarChartModel(categories, this);
400 401
401 402 for (int i = m_mapBarBottom; i <= m_mapBarTop; i++) {
402 403 QBarSet* barSet = new QBarSet(QString("Column: %1").arg(i + 1));
403 404 for(int m = m_mapFirst; m < m_mapFirst + m_mapCount; m++)
404 405 *barSet << m_model->data(m_model->index(m, i), Qt::DisplayRole).toDouble();
405 406 q->appendBarSet(barSet);
406 407 }
407 408 } else {
408 409 QStringList categories;
409 410 for (int k = m_mapFirst; k < m_mapFirst + m_mapCount; k++)
410 411 categories << m_model->data(m_model->index(m_mapCategories, k), Qt::DisplayRole).toString();
411 412 m_internalModel = new BarChartModel(categories, this);
412 413
413 414 for (int i = m_mapBarBottom; i <= m_mapBarTop; i++) {
414 415 QBarSet* barSet = new QBarSet(QString("Row: %1").arg(i + 1));
415 416 for(int m = m_mapFirst; m < m_mapFirst + m_mapCount; m++)
416 417 *barSet << m_model->data(m_model->index(i, m), Qt::DisplayRole).toDouble();
417 418 q->appendBarSet(barSet);
418 419 }
419 420 }
420 421 }
421 422
422 423 void QBarSeriesPrivate::modelUpdated(QModelIndex topLeft, QModelIndex bottomRight)
423 424 {
424 425 Q_UNUSED(bottomRight)
425 426
426 427 if (m_mapOrientation == Qt::Vertical)
427 428 {
428 429 // model update is relevant to BarSeries if the change was made to the part of the model that was mapped to BarSeries
429 430 if (topLeft.column() >= m_mapBarBottom && topLeft.column() <= m_mapBarTop && topLeft.row() >= m_mapFirst && topLeft.row() < m_mapFirst + m_mapCount)
430 431 barsetAt(topLeft.column() - m_mapBarBottom)->setValue(topLeft.row() - m_mapFirst, m_model->data(topLeft, Qt::DisplayRole).toDouble());
431 432 }
432 433 else
433 434 {
434 435 // model update is relevant to BarSeries if the change was made to the part of the model that was mapped to BarSeries
435 436 if (topLeft.row() >= m_mapBarBottom && topLeft.row() <= m_mapBarTop && topLeft.column() >= m_mapFirst && topLeft.column() < m_mapFirst + m_mapCount)
436 437 barsetAt(topLeft.row() - m_mapBarBottom)->setValue(topLeft.column() - m_mapFirst, m_model->data(topLeft, Qt::DisplayRole).toDouble());
437 438 }
438 439 }
439 440
440 441 void QBarSeriesPrivate::modelDataAdded(QModelIndex /*parent*/, int start, int /*end*/)
441 442 {
442 443 Q_Q(QBarSeries);
443 444
444 445 if (m_mapOrientation == Qt::Vertical) {
445 446 q->insertCategory(start - m_mapFirst, QString("Row: %1").arg(start + 1));
446 447 for (int i = 0; i <= m_mapBarTop - m_mapBarBottom; i++) {
447 448 barsetAt(i)->insertValue(start - m_mapFirst, m_model->data(m_model->index(start, i), Qt::DisplayRole).toDouble());
448 449 }
449 450 } else {
450 451 q->insertCategory(start - m_mapFirst, QString("Column: %1").arg(start + 1));
451 452 for (int i = 0; i <= m_mapBarTop - m_mapBarBottom; i++) {
452 453 barsetAt(i)->insertValue(start - m_mapFirst, m_model->data(m_model->index(i, start), Qt::DisplayRole).toDouble());
453 454 }
454 455 }
455 456 emit restructuredBars();
456 457 }
457 458
458 459 void QBarSeriesPrivate::modelDataRemoved(QModelIndex parent, int start, int end)
459 460 {
460 461 Q_Q(QBarSeries);
461 462 Q_UNUSED(parent)
462 463 Q_UNUSED(end)
463 464
464 465 q->removeCategory(start - m_mapFirst);
465 466 for (int i = 0; i <= m_mapBarTop - m_mapBarBottom; i++)
466 467 {
467 468 barsetAt(i)->removeValue(start - m_mapFirst);
468 469 }
469 470 emit restructuredBars();
470 471 }
471 472
472 473 void QBarSeriesPrivate::barsetChanged()
473 474 {
474 475 emit updatedBars();
475 476 }
476 477
477 478 void QBarSeriesPrivate::scaleDomain(Domain& domain)
478 479 {
479 480 qreal minX(domain.minX());
480 481 qreal minY(domain.minY());
481 482 qreal maxX(domain.maxX());
482 483 qreal maxY(domain.maxY());
483 484 int tickXCount(domain.tickXCount());
484 485 int tickYCount(domain.tickYCount());
485 486
486 487 qreal x = m_internalModel->categoryCount();
487 488 qreal y = max();
488 489 minX = qMin(minX, x);
489 490 minY = qMin(minY, y);
490 491 maxX = qMax(maxX, x);
491 492 maxY = qMax(maxY, y);
492 493 tickXCount = x+1;
493 494
494 495 domain.setRangeX(minX,maxX,tickXCount);
495 496 domain.setRangeY(minY,maxY,tickYCount);
496 497 }
497 498
498 499 Chart* QBarSeriesPrivate::createGraphics(ChartPresenter* presenter)
499 500 {
500 501 Q_Q(QBarSeries);
501 502
502 503 BarChartItem* bar = new BarChartItem(q,presenter);
503 504 if(presenter->animationOptions().testFlag(QChart::SeriesAnimations)) {
504 505 presenter->animator()->addAnimation(bar);
505 506 }
506 507 presenter->chartTheme()->decorate(q, presenter->dataSet()->seriesIndex(q));
507 508 return bar;
508 509
509 510 }
510 511
511 512 QList<LegendMarker*> QBarSeriesPrivate::createLegendMarker(QLegend* legend)
512 513 {
513 514 Q_Q(QBarSeries);
514 515 QList<LegendMarker*> markers;
515 516 foreach(QBarSet* set, q->barSets()) {
516 517 BarLegendMarker* marker = new BarLegendMarker(q,set,legend);
517 518 markers << marker;
518 519 }
519 520
520 521 return markers;
521 522 }
522 523
523 524 #include "moc_qbarseries.cpp"
524 525 #include "moc_qbarseries_p.cpp"
525 526
526 527 QTCOMMERCIALCHART_END_NAMESPACE
@@ -1,82 +1,82
1 1 /****************************************************************************
2 2 **
3 3 ** Copyright (C) 2012 Digia Plc
4 4 ** All rights reserved.
5 5 ** For any questions to Digia, please use contact form at http://qt.digia.com
6 6 **
7 7 ** This file is part of the Qt Commercial Charts Add-on.
8 8 **
9 9 ** $QT_BEGIN_LICENSE$
10 10 ** Licensees holding valid Qt Commercial licenses may use this file in
11 11 ** accordance with the Qt Commercial License Agreement provided with the
12 12 ** Software or, alternatively, in accordance with the terms contained in
13 13 ** a written agreement between you and Digia.
14 14 **
15 15 ** If you have questions regarding the use of this file, please use
16 16 ** contact form at http://qt.digia.com
17 17 ** $QT_END_LICENSE$
18 18 **
19 19 ****************************************************************************/
20 20
21 21 #ifndef BARSERIES_H
22 22 #define BARSERIES_H
23 23
24 #include <qseries.h>
24 #include <qabstractseries.h>
25 25 #include <QStringList>
26 26
27 27 class QModelIndex;
28 28
29 29 QTCOMMERCIALCHART_BEGIN_NAMESPACE
30 30
31 31 typedef QStringList QBarCategories;
32 32
33 33 class QBarSet;
34 34 class BarChartModel;
35 35 class BarCategory;
36 36 class QBarSeriesPrivate;
37 37
38 38 // Container for series
39 class QTCOMMERCIALCHART_EXPORT QBarSeries : public QSeries
39 class QTCOMMERCIALCHART_EXPORT QBarSeries : public QAbstractSeries
40 40 {
41 41 Q_OBJECT
42 42 public:
43 43 explicit QBarSeries(QBarCategories categories, QObject *parent = 0);
44 44 virtual ~QBarSeries();
45 45
46 QSeries::QSeriesType type() const;
46 QAbstractSeries::QSeriesType type() const;
47 47
48 48 void appendBarSet(QBarSet *set); // Takes ownership of set
49 49 void removeBarSet(QBarSet *set); // Releases ownership, doesn't delete set
50 50 void appendBarSets(QList<QBarSet* > sets);
51 51 void removeBarSets(QList<QBarSet* > sets);
52 52 void insertBarSet(int i, QBarSet *set);
53 53 void insertCategory(int i, QString category);
54 54 void removeCategory(int i);
55 55 int barsetCount() const;
56 56 int categoryCount() const;
57 57 QList<QBarSet*> barSets() const;
58 58 QBarCategories categories() const;
59 59
60 60 void setLabelsVisible(bool visible = true);
61 61
62 62 bool setModel(QAbstractItemModel *model);
63 63 void setModelMapping(int categories, int bottomBoundary, int topBoundary, Qt::Orientation orientation = Qt::Vertical);
64 64
65 65 protected:
66 66 explicit QBarSeries(QBarSeriesPrivate &d,QObject *parent = 0);
67 67
68 68 Q_SIGNALS:
69 69 void clicked(QBarSet *barset, QString category, Qt::MouseButtons button);
70 70 void selected();
71 71 void hovered(QBarSet* barset, bool status);
72 72
73 73 protected:
74 74 Q_DECLARE_PRIVATE(QBarSeries)
75 75 friend class BarChartItem;
76 76 friend class PercentBarChartItem;
77 77 friend class StackedBarChartItem;
78 78 };
79 79
80 80 QTCOMMERCIALCHART_END_NAMESPACE
81 81
82 82 #endif // BARSERIES_H
@@ -1,66 +1,66
1 1 #ifndef QBARSERIES_P_H
2 2 #define QBARSERIES_P_H
3 3
4 4 #include "qbarseries.h"
5 #include "qseries_p.h"
5 #include "qabstractseries_p.h"
6 6 #include <QStringList>
7 #include <QSeries>
7 #include <QAbstractSeries>
8 8
9 9 class QModelIndex;
10 10
11 11 QTCOMMERCIALCHART_BEGIN_NAMESPACE
12 12
13 13 // Container for series
14 class QBarSeriesPrivate : public QSeriesPrivate
14 class QBarSeriesPrivate : public QAbstractSeriesPrivate
15 15 {
16 16 Q_OBJECT
17 17 public:
18 18 QBarSeriesPrivate(QBarCategories categories, QBarSeries *parent);
19 19
20 20 void scaleDomain(Domain& domain);
21 21 Chart* createGraphics(ChartPresenter* presenter);
22 22 QList<LegendMarker*> createLegendMarker(QLegend* legend);
23 23
24 24 bool setModel(QAbstractItemModel *model);
25 25 void setModelMapping(int categories, int bottomBoundry, int topBoundry, Qt::Orientation orientation = Qt::Vertical);
26 26
27 27 QBarSet* barsetAt(int index);
28 28 QString categoryName(int category);
29 29 qreal min();
30 30 qreal max();
31 31 qreal valueAt(int set, int category);
32 32 qreal percentageAt(int set, int category);
33 33 qreal categorySum(int category);
34 34 qreal absoluteCategorySum(int category);
35 35 qreal maxCategorySum();
36 36 BarChartModel& modelInternal();
37 37
38 38 Q_SIGNALS:
39 39 void clicked(QBarSet *barset, QString category, Qt::MouseButtons button);
40 40 void selected();
41 41 void updatedBars();
42 42 void restructuredBars();
43 43
44 44 private Q_SLOTS:
45 45 // slots for updating bars when data in model changes
46 46 void modelUpdated(QModelIndex topLeft, QModelIndex bottomRight);
47 47 void modelDataAdded(QModelIndex parent, int start, int end);
48 48 void modelDataRemoved(QModelIndex parent, int start, int end);
49 49 void barsetChanged();
50 50
51 51 protected:
52 52 BarChartModel *m_internalModel; // TODO: this may change... current "2 models" situation doesn't look good.
53 53 QAbstractItemModel* m_model;
54 54 int m_mapCategories;
55 55 int m_mapBarBottom;
56 56 int m_mapBarTop;
57 57 int m_mapFirst;
58 58 int m_mapCount;
59 59 Qt::Orientation m_mapOrientation;
60 60 private:
61 61 Q_DECLARE_PUBLIC(QBarSeries)
62 62 };
63 63
64 64 QTCOMMERCIALCHART_END_NAMESPACE
65 65
66 66 #endif // QBARSERIESPRIVATE_P_H
@@ -1,108 +1,108
1 1 /****************************************************************************
2 2 **
3 3 ** Copyright (C) 2012 Digia Plc
4 4 ** All rights reserved.
5 5 ** For any questions to Digia, please use contact form at http://qt.digia.com
6 6 **
7 7 ** This file is part of the Qt Commercial Charts Add-on.
8 8 **
9 9 ** $QT_BEGIN_LICENSE$
10 10 ** Licensees holding valid Qt Commercial licenses may use this file in
11 11 ** accordance with the Qt Commercial License Agreement provided with the
12 12 ** Software or, alternatively, in accordance with the terms contained in
13 13 ** a written agreement between you and Digia.
14 14 **
15 15 ** If you have questions regarding the use of this file, please use
16 16 ** contact form at http://qt.digia.com
17 17 ** $QT_END_LICENSE$
18 18 **
19 19 ****************************************************************************/
20 20
21 21 #include "qpercentbarseries.h"
22 22 #include "qpercentbarseries_p.h"
23 23 #include "percentbarchartitem_p.h"
24 24 #include "chartdataset_p.h"
25 25 #include "charttheme_p.h"
26 26 #include "chartanimator_p.h"
27 27
28 28
29 29 QTCOMMERCIALCHART_BEGIN_NAMESPACE
30 30
31 31 /*!
32 32 \class QPercentBarSeries
33 33 \brief part of QtCommercial chart API.
34 34
35 35 QPercentBarSeries represents a series of data shown as bars. Each bar of QBarSet is shown as percentage
36 36 of all bars in category. One QPercentBarSeries can contain multiple QBarSet data sets.
37 37 QBarSeries groups the data from sets to categories, which are defined by QStringList.
38 38
39 39 \mainclass
40 40
41 41 \sa QBarSet, QStackedBarSeries, QBarSeries
42 42 */
43 43
44 44 /*!
45 45 \fn virtual QSeriesType QPercentBarSeries::type() const
46 46 \brief Returns type of series.
47 \sa QSeries, QSeriesType
47 \sa QAbstractSeries, QSeriesType
48 48 */
49 49
50 50 /*!
51 51 Constructs empty QPercentBarSeries. Parameter \a categories defines the categories for chart.
52 52 QPercentBarSeries is QObject which is a child of a \a parent.
53 53 */
54 54 QPercentBarSeries::QPercentBarSeries(QBarCategories categories, QObject *parent)
55 55 : QBarSeries(*new QPercentBarSeriesPrivate(categories,this), parent)
56 56 {
57 57 }
58 58
59 QSeries::QSeriesType QPercentBarSeries::type() const
59 QAbstractSeries::QSeriesType QPercentBarSeries::type() const
60 60 {
61 return QSeries::SeriesTypePercentBar;
61 return QAbstractSeries::SeriesTypePercentBar;
62 62 }
63 63
64 64 ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
65 65
66 66 QPercentBarSeriesPrivate::QPercentBarSeriesPrivate(QBarCategories categories, QPercentBarSeries *q) : QBarSeriesPrivate(categories,q)
67 67 {
68 68
69 69 }
70 70
71 71 void QPercentBarSeriesPrivate::scaleDomain(Domain& domain)
72 72 {
73 73 Q_Q(QPercentBarSeries);
74 74 qreal minX(domain.minX());
75 75 qreal minY(domain.minY());
76 76 qreal maxX(domain.maxX());
77 77 qreal maxY(domain.maxY());
78 78 int tickXCount(domain.tickXCount());
79 79 int tickYCount(domain.tickYCount());
80 80
81 81 qreal x = q->categoryCount();
82 82 minX = qMin(minX, x);
83 83 maxX = qMax(maxX, x);
84 84 minY = 0;
85 85 maxY = 100;
86 86 tickXCount = x+1;
87 87
88 88 domain.setRangeX(minX,maxX,tickXCount);
89 89 domain.setRangeY(minY,maxY,tickYCount);
90 90 }
91 91
92 92
93 93 Chart* QPercentBarSeriesPrivate::createGraphics(ChartPresenter* presenter)
94 94 {
95 95 Q_Q(QPercentBarSeries);
96 96
97 97 PercentBarChartItem* bar = new PercentBarChartItem(q,presenter);
98 98 if(presenter->animationOptions().testFlag(QChart::SeriesAnimations)) {
99 99 presenter->animator()->addAnimation(bar);
100 100 }
101 101 presenter->chartTheme()->decorate(q, presenter->dataSet()->seriesIndex(q));
102 102 return bar;
103 103 }
104 104
105 105 #include "moc_qpercentbarseries.cpp"
106 106
107 107 QTCOMMERCIALCHART_END_NAMESPACE
108 108
@@ -1,44 +1,44
1 1 /****************************************************************************
2 2 **
3 3 ** Copyright (C) 2012 Digia Plc
4 4 ** All rights reserved.
5 5 ** For any questions to Digia, please use contact form at http://qt.digia.com
6 6 **
7 7 ** This file is part of the Qt Commercial Charts Add-on.
8 8 **
9 9 ** $QT_BEGIN_LICENSE$
10 10 ** Licensees holding valid Qt Commercial licenses may use this file in
11 11 ** accordance with the Qt Commercial License Agreement provided with the
12 12 ** Software or, alternatively, in accordance with the terms contained in
13 13 ** a written agreement between you and Digia.
14 14 **
15 15 ** If you have questions regarding the use of this file, please use
16 16 ** contact form at http://qt.digia.com
17 17 ** $QT_END_LICENSE$
18 18 **
19 19 ****************************************************************************/
20 20
21 21 #ifndef PERCENTBARSERIES_H
22 22 #define PERCENTBARSERIES_H
23 23
24 24 #include <QStringList>
25 25 #include <qbarseries.h>
26 26
27 27 QTCOMMERCIALCHART_BEGIN_NAMESPACE
28 28
29 29 class QPercentBarSeriesPrivate;
30 30
31 31 class QTCOMMERCIALCHART_EXPORT QPercentBarSeries : public QBarSeries
32 32 {
33 33 Q_OBJECT
34 34 public:
35 35 explicit QPercentBarSeries(QBarCategories categories, QObject *parent = 0);
36 QSeries::QSeriesType type() const;
36 QAbstractSeries::QSeriesType type() const;
37 37 private:
38 38 Q_DECLARE_PRIVATE(QPercentBarSeries)
39 39 Q_DISABLE_COPY(QPercentBarSeries)
40 40 };
41 41
42 42 QTCOMMERCIALCHART_END_NAMESPACE
43 43
44 44 #endif // PERCENTBARSERIES_H
@@ -1,108 +1,108
1 1 /****************************************************************************
2 2 **
3 3 ** Copyright (C) 2012 Digia Plc
4 4 ** All rights reserved.
5 5 ** For any questions to Digia, please use contact form at http://qt.digia.com
6 6 **
7 7 ** This file is part of the Qt Commercial Charts Add-on.
8 8 **
9 9 ** $QT_BEGIN_LICENSE$
10 10 ** Licensees holding valid Qt Commercial licenses may use this file in
11 11 ** accordance with the Qt Commercial License Agreement provided with the
12 12 ** Software or, alternatively, in accordance with the terms contained in
13 13 ** a written agreement between you and Digia.
14 14 **
15 15 ** If you have questions regarding the use of this file, please use
16 16 ** contact form at http://qt.digia.com
17 17 ** $QT_END_LICENSE$
18 18 **
19 19 ****************************************************************************/
20 20
21 21 #include "qstackedbarseries.h"
22 22 #include "qstackedbarseries_p.h"
23 23 #include "stackedbarchartitem_p.h"
24 24 #include "barchartmodel_p.h"
25 25 #include "chartdataset_p.h"
26 26 #include "charttheme_p.h"
27 27 #include "chartanimator_p.h"
28 28
29 29 QTCOMMERCIALCHART_BEGIN_NAMESPACE
30 30
31 31 /*!
32 32 \class QStackedBarSeries
33 33 \brief part of QtCommercial chart API.
34 34
35 35 QStackedBarSeries represents a series of data shown as bars. All bars in same category are
36 36 stacked on top of each other. One QStackedBarSeries can contain multiple QBarSet data sets.
37 37 QStackedBarSeries groups the data from sets to categories, which are defined by QStringList.
38 38
39 39 \mainclass
40 40
41 41 \sa QBarSet, QPercentBarSeries, QBarSeries
42 42 */
43 43
44 44 /*!
45 45 \fn virtual QSeriesType QStackedBarSeries::type() const
46 46 \brief Returns type of series.
47 \sa QSeries, QSeriesType
47 \sa QSeriesType
48 48 */
49 49
50 50 /*!
51 51 Constructs empty QStackedBarSeries. Parameter \a categories defines the categories for chart.
52 52 QStackedBarSeries is QObject which is a child of a \a parent.
53 53 */
54 54 QStackedBarSeries::QStackedBarSeries(QBarCategories categories, QObject *parent)
55 55 : QBarSeries(*new QStackedBarSeriesPrivate(categories,this), parent)
56 56 {
57 57 }
58 58
59 QSeries::QSeriesType QStackedBarSeries::type() const
59 QAbstractSeries::QSeriesType QStackedBarSeries::type() const
60 60 {
61 return QSeries::SeriesTypeStackedBar;
61 return QAbstractSeries::SeriesTypeStackedBar;
62 62 }
63 63
64 64 ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
65 65
66 66 QStackedBarSeriesPrivate::QStackedBarSeriesPrivate(QBarCategories categories, QStackedBarSeries *q) : QBarSeriesPrivate(categories,q)
67 67 {
68 68
69 69 }
70 70
71 71 void QStackedBarSeriesPrivate::scaleDomain(Domain& domain)
72 72 {
73 73 qreal minX(domain.minX());
74 74 qreal minY(domain.minY());
75 75 qreal maxX(domain.maxX());
76 76 qreal maxY(domain.maxY());
77 77 int tickXCount(domain.tickXCount());
78 78 int tickYCount(domain.tickYCount());
79 79
80 80 qreal x = m_internalModel->categoryCount();
81 81 qreal y = maxCategorySum();
82 82 minX = qMin(minX, x);
83 83 minY = qMin(minY, y);
84 84 maxX = qMax(maxX, x);
85 85 maxY = qMax(maxY, y);
86 86 tickXCount = x+1;
87 87
88 88 domain.setRangeX(minX,maxX,tickXCount);
89 89 domain.setRangeY(minY,maxY,tickYCount);
90 90 }
91 91
92 92
93 93 Chart* QStackedBarSeriesPrivate::createGraphics(ChartPresenter* presenter)
94 94 {
95 95 Q_Q(QStackedBarSeries);
96 96
97 97 StackedBarChartItem* bar = new StackedBarChartItem(q,presenter);
98 98 if(presenter->animationOptions().testFlag(QChart::SeriesAnimations)) {
99 99 presenter->animator()->addAnimation(bar);
100 100 }
101 101 presenter->chartTheme()->decorate(q, presenter->dataSet()->seriesIndex(q));
102 102 return bar;
103 103 }
104 104
105 105 #include "moc_qstackedbarseries.cpp"
106 106
107 107 QTCOMMERCIALCHART_END_NAMESPACE
108 108
@@ -1,44 +1,44
1 1 /****************************************************************************
2 2 **
3 3 ** Copyright (C) 2012 Digia Plc
4 4 ** All rights reserved.
5 5 ** For any questions to Digia, please use contact form at http://qt.digia.com
6 6 **
7 7 ** This file is part of the Qt Commercial Charts Add-on.
8 8 **
9 9 ** $QT_BEGIN_LICENSE$
10 10 ** Licensees holding valid Qt Commercial licenses may use this file in
11 11 ** accordance with the Qt Commercial License Agreement provided with the
12 12 ** Software or, alternatively, in accordance with the terms contained in
13 13 ** a written agreement between you and Digia.
14 14 **
15 15 ** If you have questions regarding the use of this file, please use
16 16 ** contact form at http://qt.digia.com
17 17 ** $QT_END_LICENSE$
18 18 **
19 19 ****************************************************************************/
20 20
21 21 #ifndef STACKEDBARSERIES_H
22 22 #define STACKEDBARSERIES_H
23 23
24 24 #include <QStringList>
25 25 #include <qbarseries.h>
26 26
27 27 QTCOMMERCIALCHART_BEGIN_NAMESPACE
28 28
29 29 class QStackedBarSeriesPrivate;
30 30
31 31 class QTCOMMERCIALCHART_EXPORT QStackedBarSeries : public QBarSeries
32 32 {
33 33 Q_OBJECT
34 34 public:
35 35 explicit QStackedBarSeries(QBarCategories categories, QObject *parent = 0);
36 QSeries::QSeriesType type() const;
36 QAbstractSeries::QSeriesType type() const;
37 37 private:
38 38 Q_DECLARE_PRIVATE(QStackedBarSeries)
39 39 Q_DISABLE_COPY(QStackedBarSeries)
40 40 };
41 41
42 42 QTCOMMERCIALCHART_END_NAMESPACE
43 43
44 44 #endif // STACKEDBARSERIES_H
@@ -1,252 +1,252
1 1 /****************************************************************************
2 2 **
3 3 ** Copyright (C) 2012 Digia Plc
4 4 ** All rights reserved.
5 5 ** For any questions to Digia, please use contact form at http://qt.digia.com
6 6 **
7 7 ** This file is part of the Qt Commercial Charts Add-on.
8 8 **
9 9 ** $QT_BEGIN_LICENSE$
10 10 ** Licensees holding valid Qt Commercial licenses may use this file in
11 11 ** accordance with the Qt Commercial License Agreement provided with the
12 12 ** Software or, alternatively, in accordance with the terms contained in
13 13 ** a written agreement between you and Digia.
14 14 **
15 15 ** If you have questions regarding the use of this file, please use
16 16 ** contact form at http://qt.digia.com
17 17 ** $QT_END_LICENSE$
18 18 **
19 19 ****************************************************************************/
20 20
21 21 #include "chartdataset_p.h"
22 22 #include "qchartaxis.h"
23 23 #include "qchartaxis_p.h"
24 #include "qseries_p.h"
24 #include "qabstractseries_p.h"
25 25 #include "qbarseries.h"
26 26 #include "qstackedbarseries.h"
27 27 #include "qpercentbarseries.h"
28 28 #include "qpieseries.h"
29 29
30 30 QTCOMMERCIALCHART_BEGIN_NAMESPACE
31 31
32 32 ChartDataSet::ChartDataSet(QObject *parent):QObject(parent),
33 33 m_axisX(new QChartAxis(this)),
34 34 m_axisY(new QChartAxis(this)),
35 35 m_domainIndex(0),
36 36 m_axisXInitialized(false)
37 37 {
38 38 }
39 39
40 40 ChartDataSet::~ChartDataSet()
41 41 {
42 42 }
43 43
44 void ChartDataSet::addSeries(QSeries* series, QChartAxis *axisY)
44 void ChartDataSet::addSeries(QAbstractSeries* series, QChartAxis *axisY)
45 45 {
46 46 if(axisY==0) axisY = m_axisY;
47 47
48 48 QChartAxis* axis = m_seriesAxisMap.value(series);
49 49
50 50 if(axis) {
51 51 qWarning() << "Can not add series. Series already on the chart";
52 52 return;
53 53 }
54 54
55 55 series->setParent(this); // take ownership
56 56 axisY->setParent(this); // take ownership
57 57
58 58 Domain* domain = m_axisDomainMap.value(axisY);
59 59
60 60 if(!domain) {
61 61 domain = new Domain(axisY);
62 62 QObject::connect(axisY->d_ptr.data(),SIGNAL(changed(qreal,qreal,int,bool)),domain,SLOT(handleAxisYChanged(qreal,qreal,int,bool)));
63 63 QObject::connect(axisX()->d_ptr.data(),SIGNAL(changed(qreal,qreal,int,bool)),domain,SLOT(handleAxisXChanged(qreal,qreal,int,bool)));
64 64 QObject::connect(domain,SIGNAL(rangeYChanged(qreal,qreal,int)),axisY->d_ptr.data(),SLOT(handleAxisRangeChanged(qreal,qreal,int)));
65 65 QObject::connect(domain,SIGNAL(rangeXChanged(qreal,qreal,int)),axisX()->d_ptr.data(),SLOT(handleAxisRangeChanged(qreal,qreal,int)));
66 66 //initialize
67 67 m_axisDomainMap.insert(axisY,domain);
68 68 emit axisAdded(axisY,domain);
69 69 }
70 70
71 71 if(!m_axisXInitialized){
72 72 emit axisAdded(axisX(),domain);
73 73 m_axisXInitialized=true;
74 74 }
75 75
76 76 series->d_ptr->scaleDomain(*domain);
77 77
78 if(series->type() == QSeries::SeriesTypeBar || series->type() == QSeries::SeriesTypeStackedBar || series->type() == QSeries::SeriesTypePercentBar)
79 {
78 if(series->type() == QAbstractSeries::SeriesTypeBar
79 || series->type() == QAbstractSeries::SeriesTypeStackedBar
80 || series->type() == QAbstractSeries::SeriesTypePercentBar) {
80 81 QBarSeries* barSeries = static_cast<QBarSeries*>(series);
81 82 setupCategories(barSeries);
82 83 }
83 84
84 if (series->type()== QSeries::SeriesTypePie && m_seriesAxisMap.count()==0)
85 {
85 if (series->type()== QAbstractSeries::SeriesTypePie && m_seriesAxisMap.count() == 0) {
86 86 axisX()->hide();
87 87 this->axisY()->hide();
88 88 }
89 89
90 90 m_seriesAxisMap.insert(series,axisY);
91 91
92 QMapIterator<int, QSeries*> i(m_indexSeriesMap);
92 QMapIterator<int, QAbstractSeries*> i(m_indexSeriesMap);
93 93
94 94 int key=0;
95 95 while (i.hasNext()) {
96 96 i.next();
97 97 if(i.key()!=key) {
98 98 break;
99 99 }
100 100 key++;
101 101 }
102 102
103 103 m_indexSeriesMap.insert(key,series);
104 104
105 105 emit seriesAdded(series,domain);
106 106
107 107 }
108 108
109 QChartAxis* ChartDataSet::removeSeries(QSeries* series)
109 QChartAxis* ChartDataSet::removeSeries(QAbstractSeries* series)
110 110 {
111 111 QChartAxis* axis = m_seriesAxisMap.value(series);
112 112
113 113 if(!axis){
114 114 qWarning()<<"Can not remove series. Series not found on the chart.";
115 115 return 0;
116 116 }
117 117
118 118 emit seriesRemoved(series);
119 119
120 120 m_seriesAxisMap.remove(series);
121 121 int key = seriesIndex(series);
122 122 Q_ASSERT(key!=-1);
123 123
124 124 m_indexSeriesMap.remove(key);
125 125 series->setParent(0);
126 126
127 127 QList<QChartAxis*> axes = m_seriesAxisMap.values();
128 128
129 129 int i = axes.indexOf(axis);
130 130
131 131 if(i==-1){
132 132 Domain* domain = m_axisDomainMap.take(axis);
133 133 emit axisRemoved(axis);
134 134 if(axis!=axisY()){
135 135 axis->setParent(0);
136 136 }
137 137 delete domain;
138 138 }
139 139
140 140 if(m_seriesAxisMap.values().size()==0)
141 141 {
142 142 m_axisXInitialized=false;
143 143 emit axisRemoved(axisX());
144 144 }
145 145
146 146 return axis;
147 147 }
148 148
149 149 void ChartDataSet::removeAllSeries()
150 150 {
151 QList<QSeries*> series = m_seriesAxisMap.keys();
151 QList<QAbstractSeries*> series = m_seriesAxisMap.keys();
152 152 QList<QChartAxis*> axes;
153 foreach(QSeries* s , series) {
153 foreach(QAbstractSeries *s , series) {
154 154 QChartAxis* axis = removeSeries(s);
155 155 if(axis==axisY()) continue;
156 156 int i = axes.indexOf(axis);
157 157 if(i==-1){
158 158 axes<<axis;
159 159 }
160 160 }
161 161
162 162 Q_ASSERT(m_seriesAxisMap.count()==0);
163 163 Q_ASSERT(m_axisDomainMap.count()==0);
164 164
165 165 qDeleteAll(series);
166 166 qDeleteAll(axes);
167 167 }
168 168
169 169 void ChartDataSet::setupCategories(QBarSeries* series)
170 170 {
171 171 QChartAxisCategories* categories = axisX()->categories();
172 172 categories->clear();
173 173 categories->insert(series->categories());
174 174 }
175 175
176 176 void ChartDataSet::zoomInDomain(const QRectF& rect, const QSizeF& size)
177 177 {
178 178 QMapIterator<QChartAxis*, Domain*> i(m_axisDomainMap);
179 179 while (i.hasNext()) {
180 180 i.next();
181 181 i.value()->zoomIn(rect,size);
182 182 }
183 183 }
184 184
185 185 void ChartDataSet::zoomOutDomain(const QRectF& rect, const QSizeF& size)
186 186 {
187 187 QMapIterator<QChartAxis*, Domain*> i(m_axisDomainMap);
188 188 while (i.hasNext()) {
189 189 i.next();
190 190 i.value()->zoomOut(rect,size);
191 191 }
192 192 }
193 193
194 int ChartDataSet::seriesCount(QSeries::QSeriesType type)
194 int ChartDataSet::seriesCount(QAbstractSeries::QSeriesType type)
195 195 {
196 196 int count=0;
197 QMapIterator<QSeries*, QChartAxis*> i(m_seriesAxisMap);
197 QMapIterator<QAbstractSeries*, QChartAxis*> i(m_seriesAxisMap);
198 198 while (i.hasNext()) {
199 199 i.next();
200 200 if(i.key()->type()==type) count++;
201 201 }
202 202 return count;
203 203 }
204 204
205 int ChartDataSet::seriesIndex(QSeries *series)
205 int ChartDataSet::seriesIndex(QAbstractSeries *series)
206 206 {
207 QMapIterator<int, QSeries*> i(m_indexSeriesMap);
207 QMapIterator<int, QAbstractSeries*> i(m_indexSeriesMap);
208 208 while (i.hasNext()) {
209 209 i.next();
210 210 if (i.value() == series)
211 211 return i.key();
212 212 }
213 213 return -1;
214 214 }
215 215
216 QChartAxis* ChartDataSet::axisY(QSeries* series) const
216 QChartAxis* ChartDataSet::axisY(QAbstractSeries *series) const
217 217 {
218 218 if(series == 0) return m_axisY;
219 219 return m_seriesAxisMap.value(series);
220 220 }
221 221
222 Domain* ChartDataSet::domain(QSeries* series) const
222 Domain* ChartDataSet::domain(QAbstractSeries *series) const
223 223 {
224 224 QChartAxis* axis = m_seriesAxisMap.value(series);
225 225 if(axis){
226 226 return m_axisDomainMap.value(axis);
227 227 }else
228 228 return 0;
229 229 }
230 230
231 231 Domain* ChartDataSet::domain(QChartAxis* axis) const
232 232 {
233 233 if(!axis || axis==axisX()) {
234 234 return m_axisDomainMap.value(axisY());
235 235 }
236 236 else {
237 237 return m_axisDomainMap.value(axis);
238 238 }
239 239 }
240 240
241 241 void ChartDataSet::scrollDomain(int dx,int dy,const QSizeF& size)
242 242 {
243 243 QMapIterator<QChartAxis*, Domain*> i( m_axisDomainMap);
244 244 while (i.hasNext()) {
245 245 i.next();
246 246 i.value()->move(dx,dy,size);
247 247 }
248 248 }
249 249
250 250 #include "moc_chartdataset_p.cpp"
251 251
252 252 QTCOMMERCIALCHART_END_NAMESPACE
@@ -1,90 +1,90
1 1 /****************************************************************************
2 2 **
3 3 ** Copyright (C) 2012 Digia Plc
4 4 ** All rights reserved.
5 5 ** For any questions to Digia, please use contact form at http://qt.digia.com
6 6 **
7 7 ** This file is part of the Qt Commercial Charts Add-on.
8 8 **
9 9 ** $QT_BEGIN_LICENSE$
10 10 ** Licensees holding valid Qt Commercial licenses may use this file in
11 11 ** accordance with the Qt Commercial License Agreement provided with the
12 12 ** Software or, alternatively, in accordance with the terms contained in
13 13 ** a written agreement between you and Digia.
14 14 **
15 15 ** If you have questions regarding the use of this file, please use
16 16 ** contact form at http://qt.digia.com
17 17 ** $QT_END_LICENSE$
18 18 **
19 19 ****************************************************************************/
20 20
21 21 // W A R N I N G
22 22 // -------------
23 23 //
24 24 // This file is not part of the QtCommercial Chart API. It exists purely as an
25 25 // implementation detail. This header file may change from version to
26 26 // version without notice, or even be removed.
27 27 //
28 28 // We mean it.
29 29
30 30 #ifndef CHARTDATASET_P_H
31 31 #define CHARTDATASET_P_H
32 32
33 #include "qseries.h"
33 #include "qabstractseries.h"
34 34 #include "domain_p.h"
35 35 #include <QVector>
36 36
37 37 QTCOMMERCIALCHART_BEGIN_NAMESPACE
38 38
39 39 class QChartAxis;
40 40 class QBarSeries;
41 41
42 42 class ChartDataSet : public QObject
43 43 {
44 44 Q_OBJECT
45 45 public:
46 46 ChartDataSet(QObject* parent=0);
47 47 virtual ~ChartDataSet();
48 48
49 void addSeries(QSeries* series,QChartAxis *axisY = 0);
50 QChartAxis* removeSeries(QSeries* series);
49 void addSeries(QAbstractSeries* series,QChartAxis *axisY = 0);
50 QChartAxis* removeSeries(QAbstractSeries* series);
51 51 void removeAllSeries();
52 52
53 53 void zoomInDomain(const QRectF& rect, const QSizeF& size);
54 54 void zoomOutDomain(const QRectF& rect, const QSizeF& size);
55 55 void scrollDomain(int dx,int dy,const QSizeF& size);
56 56
57 int seriesCount(QSeries::QSeriesType type);
58 int seriesIndex(QSeries *series);
57 int seriesCount(QAbstractSeries::QSeriesType type);
58 int seriesIndex(QAbstractSeries *series);
59 59
60 Domain* domain(QSeries* series) const;
60 Domain* domain(QAbstractSeries* series) const;
61 61 Domain* domain(QChartAxis* axis) const;
62 62
63 63 QChartAxis* axisX() const { return m_axisX; }
64 QChartAxis* axisY(QSeries* series = 0) const;
64 QChartAxis* axisY(QAbstractSeries *series = 0) const;
65 65
66 66 Q_SIGNALS:
67 void seriesAdded(QSeries* series,Domain* domain);
68 void seriesRemoved(QSeries* series);
67 void seriesAdded(QAbstractSeries* series, Domain* domain);
68 void seriesRemoved(QAbstractSeries* series);
69 69 void axisAdded(QChartAxis* axis,Domain* domain);
70 70 void axisRemoved(QChartAxis* axis);
71 71
72 72 private:
73 73 QStringList createLabels(QChartAxis* axis,qreal min, qreal max);
74 void calculateDomain(QSeries* series,Domain* domain);
74 void calculateDomain(QAbstractSeries* series,Domain* domain);
75 75 void setupCategories(QBarSeries* series);
76 76
77 77 private:
78 QMap<QSeries*, QChartAxis*> m_seriesAxisMap;
79 QMap<QChartAxis*, Domain*> m_axisDomainMap;
80 QMap<int,QSeries*> m_indexSeriesMap;
78 QMap<QAbstractSeries *, QChartAxis *> m_seriesAxisMap;
79 QMap<QChartAxis*, Domain *> m_axisDomainMap;
80 QMap<int, QAbstractSeries *> m_indexSeriesMap;
81 81 QChartAxis* m_axisX;
82 82 QChartAxis* m_axisY;
83 83
84 84 int m_domainIndex;
85 85 bool m_axisXInitialized;
86 86 };
87 87
88 88 QTCOMMERCIALCHART_END_NAMESPACE
89 89
90 90 #endif /* CHARTENGINE_P_H_ */
@@ -1,401 +1,401
1 1 /****************************************************************************
2 2 **
3 3 ** Copyright (C) 2012 Digia Plc
4 4 ** All rights reserved.
5 5 ** For any questions to Digia, please use contact form at http://qt.digia.com
6 6 **
7 7 ** This file is part of the Qt Commercial Charts Add-on.
8 8 **
9 9 ** $QT_BEGIN_LICENSE$
10 10 ** Licensees holding valid Qt Commercial licenses may use this file in
11 11 ** accordance with the Qt Commercial License Agreement provided with the
12 12 ** Software or, alternatively, in accordance with the terms contained in
13 13 ** a written agreement between you and Digia.
14 14 **
15 15 ** If you have questions regarding the use of this file, please use
16 16 ** contact form at http://qt.digia.com
17 17 ** $QT_END_LICENSE$
18 18 **
19 19 ****************************************************************************/
20 20 #include "chartpresenter_p.h"
21 21 #include "qchart.h"
22 22 #include "qchart_p.h"
23 23 #include "qchartaxis.h"
24 24 #include "chartdataset_p.h"
25 25 #include "charttheme_p.h"
26 26 #include "chartanimator_p.h"
27 #include "qseries_p.h"
27 #include "qabstractseries_p.h"
28 28 #include "qareaseries.h"
29 29 #include "axis_p.h"
30 30 #include "areachartitem_p.h"
31 31
32 32 QTCOMMERCIALCHART_BEGIN_NAMESPACE
33 33
34 34 ChartPresenter::ChartPresenter(QChart* chart,ChartDataSet* dataset):QObject(chart),
35 35 m_chart(chart),
36 36 m_animator(0),
37 37 m_dataset(dataset),
38 38 m_chartTheme(0),
39 39 m_chartRect(QRectF(QPoint(0,0),m_chart->size())),
40 40 m_options(QChart::NoAnimation),
41 41 m_minLeftMargin(0),
42 42 m_minBottomMargin(0),
43 43 m_backgroundItem(0),
44 44 m_titleItem(0),
45 45 m_marginBig(60),
46 46 m_marginSmall(20),
47 47 m_marginTiny(10),
48 48 m_chartMargins(QRect(m_marginBig,m_marginBig,0,0))
49 49 {
50 50 }
51 51
52 52 ChartPresenter::~ChartPresenter()
53 53 {
54 54 delete m_chartTheme;
55 55 }
56 56
57 57 void ChartPresenter::setGeometry(const QRectF& rect)
58 58 {
59 59 m_rect = rect;
60 60 Q_ASSERT(m_rect.isValid());
61 61 updateLayout();
62 62 }
63 63
64 64 void ChartPresenter::setMinimumMarginWidth(Axis* axis, qreal width)
65 65 {
66 66 switch(axis->axisType()){
67 67 case Axis::X_AXIS:
68 68 {
69 69 if(width>m_chartRect.width()+ m_chartMargins.left()) {
70 70 m_minLeftMargin= width - m_chartRect.width();
71 71 updateLayout();
72 72 }
73 73 break;
74 74 }
75 75 case Axis::Y_AXIS:
76 76 {
77 77
78 78 if(m_minLeftMargin!=width){
79 79 m_minLeftMargin= width;
80 80 updateLayout();
81 81 }
82 82 break;
83 83 }
84 84
85 85 }
86 86 }
87 87
88 88 void ChartPresenter::setMinimumMarginHeight(Axis* axis, qreal height)
89 89 {
90 90 switch(axis->axisType()){
91 91 case Axis::X_AXIS:
92 92 {
93 93 if(m_minBottomMargin!=height) {
94 94 m_minBottomMargin= height;
95 95 updateLayout();
96 96 }
97 97 break;
98 98 }
99 99 case Axis::Y_AXIS:
100 100 {
101 101
102 102 if(height>m_chartMargins.bottom()+m_chartRect.height()){
103 103 m_minBottomMargin= height - m_chartRect.height();
104 104 updateLayout();
105 105 }
106 106 break;
107 107 }
108 108
109 109 }
110 110 }
111 111
112 112 void ChartPresenter::handleAxisAdded(QChartAxis* axis,Domain* domain)
113 113 {
114 114 Axis* item = new Axis(axis,this,axis==m_dataset->axisX()?Axis::X_AXIS : Axis::Y_AXIS);
115 115
116 116 if(m_options.testFlag(QChart::GridAxisAnimations)){
117 117 m_animator->addAnimation(item);
118 118 }
119 119
120 120 if(axis==m_dataset->axisX()){
121 121 m_chartTheme->decorate(axis,true);
122 122 QObject::connect(domain,SIGNAL(rangeXChanged(qreal,qreal,int)),item,SLOT(handleRangeChanged(qreal,qreal,int)));
123 123 //initialize
124 124 item->handleRangeChanged(domain->minX(),domain->maxX(),domain->tickXCount());
125 125
126 126 }
127 127 else{
128 128 m_chartTheme->decorate(axis,false);
129 129 QObject::connect(domain,SIGNAL(rangeYChanged(qreal,qreal,int)),item,SLOT(handleRangeChanged(qreal,qreal,int)));
130 130 //initialize
131 131 item->handleRangeChanged(domain->minY(),domain->maxY(),domain->tickYCount());
132 132 }
133 133
134 134 QObject::connect(this,SIGNAL(geometryChanged(QRectF)),item,SLOT(handleGeometryChanged(QRectF)));
135 135 //initialize
136 136 item->handleGeometryChanged(m_chartRect);
137 137 m_axisItems.insert(axis, item);
138 138 }
139 139
140 140 void ChartPresenter::handleAxisRemoved(QChartAxis* axis)
141 141 {
142 142 Axis* item = m_axisItems.take(axis);
143 143 Q_ASSERT(item);
144 144 if(m_animator) m_animator->removeAnimation(item);
145 145 delete item;
146 146 }
147 147
148 148
149 void ChartPresenter::handleSeriesAdded(QSeries* series,Domain* domain)
149 void ChartPresenter::handleSeriesAdded(QAbstractSeries* series,Domain* domain)
150 150 {
151 151 Chart *item = series->d_ptr->createGraphics(this);
152 152 Q_ASSERT(item);
153 153 QObject::connect(this,SIGNAL(geometryChanged(QRectF)),item,SLOT(handleGeometryChanged(QRectF)));
154 154 QObject::connect(domain,SIGNAL(domainChanged(qreal,qreal,qreal,qreal)),item,SLOT(handleDomainChanged(qreal,qreal,qreal,qreal)));
155 155 //initialize
156 156 item->handleDomainChanged(domain->minX(),domain->maxX(),domain->minY(),domain->maxY());
157 157 if(m_chartRect.isValid()) item->handleGeometryChanged(m_chartRect);
158 158 m_chartItems.insert(series,item);
159 159 }
160 160
161 void ChartPresenter::handleSeriesRemoved(QSeries* series)
161 void ChartPresenter::handleSeriesRemoved(QAbstractSeries* series)
162 162 {
163 163 Chart* item = m_chartItems.take(series);
164 164 Q_ASSERT(item);
165 165 if(m_animator) {
166 166 //small hack to handle area animations
167 if(series->type()==QSeries::SeriesTypeArea){
167 if(series->type() == QAbstractSeries::SeriesTypeArea){
168 168 QAreaSeries* areaSeries = static_cast<QAreaSeries*>(series);
169 169 AreaChartItem* area = static_cast<AreaChartItem*>(item);
170 170 m_animator->removeAnimation(area->upperLineItem());
171 171 if(areaSeries->lowerSeries()) m_animator->removeAnimation(area->lowerLineItem());
172 172 }else
173 173 m_animator->removeAnimation(item);
174 174 }
175 175 delete item;
176 176 }
177 177
178 178 void ChartPresenter::setTheme(QChart::ChartTheme theme,bool force)
179 179 {
180 180 if(m_chartTheme && m_chartTheme->id() == theme) return;
181 181 delete m_chartTheme;
182 182 m_chartTheme = ChartTheme::createTheme(theme);
183 183 m_chartTheme->setForced(force);
184 184 m_chartTheme->decorate(m_chart);
185 185 m_chartTheme->decorate(m_chart->legend());
186 186 resetAllElements();
187 187 }
188 188
189 189 QChart::ChartTheme ChartPresenter::theme()
190 190 {
191 191 return m_chartTheme->id();
192 192 }
193 193
194 194 void ChartPresenter::setAnimationOptions(QChart::AnimationOptions options)
195 195 {
196 196 if(m_options!=options) {
197 197
198 198 m_options=options;
199 199
200 200 if(m_options!=QChart::NoAnimation && !m_animator) {
201 201 m_animator= new ChartAnimator(this);
202 202 }
203 203 resetAllElements();
204 204 }
205 205
206 206 }
207 207
208 208 void ChartPresenter::resetAllElements()
209 209 {
210 QList<QChartAxis*> axisList = m_axisItems.uniqueKeys();
211 QList<QSeries*> seriesList = m_chartItems.uniqueKeys();
210 QList<QChartAxis *> axisList = m_axisItems.uniqueKeys();
211 QList<QAbstractSeries *> seriesList = m_chartItems.uniqueKeys();
212 212
213 foreach(QChartAxis* axis, axisList) {
213 foreach(QChartAxis *axis, axisList) {
214 214 handleAxisRemoved(axis);
215 215 handleAxisAdded(axis,m_dataset->domain(axis));
216 216 }
217 foreach(QSeries* series, seriesList) {
217 foreach(QAbstractSeries *series, seriesList) {
218 218 handleSeriesRemoved(series);
219 219 handleSeriesAdded(series,m_dataset->domain(series));
220 220 }
221 221 }
222 222
223 223 void ChartPresenter::zoomIn()
224 224 {
225 225 QRectF rect = chartGeometry();
226 226 rect.setWidth(rect.width()/2);
227 227 rect.setHeight(rect.height()/2);
228 228 rect.moveCenter(chartGeometry().center());
229 229 zoomIn(rect);
230 230 }
231 231
232 232 void ChartPresenter::zoomIn(const QRectF& rect)
233 233 {
234 234 QRectF r = rect.normalized();
235 235 r.translate(-m_chartMargins.topLeft());
236 236 if(m_animator) {
237 237
238 238 QPointF point(r.center().x()/chartGeometry().width(),r.center().y()/chartGeometry().height());
239 239 m_animator->setState(ChartAnimator::ZoomInState,point);
240 240 }
241 241 m_dataset->zoomInDomain(r,chartGeometry().size());
242 242 if(m_animator) {
243 243 m_animator->setState(ChartAnimator::ShowState);
244 244 }
245 245 }
246 246
247 247 void ChartPresenter::zoomOut()
248 248 {
249 249 if(m_animator)
250 250 {
251 251 m_animator->setState(ChartAnimator::ZoomOutState);
252 252 }
253 253
254 254 QSizeF size = chartGeometry().size();
255 255 QRectF rect = chartGeometry();
256 256 rect.translate(-m_chartMargins.topLeft());
257 257 m_dataset->zoomOutDomain(rect.adjusted(size.width()/4,size.height()/4,-size.width()/4,-size.height()/4),size);
258 258 //m_dataset->zoomOutDomain(m_zoomStack[m_zoomIndex-1],geometry().size());
259 259
260 260 if(m_animator){
261 261 m_animator->setState(ChartAnimator::ShowState);
262 262 }
263 263 }
264 264
265 265 void ChartPresenter::scroll(int dx,int dy)
266 266 {
267 267 if(m_animator){
268 268 if(dx<0) m_animator->setState(ChartAnimator::ScrollLeftState,QPointF());
269 269 if(dx>0) m_animator->setState(ChartAnimator::ScrollRightState,QPointF());
270 270 if(dy<0) m_animator->setState(ChartAnimator::ScrollUpState,QPointF());
271 271 if(dy>0) m_animator->setState(ChartAnimator::ScrollDownState,QPointF());
272 272 }
273 273
274 274 m_dataset->scrollDomain(dx,dy,chartGeometry().size());
275 275
276 276 if(m_animator){
277 277 m_animator->setState(ChartAnimator::ShowState);
278 278 }
279 279 }
280 280
281 281 QChart::AnimationOptions ChartPresenter::animationOptions() const
282 282 {
283 283 return m_options;
284 284 }
285 285
286 286 void ChartPresenter::updateLayout()
287 287 {
288 288 if (!m_rect.isValid()) return;
289 289
290 290 // recalculate title size
291 291
292 292 QSize titleSize;
293 293 int titlePadding=0;
294 294
295 295 if (m_titleItem) {
296 296 titleSize= m_titleItem->boundingRect().size().toSize();
297 297 }
298 298
299 299 //defaults
300 300 m_chartMargins = QRect(QPoint(m_minLeftMargin>m_marginBig?m_minLeftMargin:m_marginBig,m_marginBig),QPoint(m_marginBig,m_minBottomMargin>m_marginBig?m_minBottomMargin:m_marginBig));
301 301 titlePadding = m_chartMargins.top()/2;
302 302
303 303 QLegend* legend = m_chart->d_ptr->m_legend;
304 304
305 305 // recalculate legend position
306 306 if (legend->isAttachedToChart() && legend->isEnabled()) {
307 307
308 308 QRect legendRect;
309 309
310 310 // Reserve some space for legend
311 311 switch (legend->alignment()) {
312 312
313 313 case QLegend::AlignmentTop: {
314 314 int ledgendSize = legend->minHeight();
315 315 int topPadding = 2*m_marginTiny + titleSize.height() + ledgendSize + m_marginTiny;
316 316 m_chartMargins = QRect(QPoint(m_chartMargins.left(),topPadding),QPoint(m_chartMargins.right(),m_chartMargins.bottom()));
317 317 m_legendMargins = QRect(QPoint(m_chartMargins.left(),topPadding - (ledgendSize + m_marginTiny)),QPoint(m_chartMargins.right(),m_rect.height()-topPadding + m_marginTiny));
318 318 titlePadding = m_marginTiny + m_marginTiny;
319 319 break;
320 320 }
321 321 case QLegend::AlignmentBottom: {
322 322 int ledgendSize = legend->minHeight();
323 323 int bottomPadding = m_marginTiny + m_marginSmall + ledgendSize + m_marginTiny + m_minBottomMargin;
324 324 m_chartMargins = QRect(QPoint(m_chartMargins.left(),m_chartMargins.top()),QPoint(m_chartMargins.right(),bottomPadding));
325 325 m_legendMargins = QRect(QPoint(m_chartMargins.left(),m_rect.height()-bottomPadding + m_marginTiny + m_minBottomMargin),QPoint(m_chartMargins.right(),m_marginTiny + m_marginSmall));
326 326 titlePadding = m_chartMargins.top()/2;
327 327 break;
328 328 }
329 329 case QLegend::AlignmentLeft: {
330 330 int ledgendSize = legend->minWidth();
331 331 int leftPadding = m_marginTiny + m_marginSmall + ledgendSize + m_marginTiny + m_minLeftMargin;
332 332 m_chartMargins = QRect(QPoint(leftPadding,m_chartMargins.top()),QPoint(m_chartMargins.right(),m_chartMargins.bottom()));
333 333 m_legendMargins = QRect(QPoint(m_marginTiny + m_marginSmall,m_chartMargins.top()),QPoint(m_rect.width()-leftPadding + m_marginTiny + m_minLeftMargin,m_chartMargins.bottom()));
334 334 titlePadding = m_chartMargins.top()/2;
335 335 break;
336 336 }
337 337 case QLegend::AlignmentRight: {
338 338 int ledgendSize = legend->minWidth();
339 339 int rightPadding = m_marginTiny + m_marginSmall + ledgendSize + m_marginTiny;
340 340 m_chartMargins = QRect(QPoint(m_chartMargins.left(),m_chartMargins.top()),QPoint(rightPadding,m_chartMargins.bottom()));
341 341 m_legendMargins = QRect(QPoint(m_rect.width()- rightPadding+ m_marginTiny ,m_chartMargins.top()),QPoint(m_marginTiny + m_marginSmall,m_chartMargins.bottom()));
342 342 titlePadding = m_chartMargins.top()/2;
343 343 break;
344 344 }
345 345 default: {
346 346 break;
347 347 }
348 348 }
349 349 }
350 350
351 351 if(m_rect.width()<2*(m_chartMargins.top()+m_chartMargins.bottom()) || m_rect.height()< 2*(m_chartMargins.top() + m_chartMargins.bottom()))
352 352 {
353 353 m_chart->setMinimumSize(2*(m_chartMargins.top()+m_chartMargins.bottom()),2*(m_chartMargins.top() + m_chartMargins.bottom()));
354 354 return;
355 355 }
356 356
357 357
358 358 // recalculate title position
359 359 if (m_titleItem) {
360 360 QPointF center = m_rect.center() -m_titleItem->boundingRect().center();
361 361 m_titleItem->setPos(center.x(),titlePadding);
362 362 }
363 363
364 364 //recalculate background gradient
365 365 if (m_backgroundItem) {
366 366 m_backgroundItem->setRect(m_rect.adjusted(m_marginTiny,m_marginTiny, -m_marginTiny, -m_marginTiny));
367 367 }
368 368
369 369
370 370 QRectF chartRect = m_rect.adjusted(m_chartMargins.left(),m_chartMargins.top(),-m_chartMargins.right(),-m_chartMargins.bottom());
371 371
372 372 legend->setGeometry(m_rect.adjusted(m_legendMargins.left(),m_legendMargins.top(),-m_legendMargins.right(),-m_legendMargins.bottom()));
373 373
374 374 if(m_chartRect!=chartRect){
375 375 m_chartRect=chartRect;
376 376 emit geometryChanged(m_chartRect);
377 377 }
378 378
379 379
380 380 }
381 381
382 382 void ChartPresenter::createChartBackgroundItem()
383 383 {
384 384 if (!m_backgroundItem) {
385 385 m_backgroundItem = new ChartBackground(rootItem());
386 386 m_backgroundItem->setPen(Qt::NoPen);
387 387 m_backgroundItem->setZValue(ChartPresenter::BackgroundZValue);
388 388 }
389 389 }
390 390
391 391 void ChartPresenter::createChartTitleItem()
392 392 {
393 393 if (!m_titleItem) {
394 394 m_titleItem = new QGraphicsSimpleTextItem(rootItem());
395 395 m_titleItem->setZValue(ChartPresenter::BackgroundZValue);
396 396 }
397 397 }
398 398
399 399 #include "moc_chartpresenter_p.cpp"
400 400
401 401 QTCOMMERCIALCHART_END_NAMESPACE
@@ -1,125 +1,125
1 1 /****************************************************************************
2 2 **
3 3 ** Copyright (C) 2012 Digia Plc
4 4 ** All rights reserved.
5 5 ** For any questions to Digia, please use contact form at http://qt.digia.com
6 6 **
7 7 ** This file is part of the Qt Commercial Charts Add-on.
8 8 **
9 9 ** $QT_BEGIN_LICENSE$
10 10 ** Licensees holding valid Qt Commercial licenses may use this file in
11 11 ** accordance with the Qt Commercial License Agreement provided with the
12 12 ** Software or, alternatively, in accordance with the terms contained in
13 13 ** a written agreement between you and Digia.
14 14 **
15 15 ** If you have questions regarding the use of this file, please use
16 16 ** contact form at http://qt.digia.com
17 17 ** $QT_END_LICENSE$
18 18 **
19 19 ****************************************************************************/
20 20
21 21 #ifndef CHARTPRESENTER_H
22 22 #define CHARTPRESENTER_H
23 23
24 24 #include "qchartglobal.h"
25 25 #include "chartbackground_p.h" //TODO fix me
26 26 #include "qchart.h" //becouse of QChart::ChartThemeId //TODO
27 27 #include "qchartaxis.h"
28 28 #include <QRectF>
29 29
30 30 QTCOMMERCIALCHART_BEGIN_NAMESPACE
31 31
32 32 class Chart;
33 class QSeries;
33 class QAbstractSeries;
34 34 class ChartDataSet;
35 35 class Domain;
36 36 class Axis;
37 37 class ChartTheme;
38 38 class ChartAnimator;
39 39
40 40 class ChartPresenter: public QObject
41 41 {
42 42 Q_OBJECT
43 43 public:
44 44 enum ZValues {
45 45 BackgroundZValue = -1,
46 46 ShadesZValue,
47 47 GridZValue,
48 48 LineChartZValue,
49 49 BarSeriesZValue,
50 50 ScatterSeriesZValue,
51 51 PieSeriesZValue,
52 52 AxisZValue,
53 53 LegendZValue
54 54 };
55 55
56 56 ChartPresenter(QChart* chart,ChartDataSet *dataset);
57 57 virtual ~ChartPresenter();
58 58
59 59 ChartAnimator* animator() const { return m_animator; }
60 60 ChartTheme *chartTheme() const { return m_chartTheme; }
61 61 ChartDataSet *dataSet() const { return m_dataset; }
62 62 QGraphicsItem* rootItem() const { return m_chart; }
63 63
64 64 void setTheme(QChart::ChartTheme theme,bool force = true);
65 65 QChart::ChartTheme theme();
66 66
67 67 void setAnimationOptions(QChart::AnimationOptions options);
68 68 QChart::AnimationOptions animationOptions() const;
69 69
70 70 void zoomIn();
71 71 void zoomIn(const QRectF& rect);
72 72 void zoomOut();
73 73 void scroll(int dx,int dy);
74 74
75 75 void setGeometry(const QRectF& rect);
76 76 QRectF chartGeometry() const { return m_chartRect; }
77 77
78 78 void setMinimumMarginHeight(Axis* axis, qreal height);
79 79 void setMinimumMarginWidth(Axis* axis, qreal width);
80 80 qreal minimumLeftMargin() const { return m_minLeftMargin; }
81 81 qreal minimumBottomMargin() const { return m_minBottomMargin; }
82 82
83 83 public: //TODO: fix me
84 84 void resetAllElements();
85 85 void createChartBackgroundItem();
86 86 void createChartTitleItem();
87 87 QRectF margins() const { return m_chartMargins;}
88 88
89 89 public Q_SLOTS:
90 void handleSeriesAdded(QSeries* series,Domain* domain);
91 void handleSeriesRemoved(QSeries* series);
90 void handleSeriesAdded(QAbstractSeries* series,Domain* domain);
91 void handleSeriesRemoved(QAbstractSeries* series);
92 92 void handleAxisAdded(QChartAxis* axis,Domain* domain);
93 93 void handleAxisRemoved(QChartAxis* axis);
94 94 void updateLayout();
95 95
96 96 Q_SIGNALS:
97 97 void geometryChanged(const QRectF& rect);
98 98
99 99
100 100 private:
101 101 QChart* m_chart;
102 102 ChartAnimator* m_animator;
103 103 ChartDataSet* m_dataset;
104 104 ChartTheme *m_chartTheme;
105 QMap<QSeries*,Chart*> m_chartItems;
106 QMap<QChartAxis*,Axis*> m_axisItems;
105 QMap<QAbstractSeries *, Chart *> m_chartItems;
106 QMap<QChartAxis *, Axis *> m_axisItems;
107 107 QRectF m_rect;
108 108 QRectF m_chartRect;
109 109 QChart::AnimationOptions m_options;
110 110 qreal m_minLeftMargin;
111 111 qreal m_minBottomMargin;
112 112 public: //TODO: fixme
113 113 ChartBackground* m_backgroundItem;
114 114 QGraphicsSimpleTextItem* m_titleItem;
115 115 int m_marginBig;
116 116 int m_marginSmall;
117 117 int m_marginTiny;
118 118 QRectF m_chartMargins;
119 119 QRectF m_legendMargins;
120 120
121 121 };
122 122
123 123 QTCOMMERCIALCHART_END_NAMESPACE
124 124
125 125 #endif /* CHARTPRESENTER_H_ */
@@ -1,102 +1,101
1 1 /****************************************************************************
2 2 **
3 3 ** Copyright (C) 2012 Digia Plc
4 4 ** All rights reserved.
5 5 ** For any questions to Digia, please use contact form at http://qt.digia.com
6 6 **
7 7 ** This file is part of the Qt Commercial Charts Add-on.
8 8 **
9 9 ** $QT_BEGIN_LICENSE$
10 10 ** Licensees holding valid Qt Commercial licenses may use this file in
11 11 ** accordance with the Qt Commercial License Agreement provided with the
12 12 ** Software or, alternatively, in accordance with the terms contained in
13 13 ** a written agreement between you and Digia.
14 14 **
15 15 ** If you have questions regarding the use of this file, please use
16 16 ** contact form at http://qt.digia.com
17 17 ** $QT_END_LICENSE$
18 18 **
19 19 ****************************************************************************/
20 20
21 21 #ifndef CHARTTHEME_H
22 22 #define CHARTTHEME_H
23 23
24 24 #include "qchartglobal.h"
25 25 #include "qchart.h"
26 26 #include <QColor>
27 27 #include <QGradientStops>
28 28
29 29 QTCOMMERCIALCHART_BEGIN_NAMESPACE
30 30
31 31 class ChartItem;
32 class QSeries;
33 32 class LineChartItem;
34 33 class QLineSeries;
35 34 class BarChartItem;
36 35 class QBarSeries;
37 36 class StackedBarChartItem;
38 37 class QStackedBarSeries;
39 38 class QPercentBarSeries;
40 39 class PercentBarChartItem;
41 40 class QScatterSeries;
42 41 class ScatterChartItem;
43 42 class PieChartItem;
44 43 class QPieSeries;
45 44 class SplineChartItem;
46 45 class QSplineSeries;
47 46 class AreaChartItem;
48 47 class QAreaSeries;
49 48
50 49 class ChartTheme
51 50 {
52 51 public:
53 52 enum BackgroundShadesMode {
54 53 BackgroundShadesNone = 0,
55 54 BackgroundShadesVertical,
56 55 BackgroundShadesHorizontal,
57 56 BackgroundShadesBoth
58 57 };
59 58
60 59 protected:
61 60 explicit ChartTheme(QChart::ChartTheme id = QChart::ChartThemeLight);
62 61 public:
63 62 static ChartTheme *createTheme(QChart::ChartTheme theme);
64 63 QChart::ChartTheme id() const {return m_id;}
65 64 void decorate(QChart *chart);
66 65 void decorate(QLegend *legend);
67 66 void decorate(QBarSeries *series, int index);
68 67 void decorate(QLineSeries *series, int index);
69 68 void decorate(QAreaSeries *series, int index);
70 69 void decorate(QScatterSeries *series, int index);
71 70 void decorate(QPieSeries *series, int index);
72 71 void decorate(QSplineSeries *series, int index);
73 72 void decorate(QChartAxis *axis, bool axisX);
74 73 void setForced(bool enabled);
75 74 bool isForced() { return m_force; }
76 75
77 76 public: // utils
78 77 void generateSeriesGradients();
79 78 static QColor colorAt(const QColor &start, const QColor &end, qreal pos);
80 79 static QColor colorAt(const QGradient &gradient, qreal pos);
81 80
82 81 protected:
83 82 QChart::ChartTheme m_id;
84 83 QList<QColor> m_seriesColors;
85 84 QList<QGradient> m_seriesGradients;
86 85 QLinearGradient m_chartBackgroundGradient;
87 86
88 87 QFont m_masterFont;
89 88 QFont m_labelFont;
90 89 QBrush m_titleBrush;
91 90 QPen m_axisLinePen;
92 91 QBrush m_axisLabelBrush;
93 92 QPen m_backgroundShadesPen;
94 93 QBrush m_backgroundShadesBrush;
95 94 BackgroundShadesMode m_backgroundShades;
96 95 QPen m_gridLinePen;
97 96 bool m_force;
98 97 };
99 98
100 99 QTCOMMERCIALCHART_END_NAMESPACE
101 100
102 101 #endif // CHARTTHEME_H
@@ -1,194 +1,194
1 1 /****************************************************************************
2 2 **
3 3 ** Copyright (C) 2012 Digia Plc
4 4 ** All rights reserved.
5 5 ** For any questions to Digia, please use contact form at http://qt.digia.com
6 6 **
7 7 ** This file is part of the Qt Commercial Charts Add-on.
8 8 **
9 9 ** $QT_BEGIN_LICENSE$
10 10 ** Licensees holding valid Qt Commercial licenses may use this file in
11 11 ** accordance with the Qt Commercial License Agreement provided with the
12 12 ** Software or, alternatively, in accordance with the terms contained in
13 13 ** a written agreement between you and Digia.
14 14 **
15 15 ** If you have questions regarding the use of this file, please use
16 16 ** contact form at http://qt.digia.com
17 17 ** $QT_END_LICENSE$
18 18 **
19 19 ****************************************************************************/
20 20
21 21 #include "legendmarker_p.h"
22 22 #include "qxyseries.h"
23 23 #include "qxyseries_p.h"
24 24 #include "qlegend.h"
25 25 #include "qbarseries.h"
26 26 #include "qpieseries.h"
27 27 #include "qpieslice.h"
28 28 #include "qbarset.h"
29 29 #include "qbarset_p.h"
30 30 #include "qareaseries.h"
31 31 #include "qareaseries_p.h"
32 32 #include <QPainter>
33 33 #include <QGraphicsSceneEvent>
34 34 #include <QGraphicsSimpleTextItem>
35 35
36 36 QTCOMMERCIALCHART_BEGIN_NAMESPACE
37 37
38 LegendMarker::LegendMarker(QSeries* series,QLegend *legend) : QGraphicsObject(legend),
38 LegendMarker::LegendMarker(QAbstractSeries *series, QLegend *legend) : QGraphicsObject(legend),
39 39 m_series(series),
40 40 m_markerRect(0,0,10.0,10.0),
41 41 m_boundingRect(0,0,0,0),
42 42 m_legend(legend),
43 43 m_textItem(new QGraphicsSimpleTextItem(this)),
44 44 m_rectItem(new QGraphicsRectItem(this))
45 45 {
46 46 //setAcceptedMouseButtons(Qt::LeftButton|Qt::RightButton);
47 47 m_rectItem->setRect(m_markerRect);
48 48 updateLayout();
49 49 }
50 50
51 51 void LegendMarker::setPen(const QPen &pen)
52 52 {
53 53 m_textItem->setPen(pen);
54 54 updateLayout();
55 55 }
56 56
57 57 QPen LegendMarker::pen() const
58 58 {
59 59 return m_textItem->pen();
60 60 }
61 61
62 62 void LegendMarker::setBrush(const QBrush &brush)
63 63 {
64 64 m_rectItem->setBrush(brush);
65 65 }
66 66
67 67 QBrush LegendMarker::brush() const
68 68 {
69 69 return m_rectItem->brush();
70 70 }
71 71
72 72 void LegendMarker::setLabel(const QString name)
73 73 {
74 74 m_textItem->setText(name);
75 75 updateLayout();
76 76 }
77 77
78 78 void LegendMarker::setSize(const QSize& size)
79 79 {
80 80 m_markerRect = QRectF(0,0,size.width(),size.height());
81 81 }
82 82
83 83 QString LegendMarker::label() const
84 84 {
85 85 return m_textItem->text();
86 86 }
87 87
88 88 void LegendMarker::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget)
89 89 {
90 90 Q_UNUSED(option)
91 91 Q_UNUSED(widget)
92 92 Q_UNUSED(painter)
93 93 }
94 94
95 95 QRectF LegendMarker::boundingRect() const
96 96 {
97 97 return m_boundingRect;
98 98 }
99 99
100 100 void LegendMarker::updateLayout()
101 101 {
102 102
103 103 static const qreal margin = 2;
104 104 static const qreal space = 4;
105 105
106 106 const QRectF& textRect = m_textItem->boundingRect();
107 107 prepareGeometryChange();
108 108 m_boundingRect = QRectF(0,0,m_markerRect.width() + 2*margin + space + textRect.width(),qMax(m_markerRect.height()+2*margin,textRect.height()+2*margin));
109 109 m_textItem->setPos(m_markerRect.width() + space + margin,m_boundingRect.height()/2 - textRect.height()/2);
110 110 m_rectItem->setPos(margin,m_boundingRect.height()/2 - m_markerRect.height()/2);
111 111
112 112 }
113 113
114 114 void LegendMarker::mousePressEvent(QGraphicsSceneMouseEvent *event)
115 115 {
116 116 QGraphicsObject::mousePressEvent(event);
117 117 emit selected();
118 118 }
119 119
120 120 //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
121 121
122 122 AreaLegendMarker::AreaLegendMarker(QAreaSeries *series,QLegend *legend) : LegendMarker(series,legend),
123 123 m_series(series)
124 124 {
125 125 QObject::connect(this, SIGNAL(selected()), series, SIGNAL(selected()));
126 126 QObject::connect(series->d_func(),SIGNAL(updated()), this, SLOT(updated()));
127 127 updated();
128 128 }
129 129
130 130 void AreaLegendMarker::updated()
131 131 {
132 132 setBrush(m_series->brush());
133 133 setLabel(m_series->name());
134 134 }
135 135
136 136 //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
137 137
138 138 BarLegendMarker::BarLegendMarker(QBarSeries *barseries,QBarSet *barset, QLegend *legend) : LegendMarker(barseries,legend),
139 139 m_barset(barset)
140 140 {
141 141 QObject::connect(this, SIGNAL(selected()),barseries, SIGNAL(selected()));
142 142 QObject::connect(barset->d_ptr.data(), SIGNAL(valueChanged()), this, SLOT(updated()));
143 143 updated();
144 144 }
145 145
146 146 void BarLegendMarker::updated()
147 147 {
148 148 setBrush(m_barset->brush());
149 149 setLabel(m_barset->name());
150 150 }
151 151
152 152 //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
153 153
154 154 PieLegendMarker::PieLegendMarker(QPieSeries* series,QPieSlice *pieslice, QLegend *legend) : LegendMarker(series,legend),
155 155 m_pieslice(pieslice)
156 156 {
157 157 QObject::connect(this, SIGNAL(selected()),pieslice, SIGNAL(selected()));
158 158 QObject::connect(pieslice, SIGNAL(changed()), this, SLOT(updated()));
159 159 updated();
160 160 }
161 161
162 162 void PieLegendMarker::updated()
163 163 {
164 164 setBrush(m_pieslice->brush());
165 165 setLabel(m_pieslice->label());
166 166 }
167 167
168 168 //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
169 169
170 170 XYLegendMarker::XYLegendMarker(QXYSeries *series, QLegend *legend) : LegendMarker(series,legend),
171 171 m_series(series)
172 172 {
173 173 QObject::connect(this, SIGNAL(selected()), series, SIGNAL(selected()));
174 174 QObject::connect(series->d_func(),SIGNAL(updated()), this, SLOT(updated()));
175 175 updated();
176 176 }
177 177
178 178 void XYLegendMarker::updated()
179 179 {
180 180 setLabel(m_series->name());
181 181
182 if(m_series->type()== QSeries::SeriesTypeScatter)
182 if(m_series->type()== QAbstractSeries::SeriesTypeScatter)
183 183 {
184 184 setBrush(m_series->brush());
185 185
186 186 }
187 187 else {
188 188 setBrush(QBrush(m_series->pen().color()));
189 189 }
190 190 }
191 191
192 192 #include "moc_legendmarker_p.cpp"
193 193
194 194 QTCOMMERCIALCHART_END_NAMESPACE
@@ -1,128 +1,128
1 1 /****************************************************************************
2 2 **
3 3 ** Copyright (C) 2012 Digia Plc
4 4 ** All rights reserved.
5 5 ** For any questions to Digia, please use contact form at http://qt.digia.com
6 6 **
7 7 ** This file is part of the Qt Commercial Charts Add-on.
8 8 **
9 9 ** $QT_BEGIN_LICENSE$
10 10 ** Licensees holding valid Qt Commercial licenses may use this file in
11 11 ** accordance with the Qt Commercial License Agreement provided with the
12 12 ** Software or, alternatively, in accordance with the terms contained in
13 13 ** a written agreement between you and Digia.
14 14 **
15 15 ** If you have questions regarding the use of this file, please use
16 16 ** contact form at http://qt.digia.com
17 17 ** $QT_END_LICENSE$
18 18 **
19 19 ****************************************************************************/
20 20
21 21 #ifndef LEGENDMARKER_P_H
22 22 #define LEGENDMARKER_P_H
23 23
24 24 #include "qchartglobal.h"
25 25 #include <QGraphicsObject>
26 26 #include <QBrush>
27 27 #include <QPen>
28 28 #include <QGraphicsSimpleTextItem>
29 29
30 30 QTCOMMERCIALCHART_BEGIN_NAMESPACE
31 31
32 class QSeries;
32 class QAbstractSeries;
33 33 class QAreaSeries;
34 34 class QXYSeries;
35 35 class QBarSet;
36 36 class QBarSeries;
37 37 class QPieSlice;
38 38 class QLegend;
39 39 class QPieSeries;
40 40
41 41 class LegendMarker : public QGraphicsObject
42 42 {
43 43 Q_OBJECT
44 44
45 45 public:
46 explicit LegendMarker(QSeries* m_series,QLegend *parent);
46 explicit LegendMarker(QAbstractSeries *m_series, QLegend *parent);
47 47
48 48 void setPen(const QPen &pen);
49 49 QPen pen() const;
50 50 void setBrush(const QBrush &brush);
51 51 QBrush brush() const;
52 52
53 53 void setSize(const QSize& size);
54 54
55 55 void setLabel(const QString label);
56 56 QString label() const;
57 57
58 QSeries* series() const { return m_series;}
58 QAbstractSeries *series() const { return m_series;}
59 59
60 60 void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget = 0);
61 61
62 62 QRectF boundingRect() const;
63 63
64 64 void updateLayout();
65 65
66 66 protected:
67 67 // From QGraphicsObject
68 68 void mousePressEvent(QGraphicsSceneMouseEvent *event);
69 69
70 70 Q_SIGNALS:
71 71 void selected();
72 72
73 73 public Q_SLOTS:
74 74 virtual void updated() = 0;
75 75
76 76 protected:
77 QSeries* m_series;
77 QAbstractSeries *m_series;
78 78 QRectF m_markerRect;
79 79 QRectF m_boundingRect;
80 80 QLegend* m_legend;
81 81 QGraphicsSimpleTextItem *m_textItem;
82 82 QGraphicsRectItem *m_rectItem;
83 83
84 84 };
85 85
86 86 //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
87 87 class XYLegendMarker : public LegendMarker
88 88 {
89 89 public:
90 90 XYLegendMarker(QXYSeries *series, QLegend *legend);
91 91 protected:
92 92 void updated();
93 93 private:
94 94 QXYSeries *m_series;
95 95 };
96 96 //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
97 97 class AreaLegendMarker : public LegendMarker
98 98 {
99 99 public:
100 100 AreaLegendMarker(QAreaSeries *series, QLegend *legend);
101 101 protected:
102 102 void updated();
103 103 private:
104 104 QAreaSeries *m_series;
105 105 };
106 106 //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
107 107 class BarLegendMarker : public LegendMarker
108 108 {
109 109 public:
110 110 BarLegendMarker(QBarSeries *barseries, QBarSet *barset,QLegend *legend);
111 111 protected:
112 112 void updated();
113 113 private:
114 114 QBarSet *m_barset;
115 115 };
116 116 //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
117 117 class PieLegendMarker : public LegendMarker
118 118 {
119 119 public:
120 120 PieLegendMarker(QPieSeries *pieSeries, QPieSlice *pieslice, QLegend *legend);
121 121 protected:
122 122 void updated();
123 123 private:
124 124 QPieSlice *m_pieslice;
125 125 };
126 126
127 127 QTCOMMERCIALCHART_END_NAMESPACE
128 128 #endif // LEGENDMARKER_P_H
@@ -1,451 +1,451
1 1 /****************************************************************************
2 2 **
3 3 ** Copyright (C) 2012 Digia Plc
4 4 ** All rights reserved.
5 5 ** For any questions to Digia, please use contact form at http://qt.digia.com
6 6 **
7 7 ** This file is part of the Qt Commercial Charts Add-on.
8 8 **
9 9 ** $QT_BEGIN_LICENSE$
10 10 ** Licensees holding valid Qt Commercial licenses may use this file in
11 11 ** accordance with the Qt Commercial License Agreement provided with the
12 12 ** Software or, alternatively, in accordance with the terms contained in
13 13 ** a written agreement between you and Digia.
14 14 **
15 15 ** If you have questions regarding the use of this file, please use
16 16 ** contact form at http://qt.digia.com
17 17 ** $QT_END_LICENSE$
18 18 **
19 19 ****************************************************************************/
20 20
21 21 #include "qlegend.h"
22 22 #include "qlegend_p.h"
23 #include "qseries.h"
24 #include "qseries_p.h"
23 #include "qabstractseries.h"
24 #include "qabstractseries_p.h"
25 25 #include "qchart_p.h"
26 26
27 27 #include "legendmarker_p.h"
28 28 #include "qxyseries.h"
29 29 #include "qlineseries.h"
30 30 #include "qareaseries.h"
31 31 #include "qscatterseries.h"
32 32 #include "qsplineseries.h"
33 33 #include "qbarseries.h"
34 34 #include "qstackedbarseries.h"
35 35 #include "qpercentbarseries.h"
36 36 #include "qbarset.h"
37 37 #include "qpieseries.h"
38 38 #include "qpieslice.h"
39 39 #include "chartpresenter_p.h"
40 40 #include <QPainter>
41 41 #include <QPen>
42 42 #include <QTimer>
43 43
44 44 #include <QGraphicsSceneEvent>
45 45
46 46 QTCOMMERCIALCHART_BEGIN_NAMESPACE
47 47
48 48 /*!
49 49 \class QLegend
50 50 \brief part of QtCommercial chart API.
51 51
52 52 QLegend is a graphical object, whics displays legend of the chart. Legend state is updated by QChart, when
53 53 series have been changed. By default, legend is drawn by QChart, but user can set a new parent to legend and
54 54 handle the drawing manually.
55 55 User isn't supposed to create or delete legend objects, but can reference it via QChart class.
56 56
57 57 \mainclass
58 58
59 \sa QChart, QSeries
59 \sa QChart, QAbstractSeries
60 60 */
61 61
62 62 /*!
63 63 \enum QLegend::Alignment
64 64
65 65 This enum describes the possible position for legend inside chart.
66 66
67 67 \value AlignmentTop
68 68 \value AlignmentBottom
69 69 \value AlignmentLeft
70 70 \value AlignmentRight
71 71 */
72 72
73 73 /*!
74 74 \fn qreal QLegend::minWidth() const
75 75 Returns minimum width of the legend
76 76 */
77 77
78 78 /*!
79 79 \fn qreal QLegend::minHeight() const
80 80 Returns minimum height of the legend
81 81 */
82 82
83 83 /*!
84 84 Constructs the legend object and sets the parent to \a parent
85 85 */
86 86
87 87 QLegend::QLegend(QChart *chart):QGraphicsWidget(chart),
88 88 d_ptr(new QLegendPrivate(chart->d_ptr->m_presenter,this))
89 89 {
90 90 setZValue(ChartPresenter::LegendZValue);
91 91 setFlags(QGraphicsItem::ItemClipsChildrenToShape);
92 92 setEnabled(false); // By default legend is disabled
93 93 setVisible(false);
94 QObject::connect(chart->d_ptr->m_dataset,SIGNAL(seriesAdded(QSeries*,Domain*)),d_ptr.data(),SLOT(handleSeriesAdded(QSeries*,Domain*)));
95 QObject::connect(chart->d_ptr->m_dataset,SIGNAL(seriesRemoved(QSeries*)),d_ptr.data(),SLOT(handleSeriesRemoved(QSeries*)));
94 QObject::connect(chart->d_ptr->m_dataset,SIGNAL(seriesAdded(QAbstractSeries *, Domain *)),d_ptr.data(),SLOT(handleSeriesAdded(QAbstractSeries *,Domain*)));
95 QObject::connect(chart->d_ptr->m_dataset,SIGNAL(seriesRemoved(QAbstractSeries *)),d_ptr.data(),SLOT(handleSeriesRemoved(QAbstractSeries *)));
96 96 }
97 97
98 98 QLegend::~QLegend()
99 99 {
100 100
101 101 }
102 102
103 103 /*!
104 104 Paints the legend to given \a painter. Paremeters \a option and \a widget arent used.
105 105 */
106 106
107 107 void QLegend::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget)
108 108 {
109 109 Q_UNUSED(option)
110 110 Q_UNUSED(widget)
111 111 if(!d_ptr->m_backgroundVisible) return;
112 112
113 113 painter->setOpacity(opacity());
114 114 painter->setPen(d_ptr->m_pen);
115 115 painter->setBrush(d_ptr->m_brush);
116 116 painter->drawRect(boundingRect());
117 117 }
118 118
119 119 /*!
120 120 Bounding rect of legend.
121 121 */
122 122
123 123 QRectF QLegend::boundingRect() const
124 124 {
125 125 return d_ptr->m_rect;
126 126 }
127 127
128 128 /*!
129 129 Sets the \a brush of legend. Brush affects the background of legend.
130 130 */
131 131 void QLegend::setBrush(const QBrush &brush)
132 132 {
133 133 if (d_ptr->m_brush != brush) {
134 134 d_ptr->m_brush = brush;
135 135 update();
136 136 }
137 137 }
138 138
139 139 /*!
140 140 Returns the brush used by legend.
141 141 */
142 142 QBrush QLegend::brush() const
143 143 {
144 144 return d_ptr->m_brush;
145 145 }
146 146
147 147 /*!
148 148 Sets the \a pen of legend. Pen affects the legend borders.
149 149 */
150 150 void QLegend::setPen(const QPen &pen)
151 151 {
152 152 if (d_ptr->m_pen != pen) {
153 153 d_ptr->m_pen = pen;
154 154 update();
155 155 }
156 156 }
157 157
158 158 /*!
159 159 Returns the pen used by legend
160 160 */
161 161
162 162 QPen QLegend::pen() const
163 163 {
164 164 return d_ptr->m_pen;
165 165 }
166 166
167 167 /*!
168 168 Sets the \a alignment for legend. Legend tries to paint itself on the defined position in chart.
169 169 \sa QLegend::Alignment
170 170 */
171 171 void QLegend::setAlignment(QLegend::Alignments alignment)
172 172 {
173 173 if(d_ptr->m_alignment!=alignment && d_ptr->m_attachedToChart) {
174 174 d_ptr->m_alignment = alignment;
175 175 d_ptr->updateLayout();
176 176 }
177 177 }
178 178
179 179 /*!
180 180 Returns the preferred layout for legend
181 181 */
182 182 QLegend::Alignments QLegend::alignment() const
183 183 {
184 184 return d_ptr->m_alignment;
185 185 }
186 186
187 187 /*!
188 188 Detaches the legend from chart. Chart won't change layout of the legend.
189 189 */
190 190 void QLegend::detachFromChart()
191 191 {
192 192 d_ptr->m_attachedToChart = false;
193 193 }
194 194
195 195 /*!
196 196 Attaches the legend to chart. Chart may change layout of the legend.
197 197 */
198 198 void QLegend::attachToChart()
199 199 {
200 200 d_ptr->m_attachedToChart = true;
201 201 }
202 202
203 203 /*!
204 204 Returns true, if legend is attached to chart.
205 205 */
206 206 bool QLegend::isAttachedToChart()
207 207 {
208 208 return d_ptr->m_attachedToChart;
209 209 }
210 210
211 211 void QLegend::setOffset(const QPointF& point)
212 212 {
213 213 d_ptr->setOffset(point.x(),point.y());
214 214 }
215 215
216 216 QPointF QLegend::offset() const
217 217 {
218 218 return QPointF(d_ptr->m_offsetX,d_ptr->m_offsetY);
219 219 }
220 220
221 221 /*!
222 222 Sets the visibility of legend background to \a visible
223 223 */
224 224 void QLegend::setBackgroundVisible(bool visible)
225 225 {
226 226 if(d_ptr->m_backgroundVisible!=visible)
227 227 {
228 228 d_ptr->m_backgroundVisible=visible;
229 229 update();
230 230 }
231 231 }
232 232
233 233 /*!
234 234 Returns the visibility of legend background
235 235 */
236 236 bool QLegend::isBackgroundVisible() const
237 237 {
238 238 return d_ptr->m_backgroundVisible;
239 239 }
240 240
241 241 /*!
242 242 \internal \a event see QGraphicsWidget for details
243 243 */
244 244 void QLegend::resizeEvent(QGraphicsSceneResizeEvent *event)
245 245 {
246 246 const QRectF& rect = QRectF(QPoint(0,0),event->newSize());
247 247 QGraphicsWidget::resizeEvent(event);
248 248 if(d_ptr->m_rect != rect) {
249 249 d_ptr->m_rect = rect;
250 250 d_ptr->updateLayout();
251 251 }
252 252 }
253 253
254 254 /*!
255 255 \internal \a event see QGraphicsWidget for details
256 256 */
257 257 void QLegend::hideEvent(QHideEvent *event)
258 258 {
259 259 QGraphicsWidget::hideEvent(event);
260 260 setEnabled(false);
261 261 d_ptr->updateLayout();
262 262 }
263 263
264 264 /*!
265 265 \internal \a event see QGraphicsWidget for details
266 266 */
267 267 void QLegend::showEvent(QShowEvent *event)
268 268 {
269 269 QGraphicsWidget::showEvent(event);
270 270 setEnabled(true);
271 271 d_ptr->updateLayout();
272 272 }
273 273
274 274 qreal QLegend::minWidth() const
275 275 {
276 276 return d_ptr->m_minWidth;
277 277 }
278 278
279 279 qreal QLegend::minHeight() const
280 280 {
281 281 return d_ptr->m_minHeight;
282 282 }
283 283
284 284 ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
285 285
286 286 QLegendPrivate::QLegendPrivate(ChartPresenter* presenter,QLegend *q):
287 287 q_ptr(q),
288 288 m_presenter(presenter),
289 289 m_markers(new QGraphicsItemGroup(q)),
290 290 m_alignment(QLegend::AlignmentTop),
291 291 m_offsetX(0),
292 292 m_offsetY(0),
293 293 m_minWidth(0),
294 294 m_minHeight(0),
295 295 m_width(0),
296 296 m_height(0),
297 297 m_attachedToChart(true),
298 298 m_backgroundVisible(false)
299 299 {
300 300
301 301 }
302 302
303 303 QLegendPrivate::~QLegendPrivate()
304 304 {
305 305
306 306 }
307 307
308 308 void QLegendPrivate::setOffset(qreal x, qreal y)
309 309 {
310 310
311 311 switch(m_alignment) {
312 312
313 313 case QLegend::AlignmentTop:
314 314 case QLegend::AlignmentBottom: {
315 315 if(m_width<=m_rect.width()) return;
316 316
317 317 if (x != m_offsetX) {
318 318 m_offsetX = qBound(qreal(0), x, m_width - m_rect.width());
319 319 m_markers->setPos(-m_offsetX,m_rect.top());
320 320 }
321 321 break;
322 322 }
323 323 case QLegend::AlignmentLeft:
324 324 case QLegend::AlignmentRight: {
325 325
326 326 if(m_height<=m_rect.height()) return;
327 327
328 328 if (y != m_offsetY) {
329 329 m_offsetY = qBound(qreal(0), y, m_height - m_rect.height());
330 330 m_markers->setPos(m_rect.left(),-m_offsetY);
331 331 }
332 332 break;
333 333 }
334 334 }
335 335 }
336 336
337 337
338 338 void QLegendPrivate::updateLayout()
339 339 {
340 340 m_offsetX=0;
341 341 QList<QGraphicsItem *> items = m_markers->childItems();
342 342
343 343 if(items.isEmpty()) return;
344 344
345 345 m_minWidth=0;
346 346 m_minHeight=0;
347 347
348 348 switch(m_alignment) {
349 349
350 350 case QLegend::AlignmentTop:
351 351 case QLegend::AlignmentBottom: {
352 352 QPointF point = m_rect.topLeft();
353 353 m_width = 0;
354 354 foreach (QGraphicsItem *item, items) {
355 355 item->setPos(point.x(),m_rect.height()/2 -item->boundingRect().height()/2);
356 356 const QRectF& rect = item->boundingRect();
357 357 qreal w = rect.width();
358 358 m_minWidth=qMax(m_minWidth,w);
359 359 m_minHeight=qMax(m_minHeight,rect.height());
360 360 m_width+=w;
361 361 point.setX(point.x() + w);
362 362 }
363 363 if(m_width<m_rect.width()) {
364 364 m_markers->setPos(m_rect.width()/2-m_width/2,m_rect.top());
365 365 }
366 366 else {
367 367 m_markers->setPos(m_rect.topLeft());
368 368 }
369 369 m_height=m_minHeight;
370 370 }
371 371 break;
372 372 case QLegend::AlignmentLeft:
373 373 case QLegend::AlignmentRight: {
374 374 QPointF point = m_rect.topLeft();
375 375 m_height = 0;
376 376 foreach (QGraphicsItem *item, items) {
377 377 item->setPos(point);
378 378 const QRectF& rect = item->boundingRect();
379 379 qreal h = rect.height();
380 380 m_minWidth=qMax(m_minWidth,rect.width());
381 381 m_minHeight=qMax(m_minHeight,h);
382 382 m_height+=h;
383 383 point.setY(point.y() + h);
384 384 }
385 385 if(m_height<m_rect.height()) {
386 386 m_markers->setPos(m_rect.left(),m_rect.height()/2-m_height/2);
387 387 }
388 388 else {
389 389 m_markers->setPos(m_rect.topLeft());
390 390 }
391 391 m_width=m_minWidth;
392 392 }
393 393 break;
394 394 }
395 395
396 396 m_presenter->updateLayout();
397 397 }
398 398
399 void QLegendPrivate::handleSeriesAdded(QSeries *series, Domain *domain)
399 void QLegendPrivate::handleSeriesAdded(QAbstractSeries *series, Domain *domain)
400 400 {
401 401 Q_UNUSED(domain)
402 402
403 403 QList<LegendMarker*> markers = series->d_ptr->createLegendMarker(q_ptr);
404 404 foreach(LegendMarker* marker , markers)
405 405 m_markers->addToGroup(marker);
406 406
407 if(series->type()==QSeries::SeriesTypePie)
407 if(series->type() == QAbstractSeries::SeriesTypePie)
408 408 {
409 409 QPieSeries *pieSeries = static_cast<QPieSeries *>(series);
410 410 QObject::connect(pieSeries,SIGNAL(added(QList<QPieSlice*>)),this,SLOT(handleUpdateSeries()));
411 411 QObject::connect(pieSeries,SIGNAL(removed(QList<QPieSlice*>)),this,SLOT(handleUpdateSeries()));
412 412 }
413 413
414 414 updateLayout();
415 415 }
416 416
417 void QLegendPrivate::handleSeriesRemoved(QSeries *series)
417 void QLegendPrivate::handleSeriesRemoved(QAbstractSeries *series)
418 418 {
419 419
420 420 QList<QGraphicsItem *> items = m_markers->childItems();
421 421
422 422 foreach (QGraphicsItem *markers, items) {
423 423 LegendMarker *marker = static_cast<LegendMarker*>(markers);
424 424 if (marker->series() == series) {
425 425 delete marker;
426 426 }
427 427 }
428 428
429 if(series->type()==QSeries::SeriesTypePie)
429 if(series->type() == QAbstractSeries::SeriesTypePie)
430 430 {
431 431 QPieSeries *pieSeries = static_cast<QPieSeries *>(series);
432 432 QObject::disconnect(pieSeries,SIGNAL(added(QList<QPieSlice*>)),this,SLOT(handleUpdateSeries()));
433 433 QObject::disconnect(pieSeries,SIGNAL(removed(QList<QPieSlice*>)),this,SLOT(handleUpdateSeries()));
434 434 }
435 435
436 436 updateLayout();
437 437 }
438 438
439 439 void QLegendPrivate::handleUpdateSeries()
440 440 {
441 441 //TODO: reimplement to be optimal
442 QSeries* series = qobject_cast<QSeries *> (sender());
442 QAbstractSeries* series = qobject_cast<QAbstractSeries *> (sender());
443 443 Q_ASSERT(series);
444 444 handleSeriesRemoved(series);
445 445 handleSeriesAdded(series,0);
446 446 }
447 447
448 448 #include "moc_qlegend.cpp"
449 449 #include "moc_qlegend_p.cpp"
450 450
451 451 QTCOMMERCIALCHART_END_NAMESPACE
@@ -1,104 +1,102
1 1 /****************************************************************************
2 2 **
3 3 ** Copyright (C) 2012 Digia Plc
4 4 ** All rights reserved.
5 5 ** For any questions to Digia, please use contact form at http://qt.digia.com
6 6 **
7 7 ** This file is part of the Qt Commercial Charts Add-on.
8 8 **
9 9 ** $QT_BEGIN_LICENSE$
10 10 ** Licensees holding valid Qt Commercial licenses may use this file in
11 11 ** accordance with the Qt Commercial License Agreement provided with the
12 12 ** Software or, alternatively, in accordance with the terms contained in
13 13 ** a written agreement between you and Digia.
14 14 **
15 15 ** If you have questions regarding the use of this file, please use
16 16 ** contact form at http://qt.digia.com
17 17 ** $QT_END_LICENSE$
18 18 **
19 19 ****************************************************************************/
20 20
21 21 #ifndef QLEGEND_H
22 22 #define QLEGEND_H
23 23
24 24 #include <QChartGlobal>
25 25 #include <QGraphicsWidget>
26 26 #include <QPen>
27 27 #include <QBrush>
28 28
29 29 QTCOMMERCIALCHART_BEGIN_NAMESPACE
30 30
31 31 class Domain;
32 32 class LegendMarker;
33 33 class QPieSlice;
34 34 class QXYSeries;
35 35 class QBarSet;
36 36 class QBarSeries;
37 37 class QPieSeries;
38 38 class QAreaSeries;
39 39 class LegendScrollButton;
40 class QSeries;
41
42 40 class QChart;
43 41 class QLegendPrivate;
44 42
45 43 class QTCOMMERCIALCHART_EXPORT QLegend : public QGraphicsWidget
46 44 {
47 45 Q_OBJECT
48 46 public:
49 47
50 48 // We only support these alignments (for now)
51 49 enum Alignment {
52 50 AlignmentTop = Qt::AlignTop,
53 51 AlignmentBottom = Qt::AlignBottom,
54 52 AlignmentLeft = Qt::AlignLeft,
55 53 AlignmentRight = Qt::AlignRight
56 54 };
57 55
58 56 Q_DECLARE_FLAGS(Alignments, Alignment)
59 57
60 58 private:
61 59 explicit QLegend(QChart *chart);
62 60
63 61 public:
64 62 ~QLegend();
65 63
66 64 void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget = 0);
67 65 QRectF boundingRect() const;
68 66
69 67 void setBrush(const QBrush &brush);
70 68 QBrush brush() const;
71 69
72 70 void setPen(const QPen &pen);
73 71 QPen pen() const;
74 72
75 73 void setAlignment(QLegend::Alignments alignment);
76 74 QLegend::Alignments alignment() const;
77 75
78 76 void detachFromChart();
79 77 void attachToChart();
80 78 bool isAttachedToChart();
81 79
82 80 qreal minWidth() const;
83 81 qreal minHeight() const;
84 82
85 83 void setBackgroundVisible(bool visible = true);
86 84 bool isBackgroundVisible() const;
87 85
88 86 void setOffset(const QPointF& point);
89 87 QPointF offset() const;
90 88
91 89 protected:
92 90 void resizeEvent(QGraphicsSceneResizeEvent *event);
93 91 void hideEvent(QHideEvent *event);
94 92 void showEvent(QShowEvent *event);
95 93
96 94 private:
97 95 QScopedPointer<QLegendPrivate> d_ptr;
98 96 Q_DISABLE_COPY(QLegend);
99 97 friend class LegendScroller;
100 98 };
101 99
102 100 QTCOMMERCIALCHART_END_NAMESPACE
103 101
104 102 #endif // QLEGEND_H
@@ -1,77 +1,78
1 1 /****************************************************************************
2 2 **
3 3 ** Copyright (C) 2012 Digia Plc
4 4 ** All rights reserved.
5 5 ** For any questions to Digia, please use contact form at http://qt.digia.com
6 6 **
7 7 ** This file is part of the Qt Commercial Charts Add-on.
8 8 **
9 9 ** $QT_BEGIN_LICENSE$
10 10 ** Licensees holding valid Qt Commercial licenses may use this file in
11 11 ** accordance with the Qt Commercial License Agreement provided with the
12 12 ** Software or, alternatively, in accordance with the terms contained in
13 13 ** a written agreement between you and Digia.
14 14 **
15 15 ** If you have questions regarding the use of this file, please use
16 16 ** contact form at http://qt.digia.com
17 17 ** $QT_END_LICENSE$
18 18 **
19 19 ****************************************************************************/
20 20
21 21 // W A R N I N G
22 22 // -------------
23 23 //
24 24 // This file is not part of the QtCommercial Chart API. It exists purely as an
25 25 // implementation detail. This header file may change from version to
26 26 // version without notice, or even be removed.
27 27 //
28 28 // We mean it.
29 29
30 30 #ifndef QLEGEND_P_H
31 31 #define QLEGEND_P_H
32 32
33 33 #include "qlegend.h"
34 34
35 35 QTCOMMERCIALCHART_BEGIN_NAMESPACE
36 36
37 37 class ChartPresenter;
38 class QAbstractSeries;
38 39
39 40 class QLegendPrivate : public QObject
40 41 {
41 42 Q_OBJECT
42 43 public:
43 44 QLegendPrivate(ChartPresenter *chart,QLegend *q);
44 45 ~QLegendPrivate();
45 46
46 47 void setOffset(qreal x, qreal y);
47 48 void updateLayout();
48 49
49 50 public Q_SLOTS:
50 void handleSeriesAdded(QSeries *series, Domain *domain);
51 void handleSeriesRemoved(QSeries *series);
51 void handleSeriesAdded(QAbstractSeries *series, Domain *domain);
52 void handleSeriesRemoved(QAbstractSeries *series);
52 53 void handleUpdateSeries(); //TODO remove this function
53 54
54 55 private:
55 56 QLegend *q_ptr;
56 57 ChartPresenter *m_presenter;
57 58 QGraphicsItemGroup* m_markers;
58 59 QLegend::Alignments m_alignment;
59 60 QBrush m_brush;
60 61 QPen m_pen;
61 62 QRectF m_rect;
62 63 qreal m_offsetX;
63 64 qreal m_offsetY;
64 65 qreal m_minWidth;
65 66 qreal m_minHeight;
66 67 qreal m_width;
67 68 qreal m_height;
68 69 bool m_attachedToChart;
69 70 bool m_backgroundVisible;
70 71
71 72 friend class QLegend;
72 73
73 74 };
74 75
75 76 QTCOMMERCIALCHART_END_NAMESPACE
76 77
77 78 #endif
@@ -1,116 +1,116
1 1 /****************************************************************************
2 2 **
3 3 ** Copyright (C) 2012 Digia Plc
4 4 ** All rights reserved.
5 5 ** For any questions to Digia, please use contact form at http://qt.digia.com
6 6 **
7 7 ** This file is part of the Qt Commercial Charts Add-on.
8 8 **
9 9 ** $QT_BEGIN_LICENSE$
10 10 ** Licensees holding valid Qt Commercial licenses may use this file in
11 11 ** accordance with the Qt Commercial License Agreement provided with the
12 12 ** Software or, alternatively, in accordance with the terms contained in
13 13 ** a written agreement between you and Digia.
14 14 **
15 15 ** If you have questions regarding the use of this file, please use
16 16 ** contact form at http://qt.digia.com
17 17 ** $QT_END_LICENSE$
18 18 **
19 19 ****************************************************************************/
20 20
21 21 #include "qlineseries.h"
22 22 #include "qlineseries_p.h"
23 23 #include "linechartitem_p.h"
24 24 #include "chartdataset_p.h"
25 25 #include "charttheme_p.h"
26 26 #include "chartanimator_p.h"
27 27
28 28 QTCOMMERCIALCHART_BEGIN_NAMESPACE
29 29
30 30 /*!
31 31 \class QLineSeries
32 32 \brief The QLineSeries class is used for making line charts.
33 33
34 34 \mainclass
35 35
36 36 A line chart is used to show information as a series of data points
37 37 connected by straight lines.
38 38
39 39 \image linechart.png
40 40
41 41 Creating basic line chart is simple:
42 42 \code
43 43 QLineSeries* series = new QLineSeries();
44 44 series->append(0, 6);
45 45 series->append(2, 4);
46 46 ...
47 47 chartView->addSeries(series);
48 48 \endcode
49 49 */
50 50
51 51 /*!
52 52 \fn virtual QSeriesType QLineSeries::type() const
53 53 \brief Returns type of series.
54 \sa QSeries, QSeriesType
54 \sa QAbstractSeries, QSeriesType
55 55 */
56 56
57 57 /*!
58 58 Constructs empty series object which is a child of \a parent.
59 59 When series object is added to QChartView or QChart instance ownerships is transferred.
60 60 */
61 61 QLineSeries::QLineSeries(QObject *parent) : QXYSeries(*new QLineSeriesPrivate(this),parent)
62 62 {
63 63
64 64 }
65 65
66 66 /*!
67 67 \internal
68 68 */
69 69 QLineSeries::QLineSeries(QLineSeriesPrivate &d,QObject *parent) : QXYSeries (d,parent)
70 70 {
71 71
72 72 }
73 73 /*!
74 74 Destroys the object. Series added to QChartView or QChart instances are owned by those,
75 75 and are deleted when mentioned object are destroyed.
76 76 */
77 77 QLineSeries::~QLineSeries()
78 78 {
79 79 }
80 80
81 QSeries::QSeriesType QLineSeries::type() const
81 QAbstractSeries::QSeriesType QLineSeries::type() const
82 82 {
83 return QSeries::SeriesTypeLine;
83 return QAbstractSeries::SeriesTypeLine;
84 84 }
85 85
86 86 /*
87 87 QDebug operator<< (QDebug debug, const QLineSeries series)
88 88 {
89 89 Q_ASSERT(series.d_func()->m_x.size() == series.d_func()->m_y.size());
90 90 int size = series.d_func()->m_x.size();
91 91 for (int i=0; i<size; i++) {
92 92 debug.nospace() << "(" << series.d_func()->m_x.at(i) << ','<< series.d_func()->m_y.at(i) << ") ";
93 93 }
94 94 return debug.space();
95 95 }
96 96 */
97 97
98 98 ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
99 99
100 100 QLineSeriesPrivate::QLineSeriesPrivate(QLineSeries* q):QXYSeriesPrivate(q)
101 101 {
102 102
103 103 };
104 104
105 105 Chart* QLineSeriesPrivate::createGraphics(ChartPresenter* presenter)
106 106 {
107 107 Q_Q(QLineSeries);
108 108 LineChartItem* line = new LineChartItem(q,presenter);
109 109 if(presenter->animationOptions().testFlag(QChart::SeriesAnimations)) {
110 110 presenter->animator()->addAnimation(line);
111 111 }
112 112 presenter->chartTheme()->decorate(q, presenter->dataSet()->seriesIndex(q));
113 113 return line;
114 114 }
115 115
116 116 QTCOMMERCIALCHART_END_NAMESPACE
@@ -1,52 +1,52
1 1 /****************************************************************************
2 2 **
3 3 ** Copyright (C) 2012 Digia Plc
4 4 ** All rights reserved.
5 5 ** For any questions to Digia, please use contact form at http://qt.digia.com
6 6 **
7 7 ** This file is part of the Qt Commercial Charts Add-on.
8 8 **
9 9 ** $QT_BEGIN_LICENSE$
10 10 ** Licensees holding valid Qt Commercial licenses may use this file in
11 11 ** accordance with the Qt Commercial License Agreement provided with the
12 12 ** Software or, alternatively, in accordance with the terms contained in
13 13 ** a written agreement between you and Digia.
14 14 **
15 15 ** If you have questions regarding the use of this file, please use
16 16 ** contact form at http://qt.digia.com
17 17 ** $QT_END_LICENSE$
18 18 **
19 19 ****************************************************************************/
20 20
21 21 #ifndef QLINESERIES_H
22 22 #define QLINESERIES_H
23 23
24 24 #include <qchartglobal.h>
25 25 #include <qxyseries.h>
26 26 #include <QPen>
27 27
28 28 QTCOMMERCIALCHART_BEGIN_NAMESPACE
29 29
30 30 class QLineSeriesPrivate;
31 31
32 32 class QTCOMMERCIALCHART_EXPORT QLineSeries : public QXYSeries
33 33 {
34 34 public:
35 35 explicit QLineSeries(QObject *parent = 0);
36 36 ~QLineSeries();
37 37
38 QSeries::QSeriesType type() const;
38 QAbstractSeries::QSeriesType type() const;
39 39
40 40 protected:
41 41 QLineSeries(QLineSeriesPrivate &d,QObject *parent = 0);
42 42
43 43 private:
44 44 Q_DECLARE_PRIVATE(QLineSeries);
45 45 Q_DISABLE_COPY(QLineSeries);
46 46 friend class LineChartItem;
47 47
48 48 };
49 49
50 50 QTCOMMERCIALCHART_END_NAMESPACE
51 51
52 52 #endif
@@ -1,738 +1,738
1 1 /****************************************************************************
2 2 **
3 3 ** Copyright (C) 2012 Digia Plc
4 4 ** All rights reserved.
5 5 ** For any questions to Digia, please use contact form at http://qt.digia.com
6 6 **
7 7 ** This file is part of the Qt Commercial Charts Add-on.
8 8 **
9 9 ** $QT_BEGIN_LICENSE$
10 10 ** Licensees holding valid Qt Commercial licenses may use this file in
11 11 ** accordance with the Qt Commercial License Agreement provided with the
12 12 ** Software or, alternatively, in accordance with the terms contained in
13 13 ** a written agreement between you and Digia.
14 14 **
15 15 ** If you have questions regarding the use of this file, please use
16 16 ** contact form at http://qt.digia.com
17 17 ** $QT_END_LICENSE$
18 18 **
19 19 ****************************************************************************/
20 20
21 21 #include "qpieseries.h"
22 22 #include "qpieseries_p.h"
23 23 #include "qpieslice.h"
24 24 #include "pieslicedata_p.h"
25 25 #include "chartdataset_p.h"
26 26 #include "charttheme_p.h"
27 27 #include "chartanimator_p.h"
28 28 #include "legendmarker_p.h"
29 29 #include <QAbstractItemModel>
30 30 #include <QDebug>
31 31
32 32 QTCOMMERCIALCHART_BEGIN_NAMESPACE
33 33
34 34 /*!
35 35 \class QPieSeries
36 36 \brief Pie series API for QtCommercial Charts
37 37
38 38 The pie series defines a pie chart which consists of pie slices which are defined as QPieSlice objects.
39 39 The slices can have any values as the QPieSeries will calculate its relative value to the sum of all slices.
40 40 The actual slice size is determined by that relative value.
41 41
42 42 Pie size and position on the chart is controlled by using relative values which range from 0.0 to 1.0
43 43 These relate to the actual chart rectangle.
44 44
45 45 By default the pie is defined as a full pie but it can also be a partial pie.
46 46 This can be done by setting a starting angle and angle span to the series.
47 47 Full pie is 360 degrees where 0 is at 12 a'clock.
48 48 */
49 49
50 50 /*!
51 51 \property QPieSeries::horizontalPosition
52 52 \brief Defines the horizontal position of the pie.
53 53
54 54 The value is a relative value to the chart rectangle where:
55 55
56 56 \list
57 57 \o 0.0 is the absolute left.
58 58 \o 1.0 is the absolute right.
59 59 \endlist
60 60
61 61 Default value is 0.5 (center).
62 62 */
63 63
64 64 /*!
65 65 \property QPieSeries::verticalPosition
66 66 \brief Defines the vertical position of the pie.
67 67
68 68 The value is a relative value to the chart rectangle where:
69 69
70 70 \list
71 71 \o 0.0 is the absolute top.
72 72 \o 1.0 is the absolute bottom.
73 73 \endlist
74 74
75 75 Default value is 0.5 (center).
76 76 */
77 77
78 78 /*!
79 79 \property QPieSeries::size
80 80 \brief Defines the pie size.
81 81
82 82 The value is a relative value to the chart rectangle where:
83 83
84 84 \list
85 85 \o 0.0 is the minimum size (pie not drawn).
86 86 \o 1.0 is the maximum size that can fit the chart.
87 87 \endlist
88 88
89 89 Default value is 0.7.
90 90 */
91 91
92 92 /*!
93 93 \property QPieSeries::startAngle
94 94 \brief Defines the starting angle of the pie.
95 95
96 96 Full pie is 360 degrees where 0 degrees is at 12 a'clock.
97 97
98 98 Default is value is 0.
99 99 */
100 100
101 101 /*!
102 102 \property QPieSeries::endAngle
103 103 \brief Defines the ending angle of the pie.
104 104
105 105 Full pie is 360 degrees where 0 degrees is at 12 a'clock.
106 106
107 107 Default is value is 360.
108 108 */
109 109
110 110
111 111 /*!
112 112 Constructs a series object which is a child of \a parent.
113 113 */
114 114 QPieSeries::QPieSeries(QObject *parent) :
115 QSeries(*new QPieSeriesPrivate(this),parent)
115 QAbstractSeries(*new QPieSeriesPrivate(this),parent)
116 116 {
117 117
118 118 }
119 119
120 120 /*!
121 121 Destroys the series and its slices.
122 122 */
123 123 QPieSeries::~QPieSeries()
124 124 {
125 125 // NOTE: d_prt destroyed by QObject
126 126 }
127 127
128 128 /*!
129 129 Returns QChartSeries::SeriesTypePie.
130 130 */
131 QSeries::QSeriesType QPieSeries::type() const
131 QAbstractSeries::QSeriesType QPieSeries::type() const
132 132 {
133 return QSeries::SeriesTypePie;
133 return QAbstractSeries::SeriesTypePie;
134 134 }
135 135
136 136 /*!
137 137 Sets an array of \a slices to the series replacing the existing slices.
138 138 Slice ownership is passed to the series.
139 139 */
140 140 void QPieSeries::replace(QList<QPieSlice*> slices)
141 141 {
142 142 clear();
143 143 append(slices);
144 144 }
145 145
146 146 /*!
147 147 Appends an array of \a slices to the series.
148 148 Slice ownership is passed to the series.
149 149 */
150 150 void QPieSeries::append(QList<QPieSlice*> slices)
151 151 {
152 152 Q_D(QPieSeries);
153 153
154 154 foreach (QPieSlice* s, slices) {
155 155 s->setParent(this);
156 156 d->m_slices << s;
157 157 }
158 158
159 159 d->updateDerivativeData();
160 160
161 161 foreach (QPieSlice* s, slices) {
162 162 connect(s, SIGNAL(changed()), d, SLOT(sliceChanged()));
163 163 connect(s, SIGNAL(clicked(Qt::MouseButtons)), d, SLOT(sliceClicked(Qt::MouseButtons)));
164 164 connect(s, SIGNAL(hoverEnter()), d, SLOT(sliceHoverEnter()));
165 165 connect(s, SIGNAL(hoverLeave()), d, SLOT(sliceHoverLeave()));
166 166 }
167 167
168 168 emit added(slices);
169 169 }
170 170
171 171 /*!
172 172 Appends a single \a slice to the series.
173 173 Slice ownership is passed to the series.
174 174 */
175 175 void QPieSeries::append(QPieSlice* slice)
176 176 {
177 177 append(QList<QPieSlice*>() << slice);
178 178 }
179 179
180 180 /*!
181 181 Appends a single \a slice to the series and returns a reference to the series.
182 182 Slice ownership is passed to the series.
183 183 */
184 184 QPieSeries& QPieSeries::operator << (QPieSlice* slice)
185 185 {
186 186 append(slice);
187 187 return *this;
188 188 }
189 189
190 190
191 191 /*!
192 192 Appends a single slice to the series with give \a value and \a name.
193 193 Slice ownership is passed to the series.
194 194 */
195 195 QPieSlice* QPieSeries::append(qreal value, QString name)
196 196 {
197 197 QPieSlice* slice = new QPieSlice(value, name);
198 198 append(slice);
199 199 return slice;
200 200 }
201 201
202 202 /*!
203 203 Inserts a single \a slice to the series before the slice at \a index position.
204 204 Slice ownership is passed to the series.
205 205 */
206 206 void QPieSeries::insert(int index, QPieSlice* slice)
207 207 {
208 208 Q_D(QPieSeries);
209 209 Q_ASSERT(index <= d->m_slices.count());
210 210 slice->setParent(this);
211 211 d->m_slices.insert(index, slice);
212 212
213 213 d->updateDerivativeData();
214 214
215 215 connect(slice, SIGNAL(changed()), d, SLOT(sliceChanged()));
216 216 connect(slice, SIGNAL(clicked(Qt::MouseButtons)), d, SLOT(sliceClicked(Qt::MouseButtons)));
217 217 connect(slice, SIGNAL(hoverEnter()), d, SLOT(sliceHoverEnter()));
218 218 connect(slice, SIGNAL(hoverLeave()), d, SLOT(sliceHoverLeave()));
219 219
220 220 emit added(QList<QPieSlice*>() << slice);
221 221 }
222 222
223 223 /*!
224 224 Removes a single \a slice from the series and deletes the slice.
225 225
226 226 Do not reference the pointer after this call.
227 227 */
228 228 void QPieSeries::remove(QPieSlice* slice)
229 229 {
230 230 Q_D(QPieSeries);
231 231 if (!d->m_slices.removeOne(slice)) {
232 232 Q_ASSERT(0); // TODO: how should this be reported?
233 233 return;
234 234 }
235 235
236 236 d->updateDerivativeData();
237 237
238 238 emit removed(QList<QPieSlice*>() << slice);
239 239
240 240 delete slice;
241 241 slice = 0;
242 242 }
243 243
244 244 /*!
245 245 Clears all slices from the series.
246 246 */
247 247 void QPieSeries::clear()
248 248 {
249 249 Q_D(QPieSeries);
250 250 if (d->m_slices.count() == 0)
251 251 return;
252 252
253 253 QList<QPieSlice*> slices = d->m_slices;
254 254 foreach (QPieSlice* s, d->m_slices) {
255 255 d->m_slices.removeOne(s);
256 256 delete s;
257 257 }
258 258
259 259 d->updateDerivativeData();
260 260
261 261 emit removed(slices);
262 262 }
263 263
264 264 /*!
265 265 returns the number of the slices in this series.
266 266 */
267 267 int QPieSeries::count() const
268 268 {
269 269 Q_D(const QPieSeries);
270 270 return d->m_slices.count();
271 271 }
272 272
273 273 /*!
274 274 Returns true is the series is empty.
275 275 */
276 276 bool QPieSeries::isEmpty() const
277 277 {
278 278 Q_D(const QPieSeries);
279 279 return d->m_slices.isEmpty();
280 280 }
281 281
282 282 /*!
283 283 Returns a list of slices that belong to this series.
284 284 */
285 285 QList<QPieSlice*> QPieSeries::slices() const
286 286 {
287 287 Q_D(const QPieSeries);
288 288 return d->m_slices;
289 289 }
290 290
291 291 void QPieSeries::setHorizontalPosition(qreal relativePosition)
292 292 {
293 293 Q_D(QPieSeries);
294 294 if (d->setRealValue(d->m_pieRelativeHorPos, relativePosition, 1.0))
295 295 emit piePositionChanged();
296 296 }
297 297
298 298 void QPieSeries::setVerticalPosition(qreal relativePosition)
299 299 {
300 300 Q_D(QPieSeries);
301 301 if (d->setRealValue(d->m_pieRelativeVerPos, relativePosition, 1.0))
302 302 emit piePositionChanged();
303 303 }
304 304
305 305 qreal QPieSeries::horizontalPosition() const
306 306 {
307 307 Q_D(const QPieSeries);
308 308 return d->m_pieRelativeHorPos;
309 309 }
310 310
311 311 qreal QPieSeries::verticalPosition() const
312 312 {
313 313 Q_D(const QPieSeries);
314 314 return d->m_pieRelativeVerPos;
315 315 }
316 316
317 317 void QPieSeries::setPieSize(qreal relativeSize)
318 318 {
319 319 Q_D(QPieSeries);
320 320 if (d->setRealValue(d->m_pieRelativeSize, relativeSize, 1.0))
321 321 emit pieSizeChanged();
322 322 }
323 323
324 324 qreal QPieSeries::pieSize() const
325 325 {
326 326 Q_D(const QPieSeries);
327 327 return d->m_pieRelativeSize;
328 328 }
329 329
330 330
331 331 void QPieSeries::setPieStartAngle(qreal angle)
332 332 {
333 333 Q_D(QPieSeries);
334 334 if (d->setRealValue(d->m_pieStartAngle, angle, d->m_pieEndAngle))
335 335 d->updateDerivativeData();
336 336 }
337 337
338 338 qreal QPieSeries::pieStartAngle() const
339 339 {
340 340 Q_D(const QPieSeries);
341 341 return d->m_pieStartAngle;
342 342 }
343 343
344 344 /*!
345 345 Sets the end angle of the pie.
346 346
347 347 Full pie is 360 degrees where 0 degrees is at 12 a'clock.
348 348
349 349 \a angle must be greater than start angle.
350 350
351 351 \sa pieEndAngle(), pieStartAngle(), setPieStartAngle()
352 352 */
353 353 void QPieSeries::setPieEndAngle(qreal angle)
354 354 {
355 355 Q_D(QPieSeries);
356 356
357 357 if (d->setRealValue(d->m_pieEndAngle, angle, 360.0, d->m_pieStartAngle))
358 358 d->updateDerivativeData();
359 359 }
360 360
361 361 /*!
362 362 Returns the end angle of the pie.
363 363
364 364 Full pie is 360 degrees where 0 degrees is at 12 a'clock.
365 365
366 366 \sa setPieEndAngle(), pieStartAngle(), setPieStartAngle()
367 367 */
368 368 qreal QPieSeries::pieEndAngle() const
369 369 {
370 370 Q_D(const QPieSeries);
371 371 return d->m_pieEndAngle;
372 372 }
373 373
374 374 /*!
375 375 Sets the all the slice labels \a visible or invisible.
376 376
377 377 \sa QPieSlice::isLabelVisible(), QPieSlice::setLabelVisible()
378 378 */
379 379 void QPieSeries::setLabelsVisible(bool visible)
380 380 {
381 381 Q_D(QPieSeries);
382 382 foreach (QPieSlice* s, d->m_slices)
383 383 s->setLabelVisible(visible);
384 384 }
385 385
386 386 /*!
387 387 Returns the sum of all slice values in this series.
388 388
389 389 \sa QPieSlice::value(), QPieSlice::setValue(), QPieSlice::percentage()
390 390 */
391 391 qreal QPieSeries::sum() const
392 392 {
393 393 Q_D(const QPieSeries);
394 394 return d->m_sum;
395 395 }
396 396
397 397 /*!
398 398 \fn void QPieSeries::clicked(QPieSlice* slice, Qt::MouseButtons buttons)
399 399
400 400 This signal is emitted when a \a slice has been clicked with mouse \a buttons.
401 401
402 402 \sa QPieSlice::clicked()
403 403 */
404 404
405 405 /*!
406 406 \fn void QPieSeries::hoverEnter(QPieSlice* slice)
407 407
408 408 This signal is emitted when user has hovered over a \a slice.
409 409
410 410 \sa QPieSlice::hoverEnter()
411 411 */
412 412
413 413 /*!
414 414 \fn void QPieSeries::hoverLeave(QPieSlice* slice)
415 415
416 416 This signal is emitted when user has hovered away from a \a slice.
417 417
418 418 \sa QPieSlice::hoverLeave()
419 419 */
420 420
421 421 /*!
422 422 \fn void QPieSeries::added(QList<QPieSlice*> slices)
423 423
424 424 This signal is emitted when \a slices has been added to the series.
425 425
426 426 \sa append(), insert()
427 427 */
428 428
429 429 /*!
430 430 \fn void QPieSeries::removed(QList<QPieSlice*> slices)
431 431
432 432 This signal is emitted when \a slices has been removed from the series.
433 433
434 434 \sa remove(), clear()
435 435 */
436 436
437 437 /*!
438 438 \fn void QPieSeries::piePositionChanged()
439 439
440 440 This signal is emitted when pie position has changed.
441 441
442 442 \sa verticalPosition(), setVerticalPosition(), horizontalPosition(), setHorizontalPosition()
443 443 */
444 444
445 445 /*!
446 446 \fn void QPieSeries::pieSizeChanged()
447 447
448 448 This signal is emitted when pie size has changed.
449 449
450 450 \sa pieSize(), setPieSize()
451 451 */
452 452
453 453 /*!
454 454 \fn bool QPieSeries::setModel(QAbstractItemModel *model)
455 455 Sets the \a model to be used as a data source
456 456 */
457 457 bool QPieSeries::setModel(QAbstractItemModel* model)
458 458 {
459 459 Q_D(QPieSeries);
460 460 // disconnect signals from old model
461 461 if(d->m_model)
462 462 {
463 463 disconnect(d->m_model, 0, this, 0);
464 464 d->m_mapValues = -1;
465 465 d->m_mapLabels = -1;
466 466 d->m_mapOrientation = Qt::Vertical;
467 467 }
468 468
469 469 // set new model
470 470 if(model)
471 471 {
472 472 d->m_model = model;
473 473 return true;
474 474 }
475 475 else
476 476 {
477 477 d->m_model = 0;
478 478 return false;
479 479 }
480 480 }
481 481
482 482 /*!
483 483 \fn bool QPieSeries::setModelMapping(int modelValuesLine, int modelLabelsLine, Qt::Orientation orientation)
484 484 Sets column/row specified by \a modelValuesLine to be used as a list of pie slice values for the pie.
485 485 Parameter \a modelValuesLine indicates the column/row where the values for the pie slices are located in the model.
486 486 Parameter \a modelLabelsLine indicates the column/row where the labels for the pie slices are located in the model.
487 487 The \a orientation parameter specifies whether the data is in columns or in rows.
488 488 */
489 489 void QPieSeries::setModelMapping(int modelValuesLine, int modelLabelsLine, Qt::Orientation orientation)
490 490 {
491 491 Q_D(QPieSeries);
492 492
493 493 if (d->m_model == 0)
494 494 return;
495 495
496 496 d->m_mapValues = modelValuesLine;
497 497 d->m_mapLabels = modelLabelsLine;
498 498 d->m_mapOrientation = orientation;
499 499
500 500 // connect the signals
501 501 if (d->m_mapOrientation == Qt::Vertical) {
502 502 connect(d->m_model, SIGNAL(dataChanged(QModelIndex,QModelIndex)), d, SLOT(modelUpdated(QModelIndex,QModelIndex)));
503 503 connect(d->m_model, SIGNAL(rowsInserted(QModelIndex,int,int)), d, SLOT(modelDataAdded(QModelIndex,int,int)));
504 504 connect(d->m_model, SIGNAL(rowsRemoved(QModelIndex,int,int)), d, SLOT(modelDataRemoved(QModelIndex,int,int)));
505 505 } else {
506 506 connect(d->m_model, SIGNAL(dataChanged(QModelIndex,QModelIndex)), d, SLOT(modelUpdated(QModelIndex,QModelIndex)));
507 507 connect(d->m_model, SIGNAL(columnsInserted(QModelIndex,int,int)), d, SLOT(modelDataAdded(QModelIndex,int,int)));
508 508 connect(d->m_model, SIGNAL(columnsRemoved(QModelIndex,int,int)), d, SLOT(modelDataRemoved(QModelIndex,int,int)));
509 509 }
510 510
511 511 // create the initial slices set
512 512 if (d->m_mapOrientation == Qt::Vertical) {
513 513 for (int i = 0; i < d->m_model->rowCount(); i++)
514 514 append(d->m_model->data(d->m_model->index(i, d->m_mapValues), Qt::DisplayRole).toDouble(), d->m_model->data(d->m_model->index(i, d->m_mapLabels), Qt::DisplayRole).toString());
515 515 } else {
516 516 for (int i = 0; i < d->m_model->columnCount(); i++)
517 517 append(d->m_model->data(d->m_model->index(d->m_mapValues, i), Qt::DisplayRole).toDouble(), d->m_model->data(d->m_model->index(d->m_mapLabels, i), Qt::DisplayRole).toString());
518 518 }
519 519 }
520 520
521 521 ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
522 522
523 523
524 QPieSeriesPrivate::QPieSeriesPrivate(QPieSeries *parent)
525 :QSeriesPrivate(parent),
524 QPieSeriesPrivate::QPieSeriesPrivate(QPieSeries *parent) :
525 QAbstractSeriesPrivate(parent),
526 526 m_pieRelativeHorPos(0.5),
527 527 m_pieRelativeVerPos(0.5),
528 528 m_pieRelativeSize(0.7),
529 529 m_pieStartAngle(0),
530 530 m_pieEndAngle(360),
531 531 m_sum(0),
532 532 m_mapValues(0),
533 533 m_mapLabels(0),
534 534 m_mapOrientation(Qt::Horizontal)
535 535 {
536 536
537 537 }
538 538
539 539 QPieSeriesPrivate::~QPieSeriesPrivate()
540 540 {
541 541
542 542 }
543 543
544 544 void QPieSeriesPrivate::updateDerivativeData()
545 545 {
546 546 m_sum = 0;
547 547
548 548 // nothing to do?
549 549 if (m_slices.count() == 0)
550 550 return;
551 551
552 552 // calculate sum of all slices
553 553 foreach (QPieSlice* s, m_slices)
554 554 m_sum += s->value();
555 555
556 556 // nothing to show..
557 557 if (qFuzzyIsNull(m_sum))
558 558 return;
559 559
560 560 // update slice attributes
561 561 qreal sliceAngle = m_pieStartAngle;
562 562 qreal pieSpan = m_pieEndAngle - m_pieStartAngle;
563 563 QVector<QPieSlice*> changed;
564 564 foreach (QPieSlice* s, m_slices) {
565 565
566 566 PieSliceData data = PieSliceData::data(s);
567 567 data.m_percentage = s->value() / m_sum;
568 568 data.m_angleSpan = pieSpan * data.m_percentage;
569 569 data.m_startAngle = sliceAngle;
570 570 sliceAngle += data.m_angleSpan;
571 571
572 572 if (PieSliceData::data(s) != data) {
573 573 PieSliceData::data(s) = data;
574 574 changed << s;
575 575 }
576 576 }
577 577
578 578 // emit signals
579 579 foreach (QPieSlice* s, changed)
580 580 PieSliceData::data(s).emitChangedSignal(s);
581 581 }
582 582
583 583 void QPieSeriesPrivate::sliceChanged()
584 584 {
585 585 Q_ASSERT(m_slices.contains(qobject_cast<QPieSlice *>(sender())));
586 586 updateDerivativeData();
587 587 }
588 588
589 589 void QPieSeriesPrivate::sliceClicked(Qt::MouseButtons buttons)
590 590 {
591 591 QPieSlice* slice = qobject_cast<QPieSlice *>(sender());
592 592 Q_ASSERT(m_slices.contains(slice));
593 593 Q_Q(QPieSeries);
594 594 emit q->clicked(slice, buttons);
595 595 }
596 596
597 597 void QPieSeriesPrivate::sliceHoverEnter()
598 598 {
599 599 QPieSlice* slice = qobject_cast<QPieSlice *>(sender());
600 600 Q_ASSERT(m_slices.contains(slice));
601 601 Q_Q(QPieSeries);
602 602 emit q->hoverEnter(slice);
603 603 }
604 604
605 605 void QPieSeriesPrivate::sliceHoverLeave()
606 606 {
607 607 QPieSlice* slice = qobject_cast<QPieSlice *>(sender());
608 608 Q_ASSERT(m_slices.contains(slice));
609 609 Q_Q(QPieSeries);
610 610 emit q->hoverLeave(slice);
611 611 }
612 612
613 613 void QPieSeriesPrivate::modelUpdated(QModelIndex topLeft, QModelIndex bottomRight)
614 614 {
615 615 Q_UNUSED(bottomRight)
616 616
617 617 if (m_mapOrientation == Qt::Vertical)
618 618 {
619 619 if (topLeft.column() == m_mapValues)
620 620 if (m_mapValues == m_mapLabels)
621 621 {
622 622 m_slices.at(topLeft.row())->setValue(m_model->data(topLeft, Qt::DisplayRole).toDouble());
623 623 m_slices.at(topLeft.row())->setLabel(m_model->data(topLeft, Qt::DisplayRole).toString());
624 624 }
625 625 else
626 626 {
627 627 m_slices.at(topLeft.row())->setValue(m_model->data(topLeft, Qt::DisplayRole).toDouble());
628 628 }
629 629 else if (topLeft.column() == m_mapLabels)
630 630 m_slices.at(topLeft.row())->setLabel(m_model->data(topLeft, Qt::DisplayRole).toString());
631 631 }
632 632 else
633 633 {
634 634 if (topLeft.row() == m_mapValues)
635 635 if (m_mapValues == m_mapLabels)
636 636 {
637 637 m_slices.at(topLeft.column())->setValue(m_model->data(topLeft, Qt::DisplayRole).toDouble());
638 638 m_slices.at(topLeft.column())->setLabel(m_model->data(topLeft, Qt::DisplayRole).toString());
639 639 }
640 640 else
641 641 {
642 642 m_slices.at(topLeft.column())->setValue(m_model->data(topLeft, Qt::DisplayRole).toDouble());
643 643 }
644 644 else if (topLeft.row() == m_mapLabels)
645 645 m_slices.at(topLeft.column())->setLabel(m_model->data(topLeft, Qt::DisplayRole).toString());
646 646 }
647 647 }
648 648
649 649 void QPieSeriesPrivate::modelDataAdded(QModelIndex parent, int start, int end)
650 650 {
651 651 Q_UNUSED(parent)
652 652 Q_UNUSED(end)
653 653 Q_Q(QPieSeries);
654 654
655 655 QPieSlice* newSlice = new QPieSlice;
656 656 newSlice->setLabelVisible(true);
657 657 if (m_mapOrientation == Qt::Vertical)
658 658 {
659 659 newSlice->setValue(m_model->data(m_model->index(start, m_mapValues), Qt::DisplayRole).toDouble());
660 660 newSlice->setLabel(m_model->data(m_model->index(start, m_mapLabels), Qt::DisplayRole).toString());
661 661 }
662 662 else
663 663 {
664 664 newSlice->setValue(m_model->data(m_model->index(m_mapValues, start), Qt::DisplayRole).toDouble());
665 665 newSlice->setLabel(m_model->data(m_model->index(m_mapLabels, start), Qt::DisplayRole).toString());
666 666 }
667 667
668 668 q->insert(start, newSlice);
669 669 }
670 670
671 671 void QPieSeriesPrivate::modelDataRemoved(QModelIndex parent, int start, int end)
672 672 {
673 673 Q_UNUSED(parent)
674 674 Q_UNUSED(end)
675 675 Q_Q(QPieSeries);
676 676 q->remove(m_slices.at(start));
677 677 }
678 678
679 679 bool QPieSeriesPrivate::setRealValue(qreal &value, qreal newValue, qreal max, qreal min)
680 680 {
681 681 // Remove rounding errors
682 682 qreal roundedValue = newValue;
683 683 if (qFuzzyIsNull(min) && qFuzzyIsNull(newValue))
684 684 roundedValue = 0.0;
685 685 else if (qFuzzyCompare(newValue, max))
686 686 roundedValue = max;
687 687 else if (qFuzzyCompare(newValue, min))
688 688 roundedValue = min;
689 689
690 690 // Check if the position is valid after removing the rounding errors
691 691 if (roundedValue < min || roundedValue > max) {
692 692 qWarning("QPieSeries: Illegal value");
693 693 return false;
694 694 }
695 695
696 696 if (!qFuzzyIsNull(value - roundedValue)) {
697 697 value = roundedValue;
698 698 return true;
699 699 }
700 700
701 701 // The change was so small it is considered a rounding error
702 702 return false;
703 703 }
704 704
705 705 void QPieSeriesPrivate::scaleDomain(Domain& domain)
706 706 {
707 707 Q_UNUSED(domain);
708 708 #ifndef QT_NO_DEBUG
709 709 qWarning() << __FILE__<<__FUNCTION__<<"not implemented";
710 710 #endif
711 711 }
712 712
713 713 Chart* QPieSeriesPrivate::createGraphics(ChartPresenter* presenter)
714 714 {
715 715 Q_Q(QPieSeries);
716 716 PieChartItem* pie = new PieChartItem(q,presenter);
717 717 if(presenter->animationOptions().testFlag(QChart::SeriesAnimations)) {
718 718 presenter->animator()->addAnimation(pie);
719 719 }
720 720 presenter->chartTheme()->decorate(q, presenter->dataSet()->seriesIndex(q));
721 721 return pie;
722 722 }
723 723
724 724 QList<LegendMarker*> QPieSeriesPrivate::createLegendMarker(QLegend* legend)
725 725 {
726 726 Q_Q(QPieSeries);
727 727 QList<LegendMarker*> markers;
728 728 foreach(QPieSlice* slice, q->slices()) {
729 729 PieLegendMarker* marker = new PieLegendMarker(q,slice,legend);
730 730 markers << marker;
731 731 }
732 732 return markers;
733 733 }
734 734
735 735 #include "moc_qpieseries.cpp"
736 736 #include "moc_qpieseries_p.cpp"
737 737
738 738 QTCOMMERCIALCHART_END_NAMESPACE
@@ -1,101 +1,101
1 1 /****************************************************************************
2 2 **
3 3 ** Copyright (C) 2012 Digia Plc
4 4 ** All rights reserved.
5 5 ** For any questions to Digia, please use contact form at http://qt.digia.com
6 6 **
7 7 ** This file is part of the Qt Commercial Charts Add-on.
8 8 **
9 9 ** $QT_BEGIN_LICENSE$
10 10 ** Licensees holding valid Qt Commercial licenses may use this file in
11 11 ** accordance with the Qt Commercial License Agreement provided with the
12 12 ** Software or, alternatively, in accordance with the terms contained in
13 13 ** a written agreement between you and Digia.
14 14 **
15 15 ** If you have questions regarding the use of this file, please use
16 16 ** contact form at http://qt.digia.com
17 17 ** $QT_END_LICENSE$
18 18 **
19 19 ****************************************************************************/
20 20
21 21 #ifndef PIESERIES_H
22 22 #define PIESERIES_H
23 23
24 #include <qseries.h>
24 #include <qabstractseries.h>
25 25
26 26 QTCOMMERCIALCHART_BEGIN_NAMESPACE
27 27 class QPieSeriesPrivate;
28 28 class QPieSlice;
29 29
30 class QTCOMMERCIALCHART_EXPORT QPieSeries : public QSeries
30 class QTCOMMERCIALCHART_EXPORT QPieSeries : public QAbstractSeries
31 31 {
32 32 Q_OBJECT
33 33 Q_PROPERTY(qreal horizontalPosition READ horizontalPosition WRITE setHorizontalPosition)
34 34 Q_PROPERTY(qreal verticalPosition READ verticalPosition WRITE setVerticalPosition)
35 35 Q_PROPERTY(qreal size READ pieSize WRITE setPieSize)
36 36 Q_PROPERTY(qreal startAngle READ pieStartAngle WRITE setPieStartAngle)
37 37 Q_PROPERTY(qreal endAngle READ pieEndAngle WRITE setPieEndAngle)
38 38
39 39 public:
40 40 explicit QPieSeries(QObject *parent = 0);
41 41 virtual ~QPieSeries();
42 42
43 43 public: // from QChartSeries
44 44 QSeriesType type() const;
45 45
46 46 public:
47 47
48 48 // slice setters
49 49 void append(QPieSlice* slice);
50 50 void append(QList<QPieSlice*> slices);
51 51 void insert(int index, QPieSlice* slice);
52 52 void replace(QList<QPieSlice*> slices);
53 53 void remove(QPieSlice* slice);
54 54 void clear();
55 55
56 56 // slice getters
57 57 QList<QPieSlice*> slices() const;
58 58
59 59 // calculated data
60 60 int count() const;
61 61 bool isEmpty() const;
62 62 qreal sum() const;
63 63
64 64 // pie customization
65 65 void setHorizontalPosition(qreal relativePosition);
66 66 qreal horizontalPosition() const;
67 67 void setVerticalPosition(qreal relativePosition);
68 68 qreal verticalPosition() const;
69 69 void setPieSize(qreal relativeSize);
70 70 qreal pieSize() const;
71 71 void setPieStartAngle(qreal startAngle);
72 72 qreal pieStartAngle() const;
73 73 void setPieEndAngle(qreal endAngle);
74 74 qreal pieEndAngle() const;
75 75
76 76 // convenience function
77 77 QPieSeries& operator << (QPieSlice* slice);
78 78 QPieSlice* append(qreal value, QString name);
79 79 void setLabelsVisible(bool visible = true);
80 80
81 81 // data from model
82 82 bool setModel(QAbstractItemModel* model);
83 83 void setModelMapping(int modelValuesLine, int modelLabelsLine, Qt::Orientation orientation = Qt::Vertical);
84 84
85 85 Q_SIGNALS:
86 86 void clicked(QPieSlice* slice, Qt::MouseButtons buttons);
87 87 void hoverEnter(QPieSlice* slice);
88 88 void hoverLeave(QPieSlice* slice);
89 89 void added(QList<QPieSlice*> slices);
90 90 void removed(QList<QPieSlice*> slices);
91 91 void piePositionChanged();
92 92 void pieSizeChanged();
93 93
94 94 private:
95 95 Q_DECLARE_PRIVATE(QPieSeries)
96 96 Q_DISABLE_COPY(QPieSeries)
97 97 };
98 98
99 99 QTCOMMERCIALCHART_END_NAMESPACE
100 100
101 101 #endif // PIESERIES_H
@@ -1,74 +1,74
1 1 /****************************************************************************
2 2 **
3 3 ** Copyright (C) 2012 Digia Plc
4 4 ** All rights reserved.
5 5 ** For any questions to Digia, please use contact form at http://qt.digia.com
6 6 **
7 7 ** This file is part of the Qt Commercial Charts Add-on.
8 8 **
9 9 ** $QT_BEGIN_LICENSE$
10 10 ** Licensees holding valid Qt Commercial licenses may use this file in
11 11 ** accordance with the Qt Commercial License Agreement provided with the
12 12 ** Software or, alternatively, in accordance with the terms contained in
13 13 ** a written agreement between you and Digia.
14 14 **
15 15 ** If you have questions regarding the use of this file, please use
16 16 ** contact form at http://qt.digia.com
17 17 ** $QT_END_LICENSE$
18 18 **
19 19 ****************************************************************************/
20 20
21 21 #ifndef QPIESERIES_P_H
22 22 #define QPIESERIES_P_H
23 23
24 24 #include "qpieseries.h"
25 #include "qseries_p.h"
25 #include "qabstractseries_p.h"
26 26
27 27 class QModelIndex;
28 28
29 29 QTCOMMERCIALCHART_BEGIN_NAMESPACE
30 30
31 class QPieSeriesPrivate : public QSeriesPrivate
31 class QPieSeriesPrivate : public QAbstractSeriesPrivate
32 32 {
33 33 Q_OBJECT
34 34
35 35 public:
36 36 QPieSeriesPrivate(QPieSeries *parent);
37 37 ~QPieSeriesPrivate();
38 38
39 39 void scaleDomain(Domain& domain);
40 40 Chart* createGraphics(ChartPresenter* presenter);
41 41 QList<LegendMarker*> createLegendMarker(QLegend* legend);
42 42
43 43 void updateDerivativeData();
44 44
45 45 public Q_SLOTS:
46 46 void sliceChanged();
47 47 void sliceClicked(Qt::MouseButtons buttons);
48 48 void sliceHoverEnter();
49 49 void sliceHoverLeave();
50 50 void modelUpdated(QModelIndex topLeft, QModelIndex bottomRight);
51 51 void modelDataAdded(QModelIndex parent, int start, int end);
52 52 void modelDataRemoved(QModelIndex parent, int start, int end);
53 53 bool setRealValue(qreal &value, qreal newValue, qreal max, qreal min = 0.0);
54 54
55 55 public:
56 56 QList<QPieSlice*> m_slices;
57 57 qreal m_pieRelativeHorPos;
58 58 qreal m_pieRelativeVerPos;
59 59 qreal m_pieRelativeSize;
60 60 qreal m_pieStartAngle;
61 61 qreal m_pieEndAngle;
62 62 qreal m_sum;
63 63
64 64 // model map
65 65 int m_mapValues;
66 66 int m_mapLabels;
67 67 Qt::Orientation m_mapOrientation;
68 68 private:
69 69 Q_DECLARE_PUBLIC(QPieSeries)
70 70 };
71 71
72 72 QTCOMMERCIALCHART_END_NAMESPACE
73 73
74 74 #endif // QPIESERIES_P_H
@@ -1,133 +1,133
1 1 /****************************************************************************
2 2 **
3 3 ** Copyright (C) 2012 Digia Plc
4 4 ** All rights reserved.
5 5 ** For any questions to Digia, please use contact form at http://qt.digia.com
6 6 **
7 7 ** This file is part of the Qt Commercial Charts Add-on.
8 8 **
9 9 ** $QT_BEGIN_LICENSE$
10 10 ** Licensees holding valid Qt Commercial licenses may use this file in
11 11 ** accordance with the Qt Commercial License Agreement provided with the
12 12 ** Software or, alternatively, in accordance with the terms contained in
13 13 ** a written agreement between you and Digia.
14 14 **
15 15 ** If you have questions regarding the use of this file, please use
16 16 ** contact form at http://qt.digia.com
17 17 ** $QT_END_LICENSE$
18 18 **
19 19 ****************************************************************************/
20 20
21 #include "qseries.h"
22 #include "qseries_p.h"
21 #include "qabstractseries.h"
22 #include "qabstractseries_p.h"
23 23
24 24 QTCOMMERCIALCHART_BEGIN_NAMESPACE
25 25
26 26 /*!
27 \class QSeries
27 \class QAbstractSeries
28 28 \brief Base class for all QtCommercial Chart series.
29 29 \mainclass
30 30
31 31 Usually you use the series type specific inherited classes instead of the base class.
32 32 \sa QXYSeries, QLineSeries, QSplineSeries, QScatterSeries, QAreaSeries, QBarSeries, QStackedBarSeries,
33 33 QPercentBarSeries, QPieSeries
34 34 */
35 35
36 36 /*!
37 \enum QSeries::QSeriesType
37 \enum QAbstractSeries::QSeriesType
38 38
39 39 The type of the series object.
40 40
41 41 \value SeriesTypeLine
42 42 \value SeriesTypeArea
43 43 \value SeriesTypeBar
44 44 \value SeriesTypeStackedBar
45 45 \value SeriesTypePercentBar
46 46 \value SeriesTypePie
47 47 \value SeriesTypeScatter
48 48 \value SeriesTypeSpline
49 49 */
50 50
51 51 /*!
52 \fn QSeriesType QSeries::type() const
52 \fn QSeriesType QAbstractSeries::type() const
53 53 \brief The type of the series.
54 54 */
55 55
56 56 /*!
57 \fn bool QSeries::setModel(QAbstractItemModel *model)
57 \fn bool QAbstractSeries::setModel(QAbstractItemModel *model)
58 58 \brief Use the \a model to provide data for the series. The model overrides possible user data
59 59 set with QChartSeries type specific data setters. For example if you call both
60 60 QScatterSeries::addData() and QScatterSeries::setModel, only the data provided by the model is
61 61 used by the series. Returns true if the model is valid for the series.
62 62 */
63 63
64 64 /*!
65 \property QSeries::name
65 \property QAbstractSeries::name
66 66 \brief name of the series property
67 67 */
68 68
69 69 /*!
70 \fn void QSeries::setName(const QString& name)
70 \fn void QAbstractSeries::setName(const QString& name)
71 71 \brief Sets a \a name for the series.
72 72
73 73 The name of a series is shown in the legend for QXYSeries.
74 74 \sa QChart::setTitle()
75 75 \sa QPieSlice::setLabel()
76 76 \sa QBarSet::setName()
77 77 */
78 78
79 79 /*!
80 80 \internal
81 81 \brief Constructs ChartSeries object with \a parent.
82 82 */
83 QSeries::QSeries(QSeriesPrivate &d, QObject *parent) :
83 QAbstractSeries::QAbstractSeries(QAbstractSeriesPrivate &d, QObject *parent) :
84 84 QObject(parent),
85 85 d_ptr(&d)
86 86 {
87 87 }
88 88
89 89 /*!
90 90 \brief Virtual destructor for the chart series.
91 91 */
92 QSeries::~QSeries()
92 QAbstractSeries::~QAbstractSeries()
93 93 {
94 94 }
95 95
96 96 /*!
97 97 \brief Returns the pointer to the model that is used as the series data source
98 98 */
99 QAbstractItemModel* QSeries::model() const
99 QAbstractItemModel* QAbstractSeries::model() const
100 100 {
101 101 return d_ptr->m_model;
102 102 }
103 103
104 void QSeries::setName(const QString& name)
104 void QAbstractSeries::setName(const QString& name)
105 105 {
106 106 d_ptr->m_name = name;
107 107 }
108 108
109 109 /*!
110 110 \brief Returns the name of the series.
111 111 \sa setName()
112 112 */
113 QString QSeries::name() const
113 QString QAbstractSeries::name() const
114 114 {
115 115 return d_ptr->m_name;
116 116 }
117 117
118 118 ///////////////////////////////////////////////////////////////////////////////////////////////////
119 119
120 QSeriesPrivate::QSeriesPrivate(QSeries* q): q_ptr(q),m_model(0)
120 QAbstractSeriesPrivate::QAbstractSeriesPrivate(QAbstractSeries* q): q_ptr(q),m_model(0)
121 121 {
122 122 }
123 123
124 QSeriesPrivate::~QSeriesPrivate()
124 QAbstractSeriesPrivate::~QAbstractSeriesPrivate()
125 125 {
126 126 }
127 127
128 #include "moc_qseries.cpp"
129 #include "moc_qseries_p.cpp"
128 #include "moc_qabstractseries.cpp"
129 #include "moc_qabstractseries_p.cpp"
130 130
131 131 QTCOMMERCIALCHART_END_NAMESPACE
132 132
133 133
@@ -1,72 +1,72
1 1 /****************************************************************************
2 2 **
3 3 ** Copyright (C) 2012 Digia Plc
4 4 ** All rights reserved.
5 5 ** For any questions to Digia, please use contact form at http://qt.digia.com
6 6 **
7 7 ** This file is part of the Qt Commercial Charts Add-on.
8 8 **
9 9 ** $QT_BEGIN_LICENSE$
10 10 ** Licensees holding valid Qt Commercial licenses may use this file in
11 11 ** accordance with the Qt Commercial License Agreement provided with the
12 12 ** Software or, alternatively, in accordance with the terms contained in
13 13 ** a written agreement between you and Digia.
14 14 **
15 15 ** If you have questions regarding the use of this file, please use
16 16 ** contact form at http://qt.digia.com
17 17 ** $QT_END_LICENSE$
18 18 **
19 19 ****************************************************************************/
20 20
21 #ifndef QSERIES_H
22 #define QSERIES_H
21 #ifndef QABSTRACTSERIES_H
22 #define QABSTRACTSERIES_H
23 23
24 24 #include <qchartglobal.h>
25 25 #include <QObject>
26 26 #include <QPen>
27 27
28 28 class QAbstractItemModel;
29 29
30 30 QTCOMMERCIALCHART_BEGIN_NAMESPACE
31 31
32 class QSeriesPrivate;
32 class QAbstractSeriesPrivate;
33 33
34 class QTCOMMERCIALCHART_EXPORT QSeries : public QObject
34 class QTCOMMERCIALCHART_EXPORT QAbstractSeries : public QObject
35 35 {
36 36 Q_OBJECT
37 37 Q_PROPERTY(QString name READ name WRITE setName)
38 38 Q_ENUMS(QSeriesType)
39 39
40 40 public:
41 41 enum QSeriesType {
42 42 SeriesTypeLine,
43 43 SeriesTypeArea,
44 44 SeriesTypeBar,
45 45 SeriesTypeStackedBar,
46 46 SeriesTypePercentBar,
47 47 SeriesTypePie,
48 48 SeriesTypeScatter,
49 49 SeriesTypeSpline
50 50 };
51 51
52 52 protected:
53 QSeries(QSeriesPrivate &d, QObject *parent = 0);
53 QAbstractSeries(QAbstractSeriesPrivate &d, QObject *parent = 0);
54 54
55 55 public:
56 ~QSeries();
56 ~QAbstractSeries();
57 57 virtual QSeriesType type() const = 0;
58 58 virtual bool setModel(QAbstractItemModel* model) = 0;
59 59 QAbstractItemModel* model() const;
60 60 void setName(const QString& name);
61 61 QString name() const;
62 62
63 63 protected:
64 QScopedPointer<QSeriesPrivate> d_ptr;
64 QScopedPointer<QAbstractSeriesPrivate> d_ptr;
65 65 friend class ChartDataSet;
66 66 friend class ChartPresenter;
67 67 friend class QLegendPrivate;
68 68 };
69 69
70 70 QTCOMMERCIALCHART_END_NAMESPACE
71 71
72 72 #endif
@@ -1,66 +1,66
1 1 /****************************************************************************
2 2 **
3 3 ** Copyright (C) 2012 Digia Plc
4 4 ** All rights reserved.
5 5 ** For any questions to Digia, please use contact form at http://qt.digia.com
6 6 **
7 7 ** This file is part of the Qt Commercial Charts Add-on.
8 8 **
9 9 ** $QT_BEGIN_LICENSE$
10 10 ** Licensees holding valid Qt Commercial licenses may use this file in
11 11 ** accordance with the Qt Commercial License Agreement provided with the
12 12 ** Software or, alternatively, in accordance with the terms contained in
13 13 ** a written agreement between you and Digia.
14 14 **
15 15 ** If you have questions regarding the use of this file, please use
16 16 ** contact form at http://qt.digia.com
17 17 ** $QT_END_LICENSE$
18 18 **
19 19 ****************************************************************************/
20 20
21 21 // W A R N I N G
22 22 // -------------
23 23 //
24 24 // This file is not part of the QtCommercial Chart API. It exists purely as an
25 25 // implementation detail. This header file may change from version to
26 26 // version without notice, or even be removed.
27 27 //
28 28 // We mean it.
29 29
30 #ifndef QSERIES_P_H
31 #define QSERIES_P_H
30 #ifndef QABSTRACTSERIES_P_H
31 #define QABSTRACTSERIES_P_H
32 32
33 #include "qseries.h"
33 #include "qabstractseries.h"
34 34
35 35 class QAbstractItemModel;
36 36
37 37 QTCOMMERCIALCHART_BEGIN_NAMESPACE
38 38
39 39 class Domain;
40 40 class ChartPresenter;
41 41 class Chart;
42 42 class LegendMarker;
43 43 class QLegend;
44 44
45 class QSeriesPrivate : public QObject
45 class QAbstractSeriesPrivate : public QObject
46 46 {
47 47 Q_OBJECT
48 48 public:
49 QSeriesPrivate(QSeries *q);
50 ~QSeriesPrivate();
49 QAbstractSeriesPrivate(QAbstractSeries *q);
50 ~QAbstractSeriesPrivate();
51 51
52 52 virtual void scaleDomain(Domain& domain) = 0;
53 53 virtual Chart* createGraphics(ChartPresenter* presenter) = 0;
54 54 virtual QList<LegendMarker*> createLegendMarker(QLegend* legend) = 0;
55 55
56 56 protected:
57 QSeries *q_ptr;
57 QAbstractSeries *q_ptr;
58 58 QAbstractItemModel *m_model;
59 59 QString m_name;
60 60
61 friend class QSeries;
61 friend class QAbstractSeries;
62 62 };
63 63
64 64 QTCOMMERCIALCHART_END_NAMESPACE
65 65
66 66 #endif
@@ -1,412 +1,412
1 1 /****************************************************************************
2 2 **
3 3 ** Copyright (C) 2012 Digia Plc
4 4 ** All rights reserved.
5 5 ** For any questions to Digia, please use contact form at http://qt.digia.com
6 6 **
7 7 ** This file is part of the Qt Commercial Charts Add-on.
8 8 **
9 9 ** $QT_BEGIN_LICENSE$
10 10 ** Licensees holding valid Qt Commercial licenses may use this file in
11 11 ** accordance with the Qt Commercial License Agreement provided with the
12 12 ** Software or, alternatively, in accordance with the terms contained in
13 13 ** a written agreement between you and Digia.
14 14 **
15 15 ** If you have questions regarding the use of this file, please use
16 16 ** contact form at http://qt.digia.com
17 17 ** $QT_END_LICENSE$
18 18 **
19 19 ****************************************************************************/
20 20
21 21 #include "qchart.h"
22 22 #include "qchart_p.h"
23 23 #include "legendscroller_p.h"
24 24 #include "qlegend_p.h"
25 25 #include <QGraphicsScene>
26 26 #include <QGraphicsSceneResizeEvent>
27 27
28 28 QTCOMMERCIALCHART_BEGIN_NAMESPACE
29 29
30 30 /*!
31 31 \enum QChart::ChartTheme
32 32
33 33 This enum describes the theme used by the chart.
34 34
35 35 \value ChartThemeLight The default theme
36 36 \value ChartThemeBlueCerulean
37 37 \value ChartThemeDark
38 38 \value ChartThemeBrownSand
39 39 \value ChartThemeBlueNcs
40 40 \value ChartThemeHighContrast
41 41 \value ChartThemeBlueIcy
42 42 */
43 43
44 44 /*!
45 45 \enum QChart::AnimationOption
46 46
47 47 For enabling/disabling animations. Defaults to NoAnimation.
48 48
49 49 \value NoAnimation
50 50 \value GridAxisAnimations
51 51 \value SeriesAnimations
52 52 \value AllAnimations
53 53 */
54 54
55 55 /*!
56 56 \class QChart
57 57 \brief QtCommercial chart API.
58 58
59 59 QChart is a QGraphicsWidget that you can show in a QGraphicsScene. It manages the graphical
60 60 representation of different types of QChartSeries and other chart related objects like
61 61 QChartAxis and QChartLegend. If you simply want to show a chart in a layout, you can use the
62 62 convenience class QChartView instead of QChart.
63 63 \sa QChartView
64 64 */
65 65
66 66 /*!
67 67 Constructs a chart object which is a child of a\a parent. Parameter \a wFlags is passed to the QGraphicsWidget constructor.
68 68 */
69 69 QChart::QChart(QGraphicsItem *parent, Qt::WindowFlags wFlags) : QGraphicsWidget(parent,wFlags),
70 70 d_ptr(new QChartPrivate())
71 71 {
72 72 d_ptr->m_dataset = new ChartDataSet(this);
73 73 d_ptr->m_presenter = new ChartPresenter(this,d_ptr->m_dataset);
74 74 d_ptr->createConnections();
75 75 d_ptr->m_legend = new LegendScroller(this);
76 76 d_ptr->m_presenter->setTheme(QChart::ChartThemeLight, false);
77 77 }
78 78
79 79 /*!
80 80 Destroys the object and it's children, like QChartSeries and QChartAxis object added to it.
81 81 */
82 82 QChart::~QChart()
83 83 {
84 84 //delete first presenter , since this is a root of all the graphical items
85 85 delete d_ptr->m_presenter;
86 86 d_ptr->m_presenter=0;
87 87 }
88 88
89 89 /*!
90 90 Adds the \a series and optional \a axisY onto the chart and takes the ownership of the objects.
91 91 If auto scaling is enabled, re-scales the axes the series is bound to (both the x axis and
92 92 the y axis).
93 93 */
94 void QChart::addSeries(QSeries* series, QChartAxis* axisY)
94 void QChart::addSeries(QAbstractSeries *series, QChartAxis *axisY)
95 95 {
96 96 Q_ASSERT(series);
97 97 d_ptr->m_dataset->addSeries(series, axisY);
98 98 }
99 99
100 100 /*!
101 101 Removes the \a series specified in a perameter from the QChartView.
102 102 It releses its ownership of the specified QChartSeries object.
103 103 It does not delete the pointed QChartSeries data object
104 104 \sa addSeries(), removeAllSeries()
105 105 */
106 void QChart::removeSeries(QSeries* series)
106 void QChart::removeSeries(QAbstractSeries *series)
107 107 {
108 108 Q_ASSERT(series);
109 109 d_ptr->m_dataset->removeSeries(series);
110 110 }
111 111
112 112 /*!
113 113 Removes all the QChartSeries that have been added to the QChartView
114 114 It also deletes the pointed QChartSeries data objects
115 115 \sa addSeries(), removeSeries()
116 116 */
117 117 void QChart::removeAllSeries()
118 118 {
119 119 d_ptr->m_dataset->removeAllSeries();
120 120 }
121 121
122 122 /*!
123 123 Sets the \a brush that is used for painting the background of the chart area.
124 124 */
125 125 void QChart::setBackgroundBrush(const QBrush& brush)
126 126 {
127 127 //TODO: refactor me
128 128 d_ptr->m_presenter->createChartBackgroundItem();
129 129 d_ptr->m_presenter->m_backgroundItem->setBrush(brush);
130 130 d_ptr->m_presenter->m_backgroundItem->update();
131 131 }
132 132
133 133 /*!
134 134 Gets the brush that is used for painting the background of the chart area.
135 135 */
136 136 QBrush QChart::backgroundBrush() const
137 137 {
138 138 //TODO: refactor me
139 139 if (!d_ptr->m_presenter->m_backgroundItem) return QBrush();
140 140 return (d_ptr->m_presenter->m_backgroundItem)->brush();
141 141 }
142 142
143 143 /*!
144 144 Sets the \a pen that is used for painting the background of the chart area.
145 145 */
146 146 void QChart::setBackgroundPen(const QPen& pen)
147 147 {
148 148 //TODO: refactor me
149 149 d_ptr->m_presenter->createChartBackgroundItem();
150 150 d_ptr->m_presenter->m_backgroundItem->setPen(pen);
151 151 d_ptr->m_presenter->m_backgroundItem->update();
152 152 }
153 153
154 154 /*!
155 155 Gets the pen that is used for painting the background of the chart area.
156 156 */
157 157 QPen QChart::backgroundPen() const
158 158 {
159 159 //TODO: refactor me
160 160 if (!d_ptr->m_presenter->m_backgroundItem) return QPen();
161 161 return d_ptr->m_presenter->m_backgroundItem->pen();
162 162 }
163 163
164 164 /*!
165 165 Sets the chart \a title. The description text that is drawn above the chart.
166 166 */
167 167 void QChart::setTitle(const QString& title)
168 168 {
169 169 //TODO: refactor me
170 170 d_ptr->m_presenter->createChartTitleItem();
171 171 d_ptr->m_presenter->m_titleItem->setText(title);
172 172 d_ptr->m_presenter->updateLayout();
173 173 }
174 174
175 175 /*!
176 176 Returns the chart title. The description text that is drawn above the chart.
177 177 */
178 178 QString QChart::title() const
179 179 {
180 180 //TODO: refactor me
181 181 if (d_ptr->m_presenter->m_titleItem)
182 182 return d_ptr->m_presenter->m_titleItem->text();
183 183 else
184 184 return QString();
185 185 }
186 186
187 187 /*!
188 188 Sets the \a font that is used for drawing the chart description text that is rendered above the chart.
189 189 */
190 190 void QChart::setTitleFont(const QFont& font)
191 191 {
192 192 //TODO: refactor me
193 193 d_ptr->m_presenter->createChartTitleItem();
194 194 d_ptr->m_presenter->m_titleItem->setFont(font);
195 195 d_ptr->m_presenter->updateLayout();
196 196 }
197 197
198 198 /*!
199 199 Gets the font that is used for drawing the chart description text that is rendered above the chart.
200 200 */
201 201 QFont QChart::titleFont() const
202 202 {
203 203 if (d_ptr->m_presenter->m_titleItem)
204 204 return d_ptr->m_presenter->m_titleItem->font();
205 205 else
206 206 return QFont();
207 207 }
208 208
209 209 /*!
210 210 Sets the \a brush used for rendering the title text.
211 211 */
212 212 void QChart::setTitleBrush(const QBrush &brush)
213 213 {
214 214 //TODO: refactor me
215 215 d_ptr->m_presenter->createChartTitleItem();
216 216 d_ptr->m_presenter->m_titleItem->setBrush(brush);
217 217 d_ptr->m_presenter->updateLayout();
218 218 }
219 219
220 220 /*!
221 221 Returns the brush used for rendering the title text.
222 222 */
223 223 QBrush QChart::titleBrush() const
224 224 {
225 225 //TODO: refactor me
226 226 if (!d_ptr->m_presenter->m_titleItem) return QBrush();
227 227 return d_ptr->m_presenter->m_titleItem->brush();
228 228 }
229 229
230 230 /*!
231 231 Sets the \a theme used by the chart for rendering the graphical representation of the data
232 232 \sa theme()
233 233 */
234 234 void QChart::setTheme(QChart::ChartTheme theme)
235 235 {
236 236 d_ptr->m_presenter->setTheme(theme);
237 237 }
238 238
239 239 /*!
240 240 Returns the theme enum used by the chart.
241 241 \sa ChartTheme, setTheme()
242 242 */
243 243 QChart::ChartTheme QChart::theme() const
244 244 {
245 245 return d_ptr->m_presenter->theme();
246 246 }
247 247
248 248 /*!
249 249 Zooms in the view by a factor of 2
250 250 */
251 251 void QChart::zoomIn()
252 252 {
253 253 d_ptr->m_presenter->zoomIn();
254 254 }
255 255
256 256 /*!
257 257 Zooms in the view to a maximum level at which \a rect is still fully visible.
258 258 */
259 259 void QChart::zoomIn(const QRectF& rect)
260 260 {
261 261 if (!rect.isValid()) return;
262 262 d_ptr->m_presenter->zoomIn(rect);
263 263 }
264 264
265 265 /*!
266 266 Restores the view zoom level to the previous one.
267 267 */
268 268 void QChart::zoomOut()
269 269 {
270 270 d_ptr->m_presenter->zoomOut();
271 271 }
272 272
273 273 /*!
274 274 Returns the pointer to the x axis object of the chart
275 275 */
276 276 QChartAxis* QChart::axisX() const
277 277 {
278 278 return d_ptr->m_dataset->axisX();
279 279 }
280 280
281 281 /*!
282 282 Returns the pointer to the y axis object of the \a series
283 283 If no \a series is provided then default Y axis of the chart is returned.
284 284 */
285 QChartAxis* QChart::axisY(QSeries* series) const
285 QChartAxis* QChart::axisY(QAbstractSeries *series) const
286 286 {
287 287 return d_ptr->m_dataset->axisY(series);
288 288 }
289 289
290 290 /*!
291 291 Returns the legend object of the chart. Ownership stays in chart.
292 292 */
293 293 QLegend* QChart::legend() const
294 294 {
295 295 return d_ptr->m_legend;
296 296 }
297 297
298 298 /*!
299 299 Returns the rect that contains information about margins (distance between chart widget edge and axes).
300 300 Individual margins can be obtained by calling left, top, right, bottom on the returned rect.
301 301 */
302 302 QRectF QChart::margins() const
303 303 {
304 304 return d_ptr->m_presenter->margins();
305 305 }
306 306
307 307
308 308 /*!
309 309 Resizes and updates the chart area using the \a event data
310 310 */
311 311 void QChart::resizeEvent(QGraphicsSceneResizeEvent *event)
312 312 {
313 313 d_ptr->m_rect = QRectF(QPoint(0,0),event->newSize());
314 314 QGraphicsWidget::resizeEvent(event);
315 315 d_ptr->m_presenter->setGeometry(d_ptr->m_rect);
316 316 }
317 317
318 318 /*!
319 319 Sets animation \a options for the chart
320 320 */
321 321 void QChart::setAnimationOptions(AnimationOptions options)
322 322 {
323 323 d_ptr->m_presenter->setAnimationOptions(options);
324 324 }
325 325
326 326 /*!
327 327 Returns animation options for the chart
328 328 */
329 329 QChart::AnimationOptions QChart::animationOptions() const
330 330 {
331 331 return d_ptr->m_presenter->animationOptions();
332 332 }
333 333
334 334 /*!
335 335 Scrolls the visible area of the chart to the left by the distance between two x axis ticks
336 336 */
337 337 void QChart::scrollLeft()
338 338 {
339 339 d_ptr->m_presenter->scroll(-d_ptr->m_presenter->chartGeometry().width()/(axisX()->ticksCount()-1),0);
340 340 }
341 341
342 342 /*!
343 343 Scrolls the visible area of the chart to the right by the distance between two x axis ticks
344 344 */
345 345 void QChart::scrollRight()
346 346 {
347 347 d_ptr->m_presenter->scroll(d_ptr->m_presenter->chartGeometry().width()/(axisX()->ticksCount()-1),0);
348 348 }
349 349
350 350 /*!
351 351 Scrolls the visible area of the chart up by the distance between two y axis ticks
352 352 */
353 353 void QChart::scrollUp()
354 354 {
355 355 d_ptr->m_presenter->scroll(0,d_ptr->m_presenter->chartGeometry().width()/(axisY()->ticksCount()-1));
356 356 }
357 357
358 358 /*!
359 359 Scrolls the visible area of the chart down by the distance between two y axis ticks
360 360 */
361 361 void QChart::scrollDown()
362 362 {
363 363 d_ptr->m_presenter->scroll(0,-d_ptr->m_presenter->chartGeometry().width()/(axisY()->ticksCount()-1));
364 364 }
365 365
366 366 /*!
367 367 Sets the chart background visibility state to \a visible
368 368 */
369 369 void QChart::setBackgroundVisible(bool visible)
370 370 {
371 371 //TODO: refactor me
372 372 d_ptr->m_presenter->createChartBackgroundItem();
373 373 d_ptr->m_presenter->m_backgroundItem->setVisible(visible);
374 374 }
375 375
376 376 /*!
377 377 Returns the chart's background visibility state
378 378 */
379 379 bool QChart::isBackgroundVisible() const
380 380 {
381 381 //TODO: refactor me
382 382 if (!d_ptr->m_presenter->m_backgroundItem) return false;
383 383 return d_ptr->m_presenter->m_backgroundItem->isVisible();
384 384 }
385 385
386 386 //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
387 387
388 388 QChartPrivate::QChartPrivate():
389 389 m_legend(0),
390 390 m_dataset(0),
391 391 m_presenter(0)
392 392 {
393 393
394 394 }
395 395
396 396 QChartPrivate::~QChartPrivate()
397 397 {
398 398
399 399 }
400 400
401 401 void QChartPrivate::createConnections()
402 402 {
403 403
404 QObject::connect(m_dataset,SIGNAL(seriesAdded(QSeries*,Domain*)),m_presenter,SLOT(handleSeriesAdded(QSeries*,Domain*)));
405 QObject::connect(m_dataset,SIGNAL(seriesRemoved(QSeries*)),m_presenter,SLOT(handleSeriesRemoved(QSeries*)));
404 QObject::connect(m_dataset,SIGNAL(seriesAdded(QAbstractSeries *, Domain *)),m_presenter,SLOT(handleSeriesAdded(QAbstractSeries *, Domain *)));
405 QObject::connect(m_dataset,SIGNAL(seriesRemoved(QAbstractSeries *)),m_presenter,SLOT(handleSeriesRemoved(QAbstractSeries *)));
406 406 QObject::connect(m_dataset,SIGNAL(axisAdded(QChartAxis*,Domain*)),m_presenter,SLOT(handleAxisAdded(QChartAxis*,Domain*)));
407 407 QObject::connect(m_dataset,SIGNAL(axisRemoved(QChartAxis*)),m_presenter,SLOT(handleAxisRemoved(QChartAxis*)));
408 408 }
409 409
410 410 #include "moc_qchart.cpp"
411 411
412 412 QTCOMMERCIALCHART_END_NAMESPACE
@@ -1,119 +1,119
1 1 /****************************************************************************
2 2 **
3 3 ** Copyright (C) 2012 Digia Plc
4 4 ** All rights reserved.
5 5 ** For any questions to Digia, please use contact form at http://qt.digia.com
6 6 **
7 7 ** This file is part of the Qt Commercial Charts Add-on.
8 8 **
9 9 ** $QT_BEGIN_LICENSE$
10 10 ** Licensees holding valid Qt Commercial licenses may use this file in
11 11 ** accordance with the Qt Commercial License Agreement provided with the
12 12 ** Software or, alternatively, in accordance with the terms contained in
13 13 ** a written agreement between you and Digia.
14 14 **
15 15 ** If you have questions regarding the use of this file, please use
16 16 ** contact form at http://qt.digia.com
17 17 ** $QT_END_LICENSE$
18 18 **
19 19 ****************************************************************************/
20 20
21 21 #ifndef QCHART_H
22 22 #define QCHART_H
23 23
24 #include <QSeries>
24 #include <QAbstractSeries>
25 25 #include <QLegend>
26 26 #include <QGraphicsWidget>
27 27
28 28 class QGraphicsSceneResizeEvent;
29 29
30 30 QTCOMMERCIALCHART_BEGIN_NAMESPACE
31 31
32 class QSeries;
32 class QAbstractSeries;
33 33 class QChartAxis;
34 34 class QLegend;
35 35 struct QChartPrivate;
36 36
37 37 class QTCOMMERCIALCHART_EXPORT QChart : public QGraphicsWidget
38 38 {
39 39 Q_OBJECT
40 40 Q_ENUMS(ChartTheme)
41 41
42 42 public:
43 43 enum ChartTheme {
44 44 ChartThemeLight = 0,
45 45 ChartThemeBlueCerulean,
46 46 ChartThemeDark,
47 47 ChartThemeBrownSand,
48 48 ChartThemeBlueNcs,
49 49 ChartThemeHighContrast,
50 50 ChartThemeBlueIcy
51 51 };
52 52
53 53 enum AnimationOption {
54 54 NoAnimation = 0x0,
55 55 GridAxisAnimations = 0x1,
56 56 SeriesAnimations =0x2,
57 57 AllAnimations = 0x3
58 58 };
59 59
60 60 Q_DECLARE_FLAGS(AnimationOptions, AnimationOption)
61 61
62 62 public:
63 63 explicit QChart(QGraphicsItem *parent = 0, Qt::WindowFlags wFlags = 0);
64 64 ~QChart();
65 65
66 void addSeries(QSeries *series, QChartAxis *axisY = 0);
67 void removeSeries(QSeries *series);
66 void addSeries(QAbstractSeries *series, QChartAxis *axisY = 0);
67 void removeSeries(QAbstractSeries *series);
68 68 void removeAllSeries();
69 69
70 70 void setTheme(QChart::ChartTheme theme);
71 71 QChart::ChartTheme theme() const;
72 72
73 73 void setTitle(const QString& title);
74 74 QString title() const;
75 75 void setTitleFont(const QFont& font);
76 76 QFont titleFont() const;
77 77 void setTitleBrush(const QBrush &brush);
78 78 QBrush titleBrush() const;
79 79
80 80 void setBackgroundBrush(const QBrush &brush);
81 81 QBrush backgroundBrush() const;
82 82 void setBackgroundPen(const QPen &pen);
83 83 QPen backgroundPen() const;
84 84
85 85 void setBackgroundVisible(bool visible = true);
86 86 bool isBackgroundVisible() const;
87 87
88 88 void setAnimationOptions(AnimationOptions options);
89 89 AnimationOptions animationOptions() const;
90 90
91 91 void zoomIn();
92 92 void zoomIn(const QRectF &rect);
93 93 void zoomOut();
94 94 void scrollLeft();
95 95 void scrollRight();
96 96 void scrollUp();
97 97 void scrollDown();
98 98
99 99 QChartAxis* axisX() const;
100 QChartAxis* axisY(QSeries* series = 0) const;
100 QChartAxis* axisY(QAbstractSeries* series = 0) const;
101 101
102 102 QLegend* legend() const;
103 103 QRectF margins() const;
104 104
105 105 protected:
106 106 void resizeEvent(QGraphicsSceneResizeEvent *event);
107 107
108 108 protected:
109 109 QScopedPointer<QChartPrivate> d_ptr;
110 110 friend class QLegend;
111 111 friend class ChartPresenter;
112 112 Q_DISABLE_COPY(QChart)
113 113 };
114 114
115 115 QTCOMMERCIALCHART_END_NAMESPACE
116 116
117 117 Q_DECLARE_OPERATORS_FOR_FLAGS(QTCOMMERCIALCHART_NAMESPACE::QChart::AnimationOptions)
118 118
119 119 #endif
@@ -1,71 +1,71
1 1 /****************************************************************************
2 2 **
3 3 ** Copyright (C) 2012 Digia Plc
4 4 ** All rights reserved.
5 5 ** For any questions to Digia, please use contact form at http://qt.digia.com
6 6 **
7 7 ** This file is part of the Qt Commercial Charts Add-on.
8 8 **
9 9 ** $QT_BEGIN_LICENSE$
10 10 ** Licensees holding valid Qt Commercial licenses may use this file in
11 11 ** accordance with the Qt Commercial License Agreement provided with the
12 12 ** Software or, alternatively, in accordance with the terms contained in
13 13 ** a written agreement between you and Digia.
14 14 **
15 15 ** If you have questions regarding the use of this file, please use
16 16 ** contact form at http://qt.digia.com
17 17 ** $QT_END_LICENSE$
18 18 **
19 19 ****************************************************************************/
20 20
21 21 #ifndef QCHARTVIEW_H
22 22 #define QCHARTVIEW_H
23 23
24 24 #include <QChartAxis>
25 #include <QSeries>
25 #include <QAbstractSeries>
26 26 #include <QChart>
27 27 #include <QGraphicsView>
28 28
29 29 class QGraphicsScene;
30 30 class QRubberBand;
31 31
32 32 QTCOMMERCIALCHART_BEGIN_NAMESPACE
33 33
34 34 struct QChartViewPrivate;
35 35
36 36 class QTCOMMERCIALCHART_EXPORT QChartView : public QGraphicsView
37 37 {
38 38 Q_OBJECT
39 39
40 40 public:
41 41
42 42 enum RubberBand{
43 43 NoRubberBand = 0x0,
44 44 VerticalRubberBand = 0x1,
45 45 HorizonalRubberBand = 0x2,
46 46 RectangleRubberBand = 0x3
47 47 };
48 48
49 49 Q_DECLARE_FLAGS(RubberBands, RubberBand)
50 50
51 51 explicit QChartView(QChart *chart,QWidget *parent = 0);
52 52 ~QChartView();
53 53
54 54 void setRubberBand(const RubberBands& rubberBands);
55 55 RubberBands rubberBand() const;
56 56 QChart* chart() const;
57 57
58 58 protected:
59 59 void resizeEvent(QResizeEvent *event);
60 60 void mousePressEvent(QMouseEvent *event);
61 61 void mouseMoveEvent(QMouseEvent *event);
62 62 void mouseReleaseEvent(QMouseEvent *event);
63 63
64 64 protected:
65 65 QScopedPointer<QChartViewPrivate> d_ptr;
66 66 Q_DISABLE_COPY(QChartView)
67 67 };
68 68
69 69 QTCOMMERCIALCHART_END_NAMESPACE
70 70
71 71 #endif // QCHARTWIDGET_H
@@ -1,150 +1,150
1 1 /****************************************************************************
2 2 **
3 3 ** Copyright (C) 2012 Digia Plc
4 4 ** All rights reserved.
5 5 ** For any questions to Digia, please use contact form at http://qt.digia.com
6 6 **
7 7 ** This file is part of the Qt Commercial Charts Add-on.
8 8 **
9 9 ** $QT_BEGIN_LICENSE$
10 10 ** Licensees holding valid Qt Commercial licenses may use this file in
11 11 ** accordance with the Qt Commercial License Agreement provided with the
12 12 ** Software or, alternatively, in accordance with the terms contained in
13 13 ** a written agreement between you and Digia.
14 14 **
15 15 ** If you have questions regarding the use of this file, please use
16 16 ** contact form at http://qt.digia.com
17 17 ** $QT_END_LICENSE$
18 18 **
19 19 ****************************************************************************/
20 20
21 21 #include "qscatterseries.h"
22 22 #include "qscatterseries_p.h"
23 23 #include "scatterchartitem_p.h"
24 24 #include "chartdataset_p.h"
25 25 #include "charttheme_p.h"
26 26 #include "chartanimator_p.h"
27 27
28 28 /*!
29 29 \class QScatterSeries
30 30 \brief The QScatterSeries class is used for making scatter charts.
31 31
32 32 \mainclass
33 33
34 34 The scatter data is displayed as a collection of points on the chart. Each point determines the position on the horizontal axis
35 35 and the vertical axis.
36 36
37 37 \image scatterchart.png
38 38
39 39 Creating basic scatter chart is simple:
40 40 \code
41 41 QScatterSeries* series = new QScatterSeries();
42 42 series->append(0, 6);
43 43 series->append(2, 4);
44 44 ...
45 45 chartView->addSeries(series);
46 46 \endcode
47 47 */
48 48
49 49 /*!
50 50 \enum QScatterSeries::MarkerShape
51 51
52 52 This enum describes the shape used when rendering marker items.
53 53
54 54 \value MarkerShapeCircle
55 55 \value MarkerShapeRectangle
56 56 */
57 57
58 58 /*!
59 59 \fn QChartSeriesType QScatterSeries::type() const
60 60 \brief Returns QChartSeries::SeriesTypeScatter.
61 \sa QSeries, QSeriesType
61 \sa QAbstractSeries, QSeriesType
62 62 */
63 63
64 64 QTCOMMERCIALCHART_BEGIN_NAMESPACE
65 65
66 66 /*!
67 67 Constructs a series object which is a child of \a parent.
68 68 */
69 69 QScatterSeries::QScatterSeries(QObject *parent) : QXYSeries(*new QScatterSeriesPrivate(this),parent)
70 70 {
71 71 }
72 72
73 73 /*!
74 74 Destroys the object. Note that adding series to QChart transfers the ownership to the chart.
75 75 */
76 76 QScatterSeries::~QScatterSeries()
77 77 {
78 78 }
79 79
80 QSeries::QSeriesType QScatterSeries::type() const
80 QAbstractSeries::QSeriesType QScatterSeries::type() const
81 81 {
82 return QSeries::SeriesTypeScatter;
82 return QAbstractSeries::SeriesTypeScatter;
83 83 }
84 84
85 85 /*!
86 86 Returns the shape used for drawing markers.
87 87 */
88 88 QScatterSeries::MarkerShape QScatterSeries::shape() const
89 89 {
90 90 Q_D(const QScatterSeries);
91 91 return d->m_shape;
92 92 }
93 93
94 94 /*!
95 95 Overrides the default shape of the marker items with a user defined \a shape. The default shape
96 96 is defined by chart theme setting.
97 97 */
98 98 void QScatterSeries::setShape(MarkerShape shape)
99 99 {
100 100 Q_D(QScatterSeries);
101 101 if (d->m_shape != shape) {
102 102 d->m_shape = shape;
103 103 emit d->updated();
104 104 }
105 105 }
106 106
107 107 /*!
108 108 Returns the size of the marker items.
109 109 */
110 110 qreal QScatterSeries::size() const
111 111 {
112 112 Q_D(const QScatterSeries);
113 113 return d->m_size;
114 114 }
115 115
116 116 /*!
117 117 Set the \a size of the marker items. The default size is 15.
118 118 */
119 119 void QScatterSeries::setSize(qreal size)
120 120 {
121 121 Q_D(QScatterSeries);
122 122
123 123 if (!qFuzzyIsNull(d->m_size - size)) {
124 124 d->m_size = size;
125 125 emit d->updated();
126 126 }
127 127 }
128 128
129 129 ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
130 130
131 131 QScatterSeriesPrivate::QScatterSeriesPrivate(QScatterSeries* q):QXYSeriesPrivate(q),
132 132 m_shape(QScatterSeries::MarkerShapeCircle),
133 133 m_size(15.0)
134 134 {
135 135
136 136 };
137 137
138 138 Chart* QScatterSeriesPrivate::createGraphics(ChartPresenter* presenter)
139 139 {
140 140 Q_Q(QScatterSeries);
141 141 ScatterChartItem *scatter = new ScatterChartItem(q,presenter);
142 142 if(presenter->animationOptions().testFlag(QChart::SeriesAnimations)) {
143 143 presenter->animator()->addAnimation(scatter);
144 144 }
145 145 presenter->chartTheme()->decorate(q, presenter->dataSet()->seriesIndex(q));
146 146 return scatter;
147 147 }
148 148
149 149
150 150 QTCOMMERCIALCHART_END_NAMESPACE
@@ -1,60 +1,60
1 1 /****************************************************************************
2 2 **
3 3 ** Copyright (C) 2012 Digia Plc
4 4 ** All rights reserved.
5 5 ** For any questions to Digia, please use contact form at http://qt.digia.com
6 6 **
7 7 ** This file is part of the Qt Commercial Charts Add-on.
8 8 **
9 9 ** $QT_BEGIN_LICENSE$
10 10 ** Licensees holding valid Qt Commercial licenses may use this file in
11 11 ** accordance with the Qt Commercial License Agreement provided with the
12 12 ** Software or, alternatively, in accordance with the terms contained in
13 13 ** a written agreement between you and Digia.
14 14 **
15 15 ** If you have questions regarding the use of this file, please use
16 16 ** contact form at http://qt.digia.com
17 17 ** $QT_END_LICENSE$
18 18 **
19 19 ****************************************************************************/
20 20
21 21 #ifndef QSCATTERSERIES_H
22 22 #define QSCATTERSERIES_H
23 23
24 24 #include <qchartglobal.h>
25 25 #include <qxyseries.h>
26 26
27 27 QTCOMMERCIALCHART_BEGIN_NAMESPACE
28 28
29 29 class QScatterSeriesPrivate;
30 30
31 31 class QTCOMMERCIALCHART_EXPORT QScatterSeries : public QXYSeries
32 32 {
33 33
34 34 public:
35 35 enum MarkerShape {
36 36 MarkerShapeCircle,
37 37 MarkerShapeRectangle
38 38 };
39 39
40 40 public:
41 41 explicit QScatterSeries(QObject *parent = 0);
42 42 ~QScatterSeries();
43 43
44 QSeries::QSeriesType type() const;
44 QAbstractSeries::QSeriesType type() const;
45 45
46 46 MarkerShape shape() const;
47 47 void setShape(MarkerShape shape);
48 48 qreal size() const;
49 49 void setSize(qreal size);
50 50
51 51 private:
52 52 Q_DECLARE_PRIVATE(QScatterSeries);
53 53 Q_DISABLE_COPY(QScatterSeries);
54 54 friend class ScatterChartItem;
55 55
56 56 };
57 57
58 58 QTCOMMERCIALCHART_END_NAMESPACE
59 59
60 60 #endif // QSCATTERSERIES_H
@@ -1,236 +1,236
1 1 /****************************************************************************
2 2 **
3 3 ** Copyright (C) 2012 Digia Plc
4 4 ** All rights reserved.
5 5 ** For any questions to Digia, please use contact form at http://qt.digia.com
6 6 **
7 7 ** This file is part of the Qt Commercial Charts Add-on.
8 8 **
9 9 ** $QT_BEGIN_LICENSE$
10 10 ** Licensees holding valid Qt Commercial licenses may use this file in
11 11 ** accordance with the Qt Commercial License Agreement provided with the
12 12 ** Software or, alternatively, in accordance with the terms contained in
13 13 ** a written agreement between you and Digia.
14 14 **
15 15 ** If you have questions regarding the use of this file, please use
16 16 ** contact form at http://qt.digia.com
17 17 ** $QT_END_LICENSE$
18 18 **
19 19 ****************************************************************************/
20 20
21 21 #include "qsplineseries.h"
22 22 #include "qsplineseries_p.h"
23 23 #include "splinechartitem_p.h"
24 24 #include "chartdataset_p.h"
25 25 #include "charttheme_p.h"
26 26 #include "chartanimator_p.h"
27 27
28 28 /*!
29 29 \class QSplineSeries
30 30 \brief Series type used to store data needed to draw a spline.
31 31
32 32 QSplineSeries stores the data points along with the segment control points needed by QPainterPath to draw spline
33 33 Control points are automatically calculated when data changes. The algorithm computes the points so that the normal spline can be drawn.
34 34 */
35 35
36 36 /*!
37 37 \fn QSeriesType QSplineSeries::type() const
38 38 Returns the type of the series
39 39 */
40 40
41 41 /*!
42 42 \fn QSeriesType QSplineSeries::controlPoint(int index) const
43 43 Returns the control point specified by \a index
44 44 */
45 45
46 46 QTCOMMERCIALCHART_BEGIN_NAMESPACE
47 47
48 48 /*!
49 49 Constructs empty series object which is a child of \a parent.
50 50 When series object is added to QChartView or QChart instance then the ownerships is transferred.
51 51 */
52 52
53 53 QSplineSeries::QSplineSeries(QObject *parent) :
54 54 QLineSeries(*new QSplineSeriesPrivate(this),parent)
55 55 {
56 56 }
57 57
58 QSeries::QSeriesType QSplineSeries::type() const
58 QAbstractSeries::QSeriesType QSplineSeries::type() const
59 59 {
60 return QSeries::SeriesTypeSpline;
60 return QAbstractSeries::SeriesTypeSpline;
61 61 }
62 62
63 63 QPointF QSplineSeries::controlPoint(int index) const
64 64 {
65 65 Q_D(const QSplineSeries);
66 66 return d->m_controlPoints[index];
67 67 }
68 68
69 69 void QSplineSeries::setModelMappingRange(int first, int count)
70 70 {
71 71 Q_D(QSplineSeries);
72 72 QLineSeries::setModelMappingRange(first, count);
73 73 d->calculateControlPoints();
74 74 }
75 75
76 76 ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
77 77
78 78 QSplineSeriesPrivate::QSplineSeriesPrivate(QSplineSeries* q):QLineSeriesPrivate(q)
79 79 {
80 80 QObject::connect(this,SIGNAL(pointAdded(int)), this, SLOT(updateControlPoints()));
81 81 QObject::connect(this,SIGNAL(pointRemoved(int)), this, SLOT(updateControlPoints()));
82 82 QObject::connect(this,SIGNAL(pointReplaced(int)), this, SLOT(updateControlPoints()));
83 83 };
84 84
85 85 /*!
86 86 \internal
87 87 Calculates control points which are needed by QPainterPath.cubicTo function to draw the cubic Bezier cureve between two points.
88 88 */
89 89 void QSplineSeriesPrivate::calculateControlPoints()
90 90 {
91 91
92 92 Q_Q(QSplineSeries);
93 93 // Based on http://www.codeproject.com/Articles/31859/Draw-a-Smooth-Curve-through-a-Set-of-2D-Points-wit
94 94 // CPOL License
95 95
96 96 int n = q->count() - 1;
97 97 if (n == 1)
98 98 { // Special case: Bezier curve should be a straight line.
99 99 // firstControlPoints = new Point[1];
100 100 // 3P1 = 2P0 + P3
101 101 m_controlPoints.append(QPointF((2 * q->x(0) + q->x(1)) / 3, (2 * q->y(0) + q->y(1)) / 3));
102 102
103 103 // P2 = 2P1 P0
104 104 m_controlPoints.append(QPointF(2 * m_controlPoints[0].x() - q->x(0), 2 * m_controlPoints[0].y() - q->y(0)));
105 105 return;
106 106 }
107 107
108 108 // Calculate first Bezier control points
109 109 // Right hand side vector
110 110 // Set of equations for P0 to Pn points.
111 111 //
112 112 // | 2 1 0 0 ... 0 0 0 ... 0 0 0 | | P1_1 | | P0 + 2 * P1 |
113 113 // | 1 4 1 0 ... 0 0 0 ... 0 0 0 | | P1_2 | | 4 * P1 + 2 * P2 |
114 114 // | 0 1 4 1 ... 0 0 0 ... 0 0 0 | | P1_3 | | 4 * P2 + 2 * P3 |
115 115 // | . . . . . . . . . . . . | | ... | | ... |
116 116 // | 0 0 0 0 ... 1 4 1 ... 0 0 0 | * | P1_i | = | 4 * P(i-1) + 2 * Pi |
117 117 // | . . . . . . . . . . . . | | ... | | ... |
118 118 // | 0 0 0 0 0 0 0 0 ... 1 4 1 | | P1_(n-1)| | 4 * P(n-2) + 2 * P(n-1) |
119 119 // | 0 0 0 0 0 0 0 0 ... 0 2 7 | | P1_n | | 8 * P(n-1) + Pn |
120 120 //
121 121 QList<qreal> rhs;
122 122 rhs.append(q->x(0) + 2 * q->x(1));
123 123
124 124 // Set right hand side X values
125 125 for (int i = 1; i < n - 1; ++i)
126 126 rhs.append(4 * q->x(i) + 2 * q->x(i + 1));
127 127
128 128 rhs.append((8 * q->x(n - 1) + q->x(n)) / 2.0);
129 129 // Get first control points X-values
130 130 QList<qreal> xControl = getFirstControlPoints(rhs);
131 131 rhs[0] = q->y(0) + 2 * q->y(1);
132 132
133 133 // Set right hand side Y values
134 134 for (int i = 1; i < n - 1; ++i)
135 135 rhs[i] = 4 * q->y(i) + 2 * q->y(i + 1);
136 136
137 137 rhs[n - 1] = (8 * q->y(n - 1) + q->y(n)) / 2.0;
138 138 // Get first control points Y-values
139 139 QList<qreal> yControl = getFirstControlPoints(rhs);
140 140
141 141 // Fill output arrays.
142 142 for (int i = 0; i < n; ++i) {
143 143 // First control point
144 144 m_controlPoints.append(QPointF(xControl[i], yControl[i]));
145 145 // Second control point
146 146 if (i < n - 1)
147 147 m_controlPoints.append(QPointF(2 * q->x(i + 1) - xControl[i + 1], 2 * q->y(i + 1) - yControl[i + 1]));
148 148 else
149 149 m_controlPoints.append(QPointF((q->x(n) + xControl[n - 1]) / 2, (q->y(n) + yControl[n - 1]) / 2));
150 150 }
151 151 }
152 152
153 153 /*!
154 154 \internal
155 155 */
156 156 QList<qreal> QSplineSeriesPrivate::getFirstControlPoints(QList<qreal> rhs)
157 157 {
158 158 QList<qreal> x; // Solution vector.
159 159 QList<qreal> tmp; // Temp workspace.
160 160
161 161 qreal b = 2.0;
162 162 x.append(rhs[0] / b);
163 163 tmp.append(0);
164 164 for (int i = 1; i < rhs.size(); i++) {
165 165 // Decomposition and forward substitution.
166 166 tmp.append(1 / b);
167 167 b = (i < rhs.size() - 1 ? 4.0 : 3.5) - tmp[i];
168 168 x.append((rhs[i] - x[i - 1]) / b);
169 169 }
170 170 for (int i = 1; i < rhs.size(); i++)
171 171 x[rhs.size() - i - 1] -= tmp[rhs.size() - i] * x[rhs.size() - i]; // Backsubstitution.
172 172
173 173 return x;
174 174 }
175 175
176 176 /*!
177 177 \internal
178 178 Updates the control points, besed on currently avaiable knots.
179 179 */
180 180 void QSplineSeriesPrivate::updateControlPoints()
181 181 {
182 182 Q_Q(QSplineSeries);
183 183 if (q->count() > 1) {
184 184 m_controlPoints.clear();
185 185 calculateControlPoints();
186 186 }
187 187 }
188 188
189 189 /*//!
190 190 \fn bool QSplineSeries::setModel(QAbstractItemModel *model)
191 191 Sets the \a model to be used as a data source
192 192 \sa setModelMapping(), setModelMappingRange()
193 193 */
194 194 //bool QSplineSeries::setModel(QAbstractItemModel* model)
195 195 //{
196 196 // QXYSeries::setModel(model);
197 197 //// calculateControlPoints();
198 198 // return true;
199 199 //}
200 200
201 201 /*//!
202 202 \fn bool QSplineSeries::setModelMapping(int modelX, int modelY, Qt::Orientation orientation)
203 203 Sets the \a modelX to be used as a data source for x coordinate and \a modelY to be used
204 204 as a data source for y coordinate. The \a orientation parameter specifies whether the data
205 205 is in columns or in rows.
206 206 */
207 207 //void QSplineSeries::setModelMapping(int modelX, int modelY, Qt::Orientation orientation)
208 208 //{
209 209 // QLineSeries::setModelMapping(modelX, modelY, orientation);
210 210 //// calculateControlPoints();
211 211 //}
212 212
213 213 /*!
214 214 \fn bool QSplineSeries::setModelMappingRange(int first, int count)
215 215 Allows limiting the model mapping.
216 216 Parameter \a first specifies which element of the model should be used as a first one of the series.
217 217 Parameter \a count specifies how many elements should be mapped. If count is not specified (defaults to -1)
218 218 then all the items following \a first item in a model are used.
219 219 \sa setModel(), setModelMapping()
220 220 */
221 221
222 222 Chart* QSplineSeriesPrivate::createGraphics(ChartPresenter* presenter)
223 223 {
224 224 Q_Q(QSplineSeries);
225 225 SplineChartItem* spline = new SplineChartItem(q,presenter);
226 226 if(presenter->animationOptions().testFlag(QChart::SeriesAnimations)) {
227 227 presenter->animator()->addAnimation(spline);
228 228 }
229 229 presenter->chartTheme()->decorate(q, presenter->dataSet()->seriesIndex(q));
230 230 return spline;
231 231 }
232 232
233 233 #include "moc_qsplineseries.cpp"
234 234 #include "moc_qsplineseries_p.cpp"
235 235
236 236 QTCOMMERCIALCHART_END_NAMESPACE
@@ -1,53 +1,53
1 1 /****************************************************************************
2 2 **
3 3 ** Copyright (C) 2012 Digia Plc
4 4 ** All rights reserved.
5 5 ** For any questions to Digia, please use contact form at http://qt.digia.com
6 6 **
7 7 ** This file is part of the Qt Commercial Charts Add-on.
8 8 **
9 9 ** $QT_BEGIN_LICENSE$
10 10 ** Licensees holding valid Qt Commercial licenses may use this file in
11 11 ** accordance with the Qt Commercial License Agreement provided with the
12 12 ** Software or, alternatively, in accordance with the terms contained in
13 13 ** a written agreement between you and Digia.
14 14 **
15 15 ** If you have questions regarding the use of this file, please use
16 16 ** contact form at http://qt.digia.com
17 17 ** $QT_END_LICENSE$
18 18 **
19 19 ****************************************************************************/
20 20
21 21 #ifndef QSPLINESERIES_H
22 22 #define QSPLINESERIES_H
23 23
24 24 #include <qchartglobal.h>
25 25 #include <qlineseries.h>
26 26 #include <QList>
27 27 #include <QPointF>
28 28 #include <QtGlobal>
29 29
30 30 QTCOMMERCIALCHART_BEGIN_NAMESPACE
31 31
32 32 class QSplineSeriesPrivate;
33 33
34 34 class QTCOMMERCIALCHART_EXPORT QSplineSeries : public QLineSeries
35 35 {
36 36 Q_OBJECT
37 37 public:
38 38
39 39 explicit QSplineSeries(QObject *parent = 0);
40 QSeries::QSeriesType type() const;
40 QAbstractSeries::QSeriesType type() const;
41 41
42 42 QPointF controlPoint(int index) const;
43 43 void setModelMappingRange(int first, int count);
44 44
45 45 private:
46 46 Q_DECLARE_PRIVATE(QSplineSeries);
47 47 Q_DISABLE_COPY(QSplineSeries);
48 48 friend class SplineChartItem;
49 49 };
50 50
51 51 QTCOMMERCIALCHART_END_NAMESPACE
52 52
53 53 #endif // QSPLINESERIES_H
@@ -1,167 +1,167
1 1 !include( ../common.pri ):error( Couldn't find the common.pri file! )
2 2 TARGET = QtCommercialChart
3 3 DESTDIR = $$CHART_BUILD_LIB_DIR
4 4 TEMPLATE = lib
5 5 QT += core \
6 6 gui
7 7 win32-msvc*: LIBS += User32.lib
8 8 CONFIG += debug_and_release
9 9 CONFIG(debug, debug|release):TARGET = QtCommercialChartd
10 10 SOURCES += \
11 11 $$PWD/chartdataset.cpp \
12 12 $$PWD/chartpresenter.cpp \
13 13 $$PWD/charttheme.cpp \
14 14 $$PWD/domain.cpp \
15 15 $$PWD/qchart.cpp \
16 16 $$PWD/qchartview.cpp \
17 $$PWD/qseries.cpp \
17 $$PWD/qabstractseries.cpp \
18 18 $$PWD/chartbackground.cpp \
19 19 $$PWD/chart.cpp \
20 20 $$PWD/scroller.cpp
21 21 PRIVATE_HEADERS += \
22 22 $$PWD/chartdataset_p.h \
23 23 $$PWD/chartitem_p.h \
24 24 $$PWD/chartpresenter_p.h \
25 25 $$PWD/charttheme_p.h \
26 26 $$PWD/domain_p.h \
27 27 $$PWD/chartbackground_p.h \
28 28 $$PWD/chart_p.h \
29 29 $$PWD/chartconfig_p.h \
30 30 $$PWD/qchart_p.h \
31 31 $$PWD/qchartview_p.h \
32 32 $$PWD/scroller_p.h \
33 $$PWD/qseries_p.h
33 $$PWD/qabstractseries_p.h
34 34 PUBLIC_HEADERS += \
35 35 $$PWD/qchart.h \
36 36 $$PWD/qchartglobal.h \
37 $$PWD/qseries.h \
37 $$PWD/qabstractseries.h \
38 38 $$PWD/qchartview.h
39 39
40 40 include(animations/animations.pri)
41 41 include(areachart/areachart.pri)
42 42 include(axis/axis.pri)
43 43 include(barchart/barchart.pri)
44 44 include(legend/legend.pri)
45 45 include(linechart/linechart.pri)
46 46 include(piechart/piechart.pri)
47 47 include(scatterseries/scatter.pri)
48 48 include(splinechart/splinechart.pri)
49 49 include(themes/themes.pri)
50 50 include(xychart/xychart.pri)
51 51
52 52 HEADERS += $$PUBLIC_HEADERS
53 53 HEADERS += $$PRIVATE_HEADERS
54 54 HEADERS += $$THEMES
55 55 INCLUDEPATH += ../include .
56 56
57 57 OBJECTS_DIR = $$CHART_BUILD_DIR/lib
58 58 MOC_DIR = $$CHART_BUILD_DIR/lib
59 59 UI_DIR = $$CHART_BUILD_DIR/lib
60 60 RCC_DIR = $$CHART_BUILD_DIR/lib
61 61 DEFINES += QTCOMMERCIALCHART_LIBRARY
62 62
63 63 #qt public headers
64 64 #this is very primitive and lame parser , TODO: make perl script insted
65 65 !exists($$CHART_BUILD_PUBLIC_HEADER_DIR/QChartGlobal)
66 66 {
67 67 system($$QMAKE_MKDIR $$CHART_BUILD_PUBLIC_HEADER_DIR)
68 68 win32:{
69 69 command = "echo $${LITERAL_HASH}include \"qchartglobal.h\" > $$CHART_BUILD_PUBLIC_HEADER_DIR/QChartGlobal"
70 70 }else{
71 71 command = "echo \"$${LITERAL_HASH}include \\\"qchartglobal.h\\\"\" > $$CHART_BUILD_PUBLIC_HEADER_DIR/QChartGlobal"
72 72 }
73 73 system($$command)
74 74 }
75 75
76 76 for(file, PUBLIC_HEADERS) {
77 77 name = $$split(file,'/')
78 78 name = $$last(name)
79 79 class = "$$cat($$file)"
80 80 class = $$find(class,class)
81 81 !isEmpty(class){
82 82 class = $$split(class,QTCOMMERCIALCHART_EXPORT)
83 83 class = $$member(class,1)
84 84 class = $$split(class,' ')
85 85 class = $$replace(class,' ','')
86 86 class = $$member(class,0)
87 87 win32:{
88 88 command = "echo $${LITERAL_HASH}include \"$$name\" > $$CHART_BUILD_PUBLIC_HEADER_DIR/$$class"
89 89 }else{
90 90 command = "echo \"$${LITERAL_HASH}include \\\"$$name\\\"\" > $$CHART_BUILD_PUBLIC_HEADER_DIR/$$class"
91 91 }
92 92 PUBLIC_QT_HEADERS += $$CHART_BUILD_PUBLIC_HEADER_DIR/$$class
93 93 system($$command)
94 94 }
95 95 }
96 96
97 97 public_headers.path = $$[QT_INSTALL_HEADERS]/QtCommercialChart
98 98 public_headers.files = $$PUBLIC_HEADERS $$PUBLIC_QT_HEADERS
99 99
100 100 target.path = $$[QT_INSTALL_LIBS]
101 101 INSTALLS += target public_headers
102 102
103 103 install_build_public_headers.name = build_public_headers
104 104 install_build_public_headers.output = $$CHART_BUILD_PUBLIC_HEADER_DIR/${QMAKE_FILE_BASE}.h
105 105 install_build_public_headers.input = PUBLIC_HEADERS
106 106 install_build_public_headers.commands = $$QMAKE_COPY \
107 107 ${QMAKE_FILE_NAME} \
108 108 $$CHART_BUILD_PUBLIC_HEADER_DIR
109 109 install_build_public_headers.CONFIG += target_predeps \
110 110 no_link
111 111
112 112 install_build_private_headers.name = buld_private_headers
113 113 install_build_private_headers.output = $$CHART_BUILD_PRIVATE_HEADER_DIR/${QMAKE_FILE_BASE}.h
114 114 install_build_private_headers.input = PRIVATE_HEADERS
115 115 install_build_private_headers.commands = $$QMAKE_COPY \
116 116 ${QMAKE_FILE_NAME} \
117 117 $$CHART_BUILD_PRIVATE_HEADER_DIR
118 118 install_build_private_headers.CONFIG += target_predeps \
119 119 no_link
120 120
121 121 QMAKE_EXTRA_COMPILERS += install_build_public_headers \
122 122 install_build_private_headers \
123 123
124 124
125 125 !win32-msvc*: {
126 126
127 127 # There is a problem with jom.exe currently. It does not seem to understand QMAKE_EXTRA_TARGETS properly.
128 128 # This is the case at least with shadow builds.
129 129 # http://qt-project.org/wiki/jom
130 130
131 131 chartversion.target = $$PWD/qchartversion_p.h
132 132
133 133 unix:{
134 134 chartversion.commands = @echo \
135 135 "const char *buildTime = \\\"`date +'%y%m%d%H%M'`\\\" \\; \
136 136 const char *gitHead = \\\"`git rev-parse HEAD`\\\" \\; " \
137 137 > \
138 138 $$chartversion.target;
139 139 }else{
140 140 chartversion.commands = @echo \
141 141 "const char *buildTime = \"%date%_%time%\" ; \
142 142 const char *gitHead = \"unknown\" ; " \
143 143 > \
144 144 $$chartversion.target
145 145 }
146 146
147 147 chartversion.depends = $$HEADERS \
148 148 $$SOURCES
149 149
150 150 PRE_TARGETDEPS += $$PWD/qchartversion_p.h
151 151 QMAKE_CLEAN += $$PWD/qchartversion_p.h
152 152 QMAKE_EXTRA_TARGETS += chartversion
153 153 }
154 154
155 155 unix:QMAKE_DISTCLEAN += -r \
156 156 $$CHART_BUILD_HEADER_DIR \
157 157 $$CHART_BUILD_LIB_DIR
158 158 win32:QMAKE_DISTCLEAN += /Q \
159 159 $$CHART_BUILD_HEADER_DIR \
160 160 $$CHART_BUILD_LIB_DIR
161 161
162 162 # treat warnings as errors
163 163 win32-msvc*: {
164 164 QMAKE_CXXFLAGS += /WX
165 165 } else {
166 166 QMAKE_CXXFLAGS += -Werror
167 167 }
@@ -1,671 +1,670
1 1 /****************************************************************************
2 2 **
3 3 ** Copyright (C) 2012 Digia Plc
4 4 ** All rights reserved.
5 5 ** For any questions to Digia, please use contact form at http://qt.digia.com
6 6 **
7 7 ** This file is part of the Qt Commercial Charts Add-on.
8 8 **
9 9 ** $QT_BEGIN_LICENSE$
10 10 ** Licensees holding valid Qt Commercial licenses may use this file in
11 11 ** accordance with the Qt Commercial License Agreement provided with the
12 12 ** Software or, alternatively, in accordance with the terms contained in
13 13 ** a written agreement between you and Digia.
14 14 **
15 15 ** If you have questions regarding the use of this file, please use
16 16 ** contact form at http://qt.digia.com
17 17 ** $QT_END_LICENSE$
18 18 **
19 19 ****************************************************************************/
20 20
21 21 #include "qxyseries.h"
22 22 #include "qxyseries_p.h"
23 23 #include "domain_p.h"
24 24 #include "legendmarker_p.h"
25 25 #include <QAbstractItemModel>
26 26
27 27 QTCOMMERCIALCHART_BEGIN_NAMESPACE
28 28
29 29 /*!
30 30 \class QXYSeries
31 31 \brief The QXYSeries class is a base class for line, spline and scatter series.
32 32 */
33 33
34 34 /*!
35 35 \fn QPen QXYSeries::pen() const
36 36 \brief Returns pen used to draw points for series.
37 37 \sa setPen()
38 38 */
39 39
40 40 /*!
41 41 \fn QBrush QXYSeries::brush() const
42 42 \brief Returns brush used to draw points for series.
43 43 \sa setBrush()
44 44 */
45 45
46 46 /*!
47 47 \fn void QXYSeries::clicked(const QPointF& point)
48 48 \brief Signal is emitted when user clicks the \a point on chart.
49 49 */
50 50
51 51 /*!
52 52 \fn void QXYSeries::selected()
53 53
54 54 The signal is emitted if the user selects/deselects the XY series. The logic for maintaining selections should be
55 55 implemented by the user of QXYSeries API.
56 56 */
57 57
58 58 /*!
59 59 \fn void QXYSeriesPrivate::pointReplaced(int index)
60 60 \brief \internal \a index
61 61 */
62 62
63 63 /*!
64 64 \fn void QXYSeriesPrivate::pointAdded(int index)
65 65 \brief \internal \a index
66 66 */
67 67
68 68 /*!
69 69 \fn void QXYSeriesPrivate::pointRemoved(int index)
70 70 \brief \internal \a index
71 71 */
72 72
73 73 /*!
74 74 \fn void QXYSeriesPrivate::updated()
75 75 \brief \internal
76 76 */
77 77
78 78 /*!
79 79 \fn int QXYSeries::mapFirst() const
80 80 Returns the index of the model's item that is used as a first one for the series.
81 81 \sa mapCount()
82 82 */
83 83
84 84 /*!
85 85 \fn int QXYSeries::mapCount() const
86 86 Returns the number of the items that are taken from the model.
87 87 If -1 it means all the items of the model following the first one are used.
88 88 \sa mapFirst()
89 89 */
90 90
91 91 /*!
92 92 \internal
93 93
94 94 Constructs empty series object which is a child of \a parent.
95 95 When series object is added to QChartView or QChart instance ownerships is transferred.
96 96 */
97 QXYSeries::QXYSeries(QXYSeriesPrivate &d,QObject *parent):QSeries(d,parent)
97 QXYSeries::QXYSeries(QXYSeriesPrivate &d,QObject *parent) : QAbstractSeries(d, parent)
98 98 {
99 99
100 100 }
101 101 /*!
102 102 Destroys the object. Series added to QChartView or QChart instances are owned by those,
103 103 and are deleted when mentioned object are destroyed.
104 104 */
105 105 QXYSeries::~QXYSeries()
106 106 {
107 107 }
108 108
109 109 /*!
110 110 Adds data point \a x \a y to the series. Points are connected with lines on the chart.
111 111 */
112 112 void QXYSeries::append(qreal x,qreal y)
113 113 {
114 114 Q_D(QXYSeries);
115 115 Q_ASSERT(d->m_x.size() == d->m_y.size());
116 116 d->m_x<<x;
117 117 d->m_y<<y;
118 118 emit d->pointAdded(d->m_x.size()-1);
119 119 }
120 120
121 121 /*!
122 122 This is an overloaded function.
123 123 Adds data \a point to the series. Points are connected with lines on the chart.
124 124 */
125 125 void QXYSeries::append(const QPointF &point)
126 126 {
127 127 append(point.x(),point.y());
128 128 }
129 129
130 130 /*!
131 131 This is an overloaded function.
132 132 Adds list of data \a points to the series. Points are connected with lines on the chart.
133 133 */
134 134 void QXYSeries::append(const QList<QPointF> points)
135 135 {
136 136 foreach(const QPointF& point , points) {
137 137 append(point.x(),point.y());
138 138 }
139 139 }
140 140
141 141 /*!
142 142 Modifies \a y value for given \a x a value.
143 143 */
144 144 void QXYSeries::replace(qreal x,qreal y)
145 145 {
146 146 Q_D(QXYSeries);
147 147 int index = d->m_x.indexOf(x);
148 148 d->m_x[index] = x;
149 149 d->m_y[index] = y;
150 150 emit d->pointReplaced(index);
151 151 }
152 152
153 153 /*!
154 154 This is an overloaded function.
155 155 Replaces current y value of for given \a point x value with \a point y value.
156 156 */
157 157 void QXYSeries::replace(const QPointF &point)
158 158 {
159 159 replace(point.x(),point.y());
160 160 }
161 161
162 162 /*!
163 163 Removes first \a x value and related y value.
164 164 */
165 165 void QXYSeries::remove(qreal x)
166 166 {
167 167 Q_D(QXYSeries);
168 168 int index = d->m_x.indexOf(x);
169 169
170 170 if (index == -1) return;
171 171
172 172 d->m_x.remove(index);
173 173 d->m_y.remove(index);
174 174
175 175 emit d->pointRemoved(index);
176 176 }
177 177
178 178 /*!
179 179 Removes current \a x and \a y value.
180 180 */
181 181 void QXYSeries::remove(qreal x,qreal y)
182 182 {
183 183 Q_D(QXYSeries);
184 184 int index =-1;
185 185 do {
186 186 index = d->m_x.indexOf(x,index+1);
187 187 } while (index !=-1 && d->m_y.at(index)!=y);
188 188
189 189 if (index==-1) return;
190 190
191 191 d->m_x.remove(index);
192 192 d->m_y.remove(index);
193 193 emit d->pointRemoved(index);
194 194 }
195 195
196 196 /*!
197 197 Removes current \a point x value. Note \a point y value is ignored.
198 198 */
199 199 void QXYSeries::remove(const QPointF &point)
200 200 {
201 201 remove(point.x(),point.y());
202 202 }
203 203
204 204 /*!
205 205 Removes all data points from the series.
206 206 */
207 207 void QXYSeries::removeAll()
208 208 {
209 209 Q_D(QXYSeries);
210 210 d->m_x.clear();
211 211 d->m_y.clear();
212 212 }
213 213
214 214 /*!
215 215 \internal \a pos
216 216 */
217 217 qreal QXYSeries::x(int pos) const
218 218 {
219 219 Q_D(const QXYSeries);
220 220 if (d->m_model) {
221 221 if (d->m_mapOrientation == Qt::Vertical)
222 222 // consecutive data is read from model's column
223 223 return d->m_model->data(d->m_model->index(pos + d->m_mapFirst, d->m_mapX), Qt::DisplayRole).toDouble();
224 224 else
225 225 // consecutive data is read from model's row
226 226 return d->m_model->data(d->m_model->index(d->m_mapX, pos + d->m_mapFirst), Qt::DisplayRole).toDouble();
227 227 } else {
228 228 // model is not specified, return the data from series' internal data store
229 229 return d->m_x.at(pos);
230 230 }
231 231 }
232 232
233 233 /*!
234 234 \internal \a pos
235 235 */
236 236 qreal QXYSeries::y(int pos) const
237 237 {
238 238 Q_D(const QXYSeries);
239 239 if (d->m_model) {
240 240 if (d->m_mapOrientation == Qt::Vertical)
241 241 // consecutive data is read from model's column
242 242 return d->m_model->data(d->m_model->index(pos + d->m_mapFirst, d->m_mapY), Qt::DisplayRole).toDouble();
243 243 else
244 244 // consecutive data is read from model's row
245 245 return d->m_model->data(d->m_model->index(d->m_mapY, pos + d->m_mapFirst), Qt::DisplayRole).toDouble();
246 246 } else {
247 247 // model is not specified, return the data from series' internal data store
248 248 return d->m_y.at(pos);
249 249 }
250 250 }
251 251
252 252 /*!
253 253 Returns number of data points within series.
254 254 */
255 255 int QXYSeries::count() const
256 256 {
257 257 Q_D(const QXYSeries);
258 258
259 259 Q_ASSERT(d->m_x.size() == d->m_y.size());
260 260
261 261 if (d->m_model) {
262 262 if (d->m_mapOrientation == Qt::Vertical) {
263 263 // data is in a column. Return the number of mapped items if the model's column have enough items
264 264 // or the number of items that can be mapped
265 265 if (d->m_mapLimited)
266 266 return qMin(d->m_mapCount, qMax(d->m_model->rowCount() - d->m_mapFirst, 0));
267 267 else
268 268 return qMax(d->m_model->rowCount() - d->m_mapFirst, 0);
269 269 } else {
270 270 // data is in a row. Return the number of mapped items if the model's row have enough items
271 271 // or the number of items that can be mapped
272 272 if (d->m_mapLimited)
273 273 return qMin(d->m_mapCount, qMax(d->m_model->columnCount() - d->m_mapFirst, 0));
274 274 else
275 275 return qMax(d->m_model->columnCount() - d->m_mapFirst, 0);
276 276 }
277 277 }
278 278
279 279 // model is not specified, return the number of points in the series internal data store
280 280 return d->m_x.size();
281 281 }
282 282
283 283 /*!
284 284 Returns the data points of the series.
285 285 */
286 286 QList<QPointF> QXYSeries::data()
287 287 {
288 288 Q_D(QXYSeries);
289 289 QList<QPointF> data;
290 290 for (int i(0); i < d->m_x.count() && i < d->m_y.count(); i++)
291 291 data.append(QPointF(d->m_x.at(i), d->m_y.at(i)));
292 292 return data;
293 293 }
294 294
295 295
296 296 /*!
297 297 Sets \a pen used for drawing points on the chart. If the pen is not defined, the
298 298 pen from chart theme is used.
299 299 \sa QChart::setTheme()
300 300 */
301 301 void QXYSeries::setPen(const QPen &pen)
302 302 {
303 303 Q_D(QXYSeries);
304 304 if (d->m_pen!=pen) {
305 305 d->m_pen = pen;
306 306 emit d->updated();
307 307 }
308 308 }
309 309
310 310 QPen QXYSeries::pen() const
311 311 {
312 312 Q_D(const QXYSeries);
313 313 return d->m_pen;
314 314 }
315 315
316 316 /*!
317 317 Sets \a brush used for drawing points on the chart. If the brush is not defined, brush
318 318 from chart theme setting is used.
319 319 \sa QChart::setTheme()
320 320 */
321 321 void QXYSeries::setBrush(const QBrush &brush)
322 322 {
323 323 Q_D(QXYSeries);
324 324 if (d->m_brush!=brush) {
325 325 d->m_brush = brush;
326 326 emit d->updated();
327 327 }
328 328 }
329 329
330 330 QBrush QXYSeries::brush() const
331 331 {
332 332 Q_D(const QXYSeries);
333 333 return d->m_brush;
334 334 }
335 335
336 336
337 337 /*!
338 338 Sets if data points are \a visible and should be drawn on line.
339 339 */
340 340 void QXYSeries::setPointsVisible(bool visible)
341 341 {
342 342 Q_D(QXYSeries);
343 343 if (d->m_pointsVisible != visible){
344 344 d->m_pointsVisible = visible;
345 345 emit d->updated();
346 346 }
347 347 }
348 348
349 349 /*!
350 350 Returns true if drawing the data points of the series is enabled.
351 351 */
352 352 bool QXYSeries::pointsVisible() const
353 353 {
354 354 Q_D(const QXYSeries);
355 355 return d->m_pointsVisible;
356 356 }
357 357
358 358
359 359 /*!
360 360 Stream operator for adding a data \a point to the series.
361 361 \sa append()
362 362 */
363 363 QXYSeries& QXYSeries::operator<< (const QPointF &point)
364 364 {
365 365 append(point);
366 366 return *this;
367 367 }
368 368
369 369
370 370 /*!
371 371 Stream operator for adding a list of \a points to the series.
372 372 \sa append()
373 373 */
374 374
375 375 QXYSeries& QXYSeries::operator<< (const QList<QPointF> points)
376 376 {
377 377 append(points);
378 378 return *this;
379 379 }
380 380
381 381 /*!
382 382 \internal
383 383 */
384 384 void QXYSeries::modelUpdated(QModelIndex topLeft, QModelIndex bottomRight)
385 385 {
386 386 Q_UNUSED(bottomRight)
387 387 Q_D(QXYSeries);
388 388 if (d->m_mapOrientation == Qt::Vertical) {
389 389 if (topLeft.row() >= d->m_mapFirst && (!d->m_mapLimited || topLeft.row() < d->m_mapFirst + d->m_mapCount))
390 390 emit d->pointReplaced(topLeft.row() - d->m_mapFirst);
391 391 } else {
392 392 if (topLeft.column() >= d->m_mapFirst && (!d->m_mapLimited || topLeft.column() < d->m_mapFirst + d->m_mapCount))
393 393 emit d->pointReplaced(topLeft.column() - d->m_mapFirst);
394 394 }
395 395 }
396 396
397 397 /*!
398 398 \internal
399 399 */
400 400 void QXYSeries::modelDataAboutToBeAdded(QModelIndex parent, int start, int end)
401 401 {
402 402 Q_UNUSED(parent)
403 403 // Q_UNUSED(end)
404 404 Q_D(QXYSeries);
405 405 if (d->m_mapLimited) {
406 406 if (start >= d->m_mapFirst + d->m_mapCount) {
407 407 // the added data is below mapped area
408 408 // therefore it has no relevance
409 409 return;
410 410 } else {
411 411 // the added data is in the mapped area or before it and update is needed
412 412
413 413 // check how many mapped items there is currently (before new items are added)
414 414 // if the number of items currently is equal the m_mapCount then some needs to be removed from xychartitem
415 415 // internal storage before new ones can be added
416 416
417 417 int itemsToRemove = qMin(count() - qMax(start - d->m_mapFirst, 0), end - start + 1);
418 418 if (d->m_mapCount == count()) {
419 419 for (int i = 0; i < itemsToRemove; i++)
420 420 emit d->pointRemoved(qMin(end, count()) - i);
421 421 }
422 422 }
423 423 } else {
424 424 // map is not limited (it includes all the items starting from m_mapFirst till the end of model)
425 425 // nothing to do
426 426 // emit pointAdded(qMax(start - m_mapFirst, 0));
427 427 }
428 428 }
429 429
430 430 /*!
431 431 \internal
432 432 */
433 433 void QXYSeries::modelDataAdded(QModelIndex parent, int start, int end)
434 434 {
435 435 Q_UNUSED(parent)
436 436 // Q_UNUSED(end)
437 437 Q_D(QXYSeries);
438 438 if (d->m_mapLimited) {
439 439 if (start >= d->m_mapFirst + d->m_mapCount) {
440 440 // the added data is below mapped area
441 441 // therefore it has no relevance
442 442 return;
443 443 } else {
444 444 // the added data is in the mapped area or before it
445 445 // update needed
446 446 if (count() > 0) {
447 447 int toBeAdded = qMin(d->m_mapCount - (start - d->m_mapFirst), end - start + 1);
448 448 for (int i = 0; i < toBeAdded; i++)
449 449 if (start + i >= d->m_mapFirst)
450 450 emit d->pointAdded(start + i);
451 451 }
452 452 }
453 453 } else {
454 454 // map is not limited (it included all the items starting from m_mapFirst till the end of model)
455 455 for (int i = 0; i < end - start + 1; i++)
456 456 emit d->pointAdded(start + i);
457 457 }
458 458 }
459 459
460 460 /*!
461 461 \internal
462 462 */
463 463 void QXYSeries::modelDataAboutToBeRemoved(QModelIndex parent, int start, int end)
464 464 {
465 465 Q_UNUSED(parent)
466 466 // Q_UNUSED(end)
467 467 Q_D(QXYSeries);
468 468 if (d->m_mapLimited) {
469 469 if (start >= d->m_mapFirst + d->m_mapCount) {
470 470 // the removed data is below mapped area
471 471 // therefore it has no relevance
472 472 return;
473 473 } else {
474 474 // the removed data is in the mapped area or before it
475 475 // update needed
476 476
477 477 // check how many items need to be removed from the xychartitem storage
478 478 // the number equals the number of items that are removed and that lay before
479 479 // or in the mapped area. Items that lay beyond the map do not count
480 480 // the max is the current number of items in storage (count())
481 481 int itemsToRemove = qMin(count(), qMin(end, d->m_mapFirst + d->m_mapCount - 1) - start + 1);
482 482 for (int i = 0; i < itemsToRemove; i++)
483 483 emit d->pointRemoved(start);
484 484 }
485 485 } else {
486 486 // map is not limited (it included all the items starting from m_mapFirst till the end of model)
487 487 for (int i = 0; i < end - start + 1; i++)
488 488 emit d->pointRemoved(start);
489 489 }
490 490 }
491 491
492 492 /*!
493 493 \internal
494 494 */
495 495 void QXYSeries::modelDataRemoved(QModelIndex parent, int start, int end)
496 496 {
497 497
498 498 Q_UNUSED(parent)
499 499 Q_UNUSED(end)
500 500 Q_D(QXYSeries);
501 501 // how many items there were before data was removed
502 502 // int oldCount = count() - 1;
503 503
504 504 if (d->m_mapLimited) {
505 505 if (start >= d->m_mapFirst + d->m_mapCount) {
506 506 // the removed data is below mapped area
507 507 // therefore it has no relevance
508 508 return;
509 509 } else {
510 510 // if the current items count in the whole model is bigger than the index of the last item
511 511 // that was removed than it means there are some extra items available
512 512
513 513 int removedItemsCount = qMin(count(), qMin(end, d->m_mapFirst + d->m_mapCount - 1) - start + 1);
514 514 int extraItemsAvailable = 0;
515 515 if (d->m_mapOrientation == Qt::Vertical) {
516 516 extraItemsAvailable = qMax(d->m_model->rowCount() + (end - start + 1) - qMax(end + 1, d->m_mapFirst + d->m_mapCount), 0);
517 517 } else {
518 518 extraItemsAvailable = qMax(d->m_model->columnCount() + (end - start + 1) - qMax(end + 1, d->m_mapFirst + d->m_mapCount), 0);
519 519 }
520 520
521 521 // if there are excess items available (below the mapped area) use them to repopulate mapped area
522 522 int toBeAdded = qMin(extraItemsAvailable, removedItemsCount);
523 523 for (int k = 0; k < toBeAdded; k++)
524 524 emit d->pointAdded(d->m_mapFirst + d->m_mapCount - removedItemsCount + k);
525 525 }
526 526 } else {
527 527 // data was removed from XYSeries interal storage. Nothing more to do
528 528 }
529 529 }
530 530
531 531 /*!
532 532 \fn bool QXYSeries::setModel(QAbstractItemModel *model)
533 533 Sets the \a model to be used as a data source
534 534 \sa setModelMapping(), setModelMappingRange()
535 535 */
536 536 bool QXYSeries::setModel(QAbstractItemModel *model)
537 537 {
538 538 Q_D(QXYSeries);
539 539 // disconnect signals from old model
540 540 if (d->m_model) {
541 541 QObject::disconnect(d->m_model, 0, this, 0);
542 542 d->m_mapX = -1;
543 543 d->m_mapY = -1;
544 544 d->m_mapFirst = 0;
545 545 d->m_mapCount = 0;
546 546 d->m_mapLimited = false;
547 547 d->m_mapOrientation = Qt::Vertical;
548 548 }
549 549
550 550 // set new model
551 551 if (model) {
552 552 d->m_model = model;
553 553 return true;
554 554 } else {
555 555 d->m_model = 0;
556 556 return false;
557 557 }
558 558 }
559 559
560 560 /*!
561 561 \fn bool QXYSeries::setModelMapping(int modelX, int modelY, Qt::Orientation orientation)
562 562 Sets the \a modelX to be used as a data source for x coordinate and \a modelY to be used
563 563 as a data source for y coordinate. The \a orientation parameter specifies whether the data
564 564 is in columns or in rows.
565 565 \sa setModel(), setModelMappingRange()
566 566 */
567 567 void QXYSeries::setModelMapping(int modelX, int modelY, Qt::Orientation orientation)
568 568 {
569 569 Q_D(QXYSeries);
570 570 if (d->m_model == 0)
571 571 return;
572 572 d->m_mapX = modelX;
573 573 d->m_mapY = modelY;
574 574 d->m_mapFirst = 0;
575 575 d->m_mapOrientation = orientation;
576 576 if (d->m_mapOrientation == Qt::Vertical) {
577 577 connect(d->m_model,SIGNAL(dataChanged(QModelIndex,QModelIndex)), this, SLOT(modelUpdated(QModelIndex,QModelIndex)));
578 578 connect(d->m_model,SIGNAL(rowsAboutToBeInserted(QModelIndex,int,int)), this, SLOT(modelDataAboutToBeAdded(QModelIndex,int,int)));
579 579 connect(d->m_model,SIGNAL(rowsInserted(QModelIndex,int,int)), this, SLOT(modelDataAdded(QModelIndex,int,int)));
580 580 connect(d->m_model, SIGNAL(rowsAboutToBeRemoved(QModelIndex,int,int)), this, SLOT(modelDataAboutToBeRemoved(QModelIndex,int,int)));
581 581 connect(d->m_model, SIGNAL(rowsRemoved(QModelIndex,int,int)), this, SLOT(modelDataRemoved(QModelIndex,int,int)));
582 582 } else {
583 583 connect(d->m_model,SIGNAL(dataChanged(QModelIndex,QModelIndex)), this, SLOT(modelUpdated(QModelIndex,QModelIndex)));
584 584 connect(d->m_model,SIGNAL(columnsAboutToBeInserted(QModelIndex,int,int)), this, SLOT(modelDataAboutToBeAdded(QModelIndex,int,int)));
585 585 connect(d->m_model,SIGNAL(columnsInserted(QModelIndex,int,int)), this, SLOT(modelDataAdded(QModelIndex,int,int)));
586 586 connect(d->m_model, SIGNAL(columnsAboutToBeRemoved(QModelIndex,int,int)), this, SLOT(modelDataAboutToBeRemoved(QModelIndex,int,int)));
587 587 connect(d->m_model, SIGNAL(columnsRemoved(QModelIndex,int,int)), this, SLOT(modelDataRemoved(QModelIndex,int,int)));
588 588 }
589 589 }
590 590
591 591 /*!
592 592 \fn bool QXYSeries::setModelMappingRange(int first, int count)
593 593 Allows limiting the model mapping.
594 594 Parameter \a first specifies which element of the model should be used as a first one of the series.
595 595 Parameter \a count specifies how many elements should be mapped. If count is not specified (defaults to -1)
596 596 then all the items following \a first item in a model are used.
597 597 \sa setModel(), setModelMapping()
598 598 */
599 599 void QXYSeries::setModelMappingRange(int first, int count)
600 600 {
601 601 Q_D(QXYSeries);
602 602 d->m_mapFirst = first;
603 603 if (count == 0) {
604 604 d->m_mapLimited = false;
605 605 } else {
606 606 d->m_mapCount = count;
607 607 d->m_mapLimited = true;
608 608 }
609 609 }
610 610
611 611 int QXYSeries::mapFirst() const
612 612 {
613 613 Q_D(const QXYSeries);
614 614 return d->m_mapFirst;
615 615 }
616 616
617 617 int QXYSeries::mapCount() const
618 618 {
619 619 Q_D(const QXYSeries);
620 620 return d->m_mapCount;
621 621 }
622 622
623 623 //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
624 624
625 QXYSeriesPrivate::QXYSeriesPrivate(QXYSeries *q): QSeriesPrivate(q),
626 m_mapX(-1),
627 m_mapY(-1),
628 m_mapFirst(0),
629 m_mapCount(0),
630 m_mapLimited(false),
631 m_mapOrientation( Qt::Vertical),
632 m_pointsVisible(false)
625 QXYSeriesPrivate::QXYSeriesPrivate(QXYSeries *q) : QAbstractSeriesPrivate(q),
626 m_mapX(-1),
627 m_mapY(-1),
628 m_mapFirst(0),
629 m_mapCount(0),
630 m_mapLimited(false),
631 m_mapOrientation( Qt::Vertical),
632 m_pointsVisible(false)
633 633 {
634
635 634 }
636 635
637 636 void QXYSeriesPrivate::scaleDomain(Domain& domain)
638 637 {
639 638 qreal minX(domain.minX());
640 639 qreal minY(domain.minY());
641 640 qreal maxX(domain.maxX());
642 641 qreal maxY(domain.maxY());
643 642 int tickXCount(domain.tickXCount());
644 643 int tickYCount(domain.tickYCount());
645 644
646 645 Q_Q(QXYSeries);
647 646 for (int i = 0; i < q->count(); i++)
648 647 {
649 648 qreal x = q->x(i);
650 649 qreal y = q->y(i);
651 650 minX = qMin(minX, x);
652 651 minY = qMin(minY, y);
653 652 maxX = qMax(maxX, x);
654 653 maxY = qMax(maxY, y);
655 654 }
656 655
657 656 domain.setRangeX(minX,maxX,tickXCount);
658 657 domain.setRangeY(minY,maxY,tickYCount);
659 658 }
660 659
661 660 QList<LegendMarker*> QXYSeriesPrivate::createLegendMarker(QLegend* legend)
662 661 {
663 662 Q_Q(QXYSeries);
664 663 QList<LegendMarker*> list;
665 664 return list << new XYLegendMarker(q,legend);
666 665 }
667 666
668 667 #include "moc_qxyseries.cpp"
669 668 #include "moc_qxyseries_p.cpp"
670 669
671 670 QTCOMMERCIALCHART_END_NAMESPACE
@@ -1,97 +1,97
1 1 /****************************************************************************
2 2 **
3 3 ** Copyright (C) 2012 Digia Plc
4 4 ** All rights reserved.
5 5 ** For any questions to Digia, please use contact form at http://qt.digia.com
6 6 **
7 7 ** This file is part of the Qt Commercial Charts Add-on.
8 8 **
9 9 ** $QT_BEGIN_LICENSE$
10 10 ** Licensees holding valid Qt Commercial licenses may use this file in
11 11 ** accordance with the Qt Commercial License Agreement provided with the
12 12 ** Software or, alternatively, in accordance with the terms contained in
13 13 ** a written agreement between you and Digia.
14 14 **
15 15 ** If you have questions regarding the use of this file, please use
16 16 ** contact form at http://qt.digia.com
17 17 ** $QT_END_LICENSE$
18 18 **
19 19 ****************************************************************************/
20 20
21 21 #ifndef QXYSERIES_H
22 22 #define QXYSERIES_H
23 23
24 24 #include <qchartglobal.h>
25 #include <qseries.h>
25 #include <qabstractseries.h>
26 26 #include <QPen>
27 27 #include <QBrush>
28 28
29 29 class QModelIndex;
30 30
31 31 QTCOMMERCIALCHART_BEGIN_NAMESPACE
32 32
33 33 class QXYSeriesPrivate;
34 34
35 class QTCOMMERCIALCHART_EXPORT QXYSeries : public QSeries
35 class QTCOMMERCIALCHART_EXPORT QXYSeries : public QAbstractSeries
36 36 {
37 37 Q_OBJECT
38 38 protected:
39 39 explicit QXYSeries(QXYSeriesPrivate &d,QObject *parent = 0);
40 40 ~QXYSeries();
41 41
42 42 public:
43 43 void append(qreal x, qreal y);
44 44 void append(const QPointF &point);
45 45 void append(const QList<QPointF> points);
46 46 void replace(qreal x,qreal y);
47 47 void replace(const QPointF &point);
48 48 void remove(qreal x);
49 49 void remove(qreal x, qreal y);
50 50 void remove(const QPointF &point);
51 51 void removeAll();
52 52
53 53 int count() const;
54 54 qreal x(int pos) const;
55 55 qreal y(int pos) const;
56 56 QList<QPointF> data();
57 57
58 58 QXYSeries& operator << (const QPointF &point);
59 59 QXYSeries& operator << (const QList<QPointF> points);
60 60
61 61 void setPen(const QPen &pen);
62 62 QPen pen() const;
63 63
64 64 void setBrush(const QBrush &brush);
65 65 QBrush brush() const;
66 66
67 67 void setPointsVisible(bool visible = true);
68 68 bool pointsVisible() const;
69 69
70 70 bool setModel(QAbstractItemModel *model);
71 71
72 72 virtual void setModelMapping(int modelX, int modelY, Qt::Orientation orientation = Qt::Vertical);
73 73 virtual void setModelMappingRange(int first, int count = 0);
74 74 int mapFirst() const;
75 75 int mapCount() const;
76 76
77 77 private Q_SLOTS:
78 78 void modelUpdated(QModelIndex topLeft, QModelIndex bottomRight);
79 79 void modelDataAboutToBeAdded(QModelIndex parent, int start, int end);
80 80 void modelDataAdded(QModelIndex parent, int start, int end);
81 81 void modelDataAboutToBeRemoved(QModelIndex parent, int start, int end);
82 82 void modelDataRemoved(QModelIndex parent, int start, int end);
83 83
84 84 Q_SIGNALS:
85 85 void clicked(const QPointF &point);
86 86 void selected();
87 87
88 88 private:
89 89 Q_DECLARE_PRIVATE(QXYSeries);
90 90 Q_DISABLE_COPY(QXYSeries);
91 91 friend class XYLegendMarker;
92 92 friend class XYChartItem;
93 93 };
94 94
95 95 QTCOMMERCIALCHART_END_NAMESPACE
96 96
97 97 #endif
@@ -1,79 +1,79
1 1 /****************************************************************************
2 2 **
3 3 ** Copyright (C) 2012 Digia Plc
4 4 ** All rights reserved.
5 5 ** For any questions to Digia, please use contact form at http://qt.digia.com
6 6 **
7 7 ** This file is part of the Qt Commercial Charts Add-on.
8 8 **
9 9 ** $QT_BEGIN_LICENSE$
10 10 ** Licensees holding valid Qt Commercial licenses may use this file in
11 11 ** accordance with the Qt Commercial License Agreement provided with the
12 12 ** Software or, alternatively, in accordance with the terms contained in
13 13 ** a written agreement between you and Digia.
14 14 **
15 15 ** If you have questions regarding the use of this file, please use
16 16 ** contact form at http://qt.digia.com
17 17 ** $QT_END_LICENSE$
18 18 **
19 19 ****************************************************************************/
20 20
21 21 // W A R N I N G
22 22 // -------------
23 23 //
24 24 // This file is not part of the QtCommercial Chart API. It exists purely as an
25 25 // implementation detail. This header file may change from version to
26 26 // version without notice, or even be removed.
27 27 //
28 28 // We mean it.
29 29
30 30 #ifndef QXYSERIES_P_H
31 31 #define QXYSERIES_P_H
32 32
33 #include "qseries_p.h"
33 #include "qabstractseries_p.h"
34 34
35 35 QTCOMMERCIALCHART_BEGIN_NAMESPACE
36 36
37 37 class QXYSeries;
38 38
39 class QXYSeriesPrivate: public QSeriesPrivate
39 class QXYSeriesPrivate: public QAbstractSeriesPrivate
40 40 {
41 41 Q_OBJECT
42 42
43 43 public:
44 44 QXYSeriesPrivate(QXYSeries* q);
45 45
46 46 void scaleDomain(Domain& domain);
47 47 QList<LegendMarker*> createLegendMarker(QLegend* legend);
48 48
49 49 Q_SIGNALS:
50 50 void updated();
51 51 void pointReplaced(int index);
52 52 void pointRemoved(int index);
53 53 void pointAdded(int index);
54 54
55 55 protected:
56 56 QVector<qreal> m_x;
57 57 QVector<qreal> m_y;
58 58
59 59 QPen m_pen;
60 60 QBrush m_brush;
61 61
62 62 int m_mapX;
63 63 int m_mapY;
64 64 int m_mapFirst;
65 65 int m_mapCount;
66 66 bool m_mapLimited;
67 67 Qt::Orientation m_mapOrientation;
68 68 int tempItemsRemoved;
69 69 bool m_pointsVisible;
70 70
71 71 private:
72 72 Q_DECLARE_PUBLIC(QXYSeries);
73 73 friend class QScatterSeries;
74 74
75 75 };
76 76
77 77 QTCOMMERCIALCHART_END_NAMESPACE
78 78
79 79 #endif
@@ -1,570 +1,570
1 1 /****************************************************************************
2 2 **
3 3 ** Copyright (C) 2012 Digia Plc
4 4 ** All rights reserved.
5 5 ** For any questions to Digia, please use contact form at http://qt.digia.com
6 6 **
7 7 ** This file is part of the Qt Commercial Charts Add-on.
8 8 **
9 9 ** $QT_BEGIN_LICENSE$
10 10 ** Licensees holding valid Qt Commercial licenses may use this file in
11 11 ** accordance with the Qt Commercial License Agreement provided with the
12 12 ** Software or, alternatively, in accordance with the terms contained in
13 13 ** a written agreement between you and Digia.
14 14 **
15 15 ** If you have questions regarding the use of this file, please use
16 16 ** contact form at http://qt.digia.com
17 17 ** $QT_END_LICENSE$
18 18 **
19 19 ****************************************************************************/
20 20
21 21 #include <QtTest/QtTest>
22 22 #include <qchartaxis.h>
23 23 #include <qlineseries.h>
24 24 #include <private/chartdataset_p.h>
25 25 #include <private/domain_p.h>
26 26
27 27 QTCOMMERCIALCHART_USE_NAMESPACE
28 28
29 Q_DECLARE_METATYPE(Domain*)
30 Q_DECLARE_METATYPE(QChartAxis*)
31 Q_DECLARE_METATYPE(QSeries*)
32 Q_DECLARE_METATYPE(QLineSeries*)
29 Q_DECLARE_METATYPE(Domain *)
30 Q_DECLARE_METATYPE(QChartAxis *)
31 Q_DECLARE_METATYPE(QAbstractSeries *)
32 Q_DECLARE_METATYPE(QLineSeries *)
33 33
34 34 class tst_ChartDataSet: public QObject {
35 35
36 36 Q_OBJECT
37 37
38 38 public Q_SLOTS:
39 39 void initTestCase();
40 40 void cleanupTestCase();
41 41 void init();
42 42 void cleanup();
43 43
44 44 private Q_SLOTS:
45 45 void chartdataset_data();
46 46 void chartdataset();
47 47 void addSeries_data();
48 48 void addSeries();
49 49 void removeSeries_data();
50 50 void removeSeries();
51 51 void removeAllSeries_data();
52 52 void removeAllSeries();
53 53 void axisY_data();
54 54 void axisY();
55 55 void seriesCount_data();
56 56 void seriesCount();
57 57 void seriesIndex_data();
58 58 void seriesIndex();
59 59 void domain_data();
60 60 void domain();
61 61 void zoomInDomain_data();
62 62 void zoomInDomain();
63 63 void zoomOutDomain_data();
64 64 void zoomOutDomain();
65 65 void scrollDomain_data();
66 66 void scrollDomain();
67 67 };
68 68
69 69 void tst_ChartDataSet::initTestCase()
70 70 {
71 71 qRegisterMetaType<Domain*>();
72 72 qRegisterMetaType<QChartAxis*>();
73 73 qRegisterMetaType<QSeries*>();
74 74 }
75 75
76 76 void tst_ChartDataSet::cleanupTestCase()
77 77 {
78 78 }
79 79
80 80 void tst_ChartDataSet::init()
81 81 {
82 82 }
83 83
84 84 void tst_ChartDataSet::cleanup()
85 85 {
86 86 }
87 87
88 88 void tst_ChartDataSet::chartdataset_data()
89 89 {
90 90 }
91 91
92 92 void tst_ChartDataSet::chartdataset()
93 93 {
94 94 ChartDataSet dataSet;
95 95 QVERIFY2(dataSet.axisX(), "Missing axisX.");
96 96 QVERIFY2(dataSet.axisY(), "Missing axisY.");
97 97 //check if not dangling pointer
98 98 dataSet.axisX()->objectName();
99 99 dataSet.axisY()->objectName();
100 100 QLineSeries* series = new QLineSeries(this);
101 101 QCOMPARE(dataSet.seriesIndex(series),-1);
102 102 }
103 103
104 104 void tst_ChartDataSet::addSeries_data()
105 105 {
106 106 QTest::addColumn<QLineSeries*>("series0");
107 107 QTest::addColumn<QChartAxis*>("axis0");
108 108 QTest::addColumn<QLineSeries*>("series1");
109 109 QTest::addColumn<QChartAxis*>("axis1");
110 110 QTest::addColumn<QLineSeries*>("series2");
111 111 QTest::addColumn<QChartAxis*>("axis2");
112 112 QTest::addColumn<int>("axisCount");
113 113
114 114 QLineSeries* series0 = new QLineSeries(this);
115 115 QLineSeries* series1 = new QLineSeries(this);
116 116 QLineSeries* series2 = new QLineSeries(this);
117 117
118 118 QChartAxis* axis0 = new QChartAxis(this);
119 119 QChartAxis* axis1 = new QChartAxis(this);
120 120 QChartAxis* axis2 = new QChartAxis(this);
121 121
122 122 QTest::newRow("default axis Y: series0,series1,series2") << series0 << (QChartAxis*)0 << series1 << (QChartAxis*)0 << series2 << (QChartAxis*)0 << 2;
123 123 QTest::newRow("default axis Y: series0, axis 0: series1,series2") << series0 << (QChartAxis*)0 << series1 << axis0 << series2 << axis0 << 3;
124 124 QTest::newRow("axis0: series0, axis1: series1, axis2: series2") << series0 << axis0 << series1 << axis1 << series2 << axis2 << 4;
125 125 }
126 126
127 127 void tst_ChartDataSet::addSeries()
128 128 {
129 129 QFETCH(QLineSeries*, series0);
130 130 QFETCH(QChartAxis*, axis0);
131 131 QFETCH(QLineSeries*, series1);
132 132 QFETCH(QChartAxis*, axis1);
133 133 QFETCH(QLineSeries*, series2);
134 134 QFETCH(QChartAxis*, axis2);
135 135 QFETCH(int, axisCount);
136 136
137 137 ChartDataSet dataSet;
138 138
139 139 QSignalSpy spy0(&dataSet, SIGNAL(axisAdded(QChartAxis*,Domain*)));
140 140 QSignalSpy spy1(&dataSet, SIGNAL(axisRemoved(QChartAxis*)));
141 QSignalSpy spy2(&dataSet, SIGNAL(seriesAdded(QSeries*,Domain*)));
142 QSignalSpy spy3(&dataSet, SIGNAL(seriesRemoved(QSeries*)));
141 QSignalSpy spy2(&dataSet, SIGNAL(seriesAdded(QAbstractSeries *,Domain*)));
142 QSignalSpy spy3(&dataSet, SIGNAL(seriesRemoved(QAbstractSeries *)));
143 143
144 144 dataSet.addSeries(series0,axis0);
145 145 dataSet.addSeries(series1,axis1);
146 146 dataSet.addSeries(series2,axis2);
147 147
148 148 QCOMPARE(spy0.count(), axisCount);
149 149 QCOMPARE(spy1.count(), 0);
150 150 QCOMPARE(spy2.count(), 3);
151 151 QCOMPARE(spy3.count(), 0);
152 152
153 153 if(axis0==0) axis0 = dataSet.axisY();
154 154 if(axis1==0) axis1 = dataSet.axisY();
155 155 if(axis2==0) axis2 = dataSet.axisY();
156 156
157 157 QVERIFY(axis0 == dataSet.removeSeries(series0));
158 158 QVERIFY(axis1 == dataSet.removeSeries(series1));
159 159 QVERIFY(axis2 == dataSet.removeSeries(series2));
160 160 }
161 161
162 162 void tst_ChartDataSet::removeSeries_data()
163 163 {
164 164 addSeries_data();
165 165 }
166 166
167 167 void tst_ChartDataSet::removeSeries()
168 168 {
169 169 QFETCH(QLineSeries*, series0);
170 170 QFETCH(QChartAxis*, axis0);
171 171 QFETCH(QLineSeries*, series1);
172 172 QFETCH(QChartAxis*, axis1);
173 173 QFETCH(QLineSeries*, series2);
174 174 QFETCH(QChartAxis*, axis2);
175 175 QFETCH(int, axisCount);
176 176
177 177 ChartDataSet dataSet;
178 178
179 179 dataSet.addSeries(series0,axis0);
180 180 dataSet.addSeries(series1,axis1);
181 181 dataSet.addSeries(series2,axis2);
182 182
183 QSignalSpy spy0(&dataSet, SIGNAL(axisAdded(QChartAxis*,Domain*)));
184 QSignalSpy spy1(&dataSet, SIGNAL(axisRemoved(QChartAxis*)));
185 QSignalSpy spy2(&dataSet, SIGNAL(seriesAdded(QSeries*,Domain*)));
186 QSignalSpy spy3(&dataSet, SIGNAL(seriesRemoved(QSeries*)));
183 QSignalSpy spy0(&dataSet, SIGNAL(axisAdded(QChartAxis *, Domain *)));
184 QSignalSpy spy1(&dataSet, SIGNAL(axisRemoved(QChartAxis *)));
185 QSignalSpy spy2(&dataSet, SIGNAL(seriesAdded(QAbstractSeries *, Domain *)));
186 QSignalSpy spy3(&dataSet, SIGNAL(seriesRemoved(QAbstractSeries *)));
187 187
188 188 dataSet.removeSeries(series0);
189 189 dataSet.removeSeries(series1);
190 190 dataSet.removeSeries(series2);
191 191
192 192 QCOMPARE(spy0.count(), 0);
193 193 QCOMPARE(spy1.count(), axisCount);
194 194 QCOMPARE(spy2.count(), 0);
195 195 QCOMPARE(spy3.count(), 3);
196 196 }
197 197
198 198 void tst_ChartDataSet::removeAllSeries_data()
199 199 {
200 200
201 201 }
202 202
203 203 void tst_ChartDataSet::removeAllSeries()
204 204 {
205 205 QLineSeries* series0 = new QLineSeries(this);
206 206 QLineSeries* series1 = new QLineSeries(this);
207 207 QLineSeries* series2 = new QLineSeries(this);
208 208
209 209 QChartAxis* axis0 = new QChartAxis(this);
210 210 QChartAxis* axis1 = new QChartAxis(this);
211 211 QChartAxis* axis2 = new QChartAxis(this);
212 212
213 213
214 214 ChartDataSet dataSet;
215 215
216 216 dataSet.addSeries(series0, axis0);
217 217 dataSet.addSeries(series1, axis1);
218 218 dataSet.addSeries(series2, axis2);
219 219
220 QSignalSpy spy0(&dataSet, SIGNAL(axisAdded(QChartAxis*,Domain*)));
221 QSignalSpy spy1(&dataSet, SIGNAL(axisRemoved(QChartAxis*)));
222 QSignalSpy spy2(&dataSet, SIGNAL(seriesAdded(QSeries*,Domain*)));
223 QSignalSpy spy3(&dataSet, SIGNAL(seriesRemoved(QSeries*)));
220 QSignalSpy spy0(&dataSet, SIGNAL(axisAdded(QChartAxis *, Domain *)));
221 QSignalSpy spy1(&dataSet, SIGNAL(axisRemoved(QChartAxis *)));
222 QSignalSpy spy2(&dataSet, SIGNAL(seriesAdded(QAbstractSeries *, Domain *)));
223 QSignalSpy spy3(&dataSet, SIGNAL(seriesRemoved(QAbstractSeries *)));
224 224
225 225 dataSet.removeAllSeries();
226 226
227 227 QCOMPARE(spy0.count(), 0);
228 228 QCOMPARE(spy1.count(), 4);
229 229 QCOMPARE(spy2.count(), 0);
230 230 QCOMPARE(spy3.count(), 3);
231 231 }
232 232
233 233
234 234 void tst_ChartDataSet::axisY_data()
235 235 {
236 236 QTest::addColumn<QChartAxis*>("axis0");
237 237 QTest::addColumn<QChartAxis*>("axis1");
238 238 QTest::addColumn<QChartAxis*>("axis2");
239 239 QTest::newRow("1 defualt, 2 optional") << (QChartAxis*)0 << new QChartAxis() << new QChartAxis();
240 240 QTest::newRow("3 optional") << new QChartAxis() << new QChartAxis() << new QChartAxis();
241 241 }
242 242
243 243 void tst_ChartDataSet::axisY()
244 244 {
245 245 QFETCH(QChartAxis*, axis0);
246 246 QFETCH(QChartAxis*, axis1);
247 247 QFETCH(QChartAxis*, axis2);
248 248
249 249 ChartDataSet dataSet;
250 250
251 251 QChartAxis* defaultAxisY = dataSet.axisY();
252 252
253 253 QVERIFY2(defaultAxisY, "Missing axisY.");
254 254
255 255 QLineSeries* series0 = new QLineSeries();
256 256 dataSet.addSeries(series0,axis0);
257 257
258 258 QLineSeries* series1 = new QLineSeries();
259 259 dataSet.addSeries(series1,axis1);
260 260
261 261 QLineSeries* series2 = new QLineSeries();
262 262 dataSet.addSeries(series2,axis2);
263 263
264 264 if(!axis0) axis0=defaultAxisY ;
265 265 if(!axis1) axis1=defaultAxisY ;
266 266 if(!axis2) axis2=defaultAxisY ;
267 267
268 268 QVERIFY(dataSet.axisY(series0) == axis0);
269 269 QVERIFY(dataSet.axisY(series1) == axis1);
270 270 QVERIFY(dataSet.axisY(series2) == axis2);
271 271
272 272 }
273 273
274 274 void tst_ChartDataSet::seriesCount_data()
275 275 {
276 276 addSeries_data();
277 277 }
278 278
279 279 void tst_ChartDataSet::seriesCount()
280 280 {
281 281 QFETCH(QLineSeries*, series0);
282 282 QFETCH(QChartAxis*, axis0);
283 283 QFETCH(QLineSeries*, series1);
284 284 QFETCH(QChartAxis*, axis1);
285 285 QFETCH(QLineSeries*, series2);
286 286 QFETCH(QChartAxis*, axis2);
287 287 QFETCH(int, axisCount);
288 288 Q_UNUSED(axisCount);
289 289
290 290 ChartDataSet dataSet;
291 291
292 292 dataSet.addSeries(series0, axis0);
293 293 dataSet.addSeries(series1, axis1);
294 294 dataSet.addSeries(series2, axis2);
295 295
296 QSignalSpy spy0(&dataSet, SIGNAL(axisAdded(QChartAxis*,Domain*)));
297 QSignalSpy spy1(&dataSet, SIGNAL(axisRemoved(QChartAxis*)));
298 QSignalSpy spy2(&dataSet, SIGNAL(seriesAdded(QSeries*,Domain*)));
299 QSignalSpy spy3(&dataSet, SIGNAL(seriesRemoved(QSeries*)));
296 QSignalSpy spy0(&dataSet, SIGNAL(axisAdded(QChartAxis *, Domain *)));
297 QSignalSpy spy1(&dataSet, SIGNAL(axisRemoved(QChartAxis *)));
298 QSignalSpy spy2(&dataSet, SIGNAL(seriesAdded(QAbstractSeries *, Domain *)));
299 QSignalSpy spy3(&dataSet, SIGNAL(seriesRemoved(QAbstractSeries *)));
300 300
301 301 QCOMPARE(dataSet.seriesCount(series0->type()),3);
302 302 QCOMPARE(spy0.count(), 0);
303 303 QCOMPARE(spy1.count(), 0);
304 304 QCOMPARE(spy2.count(), 0);
305 305 QCOMPARE(spy3.count(), 0);
306 306
307 307 dataSet.removeSeries(series0);
308 308 dataSet.removeSeries(series1);
309 309 dataSet.removeSeries(series2);
310 310 }
311 311
312 312 void tst_ChartDataSet::seriesIndex_data()
313 313 {
314 314 addSeries_data();
315 315 }
316 316
317 317 void tst_ChartDataSet::seriesIndex()
318 318 {
319 319 //TODO: rewrite this series_index_data to match better
320 320
321 321 QFETCH(QLineSeries*, series0);
322 322 QFETCH(QChartAxis*, axis0);
323 323 QFETCH(QLineSeries*, series1);
324 324 QFETCH(QChartAxis*, axis1);
325 325 QFETCH(QLineSeries*, series2);
326 326 QFETCH(QChartAxis*, axis2);
327 327 QFETCH(int, axisCount);
328 328 Q_UNUSED(axisCount);
329 329
330 330 ChartDataSet dataSet;
331 331
332 332 dataSet.addSeries(series0, axis0);
333 333 dataSet.addSeries(series1, axis1);
334 334 dataSet.addSeries(series2, axis2);
335 335
336 336 QSignalSpy spy0(&dataSet, SIGNAL(axisAdded(QChartAxis*,Domain*)));
337 337 QSignalSpy spy1(&dataSet, SIGNAL(axisRemoved(QChartAxis*)));
338 338 QSignalSpy spy2(&dataSet, SIGNAL(seriesAdded(QSeries*,Domain*)));
339 339 QSignalSpy spy3(&dataSet, SIGNAL(seriesRemoved(QSeries*)));
340 340
341 341 QCOMPARE(dataSet.seriesIndex(series0),0);
342 342 QCOMPARE(dataSet.seriesIndex(series1),1);
343 343 QCOMPARE(dataSet.seriesIndex(series2),2);
344 344
345 345 QCOMPARE(spy0.count(), 0);
346 346 QCOMPARE(spy1.count(), 0);
347 347 QCOMPARE(spy2.count(), 0);
348 348 QCOMPARE(spy3.count(), 0);
349 349
350 350 dataSet.removeSeries(series0);
351 351 dataSet.removeSeries(series1);
352 352 dataSet.removeSeries(series2);
353 353
354 354 QCOMPARE(dataSet.seriesIndex(series0),-1);
355 355 QCOMPARE(dataSet.seriesIndex(series1),-1);
356 356 QCOMPARE(dataSet.seriesIndex(series2),-1);
357 357
358 358 dataSet.addSeries(series0, axis0);
359 359 dataSet.addSeries(series1, axis1);
360 360 dataSet.addSeries(series2, axis2);
361 361
362 362 QCOMPARE(dataSet.seriesIndex(series0),0);
363 363 QCOMPARE(dataSet.seriesIndex(series1),1);
364 364 QCOMPARE(dataSet.seriesIndex(series2),2);
365 365
366 366 dataSet.removeSeries(series1);
367 367
368 368 QCOMPARE(dataSet.seriesIndex(series0),0);
369 369 QCOMPARE(dataSet.seriesIndex(series1),-1);
370 370 QCOMPARE(dataSet.seriesIndex(series2),2);
371 371
372 372 dataSet.addSeries(series1, axis1);
373 373 QCOMPARE(dataSet.seriesIndex(series0),0);
374 374 QCOMPARE(dataSet.seriesIndex(series1),1);
375 375 QCOMPARE(dataSet.seriesIndex(series2),2);
376 376
377 377 dataSet.removeSeries(series2);
378 378 QCOMPARE(dataSet.seriesIndex(series0),0);
379 379 QCOMPARE(dataSet.seriesIndex(series1),1);
380 380 QCOMPARE(dataSet.seriesIndex(series2),-1);
381 381
382 382 dataSet.removeSeries(series0);
383 383 QCOMPARE(dataSet.seriesIndex(series0),-1);
384 384 QCOMPARE(dataSet.seriesIndex(series1),1);
385 385 QCOMPARE(dataSet.seriesIndex(series2),-1);
386 386
387 387 dataSet.addSeries(series2);
388 388 QCOMPARE(dataSet.seriesIndex(series0),-1);
389 389 QCOMPARE(dataSet.seriesIndex(series1),1);
390 390 QCOMPARE(dataSet.seriesIndex(series2),0);
391 391
392 392 dataSet.addSeries(series0);
393 393 QCOMPARE(dataSet.seriesIndex(series0),2);
394 394 QCOMPARE(dataSet.seriesIndex(series1),1);
395 395 QCOMPARE(dataSet.seriesIndex(series2),0);
396 396
397 397 dataSet.removeSeries(series0);
398 398 dataSet.removeSeries(series1);
399 399 dataSet.removeSeries(series2);
400 400
401 401 }
402 402
403 403 void tst_ChartDataSet::domain_data()
404 404 {
405 405 addSeries_data();
406 406 }
407 407
408 408 void tst_ChartDataSet::domain()
409 409 {
410 410 QFETCH(QLineSeries*, series0);
411 411 QFETCH(QChartAxis*, axis0);
412 412 QFETCH(QLineSeries*, series1);
413 413 QFETCH(QChartAxis*, axis1);
414 414 QFETCH(QLineSeries*, series2);
415 415 QFETCH(QChartAxis*, axis2);
416 416 QFETCH(int, axisCount);
417 417 Q_UNUSED(axisCount);
418 418
419 419 ChartDataSet dataSet;
420 420
421 421 dataSet.addSeries(series0, axis0);
422 422 dataSet.addSeries(series1, axis1);
423 423 dataSet.addSeries(series2, axis2);
424 424
425 QSignalSpy spy0(&dataSet, SIGNAL(axisAdded(QChartAxis*,Domain*)));
426 QSignalSpy spy1(&dataSet, SIGNAL(axisRemoved(QChartAxis*)));
427 QSignalSpy spy2(&dataSet, SIGNAL(seriesAdded(QSeries*,Domain*)));
428 QSignalSpy spy3(&dataSet, SIGNAL(seriesRemoved(QSeries*)));
425 QSignalSpy spy0(&dataSet, SIGNAL(axisAdded(QChartAxis *, Domain *)));
426 QSignalSpy spy1(&dataSet, SIGNAL(axisRemoved(QChartAxis *)));
427 QSignalSpy spy2(&dataSet, SIGNAL(seriesAdded(QAbstractSeries *, Domain *)));
428 QSignalSpy spy3(&dataSet, SIGNAL(seriesRemoved(QAbstractSeries *)));
429 429
430 430 QVERIFY(dataSet.domain(axis0)==dataSet.domain(series0));
431 431 QVERIFY(dataSet.domain(axis1)==dataSet.domain(series1));
432 432 QVERIFY(dataSet.domain(axis2)==dataSet.domain(series2));
433 433 QCOMPARE(spy0.count(), 0);
434 434 QCOMPARE(spy1.count(), 0);
435 435 QCOMPARE(spy2.count(), 0);
436 436 QCOMPARE(spy3.count(), 0);
437 437
438 438 dataSet.removeSeries(series0);
439 439 dataSet.removeSeries(series1);
440 440 dataSet.removeSeries(series2);
441 441 }
442 442
443 443 void tst_ChartDataSet::zoomInDomain_data()
444 444 {
445 445 addSeries_data();
446 446 }
447 447
448 448 void tst_ChartDataSet::zoomInDomain()
449 449 {
450 450 QFETCH(QLineSeries*, series0);
451 451 QFETCH(QChartAxis*, axis0);
452 452 QFETCH(QLineSeries*, series1);
453 453 QFETCH(QChartAxis*, axis1);
454 454 QFETCH(QLineSeries*, series2);
455 455 QFETCH(QChartAxis*, axis2);
456 456 QFETCH(int, axisCount);
457 457
458 458 Q_UNUSED(axisCount);
459 459 ChartDataSet dataSet;
460 460
461 461 dataSet.addSeries(series0, axis0);
462 462 dataSet.addSeries(series1, axis1);
463 463 dataSet.addSeries(series2, axis2);
464 464
465 465 Domain* domain0 = dataSet.domain(series0);
466 466 Domain* domain1 = dataSet.domain(series1);
467 467 Domain* domain2 = dataSet.domain(series2);
468 468
469 469 QSignalSpy spy0(domain0, SIGNAL(domainChanged(qreal,qreal,qreal,qreal)));
470 470 QSignalSpy spy1(domain1, SIGNAL(domainChanged(qreal,qreal,qreal,qreal)));
471 471 QSignalSpy spy2(domain2, SIGNAL(domainChanged(qreal,qreal,qreal,qreal)));
472 472
473 473 dataSet.zoomInDomain(QRect(0,0,100,100),QSize(1000,1000));
474 474
475 475 QCOMPARE(spy0.count(), 1);
476 476 QCOMPARE(spy1.count(), 1);
477 477 QCOMPARE(spy2.count(), 1);
478 478
479 479 dataSet.removeSeries(series0);
480 480 dataSet.removeSeries(series1);
481 481 dataSet.removeSeries(series2);
482 482 }
483 483
484 484 void tst_ChartDataSet::zoomOutDomain_data()
485 485 {
486 486 addSeries_data();
487 487 }
488 488
489 489 void tst_ChartDataSet::zoomOutDomain()
490 490 {
491 491 QFETCH(QLineSeries*, series0);
492 492 QFETCH(QChartAxis*, axis0);
493 493 QFETCH(QLineSeries*, series1);
494 494 QFETCH(QChartAxis*, axis1);
495 495 QFETCH(QLineSeries*, series2);
496 496 QFETCH(QChartAxis*, axis2);
497 497 QFETCH(int, axisCount);
498 498
499 499 Q_UNUSED(axisCount);
500 500
501 501 ChartDataSet dataSet;
502 502
503 503 dataSet.addSeries(series0, axis0);
504 504 dataSet.addSeries(series1, axis1);
505 505 dataSet.addSeries(series2, axis2);
506 506
507 507 Domain* domain0 = dataSet.domain(series0);
508 508 Domain* domain1 = dataSet.domain(series1);
509 509 Domain* domain2 = dataSet.domain(series2);
510 510
511 511 QSignalSpy spy0(domain0, SIGNAL(domainChanged(qreal,qreal,qreal,qreal)));
512 512 QSignalSpy spy1(domain1, SIGNAL(domainChanged(qreal,qreal,qreal,qreal)));
513 513 QSignalSpy spy2(domain2, SIGNAL(domainChanged(qreal,qreal,qreal,qreal)));
514 514
515 515 dataSet.zoomOutDomain(QRect(0,0,100,100),QSize(1000,1000));
516 516
517 517 QCOMPARE(spy0.count(), 1);
518 518 QCOMPARE(spy1.count(), 1);
519 519 QCOMPARE(spy2.count(), 1);
520 520
521 521 dataSet.removeSeries(series0);
522 522 dataSet.removeSeries(series1);
523 523 dataSet.removeSeries(series2);
524 524 }
525 525
526 526 void tst_ChartDataSet::scrollDomain_data()
527 527 {
528 528 addSeries_data();
529 529 }
530 530
531 531 void tst_ChartDataSet::scrollDomain()
532 532 {
533 533 QFETCH(QLineSeries*, series0);
534 534 QFETCH(QChartAxis*, axis0);
535 535 QFETCH(QLineSeries*, series1);
536 536 QFETCH(QChartAxis*, axis1);
537 537 QFETCH(QLineSeries*, series2);
538 538 QFETCH(QChartAxis*, axis2);
539 539 QFETCH(int, axisCount);
540 540
541 541 Q_UNUSED(axisCount);
542 542
543 543 ChartDataSet dataSet;
544 544
545 545 dataSet.addSeries(series0, axis0);
546 546 dataSet.addSeries(series1, axis1);
547 547 dataSet.addSeries(series2, axis2);
548 548
549 549 Domain* domain0 = dataSet.domain(series0);
550 550 Domain* domain1 = dataSet.domain(series1);
551 551 Domain* domain2 = dataSet.domain(series2);
552 552
553 553 QSignalSpy spy0(domain0, SIGNAL(domainChanged(qreal,qreal,qreal,qreal)));
554 554 QSignalSpy spy1(domain1, SIGNAL(domainChanged(qreal,qreal,qreal,qreal)));
555 555 QSignalSpy spy2(domain2, SIGNAL(domainChanged(qreal,qreal,qreal,qreal)));
556 556
557 557 dataSet.scrollDomain(10,10,QSize(1000,1000));
558 558
559 559 QCOMPARE(spy0.count(), 1);
560 560 QCOMPARE(spy1.count(), 1);
561 561 QCOMPARE(spy2.count(), 1);
562 562
563 563 dataSet.removeSeries(series0);
564 564 dataSet.removeSeries(series1);
565 565 dataSet.removeSeries(series2);
566 566 }
567 567
568 568 QTEST_MAIN(tst_ChartDataSet)
569 569 #include "tst_chartdataset.moc"
570 570
@@ -1,572 +1,572
1 1 #include <QtTest/QtTest>
2 2 #include <qchartview.h>
3 3 #include <qlineseries.h>
4 4 #include <qareaseries.h>
5 5 #include <qscatterseries.h>
6 6 #include <qsplineseries.h>
7 7 #include <qpieseries.h>
8 8 #include <qbarseries.h>
9 9 #include <qpercentbarseries.h>
10 10 #include <qstackedbarseries.h>
11 11
12 12 QTCOMMERCIALCHART_USE_NAMESPACE
13 13
14 Q_DECLARE_METATYPE(QChartAxis*)
15 Q_DECLARE_METATYPE(QSeries*)
14 Q_DECLARE_METATYPE(QChartAxis *)
15 Q_DECLARE_METATYPE(QAbstractSeries *)
16 16 Q_DECLARE_METATYPE(QChart::AnimationOption)
17 17 Q_DECLARE_METATYPE(QBrush)
18 18 Q_DECLARE_METATYPE(QPen)
19 19 Q_DECLARE_METATYPE(QChart::ChartTheme)
20 20
21 21 class tst_QChart : public QObject
22 22 {
23 23 Q_OBJECT
24 24
25 25 public slots:
26 26 void initTestCase();
27 27 void cleanupTestCase();
28 28 void init();
29 29 void cleanup();
30 30
31 31 private slots:
32 32 void qchart_data();
33 33 void qchart();
34 34
35 35 void addSeries_data();
36 36 void addSeries();
37 37 void animationOptions_data();
38 38 void animationOptions();
39 39 void axisX_data();
40 40 void axisX();
41 41 void axisY_data();
42 42 void axisY();
43 43 void backgroundBrush_data();
44 44 void backgroundBrush();
45 45 void backgroundPen_data();
46 46 void backgroundPen();
47 47 void isBackgroundVisible_data();
48 48 void isBackgroundVisible();
49 49 void legend_data();
50 50 void legend();
51 51 void margins_data();
52 52 void margins();
53 53 void removeAllSeries_data();
54 54 void removeAllSeries();
55 55 void removeSeries_data();
56 56 void removeSeries();
57 57 void scrollDown_data();
58 58 void scrollDown();
59 59 void scrollLeft_data();
60 60 void scrollLeft();
61 61 void scrollRight_data();
62 62 void scrollRight();
63 63 void scrollUp_data();
64 64 void scrollUp();
65 65 void theme_data();
66 66 void theme();
67 67 void title_data();
68 68 void title();
69 69 void titleBrush_data();
70 70 void titleBrush();
71 71 void titleFont_data();
72 72 void titleFont();
73 73 void zoomIn_data();
74 74 void zoomIn();
75 75 void zoomOut_data();
76 76 void zoomOut();
77 77
78 78 private:
79 79 void createTestData();
80 80
81 81 private:
82 82 QChartView* m_view;
83 83 QChart* m_chart;
84 84 };
85 85
86 86 void tst_QChart::initTestCase()
87 87 {
88 88
89 89 }
90 90
91 91 void tst_QChart::cleanupTestCase()
92 92 {
93 93
94 94 }
95 95
96 96 void tst_QChart::init()
97 97 {
98 98 m_view = new QChartView(new QChart());
99 99 m_chart = m_view->chart();
100 100 }
101 101
102 102 void tst_QChart::createTestData()
103 103 {
104 104 QLineSeries* series0 = new QLineSeries(this);
105 105 *series0 << QPointF(0, 0) << QPointF(100, 100);
106 106 m_chart->addSeries(series0);
107 107 m_view->show();
108 108 QTest::qWaitForWindowShown(m_view);
109 109 }
110 110
111 111 void tst_QChart::cleanup()
112 112 {
113 113 delete m_view;
114 114 m_view = 0;
115 115 m_chart = 0;
116 116 }
117 117
118 118 void tst_QChart::qchart_data()
119 119 {
120 120 }
121 121
122 122 void tst_QChart::qchart()
123 123 {
124 124 QVERIFY(m_chart);
125 125 QVERIFY(m_chart->legend());
126 126 QVERIFY(!m_chart->legend()->isVisible());
127 127
128 128 QCOMPARE(m_chart->animationOptions(), QChart::NoAnimation);
129 129 QVERIFY(m_chart->axisX());
130 130 QVERIFY(m_chart->axisY());
131 131 QVERIFY(m_chart->backgroundBrush()!=QBrush());
132 132 QVERIFY(m_chart->backgroundPen()!=QPen());
133 133 QCOMPARE(m_chart->isBackgroundVisible(), true);
134 134
135 135 QVERIFY(m_chart->margins().top()>0);
136 136 QVERIFY(m_chart->margins().left()>0);
137 137 QVERIFY(m_chart->margins().right()>0);
138 138 QVERIFY(m_chart->margins().bottom()>0);
139 139
140 140 QCOMPARE(m_chart->theme(), QChart::ChartThemeLight);
141 141 QCOMPARE(m_chart->title(), QString());
142 142
143 143 //QCOMPARE(m_chart->titleBrush(),QBrush());
144 144 //QCOMPARE(m_chart->titleFont(),QFont());
145 145
146 146 m_chart->removeAllSeries();
147 147 m_chart->scrollDown();
148 148 m_chart->scrollLeft();
149 149 m_chart->scrollRight();
150 150 m_chart->scrollUp();
151 151
152 152 m_chart->zoomIn();
153 153 m_chart->zoomIn(QRectF());
154 154 m_chart->zoomOut();
155 155 }
156 156
157 157 void tst_QChart::addSeries_data()
158 158 {
159 QTest::addColumn<QSeries*>("series");
160 QTest::addColumn<QChartAxis*>("axis");
159 QTest::addColumn<QAbstractSeries *>("series");
160 QTest::addColumn<QChartAxis *>("axis");
161 161
162 QSeries* series0 = new QLineSeries(this);
163 QSeries* series1 = new QAreaSeries(static_cast<QLineSeries*>(series0));
164 QSeries* series2 = new QScatterSeries(this);
165 QSeries* series3 = new QSplineSeries(this);
166 QSeries* series4 = new QPieSeries(this);
167 QSeries* series5 = new QBarSeries(QBarCategories(),this);
168 QSeries* series6 = new QPercentBarSeries(QBarCategories(),this);
169 QSeries* series7 = new QStackedBarSeries(QBarCategories(),this);
162 QAbstractSeries* series0 = new QLineSeries(this);
163 QAbstractSeries* series1 = new QAreaSeries(static_cast<QLineSeries*>(series0));
164 QAbstractSeries* series2 = new QScatterSeries(this);
165 QAbstractSeries* series3 = new QSplineSeries(this);
166 QAbstractSeries* series4 = new QPieSeries(this);
167 QAbstractSeries* series5 = new QBarSeries(QBarCategories(),this);
168 QAbstractSeries* series6 = new QPercentBarSeries(QBarCategories(),this);
169 QAbstractSeries* series7 = new QStackedBarSeries(QBarCategories(),this);
170 170
171 171 QChartAxis* axis = new QChartAxis(this);
172 172
173 173 QTest::newRow("default axis: lineSeries") << series0 << (QChartAxis*) 0;
174 174 QTest::newRow("axis0: lineSeries") << series0 << axis;
175 175 QTest::newRow("default axis: areaSeries") << series1 << (QChartAxis*) 0;
176 176 QTest::newRow("axis: areaSeries") << series1 << axis;
177 177 QTest::newRow("default axis: scatterSeries") << series2 << (QChartAxis*) 0;
178 178 QTest::newRow("axis1: scatterSeries") << series2 << axis;
179 179 QTest::newRow("default axis: splineSeries") << series3 << (QChartAxis*) 0;
180 180 QTest::newRow("axis: splineSeries") << series3 << axis;
181 181 QTest::newRow("default axis: pieSeries") << series4 << (QChartAxis*) 0;
182 182 QTest::newRow("axis: pieSeries") << series4 << axis;
183 183 QTest::newRow("default axis: barSeries") << series5 << (QChartAxis*) 0;
184 184 QTest::newRow("axis: barSeries") << series5 << axis;
185 185 QTest::newRow("default axis: percentBarSeries") << series6 << (QChartAxis*) 0;
186 186 QTest::newRow("axis: barSeries") << series6 << axis;
187 187 QTest::newRow("default axis: stackedBarSeries") << series7 << (QChartAxis*) 0;
188 188 QTest::newRow("axis: barSeries") << series7 << axis;
189 189
190 190 }
191 191
192 192 void tst_QChart::addSeries()
193 193 {
194 QFETCH(QSeries*, series);
195 QFETCH(QChartAxis*, axis);
194 QFETCH(QAbstractSeries *, series);
195 QFETCH(QChartAxis *, axis);
196 196 m_view->show();
197 197 QTest::qWaitForWindowShown(m_view);
198 198 if(!axis) axis = m_chart->axisY();
199 199 m_chart->addSeries(series,axis);
200 200 QCOMPARE(m_chart->axisY(series),axis);
201 201 m_chart->removeSeries(series);
202 202
203 203 }
204 204
205 205 void tst_QChart::animationOptions_data()
206 206 {
207 207 QTest::addColumn<QChart::AnimationOption>("animationOptions");
208 208 QTest::newRow("AllAnimations") << QChart::AllAnimations;
209 209 QTest::newRow("NoAnimation") << QChart::NoAnimation;
210 210 QTest::newRow("GridAxisAnimations") << QChart::GridAxisAnimations;
211 211 QTest::newRow("SeriesAnimations") << QChart::SeriesAnimations;
212 212 }
213 213
214 214 void tst_QChart::animationOptions()
215 215 {
216 216 createTestData();
217 217 QFETCH(QChart::AnimationOption, animationOptions);
218 218 m_chart->setAnimationOptions(animationOptions);
219 219 QCOMPARE(m_chart->animationOptions(), animationOptions);
220 220 }
221 221
222 222 void tst_QChart::axisX_data()
223 223 {
224 224
225 225 }
226 226
227 227 void tst_QChart::axisX()
228 228 {
229 229 QVERIFY(m_chart->axisX());
230 230 QChartAxis* axis = m_chart->axisX();
231 231 createTestData();
232 232 //it should be the same axis
233 233 QCOMPARE(axis,m_chart->axisX());
234 234 }
235 235
236 236 void tst_QChart::axisY_data()
237 237 {
238 238 QTest::addColumn<QChartAxis*>("axis0");
239 239 QTest::addColumn<QChartAxis*>("axis1");
240 240 QTest::addColumn<QChartAxis*>("axis2");
241 241 QTest::newRow("1 defualt, 2 optional") << (QChartAxis*)0 << new QChartAxis() << new QChartAxis();
242 242 QTest::newRow("3 optional") << new QChartAxis() << new QChartAxis() << new QChartAxis();
243 243 }
244 244
245 245
246 246 void tst_QChart::axisY()
247 247 {
248 248 QFETCH(QChartAxis*, axis0);
249 249 QFETCH(QChartAxis*, axis1);
250 250 QFETCH(QChartAxis*, axis2);
251 251
252 252 QChartAxis* defaultAxisY = m_chart->axisY();
253 253
254 254 QVERIFY2(defaultAxisY, "Missing axisY.");
255 255
256 256 QLineSeries* series0 = new QLineSeries();
257 257 m_chart->addSeries(series0, axis0);
258 258
259 259 QLineSeries* series1 = new QLineSeries();
260 260 m_chart->addSeries(series1, axis1);
261 261
262 262 QLineSeries* series2 = new QLineSeries();
263 263 m_chart->addSeries(series2, axis2);
264 264
265 265 if (!axis0)
266 266 axis0 = defaultAxisY;
267 267 if (!axis1)
268 268 axis1 = defaultAxisY;
269 269 if (!axis2)
270 270 axis2 = defaultAxisY;
271 271
272 272 QVERIFY(m_chart->axisY(series0) == axis0);
273 273 QVERIFY(m_chart->axisY(series1) == axis1);
274 274 QVERIFY(m_chart->axisY(series2) == axis2);
275 275 }
276 276
277 277 void tst_QChart::backgroundBrush_data()
278 278 {
279 279 QTest::addColumn<QBrush>("backgroundBrush");
280 280 QTest::newRow("null") << QBrush();
281 281 QTest::newRow("blue") << QBrush(Qt::blue);
282 282 QTest::newRow("white") << QBrush(Qt::white);
283 283 QTest::newRow("black") << QBrush(Qt::black);
284 284 }
285 285
286 286 void tst_QChart::backgroundBrush()
287 287 {
288 288 QFETCH(QBrush, backgroundBrush);
289 289 m_chart->setBackgroundBrush(backgroundBrush);
290 290 QCOMPARE(m_chart->backgroundBrush(), backgroundBrush);
291 291 }
292 292
293 293 void tst_QChart::backgroundPen_data()
294 294 {
295 295 QTest::addColumn<QPen>("backgroundPen");
296 296 QTest::newRow("null") << QPen();
297 297 QTest::newRow("blue") << QPen(Qt::blue);
298 298 QTest::newRow("white") << QPen(Qt::white);
299 299 QTest::newRow("black") << QPen(Qt::black);
300 300 }
301 301
302 302
303 303 void tst_QChart::backgroundPen()
304 304 {
305 305 QFETCH(QPen, backgroundPen);
306 306 m_chart->setBackgroundPen(backgroundPen);
307 307 QCOMPARE(m_chart->backgroundPen(), backgroundPen);
308 308 }
309 309
310 310 void tst_QChart::isBackgroundVisible_data()
311 311 {
312 312 QTest::addColumn<bool>("isBackgroundVisible");
313 313 QTest::newRow("true") << true;
314 314 QTest::newRow("false") << false;
315 315 }
316 316
317 317 void tst_QChart::isBackgroundVisible()
318 318 {
319 319 QFETCH(bool, isBackgroundVisible);
320 320 m_chart->setBackgroundVisible(isBackgroundVisible);
321 321 QCOMPARE(m_chart->isBackgroundVisible(), isBackgroundVisible);
322 322
323 323 }
324 324
325 325 void tst_QChart::legend_data()
326 326 {
327 327
328 328 }
329 329
330 330 void tst_QChart::legend()
331 331 {
332 332 QVERIFY(m_chart->legend());
333 333 }
334 334
335 335 void tst_QChart::margins_data()
336 336 {
337 337
338 338 }
339 339
340 340 void tst_QChart::margins()
341 341 {QTest::addColumn<int>("seriesCount");
342 342 QTest::newRow("0") << 0;
343 343 QTest::newRow("-1") << -1;
344 344 createTestData();
345 345 QRectF rect = m_chart->geometry();
346 346
347 347 QVERIFY(m_chart->margins().top()+m_chart->margins().bottom() < rect.height());
348 348 QVERIFY(m_chart->margins().left()+m_chart->margins().right() < rect.width());
349 349
350 350 }
351 351
352 352 void tst_QChart::removeAllSeries_data()
353 353 {
354 354
355 355 }
356 356
357 357 void tst_QChart::removeAllSeries()
358 358 {
359 359 QLineSeries* series0 = new QLineSeries(this);
360 360 QLineSeries* series1 = new QLineSeries(this);
361 361 QLineSeries* series2 = new QLineSeries(this);
362 362
363 363 m_chart->addSeries(series0);
364 364 m_chart->addSeries(series1);
365 365 m_chart->addSeries(series2);
366 366 m_view->show();
367 367 QTest::qWaitForWindowShown(m_view);
368 368
369 369 QVERIFY(m_chart->axisY(series0)!=0);
370 370 QVERIFY(m_chart->axisY(series1)!=0);
371 371 QVERIFY(m_chart->axisY(series2)!=0);
372 372
373 373 m_chart->removeAllSeries();
374 374
375 375 QVERIFY(m_chart->axisY(series0)==0);
376 376 QVERIFY(m_chart->axisY(series1)==0);
377 377 QVERIFY(m_chart->axisY(series2)==0);
378 378 }
379 379
380 380 void tst_QChart::removeSeries_data()
381 381 {
382 382 addSeries_data();
383 383 }
384 384
385 385 void tst_QChart::removeSeries()
386 386 {
387 QFETCH(QSeries*, series);
388 QFETCH(QChartAxis*, axis);
387 QFETCH(QAbstractSeries *, series);
388 QFETCH(QChartAxis *, axis);
389 389 m_view->show();
390 390 QTest::qWaitForWindowShown(m_view);
391 391 if(!axis) axis = m_chart->axisY();
392 392 m_chart->addSeries(series,axis);
393 393 QCOMPARE(m_chart->axisY(series),axis);
394 394 m_chart->removeSeries(series);
395 395 QVERIFY(m_chart->axisY(series)==0);
396 396 }
397 397
398 398 void tst_QChart::scrollDown_data()
399 399 {
400 400
401 401 }
402 402
403 403 void tst_QChart::scrollDown()
404 404 {
405 405 createTestData();
406 406 qreal min = m_chart->axisY()->min();
407 407 m_chart->scrollDown();
408 408 QVERIFY(m_chart->axisY()->min()<min);
409 409 }
410 410
411 411 void tst_QChart::scrollLeft_data()
412 412 {
413 413
414 414 }
415 415
416 416 void tst_QChart::scrollLeft()
417 417 {
418 418 createTestData();
419 419 qreal min = m_chart->axisX()->min();
420 420 m_chart->scrollLeft();
421 421 QVERIFY(m_chart->axisX()->min()<min);
422 422 }
423 423
424 424 void tst_QChart::scrollRight_data()
425 425 {
426 426
427 427 }
428 428
429 429 void tst_QChart::scrollRight()
430 430 {
431 431 createTestData();
432 432 qreal min = m_chart->axisX()->min();
433 433 m_chart->scrollRight();
434 434 QVERIFY(m_chart->axisX()->min()>min);
435 435 }
436 436
437 437 void tst_QChart::scrollUp_data()
438 438 {
439 439
440 440 }
441 441
442 442 void tst_QChart::scrollUp()
443 443 {
444 444 createTestData();
445 445 qreal min = m_chart->axisY()->min();
446 446 m_chart->scrollUp();
447 447 QVERIFY(m_chart->axisY()->min()>min);
448 448 }
449 449
450 450 void tst_QChart::theme_data()
451 451 {
452 452 QTest::addColumn<QChart::ChartTheme>("theme");
453 453 QTest::newRow("ChartThemeBlueCerulean") << QChart::ChartThemeBlueCerulean;
454 454 QTest::newRow("ChartThemeBlueIcy") << QChart::ChartThemeBlueIcy;
455 455 QTest::newRow("ChartThemeBlueNcs") << QChart::ChartThemeBlueNcs;
456 456 QTest::newRow("ChartThemeBrownSand") << QChart::ChartThemeBrownSand;
457 457 QTest::newRow("ChartThemeDark") << QChart::ChartThemeDark;
458 458 QTest::newRow("hartThemeHighContrast") << QChart::ChartThemeHighContrast;
459 459 QTest::newRow("ChartThemeLight") << QChart::ChartThemeLight;
460 460 }
461 461
462 462 void tst_QChart::theme()
463 463 {
464 464 QFETCH(QChart::ChartTheme, theme);
465 465 createTestData();
466 466 m_chart->setTheme(theme);
467 467 QVERIFY(m_chart->theme()==theme);
468 468 }
469 469
470 470 void tst_QChart::title_data()
471 471 {
472 472 QTest::addColumn<QString>("title");
473 473 QTest::newRow("null") << QString();
474 474 QTest::newRow("foo") << QString("foo");
475 475 }
476 476
477 477 void tst_QChart::title()
478 478 {
479 479 QFETCH(QString, title);
480 480 m_chart->setTitle(title);
481 481 QCOMPARE(m_chart->title(), title);
482 482 }
483 483
484 484 void tst_QChart::titleBrush_data()
485 485 {
486 486 QTest::addColumn<QBrush>("titleBrush");
487 487 QTest::newRow("null") << QBrush();
488 488 QTest::newRow("blue") << QBrush(Qt::blue);
489 489 QTest::newRow("white") << QBrush(Qt::white);
490 490 QTest::newRow("black") << QBrush(Qt::black);
491 491 }
492 492
493 493 void tst_QChart::titleBrush()
494 494 {
495 495 QFETCH(QBrush, titleBrush);
496 496 m_chart->setTitleBrush(titleBrush);
497 497 QCOMPARE(m_chart->titleBrush(), titleBrush);
498 498 }
499 499
500 500 void tst_QChart::titleFont_data()
501 501 {
502 502 QTest::addColumn<QFont>("titleFont");
503 503 QTest::newRow("null") << QFont();
504 504 QTest::newRow("courier") << QFont("Courier", 8, QFont::Bold, true);
505 505 }
506 506
507 507 void tst_QChart::titleFont()
508 508 {
509 509 QFETCH(QFont, titleFont);
510 510 m_chart->setTitleFont(titleFont);
511 511 QCOMPARE(m_chart->titleFont(), titleFont);
512 512 }
513 513
514 514 void tst_QChart::zoomIn_data()
515 515 {
516 516 QTest::addColumn<QRectF>("rect");
517 517 QTest::newRow("null") << QRectF();
518 518 QTest::newRow("100x100") << QRectF(10,10,100,100);
519 519 QTest::newRow("200x200") << QRectF(10,10,200,200);
520 520 }
521 521
522 522
523 523 void tst_QChart::zoomIn()
524 524 {
525 525 QFETCH(QRectF, rect);
526 526 createTestData();
527 527 QRectF marigns = m_chart->margins();
528 528 rect.adjust(marigns.left(),marigns.top(),-marigns.right(),-marigns.bottom());
529 529 qreal minX = m_chart->axisX()->min();
530 530 qreal minY = m_chart->axisY()->min();
531 531 qreal maxX = m_chart->axisX()->max();
532 532 qreal maxY = m_chart->axisY()->max();
533 533 m_chart->zoomIn(rect);
534 534 if(rect.isValid()){
535 535 QVERIFY(minX<m_chart->axisX()->min());
536 536 QVERIFY(maxX>m_chart->axisX()->max());
537 537 QVERIFY(minY<m_chart->axisY()->min());
538 538 QVERIFY(maxY>m_chart->axisY()->max());
539 539 }
540 540 }
541 541
542 542 void tst_QChart::zoomOut_data()
543 543 {
544 544
545 545 }
546 546
547 547 void tst_QChart::zoomOut()
548 548 {
549 549 createTestData();
550 550 qreal minX = m_chart->axisX()->min();
551 551 qreal minY = m_chart->axisY()->min();
552 552 qreal maxX = m_chart->axisX()->max();
553 553 qreal maxY = m_chart->axisY()->max();
554 554
555 555 m_chart->zoomIn();
556 556
557 557 QVERIFY(minX<m_chart->axisX()->min());
558 558 QVERIFY(maxX>m_chart->axisX()->max());
559 559 QVERIFY(minY<m_chart->axisY()->min());
560 560 QVERIFY(maxY>m_chart->axisY()->max());
561 561
562 562 m_chart->zoomOut();
563 563
564 564 QVERIFY(minX==m_chart->axisX()->min());
565 565 QVERIFY(maxX==m_chart->axisX()->max());
566 566 QVERIFY(minY==m_chart->axisY()->min());
567 567 QVERIFY(maxY==m_chart->axisY()->max());
568 568 }
569 569
570 570 QTEST_MAIN(tst_QChart)
571 571 #include "tst_qchart.moc"
572 572
@@ -1,66 +1,65
1 1 /****************************************************************************
2 2 **
3 3 ** Copyright (C) 2012 Digia Plc
4 4 ** All rights reserved.
5 5 ** For any questions to Digia, please use contact form at http://qt.digia.com
6 6 **
7 7 ** This file is part of the Qt Commercial Charts Add-on.
8 8 **
9 9 ** $QT_BEGIN_LICENSE$
10 10 ** Licensees holding valid Qt Commercial licenses may use this file in
11 11 ** accordance with the Qt Commercial License Agreement provided with the
12 12 ** Software or, alternatively, in accordance with the terms contained in
13 13 ** a written agreement between you and Digia.
14 14 **
15 15 ** If you have questions regarding the use of this file, please use
16 16 ** contact form at http://qt.digia.com
17 17 ** $QT_END_LICENSE$
18 18 **
19 19 ****************************************************************************/
20 20
21 21 #ifndef TABLEWIDGET_H
22 22 #define TABLEWIDGET_H
23 23
24 24 #include <QtGui/QWidget>
25 25 #include "qchartview.h"
26 26 #include "qxyseries.h"
27 27
28 28 QTCOMMERCIALCHART_USE_NAMESPACE
29 29
30 30 class CustomTableModel;
31 31 class QTableView;
32 32 class QRadioButton;
33 33 class QSpinBox;
34 //class QSeries;
35 34
36 35 class TableWidget : public QWidget
37 36 {
38 37 Q_OBJECT
39 38
40 39 public:
41 40 TableWidget(QWidget *parent = 0);
42 41 ~TableWidget();
43 42
44 43
45 44 public slots:
46 45 void addRowAbove();
47 46 void addRowBelow();
48 47 void removeRow();
49 48 void updateChartType(bool toggle);
50 49
51 50 private:
52 51 QChartView* m_chartView;
53 52 QChart* m_chart;
54 53 QXYSeries* m_series;
55 54 CustomTableModel* m_model;
56 55 QTableView* m_tableView;
57 56 QRadioButton* m_lineRadioButton;
58 57 QRadioButton* m_splineRadioButton;
59 58 QRadioButton* m_scatterRadioButton;
60 59 QRadioButton* m_pieRadioButton;
61 60 QRadioButton* m_areaRadioButton;
62 61 QRadioButton* m_barRadioButton;
63 62 QSpinBox* m_linesCountSpinBox;
64 63 };
65 64
66 65 #endif // TABLEWIDGET_H
General Comments 0
You need to be logged in to leave comments. Login now