##// END OF EJS Templates
Added animation configuration to QML chart api
Tero Ahola -
r1094:1573ff98f497
parent child
Show More
@@ -1,57 +1,58
1 /****************************************************************************
1 /****************************************************************************
2 **
2 **
3 ** Copyright (C) 2012 Digia Plc
3 ** Copyright (C) 2012 Digia Plc
4 ** All rights reserved.
4 ** All rights reserved.
5 ** For any questions to Digia, please use contact form at http://qt.digia.com
5 ** For any questions to Digia, please use contact form at http://qt.digia.com
6 **
6 **
7 ** This file is part of the Qt Commercial Charts Add-on.
7 ** This file is part of the Qt Commercial Charts Add-on.
8 **
8 **
9 ** $QT_BEGIN_LICENSE$
9 ** $QT_BEGIN_LICENSE$
10 ** Licensees holding valid Qt Commercial licenses may use this file in
10 ** Licensees holding valid Qt Commercial licenses may use this file in
11 ** accordance with the Qt Commercial License Agreement provided with the
11 ** accordance with the Qt Commercial License Agreement provided with the
12 ** Software or, alternatively, in accordance with the terms contained in
12 ** Software or, alternatively, in accordance with the terms contained in
13 ** a written agreement between you and Digia.
13 ** a written agreement between you and Digia.
14 **
14 **
15 ** If you have questions regarding the use of this file, please use
15 ** If you have questions regarding the use of this file, please use
16 ** contact form at http://qt.digia.com
16 ** contact form at http://qt.digia.com
17 ** $QT_END_LICENSE$
17 ** $QT_END_LICENSE$
18 **
18 **
19 ****************************************************************************/
19 ****************************************************************************/
20
20
21 import QtQuick 1.0
21 import QtQuick 1.0
22 import QtCommercial.Chart 1.0
22 import QtCommercial.Chart 1.0
23
23
24 Rectangle {
24 Rectangle {
25 anchors.fill: parent
25 anchors.fill: parent
26
26
27 Chart {
27 Chart {
28 title: "Line&Spline"
28 title: "Line&Spline"
29 anchors.fill: parent
29 anchors.fill: parent
30 theme: Chart.ChartThemeBrownSand
30 theme: Chart.ChartThemeBrownSand
31 animationOptions: Chart.NoAnimation
31
32
32 LineSeries {
33 LineSeries {
33 name: "Line"
34 name: "Line"
34 points: [
35 points: [
35 XyPoint { x: 0.0; y: 0.0 },
36 XyPoint { x: 0.0; y: 0.0 },
36 XyPoint { x: 1.1; y: 2.1 },
37 XyPoint { x: 1.1; y: 2.1 },
37 XyPoint { x: 1.9; y: 3.3 },
38 XyPoint { x: 1.9; y: 3.3 },
38 XyPoint { x: 2.9; y: 4.9 },
39 XyPoint { x: 2.9; y: 4.9 },
39 XyPoint { x: 3.2; y: 3.0 },
40 XyPoint { x: 3.2; y: 3.0 },
40 XyPoint { x: 4.0; y: 3.3 }
41 XyPoint { x: 4.0; y: 3.3 }
41 ]
42 ]
42 }
43 }
43
44
44 SplineSeries {
45 SplineSeries {
45 name: "Spline"
46 name: "Spline"
46 points: [
47 points: [
47 XyPoint { x: 0.0; y: 0.3 },
48 XyPoint { x: 0.0; y: 0.3 },
48 XyPoint { x: 1.1; y: 3.2 },
49 XyPoint { x: 1.1; y: 3.2 },
49 XyPoint { x: 1.7; y: 2.4 },
50 XyPoint { x: 1.7; y: 2.4 },
50 XyPoint { x: 2.1; y: 2.1 },
51 XyPoint { x: 2.1; y: 2.1 },
51 XyPoint { x: 2.9; y: 2.6 },
52 XyPoint { x: 2.9; y: 2.6 },
52 XyPoint { x: 3.4; y: 2.3 },
53 XyPoint { x: 3.4; y: 2.3 },
53 XyPoint { x: 4.1; y: 3.1 }
54 XyPoint { x: 4.1; y: 3.1 }
54 ]
55 ]
55 }
56 }
56 }
57 }
57 }
58 }
@@ -1,66 +1,78
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
23
24 QTCOMMERCIALCHART_BEGIN_NAMESPACE
24 QTCOMMERCIALCHART_BEGIN_NAMESPACE
25
25
26 DeclarativeChart::DeclarativeChart(QDeclarativeItem *parent)
26 DeclarativeChart::DeclarativeChart(QDeclarativeItem *parent)
27 : QDeclarativeItem(parent),
27 : QDeclarativeItem(parent),
28 m_chart(new QChart(this))
28 m_chart(new QChart(this))
29 {
29 {
30 m_chart->setAnimationOptions(QChart::SeriesAnimations);
30 m_chart->setAnimationOptions(QChart::SeriesAnimations);
31 setFlag(QGraphicsItem::ItemHasNoContents, false);
31 setFlag(QGraphicsItem::ItemHasNoContents, false);
32 }
32 }
33
33
34 DeclarativeChart::~DeclarativeChart()
34 DeclarativeChart::~DeclarativeChart()
35 {
35 {
36 delete m_chart;
36 delete m_chart;
37 }
37 }
38
38
39 QChart::ChartTheme DeclarativeChart::theme()
40 {
41 return m_chart->theme();
42 }
43
44 void DeclarativeChart::geometryChanged(const QRectF &newGeometry, const QRectF &oldGeometry)
39 void DeclarativeChart::geometryChanged(const QRectF &newGeometry, const QRectF &oldGeometry)
45 {
40 {
46 Q_UNUSED(oldGeometry)
41 Q_UNUSED(oldGeometry)
47
42
48 if (newGeometry.isValid()) {
43 if (newGeometry.isValid()) {
49 if (newGeometry.width() > 0 && newGeometry.height() > 0) {
44 if (newGeometry.width() > 0 && newGeometry.height() > 0) {
50 m_chart->resize(newGeometry.width(), newGeometry.height());
45 m_chart->resize(newGeometry.width(), newGeometry.height());
51 }
46 }
52 }
47 }
53 }
48 }
54
49
55 void DeclarativeChart::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget)
50 void DeclarativeChart::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget)
56 {
51 {
57 Q_UNUSED(option)
52 Q_UNUSED(option)
58 Q_UNUSED(widget)
53 Q_UNUSED(widget)
59
54
60 // TODO: optimized?
55 // TODO: optimized?
61 painter->setRenderHint(QPainter::Antialiasing, true);
56 painter->setRenderHint(QPainter::Antialiasing, true);
62 }
57 }
63
58
59 void DeclarativeChart::setAnimationOptions(QChart::AnimationOption animations)
60 {
61 m_chart->setAnimationOptions(animations);
62 }
63
64 QChart::AnimationOption DeclarativeChart::animationOptions()
65 {
66 if (m_chart->animationOptions().testFlag(QChart::AllAnimations))
67 return QChart::AllAnimations;
68 else if (m_chart->animationOptions().testFlag(QChart::GridAxisAnimations))
69 return QChart::GridAxisAnimations;
70 else if (m_chart->animationOptions().testFlag(QChart::SeriesAnimations))
71 return QChart::SeriesAnimations;
72 else
73 return QChart::NoAnimation;
74 }
75
64 #include "moc_declarativechart.cpp"
76 #include "moc_declarativechart.cpp"
65
77
66 QTCOMMERCIALCHART_END_NAMESPACE
78 QTCOMMERCIALCHART_END_NAMESPACE
@@ -1,61 +1,64
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
27
28 QTCOMMERCIALCHART_BEGIN_NAMESPACE
28 QTCOMMERCIALCHART_BEGIN_NAMESPACE
29
29
30 // TODO: Derive from QChart for easier definition of properties?
30 // TODO: Derive from QChart for easier definition of properties?
31 class DeclarativeChart : public QDeclarativeItem
31 class DeclarativeChart : public QDeclarativeItem
32 // TODO: for QTQUICK2: extend QQuickPainterItem instead
32 // TODO: for QTQUICK2: extend QQuickPainterItem instead
33 //class DeclarativeChart : public QQuickPaintedItem, public Chart
33 //class DeclarativeChart : public QQuickPaintedItem, public Chart
34 {
34 {
35 Q_OBJECT
35 Q_OBJECT
36 Q_PROPERTY(QChart::ChartTheme theme READ theme WRITE setTheme)
36 Q_PROPERTY(QChart::ChartTheme theme READ theme WRITE setTheme)
37 Q_PROPERTY(QChart::AnimationOption animationOptions READ animationOptions WRITE setAnimationOptions)
37 Q_PROPERTY(QString title READ title WRITE setTitle)
38 Q_PROPERTY(QString title READ title WRITE setTitle)
38
39
39 public:
40 public:
40 DeclarativeChart(QDeclarativeItem *parent = 0);
41 DeclarativeChart(QDeclarativeItem *parent = 0);
41 ~DeclarativeChart();
42 ~DeclarativeChart();
42
43
43 public: // From QDeclarativeItem/QGraphicsItem
44 public: // From QDeclarativeItem/QGraphicsItem
44 void geometryChanged(const QRectF &newGeometry, const QRectF &oldGeometry);
45 void geometryChanged(const QRectF &newGeometry, const QRectF &oldGeometry);
45 void paint (QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget = 0);
46 void paint (QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget = 0);
46
47
47 public:
48 public:
48 void setTheme(QChart::ChartTheme theme) {m_chart->setTheme(theme);}
49 void setTheme(QChart::ChartTheme theme) {m_chart->setTheme(theme);}
49 QChart::ChartTheme theme();
50 QChart::ChartTheme theme() {return m_chart->theme();}
51 void setAnimationOptions(QChart::AnimationOption animations);
52 QChart::AnimationOption animationOptions();
50 void setTitle(QString title) {m_chart->setTitle(title);}
53 void setTitle(QString title) {m_chart->setTitle(title);}
51 QString title() { return m_chart->title();}
54 QString title() { return m_chart->title();}
52
55
53 public:
56 public:
54 // Extending QChart with DeclarativeChart is not possible because QObject does not support
57 // Extending QChart with DeclarativeChart is not possible because QObject does not support
55 // multi inheritance, so we now have a QChart as a member instead
58 // multi inheritance, so we now have a QChart as a member instead
56 QChart *m_chart;
59 QChart *m_chart;
57 };
60 };
58
61
59 QTCOMMERCIALCHART_END_NAMESPACE
62 QTCOMMERCIALCHART_END_NAMESPACE
60
63
61 #endif // DECLARATIVECHART_H
64 #endif // DECLARATIVECHART_H
@@ -1,120 +1,121
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_ENUMS(ChartTheme)
40 Q_ENUMS(ChartTheme)
41 Q_ENUMS(AnimationOption)
41
42
42 public:
43 public:
43 enum ChartTheme {
44 enum ChartTheme {
44 ChartThemeLight = 0,
45 ChartThemeLight = 0,
45 ChartThemeBlueCerulean,
46 ChartThemeBlueCerulean,
46 ChartThemeDark,
47 ChartThemeDark,
47 ChartThemeBrownSand,
48 ChartThemeBrownSand,
48 ChartThemeBlueNcs,
49 ChartThemeBlueNcs,
49 ChartThemeHighContrast,
50 ChartThemeHighContrast,
50 ChartThemeBlueIcy
51 ChartThemeBlueIcy
51 };
52 };
52
53
53 enum AnimationOption {
54 enum AnimationOption {
54 NoAnimation = 0x0,
55 NoAnimation = 0x0,
55 GridAxisAnimations = 0x1,
56 GridAxisAnimations = 0x1,
56 SeriesAnimations =0x2,
57 SeriesAnimations =0x2,
57 AllAnimations = 0x3
58 AllAnimations = 0x3
58 };
59 };
59
60
60 Q_DECLARE_FLAGS(AnimationOptions, AnimationOption)
61 Q_DECLARE_FLAGS(AnimationOptions, AnimationOption)
61
62
62 public:
63 public:
63 explicit QChart(QGraphicsItem *parent = 0, Qt::WindowFlags wFlags = 0);
64 explicit QChart(QGraphicsItem *parent = 0, Qt::WindowFlags wFlags = 0);
64 ~QChart();
65 ~QChart();
65
66
66 void addSeries(QAbstractSeries *series, QAxis *axisY = 0);
67 void addSeries(QAbstractSeries *series, QAxis *axisY = 0);
67 void removeSeries(QAbstractSeries *series);
68 void removeSeries(QAbstractSeries *series);
68 void removeAllSeries();
69 void removeAllSeries();
69
70
70 void setTheme(QChart::ChartTheme theme);
71 void setTheme(QChart::ChartTheme theme);
71 QChart::ChartTheme theme() const;
72 QChart::ChartTheme theme() const;
72
73
73 void setTitle(const QString& title);
74 void setTitle(const QString& title);
74 QString title() const;
75 QString title() const;
75 void setTitleFont(const QFont& font);
76 void setTitleFont(const QFont& font);
76 QFont titleFont() const;
77 QFont titleFont() const;
77 void setTitleBrush(const QBrush &brush);
78 void setTitleBrush(const QBrush &brush);
78 QBrush titleBrush() const;
79 QBrush titleBrush() const;
79
80
80 void setBackgroundBrush(const QBrush &brush);
81 void setBackgroundBrush(const QBrush &brush);
81 QBrush backgroundBrush() const;
82 QBrush backgroundBrush() const;
82 void setBackgroundPen(const QPen &pen);
83 void setBackgroundPen(const QPen &pen);
83 QPen backgroundPen() const;
84 QPen backgroundPen() const;
84 void setBackgroundVisible(bool visible = true);
85 void setBackgroundVisible(bool visible = true);
85 bool isBackgroundVisible() const;
86 bool isBackgroundVisible() const;
86 void setBackgroundDropShadowEnabled(bool enabled = true);
87 void setBackgroundDropShadowEnabled(bool enabled = true);
87 bool isBackgroundDropShadowEnabled() const;
88 bool isBackgroundDropShadowEnabled() const;
88
89
89 void setAnimationOptions(AnimationOptions options);
90 void setAnimationOptions(AnimationOptions options);
90 AnimationOptions animationOptions() const;
91 AnimationOptions animationOptions() const;
91
92
92 void zoomIn();
93 void zoomIn();
93 void zoomIn(const QRectF &rect);
94 void zoomIn(const QRectF &rect);
94 void zoomOut();
95 void zoomOut();
95 void scrollLeft();
96 void scrollLeft();
96 void scrollRight();
97 void scrollRight();
97 void scrollUp();
98 void scrollUp();
98 void scrollDown();
99 void scrollDown();
99
100
100 QAxis* axisX() const;
101 QAxis* axisX() const;
101 QAxis* axisY(QAbstractSeries* series = 0) const;
102 QAxis* axisY(QAbstractSeries* series = 0) const;
102
103
103 QLegend* legend() const;
104 QLegend* legend() const;
104 QRectF margins() const;
105 QRectF margins() const;
105
106
106 protected:
107 protected:
107 void resizeEvent(QGraphicsSceneResizeEvent *event);
108 void resizeEvent(QGraphicsSceneResizeEvent *event);
108
109
109 protected:
110 protected:
110 QScopedPointer<QChartPrivate> d_ptr;
111 QScopedPointer<QChartPrivate> d_ptr;
111 friend class QLegend;
112 friend class QLegend;
112 friend class ChartPresenter;
113 friend class ChartPresenter;
113 Q_DISABLE_COPY(QChart)
114 Q_DISABLE_COPY(QChart)
114 };
115 };
115
116
116 QTCOMMERCIALCHART_END_NAMESPACE
117 QTCOMMERCIALCHART_END_NAMESPACE
117
118
118 Q_DECLARE_OPERATORS_FOR_FLAGS(QTCOMMERCIALCHART_NAMESPACE::QChart::AnimationOptions)
119 Q_DECLARE_OPERATORS_FOR_FLAGS(QTCOMMERCIALCHART_NAMESPACE::QChart::AnimationOptions)
119
120
120 #endif
121 #endif
General Comments 0
You need to be logged in to leave comments. Login now