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