##// END OF EJS Templates
Fix Krazy issues
Jani Honkonen -
r1935:beaeb7cee6fe
parent child
Show More
@@ -1,76 +1,76
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 THEMEWINDOW_H_
21 #ifndef THEMEWINDOW_H
22 #define THEMEWINDOW_H_
22 #define THEMEWINDOW_H
23 #include <QWidget>
23 #include <QWidget>
24 #include <QChartGlobal>
24 #include <QChartGlobal>
25
25
26 class QComboBox;
26 class QComboBox;
27 class QCheckBox;
27 class QCheckBox;
28
28
29 QTCOMMERCIALCHART_BEGIN_NAMESPACE
29 QTCOMMERCIALCHART_BEGIN_NAMESPACE
30 class QChartView;
30 class QChartView;
31 class QChart;
31 class QChart;
32 QTCOMMERCIALCHART_END_NAMESPACE
32 QTCOMMERCIALCHART_END_NAMESPACE
33
33
34 typedef QPair<QPointF, QString> Data;
34 typedef QPair<QPointF, QString> Data;
35 typedef QList<Data> DataList;
35 typedef QList<Data> DataList;
36 typedef QList<DataList> DataTable;
36 typedef QList<DataList> DataTable;
37
37
38 QTCOMMERCIALCHART_USE_NAMESPACE
38 QTCOMMERCIALCHART_USE_NAMESPACE
39
39
40 class ThemeWidget: public QWidget
40 class ThemeWidget: public QWidget
41 {
41 {
42 Q_OBJECT
42 Q_OBJECT
43 public:
43 public:
44 explicit ThemeWidget(QWidget *parent = 0);
44 explicit ThemeWidget(QWidget *parent = 0);
45 ~ThemeWidget();
45 ~ThemeWidget();
46
46
47 private Q_SLOTS:
47 private Q_SLOTS:
48 void updateUI();
48 void updateUI();
49
49
50 private:
50 private:
51 DataTable generateRandomData(int listCount,int valueMax,int valueCount) const;
51 DataTable generateRandomData(int listCount,int valueMax,int valueCount) const;
52 QComboBox* createThemeBox() const;
52 QComboBox* createThemeBox() const;
53 QComboBox* createAnimationBox() const;
53 QComboBox* createAnimationBox() const;
54 QComboBox* createLegendBox() const;
54 QComboBox* createLegendBox() const;
55 void connectSignals();
55 void connectSignals();
56 QChart* createAreaChart() const;
56 QChart* createAreaChart() const;
57 QChart* createBarChart(int valueCount) const;
57 QChart* createBarChart(int valueCount) const;
58 QChart* createPieChart() const;
58 QChart* createPieChart() const;
59 QChart* createLineChart() const;
59 QChart* createLineChart() const;
60 QChart* createSplineChart() const;
60 QChart* createSplineChart() const;
61 QChart* createScatterChart() const;
61 QChart* createScatterChart() const;
62
62
63 private:
63 private:
64 int m_listCount;
64 int m_listCount;
65 int m_valueMax;
65 int m_valueMax;
66 int m_valueCount;
66 int m_valueCount;
67 QList<QChartView*> m_charts;
67 QList<QChartView*> m_charts;
68 DataTable m_dataTable;
68 DataTable m_dataTable;
69
69
70 QComboBox *m_themeComboBox;
70 QComboBox *m_themeComboBox;
71 QCheckBox *m_antialiasCheckBox;
71 QCheckBox *m_antialiasCheckBox;
72 QComboBox *m_animatedComboBox;
72 QComboBox *m_animatedComboBox;
73 QComboBox *m_legendComboBox;
73 QComboBox *m_legendComboBox;
74 };
74 };
75
75
76 #endif /* THEMEWINDOW_H_ */
76 #endif /* THEMEWINDOW_H */
@@ -1,68 +1,68
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 MODEL_H_
21 #ifndef MODEL_H
22 #define MODEL_H_
22 #define MODEL_H
23
23
24 #include <QList>
24 #include <QList>
25 #include <QPair>
25 #include <QPair>
26 #include <QPointF>
26 #include <QPointF>
27 #include <QTime>
27 #include <QTime>
28 #include <stdlib.h>
28 #include <stdlib.h>
29
29
30 typedef QPair<QPointF, QString> Data;
30 typedef QPair<QPointF, QString> Data;
31 typedef QList<Data> DataList;
31 typedef QList<Data> DataList;
32 typedef QList<DataList> DataTable;
32 typedef QList<DataList> DataTable;
33
33
34
34
35 class Model
35 class Model
36 {
36 {
37 private:
37 private:
38 Model(){}
38 Model(){}
39
39
40 public:
40 public:
41 static DataTable generateRandomData(int listCount, int valueMax, int valueCount)
41 static DataTable generateRandomData(int listCount, int valueMax, int valueCount)
42 {
42 {
43 DataTable dataTable;
43 DataTable dataTable;
44
44
45 // set seed for random stuff
45 // set seed for random stuff
46 qsrand(QTime(0, 0, 0).secsTo(QTime::currentTime()));
46 qsrand(QTime(0, 0, 0).secsTo(QTime::currentTime()));
47
47
48 // generate random data
48 // generate random data
49 for (int i(0); i < listCount; i++) {
49 for (int i(0); i < listCount; i++) {
50 DataList dataList;
50 DataList dataList;
51 qreal yValue(0);
51 qreal yValue(0);
52 for (int j(0); j < valueCount; j++) {
52 for (int j(0); j < valueCount; j++) {
53 yValue = yValue + (qreal) (qrand() % valueMax) / (qreal) valueCount;
53 yValue = yValue + (qreal) (qrand() % valueMax) / (qreal) valueCount;
54 QPointF value(
54 QPointF value(
55 (j + (qreal) qrand() / (qreal) RAND_MAX)
55 (j + (qreal) qrand() / (qreal) RAND_MAX)
56 * ((qreal) valueMax / (qreal) valueCount), yValue);
56 * ((qreal) valueMax / (qreal) valueCount), yValue);
57 QString label = "Slice " + QString::number(i) + ":" + QString::number(j);
57 QString label = "Slice " + QString::number(i) + ":" + QString::number(j);
58 dataList << Data(value, label);
58 dataList << Data(value, label);
59 }
59 }
60 dataTable << dataList;
60 dataTable << dataList;
61 }
61 }
62
62
63 return dataTable;
63 return dataTable;
64 }
64 }
65
65
66 };
66 };
67
67
68 #endif
68 #endif
@@ -1,42 +1,42
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 VIEW_H_
21 #ifndef VIEW_H
22 #define VIEW_H_
22 #define VIEW_H
23 #include <QGraphicsView>
23 #include <QGraphicsView>
24
24
25 class QGraphicsScene;
25 class QGraphicsScene;
26 class QResizeEvent;
26 class QResizeEvent;
27
27
28 class View: public QGraphicsView
28 class View: public QGraphicsView
29 {
29 {
30 public:
30 public:
31 View(QGraphicsScene *scene, QGraphicsWidget *form , QWidget *parent = 0);
31 View(QGraphicsScene *scene, QGraphicsWidget *form , QWidget *parent = 0);
32
32
33 protected:
33 protected:
34 void resizeEvent(QResizeEvent *event);
34 void resizeEvent(QResizeEvent *event);
35 void mouseMoveEvent(QMouseEvent *event);
35 void mouseMoveEvent(QMouseEvent *event);
36 void mouseReleaseEvent(QMouseEvent *event);
36 void mouseReleaseEvent(QMouseEvent *event);
37
37
38 private:
38 private:
39 QGraphicsWidget *m_form;
39 QGraphicsWidget *m_form;
40 };
40 };
41
41
42 #endif
42 #endif
@@ -1,123 +1,123
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 WINDOW_H_
21 #ifndef WINDOW_H
22 #define WINDOW_H_
22 #define WINDOW_H
23 #include "model.h"
23 #include "model.h"
24 #include <QMainWindow>
24 #include <QMainWindow>
25 #include <QChartGlobal>
25 #include <QChartGlobal>
26 #include <QHash>
26 #include <QHash>
27 #include <QComboBox>
27 #include <QComboBox>
28
28
29 class QCheckBox;
29 class QCheckBox;
30 class QGraphicsRectItem;
30 class QGraphicsRectItem;
31 class QGraphicsScene;
31 class QGraphicsScene;
32 class QGraphicsWidget;
32 class QGraphicsWidget;
33 class View;
33 class View;
34 class QGraphicsGridLayout;
34 class QGraphicsGridLayout;
35 class Chart;
35 class Chart;
36
36
37 QTCOMMERCIALCHART_BEGIN_NAMESPACE
37 QTCOMMERCIALCHART_BEGIN_NAMESPACE
38 class QChart;
38 class QChart;
39 QTCOMMERCIALCHART_END_NAMESPACE
39 QTCOMMERCIALCHART_END_NAMESPACE
40
40
41 QTCOMMERCIALCHART_USE_NAMESPACE
41 QTCOMMERCIALCHART_USE_NAMESPACE
42
42
43
43
44 class Window: public QMainWindow
44 class Window: public QMainWindow
45 {
45 {
46 Q_OBJECT
46 Q_OBJECT
47 enum State{ NoState = 0, ZoomState, ScrollState};
47 enum State{ NoState = 0, ZoomState, ScrollState};
48 public:
48 public:
49 explicit Window(QWidget *parent = 0);
49 explicit Window(QWidget *parent = 0);
50 ~Window();
50 ~Window();
51
51
52 private Q_SLOTS:
52 private Q_SLOTS:
53 void updateUI();
53 void updateUI();
54 private:
54 private:
55 QComboBox* createThemeBox();
55 QComboBox* createThemeBox();
56 QComboBox* createAnimationBox();
56 QComboBox* createAnimationBox();
57 QComboBox* createLegendBox();
57 QComboBox* createLegendBox();
58 QComboBox* createTempleteBox();
58 QComboBox* createTempleteBox();
59 void connectSignals();
59 void connectSignals();
60 void createProxyWidgets();
60 void createProxyWidgets();
61 void comboBoxFocused(QComboBox *combox);
61 void comboBoxFocused(QComboBox *combox);
62 inline void checkAnimationOptions();
62 inline void checkAnimationOptions();
63 inline void checkLegend();
63 inline void checkLegend();
64 inline void checkOpenGL();
64 inline void checkOpenGL();
65 inline void checkTheme();
65 inline void checkTheme();
66 inline void checkState();
66 inline void checkState();
67 inline void checkTemplate();
67 inline void checkTemplate();
68 QMenu* createMenu();
68 QMenu* createMenu();
69 void handleMenu(QChart * chart);
69 void handleMenu(QChart * chart);
70 QAction* createMenuAction(QMenu *menu, const QIcon &icon, const QString &text, const QVariant &data);
70 QAction* createMenuAction(QMenu *menu, const QIcon &icon, const QString &text, const QVariant &data);
71
71
72 protected:
72 protected:
73 void mousePressEvent(QMouseEvent *event);
73 void mousePressEvent(QMouseEvent *event);
74 void mouseMoveEvent(QMouseEvent *event);
74 void mouseMoveEvent(QMouseEvent *event);
75 void mouseReleaseEvent(QMouseEvent *event);
75 void mouseReleaseEvent(QMouseEvent *event);
76
76
77 private:
77 private:
78 int m_listCount;
78 int m_listCount;
79 int m_valueMax;
79 int m_valueMax;
80 int m_valueCount;
80 int m_valueCount;
81 QGraphicsScene* m_scene;
81 QGraphicsScene* m_scene;
82 View* m_view;
82 View* m_view;
83 QHash<QString, QGraphicsProxyWidget*> m_widgetHash;
83 QHash<QString, QGraphicsProxyWidget*> m_widgetHash;
84 QHash<QChart*, int> m_chartHash;
84 QHash<QChart*, int> m_chartHash;
85 DataTable m_dataTable;
85 DataTable m_dataTable;
86
86
87 QGraphicsWidget *m_form;
87 QGraphicsWidget *m_form;
88 QComboBox *m_themeComboBox;
88 QComboBox *m_themeComboBox;
89 QCheckBox *m_antialiasCheckBox;
89 QCheckBox *m_antialiasCheckBox;
90 QComboBox *m_animatedComboBox;
90 QComboBox *m_animatedComboBox;
91 QComboBox *m_legendComboBox;
91 QComboBox *m_legendComboBox;
92 QComboBox *m_templateComboBox;
92 QComboBox *m_templateComboBox;
93 QCheckBox *m_openGLCheckBox;
93 QCheckBox *m_openGLCheckBox;
94 QCheckBox *m_zoomCheckBox;
94 QCheckBox *m_zoomCheckBox;
95 QCheckBox *m_scrollCheckBox;
95 QCheckBox *m_scrollCheckBox;
96 QPoint m_origin;
96 QPoint m_origin;
97 QGraphicsRectItem* m_rubberBand;
97 QGraphicsRectItem* m_rubberBand;
98 QGraphicsGridLayout* m_baseLayout;
98 QGraphicsGridLayout* m_baseLayout;
99 QMenu* m_menu;
99 QMenu* m_menu;
100 State m_state;
100 State m_state;
101 State m_currentState;
101 State m_currentState;
102 int m_template;
102 int m_template;
103
103
104 friend class ComboBox;
104 friend class ComboBox;
105 };
105 };
106
106
107 class ComboBox: public QComboBox
107 class ComboBox: public QComboBox
108 {
108 {
109 public:
109 public:
110 ComboBox(Window* window,QWidget *parent = 0):QComboBox(parent),m_window(window)
110 ComboBox(Window* window,QWidget *parent = 0):QComboBox(parent),m_window(window)
111 {}
111 {}
112
112
113 protected:
113 protected:
114 void focusInEvent(QFocusEvent *e)
114 void focusInEvent(QFocusEvent *e)
115 {
115 {
116 QComboBox::focusInEvent(e);
116 QComboBox::focusInEvent(e);
117 m_window->comboBoxFocused(this);
117 m_window->comboBoxFocused(this);
118 }
118 }
119 private:
119 private:
120 Window* m_window;
120 Window* m_window;
121 };
121 };
122
122
123 #endif
123 #endif
@@ -1,56 +1,56
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 CHART_H_
21 #ifndef CHART_H
22 #define CHART_H_
22 #define CHART_H
23
23
24 #include <QChart>
24 #include <QChart>
25 #include <QTimer>
25 #include <QTimer>
26
26
27 QTCOMMERCIALCHART_BEGIN_NAMESPACE
27 QTCOMMERCIALCHART_BEGIN_NAMESPACE
28 class QSplineSeries;
28 class QSplineSeries;
29 class QValueAxis;
29 class QValueAxis;
30 QTCOMMERCIALCHART_END_NAMESPACE
30 QTCOMMERCIALCHART_END_NAMESPACE
31
31
32 QTCOMMERCIALCHART_USE_NAMESPACE
32 QTCOMMERCIALCHART_USE_NAMESPACE
33
33
34 //![1]
34 //![1]
35 class Chart: public QChart
35 class Chart: public QChart
36 {
36 {
37 Q_OBJECT
37 Q_OBJECT
38 public:
38 public:
39 Chart(QGraphicsItem *parent = 0, Qt::WindowFlags wFlags = 0);
39 Chart(QGraphicsItem *parent = 0, Qt::WindowFlags wFlags = 0);
40 virtual ~Chart();
40 virtual ~Chart();
41
41
42 public slots:
42 public slots:
43 void handleTimeout();
43 void handleTimeout();
44
44
45 private:
45 private:
46 QTimer m_timer;
46 QTimer m_timer;
47 QSplineSeries* m_series;
47 QSplineSeries* m_series;
48 QStringList m_titles;
48 QStringList m_titles;
49 QValueAxis* m_axis;
49 QValueAxis* m_axis;
50 qreal m_step;
50 qreal m_step;
51 qreal m_x;
51 qreal m_x;
52 qreal m_y;
52 qreal m_y;
53 };
53 };
54 //![1]
54 //![1]
55
55
56 #endif /* CHART_H_ */
56 #endif /* CHART_H */
@@ -1,49 +1,49
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 CHARTVIEW_H_
21 #ifndef CHARTVIEW_H
22 #define CHARTVIEW_H_
22 #define CHARTVIEW_H
23
23
24 #include <QChartView>
24 #include <QChartView>
25 #include <QTimer>
25 #include <QTimer>
26
26
27 QTCOMMERCIALCHART_USE_NAMESPACE
27 QTCOMMERCIALCHART_USE_NAMESPACE
28
28
29 //![1]
29 //![1]
30 class ChartView: public QChartView
30 class ChartView: public QChartView
31 {
31 {
32 Q_OBJECT
32 Q_OBJECT
33 public:
33 public:
34 ChartView(QChart* chart,QWidget* parent = 0);
34 ChartView(QChart* chart,QWidget* parent = 0);
35 virtual ~ChartView();
35 virtual ~ChartView();
36
36
37 public slots:
37 public slots:
38 void handleTimeout();
38 void handleTimeout();
39
39
40 private:
40 private:
41 QTimer m_timer;
41 QTimer m_timer;
42 QList<QAbstractSeries *> m_series;
42 QList<QAbstractSeries *> m_series;
43 QStringList m_titles;
43 QStringList m_titles;
44 int m_index;
44 int m_index;
45 QChart *m_chart;
45 QChart *m_chart;
46 };
46 };
47 //![1]
47 //![1]
48
48
49 #endif /* CHARTVIEW_H_ */
49 #endif /* CHARTVIEW_H */
@@ -1,44 +1,44
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 QCHARTSPLUGIN_H_
21 #ifndef QCHARTSPLUGIN_H
22 #define QCHARTSPLUGIN_H_
22 #define QCHARTSPLUGIN_H
23
23
24 #include <QDesignerCustomWidgetInterface>
24 #include <QDesignerCustomWidgetInterface>
25
25
26 class QChartsPlugin: public QObject,public QDesignerCustomWidgetInterface
26 class QChartsPlugin: public QObject,public QDesignerCustomWidgetInterface
27 {
27 {
28 Q_OBJECT
28 Q_OBJECT
29 Q_INTERFACES(QDesignerCustomWidgetInterface)
29 Q_INTERFACES(QDesignerCustomWidgetInterface)
30 public:
30 public:
31 QChartsPlugin(QObject *parent = 0);
31 QChartsPlugin(QObject *parent = 0);
32 ~QChartsPlugin();
32 ~QChartsPlugin();
33
33
34 QString name() const;
34 QString name() const;
35 QString includeFile() const;
35 QString includeFile() const;
36 QString group() const;
36 QString group() const;
37 QIcon icon() const;
37 QIcon icon() const;
38 QString toolTip() const;
38 QString toolTip() const;
39 QString whatsThis() const;
39 QString whatsThis() const;
40 bool isContainer() const;
40 bool isContainer() const;
41 QWidget *createWidget(QWidget *parent);
41 QWidget *createWidget(QWidget *parent);
42 };
42 };
43
43
44 #endif /* QCHARTSPLUGIN_H_ */
44 #endif /* QCHARTSPLUGIN_H */
@@ -1,62 +1,62
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 AXISANIMATION_H
30 #ifndef AXISANIMATION_H
31 #define AXISANIMATION_H
31 #define AXISANIMATION_H
32
32
33 #include "chartanimation_p.h"
33 #include "chartanimation_p.h"
34 #include <QPointF>
34 #include <QPointF>
35
35
36 QTCOMMERCIALCHART_BEGIN_NAMESPACE
36 QTCOMMERCIALCHART_BEGIN_NAMESPACE
37
37
38 class ChartAxis;
38 class ChartAxis;
39
39
40 class AxisAnimation: public ChartAnimation
40 class AxisAnimation: public ChartAnimation
41 {
41 {
42 public:
42 public:
43 enum Animation { DefaultAnimation, ZoomOutAnimation, ZoomInAnimation, MoveForwardAnimation, MoveBackwordAnimation};
43 enum Animation { DefaultAnimation, ZoomOutAnimation, ZoomInAnimation, MoveForwardAnimation, MoveBackwordAnimation};
44 AxisAnimation(ChartAxis *axis);
44 AxisAnimation(ChartAxis *axis);
45 ~AxisAnimation();
45 ~AxisAnimation();
46 void setAnimationType(Animation type);
46 void setAnimationType(Animation type);
47 void setAnimationPoint(const QPointF& point);
47 void setAnimationPoint(const QPointF& point);
48 void setValues(QVector<qreal> &oldLayout, QVector<qreal> &newLayout);
48 void setValues(QVector<qreal> &oldLayout, QVector<qreal> &newLayout);
49 protected:
49 protected:
50 QVariant interpolated(const QVariant &from, const QVariant &to, qreal progress ) const;
50 QVariant interpolated(const QVariant &from, const QVariant &to, qreal progress ) const;
51 void updateCurrentValue(const QVariant &value );
51 void updateCurrentValue(const QVariant &value );
52 private:
52 private:
53 ChartAxis *m_axis;
53 ChartAxis *m_axis;
54 Animation m_type;
54 Animation m_type;
55 QPointF m_point;
55 QPointF m_point;
56 };
56 };
57
57
58 QTCOMMERCIALCHART_END_NAMESPACE
58 QTCOMMERCIALCHART_END_NAMESPACE
59
59
60
60
61
61
62 #endif /* AXISITEM_H_ */
62 #endif /* AXISANIMATION_H */
@@ -1,51 +1,49
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 CHARTANIMATION_H
30 #ifndef CHARTANIMATION_H
31 #define CHARTANIMATION_H
31 #define CHARTANIMATION_H
32
32
33 #include "qchartglobal.h"
33 #include "qchartglobal.h"
34 #include <QVariantAnimation>
34 #include <QVariantAnimation>
35
35
36 QTCOMMERCIALCHART_BEGIN_NAMESPACE
36 QTCOMMERCIALCHART_BEGIN_NAMESPACE
37
37
38 const static int ChartAnimationDuration = 1000;
38 const static int ChartAnimationDuration = 1000;
39
39
40 class ChartAnimation: public QVariantAnimation
40 class ChartAnimation: public QVariantAnimation
41 {
41 {
42 Q_OBJECT
42 Q_OBJECT
43 public:
43 public:
44 ChartAnimation(QObject *parent = 0):QVariantAnimation(parent){};
44 ChartAnimation(QObject *parent = 0):QVariantAnimation(parent){};
45 };
45 };
46
46
47 QTCOMMERCIALCHART_END_NAMESPACE
47 QTCOMMERCIALCHART_END_NAMESPACE
48
48
49
49 #endif /* CHARTANIMATION_H */
50
51 #endif /* AXISITEM_H_ */
@@ -1,64 +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 // 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 CHARTCATEGORIESAXISX_H
30 #ifndef CHARTBARCATEGORYAXISX_H
31 #define CHARTCATEGORIESAXISX_H
31 #define CHARTBARCATEGORYAXISX_H
32
32
33 #include "chartaxis_p.h"
33 #include "chartaxis_p.h"
34
34
35 QTCOMMERCIALCHART_BEGIN_NAMESPACE
35 QTCOMMERCIALCHART_BEGIN_NAMESPACE
36
36
37 class QAbstractAxis;
37 class QAbstractAxis;
38 class ChartPresenter;
38 class ChartPresenter;
39 class QBarCategoryAxis;
39 class QBarCategoryAxis;
40
40
41 class ChartBarCategoryAxisX : public ChartAxis
41 class ChartBarCategoryAxisX : public ChartAxis
42 {
42 {
43 public:
43 public:
44 ChartBarCategoryAxisX(QBarCategoryAxis *axis, ChartPresenter *presenter);
44 ChartBarCategoryAxisX(QBarCategoryAxis *axis, ChartPresenter *presenter);
45 ~ChartBarCategoryAxisX();
45 ~ChartBarCategoryAxisX();
46
46
47 AxisType axisType() const { return X_AXIS;}
47 AxisType axisType() const { return X_AXIS;}
48
48
49 protected:
49 protected:
50 QVector<qreal> calculateLayout() const;
50 QVector<qreal> calculateLayout() const;
51 void updateGeometry();
51 void updateGeometry();
52 private:
52 private:
53 QStringList createCategoryLabels(const QVector<qreal>& layout) const;
53 QStringList createCategoryLabels(const QVector<qreal>& layout) const;
54 Q_SLOTS
54 Q_SLOTS
55 void handleAxisUpdated();
55 void handleAxisUpdated();
56
56
57 private:
57 private:
58 QStringList m_categories;
58 QStringList m_categories;
59 QBarCategoryAxis *m_categoriesAxis;
59 QBarCategoryAxis *m_categoriesAxis;
60 };
60 };
61
61
62 QTCOMMERCIALCHART_END_NAMESPACE
62 QTCOMMERCIALCHART_END_NAMESPACE
63
63
64 #endif /* CHARTCATEGORIESAXISX_H */
64 #endif /* CHARTBARCATEGORYAXISX_H */
@@ -1,63 +1,63
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 CHARTCATEGORIESAXISY_H
30 #ifndef CHARTBARCATEGORYAXISY_H
31 #define CHARTCATEGORIESAXISY_H
31 #define CHARTBARCATEGORYAXISY_H
32
32
33 #include "chartaxis_p.h"
33 #include "chartaxis_p.h"
34
34
35 QTCOMMERCIALCHART_BEGIN_NAMESPACE
35 QTCOMMERCIALCHART_BEGIN_NAMESPACE
36
36
37 class QAbstractAxis;
37 class QAbstractAxis;
38 class QBarCategoryAxis;
38 class QBarCategoryAxis;
39 class ChartPresenter;
39 class ChartPresenter;
40
40
41 class ChartBarCategoryAxisY : public ChartAxis
41 class ChartBarCategoryAxisY : public ChartAxis
42 {
42 {
43 public:
43 public:
44 ChartBarCategoryAxisY(QBarCategoryAxis *axis, ChartPresenter *presenter);
44 ChartBarCategoryAxisY(QBarCategoryAxis *axis, ChartPresenter *presenter);
45 ~ChartBarCategoryAxisY();
45 ~ChartBarCategoryAxisY();
46
46
47 AxisType axisType() const { return Y_AXIS;}
47 AxisType axisType() const { return Y_AXIS;}
48
48
49 protected:
49 protected:
50 QVector<qreal> calculateLayout() const;
50 QVector<qreal> calculateLayout() const;
51 void updateGeometry();
51 void updateGeometry();
52 private:
52 private:
53 QStringList createCategoryLabels(const QVector<qreal>& layout) const;
53 QStringList createCategoryLabels(const QVector<qreal>& layout) const;
54 Q_SLOTS
54 Q_SLOTS
55 void handleAxisUpdated();
55 void handleAxisUpdated();
56 private:
56 private:
57 QStringList m_categories;
57 QStringList m_categories;
58 QBarCategoryAxis *m_categoriesAxis;
58 QBarCategoryAxis *m_categoriesAxis;
59 };
59 };
60
60
61 QTCOMMERCIALCHART_END_NAMESPACE
61 QTCOMMERCIALCHART_END_NAMESPACE
62
62
63 #endif /* CHARTCATEGORIESAXISY_H */
63 #endif /* CHARTBARCATEGORYAXISY_H */
@@ -1,487 +1,487
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 "qbarcategoryaxis.h"
21 #include "qbarcategoryaxis.h"
22 #include "qbarcategoryaxis_p.h"
22 #include "qbarcategoryaxis_p.h"
23 #include "chartbarcategoryaxisx_p.h"
23 #include "chartbarcategoryaxisx_p.h"
24 #include "chartbarcategoryaxisy_p.h"
24 #include "chartbarcategoryaxisy_p.h"
25 #include "domain_p.h"
25 #include "domain_p.h"
26 #include "chartdataset_p.h"
26 #include "chartdataset_p.h"
27 #include <qmath.h>
27 #include <qmath.h>
28
28
29 QTCOMMERCIALCHART_BEGIN_NAMESPACE
29 QTCOMMERCIALCHART_BEGIN_NAMESPACE
30 /*!
30 /*!
31 \class QBarCategoryAxis
31 \class QBarCategoryAxis
32 \brief The QBarCategoryAxis class is used for manipulating chart's axis.
32 \brief The QBarCategoryAxis class is used for manipulating chart's axis.
33 \mainclass
33 \mainclass
34
34
35 BarCategoryAxis can be setup to show axis line with tick marks, grid lines and shades.
35 BarCategoryAxis can be setup to show axis line with tick marks, grid lines and shades.
36 Categories are drawn between ticks. Note that you can use this also with lineseries too.
36 Categories are drawn between ticks. Note that you can use this also with lineseries too.
37 See the \l {Line and BarChart Example} {Line and BarChart Example} to learn how to do that.
37 See the \l {Line and BarChart Example} {Line and BarChart Example} to learn how to do that.
38
38
39 Example code on how to use QBarCategoryAxis.
39 Example code on how to use QBarCategoryAxis.
40 \code
40 \code
41 QChartView *chartView = new QChartView;
41 QChartView *chartView = new QChartView;
42 QBarSeries *series = new QBarSeries;
42 QBarSeries *series = new QBarSeries;
43 // ...
43 // ...
44 chartView->chart()->addSeries(series);
44 chartView->chart()->addSeries(series);
45 chartView->chart()->createDefaultAxes();
45 chartView->chart()->createDefaultAxes();
46
46
47 QBarCategoryAxis *axisX = new QBarCategoryAxis;
47 QBarCategoryAxis *axisX = new QBarCategoryAxis;
48 QStringList categories;
48 QStringList categories;
49 categories << "Jan" << "Feb" << "Mar" << "Apr" << "May" << "Jun";
49 categories << "Jan" << "Feb" << "Mar" << "Apr" << "May" << "Jun";
50 axisX->append(categories);
50 axisX->append(categories);
51 chartView->chart()->setAxisX(series, axisX);
51 chartView->chart()->setAxisX(series, axisX);
52 \endcode
52 \endcode
53 */
53 */
54
54
55 /*!
55 /*!
56 \qmlclass BarCategoryAxis QBarCategoryAxis
56 \qmlclass BarCategoryAxis QBarCategoryAxis
57 \inherits AbstractAxis
57 \inherits AbstractAxis
58 \brief The Axis element is used for manipulating chart's axes.
58 \brief The Axis element is used for manipulating chart's axes.
59
59
60 Axis can be setup to show axis line with tick marks, grid lines and shades.
60 Axis can be setup to show axis line with tick marks, grid lines and shades.
61 Categories are drawn between ticks. Note that you can use this also with lineseries too.
61 Categories are drawn between ticks. Note that you can use this also with lineseries too.
62
62
63 To access BarCategoryAxis you can use ChartView API. For example:
63 To access BarCategoryAxis you can use ChartView API. For example:
64 \code
64 \code
65 ChartView {
65 ChartView {
66 BarCategoryAxis {
66 BarCategoryAxis {
67 id: categoryAxis
67 id: categoryAxis
68 categories: ["Jan", "Feb", "Mar", "Apr", "May", "Jun" ]
68 categories: ["Jan", "Feb", "Mar", "Apr", "May", "Jun" ]
69 }
69 }
70 // Add a few series...
70 // Add a few series...
71 }
71 }
72 \endcode
72 \endcode
73 */
73 */
74
74
75 /*!
75 /*!
76 \property QBarCategoryAxis::categories
76 \property QBarCategoryAxis::categories
77 Defines the categories of axis
77 Defines the categories of axis
78 */
78 */
79 /*!
79 /*!
80 \qmlproperty QStringList BarCategoryAxis::categories
80 \qmlproperty QStringList BarCategoryAxis::categories
81 Defines the categories of axis
81 Defines the categories of axis
82 */
82 */
83
83
84 /*!
84 /*!
85 \property QBarCategoryAxis::min
85 \property QBarCategoryAxis::min
86 Defines the minimum value on the axis.
86 Defines the minimum value on the axis.
87 */
87 */
88 /*!
88 /*!
89 \qmlproperty QString BarCategoryAxis::min
89 \qmlproperty QString BarCategoryAxis::min
90 Defines the minimum value on the axis.
90 Defines the minimum value on the axis.
91 */
91 */
92
92
93 /*!
93 /*!
94 \property QBarCategoryAxis::max
94 \property QBarCategoryAxis::max
95 Defines the maximum value on the axis.
95 Defines the maximum value on the axis.
96 */
96 */
97 /*!
97 /*!
98 \qmlproperty QString BarCategoryAxis::max
98 \qmlproperty QString BarCategoryAxis::max
99 Defines the maximum value on the axis.
99 Defines the maximum value on the axis.
100 */
100 */
101
101
102
102
103 /*!
103 /*!
104 \fn void QBarCategoryAxis::categoriesChanged()
104 \fn void QBarCategoryAxis::categoriesChanged()
105 Axis emits signal when the categories of the axis has changed.
105 Axis emits signal when the categories of the axis has changed.
106 */
106 */
107 /*!
107 /*!
108 \fn void QBarCategoryAxis::minChanged(const QString &min)
108 \fn void QBarCategoryAxis::minChanged(const QString &min)
109 Axis emits signal when \a min of axis has changed.
109 Axis emits signal when \a min of axis has changed.
110 */
110 */
111 /*!
111 /*!
112 \qmlsignal BarCategoryAxis::onMinChanged(const QString &min)
112 \qmlsignal BarCategoryAxis::onMinChanged(const QString &min)
113 Axis emits signal when \a min of axis has changed.
113 Axis emits signal when \a min of axis has changed.
114 */
114 */
115
115
116 /*!
116 /*!
117 \fn void QBarCategoryAxis::maxChanged(const QString &max)
117 \fn void QBarCategoryAxis::maxChanged(const QString &max)
118 Axis emits signal when \a max of axis has changed.
118 Axis emits signal when \a max of axis has changed.
119 */
119 */
120 /*!
120 /*!
121 \qmlsignal BarCategoryAxis::onMaxChanged(const QString &max)
121 \qmlsignal BarCategoryAxis::onMaxChanged(const QString &max)
122 Axis emits signal when \a max of axis has changed.
122 Axis emits signal when \a max of axis has changed.
123 */
123 */
124
124
125 /*!
125 /*!
126 \fn void QBarCategoryAxis::rangeChanged(const QString &min, const QString &max)
126 \fn void QBarCategoryAxis::rangeChanged(const QString &min, const QString &max)
127 Axis emits signal when \a min or \a max of axis has changed.
127 Axis emits signal when \a min or \a max of axis has changed.
128 */
128 */
129
129
130 /*!
130 /*!
131 Constructs an axis object which is a child of \a parent.
131 Constructs an axis object which is a child of \a parent.
132 */
132 */
133 QBarCategoryAxis::QBarCategoryAxis(QObject *parent):
133 QBarCategoryAxis::QBarCategoryAxis(QObject *parent):
134 QAbstractAxis(*new QBarCategoryAxisPrivate(this),parent)
134 QAbstractAxis(*new QBarCategoryAxisPrivate(this),parent)
135 {
135 {
136 }
136 }
137
137
138 /*!
138 /*!
139 Destroys the object
139 Destroys the object
140 */
140 */
141 QBarCategoryAxis::~QBarCategoryAxis()
141 QBarCategoryAxis::~QBarCategoryAxis()
142 {
142 {
143 Q_D(QBarCategoryAxis);
143 Q_D(QBarCategoryAxis);
144 if(d->m_dataset){
144 if(d->m_dataset){
145 d->m_dataset->removeAxis(this);
145 d->m_dataset->removeAxis(this);
146 }
146 }
147 }
147 }
148
148
149 /*!
149 /*!
150 \internal
150 \internal
151 */
151 */
152 QBarCategoryAxis::QBarCategoryAxis(QBarCategoryAxisPrivate &d,QObject *parent):QAbstractAxis(d,parent)
152 QBarCategoryAxis::QBarCategoryAxis(QBarCategoryAxisPrivate &d,QObject *parent):QAbstractAxis(d,parent)
153 {
153 {
154
154
155 }
155 }
156
156
157 /*!
157 /*!
158 Appends \a categories to axis
158 Appends \a categories to axis
159 */
159 */
160 void QBarCategoryAxis::append(const QStringList &categories)
160 void QBarCategoryAxis::append(const QStringList &categories)
161 {
161 {
162 if(categories.isEmpty()) return;
162 if(categories.isEmpty()) return;
163
163
164 Q_D(QBarCategoryAxis);
164 Q_D(QBarCategoryAxis);
165 if (d->m_categories.isEmpty()) {
165 if (d->m_categories.isEmpty()) {
166 d->m_categories.append(categories);
166 d->m_categories.append(categories);
167 setRange(categories.first(),categories.last());
167 setRange(categories.first(),categories.last());
168 }else{
168 }else{
169 d->m_categories.append(categories);
169 d->m_categories.append(categories);
170 d->emitUpdated();
170 d->emitUpdated();
171 }
171 }
172 emit categoriesChanged();
172 emit categoriesChanged();
173 }
173 }
174
174
175 /*!
175 /*!
176 Appends \a category to axis
176 Appends \a category to axis
177 */
177 */
178 void QBarCategoryAxis::append(const QString &category)
178 void QBarCategoryAxis::append(const QString &category)
179 {
179 {
180 Q_D(QBarCategoryAxis);
180 Q_D(QBarCategoryAxis);
181 if (d->m_categories.isEmpty()) {
181 if (d->m_categories.isEmpty()) {
182 d->m_categories.append(category);
182 d->m_categories.append(category);
183 setRange(category,category);
183 setRange(category,category);
184 }else{
184 }else{
185 d->m_categories.append(category);
185 d->m_categories.append(category);
186 d->emitUpdated();
186 d->emitUpdated();
187 }
187 }
188 emit categoriesChanged();
188 emit categoriesChanged();
189 }
189 }
190
190
191 /*!
191 /*!
192 Removes \a category from axis
192 Removes \a category from axis
193 */
193 */
194 void QBarCategoryAxis::remove(const QString &category)
194 void QBarCategoryAxis::remove(const QString &category)
195 {
195 {
196 Q_D(QBarCategoryAxis);
196 Q_D(QBarCategoryAxis);
197 if (d->m_categories.contains(category)) {
197 if (d->m_categories.contains(category)) {
198 d->m_categories.removeAt(d->m_categories.indexOf(category));
198 d->m_categories.removeAt(d->m_categories.indexOf(category));
199 if(!d->m_categories.isEmpty())
199 if(!d->m_categories.isEmpty())
200 setRange(d->m_categories.first(),d->m_categories.last());
200 setRange(d->m_categories.first(),d->m_categories.last());
201 else
201 else
202 setRange(QString::null,QString::null);
202 setRange(QString(),QString());
203 emit categoriesChanged();
203 emit categoriesChanged();
204 }
204 }
205 }
205 }
206
206
207 /*!
207 /*!
208 Inserts \a category to axis at \a index
208 Inserts \a category to axis at \a index
209 */
209 */
210 void QBarCategoryAxis::insert(int index, const QString &category)
210 void QBarCategoryAxis::insert(int index, const QString &category)
211 {
211 {
212 Q_D(QBarCategoryAxis);
212 Q_D(QBarCategoryAxis);
213 if (d->m_categories.isEmpty()) {
213 if (d->m_categories.isEmpty()) {
214 d->m_categories.insert(index,category);
214 d->m_categories.insert(index,category);
215 setRange(category,category);
215 setRange(category,category);
216 }else{
216 }else{
217 d->m_categories.insert(index,category);
217 d->m_categories.insert(index,category);
218 d->emitUpdated();
218 d->emitUpdated();
219 }
219 }
220 emit categoriesChanged();
220 emit categoriesChanged();
221 }
221 }
222
222
223 /*!
223 /*!
224 Replaces \a oldCategory with \a newCategory.
224 Replaces \a oldCategory with \a newCategory.
225 If \a oldCategory does not exits on the axis nothing is done.
225 If \a oldCategory does not exits on the axis nothing is done.
226 */
226 */
227 void QBarCategoryAxis::replace(const QString &oldCategory, const QString &newCategory)
227 void QBarCategoryAxis::replace(const QString &oldCategory, const QString &newCategory)
228 {
228 {
229 Q_D(QBarCategoryAxis);
229 Q_D(QBarCategoryAxis);
230 int pos = d->m_categories.indexOf(oldCategory);
230 int pos = d->m_categories.indexOf(oldCategory);
231 if (pos != -1) {
231 if (pos != -1) {
232 d->m_categories.replace(pos, newCategory);
232 d->m_categories.replace(pos, newCategory);
233 d->emitUpdated();
233 d->emitUpdated();
234 emit categoriesChanged();
234 emit categoriesChanged();
235 }
235 }
236 }
236 }
237
237
238 /*!
238 /*!
239 Removes all categories.
239 Removes all categories.
240 */
240 */
241 void QBarCategoryAxis::clear()
241 void QBarCategoryAxis::clear()
242 {
242 {
243 Q_D(QBarCategoryAxis);
243 Q_D(QBarCategoryAxis);
244 d->m_categories.clear();
244 d->m_categories.clear();
245 setRange(QString::null,QString::null);
245 setRange(QString(),QString());
246 emit categoriesChanged();
246 emit categoriesChanged();
247 }
247 }
248
248
249 void QBarCategoryAxis::setCategories(const QStringList &categories)
249 void QBarCategoryAxis::setCategories(const QStringList &categories)
250 {
250 {
251 Q_D(QBarCategoryAxis);
251 Q_D(QBarCategoryAxis);
252 if(d->m_categories!=categories) {
252 if(d->m_categories!=categories) {
253 d->m_categories = categories;
253 d->m_categories = categories;
254 setRange(categories.first(),categories.last());
254 setRange(categories.first(),categories.last());
255 emit categoriesChanged();
255 emit categoriesChanged();
256 }
256 }
257 }
257 }
258
258
259 QStringList QBarCategoryAxis::categories()
259 QStringList QBarCategoryAxis::categories()
260 {
260 {
261 Q_D(QBarCategoryAxis);
261 Q_D(QBarCategoryAxis);
262 return d->m_categories;
262 return d->m_categories;
263 }
263 }
264
264
265 /*!
265 /*!
266 Returns number of categories.
266 Returns number of categories.
267 */
267 */
268 int QBarCategoryAxis::count() const
268 int QBarCategoryAxis::count() const
269 {
269 {
270 Q_D(const QBarCategoryAxis);
270 Q_D(const QBarCategoryAxis);
271 return d->m_categories.count();
271 return d->m_categories.count();
272 }
272 }
273
273
274 /*!
274 /*!
275 Returns category at \a index. Index must be valid.
275 Returns category at \a index. Index must be valid.
276 */
276 */
277 QString QBarCategoryAxis::at(int index) const
277 QString QBarCategoryAxis::at(int index) const
278 {
278 {
279 Q_D(const QBarCategoryAxis);
279 Q_D(const QBarCategoryAxis);
280 return d->m_categories.at(index);
280 return d->m_categories.at(index);
281 }
281 }
282
282
283 /*!
283 /*!
284 Sets minimum category to \a min.
284 Sets minimum category to \a min.
285 */
285 */
286 void QBarCategoryAxis::setMin(const QString& min)
286 void QBarCategoryAxis::setMin(const QString& min)
287 {
287 {
288 Q_D(QBarCategoryAxis);
288 Q_D(QBarCategoryAxis);
289 setRange(min,d->m_maxCategory);
289 setRange(min,d->m_maxCategory);
290 }
290 }
291
291
292 /*!
292 /*!
293 Returns minimum category.
293 Returns minimum category.
294 */
294 */
295 QString QBarCategoryAxis::min() const
295 QString QBarCategoryAxis::min() const
296 {
296 {
297 Q_D(const QBarCategoryAxis);
297 Q_D(const QBarCategoryAxis);
298 return d->m_minCategory;
298 return d->m_minCategory;
299 }
299 }
300
300
301 /*!
301 /*!
302 Sets maximum category to \a max.
302 Sets maximum category to \a max.
303 */
303 */
304 void QBarCategoryAxis::setMax(const QString& max)
304 void QBarCategoryAxis::setMax(const QString& max)
305 {
305 {
306 Q_D(QBarCategoryAxis);
306 Q_D(QBarCategoryAxis);
307 setRange(d->m_minCategory,max);
307 setRange(d->m_minCategory,max);
308 }
308 }
309
309
310 /*!
310 /*!
311 Returns maximum category
311 Returns maximum category
312 */
312 */
313 QString QBarCategoryAxis::max() const
313 QString QBarCategoryAxis::max() const
314 {
314 {
315 Q_D(const QBarCategoryAxis);
315 Q_D(const QBarCategoryAxis);
316 return d->m_maxCategory;
316 return d->m_maxCategory;
317 }
317 }
318
318
319 /*!
319 /*!
320 Sets range from \a minCategory to \a maxCategory
320 Sets range from \a minCategory to \a maxCategory
321 */
321 */
322 void QBarCategoryAxis::setRange(const QString& minCategory, const QString& maxCategory)
322 void QBarCategoryAxis::setRange(const QString& minCategory, const QString& maxCategory)
323 {
323 {
324 Q_D(QBarCategoryAxis);
324 Q_D(QBarCategoryAxis);
325
325
326 bool changed = false;
326 bool changed = false;
327
327
328 //special case
328 //special case
329 if(minCategory.isNull() && maxCategory.isNull()){
329 if(minCategory.isNull() && maxCategory.isNull()){
330 d->m_minCategory = minCategory;
330 d->m_minCategory = minCategory;
331 d->m_maxCategory = maxCategory;
331 d->m_maxCategory = maxCategory;
332 d->m_min = 0;
332 d->m_min = 0;
333 d->m_max = 0;
333 d->m_max = 0;
334 emit minChanged(minCategory);
334 emit minChanged(minCategory);
335 emit maxChanged(maxCategory);
335 emit maxChanged(maxCategory);
336 d->m_count=0;
336 d->m_count=0;
337 emit rangeChanged(d->m_minCategory,d->m_maxCategory);
337 emit rangeChanged(d->m_minCategory,d->m_maxCategory);
338 d->emitUpdated();
338 d->emitUpdated();
339 }
339 }
340
340
341 if(d->m_categories.indexOf(d->m_maxCategory)<d->m_categories.indexOf(d->m_minCategory)) return;
341 if(d->m_categories.indexOf(d->m_maxCategory)<d->m_categories.indexOf(d->m_minCategory)) return;
342
342
343 if (!minCategory.isEmpty() && d->m_minCategory!=minCategory && d->m_categories.contains(minCategory)) {
343 if (!minCategory.isEmpty() && d->m_minCategory!=minCategory && d->m_categories.contains(minCategory)) {
344 d->m_minCategory = minCategory;
344 d->m_minCategory = minCategory;
345 d->m_min = d->m_categories.indexOf(d->m_minCategory) - 0.5;
345 d->m_min = d->m_categories.indexOf(d->m_minCategory) - 0.5;
346 changed = true;
346 changed = true;
347 emit minChanged(minCategory);
347 emit minChanged(minCategory);
348 }
348 }
349
349
350 if (!maxCategory.isEmpty() && d->m_maxCategory!=maxCategory && d->m_categories.contains(maxCategory)) {
350 if (!maxCategory.isEmpty() && d->m_maxCategory!=maxCategory && d->m_categories.contains(maxCategory)) {
351 d->m_maxCategory = maxCategory;
351 d->m_maxCategory = maxCategory;
352 d->m_max = d->m_categories.indexOf(d->m_maxCategory) + 0.5;
352 d->m_max = d->m_categories.indexOf(d->m_maxCategory) + 0.5;
353 changed = true;
353 changed = true;
354 emit maxChanged(maxCategory);
354 emit maxChanged(maxCategory);
355 }
355 }
356
356
357 if (changed) {
357 if (changed) {
358 d->m_count=d->m_max - d->m_min;
358 d->m_count=d->m_max - d->m_min;
359 emit rangeChanged(d->m_minCategory,d->m_maxCategory);
359 emit rangeChanged(d->m_minCategory,d->m_maxCategory);
360 d->emitUpdated();
360 d->emitUpdated();
361 }
361 }
362 }
362 }
363
363
364 /*!
364 /*!
365 Returns the type of the axis
365 Returns the type of the axis
366 */
366 */
367 QAbstractAxis::AxisType QBarCategoryAxis::type() const
367 QAbstractAxis::AxisType QBarCategoryAxis::type() const
368 {
368 {
369 return AxisTypeBarCategory;
369 return AxisTypeBarCategory;
370 }
370 }
371
371
372 //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
372 //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
373
373
374 QBarCategoryAxisPrivate::QBarCategoryAxisPrivate(QBarCategoryAxis* q):
374 QBarCategoryAxisPrivate::QBarCategoryAxisPrivate(QBarCategoryAxis* q):
375 QAbstractAxisPrivate(q),
375 QAbstractAxisPrivate(q),
376 m_min(0.0),
376 m_min(0.0),
377 m_max(0.0),
377 m_max(0.0),
378 m_count(0)
378 m_count(0)
379 {
379 {
380
380
381 }
381 }
382
382
383 QBarCategoryAxisPrivate::~QBarCategoryAxisPrivate()
383 QBarCategoryAxisPrivate::~QBarCategoryAxisPrivate()
384 {
384 {
385
385
386 }
386 }
387
387
388 void QBarCategoryAxisPrivate::setMin(const QVariant &min)
388 void QBarCategoryAxisPrivate::setMin(const QVariant &min)
389 {
389 {
390 setRange(min,m_maxCategory);
390 setRange(min,m_maxCategory);
391 }
391 }
392
392
393 void QBarCategoryAxisPrivate::setMax(const QVariant &max)
393 void QBarCategoryAxisPrivate::setMax(const QVariant &max)
394 {
394 {
395 setRange(m_minCategory,max);
395 setRange(m_minCategory,max);
396 }
396 }
397
397
398 void QBarCategoryAxisPrivate::setRange(const QVariant &min, const QVariant &max)
398 void QBarCategoryAxisPrivate::setRange(const QVariant &min, const QVariant &max)
399 {
399 {
400 Q_Q(QBarCategoryAxis);
400 Q_Q(QBarCategoryAxis);
401 QString value1 = min.toString();
401 QString value1 = min.toString();
402 QString value2 = max.toString();
402 QString value2 = max.toString();
403 q->setRange(value1,value2);
403 q->setRange(value1,value2);
404 }
404 }
405
405
406 void QBarCategoryAxisPrivate::handleDomainUpdated()
406 void QBarCategoryAxisPrivate::handleDomainUpdated()
407 {
407 {
408 Q_Q(QBarCategoryAxis);
408 Q_Q(QBarCategoryAxis);
409 Domain* domain = qobject_cast<Domain*>(sender());
409 Domain* domain = qobject_cast<Domain*>(sender());
410
410
411 if(m_orientation==Qt::Horizontal) {
411 if(m_orientation==Qt::Horizontal) {
412 m_min = domain->minX();
412 m_min = domain->minX();
413 m_max = domain->maxX();
413 m_max = domain->maxX();
414 }
414 }
415 else if(m_orientation==Qt::Vertical) {
415 else if(m_orientation==Qt::Vertical) {
416 m_min = domain->minY();
416 m_min = domain->minY();
417 m_max = domain->maxY();
417 m_max = domain->maxY();
418 }
418 }
419
419
420 bool changed = false;
420 bool changed = false;
421
421
422 int min = m_min + 0.5;
422 int min = m_min + 0.5;
423 if(min>=0 && min<m_categories.count()) {
423 if(min>=0 && min<m_categories.count()) {
424 QString minCategory = m_categories.at(min);
424 QString minCategory = m_categories.at(min);
425 if(m_minCategory!=minCategory && !minCategory.isEmpty()) {
425 if(m_minCategory!=minCategory && !minCategory.isEmpty()) {
426 m_minCategory=minCategory;
426 m_minCategory=minCategory;
427 changed=true;
427 changed=true;
428 emit q->minChanged(minCategory);
428 emit q->minChanged(minCategory);
429 }
429 }
430 }
430 }
431 int max = m_max - 0.5;
431 int max = m_max - 0.5;
432 if(max>=0 && max<m_categories.count()) {
432 if(max>=0 && max<m_categories.count()) {
433 QString maxCategory = m_categories.at(max);
433 QString maxCategory = m_categories.at(max);
434 if(m_maxCategory!=maxCategory && !maxCategory.isEmpty()) {
434 if(m_maxCategory!=maxCategory && !maxCategory.isEmpty()) {
435 m_maxCategory=maxCategory;
435 m_maxCategory=maxCategory;
436 emit q->maxChanged(maxCategory);
436 emit q->maxChanged(maxCategory);
437 }
437 }
438 }
438 }
439
439
440 if (changed) {
440 if (changed) {
441 emit q->rangeChanged(m_minCategory,m_maxCategory);
441 emit q->rangeChanged(m_minCategory,m_maxCategory);
442 }
442 }
443 }
443 }
444
444
445 ChartAxis* QBarCategoryAxisPrivate::createGraphics(ChartPresenter* presenter)
445 ChartAxis* QBarCategoryAxisPrivate::createGraphics(ChartPresenter* presenter)
446 {
446 {
447 Q_Q(QBarCategoryAxis);
447 Q_Q(QBarCategoryAxis);
448 if(m_orientation == Qt::Vertical){
448 if(m_orientation == Qt::Vertical){
449 return new ChartBarCategoryAxisY(q,presenter);
449 return new ChartBarCategoryAxisY(q,presenter);
450 }else{
450 }else{
451 return new ChartBarCategoryAxisX(q,presenter);
451 return new ChartBarCategoryAxisX(q,presenter);
452 }
452 }
453 }
453 }
454
454
455 void QBarCategoryAxisPrivate::intializeDomain(Domain* domain)
455 void QBarCategoryAxisPrivate::intializeDomain(Domain* domain)
456 {
456 {
457
457
458 Q_Q(QBarCategoryAxis);
458 Q_Q(QBarCategoryAxis);
459 if(m_max==m_min) {
459 if(m_max==m_min) {
460 int min;
460 int min;
461 int max;
461 int max;
462 if(m_orientation==Qt::Vertical) {
462 if(m_orientation==Qt::Vertical) {
463 min = domain->minY() + 0.5;
463 min = domain->minY() + 0.5;
464 max = domain->maxY() - 0.5;
464 max = domain->maxY() - 0.5;
465 }
465 }
466 else {
466 else {
467 min = domain->minX() + 0.5;
467 min = domain->minX() + 0.5;
468 max = domain->maxX() - 0.5;
468 max = domain->maxX() - 0.5;
469 }
469 }
470
470
471 if(min>0 && min<m_categories.count() && max>0 && max<m_categories.count())
471 if(min>0 && min<m_categories.count() && max>0 && max<m_categories.count())
472 q->setRange(m_categories.at(min),m_categories.at(max));
472 q->setRange(m_categories.at(min),m_categories.at(max));
473 }
473 }
474 else {
474 else {
475 if(m_orientation==Qt::Vertical) {
475 if(m_orientation==Qt::Vertical) {
476 domain->setRangeY(m_min, m_max);
476 domain->setRangeY(m_min, m_max);
477 }
477 }
478 else {
478 else {
479 domain->setRangeX(m_min, m_max);
479 domain->setRangeX(m_min, m_max);
480 }
480 }
481 }
481 }
482 }
482 }
483
483
484 #include "moc_qbarcategoryaxis.cpp"
484 #include "moc_qbarcategoryaxis.cpp"
485 #include "moc_qbarcategoryaxis_p.cpp"
485 #include "moc_qbarcategoryaxis_p.cpp"
486
486
487 QTCOMMERCIALCHART_END_NAMESPACE
487 QTCOMMERCIALCHART_END_NAMESPACE
@@ -1,79 +1,79
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 QBARCATEGORIESAXIS_H
21 #ifndef QBARCATEGORYAXIS_H
22 #define QBARCATEGORIESAXIS_H
22 #define QBARCATEGORYAXIS_H
23
23
24 #include "qabstractaxis.h"
24 #include "qabstractaxis.h"
25
25
26 QTCOMMERCIALCHART_BEGIN_NAMESPACE
26 QTCOMMERCIALCHART_BEGIN_NAMESPACE
27
27
28 class QBarCategoryAxisPrivate;
28 class QBarCategoryAxisPrivate;
29
29
30 class QTCOMMERCIALCHART_EXPORT QBarCategoryAxis : public QAbstractAxis
30 class QTCOMMERCIALCHART_EXPORT QBarCategoryAxis : public QAbstractAxis
31 {
31 {
32 Q_OBJECT
32 Q_OBJECT
33 Q_PROPERTY(QStringList categories READ categories WRITE setCategories NOTIFY categoriesChanged)
33 Q_PROPERTY(QStringList categories READ categories WRITE setCategories NOTIFY categoriesChanged)
34 Q_PROPERTY(QString min READ min WRITE setMin NOTIFY minChanged)
34 Q_PROPERTY(QString min READ min WRITE setMin NOTIFY minChanged)
35 Q_PROPERTY(QString max READ max WRITE setMax NOTIFY maxChanged)
35 Q_PROPERTY(QString max READ max WRITE setMax NOTIFY maxChanged)
36
36
37 public:
37 public:
38 explicit QBarCategoryAxis(QObject *parent = 0);
38 explicit QBarCategoryAxis(QObject *parent = 0);
39 ~QBarCategoryAxis();
39 ~QBarCategoryAxis();
40
40
41 protected:
41 protected:
42 QBarCategoryAxis(QBarCategoryAxisPrivate &d,QObject *parent = 0);
42 QBarCategoryAxis(QBarCategoryAxisPrivate &d,QObject *parent = 0);
43
43
44 public:
44 public:
45 AxisType type() const;
45 AxisType type() const;
46 void append(const QStringList &categories);
46 void append(const QStringList &categories);
47 void append(const QString &category);
47 void append(const QString &category);
48 void remove(const QString &category);
48 void remove(const QString &category);
49 void insert(int index, const QString &category);
49 void insert(int index, const QString &category);
50 void replace(const QString &oldCategory, const QString &newCategory);
50 void replace(const QString &oldCategory, const QString &newCategory);
51 void clear();
51 void clear();
52 void setCategories(const QStringList &categories);
52 void setCategories(const QStringList &categories);
53 QStringList categories();
53 QStringList categories();
54 int count() const;
54 int count() const;
55 QString at(int index) const;
55 QString at(int index) const;
56
56
57 //range handling
57 //range handling
58 void setMin(const QString& minCategory);
58 void setMin(const QString& minCategory);
59 QString min() const;
59 QString min() const;
60 void setMax(const QString& maxCategory);
60 void setMax(const QString& maxCategory);
61 QString max() const;
61 QString max() const;
62 void setRange(const QString& minCategory, const QString& maxCategory);
62 void setRange(const QString& minCategory, const QString& maxCategory);
63
63
64 Q_SIGNALS:
64 Q_SIGNALS:
65 void categoriesChanged();
65 void categoriesChanged();
66 void minChanged(const QString &min);
66 void minChanged(const QString &min);
67 void maxChanged(const QString &max);
67 void maxChanged(const QString &max);
68 void rangeChanged(const QString &min, const QString &max);
68 void rangeChanged(const QString &min, const QString &max);
69
69
70 private:
70 private:
71 Q_DECLARE_PRIVATE(QBarCategoryAxis)
71 Q_DECLARE_PRIVATE(QBarCategoryAxis)
72 Q_DISABLE_COPY(QBarCategoryAxis)
72 Q_DISABLE_COPY(QBarCategoryAxis)
73 friend class ChartBarCategoryAxisX;
73 friend class ChartBarCategoryAxisX;
74 friend class ChartBarCategoryAxisY;
74 friend class ChartBarCategoryAxisY;
75 };
75 };
76
76
77 QTCOMMERCIALCHART_END_NAMESPACE
77 QTCOMMERCIALCHART_END_NAMESPACE
78
78
79 #endif // QCATEGORIESAXIS_H
79 #endif // QBARCATEGORYAXIS_H
@@ -1,76 +1,76
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 QBARCATEGORIESAXIS_P_H
30 #ifndef QBARCATEGORYAXIS_P_H
31 #define QBARCATEGORIESAXIS_P_H
31 #define QBARCATEGORYAXIS_P_H
32
32
33 #include "qbarcategoryaxis.h"
33 #include "qbarcategoryaxis.h"
34 #include "qabstractaxis_p.h"
34 #include "qabstractaxis_p.h"
35
35
36 QTCOMMERCIALCHART_BEGIN_NAMESPACE
36 QTCOMMERCIALCHART_BEGIN_NAMESPACE
37
37
38 class Domain;
38 class Domain;
39
39
40 class QBarCategoryAxisPrivate : public QAbstractAxisPrivate
40 class QBarCategoryAxisPrivate : public QAbstractAxisPrivate
41 {
41 {
42 Q_OBJECT
42 Q_OBJECT
43
43
44 public:
44 public:
45 QBarCategoryAxisPrivate(QBarCategoryAxis *q);
45 QBarCategoryAxisPrivate(QBarCategoryAxis *q);
46 ~QBarCategoryAxisPrivate();
46 ~QBarCategoryAxisPrivate();
47
47
48 public:
48 public:
49 ChartAxis* createGraphics(ChartPresenter* presenter);
49 ChartAxis* createGraphics(ChartPresenter* presenter);
50 void intializeDomain(Domain* domain);
50 void intializeDomain(Domain* domain);
51 void handleDomainUpdated();
51 void handleDomainUpdated();
52 qreal min() { return m_min;}
52 qreal min() { return m_min;}
53 qreal max() { return m_max;}
53 qreal max() { return m_max;}
54 int count() const { return m_count; }
54 int count() const { return m_count; }
55
55
56 private:
56 private:
57 //range handling
57 //range handling
58 void setMin(const QVariant &min);
58 void setMin(const QVariant &min);
59 void setMax(const QVariant &max);
59 void setMax(const QVariant &max);
60 void setRange(const QVariant &min, const QVariant &max);
60 void setRange(const QVariant &min, const QVariant &max);
61
61
62 private:
62 private:
63 QStringList m_categories;
63 QStringList m_categories;
64 QString m_minCategory;
64 QString m_minCategory;
65 QString m_maxCategory;
65 QString m_maxCategory;
66 qreal m_min;
66 qreal m_min;
67 qreal m_max;
67 qreal m_max;
68 int m_count;
68 int m_count;
69
69
70 private:
70 private:
71 Q_DECLARE_PUBLIC(QBarCategoryAxis);
71 Q_DECLARE_PUBLIC(QBarCategoryAxis);
72 };
72 };
73
73
74 QTCOMMERCIALCHART_END_NAMESPACE
74 QTCOMMERCIALCHART_END_NAMESPACE
75
75
76 #endif // QBARCATEGORIESAXIS_P_H
76 #endif // QBARCATEGORYAXIS_P_H
@@ -1,58 +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 // 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 CHARTINTERVALAXISX_H
30 #ifndef CHARTCATEGORYAXISX_H
31 #define CHARTINTERVALAXISX_H
31 #define CHARTCATEGORYAXISX_H
32
32
33 #include "chartaxis_p.h"
33 #include "chartaxis_p.h"
34
34
35 QTCOMMERCIALCHART_BEGIN_NAMESPACE
35 QTCOMMERCIALCHART_BEGIN_NAMESPACE
36
36
37 class QAbstractAxis;
37 class QAbstractAxis;
38 class ChartPresenter;
38 class ChartPresenter;
39
39
40 class ChartCategoryAxisX : public ChartAxis
40 class ChartCategoryAxisX : public ChartAxis
41 {
41 {
42 public:
42 public:
43 ChartCategoryAxisX(QAbstractAxis *axis, ChartPresenter *presenter);
43 ChartCategoryAxisX(QAbstractAxis *axis, ChartPresenter *presenter);
44 ~ChartCategoryAxisX();
44 ~ChartCategoryAxisX();
45
45
46 AxisType axisType() const { return X_AXIS;}
46 AxisType axisType() const { return X_AXIS;}
47
47
48 protected:
48 protected:
49 QVector<qreal> calculateLayout() const;
49 QVector<qreal> calculateLayout() const;
50 void updateGeometry();
50 void updateGeometry();
51
51
52 Q_SLOTS
52 Q_SLOTS
53 void handleAxisUpdated();
53 void handleAxisUpdated();
54 };
54 };
55
55
56 QTCOMMERCIALCHART_END_NAMESPACE
56 QTCOMMERCIALCHART_END_NAMESPACE
57
57
58 #endif /* CHARTINTERVALAXISX_H */
58 #endif /* CHARTCATEGORYAXISX_H */
@@ -1,58 +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 // 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 CHARTINTERVALAXISY_H
30 #ifndef CHARTCATEGORYAXISY_H
31 #define CHARTINTERVALAXISY_H
31 #define CHARTCATEGORYAXISY_H
32
32
33 #include "chartaxis_p.h"
33 #include "chartaxis_p.h"
34
34
35 QTCOMMERCIALCHART_BEGIN_NAMESPACE
35 QTCOMMERCIALCHART_BEGIN_NAMESPACE
36
36
37 class QAbstractAxis;
37 class QAbstractAxis;
38 class ChartPresenter;
38 class ChartPresenter;
39
39
40 class ChartCategoryAxisY : public ChartAxis
40 class ChartCategoryAxisY : public ChartAxis
41 {
41 {
42 public:
42 public:
43 ChartCategoryAxisY(QAbstractAxis *axis, ChartPresenter *presenter);
43 ChartCategoryAxisY(QAbstractAxis *axis, ChartPresenter *presenter);
44 ~ChartCategoryAxisY();
44 ~ChartCategoryAxisY();
45
45
46 AxisType axisType() const { return Y_AXIS;}
46 AxisType axisType() const { return Y_AXIS;}
47
47
48 protected:
48 protected:
49 QVector<qreal> calculateLayout() const;
49 QVector<qreal> calculateLayout() const;
50 void updateGeometry();
50 void updateGeometry();
51
51
52 Q_SLOTS
52 Q_SLOTS
53 void handleAxisUpdated();
53 void handleAxisUpdated();
54 };
54 };
55
55
56 QTCOMMERCIALCHART_END_NAMESPACE
56 QTCOMMERCIALCHART_END_NAMESPACE
57
57
58 #endif /* CHARTINTERVALAXISY_H */
58 #endif /* CHARTCATEGORYAXISY_H */
@@ -1,301 +1,301
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 "qcategoryaxis.h"
21 #include "qcategoryaxis.h"
22 #include "qcategoryaxis_p.h"
22 #include "qcategoryaxis_p.h"
23 #include "chartcategoryaxisx_p.h"
23 #include "chartcategoryaxisx_p.h"
24 #include "chartcategoryaxisy_p.h"
24 #include "chartcategoryaxisy_p.h"
25 #include <qmath.h>
25 #include <qmath.h>
26 #include <QDebug>
26 #include <QDebug>
27
27
28 QTCOMMERCIALCHART_BEGIN_NAMESPACE
28 QTCOMMERCIALCHART_BEGIN_NAMESPACE
29 /*!
29 /*!
30 \class QCategoryAxis
30 \class QCategoryAxis
31 \brief The QCategoryAxis class allows putting a named ranges on the axis.
31 \brief The QCategoryAxis class allows putting a named ranges on the axis.
32 \mainclass
32 \mainclass
33
33
34 This class can be used when the underlying data needs to be given extra meaning.
34 This class can be used when the underlying data needs to be given extra meaning.
35 Unlike with the QBarCategoryAxis the QCategoryAxis allows the categories ranges widths to be specified freely.
35 Unlike with the QBarCategoryAxis the QCategoryAxis allows the categories ranges widths to be specified freely.
36
36
37 Example code on how to use QCategoryAxis.
37 Example code on how to use QCategoryAxis.
38 \code
38 \code
39 QChartView *chartView = new QChartView;
39 QChartView *chartView = new QChartView;
40 QLineSeries *series = new QLineSeries;
40 QLineSeries *series = new QLineSeries;
41 // ...
41 // ...
42 chartView->chart()->addSeries(series);
42 chartView->chart()->addSeries(series);
43
43
44 QCategoryAxis *axisX = new QCategoryAxis;
44 QCategoryAxis *axisX = new QCategoryAxis;
45 axisX->setStartValue(15);
45 axisX->setStartValue(15);
46 axisX->append("First", 20);
46 axisX->append("First", 20);
47 axisX->append("Second", 37);
47 axisX->append("Second", 37);
48 axisX->append("Third", 52);
48 axisX->append("Third", 52);
49 chartView->chart()->setAxisX(series, axisX);
49 chartView->chart()->setAxisX(series, axisX);
50 \endcode
50 \endcode
51 */
51 */
52 /*!
52 /*!
53 \qmlclass CategoryAxis QCategoryAxis
53 \qmlclass CategoryAxis QCategoryAxis
54 \inherits AbstractAxis
54 \inherits AbstractAxis
55 \brief CategoryAxis allows putting a named ranges on the axis.
55 \brief CategoryAxis allows putting a named ranges on the axis.
56
56
57 For example:
57 For example:
58 \code
58 \code
59 CategoryAxis {
59 CategoryAxis {
60 startValue: 0.0
60 startValue: 0.0
61 CategoryRange { endValue: 1.0; label: "min (0-1)" }
61 CategoryRange { endValue: 1.0; label: "min (0-1)" }
62 CategoryRange { endValue: 3.0; label: "standard (1-3)" }
62 CategoryRange { endValue: 3.0; label: "standard (1-3)" }
63 CategoryRange { endValue: 4.0; label: "high (3-4)" }
63 CategoryRange { endValue: 4.0; label: "high (3-4)" }
64 }
64 }
65 \endcode
65 \endcode
66 */
66 */
67
67
68 /*!
68 /*!
69 \property QCategoryAxis::startValue
69 \property QCategoryAxis::startValue
70 Defines the low end of the first category on the axis.
70 Defines the low end of the first category on the axis.
71 */
71 */
72 /*!
72 /*!
73 \qmlproperty int CategoryAxis::startValue
73 \qmlproperty int CategoryAxis::startValue
74 Defines the low end of the first category on the axis.
74 Defines the low end of the first category on the axis.
75 */
75 */
76
76
77 /*!
77 /*!
78 Constructs an axis object which is a child of \a parent.
78 Constructs an axis object which is a child of \a parent.
79 */
79 */
80 QCategoryAxis::QCategoryAxis(QObject *parent):
80 QCategoryAxis::QCategoryAxis(QObject *parent):
81 QValueAxis(*new QCategoryAxisPrivate(this),parent)
81 QValueAxis(*new QCategoryAxisPrivate(this),parent)
82 {
82 {
83 }
83 }
84
84
85 /*!
85 /*!
86 Destroys the object
86 Destroys the object
87 */
87 */
88 QCategoryAxis::~QCategoryAxis()
88 QCategoryAxis::~QCategoryAxis()
89 {
89 {
90 // Q_D(QValueAxis);
90 // Q_D(QValueAxis);
91 // if(d->m_dataset) {
91 // if(d->m_dataset) {
92 // d->m_dataset->removeAxis(this);
92 // d->m_dataset->removeAxis(this);
93 // }
93 // }
94 }
94 }
95
95
96 /*!
96 /*!
97 \internal
97 \internal
98 */
98 */
99 QCategoryAxis::QCategoryAxis(QCategoryAxisPrivate &d,QObject *parent):QValueAxis(d,parent)
99 QCategoryAxis::QCategoryAxis(QCategoryAxisPrivate &d,QObject *parent):QValueAxis(d,parent)
100 {
100 {
101
101
102 }
102 }
103
103
104 /*!
104 /*!
105 \qmlmethod CategoryAxis::append(string label, real endValue)
105 \qmlmethod CategoryAxis::append(string label, real endValue)
106 Appends new category to the axis with an \a label. Category label has to be unique.
106 Appends new category to the axis with an \a label. Category label has to be unique.
107 Parameter \a endValue specifies the high end limit of the category.
107 Parameter \a endValue specifies the high end limit of the category.
108 It has to be greater than the high end limit of the previous category.
108 It has to be greater than the high end limit of the previous category.
109 Otherwise the method returns without adding a new category.
109 Otherwise the method returns without adding a new category.
110 */
110 */
111 /*!
111 /*!
112 Appends new category to the axis with an \a categoryLabel.
112 Appends new category to the axis with an \a categoryLabel.
113 Category label has to be unique.
113 Category label has to be unique.
114 Parameter \a categoryEndValue specifies the high end limit of the category.
114 Parameter \a categoryEndValue specifies the high end limit of the category.
115 It has to be greater than the high end limit of the previous category.
115 It has to be greater than the high end limit of the previous category.
116 Otherwise the method returns without adding a new category.
116 Otherwise the method returns without adding a new category.
117 */
117 */
118 void QCategoryAxis::append(const QString& categoryLabel, qreal categoryEndValue)
118 void QCategoryAxis::append(const QString& categoryLabel, qreal categoryEndValue)
119 {
119 {
120 Q_D(QCategoryAxis);
120 Q_D(QCategoryAxis);
121
121
122 if (!d->m_categories.contains(categoryLabel))
122 if (!d->m_categories.contains(categoryLabel))
123 {
123 {
124 if(d->m_categories.isEmpty()){
124 if(d->m_categories.isEmpty()){
125 Range range(d->m_categoryMinimum, categoryEndValue);
125 Range range(d->m_categoryMinimum, categoryEndValue);
126 d->m_categoriesMap.insert(categoryLabel, range);
126 d->m_categoriesMap.insert(categoryLabel, range);
127 d->m_categories.append(categoryLabel);
127 d->m_categories.append(categoryLabel);
128 }else if (categoryEndValue > endValue(d->m_categories.last())){
128 }else if (categoryEndValue > endValue(d->m_categories.last())){
129 Range previousRange = d->m_categoriesMap.value(d->m_categories.last());
129 Range previousRange = d->m_categoriesMap.value(d->m_categories.last());
130 d->m_categoriesMap.insert(categoryLabel, Range(previousRange.second, categoryEndValue));
130 d->m_categoriesMap.insert(categoryLabel, Range(previousRange.second, categoryEndValue));
131 d->m_categories.append(categoryLabel);
131 d->m_categories.append(categoryLabel);
132 }
132 }
133 }
133 }
134 }
134 }
135
135
136 /*!
136 /*!
137 Sets \a min to be the low end limit of the first category on the axis.
137 Sets \a min to be the low end limit of the first category on the axis.
138 If there is already some categories added to the axis then passed value must be lower than the high end value of the already defined first category range.
138 If there is already some categories added to the axis then passed value must be lower than the high end value of the already defined first category range.
139 Otherwise nothing is done.
139 Otherwise nothing is done.
140 */
140 */
141 void QCategoryAxis::setStartValue(qreal min)
141 void QCategoryAxis::setStartValue(qreal min)
142 {
142 {
143 Q_D(QCategoryAxis);
143 Q_D(QCategoryAxis);
144 if(d->m_categories.isEmpty()){
144 if(d->m_categories.isEmpty()){
145 d->m_categoryMinimum = min;
145 d->m_categoryMinimum = min;
146 }else{
146 }else{
147 Range range = d->m_categoriesMap.value(d->m_categories.first());
147 Range range = d->m_categoriesMap.value(d->m_categories.first());
148 if (min < range.second)
148 if (min < range.second)
149 d->m_categoriesMap.insert(d->m_categories.first(), Range(min, range.second));
149 d->m_categoriesMap.insert(d->m_categories.first(), Range(min, range.second));
150 }
150 }
151 }
151 }
152
152
153 /*!
153 /*!
154 Returns the low end limit of the category specified by an \a categoryLabel
154 Returns the low end limit of the category specified by an \a categoryLabel
155 */
155 */
156 qreal QCategoryAxis::startValue(const QString& categoryLabel) const
156 qreal QCategoryAxis::startValue(const QString& categoryLabel) const
157 {
157 {
158 Q_D(const QCategoryAxis);
158 Q_D(const QCategoryAxis);
159 if (categoryLabel == QString())
159 if (categoryLabel.isEmpty())
160 return d->m_categoryMinimum;
160 return d->m_categoryMinimum;
161 else
161 else
162 return d->m_categoriesMap.value(categoryLabel).first;
162 return d->m_categoriesMap.value(categoryLabel).first;
163 }
163 }
164
164
165 /*!
165 /*!
166 Returns the high end limit of the interval specified by an \a categoryLabel
166 Returns the high end limit of the interval specified by an \a categoryLabel
167 */
167 */
168 qreal QCategoryAxis::endValue(const QString& categoryLabel) const
168 qreal QCategoryAxis::endValue(const QString& categoryLabel) const
169 {
169 {
170 Q_D(const QCategoryAxis);
170 Q_D(const QCategoryAxis);
171 return d->m_categoriesMap.value(categoryLabel).second;
171 return d->m_categoriesMap.value(categoryLabel).second;
172 }
172 }
173
173
174 /*!
174 /*!
175 \qmlmethod CategoryAxis::remove(string label)
175 \qmlmethod CategoryAxis::remove(string label)
176 Removes a category specified by the \a label from the axis
176 Removes a category specified by the \a label from the axis
177 */
177 */
178 /*!
178 /*!
179 Removes an interval specified by the \a categoryLabel from the axis
179 Removes an interval specified by the \a categoryLabel from the axis
180 */
180 */
181 void QCategoryAxis::remove(const QString &categoryLabel)
181 void QCategoryAxis::remove(const QString &categoryLabel)
182 {
182 {
183 Q_D(QCategoryAxis);
183 Q_D(QCategoryAxis);
184 int labelIndex = d->m_categories.indexOf(categoryLabel);
184 int labelIndex = d->m_categories.indexOf(categoryLabel);
185
185
186 // check if such label exists
186 // check if such label exists
187 if (labelIndex != -1) {
187 if (labelIndex != -1) {
188 d->m_categories.removeAt(labelIndex);
188 d->m_categories.removeAt(labelIndex);
189 d->m_categoriesMap.remove(categoryLabel);
189 d->m_categoriesMap.remove(categoryLabel);
190
190
191 // the range of the interval that follows (if exists) needs to be updated
191 // the range of the interval that follows (if exists) needs to be updated
192 if (labelIndex < d->m_categories.count()) {
192 if (labelIndex < d->m_categories.count()) {
193 QString label = d->m_categories.at(labelIndex);
193 QString label = d->m_categories.at(labelIndex);
194 Range range = d->m_categoriesMap.value(label);
194 Range range = d->m_categoriesMap.value(label);
195
195
196 // set the range
196 // set the range
197 if (labelIndex == 0) {
197 if (labelIndex == 0) {
198 range.first = d->m_categoryMinimum;
198 range.first = d->m_categoryMinimum;
199 d->m_categoriesMap.insert(label, range);
199 d->m_categoriesMap.insert(label, range);
200 } else {
200 } else {
201 range.first = d->m_categoriesMap.value(d->m_categories.at(labelIndex - 1)).second;
201 range.first = d->m_categoriesMap.value(d->m_categories.at(labelIndex - 1)).second;
202 d->m_categoriesMap.insert(label, range);
202 d->m_categoriesMap.insert(label, range);
203 }
203 }
204 }
204 }
205 d->emitUpdated();
205 d->emitUpdated();
206 }
206 }
207 }
207 }
208
208
209 /*!
209 /*!
210 \qmlmethod CategoryAxis::replace(string oldLabel, string newLabel)
210 \qmlmethod CategoryAxis::replace(string oldLabel, string newLabel)
211 Replaces \a oldLabel of an existing category with a \a newLabel.
211 Replaces \a oldLabel of an existing category with a \a newLabel.
212 If the old label does not exist the method returns without making any changes.
212 If the old label does not exist the method returns without making any changes.
213 */
213 */
214 /*!
214 /*!
215 Replaces \a oldLabel of an existing category with a \a newLabel
215 Replaces \a oldLabel of an existing category with a \a newLabel
216 If the old label does not exist the method returns without making any changes.
216 If the old label does not exist the method returns without making any changes.
217 */
217 */
218 void QCategoryAxis::replaceLabel(const QString& oldLabel, const QString& newLabel)
218 void QCategoryAxis::replaceLabel(const QString& oldLabel, const QString& newLabel)
219 {
219 {
220 Q_D(QCategoryAxis);
220 Q_D(QCategoryAxis);
221 int labelIndex = d->m_categories.indexOf(oldLabel);
221 int labelIndex = d->m_categories.indexOf(oldLabel);
222
222
223 // check if such label exists
223 // check if such label exists
224 if (labelIndex != -1) {
224 if (labelIndex != -1) {
225 d->m_categories.replace(labelIndex, newLabel);
225 d->m_categories.replace(labelIndex, newLabel);
226 Range range = d->m_categoriesMap.value(oldLabel);
226 Range range = d->m_categoriesMap.value(oldLabel);
227 d->m_categoriesMap.remove(oldLabel);
227 d->m_categoriesMap.remove(oldLabel);
228 d->m_categoriesMap.insert(newLabel, range);
228 d->m_categoriesMap.insert(newLabel, range);
229 d->emitUpdated();
229 d->emitUpdated();
230 }
230 }
231
231
232 }
232 }
233
233
234 /*!
234 /*!
235 Returns the list of the intervals labels
235 Returns the list of the intervals labels
236 */
236 */
237 QStringList QCategoryAxis::categoriesLabels()
237 QStringList QCategoryAxis::categoriesLabels()
238 {
238 {
239 Q_D(QCategoryAxis);
239 Q_D(QCategoryAxis);
240 return d->m_categories;
240 return d->m_categories;
241 }
241 }
242
242
243 /*!
243 /*!
244 Returns number of intervals.
244 Returns number of intervals.
245 */
245 */
246 int QCategoryAxis::count() const
246 int QCategoryAxis::count() const
247 {
247 {
248 Q_D(const QCategoryAxis);
248 Q_D(const QCategoryAxis);
249 return d->m_categories.count();
249 return d->m_categories.count();
250 }
250 }
251
251
252 /*!
252 /*!
253 Returns the type of the axis
253 Returns the type of the axis
254 */
254 */
255 QAbstractAxis::AxisType QCategoryAxis::type() const
255 QAbstractAxis::AxisType QCategoryAxis::type() const
256 {
256 {
257 return QAbstractAxis::AxisTypeCategory;
257 return QAbstractAxis::AxisTypeCategory;
258 }
258 }
259
259
260 //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
260 //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
261
261
262 QCategoryAxisPrivate::QCategoryAxisPrivate(QCategoryAxis* q):
262 QCategoryAxisPrivate::QCategoryAxisPrivate(QCategoryAxis* q):
263 QValueAxisPrivate(q),
263 QValueAxisPrivate(q),
264 m_categoryMinimum(0)
264 m_categoryMinimum(0)
265 {
265 {
266
266
267 }
267 }
268
268
269 QCategoryAxisPrivate::~QCategoryAxisPrivate()
269 QCategoryAxisPrivate::~QCategoryAxisPrivate()
270 {
270 {
271
271
272 }
272 }
273
273
274 int QCategoryAxisPrivate::ticksCount() const
274 int QCategoryAxisPrivate::ticksCount() const
275 {
275 {
276 return m_categories.count() + 1;
276 return m_categories.count() + 1;
277 }
277 }
278
278
279 void QCategoryAxisPrivate::handleAxisRangeChanged(qreal min, qreal max,int count)
279 void QCategoryAxisPrivate::handleAxisRangeChanged(qreal min, qreal max,int count)
280 {
280 {
281 Q_UNUSED(count);
281 Q_UNUSED(count);
282 Q_UNUSED(min);
282 Q_UNUSED(min);
283 Q_UNUSED(max);
283 Q_UNUSED(max);
284 //m_min = min;
284 //m_min = min;
285 //m_max = max;
285 //m_max = max;
286 }
286 }
287
287
288 ChartAxis* QCategoryAxisPrivate::createGraphics(ChartPresenter* presenter)
288 ChartAxis* QCategoryAxisPrivate::createGraphics(ChartPresenter* presenter)
289 {
289 {
290 Q_Q(QCategoryAxis);
290 Q_Q(QCategoryAxis);
291 if(m_orientation == Qt::Vertical){
291 if(m_orientation == Qt::Vertical){
292 return new ChartCategoryAxisY(q,presenter);
292 return new ChartCategoryAxisY(q,presenter);
293 }else{
293 }else{
294 return new ChartCategoryAxisX(q,presenter);
294 return new ChartCategoryAxisX(q,presenter);
295 }
295 }
296 }
296 }
297
297
298 #include "moc_qcategoryaxis.cpp"
298 #include "moc_qcategoryaxis.cpp"
299 #include "moc_qcategoryaxis_p.cpp"
299 #include "moc_qcategoryaxis_p.cpp"
300
300
301 QTCOMMERCIALCHART_END_NAMESPACE
301 QTCOMMERCIALCHART_END_NAMESPACE
@@ -1,65 +1,65
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 QCATEGORIESAXIS_H
21 #ifndef QCATEGORYAXIS_H
22 #define QCATEGORIESAXIS_H
22 #define QCATEGORYAXIS_H
23
23
24 #include "qabstractaxis.h"
24 #include "qabstractaxis.h"
25 #include "qvalueaxis.h"
25 #include "qvalueaxis.h"
26
26
27 QTCOMMERCIALCHART_BEGIN_NAMESPACE
27 QTCOMMERCIALCHART_BEGIN_NAMESPACE
28
28
29 class QCategoryAxisPrivate;
29 class QCategoryAxisPrivate;
30
30
31 class QTCOMMERCIALCHART_EXPORT QCategoryAxis : public QValueAxis
31 class QTCOMMERCIALCHART_EXPORT QCategoryAxis : public QValueAxis
32 {
32 {
33 Q_OBJECT
33 Q_OBJECT
34 Q_PROPERTY(qreal startValue READ startValue WRITE setStartValue)
34 Q_PROPERTY(qreal startValue READ startValue WRITE setStartValue)
35
35
36 public:
36 public:
37 explicit QCategoryAxis(QObject *parent = 0);
37 explicit QCategoryAxis(QObject *parent = 0);
38 ~QCategoryAxis();
38 ~QCategoryAxis();
39
39
40 protected:
40 protected:
41 QCategoryAxis(QCategoryAxisPrivate &d,QObject *parent = 0);
41 QCategoryAxis(QCategoryAxisPrivate &d,QObject *parent = 0);
42
42
43 public:
43 public:
44 AxisType type() const;
44 AxisType type() const;
45
45
46 void append(const QString& label, qreal categoryEndValue);
46 void append(const QString& label, qreal categoryEndValue);
47 void remove(const QString& label);
47 void remove(const QString& label);
48 void replaceLabel(const QString& oldLabel, const QString& newLabel);
48 void replaceLabel(const QString& oldLabel, const QString& newLabel);
49
49
50 qreal startValue(const QString& categoryLabel = QString()) const;
50 qreal startValue(const QString& categoryLabel = QString()) const;
51 void setStartValue(qreal min);
51 void setStartValue(qreal min);
52
52
53 qreal endValue(const QString& categoryLabel) const;
53 qreal endValue(const QString& categoryLabel) const;
54
54
55 QStringList categoriesLabels();
55 QStringList categoriesLabels();
56 int count() const;
56 int count() const;
57
57
58 private:
58 private:
59 Q_DECLARE_PRIVATE(QCategoryAxis)
59 Q_DECLARE_PRIVATE(QCategoryAxis)
60 Q_DISABLE_COPY(QCategoryAxis)
60 Q_DISABLE_COPY(QCategoryAxis)
61 };
61 };
62
62
63 QTCOMMERCIALCHART_END_NAMESPACE
63 QTCOMMERCIALCHART_END_NAMESPACE
64
64
65 #endif // QCATEGORIESAXIS_H
65 #endif // QCATEGORYAXIS_H
@@ -1,169 +1,169
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 CHARTAXIS_H
30 #ifndef CHARTAXIS_H
31 #define CHARTAXIS_H
31 #define CHARTAXIS_H
32
32
33 #include "qchartglobal.h"
33 #include "qchartglobal.h"
34 #include "chartelement_p.h"
34 #include "chartelement_p.h"
35 #include "axisanimation_p.h"
35 #include "axisanimation_p.h"
36 #include <QGraphicsItem>
36 #include <QGraphicsItem>
37 #include <QFont>
37 #include <QFont>
38
38
39 QTCOMMERCIALCHART_BEGIN_NAMESPACE
39 QTCOMMERCIALCHART_BEGIN_NAMESPACE
40
40
41 class QAbstractAxis;
41 class QAbstractAxis;
42 class ChartPresenter;
42 class ChartPresenter;
43
43
44 class ChartAxis : public ChartElement
44 class ChartAxis : public ChartElement
45 {
45 {
46 Q_OBJECT
46 Q_OBJECT
47 public:
47 public:
48 enum AxisType{ X_AXIS,Y_AXIS };
48 enum AxisType{ X_AXIS,Y_AXIS };
49
49
50 ChartAxis(QAbstractAxis *axis, ChartPresenter *presenter);
50 ChartAxis(QAbstractAxis *axis, ChartPresenter *presenter);
51 ~ChartAxis();
51 ~ChartAxis();
52
52
53 virtual AxisType axisType() const = 0;
53 virtual AxisType axisType() const = 0;
54
54
55 void setArrowOpacity(qreal opacity);
55 void setArrowOpacity(qreal opacity);
56 qreal arrowOpacity() const;
56 qreal arrowOpacity() const;
57 void setArrowVisibility(bool visible);
57 void setArrowVisibility(bool visible);
58
58
59 void setGridOpacity(qreal opacity);
59 void setGridOpacity(qreal opacity);
60 qreal gridOpacity() const;
60 qreal gridOpacity() const;
61 void setGridVisibility(bool visible);
61 void setGridVisibility(bool visible);
62
62
63 void setLabelsOpacity(qreal opacity);
63 void setLabelsOpacity(qreal opacity);
64 qreal labelsOpacity() const;
64 qreal labelsOpacity() const;
65 void setLabelsVisibility(bool visible);
65 void setLabelsVisibility(bool visible);
66
66
67 void setShadesOpacity(qreal opacity);
67 void setShadesOpacity(qreal opacity);
68 qreal shadesOpacity() const;
68 qreal shadesOpacity() const;
69 void setShadesVisibility(bool visible);
69 void setShadesVisibility(bool visible);
70
70
71 void setLabelsAngle(int angle);
71 void setLabelsAngle(int angle);
72 int labelsAngle()const { return m_labelsAngle; }
72 int labelsAngle()const { return m_labelsAngle; }
73
73
74 void setShadesBrush(const QBrush &brush);
74 void setShadesBrush(const QBrush &brush);
75 void setShadesPen(const QPen &pen);
75 void setShadesPen(const QPen &pen);
76
76
77 void setArrowPen(const QPen &pen);
77 void setArrowPen(const QPen &pen);
78 void setGridPen(const QPen &pen);
78 void setGridPen(const QPen &pen);
79
79
80 void setLabelsPen(const QPen &pen);
80 void setLabelsPen(const QPen &pen);
81 void setLabelsBrush(const QBrush &brush);
81 void setLabelsBrush(const QBrush &brush);
82 void setLabelsFont(const QFont &font);
82 void setLabelsFont(const QFont &font);
83
83
84 void setLayout(QVector<qreal> &layout);
84 void setLayout(QVector<qreal> &layout);
85 QVector<qreal> layout() const { return m_layoutVector; }
85 QVector<qreal> layout() const { return m_layoutVector; }
86
86
87 void setAnimation(AxisAnimation* animation);
87 void setAnimation(AxisAnimation* animation);
88 ChartAnimation* animation() const { return m_animation; };
88 ChartAnimation* animation() const { return m_animation; };
89
89
90 QRectF geometry() const { return m_rect; }
90 QRectF geometry() const { return m_rect; }
91
91
92 qreal minimumWidth();
92 qreal minimumWidth();
93 qreal minimumHeight();
93 qreal minimumHeight();
94
94
95 void hide();
95 void hide();
96
96
97 protected:
97 protected:
98 virtual void updateGeometry() = 0;
98 virtual void updateGeometry() = 0;
99 virtual QVector<qreal> calculateLayout() const = 0;
99 virtual QVector<qreal> calculateLayout() const = 0;
100 void createNumberLabels(QStringList &labels,qreal min, qreal max,int ticks) const;
100 void createNumberLabels(QStringList &labels,qreal min, qreal max,int ticks) const;
101 void checkLayout();
101 void checkLayout();
102
102
103 public Q_SLOTS:
103 public Q_SLOTS:
104 virtual void handleAxisUpdated();
104 virtual void handleAxisUpdated();
105 virtual void handleDomainUpdated();
105 virtual void handleDomainUpdated();
106 void handleGeometryChanged(const QRectF &size);
106 void handleGeometryChanged(const QRectF &size);
107
107
108 private:
108 private:
109 inline bool isEmpty();
109 inline bool isEmpty();
110 void createItems(int count);
110 void createItems(int count);
111 void deleteItems(int count);
111 void deleteItems(int count);
112 void updateLayout(QVector<qreal> &layout);
112 void updateLayout(QVector<qreal> &layout);
113 void axisSelected();
113 void axisSelected();
114
114
115 protected:
115 protected:
116 QAbstractAxis* m_chartAxis;
116 QAbstractAxis* m_chartAxis;
117 QRectF m_rect;
117 QRectF m_rect;
118 int m_labelsAngle;
118 int m_labelsAngle;
119 QScopedPointer<QGraphicsItemGroup> m_grid;
119 QScopedPointer<QGraphicsItemGroup> m_grid;
120 QScopedPointer<QGraphicsItemGroup> m_shades;
120 QScopedPointer<QGraphicsItemGroup> m_shades;
121 QScopedPointer<QGraphicsItemGroup> m_labels;
121 QScopedPointer<QGraphicsItemGroup> m_labels;
122 QScopedPointer<QGraphicsItemGroup> m_arrow;
122 QScopedPointer<QGraphicsItemGroup> m_arrow;
123 QVector<qreal> m_layoutVector;
123 QVector<qreal> m_layoutVector;
124 qreal m_min;
124 qreal m_min;
125 qreal m_max;
125 qreal m_max;
126 AxisAnimation *m_animation;
126 AxisAnimation *m_animation;
127 qreal m_minWidth;
127 qreal m_minWidth;
128 qreal m_minHeight;
128 qreal m_minHeight;
129 QFont m_font;
129 QFont m_font;
130
130
131 friend class AxisAnimation;
131 friend class AxisAnimation;
132 friend class AxisItem;
132 friend class AxisItem;
133
133
134 };
134 };
135
135
136 class AxisItem: public QGraphicsLineItem
136 class AxisItem: public QGraphicsLineItem
137 {
137 {
138
138
139 public:
139 public:
140 explicit AxisItem(ChartAxis *axis, QGraphicsItem *parent = 0) : QGraphicsLineItem(parent), m_axis(axis) {}
140 explicit AxisItem(ChartAxis *axis, QGraphicsItem *parent = 0) : QGraphicsLineItem(parent), m_axis(axis) {}
141
141
142 protected:
142 protected:
143 void mousePressEvent(QGraphicsSceneMouseEvent *event)
143 void mousePressEvent(QGraphicsSceneMouseEvent *event)
144 {
144 {
145 Q_UNUSED(event)
145 Q_UNUSED(event)
146 m_axis->axisSelected();
146 m_axis->axisSelected();
147 }
147 }
148
148
149 QRectF boundingRect() const
149 QRectF boundingRect() const
150 {
150 {
151 return shape().boundingRect();
151 return shape().boundingRect();
152 }
152 }
153
153
154 QPainterPath shape() const
154 QPainterPath shape() const
155 {
155 {
156 QPainterPath path = QGraphicsLineItem::shape();
156 QPainterPath path = QGraphicsLineItem::shape();
157 QRectF rect = path.boundingRect();
157 QRectF rect = path.boundingRect();
158 path.addRect(rect.adjusted(0,0,m_axis->axisType()!=ChartAxis::X_AXIS?8:0,m_axis->axisType()!=ChartAxis::Y_AXIS?8:0));
158 path.addRect(rect.adjusted(0,0,m_axis->axisType()!=ChartAxis::X_AXIS?8:0,m_axis->axisType()!=ChartAxis::Y_AXIS?8:0));
159 return path;
159 return path;
160 }
160 }
161
161
162 private:
162 private:
163 ChartAxis* m_axis;
163 ChartAxis* m_axis;
164
164
165 };
165 };
166
166
167 QTCOMMERCIALCHART_END_NAMESPACE
167 QTCOMMERCIALCHART_END_NAMESPACE
168
168
169 #endif /* AXISITEM_H_ */
169 #endif /* CHARTAXI_H */
@@ -1,70 +1,70
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 QVALUESAXIS_P_H
30 #ifndef QDATETIMEAXIS_P_H
31 #define QVALUESAXIS_P_H
31 #define QDATETIMEAXIS_P_H
32
32
33 #include "qdatetimeaxis.h"
33 #include "qdatetimeaxis.h"
34 #include "qabstractaxis_p.h"
34 #include "qabstractaxis_p.h"
35 #include <QDateTime>
35 #include <QDateTime>
36
36
37 QTCOMMERCIALCHART_BEGIN_NAMESPACE
37 QTCOMMERCIALCHART_BEGIN_NAMESPACE
38
38
39 class QDateTimeAxisPrivate : public QAbstractAxisPrivate
39 class QDateTimeAxisPrivate : public QAbstractAxisPrivate
40 {
40 {
41 Q_OBJECT
41 Q_OBJECT
42 public:
42 public:
43 QDateTimeAxisPrivate(QDateTimeAxis *q);
43 QDateTimeAxisPrivate(QDateTimeAxis *q);
44 ~QDateTimeAxisPrivate();
44 ~QDateTimeAxisPrivate();
45
45
46 public:
46 public:
47 ChartAxis* createGraphics(ChartPresenter* presenter);
47 ChartAxis* createGraphics(ChartPresenter* presenter);
48 void intializeDomain(Domain* domain);
48 void intializeDomain(Domain* domain);
49 void handleDomainUpdated();
49 void handleDomainUpdated();
50 qreal min(){ return m_min.toMSecsSinceEpoch(); }
50 qreal min(){ return m_min.toMSecsSinceEpoch(); }
51 qreal max(){ return m_max.toMSecsSinceEpoch(); }
51 qreal max(){ return m_max.toMSecsSinceEpoch(); }
52 int count() const { /*TODO:*/ return 0;}
52 int count() const { /*TODO:*/ return 0;}
53
53
54 protected:
54 protected:
55 void setMin(const QVariant &min);
55 void setMin(const QVariant &min);
56 void setMax(const QVariant &max);
56 void setMax(const QVariant &max);
57 void setRange(const QVariant &min, const QVariant &max);
57 void setRange(const QVariant &min, const QVariant &max);
58 int tickCount() const;
58 int tickCount() const;
59
59
60 protected:
60 protected:
61 QDateTime m_min;
61 QDateTime m_min;
62 QDateTime m_max;
62 QDateTime m_max;
63 int m_tickCount;
63 int m_tickCount;
64 QString m_format;
64 QString m_format;
65 Q_DECLARE_PUBLIC(QDateTimeAxis)
65 Q_DECLARE_PUBLIC(QDateTimeAxis)
66 };
66 };
67
67
68 QTCOMMERCIALCHART_END_NAMESPACE
68 QTCOMMERCIALCHART_END_NAMESPACE
69
69
70 #endif // QVALUESAXIS_P_H
70 #endif // QDATETIMEAXIS_P_H
@@ -1,658 +1,658
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 "qabstractaxis.h"
21 #include "qabstractaxis.h"
22 #include "qabstractaxis_p.h"
22 #include "qabstractaxis_p.h"
23
23
24 QTCOMMERCIALCHART_BEGIN_NAMESPACE
24 QTCOMMERCIALCHART_BEGIN_NAMESPACE
25
25
26 /*!
26 /*!
27 \class QAbstractAxis
27 \class QAbstractAxis
28 \brief The QAbstractAxis class is used for manipulating chart's axis.
28 \brief The QAbstractAxis class is used for manipulating chart's axis.
29 \mainclass
29 \mainclass
30
30
31 There is only one x Axis visible at the time, however there can be multiple y axes.
31 There is only one x Axis visible at the time, however there can be multiple y axes.
32 Each chart series can be bound to exactly one Y axis and the shared common X axis.
32 Each chart series can be bound to exactly one Y axis and the shared common X axis.
33 Axis can be setup to show axis line with tick marks, grid lines and shades.
33 Axis can be setup to show axis line with tick marks, grid lines and shades.
34 */
34 */
35
35
36 /*!
36 /*!
37 \qmlclass AbstractAxis QAbstractAxis
37 \qmlclass AbstractAxis QAbstractAxis
38 \brief The Axis element is used for manipulating chart's axes
38 \brief The Axis element is used for manipulating chart's axes
39
39
40 There is only one x Axis visible at the time, however there can be multiple y axes on a ChartView.
40 There is only one x Axis visible at the time, however there can be multiple y axes on a ChartView.
41 Each chart series can be bound to exactly one Y axis and the shared common X axis.
41 Each chart series can be bound to exactly one Y axis and the shared common X axis.
42 Axis can be setup to show axis line with tick marks, grid lines and shades.
42 Axis can be setup to show axis line with tick marks, grid lines and shades.
43
43
44 To access Axes you can use ChartView API. For example:
44 To access Axes you can use ChartView API. For example:
45 \code
45 \code
46 ChartView {
46 ChartView {
47 axisX.min: 0
47 axisX.min: 0
48 axisX.max: 3
48 axisX.max: 3
49 axisX.ticksCount: 4
49 axisX.ticksCount: 4
50 axisY.min: 0
50 axisY.min: 0
51 axisY.max: 4
51 axisY.max: 4
52 // Add a few series...
52 // Add a few series...
53 }
53 }
54 \endcode
54 \endcode
55 */
55 */
56
56
57 /*!
57 /*!
58 \enum QAbstractAxis::AxisType
58 \enum QAbstractAxis::AxisType
59
59
60 The type of the series object.
60 The type of the series object.
61
61
62 \value AxisTypeNoAxis
62 \value AxisTypeNoAxis
63 \value AxisTypeValue
63 \value AxisTypeValue
64 \value AxisTypeBarCategory
64 \value AxisTypeBarCategory
65 \value AxisTypeCategory
65 \value AxisTypeCategory
66 \value AxisTypeDateTime
66 \value AxisTypeDateTime
67 */
67 */
68
68
69 /*!
69 /*!
70 *\fn void QAbstractAxis::type() const
70 *\fn void QAbstractAxis::type() const
71 Returns the type of the axis
71 Returns the type of the axis
72 */
72 */
73
73
74 /*!
74 /*!
75 \property QAbstractAxis::lineVisible
75 \property QAbstractAxis::lineVisible
76 The visibility of the axis line
76 The visibility of the axis line
77 */
77 */
78 /*!
78 /*!
79 \qmlproperty bool AbstractAxis::lineVisible
79 \qmlproperty bool AbstractAxis::lineVisible
80 The visibility of the axis line
80 The visibility of the axis line
81 */
81 */
82
82
83 /*!
83 /*!
84 \property QAbstractAxis::labelsVisible
84 \property QAbstractAxis::labelsVisible
85 Defines if axis labels are visible.
85 Defines if axis labels are visible.
86 */
86 */
87 /*!
87 /*!
88 \qmlproperty bool AbstractAxis::labelsVisible
88 \qmlproperty bool AbstractAxis::labelsVisible
89 Defines if axis labels are visible.
89 Defines if axis labels are visible.
90 */
90 */
91
91
92 /*!
92 /*!
93 \property QAbstractAxis::visible
93 \property QAbstractAxis::visible
94 The visibility of the axis.
94 The visibility of the axis.
95 */
95 */
96 /*!
96 /*!
97 \qmlproperty bool AbstractAxis::visible
97 \qmlproperty bool AbstractAxis::visible
98 The visibility of the axis.
98 The visibility of the axis.
99 */
99 */
100
100
101 /*!
101 /*!
102 \property QAbstractAxis::gridVisible
102 \property QAbstractAxis::gridVisible
103 The visibility of the grid lines.
103 The visibility of the grid lines.
104 */
104 */
105 /*!
105 /*!
106 \qmlproperty bool AbstractAxis::gridVisible
106 \qmlproperty bool AbstractAxis::gridVisible
107 The visibility of the grid lines.
107 The visibility of the grid lines.
108 */
108 */
109
109
110 /*!
110 /*!
111 \property QAbstractAxis::color
111 \property QAbstractAxis::color
112 The color of the axis and ticks.
112 The color of the axis and ticks.
113 */
113 */
114 /*!
114 /*!
115 \qmlproperty color AbstractAxis::color
115 \qmlproperty color AbstractAxis::color
116 The color of the axis and ticks.
116 The color of the axis and ticks.
117 */
117 */
118
118
119 /*!
119 /*!
120 \property QAbstractAxis::labelsFont
120 \property QAbstractAxis::labelsFont
121 The font of the axis labels.
121 The font of the axis labels.
122 */
122 */
123
123
124 /*!
124 /*!
125 \qmlproperty Font AbstractAxis::labelsFont
125 \qmlproperty Font AbstractAxis::labelsFont
126 The font of the axis labels.
126 The font of the axis labels.
127
127
128 See the \l {Font} {QML Font Element} for detailed documentation.
128 See the \l {Font} {QML Font Element} for detailed documentation.
129 */
129 */
130
130
131 /*!
131 /*!
132 \property QAbstractAxis::labelsColor
132 \property QAbstractAxis::labelsColor
133 The color of the axis labels.
133 The color of the axis labels.
134 */
134 */
135 /*!
135 /*!
136 \qmlproperty color AbstractAxis::labelsColor
136 \qmlproperty color AbstractAxis::labelsColor
137 The color of the axis labels.
137 The color of the axis labels.
138 */
138 */
139
139
140 /*!
140 /*!
141 \property QAbstractAxis::labelsAngle
141 \property QAbstractAxis::labelsAngle
142 The angle of the axis labels in degrees.
142 The angle of the axis labels in degrees.
143 */
143 */
144 /*!
144 /*!
145 \qmlproperty int AbstractAxis::labelsAngle
145 \qmlproperty int AbstractAxis::labelsAngle
146 The angle of the axis labels in degrees.
146 The angle of the axis labels in degrees.
147 */
147 */
148
148
149 /*!
149 /*!
150 \property QAbstractAxis::shadesVisible
150 \property QAbstractAxis::shadesVisible
151 The visibility of the axis shades.
151 The visibility of the axis shades.
152 */
152 */
153 /*!
153 /*!
154 \qmlproperty bool AbstractAxis::shadesVisible
154 \qmlproperty bool AbstractAxis::shadesVisible
155 The visibility of the axis shades.
155 The visibility of the axis shades.
156 */
156 */
157
157
158 /*!
158 /*!
159 \property QAbstractAxis::shadesColor
159 \property QAbstractAxis::shadesColor
160 The fill (brush) color of the axis shades.
160 The fill (brush) color of the axis shades.
161 */
161 */
162 /*!
162 /*!
163 \qmlproperty color AbstractAxis::shadesColor
163 \qmlproperty color AbstractAxis::shadesColor
164 The fill (brush) color of the axis shades.
164 The fill (brush) color of the axis shades.
165 */
165 */
166
166
167 /*!
167 /*!
168 \property QAbstractAxis::shadesBorderColor
168 \property QAbstractAxis::shadesBorderColor
169 The border (pen) color of the axis shades.
169 The border (pen) color of the axis shades.
170 */
170 */
171 /*!
171 /*!
172 \qmlproperty color AbstractAxis::shadesBorderColor
172 \qmlproperty color AbstractAxis::shadesBorderColor
173 The border (pen) color of the axis shades.
173 The border (pen) color of the axis shades.
174 */
174 */
175
175
176 /*!
176 /*!
177 \fn void QAbstractAxis::visibleChanged(bool visible)
177 \fn void QAbstractAxis::visibleChanged(bool visible)
178 Visibility of the axis has changed to \a visible.
178 Visibility of the axis has changed to \a visible.
179 */
179 */
180 /*!
180 /*!
181 \qmlsignal AbstractAxis::onVisibleChanged(bool visible)
181 \qmlsignal AbstractAxis::onVisibleChanged(bool visible)
182 Visibility of the axis has changed to \a visible.
182 Visibility of the axis has changed to \a visible.
183 */
183 */
184
184
185 /*!
185 /*!
186 \fn void QAbstractAxis::lineVisibleChanged(bool visible)
186 \fn void QAbstractAxis::lineVisibleChanged(bool visible)
187 Visibility of the axis line has changed to \a visible.
187 Visibility of the axis line has changed to \a visible.
188 */
188 */
189 /*!
189 /*!
190 \qmlsignal AbstractAxis::onLineVisibleChanged(bool visible)
190 \qmlsignal AbstractAxis::onLineVisibleChanged(bool visible)
191 Visibility of the axis line has changed to \a visible.
191 Visibility of the axis line has changed to \a visible.
192 */
192 */
193
193
194 /*!
194 /*!
195 \fn void QAbstractAxis::labelsVisibleChanged(bool visible)
195 \fn void QAbstractAxis::labelsVisibleChanged(bool visible)
196 Visibility of the labels of the axis has changed to \a visible.
196 Visibility of the labels of the axis has changed to \a visible.
197 */
197 */
198 /*!
198 /*!
199 \qmlsignal AbstractAxis::onLabelsVisibleChanged(bool visible)
199 \qmlsignal AbstractAxis::onLabelsVisibleChanged(bool visible)
200 Visibility of the labels of the axis has changed to \a visible.
200 Visibility of the labels of the axis has changed to \a visible.
201 */
201 */
202
202
203 /*!
203 /*!
204 \fn void QAbstractAxis::gridVisibleChanged(bool visible)
204 \fn void QAbstractAxis::gridVisibleChanged(bool visible)
205 Visibility of the grid lines of the axis has changed to \a visible.
205 Visibility of the grid lines of the axis has changed to \a visible.
206 */
206 */
207 /*!
207 /*!
208 \qmlsignal AbstractAxis::onGridVisibleChanged(bool visible)
208 \qmlsignal AbstractAxis::onGridVisibleChanged(bool visible)
209 Visibility of the grid lines of the axis has changed to \a visible.
209 Visibility of the grid lines of the axis has changed to \a visible.
210 */
210 */
211
211
212 /*!
212 /*!
213 \fn void QAbstractAxis::colorChanged(QColor color)
213 \fn void QAbstractAxis::colorChanged(QColor color)
214 Emitted if the \a color of the axis is changed.
214 Emitted if the \a color of the axis is changed.
215 */
215 */
216 /*!
216 /*!
217 \qmlsignal AbstractAxis::onColorChanged(QColor color)
217 \qmlsignal AbstractAxis::onColorChanged(QColor color)
218 Emitted if the \a color of the axis is changed.
218 Emitted if the \a color of the axis is changed.
219 */
219 */
220
220
221 /*!
221 /*!
222 \fn void QAbstractAxis::labelsColorChanged(QColor color)
222 \fn void QAbstractAxis::labelsColorChanged(QColor color)
223 Emitted if the \a color of the axis labels is changed.
223 Emitted if the \a color of the axis labels is changed.
224 */
224 */
225 /*!
225 /*!
226 \qmlsignal AbstractAxis::onLabelsColorChanged(QColor color)
226 \qmlsignal AbstractAxis::onLabelsColorChanged(QColor color)
227 Emitted if the \a color of the axis labels is changed.
227 Emitted if the \a color of the axis labels is changed.
228 */
228 */
229
229
230 /*!
230 /*!
231 \fn void QAbstractAxis::shadesVisibleChanged(bool)
231 \fn void QAbstractAxis::shadesVisibleChanged(bool)
232 Emitted if the visibility of the axis shades is changed to \a visible.
232 Emitted if the visibility of the axis shades is changed to \a visible.
233 */
233 */
234 /*!
234 /*!
235 \qmlsignal AbstractAxis::onShadesVisibleChanged(bool visible)
235 \qmlsignal AbstractAxis::onShadesVisibleChanged(bool visible)
236 Emitted if the visibility of the axis shades is changed to \a visible.
236 Emitted if the visibility of the axis shades is changed to \a visible.
237 */
237 */
238
238
239 /*!
239 /*!
240 \fn void QAbstractAxis::shadesColorChanged(QColor color)
240 \fn void QAbstractAxis::shadesColorChanged(QColor color)
241 Emitted if the \a color of the axis shades is changed.
241 Emitted if the \a color of the axis shades is changed.
242 */
242 */
243 /*!
243 /*!
244 \qmlsignal AbstractAxis::onShadesColorChanged(QColor color)
244 \qmlsignal AbstractAxis::onShadesColorChanged(QColor color)
245 Emitted if the \a color of the axis shades is changed.
245 Emitted if the \a color of the axis shades is changed.
246 */
246 */
247
247
248 /*!
248 /*!
249 \fn void QAbstractAxis::shadesBorderColorChanged(QColor)
249 \fn void QAbstractAxis::shadesBorderColorChanged(QColor)
250 Emitted if the border \a color of the axis shades is changed.
250 Emitted if the border \a color of the axis shades is changed.
251 */
251 */
252 /*!
252 /*!
253 \qmlsignal AbstractAxis::onBorderColorChanged(QColor color)
253 \qmlsignal AbstractAxis::onBorderColorChanged(QColor color)
254 Emitted if the border \a color of the axis shades is changed.
254 Emitted if the border \a color of the axis shades is changed.
255 */
255 */
256
256
257 /*!
257 /*!
258 \internal
258 \internal
259 Constructs new axis object which is a child of \a parent. Ownership is taken by
259 Constructs new axis object which is a child of \a parent. Ownership is taken by
260 QChart when axis added.
260 QChart when axis added.
261 */
261 */
262
262
263 QAbstractAxis::QAbstractAxis(QAbstractAxisPrivate &d, QObject *parent) :
263 QAbstractAxis::QAbstractAxis(QAbstractAxisPrivate &d, QObject *parent) :
264 QObject(parent),
264 QObject(parent),
265 d_ptr(&d)
265 d_ptr(&d)
266 {
266 {
267 }
267 }
268
268
269 /*!
269 /*!
270 Destructor of the axis object. When axis is added to chart, chart object takes ownership.
270 Destructor of the axis object. When axis is added to chart, chart object takes ownership.
271 */
271 */
272
272
273 QAbstractAxis::~QAbstractAxis()
273 QAbstractAxis::~QAbstractAxis()
274 {
274 {
275 if(d_ptr->m_dataset) qFatal("Still binded axis detected !");
275 if(d_ptr->m_dataset) qFatal("Still binded axis detected !");
276 }
276 }
277
277
278 /*!
278 /*!
279 Sets \a pen used to draw axis line and ticks.
279 Sets \a pen used to draw axis line and ticks.
280 */
280 */
281 void QAbstractAxis::setLinePen(const QPen &pen)
281 void QAbstractAxis::setLinePen(const QPen &pen)
282 {
282 {
283 if (d_ptr->m_axisPen!=pen) {
283 if (d_ptr->m_axisPen!=pen) {
284 d_ptr->m_axisPen = pen;
284 d_ptr->m_axisPen = pen;
285 d_ptr->emitUpdated();
285 d_ptr->emitUpdated();
286 }
286 }
287 }
287 }
288
288
289 /*!
289 /*!
290 Returns pen used to draw axis and ticks.
290 Returns pen used to draw axis and ticks.
291 */
291 */
292 QPen QAbstractAxis::linePen() const
292 QPen QAbstractAxis::linePen() const
293 {
293 {
294 return d_ptr->m_axisPen;
294 return d_ptr->m_axisPen;
295 }
295 }
296
296
297 void QAbstractAxis::setLinePenColor(QColor color)
297 void QAbstractAxis::setLinePenColor(QColor color)
298 {
298 {
299 QPen p = d_ptr->m_axisPen;
299 QPen p = d_ptr->m_axisPen;
300 if (p.color() != color) {
300 if (p.color() != color) {
301 p.setColor(color);
301 p.setColor(color);
302 setLinePen(p);
302 setLinePen(p);
303 emit colorChanged(color);
303 emit colorChanged(color);
304 }
304 }
305 }
305 }
306
306
307 QColor QAbstractAxis::linePenColor() const
307 QColor QAbstractAxis::linePenColor() const
308 {
308 {
309 return d_ptr->m_axisPen.color();
309 return d_ptr->m_axisPen.color();
310 }
310 }
311
311
312 /*!
312 /*!
313 Sets if axis and ticks are \a visible.
313 Sets if axis and ticks are \a visible.
314 */
314 */
315 void QAbstractAxis::setLineVisible(bool visible)
315 void QAbstractAxis::setLineVisible(bool visible)
316 {
316 {
317 if (d_ptr->m_arrowVisible != visible) {
317 if (d_ptr->m_arrowVisible != visible) {
318 d_ptr->m_arrowVisible = visible;
318 d_ptr->m_arrowVisible = visible;
319 d_ptr->emitUpdated();
319 d_ptr->emitUpdated();
320 emit lineVisibleChanged(visible);
320 emit lineVisibleChanged(visible);
321 }
321 }
322 }
322 }
323
323
324 bool QAbstractAxis::isLineVisible() const
324 bool QAbstractAxis::isLineVisible() const
325 {
325 {
326 return d_ptr->m_arrowVisible;
326 return d_ptr->m_arrowVisible;
327 }
327 }
328
328
329 void QAbstractAxis::setGridLineVisible(bool visible)
329 void QAbstractAxis::setGridLineVisible(bool visible)
330 {
330 {
331 if (d_ptr->m_gridLineVisible != visible) {
331 if (d_ptr->m_gridLineVisible != visible) {
332 d_ptr->m_gridLineVisible = visible;
332 d_ptr->m_gridLineVisible = visible;
333 d_ptr->emitUpdated();
333 d_ptr->emitUpdated();
334 emit gridVisibleChanged(visible);
334 emit gridVisibleChanged(visible);
335 }
335 }
336 }
336 }
337
337
338 bool QAbstractAxis::isGridLineVisible() const
338 bool QAbstractAxis::isGridLineVisible() const
339 {
339 {
340 return d_ptr->m_gridLineVisible;
340 return d_ptr->m_gridLineVisible;
341 }
341 }
342
342
343 /*!
343 /*!
344 Sets \a pen used to draw grid line.
344 Sets \a pen used to draw grid line.
345 */
345 */
346 void QAbstractAxis::setGridLinePen(const QPen &pen)
346 void QAbstractAxis::setGridLinePen(const QPen &pen)
347 {
347 {
348 if (d_ptr->m_gridLinePen != pen) {
348 if (d_ptr->m_gridLinePen != pen) {
349 d_ptr->m_gridLinePen = pen;
349 d_ptr->m_gridLinePen = pen;
350 d_ptr->emitUpdated();
350 d_ptr->emitUpdated();
351 }
351 }
352 }
352 }
353
353
354 /*!
354 /*!
355 Returns pen used to draw grid.
355 Returns pen used to draw grid.
356 */
356 */
357 QPen QAbstractAxis::gridLinePen() const
357 QPen QAbstractAxis::gridLinePen() const
358 {
358 {
359 return d_ptr->m_gridLinePen;
359 return d_ptr->m_gridLinePen;
360 }
360 }
361
361
362 void QAbstractAxis::setLabelsVisible(bool visible)
362 void QAbstractAxis::setLabelsVisible(bool visible)
363 {
363 {
364 if (d_ptr->m_labelsVisible != visible) {
364 if (d_ptr->m_labelsVisible != visible) {
365 d_ptr->m_labelsVisible = visible;
365 d_ptr->m_labelsVisible = visible;
366 d_ptr->emitUpdated();
366 d_ptr->emitUpdated();
367 emit labelsVisibleChanged(visible);
367 emit labelsVisibleChanged(visible);
368 }
368 }
369 }
369 }
370
370
371 bool QAbstractAxis::labelsVisible() const
371 bool QAbstractAxis::labelsVisible() const
372 {
372 {
373 return d_ptr->m_labelsVisible;
373 return d_ptr->m_labelsVisible;
374 }
374 }
375
375
376 /*!
376 /*!
377 Sets \a pen used to draw labels.
377 Sets \a pen used to draw labels.
378 */
378 */
379 void QAbstractAxis::setLabelsPen(const QPen &pen)
379 void QAbstractAxis::setLabelsPen(const QPen &pen)
380 {
380 {
381 if (d_ptr->m_labelsPen != pen) {
381 if (d_ptr->m_labelsPen != pen) {
382 d_ptr->m_labelsPen = pen;
382 d_ptr->m_labelsPen = pen;
383 d_ptr->emitUpdated();
383 d_ptr->emitUpdated();
384 }
384 }
385 }
385 }
386
386
387 /*!
387 /*!
388 Returns the pen used to labels.
388 Returns the pen used to labels.
389 */
389 */
390 QPen QAbstractAxis::labelsPen() const
390 QPen QAbstractAxis::labelsPen() const
391 {
391 {
392 return d_ptr->m_labelsPen;
392 return d_ptr->m_labelsPen;
393 }
393 }
394
394
395 /*!
395 /*!
396 Sets \a brush used to draw labels.
396 Sets \a brush used to draw labels.
397 */
397 */
398 void QAbstractAxis::setLabelsBrush(const QBrush &brush)
398 void QAbstractAxis::setLabelsBrush(const QBrush &brush)
399 {
399 {
400 if (d_ptr->m_labelsBrush != brush) {
400 if (d_ptr->m_labelsBrush != brush) {
401 d_ptr->m_labelsBrush = brush;
401 d_ptr->m_labelsBrush = brush;
402 d_ptr->emitUpdated();
402 d_ptr->emitUpdated();
403 }
403 }
404 }
404 }
405
405
406 /*!
406 /*!
407 Returns brush used to draw labels.
407 Returns brush used to draw labels.
408 */
408 */
409 QBrush QAbstractAxis::labelsBrush() const
409 QBrush QAbstractAxis::labelsBrush() const
410 {
410 {
411 return d_ptr->m_labelsBrush;
411 return d_ptr->m_labelsBrush;
412 }
412 }
413
413
414 /*!
414 /*!
415 Sets \a font used to draw labels.
415 Sets \a font used to draw labels.
416 */
416 */
417 void QAbstractAxis::setLabelsFont(const QFont &font)
417 void QAbstractAxis::setLabelsFont(const QFont &font)
418 {
418 {
419 if (d_ptr->m_labelsFont != font) {
419 if (d_ptr->m_labelsFont != font) {
420 d_ptr->m_labelsFont = font;
420 d_ptr->m_labelsFont = font;
421 d_ptr->emitUpdated();
421 d_ptr->emitUpdated();
422 }
422 }
423 }
423 }
424
424
425 /*!
425 /*!
426 Returns font used to draw labels.
426 Returns font used to draw labels.
427 */
427 */
428 QFont QAbstractAxis::labelsFont() const
428 QFont QAbstractAxis::labelsFont() const
429 {
429 {
430 return d_ptr->m_labelsFont;
430 return d_ptr->m_labelsFont;
431 }
431 }
432
432
433 void QAbstractAxis::setLabelsAngle(int angle)
433 void QAbstractAxis::setLabelsAngle(int angle)
434 {
434 {
435 if (d_ptr->m_labelsAngle != angle) {
435 if (d_ptr->m_labelsAngle != angle) {
436 d_ptr->m_labelsAngle = angle;
436 d_ptr->m_labelsAngle = angle;
437 d_ptr->emitUpdated();
437 d_ptr->emitUpdated();
438 }
438 }
439 }
439 }
440
440
441 int QAbstractAxis::labelsAngle() const
441 int QAbstractAxis::labelsAngle() const
442 {
442 {
443 return d_ptr->m_labelsAngle;
443 return d_ptr->m_labelsAngle;
444 }
444 }
445
445
446 void QAbstractAxis::setLabelsColor(QColor color)
446 void QAbstractAxis::setLabelsColor(QColor color)
447 {
447 {
448 QBrush b = d_ptr->m_labelsBrush;
448 QBrush b = d_ptr->m_labelsBrush;
449 if (b.color() != color) {
449 if (b.color() != color) {
450 b.setColor(color);
450 b.setColor(color);
451 setLabelsBrush(b);
451 setLabelsBrush(b);
452 emit labelsColorChanged(color);
452 emit labelsColorChanged(color);
453 }
453 }
454 }
454 }
455
455
456 QColor QAbstractAxis::labelsColor() const
456 QColor QAbstractAxis::labelsColor() const
457 {
457 {
458 return d_ptr->m_labelsBrush.color();
458 return d_ptr->m_labelsBrush.color();
459 }
459 }
460
460
461 void QAbstractAxis::setShadesVisible(bool visible)
461 void QAbstractAxis::setShadesVisible(bool visible)
462 {
462 {
463 if (d_ptr->m_shadesVisible != visible) {
463 if (d_ptr->m_shadesVisible != visible) {
464 d_ptr->m_shadesVisible = visible;
464 d_ptr->m_shadesVisible = visible;
465 d_ptr->emitUpdated();
465 d_ptr->emitUpdated();
466 emit shadesVisibleChanged(visible);
466 emit shadesVisibleChanged(visible);
467 }
467 }
468 }
468 }
469
469
470 bool QAbstractAxis::shadesVisible() const
470 bool QAbstractAxis::shadesVisible() const
471 {
471 {
472 return d_ptr->m_shadesVisible;
472 return d_ptr->m_shadesVisible;
473 }
473 }
474
474
475 /*!
475 /*!
476 Sets \a pen used to draw shades.
476 Sets \a pen used to draw shades.
477 */
477 */
478 void QAbstractAxis::setShadesPen(const QPen &pen)
478 void QAbstractAxis::setShadesPen(const QPen &pen)
479 {
479 {
480 if (d_ptr->m_shadesPen != pen) {
480 if (d_ptr->m_shadesPen != pen) {
481 d_ptr->m_shadesPen = pen;
481 d_ptr->m_shadesPen = pen;
482 d_ptr->emitUpdated();
482 d_ptr->emitUpdated();
483 }
483 }
484 }
484 }
485
485
486 /*!
486 /*!
487 Returns pen used to draw shades.
487 Returns pen used to draw shades.
488 */
488 */
489 QPen QAbstractAxis::shadesPen() const
489 QPen QAbstractAxis::shadesPen() const
490 {
490 {
491 return d_ptr->m_shadesPen;
491 return d_ptr->m_shadesPen;
492 }
492 }
493
493
494 /*!
494 /*!
495 Sets \a brush used to draw shades.
495 Sets \a brush used to draw shades.
496 */
496 */
497 void QAbstractAxis::setShadesBrush(const QBrush &brush)
497 void QAbstractAxis::setShadesBrush(const QBrush &brush)
498 {
498 {
499 if (d_ptr->m_shadesBrush != brush) {
499 if (d_ptr->m_shadesBrush != brush) {
500 d_ptr->m_shadesBrush = brush;
500 d_ptr->m_shadesBrush = brush;
501 d_ptr->emitUpdated();
501 d_ptr->emitUpdated();
502 emit shadesColorChanged(brush.color());
502 emit shadesColorChanged(brush.color());
503 }
503 }
504 }
504 }
505
505
506 /*!
506 /*!
507 Returns brush used to draw shades.
507 Returns brush used to draw shades.
508 */
508 */
509 QBrush QAbstractAxis::shadesBrush() const
509 QBrush QAbstractAxis::shadesBrush() const
510 {
510 {
511 return d_ptr->m_shadesBrush;
511 return d_ptr->m_shadesBrush;
512 }
512 }
513
513
514 void QAbstractAxis::setShadesColor(QColor color)
514 void QAbstractAxis::setShadesColor(QColor color)
515 {
515 {
516 QBrush b = d_ptr->m_shadesBrush;
516 QBrush b = d_ptr->m_shadesBrush;
517 b.setColor(color);
517 b.setColor(color);
518 setShadesBrush(b);
518 setShadesBrush(b);
519 }
519 }
520
520
521 QColor QAbstractAxis::shadesColor() const
521 QColor QAbstractAxis::shadesColor() const
522 {
522 {
523 return d_ptr->m_shadesBrush.color();
523 return d_ptr->m_shadesBrush.color();
524 }
524 }
525
525
526 void QAbstractAxis::setShadesBorderColor(QColor color)
526 void QAbstractAxis::setShadesBorderColor(QColor color)
527 {
527 {
528 QPen p = d_ptr->m_shadesPen;
528 QPen p = d_ptr->m_shadesPen;
529 p.setColor(color);
529 p.setColor(color);
530 setShadesPen(p);
530 setShadesPen(p);
531 }
531 }
532
532
533 QColor QAbstractAxis::shadesBorderColor() const
533 QColor QAbstractAxis::shadesBorderColor() const
534 {
534 {
535 return d_ptr->m_shadesPen.color();
535 return d_ptr->m_shadesPen.color();
536 }
536 }
537
537
538
538
539 bool QAbstractAxis::isVisible() const
539 bool QAbstractAxis::isVisible() const
540 {
540 {
541 return d_ptr->m_visible;
541 return d_ptr->m_visible;
542 }
542 }
543
543
544 /*!
544 /*!
545 Sets axis, shades, labels and grid lines to be visible.
545 Sets axis, shades, labels and grid lines to be visible.
546 */
546 */
547 void QAbstractAxis::setVisible(bool visible)
547 void QAbstractAxis::setVisible(bool visible)
548 {
548 {
549 if(d_ptr->m_visible!=visible){
549 if(d_ptr->m_visible!=visible){
550 d_ptr->m_visible=visible;
550 d_ptr->m_visible=visible;
551 d_ptr->emitUpdated();
551 d_ptr->emitUpdated();
552 emit visibleChanged(visible);
552 emit visibleChanged(visible);
553 }
553 }
554 }
554 }
555
555
556
556
557 /*!
557 /*!
558 Sets axis, shades, labels and grid lines to be visible.
558 Sets axis, shades, labels and grid lines to be visible.
559 */
559 */
560 void QAbstractAxis::show()
560 void QAbstractAxis::show()
561 {
561 {
562 setVisible(true);
562 setVisible(true);
563 }
563 }
564
564
565 /*!
565 /*!
566 Sets axis, shades, labels and grid lines to not be visible.
566 Sets axis, shades, labels and grid lines to not be visible.
567 */
567 */
568 void QAbstractAxis::hide()
568 void QAbstractAxis::hide()
569 {
569 {
570 setVisible(false);
570 setVisible(false);
571 }
571 }
572
572
573 /*!
573 /*!
574 Sets the minimum value shown on the axis.
574 Sets the minimum value shown on the axis.
575 Depending on the actual axis type the \a min paramter is converted to appropriate type.
575 Depending on the actual axis type the \a min parameter is converted to appropriate type.
576 If the conversion is impossible then the function call does nothing
576 If the conversion is impossible then the function call does nothing
577 */
577 */
578 void QAbstractAxis::setMin(const QVariant &min)
578 void QAbstractAxis::setMin(const QVariant &min)
579 {
579 {
580 d_ptr->setMin(min);
580 d_ptr->setMin(min);
581 }
581 }
582
582
583 /*!
583 /*!
584 Sets the maximum value shown on the axis.
584 Sets the maximum value shown on the axis.
585 Depending on the actual axis type the \a max paramter is converted to appropriate type.
585 Depending on the actual axis type the \a max parameter is converted to appropriate type.
586 If the conversion is impossible then the function call does nothing
586 If the conversion is impossible then the function call does nothing
587 */
587 */
588 void QAbstractAxis::setMax(const QVariant &max)
588 void QAbstractAxis::setMax(const QVariant &max)
589 {
589 {
590 d_ptr->setMax(max);
590 d_ptr->setMax(max);
591 }
591 }
592
592
593 /*!
593 /*!
594 Sets the range shown on the axis.
594 Sets the range shown on the axis.
595 Depending on the actual axis type the \a min and \a max paramters are converted to appropriate types.
595 Depending on the actual axis type the \a min and \a max parameters are converted to appropriate types.
596 If the conversion is impossible then the function call does nothing.
596 If the conversion is impossible then the function call does nothing.
597 */
597 */
598 void QAbstractAxis::setRange(const QVariant &min, const QVariant &max)
598 void QAbstractAxis::setRange(const QVariant &min, const QVariant &max)
599 {
599 {
600 d_ptr->setRange(min,max);
600 d_ptr->setRange(min,max);
601 }
601 }
602
602
603
603
604 /*!
604 /*!
605 Returns the orientation in which the axis is being used (Vertical or Horizontal)
605 Returns the orientation in which the axis is being used (Vertical or Horizontal)
606 */
606 */
607 Qt::Orientation QAbstractAxis::orientation()
607 Qt::Orientation QAbstractAxis::orientation()
608 {
608 {
609 return d_ptr->m_orientation;
609 return d_ptr->m_orientation;
610 }
610 }
611
611
612 /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
612 /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
613
613
614 QAbstractAxisPrivate::QAbstractAxisPrivate(QAbstractAxis* q):
614 QAbstractAxisPrivate::QAbstractAxisPrivate(QAbstractAxis* q):
615 q_ptr(q),
615 q_ptr(q),
616 m_orientation(Qt::Orientation(0)),
616 m_orientation(Qt::Orientation(0)),
617 m_dataset(0),
617 m_dataset(0),
618 m_visible(false),
618 m_visible(false),
619 m_arrowVisible(true),
619 m_arrowVisible(true),
620 m_gridLineVisible(true),
620 m_gridLineVisible(true),
621 m_labelsVisible(true),
621 m_labelsVisible(true),
622 m_labelsAngle(0),
622 m_labelsAngle(0),
623 m_shadesVisible(false),
623 m_shadesVisible(false),
624 m_shadesBrush(Qt::SolidPattern),
624 m_shadesBrush(Qt::SolidPattern),
625 m_shadesOpacity(1.0),
625 m_shadesOpacity(1.0),
626 m_dirty(false)
626 m_dirty(false)
627 {
627 {
628
628
629 }
629 }
630
630
631 QAbstractAxisPrivate::~QAbstractAxisPrivate()
631 QAbstractAxisPrivate::~QAbstractAxisPrivate()
632 {
632 {
633
633
634 }
634 }
635
635
636 void QAbstractAxisPrivate::emitUpdated()
636 void QAbstractAxisPrivate::emitUpdated()
637 {
637 {
638 if(!m_dirty){
638 if(!m_dirty){
639 m_dirty=true;
639 m_dirty=true;
640 emit updated();
640 emit updated();
641 }
641 }
642 }
642 }
643
643
644 void QAbstractAxisPrivate::setDirty(bool dirty)
644 void QAbstractAxisPrivate::setDirty(bool dirty)
645 {
645 {
646 m_dirty=dirty;
646 m_dirty=dirty;
647 }
647 }
648
648
649 void QAbstractAxisPrivate::setOrientation(Qt::Orientation orientation)
649 void QAbstractAxisPrivate::setOrientation(Qt::Orientation orientation)
650 {
650 {
651 m_orientation=orientation;
651 m_orientation=orientation;
652 }
652 }
653
653
654
654
655 #include "moc_qabstractaxis.cpp"
655 #include "moc_qabstractaxis.cpp"
656 #include "moc_qabstractaxis_p.cpp"
656 #include "moc_qabstractaxis_p.cpp"
657
657
658 QTCOMMERCIALCHART_END_NAMESPACE
658 QTCOMMERCIALCHART_END_NAMESPACE
@@ -1,60 +1,60
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 CHARTVALUESAXISX_H
30 #ifndef CHARTVALUEAXISX_H
31 #define CHARTVALUESAXISX_H
31 #define CHARTVALUEAXISX_H
32
32
33 #include "chartaxis_p.h"
33 #include "chartaxis_p.h"
34
34
35 QTCOMMERCIALCHART_BEGIN_NAMESPACE
35 QTCOMMERCIALCHART_BEGIN_NAMESPACE
36
36
37 class QAbstractAxis;
37 class QAbstractAxis;
38 class ChartPresenter;
38 class ChartPresenter;
39
39
40 class ChartValueAxisX : public ChartAxis
40 class ChartValueAxisX : public ChartAxis
41 {
41 {
42 public:
42 public:
43 ChartValueAxisX(QAbstractAxis *axis, ChartPresenter *presenter);
43 ChartValueAxisX(QAbstractAxis *axis, ChartPresenter *presenter);
44 ~ChartValueAxisX();
44 ~ChartValueAxisX();
45
45
46 AxisType axisType() const { return X_AXIS;}
46 AxisType axisType() const { return X_AXIS;}
47
47
48 protected:
48 protected:
49 void handleAxisUpdated();
49 void handleAxisUpdated();
50 QVector<qreal> calculateLayout() const;
50 QVector<qreal> calculateLayout() const;
51 void updateGeometry();
51 void updateGeometry();
52
52
53 private:
53 private:
54 int m_tickCount;
54 int m_tickCount;
55
55
56 };
56 };
57
57
58 QTCOMMERCIALCHART_END_NAMESPACE
58 QTCOMMERCIALCHART_END_NAMESPACE
59
59
60 #endif /* CHARTVALUESAXISX_H */
60 #endif /* CHARTVALUEAXISX_H */
@@ -1,58 +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 // 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 CHARTVALUESAXISY_H
30 #ifndef CHARTVALUEAXISY_H
31 #define CHARTVALUESAXISY_H
31 #define CHARTVALUEAXISY_H
32
32
33 #include "chartaxis_p.h"
33 #include "chartaxis_p.h"
34
34
35 QTCOMMERCIALCHART_BEGIN_NAMESPACE
35 QTCOMMERCIALCHART_BEGIN_NAMESPACE
36
36
37 class QAbstractAxis;
37 class QAbstractAxis;
38 class ChartPresenter;
38 class ChartPresenter;
39
39
40 class ChartValueAxisY : public ChartAxis
40 class ChartValueAxisY : public ChartAxis
41 {
41 {
42 public:
42 public:
43 ChartValueAxisY(QAbstractAxis *axis, ChartPresenter *presenter);
43 ChartValueAxisY(QAbstractAxis *axis, ChartPresenter *presenter);
44 ~ChartValueAxisY();
44 ~ChartValueAxisY();
45
45
46 AxisType axisType() const { return Y_AXIS;}
46 AxisType axisType() const { return Y_AXIS;}
47
47
48 protected:
48 protected:
49 QVector<qreal> calculateLayout() const;
49 QVector<qreal> calculateLayout() const;
50 void updateGeometry();
50 void updateGeometry();
51 void handleAxisUpdated();
51 void handleAxisUpdated();
52 private:
52 private:
53 int m_tickCount;
53 int m_tickCount;
54 };
54 };
55
55
56 QTCOMMERCIALCHART_END_NAMESPACE
56 QTCOMMERCIALCHART_END_NAMESPACE
57
57
58 #endif /* CHARTVALUESAXISY_H */
58 #endif /* CHARTVALUEAXISY_H */
@@ -1,423 +1,422
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 "qvalueaxis.h"
21 #include "qvalueaxis.h"
22 #include "qvalueaxis_p.h"
22 #include "qvalueaxis_p.h"
23 #include "chartvalueaxisx_p.h"
23 #include "chartvalueaxisx_p.h"
24 #include "chartvalueaxisy_p.h"
24 #include "chartvalueaxisy_p.h"
25 #include "domain_p.h"
25 #include "domain_p.h"
26 #include "chartdataset_p.h"
26 #include "chartdataset_p.h"
27 #include <qmath.h>
27 #include <qmath.h>
28
28
29
29
30 QTCOMMERCIALCHART_BEGIN_NAMESPACE
30 QTCOMMERCIALCHART_BEGIN_NAMESPACE
31 /*!
31 /*!
32 \class QValueAxis
32 \class QValueAxis
33 \brief The QValueAxis class is used for manipulating chart's axis.
33 \brief The QValueAxis class is used for manipulating chart's axis.
34 \mainclass
34 \mainclass
35
35
36 ValueAxis can be setup to show axis line with tick marks, grid lines and shades.
36 ValueAxis can be setup to show axis line with tick marks, grid lines and shades.
37 Values of axis are drawn to position of ticks.
37 Values of axis are drawn to position of ticks.
38
38
39 Example code on how to use QValueAxis.
39 Example code on how to use QValueAxis.
40 \code
40 \code
41 QChartView *chartView = new QChartView;
41 QChartView *chartView = new QChartView;
42 QLineSeries *series = new QLineSeries;
42 QLineSeries *series = new QLineSeries;
43 // ...
43 // ...
44 chartView->chart()->addSeries(series);
44 chartView->chart()->addSeries(series);
45
45
46 QValueAxis *axisX = new QValueAxis;
46 QValueAxis *axisX = new QValueAxis;
47 axisX->setRange(10, 20.5);
47 axisX->setRange(10, 20.5);
48 axisX->setTickCount(10);
48 axisX->setTickCount(10);
49 axisX->setLabelFormat("%.2f");
49 axisX->setLabelFormat("%.2f");
50 chartView->chart()->setAxisX(series, axisX);
50 chartView->chart()->setAxisX(series, axisX);
51 \endcode
51 \endcode
52 */
52 */
53
53
54 /*!
54 /*!
55 \qmlclass ValueAxis QValueAxis
55 \qmlclass ValueAxis QValueAxis
56 \inherits AbstractAxis
56 \inherits AbstractAxis
57 \brief The ValueAxis element is used for manipulating chart's axes
57 \brief The ValueAxis element is used for manipulating chart's axes
58
58
59 ValueAxis can be setup to show axis line with tick marks, grid lines and shades.
59 ValueAxis can be setup to show axis line with tick marks, grid lines and shades.
60 Values of axis are drawn to position of ticks
60 Values of axis are drawn to position of ticks
61
61
62 To access Axes you can use ChartView API. For example:
62 To access Axes you can use ChartView API. For example:
63 \code
63 \code
64 ChartView {
64 ChartView {
65 ValueAxis {
65 ValueAxis {
66 id: xAxis
66 id: xAxis
67 min: 0
67 min: 0
68 max: 10
68 max: 10
69 }
69 }
70 // Add a few series...
70 // Add a few series...
71 }
71 }
72 \endcode
72 \endcode
73 */
73 */
74
74
75 /*!
75 /*!
76 \property QValueAxis::min
76 \property QValueAxis::min
77 Defines the minimum value on the axis.
77 Defines the minimum value on the axis.
78 When setting this property the max is adjusted if necessary, to ensure that the range remains valid.
78 When setting this property the max is adjusted if necessary, to ensure that the range remains valid.
79 */
79 */
80 /*!
80 /*!
81 \qmlproperty real ValueAxis::min
81 \qmlproperty real ValueAxis::min
82 Defines the minimum value on the axis.
82 Defines the minimum value on the axis.
83 When setting this property the max is adjusted if necessary, to ensure that the range remains valid.
83 When setting this property the max is adjusted if necessary, to ensure that the range remains valid.
84 */
84 */
85
85
86 /*!
86 /*!
87 \property QValueAxis::max
87 \property QValueAxis::max
88 Defines the maximum value on the axis.
88 Defines the maximum value on the axis.
89 When setting this property the min is adjusted if necessary, to ensure that the range remains valid.
89 When setting this property the min is adjusted if necessary, to ensure that the range remains valid.
90 */
90 */
91 /*!
91 /*!
92 \qmlproperty real ValueAxis::max
92 \qmlproperty real ValueAxis::max
93 Defines the maximum value on the axis.
93 Defines the maximum value on the axis.
94 When setting this property the min is adjusted if necessary, to ensure that the range remains valid.
94 When setting this property the min is adjusted if necessary, to ensure that the range remains valid.
95 */
95 */
96
96
97 /*!
97 /*!
98 \property QValueAxis::labelFormat
98 \property QValueAxis::labelFormat
99 Defines the label format for the axis.
99 Defines the label format for the axis.
100 See QString::sprintf() for the details.
100 See QString::sprintf() for the details.
101 */
101 */
102 /*!
102 /*!
103 \qmlproperty real ValueAxis::labelFormat
103 \qmlproperty real ValueAxis::labelFormat
104 Defines the label format for the axis.
104 Defines the label format for the axis.
105 See QString::sprintf() for the details.
105 See QString::sprintf() for the details.
106 */
106 */
107
107
108 /*!
108 /*!
109 \fn void QValueAxis::minChanged(qreal min)
109 \fn void QValueAxis::minChanged(qreal min)
110 Axis emits signal when \a min of axis has changed.
110 Axis emits signal when \a min of axis has changed.
111 */
111 */
112 /*!
112 /*!
113 \qmlsignal ValueAxis::onMinChanged(real min)
113 \qmlsignal ValueAxis::onMinChanged(real min)
114 Axis emits signal when \a min of axis has changed.
114 Axis emits signal when \a min of axis has changed.
115 */
115 */
116
116
117 /*!
117 /*!
118 \fn void QValueAxis::maxChanged(qreal max)
118 \fn void QValueAxis::maxChanged(qreal max)
119 Axis emits signal when \a max of axis has changed.
119 Axis emits signal when \a max of axis has changed.
120 */
120 */
121 /*!
121 /*!
122 \qmlsignal ValueAxis::onMaxChanged(real max)
122 \qmlsignal ValueAxis::onMaxChanged(real max)
123 Axis emits signal when \a max of axis has changed.
123 Axis emits signal when \a max of axis has changed.
124 */
124 */
125
125
126 /*!
126 /*!
127 \fn void QValueAxis::rangeChanged(qreal min, qreal max)
127 \fn void QValueAxis::rangeChanged(qreal min, qreal max)
128 Axis emits signal when \a min or \a max of axis has changed.
128 Axis emits signal when \a min or \a max of axis has changed.
129 */
129 */
130
130
131 /*!
131 /*!
132 \property QValueAxis::tickCount
132 \property QValueAxis::tickCount
133 The number of tick marks for the axis.
133 The number of tick marks for the axis.
134 */
134 */
135
135
136 /*!
136 /*!
137 \qmlproperty int ValueAxis::tickCount
137 \qmlproperty int ValueAxis::tickCount
138 The number of tick marks for the axis.
138 The number of tick marks for the axis.
139 */
139 */
140
140
141 /*!
141 /*!
142 \property QValueAxis::niceNumbersEnabled
142 \property QValueAxis::niceNumbersEnabled
143 Whether the nice numbers algorithm is enabled or not for the axis.
143 Whether the nice numbers algorithm is enabled or not for the axis.
144 */
144 */
145
145
146 /*!
146 /*!
147 \qmlproperty bool ValueAxis::niceNumbersEnabled
147 \qmlproperty bool ValueAxis::niceNumbersEnabled
148 Whether the nice numbers algorithm is enabled or not for the axis.
148 Whether the nice numbers algorithm is enabled or not for the axis.
149 */
149 */
150
150
151 /*!
151 /*!
152 Constructs an axis object which is a child of \a parent.
152 Constructs an axis object which is a child of \a parent.
153 */
153 */
154 QValueAxis::QValueAxis(QObject *parent) :
154 QValueAxis::QValueAxis(QObject *parent) :
155 QAbstractAxis(*new QValueAxisPrivate(this),parent)
155 QAbstractAxis(*new QValueAxisPrivate(this),parent)
156 {
156 {
157
157
158 }
158 }
159
159
160 /*!
160 /*!
161 \internal
161 \internal
162 */
162 */
163 QValueAxis::QValueAxis(QValueAxisPrivate &d,QObject *parent) : QAbstractAxis(d,parent)
163 QValueAxis::QValueAxis(QValueAxisPrivate &d,QObject *parent) : QAbstractAxis(d,parent)
164 {
164 {
165
165
166 }
166 }
167
167
168 /*!
168 /*!
169 Destroys the object
169 Destroys the object
170 */
170 */
171 QValueAxis::~QValueAxis()
171 QValueAxis::~QValueAxis()
172 {
172 {
173 Q_D(QValueAxis);
173 Q_D(QValueAxis);
174 if(d->m_dataset) {
174 if(d->m_dataset) {
175 d->m_dataset->removeAxis(this);
175 d->m_dataset->removeAxis(this);
176 }
176 }
177 }
177 }
178
178
179 void QValueAxis::setMin(qreal min)
179 void QValueAxis::setMin(qreal min)
180 {
180 {
181 Q_D(QValueAxis);
181 Q_D(QValueAxis);
182 setRange(min, qMax(d->m_max, min));
182 setRange(min, qMax(d->m_max, min));
183 }
183 }
184
184
185 qreal QValueAxis::min() const
185 qreal QValueAxis::min() const
186 {
186 {
187 Q_D(const QValueAxis);
187 Q_D(const QValueAxis);
188 return d->m_min;
188 return d->m_min;
189 }
189 }
190
190
191 void QValueAxis::setMax(qreal max)
191 void QValueAxis::setMax(qreal max)
192 {
192 {
193 Q_D(QValueAxis);
193 Q_D(QValueAxis);
194 setRange(qMin(d->m_min, max), max);
194 setRange(qMin(d->m_min, max), max);
195 }
195 }
196
196
197 qreal QValueAxis::max() const
197 qreal QValueAxis::max() const
198 {
198 {
199 Q_D(const QValueAxis);
199 Q_D(const QValueAxis);
200 return d->m_max;
200 return d->m_max;
201 }
201 }
202
202
203 /*!
203 /*!
204 Sets range from \a min to \a max on the axis.
204 Sets range from \a min to \a max on the axis.
205 If min is greater than max then this function returns without making any changes.
205 If min is greater than max then this function returns without making any changes.
206 */
206 */
207 void QValueAxis::setRange(qreal min, qreal max)
207 void QValueAxis::setRange(qreal min, qreal max)
208 {
208 {
209 Q_D(QValueAxis);
209 Q_D(QValueAxis);
210 bool changed = false;
210 bool changed = false;
211
211
212 if (min > max) return;
212 if (min > max) return;
213
213
214 if(d->m_niceNumbers) {
214 if(d->m_niceNumbers) {
215 int ticks = d->m_tickCount;
215 int ticks = d->m_tickCount;
216 d->looseNiceNumbers(min, max, ticks);
216 d->looseNiceNumbers(min, max, ticks);
217 if(ticks!=d->m_tickCount) setTickCount(ticks);
217 if(ticks!=d->m_tickCount) setTickCount(ticks);
218 }
218 }
219
219
220 if (!qFuzzyIsNull(d->m_min - min)) {
220 if (!qFuzzyIsNull(d->m_min - min)) {
221 d->m_min = min;
221 d->m_min = min;
222 changed = true;
222 changed = true;
223 emit minChanged(min);
223 emit minChanged(min);
224 }
224 }
225
225
226 if (!qFuzzyIsNull(d->m_max - max)) {
226 if (!qFuzzyIsNull(d->m_max - max)) {
227 d->m_max = max;
227 d->m_max = max;
228 changed = true;
228 changed = true;
229 emit maxChanged(max);
229 emit maxChanged(max);
230 }
230 }
231
231
232 if (changed) {
232 if (changed) {
233 emit rangeChanged(min,max);
233 emit rangeChanged(min,max);
234 d->emitUpdated();
234 d->emitUpdated();
235 }
235 }
236 }
236 }
237
237
238 /*!
238 /*!
239 Sets \a count for ticks on the axis.
239 Sets \a count for ticks on the axis.
240 */
240 */
241 void QValueAxis::setTickCount(int count)
241 void QValueAxis::setTickCount(int count)
242 {
242 {
243 Q_D(QValueAxis);
243 Q_D(QValueAxis);
244 if (d->m_tickCount != count && count >=2) {
244 if (d->m_tickCount != count && count >=2) {
245 d->m_tickCount = count;
245 d->m_tickCount = count;
246 d->emitUpdated();
246 d->emitUpdated();
247 }
247 }
248 }
248 }
249
249
250 /*!
250 /*!
251 \fn int QValueAxis::tickCount() const
251 \fn int QValueAxis::tickCount() const
252 Return number of ticks on the axis
252 Return number of ticks on the axis
253 */
253 */
254 int QValueAxis::tickCount() const
254 int QValueAxis::tickCount() const
255 {
255 {
256 Q_D(const QValueAxis);
256 Q_D(const QValueAxis);
257 return d->m_tickCount;
257 return d->m_tickCount;
258 }
258 }
259
259
260 void QValueAxis::setNiceNumbersEnabled(bool enable)
260 void QValueAxis::setNiceNumbersEnabled(bool enable)
261 {
261 {
262 Q_D(QValueAxis);
262 Q_D(QValueAxis);
263 if (d->m_niceNumbers != enable){
263 if (d->m_niceNumbers != enable){
264 d->m_niceNumbers = enable;
264 d->m_niceNumbers = enable;
265 if(enable && !qFuzzyIsNull(d->m_max - d->m_min)) {
265 if(enable && !qFuzzyIsNull(d->m_max - d->m_min)) {
266 setRange(d->m_min,d->m_max);
266 setRange(d->m_min,d->m_max);
267 }
267 }
268 }
268 }
269 }
269 }
270
270
271 bool QValueAxis::niceNumbersEnabled() const
271 bool QValueAxis::niceNumbersEnabled() const
272 {
272 {
273 Q_D(const QValueAxis);
273 Q_D(const QValueAxis);
274 return d->m_niceNumbers;
274 return d->m_niceNumbers;
275 }
275 }
276
276
277 void QValueAxis::setLabelFormat(const QString &format)
277 void QValueAxis::setLabelFormat(const QString &format)
278 {
278 {
279 Q_D(QValueAxis);
279 Q_D(QValueAxis);
280 d->m_format = format;
280 d->m_format = format;
281 }
281 }
282
282
283 QString QValueAxis::labelFormat() const
283 QString QValueAxis::labelFormat() const
284 {
284 {
285 Q_D(const QValueAxis);
285 Q_D(const QValueAxis);
286 return d->m_format;
286 return d->m_format;
287 }
287 }
288
288
289 /*!
289 /*!
290 Returns the type of the axis
290 Returns the type of the axis
291 */
291 */
292 QAbstractAxis::AxisType QValueAxis::type() const
292 QAbstractAxis::AxisType QValueAxis::type() const
293 {
293 {
294 return AxisTypeValue;
294 return AxisTypeValue;
295 }
295 }
296
296
297 /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
297 /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
298
298
299 QValueAxisPrivate::QValueAxisPrivate(QValueAxis* q):
299 QValueAxisPrivate::QValueAxisPrivate(QValueAxis* q):
300 QAbstractAxisPrivate(q),
300 QAbstractAxisPrivate(q),
301 m_min(0),
301 m_min(0),
302 m_max(0),
302 m_max(0),
303 m_tickCount(5),
303 m_tickCount(5),
304 m_niceNumbers(false),
304 m_niceNumbers(false)
305 m_format(QString::null)
306 {
305 {
307
306
308 }
307 }
309
308
310 QValueAxisPrivate::~QValueAxisPrivate()
309 QValueAxisPrivate::~QValueAxisPrivate()
311 {
310 {
312
311
313 }
312 }
314
313
315 void QValueAxisPrivate::handleDomainUpdated()
314 void QValueAxisPrivate::handleDomainUpdated()
316 {
315 {
317 Q_Q(QValueAxis);
316 Q_Q(QValueAxis);
318 Domain* domain = qobject_cast<Domain*>(sender());
317 Domain* domain = qobject_cast<Domain*>(sender());
319 Q_ASSERT(domain);
318 Q_ASSERT(domain);
320
319
321 if(orientation()==Qt::Horizontal){
320 if(orientation()==Qt::Horizontal){
322 q->setRange(domain->minX(),domain->maxX());
321 q->setRange(domain->minX(),domain->maxX());
323 }else if(orientation()==Qt::Vertical){
322 }else if(orientation()==Qt::Vertical){
324 q->setRange(domain->minY(),domain->maxY());
323 q->setRange(domain->minY(),domain->maxY());
325 }
324 }
326 }
325 }
327
326
328
327
329 void QValueAxisPrivate::setMin(const QVariant &min)
328 void QValueAxisPrivate::setMin(const QVariant &min)
330 {
329 {
331 Q_Q(QValueAxis);
330 Q_Q(QValueAxis);
332 bool ok;
331 bool ok;
333 qreal value = min.toReal(&ok);
332 qreal value = min.toReal(&ok);
334 if(ok) q->setMin(value);
333 if(ok) q->setMin(value);
335 }
334 }
336
335
337 void QValueAxisPrivate::setMax(const QVariant &max)
336 void QValueAxisPrivate::setMax(const QVariant &max)
338 {
337 {
339
338
340 Q_Q(QValueAxis);
339 Q_Q(QValueAxis);
341 bool ok;
340 bool ok;
342 qreal value = max.toReal(&ok);
341 qreal value = max.toReal(&ok);
343 if(ok) q->setMax(value);
342 if(ok) q->setMax(value);
344 }
343 }
345
344
346 void QValueAxisPrivate::setRange(const QVariant &min, const QVariant &max)
345 void QValueAxisPrivate::setRange(const QVariant &min, const QVariant &max)
347 {
346 {
348 Q_Q(QValueAxis);
347 Q_Q(QValueAxis);
349 bool ok1;
348 bool ok1;
350 bool ok2;
349 bool ok2;
351 qreal value1 = min.toReal(&ok1);
350 qreal value1 = min.toReal(&ok1);
352 qreal value2 = max.toReal(&ok2);
351 qreal value2 = max.toReal(&ok2);
353 if(ok1&&ok2) q->setRange(value1,value2);
352 if(ok1&&ok2) q->setRange(value1,value2);
354 }
353 }
355
354
356 ChartAxis* QValueAxisPrivate::createGraphics(ChartPresenter* presenter)
355 ChartAxis* QValueAxisPrivate::createGraphics(ChartPresenter* presenter)
357 {
356 {
358 Q_Q(QValueAxis);
357 Q_Q(QValueAxis);
359 if(m_orientation == Qt::Vertical){
358 if(m_orientation == Qt::Vertical){
360 return new ChartValueAxisY(q,presenter);
359 return new ChartValueAxisY(q,presenter);
361 }else{
360 }else{
362 return new ChartValueAxisX(q,presenter);
361 return new ChartValueAxisX(q,presenter);
363 }
362 }
364
363
365 }
364 }
366
365
367 void QValueAxisPrivate::intializeDomain(Domain* domain)
366 void QValueAxisPrivate::intializeDomain(Domain* domain)
368 {
367 {
369 Q_Q(QValueAxis);
368 Q_Q(QValueAxis);
370 if(qFuzzyCompare(m_max,m_min)) {
369 if(qFuzzyCompare(m_max,m_min)) {
371 if(m_orientation==Qt::Vertical){
370 if(m_orientation==Qt::Vertical){
372 q->setRange(domain->minY(),domain->maxY());
371 q->setRange(domain->minY(),domain->maxY());
373 }else{
372 }else{
374 q->setRange(domain->minX(), domain->maxX());
373 q->setRange(domain->minX(), domain->maxX());
375 }
374 }
376 } else {
375 } else {
377 if(m_orientation==Qt::Vertical){
376 if(m_orientation==Qt::Vertical){
378 domain->setRangeY(m_min, m_max);
377 domain->setRangeY(m_min, m_max);
379 }else{
378 }else{
380 domain->setRangeX(m_min, m_max);
379 domain->setRangeX(m_min, m_max);
381 }
380 }
382 }
381 }
383 }
382 }
384
383
385 //algorithm defined by Paul S.Heckbert GraphicalGems I
384 //algorithm defined by Paul S.Heckbert GraphicalGems I
386
385
387 void QValueAxisPrivate::looseNiceNumbers(qreal &min, qreal &max, int &ticksCount) const
386 void QValueAxisPrivate::looseNiceNumbers(qreal &min, qreal &max, int &ticksCount) const
388 {
387 {
389 qreal range = niceNumber(max-min,true); //range with ceiling
388 qreal range = niceNumber(max-min,true); //range with ceiling
390 qreal step = niceNumber(range/(ticksCount-1),false);
389 qreal step = niceNumber(range/(ticksCount-1),false);
391 min = qFloor(min/step);
390 min = qFloor(min/step);
392 max = qCeil(max/step);
391 max = qCeil(max/step);
393 ticksCount = int(max-min) +1;
392 ticksCount = int(max-min) +1;
394 min*=step;
393 min*=step;
395 max*=step;
394 max*=step;
396 }
395 }
397
396
398 //nice numbers can be expressed as form of 1*10^n, 2* 10^n or 5*10^n
397 //nice numbers can be expressed as form of 1*10^n, 2* 10^n or 5*10^n
399
398
400 qreal QValueAxisPrivate::niceNumber(qreal x,bool ceiling) const
399 qreal QValueAxisPrivate::niceNumber(qreal x,bool ceiling) const
401 {
400 {
402 qreal z = qPow(10,qFloor(log10(x))); //find corresponding number of the form of 10^n than is smaller than x
401 qreal z = qPow(10,qFloor(log10(x))); //find corresponding number of the form of 10^n than is smaller than x
403 qreal q = x/z;//q<10 && q>=1;
402 qreal q = x/z;//q<10 && q>=1;
404
403
405 if(ceiling) {
404 if(ceiling) {
406 if(q <= 1.0) q=1;
405 if(q <= 1.0) q=1;
407 else if(q <= 2.0) q=2;
406 else if(q <= 2.0) q=2;
408 else if(q <= 5.0) q=5;
407 else if(q <= 5.0) q=5;
409 else q=10;
408 else q=10;
410 }
409 }
411 else {
410 else {
412 if(q < 1.5) q=1;
411 if(q < 1.5) q=1;
413 else if(q < 3.0) q=2;
412 else if(q < 3.0) q=2;
414 else if(q < 7.0) q=5;
413 else if(q < 7.0) q=5;
415 else q=10;
414 else q=10;
416 }
415 }
417 return q*z;
416 return q*z;
418 }
417 }
419
418
420 #include "moc_qvalueaxis.cpp"
419 #include "moc_qvalueaxis.cpp"
421 #include "moc_qvalueaxis_p.cpp"
420 #include "moc_qvalueaxis_p.cpp"
422
421
423 QTCOMMERCIALCHART_END_NAMESPACE
422 QTCOMMERCIALCHART_END_NAMESPACE
@@ -1,78 +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 #ifndef QVALUESAXIS_H
21 #ifndef QVALUEAXIS_H
22 #define QVALUESAXIS_H
22 #define QVALUEAXIS_H
23
23
24 #include "qabstractaxis.h"
24 #include "qabstractaxis.h"
25
25
26 QTCOMMERCIALCHART_BEGIN_NAMESPACE
26 QTCOMMERCIALCHART_BEGIN_NAMESPACE
27
27
28 class QValueAxisPrivate;
28 class QValueAxisPrivate;
29
29
30 class QTCOMMERCIALCHART_EXPORT QValueAxis : public QAbstractAxis
30 class QTCOMMERCIALCHART_EXPORT QValueAxis : public QAbstractAxis
31 {
31 {
32 Q_OBJECT
32 Q_OBJECT
33 Q_PROPERTY(int tickCount READ tickCount WRITE setTickCount)
33 Q_PROPERTY(int tickCount READ tickCount WRITE setTickCount)
34 Q_PROPERTY(bool niceNumbersEnabled READ niceNumbersEnabled WRITE setNiceNumbersEnabled)
34 Q_PROPERTY(bool niceNumbersEnabled READ niceNumbersEnabled WRITE setNiceNumbersEnabled)
35 Q_PROPERTY(qreal min READ min WRITE setMin NOTIFY minChanged)
35 Q_PROPERTY(qreal min READ min WRITE setMin NOTIFY minChanged)
36 Q_PROPERTY(qreal max READ max WRITE setMax NOTIFY maxChanged)
36 Q_PROPERTY(qreal max READ max WRITE setMax NOTIFY maxChanged)
37 Q_PROPERTY(QString labelFormat READ labelFormat WRITE setLabelFormat)
37 Q_PROPERTY(QString labelFormat READ labelFormat WRITE setLabelFormat)
38
38
39 public:
39 public:
40 explicit QValueAxis(QObject *parent = 0);
40 explicit QValueAxis(QObject *parent = 0);
41 ~QValueAxis();
41 ~QValueAxis();
42
42
43 protected:
43 protected:
44 QValueAxis(QValueAxisPrivate &d,QObject *parent = 0);
44 QValueAxis(QValueAxisPrivate &d,QObject *parent = 0);
45
45
46 public:
46 public:
47 AxisType type() const;
47 AxisType type() const;
48
48
49 //range handling
49 //range handling
50 void setMin(qreal min);
50 void setMin(qreal min);
51 qreal min() const;
51 qreal min() const;
52 void setMax(qreal max);
52 void setMax(qreal max);
53 qreal max() const;
53 qreal max() const;
54 void setRange(qreal min, qreal max);
54 void setRange(qreal min, qreal max);
55
55
56 //ticks handling
56 //ticks handling
57 void setTickCount(int count);
57 void setTickCount(int count);
58 int tickCount() const;
58 int tickCount() const;
59
59
60 void setLabelFormat(const QString &format);
60 void setLabelFormat(const QString &format);
61 QString labelFormat() const;
61 QString labelFormat() const;
62
62
63 void setNiceNumbersEnabled(bool enable = true);
63 void setNiceNumbersEnabled(bool enable = true);
64 bool niceNumbersEnabled() const;
64 bool niceNumbersEnabled() const;
65
65
66 Q_SIGNALS:
66 Q_SIGNALS:
67 void minChanged(qreal min);
67 void minChanged(qreal min);
68 void maxChanged(qreal max);
68 void maxChanged(qreal max);
69 void rangeChanged(qreal min, qreal max);
69 void rangeChanged(qreal min, qreal max);
70
70
71 private:
71 private:
72 Q_DECLARE_PRIVATE(QValueAxis)
72 Q_DECLARE_PRIVATE(QValueAxis)
73 Q_DISABLE_COPY(QValueAxis)
73 Q_DISABLE_COPY(QValueAxis)
74 };
74 };
75
75
76 QTCOMMERCIALCHART_END_NAMESPACE
76 QTCOMMERCIALCHART_END_NAMESPACE
77
77
78 #endif // QVALUESAXIS_H
78 #endif // QVALUEAXIS_H
@@ -1,73 +1,73
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 QVALUESAXIS_P_H
30 #ifndef QVALUEAXIS_P_H
31 #define QVALUESAXIS_P_H
31 #define QVALUEAXIS_P_H
32
32
33 #include "qvalueaxis.h"
33 #include "qvalueaxis.h"
34 #include "qabstractaxis_p.h"
34 #include "qabstractaxis_p.h"
35
35
36 QTCOMMERCIALCHART_BEGIN_NAMESPACE
36 QTCOMMERCIALCHART_BEGIN_NAMESPACE
37
37
38 class QValueAxisPrivate : public QAbstractAxisPrivate
38 class QValueAxisPrivate : public QAbstractAxisPrivate
39 {
39 {
40 Q_OBJECT
40 Q_OBJECT
41 public:
41 public:
42 QValueAxisPrivate(QValueAxis *q);
42 QValueAxisPrivate(QValueAxis *q);
43 ~QValueAxisPrivate();
43 ~QValueAxisPrivate();
44
44
45 public:
45 public:
46 ChartAxis* createGraphics(ChartPresenter* presenter);
46 ChartAxis* createGraphics(ChartPresenter* presenter);
47 void intializeDomain(Domain* domain);
47 void intializeDomain(Domain* domain);
48 void handleDomainUpdated();
48 void handleDomainUpdated();
49 qreal min(){ return m_min; };
49 qreal min(){ return m_min; };
50 qreal max(){ return m_max; };
50 qreal max(){ return m_max; };
51 int count() const { return m_tickCount;}
51 int count() const { return m_tickCount;}
52
52
53 protected:
53 protected:
54 void setMin(const QVariant &min);
54 void setMin(const QVariant &min);
55 void setMax(const QVariant &max);
55 void setMax(const QVariant &max);
56 void setRange(const QVariant &min, const QVariant &max);
56 void setRange(const QVariant &min, const QVariant &max);
57
57
58 private:
58 private:
59 void looseNiceNumbers(qreal &min, qreal &max, int &ticksCount) const;
59 void looseNiceNumbers(qreal &min, qreal &max, int &ticksCount) const;
60 qreal niceNumber(qreal x,bool ceiling) const;
60 qreal niceNumber(qreal x,bool ceiling) const;
61
61
62 private:
62 private:
63 qreal m_min;
63 qreal m_min;
64 qreal m_max;
64 qreal m_max;
65 int m_tickCount;
65 int m_tickCount;
66 bool m_niceNumbers;
66 bool m_niceNumbers;
67 QString m_format;
67 QString m_format;
68 Q_DECLARE_PUBLIC(QValueAxis)
68 Q_DECLARE_PUBLIC(QValueAxis)
69 };
69 };
70
70
71 QTCOMMERCIALCHART_END_NAMESPACE
71 QTCOMMERCIALCHART_END_NAMESPACE
72
72
73 #endif // QVALUESAXIS_P_H
73 #endif // QVALUEAXIS_P_H
@@ -1,204 +1,204
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 "abstractbarchartitem_p.h"
21 #include "abstractbarchartitem_p.h"
22 #include "bar_p.h"
22 #include "bar_p.h"
23 #include "qbarset.h"
23 #include "qbarset.h"
24 #include "qbarset_p.h"
24 #include "qbarset_p.h"
25 #include "qabstractbarseries.h"
25 #include "qabstractbarseries.h"
26 #include "qabstractbarseries_p.h"
26 #include "qabstractbarseries_p.h"
27 #include "qchart.h"
27 #include "qchart.h"
28 #include "chartpresenter_p.h"
28 #include "chartpresenter_p.h"
29 #include "charttheme_p.h"
29 #include "charttheme_p.h"
30 #include "abstractbaranimation_p.h"
30 #include "abstractbaranimation_p.h"
31 #include "chartdataset_p.h"
31 #include "chartdataset_p.h"
32 #include <QPainter>
32 #include <QPainter>
33
33
34 QTCOMMERCIALCHART_BEGIN_NAMESPACE
34 QTCOMMERCIALCHART_BEGIN_NAMESPACE
35
35
36 AbstractBarChartItem::AbstractBarChartItem(QAbstractBarSeries *series, ChartPresenter *presenter) :
36 AbstractBarChartItem::AbstractBarChartItem(QAbstractBarSeries *series, ChartPresenter *presenter) :
37 ChartItem(presenter),
37 ChartItem(presenter),
38 m_animation(0),
38 m_animation(0),
39 m_series(series)
39 m_series(series)
40 {
40 {
41
41
42 setFlag(ItemClipsChildrenToShape);
42 setFlag(ItemClipsChildrenToShape);
43 connect(series->d_func(), SIGNAL(updatedLayout()), this, SLOT(handleLayoutChanged()));
43 connect(series->d_func(), SIGNAL(updatedLayout()), this, SLOT(handleLayoutChanged()));
44 connect(series->d_func(), SIGNAL(updatedBars()), this, SLOT(handleUpdatedBars()));
44 connect(series->d_func(), SIGNAL(updatedBars()), this, SLOT(handleUpdatedBars()));
45 connect(series->d_func(), SIGNAL(labelsVisibleChanged(bool)), this, SLOT(handleLabelsVisibleChanged(bool)));
45 connect(series->d_func(), SIGNAL(labelsVisibleChanged(bool)), this, SLOT(handleLabelsVisibleChanged(bool)));
46 connect(series->d_func(), SIGNAL(restructuredBars()), this, SLOT(handleDataStructureChanged()));
46 connect(series->d_func(), SIGNAL(restructuredBars()), this, SLOT(handleDataStructureChanged()));
47 connect(series, SIGNAL(visibleChanged()), this, SLOT(handleVisibleChanged()));
47 connect(series, SIGNAL(visibleChanged()), this, SLOT(handleVisibleChanged()));
48 setZValue(ChartPresenter::BarSeriesZValue);
48 setZValue(ChartPresenter::BarSeriesZValue);
49 handleDataStructureChanged();
49 handleDataStructureChanged();
50 }
50 }
51
51
52 AbstractBarChartItem::~AbstractBarChartItem()
52 AbstractBarChartItem::~AbstractBarChartItem()
53 {
53 {
54 }
54 }
55
55
56 void AbstractBarChartItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget)
56 void AbstractBarChartItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget)
57 {
57 {
58 Q_UNUSED(painter);
58 Q_UNUSED(painter);
59 Q_UNUSED(option);
59 Q_UNUSED(option);
60 Q_UNUSED(widget);
60 Q_UNUSED(widget);
61 }
61 }
62
62
63 QRectF AbstractBarChartItem::boundingRect() const
63 QRectF AbstractBarChartItem::boundingRect() const
64 {
64 {
65 return m_rect;
65 return m_rect;
66 }
66 }
67
67
68 void AbstractBarChartItem::applyLayout(const QVector<QRectF> &layout)
68 void AbstractBarChartItem::applyLayout(const QVector<QRectF> &layout)
69 {
69 {
70 if (m_animation) {
70 if (m_animation) {
71 m_animation->setup(m_layout,layout);
71 m_animation->setup(m_layout,layout);
72 presenter()->startAnimation(m_animation);
72 presenter()->startAnimation(m_animation);
73
73
74 } else {
74 } else {
75 setLayout(layout);
75 setLayout(layout);
76 update();
76 update();
77 }
77 }
78 }
78 }
79
79
80 void AbstractBarChartItem::setAnimation(AbstractBarAnimation *animation)
80 void AbstractBarChartItem::setAnimation(AbstractBarAnimation *animation)
81 {
81 {
82 m_animation = animation;
82 m_animation = animation;
83 }
83 }
84
84
85 void AbstractBarChartItem::setLayout(const QVector<QRectF> &layout)
85 void AbstractBarChartItem::setLayout(const QVector<QRectF> &layout)
86 {
86 {
87 if (layout.count() != m_bars.count())
87 if (layout.count() != m_bars.count())
88 return;
88 return;
89
89
90 m_layout = layout;
90 m_layout = layout;
91
91
92 for (int i=0; i < m_bars.count(); i++) {
92 for (int i=0; i < m_bars.count(); i++) {
93 m_bars.at(i)->setRect(layout.at(i));
93 m_bars.at(i)->setRect(layout.at(i));
94 }
94 }
95 }
95 }
96 //handlers
96 //handlers
97
97
98 void AbstractBarChartItem::handleDomainUpdated()
98 void AbstractBarChartItem::handleDomainUpdated()
99 {
99 {
100 m_domainMinX = domain()->minX();
100 m_domainMinX = domain()->minX();
101 m_domainMaxX = domain()->maxX();
101 m_domainMaxX = domain()->maxX();
102 m_domainMinY = domain()->minY();
102 m_domainMinY = domain()->minY();
103 m_domainMaxY = domain()->maxY();
103 m_domainMaxY = domain()->maxY();
104 handleLayoutChanged();
104 handleLayoutChanged();
105 }
105 }
106
106
107 void AbstractBarChartItem::handleGeometryChanged(const QRectF &rect)
107 void AbstractBarChartItem::handleGeometryChanged(const QRectF &rect)
108 {
108 {
109 prepareGeometryChange();
109 prepareGeometryChange();
110 m_rect = rect;
110 m_rect = rect;
111 handleLayoutChanged();
111 handleLayoutChanged();
112 }
112 }
113
113
114 void AbstractBarChartItem::handleLayoutChanged()
114 void AbstractBarChartItem::handleLayoutChanged()
115 {
115 {
116 if ((m_rect.width() <= 0) || (m_rect.height() <= 0)) {
116 if ((m_rect.width() <= 0) || (m_rect.height() <= 0)) {
117 // rect size zero.
117 // rect size zero.
118 return;
118 return;
119 }
119 }
120 QVector<QRectF> layout = calculateLayout();
120 QVector<QRectF> layout = calculateLayout();
121 applyLayout(layout);
121 applyLayout(layout);
122 }
122 }
123
123
124 void AbstractBarChartItem::handleLabelsVisibleChanged(bool visible)
124 void AbstractBarChartItem::handleLabelsVisibleChanged(bool visible)
125 {
125 {
126 foreach (QGraphicsSimpleTextItem* label, m_labels) {
126 foreach (QGraphicsSimpleTextItem* label, m_labels) {
127 label->setVisible(visible);
127 label->setVisible(visible);
128 }
128 }
129 update();
129 update();
130 }
130 }
131
131
132 void AbstractBarChartItem::handleDataStructureChanged()
132 void AbstractBarChartItem::handleDataStructureChanged()
133 {
133 {
134 foreach(QGraphicsItem *item, childItems()) {
134 foreach(QGraphicsItem *item, childItems()) {
135 delete item;
135 delete item;
136 }
136 }
137
137
138 m_bars.clear();
138 m_bars.clear();
139 m_labels.clear();
139 m_labels.clear();
140 m_layout.clear();
140 m_layout.clear();
141
141
142 bool labelsVisible = m_series->isLabelsVisible();
142 bool labelsVisible = m_series->isLabelsVisible();
143
143
144 // Create new graphic items for bars
144 // Create new graphic items for bars
145 for (int c = 0; c < m_series->d_func()->categoryCount(); c++) {
145 for (int c = 0; c < m_series->d_func()->categoryCount(); c++) {
146 for (int s = 0; s < m_series->count(); s++) {
146 for (int s = 0; s < m_series->count(); s++) {
147 QBarSet *set = m_series->d_func()->barsetAt(s);
147 QBarSet *set = m_series->d_func()->barsetAt(s);
148
148
149 // Bars
149 // Bars
150 Bar *bar = new Bar(set,c,this);
150 Bar *bar = new Bar(set,c,this);
151 m_bars.append(bar);
151 m_bars.append(bar);
152 connect(bar, SIGNAL(clicked(int, QBarSet*)), m_series, SIGNAL(clicked(int, QBarSet*)));
152 connect(bar, SIGNAL(clicked(int,QBarSet*)), m_series, SIGNAL(clicked(int,QBarSet*)));
153 connect(bar, SIGNAL(hovered(bool, QBarSet*)), m_series, SIGNAL(hovered(bool, QBarSet*)));
153 connect(bar, SIGNAL(hovered(bool,QBarSet*)), m_series, SIGNAL(hovered(bool,QBarSet*)));
154 connect(bar, SIGNAL(clicked(int, QBarSet*)), set, SIGNAL(clicked(int)));
154 connect(bar, SIGNAL(clicked(int,QBarSet*)), set, SIGNAL(clicked(int)));
155 connect(bar, SIGNAL(hovered(bool, QBarSet*)), set, SIGNAL(hovered(bool)));
155 connect(bar, SIGNAL(hovered(bool,QBarSet*)), set, SIGNAL(hovered(bool)));
156 m_layout.append(QRectF(0, 0, 0, 0));
156 m_layout.append(QRectF(0, 0, 0, 0));
157
157
158 // Labels
158 // Labels
159 QGraphicsSimpleTextItem *label = new QGraphicsSimpleTextItem(this);
159 QGraphicsSimpleTextItem *label = new QGraphicsSimpleTextItem(this);
160 label->setVisible(labelsVisible);
160 label->setVisible(labelsVisible);
161 m_labels.append(label);
161 m_labels.append(label);
162 }
162 }
163 }
163 }
164
164
165 presenter()->chartTheme()->decorate(m_series, presenter()->dataSet()->seriesIndex(m_series));
165 presenter()->chartTheme()->decorate(m_series, presenter()->dataSet()->seriesIndex(m_series));
166 handleLayoutChanged();
166 handleLayoutChanged();
167 }
167 }
168
168
169 void AbstractBarChartItem::handleVisibleChanged()
169 void AbstractBarChartItem::handleVisibleChanged()
170 {
170 {
171 bool visible = m_series->isVisible();
171 bool visible = m_series->isVisible();
172 handleLabelsVisibleChanged(visible);
172 handleLabelsVisibleChanged(visible);
173 foreach(QGraphicsItem *item, childItems()) {
173 foreach(QGraphicsItem *item, childItems()) {
174 item->setVisible(visible);
174 item->setVisible(visible);
175 }
175 }
176 }
176 }
177
177
178 void AbstractBarChartItem::handleUpdatedBars()
178 void AbstractBarChartItem::handleUpdatedBars()
179 {
179 {
180 // Handle changes in pen, brush, labels etc.
180 // Handle changes in pen, brush, labels etc.
181 int categoryCount = m_series->d_func()->categoryCount();
181 int categoryCount = m_series->d_func()->categoryCount();
182 int setCount = m_series->count();
182 int setCount = m_series->count();
183 int itemIndex(0);
183 int itemIndex(0);
184
184
185 for (int category = 0; category < categoryCount; category++) {
185 for (int category = 0; category < categoryCount; category++) {
186 for (int set = 0; set < setCount; set++) {
186 for (int set = 0; set < setCount; set++) {
187 QBarSetPrivate* barSet = m_series->d_func()->barsetAt(set)->d_ptr.data();
187 QBarSetPrivate* barSet = m_series->d_func()->barsetAt(set)->d_ptr.data();
188 Bar* bar = m_bars.at(itemIndex);
188 Bar* bar = m_bars.at(itemIndex);
189 bar->setPen(barSet->m_pen);
189 bar->setPen(barSet->m_pen);
190 bar->setBrush(barSet->m_brush);
190 bar->setBrush(barSet->m_brush);
191 bar->update();
191 bar->update();
192
192
193 QGraphicsSimpleTextItem* label = m_labels.at(itemIndex);
193 QGraphicsSimpleTextItem* label = m_labels.at(itemIndex);
194 label->setFont(barSet->m_labelFont);
194 label->setFont(barSet->m_labelFont);
195 label->setBrush(barSet->m_labelBrush);
195 label->setBrush(barSet->m_labelBrush);
196 label->update();
196 label->update();
197 itemIndex++;
197 itemIndex++;
198 }
198 }
199 }
199 }
200 }
200 }
201
201
202 #include "moc_abstractbarchartitem_p.cpp"
202 #include "moc_abstractbarchartitem_p.cpp"
203
203
204 QTCOMMERCIALCHART_END_NAMESPACE
204 QTCOMMERCIALCHART_END_NAMESPACE
@@ -1,870 +1,870
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 "qabstractbarseries.h"
21 #include "qabstractbarseries.h"
22 #include "qabstractbarseries_p.h"
22 #include "qabstractbarseries_p.h"
23 #include "qbarset.h"
23 #include "qbarset.h"
24 #include "qbarset_p.h"
24 #include "qbarset_p.h"
25 #include "domain_p.h"
25 #include "domain_p.h"
26 #include "legendmarker_p.h"
26 #include "legendmarker_p.h"
27 #include "chartdataset_p.h"
27 #include "chartdataset_p.h"
28 #include "charttheme_p.h"
28 #include "charttheme_p.h"
29 #include "qvalueaxis.h"
29 #include "qvalueaxis.h"
30 #include "qbarcategoryaxis.h"
30 #include "qbarcategoryaxis.h"
31
31
32 QTCOMMERCIALCHART_BEGIN_NAMESPACE
32 QTCOMMERCIALCHART_BEGIN_NAMESPACE
33
33
34 /*!
34 /*!
35 \class QAbstractBarSeries
35 \class QAbstractBarSeries
36 \brief Series for creating a bar chart
36 \brief Series for creating a bar chart
37 \mainclass
37 \mainclass
38
38
39 QAbstractBarSeries represents a series of data shown as bars. The purpose of this class is to draw bars to
39 QAbstractBarSeries represents a series of data shown as bars. The purpose of this class is to draw bars to
40 the position defined by data. Single bar is defined by QPointF, where x value is the x-coordinate of the bar
40 the position defined by data. Single bar is defined by QPointF, where x value is the x-coordinate of the bar
41 and y-value is the height of the bar. The category names are ignored with this series and x-axis
41 and y-value is the height of the bar. The category names are ignored with this series and x-axis
42 shows the x-values.
42 shows the x-values.
43
43
44 See the \l {BarChart Example} {bar chart example} to learn how to create a simple bar chart.
44 See the \l {BarChart Example} {bar chart example} to learn how to create a simple bar chart.
45 \image examples_barchart.png
45 \image examples_barchart.png
46
46
47 \sa QBarSet, QStackedBarSeries, QPercentBarSeries
47 \sa QBarSet, QStackedBarSeries, QPercentBarSeries
48 */
48 */
49 /*!
49 /*!
50 \qmlclass AbstractBarSeries QAbstractBarSeries
50 \qmlclass AbstractBarSeries QAbstractBarSeries
51 \inherits QAbstractSeries
51 \inherits QAbstractSeries
52
52
53 The following QML shows how to create a simple bar chart:
53 The following QML shows how to create a simple bar chart:
54 \snippet ../demos/qmlchart/qml/qmlchart/View6.qml 1
54 \snippet ../demos/qmlchart/qml/qmlchart/View6.qml 1
55
55
56 \beginfloatleft
56 \beginfloatleft
57 \image demos_qmlchart6.png
57 \image demos_qmlchart6.png
58 \endfloat
58 \endfloat
59 \clearfloat
59 \clearfloat
60 */
60 */
61
61
62 /*!
62 /*!
63 \property QAbstractBarSeries::barWidth
63 \property QAbstractBarSeries::barWidth
64 The width of the bars of the series. The unit of \a width is the unit of x-axis. The minimum width for bars
64 The width of the bars of the series. The unit of \a width is the unit of x-axis. The minimum width for bars
65 is zero and negative values are treated as zero. Setting the width to zero means that width of the bar on screen
65 is zero and negative values are treated as zero. Setting the width to zero means that width of the bar on screen
66 is one pixel no matter what the scale of x-axis is. Bars wider than zero are scaled with x-axis.
66 is one pixel no matter what the scale of x-axis is. Bars wider than zero are scaled with x-axis.
67 Note that with QBarSeries this value means the width of one group of bars instead of just one bar.
67 Note that with QBarSeries this value means the width of one group of bars instead of just one bar.
68 \sa QBarSeries
68 \sa QBarSeries
69 */
69 */
70 /*!
70 /*!
71 \qmlproperty real AbstractBarSeries::barWidth
71 \qmlproperty real AbstractBarSeries::barWidth
72 The width of the bars of the series. The unit of width is the unit of x-axis. The minimum width for bars
72 The width of the bars of the series. The unit of width is the unit of x-axis. The minimum width for bars
73 is zero and negative values are treated as zero. Setting the width to zero means that width of the bar on screen
73 is zero and negative values are treated as zero. Setting the width to zero means that width of the bar on screen
74 is one pixel no matter what the scale of x-axis is. Bars wider than zero are scaled with x-axis.
74 is one pixel no matter what the scale of x-axis is. Bars wider than zero are scaled with x-axis.
75 Note that with QBarSeries this value means the width of one group of bars instead of just one bar.
75 Note that with QBarSeries this value means the width of one group of bars instead of just one bar.
76 */
76 */
77
77
78 /*!
78 /*!
79 \property QAbstractBarSeries::count
79 \property QAbstractBarSeries::count
80 Holds the number of sets in series.
80 Holds the number of sets in series.
81 */
81 */
82 /*!
82 /*!
83 \qmlproperty int AbstractBarSeries::count
83 \qmlproperty int AbstractBarSeries::count
84 Holds the number of sets in series.
84 Holds the number of sets in series.
85 */
85 */
86
86
87 /*!
87 /*!
88 \property QAbstractBarSeries::labelsVisible
88 \property QAbstractBarSeries::labelsVisible
89 Defines the visibility of the labels in series
89 Defines the visibility of the labels in series
90 */
90 */
91 /*!
91 /*!
92 \qmlproperty bool AbstractBarSeries::labelsVisible
92 \qmlproperty bool AbstractBarSeries::labelsVisible
93 Defines the visibility of the labels in series
93 Defines the visibility of the labels in series
94 */
94 */
95
95
96 /*!
96 /*!
97 \fn void QAbstractBarSeries::clicked(int index, QBarSet *barset)
97 \fn void QAbstractBarSeries::clicked(int index, QBarSet *barset)
98 The signal is emitted if the user clicks with a mouse on top of QBarSet \a barset.
98 The signal is emitted if the user clicks with a mouse on top of QBarSet \a barset.
99 Clicked bar inside set is indexed by \a index
99 Clicked bar inside set is indexed by \a index
100 */
100 */
101 /*!
101 /*!
102 \qmlsignal AbstractBarSeries::onClicked(int index, BarSet barset)
102 \qmlsignal AbstractBarSeries::onClicked(int index, BarSet barset)
103 The signal is emitted if the user clicks with a mouse on top of BarSet.
103 The signal is emitted if the user clicks with a mouse on top of BarSet.
104 Clicked bar inside set is indexed by \a index
104 Clicked bar inside set is indexed by \a index
105 */
105 */
106
106
107 /*!
107 /*!
108 \fn void QAbstractBarSeries::hovered(bool status, QBarSet* barset)
108 \fn void QAbstractBarSeries::hovered(bool status, QBarSet* barset)
109
109
110 The signal is emitted if mouse is hovered on top of series.
110 The signal is emitted if mouse is hovered on top of series.
111 Parameter \a barset is the pointer of barset, where hover happened.
111 Parameter \a barset is the pointer of barset, where hover happened.
112 Parameter \a status is true, if mouse entered on top of series, false if mouse left from top of series.
112 Parameter \a status is true, if mouse entered on top of series, false if mouse left from top of series.
113 */
113 */
114 /*!
114 /*!
115 \qmlsignal AbstractBarSeries::onHovered(bool status, BarSet barset)
115 \qmlsignal AbstractBarSeries::onHovered(bool status, BarSet barset)
116
116
117 The signal is emitted if mouse is hovered on top of series.
117 The signal is emitted if mouse is hovered on top of series.
118 Parameter \a barset is the pointer of barset, where hover happened.
118 Parameter \a barset is the pointer of barset, where hover happened.
119 Parameter \a status is true, if mouse entered on top of series, false if mouse left from top of series.
119 Parameter \a status is true, if mouse entered on top of series, false if mouse left from top of series.
120 */
120 */
121
121
122 /*!
122 /*!
123 \fn void QAbstractBarSeries::countChanged()
123 \fn void QAbstractBarSeries::countChanged()
124 This signal is emitted when barset count has been changed, for example by append or remove.
124 This signal is emitted when barset count has been changed, for example by append or remove.
125 */
125 */
126 /*!
126 /*!
127 \qmlsignal AbstractBarSeries::onCountChanged()
127 \qmlsignal AbstractBarSeries::onCountChanged()
128 This signal is emitted when barset count has been changed, for example by append or remove.
128 This signal is emitted when barset count has been changed, for example by append or remove.
129 */
129 */
130
130
131 /*!
131 /*!
132 \fn void QAbstractBarSeries::labelsVisibleChanged()
132 \fn void QAbstractBarSeries::labelsVisibleChanged()
133 This signal is emitted when labels visibility have changed.
133 This signal is emitted when labels visibility have changed.
134 \sa isLabelsVisible(), setLabelsVisible()
134 \sa isLabelsVisible(), setLabelsVisible()
135 */
135 */
136
136
137 /*!
137 /*!
138 \fn void QAbstractBarSeries::barsetsAdded(QList<QBarSet*> sets)
138 \fn void QAbstractBarSeries::barsetsAdded(QList<QBarSet*> sets)
139 This signal is emitted when \a sets have been added to the series.
139 This signal is emitted when \a sets have been added to the series.
140 \sa append(), insert()
140 \sa append(), insert()
141 */
141 */
142 /*!
142 /*!
143 \qmlsignal AbstractBarSeries::onAdded(BarSet barset)
143 \qmlsignal AbstractBarSeries::onAdded(BarSet barset)
144 Emitted when \a barset has been added to the series.
144 Emitted when \a barset has been added to the series.
145 */
145 */
146
146
147 /*!
147 /*!
148 \fn void QAbstractBarSeries::barsetsRemoved(QList<QBarSet*> sets)
148 \fn void QAbstractBarSeries::barsetsRemoved(QList<QBarSet*> sets)
149 This signal is emitted when \a sets have been removed from the series.
149 This signal is emitted when \a sets have been removed from the series.
150 \sa remove()
150 \sa remove()
151 */
151 */
152 /*!
152 /*!
153 \qmlsignal AbstractBarSeries::onRemoved(BarSet barset)
153 \qmlsignal AbstractBarSeries::onRemoved(BarSet barset)
154 Emitted when \a barset has been removed from the series.
154 Emitted when \a barset has been removed from the series.
155 */
155 */
156
156
157 /*!
157 /*!
158 \qmlmethod BarSet AbstractBarSeries::at(int index)
158 \qmlmethod BarSet AbstractBarSeries::at(int index)
159 Returns bar set at \a index. Returns null if the index is not valid.
159 Returns bar set at \a index. Returns null if the index is not valid.
160 */
160 */
161
161
162 /*!
162 /*!
163 \qmlmethod BarSet AbstractBarSeries::append(string label, VariantList values)
163 \qmlmethod BarSet AbstractBarSeries::append(string label, VariantList values)
164 Adds a new bar set with \a label and \a values to \a index. Values can be a list of reals or a list of XYPoints.
164 Adds a new bar set with \a label and \a values to \a index. Values can be a list of reals or a list of XYPoints.
165 For example:
165 For example:
166 \code
166 \code
167 myBarSeries.append("set 1", [0, 0.2, 0.2, 0.5, 0.4, 1.5, 0.9]);
167 myBarSeries.append("set 1", [0, 0.2, 0.2, 0.5, 0.4, 1.5, 0.9]);
168 myBarSeries.append("set 2", [Qt.point(0, 1), Qt.point(2, 2.5), Qt.point(3.5, 2.2)]);
168 myBarSeries.append("set 2", [Qt.point(0, 1), Qt.point(2, 2.5), Qt.point(3.5, 2.2)]);
169 \endcode
169 \endcode
170 */
170 */
171
171
172 /*!
172 /*!
173 \qmlmethod BarSet AbstractBarSeries::insert(int index, string label, VariantList values)
173 \qmlmethod BarSet AbstractBarSeries::insert(int index, string label, VariantList values)
174 Inserts a new bar set with \a label and \a values to \a index. Values can be a list of reals or a list of XYPoints.
174 Inserts a new bar set with \a label and \a values to \a index. Values can be a list of reals or a list of XYPoints.
175 If index is zero or smaller, the new barset is prepended. If the index is count or bigger, the new barset is
175 If index is zero or smaller, the new barset is prepended. If the index is count or bigger, the new barset is
176 appended.
176 appended.
177 \sa AbstractBarSeries::append()
177 \sa AbstractBarSeries::append()
178 */
178 */
179
179
180 /*!
180 /*!
181 \qmlmethod bool AbstractBarSeries::remove(BarSet barset)
181 \qmlmethod bool AbstractBarSeries::remove(BarSet barset)
182 Removes the barset from the series. Returns true if successful, false otherwise.
182 Removes the barset from the series. Returns true if successful, false otherwise.
183 */
183 */
184
184
185 /*!
185 /*!
186 \qmlmethod AbstractBarSeries::clear()
186 \qmlmethod AbstractBarSeries::clear()
187 Removes all barsets from the series.
187 Removes all barsets from the series.
188 */
188 */
189
189
190 /*!
190 /*!
191 Destructs abstractbarseries and owned barsets.
191 Destructs abstractbarseries and owned barsets.
192 */
192 */
193 QAbstractBarSeries::~QAbstractBarSeries()
193 QAbstractBarSeries::~QAbstractBarSeries()
194 {
194 {
195
195
196 }
196 }
197
197
198 /*!
198 /*!
199 \internal
199 \internal
200 */
200 */
201 QAbstractBarSeries::QAbstractBarSeries(QAbstractBarSeriesPrivate &d, QObject *parent) :
201 QAbstractBarSeries::QAbstractBarSeries(QAbstractBarSeriesPrivate &d, QObject *parent) :
202 QAbstractSeries(d,parent)
202 QAbstractSeries(d,parent)
203 {
203 {
204 }
204 }
205
205
206 /*!
206 /*!
207 Sets the width of the bars of the series. The unit of \a width is the unit of x-axis. The minimum width for bars
207 Sets the width of the bars of the series. The unit of \a width is the unit of x-axis. The minimum width for bars
208 is zero and negative values are treated as zero. Setting the width to zero means that width of the bar on screen
208 is zero and negative values are treated as zero. Setting the width to zero means that width of the bar on screen
209 is one pixel no matter what the scale of x-axis is. Bars wider than zero are scaled with x-axis.
209 is one pixel no matter what the scale of x-axis is. Bars wider than zero are scaled with x-axis.
210 Note that with \link QBarSeries \endlink this value means the width of one group of bars instead of just one bar.
210 Note that with \link QBarSeries \endlink this value means the width of one group of bars instead of just one bar.
211 */
211 */
212 void QAbstractBarSeries::setBarWidth(qreal width)
212 void QAbstractBarSeries::setBarWidth(qreal width)
213 {
213 {
214 Q_D(QAbstractBarSeries);
214 Q_D(QAbstractBarSeries);
215 d->setBarWidth(width);
215 d->setBarWidth(width);
216 }
216 }
217
217
218 /*!
218 /*!
219 Returns the width of the bars of the series.
219 Returns the width of the bars of the series.
220 \sa setBarWidth()
220 \sa setBarWidth()
221 */
221 */
222 qreal QAbstractBarSeries::barWidth() const
222 qreal QAbstractBarSeries::barWidth() const
223 {
223 {
224 Q_D(const QAbstractBarSeries);
224 Q_D(const QAbstractBarSeries);
225 return d->barWidth();
225 return d->barWidth();
226 }
226 }
227
227
228 /*!
228 /*!
229 Adds a set of bars to series. Takes ownership of \a set. If the set is null or is already in series, it won't be appended.
229 Adds a set of bars to series. Takes ownership of \a set. If the set is null or is already in series, it won't be appended.
230 Returns true, if appending succeeded.
230 Returns true, if appending succeeded.
231 */
231 */
232 bool QAbstractBarSeries::append(QBarSet *set)
232 bool QAbstractBarSeries::append(QBarSet *set)
233 {
233 {
234 Q_D(QAbstractBarSeries);
234 Q_D(QAbstractBarSeries);
235 bool success = d->append(set);
235 bool success = d->append(set);
236 if (success) {
236 if (success) {
237 QList<QBarSet*> sets;
237 QList<QBarSet*> sets;
238 sets.append(set);
238 sets.append(set);
239 set->setParent(this);
239 set->setParent(this);
240 emit barsetsAdded(sets);
240 emit barsetsAdded(sets);
241 emit countChanged();
241 emit countChanged();
242 }
242 }
243 return success;
243 return success;
244 }
244 }
245
245
246 /*!
246 /*!
247 Removes barset from series. Releases ownership of \a set. Deletes the set, if remove
247 Removes barset from series. Releases ownership of \a set. Deletes the set, if remove
248 was successful.
248 was successful.
249 Returns true, if set was removed.
249 Returns true, if set was removed.
250 */
250 */
251 bool QAbstractBarSeries::remove(QBarSet *set)
251 bool QAbstractBarSeries::remove(QBarSet *set)
252 {
252 {
253 Q_D(QAbstractBarSeries);
253 Q_D(QAbstractBarSeries);
254 bool success = d->remove(set);
254 bool success = d->remove(set);
255 if (success) {
255 if (success) {
256 QList<QBarSet*> sets;
256 QList<QBarSet*> sets;
257 sets.append(set);
257 sets.append(set);
258 set->setParent(0);
258 set->setParent(0);
259 emit barsetsRemoved(sets);
259 emit barsetsRemoved(sets);
260 emit countChanged();
260 emit countChanged();
261 delete set;
261 delete set;
262 set = 0;
262 set = 0;
263 }
263 }
264 return success;
264 return success;
265 }
265 }
266
266
267 /*!
267 /*!
268 Takes a single \a set from the series. Does not delete the barset object.
268 Takes a single \a set from the series. Does not delete the barset object.
269
269
270 NOTE: The series remains as the barset's parent object. You must set the
270 NOTE: The series remains as the barset's parent object. You must set the
271 parent object to take full ownership.
271 parent object to take full ownership.
272
272
273 Returns true if take was successful.
273 Returns true if take was successful.
274 */
274 */
275 bool QAbstractBarSeries::take(QBarSet *set)
275 bool QAbstractBarSeries::take(QBarSet *set)
276 {
276 {
277 Q_D(QAbstractBarSeries);
277 Q_D(QAbstractBarSeries);
278 bool success = d->remove(set);
278 bool success = d->remove(set);
279 if (success) {
279 if (success) {
280 QList<QBarSet*> sets;
280 QList<QBarSet*> sets;
281 sets.append(set);
281 sets.append(set);
282 emit barsetsRemoved(sets);
282 emit barsetsRemoved(sets);
283 emit countChanged();
283 emit countChanged();
284 }
284 }
285 return success;
285 return success;
286 }
286 }
287
287
288 /*!
288 /*!
289 Adds a list of barsets to series. Takes ownership of \a sets.
289 Adds a list of barsets to series. Takes ownership of \a sets.
290 Returns true, if all sets were appended succesfully. If any of the sets is null or is already appended to series,
290 Returns true, if all sets were appended successfully. If any of the sets is null or is already appended to series,
291 nothing is appended and function returns false. If any of the sets is in list more than once, nothing is appended
291 nothing is appended and function returns false. If any of the sets is in list more than once, nothing is appended
292 and function returns false.
292 and function returns false.
293 */
293 */
294 bool QAbstractBarSeries::append(QList<QBarSet* > sets)
294 bool QAbstractBarSeries::append(QList<QBarSet* > sets)
295 {
295 {
296 Q_D(QAbstractBarSeries);
296 Q_D(QAbstractBarSeries);
297 bool success = d->append(sets);
297 bool success = d->append(sets);
298 if (success) {
298 if (success) {
299 emit barsetsAdded(sets);
299 emit barsetsAdded(sets);
300 emit countChanged();
300 emit countChanged();
301 }
301 }
302 return success;
302 return success;
303 }
303 }
304
304
305 /*!
305 /*!
306 Insert a set of bars to series at \a index postion. Takes ownership of \a set. If the set is null or is already in series, it won't be appended.
306 Insert a set of bars to series at \a index postion. Takes ownership of \a set. If the set is null or is already in series, it won't be appended.
307 Returns true, if inserting succeeded.
307 Returns true, if inserting succeeded.
308
308
309 */
309 */
310 bool QAbstractBarSeries::insert(int index, QBarSet *set)
310 bool QAbstractBarSeries::insert(int index, QBarSet *set)
311 {
311 {
312 Q_D(QAbstractBarSeries);
312 Q_D(QAbstractBarSeries);
313 bool success = d->insert(index, set);
313 bool success = d->insert(index, set);
314 if (success) {
314 if (success) {
315 QList<QBarSet*> sets;
315 QList<QBarSet*> sets;
316 sets.append(set);
316 sets.append(set);
317 emit barsetsAdded(sets);
317 emit barsetsAdded(sets);
318 emit countChanged();
318 emit countChanged();
319 }
319 }
320 return success;
320 return success;
321 }
321 }
322
322
323 /*!
323 /*!
324 Removes all barsets from the series. Deletes removed sets.
324 Removes all barsets from the series. Deletes removed sets.
325 */
325 */
326 void QAbstractBarSeries::clear()
326 void QAbstractBarSeries::clear()
327 {
327 {
328 Q_D(QAbstractBarSeries);
328 Q_D(QAbstractBarSeries);
329 QList<QBarSet *> sets = barSets();
329 QList<QBarSet *> sets = barSets();
330 bool success = d->remove(sets);
330 bool success = d->remove(sets);
331 if (success) {
331 if (success) {
332 emit barsetsRemoved(sets);
332 emit barsetsRemoved(sets);
333 emit countChanged();
333 emit countChanged();
334 foreach (QBarSet* set, sets) {
334 foreach (QBarSet* set, sets) {
335 delete set;
335 delete set;
336 }
336 }
337 }
337 }
338 }
338 }
339
339
340 /*!
340 /*!
341 Returns number of sets in series.
341 Returns number of sets in series.
342 */
342 */
343 int QAbstractBarSeries::count() const
343 int QAbstractBarSeries::count() const
344 {
344 {
345 Q_D(const QAbstractBarSeries);
345 Q_D(const QAbstractBarSeries);
346 return d->m_barSets.count();
346 return d->m_barSets.count();
347 }
347 }
348
348
349 /*!
349 /*!
350 Returns a list of sets in series. Keeps ownership of sets.
350 Returns a list of sets in series. Keeps ownership of sets.
351 */
351 */
352 QList<QBarSet*> QAbstractBarSeries::barSets() const
352 QList<QBarSet*> QAbstractBarSeries::barSets() const
353 {
353 {
354 Q_D(const QAbstractBarSeries);
354 Q_D(const QAbstractBarSeries);
355 return d->m_barSets;
355 return d->m_barSets;
356 }
356 }
357
357
358 /*!
358 /*!
359 Sets the visibility of labels in series to \a visible
359 Sets the visibility of labels in series to \a visible
360 */
360 */
361 void QAbstractBarSeries::setLabelsVisible(bool visible)
361 void QAbstractBarSeries::setLabelsVisible(bool visible)
362 {
362 {
363 Q_D(QAbstractBarSeries);
363 Q_D(QAbstractBarSeries);
364 if (d->m_labelsVisible != visible) {
364 if (d->m_labelsVisible != visible) {
365 d->setLabelsVisible(visible);
365 d->setLabelsVisible(visible);
366 emit labelsVisibleChanged();
366 emit labelsVisibleChanged();
367 }
367 }
368 }
368 }
369
369
370 /*!
370 /*!
371 Returns the visibility of labels
371 Returns the visibility of labels
372 */
372 */
373 bool QAbstractBarSeries::isLabelsVisible() const
373 bool QAbstractBarSeries::isLabelsVisible() const
374 {
374 {
375 Q_D(const QAbstractBarSeries);
375 Q_D(const QAbstractBarSeries);
376 return d->m_labelsVisible;
376 return d->m_labelsVisible;
377 }
377 }
378
378
379 ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
379 ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
380
380
381 QAbstractBarSeriesPrivate::QAbstractBarSeriesPrivate(QAbstractBarSeries *q) :
381 QAbstractBarSeriesPrivate::QAbstractBarSeriesPrivate(QAbstractBarSeries *q) :
382 QAbstractSeriesPrivate(q),
382 QAbstractSeriesPrivate(q),
383 m_barWidth(0.5), // Default value is 50% of category width
383 m_barWidth(0.5), // Default value is 50% of category width
384 m_labelsVisible(false),
384 m_labelsVisible(false),
385 m_visible(true)
385 m_visible(true)
386 {
386 {
387 }
387 }
388
388
389 int QAbstractBarSeriesPrivate::categoryCount() const
389 int QAbstractBarSeriesPrivate::categoryCount() const
390 {
390 {
391 // No categories defined. return count of longest set.
391 // No categories defined. return count of longest set.
392 int count = 0;
392 int count = 0;
393 for (int i=0; i<m_barSets.count(); i++) {
393 for (int i=0; i<m_barSets.count(); i++) {
394 if (m_barSets.at(i)->count() > count) {
394 if (m_barSets.at(i)->count() > count) {
395 count = m_barSets.at(i)->count();
395 count = m_barSets.at(i)->count();
396 }
396 }
397 }
397 }
398
398
399 return count;
399 return count;
400 }
400 }
401
401
402 void QAbstractBarSeriesPrivate::setBarWidth(qreal width)
402 void QAbstractBarSeriesPrivate::setBarWidth(qreal width)
403 {
403 {
404 if (width < 0.0) {
404 if (width < 0.0) {
405 width = 0.0;
405 width = 0.0;
406 }
406 }
407 m_barWidth = width;
407 m_barWidth = width;
408 emit updatedLayout();
408 emit updatedLayout();
409 }
409 }
410
410
411 qreal QAbstractBarSeriesPrivate::barWidth() const
411 qreal QAbstractBarSeriesPrivate::barWidth() const
412 {
412 {
413 return m_barWidth;
413 return m_barWidth;
414 }
414 }
415
415
416 QBarSet* QAbstractBarSeriesPrivate::barsetAt(int index)
416 QBarSet* QAbstractBarSeriesPrivate::barsetAt(int index)
417 {
417 {
418 return m_barSets.at(index);
418 return m_barSets.at(index);
419 }
419 }
420
420
421 void QAbstractBarSeriesPrivate::setVisible(bool visible)
421 void QAbstractBarSeriesPrivate::setVisible(bool visible)
422 {
422 {
423 m_visible = visible;
423 m_visible = visible;
424 emit visibleChanged();
424 emit visibleChanged();
425 }
425 }
426
426
427 void QAbstractBarSeriesPrivate::setLabelsVisible(bool visible)
427 void QAbstractBarSeriesPrivate::setLabelsVisible(bool visible)
428 {
428 {
429 m_labelsVisible = visible;
429 m_labelsVisible = visible;
430 emit labelsVisibleChanged(visible);
430 emit labelsVisibleChanged(visible);
431 }
431 }
432
432
433 qreal QAbstractBarSeriesPrivate::min()
433 qreal QAbstractBarSeriesPrivate::min()
434 {
434 {
435 if (m_barSets.count() <= 0) {
435 if (m_barSets.count() <= 0) {
436 return 0;
436 return 0;
437 }
437 }
438 qreal min = INT_MAX;
438 qreal min = INT_MAX;
439
439
440 for (int i = 0; i < m_barSets.count(); i++) {
440 for (int i = 0; i < m_barSets.count(); i++) {
441 int categoryCount = m_barSets.at(i)->count();
441 int categoryCount = m_barSets.at(i)->count();
442 for (int j = 0; j < categoryCount; j++) {
442 for (int j = 0; j < categoryCount; j++) {
443 qreal temp = m_barSets.at(i)->at(j);
443 qreal temp = m_barSets.at(i)->at(j);
444 if (temp < min)
444 if (temp < min)
445 min = temp;
445 min = temp;
446 }
446 }
447 }
447 }
448 return min;
448 return min;
449 }
449 }
450
450
451 qreal QAbstractBarSeriesPrivate::max()
451 qreal QAbstractBarSeriesPrivate::max()
452 {
452 {
453 if (m_barSets.count() <= 0) {
453 if (m_barSets.count() <= 0) {
454 return 0;
454 return 0;
455 }
455 }
456 qreal max = INT_MIN;
456 qreal max = INT_MIN;
457
457
458 for (int i = 0; i < m_barSets.count(); i++) {
458 for (int i = 0; i < m_barSets.count(); i++) {
459 int categoryCount = m_barSets.at(i)->count();
459 int categoryCount = m_barSets.at(i)->count();
460 for (int j = 0; j < categoryCount; j++) {
460 for (int j = 0; j < categoryCount; j++) {
461 qreal temp = m_barSets.at(i)->at(j);
461 qreal temp = m_barSets.at(i)->at(j);
462 if (temp > max)
462 if (temp > max)
463 max = temp;
463 max = temp;
464 }
464 }
465 }
465 }
466
466
467 return max;
467 return max;
468 }
468 }
469
469
470 qreal QAbstractBarSeriesPrivate::valueAt(int set, int category)
470 qreal QAbstractBarSeriesPrivate::valueAt(int set, int category)
471 {
471 {
472 if ((set < 0) || (set >= m_barSets.count())) {
472 if ((set < 0) || (set >= m_barSets.count())) {
473 // No set, no value.
473 // No set, no value.
474 return 0;
474 return 0;
475 } else if ((category < 0) || (category >= m_barSets.at(set)->count())) {
475 } else if ((category < 0) || (category >= m_barSets.at(set)->count())) {
476 // No category, no value.
476 // No category, no value.
477 return 0;
477 return 0;
478 }
478 }
479
479
480 return m_barSets.at(set)->at(category);
480 return m_barSets.at(set)->at(category);
481 }
481 }
482
482
483 qreal QAbstractBarSeriesPrivate::percentageAt(int set, int category)
483 qreal QAbstractBarSeriesPrivate::percentageAt(int set, int category)
484 {
484 {
485 if ((set < 0) || (set >= m_barSets.count())) {
485 if ((set < 0) || (set >= m_barSets.count())) {
486 // No set, no value.
486 // No set, no value.
487 return 0;
487 return 0;
488 } else if ((category < 0) || (category >= m_barSets.at(set)->count())) {
488 } else if ((category < 0) || (category >= m_barSets.at(set)->count())) {
489 // No category, no value.
489 // No category, no value.
490 return 0;
490 return 0;
491 }
491 }
492
492
493 qreal value = m_barSets.at(set)->at(category);
493 qreal value = m_barSets.at(set)->at(category);
494 qreal sum = categorySum(category);
494 qreal sum = categorySum(category);
495 if ( qFuzzyIsNull(sum) ) {
495 if ( qFuzzyIsNull(sum) ) {
496 return 0;
496 return 0;
497 }
497 }
498
498
499 return value / sum;
499 return value / sum;
500 }
500 }
501
501
502 qreal QAbstractBarSeriesPrivate::categorySum(int category)
502 qreal QAbstractBarSeriesPrivate::categorySum(int category)
503 {
503 {
504 qreal sum(0);
504 qreal sum(0);
505 int count = m_barSets.count(); // Count sets
505 int count = m_barSets.count(); // Count sets
506 for (int set = 0; set < count; set++) {
506 for (int set = 0; set < count; set++) {
507 if (category < m_barSets.at(set)->count())
507 if (category < m_barSets.at(set)->count())
508 sum += m_barSets.at(set)->at(category);
508 sum += m_barSets.at(set)->at(category);
509 }
509 }
510 return sum;
510 return sum;
511 }
511 }
512
512
513 qreal QAbstractBarSeriesPrivate::absoluteCategorySum(int category)
513 qreal QAbstractBarSeriesPrivate::absoluteCategorySum(int category)
514 {
514 {
515 qreal sum(0);
515 qreal sum(0);
516 int count = m_barSets.count(); // Count sets
516 int count = m_barSets.count(); // Count sets
517 for (int set = 0; set < count; set++) {
517 for (int set = 0; set < count; set++) {
518 if (category < m_barSets.at(set)->count())
518 if (category < m_barSets.at(set)->count())
519 sum += qAbs(m_barSets.at(set)->at(category));
519 sum += qAbs(m_barSets.at(set)->at(category));
520 }
520 }
521 return sum;
521 return sum;
522 }
522 }
523
523
524 qreal QAbstractBarSeriesPrivate::maxCategorySum()
524 qreal QAbstractBarSeriesPrivate::maxCategorySum()
525 {
525 {
526 qreal max = INT_MIN;
526 qreal max = INT_MIN;
527 int count = categoryCount();
527 int count = categoryCount();
528 for (int i = 0; i < count; i++) {
528 for (int i = 0; i < count; i++) {
529 qreal sum = categorySum(i);
529 qreal sum = categorySum(i);
530 if (sum > max)
530 if (sum > max)
531 max = sum;
531 max = sum;
532 }
532 }
533 return max;
533 return max;
534 }
534 }
535
535
536 qreal QAbstractBarSeriesPrivate::minX()
536 qreal QAbstractBarSeriesPrivate::minX()
537 {
537 {
538 if (m_barSets.count() <= 0) {
538 if (m_barSets.count() <= 0) {
539 return 0;
539 return 0;
540 }
540 }
541 qreal min = INT_MAX;
541 qreal min = INT_MAX;
542
542
543 for (int i = 0; i < m_barSets.count(); i++) {
543 for (int i = 0; i < m_barSets.count(); i++) {
544 int categoryCount = m_barSets.at(i)->count();
544 int categoryCount = m_barSets.at(i)->count();
545 for (int j = 0; j < categoryCount; j++) {
545 for (int j = 0; j < categoryCount; j++) {
546 qreal temp = m_barSets.at(i)->d_ptr.data()->m_values.at(j).x();
546 qreal temp = m_barSets.at(i)->d_ptr.data()->m_values.at(j).x();
547 if (temp < min)
547 if (temp < min)
548 min = temp;
548 min = temp;
549 }
549 }
550 }
550 }
551 return min;
551 return min;
552 }
552 }
553
553
554 qreal QAbstractBarSeriesPrivate::maxX()
554 qreal QAbstractBarSeriesPrivate::maxX()
555 {
555 {
556 if (m_barSets.count() <= 0) {
556 if (m_barSets.count() <= 0) {
557 return 0;
557 return 0;
558 }
558 }
559 qreal max = INT_MIN;
559 qreal max = INT_MIN;
560
560
561 for (int i = 0; i < m_barSets.count(); i++) {
561 for (int i = 0; i < m_barSets.count(); i++) {
562 int categoryCount = m_barSets.at(i)->count();
562 int categoryCount = m_barSets.at(i)->count();
563 for (int j = 0; j < categoryCount; j++) {
563 for (int j = 0; j < categoryCount; j++) {
564 qreal temp = m_barSets.at(i)->d_ptr.data()->m_values.at(j).x();
564 qreal temp = m_barSets.at(i)->d_ptr.data()->m_values.at(j).x();
565 if (temp > max)
565 if (temp > max)
566 max = temp;
566 max = temp;
567 }
567 }
568 }
568 }
569
569
570 return max;
570 return max;
571 }
571 }
572
572
573 qreal QAbstractBarSeriesPrivate::categoryTop(int category)
573 qreal QAbstractBarSeriesPrivate::categoryTop(int category)
574 {
574 {
575 // Returns top (sum of all positive values) of category.
575 // Returns top (sum of all positive values) of category.
576 // Returns 0, if all values are negative
576 // Returns 0, if all values are negative
577 qreal top(0);
577 qreal top(0);
578 int count = m_barSets.count();
578 int count = m_barSets.count();
579 for (int set = 0; set < count; set++) {
579 for (int set = 0; set < count; set++) {
580 if (category < m_barSets.at(set)->count()) {
580 if (category < m_barSets.at(set)->count()) {
581 qreal temp = m_barSets.at(set)->at(category);
581 qreal temp = m_barSets.at(set)->at(category);
582 if (temp > 0) {
582 if (temp > 0) {
583 top += temp;
583 top += temp;
584 }
584 }
585 }
585 }
586 }
586 }
587 return top;
587 return top;
588 }
588 }
589
589
590 qreal QAbstractBarSeriesPrivate::categoryBottom(int category)
590 qreal QAbstractBarSeriesPrivate::categoryBottom(int category)
591 {
591 {
592 // Returns bottom (sum of all negative values) of category
592 // Returns bottom (sum of all negative values) of category
593 // Returns 0, if all values are positive
593 // Returns 0, if all values are positive
594 qreal bottom(0);
594 qreal bottom(0);
595 int count = m_barSets.count();
595 int count = m_barSets.count();
596 for (int set = 0; set < count; set++) {
596 for (int set = 0; set < count; set++) {
597 if (category < m_barSets.at(set)->count()) {
597 if (category < m_barSets.at(set)->count()) {
598 qreal temp = m_barSets.at(set)->at(category);
598 qreal temp = m_barSets.at(set)->at(category);
599 if (temp < 0) {
599 if (temp < 0) {
600 bottom += temp;
600 bottom += temp;
601 }
601 }
602 }
602 }
603 }
603 }
604 return bottom;
604 return bottom;
605 }
605 }
606
606
607 qreal QAbstractBarSeriesPrivate::top()
607 qreal QAbstractBarSeriesPrivate::top()
608 {
608 {
609 // Returns top of all categories
609 // Returns top of all categories
610 qreal top(0);
610 qreal top(0);
611 int count = categoryCount();
611 int count = categoryCount();
612 for (int i=0; i<count; i++) {
612 for (int i=0; i<count; i++) {
613 qreal temp = categoryTop(i);
613 qreal temp = categoryTop(i);
614 if (temp > top) {
614 if (temp > top) {
615 top = temp;
615 top = temp;
616 }
616 }
617 }
617 }
618 return top;
618 return top;
619 }
619 }
620
620
621 qreal QAbstractBarSeriesPrivate::bottom()
621 qreal QAbstractBarSeriesPrivate::bottom()
622 {
622 {
623 // Returns bottom of all categories
623 // Returns bottom of all categories
624 qreal bottom(0);
624 qreal bottom(0);
625 int count = categoryCount();
625 int count = categoryCount();
626 for (int i=0; i<count; i++) {
626 for (int i=0; i<count; i++) {
627 qreal temp = categoryBottom(i);
627 qreal temp = categoryBottom(i);
628 if (temp < bottom) {
628 if (temp < bottom) {
629 bottom = temp;
629 bottom = temp;
630 }
630 }
631 }
631 }
632 return bottom;
632 return bottom;
633 }
633 }
634
634
635
635
636 void QAbstractBarSeriesPrivate::scaleDomain(Domain& domain)
636 void QAbstractBarSeriesPrivate::scaleDomain(Domain& domain)
637 {
637 {
638 qreal minX(domain.minX());
638 qreal minX(domain.minX());
639 qreal minY(domain.minY());
639 qreal minY(domain.minY());
640 qreal maxX(domain.maxX());
640 qreal maxX(domain.maxX());
641 qreal maxY(domain.maxY());
641 qreal maxY(domain.maxY());
642
642
643 qreal seriesMinX = this->minX();
643 qreal seriesMinX = this->minX();
644 qreal seriesMaxX = this->maxX();
644 qreal seriesMaxX = this->maxX();
645 qreal y = max();
645 qreal y = max();
646 minX = qMin(minX, seriesMinX - (qreal)0.5);
646 minX = qMin(minX, seriesMinX - (qreal)0.5);
647 minY = qMin(minY, y);
647 minY = qMin(minY, y);
648 maxX = qMax(maxX, seriesMaxX + (qreal)0.5);
648 maxX = qMax(maxX, seriesMaxX + (qreal)0.5);
649 maxY = qMax(maxY, y);
649 maxY = qMax(maxY, y);
650
650
651 domain.setRange(minX,maxX,minY,maxY);
651 domain.setRange(minX,maxX,minY,maxY);
652 }
652 }
653
653
654 ChartElement* QAbstractBarSeriesPrivate::createGraphics(ChartPresenter* presenter)
654 ChartElement* QAbstractBarSeriesPrivate::createGraphics(ChartPresenter* presenter)
655 {
655 {
656 Q_UNUSED(presenter);
656 Q_UNUSED(presenter);
657 qWarning() << "QAbstractBarSeriesPrivate::createGraphics called";
657 qWarning() << "QAbstractBarSeriesPrivate::createGraphics called";
658 return 0;
658 return 0;
659 }
659 }
660
660
661 QList<LegendMarker*> QAbstractBarSeriesPrivate::createLegendMarker(QLegend* legend)
661 QList<LegendMarker*> QAbstractBarSeriesPrivate::createLegendMarker(QLegend* legend)
662 {
662 {
663 Q_Q(QAbstractBarSeries);
663 Q_Q(QAbstractBarSeries);
664 QList<LegendMarker*> markers;
664 QList<LegendMarker*> markers;
665 foreach(QBarSet* set, q->barSets()) {
665 foreach(QBarSet* set, q->barSets()) {
666 BarLegendMarker* marker = new BarLegendMarker(q,set,legend);
666 BarLegendMarker* marker = new BarLegendMarker(q,set,legend);
667 markers << marker;
667 markers << marker;
668 }
668 }
669
669
670 return markers;
670 return markers;
671 }
671 }
672
672
673 bool QAbstractBarSeriesPrivate::append(QBarSet *set)
673 bool QAbstractBarSeriesPrivate::append(QBarSet *set)
674 {
674 {
675 Q_Q(QAbstractBarSeries);
675 Q_Q(QAbstractBarSeries);
676 if ((m_barSets.contains(set)) || (set == 0)) {
676 if ((m_barSets.contains(set)) || (set == 0)) {
677 // Fail if set is already in list or set is null.
677 // Fail if set is already in list or set is null.
678 return false;
678 return false;
679 }
679 }
680 m_barSets.append(set);
680 m_barSets.append(set);
681 QObject::connect(set->d_ptr.data(), SIGNAL(updatedLayout()), this, SIGNAL(updatedLayout()));
681 QObject::connect(set->d_ptr.data(), SIGNAL(updatedLayout()), this, SIGNAL(updatedLayout()));
682 QObject::connect(set->d_ptr.data(), SIGNAL(updatedBars()), this, SIGNAL(updatedBars()));
682 QObject::connect(set->d_ptr.data(), SIGNAL(updatedBars()), this, SIGNAL(updatedBars()));
683 QObject::connect(set->d_ptr.data(), SIGNAL(restructuredBars()), this, SIGNAL(restructuredBars()));
683 QObject::connect(set->d_ptr.data(), SIGNAL(restructuredBars()), this, SIGNAL(restructuredBars()));
684 emit restructuredBars(); // this notifies barchartitem
684 emit restructuredBars(); // this notifies barchartitem
685 if (m_dataset) {
685 if (m_dataset) {
686 m_dataset->updateSeries(q); // this notifies legend
686 m_dataset->updateSeries(q); // this notifies legend
687 }
687 }
688 return true;
688 return true;
689 }
689 }
690
690
691 bool QAbstractBarSeriesPrivate::remove(QBarSet *set)
691 bool QAbstractBarSeriesPrivate::remove(QBarSet *set)
692 {
692 {
693 Q_Q(QAbstractBarSeries);
693 Q_Q(QAbstractBarSeries);
694 if (!m_barSets.contains(set)) {
694 if (!m_barSets.contains(set)) {
695 // Fail if set is not in list
695 // Fail if set is not in list
696 return false;
696 return false;
697 }
697 }
698 m_barSets.removeOne(set);
698 m_barSets.removeOne(set);
699 QObject::disconnect(set->d_ptr.data(), SIGNAL(updatedLayout()), this, SIGNAL(updatedLayout()));
699 QObject::disconnect(set->d_ptr.data(), SIGNAL(updatedLayout()), this, SIGNAL(updatedLayout()));
700 QObject::disconnect(set->d_ptr.data(), SIGNAL(updatedBars()), this, SIGNAL(updatedBars()));
700 QObject::disconnect(set->d_ptr.data(), SIGNAL(updatedBars()), this, SIGNAL(updatedBars()));
701 QObject::disconnect(set->d_ptr.data(), SIGNAL(restructuredBars()), this, SIGNAL(restructuredBars()));
701 QObject::disconnect(set->d_ptr.data(), SIGNAL(restructuredBars()), this, SIGNAL(restructuredBars()));
702 emit restructuredBars(); // this notifies barchartitem
702 emit restructuredBars(); // this notifies barchartitem
703 if (m_dataset) {
703 if (m_dataset) {
704 m_dataset->updateSeries(q); // this notifies legend
704 m_dataset->updateSeries(q); // this notifies legend
705 }
705 }
706 return true;
706 return true;
707 }
707 }
708
708
709 bool QAbstractBarSeriesPrivate::append(QList<QBarSet* > sets)
709 bool QAbstractBarSeriesPrivate::append(QList<QBarSet* > sets)
710 {
710 {
711 Q_Q(QAbstractBarSeries);
711 Q_Q(QAbstractBarSeries);
712 foreach (QBarSet* set, sets) {
712 foreach (QBarSet* set, sets) {
713 if ((set == 0) || (m_barSets.contains(set))) {
713 if ((set == 0) || (m_barSets.contains(set))) {
714 // Fail if any of the sets is null or is already appended.
714 // Fail if any of the sets is null or is already appended.
715 return false;
715 return false;
716 }
716 }
717 if (sets.count(set) != 1) {
717 if (sets.count(set) != 1) {
718 // Also fail if same set is more than once in given list.
718 // Also fail if same set is more than once in given list.
719 return false;
719 return false;
720 }
720 }
721 }
721 }
722
722
723 foreach (QBarSet* set, sets) {
723 foreach (QBarSet* set, sets) {
724 m_barSets.append(set);
724 m_barSets.append(set);
725 QObject::connect(set->d_ptr.data(), SIGNAL(updatedLayout()), this, SIGNAL(updatedLayout()));
725 QObject::connect(set->d_ptr.data(), SIGNAL(updatedLayout()), this, SIGNAL(updatedLayout()));
726 QObject::connect(set->d_ptr.data(), SIGNAL(updatedBars()), this, SIGNAL(updatedBars()));
726 QObject::connect(set->d_ptr.data(), SIGNAL(updatedBars()), this, SIGNAL(updatedBars()));
727 QObject::connect(set->d_ptr.data(), SIGNAL(restructuredBars()), this, SIGNAL(restructuredBars()));
727 QObject::connect(set->d_ptr.data(), SIGNAL(restructuredBars()), this, SIGNAL(restructuredBars()));
728 }
728 }
729 emit restructuredBars(); // this notifies barchartitem
729 emit restructuredBars(); // this notifies barchartitem
730 if (m_dataset) {
730 if (m_dataset) {
731 m_dataset->updateSeries(q); // this notifies legend
731 m_dataset->updateSeries(q); // this notifies legend
732 }
732 }
733 return true;
733 return true;
734 }
734 }
735
735
736 bool QAbstractBarSeriesPrivate::remove(QList<QBarSet* > sets)
736 bool QAbstractBarSeriesPrivate::remove(QList<QBarSet* > sets)
737 {
737 {
738 Q_Q(QAbstractBarSeries);
738 Q_Q(QAbstractBarSeries);
739 if (sets.count() == 0) {
739 if (sets.count() == 0) {
740 return false;
740 return false;
741 }
741 }
742 foreach (QBarSet* set, sets) {
742 foreach (QBarSet* set, sets) {
743 if ((set == 0) || (!m_barSets.contains(set))) {
743 if ((set == 0) || (!m_barSets.contains(set))) {
744 // Fail if any of the sets is null or is not in series
744 // Fail if any of the sets is null or is not in series
745 return false;
745 return false;
746 }
746 }
747 if (sets.count(set) != 1) {
747 if (sets.count(set) != 1) {
748 // Also fail if same set is more than once in given list.
748 // Also fail if same set is more than once in given list.
749 return false;
749 return false;
750 }
750 }
751 }
751 }
752
752
753 foreach (QBarSet* set, sets) {
753 foreach (QBarSet* set, sets) {
754 m_barSets.removeOne(set);
754 m_barSets.removeOne(set);
755 QObject::disconnect(set->d_ptr.data(), SIGNAL(updatedLayout()), this, SIGNAL(updatedLayout()));
755 QObject::disconnect(set->d_ptr.data(), SIGNAL(updatedLayout()), this, SIGNAL(updatedLayout()));
756 QObject::disconnect(set->d_ptr.data(), SIGNAL(updatedBars()), this, SIGNAL(updatedBars()));
756 QObject::disconnect(set->d_ptr.data(), SIGNAL(updatedBars()), this, SIGNAL(updatedBars()));
757 QObject::disconnect(set->d_ptr.data(), SIGNAL(restructuredBars()), this, SIGNAL(restructuredBars()));
757 QObject::disconnect(set->d_ptr.data(), SIGNAL(restructuredBars()), this, SIGNAL(restructuredBars()));
758 }
758 }
759
759
760 emit restructuredBars(); // this notifies barchartitem
760 emit restructuredBars(); // this notifies barchartitem
761 if (m_dataset) {
761 if (m_dataset) {
762 m_dataset->updateSeries(q); // this notifies legend
762 m_dataset->updateSeries(q); // this notifies legend
763 }
763 }
764 return true;
764 return true;
765 }
765 }
766
766
767 bool QAbstractBarSeriesPrivate::insert(int index, QBarSet *set)
767 bool QAbstractBarSeriesPrivate::insert(int index, QBarSet *set)
768 {
768 {
769 Q_Q(QAbstractBarSeries);
769 Q_Q(QAbstractBarSeries);
770 if ((m_barSets.contains(set)) || (set == 0)) {
770 if ((m_barSets.contains(set)) || (set == 0)) {
771 // Fail if set is already in list or set is null.
771 // Fail if set is already in list or set is null.
772 return false;
772 return false;
773 }
773 }
774 m_barSets.insert(index, set);
774 m_barSets.insert(index, set);
775 QObject::connect(set->d_ptr.data(), SIGNAL(updatedLayout()), this, SIGNAL(updatedLayout()));
775 QObject::connect(set->d_ptr.data(), SIGNAL(updatedLayout()), this, SIGNAL(updatedLayout()));
776 QObject::connect(set->d_ptr.data(), SIGNAL(updatedBars()), this, SIGNAL(updatedBars()));
776 QObject::connect(set->d_ptr.data(), SIGNAL(updatedBars()), this, SIGNAL(updatedBars()));
777 QObject::connect(set->d_ptr.data(), SIGNAL(restructuredBars()), this, SIGNAL(restructuredBars()));
777 QObject::connect(set->d_ptr.data(), SIGNAL(restructuredBars()), this, SIGNAL(restructuredBars()));
778 emit restructuredBars(); // this notifies barchartitem
778 emit restructuredBars(); // this notifies barchartitem
779 if (m_dataset) {
779 if (m_dataset) {
780 m_dataset->updateSeries(q); // this notifies legend
780 m_dataset->updateSeries(q); // this notifies legend
781 }
781 }
782 return true;
782 return true;
783 }
783 }
784
784
785 void QAbstractBarSeriesPrivate::initializeAxis(QAbstractAxis* axis)
785 void QAbstractBarSeriesPrivate::initializeAxis(QAbstractAxis* axis)
786 {
786 {
787 Q_Q(QAbstractBarSeries);
787 Q_Q(QAbstractBarSeries);
788
788
789 if(axis->type()==QAbstractAxis::AxisTypeBarCategory) {
789 if(axis->type()==QAbstractAxis::AxisTypeBarCategory) {
790
790
791 switch(q->type()) {
791 switch(q->type()) {
792
792
793 case QAbstractSeries::SeriesTypeHorizontalBar:
793 case QAbstractSeries::SeriesTypeHorizontalBar:
794 case QAbstractSeries::SeriesTypeHorizontalPercentBar:
794 case QAbstractSeries::SeriesTypeHorizontalPercentBar:
795 case QAbstractSeries::SeriesTypeHorizontalStackedBar: {
795 case QAbstractSeries::SeriesTypeHorizontalStackedBar: {
796
796
797 if(axis->orientation()==Qt::Vertical)
797 if(axis->orientation()==Qt::Vertical)
798 {
798 {
799 populateCategories(qobject_cast<QBarCategoryAxis*>(axis));
799 populateCategories(qobject_cast<QBarCategoryAxis*>(axis));
800 }
800 }
801 break;
801 break;
802 }
802 }
803 case QAbstractSeries::SeriesTypeBar:
803 case QAbstractSeries::SeriesTypeBar:
804 case QAbstractSeries::SeriesTypePercentBar:
804 case QAbstractSeries::SeriesTypePercentBar:
805 case QAbstractSeries::SeriesTypeStackedBar: {
805 case QAbstractSeries::SeriesTypeStackedBar: {
806
806
807 if(axis->orientation()==Qt::Horizontal)
807 if(axis->orientation()==Qt::Horizontal)
808 {
808 {
809 populateCategories(qobject_cast<QBarCategoryAxis*>(axis));
809 populateCategories(qobject_cast<QBarCategoryAxis*>(axis));
810 }
810 }
811 break;
811 break;
812 }
812 }
813 default:
813 default:
814 qWarning()<<"Unexpected series type";
814 qWarning()<<"Unexpected series type";
815 break;
815 break;
816
816
817 }
817 }
818 }
818 }
819 }
819 }
820
820
821 QAbstractAxis::AxisType QAbstractBarSeriesPrivate::defaultAxisType(Qt::Orientation orientation) const
821 QAbstractAxis::AxisType QAbstractBarSeriesPrivate::defaultAxisType(Qt::Orientation orientation) const
822 {
822 {
823 Q_Q(const QAbstractBarSeries);
823 Q_Q(const QAbstractBarSeries);
824
824
825 switch(q->type()) {
825 switch(q->type()) {
826
826
827 case QAbstractSeries::SeriesTypeHorizontalBar:
827 case QAbstractSeries::SeriesTypeHorizontalBar:
828 case QAbstractSeries::SeriesTypeHorizontalPercentBar:
828 case QAbstractSeries::SeriesTypeHorizontalPercentBar:
829 case QAbstractSeries::SeriesTypeHorizontalStackedBar: {
829 case QAbstractSeries::SeriesTypeHorizontalStackedBar: {
830
830
831 if(orientation==Qt::Vertical)
831 if(orientation==Qt::Vertical)
832 {
832 {
833 return QAbstractAxis::AxisTypeBarCategory;
833 return QAbstractAxis::AxisTypeBarCategory;
834 }
834 }
835 break;
835 break;
836 }
836 }
837 case QAbstractSeries::SeriesTypeBar:
837 case QAbstractSeries::SeriesTypeBar:
838 case QAbstractSeries::SeriesTypePercentBar:
838 case QAbstractSeries::SeriesTypePercentBar:
839 case QAbstractSeries::SeriesTypeStackedBar: {
839 case QAbstractSeries::SeriesTypeStackedBar: {
840
840
841 if(orientation==Qt::Horizontal)
841 if(orientation==Qt::Horizontal)
842 {
842 {
843 return QAbstractAxis::AxisTypeBarCategory;
843 return QAbstractAxis::AxisTypeBarCategory;
844 }
844 }
845 break;
845 break;
846 }
846 }
847 default:
847 default:
848 qWarning()<<"Unexpected series type";
848 qWarning()<<"Unexpected series type";
849 break;
849 break;
850
850
851 }
851 }
852 return QAbstractAxis::AxisTypeValue;
852 return QAbstractAxis::AxisTypeValue;
853
853
854 }
854 }
855
855
856 void QAbstractBarSeriesPrivate::populateCategories(QBarCategoryAxis* axis)
856 void QAbstractBarSeriesPrivate::populateCategories(QBarCategoryAxis* axis)
857 {
857 {
858 QStringList categories;
858 QStringList categories;
859 if(axis->categories().isEmpty()) {
859 if(axis->categories().isEmpty()) {
860 for (int i(1); i < categoryCount()+1; i++)
860 for (int i(1); i < categoryCount()+1; i++)
861 categories << QString::number(i);
861 categories << QString::number(i);
862 axis->append(categories);
862 axis->append(categories);
863 }
863 }
864 }
864 }
865
865
866 #include "moc_qabstractbarseries.cpp"
866 #include "moc_qabstractbarseries.cpp"
867 #include "moc_qabstractbarseries_p.cpp"
867 #include "moc_qabstractbarseries_p.cpp"
868
868
869
869
870 QTCOMMERCIALCHART_END_NAMESPACE
870 QTCOMMERCIALCHART_END_NAMESPACE
@@ -1,569 +1,569
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 "qbarmodelmapper.h"
21 #include "qbarmodelmapper.h"
22 #include "qbarmodelmapper_p.h"
22 #include "qbarmodelmapper_p.h"
23 #include "qabstractbarseries.h"
23 #include "qabstractbarseries.h"
24 #include "qbarset.h"
24 #include "qbarset.h"
25 #include "qchart.h"
25 #include "qchart.h"
26 #include <QAbstractItemModel>
26 #include <QAbstractItemModel>
27
27
28 QTCOMMERCIALCHART_BEGIN_NAMESPACE
28 QTCOMMERCIALCHART_BEGIN_NAMESPACE
29
29
30 QBarModelMapper::QBarModelMapper(QObject *parent) :
30 QBarModelMapper::QBarModelMapper(QObject *parent) :
31 QObject(parent),
31 QObject(parent),
32 d_ptr(new QBarModelMapperPrivate(this))
32 d_ptr(new QBarModelMapperPrivate(this))
33 {
33 {
34 }
34 }
35
35
36 QAbstractItemModel* QBarModelMapper::model() const
36 QAbstractItemModel* QBarModelMapper::model() const
37 {
37 {
38 Q_D(const QBarModelMapper);
38 Q_D(const QBarModelMapper);
39 return d->m_model;
39 return d->m_model;
40 }
40 }
41
41
42 void QBarModelMapper::setModel(QAbstractItemModel *model)
42 void QBarModelMapper::setModel(QAbstractItemModel *model)
43 {
43 {
44 if (model == 0)
44 if (model == 0)
45 return;
45 return;
46
46
47 Q_D(QBarModelMapper);
47 Q_D(QBarModelMapper);
48 if (d->m_model) {
48 if (d->m_model) {
49 disconnect(d->m_model, 0, d, 0);
49 disconnect(d->m_model, 0, d, 0);
50 }
50 }
51
51
52 d->m_model = model;
52 d->m_model = model;
53 d->initializeBarFromModel();
53 d->initializeBarFromModel();
54 // connect signals from the model
54 // connect signals from the model
55 connect(d->m_model, SIGNAL(dataChanged(QModelIndex,QModelIndex)), d, SLOT(modelUpdated(QModelIndex,QModelIndex)));
55 connect(d->m_model, SIGNAL(dataChanged(QModelIndex,QModelIndex)), d, SLOT(modelUpdated(QModelIndex,QModelIndex)));
56 connect(d->m_model, SIGNAL(headerDataChanged(Qt::Orientation,int,int)), d, SLOT(modelHeaderDataUpdated(Qt::Orientation,int,int)));
56 connect(d->m_model, SIGNAL(headerDataChanged(Qt::Orientation,int,int)), d, SLOT(modelHeaderDataUpdated(Qt::Orientation,int,int)));
57 connect(d->m_model, SIGNAL(rowsInserted(QModelIndex,int,int)), d, SLOT(modelRowsAdded(QModelIndex,int,int)));
57 connect(d->m_model, SIGNAL(rowsInserted(QModelIndex,int,int)), d, SLOT(modelRowsAdded(QModelIndex,int,int)));
58 connect(d->m_model, SIGNAL(rowsRemoved(QModelIndex,int,int)), d, SLOT(modelRowsRemoved(QModelIndex,int,int)));
58 connect(d->m_model, SIGNAL(rowsRemoved(QModelIndex,int,int)), d, SLOT(modelRowsRemoved(QModelIndex,int,int)));
59 connect(d->m_model, SIGNAL(columnsInserted(QModelIndex,int,int)), d, SLOT(modelColumnsAdded(QModelIndex,int,int)));
59 connect(d->m_model, SIGNAL(columnsInserted(QModelIndex,int,int)), d, SLOT(modelColumnsAdded(QModelIndex,int,int)));
60 connect(d->m_model, SIGNAL(columnsRemoved(QModelIndex,int,int)), d, SLOT(modelColumnsRemoved(QModelIndex,int,int)));
60 connect(d->m_model, SIGNAL(columnsRemoved(QModelIndex,int,int)), d, SLOT(modelColumnsRemoved(QModelIndex,int,int)));
61 connect(d->m_model, SIGNAL(destroyed()), d, SLOT(handleModelDestroyed()));
61 connect(d->m_model, SIGNAL(destroyed()), d, SLOT(handleModelDestroyed()));
62 }
62 }
63
63
64 QAbstractBarSeries* QBarModelMapper::series() const
64 QAbstractBarSeries* QBarModelMapper::series() const
65 {
65 {
66 Q_D(const QBarModelMapper);
66 Q_D(const QBarModelMapper);
67 return d->m_series;
67 return d->m_series;
68 }
68 }
69
69
70 void QBarModelMapper::setSeries(QAbstractBarSeries *series)
70 void QBarModelMapper::setSeries(QAbstractBarSeries *series)
71 {
71 {
72 Q_D(QBarModelMapper);
72 Q_D(QBarModelMapper);
73 if (d->m_series) {
73 if (d->m_series) {
74 disconnect(d->m_series, 0, d, 0);
74 disconnect(d->m_series, 0, d, 0);
75 }
75 }
76
76
77 if (series == 0)
77 if (series == 0)
78 return;
78 return;
79
79
80 d->m_series = series;
80 d->m_series = series;
81 d->initializeBarFromModel();
81 d->initializeBarFromModel();
82 // connect the signals from the series
82 // connect the signals from the series
83 connect(d->m_series, SIGNAL(barsetsAdded(QList<QBarSet*>)), d, SLOT(barSetsAdded(QList<QBarSet*>)));
83 connect(d->m_series, SIGNAL(barsetsAdded(QList<QBarSet*>)), d, SLOT(barSetsAdded(QList<QBarSet*>)));
84 connect(d->m_series, SIGNAL(barsetsRemoved(QList<QBarSet*>)), d, SLOT(barSetsRemoved(QList<QBarSet*>)));
84 connect(d->m_series, SIGNAL(barsetsRemoved(QList<QBarSet*>)), d, SLOT(barSetsRemoved(QList<QBarSet*>)));
85 connect(d->m_series, SIGNAL(destroyed()), d, SLOT(handleSeriesDestroyed()));
85 connect(d->m_series, SIGNAL(destroyed()), d, SLOT(handleSeriesDestroyed()));
86 }
86 }
87
87
88 /*!
88 /*!
89 Returns which row/column of the model contains the first values of the QBarSets in the series.
89 Returns which row/column of the model contains the first values of the QBarSets in the series.
90 The default value is 0.
90 The default value is 0.
91 */
91 */
92 int QBarModelMapper::first() const
92 int QBarModelMapper::first() const
93 {
93 {
94 Q_D(const QBarModelMapper);
94 Q_D(const QBarModelMapper);
95 return d->m_first;
95 return d->m_first;
96 }
96 }
97
97
98 /*!
98 /*!
99 Sets which row of the model contains the \a first values of the QBarSets in the series.
99 Sets which row of the model contains the \a first values of the QBarSets in the series.
100 The default value is 0.
100 The default value is 0.
101 */
101 */
102 void QBarModelMapper::setFirst(int first)
102 void QBarModelMapper::setFirst(int first)
103 {
103 {
104 Q_D(QBarModelMapper);
104 Q_D(QBarModelMapper);
105 d->m_first = qMax(first, 0);
105 d->m_first = qMax(first, 0);
106 d->initializeBarFromModel();
106 d->initializeBarFromModel();
107 }
107 }
108
108
109 /*!
109 /*!
110 Returns the number of rows/columns of the model that are mapped as the data for QAbstractBarSeries
110 Returns the number of rows/columns of the model that are mapped as the data for QAbstractBarSeries
111 Minimal and default value is: -1 (count limited by the number of rows/columns in the model)
111 Minimal and default value is: -1 (count limited by the number of rows/columns in the model)
112 */
112 */
113 int QBarModelMapper::count() const
113 int QBarModelMapper::count() const
114 {
114 {
115 Q_D(const QBarModelMapper);
115 Q_D(const QBarModelMapper);
116 return d->m_count;
116 return d->m_count;
117 }
117 }
118
118
119 /*!
119 /*!
120 Sets the \a count of rows/columns of the model that are mapped as the data for QAbstractBarSeries
120 Sets the \a count of rows/columns of the model that are mapped as the data for QAbstractBarSeries
121 Minimal and default value is: -1 (count limited by the number of rows/columns in the model)
121 Minimal and default value is: -1 (count limited by the number of rows/columns in the model)
122 */
122 */
123 void QBarModelMapper::setCount(int count)
123 void QBarModelMapper::setCount(int count)
124 {
124 {
125 Q_D(QBarModelMapper);
125 Q_D(QBarModelMapper);
126 d->m_count = qMax(count, -1);
126 d->m_count = qMax(count, -1);
127 d->initializeBarFromModel();
127 d->initializeBarFromModel();
128 }
128 }
129
129
130 /*!
130 /*!
131 Returns the orientation that is used when QBarModelMapper accesses the model.
131 Returns the orientation that is used when QBarModelMapper accesses the model.
132 This mean whether the consecutive values of the bar set are read from row (Qt::Horizontal)
132 This mean whether the consecutive values of the bar set are read from row (Qt::Horizontal)
133 or from columns (Qt::Vertical)
133 or from columns (Qt::Vertical)
134 */
134 */
135 Qt::Orientation QBarModelMapper::orientation() const
135 Qt::Orientation QBarModelMapper::orientation() const
136 {
136 {
137 Q_D(const QBarModelMapper);
137 Q_D(const QBarModelMapper);
138 return d->m_orientation;
138 return d->m_orientation;
139 }
139 }
140
140
141 /*!
141 /*!
142 Returns the \a orientation that is used when QBarModelMapper accesses the model.
142 Returns the \a orientation that is used when QBarModelMapper accesses the model.
143 This mean whether the consecutive values of the pie are read from row (Qt::Horizontal)
143 This mean whether the consecutive values of the pie are read from row (Qt::Horizontal)
144 or from columns (Qt::Vertical)
144 or from columns (Qt::Vertical)
145 */
145 */
146 void QBarModelMapper::setOrientation(Qt::Orientation orientation)
146 void QBarModelMapper::setOrientation(Qt::Orientation orientation)
147 {
147 {
148 Q_D(QBarModelMapper);
148 Q_D(QBarModelMapper);
149 d->m_orientation = orientation;
149 d->m_orientation = orientation;
150 d->initializeBarFromModel();
150 d->initializeBarFromModel();
151 }
151 }
152
152
153 /*!
153 /*!
154 Returns which section of the model is used as the data source for the first bar set
154 Returns which section of the model is used as the data source for the first bar set
155 */
155 */
156 int QBarModelMapper::firstBarSetSection() const
156 int QBarModelMapper::firstBarSetSection() const
157 {
157 {
158 Q_D(const QBarModelMapper);
158 Q_D(const QBarModelMapper);
159 return d->m_firstBarSetSection;
159 return d->m_firstBarSetSection;
160 }
160 }
161
161
162 /*!
162 /*!
163 Sets the model section that is used as the data source for the first bar set
163 Sets the model section that is used as the data source for the first bar set
164 Parameter \a firstBarSetSection specifies the section of the model.
164 Parameter \a firstBarSetSection specifies the section of the model.
165 */
165 */
166 void QBarModelMapper::setFirstBarSetSection(int firstBarSetSection)
166 void QBarModelMapper::setFirstBarSetSection(int firstBarSetSection)
167 {
167 {
168 Q_D(QBarModelMapper);
168 Q_D(QBarModelMapper);
169 d->m_firstBarSetSection = qMax(-1, firstBarSetSection);
169 d->m_firstBarSetSection = qMax(-1, firstBarSetSection);
170 d->initializeBarFromModel();
170 d->initializeBarFromModel();
171 }
171 }
172
172
173 /*!
173 /*!
174 Returns which section of the model is used as the data source for the last bar set
174 Returns which section of the model is used as the data source for the last bar set
175 */
175 */
176 int QBarModelMapper::lastBarSetSection() const
176 int QBarModelMapper::lastBarSetSection() const
177 {
177 {
178 Q_D(const QBarModelMapper);
178 Q_D(const QBarModelMapper);
179 return d->m_lastBarSetSection;
179 return d->m_lastBarSetSection;
180 }
180 }
181
181
182 /*!
182 /*!
183 Sets the model section that is used as the data source for the last bar set
183 Sets the model section that is used as the data source for the last bar set
184 Parameter \a lastBarSetSection specifies the section of the model.
184 Parameter \a lastBarSetSection specifies the section of the model.
185 */
185 */
186 void QBarModelMapper::setLastBarSetSection(int lastBarSetSection)
186 void QBarModelMapper::setLastBarSetSection(int lastBarSetSection)
187 {
187 {
188 Q_D(QBarModelMapper);
188 Q_D(QBarModelMapper);
189 d->m_lastBarSetSection = qMax(-1, lastBarSetSection);
189 d->m_lastBarSetSection = qMax(-1, lastBarSetSection);
190 d->initializeBarFromModel();
190 d->initializeBarFromModel();
191 }
191 }
192
192
193 ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
193 ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
194
194
195 QBarModelMapperPrivate::QBarModelMapperPrivate(QBarModelMapper *q) :
195 QBarModelMapperPrivate::QBarModelMapperPrivate(QBarModelMapper *q) :
196 QObject(q),
196 QObject(q),
197 m_series(0),
197 m_series(0),
198 m_model(0),
198 m_model(0),
199 m_first(0),
199 m_first(0),
200 m_count(-1),
200 m_count(-1),
201 m_orientation(Qt::Vertical),
201 m_orientation(Qt::Vertical),
202 m_firstBarSetSection(-1),
202 m_firstBarSetSection(-1),
203 m_lastBarSetSection(-1),
203 m_lastBarSetSection(-1),
204 m_seriesSignalsBlock(false),
204 m_seriesSignalsBlock(false),
205 m_modelSignalsBlock(false),
205 m_modelSignalsBlock(false),
206 q_ptr(q)
206 q_ptr(q)
207 {
207 {
208 }
208 }
209
209
210 void QBarModelMapperPrivate::blockModelSignals(bool block)
210 void QBarModelMapperPrivate::blockModelSignals(bool block)
211 {
211 {
212 m_modelSignalsBlock = block;
212 m_modelSignalsBlock = block;
213 }
213 }
214
214
215 void QBarModelMapperPrivate::blockSeriesSignals(bool block)
215 void QBarModelMapperPrivate::blockSeriesSignals(bool block)
216 {
216 {
217 m_seriesSignalsBlock = block;
217 m_seriesSignalsBlock = block;
218 }
218 }
219
219
220 QBarSet* QBarModelMapperPrivate::barSet(QModelIndex index)
220 QBarSet* QBarModelMapperPrivate::barSet(QModelIndex index)
221 {
221 {
222 if (!index.isValid())
222 if (!index.isValid())
223 return 0;
223 return 0;
224
224
225 if (m_orientation == Qt::Vertical && index.column() >= m_firstBarSetSection && index.column() <= m_lastBarSetSection) {
225 if (m_orientation == Qt::Vertical && index.column() >= m_firstBarSetSection && index.column() <= m_lastBarSetSection) {
226 if (index.row() >= m_first && (m_count == - 1 || index.row() < m_first + m_count)) {
226 if (index.row() >= m_first && (m_count == - 1 || index.row() < m_first + m_count)) {
227 // if (m_model->index(index.row(), m_valuesSection).isValid() && m_model->index(index.row(), m_labelsSection).isValid())
227 // if (m_model->index(index.row(), m_valuesSection).isValid() && m_model->index(index.row(), m_labelsSection).isValid())
228 return m_series->barSets().at(index.column() - m_firstBarSetSection);
228 return m_series->barSets().at(index.column() - m_firstBarSetSection);
229 // else
229 // else
230 // return 0;
230 // return 0;
231 }
231 }
232 } else if (m_orientation == Qt::Horizontal && index.row() >= m_firstBarSetSection && index.row() <= m_lastBarSetSection) {
232 } else if (m_orientation == Qt::Horizontal && index.row() >= m_firstBarSetSection && index.row() <= m_lastBarSetSection) {
233 if (index.column() >= m_first && (m_count == - 1 || index.column() < m_first + m_count))
233 if (index.column() >= m_first && (m_count == - 1 || index.column() < m_first + m_count))
234 return m_series->barSets().at(index.row() - m_firstBarSetSection);
234 return m_series->barSets().at(index.row() - m_firstBarSetSection);
235 }
235 }
236 return 0; // This part of model has not been mapped to any slice
236 return 0; // This part of model has not been mapped to any slice
237 }
237 }
238
238
239 QModelIndex QBarModelMapperPrivate::barModelIndex(int barSection, int posInBar)
239 QModelIndex QBarModelMapperPrivate::barModelIndex(int barSection, int posInBar)
240 {
240 {
241 if (m_count != -1 && posInBar >= m_count)
241 if (m_count != -1 && posInBar >= m_count)
242 return QModelIndex(); // invalid
242 return QModelIndex(); // invalid
243
243
244 if (barSection < m_firstBarSetSection || barSection > m_lastBarSetSection)
244 if (barSection < m_firstBarSetSection || barSection > m_lastBarSetSection)
245 return QModelIndex(); // invalid
245 return QModelIndex(); // invalid
246
246
247 if (m_orientation == Qt::Vertical)
247 if (m_orientation == Qt::Vertical)
248 return m_model->index(posInBar + m_first, barSection);
248 return m_model->index(posInBar + m_first, barSection);
249 else
249 else
250 return m_model->index(barSection, posInBar + m_first);
250 return m_model->index(barSection, posInBar + m_first);
251 }
251 }
252
252
253 void QBarModelMapperPrivate::handleSeriesDestroyed()
253 void QBarModelMapperPrivate::handleSeriesDestroyed()
254 {
254 {
255 m_series = 0;
255 m_series = 0;
256 }
256 }
257
257
258 void QBarModelMapperPrivate::modelUpdated(QModelIndex topLeft, QModelIndex bottomRight)
258 void QBarModelMapperPrivate::modelUpdated(QModelIndex topLeft, QModelIndex bottomRight)
259 {
259 {
260 Q_UNUSED(topLeft)
260 Q_UNUSED(topLeft)
261 Q_UNUSED(bottomRight)
261 Q_UNUSED(bottomRight)
262
262
263 if (m_model == 0 || m_series == 0)
263 if (m_model == 0 || m_series == 0)
264 return;
264 return;
265
265
266 if (m_modelSignalsBlock)
266 if (m_modelSignalsBlock)
267 return;
267 return;
268
268
269 blockSeriesSignals();
269 blockSeriesSignals();
270 QModelIndex index;
270 QModelIndex index;
271 for (int row = topLeft.row(); row <= bottomRight.row(); row++) {
271 for (int row = topLeft.row(); row <= bottomRight.row(); row++) {
272 for (int column = topLeft.column(); column <= bottomRight.column(); column++) {
272 for (int column = topLeft.column(); column <= bottomRight.column(); column++) {
273 index = topLeft.sibling(row, column);
273 index = topLeft.sibling(row, column);
274 QBarSet* bar = barSet(index);
274 QBarSet* bar = barSet(index);
275 if (bar) {
275 if (bar) {
276 if (m_orientation == Qt::Vertical)
276 if (m_orientation == Qt::Vertical)
277 bar->replace(row - m_first, m_model->data(index).toReal());
277 bar->replace(row - m_first, m_model->data(index).toReal());
278 else
278 else
279 bar->replace(column - m_first, m_model->data(index).toReal());
279 bar->replace(column - m_first, m_model->data(index).toReal());
280 }
280 }
281 }
281 }
282 }
282 }
283 blockSeriesSignals(false);
283 blockSeriesSignals(false);
284 }
284 }
285
285
286 void QBarModelMapperPrivate::modelHeaderDataUpdated(Qt::Orientation orientation, int first, int last)
286 void QBarModelMapperPrivate::modelHeaderDataUpdated(Qt::Orientation orientation, int first, int last)
287 {
287 {
288 if (m_model == 0 || m_series == 0)
288 if (m_model == 0 || m_series == 0)
289 return;
289 return;
290
290
291 if (m_modelSignalsBlock)
291 if (m_modelSignalsBlock)
292 return;
292 return;
293
293
294 blockSeriesSignals();
294 blockSeriesSignals();
295 if (orientation != m_orientation) {
295 if (orientation != m_orientation) {
296 for (int section = first; section <= last; section++) {
296 for (int section = first; section <= last; section++) {
297 if (section >= m_firstBarSetSection && section <= m_lastBarSetSection) {
297 if (section >= m_firstBarSetSection && section <= m_lastBarSetSection) {
298 QBarSet* bar = m_series->barSets().at(section - m_firstBarSetSection);
298 QBarSet* bar = m_series->barSets().at(section - m_firstBarSetSection);
299 if (bar)
299 if (bar)
300 bar->setLabel(m_model->headerData(section, orientation).toString());
300 bar->setLabel(m_model->headerData(section, orientation).toString());
301 }
301 }
302 }
302 }
303 }
303 }
304 blockSeriesSignals(false);
304 blockSeriesSignals(false);
305 }
305 }
306
306
307 void QBarModelMapperPrivate::modelRowsAdded(QModelIndex parent, int start, int end)
307 void QBarModelMapperPrivate::modelRowsAdded(QModelIndex parent, int start, int end)
308 {
308 {
309 Q_UNUSED(parent);
309 Q_UNUSED(parent);
310 Q_UNUSED(end)
310 Q_UNUSED(end)
311 if (m_modelSignalsBlock)
311 if (m_modelSignalsBlock)
312 return;
312 return;
313
313
314 blockSeriesSignals();
314 blockSeriesSignals();
315 if (m_orientation == Qt::Vertical)
315 if (m_orientation == Qt::Vertical)
316 // insertData(start, end);
316 // insertData(start, end);
317 initializeBarFromModel();
317 initializeBarFromModel();
318 else if (start <= m_firstBarSetSection || start <= m_lastBarSetSection) // if the changes affect the map - reinitialize
318 else if (start <= m_firstBarSetSection || start <= m_lastBarSetSection) // if the changes affect the map - reinitialize
319 initializeBarFromModel();
319 initializeBarFromModel();
320 blockSeriesSignals(false);
320 blockSeriesSignals(false);
321 }
321 }
322
322
323 void QBarModelMapperPrivate::modelRowsRemoved(QModelIndex parent, int start, int end)
323 void QBarModelMapperPrivate::modelRowsRemoved(QModelIndex parent, int start, int end)
324 {
324 {
325 Q_UNUSED(parent);
325 Q_UNUSED(parent);
326 Q_UNUSED(end)
326 Q_UNUSED(end)
327 if (m_modelSignalsBlock)
327 if (m_modelSignalsBlock)
328 return;
328 return;
329
329
330 blockSeriesSignals();
330 blockSeriesSignals();
331 if (m_orientation == Qt::Vertical)
331 if (m_orientation == Qt::Vertical)
332 // removeData(start, end);
332 // removeData(start, end);
333 initializeBarFromModel();
333 initializeBarFromModel();
334 else if (start <= m_firstBarSetSection || start <= m_lastBarSetSection) // if the changes affect the map - reinitialize
334 else if (start <= m_firstBarSetSection || start <= m_lastBarSetSection) // if the changes affect the map - reinitialize
335 initializeBarFromModel();
335 initializeBarFromModel();
336 blockSeriesSignals(false);
336 blockSeriesSignals(false);
337 }
337 }
338
338
339 void QBarModelMapperPrivate::modelColumnsAdded(QModelIndex parent, int start, int end)
339 void QBarModelMapperPrivate::modelColumnsAdded(QModelIndex parent, int start, int end)
340 {
340 {
341 Q_UNUSED(parent);
341 Q_UNUSED(parent);
342 Q_UNUSED(end)
342 Q_UNUSED(end)
343 if (m_modelSignalsBlock)
343 if (m_modelSignalsBlock)
344 return;
344 return;
345
345
346 blockSeriesSignals();
346 blockSeriesSignals();
347 if (m_orientation == Qt::Horizontal)
347 if (m_orientation == Qt::Horizontal)
348 // insertData(start, end);
348 // insertData(start, end);
349 initializeBarFromModel();
349 initializeBarFromModel();
350 else if (start <= m_firstBarSetSection || start <= m_lastBarSetSection) // if the changes affect the map - reinitialize
350 else if (start <= m_firstBarSetSection || start <= m_lastBarSetSection) // if the changes affect the map - reinitialize
351 initializeBarFromModel();
351 initializeBarFromModel();
352 blockSeriesSignals(false);
352 blockSeriesSignals(false);
353 }
353 }
354
354
355 void QBarModelMapperPrivate::modelColumnsRemoved(QModelIndex parent, int start, int end)
355 void QBarModelMapperPrivate::modelColumnsRemoved(QModelIndex parent, int start, int end)
356 {
356 {
357 Q_UNUSED(parent);
357 Q_UNUSED(parent);
358 Q_UNUSED(end)
358 Q_UNUSED(end)
359 if (m_modelSignalsBlock)
359 if (m_modelSignalsBlock)
360 return;
360 return;
361
361
362 blockSeriesSignals();
362 blockSeriesSignals();
363 if (m_orientation == Qt::Horizontal)
363 if (m_orientation == Qt::Horizontal)
364 // removeData(start, end);
364 // removeData(start, end);
365 initializeBarFromModel();
365 initializeBarFromModel();
366 else if (start <= m_firstBarSetSection || start <= m_lastBarSetSection) // if the changes affect the map - reinitialize
366 else if (start <= m_firstBarSetSection || start <= m_lastBarSetSection) // if the changes affect the map - reinitialize
367 initializeBarFromModel();
367 initializeBarFromModel();
368 blockSeriesSignals(false);
368 blockSeriesSignals(false);
369 }
369 }
370
370
371 void QBarModelMapperPrivate::handleModelDestroyed()
371 void QBarModelMapperPrivate::handleModelDestroyed()
372 {
372 {
373 m_model = 0;
373 m_model = 0;
374 }
374 }
375
375
376 void QBarModelMapperPrivate::insertData(int start, int end)
376 void QBarModelMapperPrivate::insertData(int start, int end)
377 {
377 {
378 Q_UNUSED(end)
378 Q_UNUSED(end)
379 Q_UNUSED(start)
379 Q_UNUSED(start)
380 Q_UNUSED(end)
380 Q_UNUSED(end)
381 // To be implemented
381 // To be implemented
382 }
382 }
383
383
384 void QBarModelMapperPrivate::removeData(int start, int end)
384 void QBarModelMapperPrivate::removeData(int start, int end)
385 {
385 {
386 Q_UNUSED(end)
386 Q_UNUSED(end)
387 Q_UNUSED(start)
387 Q_UNUSED(start)
388 Q_UNUSED(end)
388 Q_UNUSED(end)
389 // To be implemented
389 // To be implemented
390 }
390 }
391
391
392 void QBarModelMapperPrivate::barSetsAdded(QList<QBarSet*> sets)
392 void QBarModelMapperPrivate::barSetsAdded(QList<QBarSet*> sets)
393 {
393 {
394 if (m_seriesSignalsBlock)
394 if (m_seriesSignalsBlock)
395 return;
395 return;
396
396
397 if (sets.count() == 0)
397 if (sets.count() == 0)
398 return;
398 return;
399
399
400 int firstIndex = m_series->barSets().indexOf(sets.at(0));
400 int firstIndex = m_series->barSets().indexOf(sets.at(0));
401 if (firstIndex == -1)
401 if (firstIndex == -1)
402 return;
402 return;
403
403
404 int maxCount = 0;
404 int maxCount = 0;
405 for(int i = 0; i < sets.count(); i++)
405 for(int i = 0; i < sets.count(); i++)
406 if (sets.at(i)->count() > m_count)
406 if (sets.at(i)->count() > m_count)
407 maxCount = sets.at(i)->count();
407 maxCount = sets.at(i)->count();
408
408
409 if (m_count != -1 && m_count < maxCount)
409 if (m_count != -1 && m_count < maxCount)
410 m_count = maxCount;
410 m_count = maxCount;
411
411
412 m_lastBarSetSection += sets.count();
412 m_lastBarSetSection += sets.count();
413
413
414 blockModelSignals();
414 blockModelSignals();
415 int modelCapacity = m_orientation == Qt::Vertical ? m_model->rowCount() - m_first : m_model->columnCount() - m_first;
415 int modelCapacity = m_orientation == Qt::Vertical ? m_model->rowCount() - m_first : m_model->columnCount() - m_first;
416 if (maxCount > modelCapacity) {
416 if (maxCount > modelCapacity) {
417 if (m_orientation == Qt::Vertical)
417 if (m_orientation == Qt::Vertical)
418 m_model->insertRows(m_model->rowCount(), maxCount - modelCapacity);
418 m_model->insertRows(m_model->rowCount(), maxCount - modelCapacity);
419 else
419 else
420 m_model->insertColumns(m_model->columnCount(), maxCount - modelCapacity);
420 m_model->insertColumns(m_model->columnCount(), maxCount - modelCapacity);
421 }
421 }
422
422
423 if (m_orientation == Qt::Vertical)
423 if (m_orientation == Qt::Vertical)
424 m_model->insertColumns(firstIndex + m_firstBarSetSection, sets.count());
424 m_model->insertColumns(firstIndex + m_firstBarSetSection, sets.count());
425 else
425 else
426 m_model->insertRows(firstIndex + m_firstBarSetSection, sets.count());
426 m_model->insertRows(firstIndex + m_firstBarSetSection, sets.count());
427
427
428
428
429 for(int i = firstIndex + m_firstBarSetSection; i < firstIndex + m_firstBarSetSection + sets.count(); i++) {
429 for(int i = firstIndex + m_firstBarSetSection; i < firstIndex + m_firstBarSetSection + sets.count(); i++) {
430 m_model->setHeaderData(i, m_orientation == Qt::Vertical ? Qt::Horizontal : Qt::Vertical, sets.at(i - firstIndex - m_firstBarSetSection)->label());
430 m_model->setHeaderData(i, m_orientation == Qt::Vertical ? Qt::Horizontal : Qt::Vertical, sets.at(i - firstIndex - m_firstBarSetSection)->label());
431 for (int j = 0; j < sets.at(i - firstIndex - m_firstBarSetSection)->count(); j++)
431 for (int j = 0; j < sets.at(i - firstIndex - m_firstBarSetSection)->count(); j++)
432 m_model->setData(barModelIndex(i, j), sets.at(i - firstIndex - m_firstBarSetSection)->at(j));
432 m_model->setData(barModelIndex(i, j), sets.at(i - firstIndex - m_firstBarSetSection)->at(j));
433 }
433 }
434 blockModelSignals(false);
434 blockModelSignals(false);
435 initializeBarFromModel();
435 initializeBarFromModel();
436 }
436 }
437
437
438 void QBarModelMapperPrivate::barSetsRemoved(QList<QBarSet*> sets)
438 void QBarModelMapperPrivate::barSetsRemoved(QList<QBarSet*> sets)
439 {
439 {
440 if (m_seriesSignalsBlock)
440 if (m_seriesSignalsBlock)
441 return;
441 return;
442
442
443 if (sets.count() == 0)
443 if (sets.count() == 0)
444 return;
444 return;
445
445
446 int firstIndex = m_barSets.indexOf(sets.at(0));
446 int firstIndex = m_barSets.indexOf(sets.at(0));
447 if (firstIndex == -1)
447 if (firstIndex == -1)
448 return;
448 return;
449
449
450 m_lastBarSetSection -= sets.count();
450 m_lastBarSetSection -= sets.count();
451
451
452 for (int i = firstIndex + sets.count() - 1; i >= firstIndex; i--)
452 for (int i = firstIndex + sets.count() - 1; i >= firstIndex; i--)
453 m_barSets.removeAt(i);
453 m_barSets.removeAt(i);
454
454
455 blockModelSignals();
455 blockModelSignals();
456 if (m_orientation == Qt::Vertical)
456 if (m_orientation == Qt::Vertical)
457 m_model->removeColumns(firstIndex + m_firstBarSetSection, sets.count());
457 m_model->removeColumns(firstIndex + m_firstBarSetSection, sets.count());
458 else
458 else
459 m_model->removeRows(firstIndex + m_firstBarSetSection, sets.count());
459 m_model->removeRows(firstIndex + m_firstBarSetSection, sets.count());
460 blockModelSignals(false);
460 blockModelSignals(false);
461 initializeBarFromModel();
461 initializeBarFromModel();
462 }
462 }
463
463
464 void QBarModelMapperPrivate::valuesAdded(int index, int count)
464 void QBarModelMapperPrivate::valuesAdded(int index, int count)
465 {
465 {
466 if (m_seriesSignalsBlock)
466 if (m_seriesSignalsBlock)
467 return;
467 return;
468
468
469 if (m_count != -1)
469 if (m_count != -1)
470 m_count += count;
470 m_count += count;
471
471
472 int barSetIndex = m_barSets.indexOf(qobject_cast<QBarSet *>(QObject::sender()));
472 int barSetIndex = m_barSets.indexOf(qobject_cast<QBarSet *>(QObject::sender()));
473
473
474 blockModelSignals();
474 blockModelSignals();
475 if (m_orientation == Qt::Vertical)
475 if (m_orientation == Qt::Vertical)
476 m_model->insertRows(index + m_first, count);
476 m_model->insertRows(index + m_first, count);
477 else
477 else
478 m_model->insertColumns(index + m_first, count);
478 m_model->insertColumns(index + m_first, count);
479
479
480 for (int j = index; j < index + count; j++)
480 for (int j = index; j < index + count; j++)
481 m_model->setData(barModelIndex(barSetIndex + m_firstBarSetSection, j), m_barSets.at(barSetIndex)->at(j));
481 m_model->setData(barModelIndex(barSetIndex + m_firstBarSetSection, j), m_barSets.at(barSetIndex)->at(j));
482
482
483 blockModelSignals(false);
483 blockModelSignals(false);
484 initializeBarFromModel();
484 initializeBarFromModel();
485 }
485 }
486
486
487 void QBarModelMapperPrivate::valuesRemoved(int index, int count)
487 void QBarModelMapperPrivate::valuesRemoved(int index, int count)
488 {
488 {
489 if (m_seriesSignalsBlock)
489 if (m_seriesSignalsBlock)
490 return;
490 return;
491
491
492 if (m_count != -1)
492 if (m_count != -1)
493 m_count -= count;
493 m_count -= count;
494
494
495 blockModelSignals();
495 blockModelSignals();
496 if (m_orientation == Qt::Vertical)
496 if (m_orientation == Qt::Vertical)
497 m_model->removeRows(index + m_first, count);
497 m_model->removeRows(index + m_first, count);
498 else
498 else
499 m_model->removeColumns(index + m_first, count);
499 m_model->removeColumns(index + m_first, count);
500
500
501 blockModelSignals(false);
501 blockModelSignals(false);
502 initializeBarFromModel();
502 initializeBarFromModel();
503 }
503 }
504
504
505 void QBarModelMapperPrivate::barLabelChanged()
505 void QBarModelMapperPrivate::barLabelChanged()
506 {
506 {
507 if (m_seriesSignalsBlock)
507 if (m_seriesSignalsBlock)
508 return;
508 return;
509
509
510 int barSetIndex = m_barSets.indexOf(qobject_cast<QBarSet *>(QObject::sender()));
510 int barSetIndex = m_barSets.indexOf(qobject_cast<QBarSet *>(QObject::sender()));
511
511
512 blockModelSignals();
512 blockModelSignals();
513 m_model->setHeaderData(barSetIndex + m_firstBarSetSection, m_orientation == Qt::Vertical ? Qt::Horizontal : Qt::Vertical, m_barSets.at(barSetIndex)->label());
513 m_model->setHeaderData(barSetIndex + m_firstBarSetSection, m_orientation == Qt::Vertical ? Qt::Horizontal : Qt::Vertical, m_barSets.at(barSetIndex)->label());
514 blockModelSignals(false);
514 blockModelSignals(false);
515 initializeBarFromModel();
515 initializeBarFromModel();
516 }
516 }
517
517
518 void QBarModelMapperPrivate::barValueChanged(int index)
518 void QBarModelMapperPrivate::barValueChanged(int index)
519 {
519 {
520 if (m_seriesSignalsBlock)
520 if (m_seriesSignalsBlock)
521 return;
521 return;
522
522
523 int barSetIndex = m_barSets.indexOf(qobject_cast<QBarSet *>(QObject::sender()));
523 int barSetIndex = m_barSets.indexOf(qobject_cast<QBarSet *>(QObject::sender()));
524
524
525 blockModelSignals();
525 blockModelSignals();
526 m_model->setData(barModelIndex(barSetIndex + m_firstBarSetSection, index), m_barSets.at(barSetIndex)->at(index));
526 m_model->setData(barModelIndex(barSetIndex + m_firstBarSetSection, index), m_barSets.at(barSetIndex)->at(index));
527 blockModelSignals(false);
527 blockModelSignals(false);
528 initializeBarFromModel();
528 initializeBarFromModel();
529 }
529 }
530
530
531 void QBarModelMapperPrivate::initializeBarFromModel()
531 void QBarModelMapperPrivate::initializeBarFromModel()
532 {
532 {
533 if (m_model == 0 || m_series == 0)
533 if (m_model == 0 || m_series == 0)
534 return;
534 return;
535
535
536 blockSeriesSignals();
536 blockSeriesSignals();
537 // clear current content
537 // clear current content
538 m_series->clear();
538 m_series->clear();
539 m_barSets.clear();
539 m_barSets.clear();
540
540
541 // create the initial bar sets
541 // create the initial bar sets
542 for (int i = m_firstBarSetSection; i <= m_lastBarSetSection; i++) {
542 for (int i = m_firstBarSetSection; i <= m_lastBarSetSection; i++) {
543 int posInBar = 0;
543 int posInBar = 0;
544 QModelIndex barIndex = barModelIndex(i, posInBar);
544 QModelIndex barIndex = barModelIndex(i, posInBar);
545 // check if there is such model index
545 // check if there is such model index
546 if (barIndex.isValid()) {
546 if (barIndex.isValid()) {
547 QBarSet *barSet = new QBarSet(m_model->headerData(i, m_orientation == Qt::Vertical ? Qt::Horizontal : Qt::Vertical).toString());
547 QBarSet *barSet = new QBarSet(m_model->headerData(i, m_orientation == Qt::Vertical ? Qt::Horizontal : Qt::Vertical).toString());
548 while (barIndex.isValid()) {
548 while (barIndex.isValid()) {
549 barSet->append(m_model->data(barIndex, Qt::DisplayRole).toDouble());
549 barSet->append(m_model->data(barIndex, Qt::DisplayRole).toDouble());
550 posInBar++;
550 posInBar++;
551 barIndex = barModelIndex(i, posInBar);
551 barIndex = barModelIndex(i, posInBar);
552 }
552 }
553 connect(barSet, SIGNAL(valuesAdded(int, int)), this, SLOT(valuesAdded(int, int)));
553 connect(barSet, SIGNAL(valuesAdded(int,int)), this, SLOT(valuesAdded(int,int)));
554 connect(barSet, SIGNAL(valuesRemoved(int, int)), this, SLOT(valuesRemoved(int, int)));
554 connect(barSet, SIGNAL(valuesRemoved(int,int)), this, SLOT(valuesRemoved(int,int)));
555 connect(barSet, SIGNAL(valueChanged(int)), this, SLOT(barValueChanged(int)));
555 connect(barSet, SIGNAL(valueChanged(int)), this, SLOT(barValueChanged(int)));
556 connect(barSet, SIGNAL(labelChanged()), this, SLOT(barLabelChanged()));
556 connect(barSet, SIGNAL(labelChanged()), this, SLOT(barLabelChanged()));
557 m_series->append(barSet);
557 m_series->append(barSet);
558 m_barSets.append(barSet);
558 m_barSets.append(barSet);
559 } else {
559 } else {
560 break;
560 break;
561 }
561 }
562 }
562 }
563 blockSeriesSignals(false);
563 blockSeriesSignals(false);
564 }
564 }
565
565
566 #include "moc_qbarmodelmapper.cpp"
566 #include "moc_qbarmodelmapper.cpp"
567 #include "moc_qbarmodelmapper_p.cpp"
567 #include "moc_qbarmodelmapper_p.cpp"
568
568
569 QTCOMMERCIALCHART_END_NAMESPACE
569 QTCOMMERCIALCHART_END_NAMESPACE
@@ -1,99 +1,98
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 "barchartitem_p.h"
21 #include "barchartitem_p.h"
22 #include "bar_p.h"
22 #include "bar_p.h"
23 #include "qbarset_p.h"
24 #include "qabstractbarseries_p.h"
23 #include "qabstractbarseries_p.h"
25 #include "qbarset.h"
24 #include "qbarset.h"
26 #include "qbarset_p.h"
25 #include "qbarset_p.h"
27
26
28 QTCOMMERCIALCHART_BEGIN_NAMESPACE
27 QTCOMMERCIALCHART_BEGIN_NAMESPACE
29
28
30 BarChartItem::BarChartItem(QAbstractBarSeries *series, ChartPresenter *presenter) :
29 BarChartItem::BarChartItem(QAbstractBarSeries *series, ChartPresenter *presenter) :
31 AbstractBarChartItem(series, presenter)
30 AbstractBarChartItem(series, presenter)
32 {
31 {
33 }
32 }
34
33
35 QVector<QRectF> BarChartItem::calculateLayout()
34 QVector<QRectF> BarChartItem::calculateLayout()
36 {
35 {
37 QVector<QRectF> layout;
36 QVector<QRectF> layout;
38
37
39 // Use temporary qreals for accuracy
38 // Use temporary qreals for accuracy
40 qreal categoryCount = m_series->d_func()->categoryCount();
39 qreal categoryCount = m_series->d_func()->categoryCount();
41 qreal setCount = m_series->count();
40 qreal setCount = m_series->count();
42 bool barsVisible = m_series->isVisible();
41 bool barsVisible = m_series->isVisible();
43
42
44 // Domain:
43 // Domain:
45 qreal width = geometry().width();
44 qreal width = geometry().width();
46 qreal height = geometry().height();
45 qreal height = geometry().height();
47 qreal rangeY = m_domainMaxY - m_domainMinY;
46 qreal rangeY = m_domainMaxY - m_domainMinY;
48 qreal rangeX = m_domainMaxX - m_domainMinX;
47 qreal rangeX = m_domainMaxX - m_domainMinX;
49 qreal scaleY = (height / rangeY);
48 qreal scaleY = (height / rangeY);
50 qreal scaleX = (width / rangeX);
49 qreal scaleX = (width / rangeX);
51 qreal barWidth;
50 qreal barWidth;
52
51
53 barWidth = (scaleX / setCount) * m_series->d_func()->barWidth();
52 barWidth = (scaleX / setCount) * m_series->d_func()->barWidth();
54
53
55 int itemIndex(0);
54 int itemIndex(0);
56 for (int category = 0; category < categoryCount; category++) {
55 for (int category = 0; category < categoryCount; category++) {
57 qreal yPos = height + scaleY * m_domainMinY + geometry().topLeft().y();
56 qreal yPos = height + scaleY * m_domainMinY + geometry().topLeft().y();
58 for (int set = 0; set < setCount; set++) {
57 for (int set = 0; set < setCount; set++) {
59 QBarSetPrivate* barSet = m_series->d_func()->barsetAt(set)->d_ptr.data();
58 QBarSetPrivate* barSet = m_series->d_func()->barsetAt(set)->d_ptr.data();
60
59
61 qreal xPos = (barSet->pos(category) - m_domainMinX) * scaleX + m_rect.left();
60 qreal xPos = (barSet->pos(category) - m_domainMinX) * scaleX + m_rect.left();
62 xPos -= setCount*barWidth/2;
61 xPos -= setCount*barWidth/2;
63 xPos += set*barWidth;
62 xPos += set*barWidth;
64
63
65 qreal barHeight = barSet->value(category) * scaleY;
64 qreal barHeight = barSet->value(category) * scaleY;
66 Bar* bar = m_bars.at(itemIndex);
65 Bar* bar = m_bars.at(itemIndex);
67
66
68 QRectF rect(xPos, yPos - barHeight, barWidth, barHeight);
67 QRectF rect(xPos, yPos - barHeight, barWidth, barHeight);
69 layout.append(rect);
68 layout.append(rect);
70 bar->setPen(barSet->m_pen);
69 bar->setPen(barSet->m_pen);
71 bar->setBrush(barSet->m_brush);
70 bar->setBrush(barSet->m_brush);
72 if (qFuzzyIsNull(barHeight)) {
71 if (qFuzzyIsNull(barHeight)) {
73 bar->setVisible(false);
72 bar->setVisible(false);
74 } else {
73 } else {
75 bar->setVisible(barsVisible);
74 bar->setVisible(barsVisible);
76 }
75 }
77
76
78 QGraphicsSimpleTextItem* label = m_labels.at(itemIndex);
77 QGraphicsSimpleTextItem* label = m_labels.at(itemIndex);
79
78
80 if (!qFuzzyIsNull(barSet->value(category))) {
79 if (!qFuzzyIsNull(barSet->value(category))) {
81 label->setText(QString::number(barSet->value(category)));
80 label->setText(QString::number(barSet->value(category)));
82 } else {
81 } else {
83 label->setText(QString(""));
82 label->setText(QString(""));
84 }
83 }
85
84
86 label->setPos(xPos + (rect.width()/2 - label->boundingRect().width()/2)
85 label->setPos(xPos + (rect.width()/2 - label->boundingRect().width()/2)
87 ,yPos - barHeight/2 - label->boundingRect().height()/2);
86 ,yPos - barHeight/2 - label->boundingRect().height()/2);
88 label->setFont(barSet->m_labelFont);
87 label->setFont(barSet->m_labelFont);
89 label->setBrush(barSet->m_labelBrush);
88 label->setBrush(barSet->m_labelBrush);
90
89
91 itemIndex++;
90 itemIndex++;
92 }
91 }
93 }
92 }
94 return layout;
93 return layout;
95 }
94 }
96
95
97 #include "moc_barchartitem_p.cpp"
96 #include "moc_barchartitem_p.cpp"
98
97
99 QTCOMMERCIALCHART_END_NAMESPACE
98 QTCOMMERCIALCHART_END_NAMESPACE
@@ -1,66 +1,66
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 CHARTBACKGROUND_H
30 #ifndef CHARTBACKGROUND_H
31 #define CHARTBACKGROUND_H
31 #define CHARTBACKGROUND_H
32
32
33 #include "qchartglobal.h"
33 #include "qchartglobal.h"
34 #include <QGraphicsRectItem>
34 #include <QGraphicsRectItem>
35
35
36 class QGraphicsDropShadowEffect;
36 class QGraphicsDropShadowEffect;
37 QTCOMMERCIALCHART_BEGIN_NAMESPACE
37 QTCOMMERCIALCHART_BEGIN_NAMESPACE
38
38
39 class ChartBackground: public QGraphicsRectItem
39 class ChartBackground: public QGraphicsRectItem
40 {
40 {
41 public:
41 public:
42 ChartBackground(QGraphicsItem *parent =0);
42 ChartBackground(QGraphicsItem *parent =0);
43 ~ChartBackground();
43 ~ChartBackground();
44
44
45 void setDimeter(int dimater);
45 void setDimeter(int dimater);
46 int diameter() const;
46 int diameter() const;
47 void setDropShadowEnabled(bool enabled);
47 void setDropShadowEnabled(bool enabled);
48 bool isDropShadowEnabled() {return m_dropShadow != 0;}
48 bool isDropShadowEnabled() {return m_dropShadow != 0;}
49
49
50 protected:
50 protected:
51 void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget);
51 void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget);
52
52
53
53
54 private:
54 private:
55 int roundness(qreal size) const;
55 int roundness(qreal size) const;
56
56
57 private:
57 private:
58 int m_diameter;
58 int m_diameter;
59 QGraphicsDropShadowEffect *m_dropShadow;
59 QGraphicsDropShadowEffect *m_dropShadow;
60 };
60 };
61
61
62 QTCOMMERCIALCHART_END_NAMESPACE
62 QTCOMMERCIALCHART_END_NAMESPACE
63
63
64 #endif /* CHARTBACKGROUND_H_ */
64 #endif /* CHARTBACKGROUND_H */
65
65
66
66
@@ -1,98 +1,98
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 CHARTDATASET_P_H
30 #ifndef CHARTDATASET_P_H
31 #define CHARTDATASET_P_H
31 #define CHARTDATASET_P_H
32
32
33 #include "qabstractseries.h"
33 #include "qabstractseries.h"
34 #include "domain_p.h"
34 #include "domain_p.h"
35 #include "qabstractaxis_p.h"
35 #include "qabstractaxis_p.h"
36 #include <QVector>
36 #include <QVector>
37
37
38 QTCOMMERCIALCHART_BEGIN_NAMESPACE
38 QTCOMMERCIALCHART_BEGIN_NAMESPACE
39
39
40 class QAbstractAxis;
40 class QAbstractAxis;
41
41
42 class QTCOMMERCIALCHART_AUTOTEST_EXPORT ChartDataSet : public QObject
42 class QTCOMMERCIALCHART_AUTOTEST_EXPORT ChartDataSet : public QObject
43 {
43 {
44 Q_OBJECT
44 Q_OBJECT
45 public:
45 public:
46 ChartDataSet(QChart* parent=0);
46 ChartDataSet(QChart* parent=0);
47 virtual ~ChartDataSet();
47 virtual ~ChartDataSet();
48
48
49 void addSeries(QAbstractSeries* series);
49 void addSeries(QAbstractSeries* series);
50 void removeSeries(QAbstractSeries* series);
50 void removeSeries(QAbstractSeries* series);
51 void removeAllSeries();
51 void removeAllSeries();
52 void updateSeries(QAbstractSeries* series);
52 void updateSeries(QAbstractSeries* series);
53
53
54 void zoomInDomain(const QRectF& rect, const QSizeF& size);
54 void zoomInDomain(const QRectF& rect, const QSizeF& size);
55 void zoomOutDomain(const QRectF& rect, const QSizeF& size);
55 void zoomOutDomain(const QRectF& rect, const QSizeF& size);
56 void scrollDomain(qreal dx,qreal dy,const QSizeF& size);
56 void scrollDomain(qreal dx,qreal dy,const QSizeF& size);
57
57
58 int seriesCount(QAbstractSeries::SeriesType type);
58 int seriesCount(QAbstractSeries::SeriesType type);
59 int seriesIndex(QAbstractSeries *series);
59 int seriesIndex(QAbstractSeries *series);
60
60
61 QAbstractAxis* axisX(QAbstractSeries *series) const;
61 QAbstractAxis* axisX(QAbstractSeries *series) const;
62 QAbstractAxis* axisY(QAbstractSeries *series) const;
62 QAbstractAxis* axisY(QAbstractSeries *series) const;
63
63
64 void setAxis(QAbstractSeries *series, QAbstractAxis *axis, Qt::Orientation orientation);
64 void setAxis(QAbstractSeries *series, QAbstractAxis *axis, Qt::Orientation orientation);
65
65
66 QList<QAbstractSeries*> series() const;
66 QList<QAbstractSeries*> series() const;
67 Domain* domain(QAbstractSeries *series) const;
67 Domain* domain(QAbstractSeries *series) const;
68
68
69 void removeAxis(QAbstractAxis* axis);
69 void removeAxis(QAbstractAxis* axis);
70 void createDefaultAxes();
70 void createDefaultAxes();
71
71
72 Q_SIGNALS:
72 Q_SIGNALS:
73 void seriesAdded(QAbstractSeries* series, Domain* domain);
73 void seriesAdded(QAbstractSeries* series, Domain* domain);
74 void seriesRemoved(QAbstractSeries* series);
74 void seriesRemoved(QAbstractSeries* series);
75 void seriesUpdated(QAbstractSeries* series);
75 void seriesUpdated(QAbstractSeries* series);
76 void axisAdded(QAbstractAxis* axis,Domain* domain);
76 void axisAdded(QAbstractAxis* axis,Domain* domain);
77 void axisRemoved(QAbstractAxis* axis);
77 void axisRemoved(QAbstractAxis* axis);
78
78
79 private:
79 private:
80 void calculateDomain(QAbstractSeries* series,Domain* domain);
80 void calculateDomain(QAbstractSeries* series,Domain* domain);
81 void createAxes(QAbstractAxis::AxisTypes type,Qt::Orientation orientation);
81 void createAxes(QAbstractAxis::AxisTypes type,Qt::Orientation orientation);
82 QAbstractAxis* createAxis(QAbstractAxis::AxisType type,Qt::Orientation orientation);
82 QAbstractAxis* createAxis(QAbstractAxis::AxisType type,Qt::Orientation orientation);
83 void initializeAxis(QAbstractAxis* axis,QAbstractSeries* series);
83 void initializeAxis(QAbstractAxis* axis,QAbstractSeries* series);
84 void removeAxes(QAbstractSeries* series);
84 void removeAxes(QAbstractSeries* series);
85 void blockAxisSignals(bool enabled);
85 void blockAxisSignals(bool enabled);
86 void createSeriesIndex(QAbstractSeries* series);
86 void createSeriesIndex(QAbstractSeries* series);
87 void removeSeriesIndex(QAbstractSeries* series);
87 void removeSeriesIndex(QAbstractSeries* series);
88
88
89 private:
89 private:
90 QMap<QAbstractSeries*, QAbstractAxis*> m_seriesAxisXMap;
90 QMap<QAbstractSeries*, QAbstractAxis*> m_seriesAxisXMap;
91 QMap<QAbstractSeries*, QAbstractAxis*> m_seriesAxisYMap;
91 QMap<QAbstractSeries*, QAbstractAxis*> m_seriesAxisYMap;
92 QMap<QAbstractSeries*, Domain*> m_seriesDomainMap;
92 QMap<QAbstractSeries*, Domain*> m_seriesDomainMap;
93 QMap<int, QAbstractSeries*> m_indexSeriesMap;
93 QMap<int, QAbstractSeries*> m_indexSeriesMap;
94 };
94 };
95
95
96 QTCOMMERCIALCHART_END_NAMESPACE
96 QTCOMMERCIALCHART_END_NAMESPACE
97
97
98 #endif /* CHARTENGINE_P_H_ */
98 #endif /* CHARTENGINE_P_H */
@@ -1,48 +1,48
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 CHARTITEM_H
30 #ifndef CHARTITEM_H
31 #define CHARTITEM_H
31 #define CHARTITEM_H
32
32
33 #include "chartelement_p.h"
33 #include "chartelement_p.h"
34 #include "chartpresenter_p.h"
34 #include "chartpresenter_p.h"
35 #include <QGraphicsItem>
35 #include <QGraphicsItem>
36
36
37 QTCOMMERCIALCHART_BEGIN_NAMESPACE
37 QTCOMMERCIALCHART_BEGIN_NAMESPACE
38
38
39 class ChartItem : public QGraphicsItem, public ChartElement
39 class ChartItem : public QGraphicsItem, public ChartElement
40 {
40 {
41 enum ChartItemTypes{ AXIS_ITEM = UserType + 1, XYLINE_ITEM };
41 enum ChartItemTypes{ AXIS_ITEM = UserType + 1, XYLINE_ITEM };
42 public:
42 public:
43 ChartItem(ChartPresenter *presenter) : QGraphicsItem(presenter ? presenter->rootItem() : 0), ChartElement(presenter) {}
43 ChartItem(ChartPresenter *presenter) : QGraphicsItem(presenter ? presenter->rootItem() : 0), ChartElement(presenter) {}
44 };
44 };
45
45
46 QTCOMMERCIALCHART_END_NAMESPACE
46 QTCOMMERCIALCHART_END_NAMESPACE
47
47
48 #endif /* CHARTITEM_H_ */
48 #endif /* CHARTITEM_H */
@@ -1,63 +1,63
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 CHARTLAYOUT_H_
21 #ifndef CHARTLAYOUT_H
22 #define CHARTLAYOUT_H_
22 #define CHARTLAYOUT_H
23 #include <QGraphicsLayout>
23 #include <QGraphicsLayout>
24 #include <QMargins>
24 #include <QMargins>
25 #include "qchartglobal.h"
25 #include "qchartglobal.h"
26
26
27 QTCOMMERCIALCHART_BEGIN_NAMESPACE
27 QTCOMMERCIALCHART_BEGIN_NAMESPACE
28
28
29 class ChartPresenter;
29 class ChartPresenter;
30
30
31 class ChartLayout : public QGraphicsLayout
31 class ChartLayout : public QGraphicsLayout
32 {
32 {
33 public:
33 public:
34
34
35 ChartLayout(ChartPresenter* presenter);
35 ChartLayout(ChartPresenter* presenter);
36 virtual ~ChartLayout();
36 virtual ~ChartLayout();
37
37
38 void setMinimumMargins(const QMargins& margins);
38 void setMinimumMargins(const QMargins& margins);
39 QMargins minimumMargins() const;
39 QMargins minimumMargins() const;
40
40
41 void setGeometry(const QRectF& rect);
41 void setGeometry(const QRectF& rect);
42
42
43 protected:
43 protected:
44 QSizeF sizeHint ( Qt::SizeHint which, const QSizeF & constraint = QSizeF() ) const;
44 QSizeF sizeHint ( Qt::SizeHint which, const QSizeF & constraint = QSizeF() ) const;
45 int count() const { return 0; }
45 int count() const { return 0; }
46 QGraphicsLayoutItem* itemAt(int) const { return 0; };
46 QGraphicsLayoutItem* itemAt(int) const { return 0; };
47 void removeAt(int){};
47 void removeAt(int){};
48
48
49 private:
49 private:
50 ChartPresenter* m_presenter;
50 ChartPresenter* m_presenter;
51 int m_marginBig;
51 int m_marginBig;
52 int m_marginSmall;
52 int m_marginSmall;
53 int m_marginTiny;
53 int m_marginTiny;
54 QMargins m_chartMargins;
54 QMargins m_chartMargins;
55 QMargins m_legendMargins;
55 QMargins m_legendMargins;
56 bool m_intialized;
56 bool m_intialized;
57
57
58
58
59 };
59 };
60
60
61 QTCOMMERCIALCHART_END_NAMESPACE
61 QTCOMMERCIALCHART_END_NAMESPACE
62
62
63 #endif
63 #endif
@@ -1,177 +1,177
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 #include <QMargins>
36 #include <QMargins>
37
37
38 QTCOMMERCIALCHART_BEGIN_NAMESPACE
38 QTCOMMERCIALCHART_BEGIN_NAMESPACE
39
39
40 class ChartElement;
40 class ChartElement;
41 class QAbstractSeries;
41 class QAbstractSeries;
42 class ChartDataSet;
42 class ChartDataSet;
43 class Domain;
43 class Domain;
44 class ChartAxis;
44 class ChartAxis;
45 class ChartTheme;
45 class ChartTheme;
46 class ChartAnimator;
46 class ChartAnimator;
47 class ChartBackground;
47 class ChartBackground;
48 class ChartAnimation;
48 class ChartAnimation;
49 class ChartLayout;
49 class ChartLayout;
50
50
51 class ChartPresenter: public QObject
51 class ChartPresenter: public QObject
52 {
52 {
53 Q_OBJECT
53 Q_OBJECT
54 public:
54 public:
55 enum ZValues {
55 enum ZValues {
56 BackgroundZValue = -1,
56 BackgroundZValue = -1,
57 ShadesZValue ,
57 ShadesZValue ,
58 GridZValue,
58 GridZValue,
59 AxisZValue,
59 AxisZValue,
60 SeriesZValue,
60 SeriesZValue,
61 LineChartZValue = SeriesZValue,
61 LineChartZValue = SeriesZValue,
62 SplineChartZValue = SeriesZValue,
62 SplineChartZValue = SeriesZValue,
63 BarSeriesZValue = SeriesZValue,
63 BarSeriesZValue = SeriesZValue,
64 ScatterSeriesZValue = SeriesZValue,
64 ScatterSeriesZValue = SeriesZValue,
65 PieSeriesZValue = SeriesZValue,
65 PieSeriesZValue = SeriesZValue,
66 LegendZValue,
66 LegendZValue,
67 TopMostZValue
67 TopMostZValue
68 };
68 };
69
69
70 enum State {
70 enum State {
71 ShowState,
71 ShowState,
72 ScrollUpState,
72 ScrollUpState,
73 ScrollDownState,
73 ScrollDownState,
74 ScrollLeftState,
74 ScrollLeftState,
75 ScrollRightState,
75 ScrollRightState,
76 ZoomInState,
76 ZoomInState,
77 ZoomOutState
77 ZoomOutState
78 };
78 };
79
79
80 ChartPresenter(QChart* chart,ChartDataSet *dataset);
80 ChartPresenter(QChart* chart,ChartDataSet *dataset);
81 virtual ~ChartPresenter();
81 virtual ~ChartPresenter();
82
82
83 ChartTheme *chartTheme() const { return m_chartTheme; }
83 ChartTheme *chartTheme() const { return m_chartTheme; }
84 ChartDataSet *dataSet() const { return m_dataset; }
84 ChartDataSet *dataSet() const { return m_dataset; }
85 QGraphicsItem* rootItem() const { return m_chart; }
85 QGraphicsItem* rootItem() const { return m_chart; }
86 QGraphicsRectItem* backgroundItem();
86 QGraphicsRectItem* backgroundItem();
87 QGraphicsItem* titleItem();
87 QGraphicsItem* titleItem();
88 QList<ChartAxis*> axisItems() const;
88 QList<ChartAxis*> axisItems() const;
89
89
90 QLegend* legend();
90 QLegend* legend();
91
91
92 void setBackgroundBrush(const QBrush& brush);
92 void setBackgroundBrush(const QBrush& brush);
93 QBrush backgroundBrush() const;
93 QBrush backgroundBrush() const;
94
94
95 void setBackgroundPen(const QPen& pen);
95 void setBackgroundPen(const QPen& pen);
96 QPen backgroundPen() const;
96 QPen backgroundPen() const;
97
97
98 void setTitle(const QString& title);
98 void setTitle(const QString& title);
99 QString title() const;
99 QString title() const;
100
100
101 void setTitleFont(const QFont& font);
101 void setTitleFont(const QFont& font);
102 QFont titleFont() const;
102 QFont titleFont() const;
103
103
104 void setTitleBrush(const QBrush &brush);
104 void setTitleBrush(const QBrush &brush);
105 QBrush titleBrush() const;
105 QBrush titleBrush() const;
106
106
107 void setBackgroundVisible(bool visible);
107 void setBackgroundVisible(bool visible);
108 bool isBackgroundVisible() const;
108 bool isBackgroundVisible() const;
109
109
110 void setBackgroundDropShadowEnabled(bool enabled);
110 void setBackgroundDropShadowEnabled(bool enabled);
111 bool isBackgroundDropShadowEnabled() const;
111 bool isBackgroundDropShadowEnabled() const;
112
112
113 void setVisible(bool visible);
113 void setVisible(bool visible);
114
114
115 void setTheme(QChart::ChartTheme theme,bool force = true);
115 void setTheme(QChart::ChartTheme theme,bool force = true);
116 QChart::ChartTheme theme();
116 QChart::ChartTheme theme();
117
117
118 void setAnimationOptions(QChart::AnimationOptions options);
118 void setAnimationOptions(QChart::AnimationOptions options);
119 QChart::AnimationOptions animationOptions() const;
119 QChart::AnimationOptions animationOptions() const;
120
120
121 void zoomIn(qreal factor);
121 void zoomIn(qreal factor);
122 void zoomIn(const QRectF& rect);
122 void zoomIn(const QRectF& rect);
123 void zoomOut(qreal factor);
123 void zoomOut(qreal factor);
124 void scroll(qreal dx,qreal dy);
124 void scroll(qreal dx,qreal dy);
125
125
126 void setGeometry(const QRectF& rect);
126 void setGeometry(const QRectF& rect);
127 QRectF geometry() { return m_rect; }
127 QRectF geometry() { return m_rect; }
128
128
129 void startAnimation(ChartAnimation* animation);
129 void startAnimation(ChartAnimation* animation);
130 State state() const { return m_state; }
130 State state() const { return m_state; }
131 QPointF statePoint() const { return m_statePoint; }
131 QPointF statePoint() const { return m_statePoint; }
132
132
133 void resetAllElements();
133 void resetAllElements();
134
134
135 void setMinimumMargins(const QMargins& margins);
135 void setMinimumMargins(const QMargins& margins);
136 QMargins minimumMargins() const;
136 QMargins minimumMargins() const;
137 QGraphicsLayout* layout();
137 QGraphicsLayout* layout();
138
138
139 private:
139 private:
140 void createBackgroundItem();
140 void createBackgroundItem();
141 void createTitleItem();
141 void createTitleItem();
142 void selectVisibleAxis();
142 void selectVisibleAxis();
143
143
144 public Q_SLOTS:
144 public Q_SLOTS:
145 void handleSeriesAdded(QAbstractSeries* series,Domain* domain);
145 void handleSeriesAdded(QAbstractSeries* series,Domain* domain);
146 void handleSeriesRemoved(QAbstractSeries* series);
146 void handleSeriesRemoved(QAbstractSeries* series);
147 void handleAxisAdded(QAbstractAxis* axis,Domain* domain);
147 void handleAxisAdded(QAbstractAxis* axis,Domain* domain);
148 void handleAxisRemoved(QAbstractAxis* axis);
148 void handleAxisRemoved(QAbstractAxis* axis);
149 void handleAxisVisibleChanged(bool visible);
149 void handleAxisVisibleChanged(bool visible);
150
150
151 private Q_SLOTS:
151 private Q_SLOTS:
152 void handleAnimationFinished();
152 void handleAnimationFinished();
153
153
154 Q_SIGNALS:
154 Q_SIGNALS:
155 void geometryChanged(const QRectF& rect);
155 void geometryChanged(const QRectF& rect);
156 void animationsFinished();
156 void animationsFinished();
157 void marginsChanged(QRectF margins);
157 void marginsChanged(QRectF margins);
158
158
159 private:
159 private:
160 QChart* m_chart;
160 QChart* m_chart;
161 ChartDataSet* m_dataset;
161 ChartDataSet* m_dataset;
162 ChartTheme *m_chartTheme;
162 ChartTheme *m_chartTheme;
163 QMap<QAbstractSeries*, ChartElement*> m_chartItems;
163 QMap<QAbstractSeries*, ChartElement*> m_chartItems;
164 QMap<QAbstractAxis*, ChartAxis*> m_axisItems;
164 QMap<QAbstractAxis*, ChartAxis*> m_axisItems;
165 QRectF m_rect;
165 QRectF m_rect;
166 QChart::AnimationOptions m_options;
166 QChart::AnimationOptions m_options;
167 State m_state;
167 State m_state;
168 QPointF m_statePoint;
168 QPointF m_statePoint;
169 QList<ChartAnimation*> m_animations;
169 QList<ChartAnimation*> m_animations;
170 ChartLayout* m_layout;
170 ChartLayout* m_layout;
171 ChartBackground* m_backgroundItem;
171 ChartBackground* m_backgroundItem;
172 QGraphicsSimpleTextItem* m_titleItem;
172 QGraphicsSimpleTextItem* m_titleItem;
173 };
173 };
174
174
175 QTCOMMERCIALCHART_END_NAMESPACE
175 QTCOMMERCIALCHART_END_NAMESPACE
176
176
177 #endif /* CHARTPRESENTER_H_ */
177 #endif /* CHARTPRESENTER_H */
@@ -1,28 +1,28
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 MACROINCLUDE_H_
21 #ifndef CHARTSNAMESPACE_H
22 #define MACROINCLUDE_H_
22 #define MACROINCLUDE_H
23
23
24 // this is needed by the designer plugin.
24 // this is needed by the designer plugin.
25
25
26 QTCOMMERCIALCHART_USE_NAMESPACE
26 QTCOMMERCIALCHART_USE_NAMESPACE
27
27
28 #endif /* MACROINCLUDE_H_ */
28 #endif /* CHARTSNAMESPACE_H */
@@ -1,67 +1,67
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 LEGENDLAYOUT_H_
21 #ifndef LEGENDLAYOUT_H
22 #define LEGENDLAYOUT_H_
22 #define LEGENDLAYOUT_H
23 #include <QGraphicsLayout>
23 #include <QGraphicsLayout>
24 #include "qchartglobal.h"
24 #include "qchartglobal.h"
25
25
26 QTCOMMERCIALCHART_BEGIN_NAMESPACE
26 QTCOMMERCIALCHART_BEGIN_NAMESPACE
27
27
28 class QLegend;
28 class QLegend;
29
29
30 class LegendLayout : public QGraphicsLayout
30 class LegendLayout : public QGraphicsLayout
31 {
31 {
32 public:
32 public:
33
33
34 LegendLayout(QLegend* legend);
34 LegendLayout(QLegend* legend);
35 virtual ~LegendLayout();
35 virtual ~LegendLayout();
36
36
37 void setGeometry(const QRectF& rect);
37 void setGeometry(const QRectF& rect);
38
38
39 void setOffset(qreal x, qreal y);
39 void setOffset(qreal x, qreal y);
40 QPointF offset() const;
40 QPointF offset() const;
41
41
42 protected:
42 protected:
43 QSizeF sizeHint ( Qt::SizeHint which, const QSizeF & constraint = QSizeF() ) const;
43 QSizeF sizeHint ( Qt::SizeHint which, const QSizeF & constraint = QSizeF() ) const;
44 int count() const { return 0; }
44 int count() const { return 0; }
45 QGraphicsLayoutItem* itemAt(int) const { return 0; };
45 QGraphicsLayoutItem* itemAt(int) const { return 0; };
46 void removeAt(int){};
46 void removeAt(int){};
47
47
48 private:
48 private:
49 void setAttachedGeometry(const QRectF& rect);
49 void setAttachedGeometry(const QRectF& rect);
50 void setDettachedGeometry(const QRectF& rect);
50 void setDettachedGeometry(const QRectF& rect);
51
51
52 private:
52 private:
53 QLegend* m_legend;
53 QLegend* m_legend;
54 qreal m_offsetX;
54 qreal m_offsetX;
55 qreal m_offsetY;
55 qreal m_offsetY;
56 qreal m_minOffsetX;
56 qreal m_minOffsetX;
57 qreal m_minOffsetY;
57 qreal m_minOffsetY;
58 qreal m_maxOffsetX;
58 qreal m_maxOffsetX;
59 qreal m_maxOffsetY;
59 qreal m_maxOffsetY;
60 qreal m_width;
60 qreal m_width;
61 qreal m_height;
61 qreal m_height;
62
62
63 };
63 };
64
64
65 QTCOMMERCIALCHART_END_NAMESPACE
65 QTCOMMERCIALCHART_END_NAMESPACE
66
66
67 #endif
67 #endif
@@ -1,568 +1,568
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 "qpiemodelmapper_p.h"
22 #include "qpiemodelmapper.h"
21 #include "qpiemodelmapper.h"
22 #include "qpiemodelmapper_p.h"
23 #include "qpieseries.h"
23 #include "qpieseries.h"
24 #include "qpieslice.h"
24 #include "qpieslice.h"
25 #include <QAbstractItemModel>
25 #include <QAbstractItemModel>
26
26
27 QTCOMMERCIALCHART_BEGIN_NAMESPACE
27 QTCOMMERCIALCHART_BEGIN_NAMESPACE
28
28
29 QPieModelMapper::QPieModelMapper(QObject *parent) :
29 QPieModelMapper::QPieModelMapper(QObject *parent) :
30 QObject(parent),
30 QObject(parent),
31 d_ptr(new QPieModelMapperPrivate(this))
31 d_ptr(new QPieModelMapperPrivate(this))
32 {
32 {
33 }
33 }
34
34
35 QAbstractItemModel* QPieModelMapper::model() const
35 QAbstractItemModel* QPieModelMapper::model() const
36 {
36 {
37 Q_D(const QPieModelMapper);
37 Q_D(const QPieModelMapper);
38 return d->m_model;
38 return d->m_model;
39 }
39 }
40
40
41 void QPieModelMapper::setModel(QAbstractItemModel *model)
41 void QPieModelMapper::setModel(QAbstractItemModel *model)
42 {
42 {
43 if (model == 0)
43 if (model == 0)
44 return;
44 return;
45
45
46 Q_D(QPieModelMapper);
46 Q_D(QPieModelMapper);
47 if (d->m_model) {
47 if (d->m_model) {
48 disconnect(d->m_model, 0, d, 0);
48 disconnect(d->m_model, 0, d, 0);
49 }
49 }
50
50
51 d->m_model = model;
51 d->m_model = model;
52 d->initializePieFromModel();
52 d->initializePieFromModel();
53 // connect signals from the model
53 // connect signals from the model
54 connect(d->m_model, SIGNAL(dataChanged(QModelIndex,QModelIndex)), d, SLOT(modelUpdated(QModelIndex,QModelIndex)));
54 connect(d->m_model, SIGNAL(dataChanged(QModelIndex,QModelIndex)), d, SLOT(modelUpdated(QModelIndex,QModelIndex)));
55 connect(d->m_model, SIGNAL(rowsInserted(QModelIndex,int,int)), d, SLOT(modelRowsAdded(QModelIndex,int,int)));
55 connect(d->m_model, SIGNAL(rowsInserted(QModelIndex,int,int)), d, SLOT(modelRowsAdded(QModelIndex,int,int)));
56 connect(d->m_model, SIGNAL(rowsRemoved(QModelIndex,int,int)), d, SLOT(modelRowsRemoved(QModelIndex,int,int)));
56 connect(d->m_model, SIGNAL(rowsRemoved(QModelIndex,int,int)), d, SLOT(modelRowsRemoved(QModelIndex,int,int)));
57 connect(d->m_model, SIGNAL(columnsInserted(QModelIndex,int,int)), d, SLOT(modelColumnsAdded(QModelIndex,int,int)));
57 connect(d->m_model, SIGNAL(columnsInserted(QModelIndex,int,int)), d, SLOT(modelColumnsAdded(QModelIndex,int,int)));
58 connect(d->m_model, SIGNAL(columnsRemoved(QModelIndex,int,int)), d, SLOT(modelColumnsRemoved(QModelIndex,int,int)));
58 connect(d->m_model, SIGNAL(columnsRemoved(QModelIndex,int,int)), d, SLOT(modelColumnsRemoved(QModelIndex,int,int)));
59 connect(d->m_model, SIGNAL(destroyed()), d, SLOT(handleModelDestroyed()));
59 connect(d->m_model, SIGNAL(destroyed()), d, SLOT(handleModelDestroyed()));
60 }
60 }
61
61
62 QPieSeries* QPieModelMapper::series() const
62 QPieSeries* QPieModelMapper::series() const
63 {
63 {
64 Q_D(const QPieModelMapper);
64 Q_D(const QPieModelMapper);
65 return d->m_series;
65 return d->m_series;
66 }
66 }
67
67
68 void QPieModelMapper::setSeries(QPieSeries *series)
68 void QPieModelMapper::setSeries(QPieSeries *series)
69 {
69 {
70 Q_D(QPieModelMapper);
70 Q_D(QPieModelMapper);
71 if (d->m_series) {
71 if (d->m_series) {
72 disconnect(d->m_series, 0, d, 0);
72 disconnect(d->m_series, 0, d, 0);
73 }
73 }
74
74
75 if (series == 0)
75 if (series == 0)
76 return;
76 return;
77
77
78 d->m_series = series;
78 d->m_series = series;
79 d->initializePieFromModel();
79 d->initializePieFromModel();
80 // connect the signals from the series
80 // connect the signals from the series
81 connect(d->m_series, SIGNAL(added(QList<QPieSlice*>)), d, SLOT(slicesAdded(QList<QPieSlice*>)));
81 connect(d->m_series, SIGNAL(added(QList<QPieSlice*>)), d, SLOT(slicesAdded(QList<QPieSlice*>)));
82 connect(d->m_series, SIGNAL(removed(QList<QPieSlice*>)), d, SLOT(slicesRemoved(QList<QPieSlice*>)));
82 connect(d->m_series, SIGNAL(removed(QList<QPieSlice*>)), d, SLOT(slicesRemoved(QList<QPieSlice*>)));
83 connect(d->m_series, SIGNAL(destroyed()), d, SLOT(handleSeriesDestroyed()));
83 connect(d->m_series, SIGNAL(destroyed()), d, SLOT(handleSeriesDestroyed()));
84 }
84 }
85
85
86 /*!
86 /*!
87 Defines which row/column of the model contains the first slice value.
87 Defines which row/column of the model contains the first slice value.
88 Minimal and default value is: 0
88 Minimal and default value is: 0
89 */
89 */
90 int QPieModelMapper::first() const
90 int QPieModelMapper::first() const
91 {
91 {
92 Q_D(const QPieModelMapper);
92 Q_D(const QPieModelMapper);
93 return d->m_first;
93 return d->m_first;
94 }
94 }
95
95
96 /*!
96 /*!
97 Sets which row/column of the model contains the \a first slice value.
97 Sets which row/column of the model contains the \a first slice value.
98 Minimal and default value is: 0
98 Minimal and default value is: 0
99 */
99 */
100 void QPieModelMapper::setFirst(int first)
100 void QPieModelMapper::setFirst(int first)
101 {
101 {
102 Q_D(QPieModelMapper);
102 Q_D(QPieModelMapper);
103 d->m_first = qMax(first, 0);
103 d->m_first = qMax(first, 0);
104 d->initializePieFromModel();
104 d->initializePieFromModel();
105 }
105 }
106
106
107 /*!
107 /*!
108 Defines the number of rows/columns of the model that are mapped as the data for QPieSeries
108 Defines the number of rows/columns of the model that are mapped as the data for QPieSeries
109 Minimal and default value is: -1 (count limited by the number of rows/columns in the model)
109 Minimal and default value is: -1 (count limited by the number of rows/columns in the model)
110 */
110 */
111 int QPieModelMapper::count() const
111 int QPieModelMapper::count() const
112 {
112 {
113 Q_D(const QPieModelMapper);
113 Q_D(const QPieModelMapper);
114 return d->m_count;
114 return d->m_count;
115 }
115 }
116
116
117 /*!
117 /*!
118 Defines the \a count of rows/columns of the model that are mapped as the data for QPieSeries
118 Defines the \a count of rows/columns of the model that are mapped as the data for QPieSeries
119 Minimal and default value is: -1 (count limited by the number of rows/columns in the model)
119 Minimal and default value is: -1 (count limited by the number of rows/columns in the model)
120 */
120 */
121 void QPieModelMapper::setCount(int count)
121 void QPieModelMapper::setCount(int count)
122 {
122 {
123 Q_D(QPieModelMapper);
123 Q_D(QPieModelMapper);
124 d->m_count = qMax(count, -1);
124 d->m_count = qMax(count, -1);
125 d->initializePieFromModel();
125 d->initializePieFromModel();
126 }
126 }
127
127
128 /*!
128 /*!
129 Returns the orientation that is used when QPieModelMapper accesses the model.
129 Returns the orientation that is used when QPieModelMapper accesses the model.
130 This mean whether the consecutive values/labels of the pie are read from row (Qt::Horizontal)
130 This mean whether the consecutive values/labels of the pie are read from row (Qt::Horizontal)
131 or from columns (Qt::Vertical)
131 or from columns (Qt::Vertical)
132 */
132 */
133 Qt::Orientation QPieModelMapper::orientation() const
133 Qt::Orientation QPieModelMapper::orientation() const
134 {
134 {
135 Q_D(const QPieModelMapper);
135 Q_D(const QPieModelMapper);
136 return d->m_orientation;
136 return d->m_orientation;
137 }
137 }
138
138
139 /*!
139 /*!
140 Returns the \a orientation that is used when QPieModelMapper accesses the model.
140 Returns the \a orientation that is used when QPieModelMapper accesses the model.
141 This mean whether the consecutive values/labels of the pie are read from row (Qt::Horizontal)
141 This mean whether the consecutive values/labels of the pie are read from row (Qt::Horizontal)
142 or from columns (Qt::Vertical)
142 or from columns (Qt::Vertical)
143 */
143 */
144 void QPieModelMapper::setOrientation(Qt::Orientation orientation)
144 void QPieModelMapper::setOrientation(Qt::Orientation orientation)
145 {
145 {
146 Q_D(QPieModelMapper);
146 Q_D(QPieModelMapper);
147 d->m_orientation = orientation;
147 d->m_orientation = orientation;
148 d->initializePieFromModel();
148 d->initializePieFromModel();
149 }
149 }
150
150
151 /*!
151 /*!
152 Returns which section of the model is kept in sync with the values of the pie's slices
152 Returns which section of the model is kept in sync with the values of the pie's slices
153 */
153 */
154 int QPieModelMapper::valuesSection() const
154 int QPieModelMapper::valuesSection() const
155 {
155 {
156 Q_D(const QPieModelMapper);
156 Q_D(const QPieModelMapper);
157 return d->m_valuesSection;
157 return d->m_valuesSection;
158 }
158 }
159
159
160 /*!
160 /*!
161 Sets the model section that is kept in sync with the pie slices values.
161 Sets the model section that is kept in sync with the pie slices values.
162 Parameter \a valuesSection specifies the section of the model.
162 Parameter \a valuesSection specifies the section of the model.
163 */
163 */
164 void QPieModelMapper::setValuesSection(int valuesSection)
164 void QPieModelMapper::setValuesSection(int valuesSection)
165 {
165 {
166 Q_D(QPieModelMapper);
166 Q_D(QPieModelMapper);
167 d->m_valuesSection = qMax(-1, valuesSection);
167 d->m_valuesSection = qMax(-1, valuesSection);
168 d->initializePieFromModel();
168 d->initializePieFromModel();
169 }
169 }
170
170
171 /*!
171 /*!
172 Returns which section of the model is kept in sync with the labels of the pie's slices
172 Returns which section of the model is kept in sync with the labels of the pie's slices
173 */
173 */
174 int QPieModelMapper::labelsSection() const
174 int QPieModelMapper::labelsSection() const
175 {
175 {
176 Q_D(const QPieModelMapper);
176 Q_D(const QPieModelMapper);
177 return d->m_labelsSection;
177 return d->m_labelsSection;
178 }
178 }
179
179
180 /*!
180 /*!
181 Sets the model section that is kept in sync with the pie slices labels.
181 Sets the model section that is kept in sync with the pie slices labels.
182 Parameter \a labelsSection specifies the section of the model.
182 Parameter \a labelsSection specifies the section of the model.
183 */
183 */
184 void QPieModelMapper::setLabelsSection(int labelsSection)
184 void QPieModelMapper::setLabelsSection(int labelsSection)
185 {
185 {
186 Q_D(QPieModelMapper);
186 Q_D(QPieModelMapper);
187 d->m_labelsSection = qMax(-1, labelsSection);
187 d->m_labelsSection = qMax(-1, labelsSection);
188 d->initializePieFromModel();
188 d->initializePieFromModel();
189 }
189 }
190
190
191 ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
191 ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
192
192
193 QPieModelMapperPrivate::QPieModelMapperPrivate(QPieModelMapper *q) :
193 QPieModelMapperPrivate::QPieModelMapperPrivate(QPieModelMapper *q) :
194 QObject(q),
194 QObject(q),
195 m_series(0),
195 m_series(0),
196 m_model(0),
196 m_model(0),
197 m_first(0),
197 m_first(0),
198 m_count(-1),
198 m_count(-1),
199 m_orientation(Qt::Vertical),
199 m_orientation(Qt::Vertical),
200 m_valuesSection(-1),
200 m_valuesSection(-1),
201 m_labelsSection(-1),
201 m_labelsSection(-1),
202 m_seriesSignalsBlock(false),
202 m_seriesSignalsBlock(false),
203 m_modelSignalsBlock(false),
203 m_modelSignalsBlock(false),
204 q_ptr(q)
204 q_ptr(q)
205 {
205 {
206 }
206 }
207
207
208 void QPieModelMapperPrivate::blockModelSignals(bool block)
208 void QPieModelMapperPrivate::blockModelSignals(bool block)
209 {
209 {
210 m_modelSignalsBlock = block;
210 m_modelSignalsBlock = block;
211 }
211 }
212
212
213 void QPieModelMapperPrivate::blockSeriesSignals(bool block)
213 void QPieModelMapperPrivate::blockSeriesSignals(bool block)
214 {
214 {
215 m_seriesSignalsBlock = block;
215 m_seriesSignalsBlock = block;
216 }
216 }
217
217
218
218
219 QPieSlice* QPieModelMapperPrivate::pieSlice(QModelIndex index) const
219 QPieSlice* QPieModelMapperPrivate::pieSlice(QModelIndex index) const
220 {
220 {
221 if (!index.isValid())
221 if (!index.isValid())
222 return 0; // index is invalid
222 return 0; // index is invalid
223
223
224 if (m_orientation == Qt::Vertical && (index.column() == m_valuesSection || index.column() == m_labelsSection)) {
224 if (m_orientation == Qt::Vertical && (index.column() == m_valuesSection || index.column() == m_labelsSection)) {
225 if (index.row() >= m_first && (m_count == - 1 || index.row() < m_first + m_count)) {
225 if (index.row() >= m_first && (m_count == - 1 || index.row() < m_first + m_count)) {
226 if (m_model->index(index.row(), m_valuesSection).isValid() && m_model->index(index.row(), m_labelsSection).isValid())
226 if (m_model->index(index.row(), m_valuesSection).isValid() && m_model->index(index.row(), m_labelsSection).isValid())
227 return m_series->slices().at(index.row() - m_first);
227 return m_series->slices().at(index.row() - m_first);
228 else
228 else
229 return 0;
229 return 0;
230 }
230 }
231 } else if (m_orientation == Qt::Horizontal && (index.row() == m_valuesSection || index.row() == m_labelsSection)) {
231 } else if (m_orientation == Qt::Horizontal && (index.row() == m_valuesSection || index.row() == m_labelsSection)) {
232 if (index.column() >= m_first && (m_count == - 1 || index.column() < m_first + m_count)) {
232 if (index.column() >= m_first && (m_count == - 1 || index.column() < m_first + m_count)) {
233 if (m_model->index(m_valuesSection, index.column()).isValid() && m_model->index(m_labelsSection, index.column()).isValid())
233 if (m_model->index(m_valuesSection, index.column()).isValid() && m_model->index(m_labelsSection, index.column()).isValid())
234 return m_series->slices().at(index.column() - m_first);
234 return m_series->slices().at(index.column() - m_first);
235 else
235 else
236 return 0;
236 return 0;
237 }
237 }
238 }
238 }
239 return 0; // This part of model has not been mapped to any slice
239 return 0; // This part of model has not been mapped to any slice
240 }
240 }
241
241
242 QModelIndex QPieModelMapperPrivate::valueModelIndex(int slicePos)
242 QModelIndex QPieModelMapperPrivate::valueModelIndex(int slicePos)
243 {
243 {
244 if (m_count != -1 && slicePos >= m_count)
244 if (m_count != -1 && slicePos >= m_count)
245 return QModelIndex(); // invalid
245 return QModelIndex(); // invalid
246
246
247 if (m_orientation == Qt::Vertical)
247 if (m_orientation == Qt::Vertical)
248 return m_model->index(slicePos + m_first, m_valuesSection);
248 return m_model->index(slicePos + m_first, m_valuesSection);
249 else
249 else
250 return m_model->index(m_valuesSection, slicePos + m_first);
250 return m_model->index(m_valuesSection, slicePos + m_first);
251 }
251 }
252
252
253 QModelIndex QPieModelMapperPrivate::labelModelIndex(int slicePos)
253 QModelIndex QPieModelMapperPrivate::labelModelIndex(int slicePos)
254 {
254 {
255 if (m_count != -1 && slicePos >= m_count)
255 if (m_count != -1 && slicePos >= m_count)
256 return QModelIndex(); // invalid
256 return QModelIndex(); // invalid
257
257
258 if (m_orientation == Qt::Vertical)
258 if (m_orientation == Qt::Vertical)
259 return m_model->index(slicePos + m_first, m_labelsSection);
259 return m_model->index(slicePos + m_first, m_labelsSection);
260 else
260 else
261 return m_model->index(m_labelsSection, slicePos + m_first);
261 return m_model->index(m_labelsSection, slicePos + m_first);
262 }
262 }
263
263
264 bool QPieModelMapperPrivate::isLabelIndex(QModelIndex index) const
264 bool QPieModelMapperPrivate::isLabelIndex(QModelIndex index) const
265 {
265 {
266 if (m_orientation == Qt::Vertical && index.column() == m_labelsSection)
266 if (m_orientation == Qt::Vertical && index.column() == m_labelsSection)
267 return true;
267 return true;
268 else if (m_orientation == Qt::Horizontal && index.row() == m_labelsSection)
268 else if (m_orientation == Qt::Horizontal && index.row() == m_labelsSection)
269 return true;
269 return true;
270
270
271 return false;
271 return false;
272 }
272 }
273
273
274 bool QPieModelMapperPrivate::isValueIndex(QModelIndex index) const
274 bool QPieModelMapperPrivate::isValueIndex(QModelIndex index) const
275 {
275 {
276 if (m_orientation == Qt::Vertical && index.column() == m_valuesSection)
276 if (m_orientation == Qt::Vertical && index.column() == m_valuesSection)
277 return true;
277 return true;
278 else if (m_orientation == Qt::Horizontal && index.row() == m_valuesSection)
278 else if (m_orientation == Qt::Horizontal && index.row() == m_valuesSection)
279 return true;
279 return true;
280
280
281 return false;
281 return false;
282 }
282 }
283
283
284 void QPieModelMapperPrivate::slicesAdded(QList<QPieSlice*> slices)
284 void QPieModelMapperPrivate::slicesAdded(QList<QPieSlice*> slices)
285 {
285 {
286 if (m_seriesSignalsBlock)
286 if (m_seriesSignalsBlock)
287 return;
287 return;
288
288
289 if (slices.count() == 0)
289 if (slices.count() == 0)
290 return;
290 return;
291
291
292 int firstIndex = m_series->slices().indexOf(slices.at(0));
292 int firstIndex = m_series->slices().indexOf(slices.at(0));
293 if (firstIndex == -1)
293 if (firstIndex == -1)
294 return;
294 return;
295
295
296 if (m_count != -1)
296 if (m_count != -1)
297 m_count += slices.count();
297 m_count += slices.count();
298
298
299 for (int i = firstIndex; i < firstIndex + slices.count(); i++) {
299 for (int i = firstIndex; i < firstIndex + slices.count(); i++) {
300 m_slices.insert(i, slices.at(i - firstIndex));
300 m_slices.insert(i, slices.at(i - firstIndex));
301 connect(slices.at(i - firstIndex), SIGNAL(labelChanged()), this, SLOT(sliceLabelChanged()));
301 connect(slices.at(i - firstIndex), SIGNAL(labelChanged()), this, SLOT(sliceLabelChanged()));
302 connect(slices.at(i - firstIndex), SIGNAL(valueChanged()), this, SLOT(sliceValueChanged()));
302 connect(slices.at(i - firstIndex), SIGNAL(valueChanged()), this, SLOT(sliceValueChanged()));
303 }
303 }
304
304
305 blockModelSignals();
305 blockModelSignals();
306 if (m_orientation == Qt::Vertical)
306 if (m_orientation == Qt::Vertical)
307 m_model->insertRows(firstIndex + m_first, slices.count());
307 m_model->insertRows(firstIndex + m_first, slices.count());
308 else
308 else
309 m_model->insertColumns(firstIndex + m_first, slices.count());
309 m_model->insertColumns(firstIndex + m_first, slices.count());
310
310
311 for(int i = firstIndex; i < firstIndex + slices.count(); i++) {
311 for(int i = firstIndex; i < firstIndex + slices.count(); i++) {
312 m_model->setData(valueModelIndex(i), slices.at(i - firstIndex)->value());
312 m_model->setData(valueModelIndex(i), slices.at(i - firstIndex)->value());
313 m_model->setData(labelModelIndex(i), slices.at(i - firstIndex)->label());
313 m_model->setData(labelModelIndex(i), slices.at(i - firstIndex)->label());
314 }
314 }
315 blockModelSignals(false);
315 blockModelSignals(false);
316 }
316 }
317
317
318 void QPieModelMapperPrivate::slicesRemoved(QList<QPieSlice*> slices)
318 void QPieModelMapperPrivate::slicesRemoved(QList<QPieSlice*> slices)
319 {
319 {
320 if (m_seriesSignalsBlock)
320 if (m_seriesSignalsBlock)
321 return;
321 return;
322
322
323 if (slices.count() == 0)
323 if (slices.count() == 0)
324 return;
324 return;
325
325
326 int firstIndex = m_slices.indexOf(slices.at(0));
326 int firstIndex = m_slices.indexOf(slices.at(0));
327 if (firstIndex == -1)
327 if (firstIndex == -1)
328 return;
328 return;
329
329
330 if (m_count != -1)
330 if (m_count != -1)
331 m_count -= slices.count();
331 m_count -= slices.count();
332
332
333 for (int i = firstIndex + slices.count() - 1; i >= firstIndex; i--)
333 for (int i = firstIndex + slices.count() - 1; i >= firstIndex; i--)
334 m_slices.removeAt(i);
334 m_slices.removeAt(i);
335
335
336 blockModelSignals();
336 blockModelSignals();
337 if (m_orientation == Qt::Vertical)
337 if (m_orientation == Qt::Vertical)
338 m_model->removeRows(firstIndex + m_first, slices.count());
338 m_model->removeRows(firstIndex + m_first, slices.count());
339 else
339 else
340 m_model->removeColumns(firstIndex + m_first, slices.count());
340 m_model->removeColumns(firstIndex + m_first, slices.count());
341 blockModelSignals(false);
341 blockModelSignals(false);
342 }
342 }
343
343
344 void QPieModelMapperPrivate::sliceLabelChanged()
344 void QPieModelMapperPrivate::sliceLabelChanged()
345 {
345 {
346 if (m_seriesSignalsBlock)
346 if (m_seriesSignalsBlock)
347 return;
347 return;
348
348
349 blockModelSignals();
349 blockModelSignals();
350 QPieSlice *slice = qobject_cast<QPieSlice *>(QObject::sender());
350 QPieSlice *slice = qobject_cast<QPieSlice *>(QObject::sender());
351 m_model->setData(labelModelIndex(m_series->slices().indexOf(slice)), slice->label());
351 m_model->setData(labelModelIndex(m_series->slices().indexOf(slice)), slice->label());
352 blockModelSignals(false);
352 blockModelSignals(false);
353 }
353 }
354
354
355 void QPieModelMapperPrivate::sliceValueChanged()
355 void QPieModelMapperPrivate::sliceValueChanged()
356 {
356 {
357 if (m_seriesSignalsBlock)
357 if (m_seriesSignalsBlock)
358 return;
358 return;
359
359
360 blockModelSignals();
360 blockModelSignals();
361 QPieSlice *slice = qobject_cast<QPieSlice *>(QObject::sender());
361 QPieSlice *slice = qobject_cast<QPieSlice *>(QObject::sender());
362 m_model->setData(valueModelIndex(m_series->slices().indexOf(slice)), slice->value());
362 m_model->setData(valueModelIndex(m_series->slices().indexOf(slice)), slice->value());
363 blockModelSignals(false);
363 blockModelSignals(false);
364 }
364 }
365
365
366 void QPieModelMapperPrivate::handleSeriesDestroyed()
366 void QPieModelMapperPrivate::handleSeriesDestroyed()
367 {
367 {
368 m_series = 0;
368 m_series = 0;
369 }
369 }
370
370
371 void QPieModelMapperPrivate::modelUpdated(QModelIndex topLeft, QModelIndex bottomRight)
371 void QPieModelMapperPrivate::modelUpdated(QModelIndex topLeft, QModelIndex bottomRight)
372 {
372 {
373 if (m_model == 0 || m_series == 0)
373 if (m_model == 0 || m_series == 0)
374 return;
374 return;
375
375
376 if (m_modelSignalsBlock)
376 if (m_modelSignalsBlock)
377 return;
377 return;
378
378
379 blockSeriesSignals();
379 blockSeriesSignals();
380 QModelIndex index;
380 QModelIndex index;
381 QPieSlice *slice;
381 QPieSlice *slice;
382 for (int row = topLeft.row(); row <= bottomRight.row(); row++) {
382 for (int row = topLeft.row(); row <= bottomRight.row(); row++) {
383 for (int column = topLeft.column(); column <= bottomRight.column(); column++) {
383 for (int column = topLeft.column(); column <= bottomRight.column(); column++) {
384 index = topLeft.sibling(row, column);
384 index = topLeft.sibling(row, column);
385 slice = pieSlice(index);
385 slice = pieSlice(index);
386 if (slice) {
386 if (slice) {
387 if (isValueIndex(index))
387 if (isValueIndex(index))
388 slice->setValue(m_model->data(index, Qt::DisplayRole).toReal());
388 slice->setValue(m_model->data(index, Qt::DisplayRole).toReal());
389 if (isLabelIndex(index))
389 if (isLabelIndex(index))
390 slice->setLabel(m_model->data(index, Qt::DisplayRole).toString());
390 slice->setLabel(m_model->data(index, Qt::DisplayRole).toString());
391 }
391 }
392 }
392 }
393 }
393 }
394 blockSeriesSignals(false);
394 blockSeriesSignals(false);
395 }
395 }
396
396
397
397
398 void QPieModelMapperPrivate::modelRowsAdded(QModelIndex parent, int start, int end)
398 void QPieModelMapperPrivate::modelRowsAdded(QModelIndex parent, int start, int end)
399 {
399 {
400 Q_UNUSED(parent);
400 Q_UNUSED(parent);
401 if (m_modelSignalsBlock)
401 if (m_modelSignalsBlock)
402 return;
402 return;
403
403
404 blockSeriesSignals();
404 blockSeriesSignals();
405 if (m_orientation == Qt::Vertical)
405 if (m_orientation == Qt::Vertical)
406 insertData(start, end);
406 insertData(start, end);
407 else if (start <= m_valuesSection || start <= m_labelsSection) // if the changes affect the map - reinitialize the pie
407 else if (start <= m_valuesSection || start <= m_labelsSection) // if the changes affect the map - reinitialize the pie
408 initializePieFromModel();
408 initializePieFromModel();
409 blockSeriesSignals(false);
409 blockSeriesSignals(false);
410 }
410 }
411
411
412 void QPieModelMapperPrivate::modelRowsRemoved(QModelIndex parent, int start, int end)
412 void QPieModelMapperPrivate::modelRowsRemoved(QModelIndex parent, int start, int end)
413 {
413 {
414 Q_UNUSED(parent);
414 Q_UNUSED(parent);
415 if (m_modelSignalsBlock)
415 if (m_modelSignalsBlock)
416 return;
416 return;
417
417
418 blockSeriesSignals();
418 blockSeriesSignals();
419 if (m_orientation == Qt::Vertical)
419 if (m_orientation == Qt::Vertical)
420 removeData(start, end);
420 removeData(start, end);
421 else if (start <= m_valuesSection || start <= m_labelsSection) // if the changes affect the map - reinitialize the pie
421 else if (start <= m_valuesSection || start <= m_labelsSection) // if the changes affect the map - reinitialize the pie
422 initializePieFromModel();
422 initializePieFromModel();
423 blockSeriesSignals(false);
423 blockSeriesSignals(false);
424 }
424 }
425
425
426 void QPieModelMapperPrivate::modelColumnsAdded(QModelIndex parent, int start, int end)
426 void QPieModelMapperPrivate::modelColumnsAdded(QModelIndex parent, int start, int end)
427 {
427 {
428 Q_UNUSED(parent);
428 Q_UNUSED(parent);
429 if (m_modelSignalsBlock)
429 if (m_modelSignalsBlock)
430 return;
430 return;
431
431
432 blockSeriesSignals();
432 blockSeriesSignals();
433 if (m_orientation == Qt::Horizontal)
433 if (m_orientation == Qt::Horizontal)
434 insertData(start, end);
434 insertData(start, end);
435 else if (start <= m_valuesSection || start <= m_labelsSection) // if the changes affect the map - reinitialize the pie
435 else if (start <= m_valuesSection || start <= m_labelsSection) // if the changes affect the map - reinitialize the pie
436 initializePieFromModel();
436 initializePieFromModel();
437 blockSeriesSignals(false);
437 blockSeriesSignals(false);
438 }
438 }
439
439
440 void QPieModelMapperPrivate::modelColumnsRemoved(QModelIndex parent, int start, int end)
440 void QPieModelMapperPrivate::modelColumnsRemoved(QModelIndex parent, int start, int end)
441 {
441 {
442 Q_UNUSED(parent);
442 Q_UNUSED(parent);
443 if (m_modelSignalsBlock)
443 if (m_modelSignalsBlock)
444 return;
444 return;
445
445
446 blockSeriesSignals();
446 blockSeriesSignals();
447 if (m_orientation == Qt::Horizontal)
447 if (m_orientation == Qt::Horizontal)
448 removeData(start, end);
448 removeData(start, end);
449 else if (start <= m_valuesSection || start <= m_labelsSection) // if the changes affect the map - reinitialize the pie
449 else if (start <= m_valuesSection || start <= m_labelsSection) // if the changes affect the map - reinitialize the pie
450 initializePieFromModel();
450 initializePieFromModel();
451 blockSeriesSignals(false);
451 blockSeriesSignals(false);
452 }
452 }
453
453
454 void QPieModelMapperPrivate::handleModelDestroyed()
454 void QPieModelMapperPrivate::handleModelDestroyed()
455 {
455 {
456 m_model = 0;
456 m_model = 0;
457 }
457 }
458
458
459 void QPieModelMapperPrivate::insertData(int start, int end)
459 void QPieModelMapperPrivate::insertData(int start, int end)
460 {
460 {
461 if (m_model == 0 || m_series == 0)
461 if (m_model == 0 || m_series == 0)
462 return;
462 return;
463
463
464 if (m_count != -1 && start >= m_first + m_count) {
464 if (m_count != -1 && start >= m_first + m_count) {
465 return;
465 return;
466 } else {
466 } else {
467 int addedCount = end - start + 1;
467 int addedCount = end - start + 1;
468 if (m_count != -1 && addedCount > m_count)
468 if (m_count != -1 && addedCount > m_count)
469 addedCount = m_count;
469 addedCount = m_count;
470 int first = qMax(start, m_first);
470 int first = qMax(start, m_first);
471 int last = qMin(first + addedCount - 1, m_orientation == Qt::Vertical ? m_model->rowCount() - 1 : m_model->columnCount() - 1);
471 int last = qMin(first + addedCount - 1, m_orientation == Qt::Vertical ? m_model->rowCount() - 1 : m_model->columnCount() - 1);
472 for (int i = first; i <= last; i++) {
472 for (int i = first; i <= last; i++) {
473 QModelIndex valueIndex = valueModelIndex(i - m_first);
473 QModelIndex valueIndex = valueModelIndex(i - m_first);
474 QModelIndex labelIndex = labelModelIndex(i - m_first);
474 QModelIndex labelIndex = labelModelIndex(i - m_first);
475 if (valueIndex.isValid() && labelIndex.isValid()) {
475 if (valueIndex.isValid() && labelIndex.isValid()) {
476 QPieSlice *slice = new QPieSlice;
476 QPieSlice *slice = new QPieSlice;
477 slice->setValue(m_model->data(valueIndex, Qt::DisplayRole).toDouble());
477 slice->setValue(m_model->data(valueIndex, Qt::DisplayRole).toDouble());
478 slice->setLabel(m_model->data(labelIndex, Qt::DisplayRole).toString());
478 slice->setLabel(m_model->data(labelIndex, Qt::DisplayRole).toString());
479 connect(slice, SIGNAL(labelChanged()), this, SLOT(sliceLabelChanged()));
479 connect(slice, SIGNAL(labelChanged()), this, SLOT(sliceLabelChanged()));
480 connect(slice, SIGNAL(valueChanged()), this, SLOT(sliceValueChanged()));
480 connect(slice, SIGNAL(valueChanged()), this, SLOT(sliceValueChanged()));
481 m_series->insert(i - m_first, slice);
481 m_series->insert(i - m_first, slice);
482 m_slices.insert(i - m_first, slice);
482 m_slices.insert(i - m_first, slice);
483 }
483 }
484 }
484 }
485
485
486 // remove excess of slices (abouve m_count)
486 // remove excess of slices (abouve m_count)
487 if (m_count != -1 && m_series->slices().size() > m_count)
487 if (m_count != -1 && m_series->slices().size() > m_count)
488 for (int i = m_series->slices().size() - 1; i >= m_count; i--) {
488 for (int i = m_series->slices().size() - 1; i >= m_count; i--) {
489 m_series->remove(m_series->slices().at(i));
489 m_series->remove(m_series->slices().at(i));
490 m_slices.removeAt(i);
490 m_slices.removeAt(i);
491 }
491 }
492 }
492 }
493 }
493 }
494
494
495 void QPieModelMapperPrivate::removeData(int start, int end)
495 void QPieModelMapperPrivate::removeData(int start, int end)
496 {
496 {
497 if (m_model == 0 || m_series == 0)
497 if (m_model == 0 || m_series == 0)
498 return;
498 return;
499
499
500 int removedCount = end - start + 1;
500 int removedCount = end - start + 1;
501 if (m_count != -1 && start >= m_first + m_count) {
501 if (m_count != -1 && start >= m_first + m_count) {
502 return;
502 return;
503 } else {
503 } else {
504 int toRemove = qMin(m_series->slices().size(), removedCount); // first find how many items can actually be removed
504 int toRemove = qMin(m_series->slices().size(), removedCount); // first find how many items can actually be removed
505 int first = qMax(start, m_first); // get the index of the first item that will be removed.
505 int first = qMax(start, m_first); // get the index of the first item that will be removed.
506 int last = qMin(first + toRemove - 1, m_series->slices().size() + m_first - 1); // get the index of the last item that will be removed.
506 int last = qMin(first + toRemove - 1, m_series->slices().size() + m_first - 1); // get the index of the last item that will be removed.
507 for (int i = last; i >= first; i--) {
507 for (int i = last; i >= first; i--) {
508 m_series->remove(m_series->slices().at(i - m_first));
508 m_series->remove(m_series->slices().at(i - m_first));
509 m_slices.removeAt(i - m_first);
509 m_slices.removeAt(i - m_first);
510 }
510 }
511
511
512 if (m_count != -1) {
512 if (m_count != -1) {
513 int itemsAvailable; // check how many are available to be added
513 int itemsAvailable; // check how many are available to be added
514 if (m_orientation == Qt::Vertical)
514 if (m_orientation == Qt::Vertical)
515 itemsAvailable = m_model->rowCount() - m_first - m_series->slices().size();
515 itemsAvailable = m_model->rowCount() - m_first - m_series->slices().size();
516 else
516 else
517 itemsAvailable = m_model->columnCount() - m_first - m_series->slices().size();
517 itemsAvailable = m_model->columnCount() - m_first - m_series->slices().size();
518 int toBeAdded = qMin(itemsAvailable, m_count - m_series->slices().size()); // add not more items than there is space left to be filled.
518 int toBeAdded = qMin(itemsAvailable, m_count - m_series->slices().size()); // add not more items than there is space left to be filled.
519 int currentSize = m_series->slices().size();
519 int currentSize = m_series->slices().size();
520 if (toBeAdded > 0)
520 if (toBeAdded > 0)
521 for (int i = m_series->slices().size(); i < currentSize + toBeAdded; i++) {
521 for (int i = m_series->slices().size(); i < currentSize + toBeAdded; i++) {
522 QModelIndex valueIndex = valueModelIndex(i - m_first);
522 QModelIndex valueIndex = valueModelIndex(i - m_first);
523 QModelIndex labelIndex = labelModelIndex(i - m_first);
523 QModelIndex labelIndex = labelModelIndex(i - m_first);
524 if (valueIndex.isValid() && labelIndex.isValid()) {
524 if (valueIndex.isValid() && labelIndex.isValid()) {
525 QPieSlice *slice = new QPieSlice;
525 QPieSlice *slice = new QPieSlice;
526 slice->setValue(m_model->data(valueIndex, Qt::DisplayRole).toDouble());
526 slice->setValue(m_model->data(valueIndex, Qt::DisplayRole).toDouble());
527 slice->setLabel(m_model->data(labelIndex, Qt::DisplayRole).toString());
527 slice->setLabel(m_model->data(labelIndex, Qt::DisplayRole).toString());
528 m_series->insert(i, slice);
528 m_series->insert(i, slice);
529 m_slices.insert(i, slice);
529 m_slices.insert(i, slice);
530 }
530 }
531 }
531 }
532 }
532 }
533 }
533 }
534 }
534 }
535
535
536 void QPieModelMapperPrivate::initializePieFromModel()
536 void QPieModelMapperPrivate::initializePieFromModel()
537 {
537 {
538 if (m_model == 0 || m_series == 0)
538 if (m_model == 0 || m_series == 0)
539 return;
539 return;
540
540
541 blockSeriesSignals();
541 blockSeriesSignals();
542 // clear current content
542 // clear current content
543 m_series->clear();
543 m_series->clear();
544 m_slices.clear();
544 m_slices.clear();
545
545
546 // create the initial slices set
546 // create the initial slices set
547 int slicePos = 0;
547 int slicePos = 0;
548 QModelIndex valueIndex = valueModelIndex(slicePos);
548 QModelIndex valueIndex = valueModelIndex(slicePos);
549 QModelIndex labelIndex = labelModelIndex(slicePos);
549 QModelIndex labelIndex = labelModelIndex(slicePos);
550 while (valueIndex.isValid() && labelIndex.isValid()) {
550 while (valueIndex.isValid() && labelIndex.isValid()) {
551 QPieSlice *slice = new QPieSlice;
551 QPieSlice *slice = new QPieSlice;
552 slice->setLabel(m_model->data(labelIndex, Qt::DisplayRole).toString());
552 slice->setLabel(m_model->data(labelIndex, Qt::DisplayRole).toString());
553 slice->setValue(m_model->data(valueIndex, Qt::DisplayRole).toDouble());
553 slice->setValue(m_model->data(valueIndex, Qt::DisplayRole).toDouble());
554 connect(slice, SIGNAL(labelChanged()), this, SLOT(sliceLabelChanged()));
554 connect(slice, SIGNAL(labelChanged()), this, SLOT(sliceLabelChanged()));
555 connect(slice, SIGNAL(valueChanged()), this, SLOT(sliceValueChanged()));
555 connect(slice, SIGNAL(valueChanged()), this, SLOT(sliceValueChanged()));
556 m_series->append(slice);
556 m_series->append(slice);
557 m_slices.append(slice);
557 m_slices.append(slice);
558 slicePos++;
558 slicePos++;
559 valueIndex = valueModelIndex(slicePos);
559 valueIndex = valueModelIndex(slicePos);
560 labelIndex = labelModelIndex(slicePos);
560 labelIndex = labelModelIndex(slicePos);
561 }
561 }
562 blockSeriesSignals(false);
562 blockSeriesSignals(false);
563 }
563 }
564
564
565 #include "moc_qpiemodelmapper_p.cpp"
565 #include "moc_qpiemodelmapper_p.cpp"
566 #include "moc_qpiemodelmapper.cpp"
566 #include "moc_qpiemodelmapper.cpp"
567
567
568 QTCOMMERCIALCHART_END_NAMESPACE
568 QTCOMMERCIALCHART_END_NAMESPACE
@@ -1,62 +1,62
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 QCHARTVIEW_P_H
30 #ifndef QCHARTVIEW_P_H
31 #define QCHARTVIEW_P_H
31 #define QCHARTVIEW_P_H
32
32
33 #include "qchartview.h"
33 #include "qchartview.h"
34
34
35 class QGraphicsScene;
35 class QGraphicsScene;
36 class ChartPresenter;
36 class ChartPresenter;
37
37
38 QTCOMMERCIALCHART_BEGIN_NAMESPACE
38 QTCOMMERCIALCHART_BEGIN_NAMESPACE
39
39
40 class QChart;
40 class QChart;
41 class QChartView;
41 class QChartView;
42
42
43 class QChartViewPrivate {
43 class QChartViewPrivate {
44
44
45 public:
45 public:
46 QChartViewPrivate(QChartView *q,QChart *chart = 0);
46 explicit QChartViewPrivate(QChartView *q, QChart *chart = 0);
47 ~QChartViewPrivate();
47 ~QChartViewPrivate();
48
48
49 protected:
49 protected:
50 QChartView *q_ptr;
50 QChartView *q_ptr;
51
51
52 public:
52 public:
53 QGraphicsScene *m_scene;
53 QGraphicsScene *m_scene;
54 QChart *m_chart;
54 QChart *m_chart;
55 ChartPresenter *m_presenter;
55 ChartPresenter *m_presenter;
56 QPoint m_rubberBandOrigin;
56 QPoint m_rubberBandOrigin;
57 QRubberBand *m_rubberBand;
57 QRubberBand *m_rubberBand;
58 QChartView::RubberBands m_rubberBandFlags;
58 QChartView::RubberBands m_rubberBandFlags;
59 };
59 };
60
60
61 QTCOMMERCIALCHART_END_NAMESPACE
61 QTCOMMERCIALCHART_END_NAMESPACE
62 #endif
62 #endif
@@ -1,107 +1,107
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 SCROLLER_P_H
30 #ifndef SCROLLER_P_H
31 #define SCROLLER_P_H
31 #define SCROLLER_P_H
32
32
33 #include "qchartglobal.h"
33 #include "qchartglobal.h"
34 #include <QBasicTimer>
34 #include <QBasicTimer>
35 #include <QTime>
35 #include <QTime>
36 #include <QPointF>
36 #include <QPointF>
37
37
38 class QGraphicsSceneMouseEvent;
38 class QGraphicsSceneMouseEvent;
39
39
40 QTCOMMERCIALCHART_BEGIN_NAMESPACE
40 QTCOMMERCIALCHART_BEGIN_NAMESPACE
41
41
42 class Scroller;
42 class Scroller;
43 class QLegend;
43 class QLegend;
44
44
45 class ScrollTicker : public QObject
45 class ScrollTicker : public QObject
46 {
46 {
47 Q_OBJECT
47 Q_OBJECT
48 public:
48 public:
49 explicit ScrollTicker(Scroller *scroller,QObject *parent = 0);
49 explicit ScrollTicker(Scroller *scroller,QObject *parent = 0);
50 void start(int interval);
50 void start(int interval);
51 void stop();
51 void stop();
52 protected:
52 protected:
53 void timerEvent(QTimerEvent *event);
53 void timerEvent(QTimerEvent *event);
54
54
55 private:
55 private:
56 QBasicTimer m_timer;
56 QBasicTimer m_timer;
57 Scroller *m_scroller;
57 Scroller *m_scroller;
58 };
58 };
59
59
60 class Scroller
60 class Scroller
61 {
61 {
62 public:
62 public:
63 enum State {
63 enum State {
64 Idle,
64 Idle,
65 Pressed,
65 Pressed,
66 Move,
66 Move,
67 Scroll,
67 Scroll,
68 Stop
68 Stop
69 };
69 };
70
70
71 Scroller();
71 Scroller();
72 virtual ~Scroller();
72 virtual ~Scroller();
73
73
74 virtual void setOffset(const QPointF& point) = 0;
74 virtual void setOffset(const QPointF& point) = 0;
75 virtual QPointF offset() const = 0;
75 virtual QPointF offset() const = 0;
76
76
77 public:
77 public:
78 void scrollTick();
78 void scrollTick();
79
79
80
80
81 public:
81 public:
82 void mousePressEvent(QGraphicsSceneMouseEvent* event);
82 void mousePressEvent(QGraphicsSceneMouseEvent* event);
83 void mouseMoveEvent(QGraphicsSceneMouseEvent* event);
83 void mouseMoveEvent(QGraphicsSceneMouseEvent* event);
84 void mouseReleaseEvent(QGraphicsSceneMouseEvent* event);
84 void mouseReleaseEvent(QGraphicsSceneMouseEvent* event);
85
85
86 private:
86 private:
87 void calculateSpeed(const QPointF& position);
87 void calculateSpeed(const QPointF& position);
88 void lowerSpeed(QPointF& speed,qreal maxSpeed=100);
88 void lowerSpeed(QPointF& speed,qreal maxSpeed=100);
89
89
90 private:
90 private:
91 ScrollTicker m_ticker;
91 ScrollTicker m_ticker;
92 State m_state;
92 State m_state;
93 QTime m_timeStamp;
93 QTime m_timeStamp;
94 QPointF m_press;
94 QPointF m_press;
95 QPointF m_offset;
95 QPointF m_offset;
96 QPointF m_speed;
96 QPointF m_speed;
97 QPointF m_distance;
97 QPointF m_distance;
98 QPointF m_fraction;
98 QPointF m_fraction;
99 int m_moveThreshold;
99 int m_moveThreshold;
100 int m_timeTreshold;
100 int m_timeTreshold;
101
101
102
102
103 };
103 };
104
104
105 QTCOMMERCIALCHART_END_NAMESPACE
105 QTCOMMERCIALCHART_END_NAMESPACE
106
106
107 #endif /* SCROLLER_P_H_ */
107 #endif /* SCROLLER_P_H */
@@ -1,107 +1,107
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 XYCHARTITEM_H
30 #ifndef XYCHART_H
31 #define XYCHARTITEM_H
31 #define XYCHART_H
32
32
33 #include "qchartglobal.h"
33 #include "qchartglobal.h"
34 #include "chartitem_p.h"
34 #include "chartitem_p.h"
35 #include "xyanimation_p.h"
35 #include "xyanimation_p.h"
36 #include "qvalueaxis.h"
36 #include "qvalueaxis.h"
37 #include <QPen>
37 #include <QPen>
38
38
39 QTCOMMERCIALCHART_BEGIN_NAMESPACE
39 QTCOMMERCIALCHART_BEGIN_NAMESPACE
40
40
41 class ChartPresenter;
41 class ChartPresenter;
42 class QXYSeries;
42 class QXYSeries;
43
43
44 class XYChart : public ChartElement
44 class XYChart : public ChartElement
45 {
45 {
46 Q_OBJECT
46 Q_OBJECT
47 public:
47 public:
48 explicit XYChart(QXYSeries *series, ChartPresenter *presenter);
48 explicit XYChart(QXYSeries *series, ChartPresenter *presenter);
49 ~XYChart() {}
49 ~XYChart() {}
50
50
51 void setGeometryPoints(const QVector<QPointF>& points);
51 void setGeometryPoints(const QVector<QPointF>& points);
52 QVector<QPointF> geometryPoints() const { return m_points; }
52 QVector<QPointF> geometryPoints() const { return m_points; }
53
53
54 void setClipRect(const QRectF &rect);
54 void setClipRect(const QRectF &rect);
55 QRectF clipRect() const { return m_clipRect; }
55 QRectF clipRect() const { return m_clipRect; }
56
56
57 QSizeF size() const { return m_size; }
57 QSizeF size() const { return m_size; }
58 QPointF origin() const { return m_origin; }
58 QPointF origin() const { return m_origin; }
59
59
60 void setAnimation(XYAnimation* animation);
60 void setAnimation(XYAnimation* animation);
61 ChartAnimation* animation() const { return m_animation; }
61 ChartAnimation* animation() const { return m_animation; }
62 virtual void updateGeometry() = 0;
62 virtual void updateGeometry() = 0;
63
63
64 bool isDirty() const { return m_dirty; }
64 bool isDirty() const { return m_dirty; }
65 void setDirty(bool dirty);
65 void setDirty(bool dirty);
66
66
67 public Q_SLOTS:
67 public Q_SLOTS:
68 void handlePointAdded(int index);
68 void handlePointAdded(int index);
69 void handlePointRemoved(int index);
69 void handlePointRemoved(int index);
70 void handlePointReplaced(int index);
70 void handlePointReplaced(int index);
71 void handlePointsReplaced();
71 void handlePointsReplaced();
72 void handleDomainUpdated();
72 void handleDomainUpdated();
73 void handleGeometryChanged(const QRectF &size);
73 void handleGeometryChanged(const QRectF &size);
74
74
75 Q_SIGNALS:
75 Q_SIGNALS:
76 void clicked(const QPointF& point);
76 void clicked(const QPointF& point);
77
77
78 protected:
78 protected:
79 virtual void updateChart(QVector<QPointF> &oldPoints,QVector<QPointF> &newPoints,int index = -1);
79 virtual void updateChart(QVector<QPointF> &oldPoints,QVector<QPointF> &newPoints,int index = -1);
80 QPointF calculateGeometryPoint(const QPointF &point) const;
80 QPointF calculateGeometryPoint(const QPointF &point) const;
81 QPointF calculateGeometryPoint(int index) const;
81 QPointF calculateGeometryPoint(int index) const;
82 QPointF calculateDomainPoint(const QPointF &point) const;
82 QPointF calculateDomainPoint(const QPointF &point) const;
83 QVector<QPointF> calculateGeometryPoints() const;
83 QVector<QPointF> calculateGeometryPoints() const;
84
84
85 private:
85 private:
86 inline bool isEmpty();
86 inline bool isEmpty();
87
87
88 protected:
88 protected:
89 qreal m_minX;
89 qreal m_minX;
90 qreal m_maxX;
90 qreal m_maxX;
91 qreal m_minY;
91 qreal m_minY;
92 qreal m_maxY;
92 qreal m_maxY;
93 QXYSeries* m_series;
93 QXYSeries* m_series;
94 QSizeF m_size;
94 QSizeF m_size;
95 QPointF m_origin;
95 QPointF m_origin;
96 QRectF m_clipRect;
96 QRectF m_clipRect;
97 QVector<QPointF> m_points;
97 QVector<QPointF> m_points;
98 XYAnimation* m_animation;
98 XYAnimation* m_animation;
99 bool m_dirty;
99 bool m_dirty;
100
100
101 friend class AreaChartItem;
101 friend class AreaChartItem;
102
102
103 };
103 };
104
104
105 QTCOMMERCIALCHART_END_NAMESPACE
105 QTCOMMERCIALCHART_END_NAMESPACE
106
106
107 #endif
107 #endif
General Comments 0
You need to be logged in to leave comments. Login now