##// END OF EJS Templates
Added property definitions to QChart
Tero Ahola -
r1524:0b7cf651b670
parent child
Show More
@@ -1,262 +1,261
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 "mainwidget.h"
21 #include "mainwidget.h"
22 #include <QChart>
22 #include <QChart>
23 #include <QChartView>
23 #include <QChartView>
24 #include <QPushButton>
24 #include <QPushButton>
25 #include <QLabel>
25 #include <QLabel>
26 #include <QDebug>
26 #include <QDebug>
27 #include <QBarSet>
27 #include <QBarSet>
28 #include <QBarSeries>
28 #include <QBarSeries>
29 #include <QLegend>
29 #include <QLegend>
30 #include <QFormLayout>
30 #include <QFormLayout>
31
31
32 QTCOMMERCIALCHART_USE_NAMESPACE
32 QTCOMMERCIALCHART_USE_NAMESPACE
33
33
34 MainWidget::MainWidget(QWidget *parent) :
34 MainWidget::MainWidget(QWidget *parent) :
35 QWidget(parent)
35 QWidget(parent)
36 {
36 {
37 // Create buttons for ui
37 // Create buttons for ui
38 m_buttonLayout = new QGridLayout();
38 m_buttonLayout = new QGridLayout();
39 QPushButton *detachLegendButton = new QPushButton("detach legend");
39 QPushButton *detachLegendButton = new QPushButton("detach legend");
40 connect(detachLegendButton, SIGNAL(clicked()), this, SLOT(detachLegend()));
40 connect(detachLegendButton, SIGNAL(clicked()), this, SLOT(detachLegend()));
41 m_buttonLayout->addWidget(detachLegendButton, 0, 0);
41 m_buttonLayout->addWidget(detachLegendButton, 0, 0);
42 QPushButton *attachLegendButton = new QPushButton("attach legend");
42 QPushButton *attachLegendButton = new QPushButton("attach legend");
43 connect(attachLegendButton, SIGNAL(clicked()), this, SLOT(attachLegend()));
43 connect(attachLegendButton, SIGNAL(clicked()), this, SLOT(attachLegend()));
44 m_buttonLayout->addWidget(attachLegendButton, 1, 0);
44 m_buttonLayout->addWidget(attachLegendButton, 1, 0);
45
45
46 QPushButton *addSetButton = new QPushButton("add barset");
46 QPushButton *addSetButton = new QPushButton("add barset");
47 connect(addSetButton, SIGNAL(clicked()), this, SLOT(addBarset()));
47 connect(addSetButton, SIGNAL(clicked()), this, SLOT(addBarset()));
48 m_buttonLayout->addWidget(addSetButton, 2, 0);
48 m_buttonLayout->addWidget(addSetButton, 2, 0);
49 QPushButton *removeBarsetButton = new QPushButton("remove barset");
49 QPushButton *removeBarsetButton = new QPushButton("remove barset");
50 connect(removeBarsetButton, SIGNAL(clicked()), this, SLOT(removeBarset()));
50 connect(removeBarsetButton, SIGNAL(clicked()), this, SLOT(removeBarset()));
51 m_buttonLayout->addWidget(removeBarsetButton, 3, 0);
51 m_buttonLayout->addWidget(removeBarsetButton, 3, 0);
52
52
53 QPushButton *leftButton = new QPushButton("Align legend left");
53 QPushButton *leftButton = new QPushButton("Align legend left");
54 connect(leftButton, SIGNAL(clicked()), this, SLOT(setLegendLeft()));
54 connect(leftButton, SIGNAL(clicked()), this, SLOT(setLegendLeft()));
55 m_buttonLayout->addWidget(leftButton, 4, 0);
55 m_buttonLayout->addWidget(leftButton, 4, 0);
56
56
57 QPushButton *rightButton = new QPushButton("Align legend right");
57 QPushButton *rightButton = new QPushButton("Align legend right");
58 connect(rightButton, SIGNAL(clicked()), this, SLOT(setLegendRight()));
58 connect(rightButton, SIGNAL(clicked()), this, SLOT(setLegendRight()));
59 m_buttonLayout->addWidget(rightButton, 5, 0);
59 m_buttonLayout->addWidget(rightButton, 5, 0);
60
60
61 QPushButton *topButton = new QPushButton("Align legend top");
61 QPushButton *topButton = new QPushButton("Align legend top");
62 connect(topButton, SIGNAL(clicked()), this, SLOT(setLegendTop()));
62 connect(topButton, SIGNAL(clicked()), this, SLOT(setLegendTop()));
63 m_buttonLayout->addWidget(topButton, 6, 0);
63 m_buttonLayout->addWidget(topButton, 6, 0);
64
64
65 QPushButton *bottomButton = new QPushButton("Align legend bottom");
65 QPushButton *bottomButton = new QPushButton("Align legend bottom");
66 connect(bottomButton, SIGNAL(clicked()), this, SLOT(setLegendBottom()));
66 connect(bottomButton, SIGNAL(clicked()), this, SLOT(setLegendBottom()));
67 m_buttonLayout->addWidget(bottomButton, 7, 0);
67 m_buttonLayout->addWidget(bottomButton, 7, 0);
68
68
69 QPushButton *boldButton = new QPushButton("Toggle bold");
69 QPushButton *boldButton = new QPushButton("Toggle bold");
70 connect(boldButton, SIGNAL(clicked()), this, SLOT(toggleBold()));
70 connect(boldButton, SIGNAL(clicked()), this, SLOT(toggleBold()));
71 m_buttonLayout->addWidget(boldButton, 8, 0);
71 m_buttonLayout->addWidget(boldButton, 8, 0);
72
72
73 QPushButton *italicButton = new QPushButton("Toggle italic");
73 QPushButton *italicButton = new QPushButton("Toggle italic");
74 connect(italicButton, SIGNAL(clicked()), this, SLOT(toggleItalic()));
74 connect(italicButton, SIGNAL(clicked()), this, SLOT(toggleItalic()));
75 m_buttonLayout->addWidget(italicButton, 9, 0);
75 m_buttonLayout->addWidget(italicButton, 9, 0);
76
76
77 m_legendPosX = new QDoubleSpinBox();
77 m_legendPosX = new QDoubleSpinBox();
78 m_legendPosY = new QDoubleSpinBox();
78 m_legendPosY = new QDoubleSpinBox();
79 m_legendWidth = new QDoubleSpinBox();
79 m_legendWidth = new QDoubleSpinBox();
80 m_legendHeight = new QDoubleSpinBox();
80 m_legendHeight = new QDoubleSpinBox();
81
81
82 connect(m_legendPosX, SIGNAL(valueChanged(double)), this, SLOT(updateLegendLayout()));
82 connect(m_legendPosX, SIGNAL(valueChanged(double)), this, SLOT(updateLegendLayout()));
83 connect(m_legendPosY, SIGNAL(valueChanged(double)), this, SLOT(updateLegendLayout()));
83 connect(m_legendPosY, SIGNAL(valueChanged(double)), this, SLOT(updateLegendLayout()));
84 connect(m_legendWidth, SIGNAL(valueChanged(double)), this, SLOT(updateLegendLayout()));
84 connect(m_legendWidth, SIGNAL(valueChanged(double)), this, SLOT(updateLegendLayout()));
85 connect(m_legendHeight, SIGNAL(valueChanged(double)), this, SLOT(updateLegendLayout()));
85 connect(m_legendHeight, SIGNAL(valueChanged(double)), this, SLOT(updateLegendLayout()));
86
86
87 QFormLayout* legendLayout = new QFormLayout();
87 QFormLayout* legendLayout = new QFormLayout();
88 legendLayout->addRow("Horizontal position", m_legendPosX);
88 legendLayout->addRow("Horizontal position", m_legendPosX);
89 legendLayout->addRow("Vertical position", m_legendPosY);
89 legendLayout->addRow("Vertical position", m_legendPosY);
90 legendLayout->addRow("Width", m_legendWidth);
90 legendLayout->addRow("Width", m_legendWidth);
91 legendLayout->addRow("Height", m_legendHeight);
91 legendLayout->addRow("Height", m_legendHeight);
92 m_legendSettings = new QGroupBox("Detached legend");
92 m_legendSettings = new QGroupBox("Detached legend");
93 m_legendSettings->setLayout(legendLayout);
93 m_legendSettings->setLayout(legendLayout);
94 m_buttonLayout->addWidget(m_legendSettings);
94 m_buttonLayout->addWidget(m_legendSettings);
95 m_legendSettings->setVisible(false);
95 m_legendSettings->setVisible(false);
96
96
97 // Create chart view with the chart
97 // Create chart view with the chart
98 m_chart = new QChart();
98 m_chart = new QChart();
99 m_chartView = new QChartView(m_chart, this);
99 m_chartView = new QChartView(m_chart, this);
100
100
101 // Create spinbox to modify font size
101 // Create spinbox to modify font size
102 m_fontSize = new QDoubleSpinBox();
102 m_fontSize = new QDoubleSpinBox();
103 m_fontSize->setValue(m_chart->legend()->font().pointSizeF());
103 m_fontSize->setValue(m_chart->legend()->font().pointSizeF());
104 connect(m_fontSize, SIGNAL(valueChanged(double)), this, SLOT(fontSizeChanged()));
104 connect(m_fontSize, SIGNAL(valueChanged(double)), this, SLOT(fontSizeChanged()));
105
105
106 QFormLayout* fontLayout = new QFormLayout();
106 QFormLayout* fontLayout = new QFormLayout();
107 fontLayout->addRow("Legend font size", m_fontSize);
107 fontLayout->addRow("Legend font size", m_fontSize);
108
108
109 // Create layout for grid and detached legend
109 // Create layout for grid and detached legend
110 m_mainLayout = new QGridLayout();
110 m_mainLayout = new QGridLayout();
111 m_mainLayout->addLayout(m_buttonLayout, 0, 0);
111 m_mainLayout->addLayout(m_buttonLayout, 0, 0);
112 m_mainLayout->addLayout(fontLayout,1,0);
112 m_mainLayout->addLayout(fontLayout,1,0);
113 m_mainLayout->addWidget(m_chartView, 0, 1, 3, 1);
113 m_mainLayout->addWidget(m_chartView, 0, 1, 3, 1);
114 setLayout(m_mainLayout);
114 setLayout(m_mainLayout);
115
115
116 createSeries();
116 createSeries();
117 }
117 }
118
118
119 void MainWidget::createSeries()
119 void MainWidget::createSeries()
120 {
120 {
121 m_series = new QBarSeries();
121 m_series = new QBarSeries();
122 addBarset();
122 addBarset();
123 addBarset();
123 addBarset();
124 addBarset();
124 addBarset();
125 addBarset();
125 addBarset();
126
126
127 m_chart->addSeries(m_series);
127 m_chart->addSeries(m_series);
128 m_chart->setTitle("Legend detach example");
128 m_chart->setTitle("Legend detach example");
129 //![1]
129 //![1]
130 m_chart->legend()->setVisible(true);
130 m_chart->legend()->setVisible(true);
131 m_chart->legend()->setAlignment(Qt::AlignBottom);
131 m_chart->legend()->setAlignment(Qt::AlignBottom);
132 //![1]
132 //![1]
133
133
134 m_chart->axisY()->setNiceNumbersEnabled(true);
134 m_chart->axisY()->setNiceNumbersEnabled(true);
135 m_chartView->setRenderHint(QPainter::Antialiasing);
135 m_chartView->setRenderHint(QPainter::Antialiasing);
136 }
136 }
137
137
138 void MainWidget::showLegendSpinbox()
138 void MainWidget::showLegendSpinbox()
139 {
139 {
140 m_legendSettings->setVisible(true);
140 m_legendSettings->setVisible(true);
141 QRectF chartViewRect = m_chartView->rect();
141 QRectF chartViewRect = m_chartView->rect();
142 QRectF legendRect = m_chart->legend()->boundingRect();
143
142
144 m_legendPosX->setMinimum(0);
143 m_legendPosX->setMinimum(0);
145 m_legendPosX->setMaximum(chartViewRect.width());
144 m_legendPosX->setMaximum(chartViewRect.width());
146 m_legendPosX->setValue(150);
145 m_legendPosX->setValue(150);
147
146
148 m_legendPosY->setMinimum(0);
147 m_legendPosY->setMinimum(0);
149 m_legendPosY->setMaximum(chartViewRect.height());
148 m_legendPosY->setMaximum(chartViewRect.height());
150 m_legendPosY->setValue(150);
149 m_legendPosY->setValue(150);
151
150
152 m_legendWidth->setMinimum(0);
151 m_legendWidth->setMinimum(0);
153 m_legendWidth->setMaximum(chartViewRect.width());
152 m_legendWidth->setMaximum(chartViewRect.width());
154 m_legendWidth->setValue(150);
153 m_legendWidth->setValue(150);
155
154
156 m_legendHeight->setMinimum(0);
155 m_legendHeight->setMinimum(0);
157 m_legendHeight->setMaximum(chartViewRect.height());
156 m_legendHeight->setMaximum(chartViewRect.height());
158 m_legendHeight->setValue(75);
157 m_legendHeight->setValue(75);
159 }
158 }
160
159
161 void MainWidget::hideLegendSpinbox()
160 void MainWidget::hideLegendSpinbox()
162 {
161 {
163 m_legendSettings->setVisible(false);
162 m_legendSettings->setVisible(false);
164 }
163 }
165
164
166
165
167 void MainWidget::detachLegend()
166 void MainWidget::detachLegend()
168 {
167 {
169 //![2]
168 //![2]
170 QLegend *legend = m_chart->legend();
169 QLegend *legend = m_chart->legend();
171 legend->detachFromChart();
170 legend->detachFromChart();
172
171
173 m_chart->legend()->setBackgroundVisible(true);
172 m_chart->legend()->setBackgroundVisible(true);
174 m_chart->legend()->setBrush(QBrush(QColor(128,128,128,128)));
173 m_chart->legend()->setBrush(QBrush(QColor(128,128,128,128)));
175 m_chart->legend()->setPen(QPen(QColor(192,192,192,192)));
174 m_chart->legend()->setPen(QPen(QColor(192,192,192,192)));
176 //![2]
175 //![2]
177
176
178 showLegendSpinbox();
177 showLegendSpinbox();
179 updateLegendLayout();
178 updateLegendLayout();
180 update();
179 update();
181 }
180 }
182
181
183
182
184 void MainWidget::attachLegend()
183 void MainWidget::attachLegend()
185 {
184 {
186 //![3]
185 //![3]
187 QLegend *legend = m_chart->legend();
186 QLegend *legend = m_chart->legend();
188 legend->attachToChart();
187 legend->attachToChart();
189 m_chart->legend()->setBackgroundVisible(false);
188 m_chart->legend()->setBackgroundVisible(false);
190 //![3]
189 //![3]
191
190
192 hideLegendSpinbox();
191 hideLegendSpinbox();
193 update();
192 update();
194 }
193 }
195
194
196 void MainWidget::addBarset()
195 void MainWidget::addBarset()
197 {
196 {
198 QBarSet *barSet = new QBarSet(QString("set ") + QString::number(m_series->count()));
197 QBarSet *barSet = new QBarSet(QString("set ") + QString::number(m_series->count()));
199 qreal delta = m_series->count() * 0.1;
198 qreal delta = m_series->count() * 0.1;
200 *barSet << QPointF(0.0 + delta, 1 + delta) << QPointF(1.0 + delta, 2 + delta) << QPointF(2.0 + delta, 3 + delta) << QPointF(3.0 + delta, 4 + delta);
199 *barSet << QPointF(0.0 + delta, 1 + delta) << QPointF(1.0 + delta, 2 + delta) << QPointF(2.0 + delta, 3 + delta) << QPointF(3.0 + delta, 4 + delta);
201 m_series->append(barSet);
200 m_series->append(barSet);
202 }
201 }
203
202
204 void MainWidget::removeBarset()
203 void MainWidget::removeBarset()
205 {
204 {
206 QList<QBarSet*> sets = m_series->barSets();
205 QList<QBarSet*> sets = m_series->barSets();
207 if (sets.count() > 0) {
206 if (sets.count() > 0) {
208 m_series->remove(sets.at(sets.count()-1));
207 m_series->remove(sets.at(sets.count()-1));
209 }
208 }
210 }
209 }
211
210
212 void MainWidget::setLegendLeft()
211 void MainWidget::setLegendLeft()
213 {
212 {
214 m_chart->legend()->setAlignment(Qt::AlignLeft);
213 m_chart->legend()->setAlignment(Qt::AlignLeft);
215 }
214 }
216
215
217 void MainWidget::setLegendRight()
216 void MainWidget::setLegendRight()
218 {
217 {
219 m_chart->legend()->setAlignment(Qt::AlignRight);
218 m_chart->legend()->setAlignment(Qt::AlignRight);
220 }
219 }
221
220
222 void MainWidget::setLegendTop()
221 void MainWidget::setLegendTop()
223 {
222 {
224 m_chart->legend()->setAlignment(Qt::AlignTop);
223 m_chart->legend()->setAlignment(Qt::AlignTop);
225 }
224 }
226
225
227 void MainWidget::setLegendBottom()
226 void MainWidget::setLegendBottom()
228 {
227 {
229 m_chart->legend()->setAlignment(Qt::AlignBottom);
228 m_chart->legend()->setAlignment(Qt::AlignBottom);
230 }
229 }
231
230
232 void MainWidget::toggleBold()
231 void MainWidget::toggleBold()
233 {
232 {
234 QFont font = m_chart->legend()->font();
233 QFont font = m_chart->legend()->font();
235 font.setBold(!font.bold());
234 font.setBold(!font.bold());
236 m_chart->legend()->setFont(font);
235 m_chart->legend()->setFont(font);
237 }
236 }
238
237
239 void MainWidget::toggleItalic()
238 void MainWidget::toggleItalic()
240 {
239 {
241 QFont font = m_chart->legend()->font();
240 QFont font = m_chart->legend()->font();
242 font.setItalic(!font.italic());
241 font.setItalic(!font.italic());
243 m_chart->legend()->setFont(font);
242 m_chart->legend()->setFont(font);
244 }
243 }
245
244
246 void MainWidget::fontSizeChanged()
245 void MainWidget::fontSizeChanged()
247 {
246 {
248 QFont font = m_chart->legend()->font();
247 QFont font = m_chart->legend()->font();
249 font.setPointSizeF(m_fontSize->value());
248 font.setPointSizeF(m_fontSize->value());
250 m_chart->legend()->setFont(font);
249 m_chart->legend()->setFont(font);
251 }
250 }
252
251
253 void MainWidget::updateLegendLayout()
252 void MainWidget::updateLegendLayout()
254 {
253 {
255 //![4]
254 //![4]
256 m_chart->legend()->setGeometry(m_legendPosX->value()
255 m_chart->legend()->setGeometry(m_legendPosX->value()
257 ,m_legendPosY->value()
256 ,m_legendPosY->value()
258 ,m_legendWidth->value()
257 ,m_legendWidth->value()
259 ,m_legendHeight->value());
258 ,m_legendHeight->value());
260 m_chart->legend()->update();
259 m_chart->legend()->update();
261 //![4]
260 //![4]
262 }
261 }
@@ -1,441 +1,501
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 The following QML shows how to create a simple chart with one pie series:
37 The following QML shows how to create a simple chart with one pie series:
38 \snippet ../examples/qmlpiechart/qml/qmlpiechart/main.qml 1
38 \snippet ../examples/qmlpiechart/qml/qmlpiechart/main.qml 1
39 \snippet ../examples/qmlpiechart/qml/qmlpiechart/main.qml 2
39 \snippet ../examples/qmlpiechart/qml/qmlpiechart/main.qml 2
40 \snippet ../examples/qmlpiechart/qml/qmlpiechart/main.qml 3
40 \snippet ../examples/qmlpiechart/qml/qmlpiechart/main.qml 3
41
41
42 \beginfloatleft
42 \beginfloatleft
43 \image examples_qmlpiechart.png
43 \image examples_qmlpiechart.png
44 \endfloat
44 \endfloat
45 \clearfloat
45 \clearfloat
46 */
46 */
47
47
48 /*!
48 /*!
49 \qmlproperty Theme ChartView::theme
49 \qmlproperty Theme ChartView::theme
50 Theme defines the visual appearance of the chart, including for example colors, fonts, line
50 Theme defines the visual appearance of the chart, including for example colors, fonts, line
51 widths and chart background.
51 widths and chart background.
52 */
52 */
53
53
54 /*!
54 /*!
55 \qmlproperty Animation ChartView::animation
55 \qmlproperty Animation ChartView::animation
56 Animation configuration of the chart. One of ChartView.NoAnimation, ChartView.GridAxisAnimations,
56 Animation configuration of the chart. One of ChartView.NoAnimation, ChartView.GridAxisAnimations,
57 ChartView.SeriesAnimations or ChartView.AllAnimations.
57 ChartView.SeriesAnimations or ChartView.AllAnimations.
58 */
58 */
59
59
60 /*!
60 /*!
61 \qmlproperty Font ChartView::titleFont
61 \qmlproperty Font ChartView::titleFont
62 The title font of the chart
62 The title font of the chart
63
63
64 See the \l {Font} {QML Font Element} for detailed documentation.
64 See the \l {Font} {QML Font Element} for detailed documentation.
65 */
65 */
66
66
67 /*!
67 /*!
68 \qmlproperty string ChartView::title
68 \qmlproperty string ChartView::title
69 The title of the chart, shown on top of the chart.
69 The title of the chart, shown on top of the chart.
70 \sa ChartView::titleColor
70 \sa ChartView::titleColor
71 */
71 */
72
72
73 /*!
73 /*!
74 \qmlproperty string ChartView::titleColor
74 \qmlproperty string ChartView::titleColor
75 The color of the title text.
75 The color of the title text.
76 */
76 */
77
77
78 /*!
78 /*!
79 \qmlproperty Axis ChartView::axisX
79 \qmlproperty Axis ChartView::axisX
80 The x-axis of the chart.
80 The x-axis of the chart.
81 */
81 */
82
82
83 /*!
83 /*!
84 \qmlproperty Axis ChartView::axisY
84 \qmlproperty Axis ChartView::axisY
85 The default y-axis of the chart.
85 The default y-axis of the chart.
86 */
86 */
87
87
88 /*!
88 /*!
89 \qmlproperty Legend ChartView::legend
89 \qmlproperty Legend ChartView::legend
90 The legend of the chart. Legend lists all the series, pie slices and bar sets added on the chart.
90 The legend of the chart. Legend lists all the series, pie slices and bar sets added on the chart.
91 */
91 */
92
92
93 /*!
93 /*!
94 \qmlproperty int ChartView::count
94 \qmlproperty int ChartView::count
95 The count of series added to the chart.
95 The count of series added to the chart.
96 */
96 */
97
97
98 /*!
98 /*!
99 \qmlproperty color ChartView::backgroundColor
99 \qmlproperty color ChartView::backgroundColor
100 The color of the chart's background. By default background color is defined by chart theme.
100 The color of the chart's background. By default background color is defined by chart theme.
101 \sa ChartView::theme
101 \sa ChartView::theme
102 */
102 */
103
103
104 /*!
104 /*!
105 \qmlproperty bool ChartView::dropShadowEnabled
105 \qmlproperty bool ChartView::dropShadowEnabled
106 The chart's border drop shadow. Set to true to enable drop shadow.
106 The chart's border drop shadow. Set to true to enable drop shadow.
107 */
107 */
108
108
109 /*!
109 /*!
110 \qmlproperty real ChartView::topMargin
111 The space between the top of chart view and the top of the plot area. The title (if non-empty) is drawn on top margin
112 area of the chart view. Top margin area is also used by legend, if aligned to top.
113 */
114
115 /*!
116 \qmlproperty real ChartView::bottomMargin
117 The space between the bottom of chart view and the bottom of the plot area. The bottom margin area may be used by
118 legend (if aligned to bottom), x-axis, x-axis labels and x-axis tick marks.
119 */
120
121 /*!
122 \qmlproperty real ChartView::leftMargin
123 The space between the left side of chart view and the left side of the plot area. The left margin area may be used by
124 legend (if aligned to left), y-axis, y-axis labels and y-axis tick marks.
125 */
126
127 /*!
128 \qmlproperty real ChartView::rightMargin
129 The space between the right side of chart view and the right side of the plot area. The right margin area may be used
130 by legend (if aligned to right).
131 */
132
133 /*!
110 \qmlmethod AbstractSeries ChartView::series(int index)
134 \qmlmethod AbstractSeries ChartView::series(int index)
111 Returns the series with \a index on the chart. This allows you to loop through the series of a chart together with
135 Returns the series with \a index on the chart. This allows you to loop through the series of a chart together with
112 the count property of the chart.
136 the count property of the chart.
113 */
137 */
114
138
115 /*!
139 /*!
116 \qmlmethod AbstractSeries ChartView::series(string name)
140 \qmlmethod AbstractSeries ChartView::series(string name)
117 Returns the first series on the chart with \a name. If there is no series with that name, returns null.
141 Returns the first series on the chart with \a name. If there is no series with that name, returns null.
118 */
142 */
119
143
120 /*!
144 /*!
121 \qmlmethod AbstractSeries ChartView::createSeries(SeriesType type, string name)
145 \qmlmethod AbstractSeries ChartView::createSeries(SeriesType type, string name)
122 Creates a series object of \a type to the chart. For example:
146 Creates a series object of \a type to the chart. For example:
123 \code
147 \code
124 var scatter = chartView.createSeries(ChartView.SeriesTypeScatter, "scatter series");
148 var scatter = chartView.createSeries(ChartView.SeriesTypeScatter, "scatter series");
125 scatter.markerSize = 22;
149 scatter.markerSize = 22;
126 scatter.append(1.1, 2.0);
150 scatter.append(1.1, 2.0);
127 \endcode
151 \endcode
128 */
152 */
129
153
130 /*!
154 /*!
131 \qmlmethod Axis ChartView::axisY(QAbstractSeries *series)
155 \qmlmethod Axis ChartView::axisY(QAbstractSeries *series)
132 The y-axis of the series. This is the same as the default y-axis of the chart as multiple y-axes are not yet supported.
156 The y-axis of the series. This is the same as the default y-axis of the chart as multiple y-axes are not yet supported.
133 */
157 */
134
158
135 /*!
159 /*!
136 \qmlmethod ChartView::zoomY(real factor)
160 \qmlmethod ChartView::zoomY(real factor)
137 Zooms in by \a factor on the center of the chart.
161 Zooms in by \a factor on the center of the chart.
138 */
162 */
139
163
140 /*!
164 /*!
141 \qmlmethod ChartView::scrollLeft(real pixels)
165 \qmlmethod ChartView::scrollLeft(real pixels)
142 Scrolls to left by \a pixels. This is a convenience function that suits for example for key navigation.
166 Scrolls to left by \a pixels. This is a convenience function that suits for example for key navigation.
143 \sa Axis::min, Axis::max
167 \sa Axis::min, Axis::max
144 */
168 */
145
169
146 /*!
170 /*!
147 \qmlmethod ChartView::scrollRight(real pixels)
171 \qmlmethod ChartView::scrollRight(real pixels)
148 Scrolls to right by \a pixels. This is a convenience function that suits for example for key navigation.
172 Scrolls to right by \a pixels. This is a convenience function that suits for example for key navigation.
149 \sa Axis::min, Axis::max
173 \sa Axis::min, Axis::max
150 */
174 */
151
175
152 /*!
176 /*!
153 \qmlmethod ChartView::scrollUp(real pixels)
177 \qmlmethod ChartView::scrollUp(real pixels)
154 Scrolls up by \a pixels. This is a convenience function that suits for example for key navigation.
178 Scrolls up by \a pixels. This is a convenience function that suits for example for key navigation.
155 \sa Axis::min, Axis::max
179 \sa Axis::min, Axis::max
156 */
180 */
157
181
158 /*!
182 /*!
159 \qmlmethod ChartView::scrollDown(real pixels)
183 \qmlmethod ChartView::scrollDown(real pixels)
160 Scrolls down by \a pixels. This is a convenience function that suits for example for key navigation.
184 Scrolls down by \a pixels. This is a convenience function that suits for example for key navigation.
161 \sa Axis::min, Axis::max
185 \sa Axis::min, Axis::max
162 */
186 */
163
187
164 DeclarativeChart::DeclarativeChart(QDeclarativeItem *parent)
188 DeclarativeChart::DeclarativeChart(QDeclarativeItem *parent)
165 : QDeclarativeItem(parent),
189 : QDeclarativeItem(parent),
166 m_chart(new QChart(this))
190 m_chart(new QChart(this))
167 {
191 {
168 setFlag(QGraphicsItem::ItemHasNoContents, false);
192 setFlag(QGraphicsItem::ItemHasNoContents, false);
169 // m_chart->axisX()->setNiceNumbersEnabled(false);
193 // m_chart->axisX()->setNiceNumbersEnabled(false);
194 m_chartMargins = m_chart->margins();
195 connect(m_chart, SIGNAL(marginsChanged(QRectF)), this, SLOT(handleMarginsChanged(QRectF)));
196 }
197
198 void DeclarativeChart::handleMarginsChanged(QRectF newMargins)
199 {
200 if (m_chartMargins.top() != newMargins.top())
201 topMarginChanged(m_chart->margins().top());
202 if (m_chartMargins.bottom() != newMargins.bottom())
203 bottomMarginChanged(m_chart->margins().bottom());
204 if (m_chartMargins.left() != newMargins.left())
205 leftMarginChanged(m_chart->margins().left());
206 if (m_chartMargins.right() != newMargins.right())
207 rightMarginChanged(m_chart->margins().right());
208
209 m_chartMargins = m_chart->margins();
170 }
210 }
171
211
172 DeclarativeChart::~DeclarativeChart()
212 DeclarativeChart::~DeclarativeChart()
173 {
213 {
174 delete m_chart;
214 delete m_chart;
175 }
215 }
176
216
177 void DeclarativeChart::childEvent(QChildEvent *event)
217 void DeclarativeChart::childEvent(QChildEvent *event)
178 {
218 {
179 if (event->type() == QEvent::ChildAdded) {
219 if (event->type() == QEvent::ChildAdded) {
180 if (qobject_cast<QAbstractSeries *>(event->child())) {
220 if (qobject_cast<QAbstractSeries *>(event->child())) {
181 m_chart->addSeries(qobject_cast<QAbstractSeries *>(event->child()));
221 m_chart->addSeries(qobject_cast<QAbstractSeries *>(event->child()));
182 }
222 }
183 }
223 }
184 }
224 }
185
225
186 void DeclarativeChart::componentComplete()
226 void DeclarativeChart::componentComplete()
187 {
227 {
188 foreach(QObject *child, children()) {
228 foreach(QObject *child, children()) {
189 if (qobject_cast<QAbstractSeries *>(child)) {
229 if (qobject_cast<QAbstractSeries *>(child)) {
190 // qDebug() << "DeclarativeChart::componentComplete(), add: " << child;
230 // qDebug() << "DeclarativeChart::componentComplete(), add: " << child;
191 // TODO: how about optional y-axis?
231 // TODO: how about optional y-axis?
192 m_chart->addSeries(qobject_cast<QAbstractSeries *>(child));
232 m_chart->addSeries(qobject_cast<QAbstractSeries *>(child));
193 }
233 }
194 }
234 }
195 QDeclarativeItem::componentComplete();
235 QDeclarativeItem::componentComplete();
196 }
236 }
197
237
198 void DeclarativeChart::geometryChanged(const QRectF &newGeometry, const QRectF &oldGeometry)
238 void DeclarativeChart::geometryChanged(const QRectF &newGeometry, const QRectF &oldGeometry)
199 {
239 {
200 // qDebug() << "DeclarativeChart::geometryChanged" << newGeometry.width() << newGeometry.height();
240 // qDebug() << "DeclarativeChart::geometryChanged" << newGeometry.width() << newGeometry.height();
201 if (newGeometry.isValid()) {
241 if (newGeometry.isValid()) {
202 if (newGeometry.width() > 0 && newGeometry.height() > 0) {
242 if (newGeometry.width() > 0 && newGeometry.height() > 0) {
203 m_chart->resize(newGeometry.width(), newGeometry.height());
243 m_chart->resize(newGeometry.width(), newGeometry.height());
204 }
244 }
205 }
245 }
206 QDeclarativeItem::geometryChanged(newGeometry, oldGeometry);
246 QDeclarativeItem::geometryChanged(newGeometry, oldGeometry);
207 }
247 }
208
248
209 void DeclarativeChart::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget)
249 void DeclarativeChart::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget)
210 {
250 {
211 Q_UNUSED(option)
251 Q_UNUSED(option)
212 Q_UNUSED(widget)
252 Q_UNUSED(widget)
213
253
214 // TODO: optimized?
254 // TODO: optimized?
215 painter->setRenderHint(QPainter::Antialiasing, true);
255 painter->setRenderHint(QPainter::Antialiasing, true);
216 }
256 }
217
257
218 void DeclarativeChart::setTheme(DeclarativeChart::Theme theme)
258 void DeclarativeChart::setTheme(DeclarativeChart::Theme theme)
219 {
259 {
220 QChart::ChartTheme chartTheme = (QChart::ChartTheme) theme;
260 QChart::ChartTheme chartTheme = (QChart::ChartTheme) theme;
221 if (chartTheme != m_chart->theme())
261 if (chartTheme != m_chart->theme())
222 m_chart->setTheme(chartTheme);
262 m_chart->setTheme(chartTheme);
223 }
263 }
224
264
225 DeclarativeChart::Theme DeclarativeChart::theme()
265 DeclarativeChart::Theme DeclarativeChart::theme()
226 {
266 {
227 return (DeclarativeChart::Theme) m_chart->theme();
267 return (DeclarativeChart::Theme) m_chart->theme();
228 }
268 }
229
269
230 void DeclarativeChart::setAnimationOptions(DeclarativeChart::Animation animations)
270 void DeclarativeChart::setAnimationOptions(DeclarativeChart::Animation animations)
231 {
271 {
232 QChart::AnimationOption animationOptions = (QChart::AnimationOption) animations;
272 QChart::AnimationOption animationOptions = (QChart::AnimationOption) animations;
233 if (animationOptions != m_chart->animationOptions())
273 if (animationOptions != m_chart->animationOptions())
234 m_chart->setAnimationOptions(animationOptions);
274 m_chart->setAnimationOptions(animationOptions);
235 }
275 }
236
276
237 DeclarativeChart::Animation DeclarativeChart::animationOptions()
277 DeclarativeChart::Animation DeclarativeChart::animationOptions()
238 {
278 {
239 if (m_chart->animationOptions().testFlag(QChart::AllAnimations))
279 if (m_chart->animationOptions().testFlag(QChart::AllAnimations))
240 return DeclarativeChart::AllAnimations;
280 return DeclarativeChart::AllAnimations;
241 else if (m_chart->animationOptions().testFlag(QChart::GridAxisAnimations))
281 else if (m_chart->animationOptions().testFlag(QChart::GridAxisAnimations))
242 return DeclarativeChart::GridAxisAnimations;
282 return DeclarativeChart::GridAxisAnimations;
243 else if (m_chart->animationOptions().testFlag(QChart::SeriesAnimations))
283 else if (m_chart->animationOptions().testFlag(QChart::SeriesAnimations))
244 return DeclarativeChart::SeriesAnimations;
284 return DeclarativeChart::SeriesAnimations;
245 else
285 else
246 return DeclarativeChart::NoAnimation;
286 return DeclarativeChart::NoAnimation;
247 }
287 }
248
288
249 void DeclarativeChart::setTitle(QString title)
289 void DeclarativeChart::setTitle(QString title)
250 {
290 {
251 if (title != m_chart->title())
291 if (title != m_chart->title())
252 m_chart->setTitle(title);
292 m_chart->setTitle(title);
253 }
293 }
254 QString DeclarativeChart::title()
294 QString DeclarativeChart::title()
255 {
295 {
256 return m_chart->title();
296 return m_chart->title();
257 }
297 }
258
298
259 QAxis *DeclarativeChart::axisX()
299 QAxis *DeclarativeChart::axisX()
260 {
300 {
261 return m_chart->axisX();
301 return m_chart->axisX();
262 }
302 }
263
303
264 QAxis *DeclarativeChart::axisY(QAbstractSeries *series)
304 QAxis *DeclarativeChart::axisY(QAbstractSeries *series)
265 {
305 {
266 return m_chart->axisY(series);
306 return m_chart->axisY(series);
267 }
307 }
268
308
269 QLegend *DeclarativeChart::legend()
309 QLegend *DeclarativeChart::legend()
270 {
310 {
271 return m_chart->legend();
311 return m_chart->legend();
272 }
312 }
273
313
274 QVariantList DeclarativeChart::axisXLabels()
314 QVariantList DeclarativeChart::axisXLabels()
275 {
315 {
276 QVariantList labels;
316 QVariantList labels;
277 foreach (qreal value, m_chart->axisX()->categories()->values()) {
317 foreach (qreal value, m_chart->axisX()->categories()->values()) {
278 labels.append(value);
318 labels.append(value);
279 labels.append(m_chart->axisX()->categories()->label(value));
319 labels.append(m_chart->axisX()->categories()->label(value));
280 }
320 }
281 return labels;
321 return labels;
282 }
322 }
283
323
284 void DeclarativeChart::setAxisXLabels(QVariantList list)
324 void DeclarativeChart::setAxisXLabels(QVariantList list)
285 {
325 {
286 QVariant value(QVariant::Invalid);
326 QVariant value(QVariant::Invalid);
287 foreach (QVariant element, list) {
327 foreach (QVariant element, list) {
288 if (value.isValid() && element.type() == QVariant::String) {
328 if (value.isValid() && element.type() == QVariant::String) {
289 m_chart->axisX()->categories()->insert(value.toDouble(), element.toString());
329 m_chart->axisX()->categories()->insert(value.toDouble(), element.toString());
290 value = QVariant(QVariant::Invalid);
330 value = QVariant(QVariant::Invalid);
291 } else {
331 } else {
292 if (element.canConvert(QVariant::Double))
332 if (element.canConvert(QVariant::Double))
293 value = element;
333 value = element;
294 }
334 }
295 }
335 }
296 emit axisLabelsChanged();
336 emit axisLabelsChanged();
297 }
337 }
298
338
299 void DeclarativeChart::setTitleColor(QColor color)
339 void DeclarativeChart::setTitleColor(QColor color)
300 {
340 {
301 QBrush b = m_chart->titleBrush();
341 QBrush b = m_chart->titleBrush();
302 if (color != b.color()) {
342 if (color != b.color()) {
303 b.setColor(color);
343 b.setColor(color);
304 m_chart->setTitleBrush(b);
344 m_chart->setTitleBrush(b);
305 emit titleColorChanged();
345 emit titleColorChanged(color);
306 }
346 }
307 }
347 }
308
348
309 QFont DeclarativeChart::titleFont() const
349 QFont DeclarativeChart::titleFont() const
310 {
350 {
311 return m_chart->titleFont();
351 return m_chart->titleFont();
312 }
352 }
313
353
314 void DeclarativeChart::setTitleFont(const QFont& font)
354 void DeclarativeChart::setTitleFont(const QFont& font)
315 {
355 {
316 m_chart->setTitleFont(font);
356 m_chart->setTitleFont(font);
317 }
357 }
318
358
319 QColor DeclarativeChart::titleColor()
359 QColor DeclarativeChart::titleColor()
320 {
360 {
321 return m_chart->titleBrush().color();
361 return m_chart->titleBrush().color();
322 }
362 }
323
363
324 void DeclarativeChart::setBackgroundColor(QColor color)
364 void DeclarativeChart::setBackgroundColor(QColor color)
325 {
365 {
326 QBrush b = m_chart->backgroundBrush();
366 QBrush b = m_chart->backgroundBrush();
327 if (b.style() != Qt::SolidPattern || color != b.color()) {
367 if (b.style() != Qt::SolidPattern || color != b.color()) {
328 b.setStyle(Qt::SolidPattern);
368 b.setStyle(Qt::SolidPattern);
329 b.setColor(color);
369 b.setColor(color);
330 m_chart->setBackgroundBrush(b);
370 m_chart->setBackgroundBrush(b);
331 emit backgroundColorChanged();
371 emit backgroundColorChanged();
332 }
372 }
333 }
373 }
334
374
335 QColor DeclarativeChart::backgroundColor()
375 QColor DeclarativeChart::backgroundColor()
336 {
376 {
337 return m_chart->backgroundBrush().color();
377 return m_chart->backgroundBrush().color();
338 }
378 }
339
379
340 int DeclarativeChart::count()
380 int DeclarativeChart::count()
341 {
381 {
342 return m_chart->series().count();
382 return m_chart->series().count();
343 }
383 }
344
384
345 void DeclarativeChart::setDropShadowEnabled(bool enabled)
385 void DeclarativeChart::setDropShadowEnabled(bool enabled)
346 {
386 {
347 if (enabled != m_chart->isDropShadowEnabled()) {
387 if (enabled != m_chart->isDropShadowEnabled()) {
348 m_chart->setDropShadowEnabled(enabled);
388 m_chart->setDropShadowEnabled(enabled);
349 dropShadowEnabledChanged(enabled);
389 dropShadowEnabledChanged(enabled);
350 }
390 }
351 }
391 }
352
392
353 bool DeclarativeChart::dropShadowEnabled()
393 bool DeclarativeChart::dropShadowEnabled()
354 {
394 {
355 return m_chart->isDropShadowEnabled();
395 return m_chart->isDropShadowEnabled();
356 }
396 }
357
397
398 qreal DeclarativeChart::topMargin()
399 {
400 return m_chart->margins().top();
401 }
402
403 qreal DeclarativeChart::bottomMargin()
404 {
405 return m_chart->margins().bottom();
406 }
407
408 qreal DeclarativeChart::leftMargin()
409 {
410 return m_chart->margins().left();
411 }
412
413 qreal DeclarativeChart::rightMargin()
414 {
415 return m_chart->margins().right();
416 }
417
358 void DeclarativeChart::zoom(qreal factor)
418 void DeclarativeChart::zoom(qreal factor)
359 {
419 {
360 m_chart->zoom(factor);
420 m_chart->zoom(factor);
361 }
421 }
362
422
363 void DeclarativeChart::scrollLeft(qreal pixels)
423 void DeclarativeChart::scrollLeft(qreal pixels)
364 {
424 {
365 m_chart->scroll(QPointF(pixels, 0));
425 m_chart->scroll(QPointF(pixels, 0));
366 }
426 }
367
427
368 void DeclarativeChart::scrollRight(qreal pixels)
428 void DeclarativeChart::scrollRight(qreal pixels)
369 {
429 {
370 m_chart->scroll(QPointF(-pixels, 0));
430 m_chart->scroll(QPointF(-pixels, 0));
371 }
431 }
372
432
373 void DeclarativeChart::scrollUp(qreal pixels)
433 void DeclarativeChart::scrollUp(qreal pixels)
374 {
434 {
375 m_chart->scroll(QPointF(0, pixels));
435 m_chart->scroll(QPointF(0, pixels));
376 }
436 }
377
437
378 void DeclarativeChart::scrollDown(qreal pixels)
438 void DeclarativeChart::scrollDown(qreal pixels)
379 {
439 {
380 m_chart->scroll(QPointF(0, -pixels));
440 m_chart->scroll(QPointF(0, -pixels));
381 }
441 }
382
442
383 QAbstractSeries *DeclarativeChart::series(int index)
443 QAbstractSeries *DeclarativeChart::series(int index)
384 {
444 {
385 if (index < m_chart->series().count()) {
445 if (index < m_chart->series().count()) {
386 return m_chart->series().at(index);
446 return m_chart->series().at(index);
387 }
447 }
388 return 0;
448 return 0;
389 }
449 }
390
450
391 QAbstractSeries *DeclarativeChart::series(QString seriesName)
451 QAbstractSeries *DeclarativeChart::series(QString seriesName)
392 {
452 {
393 foreach(QAbstractSeries *series, m_chart->series()) {
453 foreach(QAbstractSeries *series, m_chart->series()) {
394 if (series->name() == seriesName)
454 if (series->name() == seriesName)
395 return series;
455 return series;
396 }
456 }
397 return 0;
457 return 0;
398 }
458 }
399
459
400 QAbstractSeries *DeclarativeChart::createSeries(DeclarativeChart::SeriesType type, QString name)
460 QAbstractSeries *DeclarativeChart::createSeries(DeclarativeChart::SeriesType type, QString name)
401 {
461 {
402 QAbstractSeries *series = 0;
462 QAbstractSeries *series = 0;
403 switch (type) {
463 switch (type) {
404 case DeclarativeChart::SeriesTypeLine:
464 case DeclarativeChart::SeriesTypeLine:
405 series = new DeclarativeLineSeries();
465 series = new DeclarativeLineSeries();
406 break;
466 break;
407 case DeclarativeChart::SeriesTypeArea:
467 case DeclarativeChart::SeriesTypeArea:
408 series = new DeclarativeAreaSeries();
468 series = new DeclarativeAreaSeries();
409 break;
469 break;
410 case DeclarativeChart::SeriesTypeBar:
470 case DeclarativeChart::SeriesTypeBar:
411 series = new DeclarativeBarSeries();
471 series = new DeclarativeBarSeries();
412 break;
472 break;
413 case DeclarativeChart::SeriesTypeStackedBar:
473 case DeclarativeChart::SeriesTypeStackedBar:
414 // TODO
474 // TODO
415 break;
475 break;
416 case DeclarativeChart::SeriesTypePercentBar:
476 case DeclarativeChart::SeriesTypePercentBar:
417 // TODO
477 // TODO
418 break;
478 break;
419 case DeclarativeChart::SeriesTypeGroupedBar:
479 case DeclarativeChart::SeriesTypeGroupedBar:
420 series = new DeclarativeGroupedBarSeries();
480 series = new DeclarativeGroupedBarSeries();
421 break;
481 break;
422 case DeclarativeChart::SeriesTypePie:
482 case DeclarativeChart::SeriesTypePie:
423 series = new DeclarativePieSeries();
483 series = new DeclarativePieSeries();
424 break;
484 break;
425 case DeclarativeChart::SeriesTypeScatter:
485 case DeclarativeChart::SeriesTypeScatter:
426 series = new DeclarativeScatterSeries();
486 series = new DeclarativeScatterSeries();
427 break;
487 break;
428 case DeclarativeChart::SeriesTypeSpline:
488 case DeclarativeChart::SeriesTypeSpline:
429 series = new DeclarativeSplineSeries();
489 series = new DeclarativeSplineSeries();
430 break;
490 break;
431 default:
491 default:
432 qWarning() << "Illegal series type";
492 qWarning() << "Illegal series type";
433 }
493 }
434 series->setName(name);
494 series->setName(name);
435 m_chart->addSeries(series);
495 m_chart->addSeries(series);
436 return series;
496 return series;
437 }
497 }
438
498
439 #include "moc_declarativechart.cpp"
499 #include "moc_declarativechart.cpp"
440
500
441 QTCOMMERCIALCHART_END_NAMESPACE
501 QTCOMMERCIALCHART_END_NAMESPACE
@@ -1,141 +1,157
1 /****************************************************************************
1 /****************************************************************************
2 **
2 **
3 ** Copyright (C) 2012 Digia Plc
3 ** Copyright (C) 2012 Digia Plc
4 ** All rights reserved.
4 ** All rights reserved.
5 ** For any questions to Digia, please use contact form at http://qt.digia.com
5 ** For any questions to Digia, please use contact form at http://qt.digia.com
6 **
6 **
7 ** This file is part of the Qt Commercial Charts Add-on.
7 ** This file is part of the Qt Commercial Charts Add-on.
8 **
8 **
9 ** $QT_BEGIN_LICENSE$
9 ** $QT_BEGIN_LICENSE$
10 ** Licensees holding valid Qt Commercial licenses may use this file in
10 ** Licensees holding valid Qt Commercial licenses may use this file in
11 ** accordance with the Qt Commercial License Agreement provided with the
11 ** accordance with the Qt Commercial License Agreement provided with the
12 ** Software or, alternatively, in accordance with the terms contained in
12 ** Software or, alternatively, in accordance with the terms contained in
13 ** a written agreement between you and Digia.
13 ** a written agreement between you and Digia.
14 **
14 **
15 ** If you have questions regarding the use of this file, please use
15 ** If you have questions regarding the use of this file, please use
16 ** contact form at http://qt.digia.com
16 ** contact form at http://qt.digia.com
17 ** $QT_END_LICENSE$
17 ** $QT_END_LICENSE$
18 **
18 **
19 ****************************************************************************/
19 ****************************************************************************/
20
20
21 #ifndef DECLARATIVECHART_H
21 #ifndef DECLARATIVECHART_H
22 #define DECLARATIVECHART_H
22 #define DECLARATIVECHART_H
23
23
24 #include <QtCore/QtGlobal>
24 #include <QtCore/QtGlobal>
25 #include <QDeclarativeItem>
25 #include <QDeclarativeItem>
26 #include <qchart.h>
26 #include <qchart.h>
27 #include <QAxis>
27 #include <QAxis>
28
28
29 QTCOMMERCIALCHART_BEGIN_NAMESPACE
29 QTCOMMERCIALCHART_BEGIN_NAMESPACE
30
30
31 // TODO: Derive from QChart for easier definition of properties?
31 // TODO: Derive from QChart for easier definition of properties?
32 class DeclarativeChart : public QDeclarativeItem
32 class DeclarativeChart : public QDeclarativeItem
33 // TODO: for QTQUICK2: extend QQuickPainterItem instead
33 // TODO: for QTQUICK2: extend QQuickPainterItem instead
34 //class DeclarativeChart : public QQuickPaintedItem, public Chart
34 //class DeclarativeChart : public QQuickPaintedItem, public Chart
35 {
35 {
36 Q_OBJECT
36 Q_OBJECT
37 Q_PROPERTY(Theme theme READ theme WRITE setTheme)
37 Q_PROPERTY(Theme theme READ theme WRITE setTheme)
38 Q_PROPERTY(Animation animationOptions READ animationOptions WRITE setAnimationOptions)
38 Q_PROPERTY(Animation animationOptions READ animationOptions WRITE setAnimationOptions)
39 Q_PROPERTY(QString title READ title WRITE setTitle)
39 Q_PROPERTY(QString title READ title WRITE setTitle)
40 Q_PROPERTY(QFont titleFont READ titleFont WRITE setTitleFont)
40 Q_PROPERTY(QFont titleFont READ titleFont WRITE setTitleFont)
41 Q_PROPERTY(QColor titleColor READ titleColor WRITE setTitleColor NOTIFY titleColorChanged)
41 Q_PROPERTY(QColor titleColor READ titleColor WRITE setTitleColor NOTIFY titleColorChanged)
42 Q_PROPERTY(QAxis *axisX READ axisX)
42 Q_PROPERTY(QAxis *axisX READ axisX)
43 Q_PROPERTY(QAxis *axisY READ axisY)
43 Q_PROPERTY(QAxis *axisY READ axisY)
44 Q_PROPERTY(QLegend *legend READ legend)
44 Q_PROPERTY(QLegend *legend READ legend)
45 // TODO: how to define axis labels? This is not very convenient
45 // TODO: how to define axis labels? This is not very convenient
46 Q_PROPERTY(QVariantList axisXLabels READ axisXLabels WRITE setAxisXLabels NOTIFY axisLabelsChanged)
46 Q_PROPERTY(QVariantList axisXLabels READ axisXLabels WRITE setAxisXLabels NOTIFY axisLabelsChanged)
47 Q_PROPERTY(int count READ count)
47 Q_PROPERTY(int count READ count)
48 Q_PROPERTY(QColor backgroundColor READ backgroundColor WRITE setBackgroundColor NOTIFY backgroundColorChanged)
48 Q_PROPERTY(QColor backgroundColor READ backgroundColor WRITE setBackgroundColor NOTIFY backgroundColorChanged)
49 Q_PROPERTY(bool dropShadowEnabled READ dropShadowEnabled WRITE setDropShadowEnabled NOTIFY dropShadowEnabledChanged)
49 Q_PROPERTY(bool dropShadowEnabled READ dropShadowEnabled WRITE setDropShadowEnabled NOTIFY dropShadowEnabledChanged)
50 Q_PROPERTY(qreal topMargin READ topMargin NOTIFY topMarginChanged)
51 Q_PROPERTY(qreal bottomMargin READ bottomMargin NOTIFY bottomMarginChanged)
52 Q_PROPERTY(qreal leftMargin READ leftMargin NOTIFY leftMarginChanged)
53 Q_PROPERTY(qreal rightMargin READ rightMargin NOTIFY rightMarginChanged)
50 Q_ENUMS(Animation)
54 Q_ENUMS(Animation)
51 Q_ENUMS(Theme)
55 Q_ENUMS(Theme)
52 Q_ENUMS(SeriesType)
56 Q_ENUMS(SeriesType)
53
57
54 public:
58 public:
55 // duplicating enums from QChart to make the QML api namings 1-to-1 with the C++ api
59 // duplicating enums from QChart to make the QML api namings 1-to-1 with the C++ api
56 enum Theme {
60 enum Theme {
57 ChartThemeLight = 0,
61 ChartThemeLight = 0,
58 ChartThemeBlueCerulean,
62 ChartThemeBlueCerulean,
59 ChartThemeDark,
63 ChartThemeDark,
60 ChartThemeBrownSand,
64 ChartThemeBrownSand,
61 ChartThemeBlueNcs,
65 ChartThemeBlueNcs,
62 ChartThemeHighContrast,
66 ChartThemeHighContrast,
63 ChartThemeBlueIcy
67 ChartThemeBlueIcy
64 };
68 };
65
69
66 enum Animation {
70 enum Animation {
67 NoAnimation = 0x0,
71 NoAnimation = 0x0,
68 GridAxisAnimations = 0x1,
72 GridAxisAnimations = 0x1,
69 SeriesAnimations =0x2,
73 SeriesAnimations =0x2,
70 AllAnimations = 0x3
74 AllAnimations = 0x3
71 };
75 };
72
76
73 enum SeriesType {
77 enum SeriesType {
74 SeriesTypeLine,
78 SeriesTypeLine,
75 SeriesTypeArea,
79 SeriesTypeArea,
76 SeriesTypeBar,
80 SeriesTypeBar,
77 SeriesTypeStackedBar,
81 SeriesTypeStackedBar,
78 SeriesTypePercentBar,
82 SeriesTypePercentBar,
79 SeriesTypeGroupedBar,
83 SeriesTypeGroupedBar,
80 SeriesTypePie,
84 SeriesTypePie,
81 SeriesTypeScatter,
85 SeriesTypeScatter,
82 SeriesTypeSpline
86 SeriesTypeSpline
83 };
87 };
84
88
85 public:
89 public:
86 DeclarativeChart(QDeclarativeItem *parent = 0);
90 DeclarativeChart(QDeclarativeItem *parent = 0);
87 ~DeclarativeChart();
91 ~DeclarativeChart();
88
92
89 public: // From QDeclarativeItem/QGraphicsItem
93 public: // From QDeclarativeItem/QGraphicsItem
90 void childEvent(QChildEvent *event);
94 void childEvent(QChildEvent *event);
91 void componentComplete();
95 void componentComplete();
92 void geometryChanged(const QRectF &newGeometry, const QRectF &oldGeometry);
96 void geometryChanged(const QRectF &newGeometry, const QRectF &oldGeometry);
93 void paint (QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget = 0);
97 void paint (QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget = 0);
94
98
95 public:
99 public:
96 void setTheme(DeclarativeChart::Theme theme);
100 void setTheme(DeclarativeChart::Theme theme);
97 DeclarativeChart::Theme theme();
101 DeclarativeChart::Theme theme();
98 void setAnimationOptions(DeclarativeChart::Animation animations);
102 void setAnimationOptions(DeclarativeChart::Animation animations);
99 DeclarativeChart::Animation animationOptions();
103 DeclarativeChart::Animation animationOptions();
100 void setTitle(QString title);
104 void setTitle(QString title);
101 QString title();
105 QString title();
102 QAxis *axisX();
106 QAxis *axisX();
103 QLegend *legend();
107 QLegend *legend();
104 QVariantList axisXLabels();
108 QVariantList axisXLabels();
105 void setAxisXLabels(QVariantList list);
109 void setAxisXLabels(QVariantList list);
106 QFont titleFont() const;
110 QFont titleFont() const;
107 void setTitleFont(const QFont& font);
111 void setTitleFont(const QFont& font);
108 void setTitleColor(QColor color);
112 void setTitleColor(QColor color);
109 QColor titleColor();
113 QColor titleColor();
110 void setBackgroundColor(QColor color);
114 void setBackgroundColor(QColor color);
111 QColor backgroundColor();
115 QColor backgroundColor();
112 int count();
116 int count();
113 void setDropShadowEnabled(bool enabled);
117 void setDropShadowEnabled(bool enabled);
114 bool dropShadowEnabled();
118 bool dropShadowEnabled();
119 qreal topMargin();
120 qreal bottomMargin();
121 qreal leftMargin();
122 qreal rightMargin();
115
123
116 public:
124 public:
117 Q_INVOKABLE QAbstractSeries *series(int index);
125 Q_INVOKABLE QAbstractSeries *series(int index);
118 Q_INVOKABLE QAbstractSeries *series(QString seriesName);
126 Q_INVOKABLE QAbstractSeries *series(QString seriesName);
119 Q_INVOKABLE QAbstractSeries *createSeries(DeclarativeChart::SeriesType type, QString name = "");
127 Q_INVOKABLE QAbstractSeries *createSeries(DeclarativeChart::SeriesType type, QString name = "");
120 Q_INVOKABLE QAxis *axisY(QAbstractSeries *series = 0);
128 Q_INVOKABLE QAxis *axisY(QAbstractSeries *series = 0);
121 Q_INVOKABLE void zoom(qreal factor);
129 Q_INVOKABLE void zoom(qreal factor);
122 Q_INVOKABLE void scrollLeft(qreal pixels);
130 Q_INVOKABLE void scrollLeft(qreal pixels);
123 Q_INVOKABLE void scrollRight(qreal pixels);
131 Q_INVOKABLE void scrollRight(qreal pixels);
124 Q_INVOKABLE void scrollUp(qreal pixels);
132 Q_INVOKABLE void scrollUp(qreal pixels);
125 Q_INVOKABLE void scrollDown(qreal pixels);
133 Q_INVOKABLE void scrollDown(qreal pixels);
126
134
127 Q_SIGNALS:
135 Q_SIGNALS:
128 void axisLabelsChanged();
136 void axisLabelsChanged();
129 void titleColorChanged();
137 void titleColorChanged(QColor color);
130 void backgroundColorChanged();
138 void backgroundColorChanged();
131 void dropShadowEnabledChanged(bool enabled);
139 void dropShadowEnabledChanged(bool enabled);
140 void topMarginChanged(qreal margin);
141 void bottomMarginChanged(qreal margin);
142 void leftMarginChanged(qreal margin);
143 void rightMarginChanged(qreal margin);
132
144
133 public:
145 public Q_SLOTS:
146 void handleMarginsChanged(QRectF newMargins);
147
148 private:
134 // Extending QChart with DeclarativeChart is not possible because QObject does not support
149 // Extending QChart with DeclarativeChart is not possible because QObject does not support
135 // multi inheritance, so we now have a QChart as a member instead
150 // multi inheritance, so we now have a QChart as a member instead
136 QChart *m_chart;
151 QChart *m_chart;
152 QRectF m_chartMargins;
137 };
153 };
138
154
139 QTCOMMERCIALCHART_END_NAMESPACE
155 QTCOMMERCIALCHART_END_NAMESPACE
140
156
141 #endif // DECLARATIVECHART_H
157 #endif // DECLARATIVECHART_H
@@ -1,429 +1,433
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 #include "chartpresenter_p.h"
20 #include "chartpresenter_p.h"
21 #include "qchart.h"
21 #include "qchart.h"
22 #include "qchart_p.h"
22 #include "qchart_p.h"
23 #include "qaxis.h"
23 #include "qaxis.h"
24 #include "chartdataset_p.h"
24 #include "chartdataset_p.h"
25 #include "charttheme_p.h"
25 #include "charttheme_p.h"
26 #include "chartanimator_p.h"
26 #include "chartanimator_p.h"
27 #include "chartanimation_p.h"
27 #include "chartanimation_p.h"
28 #include "qabstractseries_p.h"
28 #include "qabstractseries_p.h"
29 #include "qareaseries.h"
29 #include "qareaseries.h"
30 #include "chartaxis_p.h"
30 #include "chartaxis_p.h"
31 #include "chartaxisx_p.h"
31 #include "chartaxisx_p.h"
32 #include "chartaxisy_p.h"
32 #include "chartaxisy_p.h"
33 #include "areachartitem_p.h"
33 #include "areachartitem_p.h"
34 #include "chartbackground_p.h"
34 #include "chartbackground_p.h"
35 #include <QTimer>
35 #include <QTimer>
36
36
37 QTCOMMERCIALCHART_BEGIN_NAMESPACE
37 QTCOMMERCIALCHART_BEGIN_NAMESPACE
38
38
39 ChartPresenter::ChartPresenter(QChart* chart,ChartDataSet* dataset):QObject(chart),
39 ChartPresenter::ChartPresenter(QChart* chart,ChartDataSet* dataset):QObject(chart),
40 m_chart(chart),
40 m_chart(chart),
41 m_animator(0),
41 m_animator(0),
42 m_dataset(dataset),
42 m_dataset(dataset),
43 m_chartTheme(0),
43 m_chartTheme(0),
44 m_chartRect(QRectF(QPoint(0,0),m_chart->size())),
44 m_chartRect(QRectF(QPoint(0,0),m_chart->size())),
45 m_options(QChart::NoAnimation),
45 m_options(QChart::NoAnimation),
46 m_minLeftMargin(0),
46 m_minLeftMargin(0),
47 m_minBottomMargin(0),
47 m_minBottomMargin(0),
48 m_state(ShowState),
48 m_state(ShowState),
49 m_backgroundItem(0),
49 m_backgroundItem(0),
50 m_titleItem(0),
50 m_titleItem(0),
51 m_marginBig(60),
51 m_marginBig(60),
52 m_marginSmall(20),
52 m_marginSmall(20),
53 m_marginTiny(10),
53 m_marginTiny(10),
54 m_chartMargins(QRect(m_marginBig,m_marginBig,0,0))
54 m_chartMargins(QRect(m_marginBig,m_marginBig,0,0))
55 {
55 {
56
56
57 }
57 }
58
58
59 ChartPresenter::~ChartPresenter()
59 ChartPresenter::~ChartPresenter()
60 {
60 {
61 delete m_chartTheme;
61 delete m_chartTheme;
62 }
62 }
63
63
64 void ChartPresenter::setGeometry(const QRectF& rect)
64 void ChartPresenter::setGeometry(const QRectF& rect)
65 {
65 {
66 m_rect = rect;
66 m_rect = rect;
67 Q_ASSERT(m_rect.isValid());
67 Q_ASSERT(m_rect.isValid());
68 updateLayout();
68 updateLayout();
69 }
69 }
70
70
71 void ChartPresenter::setMinimumMarginWidth(ChartAxis* axis, qreal width)
71 void ChartPresenter::setMinimumMarginWidth(ChartAxis* axis, qreal width)
72 {
72 {
73 switch(axis->axisType()){
73 switch(axis->axisType()){
74 case ChartAxis::X_AXIS:
74 case ChartAxis::X_AXIS:
75 {
75 {
76 if(width>m_chartRect.width()+ m_chartMargins.left()) {
76 if(width>m_chartRect.width()+ m_chartMargins.left()) {
77 m_minLeftMargin= width - m_chartRect.width();
77 m_minLeftMargin= width - m_chartRect.width();
78 updateLayout();
78 updateLayout();
79 }
79 }
80 break;
80 break;
81 }
81 }
82 case ChartAxis::Y_AXIS:
82 case ChartAxis::Y_AXIS:
83 {
83 {
84
84
85 if(m_minLeftMargin!=width){
85 if(m_minLeftMargin!=width){
86 m_minLeftMargin= width;
86 m_minLeftMargin= width;
87 updateLayout();
87 updateLayout();
88 }
88 }
89 break;
89 break;
90 }
90 }
91
91
92 }
92 }
93 }
93 }
94
94
95 void ChartPresenter::setMinimumMarginHeight(ChartAxis* axis, qreal height)
95 void ChartPresenter::setMinimumMarginHeight(ChartAxis* axis, qreal height)
96 {
96 {
97 switch(axis->axisType()){
97 switch(axis->axisType()){
98 case ChartAxis::X_AXIS:
98 case ChartAxis::X_AXIS:
99 {
99 {
100 if(m_minBottomMargin!=height) {
100 if(m_minBottomMargin!=height) {
101 m_minBottomMargin= height;
101 m_minBottomMargin= height;
102 updateLayout();
102 updateLayout();
103 }
103 }
104 break;
104 break;
105 }
105 }
106 case ChartAxis::Y_AXIS:
106 case ChartAxis::Y_AXIS:
107 {
107 {
108
108
109 if(height>m_chartMargins.bottom()+m_chartRect.height()){
109 if(height>m_chartMargins.bottom()+m_chartRect.height()){
110 m_minBottomMargin= height - m_chartRect.height();
110 m_minBottomMargin= height - m_chartRect.height();
111 updateLayout();
111 updateLayout();
112 }
112 }
113 break;
113 break;
114 }
114 }
115
115
116 }
116 }
117 }
117 }
118
118
119 void ChartPresenter::handleAxisAdded(QAxis* axis,Domain* domain)
119 void ChartPresenter::handleAxisAdded(QAxis* axis,Domain* domain)
120 {
120 {
121 ChartAxis* item;
121 ChartAxis* item;
122
122
123 if(axis == m_dataset->axisX()){
123 if(axis == m_dataset->axisX()){
124 item = new ChartAxisX(axis,this);
124 item = new ChartAxisX(axis,this);
125 }else{
125 }else{
126 item = new ChartAxisY(axis,this);
126 item = new ChartAxisY(axis,this);
127 }
127 }
128
128
129 if(m_options.testFlag(QChart::GridAxisAnimations)){
129 if(m_options.testFlag(QChart::GridAxisAnimations)){
130 item->setAnimator(m_animator);
130 item->setAnimator(m_animator);
131 item->setAnimation(new AxisAnimation(item));
131 item->setAnimation(new AxisAnimation(item));
132 }
132 }
133
133
134 if(axis==m_dataset->axisX()){
134 if(axis==m_dataset->axisX()){
135 m_chartTheme->decorate(axis,true);
135 m_chartTheme->decorate(axis,true);
136 QObject::connect(domain,SIGNAL(rangeXChanged(qreal,qreal,int)),item,SLOT(handleRangeChanged(qreal,qreal,int)));
136 QObject::connect(domain,SIGNAL(rangeXChanged(qreal,qreal,int)),item,SLOT(handleRangeChanged(qreal,qreal,int)));
137 //initialize
137 //initialize
138 item->handleRangeChanged(domain->minX(),domain->maxX(),domain->tickXCount());
138 item->handleRangeChanged(domain->minX(),domain->maxX(),domain->tickXCount());
139
139
140 }
140 }
141 else{
141 else{
142 m_chartTheme->decorate(axis,false);
142 m_chartTheme->decorate(axis,false);
143 QObject::connect(domain,SIGNAL(rangeYChanged(qreal,qreal,int)),item,SLOT(handleRangeChanged(qreal,qreal,int)));
143 QObject::connect(domain,SIGNAL(rangeYChanged(qreal,qreal,int)),item,SLOT(handleRangeChanged(qreal,qreal,int)));
144 //initialize
144 //initialize
145 item->handleRangeChanged(domain->minY(),domain->maxY(),domain->tickYCount());
145 item->handleRangeChanged(domain->minY(),domain->maxY(),domain->tickYCount());
146 }
146 }
147
147
148 QObject::connect(this,SIGNAL(geometryChanged(QRectF)),item,SLOT(handleGeometryChanged(QRectF)));
148 QObject::connect(this,SIGNAL(geometryChanged(QRectF)),item,SLOT(handleGeometryChanged(QRectF)));
149 //initialize
149 //initialize
150 if(m_chartRect.isValid()) item->handleGeometryChanged(m_chartRect);
150 if(m_chartRect.isValid()) item->handleGeometryChanged(m_chartRect);
151 m_axisItems.insert(axis, item);
151 m_axisItems.insert(axis, item);
152 }
152 }
153
153
154 void ChartPresenter::handleAxisRemoved(QAxis* axis)
154 void ChartPresenter::handleAxisRemoved(QAxis* axis)
155 {
155 {
156 ChartAxis* item = m_axisItems.take(axis);
156 ChartAxis* item = m_axisItems.take(axis);
157 Q_ASSERT(item);
157 Q_ASSERT(item);
158 if(m_animator) m_animator->removeAnimation(item);
158 if(m_animator) m_animator->removeAnimation(item);
159 delete item;
159 delete item;
160 }
160 }
161
161
162
162
163 void ChartPresenter::handleSeriesAdded(QAbstractSeries* series,Domain* domain)
163 void ChartPresenter::handleSeriesAdded(QAbstractSeries* series,Domain* domain)
164 {
164 {
165 Chart *item = series->d_ptr->createGraphics(this);
165 Chart *item = series->d_ptr->createGraphics(this);
166 Q_ASSERT(item);
166 Q_ASSERT(item);
167 QObject::connect(this,SIGNAL(geometryChanged(QRectF)),item,SLOT(handleGeometryChanged(QRectF)));
167 QObject::connect(this,SIGNAL(geometryChanged(QRectF)),item,SLOT(handleGeometryChanged(QRectF)));
168 QObject::connect(domain,SIGNAL(domainChanged(qreal,qreal,qreal,qreal)),item,SLOT(handleDomainChanged(qreal,qreal,qreal,qreal)));
168 QObject::connect(domain,SIGNAL(domainChanged(qreal,qreal,qreal,qreal)),item,SLOT(handleDomainChanged(qreal,qreal,qreal,qreal)));
169 //initialize
169 //initialize
170 item->handleDomainChanged(domain->minX(),domain->maxX(),domain->minY(),domain->maxY());
170 item->handleDomainChanged(domain->minX(),domain->maxX(),domain->minY(),domain->maxY());
171 if(m_chartRect.isValid()) item->handleGeometryChanged(m_chartRect);
171 if(m_chartRect.isValid()) item->handleGeometryChanged(m_chartRect);
172 m_chartItems.insert(series,item);
172 m_chartItems.insert(series,item);
173 }
173 }
174
174
175 void ChartPresenter::handleSeriesRemoved(QAbstractSeries* series)
175 void ChartPresenter::handleSeriesRemoved(QAbstractSeries* series)
176 {
176 {
177 Chart* item = m_chartItems.take(series);
177 Chart* item = m_chartItems.take(series);
178 Q_ASSERT(item);
178 Q_ASSERT(item);
179 if(m_animator) {
179 if(m_animator) {
180 //small hack to handle area animations
180 //small hack to handle area animations
181 if(series->type() == QAbstractSeries::SeriesTypeArea){
181 if(series->type() == QAbstractSeries::SeriesTypeArea){
182 QAreaSeries* areaSeries = static_cast<QAreaSeries*>(series);
182 QAreaSeries* areaSeries = static_cast<QAreaSeries*>(series);
183 AreaChartItem* area = static_cast<AreaChartItem*>(item);
183 AreaChartItem* area = static_cast<AreaChartItem*>(item);
184 m_animator->removeAnimation(area->upperLineItem());
184 m_animator->removeAnimation(area->upperLineItem());
185 if(areaSeries->lowerSeries()) m_animator->removeAnimation(area->lowerLineItem());
185 if(areaSeries->lowerSeries()) m_animator->removeAnimation(area->lowerLineItem());
186 }else
186 }else
187 m_animator->removeAnimation(item);
187 m_animator->removeAnimation(item);
188 }
188 }
189 delete item;
189 delete item;
190 }
190 }
191
191
192 void ChartPresenter::setTheme(QChart::ChartTheme theme,bool force)
192 void ChartPresenter::setTheme(QChart::ChartTheme theme,bool force)
193 {
193 {
194 if(m_chartTheme && m_chartTheme->id() == theme) return;
194 if(m_chartTheme && m_chartTheme->id() == theme) return;
195 delete m_chartTheme;
195 delete m_chartTheme;
196 m_chartTheme = ChartTheme::createTheme(theme);
196 m_chartTheme = ChartTheme::createTheme(theme);
197 m_chartTheme->setForced(force);
197 m_chartTheme->setForced(force);
198 m_chartTheme->decorate(m_chart);
198 m_chartTheme->decorate(m_chart);
199 m_chartTheme->decorate(m_chart->legend());
199 m_chartTheme->decorate(m_chart->legend());
200 resetAllElements();
200 resetAllElements();
201
201
202 // We do not want "force" to stay on.
202 // We do not want "force" to stay on.
203 // Bar/pie are calling decorate when adding/removing slices/bars which means
203 // Bar/pie are calling decorate when adding/removing slices/bars which means
204 // that to preserve users colors "force" must not be on.
204 // that to preserve users colors "force" must not be on.
205 m_chartTheme->setForced(false);
205 m_chartTheme->setForced(false);
206 }
206 }
207
207
208 QChart::ChartTheme ChartPresenter::theme()
208 QChart::ChartTheme ChartPresenter::theme()
209 {
209 {
210 return m_chartTheme->id();
210 return m_chartTheme->id();
211 }
211 }
212
212
213 void ChartPresenter::setAnimationOptions(QChart::AnimationOptions options)
213 void ChartPresenter::setAnimationOptions(QChart::AnimationOptions options)
214 {
214 {
215 if(m_options!=options) {
215 if(m_options!=options) {
216
216
217 m_options=options;
217 m_options=options;
218
218
219 if(m_options!=QChart::NoAnimation && !m_animator) {
219 if(m_options!=QChart::NoAnimation && !m_animator) {
220 m_animator= new ChartAnimator(this);
220 m_animator= new ChartAnimator(this);
221 }
221 }
222 resetAllElements();
222 resetAllElements();
223 }
223 }
224
224
225 }
225 }
226
226
227 void ChartPresenter::resetAllElements()
227 void ChartPresenter::resetAllElements()
228 {
228 {
229 QList<QAxis *> axisList = m_axisItems.uniqueKeys();
229 QList<QAxis *> axisList = m_axisItems.uniqueKeys();
230 QList<QAbstractSeries *> seriesList = m_chartItems.uniqueKeys();
230 QList<QAbstractSeries *> seriesList = m_chartItems.uniqueKeys();
231
231
232 foreach(QAxis *axis, axisList) {
232 foreach(QAxis *axis, axisList) {
233 handleAxisRemoved(axis);
233 handleAxisRemoved(axis);
234 handleAxisAdded(axis,m_dataset->domain(axis));
234 handleAxisAdded(axis,m_dataset->domain(axis));
235 }
235 }
236 foreach(QAbstractSeries *series, seriesList) {
236 foreach(QAbstractSeries *series, seriesList) {
237 handleSeriesRemoved(series);
237 handleSeriesRemoved(series);
238 handleSeriesAdded(series,m_dataset->domain(series));
238 handleSeriesAdded(series,m_dataset->domain(series));
239 // m_dataset->removeSeries(series);
239 // m_dataset->removeSeries(series);
240 // m_dataset->addSeries(series);
240 // m_dataset->addSeries(series);
241 }
241 }
242 }
242 }
243
243
244 void ChartPresenter::zoomIn(qreal factor)
244 void ChartPresenter::zoomIn(qreal factor)
245 {
245 {
246 QRectF rect = chartGeometry();
246 QRectF rect = chartGeometry();
247 rect.setWidth(rect.width()/factor);
247 rect.setWidth(rect.width()/factor);
248 rect.setHeight(rect.height()/factor);
248 rect.setHeight(rect.height()/factor);
249 rect.moveCenter(chartGeometry().center());
249 rect.moveCenter(chartGeometry().center());
250 zoomIn(rect);
250 zoomIn(rect);
251 }
251 }
252
252
253 void ChartPresenter::zoomIn(const QRectF& rect)
253 void ChartPresenter::zoomIn(const QRectF& rect)
254 {
254 {
255 QRectF r = rect.normalized();
255 QRectF r = rect.normalized();
256 r.translate(-m_chartMargins.topLeft());
256 r.translate(-m_chartMargins.topLeft());
257 if (!r.isValid())
257 if (!r.isValid())
258 return;
258 return;
259
259
260 m_state = ZoomInState;
260 m_state = ZoomInState;
261 m_statePoint = QPointF(r.center().x()/chartGeometry().width(),r.center().y()/chartGeometry().height());
261 m_statePoint = QPointF(r.center().x()/chartGeometry().width(),r.center().y()/chartGeometry().height());
262 m_dataset->zoomInDomain(r,chartGeometry().size());
262 m_dataset->zoomInDomain(r,chartGeometry().size());
263 m_state = ShowState;
263 m_state = ShowState;
264 }
264 }
265
265
266 void ChartPresenter::zoomOut(qreal factor)
266 void ChartPresenter::zoomOut(qreal factor)
267 {
267 {
268 m_state = ZoomOutState;
268 m_state = ZoomOutState;
269
269
270 QRectF chartRect;
270 QRectF chartRect;
271 chartRect.setSize(chartGeometry().size());
271 chartRect.setSize(chartGeometry().size());
272
272
273 QRectF rect;
273 QRectF rect;
274 rect.setSize(chartRect.size()/factor);
274 rect.setSize(chartRect.size()/factor);
275 rect.moveCenter(chartRect.center());
275 rect.moveCenter(chartRect.center());
276 if (!rect.isValid())
276 if (!rect.isValid())
277 return;
277 return;
278 m_statePoint = QPointF(rect.center().x()/chartGeometry().width(),rect.center().y()/chartGeometry().height());
278 m_statePoint = QPointF(rect.center().x()/chartGeometry().width(),rect.center().y()/chartGeometry().height());
279 m_dataset->zoomOutDomain(rect, chartRect.size());
279 m_dataset->zoomOutDomain(rect, chartRect.size());
280 m_state = ShowState;
280 m_state = ShowState;
281 }
281 }
282
282
283 void ChartPresenter::scroll(qreal dx,qreal dy)
283 void ChartPresenter::scroll(qreal dx,qreal dy)
284 {
284 {
285 if(dx<0) m_state=ScrollLeftState;
285 if(dx<0) m_state=ScrollLeftState;
286 if(dx>0) m_state=ScrollRightState;
286 if(dx>0) m_state=ScrollRightState;
287 if(dy<0) m_state=ScrollUpState;
287 if(dy<0) m_state=ScrollUpState;
288 if(dy>0) m_state=ScrollDownState;
288 if(dy>0) m_state=ScrollDownState;
289
289
290 m_dataset->scrollDomain(dx,dy,chartGeometry().size());
290 m_dataset->scrollDomain(dx,dy,chartGeometry().size());
291 m_state = ShowState;
291 m_state = ShowState;
292 }
292 }
293
293
294 QChart::AnimationOptions ChartPresenter::animationOptions() const
294 QChart::AnimationOptions ChartPresenter::animationOptions() const
295 {
295 {
296 return m_options;
296 return m_options;
297 }
297 }
298
298
299 void ChartPresenter::updateLayout()
299 void ChartPresenter::updateLayout()
300 {
300 {
301 if (!m_rect.isValid()) return;
301 if (!m_rect.isValid()) return;
302
302
303 QRectF oldChargMargins = m_chartMargins;
304
303 // recalculate title size
305 // recalculate title size
304
306
305 QSize titleSize;
307 QSize titleSize;
306 int titlePadding=0;
308 int titlePadding=0;
307
309
308 if (m_titleItem) {
310 if (m_titleItem) {
309 titleSize= m_titleItem->boundingRect().size().toSize();
311 titleSize= m_titleItem->boundingRect().size().toSize();
310 }
312 }
311
313
312 //defaults
314 //defaults
313 m_chartMargins = QRect(QPoint(m_minLeftMargin>m_marginBig?m_minLeftMargin:m_marginBig,m_marginBig),QPoint(m_marginBig,m_minBottomMargin>m_marginBig?m_minBottomMargin:m_marginBig));
315 m_chartMargins = QRect(QPoint(m_minLeftMargin>m_marginBig?m_minLeftMargin:m_marginBig,m_marginBig),QPoint(m_marginBig,m_minBottomMargin>m_marginBig?m_minBottomMargin:m_marginBig));
314 titlePadding = m_chartMargins.top()/2;
316 titlePadding = m_chartMargins.top()/2;
315
317
316 QLegend* legend = m_chart->d_ptr->m_legend;
318 QLegend* legend = m_chart->d_ptr->m_legend;
317
319
318 // recalculate legend position
320 // recalculate legend position
319 if (legend != 0 && legend->isAttachedToChart() && legend->isEnabled()) {
321 if (legend != 0 && legend->isAttachedToChart() && legend->isEnabled()) {
320
322
321 // Reserve some space for legend
323 // Reserve some space for legend
322 switch (legend->alignment()) {
324 switch (legend->alignment()) {
323
325
324 case Qt::AlignTop: {
326 case Qt::AlignTop: {
325 int ledgendSize = legend->minHeight();
327 int ledgendSize = legend->minHeight();
326 int topPadding = 2*m_marginTiny + titleSize.height() + ledgendSize + m_marginTiny;
328 int topPadding = 2*m_marginTiny + titleSize.height() + ledgendSize + m_marginTiny;
327 m_chartMargins = QRect(QPoint(m_chartMargins.left(),topPadding),QPoint(m_chartMargins.right(),m_chartMargins.bottom()));
329 m_chartMargins = QRect(QPoint(m_chartMargins.left(),topPadding),QPoint(m_chartMargins.right(),m_chartMargins.bottom()));
328 m_legendMargins = QRect(QPoint(m_chartMargins.left(),topPadding - (ledgendSize + m_marginTiny)),QPoint(m_chartMargins.right(),m_rect.height()-topPadding + m_marginTiny));
330 m_legendMargins = QRect(QPoint(m_chartMargins.left(),topPadding - (ledgendSize + m_marginTiny)),QPoint(m_chartMargins.right(),m_rect.height()-topPadding + m_marginTiny));
329 titlePadding = m_marginTiny + m_marginTiny;
331 titlePadding = m_marginTiny + m_marginTiny;
330 break;
332 break;
331 }
333 }
332 case Qt::AlignBottom: {
334 case Qt::AlignBottom: {
333 int ledgendSize = legend->minHeight();
335 int ledgendSize = legend->minHeight();
334 int bottomPadding = m_marginTiny + m_marginSmall + ledgendSize + m_marginTiny + m_minBottomMargin;
336 int bottomPadding = m_marginTiny + m_marginSmall + ledgendSize + m_marginTiny + m_minBottomMargin;
335 m_chartMargins = QRect(QPoint(m_chartMargins.left(),m_chartMargins.top()),QPoint(m_chartMargins.right(),bottomPadding));
337 m_chartMargins = QRect(QPoint(m_chartMargins.left(),m_chartMargins.top()),QPoint(m_chartMargins.right(),bottomPadding));
336 m_legendMargins = QRect(QPoint(m_chartMargins.left(),m_rect.height()-bottomPadding + m_marginTiny + m_minBottomMargin),QPoint(m_chartMargins.right(),m_marginTiny + m_marginSmall));
338 m_legendMargins = QRect(QPoint(m_chartMargins.left(),m_rect.height()-bottomPadding + m_marginTiny + m_minBottomMargin),QPoint(m_chartMargins.right(),m_marginTiny + m_marginSmall));
337 titlePadding = m_chartMargins.top()/2;
339 titlePadding = m_chartMargins.top()/2;
338 break;
340 break;
339 }
341 }
340 case Qt::AlignLeft: {
342 case Qt::AlignLeft: {
341 int ledgendSize = legend->minWidth();
343 int ledgendSize = legend->minWidth();
342 int leftPadding = m_marginTiny + m_marginSmall + ledgendSize + m_marginTiny + m_minLeftMargin;
344 int leftPadding = m_marginTiny + m_marginSmall + ledgendSize + m_marginTiny + m_minLeftMargin;
343 m_chartMargins = QRect(QPoint(leftPadding,m_chartMargins.top()),QPoint(m_chartMargins.right(),m_chartMargins.bottom()));
345 m_chartMargins = QRect(QPoint(leftPadding,m_chartMargins.top()),QPoint(m_chartMargins.right(),m_chartMargins.bottom()));
344 m_legendMargins = QRect(QPoint(m_marginTiny + m_marginSmall,m_chartMargins.top()),QPoint(m_rect.width()-leftPadding + m_marginTiny + m_minLeftMargin,m_chartMargins.bottom()));
346 m_legendMargins = QRect(QPoint(m_marginTiny + m_marginSmall,m_chartMargins.top()),QPoint(m_rect.width()-leftPadding + m_marginTiny + m_minLeftMargin,m_chartMargins.bottom()));
345 titlePadding = m_chartMargins.top()/2;
347 titlePadding = m_chartMargins.top()/2;
346 break;
348 break;
347 }
349 }
348 case Qt::AlignRight: {
350 case Qt::AlignRight: {
349 int ledgendSize = legend->minWidth();
351 int ledgendSize = legend->minWidth();
350 int rightPadding = m_marginTiny + m_marginSmall + ledgendSize + m_marginTiny;
352 int rightPadding = m_marginTiny + m_marginSmall + ledgendSize + m_marginTiny;
351 m_chartMargins = QRect(QPoint(m_chartMargins.left(),m_chartMargins.top()),QPoint(rightPadding,m_chartMargins.bottom()));
353 m_chartMargins = QRect(QPoint(m_chartMargins.left(),m_chartMargins.top()),QPoint(rightPadding,m_chartMargins.bottom()));
352 m_legendMargins = QRect(QPoint(m_rect.width()- rightPadding+ m_marginTiny ,m_chartMargins.top()),QPoint(m_marginTiny + m_marginSmall,m_chartMargins.bottom()));
354 m_legendMargins = QRect(QPoint(m_rect.width()- rightPadding+ m_marginTiny ,m_chartMargins.top()),QPoint(m_marginTiny + m_marginSmall,m_chartMargins.bottom()));
353 titlePadding = m_chartMargins.top()/2;
355 titlePadding = m_chartMargins.top()/2;
354 break;
356 break;
355 }
357 }
356 default: {
358 default: {
357 break;
359 break;
358 }
360 }
359 }
361 }
360 }
362 }
361
363
362 if(m_rect.width()<2*(m_chartMargins.top()+m_chartMargins.bottom()) || m_rect.height()< 2*(m_chartMargins.top() + m_chartMargins.bottom()))
364 if(m_rect.width()<2*(m_chartMargins.top()+m_chartMargins.bottom()) || m_rect.height()< 2*(m_chartMargins.top() + m_chartMargins.bottom()))
363 {
365 {
364 m_chart->setMinimumSize(2*(m_chartMargins.top()+m_chartMargins.bottom()),2*(m_chartMargins.top() + m_chartMargins.bottom()));
366 m_chart->setMinimumSize(2*(m_chartMargins.top()+m_chartMargins.bottom()),2*(m_chartMargins.top() + m_chartMargins.bottom()));
365 return;
367 return;
366 }
368 }
367
369
368
370
369 // recalculate title position
371 // recalculate title position
370 if (m_titleItem) {
372 if (m_titleItem) {
371 QPointF center = m_rect.center() -m_titleItem->boundingRect().center();
373 QPointF center = m_rect.center() -m_titleItem->boundingRect().center();
372 m_titleItem->setPos(center.x(),titlePadding);
374 m_titleItem->setPos(center.x(),titlePadding);
373 }
375 }
374
376
375 //recalculate background gradient
377 //recalculate background gradient
376 if (m_backgroundItem) {
378 if (m_backgroundItem) {
377 m_backgroundItem->setRect(m_rect.adjusted(m_marginTiny,m_marginTiny, -m_marginTiny, -m_marginTiny));
379 m_backgroundItem->setRect(m_rect.adjusted(m_marginTiny,m_marginTiny, -m_marginTiny, -m_marginTiny));
378 }
380 }
379
381
380
382
381 QRectF chartRect = m_rect.adjusted(m_chartMargins.left(),m_chartMargins.top(),-m_chartMargins.right(),-m_chartMargins.bottom());
383 QRectF chartRect = m_rect.adjusted(m_chartMargins.left(),m_chartMargins.top(),-m_chartMargins.right(),-m_chartMargins.bottom());
382
384
383 if (legend != 0 && legend->isAttachedToChart() && legend->isEnabled()) {
385 if (legend != 0 && legend->isAttachedToChart() && legend->isEnabled()) {
384 legend->setGeometry(m_rect.adjusted(m_legendMargins.left(),m_legendMargins.top(),-m_legendMargins.right(),-m_legendMargins.bottom()));
386 legend->setGeometry(m_rect.adjusted(m_legendMargins.left(),m_legendMargins.top(),-m_legendMargins.right(),-m_legendMargins.bottom()));
385 }
387 }
386
388
387 if(m_chartRect!=chartRect && chartRect.isValid()){
389 if(m_chartRect!=chartRect && chartRect.isValid()){
388 m_chartRect=chartRect;
390 m_chartRect=chartRect;
389 emit geometryChanged(m_chartRect);
391 emit geometryChanged(m_chartRect);
390 }
392 }
391
393
394 if (oldChargMargins != m_chartMargins)
395 emit marginsChanged(m_chartMargins);
392 }
396 }
393
397
394 void ChartPresenter::createChartBackgroundItem()
398 void ChartPresenter::createChartBackgroundItem()
395 {
399 {
396 if (!m_backgroundItem) {
400 if (!m_backgroundItem) {
397 m_backgroundItem = new ChartBackground(rootItem());
401 m_backgroundItem = new ChartBackground(rootItem());
398 m_backgroundItem->setPen(Qt::NoPen);
402 m_backgroundItem->setPen(Qt::NoPen);
399 m_backgroundItem->setZValue(ChartPresenter::BackgroundZValue);
403 m_backgroundItem->setZValue(ChartPresenter::BackgroundZValue);
400 }
404 }
401 }
405 }
402
406
403 void ChartPresenter::createChartTitleItem()
407 void ChartPresenter::createChartTitleItem()
404 {
408 {
405 if (!m_titleItem) {
409 if (!m_titleItem) {
406 m_titleItem = new QGraphicsSimpleTextItem(rootItem());
410 m_titleItem = new QGraphicsSimpleTextItem(rootItem());
407 m_titleItem->setZValue(ChartPresenter::BackgroundZValue);
411 m_titleItem->setZValue(ChartPresenter::BackgroundZValue);
408 }
412 }
409 }
413 }
410
414
411 void ChartPresenter::handleAnimationFinished()
415 void ChartPresenter::handleAnimationFinished()
412 {
416 {
413 m_animations.removeAll(qobject_cast<ChartAnimation*>(sender()));
417 m_animations.removeAll(qobject_cast<ChartAnimation*>(sender()));
414 if(m_animations.empty()) emit animationsFinished();
418 if(m_animations.empty()) emit animationsFinished();
415 }
419 }
416
420
417 void ChartPresenter::startAnimation(ChartAnimation* animation)
421 void ChartPresenter::startAnimation(ChartAnimation* animation)
418 {
422 {
419 if (animation->state() != QAbstractAnimation::Stopped) animation->stop();
423 if (animation->state() != QAbstractAnimation::Stopped) animation->stop();
420 QObject::connect(animation, SIGNAL(finished()),this,SLOT(handleAnimationFinished()),Qt::UniqueConnection);
424 QObject::connect(animation, SIGNAL(finished()),this,SLOT(handleAnimationFinished()),Qt::UniqueConnection);
421 if(!m_animations.isEmpty()){
425 if(!m_animations.isEmpty()){
422 m_animations.append(animation);
426 m_animations.append(animation);
423 }
427 }
424 QTimer::singleShot(0, animation, SLOT(start()));
428 QTimer::singleShot(0, animation, SLOT(start()));
425 }
429 }
426
430
427 #include "moc_chartpresenter_p.cpp"
431 #include "moc_chartpresenter_p.cpp"
428
432
429 QTCOMMERCIALCHART_END_NAMESPACE
433 QTCOMMERCIALCHART_END_NAMESPACE
@@ -1,154 +1,155
1 /****************************************************************************
1 /****************************************************************************
2 **
2 **
3 ** Copyright (C) 2012 Digia Plc
3 ** Copyright (C) 2012 Digia Plc
4 ** All rights reserved.
4 ** All rights reserved.
5 ** For any questions to Digia, please use contact form at http://qt.digia.com
5 ** For any questions to Digia, please use contact form at http://qt.digia.com
6 **
6 **
7 ** This file is part of the Qt Commercial Charts Add-on.
7 ** This file is part of the Qt Commercial Charts Add-on.
8 **
8 **
9 ** $QT_BEGIN_LICENSE$
9 ** $QT_BEGIN_LICENSE$
10 ** Licensees holding valid Qt Commercial licenses may use this file in
10 ** Licensees holding valid Qt Commercial licenses may use this file in
11 ** accordance with the Qt Commercial License Agreement provided with the
11 ** accordance with the Qt Commercial License Agreement provided with the
12 ** Software or, alternatively, in accordance with the terms contained in
12 ** Software or, alternatively, in accordance with the terms contained in
13 ** a written agreement between you and Digia.
13 ** a written agreement between you and Digia.
14 **
14 **
15 ** If you have questions regarding the use of this file, please use
15 ** If you have questions regarding the use of this file, please use
16 ** contact form at http://qt.digia.com
16 ** contact form at http://qt.digia.com
17 ** $QT_END_LICENSE$
17 ** $QT_END_LICENSE$
18 **
18 **
19 ****************************************************************************/
19 ****************************************************************************/
20
20
21 // W A R N I N G
21 // W A R N I N G
22 // -------------
22 // -------------
23 //
23 //
24 // This file is not part of the QtCommercial Chart API. It exists purely as an
24 // This file is not part of the QtCommercial Chart API. It exists purely as an
25 // implementation detail. This header file may change from version to
25 // implementation detail. This header file may change from version to
26 // version without notice, or even be removed.
26 // version without notice, or even be removed.
27 //
27 //
28 // We mean it.
28 // We mean it.
29
29
30 #ifndef CHARTPRESENTER_H
30 #ifndef CHARTPRESENTER_H
31 #define CHARTPRESENTER_H
31 #define CHARTPRESENTER_H
32
32
33 #include "qchartglobal.h"
33 #include "qchartglobal.h"
34 #include "qchart.h" //becouse of QChart::ChartThemeId //TODO
34 #include "qchart.h" //becouse of QChart::ChartThemeId //TODO
35 #include <QRectF>
35 #include <QRectF>
36
36
37 QTCOMMERCIALCHART_BEGIN_NAMESPACE
37 QTCOMMERCIALCHART_BEGIN_NAMESPACE
38
38
39 class Chart;
39 class Chart;
40 class QAbstractSeries;
40 class QAbstractSeries;
41 class ChartDataSet;
41 class ChartDataSet;
42 class Domain;
42 class Domain;
43 class ChartAxis;
43 class ChartAxis;
44 class ChartTheme;
44 class ChartTheme;
45 class ChartAnimator;
45 class ChartAnimator;
46 class ChartBackground;
46 class ChartBackground;
47 class ChartAnimation;
47 class ChartAnimation;
48
48
49 class ChartPresenter: public QObject
49 class ChartPresenter: public QObject
50 {
50 {
51 Q_OBJECT
51 Q_OBJECT
52 public:
52 public:
53 enum ZValues {
53 enum ZValues {
54 BackgroundZValue = -1,
54 BackgroundZValue = -1,
55 ShadesZValue,
55 ShadesZValue,
56 GridZValue,
56 GridZValue,
57 SeriesZValue,
57 SeriesZValue,
58 LineChartZValue = SeriesZValue,
58 LineChartZValue = SeriesZValue,
59 BarSeriesZValue = SeriesZValue,
59 BarSeriesZValue = SeriesZValue,
60 ScatterSeriesZValue = SeriesZValue,
60 ScatterSeriesZValue = SeriesZValue,
61 PieSeriesZValue = SeriesZValue,
61 PieSeriesZValue = SeriesZValue,
62 AxisZValue,
62 AxisZValue,
63 LegendZValue
63 LegendZValue
64 };
64 };
65
65
66 enum State {
66 enum State {
67 ShowState,
67 ShowState,
68 ScrollUpState,
68 ScrollUpState,
69 ScrollDownState,
69 ScrollDownState,
70 ScrollLeftState,
70 ScrollLeftState,
71 ScrollRightState,
71 ScrollRightState,
72 ZoomInState,
72 ZoomInState,
73 ZoomOutState
73 ZoomOutState
74 };
74 };
75
75
76 ChartPresenter(QChart* chart,ChartDataSet *dataset);
76 ChartPresenter(QChart* chart,ChartDataSet *dataset);
77 virtual ~ChartPresenter();
77 virtual ~ChartPresenter();
78
78
79 ChartAnimator* animator() const { return m_animator; }
79 ChartAnimator* animator() const { return m_animator; }
80 ChartTheme *chartTheme() const { return m_chartTheme; }
80 ChartTheme *chartTheme() const { return m_chartTheme; }
81 ChartDataSet *dataSet() const { return m_dataset; }
81 ChartDataSet *dataSet() const { return m_dataset; }
82 QGraphicsItem* rootItem() const { return m_chart; }
82 QGraphicsItem* rootItem() const { return m_chart; }
83
83
84 void setTheme(QChart::ChartTheme theme,bool force = true);
84 void setTheme(QChart::ChartTheme theme,bool force = true);
85 QChart::ChartTheme theme();
85 QChart::ChartTheme theme();
86
86
87 void setAnimationOptions(QChart::AnimationOptions options);
87 void setAnimationOptions(QChart::AnimationOptions options);
88 QChart::AnimationOptions animationOptions() const;
88 QChart::AnimationOptions animationOptions() const;
89
89
90 void zoomIn(qreal factor);
90 void zoomIn(qreal factor);
91 void zoomIn(const QRectF& rect);
91 void zoomIn(const QRectF& rect);
92 void zoomOut(qreal factor);
92 void zoomOut(qreal factor);
93 void scroll(qreal dx,qreal dy);
93 void scroll(qreal dx,qreal dy);
94
94
95 void setGeometry(const QRectF& rect);
95 void setGeometry(const QRectF& rect);
96 QRectF chartGeometry() const { return m_chartRect; }
96 QRectF chartGeometry() const { return m_chartRect; }
97
97
98 void setMinimumMarginHeight(ChartAxis* axis, qreal height);
98 void setMinimumMarginHeight(ChartAxis* axis, qreal height);
99 void setMinimumMarginWidth(ChartAxis* axis, qreal width);
99 void setMinimumMarginWidth(ChartAxis* axis, qreal width);
100 qreal minimumLeftMargin() const { return m_minLeftMargin; }
100 qreal minimumLeftMargin() const { return m_minLeftMargin; }
101 qreal minimumBottomMargin() const { return m_minBottomMargin; }
101 qreal minimumBottomMargin() const { return m_minBottomMargin; }
102
102
103 void startAnimation(ChartAnimation* animation);
103 void startAnimation(ChartAnimation* animation);
104 State state() const { return m_state; }
104 State state() const { return m_state; }
105 QPointF statePoint() const { return m_statePoint; }
105 QPointF statePoint() const { return m_statePoint; }
106 public: //TODO: fix me
106 public: //TODO: fix me
107 void resetAllElements();
107 void resetAllElements();
108 void createChartBackgroundItem();
108 void createChartBackgroundItem();
109 void createChartTitleItem();
109 void createChartTitleItem();
110 QRectF margins() const { return m_chartMargins;}
110 QRectF margins() const { return m_chartMargins;}
111
111
112 public Q_SLOTS:
112 public Q_SLOTS:
113 void handleSeriesAdded(QAbstractSeries* series,Domain* domain);
113 void handleSeriesAdded(QAbstractSeries* series,Domain* domain);
114 void handleSeriesRemoved(QAbstractSeries* series);
114 void handleSeriesRemoved(QAbstractSeries* series);
115 void handleAxisAdded(QAxis* axis,Domain* domain);
115 void handleAxisAdded(QAxis* axis,Domain* domain);
116 void handleAxisRemoved(QAxis* axis);
116 void handleAxisRemoved(QAxis* axis);
117 void updateLayout();
117 void updateLayout();
118
118
119 private Q_SLOTS:
119 private Q_SLOTS:
120 void handleAnimationFinished();
120 void handleAnimationFinished();
121
121
122 Q_SIGNALS:
122 Q_SIGNALS:
123 void geometryChanged(const QRectF& rect);
123 void geometryChanged(const QRectF& rect);
124 void animationsFinished();
124 void animationsFinished();
125 void marginsChanged(QRectF margins);
125
126
126 private:
127 private:
127 QChart* m_chart;
128 QChart* m_chart;
128 ChartAnimator* m_animator;
129 ChartAnimator* m_animator;
129 ChartDataSet* m_dataset;
130 ChartDataSet* m_dataset;
130 ChartTheme *m_chartTheme;
131 ChartTheme *m_chartTheme;
131 QMap<QAbstractSeries *, Chart *> m_chartItems;
132 QMap<QAbstractSeries *, Chart *> m_chartItems;
132 QMap<QAxis *, ChartAxis *> m_axisItems;
133 QMap<QAxis *, ChartAxis *> m_axisItems;
133 QRectF m_rect;
134 QRectF m_rect;
134 QRectF m_chartRect;
135 QRectF m_chartRect;
135 QChart::AnimationOptions m_options;
136 QChart::AnimationOptions m_options;
136 qreal m_minLeftMargin;
137 qreal m_minLeftMargin;
137 qreal m_minBottomMargin;
138 qreal m_minBottomMargin;
138 State m_state;
139 State m_state;
139 QPointF m_statePoint;
140 QPointF m_statePoint;
140 QList<ChartAnimation*> m_animations;
141 QList<ChartAnimation*> m_animations;
141
142
142 public: //TODO: fixme
143 public: //TODO: fixme
143 ChartBackground* m_backgroundItem;
144 ChartBackground* m_backgroundItem;
144 QGraphicsSimpleTextItem* m_titleItem;
145 QGraphicsSimpleTextItem* m_titleItem;
145 int m_marginBig;
146 int m_marginBig;
146 int m_marginSmall;
147 int m_marginSmall;
147 int m_marginTiny;
148 int m_marginTiny;
148 QRectF m_chartMargins;
149 QRectF m_chartMargins;
149 QRectF m_legendMargins;
150 QRectF m_legendMargins;
150 };
151 };
151
152
152 QTCOMMERCIALCHART_END_NAMESPACE
153 QTCOMMERCIALCHART_END_NAMESPACE
153
154
154 #endif /* CHARTPRESENTER_H_ */
155 #endif /* CHARTPRESENTER_H_ */
@@ -1,479 +1,480
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 "qchart.h"
21 #include "qchart.h"
22 #include "qchart_p.h"
22 #include "qchart_p.h"
23 #include "legendscroller_p.h"
23 #include "legendscroller_p.h"
24 #include "qlegend_p.h"
24 #include "qlegend_p.h"
25 #include "chartbackground_p.h"
25 #include "chartbackground_p.h"
26 #include "qaxis.h"
26 #include "qaxis.h"
27 #include <QGraphicsScene>
27 #include <QGraphicsScene>
28 #include <QGraphicsSceneResizeEvent>
28 #include <QGraphicsSceneResizeEvent>
29
29
30 QTCOMMERCIALCHART_BEGIN_NAMESPACE
30 QTCOMMERCIALCHART_BEGIN_NAMESPACE
31
31
32 /*!
32 /*!
33 \enum QChart::ChartTheme
33 \enum QChart::ChartTheme
34
34
35 This enum describes the theme used by the chart.
35 This enum describes the theme used by the chart.
36
36
37 \value ChartThemeLight The default theme
37 \value ChartThemeLight The default theme
38 \value ChartThemeBlueCerulean
38 \value ChartThemeBlueCerulean
39 \value ChartThemeDark
39 \value ChartThemeDark
40 \value ChartThemeBrownSand
40 \value ChartThemeBrownSand
41 \value ChartThemeBlueNcs
41 \value ChartThemeBlueNcs
42 \value ChartThemeHighContrast
42 \value ChartThemeHighContrast
43 \value ChartThemeBlueIcy
43 \value ChartThemeBlueIcy
44 */
44 */
45
45
46 /*!
46 /*!
47 \enum QChart::AnimationOption
47 \enum QChart::AnimationOption
48
48
49 For enabling/disabling animations. Defaults to NoAnimation.
49 For enabling/disabling animations. Defaults to NoAnimation.
50
50
51 \value NoAnimation
51 \value NoAnimation
52 \value GridAxisAnimations
52 \value GridAxisAnimations
53 \value SeriesAnimations
53 \value SeriesAnimations
54 \value AllAnimations
54 \value AllAnimations
55 */
55 */
56
56
57 /*!
57 /*!
58 \class QChart
58 \class QChart
59 \brief QtCommercial chart API.
59 \brief QtCommercial chart API.
60
60
61 QChart is a QGraphicsWidget that you can show in a QGraphicsScene. It manages the graphical
61 QChart is a QGraphicsWidget that you can show in a QGraphicsScene. It manages the graphical
62 representation of different types of series and other chart related objects like
62 representation of different types of series and other chart related objects like
63 QAxis and QLegend. If you simply want to show a chart in a layout, you can use the
63 QAxis and QLegend. If you simply want to show a chart in a layout, you can use the
64 convenience class QChartView instead of QChart.
64 convenience class QChartView instead of QChart.
65 \sa QChartView
65 \sa QChartView
66 */
66 */
67
67
68 /*!
68 /*!
69 Constructs a chart object which is a child of a\a parent. Parameter \a wFlags is passed to the QGraphicsWidget constructor.
69 Constructs a chart object which is a child of a\a parent. Parameter \a wFlags is passed to the QGraphicsWidget constructor.
70 */
70 */
71 QChart::QChart(QGraphicsItem *parent, Qt::WindowFlags wFlags) : QGraphicsWidget(parent,wFlags),
71 QChart::QChart(QGraphicsItem *parent, Qt::WindowFlags wFlags) : QGraphicsWidget(parent,wFlags),
72 d_ptr(new QChartPrivate())
72 d_ptr(new QChartPrivate())
73 {
73 {
74 d_ptr->m_dataset = new ChartDataSet(this);
74 d_ptr->m_dataset = new ChartDataSet(this);
75 d_ptr->m_presenter = new ChartPresenter(this,d_ptr->m_dataset);
75 d_ptr->m_presenter = new ChartPresenter(this,d_ptr->m_dataset);
76 d_ptr->createConnections();
76 d_ptr->createConnections();
77 d_ptr->m_legend = new LegendScroller(this);
77 d_ptr->m_legend = new LegendScroller(this);
78 d_ptr->m_presenter->setTheme(QChart::ChartThemeLight, false);
78 d_ptr->m_presenter->setTheme(QChart::ChartThemeLight, false);
79 connect(d_ptr->m_presenter, SIGNAL(marginsChanged(QRectF)), this, SIGNAL(marginsChanged(QRectF)));
79 }
80 }
80
81
81 /*!
82 /*!
82 Destroys the object and it's children, like series and axis objects added to it.
83 Destroys the object and it's children, like series and axis objects added to it.
83 */
84 */
84 QChart::~QChart()
85 QChart::~QChart()
85 {
86 {
86 //delete first presenter , since this is a root of all the graphical items
87 //delete first presenter , since this is a root of all the graphical items
87 delete d_ptr->m_presenter;
88 delete d_ptr->m_presenter;
88 d_ptr->m_presenter=0;
89 d_ptr->m_presenter=0;
89 }
90 }
90
91
91 /*!
92 /*!
92 Adds the \a series and optional \a axisY onto the chart and takes the ownership of the objects.
93 Adds the \a series and optional \a axisY onto the chart and takes the ownership of the objects.
93 If auto scaling is enabled, re-scales the axes the series is bound to (both the x axis and
94 If auto scaling is enabled, re-scales the axes the series is bound to (both the x axis and
94 the y axis).
95 the y axis).
95
96
96 \sa removeSeries(), removeAllSeries()
97 \sa removeSeries(), removeAllSeries()
97 */
98 */
98 void QChart::addSeries(QAbstractSeries *series, QAxis *axisY)
99 void QChart::addSeries(QAbstractSeries *series, QAxis *axisY)
99 {
100 {
100 Q_ASSERT(series);
101 Q_ASSERT(series);
101 d_ptr->m_dataset->addSeries(series, axisY);
102 d_ptr->m_dataset->addSeries(series, axisY);
102 }
103 }
103
104
104 /*!
105 /*!
105 Removes the \a series specified in a perameter from the QChartView.
106 Removes the \a series specified in a perameter from the QChartView.
106 It releses its ownership of the specified QChartSeries object.
107 It releses its ownership of the specified QChartSeries object.
107 It does not delete the pointed QChartSeries data object
108 It does not delete the pointed QChartSeries data object
108 \sa addSeries(), removeAllSeries()
109 \sa addSeries(), removeAllSeries()
109 */
110 */
110 void QChart::removeSeries(QAbstractSeries *series)
111 void QChart::removeSeries(QAbstractSeries *series)
111 {
112 {
112 Q_ASSERT(series);
113 Q_ASSERT(series);
113 d_ptr->m_dataset->removeSeries(series);
114 d_ptr->m_dataset->removeSeries(series);
114 }
115 }
115
116
116 /*!
117 /*!
117 Removes all the QChartSeries that have been added to the QChartView
118 Removes all the QChartSeries that have been added to the QChartView
118 It also deletes the pointed QChartSeries data objects
119 It also deletes the pointed QChartSeries data objects
119 \sa addSeries(), removeSeries()
120 \sa addSeries(), removeSeries()
120 */
121 */
121 void QChart::removeAllSeries()
122 void QChart::removeAllSeries()
122 {
123 {
123 d_ptr->m_dataset->removeAllSeries();
124 d_ptr->m_dataset->removeAllSeries();
124 }
125 }
125
126
126 /*!
127 /*!
127 Sets the \a brush that is used for painting the background of the chart area.
128 Sets the \a brush that is used for painting the background of the chart area.
128 */
129 */
129 void QChart::setBackgroundBrush(const QBrush& brush)
130 void QChart::setBackgroundBrush(const QBrush& brush)
130 {
131 {
131 //TODO: refactor me
132 //TODO: refactor me
132 d_ptr->m_presenter->createChartBackgroundItem();
133 d_ptr->m_presenter->createChartBackgroundItem();
133 d_ptr->m_presenter->m_backgroundItem->setBrush(brush);
134 d_ptr->m_presenter->m_backgroundItem->setBrush(brush);
134 d_ptr->m_presenter->m_backgroundItem->update();
135 d_ptr->m_presenter->m_backgroundItem->update();
135 }
136 }
136
137
137 /*!
138 /*!
138 Gets the brush that is used for painting the background of the chart area.
139 Gets the brush that is used for painting the background of the chart area.
139 */
140 */
140 QBrush QChart::backgroundBrush() const
141 QBrush QChart::backgroundBrush() const
141 {
142 {
142 //TODO: refactor me
143 //TODO: refactor me
143 if (!d_ptr->m_presenter->m_backgroundItem) return QBrush();
144 if (!d_ptr->m_presenter->m_backgroundItem) return QBrush();
144 return (d_ptr->m_presenter->m_backgroundItem)->brush();
145 return (d_ptr->m_presenter->m_backgroundItem)->brush();
145 }
146 }
146
147
147 /*!
148 /*!
148 Sets the \a pen that is used for painting the background of the chart area.
149 Sets the \a pen that is used for painting the background of the chart area.
149 */
150 */
150 void QChart::setBackgroundPen(const QPen& pen)
151 void QChart::setBackgroundPen(const QPen& pen)
151 {
152 {
152 //TODO: refactor me
153 //TODO: refactor me
153 d_ptr->m_presenter->createChartBackgroundItem();
154 d_ptr->m_presenter->createChartBackgroundItem();
154 d_ptr->m_presenter->m_backgroundItem->setPen(pen);
155 d_ptr->m_presenter->m_backgroundItem->setPen(pen);
155 d_ptr->m_presenter->m_backgroundItem->update();
156 d_ptr->m_presenter->m_backgroundItem->update();
156 }
157 }
157
158
158 /*!
159 /*!
159 Gets the pen that is used for painting the background of the chart area.
160 Gets the pen that is used for painting the background of the chart area.
160 */
161 */
161 QPen QChart::backgroundPen() const
162 QPen QChart::backgroundPen() const
162 {
163 {
163 //TODO: refactor me
164 //TODO: refactor me
164 if (!d_ptr->m_presenter->m_backgroundItem) return QPen();
165 if (!d_ptr->m_presenter->m_backgroundItem) return QPen();
165 return d_ptr->m_presenter->m_backgroundItem->pen();
166 return d_ptr->m_presenter->m_backgroundItem->pen();
166 }
167 }
167
168
168 /*!
169 /*!
169 Sets the chart \a title. The description text that is drawn above the chart.
170 Sets the chart \a title. The description text that is drawn above the chart.
170 */
171 */
171 void QChart::setTitle(const QString& title)
172 void QChart::setTitle(const QString& title)
172 {
173 {
173 //TODO: refactor me
174 //TODO: refactor me
174 d_ptr->m_presenter->createChartTitleItem();
175 d_ptr->m_presenter->createChartTitleItem();
175 d_ptr->m_presenter->m_titleItem->setText(title);
176 d_ptr->m_presenter->m_titleItem->setText(title);
176 d_ptr->m_presenter->updateLayout();
177 d_ptr->m_presenter->updateLayout();
177 }
178 }
178
179
179 /*!
180 /*!
180 Returns the chart title. The description text that is drawn above the chart.
181 Returns the chart title. The description text that is drawn above the chart.
181 */
182 */
182 QString QChart::title() const
183 QString QChart::title() const
183 {
184 {
184 //TODO: refactor me
185 //TODO: refactor me
185 if (d_ptr->m_presenter->m_titleItem)
186 if (d_ptr->m_presenter->m_titleItem)
186 return d_ptr->m_presenter->m_titleItem->text();
187 return d_ptr->m_presenter->m_titleItem->text();
187 else
188 else
188 return QString();
189 return QString();
189 }
190 }
190
191
191 /*!
192 /*!
192 Sets the \a font that is used for drawing the chart description text that is rendered above the chart.
193 Sets the \a font that is used for drawing the chart description text that is rendered above the chart.
193 */
194 */
194 void QChart::setTitleFont(const QFont& font)
195 void QChart::setTitleFont(const QFont& font)
195 {
196 {
196 //TODO: refactor me
197 //TODO: refactor me
197 d_ptr->m_presenter->createChartTitleItem();
198 d_ptr->m_presenter->createChartTitleItem();
198 d_ptr->m_presenter->m_titleItem->setFont(font);
199 d_ptr->m_presenter->m_titleItem->setFont(font);
199 d_ptr->m_presenter->updateLayout();
200 d_ptr->m_presenter->updateLayout();
200 }
201 }
201
202
202 /*!
203 /*!
203 Gets the font that is used for drawing the chart description text that is rendered above the chart.
204 Gets the font that is used for drawing the chart description text that is rendered above the chart.
204 */
205 */
205 QFont QChart::titleFont() const
206 QFont QChart::titleFont() const
206 {
207 {
207 if (d_ptr->m_presenter->m_titleItem)
208 if (d_ptr->m_presenter->m_titleItem)
208 return d_ptr->m_presenter->m_titleItem->font();
209 return d_ptr->m_presenter->m_titleItem->font();
209 else
210 else
210 return QFont();
211 return QFont();
211 }
212 }
212
213
213 /*!
214 /*!
214 Sets the \a brush used for rendering the title text.
215 Sets the \a brush used for rendering the title text.
215 */
216 */
216 void QChart::setTitleBrush(const QBrush &brush)
217 void QChart::setTitleBrush(const QBrush &brush)
217 {
218 {
218 //TODO: refactor me
219 //TODO: refactor me
219 d_ptr->m_presenter->createChartTitleItem();
220 d_ptr->m_presenter->createChartTitleItem();
220 d_ptr->m_presenter->m_titleItem->setBrush(brush);
221 d_ptr->m_presenter->m_titleItem->setBrush(brush);
221 d_ptr->m_presenter->updateLayout();
222 d_ptr->m_presenter->updateLayout();
222 }
223 }
223
224
224 /*!
225 /*!
225 Returns the brush used for rendering the title text.
226 Returns the brush used for rendering the title text.
226 */
227 */
227 QBrush QChart::titleBrush() const
228 QBrush QChart::titleBrush() const
228 {
229 {
229 //TODO: refactor me
230 //TODO: refactor me
230 if (!d_ptr->m_presenter->m_titleItem) return QBrush();
231 if (!d_ptr->m_presenter->m_titleItem) return QBrush();
231 return d_ptr->m_presenter->m_titleItem->brush();
232 return d_ptr->m_presenter->m_titleItem->brush();
232 }
233 }
233
234
234 /*!
235 /*!
235 Sets the \a theme used by the chart for rendering the graphical representation of the data.
236 Sets the \a theme used by the chart for rendering the graphical representation of the data.
236
237
237 Note: changing the theme will overwrite all customizations (pen, brush, font, ect.) done to the series.
238 Note: changing the theme will overwrite all customizations (pen, brush, font, ect.) done to the series.
238 \sa theme()
239 \sa theme()
239 */
240 */
240 void QChart::setTheme(QChart::ChartTheme theme)
241 void QChart::setTheme(QChart::ChartTheme theme)
241 {
242 {
242 d_ptr->m_presenter->setTheme(theme);
243 d_ptr->m_presenter->setTheme(theme);
243 }
244 }
244
245
245 /*!
246 /*!
246 Returns the theme enum used by the chart.
247 Returns the theme enum used by the chart.
247 \sa ChartTheme, setTheme()
248 \sa ChartTheme, setTheme()
248 */
249 */
249 QChart::ChartTheme QChart::theme() const
250 QChart::ChartTheme QChart::theme() const
250 {
251 {
251 return d_ptr->m_presenter->theme();
252 return d_ptr->m_presenter->theme();
252 }
253 }
253
254
254 /*!
255 /*!
255 Zooms in the view by a factor of 2
256 Zooms in the view by a factor of 2
256 */
257 */
257 void QChart::zoomIn()
258 void QChart::zoomIn()
258 {
259 {
259 d_ptr->m_presenter->zoomIn(2.0);
260 d_ptr->m_presenter->zoomIn(2.0);
260 }
261 }
261
262
262 /*!
263 /*!
263 Zooms in the view to a maximum level at which \a rect is still fully visible.
264 Zooms in the view to a maximum level at which \a rect is still fully visible.
264 */
265 */
265 void QChart::zoomIn(const QRectF& rect)
266 void QChart::zoomIn(const QRectF& rect)
266 {
267 {
267 if (!rect.isValid()) return;
268 if (!rect.isValid()) return;
268 d_ptr->m_presenter->zoomIn(rect);
269 d_ptr->m_presenter->zoomIn(rect);
269 }
270 }
270
271
271 /*!
272 /*!
272 Restores the view zoom level to the previous one.
273 Restores the view zoom level to the previous one.
273 */
274 */
274 void QChart::zoomOut()
275 void QChart::zoomOut()
275 {
276 {
276 d_ptr->m_presenter->zoomOut(2.0);
277 d_ptr->m_presenter->zoomOut(2.0);
277 }
278 }
278
279
279 /*!
280 /*!
280 Zooms in the view by a \a factor.
281 Zooms in the view by a \a factor.
281
282
282 A factor over 1.0 zooms the view in and factor between 0.0 and 1.0 zooms out.
283 A factor over 1.0 zooms the view in and factor between 0.0 and 1.0 zooms out.
283 */
284 */
284 void QChart::zoom(qreal factor)
285 void QChart::zoom(qreal factor)
285 {
286 {
286 if (qFuzzyIsNull(factor))
287 if (qFuzzyIsNull(factor))
287 return;
288 return;
288
289
289 if (qFuzzyCompare(factor, 1.0))
290 if (qFuzzyCompare(factor, 1.0))
290 return;
291 return;
291
292
292 if (factor < 0)
293 if (factor < 0)
293 return;
294 return;
294
295
295 if (factor > 1.0)
296 if (factor > 1.0)
296 d_ptr->m_presenter->zoomIn(factor);
297 d_ptr->m_presenter->zoomIn(factor);
297 else
298 else
298 d_ptr->m_presenter->zoomOut(1.0 / factor);
299 d_ptr->m_presenter->zoomOut(1.0 / factor);
299 }
300 }
300
301
301 /*!
302 /*!
302 Returns the pointer to the x axis object of the chart
303 Returns the pointer to the x axis object of the chart
303 */
304 */
304 QAxis* QChart::axisX() const
305 QAxis* QChart::axisX() const
305 {
306 {
306 return d_ptr->m_dataset->axisX();
307 return d_ptr->m_dataset->axisX();
307 }
308 }
308
309
309 /*!
310 /*!
310 Returns the pointer to the y axis object of the \a series
311 Returns the pointer to the y axis object of the \a series
311 If no \a series is provided then default Y axis of the chart is returned.
312 If no \a series is provided then default Y axis of the chart is returned.
312 */
313 */
313 QAxis* QChart::axisY(QAbstractSeries *series) const
314 QAxis* QChart::axisY(QAbstractSeries *series) const
314 {
315 {
315 return d_ptr->m_dataset->axisY(series);
316 return d_ptr->m_dataset->axisY(series);
316 }
317 }
317
318
318 /*!
319 /*!
319 Returns the legend object of the chart. Ownership stays in chart.
320 Returns the legend object of the chart. Ownership stays in chart.
320 */
321 */
321 QLegend* QChart::legend() const
322 QLegend* QChart::legend() const
322 {
323 {
323 return d_ptr->m_legend;
324 return d_ptr->m_legend;
324 }
325 }
325
326
326 /*!
327 /*!
327 Returns the rect that contains information about margins (distance between chart widget edge and axes).
328 Returns the rect that contains information about margins (distance between chart widget edge and axes).
328 Individual margins can be obtained by calling left, top, right, bottom on the returned rect.
329 Individual margins can be obtained by calling left, top, right, bottom on the returned rect.
329 */
330 */
330 QRectF QChart::margins() const
331 QRectF QChart::margins() const
331 {
332 {
332 return d_ptr->m_presenter->margins();
333 return d_ptr->m_presenter->margins();
333 }
334 }
334
335
335
336
336 /*!
337 /*!
337 Resizes and updates the chart area using the \a event data
338 Resizes and updates the chart area using the \a event data
338 */
339 */
339 void QChart::resizeEvent(QGraphicsSceneResizeEvent *event)
340 void QChart::resizeEvent(QGraphicsSceneResizeEvent *event)
340 {
341 {
341 d_ptr->m_rect = QRectF(QPoint(0,0),event->newSize());
342 d_ptr->m_rect = QRectF(QPoint(0,0),event->newSize());
342 QGraphicsWidget::resizeEvent(event);
343 QGraphicsWidget::resizeEvent(event);
343 d_ptr->m_presenter->setGeometry(d_ptr->m_rect);
344 d_ptr->m_presenter->setGeometry(d_ptr->m_rect);
344 }
345 }
345
346
346 /*!
347 /*!
347 Sets animation \a options for the chart
348 Sets animation \a options for the chart
348 */
349 */
349 void QChart::setAnimationOptions(AnimationOptions options)
350 void QChart::setAnimationOptions(AnimationOptions options)
350 {
351 {
351 d_ptr->m_presenter->setAnimationOptions(options);
352 d_ptr->m_presenter->setAnimationOptions(options);
352 }
353 }
353
354
354 /*!
355 /*!
355 Returns animation options for the chart
356 Returns animation options for the chart
356 */
357 */
357 QChart::AnimationOptions QChart::animationOptions() const
358 QChart::AnimationOptions QChart::animationOptions() const
358 {
359 {
359 return d_ptr->m_presenter->animationOptions();
360 return d_ptr->m_presenter->animationOptions();
360 }
361 }
361
362
362 /*!
363 /*!
363 Scrolls the visible area of the chart to the left by the distance between two x axis ticks
364 Scrolls the visible area of the chart to the left by the distance between two x axis ticks
364 */
365 */
365 void QChart::scrollLeft()
366 void QChart::scrollLeft()
366 {
367 {
367 d_ptr->m_presenter->scroll(-d_ptr->m_presenter->chartGeometry().width()/(axisX()->ticksCount()-1),0);
368 d_ptr->m_presenter->scroll(-d_ptr->m_presenter->chartGeometry().width()/(axisX()->ticksCount()-1),0);
368 }
369 }
369
370
370 /*!
371 /*!
371 Scrolls the visible area of the chart to the right by the distance between two x axis ticks
372 Scrolls the visible area of the chart to the right by the distance between two x axis ticks
372 */
373 */
373 void QChart::scrollRight()
374 void QChart::scrollRight()
374 {
375 {
375 d_ptr->m_presenter->scroll(d_ptr->m_presenter->chartGeometry().width()/(axisX()->ticksCount()-1),0);
376 d_ptr->m_presenter->scroll(d_ptr->m_presenter->chartGeometry().width()/(axisX()->ticksCount()-1),0);
376 }
377 }
377
378
378 /*!
379 /*!
379 Scrolls the visible area of the chart up by the distance between two y axis ticks
380 Scrolls the visible area of the chart up by the distance between two y axis ticks
380 */
381 */
381 void QChart::scrollUp()
382 void QChart::scrollUp()
382 {
383 {
383 d_ptr->m_presenter->scroll(0,d_ptr->m_presenter->chartGeometry().width()/(axisY()->ticksCount()-1));
384 d_ptr->m_presenter->scroll(0,d_ptr->m_presenter->chartGeometry().width()/(axisY()->ticksCount()-1));
384 }
385 }
385
386
386 /*!
387 /*!
387 Scrolls the visible area of the chart down by the distance between two y axis ticks
388 Scrolls the visible area of the chart down by the distance between two y axis ticks
388 */
389 */
389 void QChart::scrollDown()
390 void QChart::scrollDown()
390 {
391 {
391 d_ptr->m_presenter->scroll(0,-d_ptr->m_presenter->chartGeometry().width()/(axisY()->ticksCount()-1));
392 d_ptr->m_presenter->scroll(0,-d_ptr->m_presenter->chartGeometry().width()/(axisY()->ticksCount()-1));
392 }
393 }
393
394
394 /*!
395 /*!
395 Scrolls the visible area of the chart by the distance defined in the \a delta.
396 Scrolls the visible area of the chart by the distance defined in the \a delta.
396 */
397 */
397 void QChart::scroll(const QPointF &delta)
398 void QChart::scroll(const QPointF &delta)
398 {
399 {
399 d_ptr->m_presenter->scroll(-delta.x(), delta.y());
400 d_ptr->m_presenter->scroll(-delta.x(), delta.y());
400 }
401 }
401
402
402 /*!
403 /*!
403 Sets the chart background visibility state to \a visible
404 Sets the chart background visibility state to \a visible
404 */
405 */
405 void QChart::setBackgroundVisible(bool visible)
406 void QChart::setBackgroundVisible(bool visible)
406 {
407 {
407 //TODO: refactor me
408 //TODO: refactor me
408 d_ptr->m_presenter->createChartBackgroundItem();
409 d_ptr->m_presenter->createChartBackgroundItem();
409 d_ptr->m_presenter->m_backgroundItem->setVisible(visible);
410 d_ptr->m_presenter->m_backgroundItem->setVisible(visible);
410 }
411 }
411
412
412 /*!
413 /*!
413 Returns the chart's background visibility state
414 Returns the chart's background visibility state
414 */
415 */
415 bool QChart::isBackgroundVisible() const
416 bool QChart::isBackgroundVisible() const
416 {
417 {
417 //TODO: refactor me
418 //TODO: refactor me
418 if (!d_ptr->m_presenter->m_backgroundItem)
419 if (!d_ptr->m_presenter->m_backgroundItem)
419 return false;
420 return false;
420
421
421 return d_ptr->m_presenter->m_backgroundItem->isVisible();
422 return d_ptr->m_presenter->m_backgroundItem->isVisible();
422 }
423 }
423
424
424 /*!
425 /*!
425 Sets the background drop shadow effect state to \a enabled.
426 Sets the background drop shadow effect state to \a enabled.
426 */
427 */
427 void QChart::setDropShadowEnabled(bool enabled)
428 void QChart::setDropShadowEnabled(bool enabled)
428 {
429 {
429 d_ptr->m_presenter->createChartBackgroundItem();
430 d_ptr->m_presenter->createChartBackgroundItem();
430 d_ptr->m_presenter->m_backgroundItem->setDropShadowEnabled(enabled);
431 d_ptr->m_presenter->m_backgroundItem->setDropShadowEnabled(enabled);
431 }
432 }
432
433
433 /*!
434 /*!
434 Returns true if the drop shadow effect is enabled for the chart background.
435 Returns true if the drop shadow effect is enabled for the chart background.
435 */
436 */
436 bool QChart::isDropShadowEnabled() const
437 bool QChart::isDropShadowEnabled() const
437 {
438 {
438 if (!d_ptr->m_presenter->m_backgroundItem)
439 if (!d_ptr->m_presenter->m_backgroundItem)
439 return false;
440 return false;
440
441
441 return d_ptr->m_presenter->m_backgroundItem->isDropShadowEnabled();
442 return d_ptr->m_presenter->m_backgroundItem->isDropShadowEnabled();
442 }
443 }
443
444
444 /*!
445 /*!
445 Returns all the series that are added to the chart.
446 Returns all the series that are added to the chart.
446
447
447 \sa addSeries(), removeSeries(), removeAllSeries()
448 \sa addSeries(), removeSeries(), removeAllSeries()
448 */
449 */
449 QList<QAbstractSeries*> QChart::series() const
450 QList<QAbstractSeries*> QChart::series() const
450 {
451 {
451 return d_ptr->m_dataset->series();
452 return d_ptr->m_dataset->series();
452 }
453 }
453
454
454 //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
455 //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
455
456
456 QChartPrivate::QChartPrivate():
457 QChartPrivate::QChartPrivate():
457 m_legend(0),
458 m_legend(0),
458 m_dataset(0),
459 m_dataset(0),
459 m_presenter(0)
460 m_presenter(0)
460 {
461 {
461
462
462 }
463 }
463
464
464 QChartPrivate::~QChartPrivate()
465 QChartPrivate::~QChartPrivate()
465 {
466 {
466
467
467 }
468 }
468
469
469 void QChartPrivate::createConnections()
470 void QChartPrivate::createConnections()
470 {
471 {
471 QObject::connect(m_dataset,SIGNAL(seriesAdded(QAbstractSeries*,Domain*)),m_presenter,SLOT(handleSeriesAdded(QAbstractSeries*,Domain*)));
472 QObject::connect(m_dataset,SIGNAL(seriesAdded(QAbstractSeries*,Domain*)),m_presenter,SLOT(handleSeriesAdded(QAbstractSeries*,Domain*)));
472 QObject::connect(m_dataset,SIGNAL(seriesRemoved(QAbstractSeries*)),m_presenter,SLOT(handleSeriesRemoved(QAbstractSeries*)));
473 QObject::connect(m_dataset,SIGNAL(seriesRemoved(QAbstractSeries*)),m_presenter,SLOT(handleSeriesRemoved(QAbstractSeries*)));
473 QObject::connect(m_dataset,SIGNAL(axisAdded(QAxis*,Domain*)),m_presenter,SLOT(handleAxisAdded(QAxis*,Domain*)));
474 QObject::connect(m_dataset,SIGNAL(axisAdded(QAxis*,Domain*)),m_presenter,SLOT(handleAxisAdded(QAxis*,Domain*)));
474 QObject::connect(m_dataset,SIGNAL(axisRemoved(QAxis*)),m_presenter,SLOT(handleAxisRemoved(QAxis*)));
475 QObject::connect(m_dataset,SIGNAL(axisRemoved(QAxis*)),m_presenter,SLOT(handleAxisRemoved(QAxis*)));
475 }
476 }
476
477
477 #include "moc_qchart.cpp"
478 #include "moc_qchart.cpp"
478
479
479 QTCOMMERCIALCHART_END_NAMESPACE
480 QTCOMMERCIALCHART_END_NAMESPACE
@@ -1,124 +1,133
1 /****************************************************************************
1 /****************************************************************************
2 **
2 **
3 ** Copyright (C) 2012 Digia Plc
3 ** Copyright (C) 2012 Digia Plc
4 ** All rights reserved.
4 ** All rights reserved.
5 ** For any questions to Digia, please use contact form at http://qt.digia.com
5 ** For any questions to Digia, please use contact form at http://qt.digia.com
6 **
6 **
7 ** This file is part of the Qt Commercial Charts Add-on.
7 ** This file is part of the Qt Commercial Charts Add-on.
8 **
8 **
9 ** $QT_BEGIN_LICENSE$
9 ** $QT_BEGIN_LICENSE$
10 ** Licensees holding valid Qt Commercial licenses may use this file in
10 ** Licensees holding valid Qt Commercial licenses may use this file in
11 ** accordance with the Qt Commercial License Agreement provided with the
11 ** accordance with the Qt Commercial License Agreement provided with the
12 ** Software or, alternatively, in accordance with the terms contained in
12 ** Software or, alternatively, in accordance with the terms contained in
13 ** a written agreement between you and Digia.
13 ** a written agreement between you and Digia.
14 **
14 **
15 ** If you have questions regarding the use of this file, please use
15 ** If you have questions regarding the use of this file, please use
16 ** contact form at http://qt.digia.com
16 ** contact form at http://qt.digia.com
17 ** $QT_END_LICENSE$
17 ** $QT_END_LICENSE$
18 **
18 **
19 ****************************************************************************/
19 ****************************************************************************/
20
20
21 #ifndef QCHART_H
21 #ifndef QCHART_H
22 #define QCHART_H
22 #define QCHART_H
23
23
24 #include <QAbstractSeries>
24 #include <QAbstractSeries>
25 #include <QLegend>
25 #include <QLegend>
26 #include <QGraphicsWidget>
26 #include <QGraphicsWidget>
27
27
28 class QGraphicsSceneResizeEvent;
28 class QGraphicsSceneResizeEvent;
29
29
30 QTCOMMERCIALCHART_BEGIN_NAMESPACE
30 QTCOMMERCIALCHART_BEGIN_NAMESPACE
31
31
32 class QAbstractSeries;
32 class QAbstractSeries;
33 class QAxis;
33 class QAxis;
34 class QLegend;
34 class QLegend;
35 struct QChartPrivate;
35 struct QChartPrivate;
36
36
37 class QTCOMMERCIALCHART_EXPORT QChart : public QGraphicsWidget
37 class QTCOMMERCIALCHART_EXPORT QChart : public QGraphicsWidget
38 {
38 {
39 Q_OBJECT
39 Q_OBJECT
40 Q_PROPERTY(QChart::ChartTheme theme READ theme WRITE setTheme)
41 Q_PROPERTY(QString title READ title WRITE setTitle)
42 Q_PROPERTY(bool backgroundVisible READ isBackgroundVisible WRITE setBackgroundVisible)
43 Q_PROPERTY(bool dropShadowEnabled READ isDropShadowEnabled WRITE setDropShadowEnabled)
44 Q_PROPERTY(QChart::AnimationOptions animationOptions READ animationOptions WRITE setAnimationOptions)
45 Q_PROPERTY(QRectF margins READ margins NOTIFY marginsChanged)
40 Q_ENUMS(ChartTheme)
46 Q_ENUMS(ChartTheme)
41 Q_ENUMS(AnimationOption)
47 Q_ENUMS(AnimationOption)
42
48
43 public:
49 public:
44 enum ChartTheme {
50 enum ChartTheme {
45 ChartThemeLight = 0,
51 ChartThemeLight = 0,
46 ChartThemeBlueCerulean,
52 ChartThemeBlueCerulean,
47 ChartThemeDark,
53 ChartThemeDark,
48 ChartThemeBrownSand,
54 ChartThemeBrownSand,
49 ChartThemeBlueNcs,
55 ChartThemeBlueNcs,
50 ChartThemeHighContrast,
56 ChartThemeHighContrast,
51 ChartThemeBlueIcy
57 ChartThemeBlueIcy
52 };
58 };
53
59
54 enum AnimationOption {
60 enum AnimationOption {
55 NoAnimation = 0x0,
61 NoAnimation = 0x0,
56 GridAxisAnimations = 0x1,
62 GridAxisAnimations = 0x1,
57 SeriesAnimations =0x2,
63 SeriesAnimations =0x2,
58 AllAnimations = 0x3
64 AllAnimations = 0x3
59 };
65 };
60
66
61 Q_DECLARE_FLAGS(AnimationOptions, AnimationOption)
67 Q_DECLARE_FLAGS(AnimationOptions, AnimationOption)
62
68
63 public:
69 public:
64 explicit QChart(QGraphicsItem *parent = 0, Qt::WindowFlags wFlags = 0);
70 explicit QChart(QGraphicsItem *parent = 0, Qt::WindowFlags wFlags = 0);
65 ~QChart();
71 ~QChart();
66
72
67 void addSeries(QAbstractSeries *series, QAxis *axisY = 0);
73 void addSeries(QAbstractSeries *series, QAxis *axisY = 0);
68 void removeSeries(QAbstractSeries *series);
74 void removeSeries(QAbstractSeries *series);
69 void removeAllSeries();
75 void removeAllSeries();
70 QList<QAbstractSeries*> series() const;
76 QList<QAbstractSeries*> series() const;
71
77
72 void setTheme(QChart::ChartTheme theme);
78 void setTheme(QChart::ChartTheme theme);
73 QChart::ChartTheme theme() const;
79 QChart::ChartTheme theme() const;
74
80
75 void setTitle(const QString& title);
81 void setTitle(const QString& title);
76 QString title() const;
82 QString title() const;
77 void setTitleFont(const QFont& font);
83 void setTitleFont(const QFont& font);
78 QFont titleFont() const;
84 QFont titleFont() const;
79 void setTitleBrush(const QBrush &brush);
85 void setTitleBrush(const QBrush &brush);
80 QBrush titleBrush() const;
86 QBrush titleBrush() const;
81
87
82 void setBackgroundBrush(const QBrush &brush);
88 void setBackgroundBrush(const QBrush &brush);
83 QBrush backgroundBrush() const;
89 QBrush backgroundBrush() const;
84 void setBackgroundPen(const QPen &pen);
90 void setBackgroundPen(const QPen &pen);
85 QPen backgroundPen() const;
91 QPen backgroundPen() const;
86 void setBackgroundVisible(bool visible = true);
92 void setBackgroundVisible(bool visible = true);
87 bool isBackgroundVisible() const;
93 bool isBackgroundVisible() const;
88
94
89 void setDropShadowEnabled(bool enabled = true);
95 void setDropShadowEnabled(bool enabled = true);
90 bool isDropShadowEnabled() const;
96 bool isDropShadowEnabled() const;
91 void setAnimationOptions(AnimationOptions options);
97 void setAnimationOptions(AnimationOptions options);
92 AnimationOptions animationOptions() const;
98 AnimationOptions animationOptions() const;
93
99
94 void zoomIn();
100 void zoomIn();
95 void zoomIn(const QRectF &rect);
101 void zoomIn(const QRectF &rect);
96 void zoomOut();
102 void zoomOut();
97 void zoom(qreal factor);
103 void zoom(qreal factor);
98 void scrollLeft();
104 void scrollLeft();
99 void scrollRight();
105 void scrollRight();
100 void scrollUp();
106 void scrollUp();
101 void scrollDown();
107 void scrollDown();
102 void scroll(const QPointF &delta);
108 void scroll(const QPointF &delta);
103
109
104 QAxis* axisX() const;
110 QAxis* axisX() const;
105 QAxis* axisY(QAbstractSeries* series = 0) const;
111 QAxis* axisY(QAbstractSeries* series = 0) const;
106
112
107 QLegend* legend() const;
113 QLegend* legend() const;
108 QRectF margins() const;
114 QRectF margins() const;
109
115
116 Q_SIGNALS:
117 void marginsChanged(QRectF newMargins);
118
110 protected:
119 protected:
111 void resizeEvent(QGraphicsSceneResizeEvent *event);
120 void resizeEvent(QGraphicsSceneResizeEvent *event);
112
121
113 protected:
122 protected:
114 QScopedPointer<QChartPrivate> d_ptr;
123 QScopedPointer<QChartPrivate> d_ptr;
115 friend class QLegend;
124 friend class QLegend;
116 friend class ChartPresenter;
125 friend class ChartPresenter;
117 Q_DISABLE_COPY(QChart)
126 Q_DISABLE_COPY(QChart)
118 };
127 };
119
128
120 QTCOMMERCIALCHART_END_NAMESPACE
129 QTCOMMERCIALCHART_END_NAMESPACE
121
130
122 Q_DECLARE_OPERATORS_FOR_FLAGS(QTCOMMERCIALCHART_NAMESPACE::QChart::AnimationOptions)
131 Q_DECLARE_OPERATORS_FOR_FLAGS(QTCOMMERCIALCHART_NAMESPACE::QChart::AnimationOptions)
123
132
124 #endif
133 #endif
@@ -1,72 +1,105
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 ChartView {
24 ChartView {
25 id: chartView
25 id: chartView
26 title: "chart"
26 title: "chart"
27 anchors.fill: parent
27 anchors.fill: parent
28 property variant series: chartView
28 property variant series: chartView
29
29
30 LineSeries {
30 LineSeries {
31 name: "line"
31 name: "line"
32 XyPoint { x: 0; y: 0 }
32 XyPoint { x: 0; y: 0 }
33 XyPoint { x: 1.1; y: 2.1 }
33 XyPoint { x: 1.1; y: 2.1 }
34 XyPoint { x: 1.9; y: 3.3 }
34 XyPoint { x: 1.9; y: 3.3 }
35 XyPoint { x: 2.1; y: 2.1 }
35 XyPoint { x: 2.1; y: 2.1 }
36 XyPoint { x: 2.9; y: 4.9 }
36 XyPoint { x: 2.9; y: 4.9 }
37 XyPoint { x: 3.4; y: 3.0 }
37 XyPoint { x: 3.4; y: 3.0 }
38 XyPoint { x: 4.1; y: 3.3 }
38 XyPoint { x: 4.1; y: 3.3 }
39 }
39 }
40
40
41 onVisibleChanged: console.log("chart.onVisibleChanged: " + series.visible);
41 onVisibleChanged: console.log("chart.onVisibleChanged: " + visible);
42 onTitleColorChanged: console.log("chart.onTitleColorChanged: " + series.titleColor);
42 onTitleColorChanged: console.log("chart.onTitleColorChanged: " + color);
43 onBackgroundColorChanged: console.log("chart.onBackgroundColorChanged: " + series.backgroundColor);
43 onBackgroundColorChanged: console.log("chart.onBackgroundColorChanged: " + series.backgroundColor);
44 onDropShadowEnabledChanged: console.log("chart.onDropShadowEnabledChanged: " + enabled);
44 onDropShadowEnabledChanged: console.log("chart.onDropShadowEnabledChanged: " + enabled);
45 onTopMarginChanged: {
46 console.log("chart.onTopMarginChanged: " + margin);
47 marginVisualizer.opacity = 1.0;
48 }
49 onBottomMarginChanged: {
50 console.log("chart.onBottomMarginChanged: " + margin);
51 marginVisualizer.opacity = 1.0;
52 }
53 onLeftMarginChanged: {
54 console.log("chart.onLeftMarginChanged: " + margin);
55 marginVisualizer.opacity = 1.0;
56 }
57 onRightMarginChanged: {
58 console.log("chart.onRightMarginChanged: " + margin);
59 marginVisualizer.opacity = 1.0;
60 }
45
61
46 legend.onVisibleChanged: console.log("legend.onVisibleChanged: " + series.legend.visible);
62 legend.onVisibleChanged: console.log("legend.onVisibleChanged: " + series.legend.visible);
47 legend.onBackgroundVisibleChanged: console.log("legend.onBackgroundVisibleChanged: " + visible);
63 legend.onBackgroundVisibleChanged: console.log("legend.onBackgroundVisibleChanged: " + visible);
48 legend.onColorChanged: console.log("legend.onColorChanged: " + color);
64 legend.onColorChanged: console.log("legend.onColorChanged: " + color);
49 legend.onBorderColorChanged: console.log("legend.onBorderColorChanged: " + color);
65 legend.onBorderColorChanged: console.log("legend.onBorderColorChanged: " + color);
50
66
51 axisX.onColorChanged: console.log("axisX.onColorChanged: " + color);
67 axisX.onColorChanged: console.log("axisX.onColorChanged: " + color);
52 axisX.onLabelsVisibleChanged: console.log("axisX.onLabelsVisibleChanged: " + visible);
68 axisX.onLabelsVisibleChanged: console.log("axisX.onLabelsVisibleChanged: " + visible);
53 axisX.onLabelsColorChanged: console.log("axisX.onLabelsColorChanged: " + color);
69 axisX.onLabelsColorChanged: console.log("axisX.onLabelsColorChanged: " + color);
54 axisX.onVisibleChanged: console.log("axisX.onVisibleChanged: " + visible);
70 axisX.onVisibleChanged: console.log("axisX.onVisibleChanged: " + visible);
55 axisX.onGridVisibleChanged: console.log("axisX.onGridVisibleChanged: " + visible);
71 axisX.onGridVisibleChanged: console.log("axisX.onGridVisibleChanged: " + visible);
56 axisX.onShadesVisibleChanged: console.log("axisX.onShadesVisibleChanged: " + visible);
72 axisX.onShadesVisibleChanged: console.log("axisX.onShadesVisibleChanged: " + visible);
57 axisX.onShadesColorChanged: console.log("axisX.onShadesColorChanged: " + color);
73 axisX.onShadesColorChanged: console.log("axisX.onShadesColorChanged: " + color);
58 axisX.onShadesBorderColorChanged: console.log("axisX.onShadesBorderColorChanged: " + color);
74 axisX.onShadesBorderColorChanged: console.log("axisX.onShadesBorderColorChanged: " + color);
59 axisX.onMinChanged: console.log("axisX.onMinChanged: " + min);
75 axisX.onMinChanged: console.log("axisX.onMinChanged: " + min);
60 axisX.onMaxChanged: console.log("axisX.onMaxChanged: " + max);
76 axisX.onMaxChanged: console.log("axisX.onMaxChanged: " + max);
61
77
62 axisY.onColorChanged: console.log("axisY.onColorChanged: " + color);
78 axisY.onColorChanged: console.log("axisY.onColorChanged: " + color);
63 axisY.onLabelsVisibleChanged: console.log("axisY.onLabelsVisibleChanged: " + visible);
79 axisY.onLabelsVisibleChanged: console.log("axisY.onLabelsVisibleChanged: " + visible);
64 axisY.onLabelsColorChanged: console.log("axisY.onLabelsColorChanged: " + color);
80 axisY.onLabelsColorChanged: console.log("axisY.onLabelsColorChanged: " + color);
65 axisY.onVisibleChanged: console.log("axisY.onVisibleChanged: " + visible);
81 axisY.onVisibleChanged: console.log("axisY.onVisibleChanged: " + visible);
66 axisY.onGridVisibleChanged: console.log("axisY.onGridVisibleChanged: " + visible);
82 axisY.onGridVisibleChanged: console.log("axisY.onGridVisibleChanged: " + visible);
67 axisY.onShadesVisibleChanged: console.log("axisY.onShadesVisibleChanged: " + visible);
83 axisY.onShadesVisibleChanged: console.log("axisY.onShadesVisibleChanged: " + visible);
68 axisY.onShadesColorChanged: console.log("axisY.onShadesColorChanged: " + color);
84 axisY.onShadesColorChanged: console.log("axisY.onShadesColorChanged: " + color);
69 axisY.onShadesBorderColorChanged: console.log("axisY.onShadesBorderColorChanged: " + color);
85 axisY.onShadesBorderColorChanged: console.log("axisY.onShadesBorderColorChanged: " + color);
70 axisY.onMinChanged: console.log("axisY.onMinChanged: " + min);
86 axisY.onMinChanged: console.log("axisY.onMinChanged: " + min);
71 axisY.onMaxChanged: console.log("axisY.onMaxChanged: " + max);
87 axisY.onMaxChanged: console.log("axisY.onMaxChanged: " + max);
88
89
90 Rectangle {
91 id: marginVisualizer
92 color: "transparent"
93 border.color: "red"
94 anchors.fill: parent
95 anchors.topMargin: parent.topMargin
96 anchors.bottomMargin: parent.bottomMargin
97 anchors.leftMargin: parent.leftMargin
98 anchors.rightMargin: parent.rightMargin
99 opacity: 0.0
100 onOpacityChanged: if (opacity == 1.0) opacity = 0.0;
101 Behavior on opacity {
102 NumberAnimation { duration: 800 }
103 }
104 }
72 }
105 }
General Comments 0
You need to be logged in to leave comments. Login now