##// END OF EJS Templates
Fix spelling errors
Jani Honkonen -
r1940:c7b5c0b5fd0b
parent child
Show More
@@ -1,110 +1,110
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 "declarativemodel.h"
21 #include "declarativemodel.h"
22 #include <qdeclarativelist.h>
22 #include <qdeclarativelist.h>
23 #include <QStringList>
23 #include <QStringList>
24 #include <QDebug>
24 #include <QDebug>
25
25
26 ////////////// Table model element ///////////////////
26 ////////////// Table model element ///////////////////
27
27
28 DeclarativeTableModelElement::DeclarativeTableModelElement(QObject *parent)
28 DeclarativeTableModelElement::DeclarativeTableModelElement(QObject *parent)
29 : QObject(parent)
29 : QObject(parent)
30 {
30 {
31 }
31 }
32
32
33 QVariantList DeclarativeTableModelElement::values()
33 QVariantList DeclarativeTableModelElement::values()
34 {
34 {
35 return m_values;
35 return m_values;
36 }
36 }
37
37
38 void DeclarativeTableModelElement::setValues(QVariantList values)
38 void DeclarativeTableModelElement::setValues(QVariantList values)
39 {
39 {
40 m_values = values;
40 m_values = values;
41 }
41 }
42
42
43 ////////////// Table model ///////////////////
43 ////////////// Table model ///////////////////
44
44
45 DeclarativeTableModel::DeclarativeTableModel(QObject *parent) :
45 DeclarativeTableModel::DeclarativeTableModel(QObject *parent) :
46 CustomTableModel(parent)
46 CustomTableModel(parent)
47 {
47 {
48 }
48 }
49
49
50 void DeclarativeTableModel::classBegin()
50 void DeclarativeTableModel::classBegin()
51 {
51 {
52 }
52 }
53
53
54 void DeclarativeTableModel::componentComplete()
54 void DeclarativeTableModel::componentComplete()
55 {
55 {
56 foreach (QObject *child, children()) {
56 foreach (QObject *child, children()) {
57 if (qobject_cast<DeclarativeTableModelElement *>(child)) {
57 if (qobject_cast<DeclarativeTableModelElement *>(child)) {
58 DeclarativeTableModelElement *element = qobject_cast<DeclarativeTableModelElement *>(child);
58 DeclarativeTableModelElement *element = qobject_cast<DeclarativeTableModelElement *>(child);
59 append(element->values());
59 append(element->values());
60 }
60 }
61 }
61 }
62 }
62 }
63
63
64 void DeclarativeTableModel::setVerticalHeaders(QStringList headers)
64 void DeclarativeTableModel::setVerticalHeaders(QStringList headers)
65 {
65 {
66 for (int i(0); i < headers.count(); i++)
66 for (int i(0); i < headers.count(); i++)
67 setHeaderData(i, Qt::Vertical, headers.at(i));
67 setHeaderData(i, Qt::Vertical, headers.at(i));
68 }
68 }
69
69
70 QStringList DeclarativeTableModel::verticalHeaders()
70 QStringList DeclarativeTableModel::verticalHeaders()
71 {
71 {
72 return QStringList();
72 return QStringList();
73 }
73 }
74
74
75 QDeclarativeListProperty<QObject> DeclarativeTableModel::modelChildren()
75 QDeclarativeListProperty<QObject> DeclarativeTableModel::modelChildren()
76 {
76 {
77 return QDeclarativeListProperty<QObject>(this, 0, &DeclarativeTableModel::appendModelChild);
77 return QDeclarativeListProperty<QObject>(this, 0, &DeclarativeTableModel::appendModelChild);
78 }
78 }
79
79
80 void DeclarativeTableModel::appendModelChild(QDeclarativeListProperty<QObject> *list,
80 void DeclarativeTableModel::appendModelChild(QDeclarativeListProperty<QObject> *list,
81 QObject *child)
81 QObject *child)
82 {
82 {
83 // childs are added in componentComplete instead
83 // children are added in componentComplete instead
84 Q_UNUSED(list)
84 Q_UNUSED(list)
85 Q_UNUSED(child)
85 Q_UNUSED(child)
86 }
86 }
87
87
88 void DeclarativeTableModel::append(QVariantList values)
88 void DeclarativeTableModel::append(QVariantList values)
89 {
89 {
90 // qDebug() << "DeclarativeTableModel::append:" << values;
90 // qDebug() << "DeclarativeTableModel::append:" << values;
91
91
92 while (columnCount() < values.count())
92 while (columnCount() < values.count())
93 insertColumn(columnCount());
93 insertColumn(columnCount());
94
94
95 insertRow(rowCount());
95 insertRow(rowCount());
96
96
97 QModelIndex beginIndex = QModelIndex();
97 QModelIndex beginIndex = QModelIndex();
98 QModelIndex endIndex = QModelIndex();
98 QModelIndex endIndex = QModelIndex();
99 for (int i(0); i < values.count(); i++) {
99 for (int i(0); i < values.count(); i++) {
100 QModelIndex modelIndex = createIndex(rowCount() - 1, i);
100 QModelIndex modelIndex = createIndex(rowCount() - 1, i);
101 if (i == 0)
101 if (i == 0)
102 beginIndex = modelIndex;
102 beginIndex = modelIndex;
103 if (i == (values.count() - 1))
103 if (i == (values.count() - 1))
104 endIndex = modelIndex;
104 endIndex = modelIndex;
105 setData(modelIndex, values.at(i));
105 setData(modelIndex, values.at(i));
106 }
106 }
107 dataChanged(beginIndex, endIndex);
107 dataChanged(beginIndex, endIndex);
108 }
108 }
109
109
110 #include "moc_declarativemodel.cpp"
110 #include "moc_declarativemodel.cpp"
@@ -1,49 +1,49
1 /*!
1 /*!
2 \example demos/nesteddonuts
2 \example demos/nesteddonuts
3 \title Nested donuts demo
3 \title Nested donuts demo
4 \subtitle
4 \subtitle
5
5
6 This example shows how to use create a nested donuts chart using QPieSeries API.
6 This example shows how to use create a nested donuts chart using QPieSeries API.
7 \image examples_donutchart.png
7 \image examples_donutchart.png
8
8
9 Let's start by creating a QChartView instance and enabling the Antialiasing on it. Last line enables the animations of the chart.
9 Let's start by creating a QChartView instance and enabling the Antialiasing on it. Last line enables the animations of the chart.
10
10
11 \snippet ../demos/nesteddonuts/widget.cpp 1
11 \snippet ../demos/nesteddonuts/widget.cpp 1
12
12
13 Three variables are defined that will be used to define the donut chart. Min and max size define the relative size of the whole donut.
13 Three variables are defined that will be used to define the donut chart. Min and max size define the relative size of the whole donut.
14 minSize is the relative inner size of the smallest donut. maxSize is the relative outer size of the biggest donut.
14 minSize is the relative inner size of the smallest donut. maxSize is the relative outer size of the biggest donut.
15
15
16 \snippet ../demos/nesteddonuts/widget.cpp 2
16 \snippet ../demos/nesteddonuts/widget.cpp 2
17
17
18 Following block of code defines the individual donuts and their slices. First new QPieSeries object is created.
18 Following block of code defines the individual donuts and their slices. First new QPieSeries object is created.
19 Callign setDonut() changes pie into a donut. The number of slices in each donut is randomized.
19 Callign setDonut() changes pie into a donut. The number of slices in each donut is randomized.
20 The internal for loop creates the slices with a random value and label same as the value.
20 The internal for loop creates the slices with a random value and label same as the value.
21 Next the label of the slice is set to be visible and its color is set to white.
21 Next the label of the slice is set to be visible and its color is set to white.
22 To make the example more interesting the hovered signal of the slice is connected to widget's slot which inner workings are explained later.
22 To make the example more interesting the hovered signal of the slice is connected to widget's slot which inner workings are explained later.
23 Finally the slice is added to the donut. The donut's size is adjusted to achive the nesting of the donuts.
23 Finally the slice is added to the donut. The donut's size is adjusted to achieve the nesting of the donuts.
24 Then the donut is added to the widget's list of donuts and to the chart.
24 Then the donut is added to the widget's list of donuts and to the chart.
25
25
26 \snippet ../demos/nesteddonuts/widget.cpp 3
26 \snippet ../demos/nesteddonuts/widget.cpp 3
27
27
28 Finally the widget is placed in a layout used by the application.
28 Finally the widget is placed in a layout used by the application.
29
29
30 \snippet ../demos/nesteddonuts/widget.cpp 4
30 \snippet ../demos/nesteddonuts/widget.cpp 4
31
31
32 To make the example more interesting the donuts are rotated randomly every 1.25 sec.
32 To make the example more interesting the donuts are rotated randomly every 1.25 sec.
33
33
34 \snippet ../demos/nesteddonuts/widget.cpp 5
34 \snippet ../demos/nesteddonuts/widget.cpp 5
35
35
36 The widget's updatedRotation slot is defined below.
36 The widget's updatedRotation slot is defined below.
37 It goes through all of the donuts and modifies thier current rotation by a random value.
37 It goes through all of the donuts and modifies thier current rotation by a random value.
38
38
39 \snippet ../demos/nesteddonuts/widget.cpp 6
39 \snippet ../demos/nesteddonuts/widget.cpp 6
40
40
41 The earlier mentioned explodeSlice slot code is provided below.
41 The earlier mentioned explodeSlice slot code is provided below.
42 If the slice is set to exploded then stop the timer that controls the donuts rotation.
42 If the slice is set to exploded then stop the timer that controls the donuts rotation.
43 Then the slice's start and end agles are obtained from the slice.
43 Then the slice's start and end agles are obtained from the slice.
44 To highlight the selected slice all the other donuts that lie outward from the one that contains the selected slice
44 To highlight the selected slice all the other donuts that lie outward from the one that contains the selected slice
45 have their start and end angles modified so that they wouldn't "block" the way for the hightlighted slice.
45 have their start and end angles modified so that they wouldn't "block" the way for the hightlighted slice.
46 If the slice is no longer selected return to the original state.
46 If the slice is no longer selected return to the original state.
47
47
48 \snippet ../demos/nesteddonuts/widget.cpp 7
48 \snippet ../demos/nesteddonuts/widget.cpp 7
49 */
49 */
@@ -1,45 +1,45
1 /*!
1 /*!
2 \example examples/stackedbarchartdrilldown
2 \example examples/stackedbarchartdrilldown
3 \title StackedBarChart Drilldown Example
3 \title StackedBarChart Drilldown Example
4 \subtitle
4 \subtitle
5
5
6 The example shows how to implement drilldown using stacked barchart. In drilldown example we create stacked barchart, which shows the harvest of various chili peppers during season. In season view the harvest is grouped by month. To drill down to weekly view, user clicks selected month with right mouse button. On weekly view, the harvest of clicked month is shown by week. For example purposes each month is 4 weeks long :)
6 The example shows how to implement drilldown using stacked barchart. In drilldown example we create stacked barchart, which shows the harvest of various chili peppers during season. In season view the harvest is grouped by month. To drill down to weekly view, user clicks selected month with right mouse button. On weekly view, the harvest of clicked month is shown by week. For example purposes each month is 4 weeks long :)
7
7
8 Season view looks like this:
8 Season view looks like this:
9 \image examples_stackedbarchartdrilldown1.png
9 \image examples_stackedbarchartdrilldown1.png
10
10
11 Mouse button clicked on a month, shows the harvest from that month:
11 Mouse button clicked on a month, shows the harvest from that month:
12 \image examples_stackedbarchartdrilldown2.png
12 \image examples_stackedbarchartdrilldown2.png
13
13
14 First we define a drilldown series class, which adds categories to stacked bar series and mapping for categories to other drilldown series.
14 First we define a drilldown series class, which adds categories to stacked bar series and mapping for categories to other drilldown series.
15 Purpose of drilldown series is to contain knowledge of the drilldown structure. The mapDrilldownSeries function maps the category to given series. We can ask the mapping for category with drilldownSeries(int category) function.
15 Purpose of drilldown series is to contain knowledge of the drilldown structure. The mapDrilldownSeries function maps the category to given series. We can ask the mapping for category with drilldownSeries(int category) function.
16
16
17 \snippet ../examples/stackedbarchartdrilldown/drilldownseries.h 1
17 \snippet ../examples/stackedbarchartdrilldown/drilldownseries.h 1
18
18
19 Next we define our own drilldown chart, which implements handler for mouse click. All QBarSeries derived classes send out clicked(QBarSet*, int) signal when series is clicked with mouse. The parameter QBarSet contains pointer to clicked bar set and parameter int contains the index of clicked category.
19 Next we define our own drilldown chart, which implements handler for mouse click. All QBarSeries derived classes send out clicked(QBarSet*, int) signal when series is clicked with mouse. The parameter QBarSet contains pointer to clicked bar set and parameter int contains the index of clicked category.
20
20
21 \snippet ../examples/stackedbarchartdrilldown/drilldownchart.h 1
21 \snippet ../examples/stackedbarchartdrilldown/drilldownchart.h 1
22
22
23 Now we have our drilldown classes and we can start using them.
23 Now we have our drilldown classes and we can start using them.
24 First create the chart.
24 First create the chart.
25
25
26 \snippet ../examples/stackedbarchartdrilldown/main.cpp 1
26 \snippet ../examples/stackedbarchartdrilldown/main.cpp 1
27
27
28 We define categories, from wich the drilldown series will be constructed.
28 We define categories, from which the drilldown series will be constructed.
29
29
30 \snippet ../examples/stackedbarchartdrilldown/main.cpp 2
30 \snippet ../examples/stackedbarchartdrilldown/main.cpp 2
31
31
32 To create the drilldown structure, we first create our top level series, which we call seasonSeries. For each month in seasonSeries we create a drilldown series, called weeklySeries which contains more detailed data for that month.
32 To create the drilldown structure, we first create our top level series, which we call seasonSeries. For each month in seasonSeries we create a drilldown series, called weeklySeries which contains more detailed data for that month.
33 In weeklySeries, we use the drilldown handler to bring us back to seasonSeries. To do this we add mapping to the series. The seasonSeries is mapped to weeklySeries for each month. Every weeklySeries is mapped back to the seasonSeries.
33 In weeklySeries, we use the drilldown handler to bring us back to seasonSeries. To do this we add mapping to the series. The seasonSeries is mapped to weeklySeries for each month. Every weeklySeries is mapped back to the seasonSeries.
34 To make mapping work, we connect the clicked signals from our series to the drilldownChart.
34 To make mapping work, we connect the clicked signals from our series to the drilldownChart.
35
35
36 \snippet ../examples/stackedbarchartdrilldown/main.cpp 3
36 \snippet ../examples/stackedbarchartdrilldown/main.cpp 3
37
37
38 When we have our drilldown structure ready, we can add the data to it. Here we generate random crop for each plant in each week. The monthly crop is calculated from weekly crops and is set as value to monthly series.
38 When we have our drilldown structure ready, we can add the data to it. Here we generate random crop for each plant in each week. The monthly crop is calculated from weekly crops and is set as value to monthly series.
39
39
40 \snippet ../examples/stackedbarchartdrilldown/main.cpp 4
40 \snippet ../examples/stackedbarchartdrilldown/main.cpp 4
41
41
42 Here we set the chart to show top level series initially.
42 Here we set the chart to show top level series initially.
43
43
44 \snippet ../examples/stackedbarchartdrilldown/main.cpp 5
44 \snippet ../examples/stackedbarchartdrilldown/main.cpp 5
45 */
45 */
@@ -1,99 +1,99
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 "declarativelineseries.h"
21 #include "declarativelineseries.h"
22
22
23 QTCOMMERCIALCHART_BEGIN_NAMESPACE
23 QTCOMMERCIALCHART_BEGIN_NAMESPACE
24
24
25 DeclarativeLineSeries::DeclarativeLineSeries(QObject *parent) :
25 DeclarativeLineSeries::DeclarativeLineSeries(QObject *parent) :
26 QLineSeries(parent),
26 QLineSeries(parent),
27 m_axisX(0),
27 m_axisX(0),
28 m_axisY(0)
28 m_axisY(0)
29 {
29 {
30 connect(this, SIGNAL(pointAdded(int)), this, SLOT(handleCountChanged(int)));
30 connect(this, SIGNAL(pointAdded(int)), this, SLOT(handleCountChanged(int)));
31 connect(this, SIGNAL(pointRemoved(int)), this, SLOT(handleCountChanged(int)));
31 connect(this, SIGNAL(pointRemoved(int)), this, SLOT(handleCountChanged(int)));
32 }
32 }
33
33
34 void DeclarativeLineSeries::handleCountChanged(int index)
34 void DeclarativeLineSeries::handleCountChanged(int index)
35 {
35 {
36 Q_UNUSED(index)
36 Q_UNUSED(index)
37 emit countChanged(points().count());
37 emit countChanged(points().count());
38 }
38 }
39
39
40 qreal DeclarativeLineSeries::width() const
40 qreal DeclarativeLineSeries::width() const
41 {
41 {
42 return pen().widthF();
42 return pen().widthF();
43 }
43 }
44
44
45 void DeclarativeLineSeries::setWidth(qreal width)
45 void DeclarativeLineSeries::setWidth(qreal width)
46 {
46 {
47 if (width != pen().widthF()) {
47 if (width != pen().widthF()) {
48 QPen p = pen();
48 QPen p = pen();
49 p.setWidthF(width);
49 p.setWidthF(width);
50 setPen(p);
50 setPen(p);
51 emit widthChanged(width);
51 emit widthChanged(width);
52 }
52 }
53 }
53 }
54
54
55 Qt::PenStyle DeclarativeLineSeries::style() const
55 Qt::PenStyle DeclarativeLineSeries::style() const
56 {
56 {
57 return pen().style();
57 return pen().style();
58 }
58 }
59
59
60 void DeclarativeLineSeries::setStyle(Qt::PenStyle style)
60 void DeclarativeLineSeries::setStyle(Qt::PenStyle style)
61 {
61 {
62 if (style != pen().style()) {
62 if (style != pen().style()) {
63 QPen p = pen();
63 QPen p = pen();
64 p.setStyle(style);
64 p.setStyle(style);
65 setPen(p);
65 setPen(p);
66 emit styleChanged(style);
66 emit styleChanged(style);
67 }
67 }
68 }
68 }
69
69
70 Qt::PenCapStyle DeclarativeLineSeries::capStyle() const
70 Qt::PenCapStyle DeclarativeLineSeries::capStyle() const
71 {
71 {
72 return pen().capStyle();
72 return pen().capStyle();
73 }
73 }
74
74
75 void DeclarativeLineSeries::setCapStyle(Qt::PenCapStyle capStyle)
75 void DeclarativeLineSeries::setCapStyle(Qt::PenCapStyle capStyle)
76 {
76 {
77 if (capStyle != pen().capStyle()) {
77 if (capStyle != pen().capStyle()) {
78 QPen p = pen();
78 QPen p = pen();
79 p.setCapStyle(capStyle);
79 p.setCapStyle(capStyle);
80 setPen(p);
80 setPen(p);
81 emit capStyleChanged(capStyle);
81 emit capStyleChanged(capStyle);
82 }
82 }
83 }
83 }
84
84
85 QDeclarativeListProperty<QObject> DeclarativeLineSeries::declarativeChildren()
85 QDeclarativeListProperty<QObject> DeclarativeLineSeries::declarativeChildren()
86 {
86 {
87 return QDeclarativeListProperty<QObject>(this, 0, &appendDeclarativeChildren);
87 return QDeclarativeListProperty<QObject>(this, 0, &appendDeclarativeChildren);
88 }
88 }
89
89
90 void DeclarativeLineSeries::appendDeclarativeChildren(QDeclarativeListProperty<QObject> *list, QObject *element)
90 void DeclarativeLineSeries::appendDeclarativeChildren(QDeclarativeListProperty<QObject> *list, QObject *element)
91 {
91 {
92 Q_UNUSED(list)
92 Q_UNUSED(list)
93 Q_UNUSED(element)
93 Q_UNUSED(element)
94 // Empty implementation, childs are parsed in componentComplete
94 // Empty implementation, children are parsed in componentComplete
95 }
95 }
96
96
97 #include "moc_declarativelineseries.cpp"
97 #include "moc_declarativelineseries.cpp"
98
98
99 QTCOMMERCIALCHART_END_NAMESPACE
99 QTCOMMERCIALCHART_END_NAMESPACE
@@ -1,69 +1,69
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 "declarativescatterseries.h"
21 #include "declarativescatterseries.h"
22
22
23 QTCOMMERCIALCHART_BEGIN_NAMESPACE
23 QTCOMMERCIALCHART_BEGIN_NAMESPACE
24
24
25 DeclarativeScatterSeries::DeclarativeScatterSeries(QObject *parent) :
25 DeclarativeScatterSeries::DeclarativeScatterSeries(QObject *parent) :
26 QScatterSeries(parent),
26 QScatterSeries(parent),
27 m_axisX(0),
27 m_axisX(0),
28 m_axisY(0)
28 m_axisY(0)
29 {
29 {
30 connect(this, SIGNAL(pointAdded(int)), this, SLOT(handleCountChanged(int)));
30 connect(this, SIGNAL(pointAdded(int)), this, SLOT(handleCountChanged(int)));
31 connect(this, SIGNAL(pointRemoved(int)), this, SLOT(handleCountChanged(int)));
31 connect(this, SIGNAL(pointRemoved(int)), this, SLOT(handleCountChanged(int)));
32 }
32 }
33
33
34 void DeclarativeScatterSeries::handleCountChanged(int index)
34 void DeclarativeScatterSeries::handleCountChanged(int index)
35 {
35 {
36 Q_UNUSED(index)
36 Q_UNUSED(index)
37 emit countChanged(QScatterSeries::count());
37 emit countChanged(QScatterSeries::count());
38 }
38 }
39
39
40 qreal DeclarativeScatterSeries::borderWidth() const
40 qreal DeclarativeScatterSeries::borderWidth() const
41 {
41 {
42 return pen().widthF();
42 return pen().widthF();
43 }
43 }
44
44
45 void DeclarativeScatterSeries::setBorderWidth(qreal width)
45 void DeclarativeScatterSeries::setBorderWidth(qreal width)
46 {
46 {
47 if (width != pen().widthF()) {
47 if (width != pen().widthF()) {
48 QPen p = pen();
48 QPen p = pen();
49 p.setWidthF(width);
49 p.setWidthF(width);
50 setPen(p);
50 setPen(p);
51 emit borderWidthChanged(width);
51 emit borderWidthChanged(width);
52 }
52 }
53 }
53 }
54
54
55 QDeclarativeListProperty<QObject> DeclarativeScatterSeries::declarativeChildren()
55 QDeclarativeListProperty<QObject> DeclarativeScatterSeries::declarativeChildren()
56 {
56 {
57 return QDeclarativeListProperty<QObject>(this, 0, &appendDeclarativeChildren);
57 return QDeclarativeListProperty<QObject>(this, 0, &appendDeclarativeChildren);
58 }
58 }
59
59
60 void DeclarativeScatterSeries::appendDeclarativeChildren(QDeclarativeListProperty<QObject> *list, QObject *element)
60 void DeclarativeScatterSeries::appendDeclarativeChildren(QDeclarativeListProperty<QObject> *list, QObject *element)
61 {
61 {
62 Q_UNUSED(list)
62 Q_UNUSED(list)
63 Q_UNUSED(element)
63 Q_UNUSED(element)
64 // Empty implementation, childs are parsed in componentComplete
64 // Empty implementation, children are parsed in componentComplete
65 }
65 }
66
66
67 #include "moc_declarativescatterseries.cpp"
67 #include "moc_declarativescatterseries.cpp"
68
68
69 QTCOMMERCIALCHART_END_NAMESPACE
69 QTCOMMERCIALCHART_END_NAMESPACE
@@ -1,99 +1,99
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 "declarativesplineseries.h"
21 #include "declarativesplineseries.h"
22
22
23 QTCOMMERCIALCHART_BEGIN_NAMESPACE
23 QTCOMMERCIALCHART_BEGIN_NAMESPACE
24
24
25 DeclarativeSplineSeries::DeclarativeSplineSeries(QObject *parent) :
25 DeclarativeSplineSeries::DeclarativeSplineSeries(QObject *parent) :
26 QSplineSeries(parent),
26 QSplineSeries(parent),
27 m_axisX(0),
27 m_axisX(0),
28 m_axisY(0)
28 m_axisY(0)
29 {
29 {
30 connect(this, SIGNAL(pointAdded(int)), this, SLOT(handleCountChanged(int)));
30 connect(this, SIGNAL(pointAdded(int)), this, SLOT(handleCountChanged(int)));
31 connect(this, SIGNAL(pointRemoved(int)), this, SLOT(handleCountChanged(int)));
31 connect(this, SIGNAL(pointRemoved(int)), this, SLOT(handleCountChanged(int)));
32 }
32 }
33
33
34 void DeclarativeSplineSeries::handleCountChanged(int index)
34 void DeclarativeSplineSeries::handleCountChanged(int index)
35 {
35 {
36 Q_UNUSED(index)
36 Q_UNUSED(index)
37 emit countChanged(points().count());
37 emit countChanged(points().count());
38 }
38 }
39
39
40 qreal DeclarativeSplineSeries::width() const
40 qreal DeclarativeSplineSeries::width() const
41 {
41 {
42 return pen().widthF();
42 return pen().widthF();
43 }
43 }
44
44
45 void DeclarativeSplineSeries::setWidth(qreal width)
45 void DeclarativeSplineSeries::setWidth(qreal width)
46 {
46 {
47 if (width != pen().widthF()) {
47 if (width != pen().widthF()) {
48 QPen p = pen();
48 QPen p = pen();
49 p.setWidthF(width);
49 p.setWidthF(width);
50 setPen(p);
50 setPen(p);
51 emit widthChanged(width);
51 emit widthChanged(width);
52 }
52 }
53 }
53 }
54
54
55 Qt::PenStyle DeclarativeSplineSeries::style() const
55 Qt::PenStyle DeclarativeSplineSeries::style() const
56 {
56 {
57 return pen().style();
57 return pen().style();
58 }
58 }
59
59
60 void DeclarativeSplineSeries::setStyle(Qt::PenStyle style)
60 void DeclarativeSplineSeries::setStyle(Qt::PenStyle style)
61 {
61 {
62 if (style != pen().style()) {
62 if (style != pen().style()) {
63 QPen p = pen();
63 QPen p = pen();
64 p.setStyle(style);
64 p.setStyle(style);
65 setPen(p);
65 setPen(p);
66 emit styleChanged(style);
66 emit styleChanged(style);
67 }
67 }
68 }
68 }
69
69
70 Qt::PenCapStyle DeclarativeSplineSeries::capStyle() const
70 Qt::PenCapStyle DeclarativeSplineSeries::capStyle() const
71 {
71 {
72 return pen().capStyle();
72 return pen().capStyle();
73 }
73 }
74
74
75 void DeclarativeSplineSeries::setCapStyle(Qt::PenCapStyle capStyle)
75 void DeclarativeSplineSeries::setCapStyle(Qt::PenCapStyle capStyle)
76 {
76 {
77 if (capStyle != pen().capStyle()) {
77 if (capStyle != pen().capStyle()) {
78 QPen p = pen();
78 QPen p = pen();
79 p.setCapStyle(capStyle);
79 p.setCapStyle(capStyle);
80 setPen(p);
80 setPen(p);
81 emit capStyleChanged(capStyle);
81 emit capStyleChanged(capStyle);
82 }
82 }
83 }
83 }
84
84
85 QDeclarativeListProperty<QObject> DeclarativeSplineSeries::declarativeChildren()
85 QDeclarativeListProperty<QObject> DeclarativeSplineSeries::declarativeChildren()
86 {
86 {
87 return QDeclarativeListProperty<QObject>(this, 0, &appendDeclarativeChildren);
87 return QDeclarativeListProperty<QObject>(this, 0, &appendDeclarativeChildren);
88 }
88 }
89
89
90 void DeclarativeSplineSeries::appendDeclarativeChildren(QDeclarativeListProperty<QObject> *list, QObject *element)
90 void DeclarativeSplineSeries::appendDeclarativeChildren(QDeclarativeListProperty<QObject> *list, QObject *element)
91 {
91 {
92 Q_UNUSED(list)
92 Q_UNUSED(list)
93 Q_UNUSED(element)
93 Q_UNUSED(element)
94 // Empty implementation, childs are parsed in componentComplete
94 // Empty implementation, children are parsed in componentComplete
95 }
95 }
96
96
97 #include "moc_declarativesplineseries.cpp"
97 #include "moc_declarativesplineseries.cpp"
98
98
99 QTCOMMERCIALCHART_END_NAMESPACE
99 QTCOMMERCIALCHART_END_NAMESPACE
@@ -1,638 +1,638
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 <QtTest/QtTest>
21 #include <QtTest/QtTest>
22 #include <qchartview.h>
22 #include <qchartview.h>
23 #include <qchart.h>
23 #include <qchart.h>
24 #include <qpieseries.h>
24 #include <qpieseries.h>
25 #include <qpieslice.h>
25 #include <qpieslice.h>
26 #include <qpiemodelmapper.h>
26 #include <qpiemodelmapper.h>
27 #include <QStandardItemModel>
27 #include <QStandardItemModel>
28 #include <tst_definitions.h>
28 #include <tst_definitions.h>
29
29
30 QTCOMMERCIALCHART_USE_NAMESPACE
30 QTCOMMERCIALCHART_USE_NAMESPACE
31
31
32 Q_DECLARE_METATYPE(QPieSlice*)
32 Q_DECLARE_METATYPE(QPieSlice*)
33 Q_DECLARE_METATYPE(QList<QPieSlice*>)
33 Q_DECLARE_METATYPE(QList<QPieSlice*>)
34
34
35 class tst_qpieseries : public QObject
35 class tst_qpieseries : public QObject
36 {
36 {
37 Q_OBJECT
37 Q_OBJECT
38
38
39 public slots:
39 public slots:
40 void initTestCase();
40 void initTestCase();
41 void cleanupTestCase();
41 void cleanupTestCase();
42 void init();
42 void init();
43 void cleanup();
43 void cleanup();
44
44
45 private slots:
45 private slots:
46 void properties();
46 void properties();
47 void append();
47 void append();
48 void appendAnimated();
48 void appendAnimated();
49 void insert();
49 void insert();
50 void insertAnimated();
50 void insertAnimated();
51 void remove();
51 void remove();
52 void removeAnimated();
52 void removeAnimated();
53 void take();
53 void take();
54 void takeAnimated();
54 void takeAnimated();
55 void calculatedValues();
55 void calculatedValues();
56 void clickedSignal();
56 void clickedSignal();
57 void hoverSignal();
57 void hoverSignal();
58 void sliceSeries();
58 void sliceSeries();
59 void destruction();
59 void destruction();
60
60
61 private:
61 private:
62 void verifyCalculatedData(const QPieSeries &series, bool *ok);
62 void verifyCalculatedData(const QPieSeries &series, bool *ok);
63
63
64 private:
64 private:
65 QChartView *m_view;
65 QChartView *m_view;
66 QPieSeries *m_series;
66 QPieSeries *m_series;
67 };
67 };
68
68
69 void tst_qpieseries::initTestCase()
69 void tst_qpieseries::initTestCase()
70 {
70 {
71 qRegisterMetaType<QPieSlice*>("QPieSlice*");
71 qRegisterMetaType<QPieSlice*>("QPieSlice*");
72 qRegisterMetaType<QList<QPieSlice*> >("QList<QPieSlice*>");
72 qRegisterMetaType<QList<QPieSlice*> >("QList<QPieSlice*>");
73 }
73 }
74
74
75 void tst_qpieseries::cleanupTestCase()
75 void tst_qpieseries::cleanupTestCase()
76 {
76 {
77 }
77 }
78
78
79 void tst_qpieseries::init()
79 void tst_qpieseries::init()
80 {
80 {
81 m_view = new QChartView();
81 m_view = new QChartView();
82 m_series = new QPieSeries(m_view);
82 m_series = new QPieSeries(m_view);
83 m_view->show();
83 m_view->show();
84 QTest::qWaitForWindowShown(m_view);
84 QTest::qWaitForWindowShown(m_view);
85
85
86 }
86 }
87
87
88 void tst_qpieseries::cleanup()
88 void tst_qpieseries::cleanup()
89 {
89 {
90 delete m_view;
90 delete m_view;
91 m_view = 0;
91 m_view = 0;
92 m_series = 0;
92 m_series = 0;
93 }
93 }
94
94
95 void tst_qpieseries::properties()
95 void tst_qpieseries::properties()
96 {
96 {
97 QSignalSpy countSpy(m_series, SIGNAL(countChanged()));
97 QSignalSpy countSpy(m_series, SIGNAL(countChanged()));
98 QSignalSpy sumSpy(m_series, SIGNAL(sumChanged()));
98 QSignalSpy sumSpy(m_series, SIGNAL(sumChanged()));
99
99
100 QVERIFY(m_series->type() == QAbstractSeries::SeriesTypePie);
100 QVERIFY(m_series->type() == QAbstractSeries::SeriesTypePie);
101 QVERIFY(m_series->count() == 0);
101 QVERIFY(m_series->count() == 0);
102 QVERIFY(m_series->isEmpty());
102 QVERIFY(m_series->isEmpty());
103 QCOMPARE(m_series->sum(), 0.0);
103 QCOMPARE(m_series->sum(), 0.0);
104 QCOMPARE(m_series->horizontalPosition(), 0.5);
104 QCOMPARE(m_series->horizontalPosition(), 0.5);
105 QCOMPARE(m_series->verticalPosition(), 0.5);
105 QCOMPARE(m_series->verticalPosition(), 0.5);
106 QCOMPARE(m_series->pieSize(), 0.7);
106 QCOMPARE(m_series->pieSize(), 0.7);
107 QCOMPARE(m_series->pieStartAngle(), 0.0);
107 QCOMPARE(m_series->pieStartAngle(), 0.0);
108 QCOMPARE(m_series->pieEndAngle(), 360.0);
108 QCOMPARE(m_series->pieEndAngle(), 360.0);
109
109
110 m_series->append("s1", 1);
110 m_series->append("s1", 1);
111 m_series->append("s2", 1);
111 m_series->append("s2", 1);
112 m_series->append("s3", 1);
112 m_series->append("s3", 1);
113 m_series->insert(1, new QPieSlice("s4", 1));
113 m_series->insert(1, new QPieSlice("s4", 1));
114 m_series->remove(m_series->slices().first());
114 m_series->remove(m_series->slices().first());
115 QCOMPARE(m_series->count(), 3);
115 QCOMPARE(m_series->count(), 3);
116 QCOMPARE(m_series->sum(), 3.0);
116 QCOMPARE(m_series->sum(), 3.0);
117 m_series->clear();
117 m_series->clear();
118 QCOMPARE(m_series->count(), 0);
118 QCOMPARE(m_series->count(), 0);
119 QCOMPARE(m_series->sum(), 0.0);
119 QCOMPARE(m_series->sum(), 0.0);
120 QCOMPARE(countSpy.count(), 6);
120 QCOMPARE(countSpy.count(), 6);
121 QCOMPARE(sumSpy.count(), 6);
121 QCOMPARE(sumSpy.count(), 6);
122
122
123 m_series->setPieSize(-1.0);
123 m_series->setPieSize(-1.0);
124 QCOMPARE(m_series->pieSize(), 0.0);
124 QCOMPARE(m_series->pieSize(), 0.0);
125 m_series->setPieSize(0.0);
125 m_series->setPieSize(0.0);
126 m_series->setPieSize(0.9);
126 m_series->setPieSize(0.9);
127 m_series->setPieSize(2.0);
127 m_series->setPieSize(2.0);
128 QCOMPARE(m_series->pieSize(), 1.0);
128 QCOMPARE(m_series->pieSize(), 1.0);
129
129
130 m_series->setPieSize(0.7);
130 m_series->setPieSize(0.7);
131 QCOMPARE(m_series->pieSize(), 0.7);
131 QCOMPARE(m_series->pieSize(), 0.7);
132
132
133 m_series->setHoleSize(-1.0);
133 m_series->setHoleSize(-1.0);
134 QCOMPARE(m_series->holeSize(), 0.0);
134 QCOMPARE(m_series->holeSize(), 0.0);
135 m_series->setHoleSize(0.5);
135 m_series->setHoleSize(0.5);
136 QCOMPARE(m_series->holeSize(), 0.5);
136 QCOMPARE(m_series->holeSize(), 0.5);
137
137
138 m_series->setHoleSize(0.8);
138 m_series->setHoleSize(0.8);
139 QCOMPARE(m_series->holeSize(), 0.8);
139 QCOMPARE(m_series->holeSize(), 0.8);
140 QCOMPARE(m_series->pieSize(), 0.8);
140 QCOMPARE(m_series->pieSize(), 0.8);
141
141
142 m_series->setPieSize(0.4);
142 m_series->setPieSize(0.4);
143 QCOMPARE(m_series->pieSize(), 0.4);
143 QCOMPARE(m_series->pieSize(), 0.4);
144 QCOMPARE(m_series->holeSize(), 0.4);
144 QCOMPARE(m_series->holeSize(), 0.4);
145
145
146 m_series->setPieStartAngle(0);
146 m_series->setPieStartAngle(0);
147 m_series->setPieStartAngle(-180);
147 m_series->setPieStartAngle(-180);
148 m_series->setPieStartAngle(180);
148 m_series->setPieStartAngle(180);
149 QCOMPARE(m_series->pieStartAngle(), 180.0);
149 QCOMPARE(m_series->pieStartAngle(), 180.0);
150
150
151 m_series->setPieEndAngle(360);
151 m_series->setPieEndAngle(360);
152 m_series->setPieEndAngle(-180);
152 m_series->setPieEndAngle(-180);
153 m_series->setPieEndAngle(180);
153 m_series->setPieEndAngle(180);
154 QCOMPARE(m_series->pieEndAngle(), 180.0);
154 QCOMPARE(m_series->pieEndAngle(), 180.0);
155
155
156 m_series->setHorizontalPosition(0.5);
156 m_series->setHorizontalPosition(0.5);
157 m_series->setHorizontalPosition(-1.0);
157 m_series->setHorizontalPosition(-1.0);
158 QCOMPARE(m_series->horizontalPosition(), 0.0);
158 QCOMPARE(m_series->horizontalPosition(), 0.0);
159 m_series->setHorizontalPosition(1.0);
159 m_series->setHorizontalPosition(1.0);
160 m_series->setHorizontalPosition(2.0);
160 m_series->setHorizontalPosition(2.0);
161 QCOMPARE(m_series->horizontalPosition(), 1.0);
161 QCOMPARE(m_series->horizontalPosition(), 1.0);
162
162
163 m_series->setVerticalPosition(0.5);
163 m_series->setVerticalPosition(0.5);
164 m_series->setVerticalPosition(-1.0);
164 m_series->setVerticalPosition(-1.0);
165 QCOMPARE(m_series->verticalPosition(), 0.0);
165 QCOMPARE(m_series->verticalPosition(), 0.0);
166 m_series->setVerticalPosition(1.0);
166 m_series->setVerticalPosition(1.0);
167 m_series->setVerticalPosition(2.0);
167 m_series->setVerticalPosition(2.0);
168 QCOMPARE(m_series->verticalPosition(), 1.0);
168 QCOMPARE(m_series->verticalPosition(), 1.0);
169 }
169 }
170
170
171 void tst_qpieseries::append()
171 void tst_qpieseries::append()
172 {
172 {
173 m_view->chart()->addSeries(m_series);
173 m_view->chart()->addSeries(m_series);
174 QSignalSpy addedSpy(m_series, SIGNAL(added(QList<QPieSlice*>)));
174 QSignalSpy addedSpy(m_series, SIGNAL(added(QList<QPieSlice*>)));
175
175
176 // append pointer
176 // append pointer
177 QPieSlice *slice1 = 0;
177 QPieSlice *slice1 = 0;
178 QVERIFY(!m_series->append(slice1));
178 QVERIFY(!m_series->append(slice1));
179 slice1 = new QPieSlice("slice 1", 1);
179 slice1 = new QPieSlice("slice 1", 1);
180 QVERIFY(m_series->append(slice1));
180 QVERIFY(m_series->append(slice1));
181 QVERIFY(!m_series->append(slice1));
181 QVERIFY(!m_series->append(slice1));
182 QCOMPARE(m_series->count(), 1);
182 QCOMPARE(m_series->count(), 1);
183 QCOMPARE(addedSpy.count(), 1);
183 QCOMPARE(addedSpy.count(), 1);
184 QList<QPieSlice*> added = qvariant_cast<QList<QPieSlice*> >(addedSpy.at(0).at(0));
184 QList<QPieSlice*> added = qvariant_cast<QList<QPieSlice*> >(addedSpy.at(0).at(0));
185 QCOMPARE(added.count(), 1);
185 QCOMPARE(added.count(), 1);
186 QCOMPARE(added.first(), slice1);
186 QCOMPARE(added.first(), slice1);
187
187
188 // try to append same slice to another series
188 // try to append same slice to another series
189 QPieSeries series2;
189 QPieSeries series2;
190 QVERIFY(!series2.append(slice1));
190 QVERIFY(!series2.append(slice1));
191
191
192 // append pointer list
192 // append pointer list
193 QList<QPieSlice *> list;
193 QList<QPieSlice *> list;
194 QVERIFY(!m_series->append(list));
194 QVERIFY(!m_series->append(list));
195 list << (QPieSlice *) 0;
195 list << (QPieSlice *) 0;
196 QVERIFY(!m_series->append(list));
196 QVERIFY(!m_series->append(list));
197 list.clear();
197 list.clear();
198 list << new QPieSlice("slice 2", 2);
198 list << new QPieSlice("slice 2", 2);
199 list << new QPieSlice("slice 3", 3);
199 list << new QPieSlice("slice 3", 3);
200 QVERIFY(m_series->append(list));
200 QVERIFY(m_series->append(list));
201 QVERIFY(!m_series->append(list));
201 QVERIFY(!m_series->append(list));
202 QCOMPARE(m_series->count(), 3);
202 QCOMPARE(m_series->count(), 3);
203 QCOMPARE(addedSpy.count(), 2);
203 QCOMPARE(addedSpy.count(), 2);
204 added = qvariant_cast<QList<QPieSlice*> >(addedSpy.at(1).at(0));
204 added = qvariant_cast<QList<QPieSlice*> >(addedSpy.at(1).at(0));
205 QCOMPARE(added.count(), 2);
205 QCOMPARE(added.count(), 2);
206 QCOMPARE(added, list);
206 QCOMPARE(added, list);
207
207
208 // append operator
208 // append operator
209 QPieSlice *slice4 = new QPieSlice("slice 4", 4);
209 QPieSlice *slice4 = new QPieSlice("slice 4", 4);
210 *m_series << slice4;
210 *m_series << slice4;
211 *m_series << slice1; // fails because already added
211 *m_series << slice1; // fails because already added
212 QCOMPARE(m_series->count(), 4);
212 QCOMPARE(m_series->count(), 4);
213 QCOMPARE(addedSpy.count(), 3);
213 QCOMPARE(addedSpy.count(), 3);
214 added = qvariant_cast<QList<QPieSlice*> >(addedSpy.at(2).at(0));
214 added = qvariant_cast<QList<QPieSlice*> >(addedSpy.at(2).at(0));
215 QCOMPARE(added.count(), 1);
215 QCOMPARE(added.count(), 1);
216 QCOMPARE(added.first(), slice4);
216 QCOMPARE(added.first(), slice4);
217
217
218 // append with params
218 // append with params
219 QPieSlice *slice5 = m_series->append("slice 5", 5);
219 QPieSlice *slice5 = m_series->append("slice 5", 5);
220 QVERIFY(slice5 != 0);
220 QVERIFY(slice5 != 0);
221 QCOMPARE(slice5->value(), 5.0);
221 QCOMPARE(slice5->value(), 5.0);
222 QCOMPARE(slice5->label(), QString("slice 5"));
222 QCOMPARE(slice5->label(), QString("slice 5"));
223 QCOMPARE(m_series->count(), 5);
223 QCOMPARE(m_series->count(), 5);
224 QCOMPARE(addedSpy.count(), 4);
224 QCOMPARE(addedSpy.count(), 4);
225 added = qvariant_cast<QList<QPieSlice*> >(addedSpy.at(3).at(0));
225 added = qvariant_cast<QList<QPieSlice*> >(addedSpy.at(3).at(0));
226 QCOMPARE(added.count(), 1);
226 QCOMPARE(added.count(), 1);
227 QCOMPARE(added.first(), slice5);
227 QCOMPARE(added.first(), slice5);
228
228
229 // check slices
229 // check slices
230 QVERIFY(!m_series->isEmpty());
230 QVERIFY(!m_series->isEmpty());
231 for (int i=0; i<m_series->count(); i++) {
231 for (int i=0; i<m_series->count(); i++) {
232 QCOMPARE(m_series->slices().at(i)->value(), (qreal) i+1);
232 QCOMPARE(m_series->slices().at(i)->value(), (qreal) i+1);
233 QCOMPARE(m_series->slices().at(i)->label(), QString("slice ") + QString::number(i+1));
233 QCOMPARE(m_series->slices().at(i)->label(), QString("slice ") + QString::number(i+1));
234 }
234 }
235 }
235 }
236
236
237 void tst_qpieseries::appendAnimated()
237 void tst_qpieseries::appendAnimated()
238 {
238 {
239 m_view->chart()->setAnimationOptions(QChart::AllAnimations);
239 m_view->chart()->setAnimationOptions(QChart::AllAnimations);
240 append();
240 append();
241 }
241 }
242
242
243 void tst_qpieseries::insert()
243 void tst_qpieseries::insert()
244 {
244 {
245 m_view->chart()->addSeries(m_series);
245 m_view->chart()->addSeries(m_series);
246 QSignalSpy addedSpy(m_series, SIGNAL(added(QList<QPieSlice*>)));
246 QSignalSpy addedSpy(m_series, SIGNAL(added(QList<QPieSlice*>)));
247
247
248 // insert one slice
248 // insert one slice
249 QPieSlice *slice1 = 0;
249 QPieSlice *slice1 = 0;
250 QVERIFY(!m_series->insert(0, slice1));
250 QVERIFY(!m_series->insert(0, slice1));
251 slice1 = new QPieSlice("slice 1", 1);
251 slice1 = new QPieSlice("slice 1", 1);
252 QVERIFY(!m_series->insert(-1, slice1));
252 QVERIFY(!m_series->insert(-1, slice1));
253 QVERIFY(!m_series->insert(5, slice1));
253 QVERIFY(!m_series->insert(5, slice1));
254 QVERIFY(m_series->insert(0, slice1));
254 QVERIFY(m_series->insert(0, slice1));
255 QVERIFY(!m_series->insert(0, slice1));
255 QVERIFY(!m_series->insert(0, slice1));
256 QCOMPARE(m_series->count(), 1);
256 QCOMPARE(m_series->count(), 1);
257 QCOMPARE(addedSpy.count(), 1);
257 QCOMPARE(addedSpy.count(), 1);
258 QList<QPieSlice*> added = qvariant_cast<QList<QPieSlice*> >(addedSpy.at(0).at(0));
258 QList<QPieSlice*> added = qvariant_cast<QList<QPieSlice*> >(addedSpy.at(0).at(0));
259 QCOMPARE(added.count(), 1);
259 QCOMPARE(added.count(), 1);
260 QCOMPARE(added.first(), slice1);
260 QCOMPARE(added.first(), slice1);
261
261
262 // try to insert same slice to another series
262 // try to insert same slice to another series
263 QPieSeries series2;
263 QPieSeries series2;
264 QVERIFY(!series2.insert(0, slice1));
264 QVERIFY(!series2.insert(0, slice1));
265
265
266 // add some more slices
266 // add some more slices
267 QPieSlice *slice2 = m_series->append("slice 2", 2);
267 QPieSlice *slice2 = m_series->append("slice 2", 2);
268 QPieSlice *slice4 = m_series->append("slice 4", 4);
268 QPieSlice *slice4 = m_series->append("slice 4", 4);
269 QCOMPARE(m_series->count(), 3);
269 QCOMPARE(m_series->count(), 3);
270 QCOMPARE(addedSpy.count(), 3);
270 QCOMPARE(addedSpy.count(), 3);
271 added = qvariant_cast<QList<QPieSlice*> >(addedSpy.at(1).at(0));
271 added = qvariant_cast<QList<QPieSlice*> >(addedSpy.at(1).at(0));
272 QCOMPARE(added.count(), 1);
272 QCOMPARE(added.count(), 1);
273 QCOMPARE(added.first(), slice2);
273 QCOMPARE(added.first(), slice2);
274 added = qvariant_cast<QList<QPieSlice*> >(addedSpy.at(2).at(0));
274 added = qvariant_cast<QList<QPieSlice*> >(addedSpy.at(2).at(0));
275 QCOMPARE(added.count(), 1);
275 QCOMPARE(added.count(), 1);
276 QCOMPARE(added.first(), slice4);
276 QCOMPARE(added.first(), slice4);
277
277
278 // insert between slices
278 // insert between slices
279 QPieSlice *slice3 = new QPieSlice("slice 3", 3);
279 QPieSlice *slice3 = new QPieSlice("slice 3", 3);
280 m_series->insert(2, slice3);
280 m_series->insert(2, slice3);
281 QCOMPARE(m_series->count(), 4);
281 QCOMPARE(m_series->count(), 4);
282 QCOMPARE(addedSpy.count(), 4);
282 QCOMPARE(addedSpy.count(), 4);
283 added = qvariant_cast<QList<QPieSlice*> >(addedSpy.at(3).at(0));
283 added = qvariant_cast<QList<QPieSlice*> >(addedSpy.at(3).at(0));
284 QCOMPARE(added.count(), 1);
284 QCOMPARE(added.count(), 1);
285 QCOMPARE(added.first(), slice3);
285 QCOMPARE(added.first(), slice3);
286
286
287 // check slices
287 // check slices
288 for (int i=0; i<m_series->count(); i++) {
288 for (int i=0; i<m_series->count(); i++) {
289 QCOMPARE(m_series->slices().at(i)->value(), (qreal) i+1);
289 QCOMPARE(m_series->slices().at(i)->value(), (qreal) i+1);
290 QCOMPARE(m_series->slices().at(i)->label(), QString("slice ") + QString::number(i+1));
290 QCOMPARE(m_series->slices().at(i)->label(), QString("slice ") + QString::number(i+1));
291 QVERIFY(m_series->slices().at(i)->parent() == m_series);
291 QVERIFY(m_series->slices().at(i)->parent() == m_series);
292 }
292 }
293 }
293 }
294
294
295 void tst_qpieseries::insertAnimated()
295 void tst_qpieseries::insertAnimated()
296 {
296 {
297 m_view->chart()->setAnimationOptions(QChart::AllAnimations);
297 m_view->chart()->setAnimationOptions(QChart::AllAnimations);
298 insert();
298 insert();
299 }
299 }
300
300
301 void tst_qpieseries::remove()
301 void tst_qpieseries::remove()
302 {
302 {
303 m_view->chart()->addSeries(m_series);
303 m_view->chart()->addSeries(m_series);
304 QSignalSpy removedSpy(m_series, SIGNAL(removed(QList<QPieSlice*>)));
304 QSignalSpy removedSpy(m_series, SIGNAL(removed(QList<QPieSlice*>)));
305
305
306 // add some slices
306 // add some slices
307 QPieSlice *slice1 = m_series->append("slice 1", 1);
307 QPieSlice *slice1 = m_series->append("slice 1", 1);
308 QPieSlice *slice2 = m_series->append("slice 2", 2);
308 QPieSlice *slice2 = m_series->append("slice 2", 2);
309 QPieSlice *slice3 = m_series->append("slice 3", 3);
309 QPieSlice *slice3 = m_series->append("slice 3", 3);
310 QSignalSpy spy1(slice1, SIGNAL(destroyed()));
310 QSignalSpy spy1(slice1, SIGNAL(destroyed()));
311 QSignalSpy spy2(slice2, SIGNAL(destroyed()));
311 QSignalSpy spy2(slice2, SIGNAL(destroyed()));
312 QSignalSpy spy3(slice3, SIGNAL(destroyed()));
312 QSignalSpy spy3(slice3, SIGNAL(destroyed()));
313 QCOMPARE(m_series->count(), 3);
313 QCOMPARE(m_series->count(), 3);
314
314
315 // null pointer remove
315 // null pointer remove
316 QVERIFY(!m_series->remove(0));
316 QVERIFY(!m_series->remove(0));
317
317
318 // remove first
318 // remove first
319 QVERIFY(m_series->remove(slice1));
319 QVERIFY(m_series->remove(slice1));
320 QVERIFY(!m_series->remove(slice1));
320 QVERIFY(!m_series->remove(slice1));
321 QCOMPARE(m_series->count(), 2);
321 QCOMPARE(m_series->count(), 2);
322 QCOMPARE(m_series->slices().at(0)->label(), slice2->label());
322 QCOMPARE(m_series->slices().at(0)->label(), slice2->label());
323 QCOMPARE(removedSpy.count(), 1);
323 QCOMPARE(removedSpy.count(), 1);
324 QList<QPieSlice*> removed = qvariant_cast<QList<QPieSlice*> >(removedSpy.at(0).at(0));
324 QList<QPieSlice*> removed = qvariant_cast<QList<QPieSlice*> >(removedSpy.at(0).at(0));
325 QCOMPARE(removed.count(), 1);
325 QCOMPARE(removed.count(), 1);
326 QCOMPARE(removed.first(), slice1);
326 QCOMPARE(removed.first(), slice1);
327
327
328 // remove all
328 // remove all
329 m_series->clear();
329 m_series->clear();
330 QVERIFY(m_series->isEmpty());
330 QVERIFY(m_series->isEmpty());
331 QVERIFY(m_series->slices().isEmpty());
331 QVERIFY(m_series->slices().isEmpty());
332 QCOMPARE(m_series->count(), 0);
332 QCOMPARE(m_series->count(), 0);
333 QCOMPARE(removedSpy.count(), 2);
333 QCOMPARE(removedSpy.count(), 2);
334 removed = qvariant_cast<QList<QPieSlice*> >(removedSpy.at(1).at(0));
334 removed = qvariant_cast<QList<QPieSlice*> >(removedSpy.at(1).at(0));
335 QCOMPARE(removed.count(), 2);
335 QCOMPARE(removed.count(), 2);
336 QCOMPARE(removed.first(), slice2);
336 QCOMPARE(removed.first(), slice2);
337 QCOMPARE(removed.last(), slice3);
337 QCOMPARE(removed.last(), slice3);
338
338
339 // check that slices were actually destroyed
339 // check that slices were actually destroyed
340 TRY_COMPARE(spy1.count(), 1);
340 TRY_COMPARE(spy1.count(), 1);
341 TRY_COMPARE(spy2.count(), 1);
341 TRY_COMPARE(spy2.count(), 1);
342 TRY_COMPARE(spy3.count(), 1);
342 TRY_COMPARE(spy3.count(), 1);
343 }
343 }
344
344
345 void tst_qpieseries::removeAnimated()
345 void tst_qpieseries::removeAnimated()
346 {
346 {
347 m_view->chart()->setAnimationOptions(QChart::AllAnimations);
347 m_view->chart()->setAnimationOptions(QChart::AllAnimations);
348 remove();
348 remove();
349 }
349 }
350
350
351 void tst_qpieseries::take()
351 void tst_qpieseries::take()
352 {
352 {
353 m_view->chart()->addSeries(m_series);
353 m_view->chart()->addSeries(m_series);
354 QSignalSpy removedSpy(m_series, SIGNAL(removed(QList<QPieSlice*>)));
354 QSignalSpy removedSpy(m_series, SIGNAL(removed(QList<QPieSlice*>)));
355
355
356 // add some slices
356 // add some slices
357 QPieSlice *slice1 = m_series->append("slice 1", 1);
357 QPieSlice *slice1 = m_series->append("slice 1", 1);
358 QPieSlice *slice2 = m_series->append("slice 2", 2);
358 QPieSlice *slice2 = m_series->append("slice 2", 2);
359 m_series->append("slice 3", 3);
359 m_series->append("slice 3", 3);
360 QSignalSpy spy1(slice1, SIGNAL(destroyed()));
360 QSignalSpy spy1(slice1, SIGNAL(destroyed()));
361 QCOMPARE(m_series->count(), 3);
361 QCOMPARE(m_series->count(), 3);
362
362
363 // null pointer remove
363 // null pointer remove
364 QVERIFY(!m_series->take(0));
364 QVERIFY(!m_series->take(0));
365
365
366 // take first
366 // take first
367 QVERIFY(m_series->take(slice1));
367 QVERIFY(m_series->take(slice1));
368 TRY_COMPARE(spy1.count(), 0);
368 TRY_COMPARE(spy1.count(), 0);
369 QVERIFY(slice1->parent() == m_series); // series is still the parent object
369 QVERIFY(slice1->parent() == m_series); // series is still the parent object
370 QVERIFY(!m_series->take(slice1));
370 QVERIFY(!m_series->take(slice1));
371 QCOMPARE(m_series->count(), 2);
371 QCOMPARE(m_series->count(), 2);
372 QCOMPARE(m_series->slices().at(0)->label(), slice2->label());
372 QCOMPARE(m_series->slices().at(0)->label(), slice2->label());
373 QCOMPARE(removedSpy.count(), 1);
373 QCOMPARE(removedSpy.count(), 1);
374 QList<QPieSlice*> removed = qvariant_cast<QList<QPieSlice*> >(removedSpy.at(0).at(0));
374 QList<QPieSlice*> removed = qvariant_cast<QList<QPieSlice*> >(removedSpy.at(0).at(0));
375 QCOMPARE(removed.count(), 1);
375 QCOMPARE(removed.count(), 1);
376 QCOMPARE(removed.first(), slice1);
376 QCOMPARE(removed.first(), slice1);
377 }
377 }
378
378
379 void tst_qpieseries::takeAnimated()
379 void tst_qpieseries::takeAnimated()
380 {
380 {
381 m_view->chart()->setAnimationOptions(QChart::AllAnimations);
381 m_view->chart()->setAnimationOptions(QChart::AllAnimations);
382 take();
382 take();
383 }
383 }
384
384
385 void tst_qpieseries::calculatedValues()
385 void tst_qpieseries::calculatedValues()
386 {
386 {
387 m_view->chart()->addSeries(m_series);
387 m_view->chart()->addSeries(m_series);
388
388
389 QPieSlice *slice1 = new QPieSlice("slice 1", 1);
389 QPieSlice *slice1 = new QPieSlice("slice 1", 1);
390 QSignalSpy percentageSpy(slice1, SIGNAL(percentageChanged()));
390 QSignalSpy percentageSpy(slice1, SIGNAL(percentageChanged()));
391 QSignalSpy startAngleSpy(slice1, SIGNAL(startAngleChanged()));
391 QSignalSpy startAngleSpy(slice1, SIGNAL(startAngleChanged()));
392 QSignalSpy angleSpanSpy(slice1, SIGNAL(angleSpanChanged()));
392 QSignalSpy angleSpanSpy(slice1, SIGNAL(angleSpanChanged()));
393
393
394 // add a slice
394 // add a slice
395 m_series->append(slice1);
395 m_series->append(slice1);
396 bool ok;
396 bool ok;
397 verifyCalculatedData(*m_series, &ok);
397 verifyCalculatedData(*m_series, &ok);
398 if (!ok)
398 if (!ok)
399 return;
399 return;
400 QCOMPARE(percentageSpy.count(), 1);
400 QCOMPARE(percentageSpy.count(), 1);
401 QCOMPARE(startAngleSpy.count(), 0);
401 QCOMPARE(startAngleSpy.count(), 0);
402 QCOMPARE(angleSpanSpy.count(), 1);
402 QCOMPARE(angleSpanSpy.count(), 1);
403
403
404 // add some more slices
404 // add some more slices
405 QList<QPieSlice *> list;
405 QList<QPieSlice *> list;
406 list << new QPieSlice("slice 2", 2);
406 list << new QPieSlice("slice 2", 2);
407 list << new QPieSlice("slice 3", 3);
407 list << new QPieSlice("slice 3", 3);
408 m_series->append(list);
408 m_series->append(list);
409 verifyCalculatedData(*m_series, &ok);
409 verifyCalculatedData(*m_series, &ok);
410 if (!ok)
410 if (!ok)
411 return;
411 return;
412 QCOMPARE(percentageSpy.count(), 2);
412 QCOMPARE(percentageSpy.count(), 2);
413 QCOMPARE(startAngleSpy.count(), 0);
413 QCOMPARE(startAngleSpy.count(), 0);
414 QCOMPARE(angleSpanSpy.count(), 2);
414 QCOMPARE(angleSpanSpy.count(), 2);
415
415
416 // remove a slice
416 // remove a slice
417 m_series->remove(list.first()); // remove slice 2
417 m_series->remove(list.first()); // remove slice 2
418 verifyCalculatedData(*m_series, &ok);
418 verifyCalculatedData(*m_series, &ok);
419 if (!ok)
419 if (!ok)
420 return;
420 return;
421 QCOMPARE(percentageSpy.count(), 3);
421 QCOMPARE(percentageSpy.count(), 3);
422 QCOMPARE(startAngleSpy.count(), 0);
422 QCOMPARE(startAngleSpy.count(), 0);
423 QCOMPARE(angleSpanSpy.count(), 3);
423 QCOMPARE(angleSpanSpy.count(), 3);
424
424
425 // insert a slice
425 // insert a slice
426 m_series->insert(0, new QPieSlice("Slice 4", 4));
426 m_series->insert(0, new QPieSlice("Slice 4", 4));
427 verifyCalculatedData(*m_series, &ok);
427 verifyCalculatedData(*m_series, &ok);
428 if (!ok)
428 if (!ok)
429 return;
429 return;
430 QCOMPARE(percentageSpy.count(), 4);
430 QCOMPARE(percentageSpy.count(), 4);
431 QCOMPARE(startAngleSpy.count(), 1);
431 QCOMPARE(startAngleSpy.count(), 1);
432 QCOMPARE(angleSpanSpy.count(), 4);
432 QCOMPARE(angleSpanSpy.count(), 4);
433
433
434 // modify pie angles
434 // modify pie angles
435 m_series->setPieStartAngle(-90);
435 m_series->setPieStartAngle(-90);
436 m_series->setPieEndAngle(90);
436 m_series->setPieEndAngle(90);
437 verifyCalculatedData(*m_series, &ok);
437 verifyCalculatedData(*m_series, &ok);
438 if (!ok)
438 if (!ok)
439 return;
439 return;
440 QCOMPARE(percentageSpy.count(), 4);
440 QCOMPARE(percentageSpy.count(), 4);
441 QCOMPARE(startAngleSpy.count(), 3);
441 QCOMPARE(startAngleSpy.count(), 3);
442 QCOMPARE(angleSpanSpy.count(), 6);
442 QCOMPARE(angleSpanSpy.count(), 6);
443
443
444 // clear all
444 // clear all
445 m_series->clear();
445 m_series->clear();
446 verifyCalculatedData(*m_series, &ok);
446 verifyCalculatedData(*m_series, &ok);
447 if (!ok)
447 if (!ok)
448 return;
448 return;
449 QCOMPARE(percentageSpy.count(), 4);
449 QCOMPARE(percentageSpy.count(), 4);
450 QCOMPARE(startAngleSpy.count(), 3);
450 QCOMPARE(startAngleSpy.count(), 3);
451 QCOMPARE(angleSpanSpy.count(), 6);
451 QCOMPARE(angleSpanSpy.count(), 6);
452 }
452 }
453
453
454 void tst_qpieseries::verifyCalculatedData(const QPieSeries &series, bool *ok)
454 void tst_qpieseries::verifyCalculatedData(const QPieSeries &series, bool *ok)
455 {
455 {
456 *ok = false;
456 *ok = false;
457
457
458 qreal sum = 0;
458 qreal sum = 0;
459 foreach (const QPieSlice *slice, series.slices())
459 foreach (const QPieSlice *slice, series.slices())
460 sum += slice->value();
460 sum += slice->value();
461 QCOMPARE(series.sum(), sum);
461 QCOMPARE(series.sum(), sum);
462
462
463 qreal startAngle = series.pieStartAngle();
463 qreal startAngle = series.pieStartAngle();
464 qreal pieAngleSpan = series.pieEndAngle() - series.pieStartAngle();
464 qreal pieAngleSpan = series.pieEndAngle() - series.pieStartAngle();
465 foreach (const QPieSlice *slice, series.slices()) {
465 foreach (const QPieSlice *slice, series.slices()) {
466 qreal ratio = slice->value() / sum;
466 qreal ratio = slice->value() / sum;
467 qreal sliceSpan = pieAngleSpan * ratio;
467 qreal sliceSpan = pieAngleSpan * ratio;
468 QCOMPARE(slice->startAngle(), startAngle);
468 QCOMPARE(slice->startAngle(), startAngle);
469 QCOMPARE(slice->angleSpan(), sliceSpan);
469 QCOMPARE(slice->angleSpan(), sliceSpan);
470 QCOMPARE(slice->percentage(), ratio);
470 QCOMPARE(slice->percentage(), ratio);
471 startAngle += sliceSpan;
471 startAngle += sliceSpan;
472 }
472 }
473
473
474 if (!series.isEmpty())
474 if (!series.isEmpty())
475 QCOMPARE(series.slices().last()->startAngle() + series.slices().last()->angleSpan(), series.pieEndAngle());
475 QCOMPARE(series.slices().last()->startAngle() + series.slices().last()->angleSpan(), series.pieEndAngle());
476
476
477 *ok = true;
477 *ok = true;
478 }
478 }
479
479
480
480
481 void tst_qpieseries::clickedSignal()
481 void tst_qpieseries::clickedSignal()
482 {
482 {
483 // add some slices
483 // add some slices
484 QPieSlice *s1 = m_series->append("slice 1", 1);
484 QPieSlice *s1 = m_series->append("slice 1", 1);
485 QPieSlice *s2 = m_series->append("slice 2", 1);
485 QPieSlice *s2 = m_series->append("slice 2", 1);
486 QPieSlice *s3 = m_series->append("slice 3", 1);
486 QPieSlice *s3 = m_series->append("slice 3", 1);
487 QPieSlice *s4 = m_series->append("slice 4", 1);
487 QPieSlice *s4 = m_series->append("slice 4", 1);
488 QSignalSpy clickSpy(m_series, SIGNAL(clicked(QPieSlice*)));
488 QSignalSpy clickSpy(m_series, SIGNAL(clicked(QPieSlice*)));
489
489
490 // add series to the chart
490 // add series to the chart
491 m_view->chart()->legend()->setVisible(false);
491 m_view->chart()->legend()->setVisible(false);
492 m_view->resize(200, 200);
492 m_view->resize(200, 200);
493 m_view->chart()->addSeries(m_series);
493 m_view->chart()->addSeries(m_series);
494 m_view->show();
494 m_view->show();
495 QTest::qWaitForWindowShown(m_view);
495 QTest::qWaitForWindowShown(m_view);
496
496
497 // if you devide the chart in four equal tiles these
497 // if you divide the chart in four equal tiles these
498 // are the center points of those tiles
498 // are the center points of those tiles
499 QPoint p1(90.25, 90);
499 QPoint p1(90.25, 90);
500 QPoint p2(150, 90);
500 QPoint p2(150, 90);
501 QPoint p3(90, 150);
501 QPoint p3(90, 150);
502 QPoint p4(150, 150);
502 QPoint p4(150, 150);
503
503
504 QPoint center(120, 120);
504 QPoint center(120, 120);
505
505
506 m_series->setPieSize(1.0);
506 m_series->setPieSize(1.0);
507 QTest::mouseClick(m_view->viewport(), Qt::LeftButton, 0, p1);
507 QTest::mouseClick(m_view->viewport(), Qt::LeftButton, 0, p1);
508 QTest::mouseClick(m_view->viewport(), Qt::LeftButton, 0, p2);
508 QTest::mouseClick(m_view->viewport(), Qt::LeftButton, 0, p2);
509 QTest::mouseClick(m_view->viewport(), Qt::LeftButton, 0, p3);
509 QTest::mouseClick(m_view->viewport(), Qt::LeftButton, 0, p3);
510 QTest::mouseClick(m_view->viewport(), Qt::LeftButton, 0, p4);
510 QTest::mouseClick(m_view->viewport(), Qt::LeftButton, 0, p4);
511 QTest::mouseClick(m_view->viewport(), Qt::LeftButton, 0, center);
511 QTest::mouseClick(m_view->viewport(), Qt::LeftButton, 0, center);
512 TRY_COMPARE(clickSpy.count(), 5); // all hit
512 TRY_COMPARE(clickSpy.count(), 5); // all hit
513 QCOMPARE(qvariant_cast<QPieSlice*>(clickSpy.at(0).at(0)), s4);
513 QCOMPARE(qvariant_cast<QPieSlice*>(clickSpy.at(0).at(0)), s4);
514 QCOMPARE(qvariant_cast<QPieSlice*>(clickSpy.at(1).at(0)), s1);
514 QCOMPARE(qvariant_cast<QPieSlice*>(clickSpy.at(1).at(0)), s1);
515 QCOMPARE(qvariant_cast<QPieSlice*>(clickSpy.at(2).at(0)), s3);
515 QCOMPARE(qvariant_cast<QPieSlice*>(clickSpy.at(2).at(0)), s3);
516 QCOMPARE(qvariant_cast<QPieSlice*>(clickSpy.at(3).at(0)), s2);
516 QCOMPARE(qvariant_cast<QPieSlice*>(clickSpy.at(3).at(0)), s2);
517 clickSpy.clear();
517 clickSpy.clear();
518
518
519 m_series->setPieSize(0.5);
519 m_series->setPieSize(0.5);
520 m_series->setVerticalPosition(0.25);
520 m_series->setVerticalPosition(0.25);
521 m_series->setHorizontalPosition(0.25);
521 m_series->setHorizontalPosition(0.25);
522 QTest::mouseClick(m_view->viewport(), Qt::LeftButton, 0, p1); // hits
522 QTest::mouseClick(m_view->viewport(), Qt::LeftButton, 0, p1); // hits
523 QTest::mouseClick(m_view->viewport(), Qt::LeftButton, 0, p2);
523 QTest::mouseClick(m_view->viewport(), Qt::LeftButton, 0, p2);
524 QTest::mouseClick(m_view->viewport(), Qt::LeftButton, 0, p3);
524 QTest::mouseClick(m_view->viewport(), Qt::LeftButton, 0, p3);
525 QTest::mouseClick(m_view->viewport(), Qt::LeftButton, 0, p4);
525 QTest::mouseClick(m_view->viewport(), Qt::LeftButton, 0, p4);
526 QTest::mouseClick(m_view->viewport(), Qt::LeftButton, 0, center);
526 QTest::mouseClick(m_view->viewport(), Qt::LeftButton, 0, center);
527 TRY_COMPARE(clickSpy.count(), 1);
527 TRY_COMPARE(clickSpy.count(), 1);
528 clickSpy.clear();
528 clickSpy.clear();
529
529
530 m_series->setVerticalPosition(0.25);
530 m_series->setVerticalPosition(0.25);
531 m_series->setHorizontalPosition(0.75);
531 m_series->setHorizontalPosition(0.75);
532 QTest::mouseClick(m_view->viewport(), Qt::LeftButton, 0, p1);
532 QTest::mouseClick(m_view->viewport(), Qt::LeftButton, 0, p1);
533 QTest::mouseClick(m_view->viewport(), Qt::LeftButton, 0, p2); // hits
533 QTest::mouseClick(m_view->viewport(), Qt::LeftButton, 0, p2); // hits
534 QTest::mouseClick(m_view->viewport(), Qt::LeftButton, 0, p3);
534 QTest::mouseClick(m_view->viewport(), Qt::LeftButton, 0, p3);
535 QTest::mouseClick(m_view->viewport(), Qt::LeftButton, 0, p4);
535 QTest::mouseClick(m_view->viewport(), Qt::LeftButton, 0, p4);
536 QTest::mouseClick(m_view->viewport(), Qt::LeftButton, 0, center);
536 QTest::mouseClick(m_view->viewport(), Qt::LeftButton, 0, center);
537 TRY_COMPARE(clickSpy.count(), 1);
537 TRY_COMPARE(clickSpy.count(), 1);
538 clickSpy.clear();
538 clickSpy.clear();
539
539
540 m_series->setVerticalPosition(0.75);
540 m_series->setVerticalPosition(0.75);
541 m_series->setHorizontalPosition(0.25);
541 m_series->setHorizontalPosition(0.25);
542 QTest::mouseClick(m_view->viewport(), Qt::LeftButton, 0, p1);
542 QTest::mouseClick(m_view->viewport(), Qt::LeftButton, 0, p1);
543 QTest::mouseClick(m_view->viewport(), Qt::LeftButton, 0, p2);
543 QTest::mouseClick(m_view->viewport(), Qt::LeftButton, 0, p2);
544 QTest::mouseClick(m_view->viewport(), Qt::LeftButton, 0, p3); // hits
544 QTest::mouseClick(m_view->viewport(), Qt::LeftButton, 0, p3); // hits
545 QTest::mouseClick(m_view->viewport(), Qt::LeftButton, 0, p4);
545 QTest::mouseClick(m_view->viewport(), Qt::LeftButton, 0, p4);
546 QTest::mouseClick(m_view->viewport(), Qt::LeftButton, 0, center);
546 QTest::mouseClick(m_view->viewport(), Qt::LeftButton, 0, center);
547 TRY_COMPARE(clickSpy.count(), 1);
547 TRY_COMPARE(clickSpy.count(), 1);
548 clickSpy.clear();
548 clickSpy.clear();
549
549
550 m_series->setVerticalPosition(0.75);
550 m_series->setVerticalPosition(0.75);
551 m_series->setHorizontalPosition(0.75);
551 m_series->setHorizontalPosition(0.75);
552 QTest::mouseClick(m_view->viewport(), Qt::LeftButton, 0, p1);
552 QTest::mouseClick(m_view->viewport(), Qt::LeftButton, 0, p1);
553 QTest::mouseClick(m_view->viewport(), Qt::LeftButton, 0, p2);
553 QTest::mouseClick(m_view->viewport(), Qt::LeftButton, 0, p2);
554 QTest::mouseClick(m_view->viewport(), Qt::LeftButton, 0, p3);
554 QTest::mouseClick(m_view->viewport(), Qt::LeftButton, 0, p3);
555 QTest::mouseClick(m_view->viewport(), Qt::LeftButton, 0, p4); // hits
555 QTest::mouseClick(m_view->viewport(), Qt::LeftButton, 0, p4); // hits
556 QTest::mouseClick(m_view->viewport(), Qt::LeftButton, 0, center);
556 QTest::mouseClick(m_view->viewport(), Qt::LeftButton, 0, center);
557 TRY_COMPARE(clickSpy.count(), 1);
557 TRY_COMPARE(clickSpy.count(), 1);
558 clickSpy.clear();
558 clickSpy.clear();
559 }
559 }
560
560
561 void tst_qpieseries::hoverSignal()
561 void tst_qpieseries::hoverSignal()
562 {
562 {
563 // add some slices
563 // add some slices
564 m_series->setPieSize(1.0);
564 m_series->setPieSize(1.0);
565 QPieSlice *s1 = m_series->append("slice 1", 1);
565 QPieSlice *s1 = m_series->append("slice 1", 1);
566 m_series->append("slice 2", 2);
566 m_series->append("slice 2", 2);
567 m_series->append("slice 3", 3);
567 m_series->append("slice 3", 3);
568
568
569 // add series to the chart
569 // add series to the chart
570 m_view->chart()->legend()->setVisible(false);
570 m_view->chart()->legend()->setVisible(false);
571 m_view->resize(200, 200);
571 m_view->resize(200, 200);
572 m_view->chart()->addSeries(m_series);
572 m_view->chart()->addSeries(m_series);
573 m_view->show();
573 m_view->show();
574 QTest::qWaitForWindowShown(m_view);
574 QTest::qWaitForWindowShown(m_view);
575
575
576 // first move to right top corner
576 // first move to right top corner
577 QTest::mouseMove(m_view->viewport(), QPoint(200, 0));
577 QTest::mouseMove(m_view->viewport(), QPoint(200, 0));
578 QCoreApplication::processEvents(QEventLoop::AllEvents, 1000);
578 QCoreApplication::processEvents(QEventLoop::AllEvents, 1000);
579
579
580 // move inside the slice
580 // move inside the slice
581 // pie rectangle: QRectF(60,60 121x121)
581 // pie rectangle: QRectF(60,60 121x121)
582 QSignalSpy hoverSpy(m_series, SIGNAL(hovered(QPieSlice*,bool)));
582 QSignalSpy hoverSpy(m_series, SIGNAL(hovered(QPieSlice*,bool)));
583 QTest::mouseMove(m_view->viewport(), QPoint(139, 85));
583 QTest::mouseMove(m_view->viewport(), QPoint(139, 85));
584 TRY_COMPARE(hoverSpy.count(), 1);
584 TRY_COMPARE(hoverSpy.count(), 1);
585 QCOMPARE(qvariant_cast<QPieSlice*>(hoverSpy.at(0).at(0)), s1);
585 QCOMPARE(qvariant_cast<QPieSlice*>(hoverSpy.at(0).at(0)), s1);
586 QCOMPARE(qvariant_cast<bool>(hoverSpy.at(0).at(1)), true);
586 QCOMPARE(qvariant_cast<bool>(hoverSpy.at(0).at(1)), true);
587
587
588 // move outside the slice
588 // move outside the slice
589 QTest::mouseMove(m_view->viewport(), QPoint(200, 0));
589 QTest::mouseMove(m_view->viewport(), QPoint(200, 0));
590 TRY_COMPARE(hoverSpy.count(), 2);
590 TRY_COMPARE(hoverSpy.count(), 2);
591 QCOMPARE(qvariant_cast<QPieSlice*>(hoverSpy.at(1).at(0)), s1);
591 QCOMPARE(qvariant_cast<QPieSlice*>(hoverSpy.at(1).at(0)), s1);
592 QCOMPARE(qvariant_cast<bool>(hoverSpy.at(1).at(1)), false);
592 QCOMPARE(qvariant_cast<bool>(hoverSpy.at(1).at(1)), false);
593 }
593 }
594
594
595 void tst_qpieseries::sliceSeries()
595 void tst_qpieseries::sliceSeries()
596 {
596 {
597 QPieSlice *slice = new QPieSlice();
597 QPieSlice *slice = new QPieSlice();
598 QVERIFY(!slice->series());
598 QVERIFY(!slice->series());
599 delete slice;
599 delete slice;
600
600
601 slice = new QPieSlice(m_series);
601 slice = new QPieSlice(m_series);
602 QVERIFY(!slice->series());
602 QVERIFY(!slice->series());
603
603
604 m_series->append(slice);
604 m_series->append(slice);
605 QCOMPARE(slice->series(), m_series);
605 QCOMPARE(slice->series(), m_series);
606
606
607 slice = new QPieSlice();
607 slice = new QPieSlice();
608 m_series->insert(0, slice);
608 m_series->insert(0, slice);
609 QCOMPARE(slice->series(), m_series);
609 QCOMPARE(slice->series(), m_series);
610
610
611 m_series->take(slice);
611 m_series->take(slice);
612 QCOMPARE(slice->series(), (QPieSeries*) 0);
612 QCOMPARE(slice->series(), (QPieSeries*) 0);
613 }
613 }
614
614
615 void tst_qpieseries::destruction()
615 void tst_qpieseries::destruction()
616 {
616 {
617 // add some slices
617 // add some slices
618 QPieSlice *slice1 = m_series->append("slice 1", 1);
618 QPieSlice *slice1 = m_series->append("slice 1", 1);
619 QPieSlice *slice2 = m_series->append("slice 2", 2);
619 QPieSlice *slice2 = m_series->append("slice 2", 2);
620 QPieSlice *slice3 = m_series->append("slice 3", 3);
620 QPieSlice *slice3 = m_series->append("slice 3", 3);
621 QSignalSpy spy1(slice1, SIGNAL(destroyed()));
621 QSignalSpy spy1(slice1, SIGNAL(destroyed()));
622 QSignalSpy spy2(slice2, SIGNAL(destroyed()));
622 QSignalSpy spy2(slice2, SIGNAL(destroyed()));
623 QSignalSpy spy3(slice3, SIGNAL(destroyed()));
623 QSignalSpy spy3(slice3, SIGNAL(destroyed()));
624
624
625 // destroy series
625 // destroy series
626 delete m_series;
626 delete m_series;
627 m_series = 0;
627 m_series = 0;
628
628
629 // check that series has destroyed its slices
629 // check that series has destroyed its slices
630 QCOMPARE(spy1.count(), 1);
630 QCOMPARE(spy1.count(), 1);
631 QCOMPARE(spy2.count(), 1);
631 QCOMPARE(spy2.count(), 1);
632 QCOMPARE(spy3.count(), 1);
632 QCOMPARE(spy3.count(), 1);
633 }
633 }
634
634
635 QTEST_MAIN(tst_qpieseries)
635 QTEST_MAIN(tst_qpieseries)
636
636
637 #include "tst_qpieseries.moc"
637 #include "tst_qpieseries.moc"
638
638
General Comments 0
You need to be logged in to leave comments. Login now