@@ -1,45 +1,45 | |||||
1 | #ifndef DECLARATIVECHART_H |
|
1 | #ifndef DECLARATIVECHART_H | |
2 | #define DECLARATIVECHART_H |
|
2 | #define DECLARATIVECHART_H | |
3 |
|
3 | |||
4 | #include <QtCore/QtGlobal> |
|
4 | #include <QtCore/QtGlobal> | |
5 | #include <QDeclarativeItem> |
|
5 | #include <QDeclarativeItem> | |
6 | #include <qchart.h> |
|
6 | #include <qchart.h> | |
7 |
|
7 | |||
8 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
8 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
9 |
|
9 | |||
10 | class DeclarativeChart : public QDeclarativeItem |
|
10 | class DeclarativeChart : public QDeclarativeItem | |
11 | // TODO: for QTQUICK2: extend QQuickPainterItem instead |
|
11 | // TODO: for QTQUICK2: extend QQuickPainterItem instead | |
12 | //class DeclarativeChart : public QQuickPaintedItem, public Chart |
|
12 | //class DeclarativeChart : public QQuickPaintedItem, public Chart | |
13 | { |
|
13 | { | |
14 | Q_OBJECT |
|
14 | Q_OBJECT | |
15 | Q_ENUMS(ChartTheme) |
|
15 | Q_ENUMS(ChartTheme) | |
16 | Q_PROPERTY(ChartTheme theme READ theme WRITE setTheme) |
|
16 | Q_PROPERTY(ChartTheme theme READ theme WRITE setTheme) | |
17 |
|
17 | |||
18 | public: |
|
18 | public: | |
19 | enum ChartTheme { |
|
19 | enum ChartTheme { | |
20 | ThemeInvalid = QChart::ChartThemeInvalid, |
|
20 | ThemeInvalid = QChart::ChartThemeInvalid, | |
21 | ThemeDefault, |
|
21 | ThemeDefault, | |
22 | ThemeVanilla, |
|
22 | ThemeVanilla, | |
23 | ThemeIcy, |
|
23 | ThemeIcy, | |
24 | ThemeGrayscale, |
|
24 | ThemeGrayscale, | |
25 |
|
|
25 | ThemeScientific, | |
26 | ThemeUnnamed1 |
|
26 | ThemeUnnamed1 | |
27 | }; |
|
27 | }; | |
28 | DeclarativeChart(QDeclarativeItem *parent = 0); |
|
28 | DeclarativeChart(QDeclarativeItem *parent = 0); | |
29 |
|
29 | |||
30 | public: // From QDeclarativeItem/QGraphicsItem |
|
30 | public: // From QDeclarativeItem/QGraphicsItem | |
31 | void geometryChanged(const QRectF &newGeometry, const QRectF &oldGeometry); |
|
31 | void geometryChanged(const QRectF &newGeometry, const QRectF &oldGeometry); | |
32 |
|
32 | |||
33 | public: |
|
33 | public: | |
34 | void setTheme(ChartTheme theme) {m_chart->setTheme((QChart::ChartThemeId) theme);} |
|
34 | void setTheme(ChartTheme theme) {m_chart->setTheme((QChart::ChartThemeId) theme);} | |
35 | ChartTheme theme(); |
|
35 | ChartTheme theme(); | |
36 |
|
36 | |||
37 | public: |
|
37 | public: | |
38 | // Extending QChart with DeclarativeChart is not possible because QObject does not support |
|
38 | // Extending QChart with DeclarativeChart is not possible because QObject does not support | |
39 | // multi inheritance, so we now have a QChart as a member instead |
|
39 | // multi inheritance, so we now have a QChart as a member instead | |
40 | QChart *m_chart; |
|
40 | QChart *m_chart; | |
41 | }; |
|
41 | }; | |
42 |
|
42 | |||
43 | QTCOMMERCIALCHART_END_NAMESPACE |
|
43 | QTCOMMERCIALCHART_END_NAMESPACE | |
44 |
|
44 | |||
45 | #endif // DECLARATIVECHART_H |
|
45 | #endif // DECLARATIVECHART_H |
@@ -1,106 +1,112 | |||||
1 | #include "charttheme_p.h" |
|
1 | #include "charttheme_p.h" | |
2 | #include "qchart.h" |
|
2 | #include "qchart.h" | |
3 |
|
3 | |||
4 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
4 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
5 |
|
5 | |||
6 | void ChartThemeData::setTheme(int theme) |
|
6 | void ChartThemeData::setTheme(int theme) | |
7 | { |
|
7 | { | |
8 | m_seriesThemes.clear(); |
|
8 | m_seriesThemes.clear(); | |
9 | m_seriesIndex = 0; |
|
9 | m_seriesIndex = 0; | |
10 | m_currentTheme = theme; |
|
10 | m_currentTheme = theme; | |
11 |
|
11 | |||
12 | switch (theme) { |
|
12 | switch (theme) { | |
13 | case QChart::ChartThemeDefault: |
|
13 | case QChart::ChartThemeDefault: | |
14 | // line: solid, dashed, dotted |
|
14 | // line: solid, dashed, dotted | |
15 | // line width: 1 |
|
15 | // line width: 1 | |
16 | // line color (and opacity) |
|
16 | // line color (and opacity) | |
17 | // line shadow (on/off) |
|
17 | // line shadow (on/off) | |
18 | // marker shape: "x", "o", "." |
|
18 | // marker shape: "x", "o", "." | |
19 | // TODO: define the default theme based on the OS |
|
19 | // TODO: define the default theme based on the OS | |
20 | m_seriesThemes.append(SeriesTheme(QRgb(0xff000000), 2)); |
|
20 | m_seriesThemes.append(SeriesTheme(QRgb(0xff000000), 2)); | |
21 | m_seriesThemes.append(SeriesTheme(QRgb(0xff707070), 2)); |
|
21 | m_seriesThemes.append(SeriesTheme(QRgb(0xff707070), 2)); | |
22 | m_gradientStartColor = QColor(QRgb(0xffffffff)); |
|
22 | m_gradientStartColor = QColor(QRgb(0xffffffff)); | |
23 | m_gradientEndColor = QColor(QRgb(0xffafafaf)); |
|
23 | m_gradientEndColor = QColor(QRgb(0xffafafaf)); | |
24 | break; |
|
24 | break; | |
25 | case QChart::ChartThemeVanilla: |
|
25 | case QChart::ChartThemeVanilla: | |
26 | m_seriesThemes.append(SeriesTheme(QColor(217, 197, 116), 6)); |
|
26 | m_seriesThemes.append(SeriesTheme(QColor(217, 197, 116), 6)); | |
27 | m_seriesThemes.append(SeriesTheme(QColor(214, 168, 150), 4)); |
|
27 | m_seriesThemes.append(SeriesTheme(QColor(214, 168, 150), 4)); | |
28 | m_seriesThemes.append(SeriesTheme(QColor(160, 160, 113), 6)); |
|
28 | m_seriesThemes.append(SeriesTheme(QColor(160, 160, 113), 6)); | |
29 | m_seriesThemes.append(SeriesTheme(QColor(210, 210, 52), 4)); |
|
29 | m_seriesThemes.append(SeriesTheme(QColor(210, 210, 52), 4)); | |
30 | m_seriesThemes.append(SeriesTheme(QColor(136, 114, 58), 6)); |
|
30 | m_seriesThemes.append(SeriesTheme(QColor(136, 114, 58), 6)); | |
31 |
|
31 | |||
32 | m_gradientStartColor = QColor(QRgb(0xff9d844d)); |
|
32 | m_gradientStartColor = QColor(QRgb(0xff9d844d)); | |
33 | m_gradientEndColor = QColor(QRgb(0xffafafaf)); |
|
33 | m_gradientEndColor = QColor(QRgb(0xffafafaf)); | |
34 | break; |
|
34 | break; | |
35 | case QChart::ChartThemeIcy: |
|
35 | case QChart::ChartThemeIcy: | |
36 |
m_seriesThemes.append(SeriesTheme(Q |
|
36 | m_seriesThemes.append(SeriesTheme(QRgb(0xFF0D2673), 2)); | |
37 |
m_seriesThemes.append(SeriesTheme(Q |
|
37 | m_seriesThemes.append(SeriesTheme(QRgb(0xFF2685BF), 2)); | |
38 |
m_seriesThemes.append(SeriesTheme(Q |
|
38 | m_seriesThemes.append(SeriesTheme(QRgb(0xFF3DADD9), 3)); | |
39 |
m_seriesThemes.append(SeriesTheme(Q |
|
39 | m_seriesThemes.append(SeriesTheme(QRgb(0xFF62C3D9), 2)); | |
40 | m_seriesThemes.append(SeriesTheme(QColor(19, 71, 90), 2)); |
|
|||
41 | m_seriesThemes.append(SeriesTheme(QColor(110, 70, 228), 2)); |
|
|||
42 |
|
40 | |||
43 |
m_gradientStartColor = QColor(QRgb(0xff |
|
41 | m_gradientStartColor = QColor(QRgb(0xffBDE3F2)); | |
44 |
m_gradientEndColor = QColor(QRgb(0xff |
|
42 | m_gradientEndColor = QColor(QRgb(0xffafafaf)); | |
45 | break; |
|
43 | break; | |
46 | case QChart::ChartThemeGrayscale: |
|
44 | case QChart::ChartThemeGrayscale: | |
47 |
m_seriesThemes.append(SeriesTheme(Q |
|
45 | m_seriesThemes.append(SeriesTheme(QRgb(0xFF869299), 2)); | |
48 |
m_seriesThemes.append(SeriesTheme(Q |
|
46 | m_seriesThemes.append(SeriesTheme(QRgb(0xFFA5BDCC), 2)); | |
49 |
m_seriesThemes.append(SeriesTheme(Q |
|
47 | m_seriesThemes.append(SeriesTheme(QRgb(0xFFE8FFFC), 3)); | |
50 |
m_seriesThemes.append(SeriesTheme(Q |
|
48 | m_seriesThemes.append(SeriesTheme(QRgb(0xFFCCC2C2), 2)); | |
51 | m_seriesThemes.append(SeriesTheme(QColor(180, 180, 180), 2)); |
|
|||
52 |
|
49 | |||
53 | m_gradientStartColor = QColor(QRgb(0xffffffff)); |
|
50 | m_gradientStartColor = QColor(QRgb(0xffffffff)); | |
54 | m_gradientEndColor = QColor(QRgb(0xffafafaf)); |
|
51 | m_gradientEndColor = QColor(QRgb(0xffafafaf)); | |
55 | break; |
|
52 | break; | |
|
53 | case QChart::ChartThemeScientific: | |||
|
54 | m_seriesThemes.append(SeriesTheme(QRgb(0xFF000000), 3)); | |||
|
55 | m_seriesThemes.append(SeriesTheme(QRgb(0xFFFFAD00), 2)); | |||
|
56 | m_seriesThemes.append(SeriesTheme(QRgb(0xFF596A75), 2)); | |||
|
57 | m_seriesThemes.append(SeriesTheme(QRgb(0xFF474747), 2)); | |||
|
58 | ||||
|
59 | m_gradientStartColor = QColor(QRgb(0xffafafaf)); | |||
|
60 | m_gradientEndColor = QColor(QRgb(0xffafafaf)); | |||
|
61 | break; | |||
56 | case QChart::ChartThemeUnnamed1: |
|
62 | case QChart::ChartThemeUnnamed1: | |
57 | m_seriesThemes.append(SeriesTheme(QColor(QRgb(0xff3fa9f5)), 2)); |
|
63 | m_seriesThemes.append(SeriesTheme(QColor(QRgb(0xff3fa9f5)), 2)); | |
58 | m_seriesThemes.append(SeriesTheme(QColor(QRgb(0xff7AC943)), 2)); |
|
64 | m_seriesThemes.append(SeriesTheme(QColor(QRgb(0xff7AC943)), 2)); | |
59 | m_seriesThemes.append(SeriesTheme(QColor(QRgb(0xffFF931E)), 2)); |
|
65 | m_seriesThemes.append(SeriesTheme(QColor(QRgb(0xffFF931E)), 2)); | |
60 | m_seriesThemes.append(SeriesTheme(QColor(QRgb(0xffFF1D25)), 2)); |
|
66 | m_seriesThemes.append(SeriesTheme(QColor(QRgb(0xffFF1D25)), 2)); | |
61 | m_seriesThemes.append(SeriesTheme(QColor(QRgb(0xffFF7BAC)), 2)); |
|
67 | m_seriesThemes.append(SeriesTheme(QColor(QRgb(0xffFF7BAC)), 2)); | |
62 |
|
68 | |||
63 | m_gradientStartColor = QColor(QRgb(0xfff3dc9e)); |
|
69 | m_gradientStartColor = QColor(QRgb(0xfff3dc9e)); | |
64 | m_gradientEndColor = QColor(QRgb(0xffafafaf)); |
|
70 | m_gradientEndColor = QColor(QRgb(0xffafafaf)); | |
65 | break; |
|
71 | break; | |
66 | default: |
|
72 | default: | |
67 | Q_ASSERT(false); |
|
73 | Q_ASSERT(false); | |
68 | break; |
|
74 | break; | |
69 | } |
|
75 | } | |
70 | } |
|
76 | } | |
71 |
|
77 | |||
72 | ChartTheme::ChartTheme(QObject *parent) : |
|
78 | ChartTheme::ChartTheme(QObject *parent) : | |
73 | QObject(parent), |
|
79 | QObject(parent), | |
74 | d(new ChartThemeData()) |
|
80 | d(new ChartThemeData()) | |
75 | { |
|
81 | { | |
76 | d->m_currentTheme = QChart::ChartThemeInvalid; |
|
82 | d->m_currentTheme = QChart::ChartThemeInvalid; | |
77 | d->m_seriesIndex = 0; |
|
83 | d->m_seriesIndex = 0; | |
78 | } |
|
84 | } | |
79 |
|
85 | |||
80 | void ChartTheme::setTheme(int theme) |
|
86 | void ChartTheme::setTheme(int theme) | |
81 | { |
|
87 | { | |
82 | if (theme != d->m_currentTheme) { |
|
88 | if (theme != d->m_currentTheme) { | |
83 | d->setTheme(theme); |
|
89 | d->setTheme(theme); | |
84 | foreach (ChartThemeObserver *o, d->m_observers) |
|
90 | foreach (ChartThemeObserver *o, d->m_observers) | |
85 | o->themeChanged(this); |
|
91 | o->themeChanged(this); | |
86 | } |
|
92 | } | |
87 | } |
|
93 | } | |
88 |
|
94 | |||
89 | SeriesTheme ChartTheme::themeForSeries() |
|
95 | SeriesTheme ChartTheme::themeForSeries() | |
90 | { |
|
96 | { | |
91 | if (d->m_seriesThemes.count() == 0) { |
|
97 | if (d->m_seriesThemes.count() == 0) { | |
92 | return SeriesTheme(); |
|
98 | return SeriesTheme(); | |
93 | } else { |
|
99 | } else { | |
94 | // Get the next available theme for the series; if no more themes available start over |
|
100 | // Get the next available theme for the series; if no more themes available start over | |
95 | // beginning from the first theme in the list |
|
101 | // beginning from the first theme in the list | |
96 | SeriesTheme nextTheme = |
|
102 | SeriesTheme nextTheme = | |
97 | d->m_seriesThemes[d->m_seriesIndex % d->m_seriesThemes.count()]; |
|
103 | d->m_seriesThemes[d->m_seriesIndex % d->m_seriesThemes.count()]; | |
98 | d->m_seriesIndex++; |
|
104 | d->m_seriesIndex++; | |
99 | return nextTheme; |
|
105 | return nextTheme; | |
100 | } |
|
106 | } | |
101 | } |
|
107 | } | |
102 |
|
108 | |||
103 |
|
109 | |||
104 | #include "moc_charttheme_p.cpp" |
|
110 | #include "moc_charttheme_p.cpp" | |
105 |
|
111 | |||
106 | QTCOMMERCIALCHART_END_NAMESPACE |
|
112 | QTCOMMERCIALCHART_END_NAMESPACE |
@@ -1,103 +1,103 | |||||
1 | #ifndef CHART_H |
|
1 | #ifndef CHART_H | |
2 | #define CHART_H |
|
2 | #define CHART_H | |
3 |
|
3 | |||
4 | #include <qchartglobal.h> |
|
4 | #include <qchartglobal.h> | |
5 | #include <qchartseries.h> |
|
5 | #include <qchartseries.h> | |
6 | #include <QGraphicsWidget> |
|
6 | #include <QGraphicsWidget> | |
7 | #include <QLinearGradient> |
|
7 | #include <QLinearGradient> | |
8 | #include <QFont> |
|
8 | #include <QFont> | |
9 |
|
9 | |||
10 | class QGraphicsSceneResizeEvent; |
|
10 | class QGraphicsSceneResizeEvent; | |
11 |
|
11 | |||
12 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
12 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
13 |
|
13 | |||
14 | class AxisItem; |
|
14 | class AxisItem; | |
15 | class QChartSeries; |
|
15 | class QChartSeries; | |
16 | class PlotDomain; |
|
16 | class PlotDomain; | |
17 | class BarGroup; |
|
17 | class BarGroup; | |
18 | class QChartAxis; |
|
18 | class QChartAxis; | |
19 | class ChartTheme; |
|
19 | class ChartTheme; | |
20 | class ChartItem; |
|
20 | class ChartItem; | |
21 |
|
21 | |||
22 | // TODO: We don't need to have QChart tied to QGraphicsItem: |
|
22 | // TODO: We don't need to have QChart tied to QGraphicsItem: | |
23 | //class QTCOMMERCIALCHART_EXPORT QChart |
|
23 | //class QTCOMMERCIALCHART_EXPORT QChart | |
24 | //class QTCOMMERCIALCHART_EXPORT QChartGraphicsItem : public QGraphicsItem { |
|
24 | //class QTCOMMERCIALCHART_EXPORT QChartGraphicsItem : public QGraphicsItem { | |
25 | // public: QChartGraphicsItem(QChart &chart); |
|
25 | // public: QChartGraphicsItem(QChart &chart); | |
26 |
|
26 | |||
27 | /*! |
|
27 | /*! | |
28 | * TODO: define the responsibilities |
|
28 | * TODO: define the responsibilities | |
29 | */ |
|
29 | */ | |
30 | class QTCOMMERCIALCHART_EXPORT QChart : public QGraphicsWidget |
|
30 | class QTCOMMERCIALCHART_EXPORT QChart : public QGraphicsWidget | |
31 | { |
|
31 | { | |
32 | Q_OBJECT |
|
32 | Q_OBJECT | |
33 | public: |
|
33 | public: | |
34 | enum GradientOrientation { |
|
34 | enum GradientOrientation { | |
35 | HorizonatlGradientOrientation, |
|
35 | HorizonatlGradientOrientation, | |
36 | VerticalGradientOrientation |
|
36 | VerticalGradientOrientation | |
37 | }; |
|
37 | }; | |
38 | enum ChartThemeId { |
|
38 | enum ChartThemeId { | |
39 | ChartThemeInvalid = -1, |
|
39 | ChartThemeInvalid = -1, | |
40 | /*! The default theme follows the GUI style of the Operating System */ |
|
40 | /*! The default theme follows the GUI style of the Operating System */ | |
41 | ChartThemeDefault, |
|
41 | ChartThemeDefault, | |
42 | ChartThemeVanilla, |
|
42 | ChartThemeVanilla, | |
43 | ChartThemeIcy, |
|
43 | ChartThemeIcy, | |
44 | ChartThemeGrayscale, |
|
44 | ChartThemeGrayscale, | |
45 |
|
|
45 | ChartThemeScientific, | |
46 | ChartThemeUnnamed1 |
|
46 | ChartThemeUnnamed1 | |
47 | }; |
|
47 | }; | |
48 |
|
48 | |||
49 | public: |
|
49 | public: | |
50 | QChart(QGraphicsItem *parent = 0, Qt::WindowFlags wFlags = 0); |
|
50 | QChart(QGraphicsItem *parent = 0, Qt::WindowFlags wFlags = 0); | |
51 | ~QChart(); |
|
51 | ~QChart(); | |
52 |
|
52 | |||
53 | void addSeries(QChartSeries* series); |
|
53 | void addSeries(QChartSeries* series); | |
54 | //TODO: QChartSeries* createSeries(QSeriesData *data, QChartSeries::QChartSeriesType type); |
|
54 | //TODO: QChartSeries* createSeries(QSeriesData *data, QChartSeries::QChartSeriesType type); | |
55 | // TODO: who owns the series now? maybe owned by chart and returned a reference instead... |
|
55 | // TODO: who owns the series now? maybe owned by chart and returned a reference instead... | |
56 | QChartSeries* createSeries(QChartSeries::QChartSeriesType type); |
|
56 | QChartSeries* createSeries(QChartSeries::QChartSeriesType type); | |
57 |
|
57 | |||
58 | void setMargin(int margin); |
|
58 | void setMargin(int margin); | |
59 | int margin() const; |
|
59 | int margin() const; | |
60 | void setTheme(QChart::ChartThemeId theme); |
|
60 | void setTheme(QChart::ChartThemeId theme); | |
61 | QChart::ChartThemeId theme(); |
|
61 | QChart::ChartThemeId theme(); | |
62 |
|
62 | |||
63 | void setTitle(const QString& title,const QFont& font = QFont()); |
|
63 | void setTitle(const QString& title,const QFont& font = QFont()); | |
64 | void setBackground(const QColor& startColor, const QColor& endColor = Qt::white, GradientOrientation orientation = VerticalGradientOrientation); |
|
64 | void setBackground(const QColor& startColor, const QColor& endColor = Qt::white, GradientOrientation orientation = VerticalGradientOrientation); | |
65 |
|
65 | |||
66 | void setChartBackgroundBrush(const QBrush& brush); |
|
66 | void setChartBackgroundBrush(const QBrush& brush); | |
67 | void setChartBackgroundPen(const QPen& pen); |
|
67 | void setChartBackgroundPen(const QPen& pen); | |
68 |
|
68 | |||
69 | void zoomInToRect(const QRectF& rectangle); |
|
69 | void zoomInToRect(const QRectF& rectangle); | |
70 | void zoomIn(); |
|
70 | void zoomIn(); | |
71 | void zoomOut(); |
|
71 | void zoomOut(); | |
72 | void zoomReset(); |
|
72 | void zoomReset(); | |
73 |
|
73 | |||
74 | void setAxisX(const QChartAxis& axis); |
|
74 | void setAxisX(const QChartAxis& axis); | |
75 | void setAxisY(const QChartAxis& axis); |
|
75 | void setAxisY(const QChartAxis& axis); | |
76 | void setAxisY(const QList<QChartAxis>& axis); |
|
76 | void setAxisY(const QList<QChartAxis>& axis); | |
77 |
|
77 | |||
78 | protected: |
|
78 | protected: | |
79 | void resizeEvent(QGraphicsSceneResizeEvent *event); |
|
79 | void resizeEvent(QGraphicsSceneResizeEvent *event); | |
80 |
|
80 | |||
81 | private: |
|
81 | private: | |
82 | void setAxis(AxisItem *item, const QChartAxis& axis); |
|
82 | void setAxis(AxisItem *item, const QChartAxis& axis); | |
83 |
|
83 | |||
84 | private: |
|
84 | private: | |
85 | Q_DISABLE_COPY(QChart) |
|
85 | Q_DISABLE_COPY(QChart) | |
86 | QGraphicsRectItem* m_backgroundItem; |
|
86 | QGraphicsRectItem* m_backgroundItem; | |
87 | QLinearGradient m_backgroundGradient; |
|
87 | QLinearGradient m_backgroundGradient; | |
88 | GradientOrientation m_bacgroundOrinetation; |
|
88 | GradientOrientation m_bacgroundOrinetation; | |
89 | QGraphicsTextItem* m_titleItem; |
|
89 | QGraphicsTextItem* m_titleItem; | |
90 | AxisItem* m_axisXItem; |
|
90 | AxisItem* m_axisXItem; | |
91 | QList<AxisItem*> m_axisYItem; |
|
91 | QList<AxisItem*> m_axisYItem; | |
92 | QRectF m_rect; |
|
92 | QRectF m_rect; | |
93 | QList<QChartSeries *> m_chartSeries; |
|
93 | QList<QChartSeries *> m_chartSeries; | |
94 | QList<ChartItem *> m_chartItems; |
|
94 | QList<ChartItem *> m_chartItems; | |
95 | QVector<PlotDomain> m_plotDomainList; |
|
95 | QVector<PlotDomain> m_plotDomainList; | |
96 | int m_plotDataIndex; |
|
96 | int m_plotDataIndex; | |
97 | int m_marginSize; |
|
97 | int m_marginSize; | |
98 | ChartTheme *m_chartTheme; |
|
98 | ChartTheme *m_chartTheme; | |
99 | }; |
|
99 | }; | |
100 |
|
100 | |||
101 | QTCOMMERCIALCHART_END_NAMESPACE |
|
101 | QTCOMMERCIALCHART_END_NAMESPACE | |
102 |
|
102 | |||
103 | #endif |
|
103 | #endif |
@@ -1,379 +1,380 | |||||
1 | #include "mainwidget.h" |
|
1 | #include "mainwidget.h" | |
2 | #include "dataseriedialog.h" |
|
2 | #include "dataseriedialog.h" | |
3 | #include "qchartseries.h" |
|
3 | #include "qchartseries.h" | |
4 | #include "qpieseries.h" |
|
4 | #include "qpieseries.h" | |
5 | #include <qxychartseries.h> |
|
5 | #include <qxychartseries.h> | |
6 | #include <barchartseries.h> |
|
6 | #include <barchartseries.h> | |
7 | #include <QPushButton> |
|
7 | #include <QPushButton> | |
8 | #include <QComboBox> |
|
8 | #include <QComboBox> | |
9 | #include <QSpinBox> |
|
9 | #include <QSpinBox> | |
10 | #include <QCheckBox> |
|
10 | #include <QCheckBox> | |
11 | #include <QGridLayout> |
|
11 | #include <QGridLayout> | |
12 | #include <QHBoxLayout> |
|
12 | #include <QHBoxLayout> | |
13 | #include <QLabel> |
|
13 | #include <QLabel> | |
14 | #include <QSpacerItem> |
|
14 | #include <QSpacerItem> | |
15 | #include <QMessageBox> |
|
15 | #include <QMessageBox> | |
16 | #include <cmath> |
|
16 | #include <cmath> | |
17 | #include <QDebug> |
|
17 | #include <QDebug> | |
18 | #include <QStandardItemModel> |
|
18 | #include <QStandardItemModel> | |
19 |
|
19 | |||
20 |
|
20 | |||
21 | QTCOMMERCIALCHART_USE_NAMESPACE |
|
21 | QTCOMMERCIALCHART_USE_NAMESPACE | |
22 |
|
22 | |||
23 | MainWidget::MainWidget(QWidget *parent) : |
|
23 | MainWidget::MainWidget(QWidget *parent) : | |
24 | QWidget(parent) |
|
24 | QWidget(parent) | |
25 | { |
|
25 | { | |
26 | m_chartWidget = new QChartWidget(this); |
|
26 | m_chartWidget = new QChartWidget(this); | |
27 |
|
27 | |||
28 | // Grid layout for the controls for configuring the chart widget |
|
28 | // Grid layout for the controls for configuring the chart widget | |
29 | QGridLayout *grid = new QGridLayout(); |
|
29 | QGridLayout *grid = new QGridLayout(); | |
30 | QPushButton *addSeriesButton = new QPushButton("Add series"); |
|
30 | QPushButton *addSeriesButton = new QPushButton("Add series"); | |
31 | connect(addSeriesButton, SIGNAL(clicked()), this, SLOT(addSeries())); |
|
31 | connect(addSeriesButton, SIGNAL(clicked()), this, SLOT(addSeries())); | |
32 | grid->addWidget(addSeriesButton, 0, 1); |
|
32 | grid->addWidget(addSeriesButton, 0, 1); | |
33 | initBackroundCombo(grid); |
|
33 | initBackroundCombo(grid); | |
34 | initScaleControls(grid); |
|
34 | initScaleControls(grid); | |
35 | initThemeCombo(grid); |
|
35 | initThemeCombo(grid); | |
36 | QCheckBox *zoomCheckBox = new QCheckBox("Drag'n drop Zoom"); |
|
36 | QCheckBox *zoomCheckBox = new QCheckBox("Drag'n drop Zoom"); | |
37 | connect(zoomCheckBox, SIGNAL(toggled(bool)), m_chartWidget, SLOT(setZoomEnabled(bool))); |
|
37 | connect(zoomCheckBox, SIGNAL(toggled(bool)), m_chartWidget, SLOT(setZoomEnabled(bool))); | |
38 | zoomCheckBox->setChecked(true); |
|
38 | zoomCheckBox->setChecked(true); | |
39 | grid->addWidget(zoomCheckBox, grid->rowCount(), 0); |
|
39 | grid->addWidget(zoomCheckBox, grid->rowCount(), 0); | |
40 | // add row with empty label to make all the other rows static |
|
40 | // add row with empty label to make all the other rows static | |
41 | grid->addWidget(new QLabel(""), grid->rowCount(), 0); |
|
41 | grid->addWidget(new QLabel(""), grid->rowCount(), 0); | |
42 | grid->setRowStretch(grid->rowCount() - 1, 1); |
|
42 | grid->setRowStretch(grid->rowCount() - 1, 1); | |
43 |
|
43 | |||
44 | // Another grid layout as a main layout |
|
44 | // Another grid layout as a main layout | |
45 | QGridLayout *mainLayout = new QGridLayout(); |
|
45 | QGridLayout *mainLayout = new QGridLayout(); | |
46 | mainLayout->addLayout(grid, 0, 0); |
|
46 | mainLayout->addLayout(grid, 0, 0); | |
47 |
|
47 | |||
48 | // Init series type specific controls |
|
48 | // Init series type specific controls | |
49 | initPieControls(); |
|
49 | initPieControls(); | |
50 | mainLayout->addLayout(m_pieLayout, 2, 0); |
|
50 | mainLayout->addLayout(m_pieLayout, 2, 0); | |
51 | // Scatter series specific settings |
|
51 | // Scatter series specific settings | |
52 | // m_scatterLayout = new QGridLayout(); |
|
52 | // m_scatterLayout = new QGridLayout(); | |
53 | // m_scatterLayout->addWidget(new QLabel("scatter"), 0, 0); |
|
53 | // m_scatterLayout->addWidget(new QLabel("scatter"), 0, 0); | |
54 | // m_scatterLayout->setEnabled(false); |
|
54 | // m_scatterLayout->setEnabled(false); | |
55 | // mainLayout->addLayout(m_scatterLayout, 1, 0); |
|
55 | // mainLayout->addLayout(m_scatterLayout, 1, 0); | |
56 |
|
56 | |||
57 | // Add layouts and the chart widget to the main layout |
|
57 | // Add layouts and the chart widget to the main layout | |
58 | mainLayout->addWidget(m_chartWidget, 0, 1, 3, 1); |
|
58 | mainLayout->addWidget(m_chartWidget, 0, 1, 3, 1); | |
59 | setLayout(mainLayout); |
|
59 | setLayout(mainLayout); | |
60 |
|
60 | |||
61 | // force an update to test data |
|
61 | // force an update to test data | |
62 | testDataChanged(0); |
|
62 | testDataChanged(0); | |
63 | } |
|
63 | } | |
64 |
|
64 | |||
65 | // Combo box for selecting the chart's background |
|
65 | // Combo box for selecting the chart's background | |
66 | void MainWidget::initBackroundCombo(QGridLayout *grid) |
|
66 | void MainWidget::initBackroundCombo(QGridLayout *grid) | |
67 | { |
|
67 | { | |
68 | QComboBox *backgroundCombo = new QComboBox(this); |
|
68 | QComboBox *backgroundCombo = new QComboBox(this); | |
69 | backgroundCombo->addItem("Color"); |
|
69 | backgroundCombo->addItem("Color"); | |
70 | backgroundCombo->addItem("Gradient"); |
|
70 | backgroundCombo->addItem("Gradient"); | |
71 | backgroundCombo->addItem("Image"); |
|
71 | backgroundCombo->addItem("Image"); | |
72 | connect(backgroundCombo, SIGNAL(currentIndexChanged(int)), |
|
72 | connect(backgroundCombo, SIGNAL(currentIndexChanged(int)), | |
73 | this, SLOT(backgroundChanged(int))); |
|
73 | this, SLOT(backgroundChanged(int))); | |
74 |
|
74 | |||
75 | grid->addWidget(new QLabel("Background:"), grid->rowCount(), 0); |
|
75 | grid->addWidget(new QLabel("Background:"), grid->rowCount(), 0); | |
76 | grid->addWidget(backgroundCombo, grid->rowCount() - 1, 1); |
|
76 | grid->addWidget(backgroundCombo, grid->rowCount() - 1, 1); | |
77 | } |
|
77 | } | |
78 |
|
78 | |||
79 | // Scale related controls (auto-scale vs. manual min-max values) |
|
79 | // Scale related controls (auto-scale vs. manual min-max values) | |
80 | void MainWidget::initScaleControls(QGridLayout *grid) |
|
80 | void MainWidget::initScaleControls(QGridLayout *grid) | |
81 | { |
|
81 | { | |
82 | m_autoScaleCheck = new QCheckBox("Automatic scaling"); |
|
82 | m_autoScaleCheck = new QCheckBox("Automatic scaling"); | |
83 | connect(m_autoScaleCheck, SIGNAL(stateChanged(int)), this, SLOT(autoScaleChanged(int))); |
|
83 | connect(m_autoScaleCheck, SIGNAL(stateChanged(int)), this, SLOT(autoScaleChanged(int))); | |
84 | // Allow setting also non-sense values (like -2147483648 and 2147483647) |
|
84 | // Allow setting also non-sense values (like -2147483648 and 2147483647) | |
85 | m_xMinSpin = new QSpinBox(); |
|
85 | m_xMinSpin = new QSpinBox(); | |
86 | m_xMinSpin->setMinimum(INT_MIN); |
|
86 | m_xMinSpin->setMinimum(INT_MIN); | |
87 | m_xMinSpin->setMaximum(INT_MAX); |
|
87 | m_xMinSpin->setMaximum(INT_MAX); | |
88 | m_xMinSpin->setValue(0); |
|
88 | m_xMinSpin->setValue(0); | |
89 | connect(m_xMinSpin, SIGNAL(valueChanged(int)), this, SLOT(xMinChanged(int))); |
|
89 | connect(m_xMinSpin, SIGNAL(valueChanged(int)), this, SLOT(xMinChanged(int))); | |
90 | m_xMaxSpin = new QSpinBox(); |
|
90 | m_xMaxSpin = new QSpinBox(); | |
91 | m_xMaxSpin->setMinimum(INT_MIN); |
|
91 | m_xMaxSpin->setMinimum(INT_MIN); | |
92 | m_xMaxSpin->setMaximum(INT_MAX); |
|
92 | m_xMaxSpin->setMaximum(INT_MAX); | |
93 | m_xMaxSpin->setValue(10); |
|
93 | m_xMaxSpin->setValue(10); | |
94 | connect(m_xMaxSpin, SIGNAL(valueChanged(int)), this, SLOT(xMaxChanged(int))); |
|
94 | connect(m_xMaxSpin, SIGNAL(valueChanged(int)), this, SLOT(xMaxChanged(int))); | |
95 | m_yMinSpin = new QSpinBox(); |
|
95 | m_yMinSpin = new QSpinBox(); | |
96 | m_yMinSpin->setMinimum(INT_MIN); |
|
96 | m_yMinSpin->setMinimum(INT_MIN); | |
97 | m_yMinSpin->setMaximum(INT_MAX); |
|
97 | m_yMinSpin->setMaximum(INT_MAX); | |
98 | m_yMinSpin->setValue(0); |
|
98 | m_yMinSpin->setValue(0); | |
99 | connect(m_yMinSpin, SIGNAL(valueChanged(int)), this, SLOT(yMinChanged(int))); |
|
99 | connect(m_yMinSpin, SIGNAL(valueChanged(int)), this, SLOT(yMinChanged(int))); | |
100 | m_yMaxSpin = new QSpinBox(); |
|
100 | m_yMaxSpin = new QSpinBox(); | |
101 | m_yMaxSpin->setMinimum(INT_MIN); |
|
101 | m_yMaxSpin->setMinimum(INT_MIN); | |
102 | m_yMaxSpin->setMaximum(INT_MAX); |
|
102 | m_yMaxSpin->setMaximum(INT_MAX); | |
103 | m_yMaxSpin->setValue(10); |
|
103 | m_yMaxSpin->setValue(10); | |
104 | connect(m_yMaxSpin, SIGNAL(valueChanged(int)), this, SLOT(yMaxChanged(int))); |
|
104 | connect(m_yMaxSpin, SIGNAL(valueChanged(int)), this, SLOT(yMaxChanged(int))); | |
105 |
|
105 | |||
106 | grid->addWidget(m_autoScaleCheck, grid->rowCount(), 0); |
|
106 | grid->addWidget(m_autoScaleCheck, grid->rowCount(), 0); | |
107 | grid->addWidget(new QLabel("x min:"), grid->rowCount(), 0); |
|
107 | grid->addWidget(new QLabel("x min:"), grid->rowCount(), 0); | |
108 | grid->addWidget(m_xMinSpin, grid->rowCount() - 1, 1); |
|
108 | grid->addWidget(m_xMinSpin, grid->rowCount() - 1, 1); | |
109 | grid->addWidget(new QLabel("x max:"), grid->rowCount(), 0); |
|
109 | grid->addWidget(new QLabel("x max:"), grid->rowCount(), 0); | |
110 | grid->addWidget(m_xMaxSpin, grid->rowCount() - 1, 1); |
|
110 | grid->addWidget(m_xMaxSpin, grid->rowCount() - 1, 1); | |
111 | grid->addWidget(new QLabel("y min:"), grid->rowCount(), 0); |
|
111 | grid->addWidget(new QLabel("y min:"), grid->rowCount(), 0); | |
112 | grid->addWidget(m_yMinSpin, grid->rowCount() - 1, 1); |
|
112 | grid->addWidget(m_yMinSpin, grid->rowCount() - 1, 1); | |
113 | grid->addWidget(new QLabel("y max:"), grid->rowCount(), 0); |
|
113 | grid->addWidget(new QLabel("y max:"), grid->rowCount(), 0); | |
114 | grid->addWidget(m_yMaxSpin, grid->rowCount() - 1, 1); |
|
114 | grid->addWidget(m_yMaxSpin, grid->rowCount() - 1, 1); | |
115 |
|
115 | |||
116 | m_autoScaleCheck->setChecked(true); |
|
116 | m_autoScaleCheck->setChecked(true); | |
117 | } |
|
117 | } | |
118 |
|
118 | |||
119 | // Combo box for selecting theme |
|
119 | // Combo box for selecting theme | |
120 | void MainWidget::initThemeCombo(QGridLayout *grid) |
|
120 | void MainWidget::initThemeCombo(QGridLayout *grid) | |
121 | { |
|
121 | { | |
122 | QComboBox *chartTheme = new QComboBox(); |
|
122 | QComboBox *chartTheme = new QComboBox(); | |
123 | chartTheme->addItem("Default"); |
|
123 | chartTheme->addItem("Default"); | |
124 | chartTheme->addItem("Vanilla"); |
|
124 | chartTheme->addItem("Vanilla"); | |
125 | chartTheme->addItem("Icy"); |
|
125 | chartTheme->addItem("Icy"); | |
126 | chartTheme->addItem("Grayscale"); |
|
126 | chartTheme->addItem("Grayscale"); | |
|
127 | chartTheme->addItem("Scientific"); | |||
127 | chartTheme->addItem("Unnamed1"); |
|
128 | chartTheme->addItem("Unnamed1"); | |
128 | connect(chartTheme, SIGNAL(currentIndexChanged(int)), |
|
129 | connect(chartTheme, SIGNAL(currentIndexChanged(int)), | |
129 | this, SLOT(changeChartTheme(int))); |
|
130 | this, SLOT(changeChartTheme(int))); | |
130 | grid->addWidget(new QLabel("Chart theme:"), 8, 0); |
|
131 | grid->addWidget(new QLabel("Chart theme:"), 8, 0); | |
131 | grid->addWidget(chartTheme, 8, 1); |
|
132 | grid->addWidget(chartTheme, 8, 1); | |
132 | } |
|
133 | } | |
133 |
|
134 | |||
134 | void MainWidget::initPieControls() |
|
135 | void MainWidget::initPieControls() | |
135 | { |
|
136 | { | |
136 | // Pie series specific settings |
|
137 | // Pie series specific settings | |
137 | // Pie size factory |
|
138 | // Pie size factory | |
138 | QDoubleSpinBox *pieSizeSpin = new QDoubleSpinBox(); |
|
139 | QDoubleSpinBox *pieSizeSpin = new QDoubleSpinBox(); | |
139 | pieSizeSpin->setMinimum(LONG_MIN); |
|
140 | pieSizeSpin->setMinimum(LONG_MIN); | |
140 | pieSizeSpin->setMaximum(LONG_MAX); |
|
141 | pieSizeSpin->setMaximum(LONG_MAX); | |
141 | pieSizeSpin->setValue(1.0); |
|
142 | pieSizeSpin->setValue(1.0); | |
142 | pieSizeSpin->setSingleStep(0.1); |
|
143 | pieSizeSpin->setSingleStep(0.1); | |
143 | connect(pieSizeSpin, SIGNAL(valueChanged(double)), this, SLOT(setPieSizeFactor(double))); |
|
144 | connect(pieSizeSpin, SIGNAL(valueChanged(double)), this, SLOT(setPieSizeFactor(double))); | |
144 | // Pie position |
|
145 | // Pie position | |
145 | QComboBox *piePosCombo = new QComboBox(this); |
|
146 | QComboBox *piePosCombo = new QComboBox(this); | |
146 | piePosCombo->addItem("Maximized"); |
|
147 | piePosCombo->addItem("Maximized"); | |
147 | piePosCombo->addItem("Top left"); |
|
148 | piePosCombo->addItem("Top left"); | |
148 | piePosCombo->addItem("Top right"); |
|
149 | piePosCombo->addItem("Top right"); | |
149 | piePosCombo->addItem("Bottom left"); |
|
150 | piePosCombo->addItem("Bottom left"); | |
150 | piePosCombo->addItem("Bottom right"); |
|
151 | piePosCombo->addItem("Bottom right"); | |
151 | connect(piePosCombo, SIGNAL(currentIndexChanged(int)), |
|
152 | connect(piePosCombo, SIGNAL(currentIndexChanged(int)), | |
152 | this, SLOT(setPiePosition(int))); |
|
153 | this, SLOT(setPiePosition(int))); | |
153 | m_pieLayout = new QGridLayout(); |
|
154 | m_pieLayout = new QGridLayout(); | |
154 | m_pieLayout->setEnabled(false); |
|
155 | m_pieLayout->setEnabled(false); | |
155 | m_pieLayout->addWidget(new QLabel("Pie size factor"), 0, 0); |
|
156 | m_pieLayout->addWidget(new QLabel("Pie size factor"), 0, 0); | |
156 | m_pieLayout->addWidget(pieSizeSpin, 0, 1); |
|
157 | m_pieLayout->addWidget(pieSizeSpin, 0, 1); | |
157 | m_pieLayout->addWidget(new QLabel("Pie position"), 1, 0); |
|
158 | m_pieLayout->addWidget(new QLabel("Pie position"), 1, 0); | |
158 | m_pieLayout->addWidget(piePosCombo, 1, 1); |
|
159 | m_pieLayout->addWidget(piePosCombo, 1, 1); | |
159 | } |
|
160 | } | |
160 |
|
161 | |||
161 | void MainWidget::addSeries() |
|
162 | void MainWidget::addSeries() | |
162 | { |
|
163 | { | |
163 | DataSerieDialog dialog(m_defaultSeriesName, this); |
|
164 | DataSerieDialog dialog(m_defaultSeriesName, this); | |
164 | connect(&dialog, SIGNAL(accepted(QString, QString)), this, SLOT(addSeries(QString, QString))); |
|
165 | connect(&dialog, SIGNAL(accepted(QString, QString)), this, SLOT(addSeries(QString, QString))); | |
165 | dialog.exec(); |
|
166 | dialog.exec(); | |
166 | } |
|
167 | } | |
167 |
|
168 | |||
168 | void MainWidget::addSeries(QString series, QString data) |
|
169 | void MainWidget::addSeries(QString series, QString data) | |
169 | { |
|
170 | { | |
170 | qDebug() << "addSeries: " << series << " data: " << data; |
|
171 | qDebug() << "addSeries: " << series << " data: " << data; | |
171 | m_defaultSeriesName = series; |
|
172 | m_defaultSeriesName = series; | |
172 |
|
173 | |||
173 | // TODO: a dedicated data class for storing x and y values |
|
174 | // TODO: a dedicated data class for storing x and y values | |
174 | QList<qreal> x; |
|
175 | QList<qreal> x; | |
175 | QList<qreal> y; |
|
176 | QList<qreal> y; | |
176 |
|
177 | |||
177 | if (data == "linear") { |
|
178 | if (data == "linear") { | |
178 | for (int i = 0; i < 20; i++) { |
|
179 | for (int i = 0; i < 20; i++) { | |
179 | x.append(i); |
|
180 | x.append(i); | |
180 | y.append(i); |
|
181 | y.append(i); | |
181 | } |
|
182 | } | |
182 | } else if (data == "linear, 1M") { |
|
183 | } else if (data == "linear, 1M") { | |
183 | // 1 million data points from 0.0001 to 100 |
|
184 | // 1 million data points from 0.0001 to 100 | |
184 | // TODO: What is the requirement? Should we be able to show this kind of data with |
|
185 | // TODO: What is the requirement? Should we be able to show this kind of data with | |
185 | // reasonable performance, or can we expect the application developer to do "data mining" |
|
186 | // reasonable performance, or can we expect the application developer to do "data mining" | |
186 | // for us, so that the count of data points given to QtCommercial Chart is always |
|
187 | // for us, so that the count of data points given to QtCommercial Chart is always | |
187 | // reasonable? |
|
188 | // reasonable? | |
188 | for (qreal i = 0; i < 100; i += 0.0001) { |
|
189 | for (qreal i = 0; i < 100; i += 0.0001) { | |
189 | x.append(i); |
|
190 | x.append(i); | |
190 | y.append(20); |
|
191 | y.append(20); | |
191 | } |
|
192 | } | |
192 | } else if (data == "SIN") { |
|
193 | } else if (data == "SIN") { | |
193 | for (int i = 0; i < 100; i++) { |
|
194 | for (int i = 0; i < 100; i++) { | |
194 | x.append(i); |
|
195 | x.append(i); | |
195 | y.append(abs(sin(3.14159265358979 / 50 * i) * 100)); |
|
196 | y.append(abs(sin(3.14159265358979 / 50 * i) * 100)); | |
196 | } |
|
197 | } | |
197 | } else if (data == "SIN + random") { |
|
198 | } else if (data == "SIN + random") { | |
198 | for (qreal i = 0; i < 100; i += 0.1) { |
|
199 | for (qreal i = 0; i < 100; i += 0.1) { | |
199 | x.append(i + (rand() % 5)); |
|
200 | x.append(i + (rand() % 5)); | |
200 | y.append(abs(sin(3.14159265358979 / 50 * i) * 100) + (rand() % 5)); |
|
201 | y.append(abs(sin(3.14159265358979 / 50 * i) * 100) + (rand() % 5)); | |
201 | } |
|
202 | } | |
202 | } else { |
|
203 | } else { | |
203 | // TODO: check if data has a valid file name |
|
204 | // TODO: check if data has a valid file name | |
204 | Q_ASSERT(false); |
|
205 | Q_ASSERT(false); | |
205 | } |
|
206 | } | |
206 |
|
207 | |||
207 | // TODO: color of the series |
|
208 | // TODO: color of the series | |
208 | QChartSeries *newSeries = 0; |
|
209 | QChartSeries *newSeries = 0; | |
209 | if (series == "Scatter") { |
|
210 | if (series == "Scatter") { | |
210 | newSeries = m_chartWidget->createSeries(QChartSeries::SeriesTypeScatter); |
|
211 | newSeries = m_chartWidget->createSeries(QChartSeries::SeriesTypeScatter); | |
211 | Q_ASSERT(newSeries->setData(x, y)); |
|
212 | Q_ASSERT(newSeries->setData(x, y)); | |
212 | } else if (series == "Pie") { |
|
213 | } else if (series == "Pie") { | |
213 | newSeries = m_chartWidget->createSeries(QChartSeries::SeriesTypePie); |
|
214 | newSeries = m_chartWidget->createSeries(QChartSeries::SeriesTypePie); | |
214 | Q_ASSERT(newSeries->setData(y)); |
|
215 | Q_ASSERT(newSeries->setData(y)); | |
215 | } else if (series == "Line") { |
|
216 | } else if (series == "Line") { | |
216 | // TODO: adding data to an existing line series does not give any visuals for some reason |
|
217 | // TODO: adding data to an existing line series does not give any visuals for some reason | |
217 | // newSeries = m_chartWidget->createSeries(QChartSeries::SeriesTypeLine); |
|
218 | // newSeries = m_chartWidget->createSeries(QChartSeries::SeriesTypeLine); | |
218 | // QXYChartSeries *lineSeries = static_cast<QXYChartSeries *>(newSeries); |
|
219 | // QXYChartSeries *lineSeries = static_cast<QXYChartSeries *>(newSeries); | |
219 | // lineSeries->setColor(Qt::blue); |
|
220 | // lineSeries->setColor(Qt::blue); | |
220 | // for (int i(0); i < x.count() && i < y.count(); i++) { |
|
221 | // for (int i(0); i < x.count() && i < y.count(); i++) { | |
221 | // lineSeries->add(x.at(i), y.at(i)); |
|
222 | // lineSeries->add(x.at(i), y.at(i)); | |
222 | // } |
|
223 | // } | |
223 | //Q_ASSERT(newSeries->setData(x, y)); |
|
224 | //Q_ASSERT(newSeries->setData(x, y)); | |
224 | QXYChartSeries* series0 = QXYChartSeries::create(); |
|
225 | QXYChartSeries* series0 = QXYChartSeries::create(); | |
225 | for (int i(0); i < x.count() && i < y.count(); i++) |
|
226 | for (int i(0); i < x.count() && i < y.count(); i++) | |
226 | series0->add(x.at(i), y.at(i)); |
|
227 | series0->add(x.at(i), y.at(i)); | |
227 | m_chartWidget->addSeries(series0); |
|
228 | m_chartWidget->addSeries(series0); | |
228 | newSeries = series0; |
|
229 | newSeries = series0; | |
229 | } else { |
|
230 | } else { | |
230 | // TODO |
|
231 | // TODO | |
231 | } |
|
232 | } | |
232 |
|
233 | |||
233 | // BarChart |
|
234 | // BarChart | |
234 | if (series == "Bar") { |
|
235 | if (series == "Bar") { | |
235 | // This is the another way of creating series. Should we create test cases for both ways, if we support them? |
|
236 | // This is the another way of creating series. Should we create test cases for both ways, if we support them? | |
236 | qDebug() << "Bar chart series"; |
|
237 | qDebug() << "Bar chart series"; | |
237 | newSeries = QChartSeries::create(QChartSeries::SeriesTypeBar, this); |
|
238 | newSeries = QChartSeries::create(QChartSeries::SeriesTypeBar, this); | |
238 |
|
239 | |||
239 | // Create some test data to chart |
|
240 | // Create some test data to chart | |
240 | QStandardItemModel dataModel(2,10,this); |
|
241 | QStandardItemModel dataModel(2,10,this); | |
241 | QModelIndex index; |
|
242 | QModelIndex index; | |
242 | index = dataModel.index(0,0); |
|
243 | index = dataModel.index(0,0); | |
243 | // Series 1, items 6 to 9 missing. |
|
244 | // Series 1, items 6 to 9 missing. | |
244 | dataModel.setData(dataModel.index(0,0),1); |
|
245 | dataModel.setData(dataModel.index(0,0),1); | |
245 | dataModel.setData(dataModel.index(0,1),12); |
|
246 | dataModel.setData(dataModel.index(0,1),12); | |
246 | dataModel.setData(dataModel.index(0,2),5); |
|
247 | dataModel.setData(dataModel.index(0,2),5); | |
247 | dataModel.setData(dataModel.index(0,3),8); |
|
248 | dataModel.setData(dataModel.index(0,3),8); | |
248 | dataModel.setData(dataModel.index(0,4),17); |
|
249 | dataModel.setData(dataModel.index(0,4),17); | |
249 | dataModel.setData(dataModel.index(0,5),9); |
|
250 | dataModel.setData(dataModel.index(0,5),9); | |
250 |
|
251 | |||
251 | // Series 2, some other items missing |
|
252 | // Series 2, some other items missing | |
252 | dataModel.setData(dataModel.index(1,0),5); |
|
253 | dataModel.setData(dataModel.index(1,0),5); | |
253 | dataModel.setData(dataModel.index(1,3),4); |
|
254 | dataModel.setData(dataModel.index(1,3),4); | |
254 | dataModel.setData(dataModel.index(1,5),7); |
|
255 | dataModel.setData(dataModel.index(1,5),7); | |
255 | dataModel.setData(dataModel.index(1,6),8); |
|
256 | dataModel.setData(dataModel.index(1,6),8); | |
256 | dataModel.setData(dataModel.index(1,8),9); |
|
257 | dataModel.setData(dataModel.index(1,8),9); | |
257 | dataModel.setData(dataModel.index(1,9),9); |
|
258 | dataModel.setData(dataModel.index(1,9),9); | |
258 |
|
259 | |||
259 | newSeries->setData(&dataModel); |
|
260 | newSeries->setData(&dataModel); | |
260 |
|
261 | |||
261 | m_chartWidget->addSeries(newSeries); |
|
262 | m_chartWidget->addSeries(newSeries); | |
262 | } |
|
263 | } | |
263 |
|
264 | |||
264 | setCurrentSeries(newSeries); |
|
265 | setCurrentSeries(newSeries); | |
265 | } |
|
266 | } | |
266 |
|
267 | |||
267 | void MainWidget::setCurrentSeries(QChartSeries *series) |
|
268 | void MainWidget::setCurrentSeries(QChartSeries *series) | |
268 | { |
|
269 | { | |
269 | m_currentSeries = series; |
|
270 | m_currentSeries = series; | |
270 | switch (m_currentSeries->type()) { |
|
271 | switch (m_currentSeries->type()) { | |
271 | case QChartSeries::SeriesTypeLine: |
|
272 | case QChartSeries::SeriesTypeLine: | |
272 | break; |
|
273 | break; | |
273 | case QChartSeries::SeriesTypeScatter: |
|
274 | case QChartSeries::SeriesTypeScatter: | |
274 | break; |
|
275 | break; | |
275 | case QChartSeries::SeriesTypePie: |
|
276 | case QChartSeries::SeriesTypePie: | |
276 | break; |
|
277 | break; | |
277 | case QChartSeries::SeriesTypeBar: |
|
278 | case QChartSeries::SeriesTypeBar: | |
278 | qDebug() << "setCurrentSeries (bar)"; |
|
279 | qDebug() << "setCurrentSeries (bar)"; | |
279 | break; |
|
280 | break; | |
280 | default: |
|
281 | default: | |
281 | Q_ASSERT(false); |
|
282 | Q_ASSERT(false); | |
282 | break; |
|
283 | break; | |
283 | } |
|
284 | } | |
284 | } |
|
285 | } | |
285 |
|
286 | |||
286 | void MainWidget::testDataChanged(int itemIndex) |
|
287 | void MainWidget::testDataChanged(int itemIndex) | |
287 | { |
|
288 | { | |
288 | qDebug() << "testDataChanged: " << itemIndex; |
|
289 | qDebug() << "testDataChanged: " << itemIndex; | |
289 |
|
290 | |||
290 | // switch (itemIndex) { |
|
291 | // switch (itemIndex) { | |
291 | // case 0: { |
|
292 | // case 0: { | |
292 | // QList<QChartDataPoint> data; |
|
293 | // QList<QChartDataPoint> data; | |
293 | // for (int x = 0; x < 20; x++) { |
|
294 | // for (int x = 0; x < 20; x++) { | |
294 | // data.append(QChartDataPoint() << x << x / 2); |
|
295 | // data.append(QChartDataPoint() << x << x / 2); | |
295 | // } |
|
296 | // } | |
296 | // m_chartWidget->setData(data); |
|
297 | // m_chartWidget->setData(data); | |
297 | // break; |
|
298 | // break; | |
298 | // } |
|
299 | // } | |
299 | // case 1: { |
|
300 | // case 1: { | |
300 | // QList<QChartDataPoint> data; |
|
301 | // QList<QChartDataPoint> data; | |
301 | // for (int x = 0; x < 100; x++) { |
|
302 | // for (int x = 0; x < 100; x++) { | |
302 | // data.append(QChartDataPoint() << x - 200 << 2 * (uint(sin(3.14159/50*x)*80) % 100)); |
|
303 | // data.append(QChartDataPoint() << x - 200 << 2 * (uint(sin(3.14159/50*x)*80) % 100)); | |
303 | // } |
|
304 | // } | |
304 | // m_chartWidget->setData(data); |
|
305 | // m_chartWidget->setData(data); | |
305 | // break; |
|
306 | // break; | |
306 | // } |
|
307 | // } | |
307 | // case 2: { |
|
308 | // case 2: { | |
308 | // QList<QChartDataPoint> data; |
|
309 | // QList<QChartDataPoint> data; | |
309 | // for (int x = 0; x < 1000; x++) { |
|
310 | // for (int x = 0; x < 1000; x++) { | |
310 | // data.append(QChartDataPoint() << x - 200 << 2 * (uint(sin(3.14159/50*x)*80) % 100) + (rand() % 100 * 0.2)); |
|
311 | // data.append(QChartDataPoint() << x - 200 << 2 * (uint(sin(3.14159/50*x)*80) % 100) + (rand() % 100 * 0.2)); | |
311 | // data.append(QChartDataPoint() << x - 200 << 2 * (uint(sin(3.14159/50*x)*80) % 100) + (rand() % 100 * 0.2)); |
|
312 | // data.append(QChartDataPoint() << x - 200 << 2 * (uint(sin(3.14159/50*x)*80) % 100) + (rand() % 100 * 0.2)); | |
312 | // data.append(QChartDataPoint() << x - 200 << 2 * (uint(sin(3.14159/50*x)*80) % 100) + (rand() % 100 * 0.2)); |
|
313 | // data.append(QChartDataPoint() << x - 200 << 2 * (uint(sin(3.14159/50*x)*80) % 100) + (rand() % 100 * 0.2)); | |
313 | // } |
|
314 | // } | |
314 | // m_chartWidget->setData(data); |
|
315 | // m_chartWidget->setData(data); | |
315 | // break; |
|
316 | // break; | |
316 | // } |
|
317 | // } | |
317 | // default: |
|
318 | // default: | |
318 | // break; |
|
319 | // break; | |
319 | // } |
|
320 | // } | |
320 | } |
|
321 | } | |
321 |
|
322 | |||
322 | void MainWidget::backgroundChanged(int itemIndex) |
|
323 | void MainWidget::backgroundChanged(int itemIndex) | |
323 | { |
|
324 | { | |
324 | qDebug() << "backgroundChanged: " << itemIndex; |
|
325 | qDebug() << "backgroundChanged: " << itemIndex; | |
325 | } |
|
326 | } | |
326 |
|
327 | |||
327 | void MainWidget::autoScaleChanged(int value) |
|
328 | void MainWidget::autoScaleChanged(int value) | |
328 | { |
|
329 | { | |
329 | if (value) { |
|
330 | if (value) { | |
330 | // TODO: enable auto scaling |
|
331 | // TODO: enable auto scaling | |
331 | } else { |
|
332 | } else { | |
332 | // TODO: set scaling manually (and disable auto scaling) |
|
333 | // TODO: set scaling manually (and disable auto scaling) | |
333 | } |
|
334 | } | |
334 |
|
335 | |||
335 | m_xMinSpin->setEnabled(!value); |
|
336 | m_xMinSpin->setEnabled(!value); | |
336 | m_xMaxSpin->setEnabled(!value); |
|
337 | m_xMaxSpin->setEnabled(!value); | |
337 | m_yMinSpin->setEnabled(!value); |
|
338 | m_yMinSpin->setEnabled(!value); | |
338 | m_yMaxSpin->setEnabled(!value); |
|
339 | m_yMaxSpin->setEnabled(!value); | |
339 | } |
|
340 | } | |
340 |
|
341 | |||
341 | void MainWidget::xMinChanged(int value) |
|
342 | void MainWidget::xMinChanged(int value) | |
342 | { |
|
343 | { | |
343 | qDebug() << "xMinChanged: " << value; |
|
344 | qDebug() << "xMinChanged: " << value; | |
344 | } |
|
345 | } | |
345 |
|
346 | |||
346 | void MainWidget::xMaxChanged(int value) |
|
347 | void MainWidget::xMaxChanged(int value) | |
347 | { |
|
348 | { | |
348 | qDebug() << "xMaxChanged: " << value; |
|
349 | qDebug() << "xMaxChanged: " << value; | |
349 | } |
|
350 | } | |
350 |
|
351 | |||
351 | void MainWidget::yMinChanged(int value) |
|
352 | void MainWidget::yMinChanged(int value) | |
352 | { |
|
353 | { | |
353 | qDebug() << "yMinChanged: " << value; |
|
354 | qDebug() << "yMinChanged: " << value; | |
354 | } |
|
355 | } | |
355 |
|
356 | |||
356 | void MainWidget::yMaxChanged(int value) |
|
357 | void MainWidget::yMaxChanged(int value) | |
357 | { |
|
358 | { | |
358 | qDebug() << "yMaxChanged: " << value; |
|
359 | qDebug() << "yMaxChanged: " << value; | |
359 | } |
|
360 | } | |
360 |
|
361 | |||
361 | void MainWidget::changeChartTheme(int themeIndex) |
|
362 | void MainWidget::changeChartTheme(int themeIndex) | |
362 | { |
|
363 | { | |
363 | qDebug() << "changeChartTheme: " << themeIndex; |
|
364 | qDebug() << "changeChartTheme: " << themeIndex; | |
364 | m_chartWidget->setTheme((QChart::ChartThemeId) themeIndex); |
|
365 | m_chartWidget->setTheme((QChart::ChartThemeId) themeIndex); | |
365 | } |
|
366 | } | |
366 |
|
367 | |||
367 | void MainWidget::setPieSizeFactor(double size) |
|
368 | void MainWidget::setPieSizeFactor(double size) | |
368 | { |
|
369 | { | |
369 | QPieSeries *pie = qobject_cast<QPieSeries *>(m_currentSeries); |
|
370 | QPieSeries *pie = qobject_cast<QPieSeries *>(m_currentSeries); | |
370 | if (pie) |
|
371 | if (pie) | |
371 | pie->setSizeFactor(qreal(size)); |
|
372 | pie->setSizeFactor(qreal(size)); | |
372 | } |
|
373 | } | |
373 |
|
374 | |||
374 | void MainWidget::setPiePosition(int position) |
|
375 | void MainWidget::setPiePosition(int position) | |
375 | { |
|
376 | { | |
376 | QPieSeries *pie = qobject_cast<QPieSeries *>(m_currentSeries); |
|
377 | QPieSeries *pie = qobject_cast<QPieSeries *>(m_currentSeries); | |
377 | if (pie) |
|
378 | if (pie) | |
378 | pie->setPosition((QPieSeries::PiePosition) position); |
|
379 | pie->setPosition((QPieSeries::PiePosition) position); | |
379 | } |
|
380 | } |
@@ -1,76 +1,30 | |||||
1 | import QtQuick 1.0 |
|
1 | import QtQuick 1.0 | |
2 | import QtCommercial.Chart 1.0 |
|
2 | import QtCommercial.Chart 1.0 | |
3 |
|
3 | |||
4 | Rectangle { |
|
4 | Rectangle { | |
5 | width: 360 |
|
5 | width: 360 | |
6 | height: 360 |
|
6 | height: 360 | |
7 | Text { |
|
7 | Text { | |
8 | text: qsTr("Hello World") |
|
8 | text: qsTr("Hello World") | |
9 | anchors.centerIn: parent |
|
9 | anchors.centerIn: parent | |
10 | } |
|
10 | } | |
11 |
|
11 | |||
12 | // Component.onCompleted: { |
|
|||
13 | // for (var i = 0.0; i < 100.0; i += 0.1) { |
|
|||
14 | // var x = i + Math.random() * 5; |
|
|||
15 | // var y = Math.abs(Math.sin(3.14159 / 50 * x) * 100) + (Math.random() * 5); |
|
|||
16 | // myData.append({'x':x, 'y':y}); |
|
|||
17 | // } |
|
|||
18 | // } |
|
|||
19 |
|
||||
20 | // ChartModel { |
|
|||
21 | // id: chartData |
|
|||
22 | // ChartElement { |
|
|||
23 | // y: 1.2 |
|
|||
24 | // } |
|
|||
25 | // ChartElement { |
|
|||
26 | // x: 1.1 |
|
|||
27 | // y: 1.2 |
|
|||
28 | // } |
|
|||
29 | // ChartElement { |
|
|||
30 | // label: "February" |
|
|||
31 | // y: 1.2 |
|
|||
32 | // } |
|
|||
33 | // ChartElement { |
|
|||
34 | // label: "January" |
|
|||
35 | // x: 0.2 |
|
|||
36 | // y: 2.1 |
|
|||
37 | // } |
|
|||
38 | // } |
|
|||
39 |
|
||||
40 | // Series { |
|
|||
41 | // model: chartData |
|
|||
42 | // seriesType: pie |
|
|||
43 | // axis: Series.AxisSecondaryY |
|
|||
44 | // } |
|
|||
45 |
|
||||
46 | ListModel { |
|
|||
47 | id: myData |
|
|||
48 | ListElement { |
|
|||
49 | nnn: 55.2 |
|
|||
50 | mmm: 13.1 |
|
|||
51 | } |
|
|||
52 | ListElement { |
|
|||
53 | nnn: 15.3 |
|
|||
54 | mmm: 3.4 |
|
|||
55 | } |
|
|||
56 | } |
|
|||
57 |
|
||||
58 | Chart { |
|
12 | Chart { | |
59 | anchors.fill: parent |
|
13 | anchors.fill: parent | |
60 | theme: Chart.ThemeIcy |
|
14 | theme: Chart.ThemeIcy | |
61 |
|
15 | |||
62 | Series { |
|
16 | Series { | |
63 | seriesType: Series.SeriesTypePie |
|
17 | seriesType: Series.SeriesTypePie | |
64 | } |
|
18 | } | |
65 | Series { |
|
19 | Series { | |
66 | seriesType: Series.SeriesTypeScatter |
|
20 | seriesType: Series.SeriesTypeScatter | |
67 | } |
|
21 | } | |
68 | Series { |
|
22 | Series { | |
69 | seriesType: Series.SeriesTypeLine |
|
23 | seriesType: Series.SeriesTypeLine | |
70 | } |
|
24 | } | |
71 | // TODO: |
|
25 | // TODO: | |
72 | // Series { |
|
26 | // Series { | |
73 | // seriesType: Series.SeriesTypeBar |
|
27 | // seriesType: Series.SeriesTypeBar | |
74 | // } |
|
28 | // } | |
75 | } |
|
29 | } | |
76 | } |
|
30 | } |
General Comments 0
You need to be logged in to leave comments.
Login now