##// END OF EJS Templates
License added to several files
Marek Rosa -
r1365:ffddfef33382
parent child
Show More
@@ -1,129 +1,149
1 /****************************************************************************
2 **
3 ** Copyright (C) 2012 Digia Plc
4 ** All rights reserved.
5 ** For any questions to Digia, please use contact form at http://qt.digia.com
6 **
7 ** This file is part of the Qt Commercial Charts Add-on.
8 **
9 ** $QT_BEGIN_LICENSE$
10 ** Licensees holding valid Qt Commercial licenses may use this file in
11 ** accordance with the Qt Commercial License Agreement provided with the
12 ** Software or, alternatively, in accordance with the terms contained in
13 ** a written agreement between you and Digia.
14 **
15 ** If you have questions regarding the use of this file, please use
16 ** contact form at http://qt.digia.com
17 ** $QT_END_LICENSE$
18 **
19 ****************************************************************************/
20
1 #include "mainwidget.h"
21 #include "mainwidget.h"
2 #include <QChart>
22 #include <QChart>
3 #include <QChartView>
23 #include <QChartView>
4 #include <QPushButton>
24 #include <QPushButton>
5 #include <QLabel>
25 #include <QLabel>
6 #include <QDebug>
26 #include <QDebug>
7 #include <QBarSet>
27 #include <QBarSet>
8 #include <QBarSeries>
28 #include <QBarSeries>
9 #include <QLegend>
29 #include <QLegend>
10
30
11 QTCOMMERCIALCHART_USE_NAMESPACE
31 QTCOMMERCIALCHART_USE_NAMESPACE
12
32
13 MainWidget::MainWidget(QWidget *parent) :
33 MainWidget::MainWidget(QWidget *parent) :
14 QWidget(parent)
34 QWidget(parent)
15 {
35 {
16 // Create buttons for ui
36 // Create buttons for ui
17 m_buttonLayout = new QGridLayout();
37 m_buttonLayout = new QGridLayout();
18 QPushButton *detachLegendButton = new QPushButton("detach legend");
38 QPushButton *detachLegendButton = new QPushButton("detach legend");
19 connect(detachLegendButton, SIGNAL(clicked()), this, SLOT(detachLegend()));
39 connect(detachLegendButton, SIGNAL(clicked()), this, SLOT(detachLegend()));
20 m_buttonLayout->addWidget(detachLegendButton, 0, 0);
40 m_buttonLayout->addWidget(detachLegendButton, 0, 0);
21 QPushButton *attachLegendButton = new QPushButton("attach legend");
41 QPushButton *attachLegendButton = new QPushButton("attach legend");
22 connect(attachLegendButton, SIGNAL(clicked()), this, SLOT(attachLegend()));
42 connect(attachLegendButton, SIGNAL(clicked()), this, SLOT(attachLegend()));
23 m_buttonLayout->addWidget(attachLegendButton, 1, 0);
43 m_buttonLayout->addWidget(attachLegendButton, 1, 0);
24
44
25 QPushButton *addSetButton = new QPushButton("add barset");
45 QPushButton *addSetButton = new QPushButton("add barset");
26 connect(addSetButton, SIGNAL(clicked()), this, SLOT(addBarset()));
46 connect(addSetButton, SIGNAL(clicked()), this, SLOT(addBarset()));
27 m_buttonLayout->addWidget(addSetButton, 2, 0);
47 m_buttonLayout->addWidget(addSetButton, 2, 0);
28 QPushButton *removeBarsetButton = new QPushButton("remove barset");
48 QPushButton *removeBarsetButton = new QPushButton("remove barset");
29 connect(removeBarsetButton, SIGNAL(clicked()), this, SLOT(removeBarset()));
49 connect(removeBarsetButton, SIGNAL(clicked()), this, SLOT(removeBarset()));
30 m_buttonLayout->addWidget(removeBarsetButton, 3, 0);
50 m_buttonLayout->addWidget(removeBarsetButton, 3, 0);
31
51
32 // Create chart view with the chart
52 // Create chart view with the chart
33 //![1]
53 //![1]
34 m_chart = new QChart();
54 m_chart = new QChart();
35 m_chartView = new QChartView(m_chart, this);
55 m_chartView = new QChartView(m_chart, this);
36 m_chartView->setRubberBand(QChartView::HorizonalRubberBand);
56 m_chartView->setRubberBand(QChartView::HorizonalRubberBand);
37 //![1]
57 //![1]
38
58
39 // Create custom scene and view, where detached legend will be drawn
59 // Create custom scene and view, where detached legend will be drawn
40 //![2]
60 //![2]
41 m_customView = new QGraphicsView(this);
61 m_customView = new QGraphicsView(this);
42 m_customScene = new QGraphicsScene(this);
62 m_customScene = new QGraphicsScene(this);
43 m_customView->setScene(m_customScene);
63 m_customView->setScene(m_customScene);
44 //![2]
64 //![2]
45
65
46 // Create layout for grid and detached legend
66 // Create layout for grid and detached legend
47 m_mainLayout = new QGridLayout();
67 m_mainLayout = new QGridLayout();
48 m_mainLayout->addLayout(m_buttonLayout, 0, 0);
68 m_mainLayout->addLayout(m_buttonLayout, 0, 0);
49 m_mainLayout->addWidget(m_chartView, 0, 1, 3, 1);
69 m_mainLayout->addWidget(m_chartView, 0, 1, 3, 1);
50 m_mainLayout->addWidget(m_customView, 0, 2, 3, 1);
70 m_mainLayout->addWidget(m_customView, 0, 2, 3, 1);
51 setLayout(m_mainLayout);
71 setLayout(m_mainLayout);
52
72
53 createSeries();
73 createSeries();
54 }
74 }
55
75
56 void MainWidget::createSeries()
76 void MainWidget::createSeries()
57 {
77 {
58 //![3]
78 //![3]
59 m_series = new QBarSeries();
79 m_series = new QBarSeries();
60 addBarset();
80 addBarset();
61 addBarset();
81 addBarset();
62 addBarset();
82 addBarset();
63 addBarset();
83 addBarset();
64
84
65 m_chart->addSeries(m_series);
85 m_chart->addSeries(m_series);
66 m_chart->setTitle("Legend detach example");
86 m_chart->setTitle("Legend detach example");
67
87
68 m_chart->legend()->setVisible(true);
88 m_chart->legend()->setVisible(true);
69 m_chart->legend()->setAlignment(Qt::AlignBottom);
89 m_chart->legend()->setAlignment(Qt::AlignBottom);
70 m_chart->axisY()->setNiceNumbersEnabled(true);
90 m_chart->axisY()->setNiceNumbersEnabled(true);
71
91
72 m_chartView->setRenderHint(QPainter::Antialiasing);
92 m_chartView->setRenderHint(QPainter::Antialiasing);
73 //![3]
93 //![3]
74 }
94 }
75
95
76 void MainWidget::detachLegend()
96 void MainWidget::detachLegend()
77 {
97 {
78 // Detach legend from chart and
98 // Detach legend from chart and
79 // put legend to our custom scene
99 // put legend to our custom scene
80 //![4]
100 //![4]
81 QLegend *legend = m_chart->legend();
101 QLegend *legend = m_chart->legend();
82 legend->detachFromChart();
102 legend->detachFromChart();
83 legend->setGeometry(m_customView->rect());
103 legend->setGeometry(m_customView->rect());
84 m_customScene->addItem(legend);
104 m_customScene->addItem(legend);
85 //![4]
105 //![4]
86
106
87 // This forces redraw
107 // This forces redraw
88 QSize delta(1,1);
108 QSize delta(1,1);
89 resize(size() + delta);
109 resize(size() + delta);
90 resize(size() - delta);
110 resize(size() - delta);
91 }
111 }
92
112
93
113
94 void MainWidget::attachLegend()
114 void MainWidget::attachLegend()
95 {
115 {
96 // Remove legend from custom scene and put it back to chartview scene.
116 // Remove legend from custom scene and put it back to chartview scene.
97 // Attach legend back to chart, so that layout works.
117 // Attach legend back to chart, so that layout works.
98
118
99 //![5]
119 //![5]
100 QLegend *legend = m_chart->legend();
120 QLegend *legend = m_chart->legend();
101
121
102 if (m_customScene->items().contains(legend)) {
122 if (m_customScene->items().contains(legend)) {
103 m_customScene->removeItem(legend);
123 m_customScene->removeItem(legend);
104 m_chartView->scene()->addItem(legend);
124 m_chartView->scene()->addItem(legend);
105 legend->attachToChart();
125 legend->attachToChart();
106 }
126 }
107 //![5]
127 //![5]
108
128
109 // This forces redraw
129 // This forces redraw
110 QSize delta(1,1);
130 QSize delta(1,1);
111 resize(size() + delta);
131 resize(size() + delta);
112 resize(size() - delta);
132 resize(size() - delta);
113 }
133 }
114
134
115 void MainWidget::addBarset()
135 void MainWidget::addBarset()
116 {
136 {
117 QBarSet *barSet = new QBarSet(QString("set ") + QString::number(m_series->barsetCount()));
137 QBarSet *barSet = new QBarSet(QString("set ") + QString::number(m_series->barsetCount()));
118 qreal delta = m_series->barsetCount() * 0.1;
138 qreal delta = m_series->barsetCount() * 0.1;
119 *barSet << QPointF(0.0 + delta, 1 + delta) << QPointF(1.0 + delta, 2 + delta) << QPointF(2.0 + delta, 3 + delta) << QPointF(3.0 + delta, 4 + delta);
139 *barSet << QPointF(0.0 + delta, 1 + delta) << QPointF(1.0 + delta, 2 + delta) << QPointF(2.0 + delta, 3 + delta) << QPointF(3.0 + delta, 4 + delta);
120 m_series->append(barSet);
140 m_series->append(barSet);
121 }
141 }
122
142
123 void MainWidget::removeBarset()
143 void MainWidget::removeBarset()
124 {
144 {
125 QList<QBarSet*> sets = m_series->barSets();
145 QList<QBarSet*> sets = m_series->barSets();
126 if (sets.count() > 0) {
146 if (sets.count() > 0) {
127 m_series->remove(sets.at(sets.count()-1));
147 m_series->remove(sets.at(sets.count()-1));
128 }
148 }
129 }
149 }
@@ -1,43 +1,63
1 /****************************************************************************
2 **
3 ** Copyright (C) 2012 Digia Plc
4 ** All rights reserved.
5 ** For any questions to Digia, please use contact form at http://qt.digia.com
6 **
7 ** This file is part of the Qt Commercial Charts Add-on.
8 **
9 ** $QT_BEGIN_LICENSE$
10 ** Licensees holding valid Qt Commercial licenses may use this file in
11 ** accordance with the Qt Commercial License Agreement provided with the
12 ** Software or, alternatively, in accordance with the terms contained in
13 ** a written agreement between you and Digia.
14 **
15 ** If you have questions regarding the use of this file, please use
16 ** contact form at http://qt.digia.com
17 ** $QT_END_LICENSE$
18 **
19 ****************************************************************************/
20
1 #ifndef MAINWIDGET_H
21 #ifndef MAINWIDGET_H
2 #define MAINWIDGET_H
22 #define MAINWIDGET_H
3
23
4 #include "qchartglobal.h"
24 #include "qchartglobal.h"
5 #include "qchart.h"
25 #include "qchart.h"
6 #include "qchartview.h"
26 #include "qchartview.h"
7 #include <QWidget>
27 #include <QWidget>
8 #include <QGraphicsWidget>
28 #include <QGraphicsWidget>
9 #include <QGridLayout>
29 #include <QGridLayout>
10 #include <QGraphicsGridLayout>
30 #include <QGraphicsGridLayout>
11
31
12 QTCOMMERCIALCHART_USE_NAMESPACE
32 QTCOMMERCIALCHART_USE_NAMESPACE
13
33
14 class MainWidget : public QWidget
34 class MainWidget : public QWidget
15 {
35 {
16 Q_OBJECT
36 Q_OBJECT
17 public:
37 public:
18 explicit MainWidget(QWidget *parent = 0);
38 explicit MainWidget(QWidget *parent = 0);
19
39
20 void createSeries();
40 void createSeries();
21
41
22 signals:
42 signals:
23
43
24 public slots:
44 public slots:
25 void detachLegend();
45 void detachLegend();
26 void attachLegend();
46 void attachLegend();
27 void addBarset();
47 void addBarset();
28 void removeBarset();
48 void removeBarset();
29
49
30 private:
50 private:
31
51
32 QChart *m_chart;
52 QChart *m_chart;
33 QBarSeries *m_series;
53 QBarSeries *m_series;
34
54
35 QChartView *m_chartView;
55 QChartView *m_chartView;
36 QGridLayout *m_mainLayout;
56 QGridLayout *m_mainLayout;
37 QGridLayout *m_buttonLayout;
57 QGridLayout *m_buttonLayout;
38
58
39 QGraphicsView *m_customView;
59 QGraphicsView *m_customView;
40 QGraphicsScene *m_customScene;
60 QGraphicsScene *m_customScene;
41 };
61 };
42
62
43 #endif // MAINWIDGET_H
63 #endif // MAINWIDGET_H
@@ -1,36 +1,56
1 /****************************************************************************
2 **
3 ** Copyright (C) 2012 Digia Plc
4 ** All rights reserved.
5 ** For any questions to Digia, please use contact form at http://qt.digia.com
6 **
7 ** This file is part of the Qt Commercial Charts Add-on.
8 **
9 ** $QT_BEGIN_LICENSE$
10 ** Licensees holding valid Qt Commercial licenses may use this file in
11 ** accordance with the Qt Commercial License Agreement provided with the
12 ** Software or, alternatively, in accordance with the terms contained in
13 ** a written agreement between you and Digia.
14 **
15 ** If you have questions regarding the use of this file, please use
16 ** contact form at http://qt.digia.com
17 ** $QT_END_LICENSE$
18 **
19 ****************************************************************************/
20
1 #include "chartview.h"
21 #include "chartview.h"
2 #include <QScatterSeries>
22 #include <QScatterSeries>
3
23
4 ChartView::ChartView(QWidget *parent) :
24 ChartView::ChartView(QWidget *parent) :
5 QChartView(new QChart(), parent)
25 QChartView(new QChart(), parent)
6 {
26 {
7 //![1]
27 //![1]
8 QScatterSeries *series0 = new QScatterSeries();
28 QScatterSeries *series0 = new QScatterSeries();
9 series0->setName("scatter1");
29 series0->setName("scatter1");
10 series0->setMarkerShape(QScatterSeries::MarkerShapeCircle);
30 series0->setMarkerShape(QScatterSeries::MarkerShapeCircle);
11 series0->setMarkerSize(15.0);
31 series0->setMarkerSize(15.0);
12
32
13 QScatterSeries *series1 = new QScatterSeries();
33 QScatterSeries *series1 = new QScatterSeries();
14 series1->setName("scatter2");
34 series1->setName("scatter2");
15 series1->setMarkerShape(QScatterSeries::MarkerShapeCircle);
35 series1->setMarkerShape(QScatterSeries::MarkerShapeCircle);
16 series1->setMarkerSize(20.0);
36 series1->setMarkerSize(20.0);
17 //![1]
37 //![1]
18
38
19 //![2]
39 //![2]
20 series0->append(0, 6);
40 series0->append(0, 6);
21 series0->append(2, 4);
41 series0->append(2, 4);
22 series0->append(3, 8);
42 series0->append(3, 8);
23 series0->append(7, 4);
43 series0->append(7, 4);
24 series0->append(10, 5);
44 series0->append(10, 5);
25
45
26 *series1 << QPointF(1, 1) << QPointF(3, 3) << QPointF(7, 6) << QPointF(8, 3) << QPointF(10, 2);
46 *series1 << QPointF(1, 1) << QPointF(3, 3) << QPointF(7, 6) << QPointF(8, 3) << QPointF(10, 2);
27 //![2]
47 //![2]
28
48
29 //![3]
49 //![3]
30 setRenderHint(QPainter::Antialiasing);
50 setRenderHint(QPainter::Antialiasing);
31 chart()->addSeries(series0);
51 chart()->addSeries(series0);
32 chart()->addSeries(series1);
52 chart()->addSeries(series1);
33 chart()->setTitle("Simple scatterchart example");
53 chart()->setTitle("Simple scatterchart example");
34 chart()->setBackgroundDropShadowEnabled(false);
54 chart()->setBackgroundDropShadowEnabled(false);
35 //![3]
55 //![3]
36 }
56 }
@@ -1,20 +1,40
1 /****************************************************************************
2 **
3 ** Copyright (C) 2012 Digia Plc
4 ** All rights reserved.
5 ** For any questions to Digia, please use contact form at http://qt.digia.com
6 **
7 ** This file is part of the Qt Commercial Charts Add-on.
8 **
9 ** $QT_BEGIN_LICENSE$
10 ** Licensees holding valid Qt Commercial licenses may use this file in
11 ** accordance with the Qt Commercial License Agreement provided with the
12 ** Software or, alternatively, in accordance with the terms contained in
13 ** a written agreement between you and Digia.
14 **
15 ** If you have questions regarding the use of this file, please use
16 ** contact form at http://qt.digia.com
17 ** $QT_END_LICENSE$
18 **
19 ****************************************************************************/
20
1 #ifndef CHARTVIEW_H
21 #ifndef CHARTVIEW_H
2 #define CHARTVIEW_H
22 #define CHARTVIEW_H
3
23
4 #include <QChartView>
24 #include <QChartView>
5
25
6 QTCOMMERCIALCHART_USE_NAMESPACE
26 QTCOMMERCIALCHART_USE_NAMESPACE
7
27
8 class ChartView : public QChartView
28 class ChartView : public QChartView
9 {
29 {
10 Q_OBJECT
30 Q_OBJECT
11 public:
31 public:
12 explicit ChartView(QWidget *parent = 0);
32 explicit ChartView(QWidget *parent = 0);
13
33
14 signals:
34 signals:
15
35
16 public slots:
36 public slots:
17
37
18 };
38 };
19
39
20 #endif // CHARTVIEW_H
40 #endif // CHARTVIEW_H
@@ -1,58 +1,78
1 /****************************************************************************
2 **
3 ** Copyright (C) 2012 Digia Plc
4 ** All rights reserved.
5 ** For any questions to Digia, please use contact form at http://qt.digia.com
6 **
7 ** This file is part of the Qt Commercial Charts Add-on.
8 **
9 ** $QT_BEGIN_LICENSE$
10 ** Licensees holding valid Qt Commercial licenses may use this file in
11 ** accordance with the Qt Commercial License Agreement provided with the
12 ** Software or, alternatively, in accordance with the terms contained in
13 ** a written agreement between you and Digia.
14 **
15 ** If you have questions regarding the use of this file, please use
16 ** contact form at http://qt.digia.com
17 ** $QT_END_LICENSE$
18 **
19 ****************************************************************************/
20
1 #include "qchartsplugin.h"
21 #include "qchartsplugin.h"
2 #include "qchartview.h"
22 #include "qchartview.h"
3 #include <QtPlugin>
23 #include <QtPlugin>
4
24
5 QTCOMMERCIALCHART_USE_NAMESPACE
25 QTCOMMERCIALCHART_USE_NAMESPACE
6
26
7 QChartsPlugin::QChartsPlugin(QObject *parent) :
27 QChartsPlugin::QChartsPlugin(QObject *parent) :
8 QObject(parent)
28 QObject(parent)
9 {
29 {
10 // TODO Auto-generated constructor stub
30 // TODO Auto-generated constructor stub
11 }
31 }
12
32
13 QChartsPlugin::~QChartsPlugin()
33 QChartsPlugin::~QChartsPlugin()
14 {
34 {
15 // TODO Auto-generated destructor stub
35 // TODO Auto-generated destructor stub
16 }
36 }
17
37
18 QString QChartsPlugin::name() const
38 QString QChartsPlugin::name() const
19 {
39 {
20 return "QChartView";
40 return "QChartView";
21 }
41 }
22
42
23 QString QChartsPlugin::includeFile() const
43 QString QChartsPlugin::includeFile() const
24 {
44 {
25 return "<qchartview.h>";
45 return "<qchartview.h>";
26 }
46 }
27
47
28 QString QChartsPlugin::group() const
48 QString QChartsPlugin::group() const
29 {
49 {
30 return tr("QCharts Widgets");
50 return tr("QCharts Widgets");
31 }
51 }
32
52
33 QIcon QChartsPlugin::icon() const
53 QIcon QChartsPlugin::icon() const
34 {
54 {
35 return QIcon(":/images/qcharts.png");
55 return QIcon(":/images/qcharts.png");
36 }
56 }
37
57
38 QString QChartsPlugin::toolTip() const
58 QString QChartsPlugin::toolTip() const
39 {
59 {
40 return tr("An qcharts view widget");
60 return tr("An qcharts view widget");
41 }
61 }
42
62
43 QString QChartsPlugin::whatsThis() const
63 QString QChartsPlugin::whatsThis() const
44 {
64 {
45 return tr("This widget is presents QChartView widget");
65 return tr("This widget is presents QChartView widget");
46 }
66 }
47
67
48 bool QChartsPlugin::isContainer() const
68 bool QChartsPlugin::isContainer() const
49 {
69 {
50 return false;
70 return false;
51 }
71 }
52
72
53 QWidget* QChartsPlugin::createWidget(QWidget *parent)
73 QWidget* QChartsPlugin::createWidget(QWidget *parent)
54 {
74 {
55 return new QChartView(new QChart(), parent);
75 return new QChartView(new QChart(), parent);
56 }
76 }
57
77
58 Q_EXPORT_PLUGIN2(qtcommercialchart, QChartsPlugin)
78 Q_EXPORT_PLUGIN2(qtcommercialchart, QChartsPlugin)
@@ -1,24 +1,44
1 /****************************************************************************
2 **
3 ** Copyright (C) 2012 Digia Plc
4 ** All rights reserved.
5 ** For any questions to Digia, please use contact form at http://qt.digia.com
6 **
7 ** This file is part of the Qt Commercial Charts Add-on.
8 **
9 ** $QT_BEGIN_LICENSE$
10 ** Licensees holding valid Qt Commercial licenses may use this file in
11 ** accordance with the Qt Commercial License Agreement provided with the
12 ** Software or, alternatively, in accordance with the terms contained in
13 ** a written agreement between you and Digia.
14 **
15 ** If you have questions regarding the use of this file, please use
16 ** contact form at http://qt.digia.com
17 ** $QT_END_LICENSE$
18 **
19 ****************************************************************************/
20
1 #ifndef QCHARTSPLUGIN_H_
21 #ifndef QCHARTSPLUGIN_H_
2 #define QCHARTSPLUGIN_H_
22 #define QCHARTSPLUGIN_H_
3
23
4 #include <QDesignerCustomWidgetInterface>
24 #include <QDesignerCustomWidgetInterface>
5
25
6 class QChartsPlugin: public QObject,public QDesignerCustomWidgetInterface
26 class QChartsPlugin: public QObject,public QDesignerCustomWidgetInterface
7 {
27 {
8 Q_OBJECT
28 Q_OBJECT
9 Q_INTERFACES(QDesignerCustomWidgetInterface)
29 Q_INTERFACES(QDesignerCustomWidgetInterface)
10 public:
30 public:
11 QChartsPlugin(QObject *parent = 0);
31 QChartsPlugin(QObject *parent = 0);
12 ~QChartsPlugin();
32 ~QChartsPlugin();
13
33
14 QString name() const;
34 QString name() const;
15 QString includeFile() const;
35 QString includeFile() const;
16 QString group() const;
36 QString group() const;
17 QIcon icon() const;
37 QIcon icon() const;
18 QString toolTip() const;
38 QString toolTip() const;
19 QString whatsThis() const;
39 QString whatsThis() const;
20 bool isContainer() const;
40 bool isContainer() const;
21 QWidget *createWidget(QWidget *parent);
41 QWidget *createWidget(QWidget *parent);
22 };
42 };
23
43
24 #endif /* QCHARTSPLUGIN_H_ */
44 #endif /* QCHARTSPLUGIN_H_ */
@@ -1,483 +1,482
1 /****************************************************************************
1 /****************************************************************************
2 **
2 **
3 ** Copyright (C) 2012 Digia Plc
3 ** Copyright (C) 2012 Digia Plc
4 ** All rights reserved.
4 ** All rights reserved.
5 ** For any questions to Digia, please use contact form at http://qt.digia.com
5 ** For any questions to Digia, please use contact form at http://qt.digia.com
6 **
6 **
7 ** This file is part of the Qt Commercial Charts Add-on.
7 ** This file is part of the Qt Commercial Charts Add-on.
8 **
8 **
9 ** $QT_BEGIN_LICENSE$
9 ** $QT_BEGIN_LICENSE$
10 ** Licensees holding valid Qt Commercial licenses may use this file in
10 ** Licensees holding valid Qt Commercial licenses may use this file in
11 ** accordance with the Qt Commercial License Agreement provided with the
11 ** accordance with the Qt Commercial License Agreement provided with the
12 ** Software or, alternatively, in accordance with the terms contained in
12 ** Software or, alternatively, in accordance with the terms contained in
13 ** a written agreement between you and Digia.
13 ** a written agreement between you and Digia.
14 **
14 **
15 ** If you have questions regarding the use of this file, please use
15 ** If you have questions regarding the use of this file, please use
16 ** contact form at http://qt.digia.com
16 ** contact form at http://qt.digia.com
17 ** $QT_END_LICENSE$
17 ** $QT_END_LICENSE$
18 **
18 **
19 ****************************************************************************/
19 ****************************************************************************/
20
20
21 #include "qbarmodelmapper.h"
21 #include "qbarmodelmapper.h"
22 #include "qbarmodelmapper_p.h"
22 #include "qbarmodelmapper_p.h"
23 #include "qbarseries.h"
23 #include "qbarseries.h"
24 #include "qbarset.h"
24 #include "qbarset.h"
25 #include "qchart.h"
25 #include "qchart.h"
26 #include "qaxis.h"
27 #include <QAbstractItemModel>
26 #include <QAbstractItemModel>
28
27
29 QTCOMMERCIALCHART_BEGIN_NAMESPACE
28 QTCOMMERCIALCHART_BEGIN_NAMESPACE
30
29
31 /*!
30 /*!
32 \property QBarModelMapper::series
31 \property QBarModelMapper::series
33 \brief Defines the QPieSeries object that is used by the mapper.
32 \brief Defines the QPieSeries object that is used by the mapper.
34
33
35 All the data in the series in the series is discarded when it is set to the mapper.
34 All the data in the series in the series is discarded when it is set to the mapper.
36 When new series is specified the old series is disconnected (it preserves its data)
35 When new series is specified the old series is disconnected (it preserves its data)
37 */
36 */
38
37
39 /*!
38 /*!
40 \property QBarModelMapper::model
39 \property QBarModelMapper::model
41 \brief Defines the model that is used by the mapper.
40 \brief Defines the model that is used by the mapper.
42 */
41 */
43
42
44 /*!
43 /*!
45 \property QBarModelMapper::first
44 \property QBarModelMapper::first
46 \brief Defines which item of the model's row/column should be mapped as the value of the first QBarSet in the series.
45 \brief Defines which item of the model's row/column should be mapped as the value of the first QBarSet in the series.
47
46
48 Minimal and default value is: 0
47 Minimal and default value is: 0
49 */
48 */
50
49
51 /*!
50 /*!
52 \property QBarModelMapper::count
51 \property QBarModelMapper::count
53 \brief Defines the number of rows/columns of the model that are mapped as the data for QBarSeries
52 \brief Defines the number of rows/columns of the model that are mapped as the data for QBarSeries
54
53
55 Minimal and default value is: -1 (count limited by the number of rows/columns in the model)
54 Minimal and default value is: -1 (count limited by the number of rows/columns in the model)
56 */
55 */
57
56
58 /*!
57 /*!
59 \class QBarModelMapper
58 \class QBarModelMapper
60 \brief part of QtCommercial chart API.
59 \brief part of QtCommercial chart API.
61 \mainclass
60 \mainclass
62
61
63 The instance of this class cannot be created directly. QHBarModelMapper of QVBarModelMapper should be used instead. This class is used to create a connection between QBarSeries and QAbstractItemModel derived model object.
62 The instance of this class cannot be created directly. QHBarModelMapper of QVBarModelMapper should be used instead. This class is used to create a connection between QBarSeries and QAbstractItemModel derived model object.
64 Curently it is NOT possible to use both QAbstractItemModel and QXYSeries model API.
63 Curently it is NOT possible to use both QAbstractItemModel and QXYSeries model API.
65 When the series is set to the mapper the QBarSeries and QBarSet API that affect the data (append, setValue, remove) should not be used.
64 When the series is set to the mapper the QBarSeries and QBarSet API that affect the data (append, setValue, remove) should not be used.
66 The model and the QBarSeries won't be kept in sync. Model API should be used to insert,remove,modify BarSets.
65 The model and the QBarSeries won't be kept in sync. Model API should be used to insert,remove,modify BarSets.
67 NOTE: used model has to support adding/removing rows/columns and modifying the data of the cells.
66 NOTE: used model has to support adding/removing rows/columns and modifying the data of the cells.
68 */
67 */
69
68
70 /*!
69 /*!
71 Constructs a mapper object which is a child of \a parent.
70 Constructs a mapper object which is a child of \a parent.
72 */
71 */
73 QBarModelMapper::QBarModelMapper(QObject *parent) :
72 QBarModelMapper::QBarModelMapper(QObject *parent) :
74 QObject(parent),
73 QObject(parent),
75 d_ptr(new QBarModelMapperPrivate(this))
74 d_ptr(new QBarModelMapperPrivate(this))
76 {
75 {
77 }
76 }
78
77
79 QAbstractItemModel* QBarModelMapper::model() const
78 QAbstractItemModel* QBarModelMapper::model() const
80 {
79 {
81 Q_D(const QBarModelMapper);
80 Q_D(const QBarModelMapper);
82 return d->m_model;
81 return d->m_model;
83 }
82 }
84
83
85 void QBarModelMapper::setModel(QAbstractItemModel *model)
84 void QBarModelMapper::setModel(QAbstractItemModel *model)
86 {
85 {
87 if (model == 0)
86 if (model == 0)
88 return;
87 return;
89
88
90 Q_D(QBarModelMapper);
89 Q_D(QBarModelMapper);
91 if (d->m_model) {
90 if (d->m_model) {
92 disconnect(d->m_model, 0, d, 0);
91 disconnect(d->m_model, 0, d, 0);
93 }
92 }
94
93
95 d->m_model = model;
94 d->m_model = model;
96 d->initializeBarFromModel();
95 d->initializeBarFromModel();
97 // connect signals from the model
96 // connect signals from the model
98 connect(d->m_model, SIGNAL(dataChanged(QModelIndex,QModelIndex)), d, SLOT(modelUpdated(QModelIndex,QModelIndex)));
97 connect(d->m_model, SIGNAL(dataChanged(QModelIndex,QModelIndex)), d, SLOT(modelUpdated(QModelIndex,QModelIndex)));
99 connect(d->m_model, SIGNAL(rowsInserted(QModelIndex,int,int)), d, SLOT(modelRowsAdded(QModelIndex,int,int)));
98 connect(d->m_model, SIGNAL(rowsInserted(QModelIndex,int,int)), d, SLOT(modelRowsAdded(QModelIndex,int,int)));
100 connect(d->m_model, SIGNAL(rowsRemoved(QModelIndex,int,int)), d, SLOT(modelRowsRemoved(QModelIndex,int,int)));
99 connect(d->m_model, SIGNAL(rowsRemoved(QModelIndex,int,int)), d, SLOT(modelRowsRemoved(QModelIndex,int,int)));
101 connect(d->m_model, SIGNAL(columnsInserted(QModelIndex,int,int)), d, SLOT(modelColumnsAdded(QModelIndex,int,int)));
100 connect(d->m_model, SIGNAL(columnsInserted(QModelIndex,int,int)), d, SLOT(modelColumnsAdded(QModelIndex,int,int)));
102 connect(d->m_model, SIGNAL(columnsRemoved(QModelIndex,int,int)), d, SLOT(modelColumnsRemoved(QModelIndex,int,int)));
101 connect(d->m_model, SIGNAL(columnsRemoved(QModelIndex,int,int)), d, SLOT(modelColumnsRemoved(QModelIndex,int,int)));
103 }
102 }
104
103
105 QBarSeries* QBarModelMapper::series() const
104 QBarSeries* QBarModelMapper::series() const
106 {
105 {
107 Q_D(const QBarModelMapper);
106 Q_D(const QBarModelMapper);
108 return d->m_series;
107 return d->m_series;
109 }
108 }
110
109
111 void QBarModelMapper::setSeries(QBarSeries *series)
110 void QBarModelMapper::setSeries(QBarSeries *series)
112 {
111 {
113 Q_D(QBarModelMapper);
112 Q_D(QBarModelMapper);
114 if (d->m_series) {
113 if (d->m_series) {
115 disconnect(d->m_series, 0, d, 0);
114 disconnect(d->m_series, 0, d, 0);
116 }
115 }
117
116
118 if (series == 0)
117 if (series == 0)
119 return;
118 return;
120
119
121 d->m_series = series;
120 d->m_series = series;
122 d->initializeBarFromModel();
121 d->initializeBarFromModel();
123 // connect the signals from the series
122 // connect the signals from the series
124 // connect(d->m_series, SIGNAL(pointAdded(int)), d, SLOT(handlePointAdded(int)));
123 // connect(d->m_series, SIGNAL(pointAdded(int)), d, SLOT(handlePointAdded(int)));
125 // connect(d->m_series, SIGNAL(pointRemoved(int)), d, SLOT(handlePointRemoved(int)));
124 // connect(d->m_series, SIGNAL(pointRemoved(int)), d, SLOT(handlePointRemoved(int)));
126 // connect(d->m_series, SIGNAL(pointReplaced(int)), d, SLOT(handlePointReplaced(int)));
125 // connect(d->m_series, SIGNAL(pointReplaced(int)), d, SLOT(handlePointReplaced(int)));
127 }
126 }
128
127
129 int QBarModelMapper::first() const
128 int QBarModelMapper::first() const
130 {
129 {
131 Q_D(const QBarModelMapper);
130 Q_D(const QBarModelMapper);
132 return d->m_first;
131 return d->m_first;
133 }
132 }
134
133
135 void QBarModelMapper::setFirst(int first)
134 void QBarModelMapper::setFirst(int first)
136 {
135 {
137 Q_D(QBarModelMapper);
136 Q_D(QBarModelMapper);
138 d->m_first = qMax(first, 0);
137 d->m_first = qMax(first, 0);
139 d->initializeBarFromModel();
138 d->initializeBarFromModel();
140 }
139 }
141
140
142 int QBarModelMapper::count() const
141 int QBarModelMapper::count() const
143 {
142 {
144 Q_D(const QBarModelMapper);
143 Q_D(const QBarModelMapper);
145 return d->m_count;
144 return d->m_count;
146 }
145 }
147
146
148 void QBarModelMapper::setCount(int count)
147 void QBarModelMapper::setCount(int count)
149 {
148 {
150 Q_D(QBarModelMapper);
149 Q_D(QBarModelMapper);
151 d->m_count = qMax(count, -1);
150 d->m_count = qMax(count, -1);
152 d->initializeBarFromModel();
151 d->initializeBarFromModel();
153 }
152 }
154
153
155 /*!
154 /*!
156 Returns the orientation that is used when QBarModelMapper accesses the model.
155 Returns the orientation that is used when QBarModelMapper accesses the model.
157 This mean whether the consecutive values of the bar set are read from row (Qt::Horizontal)
156 This mean whether the consecutive values of the bar set are read from row (Qt::Horizontal)
158 or from columns (Qt::Vertical)
157 or from columns (Qt::Vertical)
159 */
158 */
160 Qt::Orientation QBarModelMapper::orientation() const
159 Qt::Orientation QBarModelMapper::orientation() const
161 {
160 {
162 Q_D(const QBarModelMapper);
161 Q_D(const QBarModelMapper);
163 return d->m_orientation;
162 return d->m_orientation;
164 }
163 }
165
164
166 /*!
165 /*!
167 Returns the \a orientation that is used when QBarModelMapper accesses the model.
166 Returns the \a orientation that is used when QBarModelMapper accesses the model.
168 This mean whether the consecutive values of the pie are read from row (Qt::Horizontal)
167 This mean whether the consecutive values of the pie are read from row (Qt::Horizontal)
169 or from columns (Qt::Vertical)
168 or from columns (Qt::Vertical)
170 */
169 */
171 void QBarModelMapper::setOrientation(Qt::Orientation orientation)
170 void QBarModelMapper::setOrientation(Qt::Orientation orientation)
172 {
171 {
173 Q_D(QBarModelMapper);
172 Q_D(QBarModelMapper);
174 d->m_orientation = orientation;
173 d->m_orientation = orientation;
175 d->initializeBarFromModel();
174 d->initializeBarFromModel();
176 }
175 }
177
176
178 /*!
177 /*!
179 Returns which section of the model is used as the data source for the first bar set
178 Returns which section of the model is used as the data source for the first bar set
180 */
179 */
181 int QBarModelMapper::firstBarSetSection() const
180 int QBarModelMapper::firstBarSetSection() const
182 {
181 {
183 Q_D(const QBarModelMapper);
182 Q_D(const QBarModelMapper);
184 return d->m_firstBarSetSection;
183 return d->m_firstBarSetSection;
185 }
184 }
186
185
187 /*!
186 /*!
188 Sets the model section that is used as the data source for the first bar set
187 Sets the model section that is used as the data source for the first bar set
189 Parameter \a firstBarSetSection specifies the section of the model.
188 Parameter \a firstBarSetSection specifies the section of the model.
190 */
189 */
191 void QBarModelMapper::setFirstBarSetSection(int firstBarSetSection)
190 void QBarModelMapper::setFirstBarSetSection(int firstBarSetSection)
192 {
191 {
193 Q_D(QBarModelMapper);
192 Q_D(QBarModelMapper);
194 d->m_firstBarSetSection = qMax(-1, firstBarSetSection);
193 d->m_firstBarSetSection = qMax(-1, firstBarSetSection);
195 d->initializeBarFromModel();
194 d->initializeBarFromModel();
196 }
195 }
197
196
198 /*!
197 /*!
199 Returns which section of the model is used as the data source for the last bar set
198 Returns which section of the model is used as the data source for the last bar set
200 */
199 */
201 int QBarModelMapper::lastBarSetSection() const
200 int QBarModelMapper::lastBarSetSection() const
202 {
201 {
203 Q_D(const QBarModelMapper);
202 Q_D(const QBarModelMapper);
204 return d->m_lastBarSetSection;
203 return d->m_lastBarSetSection;
205 }
204 }
206
205
207 /*!
206 /*!
208 Sets the model section that is used as the data source for the last bar set
207 Sets the model section that is used as the data source for the last bar set
209 Parameter \a lastBarSetSection specifies the section of the model.
208 Parameter \a lastBarSetSection specifies the section of the model.
210 */
209 */
211 void QBarModelMapper::setLastBarSetSection(int lastBarSetSection)
210 void QBarModelMapper::setLastBarSetSection(int lastBarSetSection)
212 {
211 {
213 Q_D(QBarModelMapper);
212 Q_D(QBarModelMapper);
214 d->m_lastBarSetSection = qMax(-1, lastBarSetSection);
213 d->m_lastBarSetSection = qMax(-1, lastBarSetSection);
215 d->initializeBarFromModel();
214 d->initializeBarFromModel();
216 }
215 }
217
216
218 /*!
217 /*!
219 Resets the QBarModelMapper to the default state.
218 Resets the QBarModelMapper to the default state.
220 first: 0; count: -1; firstBarSetSection: -1; lastBarSetSection: -1; categoriesSection: -1
219 first: 0; count: -1; firstBarSetSection: -1; lastBarSetSection: -1; categoriesSection: -1
221 */
220 */
222 void QBarModelMapper::reset()
221 void QBarModelMapper::reset()
223 {
222 {
224 Q_D(QBarModelMapper);
223 Q_D(QBarModelMapper);
225 d->m_first = 0;
224 d->m_first = 0;
226 d->m_count = -1;
225 d->m_count = -1;
227 d->m_firstBarSetSection = -1;
226 d->m_firstBarSetSection = -1;
228 d->m_lastBarSetSection = -1;
227 d->m_lastBarSetSection = -1;
229 d->initializeBarFromModel();
228 d->initializeBarFromModel();
230 }
229 }
231
230
232 ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
231 ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
233
232
234 QBarModelMapperPrivate::QBarModelMapperPrivate(QBarModelMapper *q) :
233 QBarModelMapperPrivate::QBarModelMapperPrivate(QBarModelMapper *q) :
235 m_series(0),
234 m_series(0),
236 m_model(0),
235 m_model(0),
237 m_first(0),
236 m_first(0),
238 m_count(-1),
237 m_count(-1),
239 m_orientation(Qt::Vertical),
238 m_orientation(Qt::Vertical),
240 m_firstBarSetSection(-1),
239 m_firstBarSetSection(-1),
241 m_lastBarSetSection(-1),
240 m_lastBarSetSection(-1),
242 m_seriesSignalsBlock(false),
241 m_seriesSignalsBlock(false),
243 m_modelSignalsBlock(false),
242 m_modelSignalsBlock(false),
244 q_ptr(q)
243 q_ptr(q)
245 {
244 {
246 }
245 }
247
246
248 void QBarModelMapperPrivate::blockModelSignals(bool block)
247 void QBarModelMapperPrivate::blockModelSignals(bool block)
249 {
248 {
250 m_modelSignalsBlock = block;
249 m_modelSignalsBlock = block;
251 }
250 }
252
251
253 void QBarModelMapperPrivate::blockSeriesSignals(bool block)
252 void QBarModelMapperPrivate::blockSeriesSignals(bool block)
254 {
253 {
255 m_seriesSignalsBlock = block;
254 m_seriesSignalsBlock = block;
256 }
255 }
257
256
258 QBarSet* QBarModelMapperPrivate::barSet(QModelIndex index)
257 QBarSet* QBarModelMapperPrivate::barSet(QModelIndex index)
259 {
258 {
260 if (!index.isValid())
259 if (!index.isValid())
261 return 0;
260 return 0;
262
261
263 if (m_orientation == Qt::Vertical && index.column() >= m_firstBarSetSection && index.column() <= m_lastBarSetSection) {
262 if (m_orientation == Qt::Vertical && index.column() >= m_firstBarSetSection && index.column() <= m_lastBarSetSection) {
264 if (index.row() >= m_first && (m_count == - 1 || index.row() < m_first + m_count)) {
263 if (index.row() >= m_first && (m_count == - 1 || index.row() < m_first + m_count)) {
265 // if (m_model->index(index.row(), m_valuesSection).isValid() && m_model->index(index.row(), m_labelsSection).isValid())
264 // if (m_model->index(index.row(), m_valuesSection).isValid() && m_model->index(index.row(), m_labelsSection).isValid())
266 return m_series->barSets().at(index.column() - m_firstBarSetSection);
265 return m_series->barSets().at(index.column() - m_firstBarSetSection);
267 // else
266 // else
268 // return 0;
267 // return 0;
269 }
268 }
270 } else if (m_orientation == Qt::Horizontal && index.row() >= m_firstBarSetSection && index.row() <= m_lastBarSetSection) {
269 } else if (m_orientation == Qt::Horizontal && index.row() >= m_firstBarSetSection && index.row() <= m_lastBarSetSection) {
271 if (index.column() >= m_first && (m_count == - 1 || index.column() < m_first + m_count))
270 if (index.column() >= m_first && (m_count == - 1 || index.column() < m_first + m_count))
272 return m_series->barSets().at(index.row() - m_firstBarSetSection);
271 return m_series->barSets().at(index.row() - m_firstBarSetSection);
273 }
272 }
274 return 0; // This part of model has not been mapped to any slice
273 return 0; // This part of model has not been mapped to any slice
275 }
274 }
276
275
277 QModelIndex QBarModelMapperPrivate::barModelIndex(int barSection, int posInBar)
276 QModelIndex QBarModelMapperPrivate::barModelIndex(int barSection, int posInBar)
278 {
277 {
279 if (m_count != -1 && posInBar >= m_count)
278 if (m_count != -1 && posInBar >= m_count)
280 return QModelIndex(); // invalid
279 return QModelIndex(); // invalid
281
280
282 if (barSection < m_firstBarSetSection || barSection > m_lastBarSetSection)
281 if (barSection < m_firstBarSetSection || barSection > m_lastBarSetSection)
283 return QModelIndex(); // invalid
282 return QModelIndex(); // invalid
284
283
285 if (m_orientation == Qt::Vertical)
284 if (m_orientation == Qt::Vertical)
286 return m_model->index(posInBar + m_first, barSection);
285 return m_model->index(posInBar + m_first, barSection);
287 else
286 else
288 return m_model->index(barSection, posInBar + m_first);
287 return m_model->index(barSection, posInBar + m_first);
289 }
288 }
290
289
291 void QBarModelMapperPrivate::modelUpdated(QModelIndex topLeft, QModelIndex bottomRight)
290 void QBarModelMapperPrivate::modelUpdated(QModelIndex topLeft, QModelIndex bottomRight)
292 {
291 {
293 Q_UNUSED(topLeft)
292 Q_UNUSED(topLeft)
294 Q_UNUSED(bottomRight)
293 Q_UNUSED(bottomRight)
295
294
296 if (m_model == 0 || m_series == 0)
295 if (m_model == 0 || m_series == 0)
297 return;
296 return;
298
297
299 if (m_modelSignalsBlock)
298 if (m_modelSignalsBlock)
300 return;
299 return;
301
300
302 blockSeriesSignals();
301 blockSeriesSignals();
303 QModelIndex index;
302 QModelIndex index;
304 for (int row = topLeft.row(); row <= bottomRight.row(); row++) {
303 for (int row = topLeft.row(); row <= bottomRight.row(); row++) {
305 for (int column = topLeft.column(); column <= bottomRight.column(); column++) {
304 for (int column = topLeft.column(); column <= bottomRight.column(); column++) {
306 index = topLeft.sibling(row, column);
305 index = topLeft.sibling(row, column);
307 QBarSet* bar = barSet(index);
306 QBarSet* bar = barSet(index);
308 if (bar) {
307 if (bar) {
309 if (m_orientation == Qt::Vertical)
308 if (m_orientation == Qt::Vertical)
310 bar->replace(row - m_first, m_model->data(index).toReal());
309 bar->replace(row - m_first, m_model->data(index).toReal());
311 else
310 else
312 bar->replace(column - m_first, m_model->data(index).toReal());
311 bar->replace(column - m_first, m_model->data(index).toReal());
313 }
312 }
314 }
313 }
315 }
314 }
316 blockSeriesSignals(false);
315 blockSeriesSignals(false);
317 }
316 }
318
317
319 void QBarModelMapperPrivate::modelRowsAdded(QModelIndex parent, int start, int end)
318 void QBarModelMapperPrivate::modelRowsAdded(QModelIndex parent, int start, int end)
320 {
319 {
321 Q_UNUSED(parent);
320 Q_UNUSED(parent);
322 Q_UNUSED(end)
321 Q_UNUSED(end)
323 if (m_modelSignalsBlock)
322 if (m_modelSignalsBlock)
324 return;
323 return;
325
324
326 blockSeriesSignals();
325 blockSeriesSignals();
327 if (m_orientation == Qt::Vertical)
326 if (m_orientation == Qt::Vertical)
328 // insertData(start, end);
327 // insertData(start, end);
329 initializeBarFromModel();
328 initializeBarFromModel();
330 else if (start <= m_firstBarSetSection || start <= m_lastBarSetSection) // if the changes affect the map - reinitialize
329 else if (start <= m_firstBarSetSection || start <= m_lastBarSetSection) // if the changes affect the map - reinitialize
331 initializeBarFromModel();
330 initializeBarFromModel();
332 blockSeriesSignals(false);
331 blockSeriesSignals(false);
333 }
332 }
334
333
335 void QBarModelMapperPrivate::modelRowsRemoved(QModelIndex parent, int start, int end)
334 void QBarModelMapperPrivate::modelRowsRemoved(QModelIndex parent, int start, int end)
336 {
335 {
337 Q_UNUSED(parent);
336 Q_UNUSED(parent);
338 Q_UNUSED(end)
337 Q_UNUSED(end)
339 if (m_modelSignalsBlock)
338 if (m_modelSignalsBlock)
340 return;
339 return;
341
340
342 blockSeriesSignals();
341 blockSeriesSignals();
343 if (m_orientation == Qt::Vertical)
342 if (m_orientation == Qt::Vertical)
344 // removeData(start, end);
343 // removeData(start, end);
345 initializeBarFromModel();
344 initializeBarFromModel();
346 else if (start <= m_firstBarSetSection || start <= m_lastBarSetSection) // if the changes affect the map - reinitialize
345 else if (start <= m_firstBarSetSection || start <= m_lastBarSetSection) // if the changes affect the map - reinitialize
347 initializeBarFromModel();
346 initializeBarFromModel();
348 blockSeriesSignals(false);
347 blockSeriesSignals(false);
349 }
348 }
350
349
351 void QBarModelMapperPrivate::modelColumnsAdded(QModelIndex parent, int start, int end)
350 void QBarModelMapperPrivate::modelColumnsAdded(QModelIndex parent, int start, int end)
352 {
351 {
353 Q_UNUSED(parent);
352 Q_UNUSED(parent);
354 Q_UNUSED(end)
353 Q_UNUSED(end)
355 if (m_modelSignalsBlock)
354 if (m_modelSignalsBlock)
356 return;
355 return;
357
356
358 blockSeriesSignals();
357 blockSeriesSignals();
359 if (m_orientation == Qt::Horizontal)
358 if (m_orientation == Qt::Horizontal)
360 // insertData(start, end);
359 // insertData(start, end);
361 initializeBarFromModel();
360 initializeBarFromModel();
362 else if (start <= m_firstBarSetSection || start <= m_lastBarSetSection) // if the changes affect the map - reinitialize
361 else if (start <= m_firstBarSetSection || start <= m_lastBarSetSection) // if the changes affect the map - reinitialize
363 initializeBarFromModel();
362 initializeBarFromModel();
364 blockSeriesSignals(false);
363 blockSeriesSignals(false);
365 }
364 }
366
365
367 void QBarModelMapperPrivate::modelColumnsRemoved(QModelIndex parent, int start, int end)
366 void QBarModelMapperPrivate::modelColumnsRemoved(QModelIndex parent, int start, int end)
368 {
367 {
369 Q_UNUSED(parent);
368 Q_UNUSED(parent);
370 Q_UNUSED(end)
369 Q_UNUSED(end)
371 if (m_modelSignalsBlock)
370 if (m_modelSignalsBlock)
372 return;
371 return;
373
372
374 blockSeriesSignals();
373 blockSeriesSignals();
375 if (m_orientation == Qt::Horizontal)
374 if (m_orientation == Qt::Horizontal)
376 // removeData(start, end);
375 // removeData(start, end);
377 initializeBarFromModel();
376 initializeBarFromModel();
378 else if (start <= m_firstBarSetSection || start <= m_lastBarSetSection) // if the changes affect the map - reinitialize
377 else if (start <= m_firstBarSetSection || start <= m_lastBarSetSection) // if the changes affect the map - reinitialize
379 initializeBarFromModel();
378 initializeBarFromModel();
380 blockSeriesSignals(false);
379 blockSeriesSignals(false);
381 }
380 }
382
381
383 void QBarModelMapperPrivate::insertData(int start, int end)
382 void QBarModelMapperPrivate::insertData(int start, int end)
384 {
383 {
385 Q_UNUSED(end)
384 Q_UNUSED(end)
386 if (m_model == 0 || m_series == 0)
385 if (m_model == 0 || m_series == 0)
387 return;
386 return;
388
387
389 if (m_count != -1 && start >= m_first + m_count) {
388 if (m_count != -1 && start >= m_first + m_count) {
390 return;
389 return;
391 } /*else {
390 } /*else {
392 int addedCount = end - start + 1;
391 int addedCount = end - start + 1;
393 if (m_count != -1 && addedCount > m_count)
392 if (m_count != -1 && addedCount > m_count)
394 addedCount = m_count;
393 addedCount = m_count;
395 int first = qMax(start, m_first);
394 int first = qMax(start, m_first);
396 int last = qMin(first + addedCount - 1, m_orientation == Qt::Vertical ? m_model->rowCount() - 1 : m_model->columnCount() - 1);
395 int last = qMin(first + addedCount - 1, m_orientation == Qt::Vertical ? m_model->rowCount() - 1 : m_model->columnCount() - 1);
397 for (int k = 0; k < m_series->barSets().count(); k++) {
396 for (int k = 0; k < m_series->barSets().count(); k++) {
398 for (int i = first; i <= last; i++) {
397 for (int i = first; i <= last; i++) {
399 QBar point;
398 QBar point;
400 point.setX(m_model->data(xModelIndex(i - m_first), Qt::DisplayRole).toDouble());
399 point.setX(m_model->data(xModelIndex(i - m_first), Qt::DisplayRole).toDouble());
401 point.setY(m_model->data(yModelIndex(i - m_first), Qt::DisplayRole).toDouble());
400 point.setY(m_model->data(yModelIndex(i - m_first), Qt::DisplayRole).toDouble());
402 m_series->insert(i - m_first, point);
401 m_series->insert(i - m_first, point);
403 }
402 }
404 >>>>>>> Stashed changes
403 >>>>>>> Stashed changes
405 }
404 }
406
405
407 // remove excess of slices (abouve m_count)
406 // remove excess of slices (abouve m_count)
408 if (m_count != -1 && m_series->points().size() > m_count)
407 if (m_count != -1 && m_series->points().size() > m_count)
409 for (int i = m_series->points().size() - 1; i >= m_count; i--) {
408 for (int i = m_series->points().size() - 1; i >= m_count; i--) {
410 m_series->remove(m_series->points().at(i));
409 m_series->remove(m_series->points().at(i));
411 }
410 }
412 }*/
411 }*/
413 }
412 }
414
413
415 void QBarModelMapperPrivate::removeData(int start, int end)
414 void QBarModelMapperPrivate::removeData(int start, int end)
416 {
415 {
417 Q_UNUSED(end)
416 Q_UNUSED(end)
418 if (m_model == 0 || m_series == 0)
417 if (m_model == 0 || m_series == 0)
419 return;
418 return;
420
419
421 // int removedCount = end - start + 1;
420 // int removedCount = end - start + 1;
422 if (m_count != -1 && start >= m_first + m_count) {
421 if (m_count != -1 && start >= m_first + m_count) {
423 return;
422 return;
424 } /*else {
423 } /*else {
425 int toRemove = qMin(m_series->count(), removedCount); // first find how many items can actually be removed
424 int toRemove = qMin(m_series->count(), removedCount); // first find how many items can actually be removed
426 int first = qMax(start, m_first); // get the index of the first item that will be removed.
425 int first = qMax(start, m_first); // get the index of the first item that will be removed.
427 int last = qMin(first + toRemove - 1, m_series->count() + m_first - 1); // get the index of the last item that will be removed.
426 int last = qMin(first + toRemove - 1, m_series->count() + m_first - 1); // get the index of the last item that will be removed.
428 for (int i = last; i >= first; i--) {
427 for (int i = last; i >= first; i--) {
429 m_series->remove(m_series->points().at(i - m_first));
428 m_series->remove(m_series->points().at(i - m_first));
430 }
429 }
431
430
432 if (m_count != -1) {
431 if (m_count != -1) {
433 int itemsAvailable; // check how many are available to be added
432 int itemsAvailable; // check how many are available to be added
434 if (m_orientation == Qt::Vertical)
433 if (m_orientation == Qt::Vertical)
435 itemsAvailable = m_model->rowCount() - m_first - m_series->count();
434 itemsAvailable = m_model->rowCount() - m_first - m_series->count();
436 else
435 else
437 itemsAvailable = m_model->columnCount() - m_first - m_series->count();
436 itemsAvailable = m_model->columnCount() - m_first - m_series->count();
438 int toBeAdded = qMin(itemsAvailable, m_count - m_series->count()); // add not more items than there is space left to be filled.
437 int toBeAdded = qMin(itemsAvailable, m_count - m_series->count()); // add not more items than there is space left to be filled.
439 int currentSize = m_series->count();
438 int currentSize = m_series->count();
440 if (toBeAdded > 0)
439 if (toBeAdded > 0)
441 for (int i = m_series->count(); i < currentSize + toBeAdded; i++) {
440 for (int i = m_series->count(); i < currentSize + toBeAdded; i++) {
442 QPointF point;
441 QPointF point;
443 point.setX(m_model->data(xModelIndex(i), Qt::DisplayRole).toDouble());
442 point.setX(m_model->data(xModelIndex(i), Qt::DisplayRole).toDouble());
444 point.setY(m_model->data(yModelIndex(i), Qt::DisplayRole).toDouble());
443 point.setY(m_model->data(yModelIndex(i), Qt::DisplayRole).toDouble());
445 m_series->insert(i, point);
444 m_series->insert(i, point);
446 }
445 }
447 }
446 }
448 }*/
447 }*/
449 }
448 }
450
449
451 void QBarModelMapperPrivate::initializeBarFromModel()
450 void QBarModelMapperPrivate::initializeBarFromModel()
452 {
451 {
453 if (m_model == 0 || m_series == 0)
452 if (m_model == 0 || m_series == 0)
454 return;
453 return;
455
454
456 blockSeriesSignals();
455 blockSeriesSignals();
457 // clear current content
456 // clear current content
458 m_series->clear();
457 m_series->clear();
459
458
460 // create the initial bar sets
459 // create the initial bar sets
461 for (int i = m_firstBarSetSection; i <= m_lastBarSetSection; i++) {
460 for (int i = m_firstBarSetSection; i <= m_lastBarSetSection; i++) {
462 int posInBar = 0;
461 int posInBar = 0;
463 QModelIndex barIndex = barModelIndex(i, posInBar);
462 QModelIndex barIndex = barModelIndex(i, posInBar);
464 // check if there is such model index
463 // check if there is such model index
465 if (barIndex.isValid()) {
464 if (barIndex.isValid()) {
466 QBarSet *barSet = new QBarSet(m_model->headerData(i, Qt::Horizontal).toString());
465 QBarSet *barSet = new QBarSet(m_model->headerData(i, Qt::Horizontal).toString());
467 while (barIndex.isValid()) {
466 while (barIndex.isValid()) {
468 barSet->append(m_model->data(barIndex, Qt::DisplayRole).toDouble());
467 barSet->append(m_model->data(barIndex, Qt::DisplayRole).toDouble());
469 posInBar++;
468 posInBar++;
470 barIndex = barModelIndex(i, posInBar);
469 barIndex = barModelIndex(i, posInBar);
471 }
470 }
472 m_series->append(barSet);
471 m_series->append(barSet);
473 } else {
472 } else {
474 break;
473 break;
475 }
474 }
476 }
475 }
477 blockSeriesSignals(false);
476 blockSeriesSignals(false);
478 }
477 }
479
478
480 #include "moc_qbarmodelmapper.cpp"
479 #include "moc_qbarmodelmapper.cpp"
481 #include "moc_qbarmodelmapper_p.cpp"
480 #include "moc_qbarmodelmapper_p.cpp"
482
481
483 QTCOMMERCIALCHART_END_NAMESPACE
482 QTCOMMERCIALCHART_END_NAMESPACE
@@ -1,70 +1,79
1 /****************************************************************************
1 /****************************************************************************
2 **
2 **
3 ** Copyright (C) 2012 Digia Plc
3 ** Copyright (C) 2012 Digia Plc
4 ** All rights reserved.
4 ** All rights reserved.
5 ** For any questions to Digia, please use contact form at http://qt.digia.com
5 ** For any questions to Digia, please use contact form at http://qt.digia.com
6 **
6 **
7 ** This file is part of the Qt Commercial Charts Add-on.
7 ** This file is part of the Qt Commercial Charts Add-on.
8 **
8 **
9 ** $QT_BEGIN_LICENSE$
9 ** $QT_BEGIN_LICENSE$
10 ** Licensees holding valid Qt Commercial licenses may use this file in
10 ** Licensees holding valid Qt Commercial licenses may use this file in
11 ** accordance with the Qt Commercial License Agreement provided with the
11 ** accordance with the Qt Commercial License Agreement provided with the
12 ** Software or, alternatively, in accordance with the terms contained in
12 ** Software or, alternatively, in accordance with the terms contained in
13 ** a written agreement between you and Digia.
13 ** a written agreement between you and Digia.
14 **
14 **
15 ** If you have questions regarding the use of this file, please use
15 ** If you have questions regarding the use of this file, please use
16 ** contact form at http://qt.digia.com
16 ** contact form at http://qt.digia.com
17 ** $QT_END_LICENSE$
17 ** $QT_END_LICENSE$
18 **
18 **
19 ****************************************************************************/
19 ****************************************************************************/
20
20
21 // W A R N I N G
22 // -------------
23 //
24 // This file is not part of the QtCommercial Chart API. It exists purely as an
25 // implementation detail. This header file may change from version to
26 // version without notice, or even be removed.
27 //
28 // We mean it.
29
21 #ifndef QPIESERIES_P_H
30 #ifndef QPIESERIES_P_H
22 #define QPIESERIES_P_H
31 #define QPIESERIES_P_H
23
32
24 #include "qpieseries.h"
33 #include "qpieseries.h"
25 #include "qabstractseries_p.h"
34 #include "qabstractseries_p.h"
26
35
27 QTCOMMERCIALCHART_BEGIN_NAMESPACE
36 QTCOMMERCIALCHART_BEGIN_NAMESPACE
28 class QLegendPrivate;
37 class QLegendPrivate;
29
38
30 class QPieSeriesPrivate : public QAbstractSeriesPrivate
39 class QPieSeriesPrivate : public QAbstractSeriesPrivate
31 {
40 {
32 Q_OBJECT
41 Q_OBJECT
33
42
34 public:
43 public:
35 QPieSeriesPrivate(QPieSeries *parent);
44 QPieSeriesPrivate(QPieSeries *parent);
36 ~QPieSeriesPrivate();
45 ~QPieSeriesPrivate();
37
46
38 void scaleDomain(Domain& domain);
47 void scaleDomain(Domain& domain);
39 Chart* createGraphics(ChartPresenter *presenter);
48 Chart* createGraphics(ChartPresenter *presenter);
40 QList<LegendMarker*> createLegendMarker(QLegend *legend);
49 QList<LegendMarker*> createLegendMarker(QLegend *legend);
41
50
42 void updateDerivativeData();
51 void updateDerivativeData();
43
52
44 static QPieSeriesPrivate* fromSeries(QPieSeries *series);
53 static QPieSeriesPrivate* fromSeries(QPieSeries *series);
45
54
46 signals:
55 signals:
47 void calculatedDataChanged();
56 void calculatedDataChanged();
48
57
49 public Q_SLOTS:
58 public Q_SLOTS:
50 void sliceValueChanged();
59 void sliceValueChanged();
51 void sliceClicked();
60 void sliceClicked();
52 void sliceHovered(bool state);
61 void sliceHovered(bool state);
53
62
54 private:
63 private:
55 QList<QPieSlice*> m_slices;
64 QList<QPieSlice*> m_slices;
56 qreal m_pieRelativeHorPos;
65 qreal m_pieRelativeHorPos;
57 qreal m_pieRelativeVerPos;
66 qreal m_pieRelativeVerPos;
58 qreal m_pieRelativeSize;
67 qreal m_pieRelativeSize;
59 qreal m_pieStartAngle;
68 qreal m_pieStartAngle;
60 qreal m_pieEndAngle;
69 qreal m_pieEndAngle;
61 qreal m_sum;
70 qreal m_sum;
62
71
63 private:
72 private:
64 friend class QLegendPrivate;
73 friend class QLegendPrivate;
65 Q_DECLARE_PUBLIC(QPieSeries)
74 Q_DECLARE_PUBLIC(QPieSeries)
66 };
75 };
67
76
68 QTCOMMERCIALCHART_END_NAMESPACE
77 QTCOMMERCIALCHART_END_NAMESPACE
69
78
70 #endif // QPIESERIES_P_H
79 #endif // QPIESERIES_P_H
@@ -1,45 +1,74
1 /****************************************************************************
2 **
3 ** Copyright (C) 2012 Digia Plc
4 ** All rights reserved.
5 ** For any questions to Digia, please use contact form at http://qt.digia.com
6 **
7 ** This file is part of the Qt Commercial Charts Add-on.
8 **
9 ** $QT_BEGIN_LICENSE$
10 ** Licensees holding valid Qt Commercial licenses may use this file in
11 ** accordance with the Qt Commercial License Agreement provided with the
12 ** Software or, alternatively, in accordance with the terms contained in
13 ** a written agreement between you and Digia.
14 **
15 ** If you have questions regarding the use of this file, please use
16 ** contact form at http://qt.digia.com
17 ** $QT_END_LICENSE$
18 **
19 ****************************************************************************/
20
21 // W A R N I N G
22 // -------------
23 //
24 // This file is not part of the QtCommercial Chart API. It exists purely as an
25 // implementation detail. This header file may change from version to
26 // version without notice, or even be removed.
27 //
28 // We mean it.
29
1 #ifndef QPIESLICE_P_H
30 #ifndef QPIESLICE_P_H
2 #define QPIESLICE_P_H
31 #define QPIESLICE_P_H
3
32
4 #include <QObject>
33 #include <QObject>
5 #include "qpieslice.h"
34 #include "qpieslice.h"
6 #include "pieslicedata_p.h"
35 #include "pieslicedata_p.h"
7
36
8 QTCOMMERCIALCHART_BEGIN_NAMESPACE
37 QTCOMMERCIALCHART_BEGIN_NAMESPACE
9 class QPieSeries;
38 class QPieSeries;
10
39
11 class QPieSlicePrivate : public QObject
40 class QPieSlicePrivate : public QObject
12 {
41 {
13 Q_OBJECT
42 Q_OBJECT
14
43
15 public:
44 public:
16 QPieSlicePrivate(QPieSlice *parent);
45 QPieSlicePrivate(QPieSlice *parent);
17 ~QPieSlicePrivate();
46 ~QPieSlicePrivate();
18
47
19 static QPieSlicePrivate* fromSlice(QPieSlice *slice);
48 static QPieSlicePrivate* fromSlice(QPieSlice *slice);
20
49
21 void setPen(const QPen &pen, bool themed);
50 void setPen(const QPen &pen, bool themed);
22 void setBrush(const QBrush &brush, bool themed);
51 void setBrush(const QBrush &brush, bool themed);
23 void setLabelBrush(const QBrush &brush, bool themed);
52 void setLabelBrush(const QBrush &brush, bool themed);
24 void setLabelFont(const QFont &font, bool themed);
53 void setLabelFont(const QFont &font, bool themed);
25
54
26 void setPercentage(qreal percentage);
55 void setPercentage(qreal percentage);
27 void setStartAngle(qreal angle);
56 void setStartAngle(qreal angle);
28 void setAngleSpan(qreal span);
57 void setAngleSpan(qreal span);
29
58
30 private:
59 private:
31 friend class QPieSeries;
60 friend class QPieSeries;
32 friend class QPieSeriesPrivate;
61 friend class QPieSeriesPrivate;
33 friend class ChartTheme;
62 friend class ChartTheme;
34 friend class PieChartItem;
63 friend class PieChartItem;
35
64
36 QPieSlice * const q_ptr;
65 QPieSlice * const q_ptr;
37 Q_DECLARE_PUBLIC(QPieSlice)
66 Q_DECLARE_PUBLIC(QPieSlice)
38
67
39 PieSliceData m_data;
68 PieSliceData m_data;
40 QPieSeries *m_series;
69 QPieSeries *m_series;
41 };
70 };
42
71
43 QTCOMMERCIALCHART_END_NAMESPACE
72 QTCOMMERCIALCHART_END_NAMESPACE
44
73
45 #endif // QPIESLICE_P_H
74 #endif // QPIESLICE_P_H
@@ -1,266 +1,286
1 /****************************************************************************
2 **
3 ** Copyright (C) 2012 Digia Plc
4 ** All rights reserved.
5 ** For any questions to Digia, please use contact form at http://qt.digia.com
6 **
7 ** This file is part of the Qt Commercial Charts Add-on.
8 **
9 ** $QT_BEGIN_LICENSE$
10 ** Licensees holding valid Qt Commercial licenses may use this file in
11 ** accordance with the Qt Commercial License Agreement provided with the
12 ** Software or, alternatively, in accordance with the terms contained in
13 ** a written agreement between you and Digia.
14 **
15 ** If you have questions regarding the use of this file, please use
16 ** contact form at http://qt.digia.com
17 ** $QT_END_LICENSE$
18 **
19 ****************************************************************************/
20
1 #include <QtCore/QString>
21 #include <QtCore/QString>
2 #include <QtTest/QtTest>
22 #include <QtTest/QtTest>
3
23
4 #include <qchart.h>
24 #include <qchart.h>
5 #include <qchartview.h>
25 #include <qchartview.h>
6 #include <qgroupedbarseries.h>
26 #include <qgroupedbarseries.h>
7 #include <qbarset.h>
27 #include <qbarset.h>
8 #include <qvbarmodelmapper.h>
28 #include <qvbarmodelmapper.h>
9 #include <qhbarmodelmapper.h>
29 #include <qhbarmodelmapper.h>
10 #include <QStandardItemModel>
30 #include <QStandardItemModel>
11
31
12 QTCOMMERCIALCHART_USE_NAMESPACE
32 QTCOMMERCIALCHART_USE_NAMESPACE
13
33
14 class tst_qbarmodelmapper : public QObject
34 class tst_qbarmodelmapper : public QObject
15 {
35 {
16 Q_OBJECT
36 Q_OBJECT
17
37
18 public:
38 public:
19 tst_qbarmodelmapper();
39 tst_qbarmodelmapper();
20
40
21 private Q_SLOTS:
41 private Q_SLOTS:
22 void initTestCase();
42 void initTestCase();
23 void cleanupTestCase();
43 void cleanupTestCase();
24 void init();
44 void init();
25 void cleanup();
45 void cleanup();
26 void verticalMapper_data();
46 void verticalMapper_data();
27 void verticalMapper();
47 void verticalMapper();
28 void verticalMapperCustomMapping_data();
48 void verticalMapperCustomMapping_data();
29 void verticalMapperCustomMapping();
49 void verticalMapperCustomMapping();
30 void horizontalMapper_data();
50 void horizontalMapper_data();
31 void horizontalMapper();
51 void horizontalMapper();
32 void horizontalMapperCustomMapping_data();
52 void horizontalMapperCustomMapping_data();
33 void horizontalMapperCustomMapping();
53 void horizontalMapperCustomMapping();
34
54
35 private:
55 private:
36 QStandardItemModel *m_model;
56 QStandardItemModel *m_model;
37 int m_modelRowCount;
57 int m_modelRowCount;
38 int m_modelColumnCount;
58 int m_modelColumnCount;
39
59
40 QGroupedBarSeries *m_series;
60 QGroupedBarSeries *m_series;
41 QChart *m_chart;
61 QChart *m_chart;
42 };
62 };
43
63
44 tst_qbarmodelmapper::tst_qbarmodelmapper():
64 tst_qbarmodelmapper::tst_qbarmodelmapper():
45 m_model(0),
65 m_model(0),
46 m_modelRowCount(10),
66 m_modelRowCount(10),
47 m_modelColumnCount(8)
67 m_modelColumnCount(8)
48 {
68 {
49 }
69 }
50
70
51 void tst_qbarmodelmapper::init()
71 void tst_qbarmodelmapper::init()
52 {
72 {
53 // m_series = new QGroupedBarSeries;
73 // m_series = new QGroupedBarSeries;
54 // m_chart->addSeries(m_series);
74 // m_chart->addSeries(m_series);
55 }
75 }
56
76
57 void tst_qbarmodelmapper::cleanup()
77 void tst_qbarmodelmapper::cleanup()
58 {
78 {
59 m_chart->removeSeries(m_series);
79 m_chart->removeSeries(m_series);
60 delete m_series;
80 delete m_series;
61 m_series = 0;
81 m_series = 0;
62 }
82 }
63
83
64 void tst_qbarmodelmapper::initTestCase()
84 void tst_qbarmodelmapper::initTestCase()
65 {
85 {
66 m_chart = new QChart;
86 m_chart = new QChart;
67 QChartView *chartView = new QChartView(m_chart);
87 QChartView *chartView = new QChartView(m_chart);
68 chartView->show();
88 chartView->show();
69
89
70 m_model = new QStandardItemModel(this);
90 m_model = new QStandardItemModel(this);
71 for (int row = 0; row < m_modelRowCount; ++row) {
91 for (int row = 0; row < m_modelRowCount; ++row) {
72 for (int column = 0; column < m_modelColumnCount; column++) {
92 for (int column = 0; column < m_modelColumnCount; column++) {
73 QStandardItem *item = new QStandardItem(row * column);
93 QStandardItem *item = new QStandardItem(row * column);
74 m_model->setItem(row, column, item);
94 m_model->setItem(row, column, item);
75 }
95 }
76 }
96 }
77 }
97 }
78
98
79 void tst_qbarmodelmapper::cleanupTestCase()
99 void tst_qbarmodelmapper::cleanupTestCase()
80 {
100 {
81 m_model->clear();
101 m_model->clear();
82 }
102 }
83
103
84 void tst_qbarmodelmapper::verticalMapper_data()
104 void tst_qbarmodelmapper::verticalMapper_data()
85 {
105 {
86 QTest::addColumn<int>("firstBarSetColumn");
106 QTest::addColumn<int>("firstBarSetColumn");
87 QTest::addColumn<int>("lastBarSetColumn");
107 QTest::addColumn<int>("lastBarSetColumn");
88 QTest::addColumn<int>("expectedBarSetCount");
108 QTest::addColumn<int>("expectedBarSetCount");
89 QTest::newRow("lastBarSetColumn greater than firstBarSetColumn") << 0 << 1 << 2;
109 QTest::newRow("lastBarSetColumn greater than firstBarSetColumn") << 0 << 1 << 2;
90 QTest::newRow("lastBarSetColumn equal to firstBarSetColumn") << 1 << 1 << 1;
110 QTest::newRow("lastBarSetColumn equal to firstBarSetColumn") << 1 << 1 << 1;
91 QTest::newRow("lastBarSetColumn lesser than firstBarSetColumn") << 1 << 0 << 0;
111 QTest::newRow("lastBarSetColumn lesser than firstBarSetColumn") << 1 << 0 << 0;
92 QTest::newRow("invalid firstBarSetColumn and correct lastBarSetColumn") << -3 << 1 << 0;
112 QTest::newRow("invalid firstBarSetColumn and correct lastBarSetColumn") << -3 << 1 << 0;
93 QTest::newRow("firstBarSetColumn beyond the size of model and correct lastBarSetColumn") << m_modelColumnCount << 1 << 0;
113 QTest::newRow("firstBarSetColumn beyond the size of model and correct lastBarSetColumn") << m_modelColumnCount << 1 << 0;
94 QTest::newRow("firstBarSetColumn beyond the size of model and invalid lastBarSetColumn") << m_modelColumnCount << -1 << 0;
114 QTest::newRow("firstBarSetColumn beyond the size of model and invalid lastBarSetColumn") << m_modelColumnCount << -1 << 0;
95 }
115 }
96
116
97 void tst_qbarmodelmapper::verticalMapper()
117 void tst_qbarmodelmapper::verticalMapper()
98 {
118 {
99 QFETCH(int, firstBarSetColumn);
119 QFETCH(int, firstBarSetColumn);
100 QFETCH(int, lastBarSetColumn);
120 QFETCH(int, lastBarSetColumn);
101 QFETCH(int, expectedBarSetCount);
121 QFETCH(int, expectedBarSetCount);
102
122
103 m_series = new QGroupedBarSeries;
123 m_series = new QGroupedBarSeries;
104
124
105 QVBarModelMapper *mapper = new QVBarModelMapper;
125 QVBarModelMapper *mapper = new QVBarModelMapper;
106 mapper->setFirstBarSetColumn(firstBarSetColumn);
126 mapper->setFirstBarSetColumn(firstBarSetColumn);
107 mapper->setLastBarSetColumn(lastBarSetColumn);
127 mapper->setLastBarSetColumn(lastBarSetColumn);
108 mapper->setModel(m_model);
128 mapper->setModel(m_model);
109 mapper->setSeries(m_series);
129 mapper->setSeries(m_series);
110
130
111 m_chart->addSeries(m_series);
131 m_chart->addSeries(m_series);
112
132
113 QCOMPARE(m_series->barsetCount(), expectedBarSetCount);
133 QCOMPARE(m_series->barsetCount(), expectedBarSetCount);
114 QCOMPARE(mapper->firstBarSetColumn(), qMax(-1, firstBarSetColumn));
134 QCOMPARE(mapper->firstBarSetColumn(), qMax(-1, firstBarSetColumn));
115 QCOMPARE(mapper->lastBarSetColumn(), qMax(-1, lastBarSetColumn));
135 QCOMPARE(mapper->lastBarSetColumn(), qMax(-1, lastBarSetColumn));
116
136
117 delete mapper;
137 delete mapper;
118 mapper = 0;
138 mapper = 0;
119 }
139 }
120
140
121 void tst_qbarmodelmapper::verticalMapperCustomMapping_data()
141 void tst_qbarmodelmapper::verticalMapperCustomMapping_data()
122 {
142 {
123 QTest::addColumn<int>("first");
143 QTest::addColumn<int>("first");
124 QTest::addColumn<int>("countLimit");
144 QTest::addColumn<int>("countLimit");
125 QTest::addColumn<int>("expectedBarSetCount");
145 QTest::addColumn<int>("expectedBarSetCount");
126 QTest::addColumn<int>("expectedCount");
146 QTest::addColumn<int>("expectedCount");
127 QTest::newRow("first: 0, unlimited count") << 0 << -1 << 2 << m_modelRowCount;
147 QTest::newRow("first: 0, unlimited count") << 0 << -1 << 2 << m_modelRowCount;
128 QTest::newRow("first: 3, unlimited count") << 3 << -1 << 2 << m_modelRowCount - 3;
148 QTest::newRow("first: 3, unlimited count") << 3 << -1 << 2 << m_modelRowCount - 3;
129 QTest::newRow("first: 0, count: 5") << 0 << 5 << 2 << qMin(5, m_modelRowCount);
149 QTest::newRow("first: 0, count: 5") << 0 << 5 << 2 << qMin(5, m_modelRowCount);
130 QTest::newRow("first: 3, count: 5") << 3 << 5 << 2 << qMin(5, m_modelRowCount - 3);
150 QTest::newRow("first: 3, count: 5") << 3 << 5 << 2 << qMin(5, m_modelRowCount - 3);
131 QTest::newRow("first: +1 greater then the number of rows in the model, unlimited count") << m_modelRowCount + 1 << -1 << 0 << 0;
151 QTest::newRow("first: +1 greater then the number of rows in the model, unlimited count") << m_modelRowCount + 1 << -1 << 0 << 0;
132 QTest::newRow("first: +1 greater then the number of rows in the model, count: 5") << m_modelRowCount + 1 << 5 << 0 << 0;
152 QTest::newRow("first: +1 greater then the number of rows in the model, count: 5") << m_modelRowCount + 1 << 5 << 0 << 0;
133 QTest::newRow("first: 0, count: +3 greater than the number of rows in the model (should limit to the size of model)") << 0 << m_modelRowCount + 3 << 2 << m_modelRowCount;
153 QTest::newRow("first: 0, count: +3 greater than the number of rows in the model (should limit to the size of model)") << 0 << m_modelRowCount + 3 << 2 << m_modelRowCount;
134 QTest::newRow("first: -3(invalid - should default to 0), unlimited count") << -3 << -1 << 2 << m_modelRowCount;
154 QTest::newRow("first: -3(invalid - should default to 0), unlimited count") << -3 << -1 << 2 << m_modelRowCount;
135 QTest::newRow("first: 0, count: -3 (invalid - shlould default to -1)") << 0 << -3 << 2 << m_modelRowCount;
155 QTest::newRow("first: 0, count: -3 (invalid - shlould default to -1)") << 0 << -3 << 2 << m_modelRowCount;
136 QTest::newRow("first: -3(invalid - should default to 0), count: -3 (invalid - shlould default to -1)") << -3 << -3 << 2 << m_modelRowCount;
156 QTest::newRow("first: -3(invalid - should default to 0), count: -3 (invalid - shlould default to -1)") << -3 << -3 << 2 << m_modelRowCount;
137 }
157 }
138
158
139 void tst_qbarmodelmapper::verticalMapperCustomMapping()
159 void tst_qbarmodelmapper::verticalMapperCustomMapping()
140 {
160 {
141 QFETCH(int, first);
161 QFETCH(int, first);
142 QFETCH(int, countLimit);
162 QFETCH(int, countLimit);
143 QFETCH(int, expectedBarSetCount);
163 QFETCH(int, expectedBarSetCount);
144 QFETCH(int, expectedCount);
164 QFETCH(int, expectedCount);
145
165
146 m_series = new QGroupedBarSeries;
166 m_series = new QGroupedBarSeries;
147
167
148 QCOMPARE(m_series->barsetCount(), 0);
168 QCOMPARE(m_series->barsetCount(), 0);
149
169
150 QVBarModelMapper *mapper = new QVBarModelMapper;
170 QVBarModelMapper *mapper = new QVBarModelMapper;
151 mapper->setFirstBarSetColumn(0);
171 mapper->setFirstBarSetColumn(0);
152 mapper->setLastBarSetColumn(1);
172 mapper->setLastBarSetColumn(1);
153 mapper->setModel(m_model);
173 mapper->setModel(m_model);
154 mapper->setSeries(m_series);
174 mapper->setSeries(m_series);
155 mapper->setFirst(first);
175 mapper->setFirst(first);
156 mapper->setCount(countLimit);
176 mapper->setCount(countLimit);
157 m_chart->addSeries(m_series);
177 m_chart->addSeries(m_series);
158
178
159 QCOMPARE(m_series->barsetCount(), expectedBarSetCount);
179 QCOMPARE(m_series->barsetCount(), expectedBarSetCount);
160
180
161 if (expectedBarSetCount > 0)
181 if (expectedBarSetCount > 0)
162 QCOMPARE(m_series->barSets().first()->count(), expectedCount);
182 QCOMPARE(m_series->barSets().first()->count(), expectedCount);
163
183
164 // change values column mapping to invalid
184 // change values column mapping to invalid
165 mapper->setFirstBarSetColumn(-1);
185 mapper->setFirstBarSetColumn(-1);
166 mapper->setLastBarSetColumn(1);
186 mapper->setLastBarSetColumn(1);
167
187
168 QCOMPARE(m_series->barsetCount(), 0);
188 QCOMPARE(m_series->barsetCount(), 0);
169
189
170 delete mapper;
190 delete mapper;
171 mapper = 0;
191 mapper = 0;
172 }
192 }
173
193
174 void tst_qbarmodelmapper::horizontalMapper_data()
194 void tst_qbarmodelmapper::horizontalMapper_data()
175 {
195 {
176 QTest::addColumn<int>("firstBarSetRow");
196 QTest::addColumn<int>("firstBarSetRow");
177 QTest::addColumn<int>("lastBarSetRow");
197 QTest::addColumn<int>("lastBarSetRow");
178 QTest::addColumn<int>("expectedBarSetCount");
198 QTest::addColumn<int>("expectedBarSetCount");
179 QTest::newRow("lastBarSetRow greater than firstBarSetRow") << 0 << 1 << 2;
199 QTest::newRow("lastBarSetRow greater than firstBarSetRow") << 0 << 1 << 2;
180 QTest::newRow("lastBarSetRow equal to firstBarSetRow") << 1 << 1 << 1;
200 QTest::newRow("lastBarSetRow equal to firstBarSetRow") << 1 << 1 << 1;
181 QTest::newRow("lastBarSetRow lesser than firstBarSetRow") << 1 << 0 << 0;
201 QTest::newRow("lastBarSetRow lesser than firstBarSetRow") << 1 << 0 << 0;
182 QTest::newRow("invalid firstBarSetRow and correct lastBarSetRow") << -3 << 1 << 0;
202 QTest::newRow("invalid firstBarSetRow and correct lastBarSetRow") << -3 << 1 << 0;
183 QTest::newRow("firstBarSetRow beyond the size of model and correct lastBarSetRow") << m_modelRowCount << 1 << 0;
203 QTest::newRow("firstBarSetRow beyond the size of model and correct lastBarSetRow") << m_modelRowCount << 1 << 0;
184 QTest::newRow("firstBarSetRow beyond the size of model and invalid lastBarSetRow") << m_modelRowCount << -1 << 0;
204 QTest::newRow("firstBarSetRow beyond the size of model and invalid lastBarSetRow") << m_modelRowCount << -1 << 0;
185 }
205 }
186
206
187 void tst_qbarmodelmapper::horizontalMapper()
207 void tst_qbarmodelmapper::horizontalMapper()
188 {
208 {
189 QFETCH(int, firstBarSetRow);
209 QFETCH(int, firstBarSetRow);
190 QFETCH(int, lastBarSetRow);
210 QFETCH(int, lastBarSetRow);
191 QFETCH(int, expectedBarSetCount);
211 QFETCH(int, expectedBarSetCount);
192
212
193 m_series = new QGroupedBarSeries;
213 m_series = new QGroupedBarSeries;
194
214
195 QHBarModelMapper *mapper = new QHBarModelMapper;
215 QHBarModelMapper *mapper = new QHBarModelMapper;
196 mapper->setFirstBarSetRow(firstBarSetRow);
216 mapper->setFirstBarSetRow(firstBarSetRow);
197 mapper->setLastBarSetRow(lastBarSetRow);
217 mapper->setLastBarSetRow(lastBarSetRow);
198 mapper->setModel(m_model);
218 mapper->setModel(m_model);
199 mapper->setSeries(m_series);
219 mapper->setSeries(m_series);
200
220
201 m_chart->addSeries(m_series);
221 m_chart->addSeries(m_series);
202
222
203 QCOMPARE(m_series->barsetCount(), expectedBarSetCount);
223 QCOMPARE(m_series->barsetCount(), expectedBarSetCount);
204 QCOMPARE(mapper->firstBarSetRow(), qMax(-1, firstBarSetRow));
224 QCOMPARE(mapper->firstBarSetRow(), qMax(-1, firstBarSetRow));
205 QCOMPARE(mapper->lastBarSetRow(), qMax(-1, lastBarSetRow));
225 QCOMPARE(mapper->lastBarSetRow(), qMax(-1, lastBarSetRow));
206
226
207 delete mapper;
227 delete mapper;
208 mapper = 0;
228 mapper = 0;
209 }
229 }
210
230
211 void tst_qbarmodelmapper::horizontalMapperCustomMapping_data()
231 void tst_qbarmodelmapper::horizontalMapperCustomMapping_data()
212 {
232 {
213 QTest::addColumn<int>("first");
233 QTest::addColumn<int>("first");
214 QTest::addColumn<int>("countLimit");
234 QTest::addColumn<int>("countLimit");
215 QTest::addColumn<int>("expectedBarSetCount");
235 QTest::addColumn<int>("expectedBarSetCount");
216 QTest::addColumn<int>("expectedCount");
236 QTest::addColumn<int>("expectedCount");
217 QTest::newRow("first: 0, unlimited count") << 0 << -1 << 2 << m_modelColumnCount;
237 QTest::newRow("first: 0, unlimited count") << 0 << -1 << 2 << m_modelColumnCount;
218 QTest::newRow("first: 3, unlimited count") << 3 << -1 << 2 << m_modelColumnCount - 3;
238 QTest::newRow("first: 3, unlimited count") << 3 << -1 << 2 << m_modelColumnCount - 3;
219 QTest::newRow("first: 0, count: 5") << 0 << 5 << 2 << qMin(5, m_modelColumnCount);
239 QTest::newRow("first: 0, count: 5") << 0 << 5 << 2 << qMin(5, m_modelColumnCount);
220 QTest::newRow("first: 3, count: 5") << 3 << 5 << 2 << qMin(5, m_modelColumnCount - 3);
240 QTest::newRow("first: 3, count: 5") << 3 << 5 << 2 << qMin(5, m_modelColumnCount - 3);
221 QTest::newRow("first: +1 greater then the number of rows in the model, unlimited count") << m_modelColumnCount + 1 << -1 << 0 << 0;
241 QTest::newRow("first: +1 greater then the number of rows in the model, unlimited count") << m_modelColumnCount + 1 << -1 << 0 << 0;
222 QTest::newRow("first: +1 greater then the number of rows in the model, count: 5") << m_modelColumnCount + 1 << 5 << 0 << 0;
242 QTest::newRow("first: +1 greater then the number of rows in the model, count: 5") << m_modelColumnCount + 1 << 5 << 0 << 0;
223 QTest::newRow("first: 0, count: +3 greater than the number of rows in the model (should limit to the size of model)") << 0 << m_modelColumnCount + 3 << 2 << m_modelColumnCount;
243 QTest::newRow("first: 0, count: +3 greater than the number of rows in the model (should limit to the size of model)") << 0 << m_modelColumnCount + 3 << 2 << m_modelColumnCount;
224 QTest::newRow("first: -3(invalid - should default to 0), unlimited count") << -3 << -1 << 2 << m_modelColumnCount;
244 QTest::newRow("first: -3(invalid - should default to 0), unlimited count") << -3 << -1 << 2 << m_modelColumnCount;
225 QTest::newRow("first: 0, count: -3 (invalid - shlould default to -1)") << 0 << -3 << 2 << m_modelColumnCount;
245 QTest::newRow("first: 0, count: -3 (invalid - shlould default to -1)") << 0 << -3 << 2 << m_modelColumnCount;
226 QTest::newRow("first: -3(invalid - should default to 0), count: -3 (invalid - shlould default to -1)") << -3 << -3 << 2 << m_modelColumnCount;
246 QTest::newRow("first: -3(invalid - should default to 0), count: -3 (invalid - shlould default to -1)") << -3 << -3 << 2 << m_modelColumnCount;
227 }
247 }
228
248
229 void tst_qbarmodelmapper::horizontalMapperCustomMapping()
249 void tst_qbarmodelmapper::horizontalMapperCustomMapping()
230 {
250 {
231 QFETCH(int, first);
251 QFETCH(int, first);
232 QFETCH(int, countLimit);
252 QFETCH(int, countLimit);
233 QFETCH(int, expectedBarSetCount);
253 QFETCH(int, expectedBarSetCount);
234 QFETCH(int, expectedCount);
254 QFETCH(int, expectedCount);
235
255
236 m_series = new QGroupedBarSeries;
256 m_series = new QGroupedBarSeries;
237
257
238 QCOMPARE(m_series->barsetCount(), 0);
258 QCOMPARE(m_series->barsetCount(), 0);
239
259
240 QHBarModelMapper *mapper = new QHBarModelMapper;
260 QHBarModelMapper *mapper = new QHBarModelMapper;
241 mapper->setFirstBarSetRow(0);
261 mapper->setFirstBarSetRow(0);
242 mapper->setLastBarSetRow(1);
262 mapper->setLastBarSetRow(1);
243 mapper->setModel(m_model);
263 mapper->setModel(m_model);
244 mapper->setSeries(m_series);
264 mapper->setSeries(m_series);
245 mapper->setFirst(first);
265 mapper->setFirst(first);
246 mapper->setCount(countLimit);
266 mapper->setCount(countLimit);
247 m_chart->addSeries(m_series);
267 m_chart->addSeries(m_series);
248
268
249 QCOMPARE(m_series->barsetCount(), expectedBarSetCount);
269 QCOMPARE(m_series->barsetCount(), expectedBarSetCount);
250
270
251 if (expectedBarSetCount > 0)
271 if (expectedBarSetCount > 0)
252 QCOMPARE(m_series->barSets().first()->count(), expectedCount);
272 QCOMPARE(m_series->barSets().first()->count(), expectedCount);
253
273
254 // change values column mapping to invalid
274 // change values column mapping to invalid
255 mapper->setFirstBarSetRow(-1);
275 mapper->setFirstBarSetRow(-1);
256 mapper->setLastBarSetRow(1);
276 mapper->setLastBarSetRow(1);
257
277
258 QCOMPARE(m_series->barsetCount(), 0);
278 QCOMPARE(m_series->barsetCount(), 0);
259
279
260 delete mapper;
280 delete mapper;
261 mapper = 0;
281 mapper = 0;
262 }
282 }
263
283
264 QTEST_MAIN(tst_qbarmodelmapper)
284 QTEST_MAIN(tst_qbarmodelmapper)
265
285
266 #include "tst_qbarmodelmapper.moc"
286 #include "tst_qbarmodelmapper.moc"
@@ -1,591 +1,611
1 /****************************************************************************
2 **
3 ** Copyright (C) 2012 Digia Plc
4 ** All rights reserved.
5 ** For any questions to Digia, please use contact form at http://qt.digia.com
6 **
7 ** This file is part of the Qt Commercial Charts Add-on.
8 **
9 ** $QT_BEGIN_LICENSE$
10 ** Licensees holding valid Qt Commercial licenses may use this file in
11 ** accordance with the Qt Commercial License Agreement provided with the
12 ** Software or, alternatively, in accordance with the terms contained in
13 ** a written agreement between you and Digia.
14 **
15 ** If you have questions regarding the use of this file, please use
16 ** contact form at http://qt.digia.com
17 ** $QT_END_LICENSE$
18 **
19 ****************************************************************************/
20
1 #include <QtTest/QtTest>
21 #include <QtTest/QtTest>
2 #include <qchartview.h>
22 #include <qchartview.h>
3 #include <qlineseries.h>
23 #include <qlineseries.h>
4 #include <qareaseries.h>
24 #include <qareaseries.h>
5 #include <qscatterseries.h>
25 #include <qscatterseries.h>
6 #include <qsplineseries.h>
26 #include <qsplineseries.h>
7 #include <qpieseries.h>
27 #include <qpieseries.h>
8 #include <qbarseries.h>
28 #include <qbarseries.h>
9 #include <qpercentbarseries.h>
29 #include <qpercentbarseries.h>
10 #include <qstackedbarseries.h>
30 #include <qstackedbarseries.h>
11
31
12 QTCOMMERCIALCHART_USE_NAMESPACE
32 QTCOMMERCIALCHART_USE_NAMESPACE
13
33
14 Q_DECLARE_METATYPE(QAxis *)
34 Q_DECLARE_METATYPE(QAxis *)
15 Q_DECLARE_METATYPE(QAbstractSeries *)
35 Q_DECLARE_METATYPE(QAbstractSeries *)
16 Q_DECLARE_METATYPE(QChart::AnimationOption)
36 Q_DECLARE_METATYPE(QChart::AnimationOption)
17 Q_DECLARE_METATYPE(QBrush)
37 Q_DECLARE_METATYPE(QBrush)
18 Q_DECLARE_METATYPE(QPen)
38 Q_DECLARE_METATYPE(QPen)
19 Q_DECLARE_METATYPE(QChart::ChartTheme)
39 Q_DECLARE_METATYPE(QChart::ChartTheme)
20
40
21 class tst_QChart : public QObject
41 class tst_QChart : public QObject
22 {
42 {
23 Q_OBJECT
43 Q_OBJECT
24
44
25 public slots:
45 public slots:
26 void initTestCase();
46 void initTestCase();
27 void cleanupTestCase();
47 void cleanupTestCase();
28 void init();
48 void init();
29 void cleanup();
49 void cleanup();
30
50
31 private slots:
51 private slots:
32 void qchart_data();
52 void qchart_data();
33 void qchart();
53 void qchart();
34
54
35 void addSeries_data();
55 void addSeries_data();
36 void addSeries();
56 void addSeries();
37 void animationOptions_data();
57 void animationOptions_data();
38 void animationOptions();
58 void animationOptions();
39 void axisX_data();
59 void axisX_data();
40 void axisX();
60 void axisX();
41 void axisY_data();
61 void axisY_data();
42 void axisY();
62 void axisY();
43 void backgroundBrush_data();
63 void backgroundBrush_data();
44 void backgroundBrush();
64 void backgroundBrush();
45 void backgroundPen_data();
65 void backgroundPen_data();
46 void backgroundPen();
66 void backgroundPen();
47 void isBackgroundVisible_data();
67 void isBackgroundVisible_data();
48 void isBackgroundVisible();
68 void isBackgroundVisible();
49 void legend_data();
69 void legend_data();
50 void legend();
70 void legend();
51 void margins_data();
71 void margins_data();
52 void margins();
72 void margins();
53 void removeAllSeries_data();
73 void removeAllSeries_data();
54 void removeAllSeries();
74 void removeAllSeries();
55 void removeSeries_data();
75 void removeSeries_data();
56 void removeSeries();
76 void removeSeries();
57 void scrollDown_data();
77 void scrollDown_data();
58 void scrollDown();
78 void scrollDown();
59 void scrollLeft_data();
79 void scrollLeft_data();
60 void scrollLeft();
80 void scrollLeft();
61 void scrollRight_data();
81 void scrollRight_data();
62 void scrollRight();
82 void scrollRight();
63 void scrollUp_data();
83 void scrollUp_data();
64 void scrollUp();
84 void scrollUp();
65 void theme_data();
85 void theme_data();
66 void theme();
86 void theme();
67 void title_data();
87 void title_data();
68 void title();
88 void title();
69 void titleBrush_data();
89 void titleBrush_data();
70 void titleBrush();
90 void titleBrush();
71 void titleFont_data();
91 void titleFont_data();
72 void titleFont();
92 void titleFont();
73 void zoomIn_data();
93 void zoomIn_data();
74 void zoomIn();
94 void zoomIn();
75 void zoomOut_data();
95 void zoomOut_data();
76 void zoomOut();
96 void zoomOut();
77
97
78 private:
98 private:
79 void createTestData();
99 void createTestData();
80
100
81 private:
101 private:
82 QChartView* m_view;
102 QChartView* m_view;
83 QChart* m_chart;
103 QChart* m_chart;
84 };
104 };
85
105
86 void tst_QChart::initTestCase()
106 void tst_QChart::initTestCase()
87 {
107 {
88
108
89 }
109 }
90
110
91 void tst_QChart::cleanupTestCase()
111 void tst_QChart::cleanupTestCase()
92 {
112 {
93
113
94 }
114 }
95
115
96 void tst_QChart::init()
116 void tst_QChart::init()
97 {
117 {
98 m_view = new QChartView(new QChart());
118 m_view = new QChartView(new QChart());
99 m_chart = m_view->chart();
119 m_chart = m_view->chart();
100 }
120 }
101
121
102 void tst_QChart::createTestData()
122 void tst_QChart::createTestData()
103 {
123 {
104 QLineSeries* series0 = new QLineSeries(this);
124 QLineSeries* series0 = new QLineSeries(this);
105 *series0 << QPointF(0, 0) << QPointF(100, 100);
125 *series0 << QPointF(0, 0) << QPointF(100, 100);
106 m_chart->addSeries(series0);
126 m_chart->addSeries(series0);
107 m_view->show();
127 m_view->show();
108 QTest::qWaitForWindowShown(m_view);
128 QTest::qWaitForWindowShown(m_view);
109 }
129 }
110
130
111 void tst_QChart::cleanup()
131 void tst_QChart::cleanup()
112 {
132 {
113 delete m_view;
133 delete m_view;
114 m_view = 0;
134 m_view = 0;
115 m_chart = 0;
135 m_chart = 0;
116 }
136 }
117
137
118 void tst_QChart::qchart_data()
138 void tst_QChart::qchart_data()
119 {
139 {
120 }
140 }
121
141
122 void tst_QChart::qchart()
142 void tst_QChart::qchart()
123 {
143 {
124 QVERIFY(m_chart);
144 QVERIFY(m_chart);
125 QVERIFY(m_chart->legend());
145 QVERIFY(m_chart->legend());
126 QVERIFY(m_chart->legend()->isVisible());
146 QVERIFY(m_chart->legend()->isVisible());
127
147
128 QCOMPARE(m_chart->animationOptions(), QChart::NoAnimation);
148 QCOMPARE(m_chart->animationOptions(), QChart::NoAnimation);
129 QVERIFY(m_chart->axisX());
149 QVERIFY(m_chart->axisX());
130 QVERIFY(m_chart->axisY());
150 QVERIFY(m_chart->axisY());
131 QVERIFY(m_chart->backgroundBrush()!=QBrush());
151 QVERIFY(m_chart->backgroundBrush()!=QBrush());
132 QVERIFY(m_chart->backgroundPen()!=QPen());
152 QVERIFY(m_chart->backgroundPen()!=QPen());
133 QCOMPARE(m_chart->isBackgroundVisible(), true);
153 QCOMPARE(m_chart->isBackgroundVisible(), true);
134
154
135 QVERIFY(m_chart->margins().top()>0);
155 QVERIFY(m_chart->margins().top()>0);
136 QVERIFY(m_chart->margins().left()>0);
156 QVERIFY(m_chart->margins().left()>0);
137 QVERIFY(m_chart->margins().right()>0);
157 QVERIFY(m_chart->margins().right()>0);
138 QVERIFY(m_chart->margins().bottom()>0);
158 QVERIFY(m_chart->margins().bottom()>0);
139
159
140 QCOMPARE(m_chart->theme(), QChart::ChartThemeLight);
160 QCOMPARE(m_chart->theme(), QChart::ChartThemeLight);
141 QCOMPARE(m_chart->title(), QString());
161 QCOMPARE(m_chart->title(), QString());
142
162
143 //QCOMPARE(m_chart->titleBrush(),QBrush());
163 //QCOMPARE(m_chart->titleBrush(),QBrush());
144 //QCOMPARE(m_chart->titleFont(),QFont());
164 //QCOMPARE(m_chart->titleFont(),QFont());
145
165
146 m_chart->removeAllSeries();
166 m_chart->removeAllSeries();
147 m_chart->scrollDown();
167 m_chart->scrollDown();
148 m_chart->scrollLeft();
168 m_chart->scrollLeft();
149 m_chart->scrollRight();
169 m_chart->scrollRight();
150 m_chart->scrollUp();
170 m_chart->scrollUp();
151
171
152 m_chart->zoomIn();
172 m_chart->zoomIn();
153 m_chart->zoomIn(QRectF());
173 m_chart->zoomIn(QRectF());
154 m_chart->zoomOut();
174 m_chart->zoomOut();
155 }
175 }
156
176
157 void tst_QChart::addSeries_data()
177 void tst_QChart::addSeries_data()
158 {
178 {
159 QTest::addColumn<QAbstractSeries *>("series");
179 QTest::addColumn<QAbstractSeries *>("series");
160 QTest::addColumn<QAxis *>("axis");
180 QTest::addColumn<QAxis *>("axis");
161
181
162 QAbstractSeries* series0 = new QLineSeries(this);
182 QAbstractSeries* series0 = new QLineSeries(this);
163 QAbstractSeries* series1 = new QAreaSeries(static_cast<QLineSeries*>(series0));
183 QAbstractSeries* series1 = new QAreaSeries(static_cast<QLineSeries*>(series0));
164 QAbstractSeries* series2 = new QScatterSeries(this);
184 QAbstractSeries* series2 = new QScatterSeries(this);
165 QAbstractSeries* series3 = new QSplineSeries(this);
185 QAbstractSeries* series3 = new QSplineSeries(this);
166 QAbstractSeries* series4 = new QPieSeries(this);
186 QAbstractSeries* series4 = new QPieSeries(this);
167 QAbstractSeries* series5 = new QBarSeries(this);
187 QAbstractSeries* series5 = new QBarSeries(this);
168 QAbstractSeries* series6 = new QPercentBarSeries(this);
188 QAbstractSeries* series6 = new QPercentBarSeries(this);
169 QAbstractSeries* series7 = new QStackedBarSeries(this);
189 QAbstractSeries* series7 = new QStackedBarSeries(this);
170
190
171 QAxis* axis = new QAxis(this);
191 QAxis* axis = new QAxis(this);
172
192
173 QTest::newRow("default axis: lineSeries") << series0 << (QAxis*) 0;
193 QTest::newRow("default axis: lineSeries") << series0 << (QAxis*) 0;
174 QTest::newRow("axis0: lineSeries") << series0 << axis;
194 QTest::newRow("axis0: lineSeries") << series0 << axis;
175 QTest::newRow("default axis: areaSeries") << series1 << (QAxis*) 0;
195 QTest::newRow("default axis: areaSeries") << series1 << (QAxis*) 0;
176 QTest::newRow("axis: areaSeries") << series1 << axis;
196 QTest::newRow("axis: areaSeries") << series1 << axis;
177 QTest::newRow("default axis: scatterSeries") << series2 << (QAxis*) 0;
197 QTest::newRow("default axis: scatterSeries") << series2 << (QAxis*) 0;
178 QTest::newRow("axis1: scatterSeries") << series2 << axis;
198 QTest::newRow("axis1: scatterSeries") << series2 << axis;
179 QTest::newRow("default axis: splineSeries") << series3 << (QAxis*) 0;
199 QTest::newRow("default axis: splineSeries") << series3 << (QAxis*) 0;
180 QTest::newRow("axis: splineSeries") << series3 << axis;
200 QTest::newRow("axis: splineSeries") << series3 << axis;
181 QTest::newRow("default axis: pieSeries") << series4 << (QAxis*) 0;
201 QTest::newRow("default axis: pieSeries") << series4 << (QAxis*) 0;
182 QTest::newRow("axis: pieSeries") << series4 << axis;
202 QTest::newRow("axis: pieSeries") << series4 << axis;
183 QTest::newRow("default axis: barSeries") << series5 << (QAxis*) 0;
203 QTest::newRow("default axis: barSeries") << series5 << (QAxis*) 0;
184 QTest::newRow("axis: barSeries") << series5 << axis;
204 QTest::newRow("axis: barSeries") << series5 << axis;
185 QTest::newRow("default axis: percentBarSeries") << series6 << (QAxis*) 0;
205 QTest::newRow("default axis: percentBarSeries") << series6 << (QAxis*) 0;
186 QTest::newRow("axis: barSeries") << series6 << axis;
206 QTest::newRow("axis: barSeries") << series6 << axis;
187 QTest::newRow("default axis: stackedBarSeries") << series7 << (QAxis*) 0;
207 QTest::newRow("default axis: stackedBarSeries") << series7 << (QAxis*) 0;
188 QTest::newRow("axis: barSeries") << series7 << axis;
208 QTest::newRow("axis: barSeries") << series7 << axis;
189
209
190 }
210 }
191
211
192 void tst_QChart::addSeries()
212 void tst_QChart::addSeries()
193 {
213 {
194 QFETCH(QAbstractSeries *, series);
214 QFETCH(QAbstractSeries *, series);
195 QFETCH(QAxis *, axis);
215 QFETCH(QAxis *, axis);
196 m_view->show();
216 m_view->show();
197 QTest::qWaitForWindowShown(m_view);
217 QTest::qWaitForWindowShown(m_view);
198 if(!axis) axis = m_chart->axisY();
218 if(!axis) axis = m_chart->axisY();
199 QVERIFY(!series->chart());
219 QVERIFY(!series->chart());
200 QCOMPARE(m_chart->series().count(), 0);
220 QCOMPARE(m_chart->series().count(), 0);
201 m_chart->addSeries(series,axis);
221 m_chart->addSeries(series,axis);
202 QCOMPARE(m_chart->series().count(), 1);
222 QCOMPARE(m_chart->series().count(), 1);
203 QCOMPARE(m_chart->series().first(), series);
223 QCOMPARE(m_chart->series().first(), series);
204 QVERIFY(series->chart() == m_chart);
224 QVERIFY(series->chart() == m_chart);
205 QCOMPARE(m_chart->axisY(series),axis);
225 QCOMPARE(m_chart->axisY(series),axis);
206 m_chart->removeSeries(series);
226 m_chart->removeSeries(series);
207 QVERIFY(!series->chart());
227 QVERIFY(!series->chart());
208 QCOMPARE(m_chart->series().count(), 0);
228 QCOMPARE(m_chart->series().count(), 0);
209 }
229 }
210
230
211 void tst_QChart::animationOptions_data()
231 void tst_QChart::animationOptions_data()
212 {
232 {
213 QTest::addColumn<QChart::AnimationOption>("animationOptions");
233 QTest::addColumn<QChart::AnimationOption>("animationOptions");
214 QTest::newRow("AllAnimations") << QChart::AllAnimations;
234 QTest::newRow("AllAnimations") << QChart::AllAnimations;
215 QTest::newRow("NoAnimation") << QChart::NoAnimation;
235 QTest::newRow("NoAnimation") << QChart::NoAnimation;
216 QTest::newRow("GridAxisAnimations") << QChart::GridAxisAnimations;
236 QTest::newRow("GridAxisAnimations") << QChart::GridAxisAnimations;
217 QTest::newRow("SeriesAnimations") << QChart::SeriesAnimations;
237 QTest::newRow("SeriesAnimations") << QChart::SeriesAnimations;
218 }
238 }
219
239
220 void tst_QChart::animationOptions()
240 void tst_QChart::animationOptions()
221 {
241 {
222 createTestData();
242 createTestData();
223 QFETCH(QChart::AnimationOption, animationOptions);
243 QFETCH(QChart::AnimationOption, animationOptions);
224 m_chart->setAnimationOptions(animationOptions);
244 m_chart->setAnimationOptions(animationOptions);
225 QCOMPARE(m_chart->animationOptions(), animationOptions);
245 QCOMPARE(m_chart->animationOptions(), animationOptions);
226 }
246 }
227
247
228 void tst_QChart::axisX_data()
248 void tst_QChart::axisX_data()
229 {
249 {
230
250
231 }
251 }
232
252
233 void tst_QChart::axisX()
253 void tst_QChart::axisX()
234 {
254 {
235 QVERIFY(m_chart->axisX());
255 QVERIFY(m_chart->axisX());
236 QAxis* axis = m_chart->axisX();
256 QAxis* axis = m_chart->axisX();
237 createTestData();
257 createTestData();
238 //it should be the same axis
258 //it should be the same axis
239 QCOMPARE(axis,m_chart->axisX());
259 QCOMPARE(axis,m_chart->axisX());
240 }
260 }
241
261
242 void tst_QChart::axisY_data()
262 void tst_QChart::axisY_data()
243 {
263 {
244 QTest::addColumn<QAxis*>("axis0");
264 QTest::addColumn<QAxis*>("axis0");
245 QTest::addColumn<QAxis*>("axis1");
265 QTest::addColumn<QAxis*>("axis1");
246 QTest::addColumn<QAxis*>("axis2");
266 QTest::addColumn<QAxis*>("axis2");
247 QTest::newRow("1 defualt, 2 optional") << (QAxis*)0 << new QAxis() << new QAxis();
267 QTest::newRow("1 defualt, 2 optional") << (QAxis*)0 << new QAxis() << new QAxis();
248 QTest::newRow("3 optional") << new QAxis() << new QAxis() << new QAxis();
268 QTest::newRow("3 optional") << new QAxis() << new QAxis() << new QAxis();
249 }
269 }
250
270
251
271
252 void tst_QChart::axisY()
272 void tst_QChart::axisY()
253 {
273 {
254 QFETCH(QAxis*, axis0);
274 QFETCH(QAxis*, axis0);
255 QFETCH(QAxis*, axis1);
275 QFETCH(QAxis*, axis1);
256 QFETCH(QAxis*, axis2);
276 QFETCH(QAxis*, axis2);
257
277
258 QAxis* defaultAxisY = m_chart->axisY();
278 QAxis* defaultAxisY = m_chart->axisY();
259
279
260 QVERIFY2(defaultAxisY, "Missing axisY.");
280 QVERIFY2(defaultAxisY, "Missing axisY.");
261
281
262 QLineSeries* series0 = new QLineSeries();
282 QLineSeries* series0 = new QLineSeries();
263 m_chart->addSeries(series0, axis0);
283 m_chart->addSeries(series0, axis0);
264
284
265 QLineSeries* series1 = new QLineSeries();
285 QLineSeries* series1 = new QLineSeries();
266 m_chart->addSeries(series1, axis1);
286 m_chart->addSeries(series1, axis1);
267
287
268 QLineSeries* series2 = new QLineSeries();
288 QLineSeries* series2 = new QLineSeries();
269 m_chart->addSeries(series2, axis2);
289 m_chart->addSeries(series2, axis2);
270
290
271 if (!axis0)
291 if (!axis0)
272 axis0 = defaultAxisY;
292 axis0 = defaultAxisY;
273 if (!axis1)
293 if (!axis1)
274 axis1 = defaultAxisY;
294 axis1 = defaultAxisY;
275 if (!axis2)
295 if (!axis2)
276 axis2 = defaultAxisY;
296 axis2 = defaultAxisY;
277
297
278 QVERIFY(m_chart->axisY(series0) == axis0);
298 QVERIFY(m_chart->axisY(series0) == axis0);
279 QVERIFY(m_chart->axisY(series1) == axis1);
299 QVERIFY(m_chart->axisY(series1) == axis1);
280 QVERIFY(m_chart->axisY(series2) == axis2);
300 QVERIFY(m_chart->axisY(series2) == axis2);
281 }
301 }
282
302
283 void tst_QChart::backgroundBrush_data()
303 void tst_QChart::backgroundBrush_data()
284 {
304 {
285 QTest::addColumn<QBrush>("backgroundBrush");
305 QTest::addColumn<QBrush>("backgroundBrush");
286 QTest::newRow("null") << QBrush();
306 QTest::newRow("null") << QBrush();
287 QTest::newRow("blue") << QBrush(Qt::blue);
307 QTest::newRow("blue") << QBrush(Qt::blue);
288 QTest::newRow("white") << QBrush(Qt::white);
308 QTest::newRow("white") << QBrush(Qt::white);
289 QTest::newRow("black") << QBrush(Qt::black);
309 QTest::newRow("black") << QBrush(Qt::black);
290 }
310 }
291
311
292 void tst_QChart::backgroundBrush()
312 void tst_QChart::backgroundBrush()
293 {
313 {
294 QFETCH(QBrush, backgroundBrush);
314 QFETCH(QBrush, backgroundBrush);
295 m_chart->setBackgroundBrush(backgroundBrush);
315 m_chart->setBackgroundBrush(backgroundBrush);
296 QCOMPARE(m_chart->backgroundBrush(), backgroundBrush);
316 QCOMPARE(m_chart->backgroundBrush(), backgroundBrush);
297 }
317 }
298
318
299 void tst_QChart::backgroundPen_data()
319 void tst_QChart::backgroundPen_data()
300 {
320 {
301 QTest::addColumn<QPen>("backgroundPen");
321 QTest::addColumn<QPen>("backgroundPen");
302 QTest::newRow("null") << QPen();
322 QTest::newRow("null") << QPen();
303 QTest::newRow("blue") << QPen(Qt::blue);
323 QTest::newRow("blue") << QPen(Qt::blue);
304 QTest::newRow("white") << QPen(Qt::white);
324 QTest::newRow("white") << QPen(Qt::white);
305 QTest::newRow("black") << QPen(Qt::black);
325 QTest::newRow("black") << QPen(Qt::black);
306 }
326 }
307
327
308
328
309 void tst_QChart::backgroundPen()
329 void tst_QChart::backgroundPen()
310 {
330 {
311 QFETCH(QPen, backgroundPen);
331 QFETCH(QPen, backgroundPen);
312 m_chart->setBackgroundPen(backgroundPen);
332 m_chart->setBackgroundPen(backgroundPen);
313 QCOMPARE(m_chart->backgroundPen(), backgroundPen);
333 QCOMPARE(m_chart->backgroundPen(), backgroundPen);
314 }
334 }
315
335
316 void tst_QChart::isBackgroundVisible_data()
336 void tst_QChart::isBackgroundVisible_data()
317 {
337 {
318 QTest::addColumn<bool>("isBackgroundVisible");
338 QTest::addColumn<bool>("isBackgroundVisible");
319 QTest::newRow("true") << true;
339 QTest::newRow("true") << true;
320 QTest::newRow("false") << false;
340 QTest::newRow("false") << false;
321 }
341 }
322
342
323 void tst_QChart::isBackgroundVisible()
343 void tst_QChart::isBackgroundVisible()
324 {
344 {
325 QFETCH(bool, isBackgroundVisible);
345 QFETCH(bool, isBackgroundVisible);
326 m_chart->setBackgroundVisible(isBackgroundVisible);
346 m_chart->setBackgroundVisible(isBackgroundVisible);
327 QCOMPARE(m_chart->isBackgroundVisible(), isBackgroundVisible);
347 QCOMPARE(m_chart->isBackgroundVisible(), isBackgroundVisible);
328 }
348 }
329
349
330 void tst_QChart::legend_data()
350 void tst_QChart::legend_data()
331 {
351 {
332
352
333 }
353 }
334
354
335 void tst_QChart::legend()
355 void tst_QChart::legend()
336 {
356 {
337 QVERIFY(m_chart->legend());
357 QVERIFY(m_chart->legend());
338 }
358 }
339
359
340 void tst_QChart::margins_data()
360 void tst_QChart::margins_data()
341 {
361 {
342
362
343 }
363 }
344
364
345 void tst_QChart::margins()
365 void tst_QChart::margins()
346 {
366 {
347 createTestData();
367 createTestData();
348 QRectF rect = m_chart->geometry();
368 QRectF rect = m_chart->geometry();
349
369
350 QVERIFY(m_chart->margins().top()+m_chart->margins().bottom() < rect.height());
370 QVERIFY(m_chart->margins().top()+m_chart->margins().bottom() < rect.height());
351 QVERIFY(m_chart->margins().left()+m_chart->margins().right() < rect.width());
371 QVERIFY(m_chart->margins().left()+m_chart->margins().right() < rect.width());
352 }
372 }
353
373
354 void tst_QChart::removeAllSeries_data()
374 void tst_QChart::removeAllSeries_data()
355 {
375 {
356
376
357 }
377 }
358
378
359 void tst_QChart::removeAllSeries()
379 void tst_QChart::removeAllSeries()
360 {
380 {
361 QLineSeries* series0 = new QLineSeries(this);
381 QLineSeries* series0 = new QLineSeries(this);
362 QLineSeries* series1 = new QLineSeries(this);
382 QLineSeries* series1 = new QLineSeries(this);
363 QLineSeries* series2 = new QLineSeries(this);
383 QLineSeries* series2 = new QLineSeries(this);
364 QSignalSpy deleteSpy1(series0, SIGNAL(destroyed()));
384 QSignalSpy deleteSpy1(series0, SIGNAL(destroyed()));
365 QSignalSpy deleteSpy2(series1, SIGNAL(destroyed()));
385 QSignalSpy deleteSpy2(series1, SIGNAL(destroyed()));
366 QSignalSpy deleteSpy3(series2, SIGNAL(destroyed()));
386 QSignalSpy deleteSpy3(series2, SIGNAL(destroyed()));
367
387
368 m_chart->addSeries(series0);
388 m_chart->addSeries(series0);
369 m_chart->addSeries(series1);
389 m_chart->addSeries(series1);
370 m_chart->addSeries(series2);
390 m_chart->addSeries(series2);
371 m_view->show();
391 m_view->show();
372 QTest::qWaitForWindowShown(m_view);
392 QTest::qWaitForWindowShown(m_view);
373
393
374 QVERIFY(m_chart->axisY(series0)!=0);
394 QVERIFY(m_chart->axisY(series0)!=0);
375 QVERIFY(m_chart->axisY(series1)!=0);
395 QVERIFY(m_chart->axisY(series1)!=0);
376 QVERIFY(m_chart->axisY(series2)!=0);
396 QVERIFY(m_chart->axisY(series2)!=0);
377
397
378 m_chart->removeAllSeries();
398 m_chart->removeAllSeries();
379 QVERIFY(m_chart->axisY(series0)==0);
399 QVERIFY(m_chart->axisY(series0)==0);
380 QVERIFY(m_chart->axisY(series1)==0);
400 QVERIFY(m_chart->axisY(series1)==0);
381 QVERIFY(m_chart->axisY(series2)==0);
401 QVERIFY(m_chart->axisY(series2)==0);
382 QCOMPARE(deleteSpy1.count(), 1);
402 QCOMPARE(deleteSpy1.count(), 1);
383 QCOMPARE(deleteSpy2.count(), 1);
403 QCOMPARE(deleteSpy2.count(), 1);
384 QCOMPARE(deleteSpy3.count(), 1);
404 QCOMPARE(deleteSpy3.count(), 1);
385 }
405 }
386
406
387 void tst_QChart::removeSeries_data()
407 void tst_QChart::removeSeries_data()
388 {
408 {
389 addSeries_data();
409 addSeries_data();
390 }
410 }
391
411
392 void tst_QChart::removeSeries()
412 void tst_QChart::removeSeries()
393 {
413 {
394 QFETCH(QAbstractSeries *, series);
414 QFETCH(QAbstractSeries *, series);
395 QFETCH(QAxis *, axis);
415 QFETCH(QAxis *, axis);
396 QSignalSpy deleteSpy(series, SIGNAL(destroyed()));
416 QSignalSpy deleteSpy(series, SIGNAL(destroyed()));
397 m_view->show();
417 m_view->show();
398 QTest::qWaitForWindowShown(m_view);
418 QTest::qWaitForWindowShown(m_view);
399 if(!axis) axis = m_chart->axisY();
419 if(!axis) axis = m_chart->axisY();
400 m_chart->addSeries(series,axis);
420 m_chart->addSeries(series,axis);
401 QCOMPARE(m_chart->axisY(series),axis);
421 QCOMPARE(m_chart->axisY(series),axis);
402 m_chart->removeSeries(series);
422 m_chart->removeSeries(series);
403 QVERIFY(m_chart->axisY(series)==0);
423 QVERIFY(m_chart->axisY(series)==0);
404 QCOMPARE(deleteSpy.count(), 0);
424 QCOMPARE(deleteSpy.count(), 0);
405 }
425 }
406
426
407 void tst_QChart::scrollDown_data()
427 void tst_QChart::scrollDown_data()
408 {
428 {
409
429
410 }
430 }
411
431
412 void tst_QChart::scrollDown()
432 void tst_QChart::scrollDown()
413 {
433 {
414 createTestData();
434 createTestData();
415 qreal min = m_chart->axisY()->min();
435 qreal min = m_chart->axisY()->min();
416 m_chart->scrollDown();
436 m_chart->scrollDown();
417 QVERIFY(m_chart->axisY()->min()<min);
437 QVERIFY(m_chart->axisY()->min()<min);
418 }
438 }
419
439
420 void tst_QChart::scrollLeft_data()
440 void tst_QChart::scrollLeft_data()
421 {
441 {
422
442
423 }
443 }
424
444
425 void tst_QChart::scrollLeft()
445 void tst_QChart::scrollLeft()
426 {
446 {
427 createTestData();
447 createTestData();
428 qreal min = m_chart->axisX()->min();
448 qreal min = m_chart->axisX()->min();
429 m_chart->scrollLeft();
449 m_chart->scrollLeft();
430 QVERIFY(m_chart->axisX()->min()<min);
450 QVERIFY(m_chart->axisX()->min()<min);
431 }
451 }
432
452
433 void tst_QChart::scrollRight_data()
453 void tst_QChart::scrollRight_data()
434 {
454 {
435
455
436 }
456 }
437
457
438 void tst_QChart::scrollRight()
458 void tst_QChart::scrollRight()
439 {
459 {
440 createTestData();
460 createTestData();
441 qreal min = m_chart->axisX()->min();
461 qreal min = m_chart->axisX()->min();
442 m_chart->scrollRight();
462 m_chart->scrollRight();
443 QVERIFY(m_chart->axisX()->min()>min);
463 QVERIFY(m_chart->axisX()->min()>min);
444 }
464 }
445
465
446 void tst_QChart::scrollUp_data()
466 void tst_QChart::scrollUp_data()
447 {
467 {
448
468
449 }
469 }
450
470
451 void tst_QChart::scrollUp()
471 void tst_QChart::scrollUp()
452 {
472 {
453 createTestData();
473 createTestData();
454 qreal min = m_chart->axisY()->min();
474 qreal min = m_chart->axisY()->min();
455 m_chart->scrollUp();
475 m_chart->scrollUp();
456 QVERIFY(m_chart->axisY()->min()>min);
476 QVERIFY(m_chart->axisY()->min()>min);
457 }
477 }
458
478
459 void tst_QChart::theme_data()
479 void tst_QChart::theme_data()
460 {
480 {
461 QTest::addColumn<QChart::ChartTheme>("theme");
481 QTest::addColumn<QChart::ChartTheme>("theme");
462 QTest::newRow("ChartThemeBlueCerulean") << QChart::ChartThemeBlueCerulean;
482 QTest::newRow("ChartThemeBlueCerulean") << QChart::ChartThemeBlueCerulean;
463 QTest::newRow("ChartThemeBlueIcy") << QChart::ChartThemeBlueIcy;
483 QTest::newRow("ChartThemeBlueIcy") << QChart::ChartThemeBlueIcy;
464 QTest::newRow("ChartThemeBlueNcs") << QChart::ChartThemeBlueNcs;
484 QTest::newRow("ChartThemeBlueNcs") << QChart::ChartThemeBlueNcs;
465 QTest::newRow("ChartThemeBrownSand") << QChart::ChartThemeBrownSand;
485 QTest::newRow("ChartThemeBrownSand") << QChart::ChartThemeBrownSand;
466 QTest::newRow("ChartThemeDark") << QChart::ChartThemeDark;
486 QTest::newRow("ChartThemeDark") << QChart::ChartThemeDark;
467 QTest::newRow("hartThemeHighContrast") << QChart::ChartThemeHighContrast;
487 QTest::newRow("hartThemeHighContrast") << QChart::ChartThemeHighContrast;
468 QTest::newRow("ChartThemeLight") << QChart::ChartThemeLight;
488 QTest::newRow("ChartThemeLight") << QChart::ChartThemeLight;
469 }
489 }
470
490
471 void tst_QChart::theme()
491 void tst_QChart::theme()
472 {
492 {
473 QFETCH(QChart::ChartTheme, theme);
493 QFETCH(QChart::ChartTheme, theme);
474 createTestData();
494 createTestData();
475 m_chart->setTheme(theme);
495 m_chart->setTheme(theme);
476 QVERIFY(m_chart->theme()==theme);
496 QVERIFY(m_chart->theme()==theme);
477 }
497 }
478
498
479 void tst_QChart::title_data()
499 void tst_QChart::title_data()
480 {
500 {
481 QTest::addColumn<QString>("title");
501 QTest::addColumn<QString>("title");
482 QTest::newRow("null") << QString();
502 QTest::newRow("null") << QString();
483 QTest::newRow("foo") << QString("foo");
503 QTest::newRow("foo") << QString("foo");
484 }
504 }
485
505
486 void tst_QChart::title()
506 void tst_QChart::title()
487 {
507 {
488 QFETCH(QString, title);
508 QFETCH(QString, title);
489 m_chart->setTitle(title);
509 m_chart->setTitle(title);
490 QCOMPARE(m_chart->title(), title);
510 QCOMPARE(m_chart->title(), title);
491 }
511 }
492
512
493 void tst_QChart::titleBrush_data()
513 void tst_QChart::titleBrush_data()
494 {
514 {
495 QTest::addColumn<QBrush>("titleBrush");
515 QTest::addColumn<QBrush>("titleBrush");
496 QTest::newRow("null") << QBrush();
516 QTest::newRow("null") << QBrush();
497 QTest::newRow("blue") << QBrush(Qt::blue);
517 QTest::newRow("blue") << QBrush(Qt::blue);
498 QTest::newRow("white") << QBrush(Qt::white);
518 QTest::newRow("white") << QBrush(Qt::white);
499 QTest::newRow("black") << QBrush(Qt::black);
519 QTest::newRow("black") << QBrush(Qt::black);
500 }
520 }
501
521
502 void tst_QChart::titleBrush()
522 void tst_QChart::titleBrush()
503 {
523 {
504 QFETCH(QBrush, titleBrush);
524 QFETCH(QBrush, titleBrush);
505 m_chart->setTitleBrush(titleBrush);
525 m_chart->setTitleBrush(titleBrush);
506 QCOMPARE(m_chart->titleBrush(), titleBrush);
526 QCOMPARE(m_chart->titleBrush(), titleBrush);
507 }
527 }
508
528
509 void tst_QChart::titleFont_data()
529 void tst_QChart::titleFont_data()
510 {
530 {
511 QTest::addColumn<QFont>("titleFont");
531 QTest::addColumn<QFont>("titleFont");
512 QTest::newRow("null") << QFont();
532 QTest::newRow("null") << QFont();
513 QTest::newRow("courier") << QFont("Courier", 8, QFont::Bold, true);
533 QTest::newRow("courier") << QFont("Courier", 8, QFont::Bold, true);
514 }
534 }
515
535
516 void tst_QChart::titleFont()
536 void tst_QChart::titleFont()
517 {
537 {
518 QFETCH(QFont, titleFont);
538 QFETCH(QFont, titleFont);
519 m_chart->setTitleFont(titleFont);
539 m_chart->setTitleFont(titleFont);
520 QCOMPARE(m_chart->titleFont(), titleFont);
540 QCOMPARE(m_chart->titleFont(), titleFont);
521 }
541 }
522
542
523 void tst_QChart::zoomIn_data()
543 void tst_QChart::zoomIn_data()
524 {
544 {
525 QTest::addColumn<QRectF>("rect");
545 QTest::addColumn<QRectF>("rect");
526 QTest::newRow("null") << QRectF();
546 QTest::newRow("null") << QRectF();
527 QTest::newRow("100x100") << QRectF(10,10,100,100);
547 QTest::newRow("100x100") << QRectF(10,10,100,100);
528 QTest::newRow("200x200") << QRectF(10,10,200,200);
548 QTest::newRow("200x200") << QRectF(10,10,200,200);
529 }
549 }
530
550
531
551
532 void tst_QChart::zoomIn()
552 void tst_QChart::zoomIn()
533 {
553 {
534 QFETCH(QRectF, rect);
554 QFETCH(QRectF, rect);
535 createTestData();
555 createTestData();
536 QRectF marigns = m_chart->margins();
556 QRectF marigns = m_chart->margins();
537 rect.adjust(marigns.left(),marigns.top(),-marigns.right(),-marigns.bottom());
557 rect.adjust(marigns.left(),marigns.top(),-marigns.right(),-marigns.bottom());
538 qreal minX = m_chart->axisX()->min();
558 qreal minX = m_chart->axisX()->min();
539 qreal minY = m_chart->axisY()->min();
559 qreal minY = m_chart->axisY()->min();
540 qreal maxX = m_chart->axisX()->max();
560 qreal maxX = m_chart->axisX()->max();
541 qreal maxY = m_chart->axisY()->max();
561 qreal maxY = m_chart->axisY()->max();
542 m_chart->zoomIn(rect);
562 m_chart->zoomIn(rect);
543 if(rect.isValid()){
563 if(rect.isValid()){
544 QVERIFY(minX<m_chart->axisX()->min());
564 QVERIFY(minX<m_chart->axisX()->min());
545 QVERIFY(maxX>m_chart->axisX()->max());
565 QVERIFY(maxX>m_chart->axisX()->max());
546 QVERIFY(minY<m_chart->axisY()->min());
566 QVERIFY(minY<m_chart->axisY()->min());
547 QVERIFY(maxY>m_chart->axisY()->max());
567 QVERIFY(maxY>m_chart->axisY()->max());
548 }
568 }
549 }
569 }
550
570
551 void tst_QChart::zoomOut_data()
571 void tst_QChart::zoomOut_data()
552 {
572 {
553
573
554 }
574 }
555
575
556 void tst_QChart::zoomOut()
576 void tst_QChart::zoomOut()
557 {
577 {
558 createTestData();
578 createTestData();
559 qreal minX = m_chart->axisX()->min();
579 qreal minX = m_chart->axisX()->min();
560 qreal minY = m_chart->axisY()->min();
580 qreal minY = m_chart->axisY()->min();
561 qreal maxX = m_chart->axisX()->max();
581 qreal maxX = m_chart->axisX()->max();
562 qreal maxY = m_chart->axisY()->max();
582 qreal maxY = m_chart->axisY()->max();
563
583
564 m_chart->zoomIn();
584 m_chart->zoomIn();
565
585
566 QVERIFY(minX < m_chart->axisX()->min());
586 QVERIFY(minX < m_chart->axisX()->min());
567 QVERIFY(maxX > m_chart->axisX()->max());
587 QVERIFY(maxX > m_chart->axisX()->max());
568 QVERIFY(minY < m_chart->axisY()->min());
588 QVERIFY(minY < m_chart->axisY()->min());
569 QVERIFY(maxY > m_chart->axisY()->max());
589 QVERIFY(maxY > m_chart->axisY()->max());
570
590
571 m_chart->zoomOut();
591 m_chart->zoomOut();
572
592
573 // min x may be a zero value
593 // min x may be a zero value
574 if (qFuzzyIsNull(minX))
594 if (qFuzzyIsNull(minX))
575 QVERIFY(qFuzzyIsNull(m_chart->axisX()->min()));
595 QVERIFY(qFuzzyIsNull(m_chart->axisX()->min()));
576 else
596 else
577 QCOMPARE(minX, m_chart->axisX()->min());
597 QCOMPARE(minX, m_chart->axisX()->min());
578
598
579 // min y may be a zero value
599 // min y may be a zero value
580 if (qFuzzyIsNull(minY))
600 if (qFuzzyIsNull(minY))
581 QVERIFY(qFuzzyIsNull(m_chart->axisY()->min()));
601 QVERIFY(qFuzzyIsNull(m_chart->axisY()->min()));
582 else
602 else
583 QCOMPARE(minY, m_chart->axisY()->min());
603 QCOMPARE(minY, m_chart->axisY()->min());
584
604
585 QVERIFY(maxX == m_chart->axisX()->max());
605 QVERIFY(maxX == m_chart->axisX()->max());
586 QVERIFY(maxY == m_chart->axisY()->max());
606 QVERIFY(maxY == m_chart->axisY()->max());
587 }
607 }
588
608
589 QTEST_MAIN(tst_QChart)
609 QTEST_MAIN(tst_QChart)
590 #include "tst_qchart.moc"
610 #include "tst_qchart.moc"
591
611
@@ -1,273 +1,293
1 /****************************************************************************
2 **
3 ** Copyright (C) 2012 Digia Plc
4 ** All rights reserved.
5 ** For any questions to Digia, please use contact form at http://qt.digia.com
6 **
7 ** This file is part of the Qt Commercial Charts Add-on.
8 **
9 ** $QT_BEGIN_LICENSE$
10 ** Licensees holding valid Qt Commercial licenses may use this file in
11 ** accordance with the Qt Commercial License Agreement provided with the
12 ** Software or, alternatively, in accordance with the terms contained in
13 ** a written agreement between you and Digia.
14 **
15 ** If you have questions regarding the use of this file, please use
16 ** contact form at http://qt.digia.com
17 ** $QT_END_LICENSE$
18 **
19 ****************************************************************************/
20
1 #include <QtCore/QString>
21 #include <QtCore/QString>
2 #include <QtTest/QtTest>
22 #include <QtTest/QtTest>
3
23
4 #include <qchart.h>
24 #include <qchart.h>
5 #include <qchartview.h>
25 #include <qchartview.h>
6 #include <qpieseries.h>
26 #include <qpieseries.h>
7 #include <qvpiemodelmapper.h>
27 #include <qvpiemodelmapper.h>
8 #include <qhpiemodelmapper.h>
28 #include <qhpiemodelmapper.h>
9 #include <QStandardItemModel>
29 #include <QStandardItemModel>
10
30
11 QTCOMMERCIALCHART_USE_NAMESPACE
31 QTCOMMERCIALCHART_USE_NAMESPACE
12
32
13 class tst_qpiemodelmapper : public QObject
33 class tst_qpiemodelmapper : public QObject
14 {
34 {
15 Q_OBJECT
35 Q_OBJECT
16
36
17 public:
37 public:
18 tst_qpiemodelmapper();
38 tst_qpiemodelmapper();
19
39
20 private Q_SLOTS:
40 private Q_SLOTS:
21 void initTestCase();
41 void initTestCase();
22 void cleanupTestCase();
42 void cleanupTestCase();
23 void init();
43 void init();
24 void cleanup();
44 void cleanup();
25 void verticalMapper_data();
45 void verticalMapper_data();
26 void verticalMapper();
46 void verticalMapper();
27 void verticalMapperCustomMapping_data();
47 void verticalMapperCustomMapping_data();
28 void verticalMapperCustomMapping();
48 void verticalMapperCustomMapping();
29 void horizontalMapper_data();
49 void horizontalMapper_data();
30 void horizontalMapper();
50 void horizontalMapper();
31 void horizontalMapperCustomMapping_data();
51 void horizontalMapperCustomMapping_data();
32 void horizontalMapperCustomMapping();
52 void horizontalMapperCustomMapping();
33 void seriesUpdated();
53 void seriesUpdated();
34
54
35
55
36 private:
56 private:
37 QStandardItemModel *m_model;
57 QStandardItemModel *m_model;
38 int m_modelRowCount;
58 int m_modelRowCount;
39 int m_modelColumnCount;
59 int m_modelColumnCount;
40
60
41 QPieSeries *m_series;
61 QPieSeries *m_series;
42 QChart *m_chart;
62 QChart *m_chart;
43 };
63 };
44
64
45 tst_qpiemodelmapper::tst_qpiemodelmapper():
65 tst_qpiemodelmapper::tst_qpiemodelmapper():
46 m_model(0),
66 m_model(0),
47 m_modelRowCount(10),
67 m_modelRowCount(10),
48 m_modelColumnCount(8)
68 m_modelColumnCount(8)
49 {
69 {
50 }
70 }
51
71
52 void tst_qpiemodelmapper::init()
72 void tst_qpiemodelmapper::init()
53 {
73 {
54 m_series = new QPieSeries;
74 m_series = new QPieSeries;
55 m_chart->addSeries(m_series);
75 m_chart->addSeries(m_series);
56 }
76 }
57
77
58 void tst_qpiemodelmapper::cleanup()
78 void tst_qpiemodelmapper::cleanup()
59 {
79 {
60 m_chart->removeSeries(m_series);
80 m_chart->removeSeries(m_series);
61 delete m_series;
81 delete m_series;
62 m_series = 0;
82 m_series = 0;
63 }
83 }
64
84
65 void tst_qpiemodelmapper::initTestCase()
85 void tst_qpiemodelmapper::initTestCase()
66 {
86 {
67 m_chart = new QChart;
87 m_chart = new QChart;
68 QChartView *chartView = new QChartView(m_chart);
88 QChartView *chartView = new QChartView(m_chart);
69 chartView->show();
89 chartView->show();
70
90
71 m_model = new QStandardItemModel(this);
91 m_model = new QStandardItemModel(this);
72 for (int row = 0; row < m_modelRowCount; ++row) {
92 for (int row = 0; row < m_modelRowCount; ++row) {
73 for (int column = 0; column < m_modelColumnCount; column++) {
93 for (int column = 0; column < m_modelColumnCount; column++) {
74 QStandardItem *item = new QStandardItem(row * column);
94 QStandardItem *item = new QStandardItem(row * column);
75 m_model->setItem(row, column, item);
95 m_model->setItem(row, column, item);
76 }
96 }
77 }
97 }
78 }
98 }
79
99
80 void tst_qpiemodelmapper::cleanupTestCase()
100 void tst_qpiemodelmapper::cleanupTestCase()
81 {
101 {
82 m_model->clear();
102 m_model->clear();
83 }
103 }
84
104
85 void tst_qpiemodelmapper::verticalMapper_data()
105 void tst_qpiemodelmapper::verticalMapper_data()
86 {
106 {
87 QTest::addColumn<int>("valuesColumn");
107 QTest::addColumn<int>("valuesColumn");
88 QTest::addColumn<int>("labelsColumn");
108 QTest::addColumn<int>("labelsColumn");
89 QTest::addColumn<int>("expectedCount");
109 QTest::addColumn<int>("expectedCount");
90 QTest::newRow("different values and labels columns") << 0 << 1 << m_modelRowCount;
110 QTest::newRow("different values and labels columns") << 0 << 1 << m_modelRowCount;
91 QTest::newRow("same values and labels columns") << 1 << 1 << m_modelRowCount;
111 QTest::newRow("same values and labels columns") << 1 << 1 << m_modelRowCount;
92 QTest::newRow("invalid values column and correct labels column") << -3 << 1 << 0;
112 QTest::newRow("invalid values column and correct labels column") << -3 << 1 << 0;
93 QTest::newRow("values column beyond the size of model and correct labels column") << m_modelColumnCount << 1 << 0;
113 QTest::newRow("values column beyond the size of model and correct labels column") << m_modelColumnCount << 1 << 0;
94 QTest::newRow("values column beyond the size of model and invalid labels column") << m_modelColumnCount << -1 << 0;
114 QTest::newRow("values column beyond the size of model and invalid labels column") << m_modelColumnCount << -1 << 0;
95 }
115 }
96
116
97 void tst_qpiemodelmapper::verticalMapper()
117 void tst_qpiemodelmapper::verticalMapper()
98 {
118 {
99 QFETCH(int, valuesColumn);
119 QFETCH(int, valuesColumn);
100 QFETCH(int, labelsColumn);
120 QFETCH(int, labelsColumn);
101 QFETCH(int, expectedCount);
121 QFETCH(int, expectedCount);
102
122
103 QVPieModelMapper *mapper = new QVPieModelMapper;
123 QVPieModelMapper *mapper = new QVPieModelMapper;
104 mapper->setValuesColumn(valuesColumn);
124 mapper->setValuesColumn(valuesColumn);
105 mapper->setLabelsColumn(labelsColumn);
125 mapper->setLabelsColumn(labelsColumn);
106 mapper->setModel(m_model);
126 mapper->setModel(m_model);
107 mapper->setSeries(m_series);
127 mapper->setSeries(m_series);
108
128
109 QCOMPARE(m_series->count(), expectedCount);
129 QCOMPARE(m_series->count(), expectedCount);
110 QCOMPARE(mapper->valuesColumn(), qMax(-1, valuesColumn));
130 QCOMPARE(mapper->valuesColumn(), qMax(-1, valuesColumn));
111 QCOMPARE(mapper->labelsColumn(), qMax(-1, labelsColumn));
131 QCOMPARE(mapper->labelsColumn(), qMax(-1, labelsColumn));
112
132
113 delete mapper;
133 delete mapper;
114 mapper = 0;
134 mapper = 0;
115 }
135 }
116
136
117 void tst_qpiemodelmapper::verticalMapperCustomMapping_data()
137 void tst_qpiemodelmapper::verticalMapperCustomMapping_data()
118 {
138 {
119 QTest::addColumn<int>("first");
139 QTest::addColumn<int>("first");
120 QTest::addColumn<int>("countLimit");
140 QTest::addColumn<int>("countLimit");
121 QTest::addColumn<int>("expectedCount");
141 QTest::addColumn<int>("expectedCount");
122 QTest::newRow("first: 0, unlimited count") << 0 << -1 << m_modelRowCount;
142 QTest::newRow("first: 0, unlimited count") << 0 << -1 << m_modelRowCount;
123 QTest::newRow("first: 3, unlimited count") << 3 << -1 << m_modelRowCount - 3;
143 QTest::newRow("first: 3, unlimited count") << 3 << -1 << m_modelRowCount - 3;
124 QTest::newRow("first: 0, count: 5") << 0 << 5 << qMin(5, m_modelRowCount);
144 QTest::newRow("first: 0, count: 5") << 0 << 5 << qMin(5, m_modelRowCount);
125 QTest::newRow("first: 3, count: 5") << 3 << 5 << qMin(5, m_modelRowCount - 3);
145 QTest::newRow("first: 3, count: 5") << 3 << 5 << qMin(5, m_modelRowCount - 3);
126 QTest::newRow("first: +1 greater then the number of rows in the model, unlimited count") << m_modelRowCount + 1 << -1 << 0;
146 QTest::newRow("first: +1 greater then the number of rows in the model, unlimited count") << m_modelRowCount + 1 << -1 << 0;
127 QTest::newRow("first: +1 greater then the number of rows in the model, count: 5") << m_modelRowCount + 1 << 5 << 0;
147 QTest::newRow("first: +1 greater then the number of rows in the model, count: 5") << m_modelRowCount + 1 << 5 << 0;
128 QTest::newRow("first: 0, count: +3 greater than the number of rows in the model (should limit to the size of model)") << 0 << m_modelRowCount + 3 << m_modelRowCount;
148 QTest::newRow("first: 0, count: +3 greater than the number of rows in the model (should limit to the size of model)") << 0 << m_modelRowCount + 3 << m_modelRowCount;
129 QTest::newRow("first: -3(invalid - should default to 0), unlimited count") << -3 << -1 << m_modelRowCount;
149 QTest::newRow("first: -3(invalid - should default to 0), unlimited count") << -3 << -1 << m_modelRowCount;
130 QTest::newRow("first: 0, count: -3 (invalid - shlould default to -1)") << 0 << -3 << m_modelRowCount;
150 QTest::newRow("first: 0, count: -3 (invalid - shlould default to -1)") << 0 << -3 << m_modelRowCount;
131 QTest::newRow("first: -3(invalid - should default to 0), count: -3 (invalid - shlould default to -1)") << -3 << -3 << m_modelRowCount;
151 QTest::newRow("first: -3(invalid - should default to 0), count: -3 (invalid - shlould default to -1)") << -3 << -3 << m_modelRowCount;
132
152
133 }
153 }
134
154
135 void tst_qpiemodelmapper::verticalMapperCustomMapping()
155 void tst_qpiemodelmapper::verticalMapperCustomMapping()
136 {
156 {
137 QFETCH(int, first);
157 QFETCH(int, first);
138 QFETCH(int, countLimit);
158 QFETCH(int, countLimit);
139 QFETCH(int, expectedCount);
159 QFETCH(int, expectedCount);
140
160
141 QCOMPARE(m_series->count(), 0);
161 QCOMPARE(m_series->count(), 0);
142
162
143 QVPieModelMapper *mapper = new QVPieModelMapper;
163 QVPieModelMapper *mapper = new QVPieModelMapper;
144 mapper->setValuesColumn(0);
164 mapper->setValuesColumn(0);
145 mapper->setLabelsColumn(1);
165 mapper->setLabelsColumn(1);
146 mapper->setModel(m_model);
166 mapper->setModel(m_model);
147 mapper->setSeries(m_series);
167 mapper->setSeries(m_series);
148 mapper->setFirst(first);
168 mapper->setFirst(first);
149 mapper->setCount(countLimit);
169 mapper->setCount(countLimit);
150
170
151 QCOMPARE(m_series->count(), expectedCount);
171 QCOMPARE(m_series->count(), expectedCount);
152
172
153 // change values column mapping to invalid
173 // change values column mapping to invalid
154 mapper->setValuesColumn(-1);
174 mapper->setValuesColumn(-1);
155 mapper->setLabelsColumn(1);
175 mapper->setLabelsColumn(1);
156
176
157 QCOMPARE(m_series->count(), 0);
177 QCOMPARE(m_series->count(), 0);
158
178
159 delete mapper;
179 delete mapper;
160 mapper = 0;
180 mapper = 0;
161 }
181 }
162
182
163 void tst_qpiemodelmapper::horizontalMapper_data()
183 void tst_qpiemodelmapper::horizontalMapper_data()
164 {
184 {
165 QTest::addColumn<int>("valuesRow");
185 QTest::addColumn<int>("valuesRow");
166 QTest::addColumn<int>("labelsRow");
186 QTest::addColumn<int>("labelsRow");
167 QTest::addColumn<int>("expectedCount");
187 QTest::addColumn<int>("expectedCount");
168 QTest::newRow("different values and labels rows") << 0 << 1 << m_modelColumnCount;
188 QTest::newRow("different values and labels rows") << 0 << 1 << m_modelColumnCount;
169 QTest::newRow("same values and labels rows") << 1 << 1 << m_modelColumnCount;
189 QTest::newRow("same values and labels rows") << 1 << 1 << m_modelColumnCount;
170 QTest::newRow("invalid values row and correct labels row") << -3 << 1 << 0;
190 QTest::newRow("invalid values row and correct labels row") << -3 << 1 << 0;
171 QTest::newRow("values row beyond the size of model and correct labels row") << m_modelRowCount << 1 << 0;
191 QTest::newRow("values row beyond the size of model and correct labels row") << m_modelRowCount << 1 << 0;
172 QTest::newRow("values row beyond the size of model and invalid labels row") << m_modelRowCount << -1 << 0;
192 QTest::newRow("values row beyond the size of model and invalid labels row") << m_modelRowCount << -1 << 0;
173 }
193 }
174
194
175 void tst_qpiemodelmapper::horizontalMapper()
195 void tst_qpiemodelmapper::horizontalMapper()
176 {
196 {
177 QFETCH(int, valuesRow);
197 QFETCH(int, valuesRow);
178 QFETCH(int, labelsRow);
198 QFETCH(int, labelsRow);
179 QFETCH(int, expectedCount);
199 QFETCH(int, expectedCount);
180
200
181 QHPieModelMapper *mapper = new QHPieModelMapper;
201 QHPieModelMapper *mapper = new QHPieModelMapper;
182 mapper->setValuesRow(valuesRow);
202 mapper->setValuesRow(valuesRow);
183 mapper->setLabelsRow(labelsRow);
203 mapper->setLabelsRow(labelsRow);
184 mapper->setModel(m_model);
204 mapper->setModel(m_model);
185 mapper->setSeries(m_series);
205 mapper->setSeries(m_series);
186
206
187 QCOMPARE(m_series->count(), expectedCount);
207 QCOMPARE(m_series->count(), expectedCount);
188 QCOMPARE(mapper->valuesRow(), qMax(-1, valuesRow));
208 QCOMPARE(mapper->valuesRow(), qMax(-1, valuesRow));
189 QCOMPARE(mapper->labelsRow(), qMax(-1, labelsRow));
209 QCOMPARE(mapper->labelsRow(), qMax(-1, labelsRow));
190
210
191 delete mapper;
211 delete mapper;
192 mapper = 0;
212 mapper = 0;
193 }
213 }
194
214
195 void tst_qpiemodelmapper::horizontalMapperCustomMapping_data()
215 void tst_qpiemodelmapper::horizontalMapperCustomMapping_data()
196 {
216 {
197 QTest::addColumn<int>("first");
217 QTest::addColumn<int>("first");
198 QTest::addColumn<int>("countLimit");
218 QTest::addColumn<int>("countLimit");
199 QTest::addColumn<int>("expectedCount");
219 QTest::addColumn<int>("expectedCount");
200 QTest::newRow("first: 0, unlimited count") << 0 << -1 << m_modelColumnCount;
220 QTest::newRow("first: 0, unlimited count") << 0 << -1 << m_modelColumnCount;
201 QTest::newRow("first: 3, unlimited count") << 3 << -1 << m_modelColumnCount - 3;
221 QTest::newRow("first: 3, unlimited count") << 3 << -1 << m_modelColumnCount - 3;
202 QTest::newRow("first: 0, count: 5") << 0 << 5 << qMin(5, m_modelColumnCount);
222 QTest::newRow("first: 0, count: 5") << 0 << 5 << qMin(5, m_modelColumnCount);
203 QTest::newRow("first: 3, count: 5") << 3 << 5 << qMin(5, m_modelColumnCount - 3);
223 QTest::newRow("first: 3, count: 5") << 3 << 5 << qMin(5, m_modelColumnCount - 3);
204 QTest::newRow("first: +1 greater then the number of columns in the model, unlimited count") << m_modelColumnCount + 1 << -1 << 0;
224 QTest::newRow("first: +1 greater then the number of columns in the model, unlimited count") << m_modelColumnCount + 1 << -1 << 0;
205 QTest::newRow("first: +1 greater then the number of columns in the model, count: 5") << m_modelColumnCount + 1 << 5 << 0;
225 QTest::newRow("first: +1 greater then the number of columns in the model, count: 5") << m_modelColumnCount + 1 << 5 << 0;
206 QTest::newRow("first: 0, count: +3 greater than the number of columns in the model (should limit to the size of model)") << 0 << m_modelColumnCount + 3 << m_modelColumnCount;
226 QTest::newRow("first: 0, count: +3 greater than the number of columns in the model (should limit to the size of model)") << 0 << m_modelColumnCount + 3 << m_modelColumnCount;
207 QTest::newRow("first: -3(invalid - should default to 0), unlimited count") << -3 << -1 << m_modelColumnCount;
227 QTest::newRow("first: -3(invalid - should default to 0), unlimited count") << -3 << -1 << m_modelColumnCount;
208 QTest::newRow("first: 0, count: -3 (invalid - shlould default to -1)") << 0 << -3 << m_modelColumnCount;
228 QTest::newRow("first: 0, count: -3 (invalid - shlould default to -1)") << 0 << -3 << m_modelColumnCount;
209 QTest::newRow("first: -3(invalid - should default to 0), count: -3 (invalid - shlould default to -1)") << -3 << -3 << m_modelColumnCount;
229 QTest::newRow("first: -3(invalid - should default to 0), count: -3 (invalid - shlould default to -1)") << -3 << -3 << m_modelColumnCount;
210 }
230 }
211
231
212 void tst_qpiemodelmapper::horizontalMapperCustomMapping()
232 void tst_qpiemodelmapper::horizontalMapperCustomMapping()
213 {
233 {
214 QFETCH(int, first);
234 QFETCH(int, first);
215 QFETCH(int, countLimit);
235 QFETCH(int, countLimit);
216 QFETCH(int, expectedCount);
236 QFETCH(int, expectedCount);
217
237
218 QCOMPARE(m_series->count(), 0);
238 QCOMPARE(m_series->count(), 0);
219
239
220 QHPieModelMapper *mapper = new QHPieModelMapper;
240 QHPieModelMapper *mapper = new QHPieModelMapper;
221 mapper->setValuesRow(0);
241 mapper->setValuesRow(0);
222 mapper->setLabelsRow(1);
242 mapper->setLabelsRow(1);
223 mapper->setModel(m_model);
243 mapper->setModel(m_model);
224 mapper->setSeries(m_series);
244 mapper->setSeries(m_series);
225 mapper->setFirst(first);
245 mapper->setFirst(first);
226 mapper->setCount(countLimit);
246 mapper->setCount(countLimit);
227
247
228 QCOMPARE(m_series->count(), expectedCount);
248 QCOMPARE(m_series->count(), expectedCount);
229
249
230 // change values row mapping to invalid
250 // change values row mapping to invalid
231 mapper->setValuesRow(-1);
251 mapper->setValuesRow(-1);
232 mapper->setLabelsRow(1);
252 mapper->setLabelsRow(1);
233
253
234 QCOMPARE(m_series->count(), 0);
254 QCOMPARE(m_series->count(), 0);
235
255
236 delete mapper;
256 delete mapper;
237 mapper = 0;
257 mapper = 0;
238 }
258 }
239
259
240 void tst_qpiemodelmapper::seriesUpdated()
260 void tst_qpiemodelmapper::seriesUpdated()
241 {
261 {
242 QStandardItemModel *otherModel = new QStandardItemModel;
262 QStandardItemModel *otherModel = new QStandardItemModel;
243 for (int row = 0; row < m_modelRowCount; ++row) {
263 for (int row = 0; row < m_modelRowCount; ++row) {
244 for (int column = 0; column < m_modelColumnCount; column++) {
264 for (int column = 0; column < m_modelColumnCount; column++) {
245 QStandardItem *item = new QStandardItem(row * column);
265 QStandardItem *item = new QStandardItem(row * column);
246 otherModel->setItem(row, column, item);
266 otherModel->setItem(row, column, item);
247 }
267 }
248 }
268 }
249
269
250 QVPieModelMapper *mapper = new QVPieModelMapper;
270 QVPieModelMapper *mapper = new QVPieModelMapper;
251 mapper->setValuesColumn(0);
271 mapper->setValuesColumn(0);
252 mapper->setLabelsColumn(1);
272 mapper->setLabelsColumn(1);
253 mapper->setModel(otherModel);
273 mapper->setModel(otherModel);
254 mapper->setSeries(m_series);
274 mapper->setSeries(m_series);
255 QCOMPARE(m_series->count(), m_modelRowCount);
275 QCOMPARE(m_series->count(), m_modelRowCount);
256 QCOMPARE(mapper->count(), -1);
276 QCOMPARE(mapper->count(), -1);
257
277
258 m_series->append("1000", 1000);
278 m_series->append("1000", 1000);
259 QCOMPARE(m_series->count(), m_modelRowCount + 1);
279 QCOMPARE(m_series->count(), m_modelRowCount + 1);
260 QCOMPARE(mapper->count(), -1); // the value should not change as it indicates 'all' items there are in the model
280 QCOMPARE(mapper->count(), -1); // the value should not change as it indicates 'all' items there are in the model
261
281
262 m_series->remove(m_series->slices().last());
282 m_series->remove(m_series->slices().last());
263 QCOMPARE(m_series->count(), m_modelRowCount);
283 QCOMPARE(m_series->count(), m_modelRowCount);
264 QCOMPARE(mapper->count(), -1); // the value should not change as it indicates 'all' items there are in the model
284 QCOMPARE(mapper->count(), -1); // the value should not change as it indicates 'all' items there are in the model
265
285
266 otherModel->clear();
286 otherModel->clear();
267 delete otherModel;
287 delete otherModel;
268 otherModel = 0;
288 otherModel = 0;
269 }
289 }
270
290
271 QTEST_MAIN(tst_qpiemodelmapper)
291 QTEST_MAIN(tst_qpiemodelmapper)
272
292
273 #include "tst_qpiemodelmapper.moc"
293 #include "tst_qpiemodelmapper.moc"
@@ -1,273 +1,293
1 /****************************************************************************
2 **
3 ** Copyright (C) 2012 Digia Plc
4 ** All rights reserved.
5 ** For any questions to Digia, please use contact form at http://qt.digia.com
6 **
7 ** This file is part of the Qt Commercial Charts Add-on.
8 **
9 ** $QT_BEGIN_LICENSE$
10 ** Licensees holding valid Qt Commercial licenses may use this file in
11 ** accordance with the Qt Commercial License Agreement provided with the
12 ** Software or, alternatively, in accordance with the terms contained in
13 ** a written agreement between you and Digia.
14 **
15 ** If you have questions regarding the use of this file, please use
16 ** contact form at http://qt.digia.com
17 ** $QT_END_LICENSE$
18 **
19 ****************************************************************************/
20
1 #include <QtCore/QString>
21 #include <QtCore/QString>
2 #include <QtTest/QtTest>
22 #include <QtTest/QtTest>
3
23
4 #include <qchart.h>
24 #include <qchart.h>
5 #include <qchartview.h>
25 #include <qchartview.h>
6 #include <qxyseries.h>
26 #include <qxyseries.h>
7 #include <qlineseries.h>
27 #include <qlineseries.h>
8 #include <qvxymodelmapper.h>
28 #include <qvxymodelmapper.h>
9 #include <qhxymodelmapper.h>
29 #include <qhxymodelmapper.h>
10 #include <QStandardItemModel>
30 #include <QStandardItemModel>
11
31
12 QTCOMMERCIALCHART_USE_NAMESPACE
32 QTCOMMERCIALCHART_USE_NAMESPACE
13
33
14 class tst_qxymodelmapper : public QObject
34 class tst_qxymodelmapper : public QObject
15 {
35 {
16 Q_OBJECT
36 Q_OBJECT
17
37
18 public:
38 public:
19 tst_qxymodelmapper();
39 tst_qxymodelmapper();
20
40
21 private Q_SLOTS:
41 private Q_SLOTS:
22 void initTestCase();
42 void initTestCase();
23 void cleanupTestCase();
43 void cleanupTestCase();
24 void init();
44 void init();
25 void cleanup();
45 void cleanup();
26 void verticalMapper_data();
46 void verticalMapper_data();
27 void verticalMapper();
47 void verticalMapper();
28 void verticalMapperCustomMapping_data();
48 void verticalMapperCustomMapping_data();
29 void verticalMapperCustomMapping();
49 void verticalMapperCustomMapping();
30 void horizontalMapper_data();
50 void horizontalMapper_data();
31 void horizontalMapper();
51 void horizontalMapper();
32 void horizontalMapperCustomMapping_data();
52 void horizontalMapperCustomMapping_data();
33 void horizontalMapperCustomMapping();
53 void horizontalMapperCustomMapping();
34 void seriesUpdated();
54 void seriesUpdated();
35
55
36 private:
56 private:
37 QStandardItemModel *m_model;
57 QStandardItemModel *m_model;
38 int m_modelRowCount;
58 int m_modelRowCount;
39 int m_modelColumnCount;
59 int m_modelColumnCount;
40
60
41 QXYSeries *m_series;
61 QXYSeries *m_series;
42 QChart *m_chart;
62 QChart *m_chart;
43 };
63 };
44
64
45 tst_qxymodelmapper::tst_qxymodelmapper():
65 tst_qxymodelmapper::tst_qxymodelmapper():
46 m_model(0),
66 m_model(0),
47 m_modelRowCount(10),
67 m_modelRowCount(10),
48 m_modelColumnCount(8)
68 m_modelColumnCount(8)
49 {
69 {
50 }
70 }
51
71
52 void tst_qxymodelmapper::init()
72 void tst_qxymodelmapper::init()
53 {
73 {
54 m_series = new QLineSeries;
74 m_series = new QLineSeries;
55 m_chart->addSeries(m_series);
75 m_chart->addSeries(m_series);
56 }
76 }
57
77
58 void tst_qxymodelmapper::cleanup()
78 void tst_qxymodelmapper::cleanup()
59 {
79 {
60 m_chart->removeSeries(m_series);
80 m_chart->removeSeries(m_series);
61 delete m_series;
81 delete m_series;
62 m_series = 0;
82 m_series = 0;
63 }
83 }
64
84
65 void tst_qxymodelmapper::initTestCase()
85 void tst_qxymodelmapper::initTestCase()
66 {
86 {
67 m_chart = new QChart;
87 m_chart = new QChart;
68 QChartView *chartView = new QChartView(m_chart);
88 QChartView *chartView = new QChartView(m_chart);
69 chartView->show();
89 chartView->show();
70
90
71 m_model = new QStandardItemModel(this);
91 m_model = new QStandardItemModel(this);
72 for (int row = 0; row < m_modelRowCount; ++row) {
92 for (int row = 0; row < m_modelRowCount; ++row) {
73 for (int column = 0; column < m_modelColumnCount; column++) {
93 for (int column = 0; column < m_modelColumnCount; column++) {
74 QStandardItem *item = new QStandardItem(row * column);
94 QStandardItem *item = new QStandardItem(row * column);
75 m_model->setItem(row, column, item);
95 m_model->setItem(row, column, item);
76 }
96 }
77 }
97 }
78 }
98 }
79
99
80 void tst_qxymodelmapper::cleanupTestCase()
100 void tst_qxymodelmapper::cleanupTestCase()
81 {
101 {
82 m_model->clear();
102 m_model->clear();
83 }
103 }
84
104
85 void tst_qxymodelmapper::verticalMapper_data()
105 void tst_qxymodelmapper::verticalMapper_data()
86 {
106 {
87 QTest::addColumn<int>("xColumn");
107 QTest::addColumn<int>("xColumn");
88 QTest::addColumn<int>("yColumn");
108 QTest::addColumn<int>("yColumn");
89 QTest::addColumn<int>("expectedCount");
109 QTest::addColumn<int>("expectedCount");
90 QTest::newRow("different x and y columns") << 0 << 1 << m_modelRowCount;
110 QTest::newRow("different x and y columns") << 0 << 1 << m_modelRowCount;
91 QTest::newRow("same x and y columns") << 1 << 1 << m_modelRowCount;
111 QTest::newRow("same x and y columns") << 1 << 1 << m_modelRowCount;
92 QTest::newRow("invalid x column and correct y column") << -3 << 1 << 0;
112 QTest::newRow("invalid x column and correct y column") << -3 << 1 << 0;
93 QTest::newRow("x column beyond the size of model and correct y column") << m_modelColumnCount << 1 << 0;
113 QTest::newRow("x column beyond the size of model and correct y column") << m_modelColumnCount << 1 << 0;
94 QTest::newRow("x column beyond the size of model and invalid y column") << m_modelColumnCount << -1 << 0;
114 QTest::newRow("x column beyond the size of model and invalid y column") << m_modelColumnCount << -1 << 0;
95 }
115 }
96
116
97 void tst_qxymodelmapper::verticalMapper()
117 void tst_qxymodelmapper::verticalMapper()
98 {
118 {
99 QFETCH(int, xColumn);
119 QFETCH(int, xColumn);
100 QFETCH(int, yColumn);
120 QFETCH(int, yColumn);
101 QFETCH(int, expectedCount);
121 QFETCH(int, expectedCount);
102
122
103 QVXYModelMapper *mapper = new QVXYModelMapper;
123 QVXYModelMapper *mapper = new QVXYModelMapper;
104 mapper->setXColumn(xColumn);
124 mapper->setXColumn(xColumn);
105 mapper->setYColumn(yColumn);
125 mapper->setYColumn(yColumn);
106 mapper->setModel(m_model);
126 mapper->setModel(m_model);
107 mapper->setSeries(m_series);
127 mapper->setSeries(m_series);
108
128
109 QCOMPARE(m_series->count(), expectedCount);
129 QCOMPARE(m_series->count(), expectedCount);
110 QCOMPARE(mapper->xColumn(), qMax(-1, xColumn));
130 QCOMPARE(mapper->xColumn(), qMax(-1, xColumn));
111 QCOMPARE(mapper->yColumn(), qMax(-1, yColumn));
131 QCOMPARE(mapper->yColumn(), qMax(-1, yColumn));
112
132
113 delete mapper;
133 delete mapper;
114 mapper = 0;
134 mapper = 0;
115 }
135 }
116
136
117 void tst_qxymodelmapper::verticalMapperCustomMapping_data()
137 void tst_qxymodelmapper::verticalMapperCustomMapping_data()
118 {
138 {
119 QTest::addColumn<int>("first");
139 QTest::addColumn<int>("first");
120 QTest::addColumn<int>("countLimit");
140 QTest::addColumn<int>("countLimit");
121 QTest::addColumn<int>("expectedCount");
141 QTest::addColumn<int>("expectedCount");
122 QTest::newRow("first: 0, unlimited count") << 0 << -1 << m_modelRowCount;
142 QTest::newRow("first: 0, unlimited count") << 0 << -1 << m_modelRowCount;
123 QTest::newRow("first: 3, unlimited count") << 3 << -1 << m_modelRowCount - 3;
143 QTest::newRow("first: 3, unlimited count") << 3 << -1 << m_modelRowCount - 3;
124 QTest::newRow("first: 0, count: 5") << 0 << 5 << qMin(5, m_modelRowCount);
144 QTest::newRow("first: 0, count: 5") << 0 << 5 << qMin(5, m_modelRowCount);
125 QTest::newRow("first: 3, count: 5") << 3 << 5 << qMin(5, m_modelRowCount - 3);
145 QTest::newRow("first: 3, count: 5") << 3 << 5 << qMin(5, m_modelRowCount - 3);
126 QTest::newRow("first: +1 greater then the number of rows in the model, unlimited count") << m_modelRowCount + 1 << -1 << 0;
146 QTest::newRow("first: +1 greater then the number of rows in the model, unlimited count") << m_modelRowCount + 1 << -1 << 0;
127 QTest::newRow("first: +1 greater then the number of rows in the model, count: 5") << m_modelRowCount + 1 << 5 << 0;
147 QTest::newRow("first: +1 greater then the number of rows in the model, count: 5") << m_modelRowCount + 1 << 5 << 0;
128 QTest::newRow("first: 0, count: +3 greater than the number of rows in the model (should limit to the size of model)") << 0 << m_modelRowCount + 3 << m_modelRowCount;
148 QTest::newRow("first: 0, count: +3 greater than the number of rows in the model (should limit to the size of model)") << 0 << m_modelRowCount + 3 << m_modelRowCount;
129 QTest::newRow("first: -3(invalid - should default to 0), unlimited count") << -3 << -1 << m_modelRowCount;
149 QTest::newRow("first: -3(invalid - should default to 0), unlimited count") << -3 << -1 << m_modelRowCount;
130 QTest::newRow("first: 0, count: -3 (invalid - shlould default to -1)") << 0 << -3 << m_modelRowCount;
150 QTest::newRow("first: 0, count: -3 (invalid - shlould default to -1)") << 0 << -3 << m_modelRowCount;
131 QTest::newRow("first: -3(invalid - should default to 0), count: -3 (invalid - shlould default to -1)") << -3 << -3 << m_modelRowCount;
151 QTest::newRow("first: -3(invalid - should default to 0), count: -3 (invalid - shlould default to -1)") << -3 << -3 << m_modelRowCount;
132
152
133 }
153 }
134
154
135 void tst_qxymodelmapper::verticalMapperCustomMapping()
155 void tst_qxymodelmapper::verticalMapperCustomMapping()
136 {
156 {
137 QFETCH(int, first);
157 QFETCH(int, first);
138 QFETCH(int, countLimit);
158 QFETCH(int, countLimit);
139 QFETCH(int, expectedCount);
159 QFETCH(int, expectedCount);
140
160
141 QCOMPARE(m_series->count(), 0);
161 QCOMPARE(m_series->count(), 0);
142
162
143 QVXYModelMapper *mapper = new QVXYModelMapper;
163 QVXYModelMapper *mapper = new QVXYModelMapper;
144 mapper->setXColumn(0);
164 mapper->setXColumn(0);
145 mapper->setYColumn(1);
165 mapper->setYColumn(1);
146 mapper->setModel(m_model);
166 mapper->setModel(m_model);
147 mapper->setSeries(m_series);
167 mapper->setSeries(m_series);
148 mapper->setFirst(first);
168 mapper->setFirst(first);
149 mapper->setCount(countLimit);
169 mapper->setCount(countLimit);
150
170
151 QCOMPARE(m_series->count(), expectedCount);
171 QCOMPARE(m_series->count(), expectedCount);
152
172
153 // change values column mapping to invalid
173 // change values column mapping to invalid
154 mapper->setXColumn(-1);
174 mapper->setXColumn(-1);
155 mapper->setYColumn(1);
175 mapper->setYColumn(1);
156
176
157 QCOMPARE(m_series->count(), 0);
177 QCOMPARE(m_series->count(), 0);
158
178
159 delete mapper;
179 delete mapper;
160 mapper = 0;
180 mapper = 0;
161 }
181 }
162
182
163 void tst_qxymodelmapper::horizontalMapper_data()
183 void tst_qxymodelmapper::horizontalMapper_data()
164 {
184 {
165 QTest::addColumn<int>("xRow");
185 QTest::addColumn<int>("xRow");
166 QTest::addColumn<int>("yRow");
186 QTest::addColumn<int>("yRow");
167 QTest::addColumn<int>("expectedCount");
187 QTest::addColumn<int>("expectedCount");
168 QTest::newRow("different x and y rows") << 0 << 1 << m_modelColumnCount;
188 QTest::newRow("different x and y rows") << 0 << 1 << m_modelColumnCount;
169 QTest::newRow("same x and y rows") << 1 << 1 << m_modelColumnCount;
189 QTest::newRow("same x and y rows") << 1 << 1 << m_modelColumnCount;
170 QTest::newRow("invalid x row and correct y row") << -3 << 1 << 0;
190 QTest::newRow("invalid x row and correct y row") << -3 << 1 << 0;
171 QTest::newRow("x row beyond the size of model and correct y row") << m_modelRowCount << 1 << 0;
191 QTest::newRow("x row beyond the size of model and correct y row") << m_modelRowCount << 1 << 0;
172 QTest::newRow("x row beyond the size of model and invalid y row") << m_modelRowCount << -1 << 0;
192 QTest::newRow("x row beyond the size of model and invalid y row") << m_modelRowCount << -1 << 0;
173 }
193 }
174
194
175 void tst_qxymodelmapper::horizontalMapper()
195 void tst_qxymodelmapper::horizontalMapper()
176 {
196 {
177 QFETCH(int, xRow);
197 QFETCH(int, xRow);
178 QFETCH(int, yRow);
198 QFETCH(int, yRow);
179 QFETCH(int, expectedCount);
199 QFETCH(int, expectedCount);
180
200
181 QHXYModelMapper *mapper = new QHXYModelMapper;
201 QHXYModelMapper *mapper = new QHXYModelMapper;
182 mapper->setXRow(xRow);
202 mapper->setXRow(xRow);
183 mapper->setYRow(yRow);
203 mapper->setYRow(yRow);
184 mapper->setModel(m_model);
204 mapper->setModel(m_model);
185 mapper->setSeries(m_series);
205 mapper->setSeries(m_series);
186
206
187 QCOMPARE(m_series->count(), expectedCount);
207 QCOMPARE(m_series->count(), expectedCount);
188 QCOMPARE(mapper->xRow(), qMax(-1, xRow));
208 QCOMPARE(mapper->xRow(), qMax(-1, xRow));
189 QCOMPARE(mapper->yRow(), qMax(-1, yRow));
209 QCOMPARE(mapper->yRow(), qMax(-1, yRow));
190
210
191 delete mapper;
211 delete mapper;
192 mapper = 0;
212 mapper = 0;
193 }
213 }
194
214
195 void tst_qxymodelmapper::horizontalMapperCustomMapping_data()
215 void tst_qxymodelmapper::horizontalMapperCustomMapping_data()
196 {
216 {
197 QTest::addColumn<int>("first");
217 QTest::addColumn<int>("first");
198 QTest::addColumn<int>("countLimit");
218 QTest::addColumn<int>("countLimit");
199 QTest::addColumn<int>("expectedCount");
219 QTest::addColumn<int>("expectedCount");
200 QTest::newRow("first: 0, unlimited count") << 0 << -1 << m_modelColumnCount;
220 QTest::newRow("first: 0, unlimited count") << 0 << -1 << m_modelColumnCount;
201 QTest::newRow("first: 3, unlimited count") << 3 << -1 << m_modelColumnCount - 3;
221 QTest::newRow("first: 3, unlimited count") << 3 << -1 << m_modelColumnCount - 3;
202 QTest::newRow("first: 0, count: 5") << 0 << 5 << qMin(5, m_modelColumnCount);
222 QTest::newRow("first: 0, count: 5") << 0 << 5 << qMin(5, m_modelColumnCount);
203 QTest::newRow("first: 3, count: 5") << 3 << 5 << qMin(5, m_modelColumnCount - 3);
223 QTest::newRow("first: 3, count: 5") << 3 << 5 << qMin(5, m_modelColumnCount - 3);
204 QTest::newRow("first: +1 greater then the number of columns in the model, unlimited count") << m_modelColumnCount + 1 << -1 << 0;
224 QTest::newRow("first: +1 greater then the number of columns in the model, unlimited count") << m_modelColumnCount + 1 << -1 << 0;
205 QTest::newRow("first: +1 greater then the number of columns in the model, count: 5") << m_modelColumnCount + 1 << 5 << 0;
225 QTest::newRow("first: +1 greater then the number of columns in the model, count: 5") << m_modelColumnCount + 1 << 5 << 0;
206 QTest::newRow("first: 0, count: +3 greater than the number of columns in the model (should limit to the size of model)") << 0 << m_modelColumnCount + 3 << m_modelColumnCount;
226 QTest::newRow("first: 0, count: +3 greater than the number of columns in the model (should limit to the size of model)") << 0 << m_modelColumnCount + 3 << m_modelColumnCount;
207 QTest::newRow("first: -3(invalid - should default to 0), unlimited count") << -3 << -1 << m_modelColumnCount;
227 QTest::newRow("first: -3(invalid - should default to 0), unlimited count") << -3 << -1 << m_modelColumnCount;
208 QTest::newRow("first: 0, count: -3 (invalid - shlould default to -1)") << 0 << -3 << m_modelColumnCount;
228 QTest::newRow("first: 0, count: -3 (invalid - shlould default to -1)") << 0 << -3 << m_modelColumnCount;
209 QTest::newRow("first: -3(invalid - should default to 0), count: -3 (invalid - shlould default to -1)") << -3 << -3 << m_modelColumnCount;
229 QTest::newRow("first: -3(invalid - should default to 0), count: -3 (invalid - shlould default to -1)") << -3 << -3 << m_modelColumnCount;
210 }
230 }
211
231
212 void tst_qxymodelmapper::horizontalMapperCustomMapping()
232 void tst_qxymodelmapper::horizontalMapperCustomMapping()
213 {
233 {
214 QFETCH(int, first);
234 QFETCH(int, first);
215 QFETCH(int, countLimit);
235 QFETCH(int, countLimit);
216 QFETCH(int, expectedCount);
236 QFETCH(int, expectedCount);
217
237
218 QCOMPARE(m_series->count(), 0);
238 QCOMPARE(m_series->count(), 0);
219
239
220 QHXYModelMapper *mapper = new QHXYModelMapper;
240 QHXYModelMapper *mapper = new QHXYModelMapper;
221 mapper->setXRow(0);
241 mapper->setXRow(0);
222 mapper->setYRow(1);
242 mapper->setYRow(1);
223 mapper->setModel(m_model);
243 mapper->setModel(m_model);
224 mapper->setSeries(m_series);
244 mapper->setSeries(m_series);
225 mapper->setFirst(first);
245 mapper->setFirst(first);
226 mapper->setCount(countLimit);
246 mapper->setCount(countLimit);
227
247
228 QCOMPARE(m_series->count(), expectedCount);
248 QCOMPARE(m_series->count(), expectedCount);
229
249
230 // change values row mapping to invalid
250 // change values row mapping to invalid
231 mapper->setXRow(-1);
251 mapper->setXRow(-1);
232 mapper->setYRow(1);
252 mapper->setYRow(1);
233
253
234 QCOMPARE(m_series->count(), 0);
254 QCOMPARE(m_series->count(), 0);
235
255
236 delete mapper;
256 delete mapper;
237 mapper = 0;
257 mapper = 0;
238 }
258 }
239
259
240 void tst_qxymodelmapper::seriesUpdated()
260 void tst_qxymodelmapper::seriesUpdated()
241 {
261 {
242 QStandardItemModel *otherModel = new QStandardItemModel;
262 QStandardItemModel *otherModel = new QStandardItemModel;
243 for (int row = 0; row < m_modelRowCount; ++row) {
263 for (int row = 0; row < m_modelRowCount; ++row) {
244 for (int column = 0; column < m_modelColumnCount; column++) {
264 for (int column = 0; column < m_modelColumnCount; column++) {
245 QStandardItem *item = new QStandardItem(row * column);
265 QStandardItem *item = new QStandardItem(row * column);
246 otherModel->setItem(row, column, item);
266 otherModel->setItem(row, column, item);
247 }
267 }
248 }
268 }
249
269
250 QVXYModelMapper *mapper = new QVXYModelMapper;
270 QVXYModelMapper *mapper = new QVXYModelMapper;
251 mapper->setXColumn(0);
271 mapper->setXColumn(0);
252 mapper->setYColumn(1);
272 mapper->setYColumn(1);
253 mapper->setModel(otherModel);
273 mapper->setModel(otherModel);
254 mapper->setSeries(m_series);
274 mapper->setSeries(m_series);
255 QCOMPARE(m_series->count(), m_modelRowCount);
275 QCOMPARE(m_series->count(), m_modelRowCount);
256 QCOMPARE(mapper->count(), -1);
276 QCOMPARE(mapper->count(), -1);
257
277
258 m_series->append(QPointF(100, 100));
278 m_series->append(QPointF(100, 100));
259 QCOMPARE(m_series->count(), m_modelRowCount + 1);
279 QCOMPARE(m_series->count(), m_modelRowCount + 1);
260 QCOMPARE(mapper->count(), -1); // the value should not change as it indicates 'all' items there are in the model
280 QCOMPARE(mapper->count(), -1); // the value should not change as it indicates 'all' items there are in the model
261
281
262 m_series->remove(m_series->points().last());
282 m_series->remove(m_series->points().last());
263 QCOMPARE(m_series->count(), m_modelRowCount);
283 QCOMPARE(m_series->count(), m_modelRowCount);
264 QCOMPARE(mapper->count(), -1); // the value should not change as it indicates 'all' items there are in the model
284 QCOMPARE(mapper->count(), -1); // the value should not change as it indicates 'all' items there are in the model
265
285
266 otherModel->clear();
286 otherModel->clear();
267 delete otherModel;
287 delete otherModel;
268 otherModel = 0;
288 otherModel = 0;
269 }
289 }
270
290
271 QTEST_MAIN(tst_qxymodelmapper)
291 QTEST_MAIN(tst_qxymodelmapper)
272
292
273 #include "tst_qxymodelmapper.moc"
293 #include "tst_qxymodelmapper.moc"
General Comments 0
You need to be logged in to leave comments. Login now