##// END OF EJS Templates
Documentation of QML ChartView, Axis and Legend
Tero Ahola -
r1475:b687c49332c3
parent child
Show More
@@ -1,56 +1,58
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 import QtQuick 1.0
21 import QtQuick 1.0
22 import QtCommercial.Chart 1.0
22 import QtCommercial.Chart 1.0
23
23
24 Rectangle {
24 Rectangle {
25 anchors.fill: parent
25 anchors.fill: parent
26
26
27 //![1]
27 //![1]
28 ChartView {
28 ChartView {
29 title: "Scatters"
29 title: "Scatters"
30 anchors.fill: parent
30 anchors.fill: parent
31
31
32 ScatterSeries {
32 ScatterSeries {
33 id: scatter1
33 id: scatter1
34 name: "Scatter1"
34 name: "Scatter1"
35 XyPoint { x: 1.5; y: 1.5 }
35 XyPoint { x: 1.5; y: 1.5 }
36 XyPoint { x: 1.5; y: 1.6 }
36 XyPoint { x: 1.5; y: 1.6 }
37 XyPoint { x: 1.57; y: 1.55 }
37 XyPoint { x: 1.57; y: 1.55 }
38 XyPoint { x: 1.8; y: 1.8 }
38 XyPoint { x: 1.8; y: 1.8 }
39 XyPoint { x: 1.9; y: 1.6 }
39 XyPoint { x: 1.9; y: 1.6 }
40 XyPoint { x: 2.1; y: 1.3 }
40 XyPoint { x: 2.1; y: 1.3 }
41 XyPoint { x: 2.5; y: 2.1 }
41 XyPoint { x: 2.5; y: 2.1 }
42 }
42 }
43
43
44 ScatterSeries {
44 ScatterSeries {
45 name: "Scatter2"
45 name: "Scatter2"
46 // ...
46 // ...
47 //![1]
47 //![1]
48 XyPoint { x: 2.0; y: 2.0 }
48 XyPoint { x: 2.0; y: 2.0 }
49 XyPoint { x: 2.0; y: 2.1 }
49 XyPoint { x: 2.0; y: 2.1 }
50 XyPoint { x: 2.07; y: 2.05 }
50 XyPoint { x: 2.07; y: 2.05 }
51 XyPoint { x: 2.2; y: 2.9 }
51 XyPoint { x: 2.2; y: 2.9 }
52 XyPoint { x: 2.4; y: 2.7 }
52 XyPoint { x: 2.4; y: 2.7 }
53 XyPoint { x: 2.67; y: 2.65 }
53 XyPoint { x: 2.67; y: 2.65 }
54 //![2]
54 }
55 }
55 }
56 }
57 //![2]
56 }
58 }
@@ -1,88 +1,90
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 import QtQuick 1.0
21 import QtQuick 1.0
22 import QtCommercial.Chart 1.0
22 import QtCommercial.Chart 1.0
23
23
24 Rectangle {
24 Rectangle {
25 width: parent.width
25 width: parent.width
26 height: parent.height
26 height: parent.height
27 property int viewNumber: 1
27 property int viewNumber: 1
28
28
29 Loader {
29 Loader {
30 id: loader
30 id: loader
31 anchors.top: parent.top
31 anchors.fill: parent
32 anchors.bottom: buttons.top
33 anchors.left: parent.left
34 anchors.right: parent.right
35 source: "View" + viewNumber + ".qml";
32 source: "View" + viewNumber + ".qml";
36 }
33 }
37
34
38 Row {
35 Rectangle {
39 id: buttons
36 id: infoText
40 anchors.bottom: parent.bottom
37 anchors.centerIn: parent
41 anchors.bottomMargin: 15
38 width: parent.width
42 anchors.horizontalCenter: parent.horizontalCenter
39 height: 40
43 spacing: 5
40 color: "black"
41 Text {
42 color: "white"
43 anchors.centerIn: parent
44 text: "Use left and right arrow keys to navigate between chart types"
45 }
44
46
45 Rectangle {
47 Behavior on opacity {
46 height: 35
48 NumberAnimation { duration: 400 }
47 width: 60
48 border.color: "#c8955c"
49 border.width: 2
50 radius: 5
51 Text {
52 anchors.centerIn: parent
53 text: "<"
54 }
55 MouseArea {
56 anchors.fill: parent
57 onClicked: {
58 var i = viewNumber - 1;
59 if (i <= 0)
60 viewNumber = 9;
61 else
62 viewNumber = i;
63 }
64 }
65 }
49 }
66 Rectangle {
50 }
67 height: 35
51
68 width: 60
52 MouseArea {
69 border.color: "#c8955c"
53 focus: true
70 border.width: 2
54 anchors.fill: parent
71 radius: 5
55 onClicked: {
72 Text {
56 if (infoText.opacity > 0) {
73 anchors.centerIn: parent
57 infoText.opacity = 0.0;
74 text: ">"
58 } else {
59 nextView();
75 }
60 }
76 MouseArea {
61 }
77 anchors.fill: parent
62 Keys.onPressed: {
78 onClicked: {
63 if (infoText.opacity > 0) {
79 var i = viewNumber + 1;
64 infoText.opacity = 0.0;
80 if (i > 9)
65 } else {
81 viewNumber = 1;
66 if (event.key == Qt.Key_Left) {
82 else
67 previousView();
83 viewNumber = i;
68 } else {
69 nextView();
84 }
70 }
85 }
71 }
86 }
72 }
87 }
73 }
74
75 function nextView() {
76 var i = viewNumber + 1;
77 if (i > 9)
78 viewNumber = 1;
79 else
80 viewNumber = i;
81 }
82
83 function previousView() {
84 var i = viewNumber - 1;
85 if (i <= 0)
86 viewNumber = 9;
87 else
88 viewNumber = i;
89 }
88 }
90 }
1 NO CONTENT: modified file, binary diff hidden
NO CONTENT: modified file, binary diff hidden
1 NO CONTENT: modified file, binary diff hidden
NO CONTENT: modified file, binary diff hidden
1 NO CONTENT: modified file, binary diff hidden
NO CONTENT: modified file, binary diff hidden
1 NO CONTENT: modified file, binary diff hidden
NO CONTENT: modified file, binary diff hidden
1 NO CONTENT: modified file, binary diff hidden
NO CONTENT: modified file, binary diff hidden
1 NO CONTENT: modified file, binary diff hidden
NO CONTENT: modified file, binary diff hidden
1 NO CONTENT: modified file, binary diff hidden
NO CONTENT: modified file, binary diff hidden
1 NO CONTENT: modified file, binary diff hidden
NO CONTENT: modified file, binary diff hidden
1 NO CONTENT: modified file, binary diff hidden
NO CONTENT: modified file, binary diff hidden
@@ -1,76 +1,76
1 /*!
1 /*!
2 \page qml.html
2 \page qml.html
3 \title QtCommercial Charts QML API
3 \title QtCommercial Charts QML API
4 \keyword Charts QML API
4 \keyword Charts QML API
5
5
6 QtCommercial Charts QML API is an intuitive and simple way to show charts in your QML
6 QtCommercial Charts QML API is an intuitive and simple way to show charts in your QML
7 applications. The following example QML shows you how to create a simple pie chart:
7 applications. The following QML shows you to create a simple pie chart:
8 \snippet ../examples/qmlpiechart/qml/qmlpiechart/main.qml 1
8 \snippet ../examples/qmlpiechart/qml/qmlpiechart/main.qml 1
9 \snippet ../examples/qmlpiechart/qml/qmlpiechart/main.qml 2
9 \snippet ../examples/qmlpiechart/qml/qmlpiechart/main.qml 2
10 \snippet ../examples/qmlpiechart/qml/qmlpiechart/main.qml 3
10 \snippet ../examples/qmlpiechart/qml/qmlpiechart/main.qml 3
11
11
12 \beginfloatleft
12 \beginfloatleft
13 \image examples_qmlpiechart.png
13 \image examples_qmlpiechart.png
14 \endfloat
14 \endfloat
15 \clearfloat
15 \clearfloat
16
16
17 \raw HTML
17 \raw HTML
18 <table cellpadding="2" cellspacing="1" border="0" width="95%" class="indextable">
18 <table cellpadding="2" cellspacing="1" border="0" width="95%" class="indextable">
19 <tr>
19 <tr>
20 <th class="titleheader" width="25%"> ChartView and it's properties </th>
20 <th class="titleheader" width="25%"> ChartView and it's properties </th>
21 </tr>
21 </tr>
22 <tr>
22 <tr>
23 <td valign="top">
23 <td valign="top">
24 <ul>
24 <ul>
25 <li><a href="qml-chartview.html">ChartView</a></li>
25 <li><a href="qml-chartview.html">ChartView</a></li>
26 <li><a href="qml-axis.html">Axis</a></li>
26 <li><a href="qml-axis.html">Axis</a></li>
27 <li><a href="qml-legend.html">Legend</a></li>
27 <li><a href="qml-legend.html">Legend</a></li>
28 </ul>
28 </ul>
29 </td>
29 </td>
30 </tr>
30 </tr>
31 </table>
31 </table>
32 <table cellpadding="2" cellspacing="1" border="0" width="95%" class="indextable">
32 <table cellpadding="2" cellspacing="1" border="0" width="95%" class="indextable">
33 <tr>
33 <tr>
34 <th class="titleheader" width="25%"> XY chart </th>
34 <th class="titleheader" width="25%"> XY chart </th>
35 </tr>
35 </tr>
36 <tr>
36 <tr>
37 <td valign="top">
37 <td valign="top">
38 <ul>
38 <ul>
39 <li><a href="qml-lineseries.html">LineSeries</a></li>
39 <li><a href="qml-lineseries.html">LineSeries</a></li>
40 <li><a href="qml-areaseries.html">AreaSeries</a></li>
40 <li><a href="qml-areaseries.html">AreaSeries</a></li>
41 <li><a href="qml-scatterseries.html">ScatterSeries</a></li>
41 <li><a href="qml-scatterseries.html">ScatterSeries</a></li>
42 <li><a href="qml-splineseries.html">SplineSeries</a></li>
42 <li><a href="qml-splineseries.html">SplineSeries</a></li>
43 <li><a href="qml-xypoint.html">XyPoint</a></li>
43 <li><a href="qml-xypoint.html">XyPoint</a></li>
44 </ul>
44 </ul>
45 </td>
45 </td>
46 </tr>
46 </tr>
47 </table>
47 </table>
48 <table cellpadding="2" cellspacing="1" border="0" width="95%" class="indextable">
48 <table cellpadding="2" cellspacing="1" border="0" width="95%" class="indextable">
49 <tr>
49 <tr>
50 <th class="titleheader" width="25%"> Pie chart </th>
50 <th class="titleheader" width="25%"> Pie chart </th>
51 <tr>
51 <tr>
52 <td valign="top">
52 <td valign="top">
53 <ul>
53 <ul>
54 <li><a href="qml-pieseries.html">PieSeries</a></li>
54 <li><a href="qml-pieseries.html">PieSeries</a></li>
55 <li><a href="qml-pieslice.html">PieSlice</a></li>
55 <li><a href="qml-pieslice.html">PieSlice</a></li>
56 </ul>
56 </ul>
57 </td>
57 </td>
58 </tr>
58 </tr>
59 </table>
59 </table>
60 <table cellpadding="2" cellspacing="1" border="0" width="95%" class="indextable">
60 <table cellpadding="2" cellspacing="1" border="0" width="95%" class="indextable">
61 <tr>
61 <tr>
62 <th class="titleheader" width="25%"> Bar chart </th>
62 <th class="titleheader" width="25%"> Bar chart </th>
63 <tr>
63 <tr>
64 <td valign="top">
64 <td valign="top">
65 <ul>
65 <ul>
66 <li><a href="qml-barseries.html">BarSeries</a></li>
66 <li><a href="qml-barseries.html">BarSeries</a></li>
67 <li><a href="qml-groupedbarseries.html">GroupedBarSeries</a></li>
67 <li><a href="qml-groupedbarseries.html">GroupedBarSeries</a></li>
68 <li><a href="qml-stackedbarseries.html">StackedBarSeries</a></li>
68 <li><a href="qml-stackedbarseries.html">StackedBarSeries</a></li>
69 <li><a href="qml-percentbarseries.html">PercentBarSeries</a></li>
69 <li><a href="qml-percentbarseries.html">PercentBarSeries</a></li>
70 <li><a href="qml-barset.html">BarSet</a></li>
70 <li><a href="qml-barset.html">BarSet</a></li>
71 </ul>
71 </ul>
72 </td>
72 </td>
73 </tr>
73 </tr>
74 </table>
74 </table>
75 \endraw
75 \endraw
76 */
76 */
@@ -1,378 +1,379
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 "declarativechart.h"
21 #include "declarativechart.h"
22 #include <QPainter>
22 #include <QPainter>
23 #include "declarativelineseries.h"
23 #include "declarativelineseries.h"
24 #include "declarativeareaseries.h"
24 #include "declarativeareaseries.h"
25 #include "declarativebarseries.h"
25 #include "declarativebarseries.h"
26 #include "declarativepieseries.h"
26 #include "declarativepieseries.h"
27 #include "declarativesplineseries.h"
27 #include "declarativesplineseries.h"
28 #include "declarativescatterseries.h"
28 #include "declarativescatterseries.h"
29
29
30 QTCOMMERCIALCHART_BEGIN_NAMESPACE
30 QTCOMMERCIALCHART_BEGIN_NAMESPACE
31
31
32 /*!
32 /*!
33 \qmlclass ChartView DeclarativeChart
33 \qmlclass ChartView DeclarativeChart
34
34
35 ChartView element is the parent that is responsible for showing different chart series types.
35 ChartView element is the parent that is responsible for showing different chart series types.
36
36
37 \section1 Example Usage
37 The following QML shows how to create a simple line chart:
38 \snippet ../demos/qmlchart/qml/qmlchart/View2.qml 1
38
39
39 \beginfloatleft
40 \beginfloatleft
40 \image demos_qmlchart1.png
41 \image demos_qmlchart2.png
41 \endfloat
42 \endfloat
42 \clearfloat
43 \clearfloat
43 */
44 */
44
45
45 /*!
46 /*!
46 \qmlproperty Theme ChartView::theme
47 \qmlproperty Theme ChartView::theme
47 Theme defines the visual appearance of the chart, including for example colors, fonts, line
48 Theme defines the visual appearance of the chart, including for example colors, fonts, line
48 widths and chart background.
49 widths and chart background.
49 */
50 */
50
51
51 /*!
52 /*!
52 \qmlproperty Animation ChartView::animation
53 \qmlproperty Animation ChartView::animation
53 Animation configuration of the chart. One of ChartView.NoAnimation, ChartView.GridAxisAnimations,
54 Animation configuration of the chart. One of ChartView.NoAnimation, ChartView.GridAxisAnimations,
54 ChartView.SeriesAnimations or ChartView.AllAnimations.
55 ChartView.SeriesAnimations or ChartView.AllAnimations.
55 */
56 */
56
57
57 /*!
58 /*!
58 \qmlproperty string ChartView::title
59 \qmlproperty string ChartView::title
59 The title of the chart, shown on top of the chart.
60 The title of the chart, shown on top of the chart.
60 \sa ChartView::titleColor
61 \sa ChartView::titleColor
61 */
62 */
62
63
63 /*!
64 /*!
64 \qmlproperty string ChartView::titleColor
65 \qmlproperty string ChartView::titleColor
65 The color of the title text.
66 The color of the title text.
66 */
67 */
67
68
68 /*!
69 /*!
69 \qmlproperty Axis ChartView::axisX
70 \qmlproperty Axis ChartView::axisX
70 The x-axis of the chart.
71 The x-axis of the chart.
71 */
72 */
72
73
73 /*!
74 /*!
74 \qmlproperty Axis ChartView::axisY
75 \qmlproperty Axis ChartView::axisY
75 The default y-axis of the chart.
76 The default y-axis of the chart.
76 */
77 */
77
78
78 /*!
79 /*!
79 \qmlproperty Legend ChartView::legend
80 \qmlproperty Legend ChartView::legend
80 The legend of the chart. Legend lists all the series, pie slices and bar sets added on the chart.
81 The legend of the chart. Legend lists all the series, pie slices and bar sets added on the chart.
81 */
82 */
82
83
83 /*!
84 /*!
84 \qmlproperty int ChartView::count
85 \qmlproperty int ChartView::count
85 The count of series added to the chart.
86 The count of series added to the chart.
86 */
87 */
87
88
88 /*!
89 /*!
89 \qmlproperty color ChartView::backgroundColor
90 \qmlproperty color ChartView::backgroundColor
90 The color of the chart's background. By default background color is defined by chart theme.
91 The color of the chart's background. By default background color is defined by chart theme.
91 \sa ChartView::theme
92 \sa ChartView::theme
92 */
93 */
93
94
94 /*!
95 /*!
95 \qmlproperty bool ChartView::dropShadowEnabled
96 \qmlproperty bool ChartView::dropShadowEnabled
96 The chart's border drop shadow. Set to true to enable drop shadow.
97 The chart's border drop shadow. Set to true to enable drop shadow.
97 */
98 */
98
99
99 /*!
100 /*!
100 \qmlmethod Axis ChartView::axisY(QAbstractSeries *series)
101 \qmlmethod Axis ChartView::axisY(QAbstractSeries *series)
101 The y-axis of the series. This is the same as the default y-axis of the chart, unless you have
102 The y-axis of the series. This is the same as the default y-axis of the chart, unless you have
102 explicitly defined the series to have a non-default y-axis.
103 explicitly defined the series to have a non-default y-axis.
103 */
104 */
104
105
105 DeclarativeChart::DeclarativeChart(QDeclarativeItem *parent)
106 DeclarativeChart::DeclarativeChart(QDeclarativeItem *parent)
106 : QDeclarativeItem(parent),
107 : QDeclarativeItem(parent),
107 m_chart(new QChart(this))
108 m_chart(new QChart(this))
108 {
109 {
109 setFlag(QGraphicsItem::ItemHasNoContents, false);
110 setFlag(QGraphicsItem::ItemHasNoContents, false);
110 // m_chart->axisX()->setNiceNumbersEnabled(false);
111 // m_chart->axisX()->setNiceNumbersEnabled(false);
111 }
112 }
112
113
113 DeclarativeChart::~DeclarativeChart()
114 DeclarativeChart::~DeclarativeChart()
114 {
115 {
115 delete m_chart;
116 delete m_chart;
116 }
117 }
117
118
118 void DeclarativeChart::childEvent(QChildEvent *event)
119 void DeclarativeChart::childEvent(QChildEvent *event)
119 {
120 {
120 if (event->type() == QEvent::ChildAdded) {
121 if (event->type() == QEvent::ChildAdded) {
121 if (qobject_cast<QAbstractSeries *>(event->child())) {
122 if (qobject_cast<QAbstractSeries *>(event->child())) {
122 m_chart->addSeries(qobject_cast<QAbstractSeries *>(event->child()));
123 m_chart->addSeries(qobject_cast<QAbstractSeries *>(event->child()));
123 }
124 }
124 }
125 }
125 }
126 }
126
127
127 void DeclarativeChart::componentComplete()
128 void DeclarativeChart::componentComplete()
128 {
129 {
129 foreach(QObject *child, children()) {
130 foreach(QObject *child, children()) {
130 if (qobject_cast<QAbstractSeries *>(child)) {
131 if (qobject_cast<QAbstractSeries *>(child)) {
131 // qDebug() << "DeclarativeChart::componentComplete(), add: " << child;
132 // qDebug() << "DeclarativeChart::componentComplete(), add: " << child;
132 // TODO: how about optional y-axis?
133 // TODO: how about optional y-axis?
133 m_chart->addSeries(qobject_cast<QAbstractSeries *>(child));
134 m_chart->addSeries(qobject_cast<QAbstractSeries *>(child));
134 }
135 }
135 }
136 }
136 QDeclarativeItem::componentComplete();
137 QDeclarativeItem::componentComplete();
137 }
138 }
138
139
139 void DeclarativeChart::geometryChanged(const QRectF &newGeometry, const QRectF &oldGeometry)
140 void DeclarativeChart::geometryChanged(const QRectF &newGeometry, const QRectF &oldGeometry)
140 {
141 {
141 // qDebug() << "DeclarativeChart::geometryChanged" << newGeometry.width() << newGeometry.height();
142 // qDebug() << "DeclarativeChart::geometryChanged" << newGeometry.width() << newGeometry.height();
142 if (newGeometry.isValid()) {
143 if (newGeometry.isValid()) {
143 if (newGeometry.width() > 0 && newGeometry.height() > 0) {
144 if (newGeometry.width() > 0 && newGeometry.height() > 0) {
144 m_chart->resize(newGeometry.width(), newGeometry.height());
145 m_chart->resize(newGeometry.width(), newGeometry.height());
145 }
146 }
146 }
147 }
147 QDeclarativeItem::geometryChanged(newGeometry, oldGeometry);
148 QDeclarativeItem::geometryChanged(newGeometry, oldGeometry);
148 }
149 }
149
150
150 void DeclarativeChart::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget)
151 void DeclarativeChart::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget)
151 {
152 {
152 Q_UNUSED(option)
153 Q_UNUSED(option)
153 Q_UNUSED(widget)
154 Q_UNUSED(widget)
154
155
155 // TODO: optimized?
156 // TODO: optimized?
156 painter->setRenderHint(QPainter::Antialiasing, true);
157 painter->setRenderHint(QPainter::Antialiasing, true);
157 }
158 }
158
159
159 void DeclarativeChart::setTheme(DeclarativeChart::Theme theme)
160 void DeclarativeChart::setTheme(DeclarativeChart::Theme theme)
160 {
161 {
161 QChart::ChartTheme chartTheme = (QChart::ChartTheme) theme;
162 QChart::ChartTheme chartTheme = (QChart::ChartTheme) theme;
162 if (chartTheme != m_chart->theme()) {
163 if (chartTheme != m_chart->theme()) {
163 m_chart->setTheme(chartTheme);
164 m_chart->setTheme(chartTheme);
164 themeChanged();
165 themeChanged();
165 }
166 }
166 }
167 }
167
168
168 DeclarativeChart::Theme DeclarativeChart::theme()
169 DeclarativeChart::Theme DeclarativeChart::theme()
169 {
170 {
170 return (DeclarativeChart::Theme) m_chart->theme();
171 return (DeclarativeChart::Theme) m_chart->theme();
171 }
172 }
172
173
173 void DeclarativeChart::setAnimationOptions(DeclarativeChart::Animation animations)
174 void DeclarativeChart::setAnimationOptions(DeclarativeChart::Animation animations)
174 {
175 {
175 QChart::AnimationOption animationOptions = (QChart::AnimationOption) animations;
176 QChart::AnimationOption animationOptions = (QChart::AnimationOption) animations;
176 if (animationOptions != m_chart->animationOptions()) {
177 if (animationOptions != m_chart->animationOptions()) {
177 m_chart->setAnimationOptions(animationOptions);
178 m_chart->setAnimationOptions(animationOptions);
178 animationOptionsChanged();
179 animationOptionsChanged();
179 }
180 }
180 }
181 }
181
182
182 DeclarativeChart::Animation DeclarativeChart::animationOptions()
183 DeclarativeChart::Animation DeclarativeChart::animationOptions()
183 {
184 {
184 if (m_chart->animationOptions().testFlag(QChart::AllAnimations))
185 if (m_chart->animationOptions().testFlag(QChart::AllAnimations))
185 return DeclarativeChart::AllAnimations;
186 return DeclarativeChart::AllAnimations;
186 else if (m_chart->animationOptions().testFlag(QChart::GridAxisAnimations))
187 else if (m_chart->animationOptions().testFlag(QChart::GridAxisAnimations))
187 return DeclarativeChart::GridAxisAnimations;
188 return DeclarativeChart::GridAxisAnimations;
188 else if (m_chart->animationOptions().testFlag(QChart::SeriesAnimations))
189 else if (m_chart->animationOptions().testFlag(QChart::SeriesAnimations))
189 return DeclarativeChart::SeriesAnimations;
190 return DeclarativeChart::SeriesAnimations;
190 else
191 else
191 return DeclarativeChart::NoAnimation;
192 return DeclarativeChart::NoAnimation;
192 }
193 }
193
194
194 void DeclarativeChart::setTitle(QString title)
195 void DeclarativeChart::setTitle(QString title)
195 {
196 {
196 if (title != m_chart->title()) {
197 if (title != m_chart->title()) {
197 m_chart->setTitle(title);
198 m_chart->setTitle(title);
198 emit titleChanged();
199 emit titleChanged();
199 }
200 }
200 }
201 }
201 QString DeclarativeChart::title()
202 QString DeclarativeChart::title()
202 {
203 {
203 return m_chart->title();
204 return m_chart->title();
204 }
205 }
205
206
206 QAxis *DeclarativeChart::axisX()
207 QAxis *DeclarativeChart::axisX()
207 {
208 {
208 return m_chart->axisX();
209 return m_chart->axisX();
209 }
210 }
210
211
211 QAxis *DeclarativeChart::axisY(QAbstractSeries *series)
212 QAxis *DeclarativeChart::axisY(QAbstractSeries *series)
212 {
213 {
213 return m_chart->axisY(series);
214 return m_chart->axisY(series);
214 }
215 }
215
216
216 QLegend *DeclarativeChart::legend()
217 QLegend *DeclarativeChart::legend()
217 {
218 {
218 return m_chart->legend();
219 return m_chart->legend();
219 }
220 }
220
221
221 QVariantList DeclarativeChart::axisXLabels()
222 QVariantList DeclarativeChart::axisXLabels()
222 {
223 {
223 QVariantList labels;
224 QVariantList labels;
224 foreach (qreal value, m_chart->axisX()->categories()->values()) {
225 foreach (qreal value, m_chart->axisX()->categories()->values()) {
225 labels.append(value);
226 labels.append(value);
226 labels.append(m_chart->axisX()->categories()->label(value));
227 labels.append(m_chart->axisX()->categories()->label(value));
227 }
228 }
228 return labels;
229 return labels;
229 }
230 }
230
231
231 void DeclarativeChart::setAxisXLabels(QVariantList list)
232 void DeclarativeChart::setAxisXLabels(QVariantList list)
232 {
233 {
233 QVariant value(QVariant::Invalid);
234 QVariant value(QVariant::Invalid);
234 foreach (QVariant element, list) {
235 foreach (QVariant element, list) {
235 if (value.isValid() && element.type() == QVariant::String) {
236 if (value.isValid() && element.type() == QVariant::String) {
236 m_chart->axisX()->categories()->insert(value.toDouble(), element.toString());
237 m_chart->axisX()->categories()->insert(value.toDouble(), element.toString());
237 value = QVariant(QVariant::Invalid);
238 value = QVariant(QVariant::Invalid);
238 } else {
239 } else {
239 if (element.canConvert(QVariant::Double))
240 if (element.canConvert(QVariant::Double))
240 value = element;
241 value = element;
241 }
242 }
242 }
243 }
243 emit axisLabelsChanged();
244 emit axisLabelsChanged();
244 }
245 }
245
246
246 void DeclarativeChart::setTitleColor(QColor color)
247 void DeclarativeChart::setTitleColor(QColor color)
247 {
248 {
248 QBrush b = m_chart->titleBrush();
249 QBrush b = m_chart->titleBrush();
249 if (color != b.color()) {
250 if (color != b.color()) {
250 b.setColor(color);
251 b.setColor(color);
251 m_chart->setTitleBrush(b);
252 m_chart->setTitleBrush(b);
252 emit titleColorChanged();
253 emit titleColorChanged();
253 }
254 }
254 }
255 }
255
256
256 QColor DeclarativeChart::titleColor()
257 QColor DeclarativeChart::titleColor()
257 {
258 {
258 return m_chart->titleBrush().color();
259 return m_chart->titleBrush().color();
259 }
260 }
260
261
261 void DeclarativeChart::setBackgroundColor(QColor color)
262 void DeclarativeChart::setBackgroundColor(QColor color)
262 {
263 {
263 QBrush b = m_chart->backgroundBrush();
264 QBrush b = m_chart->backgroundBrush();
264 if (b.style() != Qt::SolidPattern || color != b.color()) {
265 if (b.style() != Qt::SolidPattern || color != b.color()) {
265 b.setStyle(Qt::SolidPattern);
266 b.setStyle(Qt::SolidPattern);
266 b.setColor(color);
267 b.setColor(color);
267 m_chart->setBackgroundBrush(b);
268 m_chart->setBackgroundBrush(b);
268 emit backgroundColorChanged();
269 emit backgroundColorChanged();
269 }
270 }
270 }
271 }
271
272
272 QColor DeclarativeChart::backgroundColor()
273 QColor DeclarativeChart::backgroundColor()
273 {
274 {
274 return m_chart->backgroundBrush().color();
275 return m_chart->backgroundBrush().color();
275 }
276 }
276
277
277 int DeclarativeChart::count()
278 int DeclarativeChart::count()
278 {
279 {
279 return m_chart->series().count();
280 return m_chart->series().count();
280 }
281 }
281
282
282 void DeclarativeChart::setDropShadowEnabled(bool enabled)
283 void DeclarativeChart::setDropShadowEnabled(bool enabled)
283 {
284 {
284 if (enabled != m_chart->isDropShadowEnabled()) {
285 if (enabled != m_chart->isDropShadowEnabled()) {
285 m_chart->setDropShadowEnabled(enabled);
286 m_chart->setDropShadowEnabled(enabled);
286 dropShadowEnabledChanged(enabled);
287 dropShadowEnabledChanged(enabled);
287 }
288 }
288 }
289 }
289
290
290 bool DeclarativeChart::dropShadowEnabled()
291 bool DeclarativeChart::dropShadowEnabled()
291 {
292 {
292 return m_chart->isDropShadowEnabled();
293 return m_chart->isDropShadowEnabled();
293 }
294 }
294
295
295 void DeclarativeChart::zoom(qreal factor)
296 void DeclarativeChart::zoom(qreal factor)
296 {
297 {
297 m_chart->zoom(factor);
298 m_chart->zoom(factor);
298 }
299 }
299
300
300 void DeclarativeChart::scrollLeft(qreal pixels)
301 void DeclarativeChart::scrollLeft(qreal pixels)
301 {
302 {
302 m_chart->scroll(QPointF(pixels, 0));
303 m_chart->scroll(QPointF(pixels, 0));
303 }
304 }
304
305
305 void DeclarativeChart::scrollRight(qreal pixels)
306 void DeclarativeChart::scrollRight(qreal pixels)
306 {
307 {
307 m_chart->scroll(QPointF(-pixels, 0));
308 m_chart->scroll(QPointF(-pixels, 0));
308 }
309 }
309
310
310 void DeclarativeChart::scrollUp(qreal pixels)
311 void DeclarativeChart::scrollUp(qreal pixels)
311 {
312 {
312 m_chart->scroll(QPointF(0, pixels));
313 m_chart->scroll(QPointF(0, pixels));
313 }
314 }
314
315
315 void DeclarativeChart::scrollDown(qreal pixels)
316 void DeclarativeChart::scrollDown(qreal pixels)
316 {
317 {
317 m_chart->scroll(QPointF(0, -pixels));
318 m_chart->scroll(QPointF(0, -pixels));
318 }
319 }
319
320
320 QAbstractSeries *DeclarativeChart::series(int index)
321 QAbstractSeries *DeclarativeChart::series(int index)
321 {
322 {
322 if (index < m_chart->series().count()) {
323 if (index < m_chart->series().count()) {
323 return m_chart->series().at(index);
324 return m_chart->series().at(index);
324 }
325 }
325 return 0;
326 return 0;
326 }
327 }
327
328
328 QAbstractSeries *DeclarativeChart::series(QString seriesName)
329 QAbstractSeries *DeclarativeChart::series(QString seriesName)
329 {
330 {
330 foreach(QAbstractSeries *series, m_chart->series()) {
331 foreach(QAbstractSeries *series, m_chart->series()) {
331 if (series->name() == seriesName)
332 if (series->name() == seriesName)
332 return series;
333 return series;
333 }
334 }
334 return 0;
335 return 0;
335 }
336 }
336
337
337 QAbstractSeries *DeclarativeChart::createSeries(DeclarativeChart::SeriesType type, QString name)
338 QAbstractSeries *DeclarativeChart::createSeries(DeclarativeChart::SeriesType type, QString name)
338 {
339 {
339 QAbstractSeries *series = 0;
340 QAbstractSeries *series = 0;
340 switch (type) {
341 switch (type) {
341 case DeclarativeChart::SeriesTypeLine:
342 case DeclarativeChart::SeriesTypeLine:
342 series = new DeclarativeLineSeries();
343 series = new DeclarativeLineSeries();
343 break;
344 break;
344 case DeclarativeChart::SeriesTypeArea:
345 case DeclarativeChart::SeriesTypeArea:
345 series = new DeclarativeAreaSeries();
346 series = new DeclarativeAreaSeries();
346 break;
347 break;
347 case DeclarativeChart::SeriesTypeBar:
348 case DeclarativeChart::SeriesTypeBar:
348 series = new DeclarativeBarSeries();
349 series = new DeclarativeBarSeries();
349 break;
350 break;
350 case DeclarativeChart::SeriesTypeStackedBar:
351 case DeclarativeChart::SeriesTypeStackedBar:
351 // TODO
352 // TODO
352 break;
353 break;
353 case DeclarativeChart::SeriesTypePercentBar:
354 case DeclarativeChart::SeriesTypePercentBar:
354 // TODO
355 // TODO
355 break;
356 break;
356 case DeclarativeChart::SeriesTypeGroupedBar:
357 case DeclarativeChart::SeriesTypeGroupedBar:
357 series = new DeclarativeGroupedBarSeries();
358 series = new DeclarativeGroupedBarSeries();
358 break;
359 break;
359 case DeclarativeChart::SeriesTypePie:
360 case DeclarativeChart::SeriesTypePie:
360 series = new DeclarativePieSeries();
361 series = new DeclarativePieSeries();
361 break;
362 break;
362 case DeclarativeChart::SeriesTypeScatter:
363 case DeclarativeChart::SeriesTypeScatter:
363 series = new DeclarativeScatterSeries();
364 series = new DeclarativeScatterSeries();
364 break;
365 break;
365 case DeclarativeChart::SeriesTypeSpline:
366 case DeclarativeChart::SeriesTypeSpline:
366 series = new DeclarativeSplineSeries();
367 series = new DeclarativeSplineSeries();
367 break;
368 break;
368 default:
369 default:
369 qWarning() << "Illegal series type";
370 qWarning() << "Illegal series type";
370 }
371 }
371 series->setName(name);
372 series->setName(name);
372 m_chart->addSeries(series);
373 m_chart->addSeries(series);
373 return series;
374 return series;
374 }
375 }
375
376
376 #include "moc_declarativechart.cpp"
377 #include "moc_declarativechart.cpp"
377
378
378 QTCOMMERCIALCHART_END_NAMESPACE
379 QTCOMMERCIALCHART_END_NAMESPACE
@@ -1,74 +1,72
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 #include "declarativechart.h"
22 #include "declarativechart.h"
23 #include "qchart.h"
23 #include "qchart.h"
24 #include "qlineseries.h"
24 #include "qlineseries.h"
25
25
26 QTCOMMERCIALCHART_BEGIN_NAMESPACE
26 QTCOMMERCIALCHART_BEGIN_NAMESPACE
27
27
28 /*!
28 /*!
29 \qmlclass LineSeries QLineSeries
29 \qmlclass LineSeries QLineSeries
30
30
31 \section1 Example Usage
32
33 \beginfloatleft
31 \beginfloatleft
34 \image demos_qmlchart2.png
32 \image demos_qmlchart2.png
35 \endfloat
33 \endfloat
36 \clearfloat
34 \clearfloat
37
35
38 The following QML shows how to create a simple line chart:
36 The following QML shows how to create a simple line chart:
39 \snippet ../demos/qmlchart/qml/qmlchart/View2.qml 1
37 \snippet ../demos/qmlchart/qml/qmlchart/View2.qml 1
40 */
38 */
41
39
42 DeclarativeLineSeries::DeclarativeLineSeries(QObject *parent) :
40 DeclarativeLineSeries::DeclarativeLineSeries(QObject *parent) :
43 QLineSeries(parent)
41 QLineSeries(parent)
44 {
42 {
45 connect(this, SIGNAL(pointAdded(int)), this, SLOT(handleCountChanged(int)));
43 connect(this, SIGNAL(pointAdded(int)), this, SLOT(handleCountChanged(int)));
46 connect(this, SIGNAL(pointRemoved(int)), this, SLOT(handleCountChanged(int)));
44 connect(this, SIGNAL(pointRemoved(int)), this, SLOT(handleCountChanged(int)));
47 }
45 }
48
46
49 QXYSeries *DeclarativeLineSeries::xySeries()
47 QXYSeries *DeclarativeLineSeries::xySeries()
50 {
48 {
51 return this;
49 return this;
52 }
50 }
53
51
54 void DeclarativeLineSeries::handleCountChanged(int index)
52 void DeclarativeLineSeries::handleCountChanged(int index)
55 {
53 {
56 Q_UNUSED(index)
54 Q_UNUSED(index)
57 emit countChanged(points().count());
55 emit countChanged(points().count());
58 }
56 }
59
57
60 QDeclarativeListProperty<QObject> DeclarativeLineSeries::declarativeChildren()
58 QDeclarativeListProperty<QObject> DeclarativeLineSeries::declarativeChildren()
61 {
59 {
62 return QDeclarativeListProperty<QObject>(this, 0, &appendDeclarativeChildren);
60 return QDeclarativeListProperty<QObject>(this, 0, &appendDeclarativeChildren);
63 }
61 }
64
62
65 void DeclarativeLineSeries::appendDeclarativeChildren(QDeclarativeListProperty<QObject> *list, QObject *element)
63 void DeclarativeLineSeries::appendDeclarativeChildren(QDeclarativeListProperty<QObject> *list, QObject *element)
66 {
64 {
67 Q_UNUSED(list)
65 Q_UNUSED(list)
68 Q_UNUSED(element)
66 Q_UNUSED(element)
69 // Empty implementation, childs are parsed in componentComplete
67 // Empty implementation, childs are parsed in componentComplete
70 }
68 }
71
69
72 #include "moc_declarativelineseries.cpp"
70 #include "moc_declarativelineseries.cpp"
73
71
74 QTCOMMERCIALCHART_END_NAMESPACE
72 QTCOMMERCIALCHART_END_NAMESPACE
@@ -1,86 +1,85
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 #include "declarativechart.h"
22 #include "declarativechart.h"
23 #include "qchart.h"
23 #include "qchart.h"
24 #include "qscatterseries.h"
24 #include "qscatterseries.h"
25
25
26 QTCOMMERCIALCHART_BEGIN_NAMESPACE
26 QTCOMMERCIALCHART_BEGIN_NAMESPACE
27
27
28 /*!
28 /*!
29 \qmlclass ScatterSeries QScatterSeries
29 \qmlclass ScatterSeries QScatterSeries
30
30
31 \section1 Example Usage
31 The following QML shows how to create a chart with two simple scatter series:
32 \snippet ../demos/qmlchart/qml/qmlchart/View5.qml 1
33 \snippet ../demos/qmlchart/qml/qmlchart/View5.qml 2
32
34
33 \beginfloatleft
35 \beginfloatleft
34 \image demos_qmlchart5.png
36 \image demos_qmlchart5.png
35 \endfloat
37 \endfloat
36 \clearfloat
38 \clearfloat
37
38 The following QML shows how to create a simple scatter chart:
39 \snippet ../demos/qmlchart/qml/qmlchart/View5.qml 1
40 */
39 */
41
40
42 DeclarativeScatterSeries::DeclarativeScatterSeries(QObject *parent) :
41 DeclarativeScatterSeries::DeclarativeScatterSeries(QObject *parent) :
43 QScatterSeries(parent)
42 QScatterSeries(parent)
44 {
43 {
45 connect(this, SIGNAL(pointAdded(int)), this, SLOT(handleCountChanged(int)));
44 connect(this, SIGNAL(pointAdded(int)), this, SLOT(handleCountChanged(int)));
46 connect(this, SIGNAL(pointRemoved(int)), this, SLOT(handleCountChanged(int)));
45 connect(this, SIGNAL(pointRemoved(int)), this, SLOT(handleCountChanged(int)));
47 }
46 }
48
47
49 QXYSeries *DeclarativeScatterSeries::xySeries()
48 QXYSeries *DeclarativeScatterSeries::xySeries()
50 {
49 {
51 return this;
50 return this;
52 }
51 }
53
52
54 void DeclarativeScatterSeries::handleCountChanged(int index)
53 void DeclarativeScatterSeries::handleCountChanged(int index)
55 {
54 {
56 Q_UNUSED(index)
55 Q_UNUSED(index)
57 emit countChanged(QScatterSeries::count());
56 emit countChanged(QScatterSeries::count());
58 }
57 }
59
58
60 QDeclarativeListProperty<QObject> DeclarativeScatterSeries::declarativeChildren()
59 QDeclarativeListProperty<QObject> DeclarativeScatterSeries::declarativeChildren()
61 {
60 {
62 return QDeclarativeListProperty<QObject>(this, 0, &appendDeclarativeChildren);
61 return QDeclarativeListProperty<QObject>(this, 0, &appendDeclarativeChildren);
63 }
62 }
64
63
65 void DeclarativeScatterSeries::appendDeclarativeChildren(QDeclarativeListProperty<QObject> *list, QObject *element)
64 void DeclarativeScatterSeries::appendDeclarativeChildren(QDeclarativeListProperty<QObject> *list, QObject *element)
66 {
65 {
67 Q_UNUSED(list)
66 Q_UNUSED(list)
68 Q_UNUSED(element)
67 Q_UNUSED(element)
69 // Empty implementation, childs are parsed in componentComplete
68 // Empty implementation, childs are parsed in componentComplete
70 }
69 }
71
70
72 QColor DeclarativeScatterSeries::brushColor()
71 QColor DeclarativeScatterSeries::brushColor()
73 {
72 {
74 return brush().color();
73 return brush().color();
75 }
74 }
76
75
77 void DeclarativeScatterSeries::setBrushColor(QColor color)
76 void DeclarativeScatterSeries::setBrushColor(QColor color)
78 {
77 {
79 QBrush b = brush();
78 QBrush b = brush();
80 b.setColor(color);
79 b.setColor(color);
81 setBrush(b);
80 setBrush(b);
82 }
81 }
83
82
84 #include "moc_declarativescatterseries.cpp"
83 #include "moc_declarativescatterseries.cpp"
85
84
86 QTCOMMERCIALCHART_END_NAMESPACE
85 QTCOMMERCIALCHART_END_NAMESPACE
@@ -1,662 +1,674
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 "qaxis.h"
21 #include "qaxis.h"
22 #include "qaxis_p.h"
22 #include "qaxis_p.h"
23
23
24 QTCOMMERCIALCHART_BEGIN_NAMESPACE
24 QTCOMMERCIALCHART_BEGIN_NAMESPACE
25
25
26 /*!
26 /*!
27 \class QAxis
27 \class QAxis
28 \brief The QAxis class is used for manipulating chart's axis
28 \brief The QAxis class is used for manipulating chart's axis
29 and for adding optional axes to the chart.
29 and for adding optional axes to the chart.
30 \mainclass
30 \mainclass
31
31
32 There is only one x Axis, however there can be multiple y axes.
32 There is only one x Axis, however there can be multiple y axes.
33 Each chart series can be bound to exactly one Y axis and the shared common X axis.
33 Each chart series can be bound to exactly one Y axis and the shared common X axis.
34 Axis can be setup to show axis line with tick marks, grid lines and shades.
34 Axis can be setup to show axis line with tick marks, grid lines and shades.
35 */
35 */
36
36
37 /*!
37 /*!
38 \qmlclass Axis QAxis
38 \qmlclass Axis QAxis
39 \brief The Axis element is used for manipulating chart's axes
39 \brief The Axis element is used for manipulating chart's axes
40
40
41 There is only one x Axis, however there can be multiple y axes on a ChartView.
41 There is only one x Axis, however there can be multiple y axes on a ChartView.
42 Each chart series can be bound to exactly one Y axis and the shared common X axis.
42 Each chart series can be bound to exactly one Y axis and the shared common X axis.
43 Axis can be setup to show axis line with tick marks, grid lines and shades.
43 Axis can be setup to show axis line with tick marks, grid lines and shades.
44
45 To access Axes you can use ChartView API. For example:
46 \code
47 ChartView {
48 axisX.min: 0
49 axisX.max: 3
50 axisX.ticksCount: 4
51 axisY.min: 0
52 axisY.max: 4
53 // Add a few series...
54 }
55 \endcode
44 */
56 */
45
57
46 /*!
58 /*!
47 \property QAxis::labelsVisible
59 \property QAxis::labelsVisible
48 Defines if axis labels are visible.
60 Defines if axis labels are visible.
49 */
61 */
50 /*!
62 /*!
51 \qmlproperty bool Axis::labelsVisible
63 \qmlproperty bool Axis::labelsVisible
52 Defines if axis labels are visible.
64 Defines if axis labels are visible.
53 */
65 */
54
66
55 /*!
67 /*!
56 \property QAxis::min
68 \property QAxis::min
57 Defines the minimum value on the axis.
69 Defines the minimum value on the axis.
58 */
70 */
59 /*!
71 /*!
60 \qmlproperty real Axis::min
72 \qmlproperty real Axis::min
61 Defines the minimum value on the axis.
73 Defines the minimum value on the axis.
62 */
74 */
63
75
64 /*!
76 /*!
65 \property QAxis::max
77 \property QAxis::max
66 Defines the maximum value on the axis.
78 Defines the maximum value on the axis.
67 */
79 */
68 /*!
80 /*!
69 \qmlproperty real Axis::max
81 \qmlproperty real Axis::max
70 Defines the maximum value on the axis.
82 Defines the maximum value on the axis.
71 */
83 */
72
84
73 /*!
85 /*!
74 \property QAxis::visible
86 \property QAxis::visible
75 The visibility of the axis.
87 The visibility of the axis.
76 */
88 */
77 /*!
89 /*!
78 \qmlproperty bool Axis::visible
90 \qmlproperty bool Axis::visible
79 The visibility of the axis.
91 The visibility of the axis.
80 */
92 */
81
93
82 /*!
94 /*!
83 \property QAxis::gridVisible
95 \property QAxis::gridVisible
84 The visibility of the grid lines.
96 The visibility of the grid lines.
85 */
97 */
86 /*!
98 /*!
87 \qmlproperty bool Axis::gridVisible
99 \qmlproperty bool Axis::gridVisible
88 The visibility of the grid lines.
100 The visibility of the grid lines.
89 */
101 */
90
102
91 /*!
103 /*!
92 \property QAxis::color
104 \property QAxis::color
93 The color of the axis and ticks.
105 The color of the axis and ticks.
94 */
106 */
95 /*!
107 /*!
96 \qmlproperty color Axis::color
108 \qmlproperty color Axis::color
97 The color of the axis and ticks.
109 The color of the axis and ticks.
98 */
110 */
99
111
100 /*!
112 /*!
101 \property QAxis::labelsColor
113 \property QAxis::labelsColor
102 The color of the axis labels.
114 The color of the axis labels.
103 */
115 */
104 /*!
116 /*!
105 \qmlproperty color Axis::labelsColor
117 \qmlproperty color Axis::labelsColor
106 The color of the axis labels.
118 The color of the axis labels.
107 */
119 */
108
120
109 /*!
121 /*!
110 \property QAxis::labelsAngle
122 \property QAxis::labelsAngle
111 The angle of the axis labels in degrees.
123 The angle of the axis labels in degrees.
112 */
124 */
113 /*!
125 /*!
114 \qmlproperty int Axis::labelsAngle
126 \qmlproperty int Axis::labelsAngle
115 The angle of the axis labels in degrees.
127 The angle of the axis labels in degrees.
116 */
128 */
117
129
118 /*!
130 /*!
119 \property QAxis::shadesVisible
131 \property QAxis::shadesVisible
120 The visibility of the axis shades.
132 The visibility of the axis shades.
121 */
133 */
122 /*!
134 /*!
123 \qmlproperty bool Axis::shadesVisible
135 \qmlproperty bool Axis::shadesVisible
124 The visibility of the axis shades.
136 The visibility of the axis shades.
125 */
137 */
126
138
127 /*!
139 /*!
128 \property QAxis::shadesColor
140 \property QAxis::shadesColor
129 The fill (brush) color of the axis shades.
141 The fill (brush) color of the axis shades.
130 */
142 */
131 /*!
143 /*!
132 \qmlproperty color Axis::shadesColor
144 \qmlproperty color Axis::shadesColor
133 The fill (brush) color of the axis shades.
145 The fill (brush) color of the axis shades.
134 */
146 */
135
147
136 /*!
148 /*!
137 \property QAxis::shadesBorderColor
149 \property QAxis::shadesBorderColor
138 The border (pen) color of the axis shades.
150 The border (pen) color of the axis shades.
139 */
151 */
140 /*!
152 /*!
141 \qmlproperty color Axis::shadesBorderColor
153 \qmlproperty color Axis::shadesBorderColor
142 The border (pen) color of the axis shades.
154 The border (pen) color of the axis shades.
143 */
155 */
144
156
145 /*!
157 /*!
146 \property QAxis::ticksCount
158 \property QAxis::ticksCount
147 The number of tick marks for the axis.
159 The number of tick marks for the axis.
148 */
160 */
149 /*!
161 /*!
150 \qmlproperty int Axis::ticksCount
162 \qmlproperty int Axis::ticksCount
151 The number of tick marks for the axis.
163 The number of tick marks for the axis.
152 */
164 */
153
165
154 /*!
166 /*!
155 \property QAxis::niceNumbersEnabled
167 \property QAxis::niceNumbersEnabled
156 Whether the nice numbers algorithm is enabled or not for the axis.
168 Whether the nice numbers algorithm is enabled or not for the axis.
157 */
169 */
158 /*!
170 /*!
159 \qmlproperty bool Axis::niceNumbersEnabled
171 \qmlproperty bool Axis::niceNumbersEnabled
160 Whether the nice numbers algorithm is enabled or not for the axis.
172 Whether the nice numbers algorithm is enabled or not for the axis.
161 */
173 */
162
174
163 /*!
175 /*!
164 \fn void QAxis::visibleChanged(bool)
176 \fn void QAxis::visibleChanged(bool)
165 Visiblity of the axis has changed to \a visible.
177 Visiblity of the axis has changed to \a visible.
166 */
178 */
167
179
168 /*!
180 /*!
169 \fn void QAxis::labelsVisibleChanged(bool)
181 \fn void QAxis::labelsVisibleChanged(bool)
170 Visiblity of the labels of the axis has changed to \a visible.
182 Visiblity of the labels of the axis has changed to \a visible.
171 */
183 */
172
184
173 /*!
185 /*!
174 \fn void QAxis::gridVisibleChanged(bool)
186 \fn void QAxis::gridVisibleChanged(bool)
175 Visiblity of the grid lines of the axis has changed to \a visible.
187 Visiblity of the grid lines of the axis has changed to \a visible.
176 */
188 */
177
189
178 /*!
190 /*!
179 \fn void QAxis::minChanged(qreal min)
191 \fn void QAxis::minChanged(qreal min)
180 Axis emits signal when \a min of axis has changed.
192 Axis emits signal when \a min of axis has changed.
181 */
193 */
182
194
183 /*!
195 /*!
184 \fn void QAxis::maxChanged(qreal max)
196 \fn void QAxis::maxChanged(qreal max)
185 Axis emits signal when \a max of axis has changed.
197 Axis emits signal when \a max of axis has changed.
186 */
198 */
187
199
188 /*!
200 /*!
189 \fn void QAxis::rangeChanged(qreal min, qreal max)
201 \fn void QAxis::rangeChanged(qreal min, qreal max)
190 Axis emits signal when \a min or \a max of axis has changed.
202 Axis emits signal when \a min or \a max of axis has changed.
191 */
203 */
192
204
193 /*!
205 /*!
194 \fn QChartAxisCategories* QAxis::categories()
206 \fn QChartAxisCategories* QAxis::categories()
195 Returns pointer to the list of categories which correspond to the values on the axis.
207 Returns pointer to the list of categories which correspond to the values on the axis.
196 */
208 */
197
209
198 /*!
210 /*!
199 \fn void QAxis::colorChanged(QColor)
211 \fn void QAxis::colorChanged(QColor)
200 Emitted if the \a color of the axis is changed.
212 Emitted if the \a color of the axis is changed.
201 */
213 */
202
214
203 /*!
215 /*!
204 \fn void QAxis::labelsColorChanged(QColor)
216 \fn void QAxis::labelsColorChanged(QColor)
205 Emitted if the \a color of the axis labels is changed.
217 Emitted if the \a color of the axis labels is changed.
206 */
218 */
207
219
208 /*!
220 /*!
209 \fn void QAxis::labelsAngleChanged(int)
221 \fn void QAxis::labelsAngleChanged(int)
210 Emitted if the \a angle of the axis labels is changed.
222 Emitted if the \a angle of the axis labels is changed.
211 */
223 */
212
224
213 /*!
225 /*!
214 \fn void QAxis::shadesVisibleChanged(bool)
226 \fn void QAxis::shadesVisibleChanged(bool)
215 Emitted if the visibility of the axis shades is changed to \a visible.
227 Emitted if the visibility of the axis shades is changed to \a visible.
216 */
228 */
217
229
218 /*!
230 /*!
219 \fn void QAxis::shadesColorChanged(QColor)
231 \fn void QAxis::shadesColorChanged(QColor)
220 Emitted if the \a color of the axis shades is changed.
232 Emitted if the \a color of the axis shades is changed.
221 */
233 */
222
234
223 /*!
235 /*!
224 \fn void QAxis::shadesBorderColorChanged(QColor)
236 \fn void QAxis::shadesBorderColorChanged(QColor)
225 Emitted if the border \a color of the axis shades is changed.
237 Emitted if the border \a color of the axis shades is changed.
226 */
238 */
227
239
228 /*!
240 /*!
229 \fn void QAxis::ticksCountChanged(int count)
241 \fn void QAxis::ticksCountChanged(int count)
230 \brief Emits the new \a count of ticks on the axis
242 \brief Emits the new \a count of ticks on the axis
231 Signal is emitted when the number of the ticks on the axis has been changed to a different value.
243 Signal is emitted when the number of the ticks on the axis has been changed to a different value.
232 Parementer count\a count is the new number of ticks on the axis.
244 Parementer count\a count is the new number of ticks on the axis.
233 */
245 */
234
246
235 /*!
247 /*!
236 \fn void QAxis::niceNumbersEnabledChanged(bool)
248 \fn void QAxis::niceNumbersEnabledChanged(bool)
237 Nice numbers algorithm was \a enabled or disabled.
249 Nice numbers algorithm was \a enabled or disabled.
238 */
250 */
239
251
240 /*!
252 /*!
241 Constructs new axis object which is a child of \a parent. Ownership is taken by
253 Constructs new axis object which is a child of \a parent. Ownership is taken by
242 QChart when axis added.
254 QChart when axis added.
243 */
255 */
244 QAxis::QAxis(QObject *parent) : QObject(parent),
256 QAxis::QAxis(QObject *parent) : QObject(parent),
245 d_ptr(new QAxisPrivate(this))
257 d_ptr(new QAxisPrivate(this))
246 {
258 {
247
259
248 }
260 }
249
261
250 /*!
262 /*!
251 Destructor of the axis object. When axis is added to chart, chart object takes ownership.
263 Destructor of the axis object. When axis is added to chart, chart object takes ownership.
252 */
264 */
253
265
254 QAxis::~QAxis()
266 QAxis::~QAxis()
255 {
267 {
256 }
268 }
257
269
258 /*!
270 /*!
259 Sets \a pen used to draw axis line and ticks.
271 Sets \a pen used to draw axis line and ticks.
260 */
272 */
261 void QAxis::setAxisPen(const QPen &pen)
273 void QAxis::setAxisPen(const QPen &pen)
262 {
274 {
263 if (d_ptr->m_axisPen!=pen) {
275 if (d_ptr->m_axisPen!=pen) {
264 d_ptr->m_axisPen = pen;
276 d_ptr->m_axisPen = pen;
265 emit d_ptr->updated();
277 emit d_ptr->updated();
266 }
278 }
267 }
279 }
268
280
269 /*!
281 /*!
270 Returns pen used to draw axis and ticks.
282 Returns pen used to draw axis and ticks.
271 */
283 */
272 QPen QAxis::axisPen() const
284 QPen QAxis::axisPen() const
273 {
285 {
274 return d_ptr->m_axisPen;
286 return d_ptr->m_axisPen;
275 }
287 }
276
288
277 void QAxis::setAxisPenColor(QColor color)
289 void QAxis::setAxisPenColor(QColor color)
278 {
290 {
279 QPen p = d_ptr->m_axisPen;
291 QPen p = d_ptr->m_axisPen;
280 if (p.color() != color) {
292 if (p.color() != color) {
281 p.setColor(color);
293 p.setColor(color);
282 setAxisPen(p);
294 setAxisPen(p);
283 emit colorChanged(color);
295 emit colorChanged(color);
284 }
296 }
285 }
297 }
286
298
287 QColor QAxis::axisPenColor() const
299 QColor QAxis::axisPenColor() const
288 {
300 {
289 return d_ptr->m_axisPen.color();
301 return d_ptr->m_axisPen.color();
290 }
302 }
291
303
292 /*!
304 /*!
293 Sets if axis and ticks are \a visible.
305 Sets if axis and ticks are \a visible.
294 */
306 */
295 void QAxis::setAxisVisible(bool visible)
307 void QAxis::setAxisVisible(bool visible)
296 {
308 {
297 if (d_ptr->m_axisVisible != visible) {
309 if (d_ptr->m_axisVisible != visible) {
298 d_ptr->m_axisVisible = visible;
310 d_ptr->m_axisVisible = visible;
299 emit d_ptr->updated();
311 emit d_ptr->updated();
300 emit visibleChanged(visible);
312 emit visibleChanged(visible);
301 }
313 }
302 }
314 }
303
315
304 bool QAxis::isAxisVisible() const
316 bool QAxis::isAxisVisible() const
305 {
317 {
306 return d_ptr->m_axisVisible;
318 return d_ptr->m_axisVisible;
307 }
319 }
308
320
309 void QAxis::setGridLineVisible(bool visible)
321 void QAxis::setGridLineVisible(bool visible)
310 {
322 {
311 if (d_ptr->m_gridLineVisible != visible) {
323 if (d_ptr->m_gridLineVisible != visible) {
312 d_ptr->m_gridLineVisible = visible;
324 d_ptr->m_gridLineVisible = visible;
313 emit d_ptr->updated();
325 emit d_ptr->updated();
314 emit gridVisibleChanged(visible);
326 emit gridVisibleChanged(visible);
315 }
327 }
316 }
328 }
317
329
318 bool QAxis::isGridLineVisible() const
330 bool QAxis::isGridLineVisible() const
319 {
331 {
320 return d_ptr->m_gridLineVisible;
332 return d_ptr->m_gridLineVisible;
321 }
333 }
322
334
323 /*!
335 /*!
324 Sets \a pen used to draw grid line.
336 Sets \a pen used to draw grid line.
325 */
337 */
326 void QAxis::setGridLinePen(const QPen &pen)
338 void QAxis::setGridLinePen(const QPen &pen)
327 {
339 {
328 if (d_ptr->m_gridLinePen != pen) {
340 if (d_ptr->m_gridLinePen != pen) {
329 d_ptr->m_gridLinePen = pen;
341 d_ptr->m_gridLinePen = pen;
330 emit d_ptr->updated();
342 emit d_ptr->updated();
331 }
343 }
332 }
344 }
333
345
334 /*!
346 /*!
335 Returns pen used to draw grid.
347 Returns pen used to draw grid.
336 */
348 */
337 QPen QAxis::gridLinePen() const
349 QPen QAxis::gridLinePen() const
338 {
350 {
339 return d_ptr->m_gridLinePen;
351 return d_ptr->m_gridLinePen;
340 }
352 }
341
353
342 void QAxis::setLabelsVisible(bool visible)
354 void QAxis::setLabelsVisible(bool visible)
343 {
355 {
344 if (d_ptr->m_labelsVisible != visible) {
356 if (d_ptr->m_labelsVisible != visible) {
345 d_ptr->m_labelsVisible = visible;
357 d_ptr->m_labelsVisible = visible;
346 emit d_ptr->updated();
358 emit d_ptr->updated();
347 emit labelsVisibleChanged(visible);
359 emit labelsVisibleChanged(visible);
348 }
360 }
349 }
361 }
350
362
351 bool QAxis::labelsVisible() const
363 bool QAxis::labelsVisible() const
352 {
364 {
353 return d_ptr->m_labelsVisible;
365 return d_ptr->m_labelsVisible;
354 }
366 }
355
367
356 /*!
368 /*!
357 Sets \a pen used to draw labels.
369 Sets \a pen used to draw labels.
358 */
370 */
359 void QAxis::setLabelsPen(const QPen &pen)
371 void QAxis::setLabelsPen(const QPen &pen)
360 {
372 {
361 if (d_ptr->m_labelsPen != pen) {
373 if (d_ptr->m_labelsPen != pen) {
362 d_ptr->m_labelsPen = pen;
374 d_ptr->m_labelsPen = pen;
363 emit d_ptr->updated();
375 emit d_ptr->updated();
364 }
376 }
365 }
377 }
366
378
367 /*!
379 /*!
368 Returns the pen used to labels.
380 Returns the pen used to labels.
369 */
381 */
370 QPen QAxis::labelsPen() const
382 QPen QAxis::labelsPen() const
371 {
383 {
372 return d_ptr->m_labelsPen;
384 return d_ptr->m_labelsPen;
373 }
385 }
374
386
375 /*!
387 /*!
376 Sets \a brush used to draw labels.
388 Sets \a brush used to draw labels.
377 */
389 */
378 void QAxis::setLabelsBrush(const QBrush &brush)
390 void QAxis::setLabelsBrush(const QBrush &brush)
379 {
391 {
380 if (d_ptr->m_labelsBrush != brush) {
392 if (d_ptr->m_labelsBrush != brush) {
381 d_ptr->m_labelsBrush = brush;
393 d_ptr->m_labelsBrush = brush;
382 emit d_ptr->updated();
394 emit d_ptr->updated();
383 }
395 }
384 }
396 }
385
397
386 /*!
398 /*!
387 Returns brush used to draw labels.
399 Returns brush used to draw labels.
388 */
400 */
389 QBrush QAxis::labelsBrush() const
401 QBrush QAxis::labelsBrush() const
390 {
402 {
391 return d_ptr->m_labelsBrush;
403 return d_ptr->m_labelsBrush;
392 }
404 }
393
405
394 /*!
406 /*!
395 Sets \a font used to draw labels.
407 Sets \a font used to draw labels.
396 */
408 */
397 void QAxis::setLabelsFont(const QFont &font)
409 void QAxis::setLabelsFont(const QFont &font)
398 {
410 {
399 if (d_ptr->m_labelsFont != font) {
411 if (d_ptr->m_labelsFont != font) {
400 d_ptr->m_labelsFont = font;
412 d_ptr->m_labelsFont = font;
401 emit d_ptr->updated();
413 emit d_ptr->updated();
402 }
414 }
403 }
415 }
404
416
405 /*!
417 /*!
406 Returns font used to draw labels.
418 Returns font used to draw labels.
407 */
419 */
408 QFont QAxis::labelsFont() const
420 QFont QAxis::labelsFont() const
409 {
421 {
410 return d_ptr->m_labelsFont;
422 return d_ptr->m_labelsFont;
411 }
423 }
412
424
413 void QAxis::setLabelsAngle(int angle)
425 void QAxis::setLabelsAngle(int angle)
414 {
426 {
415 if (d_ptr->m_labelsAngle != angle) {
427 if (d_ptr->m_labelsAngle != angle) {
416 d_ptr->m_labelsAngle = angle;
428 d_ptr->m_labelsAngle = angle;
417 emit d_ptr->updated();
429 emit d_ptr->updated();
418 emit labelsAngleChanged(angle);
430 emit labelsAngleChanged(angle);
419 }
431 }
420 }
432 }
421
433
422 int QAxis::labelsAngle() const
434 int QAxis::labelsAngle() const
423 {
435 {
424 return d_ptr->m_labelsAngle;
436 return d_ptr->m_labelsAngle;
425 }
437 }
426
438
427 void QAxis::setLabelsColor(QColor color)
439 void QAxis::setLabelsColor(QColor color)
428 {
440 {
429 QBrush b = d_ptr->m_labelsBrush;
441 QBrush b = d_ptr->m_labelsBrush;
430 if (b.color() != color) {
442 if (b.color() != color) {
431 b.setColor(color);
443 b.setColor(color);
432 setLabelsBrush(b);
444 setLabelsBrush(b);
433 emit labelsColorChanged(color);
445 emit labelsColorChanged(color);
434 }
446 }
435 }
447 }
436
448
437 QColor QAxis::labelsColor() const
449 QColor QAxis::labelsColor() const
438 {
450 {
439 return d_ptr->m_labelsBrush.color();
451 return d_ptr->m_labelsBrush.color();
440 }
452 }
441
453
442 void QAxis::setShadesVisible(bool visible)
454 void QAxis::setShadesVisible(bool visible)
443 {
455 {
444 if (d_ptr->m_shadesVisible != visible) {
456 if (d_ptr->m_shadesVisible != visible) {
445 d_ptr->m_shadesVisible = visible;
457 d_ptr->m_shadesVisible = visible;
446 emit d_ptr->updated();
458 emit d_ptr->updated();
447 emit shadesVisibleChanged(visible);
459 emit shadesVisibleChanged(visible);
448 }
460 }
449 }
461 }
450
462
451 bool QAxis::shadesVisible() const
463 bool QAxis::shadesVisible() const
452 {
464 {
453 return d_ptr->m_shadesVisible;
465 return d_ptr->m_shadesVisible;
454 }
466 }
455
467
456 /*!
468 /*!
457 Sets \a pen used to draw shades.
469 Sets \a pen used to draw shades.
458 */
470 */
459 void QAxis::setShadesPen(const QPen &pen)
471 void QAxis::setShadesPen(const QPen &pen)
460 {
472 {
461 if (d_ptr->m_shadesPen != pen) {
473 if (d_ptr->m_shadesPen != pen) {
462 d_ptr->m_shadesPen = pen;
474 d_ptr->m_shadesPen = pen;
463 emit d_ptr->updated();
475 emit d_ptr->updated();
464 }
476 }
465 }
477 }
466
478
467 /*!
479 /*!
468 Returns pen used to draw shades.
480 Returns pen used to draw shades.
469 */
481 */
470 QPen QAxis::shadesPen() const
482 QPen QAxis::shadesPen() const
471 {
483 {
472 return d_ptr->m_shadesPen;
484 return d_ptr->m_shadesPen;
473 }
485 }
474
486
475 /*!
487 /*!
476 Sets \a brush used to draw shades.
488 Sets \a brush used to draw shades.
477 */
489 */
478 void QAxis::setShadesBrush(const QBrush &brush)
490 void QAxis::setShadesBrush(const QBrush &brush)
479 {
491 {
480 if (d_ptr->m_shadesBrush != brush) {
492 if (d_ptr->m_shadesBrush != brush) {
481 d_ptr->m_shadesBrush = brush;
493 d_ptr->m_shadesBrush = brush;
482 emit d_ptr->updated();
494 emit d_ptr->updated();
483 emit shadesColorChanged(brush.color());
495 emit shadesColorChanged(brush.color());
484 }
496 }
485 }
497 }
486
498
487 /*!
499 /*!
488 \brief Returns brush used to draw shades.
500 \brief Returns brush used to draw shades.
489 */
501 */
490 QBrush QAxis::shadesBrush() const
502 QBrush QAxis::shadesBrush() const
491 {
503 {
492 return d_ptr->m_shadesBrush;
504 return d_ptr->m_shadesBrush;
493 }
505 }
494
506
495 void QAxis::setShadesColor(QColor color)
507 void QAxis::setShadesColor(QColor color)
496 {
508 {
497 QBrush b = d_ptr->m_shadesBrush;
509 QBrush b = d_ptr->m_shadesBrush;
498 b.setColor(color);
510 b.setColor(color);
499 setShadesBrush(b);
511 setShadesBrush(b);
500 }
512 }
501
513
502 QColor QAxis::shadesColor() const
514 QColor QAxis::shadesColor() const
503 {
515 {
504 return d_ptr->m_shadesBrush.color();
516 return d_ptr->m_shadesBrush.color();
505 }
517 }
506
518
507 void QAxis::setShadesBorderColor(QColor color)
519 void QAxis::setShadesBorderColor(QColor color)
508 {
520 {
509 QPen p = d_ptr->m_shadesPen;
521 QPen p = d_ptr->m_shadesPen;
510 p.setColor(color);
522 p.setColor(color);
511 setShadesPen(p);
523 setShadesPen(p);
512 }
524 }
513
525
514 QColor QAxis::shadesBorderColor() const
526 QColor QAxis::shadesBorderColor() const
515 {
527 {
516 return d_ptr->m_shadesPen.color();
528 return d_ptr->m_shadesPen.color();
517 }
529 }
518
530
519 void QAxis::setMin(qreal min)
531 void QAxis::setMin(qreal min)
520 {
532 {
521 setRange(min,d_ptr->m_max);
533 setRange(min,d_ptr->m_max);
522 }
534 }
523
535
524 qreal QAxis::min() const
536 qreal QAxis::min() const
525 {
537 {
526 return d_ptr->m_min;
538 return d_ptr->m_min;
527 }
539 }
528
540
529 void QAxis::setMax(qreal max)
541 void QAxis::setMax(qreal max)
530 {
542 {
531 setRange(d_ptr->m_min,max);
543 setRange(d_ptr->m_min,max);
532 }
544 }
533
545
534 qreal QAxis::max() const
546 qreal QAxis::max() const
535 {
547 {
536 return d_ptr->m_max;
548 return d_ptr->m_max;
537 }
549 }
538
550
539 /*!
551 /*!
540 Sets range from \a min to \a max on the axis.
552 Sets range from \a min to \a max on the axis.
541 */
553 */
542 void QAxis::setRange(qreal min, qreal max)
554 void QAxis::setRange(qreal min, qreal max)
543 {
555 {
544 bool changed = false;
556 bool changed = false;
545 if (!qFuzzyIsNull(d_ptr->m_min - min)) {
557 if (!qFuzzyIsNull(d_ptr->m_min - min)) {
546 d_ptr->m_min = min;
558 d_ptr->m_min = min;
547 changed = true;
559 changed = true;
548 emit minChanged(min);
560 emit minChanged(min);
549 }
561 }
550
562
551 if (!qFuzzyIsNull(d_ptr->m_max - max)) {
563 if (!qFuzzyIsNull(d_ptr->m_max - max)) {
552 d_ptr->m_max = max;
564 d_ptr->m_max = max;
553 changed = true;
565 changed = true;
554 emit maxChanged(max);
566 emit maxChanged(max);
555 }
567 }
556
568
557 if (changed) {
569 if (changed) {
558 emit rangeChanged(d_ptr->m_min,d_ptr->m_max);
570 emit rangeChanged(d_ptr->m_min,d_ptr->m_max);
559 emit d_ptr->changed(d_ptr->m_min, d_ptr->m_max, d_ptr->m_ticksCount, d_ptr->m_niceNumbers);
571 emit d_ptr->changed(d_ptr->m_min, d_ptr->m_max, d_ptr->m_ticksCount, d_ptr->m_niceNumbers);
560 }
572 }
561 }
573 }
562
574
563 /*!
575 /*!
564 Sets \a count for ticks on the axis.
576 Sets \a count for ticks on the axis.
565 */
577 */
566 void QAxis::setTicksCount(int count)
578 void QAxis::setTicksCount(int count)
567 {
579 {
568 if (d_ptr->m_ticksCount != count) {
580 if (d_ptr->m_ticksCount != count) {
569 d_ptr->m_ticksCount = count;
581 d_ptr->m_ticksCount = count;
570 emit ticksCountChanged(count);
582 emit ticksCountChanged(count);
571 emit d_ptr->changed(d_ptr->m_min, d_ptr->m_max, d_ptr->m_ticksCount, d_ptr->m_niceNumbers);
583 emit d_ptr->changed(d_ptr->m_min, d_ptr->m_max, d_ptr->m_ticksCount, d_ptr->m_niceNumbers);
572 }
584 }
573 }
585 }
574
586
575 /*!
587 /*!
576 \fn int QAxis::ticksCount() const
588 \fn int QAxis::ticksCount() const
577 Return number of ticks on the axis
589 Return number of ticks on the axis
578 */
590 */
579 int QAxis::ticksCount() const
591 int QAxis::ticksCount() const
580 {
592 {
581 return d_ptr->m_ticksCount;
593 return d_ptr->m_ticksCount;
582 }
594 }
583
595
584 /*!
596 /*!
585 Sets axis, shades, labels and grid lines to be visible.
597 Sets axis, shades, labels and grid lines to be visible.
586 */
598 */
587 void QAxis::show()
599 void QAxis::show()
588 {
600 {
589 d_ptr->m_axisVisible=true;
601 d_ptr->m_axisVisible=true;
590 d_ptr->m_gridLineVisible=true;
602 d_ptr->m_gridLineVisible=true;
591 d_ptr->m_labelsVisible=true;
603 d_ptr->m_labelsVisible=true;
592 d_ptr->m_shadesVisible=true;
604 d_ptr->m_shadesVisible=true;
593 emit d_ptr->updated();
605 emit d_ptr->updated();
594 }
606 }
595
607
596 /*!
608 /*!
597 Sets axis, shades, labels and grid lines to not be visible.
609 Sets axis, shades, labels and grid lines to not be visible.
598 */
610 */
599 void QAxis::hide()
611 void QAxis::hide()
600 {
612 {
601 d_ptr->m_axisVisible = false;
613 d_ptr->m_axisVisible = false;
602 d_ptr->m_gridLineVisible = false;
614 d_ptr->m_gridLineVisible = false;
603 d_ptr->m_labelsVisible = false;
615 d_ptr->m_labelsVisible = false;
604 d_ptr->m_shadesVisible = false;
616 d_ptr->m_shadesVisible = false;
605 emit d_ptr->updated();
617 emit d_ptr->updated();
606 }
618 }
607
619
608 void QAxis::setNiceNumbersEnabled(bool enable)
620 void QAxis::setNiceNumbersEnabled(bool enable)
609 {
621 {
610 if (d_ptr->m_niceNumbers != enable){
622 if (d_ptr->m_niceNumbers != enable){
611 d_ptr->m_niceNumbers = enable;
623 d_ptr->m_niceNumbers = enable;
612 emit d_ptr->changed(d_ptr->m_min, d_ptr->m_max, d_ptr->m_ticksCount, d_ptr->m_niceNumbers);
624 emit d_ptr->changed(d_ptr->m_min, d_ptr->m_max, d_ptr->m_ticksCount, d_ptr->m_niceNumbers);
613 emit niceNumbersEnabledChanged(enable);
625 emit niceNumbersEnabledChanged(enable);
614 }
626 }
615 }
627 }
616
628
617 bool QAxis::niceNumbersEnabled() const
629 bool QAxis::niceNumbersEnabled() const
618 {
630 {
619 return d_ptr->m_niceNumbers;
631 return d_ptr->m_niceNumbers;
620 }
632 }
621
633
622 QAxisCategories* QAxis::categories()
634 QAxisCategories* QAxis::categories()
623 {
635 {
624 return &d_ptr->m_category;
636 return &d_ptr->m_category;
625 }
637 }
626
638
627 /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
639 /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
628
640
629 QAxisPrivate::QAxisPrivate(QAxis* q):
641 QAxisPrivate::QAxisPrivate(QAxis* q):
630 q_ptr(q),
642 q_ptr(q),
631 m_axisVisible(true),
643 m_axisVisible(true),
632 m_gridLineVisible(true),
644 m_gridLineVisible(true),
633 m_labelsVisible(true),
645 m_labelsVisible(true),
634 m_labelsAngle(0),
646 m_labelsAngle(0),
635 m_shadesVisible(false),
647 m_shadesVisible(false),
636 m_shadesBrush(Qt::SolidPattern),
648 m_shadesBrush(Qt::SolidPattern),
637 m_shadesOpacity(1.0),
649 m_shadesOpacity(1.0),
638 m_min(0),
650 m_min(0),
639 m_max(0),
651 m_max(0),
640 m_ticksCount(5),
652 m_ticksCount(5),
641 m_niceNumbers(false)
653 m_niceNumbers(false)
642 {
654 {
643
655
644 }
656 }
645
657
646 QAxisPrivate::~QAxisPrivate()
658 QAxisPrivate::~QAxisPrivate()
647 {
659 {
648
660
649 }
661 }
650
662
651 void QAxisPrivate::handleAxisRangeChanged(qreal min, qreal max,int count)
663 void QAxisPrivate::handleAxisRangeChanged(qreal min, qreal max,int count)
652 {
664 {
653 q_ptr->setRange(min,max);
665 q_ptr->setRange(min,max);
654 q_ptr->setTicksCount(count);
666 q_ptr->setTicksCount(count);
655 }
667 }
656
668
657 QTCOMMERCIALCHART_END_NAMESPACE
669 QTCOMMERCIALCHART_END_NAMESPACE
658
670
659 QTCOMMERCIALCHART_USE_NAMESPACE
671 QTCOMMERCIALCHART_USE_NAMESPACE
660
672
661 #include "moc_qaxis.cpp"
673 #include "moc_qaxis.cpp"
662 #include "moc_qaxis_p.cpp"
674 #include "moc_qaxis_p.cpp"
@@ -1,768 +1,768
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 "qlegend.h"
21 #include "qlegend.h"
22 #include "qlegend_p.h"
22 #include "qlegend_p.h"
23 #include "qabstractseries.h"
23 #include "qabstractseries.h"
24 #include "qabstractseries_p.h"
24 #include "qabstractseries_p.h"
25 #include "qchart_p.h"
25 #include "qchart_p.h"
26
26
27 #include "legendmarker_p.h"
27 #include "legendmarker_p.h"
28 #include "qxyseries.h"
28 #include "qxyseries.h"
29 #include "qlineseries.h"
29 #include "qlineseries.h"
30 #include "qareaseries.h"
30 #include "qareaseries.h"
31 #include "qscatterseries.h"
31 #include "qscatterseries.h"
32 #include "qsplineseries.h"
32 #include "qsplineseries.h"
33 #include "qbarseries.h"
33 #include "qbarseries.h"
34 #include "qstackedbarseries.h"
34 #include "qstackedbarseries.h"
35 #include "qpercentbarseries.h"
35 #include "qpercentbarseries.h"
36 #include "qbarset.h"
36 #include "qbarset.h"
37 #include "qpieseries.h"
37 #include "qpieseries.h"
38 #include "qpieseries_p.h"
38 #include "qpieseries_p.h"
39 #include "qpieslice.h"
39 #include "qpieslice.h"
40 #include "chartpresenter_p.h"
40 #include "chartpresenter_p.h"
41 #include <QPainter>
41 #include <QPainter>
42 #include <QPen>
42 #include <QPen>
43 #include <QTimer>
43 #include <QTimer>
44
44
45 #include <QGraphicsSceneEvent>
45 #include <QGraphicsSceneEvent>
46
46
47 QTCOMMERCIALCHART_BEGIN_NAMESPACE
47 QTCOMMERCIALCHART_BEGIN_NAMESPACE
48
48
49 /*!
49 /*!
50 \class QLegend
50 \class QLegend
51 \brief part of QtCommercial chart API.
51 \brief part of QtCommercial chart API.
52 \mainclass
52 \mainclass
53
53
54 QLegend is a graphical object, whics displays legend of the chart. Legend state is updated by QChart, when
54 QLegend is a graphical object, whics displays legend of the chart. Legend state is updated by QChart, when
55 series have been changed. By default, legend is drawn by QChart, but user can set a new parent to legend and
55 series have been changed. By default, legend is drawn by QChart, but user can set a new parent to legend and
56 handle the drawing manually.
56 handle the drawing manually.
57 User isn't supposed to create or delete legend objects, but can reference it via QChart class.
57 User isn't supposed to create or delete legend objects, but can reference it via QChart class.
58
58
59 \image examples_percentbarchart_legend.png
59 \image examples_percentbarchart_legend.png
60
60
61 \sa QChart
61 \sa QChart
62 */
62 */
63 /*!
63 /*!
64 \qmlclass Legend QLegend
64 \qmlclass Legend QLegend
65 \brief Legend is part of QtCommercial Chart QML API.
65 \brief Legend is part of QtCommercial Chart QML API.
66
66
67 Legend is a graphical object, whics displays legend of the chart. Legend state is updated by ChartView, when
67 Legend is a graphical object, whics displays legend of the chart. Legend state is updated by ChartView, when
68 series have been changed. Legend is referenced via ChartView class. For example:
68 series have been changed. Legend is used via ChartView class. For example:
69 \code
69 \code
70 ChartView {
70 ChartView {
71 legend.visible: true
71 legend.visible: true
72 legend.alignment: Qt.AlignBottom
72 legend.alignment: Qt.AlignBottom
73 // Add a few series...
73 // Add a few series...
74 }
74 }
75 \endcode
75 \endcode
76
76
77 \image examples_percentbarchart_legend.png
77 \image examples_percentbarchart_legend.png
78 */
78 */
79
79
80 /*!
80 /*!
81 \property QLegend::alignment
81 \property QLegend::alignment
82 \brief The alignment of the legend.
82 \brief The alignment of the legend.
83
83
84 Legend paints on the defined position in the chart. The following alignments are supported:
84 Legend paints on the defined position in the chart. The following alignments are supported:
85 Qt::AlignTop, Qt::AlignBottom, Qt::AlignLeft, Qt::AlignRight. If you set more than one flag the result is undefined.
85 Qt::AlignTop, Qt::AlignBottom, Qt::AlignLeft, Qt::AlignRight. If you set more than one flag the result is undefined.
86 */
86 */
87 /*!
87 /*!
88 \qmlproperty Qt.Alignment Legend::alignment
88 \qmlproperty Qt.Alignment Legend::alignment
89 \brief The alignment of the legend.
89 \brief The alignment of the legend.
90
90
91 Legend paints on the defined position in the chart. The following alignments are supported:
91 Legend paints on the defined position in the chart. The following alignments are supported:
92 Qt.AlignTop, Qt.AlignBottom, Qt.AlignLeft, Qt.AlignRight. If you set more than one flag the result is undefined.
92 Qt.AlignTop, Qt.AlignBottom, Qt.AlignLeft, Qt.AlignRight. If you set more than one flag the result is undefined.
93 */
93 */
94
94
95 /*!
95 /*!
96 \property QLegend::backgroundVisible
96 \property QLegend::backgroundVisible
97 Whether the legend background is visible or not.
97 Whether the legend background is visible or not.
98 */
98 */
99 /*!
99 /*!
100 \qmlproperty bool Legend::backgroundVisible
100 \qmlproperty bool Legend::backgroundVisible
101 Whether the legend background is visible or not.
101 Whether the legend background is visible or not.
102 */
102 */
103
103
104 /*!
104 /*!
105 \property QLegend::color
105 \property QLegend::color
106 The color of the legend, i.e. the background (brush) color. Note that if you change the color
106 The color of the legend, i.e. the background (brush) color. Note that if you change the color
107 of the legend, the style of the legend brush is set to Qt::SolidPattern.
107 of the legend, the style of the legend brush is set to Qt::SolidPattern.
108 */
108 */
109 /*!
109 /*!
110 \qmlproperty color Legend::color
110 \qmlproperty color Legend::color
111 The color of the legend, i.e. the background (brush) color.
111 The color of the legend, i.e. the background (brush) color.
112 */
112 */
113
113
114 /*!
114 /*!
115 \property QLegend::borderColor
115 \property QLegend::borderColor
116 The border color of the legend, i.e. the line color.
116 The border color of the legend, i.e. the line color.
117 */
117 */
118 /*!
118 /*!
119 \qmlproperty color Legend::borderColor
119 \qmlproperty color Legend::borderColor
120 The border color of the legend, i.e. the line color.
120 The border color of the legend, i.e. the line color.
121 */
121 */
122
122
123 /*!
123 /*!
124 \fn void QLegend::alignmentChanged(Qt::Alignment)
124 \fn void QLegend::alignmentChanged(Qt::Alignment)
125 Emitted when the \a alignment of the legend changes.
125 Emitted when the \a alignment of the legend changes.
126 */
126 */
127
127
128 /*!
128 /*!
129 \fn void QLegend::backgroundVisibleChanged(bool)
129 \fn void QLegend::backgroundVisibleChanged(bool)
130 The visibility of the legend background changed to \a visible.
130 The visibility of the legend background changed to \a visible.
131 */
131 */
132
132
133 /*!
133 /*!
134 \fn void QLegend::colorChanged(QColor)
134 \fn void QLegend::colorChanged(QColor)
135 The color of the legend background changed to \a color.
135 The color of the legend background changed to \a color.
136 */
136 */
137
137
138 /*!
138 /*!
139 \fn void QLegend::borderColorChanged(QColor)
139 \fn void QLegend::borderColorChanged(QColor)
140 The border color of the legend background changed to \a color.
140 The border color of the legend background changed to \a color.
141 */
141 */
142
142
143 /*!
143 /*!
144 \fn qreal QLegend::minWidth() const
144 \fn qreal QLegend::minWidth() const
145 Returns minimum width of the legend
145 Returns minimum width of the legend
146 */
146 */
147
147
148 /*!
148 /*!
149 \fn qreal QLegend::minHeight() const
149 \fn qreal QLegend::minHeight() const
150 Returns minimum height of the legend
150 Returns minimum height of the legend
151 */
151 */
152
152
153 /*!
153 /*!
154 Constructs the legend object and sets the parent to \a parent
154 Constructs the legend object and sets the parent to \a parent
155 */
155 */
156
156
157 QLegend::QLegend(QChart *chart):QGraphicsWidget(chart),
157 QLegend::QLegend(QChart *chart):QGraphicsWidget(chart),
158 d_ptr(new QLegendPrivate(chart->d_ptr->m_presenter,chart,this))
158 d_ptr(new QLegendPrivate(chart->d_ptr->m_presenter,chart,this))
159 {
159 {
160 setZValue(ChartPresenter::LegendZValue);
160 setZValue(ChartPresenter::LegendZValue);
161 setFlags(QGraphicsItem::ItemClipsChildrenToShape);
161 setFlags(QGraphicsItem::ItemClipsChildrenToShape);
162 QObject::connect(chart->d_ptr->m_dataset,SIGNAL(seriesAdded(QAbstractSeries*,Domain*)),d_ptr.data(),SLOT(handleSeriesAdded(QAbstractSeries*,Domain*)));
162 QObject::connect(chart->d_ptr->m_dataset,SIGNAL(seriesAdded(QAbstractSeries*,Domain*)),d_ptr.data(),SLOT(handleSeriesAdded(QAbstractSeries*,Domain*)));
163 QObject::connect(chart->d_ptr->m_dataset,SIGNAL(seriesRemoved(QAbstractSeries*)),d_ptr.data(),SLOT(handleSeriesRemoved(QAbstractSeries*)));
163 QObject::connect(chart->d_ptr->m_dataset,SIGNAL(seriesRemoved(QAbstractSeries*)),d_ptr.data(),SLOT(handleSeriesRemoved(QAbstractSeries*)));
164 QObject::connect(chart->d_ptr->m_dataset,SIGNAL(seriesUpdated(QAbstractSeries*)),d_ptr.data(),SLOT(handleSeriesUpdated(QAbstractSeries*)));
164 QObject::connect(chart->d_ptr->m_dataset,SIGNAL(seriesUpdated(QAbstractSeries*)),d_ptr.data(),SLOT(handleSeriesUpdated(QAbstractSeries*)));
165 }
165 }
166
166
167 /*!
167 /*!
168 Destroys the legend object. Legend is always owned by a QChart, so an application should never call this.
168 Destroys the legend object. Legend is always owned by a QChart, so an application should never call this.
169 */
169 */
170 QLegend::~QLegend()
170 QLegend::~QLegend()
171 {
171 {
172 }
172 }
173
173
174 /*!
174 /*!
175 Paints the legend to given \a painter. Paremeters \a option and \a widget arent used.
175 Paints the legend to given \a painter. Paremeters \a option and \a widget arent used.
176 */
176 */
177
177
178 void QLegend::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget)
178 void QLegend::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget)
179 {
179 {
180 Q_UNUSED(option)
180 Q_UNUSED(option)
181 Q_UNUSED(widget)
181 Q_UNUSED(widget)
182 if(!d_ptr->m_backgroundVisible) return;
182 if(!d_ptr->m_backgroundVisible) return;
183
183
184 painter->setOpacity(opacity());
184 painter->setOpacity(opacity());
185 painter->setPen(d_ptr->m_pen);
185 painter->setPen(d_ptr->m_pen);
186 painter->setBrush(d_ptr->m_brush);
186 painter->setBrush(d_ptr->m_brush);
187 painter->drawRoundRect(rect(),d_ptr->roundness(rect().width()),d_ptr->roundness(rect().height()));
187 painter->drawRoundRect(rect(),d_ptr->roundness(rect().width()),d_ptr->roundness(rect().height()));
188 }
188 }
189
189
190 /*!
190 /*!
191 Bounding rect of legend.
191 Bounding rect of legend.
192 */
192 */
193
193
194 QRectF QLegend::boundingRect() const
194 QRectF QLegend::boundingRect() const
195 {
195 {
196 return d_ptr->m_rect;
196 return d_ptr->m_rect;
197 }
197 }
198
198
199 /*!
199 /*!
200 Sets the \a brush of legend. Brush affects the background of legend.
200 Sets the \a brush of legend. Brush affects the background of legend.
201 */
201 */
202 void QLegend::setBrush(const QBrush &brush)
202 void QLegend::setBrush(const QBrush &brush)
203 {
203 {
204 if (d_ptr->m_brush != brush) {
204 if (d_ptr->m_brush != brush) {
205 d_ptr->m_brush = brush;
205 d_ptr->m_brush = brush;
206 update();
206 update();
207 }
207 }
208 }
208 }
209
209
210 /*!
210 /*!
211 Returns the brush used by legend.
211 Returns the brush used by legend.
212 */
212 */
213 QBrush QLegend::brush() const
213 QBrush QLegend::brush() const
214 {
214 {
215 return d_ptr->m_brush;
215 return d_ptr->m_brush;
216 }
216 }
217
217
218 void QLegend::setColor(QColor color)
218 void QLegend::setColor(QColor color)
219 {
219 {
220 QBrush b = d_ptr->m_brush;
220 QBrush b = d_ptr->m_brush;
221 if (b.style() != Qt::SolidPattern || b.color() != color) {
221 if (b.style() != Qt::SolidPattern || b.color() != color) {
222 b.setStyle(Qt::SolidPattern);
222 b.setStyle(Qt::SolidPattern);
223 b.setColor(color);
223 b.setColor(color);
224 setBrush(b);
224 setBrush(b);
225 emit colorChanged(color);
225 emit colorChanged(color);
226 }
226 }
227 }
227 }
228
228
229 QColor QLegend::color()
229 QColor QLegend::color()
230 {
230 {
231 return d_ptr->m_brush.color();
231 return d_ptr->m_brush.color();
232 }
232 }
233
233
234 /*!
234 /*!
235 Sets the \a pen of legend. Pen affects the legend borders.
235 Sets the \a pen of legend. Pen affects the legend borders.
236 */
236 */
237 void QLegend::setPen(const QPen &pen)
237 void QLegend::setPen(const QPen &pen)
238 {
238 {
239 if (d_ptr->m_pen != pen) {
239 if (d_ptr->m_pen != pen) {
240 d_ptr->m_pen = pen;
240 d_ptr->m_pen = pen;
241 update();
241 update();
242 }
242 }
243 }
243 }
244
244
245 /*!
245 /*!
246 Returns the pen used by legend
246 Returns the pen used by legend
247 */
247 */
248
248
249 QPen QLegend::pen() const
249 QPen QLegend::pen() const
250 {
250 {
251 return d_ptr->m_pen;
251 return d_ptr->m_pen;
252 }
252 }
253
253
254 void QLegend::setBorderColor(QColor color)
254 void QLegend::setBorderColor(QColor color)
255 {
255 {
256 QPen p = d_ptr->m_pen;
256 QPen p = d_ptr->m_pen;
257 if (p.color() != color) {
257 if (p.color() != color) {
258 p.setColor(color);
258 p.setColor(color);
259 setPen(p);
259 setPen(p);
260 emit borderColorChanged(color);
260 emit borderColorChanged(color);
261 }
261 }
262 }
262 }
263
263
264 QColor QLegend::borderColor()
264 QColor QLegend::borderColor()
265 {
265 {
266 return d_ptr->m_pen.color();
266 return d_ptr->m_pen.color();
267 }
267 }
268
268
269 void QLegend::setAlignment(Qt::Alignment alignment)
269 void QLegend::setAlignment(Qt::Alignment alignment)
270 {
270 {
271 if(d_ptr->m_alignment!=alignment) {
271 if(d_ptr->m_alignment!=alignment) {
272 d_ptr->m_alignment = alignment;
272 d_ptr->m_alignment = alignment;
273 d_ptr->updateLayout();
273 d_ptr->updateLayout();
274 alignmentChanged(alignment);
274 alignmentChanged(alignment);
275 }
275 }
276 }
276 }
277
277
278 Qt::Alignment QLegend::alignment() const
278 Qt::Alignment QLegend::alignment() const
279 {
279 {
280 return d_ptr->m_alignment;
280 return d_ptr->m_alignment;
281 }
281 }
282
282
283 /*!
283 /*!
284 Detaches the legend from chart. Chart won't change layout of the legend.
284 Detaches the legend from chart. Chart won't change layout of the legend.
285 */
285 */
286 void QLegend::detachFromChart()
286 void QLegend::detachFromChart()
287 {
287 {
288 d_ptr->m_attachedToChart = false;
288 d_ptr->m_attachedToChart = false;
289 }
289 }
290
290
291 /*!
291 /*!
292 Attaches the legend to chart. Chart may change layout of the legend.
292 Attaches the legend to chart. Chart may change layout of the legend.
293 */
293 */
294 void QLegend::attachToChart()
294 void QLegend::attachToChart()
295 {
295 {
296 d_ptr->attachToChart();
296 d_ptr->attachToChart();
297 }
297 }
298
298
299 /*!
299 /*!
300 Returns true, if legend is attached to chart.
300 Returns true, if legend is attached to chart.
301 */
301 */
302 bool QLegend::isAttachedToChart()
302 bool QLegend::isAttachedToChart()
303 {
303 {
304 return d_ptr->m_attachedToChart;
304 return d_ptr->m_attachedToChart;
305 }
305 }
306
306
307 /*!
307 /*!
308 Sets the visibility of legend background to \a visible
308 Sets the visibility of legend background to \a visible
309 */
309 */
310 void QLegend::setBackgroundVisible(bool visible)
310 void QLegend::setBackgroundVisible(bool visible)
311 {
311 {
312 if(d_ptr->m_backgroundVisible != visible) {
312 if(d_ptr->m_backgroundVisible != visible) {
313 d_ptr->m_backgroundVisible = visible;
313 d_ptr->m_backgroundVisible = visible;
314 update();
314 update();
315 emit backgroundVisibleChanged(visible);
315 emit backgroundVisibleChanged(visible);
316 }
316 }
317 }
317 }
318
318
319 /*!
319 /*!
320 Returns the visibility of legend background
320 Returns the visibility of legend background
321 */
321 */
322 bool QLegend::isBackgroundVisible() const
322 bool QLegend::isBackgroundVisible() const
323 {
323 {
324 return d_ptr->m_backgroundVisible;
324 return d_ptr->m_backgroundVisible;
325 }
325 }
326
326
327 /*!
327 /*!
328 \internal \a event see QGraphicsWidget for details
328 \internal \a event see QGraphicsWidget for details
329 */
329 */
330 void QLegend::resizeEvent(QGraphicsSceneResizeEvent *event)
330 void QLegend::resizeEvent(QGraphicsSceneResizeEvent *event)
331 {
331 {
332 const QRectF& rect = QRectF(QPoint(0,0),event->newSize());
332 const QRectF& rect = QRectF(QPoint(0,0),event->newSize());
333 QGraphicsWidget::resizeEvent(event);
333 QGraphicsWidget::resizeEvent(event);
334 if(d_ptr->m_rect != rect) {
334 if(d_ptr->m_rect != rect) {
335 d_ptr->m_rect = rect;
335 d_ptr->m_rect = rect;
336 d_ptr->updateLayout();
336 d_ptr->updateLayout();
337 }
337 }
338 }
338 }
339
339
340 /*!
340 /*!
341 \internal \a event see QGraphicsWidget for details
341 \internal \a event see QGraphicsWidget for details
342 */
342 */
343 void QLegend::hideEvent(QHideEvent *event)
343 void QLegend::hideEvent(QHideEvent *event)
344 {
344 {
345 QGraphicsWidget::hideEvent(event);
345 QGraphicsWidget::hideEvent(event);
346 setEnabled(false);
346 setEnabled(false);
347 d_ptr->updateLayout();
347 d_ptr->updateLayout();
348 }
348 }
349
349
350 /*!
350 /*!
351 \internal \a event see QGraphicsWidget for details
351 \internal \a event see QGraphicsWidget for details
352 */
352 */
353 void QLegend::showEvent(QShowEvent *event)
353 void QLegend::showEvent(QShowEvent *event)
354 {
354 {
355 QGraphicsWidget::showEvent(event);
355 QGraphicsWidget::showEvent(event);
356 setEnabled(true);
356 setEnabled(true);
357 d_ptr->updateLayout();
357 d_ptr->updateLayout();
358 }
358 }
359
359
360 qreal QLegend::minWidth() const
360 qreal QLegend::minWidth() const
361 {
361 {
362 return d_ptr->m_minWidth;
362 return d_ptr->m_minWidth;
363 }
363 }
364
364
365 qreal QLegend::minHeight() const
365 qreal QLegend::minHeight() const
366 {
366 {
367 return d_ptr->m_minHeight;
367 return d_ptr->m_minHeight;
368 }
368 }
369
369
370 ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
370 ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
371
371
372 QLegendPrivate::QLegendPrivate(ChartPresenter* presenter, QChart *chart, QLegend *q):
372 QLegendPrivate::QLegendPrivate(ChartPresenter* presenter, QChart *chart, QLegend *q):
373 q_ptr(q),
373 q_ptr(q),
374 m_presenter(presenter),
374 m_presenter(presenter),
375 m_chart(chart),
375 m_chart(chart),
376 m_markers(new QGraphicsItemGroup(q)),
376 m_markers(new QGraphicsItemGroup(q)),
377 m_alignment(Qt::AlignTop),
377 m_alignment(Qt::AlignTop),
378 m_brush(QBrush()),
378 m_brush(QBrush()),
379 m_pen(QPen()),
379 m_pen(QPen()),
380 m_offsetX(0),
380 m_offsetX(0),
381 m_offsetY(0),
381 m_offsetY(0),
382 m_minWidth(0),
382 m_minWidth(0),
383 m_minHeight(0),
383 m_minHeight(0),
384 m_width(0),
384 m_width(0),
385 m_height(0),
385 m_height(0),
386 m_diameter(5),
386 m_diameter(5),
387 m_attachedToChart(true),
387 m_attachedToChart(true),
388 m_backgroundVisible(false)
388 m_backgroundVisible(false)
389 {
389 {
390
390
391 }
391 }
392
392
393 QLegendPrivate::~QLegendPrivate()
393 QLegendPrivate::~QLegendPrivate()
394 {
394 {
395
395
396 }
396 }
397
397
398 void QLegendPrivate::setOffset(qreal x, qreal y)
398 void QLegendPrivate::setOffset(qreal x, qreal y)
399 {
399 {
400 bool scrollHorizontal = true;
400 bool scrollHorizontal = true;
401 switch(m_alignment) {
401 switch(m_alignment) {
402 case Qt::AlignTop:
402 case Qt::AlignTop:
403 case Qt::AlignBottom: {
403 case Qt::AlignBottom: {
404 scrollHorizontal = true;
404 scrollHorizontal = true;
405 break;
405 break;
406 }
406 }
407 case Qt::AlignLeft:
407 case Qt::AlignLeft:
408 case Qt::AlignRight: {
408 case Qt::AlignRight: {
409 scrollHorizontal = false;
409 scrollHorizontal = false;
410 break;
410 break;
411 }
411 }
412 }
412 }
413
413
414 // If detached, the scrolling direction is vertical instead of horizontal and vice versa.
414 // If detached, the scrolling direction is vertical instead of horizontal and vice versa.
415 if (!m_attachedToChart) {
415 if (!m_attachedToChart) {
416 scrollHorizontal = !scrollHorizontal;
416 scrollHorizontal = !scrollHorizontal;
417 }
417 }
418
418
419 // Limit offset between m_minOffset and m_maxOffset
419 // Limit offset between m_minOffset and m_maxOffset
420 if (scrollHorizontal) {
420 if (scrollHorizontal) {
421 if(m_width<=m_rect.width()) return;
421 if(m_width<=m_rect.width()) return;
422
422
423 if (x != m_offsetX) {
423 if (x != m_offsetX) {
424 m_offsetX = qBound(m_minOffsetX, x, m_maxOffsetX);
424 m_offsetX = qBound(m_minOffsetX, x, m_maxOffsetX);
425 m_markers->setPos(-m_offsetX,m_rect.top());
425 m_markers->setPos(-m_offsetX,m_rect.top());
426 }
426 }
427 } else {
427 } else {
428 if(m_height<=m_rect.height()) return;
428 if(m_height<=m_rect.height()) return;
429
429
430 if (y != m_offsetY) {
430 if (y != m_offsetY) {
431 m_offsetY = qBound(m_minOffsetY, y, m_maxOffsetY);
431 m_offsetY = qBound(m_minOffsetY, y, m_maxOffsetY);
432 m_markers->setPos(m_rect.left(),-m_offsetY);
432 m_markers->setPos(m_rect.left(),-m_offsetY);
433 }
433 }
434 }
434 }
435 }
435 }
436
436
437 QPointF QLegendPrivate::offset() const
437 QPointF QLegendPrivate::offset() const
438 {
438 {
439 return QPointF(m_offsetX,m_offsetY);
439 return QPointF(m_offsetX,m_offsetY);
440 }
440 }
441
441
442 void QLegendPrivate::updateLayout()
442 void QLegendPrivate::updateLayout()
443 {
443 {
444 if (!m_attachedToChart) {
444 if (!m_attachedToChart) {
445 updateDetachedLayout();
445 updateDetachedLayout();
446 return;
446 return;
447 }
447 }
448
448
449 m_offsetX=0;
449 m_offsetX=0;
450 QList<QGraphicsItem *> items = m_markers->childItems();
450 QList<QGraphicsItem *> items = m_markers->childItems();
451
451
452 if(items.isEmpty()) return;
452 if(items.isEmpty()) return;
453
453
454 m_minWidth=0;
454 m_minWidth=0;
455 m_minHeight=0;
455 m_minHeight=0;
456
456
457 switch(m_alignment) {
457 switch(m_alignment) {
458
458
459 case Qt::AlignTop:
459 case Qt::AlignTop:
460 case Qt::AlignBottom: {
460 case Qt::AlignBottom: {
461 QPointF point = m_rect.topLeft();
461 QPointF point = m_rect.topLeft();
462 m_width = 0;
462 m_width = 0;
463 foreach (QGraphicsItem *item, items) {
463 foreach (QGraphicsItem *item, items) {
464 if (item->isVisible()) {
464 if (item->isVisible()) {
465 item->setPos(point.x(),m_rect.height()/2 -item->boundingRect().height()/2);
465 item->setPos(point.x(),m_rect.height()/2 -item->boundingRect().height()/2);
466 const QRectF& rect = item->boundingRect();
466 const QRectF& rect = item->boundingRect();
467 qreal w = rect.width();
467 qreal w = rect.width();
468 m_minWidth=qMax(m_minWidth,w);
468 m_minWidth=qMax(m_minWidth,w);
469 m_minHeight=qMax(m_minHeight,rect.height());
469 m_minHeight=qMax(m_minHeight,rect.height());
470 m_width+=w;
470 m_width+=w;
471 point.setX(point.x() + w);
471 point.setX(point.x() + w);
472 }
472 }
473 }
473 }
474 if(m_width<m_rect.width()) {
474 if(m_width<m_rect.width()) {
475 m_markers->setPos(m_rect.width()/2-m_width/2,m_rect.top());
475 m_markers->setPos(m_rect.width()/2-m_width/2,m_rect.top());
476 }
476 }
477 else {
477 else {
478 m_markers->setPos(m_rect.topLeft());
478 m_markers->setPos(m_rect.topLeft());
479 }
479 }
480 m_height=m_minHeight;
480 m_height=m_minHeight;
481 }
481 }
482 break;
482 break;
483 case Qt::AlignLeft:
483 case Qt::AlignLeft:
484 case Qt::AlignRight: {
484 case Qt::AlignRight: {
485 QPointF point = m_rect.topLeft();
485 QPointF point = m_rect.topLeft();
486 m_height = 0;
486 m_height = 0;
487 foreach (QGraphicsItem *item, items) {
487 foreach (QGraphicsItem *item, items) {
488 if (item->isVisible()) {
488 if (item->isVisible()) {
489 item->setPos(point);
489 item->setPos(point);
490 const QRectF& rect = item->boundingRect();
490 const QRectF& rect = item->boundingRect();
491 qreal h = rect.height();
491 qreal h = rect.height();
492 m_minWidth=qMax(m_minWidth,rect.width());
492 m_minWidth=qMax(m_minWidth,rect.width());
493 m_minHeight=qMax(m_minHeight,h);
493 m_minHeight=qMax(m_minHeight,h);
494 m_height+=h;
494 m_height+=h;
495 point.setY(point.y() + h);
495 point.setY(point.y() + h);
496 }
496 }
497 }
497 }
498 if(m_height<m_rect.height()) {
498 if(m_height<m_rect.height()) {
499 m_markers->setPos(m_rect.left(),m_rect.height()/2-m_height/2);
499 m_markers->setPos(m_rect.left(),m_rect.height()/2-m_height/2);
500 }
500 }
501 else {
501 else {
502 m_markers->setPos(m_rect.topLeft());
502 m_markers->setPos(m_rect.topLeft());
503 }
503 }
504 m_width=m_minWidth;
504 m_width=m_minWidth;
505 }
505 }
506 break;
506 break;
507 }
507 }
508
508
509 m_minOffsetX = 0;
509 m_minOffsetX = 0;
510 m_minOffsetY = 0;
510 m_minOffsetY = 0;
511 m_maxOffsetX = m_width - m_rect.width();
511 m_maxOffsetX = m_width - m_rect.width();
512 m_maxOffsetY = m_height - m_rect.height();
512 m_maxOffsetY = m_height - m_rect.height();
513
513
514 m_presenter->updateLayout();
514 m_presenter->updateLayout();
515 }
515 }
516
516
517 void QLegendPrivate::updateDetachedLayout()
517 void QLegendPrivate::updateDetachedLayout()
518 {
518 {
519 // Detached layout is different.
519 // Detached layout is different.
520 // In detached mode legend may have multiple rows and columns, so layout calculations
520 // In detached mode legend may have multiple rows and columns, so layout calculations
521 // differ a log from attached mode.
521 // differ a log from attached mode.
522 // Also the scrolling logic is bit different.
522 // Also the scrolling logic is bit different.
523 m_offsetX=0;
523 m_offsetX=0;
524 m_offsetY=0;
524 m_offsetY=0;
525 QList<QGraphicsItem *> items = m_markers->childItems();
525 QList<QGraphicsItem *> items = m_markers->childItems();
526
526
527 if(items.isEmpty()) return;
527 if(items.isEmpty()) return;
528
528
529 m_minWidth = 0;
529 m_minWidth = 0;
530 m_minHeight = 0;
530 m_minHeight = 0;
531
531
532 switch (m_alignment) {
532 switch (m_alignment) {
533 case Qt::AlignTop: {
533 case Qt::AlignTop: {
534 QPointF point = m_rect.topLeft();
534 QPointF point = m_rect.topLeft();
535 m_width = 0;
535 m_width = 0;
536 m_height = 0;
536 m_height = 0;
537 for (int i=0; i<items.count(); i++) {
537 for (int i=0; i<items.count(); i++) {
538 QGraphicsItem *item = items.at(i);
538 QGraphicsItem *item = items.at(i);
539 if (item->isVisible()) {
539 if (item->isVisible()) {
540 const QRectF& rect = item->boundingRect();
540 const QRectF& rect = item->boundingRect();
541 qreal w = rect.width();
541 qreal w = rect.width();
542 qreal h = rect.height();
542 qreal h = rect.height();
543 m_minWidth = qMax(m_minWidth,w);
543 m_minWidth = qMax(m_minWidth,w);
544 m_minHeight = qMax(m_minHeight,rect.height());
544 m_minHeight = qMax(m_minHeight,rect.height());
545 m_height = qMax(m_height,h);
545 m_height = qMax(m_height,h);
546 item->setPos(point.x(),point.y());
546 item->setPos(point.x(),point.y());
547 point.setX(point.x() + w);
547 point.setX(point.x() + w);
548 if (point.x() + w > m_rect.topLeft().x() + m_rect.width()) {
548 if (point.x() + w > m_rect.topLeft().x() + m_rect.width()) {
549 // Next item would go off rect.
549 // Next item would go off rect.
550 point.setX(m_rect.topLeft().x());
550 point.setX(m_rect.topLeft().x());
551 point.setY(point.y() + h);
551 point.setY(point.y() + h);
552 if (i+1 < items.count()) {
552 if (i+1 < items.count()) {
553 m_height += h;
553 m_height += h;
554 }
554 }
555 }
555 }
556 }
556 }
557 }
557 }
558 m_markers->setPos(m_rect.topLeft());
558 m_markers->setPos(m_rect.topLeft());
559 m_width = m_minWidth;
559 m_width = m_minWidth;
560
560
561 m_minOffsetX = 0;
561 m_minOffsetX = 0;
562 m_minOffsetY = 0;
562 m_minOffsetY = 0;
563 m_maxOffsetX = m_width - m_rect.width();
563 m_maxOffsetX = m_width - m_rect.width();
564 m_maxOffsetY = m_height - m_rect.height();
564 m_maxOffsetY = m_height - m_rect.height();
565 }
565 }
566 break;
566 break;
567 case Qt::AlignBottom: {
567 case Qt::AlignBottom: {
568 QPointF point = m_rect.bottomLeft();
568 QPointF point = m_rect.bottomLeft();
569 m_width = 0;
569 m_width = 0;
570 m_height = 0;
570 m_height = 0;
571 for (int i=0; i<items.count(); i++) {
571 for (int i=0; i<items.count(); i++) {
572 QGraphicsItem *item = items.at(i);
572 QGraphicsItem *item = items.at(i);
573 if (item->isVisible()) {
573 if (item->isVisible()) {
574 const QRectF& rect = item->boundingRect();
574 const QRectF& rect = item->boundingRect();
575 qreal w = rect.width();
575 qreal w = rect.width();
576 qreal h = rect.height();
576 qreal h = rect.height();
577 m_minWidth = qMax(m_minWidth,w);
577 m_minWidth = qMax(m_minWidth,w);
578 m_minHeight = qMax(m_minHeight,rect.height());
578 m_minHeight = qMax(m_minHeight,rect.height());
579 m_height = qMax(m_height,h);
579 m_height = qMax(m_height,h);
580 item->setPos(point.x(),point.y() - h);
580 item->setPos(point.x(),point.y() - h);
581 point.setX(point.x() + w);
581 point.setX(point.x() + w);
582 if (point.x() + w > m_rect.bottomLeft().x() + m_rect.width()) {
582 if (point.x() + w > m_rect.bottomLeft().x() + m_rect.width()) {
583 // Next item would go off rect.
583 // Next item would go off rect.
584 point.setX(m_rect.bottomLeft().x());
584 point.setX(m_rect.bottomLeft().x());
585 point.setY(point.y() - h);
585 point.setY(point.y() - h);
586 if (i+1 < items.count()) {
586 if (i+1 < items.count()) {
587 m_height += h;
587 m_height += h;
588 }
588 }
589 }
589 }
590 }
590 }
591 }
591 }
592 m_markers->setPos(m_rect.topLeft());
592 m_markers->setPos(m_rect.topLeft());
593 m_width = m_minWidth;
593 m_width = m_minWidth;
594
594
595 m_minOffsetX = 0;
595 m_minOffsetX = 0;
596 m_minOffsetY = qMin(m_rect.topLeft().y(), m_rect.topLeft().y() - m_height + m_rect.height());
596 m_minOffsetY = qMin(m_rect.topLeft().y(), m_rect.topLeft().y() - m_height + m_rect.height());
597 m_maxOffsetX = m_width - m_rect.width();
597 m_maxOffsetX = m_width - m_rect.width();
598 m_maxOffsetY = 0;
598 m_maxOffsetY = 0;
599 }
599 }
600 break;
600 break;
601 case Qt::AlignLeft: {
601 case Qt::AlignLeft: {
602 QPointF point = m_rect.topLeft();
602 QPointF point = m_rect.topLeft();
603 m_width = 0;
603 m_width = 0;
604 m_height = 0;
604 m_height = 0;
605 qreal maxWidth = 0;
605 qreal maxWidth = 0;
606 for (int i=0; i<items.count(); i++) {
606 for (int i=0; i<items.count(); i++) {
607 QGraphicsItem *item = items.at(i);
607 QGraphicsItem *item = items.at(i);
608 if (item->isVisible()) {
608 if (item->isVisible()) {
609 const QRectF& rect = item->boundingRect();
609 const QRectF& rect = item->boundingRect();
610 qreal w = rect.width();
610 qreal w = rect.width();
611 qreal h = rect.height();
611 qreal h = rect.height();
612 m_minWidth = qMax(m_minWidth,rect.width());
612 m_minWidth = qMax(m_minWidth,rect.width());
613 m_minHeight = qMax(m_minHeight,h);
613 m_minHeight = qMax(m_minHeight,h);
614 maxWidth = qMax(maxWidth,w);
614 maxWidth = qMax(maxWidth,w);
615 item->setPos(point.x(),point.y());
615 item->setPos(point.x(),point.y());
616 point.setY(point.y() + h);
616 point.setY(point.y() + h);
617 if (point.y() + h > m_rect.topLeft().y() + m_rect.height()) {
617 if (point.y() + h > m_rect.topLeft().y() + m_rect.height()) {
618 // Next item would go off rect.
618 // Next item would go off rect.
619 point.setX(point.x() + maxWidth);
619 point.setX(point.x() + maxWidth);
620 point.setY(m_rect.topLeft().y());
620 point.setY(m_rect.topLeft().y());
621 if (i+1 < items.count()) {
621 if (i+1 < items.count()) {
622 m_width += maxWidth;
622 m_width += maxWidth;
623 maxWidth = 0;
623 maxWidth = 0;
624 }
624 }
625 }
625 }
626 }
626 }
627 }
627 }
628 m_width += maxWidth;
628 m_width += maxWidth;
629 m_markers->setPos(m_rect.topLeft());
629 m_markers->setPos(m_rect.topLeft());
630 m_height = m_minHeight;
630 m_height = m_minHeight;
631
631
632 m_minOffsetX = 0;
632 m_minOffsetX = 0;
633 m_minOffsetY = 0;
633 m_minOffsetY = 0;
634 m_maxOffsetX = m_width - m_rect.width();
634 m_maxOffsetX = m_width - m_rect.width();
635 m_maxOffsetY = m_height - m_rect.height();
635 m_maxOffsetY = m_height - m_rect.height();
636 }
636 }
637 break;
637 break;
638 case Qt::AlignRight: {
638 case Qt::AlignRight: {
639 QPointF point = m_rect.topRight();
639 QPointF point = m_rect.topRight();
640 m_width = 0;
640 m_width = 0;
641 m_height = 0;
641 m_height = 0;
642 qreal maxWidth = 0;
642 qreal maxWidth = 0;
643 for (int i=0; i<items.count(); i++) {
643 for (int i=0; i<items.count(); i++) {
644 QGraphicsItem *item = items.at(i);
644 QGraphicsItem *item = items.at(i);
645 if (item->isVisible()) {
645 if (item->isVisible()) {
646 const QRectF& rect = item->boundingRect();
646 const QRectF& rect = item->boundingRect();
647 qreal w = rect.width();
647 qreal w = rect.width();
648 qreal h = rect.height();
648 qreal h = rect.height();
649 m_minWidth = qMax(m_minWidth,rect.width());
649 m_minWidth = qMax(m_minWidth,rect.width());
650 m_minHeight = qMax(m_minHeight,h);
650 m_minHeight = qMax(m_minHeight,h);
651 maxWidth = qMax(maxWidth,w);
651 maxWidth = qMax(maxWidth,w);
652 item->setPos(point.x() - w,point.y());
652 item->setPos(point.x() - w,point.y());
653 point.setY(point.y() + h);
653 point.setY(point.y() + h);
654 if (point.y() + h > m_rect.topLeft().y() + m_rect.height()) {
654 if (point.y() + h > m_rect.topLeft().y() + m_rect.height()) {
655 // Next item would go off rect.
655 // Next item would go off rect.
656 point.setX(point.x() - maxWidth);
656 point.setX(point.x() - maxWidth);
657 point.setY(m_rect.topLeft().y());
657 point.setY(m_rect.topLeft().y());
658 if (i+1 < items.count()) {
658 if (i+1 < items.count()) {
659 m_width += maxWidth;
659 m_width += maxWidth;
660 maxWidth = 0;
660 maxWidth = 0;
661 }
661 }
662 }
662 }
663 }
663 }
664 }
664 }
665 m_width += maxWidth;
665 m_width += maxWidth;
666 m_markers->setPos(m_rect.topLeft());
666 m_markers->setPos(m_rect.topLeft());
667 m_height = m_minHeight;
667 m_height = m_minHeight;
668
668
669 m_minOffsetX = qMin(m_rect.topLeft().x(), m_rect.topLeft().x() - m_width + m_rect.width());
669 m_minOffsetX = qMin(m_rect.topLeft().x(), m_rect.topLeft().x() - m_width + m_rect.width());
670 m_minOffsetY = 0;
670 m_minOffsetY = 0;
671 m_maxOffsetX = 0;
671 m_maxOffsetX = 0;
672 m_maxOffsetY = m_height - m_rect.height();
672 m_maxOffsetY = m_height - m_rect.height();
673 }
673 }
674 break;
674 break;
675 default:
675 default:
676 break;
676 break;
677 }
677 }
678 }
678 }
679
679
680 void QLegendPrivate::attachToChart()
680 void QLegendPrivate::attachToChart()
681 {
681 {
682 m_attachedToChart = true;
682 m_attachedToChart = true;
683 q_ptr->setParent(m_chart);
683 q_ptr->setParent(m_chart);
684 }
684 }
685
685
686 int QLegendPrivate::roundness(qreal size)
686 int QLegendPrivate::roundness(qreal size)
687 {
687 {
688 return 100*m_diameter/int(size);
688 return 100*m_diameter/int(size);
689 }
689 }
690
690
691 void QLegendPrivate::handleSeriesAdded(QAbstractSeries *series, Domain *domain)
691 void QLegendPrivate::handleSeriesAdded(QAbstractSeries *series, Domain *domain)
692 {
692 {
693 Q_UNUSED(domain)
693 Q_UNUSED(domain)
694
694
695 QList<LegendMarker*> markers = series->d_ptr->createLegendMarker(q_ptr);
695 QList<LegendMarker*> markers = series->d_ptr->createLegendMarker(q_ptr);
696 foreach(LegendMarker* marker, markers)
696 foreach(LegendMarker* marker, markers)
697 m_markers->addToGroup(marker);
697 m_markers->addToGroup(marker);
698
698
699 QObject::connect(series, SIGNAL(visibleChanged()), this, SLOT(handleSeriesVisibleChanged()));
699 QObject::connect(series, SIGNAL(visibleChanged()), this, SLOT(handleSeriesVisibleChanged()));
700
700
701 if(series->type() == QAbstractSeries::SeriesTypePie) {
701 if(series->type() == QAbstractSeries::SeriesTypePie) {
702 QPieSeries *pieSeries = static_cast<QPieSeries *>(series);
702 QPieSeries *pieSeries = static_cast<QPieSeries *>(series);
703 QObject::connect(pieSeries, SIGNAL(added(QList<QPieSlice*>)), this, SLOT(handleUpdatePieSeries()));
703 QObject::connect(pieSeries, SIGNAL(added(QList<QPieSlice*>)), this, SLOT(handleUpdatePieSeries()));
704 QObject::connect(pieSeries, SIGNAL(removed(QList<QPieSlice*>)), this, SLOT(handleUpdatePieSeries()));
704 QObject::connect(pieSeries, SIGNAL(removed(QList<QPieSlice*>)), this, SLOT(handleUpdatePieSeries()));
705 }
705 }
706
706
707 updateLayout();
707 updateLayout();
708 }
708 }
709
709
710 void QLegendPrivate::handleSeriesRemoved(QAbstractSeries *series)
710 void QLegendPrivate::handleSeriesRemoved(QAbstractSeries *series)
711 {
711 {
712 QList<QGraphicsItem *> items = m_markers->childItems();
712 QList<QGraphicsItem *> items = m_markers->childItems();
713
713
714 foreach (QGraphicsItem *markers, items) {
714 foreach (QGraphicsItem *markers, items) {
715 LegendMarker *marker = static_cast<LegendMarker*>(markers);
715 LegendMarker *marker = static_cast<LegendMarker*>(markers);
716 if (marker->series() == series) {
716 if (marker->series() == series) {
717 delete marker;
717 delete marker;
718 }
718 }
719 }
719 }
720
720
721 if(series->type() == QAbstractSeries::SeriesTypePie)
721 if(series->type() == QAbstractSeries::SeriesTypePie)
722 {
722 {
723 QPieSeries *pieSeries = static_cast<QPieSeries *>(series);
723 QPieSeries *pieSeries = static_cast<QPieSeries *>(series);
724 QObject::disconnect(pieSeries, SIGNAL(added(QList<QPieSlice*>)), this, SLOT(handleUpdatePieSeries()));
724 QObject::disconnect(pieSeries, SIGNAL(added(QList<QPieSlice*>)), this, SLOT(handleUpdatePieSeries()));
725 QObject::disconnect(pieSeries, SIGNAL(removed(QList<QPieSlice*>)), this, SLOT(handleUpdatePieSeries()));
725 QObject::disconnect(pieSeries, SIGNAL(removed(QList<QPieSlice*>)), this, SLOT(handleUpdatePieSeries()));
726 }
726 }
727
727
728 updateLayout();
728 updateLayout();
729 }
729 }
730
730
731 void QLegendPrivate::handleSeriesUpdated(QAbstractSeries *series)
731 void QLegendPrivate::handleSeriesUpdated(QAbstractSeries *series)
732 {
732 {
733 // TODO: find out which markers are are added or removed. Update them
733 // TODO: find out which markers are are added or removed. Update them
734 // TODO: better implementation
734 // TODO: better implementation
735 handleSeriesRemoved(series);
735 handleSeriesRemoved(series);
736 Domain domain;
736 Domain domain;
737 handleSeriesAdded(series, &domain);
737 handleSeriesAdded(series, &domain);
738 }
738 }
739
739
740 void QLegendPrivate::handleUpdatePieSeries()
740 void QLegendPrivate::handleUpdatePieSeries()
741 {
741 {
742 //TODO: reimplement to be optimal
742 //TODO: reimplement to be optimal
743 QPieSeries* series = qobject_cast<QPieSeries *> (sender());
743 QPieSeries* series = qobject_cast<QPieSeries *> (sender());
744 Q_ASSERT(series);
744 Q_ASSERT(series);
745 handleSeriesRemoved(series);
745 handleSeriesRemoved(series);
746 handleSeriesAdded(series, 0);
746 handleSeriesAdded(series, 0);
747 }
747 }
748
748
749 void QLegendPrivate::handleSeriesVisibleChanged()
749 void QLegendPrivate::handleSeriesVisibleChanged()
750 {
750 {
751 QAbstractSeries* series = qobject_cast<QAbstractSeries *> (sender());
751 QAbstractSeries* series = qobject_cast<QAbstractSeries *> (sender());
752 QList<QGraphicsItem *> items = m_markers->childItems();
752 QList<QGraphicsItem *> items = m_markers->childItems();
753
753
754 foreach (QGraphicsItem *markers, items) {
754 foreach (QGraphicsItem *markers, items) {
755 LegendMarker *marker = static_cast<LegendMarker*>(markers);
755 LegendMarker *marker = static_cast<LegendMarker*>(markers);
756 if (marker->series() == series) {
756 if (marker->series() == series) {
757 marker->setVisible(!marker->isVisible());
757 marker->setVisible(!marker->isVisible());
758 }
758 }
759 }
759 }
760
760
761 updateLayout();
761 updateLayout();
762 }
762 }
763
763
764
764
765 #include "moc_qlegend.cpp"
765 #include "moc_qlegend.cpp"
766 #include "moc_qlegend_p.cpp"
766 #include "moc_qlegend_p.cpp"
767
767
768 QTCOMMERCIALCHART_END_NAMESPACE
768 QTCOMMERCIALCHART_END_NAMESPACE
General Comments 0
You need to be logged in to leave comments. Login now