@@ -1,37 +1,35 | |||||
1 | /**************************************************************************** |
|
1 | /**************************************************************************** | |
2 | ** |
|
2 | ** | |
3 | ** Copyright (C) 2012 Digia Plc |
|
3 | ** Copyright (C) 2012 Digia Plc | |
4 | ** All rights reserved. |
|
4 | ** All rights reserved. | |
5 | ** For any questions to Digia, please use contact form at http://qt.digia.com |
|
5 | ** For any questions to Digia, please use contact form at http://qt.digia.com | |
6 | ** |
|
6 | ** | |
7 | ** This file is part of the Qt Commercial Charts Add-on. |
|
7 | ** This file is part of the Qt Commercial Charts Add-on. | |
8 | ** |
|
8 | ** | |
9 | ** $QT_BEGIN_LICENSE$ |
|
9 | ** $QT_BEGIN_LICENSE$ | |
10 | ** Licensees holding valid Qt Commercial licenses may use this file in |
|
10 | ** Licensees holding valid Qt Commercial licenses may use this file in | |
11 | ** accordance with the Qt Commercial License Agreement provided with the |
|
11 | ** accordance with the Qt Commercial License Agreement provided with the | |
12 | ** Software or, alternatively, in accordance with the terms contained in |
|
12 | ** Software or, alternatively, in accordance with the terms contained in | |
13 | ** a written agreement between you and Digia. |
|
13 | ** a written agreement between you and Digia. | |
14 | ** |
|
14 | ** | |
15 | ** If you have questions regarding the use of this file, please use |
|
15 | ** If you have questions regarding the use of this file, please use | |
16 | ** contact form at http://qt.digia.com |
|
16 | ** contact form at http://qt.digia.com | |
17 | ** $QT_END_LICENSE$ |
|
17 | ** $QT_END_LICENSE$ | |
18 | ** |
|
18 | ** | |
19 | ****************************************************************************/ |
|
19 | ****************************************************************************/ | |
20 |
|
20 | |||
21 | #include "mainwidget.h" |
|
21 | #include "mainwidget.h" | |
22 |
|
22 | |||
23 | #include <QApplication> |
|
23 | #include <QApplication> | |
24 | #include <QMainWindow> |
|
24 | #include <QMainWindow> | |
25 |
|
25 | |||
26 | QTCOMMERCIALCHART_USE_NAMESPACE |
|
|||
27 |
|
||||
28 | int main(int argc, char *argv[]) |
|
26 | int main(int argc, char *argv[]) | |
29 | { |
|
27 | { | |
30 | QApplication a(argc, argv); |
|
28 | QApplication a(argc, argv); | |
31 |
|
29 | |||
32 | MainWidget w; |
|
30 | MainWidget w; | |
33 | w.resize(720, 480); |
|
31 | w.resize(720, 480); | |
34 | w.show(); |
|
32 | w.show(); | |
35 |
|
33 | |||
36 | return a.exec(); |
|
34 | return a.exec(); | |
37 | } |
|
35 | } |
@@ -1,88 +1,84 | |||||
1 | /**************************************************************************** |
|
1 | /**************************************************************************** | |
2 | ** |
|
2 | ** | |
3 | ** Copyright (C) 2012 Digia Plc |
|
3 | ** Copyright (C) 2012 Digia Plc | |
4 | ** All rights reserved. |
|
4 | ** All rights reserved. | |
5 | ** For any questions to Digia, please use contact form at http://qt.digia.com |
|
5 | ** For any questions to Digia, please use contact form at http://qt.digia.com | |
6 | ** |
|
6 | ** | |
7 | ** This file is part of the Qt Commercial Charts Add-on. |
|
7 | ** This file is part of the Qt Commercial Charts Add-on. | |
8 | ** |
|
8 | ** | |
9 | ** $QT_BEGIN_LICENSE$ |
|
9 | ** $QT_BEGIN_LICENSE$ | |
10 | ** Licensees holding valid Qt Commercial licenses may use this file in |
|
10 | ** Licensees holding valid Qt Commercial licenses may use this file in | |
11 | ** accordance with the Qt Commercial License Agreement provided with the |
|
11 | ** accordance with the Qt Commercial License Agreement provided with the | |
12 | ** Software or, alternatively, in accordance with the terms contained in |
|
12 | ** Software or, alternatively, in accordance with the terms contained in | |
13 | ** a written agreement between you and Digia. |
|
13 | ** a written agreement between you and Digia. | |
14 | ** |
|
14 | ** | |
15 | ** If you have questions regarding the use of this file, please use |
|
15 | ** If you have questions regarding the use of this file, please use | |
16 | ** contact form at http://qt.digia.com |
|
16 | ** contact form at http://qt.digia.com | |
17 | ** $QT_END_LICENSE$ |
|
17 | ** $QT_END_LICENSE$ | |
18 | ** |
|
18 | ** | |
19 | ****************************************************************************/ |
|
19 | ****************************************************************************/ | |
20 |
|
20 | |||
21 | #ifndef MAINWIDGET_H |
|
21 | #ifndef MAINWIDGET_H | |
22 | #define MAINWIDGET_H |
|
22 | #define MAINWIDGET_H | |
23 |
|
23 | |||
24 | #include "qchartglobal.h" |
|
24 | #include "qchartglobal.h" | |
25 | #include "qchart.h" |
|
25 | #include "qchart.h" | |
26 | #include "qchartview.h" |
|
26 | #include "qchartview.h" | |
27 | #include <QWidget> |
|
27 | #include <QWidget> | |
28 | #include <QGraphicsWidget> |
|
28 | #include <QGraphicsWidget> | |
29 | #include <QGridLayout> |
|
29 | #include <QGridLayout> | |
30 | #include <QGraphicsGridLayout> |
|
30 | #include <QGraphicsGridLayout> | |
31 | #include <QDoubleSpinBox> |
|
31 | #include <QDoubleSpinBox> | |
32 | #include <QGroupBox> |
|
32 | #include <QGroupBox> | |
33 | #include <QPieSlice> |
|
33 | #include <QPieSlice> | |
34 | #include <QPieSeries> |
|
34 | #include <QPieSeries> | |
35 |
|
35 | |||
36 | QTCOMMERCIALCHART_USE_NAMESPACE |
|
36 | QTCOMMERCIALCHART_USE_NAMESPACE | |
37 |
|
37 | |||
38 | class MainWidget : public QWidget |
|
38 | class MainWidget : public QWidget | |
39 | { |
|
39 | { | |
40 | Q_OBJECT |
|
40 | Q_OBJECT | |
41 | public: |
|
41 | public: | |
42 | explicit MainWidget(QWidget *parent = 0); |
|
42 | explicit MainWidget(QWidget *parent = 0); | |
43 | void createSeries(); |
|
43 | void createSeries(); | |
44 | void showLegendSpinbox(); |
|
44 | void showLegendSpinbox(); | |
45 | void hideLegendSpinbox(); |
|
45 | void hideLegendSpinbox(); | |
46 |
|
46 | |||
47 | signals: |
|
|||
48 |
|
||||
49 | public slots: |
|
47 | public slots: | |
50 | void toggleAttached(); |
|
48 | void toggleAttached(); | |
51 | void addSlice(); |
|
49 | void addSlice(); | |
52 | void removeSlice(); |
|
50 | void removeSlice(); | |
53 | void connectMarkers(); |
|
51 | void connectMarkers(); | |
54 | void disconnectMarkers(); |
|
52 | void disconnectMarkers(); | |
55 |
|
53 | |||
56 | void setLegendAlignment(); |
|
54 | void setLegendAlignment(); | |
57 |
|
55 | |||
58 | void toggleBold(); |
|
56 | void toggleBold(); | |
59 | void toggleItalic(); |
|
57 | void toggleItalic(); | |
60 | void showDebugInfo(); |
|
58 | void showDebugInfo(); | |
61 | void fontSizeChanged(); |
|
59 | void fontSizeChanged(); | |
62 |
|
60 | |||
63 | void updateLegendLayout(); |
|
61 | void updateLegendLayout(); | |
64 |
|
||||
65 | void handleMarkerClicked(); |
|
62 | void handleMarkerClicked(); | |
66 |
|
63 | |||
67 |
|
||||
68 | private: |
|
64 | private: | |
69 |
|
65 | |||
70 | QChart *m_chart; |
|
66 | QChart *m_chart; | |
71 | QPieSeries *m_series; |
|
67 | QPieSeries *m_series; | |
72 |
|
68 | |||
73 | QChartView *m_chartView; |
|
69 | QChartView *m_chartView; | |
74 | QGridLayout *m_mainLayout; |
|
70 | QGridLayout *m_mainLayout; | |
75 | QGridLayout *m_buttonLayout; |
|
71 | QGridLayout *m_buttonLayout; | |
76 | QGridLayout *m_fontLayout; |
|
72 | QGridLayout *m_fontLayout; | |
77 |
|
73 | |||
78 | QDoubleSpinBox *m_fontSize; |
|
74 | QDoubleSpinBox *m_fontSize; | |
79 |
|
75 | |||
80 | // For detached layout |
|
76 | // For detached layout | |
81 | QGroupBox* m_legendSettings; |
|
77 | QGroupBox* m_legendSettings; | |
82 | QDoubleSpinBox *m_legendPosX; |
|
78 | QDoubleSpinBox *m_legendPosX; | |
83 | QDoubleSpinBox *m_legendPosY; |
|
79 | QDoubleSpinBox *m_legendPosY; | |
84 | QDoubleSpinBox *m_legendWidth; |
|
80 | QDoubleSpinBox *m_legendWidth; | |
85 | QDoubleSpinBox *m_legendHeight; |
|
81 | QDoubleSpinBox *m_legendHeight; | |
86 | }; |
|
82 | }; | |
87 |
|
83 | |||
88 | #endif // MAINWIDGET_H |
|
84 | #endif // MAINWIDGET_H |
@@ -1,400 +1,399 | |||||
1 | /**************************************************************************** |
|
1 | /**************************************************************************** | |
2 | ** |
|
2 | ** | |
3 | ** Copyright (C) 2012 Digia Plc |
|
3 | ** Copyright (C) 2012 Digia Plc | |
4 | ** All rights reserved. |
|
4 | ** All rights reserved. | |
5 | ** For any questions to Digia, please use contact form at http://qt.digia.com |
|
5 | ** For any questions to Digia, please use contact form at http://qt.digia.com | |
6 | ** |
|
6 | ** | |
7 | ** This file is part of the Qt Commercial Charts Add-on. |
|
7 | ** This file is part of the Qt Commercial Charts Add-on. | |
8 | ** |
|
8 | ** | |
9 | ** $QT_BEGIN_LICENSE$ |
|
9 | ** $QT_BEGIN_LICENSE$ | |
10 | ** Licensees holding valid Qt Commercial licenses may use this file in |
|
10 | ** Licensees holding valid Qt Commercial licenses may use this file in | |
11 | ** accordance with the Qt Commercial License Agreement provided with the |
|
11 | ** accordance with the Qt Commercial License Agreement provided with the | |
12 | ** Software or, alternatively, in accordance with the terms contained in |
|
12 | ** Software or, alternatively, in accordance with the terms contained in | |
13 | ** a written agreement between you and Digia. |
|
13 | ** a written agreement between you and Digia. | |
14 | ** |
|
14 | ** | |
15 | ** If you have questions regarding the use of this file, please use |
|
15 | ** If you have questions regarding the use of this file, please use | |
16 | ** contact form at http://qt.digia.com |
|
16 | ** contact form at http://qt.digia.com | |
17 | ** $QT_END_LICENSE$ |
|
17 | ** $QT_END_LICENSE$ | |
18 | ** |
|
18 | ** | |
19 | ****************************************************************************/ |
|
19 | ****************************************************************************/ | |
20 |
|
20 | |||
21 | #include "qareaseries.h" |
|
21 | #include "qareaseries.h" | |
22 | #include "qareaseries_p.h" |
|
22 | #include "qareaseries_p.h" | |
23 | #include "qlineseries.h" |
|
23 | #include "qlineseries.h" | |
24 | #include "areachartitem_p.h" |
|
24 | #include "areachartitem_p.h" | |
25 | #include "domain_p.h" |
|
25 | #include "domain_p.h" | |
26 | #include "chartdataset_p.h" |
|
26 | #include "chartdataset_p.h" | |
27 | #include "charttheme_p.h" |
|
27 | #include "charttheme_p.h" | |
28 | #include "qvalueaxis.h" |
|
28 | #include "qvalueaxis.h" | |
29 |
|
||||
30 | #include "qarealegendmarker.h" |
|
29 | #include "qarealegendmarker.h" | |
31 |
|
30 | |||
32 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
31 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
33 |
|
32 | |||
34 | /*! |
|
33 | /*! | |
35 | \class QAreaSeries |
|
34 | \class QAreaSeries | |
36 | \brief The QAreaSeries class is used for making area charts. |
|
35 | \brief The QAreaSeries class is used for making area charts. | |
37 |
|
36 | |||
38 | \mainclass |
|
37 | \mainclass | |
39 |
|
38 | |||
40 | An area chart is used to show quantitative data. It is based on line chart, in the way that area between axis and the line |
|
39 | An area chart is used to show quantitative data. It is based on line chart, in the way that area between axis and the line | |
41 | is emphasized with color. Since the area chart is based on line chart, QAreaSeries constructor needs QLineSeries instance, |
|
40 | is emphasized with color. Since the area chart is based on line chart, QAreaSeries constructor needs QLineSeries instance, | |
42 | which defines "upper" boundary of the area. "Lower" boundary is defined by default by axis X. Instead of axis X "lower" boundary can be specified by other line. |
|
41 | which defines "upper" boundary of the area. "Lower" boundary is defined by default by axis X. Instead of axis X "lower" boundary can be specified by other line. | |
43 | In that case QAreaSeries should be initiated with two QLineSeries instances. Please note terms "upper" and "lower" boundary can be misleading in cases |
|
42 | In that case QAreaSeries should be initiated with two QLineSeries instances. Please note terms "upper" and "lower" boundary can be misleading in cases | |
44 | where "lower" boundary had bigger values than the "upper" one, however the main point that area between these two boundary lines will be filled. |
|
43 | where "lower" boundary had bigger values than the "upper" one, however the main point that area between these two boundary lines will be filled. | |
45 |
|
44 | |||
46 | See the \l {AreaChart Example} {area chart example} to learn how to create a simple area chart. |
|
45 | See the \l {AreaChart Example} {area chart example} to learn how to create a simple area chart. | |
47 | \image examples_areachart.png |
|
46 | \image examples_areachart.png | |
48 | */ |
|
47 | */ | |
49 | /*! |
|
48 | /*! | |
50 | \qmlclass AreaSeries QAreaSeries |
|
49 | \qmlclass AreaSeries QAreaSeries | |
51 |
|
50 | |||
52 | The following QML shows how to create a simple area chart: |
|
51 | The following QML shows how to create a simple area chart: | |
53 | \snippet ../demos/qmlchart/qml/qmlchart/View4.qml 1 |
|
52 | \snippet ../demos/qmlchart/qml/qmlchart/View4.qml 1 | |
54 | \beginfloatleft |
|
53 | \beginfloatleft | |
55 | \image demos_qmlchart4.png |
|
54 | \image demos_qmlchart4.png | |
56 | \endfloat |
|
55 | \endfloat | |
57 | \clearfloat |
|
56 | \clearfloat | |
58 | */ |
|
57 | */ | |
59 |
|
58 | |||
60 | /*! |
|
59 | /*! | |
61 | \property QAreaSeries::upperSeries |
|
60 | \property QAreaSeries::upperSeries | |
62 | \brief The upper one of the two line series used to define area series boundaries. |
|
61 | \brief The upper one of the two line series used to define area series boundaries. | |
63 | */ |
|
62 | */ | |
64 | /*! |
|
63 | /*! | |
65 | \qmlproperty LineSeries AreaSeries::upperSeries |
|
64 | \qmlproperty LineSeries AreaSeries::upperSeries | |
66 | The upper one of the two line series used to define area series boundaries. |
|
65 | The upper one of the two line series used to define area series boundaries. | |
67 | */ |
|
66 | */ | |
68 |
|
67 | |||
69 | /*! |
|
68 | /*! | |
70 | \property QAreaSeries::lowerSeries |
|
69 | \property QAreaSeries::lowerSeries | |
71 | The lower one of the two line series used to define are series boundaries. Note if |
|
70 | The lower one of the two line series used to define are series boundaries. Note if | |
72 | QAreaSeries was counstucted wihtout a\ lowerSeries this is null. |
|
71 | QAreaSeries was counstucted wihtout a\ lowerSeries this is null. | |
73 | */ |
|
72 | */ | |
74 | /*! |
|
73 | /*! | |
75 | \qmlproperty LineSeries AreaSeries::lowerSeries |
|
74 | \qmlproperty LineSeries AreaSeries::lowerSeries | |
76 | The lower one of the two line series used to define are series boundaries. Note if |
|
75 | The lower one of the two line series used to define are series boundaries. Note if | |
77 | AreaSeries was counstucted wihtout a\ lowerSeries this is null. |
|
76 | AreaSeries was counstucted wihtout a\ lowerSeries this is null. | |
78 | */ |
|
77 | */ | |
79 |
|
78 | |||
80 | /*! |
|
79 | /*! | |
81 | \property QAreaSeries::color |
|
80 | \property QAreaSeries::color | |
82 | Fill (brush) color of the series. This is a convenience property for modifying the color of brush. |
|
81 | Fill (brush) color of the series. This is a convenience property for modifying the color of brush. | |
83 | \sa QAreaSeries::brush() |
|
82 | \sa QAreaSeries::brush() | |
84 | */ |
|
83 | */ | |
85 | /*! |
|
84 | /*! | |
86 | \qmlproperty color AreaSeries::color |
|
85 | \qmlproperty color AreaSeries::color | |
87 | Fill (brush) color of the series. |
|
86 | Fill (brush) color of the series. | |
88 | */ |
|
87 | */ | |
89 |
|
88 | |||
90 | /*! |
|
89 | /*! | |
91 | \property QAreaSeries::borderColor |
|
90 | \property QAreaSeries::borderColor | |
92 | Line (pen) color of the series. This is a convenience property for modifying the color of pen. |
|
91 | Line (pen) color of the series. This is a convenience property for modifying the color of pen. | |
93 | \sa QAreaSeries::pen() |
|
92 | \sa QAreaSeries::pen() | |
94 | */ |
|
93 | */ | |
95 | /*! |
|
94 | /*! | |
96 | \qmlproperty color AreaSeries::borderColor |
|
95 | \qmlproperty color AreaSeries::borderColor | |
97 | Line (pen) color of the series. |
|
96 | Line (pen) color of the series. | |
98 | */ |
|
97 | */ | |
99 |
|
98 | |||
100 | /*! |
|
99 | /*! | |
101 | \qmlproperty real AreaSeries::borderWidth |
|
100 | \qmlproperty real AreaSeries::borderWidth | |
102 | The width of the border line. By default the width is 2.0. |
|
101 | The width of the border line. By default the width is 2.0. | |
103 | */ |
|
102 | */ | |
104 |
|
103 | |||
105 | /*! |
|
104 | /*! | |
106 | \fn QPen QAreaSeries::pen() const |
|
105 | \fn QPen QAreaSeries::pen() const | |
107 | \brief Returns the pen used to draw line for this series. |
|
106 | \brief Returns the pen used to draw line for this series. | |
108 | \sa setPen() |
|
107 | \sa setPen() | |
109 | */ |
|
108 | */ | |
110 |
|
109 | |||
111 | /*! |
|
110 | /*! | |
112 | \fn QPen QAreaSeries::brush() const |
|
111 | \fn QPen QAreaSeries::brush() const | |
113 | \brief Returns the brush used to draw line for this series. |
|
112 | \brief Returns the brush used to draw line for this series. | |
114 | \sa setBrush() |
|
113 | \sa setBrush() | |
115 | */ |
|
114 | */ | |
116 |
|
115 | |||
117 | /*! |
|
116 | /*! | |
118 | \fn void QAreaSeries::colorChanged(QColor color) |
|
117 | \fn void QAreaSeries::colorChanged(QColor color) | |
119 | \brief Signal is emitted when the fill (brush) color has changed to \a color. |
|
118 | \brief Signal is emitted when the fill (brush) color has changed to \a color. | |
120 | */ |
|
119 | */ | |
121 | /*! |
|
120 | /*! | |
122 | \qmlsignal AreaSeries::onColorChanged(color color) |
|
121 | \qmlsignal AreaSeries::onColorChanged(color color) | |
123 | Signal is emitted when the fill (brush) color has changed to \a color. |
|
122 | Signal is emitted when the fill (brush) color has changed to \a color. | |
124 | */ |
|
123 | */ | |
125 |
|
124 | |||
126 | /*! |
|
125 | /*! | |
127 | \fn void QAreaSeries::borderColorChanged(QColor color) |
|
126 | \fn void QAreaSeries::borderColorChanged(QColor color) | |
128 | \brief Signal is emitted when the line (pen) color has changed to \a color. |
|
127 | \brief Signal is emitted when the line (pen) color has changed to \a color. | |
129 | */ |
|
128 | */ | |
130 | /*! |
|
129 | /*! | |
131 | \qmlsignal AreaSeries::onBorderColorChanged(color color) |
|
130 | \qmlsignal AreaSeries::onBorderColorChanged(color color) | |
132 | Signal is emitted when the line (pen) color has changed to \a color. |
|
131 | Signal is emitted when the line (pen) color has changed to \a color. | |
133 | */ |
|
132 | */ | |
134 |
|
133 | |||
135 | /*! |
|
134 | /*! | |
136 | \fn void QAreaSeries::clicked(const QPointF& point) |
|
135 | \fn void QAreaSeries::clicked(const QPointF& point) | |
137 | \brief Signal is emitted when user clicks the \a point on area chart. |
|
136 | \brief Signal is emitted when user clicks the \a point on area chart. | |
138 | */ |
|
137 | */ | |
139 | /*! |
|
138 | /*! | |
140 | \qmlsignal AreaSeries::onClicked(QPointF point) |
|
139 | \qmlsignal AreaSeries::onClicked(QPointF point) | |
141 | Signal is emitted when user clicks the \a point on area chart. |
|
140 | Signal is emitted when user clicks the \a point on area chart. | |
142 | */ |
|
141 | */ | |
143 |
|
142 | |||
144 | /*! |
|
143 | /*! | |
145 | \fn void QAreaSeries::selected() |
|
144 | \fn void QAreaSeries::selected() | |
146 | The signal is emitted if the user selects/deselects the XY series. The logic for maintaining selections should be |
|
145 | The signal is emitted if the user selects/deselects the XY series. The logic for maintaining selections should be | |
147 | implemented by the user of QAreaSeries API. |
|
146 | implemented by the user of QAreaSeries API. | |
148 | */ |
|
147 | */ | |
149 | /*! |
|
148 | /*! | |
150 | \qmlsignal AreaSeries::onSelected() |
|
149 | \qmlsignal AreaSeries::onSelected() | |
151 | The signal is emitted if the user selects/deselects the XY series. The logic for maintaining selections should be |
|
150 | The signal is emitted if the user selects/deselects the XY series. The logic for maintaining selections should be | |
152 | implemented by the user of AreaSeries API. |
|
151 | implemented by the user of AreaSeries API. | |
153 | */ |
|
152 | */ | |
154 |
|
153 | |||
155 | /*! |
|
154 | /*! | |
156 | \fn void QAreaSeriesPrivate::updated() |
|
155 | \fn void QAreaSeriesPrivate::updated() | |
157 | \brief \internal |
|
156 | \brief \internal | |
158 | */ |
|
157 | */ | |
159 |
|
158 | |||
160 | /*! |
|
159 | /*! | |
161 | Constructs area series object which is a child of \a upperSeries. Area will be spanned between \a |
|
160 | Constructs area series object which is a child of \a upperSeries. Area will be spanned between \a | |
162 | upperSeries line and \a lowerSeries line. If no \a lowerSeries is passed to constructor, area is specified by axis x (y=0) instead. |
|
161 | upperSeries line and \a lowerSeries line. If no \a lowerSeries is passed to constructor, area is specified by axis x (y=0) instead. | |
163 | When series object is added to QChartView or QChart instance ownerships is transferred. |
|
162 | When series object is added to QChartView or QChart instance ownerships is transferred. | |
164 | */ |
|
163 | */ | |
165 | QAreaSeries::QAreaSeries(QLineSeries *upperSeries, QLineSeries *lowerSeries) |
|
164 | QAreaSeries::QAreaSeries(QLineSeries *upperSeries, QLineSeries *lowerSeries) | |
166 | : QAbstractSeries(*new QAreaSeriesPrivate(upperSeries, lowerSeries, this), upperSeries) |
|
165 | : QAbstractSeries(*new QAreaSeriesPrivate(upperSeries, lowerSeries, this), upperSeries) | |
167 | { |
|
166 | { | |
168 | } |
|
167 | } | |
169 |
|
168 | |||
170 | /*! |
|
169 | /*! | |
171 | Constructs area series object without upper or lower series with \a parent object. |
|
170 | Constructs area series object without upper or lower series with \a parent object. | |
172 | */ |
|
171 | */ | |
173 | QAreaSeries::QAreaSeries(QObject *parent) |
|
172 | QAreaSeries::QAreaSeries(QObject *parent) | |
174 | : QAbstractSeries(*new QAreaSeriesPrivate(0, 0, this), parent) |
|
173 | : QAbstractSeries(*new QAreaSeriesPrivate(0, 0, this), parent) | |
175 | { |
|
174 | { | |
176 | } |
|
175 | } | |
177 |
|
176 | |||
178 | /*! |
|
177 | /*! | |
179 | Destroys the object. |
|
178 | Destroys the object. | |
180 | */ |
|
179 | */ | |
181 | QAreaSeries::~QAreaSeries() |
|
180 | QAreaSeries::~QAreaSeries() | |
182 | { |
|
181 | { | |
183 | Q_D(QAreaSeries); |
|
182 | Q_D(QAreaSeries); | |
184 | if (d->m_dataset) |
|
183 | if (d->m_dataset) | |
185 | d->m_dataset->removeSeries(this); |
|
184 | d->m_dataset->removeSeries(this); | |
186 | } |
|
185 | } | |
187 |
|
186 | |||
188 | /*! |
|
187 | /*! | |
189 | Returns QChartSeries::SeriesTypeArea. |
|
188 | Returns QChartSeries::SeriesTypeArea. | |
190 | */ |
|
189 | */ | |
191 | QAbstractSeries::SeriesType QAreaSeries::type() const |
|
190 | QAbstractSeries::SeriesType QAreaSeries::type() const | |
192 | { |
|
191 | { | |
193 | return QAbstractSeries::SeriesTypeArea; |
|
192 | return QAbstractSeries::SeriesTypeArea; | |
194 | } |
|
193 | } | |
195 |
|
194 | |||
196 | /*! |
|
195 | /*! | |
197 | Sets the \a series that is to be used as the area chart upper series. |
|
196 | Sets the \a series that is to be used as the area chart upper series. | |
198 | */ |
|
197 | */ | |
199 | void QAreaSeries::setUpperSeries(QLineSeries *series) |
|
198 | void QAreaSeries::setUpperSeries(QLineSeries *series) | |
200 | { |
|
199 | { | |
201 | Q_D(QAreaSeries); |
|
200 | Q_D(QAreaSeries); | |
202 | d->m_upperSeries = series; |
|
201 | d->m_upperSeries = series; | |
203 | } |
|
202 | } | |
204 |
|
203 | |||
205 | QLineSeries *QAreaSeries::upperSeries() const |
|
204 | QLineSeries *QAreaSeries::upperSeries() const | |
206 | { |
|
205 | { | |
207 | Q_D(const QAreaSeries); |
|
206 | Q_D(const QAreaSeries); | |
208 | return d->m_upperSeries; |
|
207 | return d->m_upperSeries; | |
209 | } |
|
208 | } | |
210 |
|
209 | |||
211 | /*! |
|
210 | /*! | |
212 | Sets the \a series that is to be used as the area chart lower series. |
|
211 | Sets the \a series that is to be used as the area chart lower series. | |
213 | */ |
|
212 | */ | |
214 | void QAreaSeries::setLowerSeries(QLineSeries *series) |
|
213 | void QAreaSeries::setLowerSeries(QLineSeries *series) | |
215 | { |
|
214 | { | |
216 | Q_D(QAreaSeries); |
|
215 | Q_D(QAreaSeries); | |
217 | d->m_lowerSeries = series; |
|
216 | d->m_lowerSeries = series; | |
218 | } |
|
217 | } | |
219 |
|
218 | |||
220 | QLineSeries *QAreaSeries::lowerSeries() const |
|
219 | QLineSeries *QAreaSeries::lowerSeries() const | |
221 | { |
|
220 | { | |
222 | Q_D(const QAreaSeries); |
|
221 | Q_D(const QAreaSeries); | |
223 | return d->m_lowerSeries; |
|
222 | return d->m_lowerSeries; | |
224 | } |
|
223 | } | |
225 |
|
224 | |||
226 | /*! |
|
225 | /*! | |
227 | Sets \a pen used for drawing area outline. |
|
226 | Sets \a pen used for drawing area outline. | |
228 | */ |
|
227 | */ | |
229 | void QAreaSeries::setPen(const QPen &pen) |
|
228 | void QAreaSeries::setPen(const QPen &pen) | |
230 | { |
|
229 | { | |
231 | Q_D(QAreaSeries); |
|
230 | Q_D(QAreaSeries); | |
232 | if (d->m_pen != pen) { |
|
231 | if (d->m_pen != pen) { | |
233 | d->m_pen = pen; |
|
232 | d->m_pen = pen; | |
234 | emit d->updated(); |
|
233 | emit d->updated(); | |
235 | } |
|
234 | } | |
236 | } |
|
235 | } | |
237 |
|
236 | |||
238 | QPen QAreaSeries::pen() const |
|
237 | QPen QAreaSeries::pen() const | |
239 | { |
|
238 | { | |
240 | Q_D(const QAreaSeries); |
|
239 | Q_D(const QAreaSeries); | |
241 | return d->m_pen; |
|
240 | return d->m_pen; | |
242 | } |
|
241 | } | |
243 |
|
242 | |||
244 | /*! |
|
243 | /*! | |
245 | Sets \a brush used for filling the area. |
|
244 | Sets \a brush used for filling the area. | |
246 | */ |
|
245 | */ | |
247 | void QAreaSeries::setBrush(const QBrush &brush) |
|
246 | void QAreaSeries::setBrush(const QBrush &brush) | |
248 | { |
|
247 | { | |
249 | Q_D(QAreaSeries); |
|
248 | Q_D(QAreaSeries); | |
250 | if (d->m_brush != brush) { |
|
249 | if (d->m_brush != brush) { | |
251 | bool emitColorChanged = brush.color() != d->m_brush.color(); |
|
250 | bool emitColorChanged = brush.color() != d->m_brush.color(); | |
252 | d->m_brush = brush; |
|
251 | d->m_brush = brush; | |
253 | emit d->updated(); |
|
252 | emit d->updated(); | |
254 | if (emitColorChanged) |
|
253 | if (emitColorChanged) | |
255 | emit colorChanged(brush.color()); |
|
254 | emit colorChanged(brush.color()); | |
256 | } |
|
255 | } | |
257 | } |
|
256 | } | |
258 |
|
257 | |||
259 | QBrush QAreaSeries::brush() const |
|
258 | QBrush QAreaSeries::brush() const | |
260 | { |
|
259 | { | |
261 | Q_D(const QAreaSeries); |
|
260 | Q_D(const QAreaSeries); | |
262 | return d->m_brush; |
|
261 | return d->m_brush; | |
263 | } |
|
262 | } | |
264 |
|
263 | |||
265 | void QAreaSeries::setColor(const QColor &color) |
|
264 | void QAreaSeries::setColor(const QColor &color) | |
266 | { |
|
265 | { | |
267 | QBrush b = brush(); |
|
266 | QBrush b = brush(); | |
268 | if (b == QBrush()) |
|
267 | if (b == QBrush()) | |
269 | b.setStyle(Qt::SolidPattern); |
|
268 | b.setStyle(Qt::SolidPattern); | |
270 | b.setColor(color); |
|
269 | b.setColor(color); | |
271 | setBrush(b); |
|
270 | setBrush(b); | |
272 | } |
|
271 | } | |
273 |
|
272 | |||
274 | QColor QAreaSeries::color() const |
|
273 | QColor QAreaSeries::color() const | |
275 | { |
|
274 | { | |
276 | return brush().color(); |
|
275 | return brush().color(); | |
277 | } |
|
276 | } | |
278 |
|
277 | |||
279 | void QAreaSeries::setBorderColor(const QColor &color) |
|
278 | void QAreaSeries::setBorderColor(const QColor &color) | |
280 | { |
|
279 | { | |
281 | QPen p = pen(); |
|
280 | QPen p = pen(); | |
282 | if (p.color() != color) { |
|
281 | if (p.color() != color) { | |
283 | p.setColor(color); |
|
282 | p.setColor(color); | |
284 | setPen(p); |
|
283 | setPen(p); | |
285 | emit borderColorChanged(color); |
|
284 | emit borderColorChanged(color); | |
286 | } |
|
285 | } | |
287 | } |
|
286 | } | |
288 |
|
287 | |||
289 | QColor QAreaSeries::borderColor() const |
|
288 | QColor QAreaSeries::borderColor() const | |
290 | { |
|
289 | { | |
291 | return pen().color(); |
|
290 | return pen().color(); | |
292 | } |
|
291 | } | |
293 |
|
292 | |||
294 | /*! |
|
293 | /*! | |
295 | Sets if data points are \a visible and should be drawn on line. |
|
294 | Sets if data points are \a visible and should be drawn on line. | |
296 | */ |
|
295 | */ | |
297 | void QAreaSeries::setPointsVisible(bool visible) |
|
296 | void QAreaSeries::setPointsVisible(bool visible) | |
298 | { |
|
297 | { | |
299 | Q_D(QAreaSeries); |
|
298 | Q_D(QAreaSeries); | |
300 | if (d->m_pointsVisible != visible) { |
|
299 | if (d->m_pointsVisible != visible) { | |
301 | d->m_pointsVisible = visible; |
|
300 | d->m_pointsVisible = visible; | |
302 | emit d->updated(); |
|
301 | emit d->updated(); | |
303 | } |
|
302 | } | |
304 | } |
|
303 | } | |
305 |
|
304 | |||
306 | /*! |
|
305 | /*! | |
307 | Returns if the points are drawn for this series. |
|
306 | Returns if the points are drawn for this series. | |
308 | \sa setPointsVisible() |
|
307 | \sa setPointsVisible() | |
309 | */ |
|
308 | */ | |
310 | bool QAreaSeries::pointsVisible() const |
|
309 | bool QAreaSeries::pointsVisible() const | |
311 | { |
|
310 | { | |
312 | Q_D(const QAreaSeries); |
|
311 | Q_D(const QAreaSeries); | |
313 | return d->m_pointsVisible; |
|
312 | return d->m_pointsVisible; | |
314 | } |
|
313 | } | |
315 |
|
314 | |||
316 | //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
|
315 | //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// | |
317 |
|
316 | |||
318 | QAreaSeriesPrivate::QAreaSeriesPrivate(QLineSeries *upperSeries, QLineSeries *lowerSeries, QAreaSeries *q) |
|
317 | QAreaSeriesPrivate::QAreaSeriesPrivate(QLineSeries *upperSeries, QLineSeries *lowerSeries, QAreaSeries *q) | |
319 | : QAbstractSeriesPrivate(q), |
|
318 | : QAbstractSeriesPrivate(q), | |
320 | m_upperSeries(upperSeries), |
|
319 | m_upperSeries(upperSeries), | |
321 | m_lowerSeries(lowerSeries), |
|
320 | m_lowerSeries(lowerSeries), | |
322 | m_pointsVisible(false) |
|
321 | m_pointsVisible(false) | |
323 | { |
|
322 | { | |
324 | } |
|
323 | } | |
325 |
|
324 | |||
326 | void QAreaSeriesPrivate::scaleDomain(Domain &domain) |
|
325 | void QAreaSeriesPrivate::scaleDomain(Domain &domain) | |
327 | { |
|
326 | { | |
328 | Q_Q(QAreaSeries); |
|
327 | Q_Q(QAreaSeries); | |
329 |
|
328 | |||
330 | qreal minX(domain.minX()); |
|
329 | qreal minX(domain.minX()); | |
331 | qreal minY(domain.minY()); |
|
330 | qreal minY(domain.minY()); | |
332 | qreal maxX(domain.maxX()); |
|
331 | qreal maxX(domain.maxX()); | |
333 | qreal maxY(domain.maxY()); |
|
332 | qreal maxY(domain.maxY()); | |
334 |
|
333 | |||
335 | QLineSeries *upperSeries = q->upperSeries(); |
|
334 | QLineSeries *upperSeries = q->upperSeries(); | |
336 | QLineSeries *lowerSeries = q->lowerSeries(); |
|
335 | QLineSeries *lowerSeries = q->lowerSeries(); | |
337 |
|
336 | |||
338 | const QList<QPointF>& points = upperSeries->points(); |
|
337 | const QList<QPointF>& points = upperSeries->points(); | |
339 |
|
338 | |||
340 | for (int i = 0; i < points.count(); i++) { |
|
339 | for (int i = 0; i < points.count(); i++) { | |
341 | qreal x = points[i].x(); |
|
340 | qreal x = points[i].x(); | |
342 | qreal y = points[i].y(); |
|
341 | qreal y = points[i].y(); | |
343 | minX = qMin(minX, x); |
|
342 | minX = qMin(minX, x); | |
344 | minY = qMin(minY, y); |
|
343 | minY = qMin(minY, y); | |
345 | maxX = qMax(maxX, x); |
|
344 | maxX = qMax(maxX, x); | |
346 | maxY = qMax(maxY, y); |
|
345 | maxY = qMax(maxY, y); | |
347 | } |
|
346 | } | |
348 | if (lowerSeries) { |
|
347 | if (lowerSeries) { | |
349 |
|
348 | |||
350 | const QList<QPointF>& points = lowerSeries->points(); |
|
349 | const QList<QPointF>& points = lowerSeries->points(); | |
351 |
|
350 | |||
352 | for (int i = 0; i < points.count(); i++) { |
|
351 | for (int i = 0; i < points.count(); i++) { | |
353 | qreal x = points[i].x(); |
|
352 | qreal x = points[i].x(); | |
354 | qreal y = points[i].y(); |
|
353 | qreal y = points[i].y(); | |
355 | minX = qMin(minX, x); |
|
354 | minX = qMin(minX, x); | |
356 | minY = qMin(minY, y); |
|
355 | minY = qMin(minY, y); | |
357 | maxX = qMax(maxX, x); |
|
356 | maxX = qMax(maxX, x); | |
358 | maxY = qMax(maxY, y); |
|
357 | maxY = qMax(maxY, y); | |
359 | } |
|
358 | } | |
360 | } |
|
359 | } | |
361 |
|
360 | |||
362 | domain.setRange(minX, maxX, minY, maxY); |
|
361 | domain.setRange(minX, maxX, minY, maxY); | |
363 | } |
|
362 | } | |
364 |
|
363 | |||
365 | ChartElement *QAreaSeriesPrivate::createGraphics(ChartPresenter *presenter) |
|
364 | ChartElement *QAreaSeriesPrivate::createGraphics(ChartPresenter *presenter) | |
366 | { |
|
365 | { | |
367 | Q_Q(QAreaSeries); |
|
366 | Q_Q(QAreaSeries); | |
368 |
|
367 | |||
369 | AreaChartItem *area = new AreaChartItem(q, presenter); |
|
368 | AreaChartItem *area = new AreaChartItem(q, presenter); | |
370 | if (presenter->animationOptions().testFlag(QChart::SeriesAnimations)) { |
|
369 | if (presenter->animationOptions().testFlag(QChart::SeriesAnimations)) { | |
371 | area->upperLineItem()->setAnimation(new XYAnimation(area->upperLineItem())); |
|
370 | area->upperLineItem()->setAnimation(new XYAnimation(area->upperLineItem())); | |
372 | if (q->lowerSeries()) |
|
371 | if (q->lowerSeries()) | |
373 | area->lowerLineItem()->setAnimation(new XYAnimation(area->lowerLineItem())); |
|
372 | area->lowerLineItem()->setAnimation(new XYAnimation(area->lowerLineItem())); | |
374 | } |
|
373 | } | |
375 | presenter->chartTheme()->decorate(q, presenter->dataSet()->seriesIndex(q)); |
|
374 | presenter->chartTheme()->decorate(q, presenter->dataSet()->seriesIndex(q)); | |
376 | return area; |
|
375 | return area; | |
377 | } |
|
376 | } | |
378 |
|
377 | |||
379 | QList<QLegendMarker*> QAreaSeriesPrivate::createLegendMarkers(QLegend* legend) |
|
378 | QList<QLegendMarker*> QAreaSeriesPrivate::createLegendMarkers(QLegend* legend) | |
380 | { |
|
379 | { | |
381 | Q_Q(QAreaSeries); |
|
380 | Q_Q(QAreaSeries); | |
382 | QList<QLegendMarker*> list; |
|
381 | QList<QLegendMarker*> list; | |
383 | return list << new QAreaLegendMarker(q,legend); |
|
382 | return list << new QAreaLegendMarker(q,legend); | |
384 | } |
|
383 | } | |
385 |
|
384 | |||
386 | void QAreaSeriesPrivate::initializeAxis(QAbstractAxis *axis) |
|
385 | void QAreaSeriesPrivate::initializeAxis(QAbstractAxis *axis) | |
387 | { |
|
386 | { | |
388 | Q_UNUSED(axis); |
|
387 | Q_UNUSED(axis); | |
389 | } |
|
388 | } | |
390 |
|
389 | |||
391 | QAbstractAxis::AxisType QAreaSeriesPrivate::defaultAxisType(Qt::Orientation orientation) const |
|
390 | QAbstractAxis::AxisType QAreaSeriesPrivate::defaultAxisType(Qt::Orientation orientation) const | |
392 | { |
|
391 | { | |
393 | Q_UNUSED(orientation); |
|
392 | Q_UNUSED(orientation); | |
394 | return QAbstractAxis::AxisTypeValue; |
|
393 | return QAbstractAxis::AxisTypeValue; | |
395 | } |
|
394 | } | |
396 |
|
395 | |||
397 | #include "moc_qareaseries.cpp" |
|
396 | #include "moc_qareaseries.cpp" | |
398 | #include "moc_qareaseries_p.cpp" |
|
397 | #include "moc_qareaseries_p.cpp" | |
399 |
|
398 | |||
400 | QTCOMMERCIALCHART_END_NAMESPACE |
|
399 | QTCOMMERCIALCHART_END_NAMESPACE |
@@ -1,813 +1,812 | |||||
1 | /**************************************************************************** |
|
1 | /**************************************************************************** | |
2 | ** |
|
2 | ** | |
3 | ** Copyright (C) 2012 Digia Plc |
|
3 | ** Copyright (C) 2012 Digia Plc | |
4 | ** All rights reserved. |
|
4 | ** All rights reserved. | |
5 | ** For any questions to Digia, please use contact form at http://qt.digia.com |
|
5 | ** For any questions to Digia, please use contact form at http://qt.digia.com | |
6 | ** |
|
6 | ** | |
7 | ** This file is part of the Qt Commercial Charts Add-on. |
|
7 | ** This file is part of the Qt Commercial Charts Add-on. | |
8 | ** |
|
8 | ** | |
9 | ** $QT_BEGIN_LICENSE$ |
|
9 | ** $QT_BEGIN_LICENSE$ | |
10 | ** Licensees holding valid Qt Commercial licenses may use this file in |
|
10 | ** Licensees holding valid Qt Commercial licenses may use this file in | |
11 | ** accordance with the Qt Commercial License Agreement provided with the |
|
11 | ** accordance with the Qt Commercial License Agreement provided with the | |
12 | ** Software or, alternatively, in accordance with the terms contained in |
|
12 | ** Software or, alternatively, in accordance with the terms contained in | |
13 | ** a written agreement between you and Digia. |
|
13 | ** a written agreement between you and Digia. | |
14 | ** |
|
14 | ** | |
15 | ** If you have questions regarding the use of this file, please use |
|
15 | ** If you have questions regarding the use of this file, please use | |
16 | ** contact form at http://qt.digia.com |
|
16 | ** contact form at http://qt.digia.com | |
17 | ** $QT_END_LICENSE$ |
|
17 | ** $QT_END_LICENSE$ | |
18 | ** |
|
18 | ** | |
19 | ****************************************************************************/ |
|
19 | ****************************************************************************/ | |
20 |
|
20 | |||
21 | #include "qabstractbarseries.h" |
|
21 | #include "qabstractbarseries.h" | |
22 | #include "qabstractbarseries_p.h" |
|
22 | #include "qabstractbarseries_p.h" | |
23 | #include "qbarset.h" |
|
23 | #include "qbarset.h" | |
24 | #include "qbarset_p.h" |
|
24 | #include "qbarset_p.h" | |
25 | #include "domain_p.h" |
|
25 | #include "domain_p.h" | |
26 | #include "chartdataset_p.h" |
|
26 | #include "chartdataset_p.h" | |
27 | #include "charttheme_p.h" |
|
27 | #include "charttheme_p.h" | |
28 | #include "qvalueaxis.h" |
|
28 | #include "qvalueaxis.h" | |
29 | #include "qbarcategoryaxis.h" |
|
29 | #include "qbarcategoryaxis.h" | |
30 |
|
||||
31 | #include "qbarlegendmarker.h" |
|
30 | #include "qbarlegendmarker.h" | |
32 |
|
31 | |||
33 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
32 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
34 |
|
33 | |||
35 | /*! |
|
34 | /*! | |
36 | \class QAbstractBarSeries |
|
35 | \class QAbstractBarSeries | |
37 | \brief Series for creating a bar chart |
|
36 | \brief Series for creating a bar chart | |
38 | \mainclass |
|
37 | \mainclass | |
39 |
|
38 | |||
40 | QAbstractBarSeries represents a series of data shown as bars. The purpose of this class is to draw bars to |
|
39 | QAbstractBarSeries represents a series of data shown as bars. The purpose of this class is to draw bars to | |
41 | the position defined by data. Single bar is defined by QPointF, where x value is the x-coordinate of the bar |
|
40 | the position defined by data. Single bar is defined by QPointF, where x value is the x-coordinate of the bar | |
42 | and y-value is the height of the bar. The category names are ignored with this series and x-axis |
|
41 | and y-value is the height of the bar. The category names are ignored with this series and x-axis | |
43 | shows the x-values. |
|
42 | shows the x-values. | |
44 |
|
43 | |||
45 | See the \l {BarChart Example} {bar chart example} to learn how to create a simple bar chart. |
|
44 | See the \l {BarChart Example} {bar chart example} to learn how to create a simple bar chart. | |
46 | \image examples_barchart.png |
|
45 | \image examples_barchart.png | |
47 |
|
46 | |||
48 | \sa QBarSet, QStackedBarSeries, QPercentBarSeries |
|
47 | \sa QBarSet, QStackedBarSeries, QPercentBarSeries | |
49 | */ |
|
48 | */ | |
50 | /*! |
|
49 | /*! | |
51 | \qmlclass AbstractBarSeries QAbstractBarSeries |
|
50 | \qmlclass AbstractBarSeries QAbstractBarSeries | |
52 | \inherits QAbstractSeries |
|
51 | \inherits QAbstractSeries | |
53 |
|
52 | |||
54 | The following QML shows how to create a simple bar chart: |
|
53 | The following QML shows how to create a simple bar chart: | |
55 | \snippet ../demos/qmlchart/qml/qmlchart/View6.qml 1 |
|
54 | \snippet ../demos/qmlchart/qml/qmlchart/View6.qml 1 | |
56 |
|
55 | |||
57 | \beginfloatleft |
|
56 | \beginfloatleft | |
58 | \image demos_qmlchart6.png |
|
57 | \image demos_qmlchart6.png | |
59 | \endfloat |
|
58 | \endfloat | |
60 | \clearfloat |
|
59 | \clearfloat | |
61 | */ |
|
60 | */ | |
62 |
|
61 | |||
63 | /*! |
|
62 | /*! | |
64 | \property QAbstractBarSeries::barWidth |
|
63 | \property QAbstractBarSeries::barWidth | |
65 | The width of the bars of the series. The unit of \a width is the unit of x-axis. The minimum width for bars |
|
64 | The width of the bars of the series. The unit of \a width is the unit of x-axis. The minimum width for bars | |
66 | is zero and negative values are treated as zero. Setting the width to zero means that width of the bar on screen |
|
65 | is zero and negative values are treated as zero. Setting the width to zero means that width of the bar on screen | |
67 | is one pixel no matter what the scale of x-axis is. Bars wider than zero are scaled with x-axis. |
|
66 | is one pixel no matter what the scale of x-axis is. Bars wider than zero are scaled with x-axis. | |
68 | Note that with QBarSeries this value means the width of one group of bars instead of just one bar. |
|
67 | Note that with QBarSeries this value means the width of one group of bars instead of just one bar. | |
69 | \sa QBarSeries |
|
68 | \sa QBarSeries | |
70 | */ |
|
69 | */ | |
71 | /*! |
|
70 | /*! | |
72 | \qmlproperty real AbstractBarSeries::barWidth |
|
71 | \qmlproperty real AbstractBarSeries::barWidth | |
73 | The width of the bars of the series. The unit of width is the unit of x-axis. The minimum width for bars |
|
72 | The width of the bars of the series. The unit of width is the unit of x-axis. The minimum width for bars | |
74 | is zero and negative values are treated as zero. Setting the width to zero means that width of the bar on screen |
|
73 | is zero and negative values are treated as zero. Setting the width to zero means that width of the bar on screen | |
75 | is one pixel no matter what the scale of x-axis is. Bars wider than zero are scaled with x-axis. |
|
74 | is one pixel no matter what the scale of x-axis is. Bars wider than zero are scaled with x-axis. | |
76 | Note that with QBarSeries this value means the width of one group of bars instead of just one bar. |
|
75 | Note that with QBarSeries this value means the width of one group of bars instead of just one bar. | |
77 | */ |
|
76 | */ | |
78 |
|
77 | |||
79 | /*! |
|
78 | /*! | |
80 | \property QAbstractBarSeries::count |
|
79 | \property QAbstractBarSeries::count | |
81 | Holds the number of sets in series. |
|
80 | Holds the number of sets in series. | |
82 | */ |
|
81 | */ | |
83 | /*! |
|
82 | /*! | |
84 | \qmlproperty int AbstractBarSeries::count |
|
83 | \qmlproperty int AbstractBarSeries::count | |
85 | Holds the number of sets in series. |
|
84 | Holds the number of sets in series. | |
86 | */ |
|
85 | */ | |
87 |
|
86 | |||
88 | /*! |
|
87 | /*! | |
89 | \property QAbstractBarSeries::labelsVisible |
|
88 | \property QAbstractBarSeries::labelsVisible | |
90 | Defines the visibility of the labels in series |
|
89 | Defines the visibility of the labels in series | |
91 | */ |
|
90 | */ | |
92 | /*! |
|
91 | /*! | |
93 | \qmlproperty bool AbstractBarSeries::labelsVisible |
|
92 | \qmlproperty bool AbstractBarSeries::labelsVisible | |
94 | Defines the visibility of the labels in series |
|
93 | Defines the visibility of the labels in series | |
95 | */ |
|
94 | */ | |
96 |
|
95 | |||
97 | /*! |
|
96 | /*! | |
98 | \fn void QAbstractBarSeries::clicked(int index, QBarSet *barset) |
|
97 | \fn void QAbstractBarSeries::clicked(int index, QBarSet *barset) | |
99 | The signal is emitted if the user clicks with a mouse on top of QBarSet \a barset. |
|
98 | The signal is emitted if the user clicks with a mouse on top of QBarSet \a barset. | |
100 | Clicked bar inside set is indexed by \a index |
|
99 | Clicked bar inside set is indexed by \a index | |
101 | */ |
|
100 | */ | |
102 | /*! |
|
101 | /*! | |
103 | \qmlsignal AbstractBarSeries::onClicked(int index, BarSet barset) |
|
102 | \qmlsignal AbstractBarSeries::onClicked(int index, BarSet barset) | |
104 | The signal is emitted if the user clicks with a mouse on top of BarSet. |
|
103 | The signal is emitted if the user clicks with a mouse on top of BarSet. | |
105 | Clicked bar inside set is indexed by \a index |
|
104 | Clicked bar inside set is indexed by \a index | |
106 | */ |
|
105 | */ | |
107 |
|
106 | |||
108 | /*! |
|
107 | /*! | |
109 | \fn void QAbstractBarSeries::hovered(bool status, QBarSet* barset) |
|
108 | \fn void QAbstractBarSeries::hovered(bool status, QBarSet* barset) | |
110 |
|
109 | |||
111 | The signal is emitted if mouse is hovered on top of series. |
|
110 | The signal is emitted if mouse is hovered on top of series. | |
112 | Parameter \a barset is the pointer of barset, where hover happened. |
|
111 | Parameter \a barset is the pointer of barset, where hover happened. | |
113 | Parameter \a status is true, if mouse entered on top of series, false if mouse left from top of series. |
|
112 | Parameter \a status is true, if mouse entered on top of series, false if mouse left from top of series. | |
114 | */ |
|
113 | */ | |
115 | /*! |
|
114 | /*! | |
116 | \qmlsignal AbstractBarSeries::onHovered(bool status, BarSet barset) |
|
115 | \qmlsignal AbstractBarSeries::onHovered(bool status, BarSet barset) | |
117 |
|
116 | |||
118 | The signal is emitted if mouse is hovered on top of series. |
|
117 | The signal is emitted if mouse is hovered on top of series. | |
119 | Parameter \a barset is the pointer of barset, where hover happened. |
|
118 | Parameter \a barset is the pointer of barset, where hover happened. | |
120 | Parameter \a status is true, if mouse entered on top of series, false if mouse left from top of series. |
|
119 | Parameter \a status is true, if mouse entered on top of series, false if mouse left from top of series. | |
121 | */ |
|
120 | */ | |
122 |
|
121 | |||
123 | /*! |
|
122 | /*! | |
124 | \fn void QAbstractBarSeries::countChanged() |
|
123 | \fn void QAbstractBarSeries::countChanged() | |
125 | This signal is emitted when barset count has been changed, for example by append or remove. |
|
124 | This signal is emitted when barset count has been changed, for example by append or remove. | |
126 | */ |
|
125 | */ | |
127 | /*! |
|
126 | /*! | |
128 | \qmlsignal AbstractBarSeries::onCountChanged() |
|
127 | \qmlsignal AbstractBarSeries::onCountChanged() | |
129 | This signal is emitted when barset count has been changed, for example by append or remove. |
|
128 | This signal is emitted when barset count has been changed, for example by append or remove. | |
130 | */ |
|
129 | */ | |
131 |
|
130 | |||
132 | /*! |
|
131 | /*! | |
133 | \fn void QAbstractBarSeries::labelsVisibleChanged() |
|
132 | \fn void QAbstractBarSeries::labelsVisibleChanged() | |
134 | This signal is emitted when labels visibility have changed. |
|
133 | This signal is emitted when labels visibility have changed. | |
135 | \sa isLabelsVisible(), setLabelsVisible() |
|
134 | \sa isLabelsVisible(), setLabelsVisible() | |
136 | */ |
|
135 | */ | |
137 |
|
136 | |||
138 | /*! |
|
137 | /*! | |
139 | \fn void QAbstractBarSeries::barsetsAdded(QList<QBarSet*> sets) |
|
138 | \fn void QAbstractBarSeries::barsetsAdded(QList<QBarSet*> sets) | |
140 | This signal is emitted when \a sets have been added to the series. |
|
139 | This signal is emitted when \a sets have been added to the series. | |
141 | \sa append(), insert() |
|
140 | \sa append(), insert() | |
142 | */ |
|
141 | */ | |
143 | /*! |
|
142 | /*! | |
144 | \qmlsignal AbstractBarSeries::onBarsetsAdded(BarSet barset) |
|
143 | \qmlsignal AbstractBarSeries::onBarsetsAdded(BarSet barset) | |
145 | Emitted when \a barset has been added to the series. |
|
144 | Emitted when \a barset has been added to the series. | |
146 | */ |
|
145 | */ | |
147 |
|
146 | |||
148 | /*! |
|
147 | /*! | |
149 | \fn void QAbstractBarSeries::barsetsRemoved(QList<QBarSet*> sets) |
|
148 | \fn void QAbstractBarSeries::barsetsRemoved(QList<QBarSet*> sets) | |
150 | This signal is emitted when \a sets have been removed from the series. |
|
149 | This signal is emitted when \a sets have been removed from the series. | |
151 | \sa remove() |
|
150 | \sa remove() | |
152 | */ |
|
151 | */ | |
153 | /*! |
|
152 | /*! | |
154 | \qmlsignal AbstractBarSeries::onBarsetsRemoved(BarSet barset) |
|
153 | \qmlsignal AbstractBarSeries::onBarsetsRemoved(BarSet barset) | |
155 | Emitted when \a barset has been removed from the series. |
|
154 | Emitted when \a barset has been removed from the series. | |
156 | */ |
|
155 | */ | |
157 |
|
156 | |||
158 | /*! |
|
157 | /*! | |
159 | \qmlmethod BarSet AbstractBarSeries::at(int index) |
|
158 | \qmlmethod BarSet AbstractBarSeries::at(int index) | |
160 | Returns bar set at \a index. Returns null if the index is not valid. |
|
159 | Returns bar set at \a index. Returns null if the index is not valid. | |
161 | */ |
|
160 | */ | |
162 |
|
161 | |||
163 | /*! |
|
162 | /*! | |
164 | \qmlmethod BarSet AbstractBarSeries::append(string label, VariantList values) |
|
163 | \qmlmethod BarSet AbstractBarSeries::append(string label, VariantList values) | |
165 | Adds a new bar set with \a label and \a values to \a index. Values is a list of reals. |
|
164 | Adds a new bar set with \a label and \a values to \a index. Values is a list of reals. | |
166 | For example: |
|
165 | For example: | |
167 | \code |
|
166 | \code | |
168 | myBarSeries.append("set 1", [0, 0.2, 0.2, 0.5, 0.4, 1.5, 0.9]); |
|
167 | myBarSeries.append("set 1", [0, 0.2, 0.2, 0.5, 0.4, 1.5, 0.9]); | |
169 | \endcode |
|
168 | \endcode | |
170 | */ |
|
169 | */ | |
171 |
|
170 | |||
172 | /*! |
|
171 | /*! | |
173 | \qmlmethod BarSet AbstractBarSeries::insert(int index, string label, VariantList values) |
|
172 | \qmlmethod BarSet AbstractBarSeries::insert(int index, string label, VariantList values) | |
174 | Inserts a new bar set with \a label and \a values to \a index. Values can be a list of reals or a list of XYPoints. |
|
173 | Inserts a new bar set with \a label and \a values to \a index. Values can be a list of reals or a list of XYPoints. | |
175 | If index is zero or smaller, the new barset is prepended. If the index is count or bigger, the new barset is |
|
174 | If index is zero or smaller, the new barset is prepended. If the index is count or bigger, the new barset is | |
176 | appended. |
|
175 | appended. | |
177 | \sa AbstractBarSeries::append() |
|
176 | \sa AbstractBarSeries::append() | |
178 | */ |
|
177 | */ | |
179 |
|
178 | |||
180 | /*! |
|
179 | /*! | |
181 | \qmlmethod bool AbstractBarSeries::remove(BarSet barset) |
|
180 | \qmlmethod bool AbstractBarSeries::remove(BarSet barset) | |
182 | Removes the barset from the series. Returns true if successful, false otherwise. |
|
181 | Removes the barset from the series. Returns true if successful, false otherwise. | |
183 | */ |
|
182 | */ | |
184 |
|
183 | |||
185 | /*! |
|
184 | /*! | |
186 | \qmlmethod AbstractBarSeries::clear() |
|
185 | \qmlmethod AbstractBarSeries::clear() | |
187 | Removes all barsets from the series. |
|
186 | Removes all barsets from the series. | |
188 | */ |
|
187 | */ | |
189 |
|
188 | |||
190 | /*! |
|
189 | /*! | |
191 | Destructs abstractbarseries and owned barsets. |
|
190 | Destructs abstractbarseries and owned barsets. | |
192 | */ |
|
191 | */ | |
193 | QAbstractBarSeries::~QAbstractBarSeries() |
|
192 | QAbstractBarSeries::~QAbstractBarSeries() | |
194 | { |
|
193 | { | |
195 |
|
194 | |||
196 | } |
|
195 | } | |
197 |
|
196 | |||
198 | /*! |
|
197 | /*! | |
199 | \internal |
|
198 | \internal | |
200 | */ |
|
199 | */ | |
201 | QAbstractBarSeries::QAbstractBarSeries(QAbstractBarSeriesPrivate &o, QObject *parent) |
|
200 | QAbstractBarSeries::QAbstractBarSeries(QAbstractBarSeriesPrivate &o, QObject *parent) | |
202 | : QAbstractSeries(o, parent) |
|
201 | : QAbstractSeries(o, parent) | |
203 | { |
|
202 | { | |
204 | Q_D(QAbstractSeries); |
|
203 | Q_D(QAbstractSeries); | |
205 | QObject::connect(this, SIGNAL(countChanged()), d, SIGNAL(countChanged())); |
|
204 | QObject::connect(this, SIGNAL(countChanged()), d, SIGNAL(countChanged())); | |
206 | } |
|
205 | } | |
207 |
|
206 | |||
208 | /*! |
|
207 | /*! | |
209 | 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 | 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 | |
210 | is zero and negative values are treated as zero. Setting the width to zero means that width of the bar on screen |
|
209 | is zero and negative values are treated as zero. Setting the width to zero means that width of the bar on screen | |
211 | is one pixel no matter what the scale of x-axis is. Bars wider than zero are scaled with x-axis. |
|
210 | is one pixel no matter what the scale of x-axis is. Bars wider than zero are scaled with x-axis. | |
212 | Note that with \link QBarSeries \endlink this value means the width of one group of bars instead of just one bar. |
|
211 | Note that with \link QBarSeries \endlink this value means the width of one group of bars instead of just one bar. | |
213 | */ |
|
212 | */ | |
214 | void QAbstractBarSeries::setBarWidth(qreal width) |
|
213 | void QAbstractBarSeries::setBarWidth(qreal width) | |
215 | { |
|
214 | { | |
216 | Q_D(QAbstractBarSeries); |
|
215 | Q_D(QAbstractBarSeries); | |
217 | d->setBarWidth(width); |
|
216 | d->setBarWidth(width); | |
218 | } |
|
217 | } | |
219 |
|
218 | |||
220 | /*! |
|
219 | /*! | |
221 | Returns the width of the bars of the series. |
|
220 | Returns the width of the bars of the series. | |
222 | \sa setBarWidth() |
|
221 | \sa setBarWidth() | |
223 | */ |
|
222 | */ | |
224 | qreal QAbstractBarSeries::barWidth() const |
|
223 | qreal QAbstractBarSeries::barWidth() const | |
225 | { |
|
224 | { | |
226 | Q_D(const QAbstractBarSeries); |
|
225 | Q_D(const QAbstractBarSeries); | |
227 | return d->barWidth(); |
|
226 | return d->barWidth(); | |
228 | } |
|
227 | } | |
229 |
|
228 | |||
230 | /*! |
|
229 | /*! | |
231 | 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 | 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. | |
232 | Returns true, if appending succeeded. |
|
231 | Returns true, if appending succeeded. | |
233 | */ |
|
232 | */ | |
234 | bool QAbstractBarSeries::append(QBarSet *set) |
|
233 | bool QAbstractBarSeries::append(QBarSet *set) | |
235 | { |
|
234 | { | |
236 | Q_D(QAbstractBarSeries); |
|
235 | Q_D(QAbstractBarSeries); | |
237 | bool success = d->append(set); |
|
236 | bool success = d->append(set); | |
238 | if (success) { |
|
237 | if (success) { | |
239 | QList<QBarSet *> sets; |
|
238 | QList<QBarSet *> sets; | |
240 | sets.append(set); |
|
239 | sets.append(set); | |
241 | set->setParent(this); |
|
240 | set->setParent(this); | |
242 | emit barsetsAdded(sets); |
|
241 | emit barsetsAdded(sets); | |
243 | emit countChanged(); |
|
242 | emit countChanged(); | |
244 | } |
|
243 | } | |
245 | return success; |
|
244 | return success; | |
246 | } |
|
245 | } | |
247 |
|
246 | |||
248 | /*! |
|
247 | /*! | |
249 | Removes barset from series. Releases ownership of \a set. Deletes the set, if remove |
|
248 | Removes barset from series. Releases ownership of \a set. Deletes the set, if remove | |
250 | was successful. |
|
249 | was successful. | |
251 | Returns true, if set was removed. |
|
250 | Returns true, if set was removed. | |
252 | */ |
|
251 | */ | |
253 | bool QAbstractBarSeries::remove(QBarSet *set) |
|
252 | bool QAbstractBarSeries::remove(QBarSet *set) | |
254 | { |
|
253 | { | |
255 | Q_D(QAbstractBarSeries); |
|
254 | Q_D(QAbstractBarSeries); | |
256 | bool success = d->remove(set); |
|
255 | bool success = d->remove(set); | |
257 | if (success) { |
|
256 | if (success) { | |
258 | QList<QBarSet *> sets; |
|
257 | QList<QBarSet *> sets; | |
259 | sets.append(set); |
|
258 | sets.append(set); | |
260 | set->setParent(0); |
|
259 | set->setParent(0); | |
261 | emit barsetsRemoved(sets); |
|
260 | emit barsetsRemoved(sets); | |
262 | emit countChanged(); |
|
261 | emit countChanged(); | |
263 | delete set; |
|
262 | delete set; | |
264 | set = 0; |
|
263 | set = 0; | |
265 | } |
|
264 | } | |
266 | return success; |
|
265 | return success; | |
267 | } |
|
266 | } | |
268 |
|
267 | |||
269 | /*! |
|
268 | /*! | |
270 | Takes a single \a set from the series. Does not delete the barset object. |
|
269 | Takes a single \a set from the series. Does not delete the barset object. | |
271 |
|
270 | |||
272 | NOTE: The series remains as the barset's parent object. You must set the |
|
271 | NOTE: The series remains as the barset's parent object. You must set the | |
273 | parent object to take full ownership. |
|
272 | parent object to take full ownership. | |
274 |
|
273 | |||
275 | Returns true if take was successful. |
|
274 | Returns true if take was successful. | |
276 | */ |
|
275 | */ | |
277 | bool QAbstractBarSeries::take(QBarSet *set) |
|
276 | bool QAbstractBarSeries::take(QBarSet *set) | |
278 | { |
|
277 | { | |
279 | Q_D(QAbstractBarSeries); |
|
278 | Q_D(QAbstractBarSeries); | |
280 | bool success = d->remove(set); |
|
279 | bool success = d->remove(set); | |
281 | if (success) { |
|
280 | if (success) { | |
282 | QList<QBarSet *> sets; |
|
281 | QList<QBarSet *> sets; | |
283 | sets.append(set); |
|
282 | sets.append(set); | |
284 | emit barsetsRemoved(sets); |
|
283 | emit barsetsRemoved(sets); | |
285 | emit countChanged(); |
|
284 | emit countChanged(); | |
286 | } |
|
285 | } | |
287 | return success; |
|
286 | return success; | |
288 | } |
|
287 | } | |
289 |
|
288 | |||
290 | /*! |
|
289 | /*! | |
291 | Adds a list of barsets to series. Takes ownership of \a sets. |
|
290 | Adds a list of barsets to series. Takes ownership of \a sets. | |
292 | Returns true, if all sets were appended successfully. If any of the sets is null or is already appended to series, |
|
291 | Returns true, if all sets were appended successfully. If any of the sets is null or is already appended to series, | |
293 | nothing is appended and function returns false. If any of the sets is in list more than once, nothing is appended |
|
292 | nothing is appended and function returns false. If any of the sets is in list more than once, nothing is appended | |
294 | and function returns false. |
|
293 | and function returns false. | |
295 | */ |
|
294 | */ | |
296 | bool QAbstractBarSeries::append(QList<QBarSet *> sets) |
|
295 | bool QAbstractBarSeries::append(QList<QBarSet *> sets) | |
297 | { |
|
296 | { | |
298 | Q_D(QAbstractBarSeries); |
|
297 | Q_D(QAbstractBarSeries); | |
299 | bool success = d->append(sets); |
|
298 | bool success = d->append(sets); | |
300 | if (success) { |
|
299 | if (success) { | |
301 | emit barsetsAdded(sets); |
|
300 | emit barsetsAdded(sets); | |
302 | emit countChanged(); |
|
301 | emit countChanged(); | |
303 | } |
|
302 | } | |
304 | return success; |
|
303 | return success; | |
305 | } |
|
304 | } | |
306 |
|
305 | |||
307 | /*! |
|
306 | /*! | |
308 | 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 | 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. | |
309 | Returns true, if inserting succeeded. |
|
308 | Returns true, if inserting succeeded. | |
310 |
|
309 | |||
311 | */ |
|
310 | */ | |
312 | bool QAbstractBarSeries::insert(int index, QBarSet *set) |
|
311 | bool QAbstractBarSeries::insert(int index, QBarSet *set) | |
313 | { |
|
312 | { | |
314 | Q_D(QAbstractBarSeries); |
|
313 | Q_D(QAbstractBarSeries); | |
315 | bool success = d->insert(index, set); |
|
314 | bool success = d->insert(index, set); | |
316 | if (success) { |
|
315 | if (success) { | |
317 | QList<QBarSet *> sets; |
|
316 | QList<QBarSet *> sets; | |
318 | sets.append(set); |
|
317 | sets.append(set); | |
319 | emit barsetsAdded(sets); |
|
318 | emit barsetsAdded(sets); | |
320 | emit countChanged(); |
|
319 | emit countChanged(); | |
321 | } |
|
320 | } | |
322 | return success; |
|
321 | return success; | |
323 | } |
|
322 | } | |
324 |
|
323 | |||
325 | /*! |
|
324 | /*! | |
326 | Removes all barsets from the series. Deletes removed sets. |
|
325 | Removes all barsets from the series. Deletes removed sets. | |
327 | */ |
|
326 | */ | |
328 | void QAbstractBarSeries::clear() |
|
327 | void QAbstractBarSeries::clear() | |
329 | { |
|
328 | { | |
330 | Q_D(QAbstractBarSeries); |
|
329 | Q_D(QAbstractBarSeries); | |
331 | QList<QBarSet *> sets = barSets(); |
|
330 | QList<QBarSet *> sets = barSets(); | |
332 | bool success = d->remove(sets); |
|
331 | bool success = d->remove(sets); | |
333 | if (success) { |
|
332 | if (success) { | |
334 | emit barsetsRemoved(sets); |
|
333 | emit barsetsRemoved(sets); | |
335 | emit countChanged(); |
|
334 | emit countChanged(); | |
336 | foreach (QBarSet *set, sets) |
|
335 | foreach (QBarSet *set, sets) | |
337 | delete set; |
|
336 | delete set; | |
338 | } |
|
337 | } | |
339 | } |
|
338 | } | |
340 |
|
339 | |||
341 | /*! |
|
340 | /*! | |
342 | Returns number of sets in series. |
|
341 | Returns number of sets in series. | |
343 | */ |
|
342 | */ | |
344 | int QAbstractBarSeries::count() const |
|
343 | int QAbstractBarSeries::count() const | |
345 | { |
|
344 | { | |
346 | Q_D(const QAbstractBarSeries); |
|
345 | Q_D(const QAbstractBarSeries); | |
347 | return d->m_barSets.count(); |
|
346 | return d->m_barSets.count(); | |
348 | } |
|
347 | } | |
349 |
|
348 | |||
350 | /*! |
|
349 | /*! | |
351 | Returns a list of sets in series. Keeps ownership of sets. |
|
350 | Returns a list of sets in series. Keeps ownership of sets. | |
352 | */ |
|
351 | */ | |
353 | QList<QBarSet *> QAbstractBarSeries::barSets() const |
|
352 | QList<QBarSet *> QAbstractBarSeries::barSets() const | |
354 | { |
|
353 | { | |
355 | Q_D(const QAbstractBarSeries); |
|
354 | Q_D(const QAbstractBarSeries); | |
356 | return d->m_barSets; |
|
355 | return d->m_barSets; | |
357 | } |
|
356 | } | |
358 |
|
357 | |||
359 | /*! |
|
358 | /*! | |
360 | Sets the visibility of labels in series to \a visible |
|
359 | Sets the visibility of labels in series to \a visible | |
361 | */ |
|
360 | */ | |
362 | void QAbstractBarSeries::setLabelsVisible(bool visible) |
|
361 | void QAbstractBarSeries::setLabelsVisible(bool visible) | |
363 | { |
|
362 | { | |
364 | Q_D(QAbstractBarSeries); |
|
363 | Q_D(QAbstractBarSeries); | |
365 | if (d->m_labelsVisible != visible) { |
|
364 | if (d->m_labelsVisible != visible) { | |
366 | d->setLabelsVisible(visible); |
|
365 | d->setLabelsVisible(visible); | |
367 | emit labelsVisibleChanged(); |
|
366 | emit labelsVisibleChanged(); | |
368 | } |
|
367 | } | |
369 | } |
|
368 | } | |
370 |
|
369 | |||
371 | /*! |
|
370 | /*! | |
372 | Returns the visibility of labels |
|
371 | Returns the visibility of labels | |
373 | */ |
|
372 | */ | |
374 | bool QAbstractBarSeries::isLabelsVisible() const |
|
373 | bool QAbstractBarSeries::isLabelsVisible() const | |
375 | { |
|
374 | { | |
376 | Q_D(const QAbstractBarSeries); |
|
375 | Q_D(const QAbstractBarSeries); | |
377 | return d->m_labelsVisible; |
|
376 | return d->m_labelsVisible; | |
378 | } |
|
377 | } | |
379 |
|
378 | |||
380 | /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
|
379 | /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// | |
381 |
|
380 | |||
382 | QAbstractBarSeriesPrivate::QAbstractBarSeriesPrivate(QAbstractBarSeries *q) : |
|
381 | QAbstractBarSeriesPrivate::QAbstractBarSeriesPrivate(QAbstractBarSeries *q) : | |
383 | QAbstractSeriesPrivate(q), |
|
382 | QAbstractSeriesPrivate(q), | |
384 | m_barWidth(0.5), // Default value is 50% of category width |
|
383 | m_barWidth(0.5), // Default value is 50% of category width | |
385 | m_labelsVisible(false), |
|
384 | m_labelsVisible(false), | |
386 | m_visible(true) |
|
385 | m_visible(true) | |
387 | { |
|
386 | { | |
388 | } |
|
387 | } | |
389 |
|
388 | |||
390 | int QAbstractBarSeriesPrivate::categoryCount() const |
|
389 | int QAbstractBarSeriesPrivate::categoryCount() const | |
391 | { |
|
390 | { | |
392 | // No categories defined. return count of longest set. |
|
391 | // No categories defined. return count of longest set. | |
393 | int count = 0; |
|
392 | int count = 0; | |
394 | for (int i = 0; i < m_barSets.count(); i++) { |
|
393 | for (int i = 0; i < m_barSets.count(); i++) { | |
395 | if (m_barSets.at(i)->count() > count) |
|
394 | if (m_barSets.at(i)->count() > count) | |
396 | count = m_barSets.at(i)->count(); |
|
395 | count = m_barSets.at(i)->count(); | |
397 | } |
|
396 | } | |
398 |
|
397 | |||
399 | return count; |
|
398 | return count; | |
400 | } |
|
399 | } | |
401 |
|
400 | |||
402 | void QAbstractBarSeriesPrivate::setBarWidth(qreal width) |
|
401 | void QAbstractBarSeriesPrivate::setBarWidth(qreal width) | |
403 | { |
|
402 | { | |
404 | if (width < 0.0) |
|
403 | if (width < 0.0) | |
405 | width = 0.0; |
|
404 | width = 0.0; | |
406 | m_barWidth = width; |
|
405 | m_barWidth = width; | |
407 | emit updatedLayout(); |
|
406 | emit updatedLayout(); | |
408 | } |
|
407 | } | |
409 |
|
408 | |||
410 | qreal QAbstractBarSeriesPrivate::barWidth() const |
|
409 | qreal QAbstractBarSeriesPrivate::barWidth() const | |
411 | { |
|
410 | { | |
412 | return m_barWidth; |
|
411 | return m_barWidth; | |
413 | } |
|
412 | } | |
414 |
|
413 | |||
415 | QBarSet *QAbstractBarSeriesPrivate::barsetAt(int index) |
|
414 | QBarSet *QAbstractBarSeriesPrivate::barsetAt(int index) | |
416 | { |
|
415 | { | |
417 | return m_barSets.at(index); |
|
416 | return m_barSets.at(index); | |
418 | } |
|
417 | } | |
419 |
|
418 | |||
420 | void QAbstractBarSeriesPrivate::setVisible(bool visible) |
|
419 | void QAbstractBarSeriesPrivate::setVisible(bool visible) | |
421 | { |
|
420 | { | |
422 | m_visible = visible; |
|
421 | m_visible = visible; | |
423 | emit visibleChanged(); |
|
422 | emit visibleChanged(); | |
424 | } |
|
423 | } | |
425 |
|
424 | |||
426 | void QAbstractBarSeriesPrivate::setLabelsVisible(bool visible) |
|
425 | void QAbstractBarSeriesPrivate::setLabelsVisible(bool visible) | |
427 | { |
|
426 | { | |
428 | m_labelsVisible = visible; |
|
427 | m_labelsVisible = visible; | |
429 | emit labelsVisibleChanged(visible); |
|
428 | emit labelsVisibleChanged(visible); | |
430 | } |
|
429 | } | |
431 |
|
430 | |||
432 | qreal QAbstractBarSeriesPrivate::min() |
|
431 | qreal QAbstractBarSeriesPrivate::min() | |
433 | { |
|
432 | { | |
434 | if (m_barSets.count() <= 0) |
|
433 | if (m_barSets.count() <= 0) | |
435 | return 0; |
|
434 | return 0; | |
436 |
|
435 | |||
437 | qreal min = INT_MAX; |
|
436 | qreal min = INT_MAX; | |
438 |
|
437 | |||
439 | for (int i = 0; i < m_barSets.count(); i++) { |
|
438 | for (int i = 0; i < m_barSets.count(); i++) { | |
440 | int categoryCount = m_barSets.at(i)->count(); |
|
439 | int categoryCount = m_barSets.at(i)->count(); | |
441 | for (int j = 0; j < categoryCount; j++) { |
|
440 | for (int j = 0; j < categoryCount; j++) { | |
442 | qreal temp = m_barSets.at(i)->at(j); |
|
441 | qreal temp = m_barSets.at(i)->at(j); | |
443 | if (temp < min) |
|
442 | if (temp < min) | |
444 | min = temp; |
|
443 | min = temp; | |
445 | } |
|
444 | } | |
446 | } |
|
445 | } | |
447 | return min; |
|
446 | return min; | |
448 | } |
|
447 | } | |
449 |
|
448 | |||
450 | qreal QAbstractBarSeriesPrivate::max() |
|
449 | qreal QAbstractBarSeriesPrivate::max() | |
451 | { |
|
450 | { | |
452 | if (m_barSets.count() <= 0) |
|
451 | if (m_barSets.count() <= 0) | |
453 | return 0; |
|
452 | return 0; | |
454 |
|
453 | |||
455 | qreal max = INT_MIN; |
|
454 | qreal max = INT_MIN; | |
456 |
|
455 | |||
457 | for (int i = 0; i < m_barSets.count(); i++) { |
|
456 | for (int i = 0; i < m_barSets.count(); i++) { | |
458 | int categoryCount = m_barSets.at(i)->count(); |
|
457 | int categoryCount = m_barSets.at(i)->count(); | |
459 | for (int j = 0; j < categoryCount; j++) { |
|
458 | for (int j = 0; j < categoryCount; j++) { | |
460 | qreal temp = m_barSets.at(i)->at(j); |
|
459 | qreal temp = m_barSets.at(i)->at(j); | |
461 | if (temp > max) |
|
460 | if (temp > max) | |
462 | max = temp; |
|
461 | max = temp; | |
463 | } |
|
462 | } | |
464 | } |
|
463 | } | |
465 |
|
464 | |||
466 | return max; |
|
465 | return max; | |
467 | } |
|
466 | } | |
468 |
|
467 | |||
469 | qreal QAbstractBarSeriesPrivate::valueAt(int set, int category) |
|
468 | qreal QAbstractBarSeriesPrivate::valueAt(int set, int category) | |
470 | { |
|
469 | { | |
471 | if ((set < 0) || (set >= m_barSets.count())) |
|
470 | if ((set < 0) || (set >= m_barSets.count())) | |
472 | return 0; // No set, no value. |
|
471 | return 0; // No set, no value. | |
473 | else if ((category < 0) || (category >= m_barSets.at(set)->count())) |
|
472 | else if ((category < 0) || (category >= m_barSets.at(set)->count())) | |
474 | return 0; // No category, no value. |
|
473 | return 0; // No category, no value. | |
475 |
|
474 | |||
476 | return m_barSets.at(set)->at(category); |
|
475 | return m_barSets.at(set)->at(category); | |
477 | } |
|
476 | } | |
478 |
|
477 | |||
479 | qreal QAbstractBarSeriesPrivate::percentageAt(int set, int category) |
|
478 | qreal QAbstractBarSeriesPrivate::percentageAt(int set, int category) | |
480 | { |
|
479 | { | |
481 | if ((set < 0) || (set >= m_barSets.count())) |
|
480 | if ((set < 0) || (set >= m_barSets.count())) | |
482 | return 0; // No set, no value. |
|
481 | return 0; // No set, no value. | |
483 | else if ((category < 0) || (category >= m_barSets.at(set)->count())) |
|
482 | else if ((category < 0) || (category >= m_barSets.at(set)->count())) | |
484 | return 0; // No category, no value. |
|
483 | return 0; // No category, no value. | |
485 |
|
484 | |||
486 | qreal value = m_barSets.at(set)->at(category); |
|
485 | qreal value = m_barSets.at(set)->at(category); | |
487 | qreal sum = categorySum(category); |
|
486 | qreal sum = categorySum(category); | |
488 | if (qFuzzyIsNull(sum)) |
|
487 | if (qFuzzyIsNull(sum)) | |
489 | return 0; |
|
488 | return 0; | |
490 |
|
489 | |||
491 | return value / sum; |
|
490 | return value / sum; | |
492 | } |
|
491 | } | |
493 |
|
492 | |||
494 | qreal QAbstractBarSeriesPrivate::categorySum(int category) |
|
493 | qreal QAbstractBarSeriesPrivate::categorySum(int category) | |
495 | { |
|
494 | { | |
496 | qreal sum(0); |
|
495 | qreal sum(0); | |
497 | int count = m_barSets.count(); // Count sets |
|
496 | int count = m_barSets.count(); // Count sets | |
498 | for (int set = 0; set < count; set++) { |
|
497 | for (int set = 0; set < count; set++) { | |
499 | if (category < m_barSets.at(set)->count()) |
|
498 | if (category < m_barSets.at(set)->count()) | |
500 | sum += m_barSets.at(set)->at(category); |
|
499 | sum += m_barSets.at(set)->at(category); | |
501 | } |
|
500 | } | |
502 | return sum; |
|
501 | return sum; | |
503 | } |
|
502 | } | |
504 |
|
503 | |||
505 | qreal QAbstractBarSeriesPrivate::absoluteCategorySum(int category) |
|
504 | qreal QAbstractBarSeriesPrivate::absoluteCategorySum(int category) | |
506 | { |
|
505 | { | |
507 | qreal sum(0); |
|
506 | qreal sum(0); | |
508 | int count = m_barSets.count(); // Count sets |
|
507 | int count = m_barSets.count(); // Count sets | |
509 | for (int set = 0; set < count; set++) { |
|
508 | for (int set = 0; set < count; set++) { | |
510 | if (category < m_barSets.at(set)->count()) |
|
509 | if (category < m_barSets.at(set)->count()) | |
511 | sum += qAbs(m_barSets.at(set)->at(category)); |
|
510 | sum += qAbs(m_barSets.at(set)->at(category)); | |
512 | } |
|
511 | } | |
513 | return sum; |
|
512 | return sum; | |
514 | } |
|
513 | } | |
515 |
|
514 | |||
516 | qreal QAbstractBarSeriesPrivate::maxCategorySum() |
|
515 | qreal QAbstractBarSeriesPrivate::maxCategorySum() | |
517 | { |
|
516 | { | |
518 | qreal max = INT_MIN; |
|
517 | qreal max = INT_MIN; | |
519 | int count = categoryCount(); |
|
518 | int count = categoryCount(); | |
520 | for (int i = 0; i < count; i++) { |
|
519 | for (int i = 0; i < count; i++) { | |
521 | qreal sum = categorySum(i); |
|
520 | qreal sum = categorySum(i); | |
522 | if (sum > max) |
|
521 | if (sum > max) | |
523 | max = sum; |
|
522 | max = sum; | |
524 | } |
|
523 | } | |
525 | return max; |
|
524 | return max; | |
526 | } |
|
525 | } | |
527 |
|
526 | |||
528 | qreal QAbstractBarSeriesPrivate::minX() |
|
527 | qreal QAbstractBarSeriesPrivate::minX() | |
529 | { |
|
528 | { | |
530 | if (m_barSets.count() <= 0) |
|
529 | if (m_barSets.count() <= 0) | |
531 | return 0; |
|
530 | return 0; | |
532 |
|
531 | |||
533 | qreal min = INT_MAX; |
|
532 | qreal min = INT_MAX; | |
534 |
|
533 | |||
535 | for (int i = 0; i < m_barSets.count(); i++) { |
|
534 | for (int i = 0; i < m_barSets.count(); i++) { | |
536 | int categoryCount = m_barSets.at(i)->count(); |
|
535 | int categoryCount = m_barSets.at(i)->count(); | |
537 | for (int j = 0; j < categoryCount; j++) { |
|
536 | for (int j = 0; j < categoryCount; j++) { | |
538 | qreal temp = m_barSets.at(i)->d_ptr.data()->m_values.at(j).x(); |
|
537 | qreal temp = m_barSets.at(i)->d_ptr.data()->m_values.at(j).x(); | |
539 | if (temp < min) |
|
538 | if (temp < min) | |
540 | min = temp; |
|
539 | min = temp; | |
541 | } |
|
540 | } | |
542 | } |
|
541 | } | |
543 | return min; |
|
542 | return min; | |
544 | } |
|
543 | } | |
545 |
|
544 | |||
546 | qreal QAbstractBarSeriesPrivate::maxX() |
|
545 | qreal QAbstractBarSeriesPrivate::maxX() | |
547 | { |
|
546 | { | |
548 | if (m_barSets.count() <= 0) |
|
547 | if (m_barSets.count() <= 0) | |
549 | return 0; |
|
548 | return 0; | |
550 |
|
549 | |||
551 | qreal max = INT_MIN; |
|
550 | qreal max = INT_MIN; | |
552 |
|
551 | |||
553 | for (int i = 0; i < m_barSets.count(); i++) { |
|
552 | for (int i = 0; i < m_barSets.count(); i++) { | |
554 | int categoryCount = m_barSets.at(i)->count(); |
|
553 | int categoryCount = m_barSets.at(i)->count(); | |
555 | for (int j = 0; j < categoryCount; j++) { |
|
554 | for (int j = 0; j < categoryCount; j++) { | |
556 | qreal temp = m_barSets.at(i)->d_ptr.data()->m_values.at(j).x(); |
|
555 | qreal temp = m_barSets.at(i)->d_ptr.data()->m_values.at(j).x(); | |
557 | if (temp > max) |
|
556 | if (temp > max) | |
558 | max = temp; |
|
557 | max = temp; | |
559 | } |
|
558 | } | |
560 | } |
|
559 | } | |
561 |
|
560 | |||
562 | return max; |
|
561 | return max; | |
563 | } |
|
562 | } | |
564 |
|
563 | |||
565 | qreal QAbstractBarSeriesPrivate::categoryTop(int category) |
|
564 | qreal QAbstractBarSeriesPrivate::categoryTop(int category) | |
566 | { |
|
565 | { | |
567 | // Returns top (sum of all positive values) of category. |
|
566 | // Returns top (sum of all positive values) of category. | |
568 | // Returns 0, if all values are negative |
|
567 | // Returns 0, if all values are negative | |
569 | qreal top(0); |
|
568 | qreal top(0); | |
570 | int count = m_barSets.count(); |
|
569 | int count = m_barSets.count(); | |
571 | for (int set = 0; set < count; set++) { |
|
570 | for (int set = 0; set < count; set++) { | |
572 | if (category < m_barSets.at(set)->count()) { |
|
571 | if (category < m_barSets.at(set)->count()) { | |
573 | qreal temp = m_barSets.at(set)->at(category); |
|
572 | qreal temp = m_barSets.at(set)->at(category); | |
574 | if (temp > 0) { |
|
573 | if (temp > 0) { | |
575 | top += temp; |
|
574 | top += temp; | |
576 | } |
|
575 | } | |
577 | } |
|
576 | } | |
578 | } |
|
577 | } | |
579 | return top; |
|
578 | return top; | |
580 | } |
|
579 | } | |
581 |
|
580 | |||
582 | qreal QAbstractBarSeriesPrivate::categoryBottom(int category) |
|
581 | qreal QAbstractBarSeriesPrivate::categoryBottom(int category) | |
583 | { |
|
582 | { | |
584 | // Returns bottom (sum of all negative values) of category |
|
583 | // Returns bottom (sum of all negative values) of category | |
585 | // Returns 0, if all values are positive |
|
584 | // Returns 0, if all values are positive | |
586 | qreal bottom(0); |
|
585 | qreal bottom(0); | |
587 | int count = m_barSets.count(); |
|
586 | int count = m_barSets.count(); | |
588 | for (int set = 0; set < count; set++) { |
|
587 | for (int set = 0; set < count; set++) { | |
589 | if (category < m_barSets.at(set)->count()) { |
|
588 | if (category < m_barSets.at(set)->count()) { | |
590 | qreal temp = m_barSets.at(set)->at(category); |
|
589 | qreal temp = m_barSets.at(set)->at(category); | |
591 | if (temp < 0) { |
|
590 | if (temp < 0) { | |
592 | bottom += temp; |
|
591 | bottom += temp; | |
593 | } |
|
592 | } | |
594 | } |
|
593 | } | |
595 | } |
|
594 | } | |
596 | return bottom; |
|
595 | return bottom; | |
597 | } |
|
596 | } | |
598 |
|
597 | |||
599 | qreal QAbstractBarSeriesPrivate::top() |
|
598 | qreal QAbstractBarSeriesPrivate::top() | |
600 | { |
|
599 | { | |
601 | // Returns top of all categories |
|
600 | // Returns top of all categories | |
602 | qreal top(0); |
|
601 | qreal top(0); | |
603 | int count = categoryCount(); |
|
602 | int count = categoryCount(); | |
604 | for (int i = 0; i < count; i++) { |
|
603 | for (int i = 0; i < count; i++) { | |
605 | qreal temp = categoryTop(i); |
|
604 | qreal temp = categoryTop(i); | |
606 | if (temp > top) |
|
605 | if (temp > top) | |
607 | top = temp; |
|
606 | top = temp; | |
608 | } |
|
607 | } | |
609 | return top; |
|
608 | return top; | |
610 | } |
|
609 | } | |
611 |
|
610 | |||
612 | qreal QAbstractBarSeriesPrivate::bottom() |
|
611 | qreal QAbstractBarSeriesPrivate::bottom() | |
613 | { |
|
612 | { | |
614 | // Returns bottom of all categories |
|
613 | // Returns bottom of all categories | |
615 | qreal bottom(0); |
|
614 | qreal bottom(0); | |
616 | int count = categoryCount(); |
|
615 | int count = categoryCount(); | |
617 | for (int i = 0; i < count; i++) { |
|
616 | for (int i = 0; i < count; i++) { | |
618 | qreal temp = categoryBottom(i); |
|
617 | qreal temp = categoryBottom(i); | |
619 | if (temp < bottom) |
|
618 | if (temp < bottom) | |
620 | bottom = temp; |
|
619 | bottom = temp; | |
621 | } |
|
620 | } | |
622 | return bottom; |
|
621 | return bottom; | |
623 | } |
|
622 | } | |
624 |
|
623 | |||
625 |
|
624 | |||
626 | void QAbstractBarSeriesPrivate::scaleDomain(Domain &domain) |
|
625 | void QAbstractBarSeriesPrivate::scaleDomain(Domain &domain) | |
627 | { |
|
626 | { | |
628 | qreal minX(domain.minX()); |
|
627 | qreal minX(domain.minX()); | |
629 | qreal minY(domain.minY()); |
|
628 | qreal minY(domain.minY()); | |
630 | qreal maxX(domain.maxX()); |
|
629 | qreal maxX(domain.maxX()); | |
631 | qreal maxY(domain.maxY()); |
|
630 | qreal maxY(domain.maxY()); | |
632 |
|
631 | |||
633 | qreal seriesMinX = this->minX(); |
|
632 | qreal seriesMinX = this->minX(); | |
634 | qreal seriesMaxX = this->maxX(); |
|
633 | qreal seriesMaxX = this->maxX(); | |
635 | qreal y = max(); |
|
634 | qreal y = max(); | |
636 | minX = qMin(minX, seriesMinX - (qreal)0.5); |
|
635 | minX = qMin(minX, seriesMinX - (qreal)0.5); | |
637 | minY = qMin(minY, y); |
|
636 | minY = qMin(minY, y); | |
638 | maxX = qMax(maxX, seriesMaxX + (qreal)0.5); |
|
637 | maxX = qMax(maxX, seriesMaxX + (qreal)0.5); | |
639 | maxY = qMax(maxY, y); |
|
638 | maxY = qMax(maxY, y); | |
640 |
|
639 | |||
641 | domain.setRange(minX, maxX, minY, maxY); |
|
640 | domain.setRange(minX, maxX, minY, maxY); | |
642 | } |
|
641 | } | |
643 |
|
642 | |||
644 | ChartElement *QAbstractBarSeriesPrivate::createGraphics(ChartPresenter *presenter) |
|
643 | ChartElement *QAbstractBarSeriesPrivate::createGraphics(ChartPresenter *presenter) | |
645 | { |
|
644 | { | |
646 | Q_UNUSED(presenter); |
|
645 | Q_UNUSED(presenter); | |
647 | qWarning() << "QAbstractBarSeriesPrivate::createGraphics called"; |
|
646 | qWarning() << "QAbstractBarSeriesPrivate::createGraphics called"; | |
648 | return 0; |
|
647 | return 0; | |
649 | } |
|
648 | } | |
650 |
|
649 | |||
651 | QList<QLegendMarker*> QAbstractBarSeriesPrivate::createLegendMarkers(QLegend* legend) |
|
650 | QList<QLegendMarker*> QAbstractBarSeriesPrivate::createLegendMarkers(QLegend* legend) | |
652 | { |
|
651 | { | |
653 | Q_Q(QAbstractBarSeries); |
|
652 | Q_Q(QAbstractBarSeries); | |
654 | QList<QLegendMarker*> markers; |
|
653 | QList<QLegendMarker*> markers; | |
655 |
|
654 | |||
656 | foreach(QBarSet* set, q->barSets()) { |
|
655 | foreach(QBarSet* set, q->barSets()) { | |
657 | QBarLegendMarker* marker = new QBarLegendMarker(q,set,legend); |
|
656 | QBarLegendMarker* marker = new QBarLegendMarker(q,set,legend); | |
658 | markers << marker; |
|
657 | markers << marker; | |
659 | } |
|
658 | } | |
660 | return markers; |
|
659 | return markers; | |
661 | } |
|
660 | } | |
662 |
|
661 | |||
663 |
|
662 | |||
664 | bool QAbstractBarSeriesPrivate::append(QBarSet *set) |
|
663 | bool QAbstractBarSeriesPrivate::append(QBarSet *set) | |
665 | { |
|
664 | { | |
666 | if ((m_barSets.contains(set)) || (set == 0)) |
|
665 | if ((m_barSets.contains(set)) || (set == 0)) | |
667 | return false; // Fail if set is already in list or set is null. |
|
666 | return false; // Fail if set is already in list or set is null. | |
668 |
|
667 | |||
669 | m_barSets.append(set); |
|
668 | m_barSets.append(set); | |
670 | QObject::connect(set->d_ptr.data(), SIGNAL(updatedLayout()), this, SIGNAL(updatedLayout())); |
|
669 | QObject::connect(set->d_ptr.data(), SIGNAL(updatedLayout()), this, SIGNAL(updatedLayout())); | |
671 | QObject::connect(set->d_ptr.data(), SIGNAL(updatedBars()), this, SIGNAL(updatedBars())); |
|
670 | QObject::connect(set->d_ptr.data(), SIGNAL(updatedBars()), this, SIGNAL(updatedBars())); | |
672 | QObject::connect(set->d_ptr.data(), SIGNAL(restructuredBars()), this, SIGNAL(restructuredBars())); |
|
671 | QObject::connect(set->d_ptr.data(), SIGNAL(restructuredBars()), this, SIGNAL(restructuredBars())); | |
673 |
|
672 | |||
674 | emit restructuredBars(); // this notifies barchartitem |
|
673 | emit restructuredBars(); // this notifies barchartitem | |
675 | return true; |
|
674 | return true; | |
676 | } |
|
675 | } | |
677 |
|
676 | |||
678 | bool QAbstractBarSeriesPrivate::remove(QBarSet *set) |
|
677 | bool QAbstractBarSeriesPrivate::remove(QBarSet *set) | |
679 | { |
|
678 | { | |
680 | if (!m_barSets.contains(set)) |
|
679 | if (!m_barSets.contains(set)) | |
681 | return false; // Fail if set is not in list |
|
680 | return false; // Fail if set is not in list | |
682 |
|
681 | |||
683 | m_barSets.removeOne(set); |
|
682 | m_barSets.removeOne(set); | |
684 | QObject::disconnect(set->d_ptr.data(), SIGNAL(updatedLayout()), this, SIGNAL(updatedLayout())); |
|
683 | QObject::disconnect(set->d_ptr.data(), SIGNAL(updatedLayout()), this, SIGNAL(updatedLayout())); | |
685 | QObject::disconnect(set->d_ptr.data(), SIGNAL(updatedBars()), this, SIGNAL(updatedBars())); |
|
684 | QObject::disconnect(set->d_ptr.data(), SIGNAL(updatedBars()), this, SIGNAL(updatedBars())); | |
686 | QObject::disconnect(set->d_ptr.data(), SIGNAL(restructuredBars()), this, SIGNAL(restructuredBars())); |
|
685 | QObject::disconnect(set->d_ptr.data(), SIGNAL(restructuredBars()), this, SIGNAL(restructuredBars())); | |
687 |
|
686 | |||
688 | emit restructuredBars(); // this notifies barchartitem |
|
687 | emit restructuredBars(); // this notifies barchartitem | |
689 | return true; |
|
688 | return true; | |
690 | } |
|
689 | } | |
691 |
|
690 | |||
692 | bool QAbstractBarSeriesPrivate::append(QList<QBarSet * > sets) |
|
691 | bool QAbstractBarSeriesPrivate::append(QList<QBarSet * > sets) | |
693 | { |
|
692 | { | |
694 | foreach (QBarSet *set, sets) { |
|
693 | foreach (QBarSet *set, sets) { | |
695 | if ((set == 0) || (m_barSets.contains(set))) |
|
694 | if ((set == 0) || (m_barSets.contains(set))) | |
696 | return false; // Fail if any of the sets is null or is already appended. |
|
695 | return false; // Fail if any of the sets is null or is already appended. | |
697 | if (sets.count(set) != 1) |
|
696 | if (sets.count(set) != 1) | |
698 | return false; // Also fail if same set is more than once in given list. |
|
697 | return false; // Also fail if same set is more than once in given list. | |
699 | } |
|
698 | } | |
700 |
|
699 | |||
701 | foreach (QBarSet *set, sets) { |
|
700 | foreach (QBarSet *set, sets) { | |
702 | m_barSets.append(set); |
|
701 | m_barSets.append(set); | |
703 | QObject::connect(set->d_ptr.data(), SIGNAL(updatedLayout()), this, SIGNAL(updatedLayout())); |
|
702 | QObject::connect(set->d_ptr.data(), SIGNAL(updatedLayout()), this, SIGNAL(updatedLayout())); | |
704 | QObject::connect(set->d_ptr.data(), SIGNAL(updatedBars()), this, SIGNAL(updatedBars())); |
|
703 | QObject::connect(set->d_ptr.data(), SIGNAL(updatedBars()), this, SIGNAL(updatedBars())); | |
705 | QObject::connect(set->d_ptr.data(), SIGNAL(restructuredBars()), this, SIGNAL(restructuredBars())); |
|
704 | QObject::connect(set->d_ptr.data(), SIGNAL(restructuredBars()), this, SIGNAL(restructuredBars())); | |
706 | } |
|
705 | } | |
707 |
|
706 | |||
708 | emit restructuredBars(); // this notifies barchartitem |
|
707 | emit restructuredBars(); // this notifies barchartitem | |
709 | return true; |
|
708 | return true; | |
710 | } |
|
709 | } | |
711 |
|
710 | |||
712 | bool QAbstractBarSeriesPrivate::remove(QList<QBarSet * > sets) |
|
711 | bool QAbstractBarSeriesPrivate::remove(QList<QBarSet * > sets) | |
713 | { |
|
712 | { | |
714 | if (sets.count() == 0) |
|
713 | if (sets.count() == 0) | |
715 | return false; |
|
714 | return false; | |
716 |
|
715 | |||
717 | foreach (QBarSet *set, sets) { |
|
716 | foreach (QBarSet *set, sets) { | |
718 | if ((set == 0) || (!m_barSets.contains(set))) |
|
717 | if ((set == 0) || (!m_barSets.contains(set))) | |
719 | return false; // Fail if any of the sets is null or is not in series |
|
718 | return false; // Fail if any of the sets is null or is not in series | |
720 | if (sets.count(set) != 1) |
|
719 | if (sets.count(set) != 1) | |
721 | return false; // Also fail if same set is more than once in given list. |
|
720 | return false; // Also fail if same set is more than once in given list. | |
722 | } |
|
721 | } | |
723 |
|
722 | |||
724 | foreach (QBarSet *set, sets) { |
|
723 | foreach (QBarSet *set, sets) { | |
725 | m_barSets.removeOne(set); |
|
724 | m_barSets.removeOne(set); | |
726 | QObject::disconnect(set->d_ptr.data(), SIGNAL(updatedLayout()), this, SIGNAL(updatedLayout())); |
|
725 | QObject::disconnect(set->d_ptr.data(), SIGNAL(updatedLayout()), this, SIGNAL(updatedLayout())); | |
727 | QObject::disconnect(set->d_ptr.data(), SIGNAL(updatedBars()), this, SIGNAL(updatedBars())); |
|
726 | QObject::disconnect(set->d_ptr.data(), SIGNAL(updatedBars()), this, SIGNAL(updatedBars())); | |
728 | QObject::disconnect(set->d_ptr.data(), SIGNAL(restructuredBars()), this, SIGNAL(restructuredBars())); |
|
727 | QObject::disconnect(set->d_ptr.data(), SIGNAL(restructuredBars()), this, SIGNAL(restructuredBars())); | |
729 | } |
|
728 | } | |
730 |
|
729 | |||
731 | emit restructuredBars(); // this notifies barchartitem |
|
730 | emit restructuredBars(); // this notifies barchartitem | |
732 |
|
731 | |||
733 | return true; |
|
732 | return true; | |
734 | } |
|
733 | } | |
735 |
|
734 | |||
736 | bool QAbstractBarSeriesPrivate::insert(int index, QBarSet *set) |
|
735 | bool QAbstractBarSeriesPrivate::insert(int index, QBarSet *set) | |
737 | { |
|
736 | { | |
738 | if ((m_barSets.contains(set)) || (set == 0)) |
|
737 | if ((m_barSets.contains(set)) || (set == 0)) | |
739 | return false; // Fail if set is already in list or set is null. |
|
738 | return false; // Fail if set is already in list or set is null. | |
740 |
|
739 | |||
741 | m_barSets.insert(index, set); |
|
740 | m_barSets.insert(index, set); | |
742 | QObject::connect(set->d_ptr.data(), SIGNAL(updatedLayout()), this, SIGNAL(updatedLayout())); |
|
741 | QObject::connect(set->d_ptr.data(), SIGNAL(updatedLayout()), this, SIGNAL(updatedLayout())); | |
743 | QObject::connect(set->d_ptr.data(), SIGNAL(updatedBars()), this, SIGNAL(updatedBars())); |
|
742 | QObject::connect(set->d_ptr.data(), SIGNAL(updatedBars()), this, SIGNAL(updatedBars())); | |
744 | QObject::connect(set->d_ptr.data(), SIGNAL(restructuredBars()), this, SIGNAL(restructuredBars())); |
|
743 | QObject::connect(set->d_ptr.data(), SIGNAL(restructuredBars()), this, SIGNAL(restructuredBars())); | |
745 |
|
744 | |||
746 | emit restructuredBars(); // this notifies barchartitem |
|
745 | emit restructuredBars(); // this notifies barchartitem | |
747 | return true; |
|
746 | return true; | |
748 | } |
|
747 | } | |
749 |
|
748 | |||
750 | void QAbstractBarSeriesPrivate::initializeAxis(QAbstractAxis *axis) |
|
749 | void QAbstractBarSeriesPrivate::initializeAxis(QAbstractAxis *axis) | |
751 | { |
|
750 | { | |
752 | Q_Q(QAbstractBarSeries); |
|
751 | Q_Q(QAbstractBarSeries); | |
753 |
|
752 | |||
754 | if (axis->type() == QAbstractAxis::AxisTypeBarCategory) { |
|
753 | if (axis->type() == QAbstractAxis::AxisTypeBarCategory) { | |
755 | switch (q->type()) { |
|
754 | switch (q->type()) { | |
756 | case QAbstractSeries::SeriesTypeHorizontalBar: |
|
755 | case QAbstractSeries::SeriesTypeHorizontalBar: | |
757 | case QAbstractSeries::SeriesTypeHorizontalPercentBar: |
|
756 | case QAbstractSeries::SeriesTypeHorizontalPercentBar: | |
758 | case QAbstractSeries::SeriesTypeHorizontalStackedBar: |
|
757 | case QAbstractSeries::SeriesTypeHorizontalStackedBar: | |
759 | if (axis->orientation() == Qt::Vertical) |
|
758 | if (axis->orientation() == Qt::Vertical) | |
760 | populateCategories(qobject_cast<QBarCategoryAxis *>(axis)); |
|
759 | populateCategories(qobject_cast<QBarCategoryAxis *>(axis)); | |
761 | break; |
|
760 | break; | |
762 | case QAbstractSeries::SeriesTypeBar: |
|
761 | case QAbstractSeries::SeriesTypeBar: | |
763 | case QAbstractSeries::SeriesTypePercentBar: |
|
762 | case QAbstractSeries::SeriesTypePercentBar: | |
764 | case QAbstractSeries::SeriesTypeStackedBar: |
|
763 | case QAbstractSeries::SeriesTypeStackedBar: | |
765 | if (axis->orientation() == Qt::Horizontal) |
|
764 | if (axis->orientation() == Qt::Horizontal) | |
766 | populateCategories(qobject_cast<QBarCategoryAxis *>(axis)); |
|
765 | populateCategories(qobject_cast<QBarCategoryAxis *>(axis)); | |
767 | break; |
|
766 | break; | |
768 | default: |
|
767 | default: | |
769 | qWarning() << "Unexpected series type"; |
|
768 | qWarning() << "Unexpected series type"; | |
770 | break; |
|
769 | break; | |
771 | } |
|
770 | } | |
772 | } |
|
771 | } | |
773 | } |
|
772 | } | |
774 |
|
773 | |||
775 | QAbstractAxis::AxisType QAbstractBarSeriesPrivate::defaultAxisType(Qt::Orientation orientation) const |
|
774 | QAbstractAxis::AxisType QAbstractBarSeriesPrivate::defaultAxisType(Qt::Orientation orientation) const | |
776 | { |
|
775 | { | |
777 | Q_Q(const QAbstractBarSeries); |
|
776 | Q_Q(const QAbstractBarSeries); | |
778 |
|
777 | |||
779 | switch (q->type()) { |
|
778 | switch (q->type()) { | |
780 | case QAbstractSeries::SeriesTypeHorizontalBar: |
|
779 | case QAbstractSeries::SeriesTypeHorizontalBar: | |
781 | case QAbstractSeries::SeriesTypeHorizontalPercentBar: |
|
780 | case QAbstractSeries::SeriesTypeHorizontalPercentBar: | |
782 | case QAbstractSeries::SeriesTypeHorizontalStackedBar: |
|
781 | case QAbstractSeries::SeriesTypeHorizontalStackedBar: | |
783 | if (orientation == Qt::Vertical) |
|
782 | if (orientation == Qt::Vertical) | |
784 | return QAbstractAxis::AxisTypeBarCategory; |
|
783 | return QAbstractAxis::AxisTypeBarCategory; | |
785 | break; |
|
784 | break; | |
786 | case QAbstractSeries::SeriesTypeBar: |
|
785 | case QAbstractSeries::SeriesTypeBar: | |
787 | case QAbstractSeries::SeriesTypePercentBar: |
|
786 | case QAbstractSeries::SeriesTypePercentBar: | |
788 | case QAbstractSeries::SeriesTypeStackedBar: |
|
787 | case QAbstractSeries::SeriesTypeStackedBar: | |
789 | if (orientation == Qt::Horizontal) |
|
788 | if (orientation == Qt::Horizontal) | |
790 | return QAbstractAxis::AxisTypeBarCategory; |
|
789 | return QAbstractAxis::AxisTypeBarCategory; | |
791 | break; |
|
790 | break; | |
792 | default: |
|
791 | default: | |
793 | qWarning() << "Unexpected series type"; |
|
792 | qWarning() << "Unexpected series type"; | |
794 | break; |
|
793 | break; | |
795 | } |
|
794 | } | |
796 | return QAbstractAxis::AxisTypeValue; |
|
795 | return QAbstractAxis::AxisTypeValue; | |
797 |
|
796 | |||
798 | } |
|
797 | } | |
799 |
|
798 | |||
800 | void QAbstractBarSeriesPrivate::populateCategories(QBarCategoryAxis *axis) |
|
799 | void QAbstractBarSeriesPrivate::populateCategories(QBarCategoryAxis *axis) | |
801 | { |
|
800 | { | |
802 | QStringList categories; |
|
801 | QStringList categories; | |
803 | if (axis->categories().isEmpty()) { |
|
802 | if (axis->categories().isEmpty()) { | |
804 | for (int i(1); i < categoryCount() + 1; i++) |
|
803 | for (int i(1); i < categoryCount() + 1; i++) | |
805 | categories << QString::number(i); |
|
804 | categories << QString::number(i); | |
806 | axis->append(categories); |
|
805 | axis->append(categories); | |
807 | } |
|
806 | } | |
808 | } |
|
807 | } | |
809 |
|
808 | |||
810 | #include "moc_qabstractbarseries.cpp" |
|
809 | #include "moc_qabstractbarseries.cpp" | |
811 | #include "moc_qabstractbarseries_p.cpp" |
|
810 | #include "moc_qabstractbarseries_p.cpp" | |
812 |
|
811 | |||
813 | QTCOMMERCIALCHART_END_NAMESPACE |
|
812 | QTCOMMERCIALCHART_END_NAMESPACE |
@@ -1,399 +1,399 | |||||
1 | /**************************************************************************** |
|
1 | /**************************************************************************** | |
2 | ** |
|
2 | ** | |
3 | ** Copyright (C) 2012 Digia Plc |
|
3 | ** Copyright (C) 2012 Digia Plc | |
4 | ** All rights reserved. |
|
4 | ** All rights reserved. | |
5 | ** For any questions to Digia, please use contact form at http://qt.digia.com |
|
5 | ** For any questions to Digia, please use contact form at http://qt.digia.com | |
6 | ** |
|
6 | ** | |
7 | ** This file is part of the Qt Commercial Charts Add-on. |
|
7 | ** This file is part of the Qt Commercial Charts Add-on. | |
8 | ** |
|
8 | ** | |
9 | ** $QT_BEGIN_LICENSE$ |
|
9 | ** $QT_BEGIN_LICENSE$ | |
10 | ** Licensees holding valid Qt Commercial licenses may use this file in |
|
10 | ** Licensees holding valid Qt Commercial licenses may use this file in | |
11 | ** accordance with the Qt Commercial License Agreement provided with the |
|
11 | ** accordance with the Qt Commercial License Agreement provided with the | |
12 | ** Software or, alternatively, in accordance with the terms contained in |
|
12 | ** Software or, alternatively, in accordance with the terms contained in | |
13 | ** a written agreement between you and Digia. |
|
13 | ** a written agreement between you and Digia. | |
14 | ** |
|
14 | ** | |
15 | ** If you have questions regarding the use of this file, please use |
|
15 | ** If you have questions regarding the use of this file, please use | |
16 | ** contact form at http://qt.digia.com |
|
16 | ** contact form at http://qt.digia.com | |
17 | ** $QT_END_LICENSE$ |
|
17 | ** $QT_END_LICENSE$ | |
18 | ** |
|
18 | ** | |
19 | ****************************************************************************/ |
|
19 | ****************************************************************************/ | |
20 |
|
20 | |||
21 | #include "legendlayout_p.h" |
|
21 | #include "legendlayout_p.h" | |
22 | #include "chartpresenter_p.h" |
|
22 | #include "chartpresenter_p.h" | |
23 | #include "qlegend_p.h" |
|
23 | #include "qlegend_p.h" | |
24 | #include "chartlayout_p.h" |
|
24 | #include "chartlayout_p.h" | |
25 |
|
25 | |||
26 | #include "qlegendmarker_p.h" |
|
26 | #include "qlegendmarker_p.h" | |
27 | #include "legendmarkeritem_p.h" |
|
27 | #include "legendmarkeritem_p.h" | |
28 | #include "qlegendmarker.h" |
|
28 | #include "qlegendmarker.h" | |
29 |
|
29 | |||
30 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
30 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
31 |
|
31 | |||
32 | LegendLayout::LegendLayout(QLegend *legend) |
|
32 | LegendLayout::LegendLayout(QLegend *legend) | |
33 | : m_legend(legend) |
|
33 | : m_legend(legend) | |
34 | { |
|
34 | { | |
35 |
|
35 | |||
36 | } |
|
36 | } | |
37 |
|
37 | |||
38 | LegendLayout::~LegendLayout() |
|
38 | LegendLayout::~LegendLayout() | |
39 | { |
|
39 | { | |
40 |
|
40 | |||
41 | } |
|
41 | } | |
42 |
|
42 | |||
43 | void LegendLayout::setOffset(qreal x, qreal y) |
|
43 | void LegendLayout::setOffset(qreal x, qreal y) | |
44 | { |
|
44 | { | |
45 | bool scrollHorizontal = true; |
|
45 | bool scrollHorizontal = true; | |
46 | switch (m_legend->alignment()) { |
|
46 | switch (m_legend->alignment()) { | |
47 | case Qt::AlignTop: |
|
47 | case Qt::AlignTop: | |
48 | case Qt::AlignBottom: |
|
48 | case Qt::AlignBottom: | |
49 | scrollHorizontal = true; |
|
49 | scrollHorizontal = true; | |
50 | break; |
|
50 | break; | |
51 | case Qt::AlignLeft: |
|
51 | case Qt::AlignLeft: | |
52 | case Qt::AlignRight: |
|
52 | case Qt::AlignRight: | |
53 | scrollHorizontal = false; |
|
53 | scrollHorizontal = false; | |
54 | break; |
|
54 | break; | |
55 | } |
|
55 | } | |
56 |
|
56 | |||
57 | // If detached, the scrolling direction is vertical instead of horizontal and vice versa. |
|
57 | // If detached, the scrolling direction is vertical instead of horizontal and vice versa. | |
58 | if (!m_legend->isAttachedToChart()) |
|
58 | if (!m_legend->isAttachedToChart()) | |
59 | scrollHorizontal = !scrollHorizontal; |
|
59 | scrollHorizontal = !scrollHorizontal; | |
60 |
|
60 | |||
61 | QRectF boundingRect = geometry(); |
|
61 | QRectF boundingRect = geometry(); | |
62 | qreal left, top, right, bottom; |
|
62 | qreal left, top, right, bottom; | |
63 | getContentsMargins(&left, &top, &right, &bottom); |
|
63 | getContentsMargins(&left, &top, &right, &bottom); | |
64 | boundingRect.adjust(left, top, -right, -bottom); |
|
64 | boundingRect.adjust(left, top, -right, -bottom); | |
65 |
|
65 | |||
66 | // Limit offset between m_minOffset and m_maxOffset |
|
66 | // Limit offset between m_minOffset and m_maxOffset | |
67 | if (scrollHorizontal) { |
|
67 | if (scrollHorizontal) { | |
68 | if (m_width <= boundingRect.width()) |
|
68 | if (m_width <= boundingRect.width()) | |
69 | return; |
|
69 | return; | |
70 |
|
70 | |||
71 | if (x != m_offsetX) { |
|
71 | if (x != m_offsetX) { | |
72 | m_offsetX = qBound(m_minOffsetX, x, m_maxOffsetX); |
|
72 | m_offsetX = qBound(m_minOffsetX, x, m_maxOffsetX); | |
73 | m_legend->d_ptr->items()->setPos(-m_offsetX, boundingRect.top()); |
|
73 | m_legend->d_ptr->items()->setPos(-m_offsetX, boundingRect.top()); | |
74 | } |
|
74 | } | |
75 | } else { |
|
75 | } else { | |
76 | if (m_height <= boundingRect.height()) |
|
76 | if (m_height <= boundingRect.height()) | |
77 | return; |
|
77 | return; | |
78 |
|
78 | |||
79 | if (y != m_offsetY) { |
|
79 | if (y != m_offsetY) { | |
80 | m_offsetY = qBound(m_minOffsetY, y, m_maxOffsetY); |
|
80 | m_offsetY = qBound(m_minOffsetY, y, m_maxOffsetY); | |
81 | m_legend->d_ptr->items()->setPos(boundingRect.left(), -m_offsetY); |
|
81 | m_legend->d_ptr->items()->setPos(boundingRect.left(), -m_offsetY); | |
82 | } |
|
82 | } | |
83 | } |
|
83 | } | |
84 | } |
|
84 | } | |
85 |
|
85 | |||
86 | QPointF LegendLayout::offset() const |
|
86 | QPointF LegendLayout::offset() const | |
87 | { |
|
87 | { | |
88 | return QPointF(m_offsetX, m_offsetY); |
|
88 | return QPointF(m_offsetX, m_offsetY); | |
89 | } |
|
89 | } | |
90 |
|
90 | |||
91 | void LegendLayout::invalidate() |
|
91 | void LegendLayout::invalidate() | |
92 | { |
|
92 | { | |
93 | QGraphicsLayout::invalidate(); |
|
93 | QGraphicsLayout::invalidate(); | |
94 | if (m_legend->isAttachedToChart()) |
|
94 | if (m_legend->isAttachedToChart()) | |
95 | m_legend->d_ptr->m_presenter->layout()->invalidate(); |
|
95 | m_legend->d_ptr->m_presenter->layout()->invalidate(); | |
96 | } |
|
96 | } | |
97 |
|
97 | |||
98 | void LegendLayout::setGeometry(const QRectF &rect) |
|
98 | void LegendLayout::setGeometry(const QRectF &rect) | |
99 | { |
|
99 | { | |
100 | m_legend->d_ptr->items()->setVisible(m_legend->isVisible()); |
|
100 | m_legend->d_ptr->items()->setVisible(m_legend->isVisible()); | |
101 |
|
101 | |||
102 | QGraphicsLayout::setGeometry(rect); |
|
102 | QGraphicsLayout::setGeometry(rect); | |
103 |
|
103 | |||
104 | if (m_legend->isAttachedToChart()) |
|
104 | if (m_legend->isAttachedToChart()) | |
105 | setAttachedGeometry(rect); |
|
105 | setAttachedGeometry(rect); | |
106 | else |
|
106 | else | |
107 | setDettachedGeometry(rect); |
|
107 | setDettachedGeometry(rect); | |
108 | } |
|
108 | } | |
109 |
|
109 | |||
110 | void LegendLayout::setAttachedGeometry(const QRectF &rect) |
|
110 | void LegendLayout::setAttachedGeometry(const QRectF &rect) | |
111 | { |
|
111 | { | |
112 | if (!rect.isValid()) |
|
112 | if (!rect.isValid()) | |
113 | return; |
|
113 | return; | |
114 |
|
114 | |||
115 | m_offsetX = 0; |
|
115 | m_offsetX = 0; | |
116 | m_offsetY = 0; |
|
116 | m_offsetY = 0; | |
117 |
|
117 | |||
118 | QSizeF size(0, 0); |
|
118 | QSizeF size(0, 0); | |
119 |
|
119 | |||
120 |
if (m_legend->d_ptr-> |
|
120 | if (m_legend->d_ptr->markers().isEmpty()) { | |
121 | return; |
|
121 | return; | |
122 | } |
|
122 | } | |
123 |
|
123 | |||
124 | m_width = 0; |
|
124 | m_width = 0; | |
125 | m_height = 0; |
|
125 | m_height = 0; | |
126 |
|
126 | |||
127 | qreal left, top, right, bottom; |
|
127 | qreal left, top, right, bottom; | |
128 | getContentsMargins(&left, &top, &right, &bottom); |
|
128 | getContentsMargins(&left, &top, &right, &bottom); | |
129 |
|
129 | |||
130 | QRectF geometry = rect.adjusted(left, top, -right, -bottom); |
|
130 | QRectF geometry = rect.adjusted(left, top, -right, -bottom); | |
131 |
|
131 | |||
132 | switch(m_legend->alignment()) { |
|
132 | switch(m_legend->alignment()) { | |
133 | case Qt::AlignTop: |
|
133 | case Qt::AlignTop: | |
134 | case Qt::AlignBottom: { |
|
134 | case Qt::AlignBottom: { | |
135 | QPointF point(0,0); |
|
135 | QPointF point(0,0); | |
136 |
foreach (QLegendMarker* marker, m_legend->d_ptr-> |
|
136 | foreach (QLegendMarker* marker, m_legend->d_ptr->markers()) { | |
137 | LegendMarkerItem* item = marker->d_ptr->item(); |
|
137 | LegendMarkerItem* item = marker->d_ptr->item(); | |
138 | if (item->isVisible()) { |
|
138 | if (item->isVisible()) { | |
139 | item->setGeometry(geometry); |
|
139 | item->setGeometry(geometry); | |
140 | item->setPos(point.x(),geometry.height()/2 - item->boundingRect().height()/2); |
|
140 | item->setPos(point.x(),geometry.height()/2 - item->boundingRect().height()/2); | |
141 | const QRectF& rect = item->boundingRect(); |
|
141 | const QRectF& rect = item->boundingRect(); | |
142 | size = size.expandedTo(rect.size()); |
|
142 | size = size.expandedTo(rect.size()); | |
143 | qreal w = rect.width(); |
|
143 | qreal w = rect.width(); | |
144 | m_width+=w; |
|
144 | m_width+=w; | |
145 | point.setX(point.x() + w); |
|
145 | point.setX(point.x() + w); | |
146 | } |
|
146 | } | |
147 | } |
|
147 | } | |
148 | if (m_width < geometry.width()) |
|
148 | if (m_width < geometry.width()) | |
149 | m_legend->d_ptr->items()->setPos(geometry.width() / 2 - m_width / 2, geometry.top()); |
|
149 | m_legend->d_ptr->items()->setPos(geometry.width() / 2 - m_width / 2, geometry.top()); | |
150 | else |
|
150 | else | |
151 | m_legend->d_ptr->items()->setPos(geometry.topLeft()); |
|
151 | m_legend->d_ptr->items()->setPos(geometry.topLeft()); | |
152 | m_height = size.height(); |
|
152 | m_height = size.height(); | |
153 | } |
|
153 | } | |
154 | break; |
|
154 | break; | |
155 | case Qt::AlignLeft: |
|
155 | case Qt::AlignLeft: | |
156 | case Qt::AlignRight: { |
|
156 | case Qt::AlignRight: { | |
157 | QPointF point(0,0); |
|
157 | QPointF point(0,0); | |
158 |
foreach (QLegendMarker* marker, m_legend->d_ptr-> |
|
158 | foreach (QLegendMarker* marker, m_legend->d_ptr->markers()) { | |
159 | LegendMarkerItem* item = marker->d_ptr->item(); |
|
159 | LegendMarkerItem* item = marker->d_ptr->item(); | |
160 | if (item->isVisible()) { |
|
160 | if (item->isVisible()) { | |
161 | item->setGeometry(geometry); |
|
161 | item->setGeometry(geometry); | |
162 | item->setPos(point); |
|
162 | item->setPos(point); | |
163 | const QRectF& rect = item->boundingRect(); |
|
163 | const QRectF& rect = item->boundingRect(); | |
164 | qreal h = rect.height(); |
|
164 | qreal h = rect.height(); | |
165 | size = size.expandedTo(rect.size()); |
|
165 | size = size.expandedTo(rect.size()); | |
166 | m_height+=h; |
|
166 | m_height+=h; | |
167 | point.setY(point.y() + h); |
|
167 | point.setY(point.y() + h); | |
168 | } |
|
168 | } | |
169 | } |
|
169 | } | |
170 |
|
170 | |||
171 | if (m_height < geometry.height()) |
|
171 | if (m_height < geometry.height()) | |
172 | m_legend->d_ptr->items()->setPos(geometry.left(), geometry.height() / 2 - m_height / 2); |
|
172 | m_legend->d_ptr->items()->setPos(geometry.left(), geometry.height() / 2 - m_height / 2); | |
173 | else |
|
173 | else | |
174 | m_legend->d_ptr->items()->setPos(geometry.topLeft()); |
|
174 | m_legend->d_ptr->items()->setPos(geometry.topLeft()); | |
175 | m_width = size.width(); |
|
175 | m_width = size.width(); | |
176 | break; |
|
176 | break; | |
177 | } |
|
177 | } | |
178 | } |
|
178 | } | |
179 |
|
179 | |||
180 | m_minOffsetX = -left; |
|
180 | m_minOffsetX = -left; | |
181 | m_minOffsetY = - top; |
|
181 | m_minOffsetY = - top; | |
182 | m_maxOffsetX = m_width - geometry.width() - right; |
|
182 | m_maxOffsetX = m_width - geometry.width() - right; | |
183 | m_maxOffsetY = m_height - geometry.height() - bottom; |
|
183 | m_maxOffsetY = m_height - geometry.height() - bottom; | |
184 | } |
|
184 | } | |
185 |
|
185 | |||
186 | void LegendLayout::setDettachedGeometry(const QRectF &rect) |
|
186 | void LegendLayout::setDettachedGeometry(const QRectF &rect) | |
187 | { |
|
187 | { | |
188 | if (!rect.isValid()) |
|
188 | if (!rect.isValid()) | |
189 | return; |
|
189 | return; | |
190 |
|
190 | |||
191 | // Detached layout is different. |
|
191 | // Detached layout is different. | |
192 | // In detached mode legend may have multiple rows and columns, so layout calculations |
|
192 | // In detached mode legend may have multiple rows and columns, so layout calculations | |
193 | // differ a log from attached mode. |
|
193 | // differ a log from attached mode. | |
194 | // Also the scrolling logic is bit different. |
|
194 | // Also the scrolling logic is bit different. | |
195 |
|
195 | |||
196 | m_offsetX = 0; |
|
196 | m_offsetX = 0; | |
197 | m_offsetY = 0; |
|
197 | m_offsetY = 0; | |
198 |
|
198 | |||
199 | qreal left, top, right, bottom; |
|
199 | qreal left, top, right, bottom; | |
200 | getContentsMargins(&left, &top, &right, &bottom); |
|
200 | getContentsMargins(&left, &top, &right, &bottom); | |
201 | QRectF geometry = rect.adjusted(left, top, -right, -bottom); |
|
201 | QRectF geometry = rect.adjusted(left, top, -right, -bottom); | |
202 |
|
202 | |||
203 | QSizeF size(0, 0); |
|
203 | QSizeF size(0, 0); | |
204 |
|
204 | |||
205 |
QList<QLegendMarker *> markers = m_legend->d_ptr-> |
|
205 | QList<QLegendMarker *> markers = m_legend->d_ptr->markers(); | |
206 |
|
206 | |||
207 | if (markers.isEmpty()) |
|
207 | if (markers.isEmpty()) | |
208 | return; |
|
208 | return; | |
209 |
|
209 | |||
210 | switch (m_legend->alignment()) { |
|
210 | switch (m_legend->alignment()) { | |
211 | case Qt::AlignTop: { |
|
211 | case Qt::AlignTop: { | |
212 | QPointF point(0, 0); |
|
212 | QPointF point(0, 0); | |
213 | m_width = 0; |
|
213 | m_width = 0; | |
214 | m_height = 0; |
|
214 | m_height = 0; | |
215 | for (int i = 0; i < markers.count(); i++) { |
|
215 | for (int i = 0; i < markers.count(); i++) { | |
216 | LegendMarkerItem *item = markers.at(i)->d_ptr->item(); |
|
216 | LegendMarkerItem *item = markers.at(i)->d_ptr->item(); | |
217 | if (item->isVisible()) { |
|
217 | if (item->isVisible()) { | |
218 | item->setGeometry(geometry); |
|
218 | item->setGeometry(geometry); | |
219 | item->setPos(point.x(),point.y()); |
|
219 | item->setPos(point.x(),point.y()); | |
220 | const QRectF& boundingRect = item->boundingRect(); |
|
220 | const QRectF& boundingRect = item->boundingRect(); | |
221 | qreal w = boundingRect.width(); |
|
221 | qreal w = boundingRect.width(); | |
222 | qreal h = boundingRect.height(); |
|
222 | qreal h = boundingRect.height(); | |
223 | m_width = qMax(m_width,w); |
|
223 | m_width = qMax(m_width,w); | |
224 | m_height = qMax(m_height,h); |
|
224 | m_height = qMax(m_height,h); | |
225 | point.setX(point.x() + w); |
|
225 | point.setX(point.x() + w); | |
226 | if (point.x() + w > geometry.left() + geometry.width() - right) { |
|
226 | if (point.x() + w > geometry.left() + geometry.width() - right) { | |
227 | // Next item would go off rect. |
|
227 | // Next item would go off rect. | |
228 | point.setX(0); |
|
228 | point.setX(0); | |
229 | point.setY(point.y() + h); |
|
229 | point.setY(point.y() + h); | |
230 | if (i+1 < markers.count()) { |
|
230 | if (i+1 < markers.count()) { | |
231 | m_height += h; |
|
231 | m_height += h; | |
232 | } |
|
232 | } | |
233 | } |
|
233 | } | |
234 | } |
|
234 | } | |
235 | } |
|
235 | } | |
236 | m_legend->d_ptr->items()->setPos(geometry.topLeft()); |
|
236 | m_legend->d_ptr->items()->setPos(geometry.topLeft()); | |
237 |
|
237 | |||
238 | m_minOffsetX = -left; |
|
238 | m_minOffsetX = -left; | |
239 | m_minOffsetY = -top; |
|
239 | m_minOffsetY = -top; | |
240 | m_maxOffsetX = m_width - geometry.width() - right; |
|
240 | m_maxOffsetX = m_width - geometry.width() - right; | |
241 | m_maxOffsetY = m_height - geometry.height() - bottom; |
|
241 | m_maxOffsetY = m_height - geometry.height() - bottom; | |
242 | } |
|
242 | } | |
243 | break; |
|
243 | break; | |
244 | case Qt::AlignBottom: { |
|
244 | case Qt::AlignBottom: { | |
245 | QPointF point(0, geometry.height()); |
|
245 | QPointF point(0, geometry.height()); | |
246 | m_width = 0; |
|
246 | m_width = 0; | |
247 | m_height = 0; |
|
247 | m_height = 0; | |
248 | for (int i = 0; i < markers.count(); i++) { |
|
248 | for (int i = 0; i < markers.count(); i++) { | |
249 | LegendMarkerItem *item = markers.at(i)->d_ptr->item(); |
|
249 | LegendMarkerItem *item = markers.at(i)->d_ptr->item(); | |
250 | if (item->isVisible()) { |
|
250 | if (item->isVisible()) { | |
251 | item->setGeometry(geometry); |
|
251 | item->setGeometry(geometry); | |
252 | const QRectF& boundingRect = item->boundingRect(); |
|
252 | const QRectF& boundingRect = item->boundingRect(); | |
253 | qreal w = boundingRect.width(); |
|
253 | qreal w = boundingRect.width(); | |
254 | qreal h = boundingRect.height(); |
|
254 | qreal h = boundingRect.height(); | |
255 | m_width = qMax(m_width,w); |
|
255 | m_width = qMax(m_width,w); | |
256 | m_height = qMax(m_height,h); |
|
256 | m_height = qMax(m_height,h); | |
257 | item->setPos(point.x(),point.y() - h); |
|
257 | item->setPos(point.x(),point.y() - h); | |
258 | point.setX(point.x() + w); |
|
258 | point.setX(point.x() + w); | |
259 | if (point.x() + w > geometry.left() + geometry.width() - right) { |
|
259 | if (point.x() + w > geometry.left() + geometry.width() - right) { | |
260 | // Next item would go off rect. |
|
260 | // Next item would go off rect. | |
261 | point.setX(0); |
|
261 | point.setX(0); | |
262 | point.setY(point.y() - h); |
|
262 | point.setY(point.y() - h); | |
263 | if (i+1 < markers.count()) { |
|
263 | if (i+1 < markers.count()) { | |
264 | m_height += h; |
|
264 | m_height += h; | |
265 | } |
|
265 | } | |
266 | } |
|
266 | } | |
267 | } |
|
267 | } | |
268 | } |
|
268 | } | |
269 | m_legend->d_ptr->items()->setPos(geometry.topLeft()); |
|
269 | m_legend->d_ptr->items()->setPos(geometry.topLeft()); | |
270 |
|
270 | |||
271 | m_minOffsetX = -left; |
|
271 | m_minOffsetX = -left; | |
272 | m_minOffsetY = -m_height + geometry.height() - top; |
|
272 | m_minOffsetY = -m_height + geometry.height() - top; | |
273 | m_maxOffsetX = m_width - geometry.width() - right; |
|
273 | m_maxOffsetX = m_width - geometry.width() - right; | |
274 | m_maxOffsetY = -bottom; |
|
274 | m_maxOffsetY = -bottom; | |
275 | } |
|
275 | } | |
276 | break; |
|
276 | break; | |
277 | case Qt::AlignLeft: { |
|
277 | case Qt::AlignLeft: { | |
278 | QPointF point(0, 0); |
|
278 | QPointF point(0, 0); | |
279 | m_width = 0; |
|
279 | m_width = 0; | |
280 | m_height = 0; |
|
280 | m_height = 0; | |
281 | qreal maxWidth = 0; |
|
281 | qreal maxWidth = 0; | |
282 | for (int i = 0; i < markers.count(); i++) { |
|
282 | for (int i = 0; i < markers.count(); i++) { | |
283 | LegendMarkerItem *item = markers.at(i)->d_ptr->item(); |
|
283 | LegendMarkerItem *item = markers.at(i)->d_ptr->item(); | |
284 | if (item->isVisible()) { |
|
284 | if (item->isVisible()) { | |
285 | item->setGeometry(geometry); |
|
285 | item->setGeometry(geometry); | |
286 | const QRectF& boundingRect = item->boundingRect(); |
|
286 | const QRectF& boundingRect = item->boundingRect(); | |
287 | qreal w = boundingRect.width(); |
|
287 | qreal w = boundingRect.width(); | |
288 | qreal h = boundingRect.height(); |
|
288 | qreal h = boundingRect.height(); | |
289 | m_height = qMax(m_height,h); |
|
289 | m_height = qMax(m_height,h); | |
290 | maxWidth = qMax(maxWidth,w); |
|
290 | maxWidth = qMax(maxWidth,w); | |
291 | item->setPos(point.x(),point.y()); |
|
291 | item->setPos(point.x(),point.y()); | |
292 | point.setY(point.y() + h); |
|
292 | point.setY(point.y() + h); | |
293 | if (point.y() + h > geometry.bottom() - bottom) { |
|
293 | if (point.y() + h > geometry.bottom() - bottom) { | |
294 | // Next item would go off rect. |
|
294 | // Next item would go off rect. | |
295 | point.setX(point.x() + maxWidth); |
|
295 | point.setX(point.x() + maxWidth); | |
296 | point.setY(0); |
|
296 | point.setY(0); | |
297 | if (i+1 < markers.count()) { |
|
297 | if (i+1 < markers.count()) { | |
298 | m_width += maxWidth; |
|
298 | m_width += maxWidth; | |
299 | maxWidth = 0; |
|
299 | maxWidth = 0; | |
300 | } |
|
300 | } | |
301 | } |
|
301 | } | |
302 | } |
|
302 | } | |
303 | } |
|
303 | } | |
304 | m_width += maxWidth; |
|
304 | m_width += maxWidth; | |
305 | m_legend->d_ptr->items()->setPos(geometry.topLeft()); |
|
305 | m_legend->d_ptr->items()->setPos(geometry.topLeft()); | |
306 |
|
306 | |||
307 | m_minOffsetX = -left; |
|
307 | m_minOffsetX = -left; | |
308 | m_minOffsetY = -top; |
|
308 | m_minOffsetY = -top; | |
309 | m_maxOffsetX = m_width - geometry.width() - right; |
|
309 | m_maxOffsetX = m_width - geometry.width() - right; | |
310 | m_maxOffsetY = m_height - geometry.height() - bottom; |
|
310 | m_maxOffsetY = m_height - geometry.height() - bottom; | |
311 | } |
|
311 | } | |
312 | break; |
|
312 | break; | |
313 | case Qt::AlignRight: { |
|
313 | case Qt::AlignRight: { | |
314 | QPointF point(geometry.width(), 0); |
|
314 | QPointF point(geometry.width(), 0); | |
315 | m_width = 0; |
|
315 | m_width = 0; | |
316 | m_height = 0; |
|
316 | m_height = 0; | |
317 | qreal maxWidth = 0; |
|
317 | qreal maxWidth = 0; | |
318 | for (int i = 0; i < markers.count(); i++) { |
|
318 | for (int i = 0; i < markers.count(); i++) { | |
319 | LegendMarkerItem *item = markers.at(i)->d_ptr->item(); |
|
319 | LegendMarkerItem *item = markers.at(i)->d_ptr->item(); | |
320 | if (item->isVisible()) { |
|
320 | if (item->isVisible()) { | |
321 | item->setGeometry(geometry); |
|
321 | item->setGeometry(geometry); | |
322 | const QRectF& boundingRect = item->boundingRect(); |
|
322 | const QRectF& boundingRect = item->boundingRect(); | |
323 | qreal w = boundingRect.width(); |
|
323 | qreal w = boundingRect.width(); | |
324 | qreal h = boundingRect.height(); |
|
324 | qreal h = boundingRect.height(); | |
325 | m_height = qMax(m_height,h); |
|
325 | m_height = qMax(m_height,h); | |
326 | maxWidth = qMax(maxWidth,w); |
|
326 | maxWidth = qMax(maxWidth,w); | |
327 | item->setPos(point.x() - w,point.y()); |
|
327 | item->setPos(point.x() - w,point.y()); | |
328 | point.setY(point.y() + h); |
|
328 | point.setY(point.y() + h); | |
329 | if (point.y() + h > geometry.bottom()-bottom) { |
|
329 | if (point.y() + h > geometry.bottom()-bottom) { | |
330 | // Next item would go off rect. |
|
330 | // Next item would go off rect. | |
331 | point.setX(point.x() - maxWidth); |
|
331 | point.setX(point.x() - maxWidth); | |
332 | point.setY(0); |
|
332 | point.setY(0); | |
333 | if (i+1 < markers.count()) { |
|
333 | if (i+1 < markers.count()) { | |
334 | m_width += maxWidth; |
|
334 | m_width += maxWidth; | |
335 | maxWidth = 0; |
|
335 | maxWidth = 0; | |
336 | } |
|
336 | } | |
337 | } |
|
337 | } | |
338 | } |
|
338 | } | |
339 | } |
|
339 | } | |
340 | m_width += maxWidth; |
|
340 | m_width += maxWidth; | |
341 | m_legend->d_ptr->items()->setPos(geometry.topLeft()); |
|
341 | m_legend->d_ptr->items()->setPos(geometry.topLeft()); | |
342 |
|
342 | |||
343 | m_minOffsetX = - m_width + geometry.width() - left; |
|
343 | m_minOffsetX = - m_width + geometry.width() - left; | |
344 | m_minOffsetY = -top; |
|
344 | m_minOffsetY = -top; | |
345 | m_maxOffsetX = - right; |
|
345 | m_maxOffsetX = - right; | |
346 | m_maxOffsetY = m_height - geometry.height() - bottom; |
|
346 | m_maxOffsetY = m_height - geometry.height() - bottom; | |
347 | } |
|
347 | } | |
348 | break; |
|
348 | break; | |
349 | default: |
|
349 | default: | |
350 | break; |
|
350 | break; | |
351 | } |
|
351 | } | |
352 |
|
352 | |||
353 | } |
|
353 | } | |
354 |
|
354 | |||
355 | QSizeF LegendLayout::sizeHint(Qt::SizeHint which, const QSizeF &constraint) const |
|
355 | QSizeF LegendLayout::sizeHint(Qt::SizeHint which, const QSizeF &constraint) const | |
356 | { |
|
356 | { | |
357 | QSizeF size(0, 0); |
|
357 | QSizeF size(0, 0); | |
358 | qreal left, top, right, bottom; |
|
358 | qreal left, top, right, bottom; | |
359 | getContentsMargins(&left, &top, &right, &bottom); |
|
359 | getContentsMargins(&left, &top, &right, &bottom); | |
360 |
|
360 | |||
361 | if(constraint.isValid()) { |
|
361 | if(constraint.isValid()) { | |
362 |
foreach(QLegendMarker* marker, m_legend->d_ptr-> |
|
362 | foreach(QLegendMarker* marker, m_legend->d_ptr->markers()) { | |
363 | LegendMarkerItem *item = marker->d_ptr->item(); |
|
363 | LegendMarkerItem *item = marker->d_ptr->item(); | |
364 | size = size.expandedTo(item->effectiveSizeHint(which)); |
|
364 | size = size.expandedTo(item->effectiveSizeHint(which)); | |
365 | } |
|
365 | } | |
366 | size = size.boundedTo(constraint); |
|
366 | size = size.boundedTo(constraint); | |
367 | } |
|
367 | } | |
368 | else if (constraint.width() >= 0) { |
|
368 | else if (constraint.width() >= 0) { | |
369 | qreal width = 0; |
|
369 | qreal width = 0; | |
370 | qreal height = 0; |
|
370 | qreal height = 0; | |
371 |
foreach(QLegendMarker* marker, m_legend->d_ptr-> |
|
371 | foreach(QLegendMarker* marker, m_legend->d_ptr->markers()) { | |
372 | LegendMarkerItem *item = marker->d_ptr->item(); |
|
372 | LegendMarkerItem *item = marker->d_ptr->item(); | |
373 | width+=item->effectiveSizeHint(which).width(); |
|
373 | width+=item->effectiveSizeHint(which).width(); | |
374 | height=qMax(height,item->effectiveSizeHint(which).height()); |
|
374 | height=qMax(height,item->effectiveSizeHint(which).height()); | |
375 | } |
|
375 | } | |
376 |
|
376 | |||
377 | size = QSizeF(qMin(constraint.width(),width), height); |
|
377 | size = QSizeF(qMin(constraint.width(),width), height); | |
378 | } |
|
378 | } | |
379 | else if (constraint.height() >= 0) { |
|
379 | else if (constraint.height() >= 0) { | |
380 | qreal width = 0; |
|
380 | qreal width = 0; | |
381 | qreal height = 0; |
|
381 | qreal height = 0; | |
382 |
foreach(QLegendMarker* marker, m_legend->d_ptr-> |
|
382 | foreach(QLegendMarker* marker, m_legend->d_ptr->markers()) { | |
383 | LegendMarkerItem *item = marker->d_ptr->item(); |
|
383 | LegendMarkerItem *item = marker->d_ptr->item(); | |
384 | width=qMax(width,item->effectiveSizeHint(which).width()); |
|
384 | width=qMax(width,item->effectiveSizeHint(which).width()); | |
385 | height+=height,item->effectiveSizeHint(which).height(); |
|
385 | height+=height,item->effectiveSizeHint(which).height(); | |
386 | } |
|
386 | } | |
387 | size = QSizeF(width,qMin(constraint.height(),height)); |
|
387 | size = QSizeF(width,qMin(constraint.height(),height)); | |
388 | } |
|
388 | } | |
389 | else { |
|
389 | else { | |
390 |
foreach(QLegendMarker* marker, m_legend->d_ptr-> |
|
390 | foreach(QLegendMarker* marker, m_legend->d_ptr->markers()) { | |
391 | LegendMarkerItem *item = marker->d_ptr->item(); |
|
391 | LegendMarkerItem *item = marker->d_ptr->item(); | |
392 | size = size.expandedTo(item->effectiveSizeHint(which)); |
|
392 | size = size.expandedTo(item->effectiveSizeHint(which)); | |
393 | } |
|
393 | } | |
394 | } |
|
394 | } | |
395 | size += QSize(left + right, top + bottom); |
|
395 | size += QSize(left + right, top + bottom); | |
396 | return size; |
|
396 | return size; | |
397 | } |
|
397 | } | |
398 |
|
398 | |||
399 | QTCOMMERCIALCHART_END_NAMESPACE |
|
399 | QTCOMMERCIALCHART_END_NAMESPACE |
@@ -1,89 +1,87 | |||||
1 | /**************************************************************************** |
|
1 | /**************************************************************************** | |
2 | ** |
|
2 | ** | |
3 | ** Copyright (C) 2012 Digia Plc |
|
3 | ** Copyright (C) 2012 Digia Plc | |
4 | ** All rights reserved. |
|
4 | ** All rights reserved. | |
5 | ** For any questions to Digia, please use contact form at http://qt.digia.com |
|
5 | ** For any questions to Digia, please use contact form at http://qt.digia.com | |
6 | ** |
|
6 | ** | |
7 | ** This file is part of the Qt Commercial Charts Add-on. |
|
7 | ** This file is part of the Qt Commercial Charts Add-on. | |
8 | ** |
|
8 | ** | |
9 | ** $QT_BEGIN_LICENSE$ |
|
9 | ** $QT_BEGIN_LICENSE$ | |
10 | ** Licensees holding valid Qt Commercial licenses may use this file in |
|
10 | ** Licensees holding valid Qt Commercial licenses may use this file in | |
11 | ** accordance with the Qt Commercial License Agreement provided with the |
|
11 | ** accordance with the Qt Commercial License Agreement provided with the | |
12 | ** Software or, alternatively, in accordance with the terms contained in |
|
12 | ** Software or, alternatively, in accordance with the terms contained in | |
13 | ** a written agreement between you and Digia. |
|
13 | ** a written agreement between you and Digia. | |
14 | ** |
|
14 | ** | |
15 | ** If you have questions regarding the use of this file, please use |
|
15 | ** If you have questions regarding the use of this file, please use | |
16 | ** contact form at http://qt.digia.com |
|
16 | ** contact form at http://qt.digia.com | |
17 | ** $QT_END_LICENSE$ |
|
17 | ** $QT_END_LICENSE$ | |
18 | ** |
|
18 | ** | |
19 | ****************************************************************************/ |
|
19 | ****************************************************************************/ | |
20 |
|
20 | |||
21 | #include "qarealegendmarker.h" |
|
21 | #include "qarealegendmarker.h" | |
22 | #include "qarealegendmarker_p.h" |
|
22 | #include "qarealegendmarker_p.h" | |
23 | #include "qareaseries_p.h" |
|
23 | #include "qareaseries_p.h" | |
24 | #include <QAreaSeries> |
|
24 | #include <QAreaSeries> | |
25 | #include <QDebug> |
|
25 | #include <QDebug> | |
26 |
|
26 | |||
27 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
27 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
28 |
|
28 | |||
29 | QAreaLegendMarker::QAreaLegendMarker(QAreaSeries* series, QLegend *legend, QObject *parent) : |
|
29 | QAreaLegendMarker::QAreaLegendMarker(QAreaSeries* series, QLegend *legend, QObject *parent) : | |
30 | QLegendMarker(*new QAreaLegendMarkerPrivate(this,series,legend), parent) |
|
30 | QLegendMarker(*new QAreaLegendMarkerPrivate(this,series,legend), parent) | |
31 | { |
|
31 | { | |
32 | } |
|
32 | } | |
33 |
|
33 | |||
34 | QAreaLegendMarker::~QAreaLegendMarker() |
|
34 | QAreaLegendMarker::~QAreaLegendMarker() | |
35 | { |
|
35 | { | |
36 | // qDebug() << "deleting Area marker" << this; |
|
36 | // qDebug() << "deleting Area marker" << this; | |
37 | } |
|
37 | } | |
38 |
|
38 | |||
39 | /*! |
|
39 | /*! | |
40 | \internal |
|
40 | \internal | |
41 | */ |
|
41 | */ | |
42 | QAreaLegendMarker::QAreaLegendMarker(QAreaLegendMarkerPrivate &d, QObject *parent) : |
|
42 | QAreaLegendMarker::QAreaLegendMarker(QAreaLegendMarkerPrivate &d, QObject *parent) : | |
43 | QLegendMarker(d, parent) |
|
43 | QLegendMarker(d, parent) | |
44 | { |
|
44 | { | |
45 | } |
|
45 | } | |
46 |
|
46 | |||
47 | QAreaSeries* QAreaLegendMarker::series() |
|
47 | QAreaSeries* QAreaLegendMarker::series() | |
48 | { |
|
48 | { | |
49 | Q_D(QAreaLegendMarker); |
|
49 | Q_D(QAreaLegendMarker); | |
50 | return d->m_series; |
|
50 | return d->m_series; | |
51 | } |
|
51 | } | |
52 |
|
52 | |||
53 | //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
|
53 | //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// | |
54 |
|
54 | |||
55 | QAreaLegendMarkerPrivate::QAreaLegendMarkerPrivate(QAreaLegendMarker *q, QAreaSeries *series, QLegend *legend) : |
|
55 | QAreaLegendMarkerPrivate::QAreaLegendMarkerPrivate(QAreaLegendMarker *q, QAreaSeries *series, QLegend *legend) : | |
56 | QLegendMarkerPrivate(q,legend), |
|
56 | QLegendMarkerPrivate(q,legend), | |
57 | m_series(series) |
|
57 | m_series(series) | |
58 | { |
|
58 | { | |
59 | QObject::connect(m_series->d_func(),SIGNAL(updated()), this, SLOT(updated())); |
|
59 | QObject::connect(m_series->d_func(),SIGNAL(updated()), this, SLOT(updated())); | |
60 | QObject::connect(m_series, SIGNAL(nameChanged()), this, SLOT(updated())); |
|
60 | QObject::connect(m_series, SIGNAL(nameChanged()), this, SLOT(updated())); | |
61 | updated(); |
|
61 | updated(); | |
62 | } |
|
62 | } | |
63 |
|
63 | |||
64 | QAreaLegendMarkerPrivate::~QAreaLegendMarkerPrivate() |
|
64 | QAreaLegendMarkerPrivate::~QAreaLegendMarkerPrivate() | |
65 | { |
|
65 | { | |
66 | QObject::disconnect(m_series->d_func(),SIGNAL(updated()), this, SLOT(updated())); |
|
|||
67 | QObject::disconnect(m_series, SIGNAL(nameChanged()), this, SLOT(updated())); |
|
|||
68 | } |
|
66 | } | |
69 |
|
67 | |||
70 | QAreaSeries* QAreaLegendMarkerPrivate::series() |
|
68 | QAreaSeries* QAreaLegendMarkerPrivate::series() | |
71 | { |
|
69 | { | |
72 | return m_series; |
|
70 | return m_series; | |
73 | } |
|
71 | } | |
74 |
|
72 | |||
75 | QObject* QAreaLegendMarkerPrivate::relatedObject() |
|
73 | QObject* QAreaLegendMarkerPrivate::relatedObject() | |
76 | { |
|
74 | { | |
77 | return m_series; |
|
75 | return m_series; | |
78 | } |
|
76 | } | |
79 |
|
77 | |||
80 | void QAreaLegendMarkerPrivate::updated() |
|
78 | void QAreaLegendMarkerPrivate::updated() | |
81 | { |
|
79 | { | |
82 | m_item->setBrush(m_series->brush()); |
|
80 | m_item->setBrush(m_series->brush()); | |
83 | m_item->setLabel(m_series->name()); |
|
81 | m_item->setLabel(m_series->name()); | |
84 | } |
|
82 | } | |
85 |
|
83 | |||
86 | #include "moc_qarealegendmarker.cpp" |
|
84 | #include "moc_qarealegendmarker.cpp" | |
87 | #include "moc_qarealegendmarker_p.cpp" |
|
85 | #include "moc_qarealegendmarker_p.cpp" | |
88 |
|
86 | |||
89 | QTCOMMERCIALCHART_END_NAMESPACE |
|
87 | QTCOMMERCIALCHART_END_NAMESPACE |
@@ -1,100 +1,97 | |||||
1 | /**************************************************************************** |
|
1 | /**************************************************************************** | |
2 | ** |
|
2 | ** | |
3 | ** Copyright (C) 2012 Digia Plc |
|
3 | ** Copyright (C) 2012 Digia Plc | |
4 | ** All rights reserved. |
|
4 | ** All rights reserved. | |
5 | ** For any questions to Digia, please use contact form at http://qt.digia.com |
|
5 | ** For any questions to Digia, please use contact form at http://qt.digia.com | |
6 | ** |
|
6 | ** | |
7 | ** This file is part of the Qt Commercial Charts Add-on. |
|
7 | ** This file is part of the Qt Commercial Charts Add-on. | |
8 | ** |
|
8 | ** | |
9 | ** $QT_BEGIN_LICENSE$ |
|
9 | ** $QT_BEGIN_LICENSE$ | |
10 | ** Licensees holding valid Qt Commercial licenses may use this file in |
|
10 | ** Licensees holding valid Qt Commercial licenses may use this file in | |
11 | ** accordance with the Qt Commercial License Agreement provided with the |
|
11 | ** accordance with the Qt Commercial License Agreement provided with the | |
12 | ** Software or, alternatively, in accordance with the terms contained in |
|
12 | ** Software or, alternatively, in accordance with the terms contained in | |
13 | ** a written agreement between you and Digia. |
|
13 | ** a written agreement between you and Digia. | |
14 | ** |
|
14 | ** | |
15 | ** If you have questions regarding the use of this file, please use |
|
15 | ** If you have questions regarding the use of this file, please use | |
16 | ** contact form at http://qt.digia.com |
|
16 | ** contact form at http://qt.digia.com | |
17 | ** $QT_END_LICENSE$ |
|
17 | ** $QT_END_LICENSE$ | |
18 | ** |
|
18 | ** | |
19 | ****************************************************************************/ |
|
19 | ****************************************************************************/ | |
20 |
|
20 | |||
21 | #include "qbarlegendmarker.h" |
|
21 | #include "qbarlegendmarker.h" | |
22 | #include "qbarlegendmarker_p.h" |
|
22 | #include "qbarlegendmarker_p.h" | |
23 | #include <QAbstractBarSeries> |
|
23 | #include <QAbstractBarSeries> | |
24 | #include <QBarSet> |
|
24 | #include <QBarSet> | |
25 | #include <QDebug> |
|
25 | #include <QDebug> | |
26 |
|
26 | |||
27 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
27 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
28 |
|
28 | |||
29 | QBarLegendMarker::QBarLegendMarker(QAbstractBarSeries* series, QBarSet* barset, QLegend *legend, QObject *parent) : |
|
29 | QBarLegendMarker::QBarLegendMarker(QAbstractBarSeries* series, QBarSet* barset, QLegend *legend, QObject *parent) : | |
30 | QLegendMarker(*new QBarLegendMarkerPrivate(this,series,barset,legend), parent) |
|
30 | QLegendMarker(*new QBarLegendMarkerPrivate(this,series,barset,legend), parent) | |
31 | { |
|
31 | { | |
32 | } |
|
32 | } | |
33 |
|
33 | |||
34 | QBarLegendMarker::~QBarLegendMarker() |
|
34 | QBarLegendMarker::~QBarLegendMarker() | |
35 | { |
|
35 | { | |
36 | // qDebug() << "deleting bar marker" << this; |
|
36 | // qDebug() << "deleting bar marker" << this; | |
37 | } |
|
37 | } | |
38 |
|
38 | |||
39 | /*! |
|
39 | /*! | |
40 | \internal |
|
40 | \internal | |
41 | */ |
|
41 | */ | |
42 | QBarLegendMarker::QBarLegendMarker(QBarLegendMarkerPrivate &d, QObject *parent) : |
|
42 | QBarLegendMarker::QBarLegendMarker(QBarLegendMarkerPrivate &d, QObject *parent) : | |
43 | QLegendMarker(d, parent) |
|
43 | QLegendMarker(d, parent) | |
44 | { |
|
44 | { | |
45 | } |
|
45 | } | |
46 |
|
46 | |||
47 | QAbstractBarSeries *QBarLegendMarker::series() |
|
47 | QAbstractBarSeries *QBarLegendMarker::series() | |
48 | { |
|
48 | { | |
49 | Q_D(QBarLegendMarker); |
|
49 | Q_D(QBarLegendMarker); | |
50 | return d->m_series; |
|
50 | return d->m_series; | |
51 | } |
|
51 | } | |
52 |
|
52 | |||
53 | QBarSet* QBarLegendMarker::barset() |
|
53 | QBarSet* QBarLegendMarker::barset() | |
54 | { |
|
54 | { | |
55 | Q_D(QBarLegendMarker); |
|
55 | Q_D(QBarLegendMarker); | |
56 | return d->m_barset; |
|
56 | return d->m_barset; | |
57 | } |
|
57 | } | |
58 |
|
58 | |||
59 | //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
|
59 | //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// | |
60 |
|
60 | |||
61 | QBarLegendMarkerPrivate::QBarLegendMarkerPrivate(QBarLegendMarker *q, QAbstractBarSeries *series, QBarSet *barset, QLegend *legend) : |
|
61 | QBarLegendMarkerPrivate::QBarLegendMarkerPrivate(QBarLegendMarker *q, QAbstractBarSeries *series, QBarSet *barset, QLegend *legend) : | |
62 | QLegendMarkerPrivate(q,legend), |
|
62 | QLegendMarkerPrivate(q,legend), | |
63 | m_series(series), |
|
63 | m_series(series), | |
64 | m_barset(barset) |
|
64 | m_barset(barset) | |
65 | { |
|
65 | { | |
66 | QObject::connect(m_barset, SIGNAL(penChanged()), this, SLOT(updated())); |
|
66 | QObject::connect(m_barset, SIGNAL(penChanged()), this, SLOT(updated())); | |
67 | QObject::connect(m_barset, SIGNAL(labelChanged()), this, SLOT(updated())); |
|
67 | QObject::connect(m_barset, SIGNAL(labelChanged()), this, SLOT(updated())); | |
68 | QObject::connect(m_barset, SIGNAL(brushChanged()), this, SLOT(updated())); |
|
68 | QObject::connect(m_barset, SIGNAL(brushChanged()), this, SLOT(updated())); | |
69 | updated(); |
|
69 | updated(); | |
70 | } |
|
70 | } | |
71 |
|
71 | |||
72 | QBarLegendMarkerPrivate::~QBarLegendMarkerPrivate() |
|
72 | QBarLegendMarkerPrivate::~QBarLegendMarkerPrivate() | |
73 | { |
|
73 | { | |
74 | QObject::disconnect(m_barset, SIGNAL(labelChanged()), this, SLOT(updated())); |
|
|||
75 | QObject::disconnect(m_barset, SIGNAL(brushChanged()), this, SLOT(updated())); |
|
|||
76 | QObject::disconnect(m_barset, SIGNAL(penChanged()), this, SLOT(updated())); |
|
|||
77 | } |
|
74 | } | |
78 |
|
75 | |||
79 | QAbstractBarSeries* QBarLegendMarkerPrivate::series() |
|
76 | QAbstractBarSeries* QBarLegendMarkerPrivate::series() | |
80 | { |
|
77 | { | |
81 | return m_series; |
|
78 | return m_series; | |
82 | } |
|
79 | } | |
83 |
|
80 | |||
84 | QObject* QBarLegendMarkerPrivate::relatedObject() |
|
81 | QObject* QBarLegendMarkerPrivate::relatedObject() | |
85 | { |
|
82 | { | |
86 | return m_barset; |
|
83 | return m_barset; | |
87 | } |
|
84 | } | |
88 |
|
85 | |||
89 | void QBarLegendMarkerPrivate::updated() |
|
86 | void QBarLegendMarkerPrivate::updated() | |
90 | { |
|
87 | { | |
91 | m_item->setPen(m_barset->pen()); |
|
88 | m_item->setPen(m_barset->pen()); | |
92 | m_item->setBrush(m_barset->brush()); |
|
89 | m_item->setBrush(m_barset->brush()); | |
93 | m_item->setLabel(m_barset->label()); |
|
90 | m_item->setLabel(m_barset->label()); | |
94 | } |
|
91 | } | |
95 |
|
92 | |||
96 | #include "moc_qbarlegendmarker.cpp" |
|
93 | #include "moc_qbarlegendmarker.cpp" | |
97 | #include "moc_qbarlegendmarker_p.cpp" |
|
94 | #include "moc_qbarlegendmarker_p.cpp" | |
98 |
|
95 | |||
99 | QTCOMMERCIALCHART_END_NAMESPACE |
|
96 | QTCOMMERCIALCHART_END_NAMESPACE | |
100 |
|
97 |
@@ -1,70 +1,70 | |||||
1 | /**************************************************************************** |
|
1 | /**************************************************************************** | |
2 | ** |
|
2 | ** | |
3 | ** Copyright (C) 2012 Digia Plc |
|
3 | ** Copyright (C) 2012 Digia Plc | |
4 | ** All rights reserved. |
|
4 | ** All rights reserved. | |
5 | ** For any questions to Digia, please use contact form at http://qt.digia.com |
|
5 | ** For any questions to Digia, please use contact form at http://qt.digia.com | |
6 | ** |
|
6 | ** | |
7 | ** This file is part of the Qt Commercial Charts Add-on. |
|
7 | ** This file is part of the Qt Commercial Charts Add-on. | |
8 | ** |
|
8 | ** | |
9 | ** $QT_BEGIN_LICENSE$ |
|
9 | ** $QT_BEGIN_LICENSE$ | |
10 | ** Licensees holding valid Qt Commercial licenses may use this file in |
|
10 | ** Licensees holding valid Qt Commercial licenses may use this file in | |
11 | ** accordance with the Qt Commercial License Agreement provided with the |
|
11 | ** accordance with the Qt Commercial License Agreement provided with the | |
12 | ** Software or, alternatively, in accordance with the terms contained in |
|
12 | ** Software or, alternatively, in accordance with the terms contained in | |
13 | ** a written agreement between you and Digia. |
|
13 | ** a written agreement between you and Digia. | |
14 | ** |
|
14 | ** | |
15 | ** If you have questions regarding the use of this file, please use |
|
15 | ** If you have questions regarding the use of this file, please use | |
16 | ** contact form at http://qt.digia.com |
|
16 | ** contact form at http://qt.digia.com | |
17 | ** $QT_END_LICENSE$ |
|
17 | ** $QT_END_LICENSE$ | |
18 | ** |
|
18 | ** | |
19 | ****************************************************************************/ |
|
19 | ****************************************************************************/ | |
20 |
|
20 | |||
21 | // W A R N I N G |
|
21 | // W A R N I N G | |
22 | // ------------- |
|
22 | // ------------- | |
23 | // |
|
23 | // | |
24 | // This file is not part of the QtCommercial Chart API. It exists purely as an |
|
24 | // This file is not part of the QtCommercial Chart API. It exists purely as an | |
25 | // implementation detail. This header file may change from version to |
|
25 | // implementation detail. This header file may change from version to | |
26 | // version without notice, or even be removed. |
|
26 | // version without notice, or even be removed. | |
27 | // |
|
27 | // | |
28 | // We mean it. |
|
28 | // We mean it. | |
29 |
|
29 | |||
30 | #ifndef QBARLEGENDMARKER_P_H |
|
30 | #ifndef QBARLEGENDMARKER_P_H | |
31 | #define QBARLEGENDMARKER_P_H |
|
31 | #define QBARLEGENDMARKER_P_H | |
32 |
|
32 | |||
33 | #include "qchartglobal.h" |
|
33 | #include "qchartglobal.h" | |
34 | #include "qlegendmarker_p.h" |
|
34 | #include "qlegendmarker_p.h" | |
35 | #include "legendmarkeritem_p.h" |
|
35 | #include "legendmarkeritem_p.h" | |
36 | #include <QAbstractBarSeries> |
|
36 | #include <QAbstractBarSeries> | |
37 | #include <QBarSet> |
|
37 | #include <QBarSet> | |
38 |
|
38 | |||
39 | #include <QDebug> |
|
39 | #include <QDebug> | |
40 |
|
40 | |||
41 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
41 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
42 |
|
42 | |||
43 | class QBarLegendMarker; |
|
43 | class QBarLegendMarker; | |
44 |
|
44 | |||
45 | class QBarLegendMarkerPrivate : public QLegendMarkerPrivate |
|
45 | class QBarLegendMarkerPrivate : public QLegendMarkerPrivate | |
46 | { |
|
46 | { | |
47 | Q_OBJECT |
|
47 | Q_OBJECT | |
48 | public: |
|
48 | public: | |
49 | explicit QBarLegendMarkerPrivate(QBarLegendMarker *q, QAbstractBarSeries *series, QBarSet *barset, QLegend *legend); |
|
49 | explicit QBarLegendMarkerPrivate(QBarLegendMarker *q, QAbstractBarSeries *series, QBarSet *barset, QLegend *legend); | |
50 | virtual ~QBarLegendMarkerPrivate(); |
|
50 | virtual ~QBarLegendMarkerPrivate(); | |
51 |
|
51 | |||
52 | virtual QAbstractBarSeries* series(); |
|
52 | virtual QAbstractBarSeries* series(); | |
53 | virtual QObject* relatedObject(); |
|
53 | virtual QObject* relatedObject(); | |
54 |
|
54 | |||
55 | public Q_SLOTS: |
|
55 | public Q_SLOTS: | |
56 | virtual void updated(); |
|
56 | virtual void updated(); | |
57 |
|
57 | |||
58 | private: |
|
58 | private: | |
59 | QBarLegendMarker *q_ptr; |
|
59 | QBarLegendMarker *q_ptr; | |
60 |
|
60 | |||
61 | QAbstractBarSeries* m_series; |
|
61 | QAbstractBarSeries* m_series; | |
62 | QBarSet* m_barset; |
|
62 | QBarSet* m_barset; | |
63 |
|
63 | |||
64 |
friend class QLegendPrivate; |
|
64 | friend class QLegendPrivate; | |
65 | Q_DECLARE_PUBLIC(QBarLegendMarker) |
|
65 | Q_DECLARE_PUBLIC(QBarLegendMarker) | |
66 | }; |
|
66 | }; | |
67 |
|
67 | |||
68 | QTCOMMERCIALCHART_END_NAMESPACE |
|
68 | QTCOMMERCIALCHART_END_NAMESPACE | |
69 |
|
69 | |||
70 | #endif // QBARLEGENDMARKER_P_H |
|
70 | #endif // QBARLEGENDMARKER_P_H |
@@ -1,671 +1,669 | |||||
1 | /**************************************************************************** |
|
1 | /**************************************************************************** | |
2 | ** |
|
2 | ** | |
3 | ** Copyright (C) 2012 Digia Plc |
|
3 | ** Copyright (C) 2012 Digia Plc | |
4 | ** All rights reserved. |
|
4 | ** All rights reserved. | |
5 | ** For any questions to Digia, please use contact form at http://qt.digia.com |
|
5 | ** For any questions to Digia, please use contact form at http://qt.digia.com | |
6 | ** |
|
6 | ** | |
7 | ** This file is part of the Qt Commercial Charts Add-on. |
|
7 | ** This file is part of the Qt Commercial Charts Add-on. | |
8 | ** |
|
8 | ** | |
9 | ** $QT_BEGIN_LICENSE$ |
|
9 | ** $QT_BEGIN_LICENSE$ | |
10 | ** Licensees holding valid Qt Commercial licenses may use this file in |
|
10 | ** Licensees holding valid Qt Commercial licenses may use this file in | |
11 | ** accordance with the Qt Commercial License Agreement provided with the |
|
11 | ** accordance with the Qt Commercial License Agreement provided with the | |
12 | ** Software or, alternatively, in accordance with the terms contained in |
|
12 | ** Software or, alternatively, in accordance with the terms contained in | |
13 | ** a written agreement between you and Digia. |
|
13 | ** a written agreement between you and Digia. | |
14 | ** |
|
14 | ** | |
15 | ** If you have questions regarding the use of this file, please use |
|
15 | ** If you have questions regarding the use of this file, please use | |
16 | ** contact form at http://qt.digia.com |
|
16 | ** contact form at http://qt.digia.com | |
17 | ** $QT_END_LICENSE$ |
|
17 | ** $QT_END_LICENSE$ | |
18 | ** |
|
18 | ** | |
19 | ****************************************************************************/ |
|
19 | ****************************************************************************/ | |
20 |
|
20 | |||
21 | #include "qlegend.h" |
|
21 | #include "qlegend.h" | |
22 | #include "qlegend_p.h" |
|
22 | #include "qlegend_p.h" | |
23 | #include "qabstractseries.h" |
|
23 | #include "qabstractseries.h" | |
24 | #include "qabstractseries_p.h" |
|
24 | #include "qabstractseries_p.h" | |
25 | #include "qchart_p.h" |
|
25 | #include "qchart_p.h" | |
26 | #include "legendlayout_p.h" |
|
26 | #include "legendlayout_p.h" | |
27 | #include "qxyseries.h" |
|
27 | #include "qxyseries.h" | |
28 | #include "qlineseries.h" |
|
28 | #include "qlineseries.h" | |
29 | #include "qareaseries.h" |
|
29 | #include "qareaseries.h" | |
30 | #include "qscatterseries.h" |
|
30 | #include "qscatterseries.h" | |
31 | #include "qsplineseries.h" |
|
31 | #include "qsplineseries.h" | |
32 | #include "qabstractbarseries.h" |
|
32 | #include "qabstractbarseries.h" | |
33 | #include "qstackedbarseries.h" |
|
33 | #include "qstackedbarseries.h" | |
34 | #include "qpercentbarseries.h" |
|
34 | #include "qpercentbarseries.h" | |
35 | #include "qbarset.h" |
|
35 | #include "qbarset.h" | |
36 | #include "qpieseries.h" |
|
36 | #include "qpieseries.h" | |
37 | #include "qpieseries_p.h" |
|
37 | #include "qpieseries_p.h" | |
38 | #include "qpieslice.h" |
|
38 | #include "qpieslice.h" | |
39 | #include "chartpresenter_p.h" |
|
39 | #include "chartpresenter_p.h" | |
40 | #include "chartlayout_p.h" |
|
40 | #include "chartlayout_p.h" | |
41 | #include <QPainter> |
|
41 | #include <QPainter> | |
42 | #include <QPen> |
|
42 | #include <QPen> | |
43 | #include <QTimer> |
|
43 | #include <QTimer> | |
44 | #include <QGraphicsSceneEvent> |
|
44 | #include <QGraphicsSceneEvent> | |
45 | #include <QGraphicsItemGroup> |
|
45 | #include <QGraphicsItemGroup> | |
46 |
|
46 | |||
47 | #include "qlegendmarker.h" |
|
47 | #include "qlegendmarker.h" | |
48 | #include "qlegendmarker_p.h" |
|
48 | #include "qlegendmarker_p.h" | |
49 | #include "legendmarkeritem_p.h" |
|
49 | #include "legendmarkeritem_p.h" | |
50 |
|
50 | |||
51 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
51 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
52 |
|
52 | |||
53 | /*! |
|
53 | /*! | |
54 | \class QLegend |
|
54 | \class QLegend | |
55 | \brief Legend object |
|
55 | \brief Legend object | |
56 | \mainclass |
|
56 | \mainclass | |
57 |
|
57 | |||
58 | QLegend is a graphical object, whics displays legend of the chart. Legend state is updated by QChart, when |
|
58 | QLegend is a graphical object, whics displays legend of the chart. Legend state is updated by QChart, when | |
59 | series have been changed. By default, legend is drawn by QChart, but user can set a new parent to legend and |
|
59 | series have been changed. By default, legend is drawn by QChart, but user can set a new parent to legend and | |
60 | handle the drawing manually. |
|
60 | handle the drawing manually. | |
61 | User isn't supposed to create or delete legend objects, but can reference it via QChart class. |
|
61 | User isn't supposed to create or delete legend objects, but can reference it via QChart class. | |
62 |
|
62 | |||
63 | \image examples_percentbarchart_legend.png |
|
63 | \image examples_percentbarchart_legend.png | |
64 |
|
64 | |||
65 | \sa QChart |
|
65 | \sa QChart | |
66 | */ |
|
66 | */ | |
67 | /*! |
|
67 | /*! | |
68 | \qmlclass Legend QLegend |
|
68 | \qmlclass Legend QLegend | |
69 | \brief Legend is part of QtCommercial Chart QML API. |
|
69 | \brief Legend is part of QtCommercial Chart QML API. | |
70 |
|
70 | |||
71 | Legend is a graphical object, whics displays legend of the chart. Legend state is updated by ChartView, when |
|
71 | Legend is a graphical object, whics displays legend of the chart. Legend state is updated by ChartView, when | |
72 | series have been changed. Legend is used via ChartView class. For example: |
|
72 | series have been changed. Legend is used via ChartView class. For example: | |
73 | \code |
|
73 | \code | |
74 | ChartView { |
|
74 | ChartView { | |
75 | legend.visible: true |
|
75 | legend.visible: true | |
76 | legend.alignment: Qt.AlignBottom |
|
76 | legend.alignment: Qt.AlignBottom | |
77 | // Add a few series... |
|
77 | // Add a few series... | |
78 | } |
|
78 | } | |
79 | \endcode |
|
79 | \endcode | |
80 |
|
80 | |||
81 | \image examples_percentbarchart_legend.png |
|
81 | \image examples_percentbarchart_legend.png | |
82 | */ |
|
82 | */ | |
83 |
|
83 | |||
84 | /*! |
|
84 | /*! | |
85 | \property QLegend::alignment |
|
85 | \property QLegend::alignment | |
86 | \brief The alignment of the legend. |
|
86 | \brief The alignment of the legend. | |
87 |
|
87 | |||
88 | Legend paints on the defined position in the chart. The following alignments are supported: |
|
88 | Legend paints on the defined position in the chart. The following alignments are supported: | |
89 | Qt::AlignTop, Qt::AlignBottom, Qt::AlignLeft, Qt::AlignRight. If you set more than one flag the result is undefined. |
|
89 | Qt::AlignTop, Qt::AlignBottom, Qt::AlignLeft, Qt::AlignRight. If you set more than one flag the result is undefined. | |
90 | */ |
|
90 | */ | |
91 | /*! |
|
91 | /*! | |
92 | \qmlproperty Qt.Alignment Legend::alignment |
|
92 | \qmlproperty Qt.Alignment Legend::alignment | |
93 | \brief The alignment of the legend. |
|
93 | \brief The alignment of the legend. | |
94 |
|
94 | |||
95 | Legend paints on the defined position in the chart. The following alignments are supported: |
|
95 | Legend paints on the defined position in the chart. The following alignments are supported: | |
96 | Qt.AlignTop, Qt.AlignBottom, Qt.AlignLeft, Qt.AlignRight. If you set more than one flag the result is undefined. |
|
96 | Qt.AlignTop, Qt.AlignBottom, Qt.AlignLeft, Qt.AlignRight. If you set more than one flag the result is undefined. | |
97 | */ |
|
97 | */ | |
98 |
|
98 | |||
99 | /*! |
|
99 | /*! | |
100 | \property QLegend::backgroundVisible |
|
100 | \property QLegend::backgroundVisible | |
101 | Whether the legend background is visible or not. |
|
101 | Whether the legend background is visible or not. | |
102 | */ |
|
102 | */ | |
103 | /*! |
|
103 | /*! | |
104 | \qmlproperty bool Legend::backgroundVisible |
|
104 | \qmlproperty bool Legend::backgroundVisible | |
105 | Whether the legend background is visible or not. |
|
105 | Whether the legend background is visible or not. | |
106 | */ |
|
106 | */ | |
107 |
|
107 | |||
108 | /*! |
|
108 | /*! | |
109 | \property QLegend::color |
|
109 | \property QLegend::color | |
110 | The color of the legend, i.e. the background (brush) color. Note that if you change the color |
|
110 | The color of the legend, i.e. the background (brush) color. Note that if you change the color | |
111 | of the legend, the style of the legend brush is set to Qt::SolidPattern. |
|
111 | of the legend, the style of the legend brush is set to Qt::SolidPattern. | |
112 | */ |
|
112 | */ | |
113 | /*! |
|
113 | /*! | |
114 | \qmlproperty color Legend::color |
|
114 | \qmlproperty color Legend::color | |
115 | The color of the legend, i.e. the background (brush) color. |
|
115 | The color of the legend, i.e. the background (brush) color. | |
116 | */ |
|
116 | */ | |
117 |
|
117 | |||
118 | /*! |
|
118 | /*! | |
119 | \property QLegend::borderColor |
|
119 | \property QLegend::borderColor | |
120 | The border color of the legend, i.e. the line color. |
|
120 | The border color of the legend, i.e. the line color. | |
121 | */ |
|
121 | */ | |
122 | /*! |
|
122 | /*! | |
123 | \qmlproperty color Legend::borderColor |
|
123 | \qmlproperty color Legend::borderColor | |
124 | The border color of the legend, i.e. the line color. |
|
124 | The border color of the legend, i.e. the line color. | |
125 | */ |
|
125 | */ | |
126 |
|
126 | |||
127 | /*! |
|
127 | /*! | |
128 | \property QLegend::font |
|
128 | \property QLegend::font | |
129 | The font of markers used by legend |
|
129 | The font of markers used by legend | |
130 | */ |
|
130 | */ | |
131 | /*! |
|
131 | /*! | |
132 | \qmlproperty Font Legend::font |
|
132 | \qmlproperty Font Legend::font | |
133 | The font of markers used by legend |
|
133 | The font of markers used by legend | |
134 | */ |
|
134 | */ | |
135 |
|
135 | |||
136 | /*! |
|
136 | /*! | |
137 | \property QLegend::labelColor |
|
137 | \property QLegend::labelColor | |
138 | The color of brush used to draw labels. |
|
138 | The color of brush used to draw labels. | |
139 | */ |
|
139 | */ | |
140 | /*! |
|
140 | /*! | |
141 | \qmlproperty color QLegend::labelColor |
|
141 | \qmlproperty color QLegend::labelColor | |
142 | The color of brush used to draw labels. |
|
142 | The color of brush used to draw labels. | |
143 | */ |
|
143 | */ | |
144 |
|
144 | |||
145 | /*! |
|
145 | /*! | |
146 | \fn void QLegend::backgroundVisibleChanged(bool) |
|
146 | \fn void QLegend::backgroundVisibleChanged(bool) | |
147 | The visibility of the legend background changed to \a visible. |
|
147 | The visibility of the legend background changed to \a visible. | |
148 | */ |
|
148 | */ | |
149 |
|
149 | |||
150 | /*! |
|
150 | /*! | |
151 | \fn void QLegend::colorChanged(QColor) |
|
151 | \fn void QLegend::colorChanged(QColor) | |
152 | The color of the legend background changed to \a color. |
|
152 | The color of the legend background changed to \a color. | |
153 | */ |
|
153 | */ | |
154 |
|
154 | |||
155 | /*! |
|
155 | /*! | |
156 | \fn void QLegend::borderColorChanged(QColor) |
|
156 | \fn void QLegend::borderColorChanged(QColor) | |
157 | The border color of the legend background changed to \a color. |
|
157 | The border color of the legend background changed to \a color. | |
158 | */ |
|
158 | */ | |
159 |
|
159 | |||
160 | /*! |
|
160 | /*! | |
161 | \fn void QLegend::fontChanged(QFont) |
|
161 | \fn void QLegend::fontChanged(QFont) | |
162 | The font of markers of the legend changed to \a font. |
|
162 | The font of markers of the legend changed to \a font. | |
163 | */ |
|
163 | */ | |
164 |
|
164 | |||
165 | /*! |
|
165 | /*! | |
166 | \fn void QLegend::labelColorChanged(QColor color) |
|
166 | \fn void QLegend::labelColorChanged(QColor color) | |
167 | This signal is emitted when the color of brush used to draw labels has changed to \a color. |
|
167 | This signal is emitted when the color of brush used to draw labels has changed to \a color. | |
168 | */ |
|
168 | */ | |
169 |
|
169 | |||
170 | /*! |
|
170 | /*! | |
171 | Constructs the legend object and sets the parent to \a parent |
|
171 | Constructs the legend object and sets the parent to \a parent | |
172 | */ |
|
172 | */ | |
173 |
|
173 | |||
174 | QLegend::QLegend(QChart *chart): QGraphicsWidget(chart), |
|
174 | QLegend::QLegend(QChart *chart): QGraphicsWidget(chart), | |
175 | d_ptr(new QLegendPrivate(chart->d_ptr->m_presenter, chart, this)) |
|
175 | d_ptr(new QLegendPrivate(chart->d_ptr->m_presenter, chart, this)) | |
176 | { |
|
176 | { | |
177 | setZValue(ChartPresenter::LegendZValue); |
|
177 | setZValue(ChartPresenter::LegendZValue); | |
178 | setFlags(QGraphicsItem::ItemClipsChildrenToShape); |
|
178 | setFlags(QGraphicsItem::ItemClipsChildrenToShape); | |
179 | QObject::connect(chart->d_ptr->m_dataset, SIGNAL(seriesAdded(QAbstractSeries*,Domain*)), d_ptr.data(), SLOT(handleSeriesAdded(QAbstractSeries*))); |
|
179 | QObject::connect(chart->d_ptr->m_dataset, SIGNAL(seriesAdded(QAbstractSeries*,Domain*)), d_ptr.data(), SLOT(handleSeriesAdded(QAbstractSeries*))); | |
180 | QObject::connect(chart->d_ptr->m_dataset, SIGNAL(seriesRemoved(QAbstractSeries*)), d_ptr.data(), SLOT(handleSeriesRemoved(QAbstractSeries*))); |
|
180 | QObject::connect(chart->d_ptr->m_dataset, SIGNAL(seriesRemoved(QAbstractSeries*)), d_ptr.data(), SLOT(handleSeriesRemoved(QAbstractSeries*))); | |
181 | // QObject::connect(chart->d_ptr->m_dataset,SIGNAL(seriesUpdated(QAbstractSeries*)),d_ptr.data(),SLOT(handleSeriesUpdated(QAbstractSeries*))); |
|
181 | // QObject::connect(chart->d_ptr->m_dataset,SIGNAL(seriesUpdated(QAbstractSeries*)),d_ptr.data(),SLOT(handleSeriesUpdated(QAbstractSeries*))); | |
182 | setLayout(d_ptr->m_layout); |
|
182 | setLayout(d_ptr->m_layout); | |
183 | } |
|
183 | } | |
184 |
|
184 | |||
185 | /*! |
|
185 | /*! | |
186 | Destroys the legend object. Legend is always owned by a QChart, so an application should never call this. |
|
186 | Destroys the legend object. Legend is always owned by a QChart, so an application should never call this. | |
187 | */ |
|
187 | */ | |
188 | QLegend::~QLegend() |
|
188 | QLegend::~QLegend() | |
189 | { |
|
189 | { | |
190 | } |
|
190 | } | |
191 |
|
191 | |||
192 | /*! |
|
192 | /*! | |
193 | \internal |
|
193 | \internal | |
194 | */ |
|
194 | */ | |
195 | void QLegend::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) |
|
195 | void QLegend::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) | |
196 | { |
|
196 | { | |
197 | Q_UNUSED(option) |
|
197 | Q_UNUSED(option) | |
198 | Q_UNUSED(widget) |
|
198 | Q_UNUSED(widget) | |
199 |
|
199 | |||
200 | if (!d_ptr->m_backgroundVisible) |
|
200 | if (!d_ptr->m_backgroundVisible) | |
201 | return; |
|
201 | return; | |
202 |
|
202 | |||
203 | painter->setOpacity(opacity()); |
|
203 | painter->setOpacity(opacity()); | |
204 | painter->setPen(d_ptr->m_pen); |
|
204 | painter->setPen(d_ptr->m_pen); | |
205 | painter->setBrush(d_ptr->m_brush); |
|
205 | painter->setBrush(d_ptr->m_brush); | |
206 | painter->drawRoundRect(rect(), d_ptr->roundness(rect().width()), d_ptr->roundness(rect().height())); |
|
206 | painter->drawRoundRect(rect(), d_ptr->roundness(rect().width()), d_ptr->roundness(rect().height())); | |
207 | } |
|
207 | } | |
208 |
|
208 | |||
209 |
|
209 | |||
210 | /*! |
|
210 | /*! | |
211 | Sets the \a brush of legend. Brush affects the background of legend. |
|
211 | Sets the \a brush of legend. Brush affects the background of legend. | |
212 | */ |
|
212 | */ | |
213 | void QLegend::setBrush(const QBrush &brush) |
|
213 | void QLegend::setBrush(const QBrush &brush) | |
214 | { |
|
214 | { | |
215 | if (d_ptr->m_brush != brush) { |
|
215 | if (d_ptr->m_brush != brush) { | |
216 | d_ptr->m_brush = brush; |
|
216 | d_ptr->m_brush = brush; | |
217 | update(); |
|
217 | update(); | |
218 | emit colorChanged(brush.color()); |
|
218 | emit colorChanged(brush.color()); | |
219 | } |
|
219 | } | |
220 | } |
|
220 | } | |
221 |
|
221 | |||
222 | /*! |
|
222 | /*! | |
223 | Returns the brush used by legend. |
|
223 | Returns the brush used by legend. | |
224 | */ |
|
224 | */ | |
225 | QBrush QLegend::brush() const |
|
225 | QBrush QLegend::brush() const | |
226 | { |
|
226 | { | |
227 | return d_ptr->m_brush; |
|
227 | return d_ptr->m_brush; | |
228 | } |
|
228 | } | |
229 |
|
229 | |||
230 | void QLegend::setColor(QColor color) |
|
230 | void QLegend::setColor(QColor color) | |
231 | { |
|
231 | { | |
232 | QBrush b = d_ptr->m_brush; |
|
232 | QBrush b = d_ptr->m_brush; | |
233 | if (b.style() != Qt::SolidPattern || b.color() != color) { |
|
233 | if (b.style() != Qt::SolidPattern || b.color() != color) { | |
234 | b.setStyle(Qt::SolidPattern); |
|
234 | b.setStyle(Qt::SolidPattern); | |
235 | b.setColor(color); |
|
235 | b.setColor(color); | |
236 | setBrush(b); |
|
236 | setBrush(b); | |
237 | } |
|
237 | } | |
238 | } |
|
238 | } | |
239 |
|
239 | |||
240 | QColor QLegend::color() |
|
240 | QColor QLegend::color() | |
241 | { |
|
241 | { | |
242 | return d_ptr->m_brush.color(); |
|
242 | return d_ptr->m_brush.color(); | |
243 | } |
|
243 | } | |
244 |
|
244 | |||
245 | /*! |
|
245 | /*! | |
246 | Sets the \a pen of legend. Pen affects the legend borders. |
|
246 | Sets the \a pen of legend. Pen affects the legend borders. | |
247 | */ |
|
247 | */ | |
248 | void QLegend::setPen(const QPen &pen) |
|
248 | void QLegend::setPen(const QPen &pen) | |
249 | { |
|
249 | { | |
250 | if (d_ptr->m_pen != pen) { |
|
250 | if (d_ptr->m_pen != pen) { | |
251 | d_ptr->m_pen = pen; |
|
251 | d_ptr->m_pen = pen; | |
252 | update(); |
|
252 | update(); | |
253 | emit borderColorChanged(pen.color()); |
|
253 | emit borderColorChanged(pen.color()); | |
254 | } |
|
254 | } | |
255 | } |
|
255 | } | |
256 |
|
256 | |||
257 | /*! |
|
257 | /*! | |
258 | Returns the pen used by legend |
|
258 | Returns the pen used by legend | |
259 | */ |
|
259 | */ | |
260 |
|
260 | |||
261 | QPen QLegend::pen() const |
|
261 | QPen QLegend::pen() const | |
262 | { |
|
262 | { | |
263 | return d_ptr->m_pen; |
|
263 | return d_ptr->m_pen; | |
264 | } |
|
264 | } | |
265 |
|
265 | |||
266 | void QLegend::setFont(const QFont &font) |
|
266 | void QLegend::setFont(const QFont &font) | |
267 | { |
|
267 | { | |
268 | if (d_ptr->m_font != font) |
|
268 | if (d_ptr->m_font != font) | |
269 | d_ptr->m_font = font; |
|
269 | d_ptr->m_font = font; | |
270 |
|
270 | |||
271 |
foreach (QLegendMarker *marker, d_ptr-> |
|
271 | foreach (QLegendMarker *marker, d_ptr->markers()) { | |
272 | marker->setFont(d_ptr->m_font); |
|
272 | marker->setFont(d_ptr->m_font); | |
273 | layout()->invalidate(); |
|
|||
274 | emit fontChanged(font); |
|
|||
275 | } |
|
273 | } | |
|
274 | layout()->invalidate(); | |||
|
275 | emit fontChanged(font); | |||
276 | } |
|
276 | } | |
277 |
|
277 | |||
278 | QFont QLegend::font() const |
|
278 | QFont QLegend::font() const | |
279 | { |
|
279 | { | |
280 | return d_ptr->m_font; |
|
280 | return d_ptr->m_font; | |
281 | } |
|
281 | } | |
282 |
|
282 | |||
283 | void QLegend::setBorderColor(QColor color) |
|
283 | void QLegend::setBorderColor(QColor color) | |
284 | { |
|
284 | { | |
285 | QPen p = d_ptr->m_pen; |
|
285 | QPen p = d_ptr->m_pen; | |
286 | if (p.color() != color) { |
|
286 | if (p.color() != color) { | |
287 | p.setColor(color); |
|
287 | p.setColor(color); | |
288 | setPen(p); |
|
288 | setPen(p); | |
289 | } |
|
289 | } | |
290 | } |
|
290 | } | |
291 |
|
291 | |||
292 | QColor QLegend::borderColor() |
|
292 | QColor QLegend::borderColor() | |
293 | { |
|
293 | { | |
294 | return d_ptr->m_pen.color(); |
|
294 | return d_ptr->m_pen.color(); | |
295 | } |
|
295 | } | |
296 |
|
296 | |||
297 | /*! |
|
297 | /*! | |
298 | Set brush used to draw labels to \a brush. |
|
298 | Set brush used to draw labels to \a brush. | |
299 | */ |
|
299 | */ | |
300 | void QLegend::setLabelBrush(const QBrush &brush) |
|
300 | void QLegend::setLabelBrush(const QBrush &brush) | |
301 | { |
|
301 | { | |
302 | if (d_ptr->m_labelBrush != brush) { |
|
302 | if (d_ptr->m_labelBrush != brush) { | |
303 | d_ptr->m_labelBrush = brush; |
|
303 | d_ptr->m_labelBrush = brush; | |
304 |
foreach (QLegendMarker *marker, d_ptr-> |
|
304 | foreach (QLegendMarker *marker, d_ptr->markers()) { | |
305 | marker->setLabelBrush(d_ptr->m_labelBrush); |
|
305 | marker->setLabelBrush(d_ptr->m_labelBrush); | |
306 | // Note: The pen of the marker rectangle could be exposed in the public QLegend API |
|
306 | // Note: The pen of the marker rectangle could be exposed in the public QLegend API | |
307 | // instead of mapping it from label brush color |
|
307 | // instead of mapping it from label brush color | |
308 | marker->setPen(brush.color()); |
|
308 | marker->setPen(brush.color()); | |
309 | } |
|
309 | } | |
310 | emit labelColorChanged(brush.color()); |
|
310 | emit labelColorChanged(brush.color()); | |
311 | } |
|
311 | } | |
312 | } |
|
312 | } | |
313 |
|
313 | |||
314 | /*! |
|
314 | /*! | |
315 | Brush used to draw labels. |
|
315 | Brush used to draw labels. | |
316 | */ |
|
316 | */ | |
317 | QBrush QLegend::labelBrush() const |
|
317 | QBrush QLegend::labelBrush() const | |
318 | { |
|
318 | { | |
319 | return d_ptr->m_labelBrush; |
|
319 | return d_ptr->m_labelBrush; | |
320 | } |
|
320 | } | |
321 |
|
321 | |||
322 | void QLegend::setLabelColor(QColor color) |
|
322 | void QLegend::setLabelColor(QColor color) | |
323 | { |
|
323 | { | |
324 | QBrush b = d_ptr->m_labelBrush; |
|
324 | QBrush b = d_ptr->m_labelBrush; | |
325 | if (b.style() != Qt::SolidPattern || b.color() != color) { |
|
325 | if (b.style() != Qt::SolidPattern || b.color() != color) { | |
326 | b.setStyle(Qt::SolidPattern); |
|
326 | b.setStyle(Qt::SolidPattern); | |
327 | b.setColor(color); |
|
327 | b.setColor(color); | |
328 | setLabelBrush(b); |
|
328 | setLabelBrush(b); | |
329 | } |
|
329 | } | |
330 | } |
|
330 | } | |
331 |
|
331 | |||
332 | QColor QLegend::labelColor() const |
|
332 | QColor QLegend::labelColor() const | |
333 | { |
|
333 | { | |
334 | return d_ptr->m_labelBrush.color(); |
|
334 | return d_ptr->m_labelBrush.color(); | |
335 | } |
|
335 | } | |
336 |
|
336 | |||
337 |
|
337 | |||
338 | void QLegend::setAlignment(Qt::Alignment alignment) |
|
338 | void QLegend::setAlignment(Qt::Alignment alignment) | |
339 | { |
|
339 | { | |
340 | if (d_ptr->m_alignment != alignment) { |
|
340 | if (d_ptr->m_alignment != alignment) { | |
341 | d_ptr->m_alignment = alignment; |
|
341 | d_ptr->m_alignment = alignment; | |
342 | layout()->invalidate(); |
|
342 | layout()->invalidate(); | |
343 | } |
|
343 | } | |
344 | } |
|
344 | } | |
345 |
|
345 | |||
346 | Qt::Alignment QLegend::alignment() const |
|
346 | Qt::Alignment QLegend::alignment() const | |
347 | { |
|
347 | { | |
348 | return d_ptr->m_alignment; |
|
348 | return d_ptr->m_alignment; | |
349 | } |
|
349 | } | |
350 |
|
350 | |||
351 | /*! |
|
351 | /*! | |
352 | Detaches the legend from chart. Chart won't change layout of the legend. |
|
352 | Detaches the legend from chart. Chart won't change layout of the legend. | |
353 | */ |
|
353 | */ | |
354 | void QLegend::detachFromChart() |
|
354 | void QLegend::detachFromChart() | |
355 | { |
|
355 | { | |
356 | d_ptr->m_attachedToChart = false; |
|
356 | d_ptr->m_attachedToChart = false; | |
357 | layout()->invalidate(); |
|
357 | layout()->invalidate(); | |
358 | setParent(0); |
|
358 | setParent(0); | |
359 |
|
359 | |||
360 | } |
|
360 | } | |
361 |
|
361 | |||
362 | /*! |
|
362 | /*! | |
363 | Attaches the legend to chart. Chart may change layout of the legend. |
|
363 | Attaches the legend to chart. Chart may change layout of the legend. | |
364 | */ |
|
364 | */ | |
365 | void QLegend::attachToChart() |
|
365 | void QLegend::attachToChart() | |
366 | { |
|
366 | { | |
367 | d_ptr->m_attachedToChart = true; |
|
367 | d_ptr->m_attachedToChart = true; | |
368 | layout()->invalidate(); |
|
368 | layout()->invalidate(); | |
369 | setParent(d_ptr->m_chart); |
|
369 | setParent(d_ptr->m_chart); | |
370 | } |
|
370 | } | |
371 |
|
371 | |||
372 | /*! |
|
372 | /*! | |
373 | Returns true, if legend is attached to chart. |
|
373 | Returns true, if legend is attached to chart. | |
374 | */ |
|
374 | */ | |
375 | bool QLegend::isAttachedToChart() |
|
375 | bool QLegend::isAttachedToChart() | |
376 | { |
|
376 | { | |
377 | return d_ptr->m_attachedToChart; |
|
377 | return d_ptr->m_attachedToChart; | |
378 | } |
|
378 | } | |
379 |
|
379 | |||
380 | /*! |
|
380 | /*! | |
381 | Sets the visibility of legend background to \a visible |
|
381 | Sets the visibility of legend background to \a visible | |
382 | */ |
|
382 | */ | |
383 | void QLegend::setBackgroundVisible(bool visible) |
|
383 | void QLegend::setBackgroundVisible(bool visible) | |
384 | { |
|
384 | { | |
385 | if (d_ptr->m_backgroundVisible != visible) { |
|
385 | if (d_ptr->m_backgroundVisible != visible) { | |
386 | d_ptr->m_backgroundVisible = visible; |
|
386 | d_ptr->m_backgroundVisible = visible; | |
387 | update(); |
|
387 | update(); | |
388 | emit backgroundVisibleChanged(visible); |
|
388 | emit backgroundVisibleChanged(visible); | |
389 | } |
|
389 | } | |
390 | } |
|
390 | } | |
391 |
|
391 | |||
392 | /*! |
|
392 | /*! | |
393 | Returns the visibility of legend background |
|
393 | Returns the visibility of legend background | |
394 | */ |
|
394 | */ | |
395 | bool QLegend::isBackgroundVisible() const |
|
395 | bool QLegend::isBackgroundVisible() const | |
396 | { |
|
396 | { | |
397 | return d_ptr->m_backgroundVisible; |
|
397 | return d_ptr->m_backgroundVisible; | |
398 | } |
|
398 | } | |
399 |
|
399 | |||
400 |
|
||||
401 | QList<QLegendMarker*> QLegend::markers() const |
|
400 | QList<QLegendMarker*> QLegend::markers() const | |
402 | { |
|
401 | { | |
403 | // TODO: name of PIMPL method will change. |
|
402 | return d_ptr->markers(); | |
404 | return d_ptr->legendMarkers(); |
|
|||
405 | } |
|
403 | } | |
406 |
|
404 | |||
407 |
void QLegend::a |
|
405 | void QLegend::addSeries(QAbstractSeries* series) | |
408 | { |
|
406 | { | |
409 |
d_ptr->a |
|
407 | d_ptr->addSeries(series); | |
410 | } |
|
408 | } | |
411 |
|
409 | |||
412 | void QLegend::removeSeries(QAbstractSeries* series) |
|
410 | void QLegend::removeSeries(QAbstractSeries* series) | |
413 | { |
|
411 | { | |
414 | d_ptr->removeSeries(series); |
|
412 | d_ptr->removeSeries(series); | |
415 | } |
|
413 | } | |
416 |
|
414 | |||
417 | /*! |
|
415 | /*! | |
418 | \internal \a event see QGraphicsWidget for details |
|
416 | \internal \a event see QGraphicsWidget for details | |
419 | */ |
|
417 | */ | |
420 | void QLegend::hideEvent(QHideEvent *event) |
|
418 | void QLegend::hideEvent(QHideEvent *event) | |
421 | { |
|
419 | { | |
422 | if (isAttachedToChart()) |
|
420 | if (isAttachedToChart()) | |
423 | d_ptr->m_presenter->layout()->invalidate(); |
|
421 | d_ptr->m_presenter->layout()->invalidate(); | |
424 | QGraphicsWidget::hideEvent(event); |
|
422 | QGraphicsWidget::hideEvent(event); | |
425 | } |
|
423 | } | |
426 | /*! |
|
424 | /*! | |
427 | \internal \a event see QGraphicsWidget for details |
|
425 | \internal \a event see QGraphicsWidget for details | |
428 | */ |
|
426 | */ | |
429 | void QLegend::showEvent(QShowEvent *event) |
|
427 | void QLegend::showEvent(QShowEvent *event) | |
430 | { |
|
428 | { | |
431 | if (isAttachedToChart()) { |
|
429 | if (isAttachedToChart()) { | |
432 | d_ptr->items()->setVisible(false); |
|
430 | d_ptr->items()->setVisible(false); | |
433 | layout()->invalidate(); |
|
431 | layout()->invalidate(); | |
434 | } |
|
432 | } | |
435 | QGraphicsWidget::showEvent(event); |
|
433 | QGraphicsWidget::showEvent(event); | |
436 | //layout activation will show the items |
|
434 | //layout activation will show the items | |
437 | } |
|
435 | } | |
438 |
|
436 | |||
439 | //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
|
437 | //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// | |
440 |
|
438 | |||
441 | QLegendPrivate::QLegendPrivate(ChartPresenter *presenter, QChart *chart, QLegend *q) |
|
439 | QLegendPrivate::QLegendPrivate(ChartPresenter *presenter, QChart *chart, QLegend *q) | |
442 | : q_ptr(q), |
|
440 | : q_ptr(q), | |
443 | m_presenter(presenter), |
|
441 | m_presenter(presenter), | |
444 | m_layout(new LegendLayout(q)), |
|
442 | m_layout(new LegendLayout(q)), | |
445 | m_chart(chart), |
|
443 | m_chart(chart), | |
446 | m_items(new QGraphicsItemGroup(q)), |
|
444 | m_items(new QGraphicsItemGroup(q)), | |
447 | m_alignment(Qt::AlignTop), |
|
445 | m_alignment(Qt::AlignTop), | |
448 | m_brush(QBrush()), |
|
446 | m_brush(QBrush()), | |
449 | m_pen(QPen()), |
|
447 | m_pen(QPen()), | |
450 | m_labelBrush(QBrush()), |
|
448 | m_labelBrush(QBrush()), | |
451 | m_diameter(5), |
|
449 | m_diameter(5), | |
452 | m_attachedToChart(true), |
|
450 | m_attachedToChart(true), | |
453 | m_backgroundVisible(false) |
|
451 | m_backgroundVisible(false) | |
454 | { |
|
452 | { | |
455 | m_items->setHandlesChildEvents(false); |
|
453 | m_items->setHandlesChildEvents(false); | |
456 | } |
|
454 | } | |
457 |
|
455 | |||
458 | QLegendPrivate::~QLegendPrivate() |
|
456 | QLegendPrivate::~QLegendPrivate() | |
459 | { |
|
457 | { | |
460 |
|
458 | |||
461 | } |
|
459 | } | |
462 |
|
460 | |||
463 | void QLegendPrivate::setOffset(qreal x, qreal y) |
|
461 | void QLegendPrivate::setOffset(qreal x, qreal y) | |
464 | { |
|
462 | { | |
465 | m_layout->setOffset(x, y); |
|
463 | m_layout->setOffset(x, y); | |
466 | } |
|
464 | } | |
467 |
|
465 | |||
468 | QPointF QLegendPrivate::offset() const |
|
466 | QPointF QLegendPrivate::offset() const | |
469 | { |
|
467 | { | |
470 | return m_layout->offset(); |
|
468 | return m_layout->offset(); | |
471 | } |
|
469 | } | |
472 |
|
470 | |||
473 | int QLegendPrivate::roundness(qreal size) |
|
471 | int QLegendPrivate::roundness(qreal size) | |
474 | { |
|
472 | { | |
475 | return 100 * m_diameter / int(size); |
|
473 | return 100 * m_diameter / int(size); | |
476 | } |
|
474 | } | |
477 |
|
475 | |||
478 |
void QLegendPrivate::a |
|
476 | void QLegendPrivate::addSeries(QAbstractSeries* series) | |
479 | { |
|
477 | { | |
480 | // Only allow one instance of series |
|
478 | // Only allow one instance of series | |
481 | if (m_series.contains(series)) { |
|
479 | if (m_series.contains(series)) { | |
482 | qDebug() << "series already added" << series; |
|
480 | qDebug() << "series already added" << series; | |
483 | return; |
|
481 | return; | |
484 | } |
|
482 | } | |
485 |
|
483 | |||
486 | QList<QLegendMarker*> newMarkers = series->d_ptr->createLegendMarkers(q_ptr); |
|
484 | QList<QLegendMarker*> newMarkers = series->d_ptr->createLegendMarkers(q_ptr); | |
487 | decorateMarkers(newMarkers); |
|
485 | decorateMarkers(newMarkers); | |
488 | addMarkers(newMarkers); |
|
486 | addMarkers(newMarkers); | |
489 |
|
487 | |||
490 | // TODO: This is the part I don't like. There should be better solution. |
|
488 | // TODO: This is the part I don't like. There should be better solution. | |
491 | // On the other hand. It is only one switch case for appending and another for removing series |
|
489 | // On the other hand. It is only one switch case for appending and another for removing series | |
492 | // If countChanged signal were on QAbstractSeries, there would be no need for switch at all. |
|
490 | // If countChanged signal were on QAbstractSeries, there would be no need for switch at all. | |
493 | switch (series->type()) |
|
491 | switch (series->type()) | |
494 | { |
|
492 | { | |
495 | case QAbstractSeries::SeriesTypePie: { |
|
493 | case QAbstractSeries::SeriesTypePie: { | |
496 | QPieSeries *s = qobject_cast<QPieSeries *> (series); |
|
494 | QPieSeries *s = qobject_cast<QPieSeries *> (series); | |
497 | QObject::connect(s, SIGNAL(countChanged()), this, SLOT(handleSeriesUpdated())); |
|
495 | QObject::connect(s, SIGNAL(countChanged()), this, SLOT(handleSeriesUpdated())); | |
498 | break; |
|
496 | break; | |
499 | } |
|
497 | } | |
500 | case QAbstractSeries::SeriesTypeBar: |
|
498 | case QAbstractSeries::SeriesTypeBar: | |
501 | case QAbstractSeries::SeriesTypeStackedBar: |
|
499 | case QAbstractSeries::SeriesTypeStackedBar: | |
502 | case QAbstractSeries::SeriesTypePercentBar: |
|
500 | case QAbstractSeries::SeriesTypePercentBar: | |
503 | case QAbstractSeries::SeriesTypeHorizontalBar: |
|
501 | case QAbstractSeries::SeriesTypeHorizontalBar: | |
504 | case QAbstractSeries::SeriesTypeHorizontalStackedBar: |
|
502 | case QAbstractSeries::SeriesTypeHorizontalStackedBar: | |
505 | case QAbstractSeries::SeriesTypeHorizontalPercentBar: { |
|
503 | case QAbstractSeries::SeriesTypeHorizontalPercentBar: { | |
506 | QAbstractBarSeries *s = qobject_cast<QAbstractBarSeries *> (series); |
|
504 | QAbstractBarSeries *s = qobject_cast<QAbstractBarSeries *> (series); | |
507 | QObject::connect(s, SIGNAL(countChanged()), this, SLOT(handleSeriesUpdated())); |
|
505 | QObject::connect(s, SIGNAL(countChanged()), this, SLOT(handleSeriesUpdated())); | |
508 | break; |
|
506 | break; | |
509 | } |
|
507 | } | |
510 | case QAbstractSeries::SeriesTypeLine: |
|
508 | case QAbstractSeries::SeriesTypeLine: | |
511 | case QAbstractSeries::SeriesTypeArea: |
|
509 | case QAbstractSeries::SeriesTypeArea: | |
512 | case QAbstractSeries::SeriesTypeScatter: |
|
510 | case QAbstractSeries::SeriesTypeScatter: | |
513 | case QAbstractSeries::SeriesTypeSpline: |
|
511 | case QAbstractSeries::SeriesTypeSpline: | |
514 | default: { |
|
512 | default: { | |
515 | // No need to connect any series related signals. We have no series level |
|
513 | // No need to connect any series related signals. We have no series level | |
516 | // changes, that would generate or delete markers |
|
514 | // changes, that would generate or delete markers | |
517 | } |
|
515 | } | |
518 | } |
|
516 | } | |
519 |
|
517 | |||
520 | QObject::connect(series, SIGNAL(visibleChanged()), this, SLOT(handleSeriesVisibleChanged())); |
|
518 | QObject::connect(series, SIGNAL(visibleChanged()), this, SLOT(handleSeriesVisibleChanged())); | |
521 |
|
519 | |||
522 | m_series.append(series); |
|
520 | m_series.append(series); | |
523 | m_items->setVisible(false); |
|
521 | m_items->setVisible(false); | |
524 | m_layout->invalidate(); |
|
522 | m_layout->invalidate(); | |
525 | } |
|
523 | } | |
526 |
|
524 | |||
527 | void QLegendPrivate::removeSeries(QAbstractSeries* series) |
|
525 | void QLegendPrivate::removeSeries(QAbstractSeries* series) | |
528 | { |
|
526 | { | |
529 | if (m_series.contains(series)) { |
|
527 | if (m_series.contains(series)) { | |
530 | m_series.removeOne(series); |
|
528 | m_series.removeOne(series); | |
531 | } |
|
529 | } | |
532 |
|
530 | |||
533 | // Find out, which markers to remove |
|
531 | // Find out, which markers to remove | |
534 | QList<QLegendMarker *> removed; |
|
532 | QList<QLegendMarker *> removed; | |
535 |
foreach (QLegendMarker *m, m_ |
|
533 | foreach (QLegendMarker *m, m_markers) { | |
536 | if (m->series() == series) { |
|
534 | if (m->series() == series) { | |
537 | removed << m; |
|
535 | removed << m; | |
538 | } |
|
536 | } | |
539 | } |
|
537 | } | |
540 | removeMarkers(removed); |
|
538 | removeMarkers(removed); | |
541 |
|
539 | |||
542 | switch (series->type()) |
|
540 | switch (series->type()) | |
543 | { |
|
541 | { | |
544 | case QAbstractSeries::SeriesTypePie: { |
|
542 | case QAbstractSeries::SeriesTypePie: { | |
545 | QPieSeries *s = qobject_cast<QPieSeries *> (series); |
|
543 | QPieSeries *s = qobject_cast<QPieSeries *> (series); | |
546 | QObject::disconnect(s, SIGNAL(countChanged()), this, SLOT(handleSeriesUpdated())); |
|
544 | QObject::disconnect(s, SIGNAL(countChanged()), this, SLOT(handleSeriesUpdated())); | |
547 | break; |
|
545 | break; | |
548 | } |
|
546 | } | |
549 | case QAbstractSeries::SeriesTypeBar: |
|
547 | case QAbstractSeries::SeriesTypeBar: | |
550 | case QAbstractSeries::SeriesTypeStackedBar: |
|
548 | case QAbstractSeries::SeriesTypeStackedBar: | |
551 | case QAbstractSeries::SeriesTypePercentBar: |
|
549 | case QAbstractSeries::SeriesTypePercentBar: | |
552 | case QAbstractSeries::SeriesTypeHorizontalBar: |
|
550 | case QAbstractSeries::SeriesTypeHorizontalBar: | |
553 | case QAbstractSeries::SeriesTypeHorizontalStackedBar: |
|
551 | case QAbstractSeries::SeriesTypeHorizontalStackedBar: | |
554 | case QAbstractSeries::SeriesTypeHorizontalPercentBar: { |
|
552 | case QAbstractSeries::SeriesTypeHorizontalPercentBar: { | |
555 | QAbstractBarSeries *s = qobject_cast<QAbstractBarSeries *> (series); |
|
553 | QAbstractBarSeries *s = qobject_cast<QAbstractBarSeries *> (series); | |
556 | QObject::disconnect(s, SIGNAL(countChanged()), this, SLOT(handleSeriesUpdated())); |
|
554 | QObject::disconnect(s, SIGNAL(countChanged()), this, SLOT(handleSeriesUpdated())); | |
557 | break; |
|
555 | break; | |
558 | } |
|
556 | } | |
559 | // TODO: |
|
557 | // TODO: | |
560 | case QAbstractSeries::SeriesTypeLine: |
|
558 | case QAbstractSeries::SeriesTypeLine: | |
561 | case QAbstractSeries::SeriesTypeArea: |
|
559 | case QAbstractSeries::SeriesTypeArea: | |
562 | case QAbstractSeries::SeriesTypeScatter: |
|
560 | case QAbstractSeries::SeriesTypeScatter: | |
563 | case QAbstractSeries::SeriesTypeSpline: |
|
561 | case QAbstractSeries::SeriesTypeSpline: | |
564 | default: { |
|
562 | default: { | |
565 | // No need to disconnect any series related signals |
|
563 | // No need to disconnect any series related signals | |
566 | break; |
|
564 | break; | |
567 | } |
|
565 | } | |
568 | } |
|
566 | } | |
569 |
|
567 | |||
570 | QObject::disconnect(series, SIGNAL(visibleChanged()), this, SLOT(handleSeriesVisibleChanged())); |
|
568 | QObject::disconnect(series, SIGNAL(visibleChanged()), this, SLOT(handleSeriesVisibleChanged())); | |
571 |
|
569 | |||
572 | m_layout->invalidate(); |
|
570 | m_layout->invalidate(); | |
573 | // q_ptr->layout()->activate(); |
|
571 | // q_ptr->layout()->activate(); | |
574 | } |
|
572 | } | |
575 |
|
573 | |||
576 | void QLegendPrivate::handleSeriesAdded(QAbstractSeries *series) |
|
574 | void QLegendPrivate::handleSeriesAdded(QAbstractSeries *series) | |
577 | { |
|
575 | { | |
578 | // Moved to appendSeries |
|
576 | // Moved to appendSeries | |
579 | // This slot is just to make old code work for now. |
|
577 | // This slot is just to make old code work for now. | |
580 |
a |
|
578 | addSeries(series); | |
581 | } |
|
579 | } | |
582 |
|
580 | |||
583 | void QLegendPrivate::handleSeriesRemoved(QAbstractSeries *series) |
|
581 | void QLegendPrivate::handleSeriesRemoved(QAbstractSeries *series) | |
584 | { |
|
582 | { | |
585 | // Moved to removeSeries |
|
583 | // Moved to removeSeries | |
586 | // This slot is just to make old code work for now. |
|
584 | // This slot is just to make old code work for now. | |
587 | removeSeries(series); |
|
585 | removeSeries(series); | |
588 | } |
|
586 | } | |
589 |
|
587 | |||
590 | void QLegendPrivate::handleSeriesVisibleChanged() |
|
588 | void QLegendPrivate::handleSeriesVisibleChanged() | |
591 | { |
|
589 | { | |
592 | QAbstractSeries *series = qobject_cast<QAbstractSeries *> (sender()); |
|
590 | QAbstractSeries *series = qobject_cast<QAbstractSeries *> (sender()); | |
593 | Q_ASSERT(series); |
|
591 | Q_ASSERT(series); | |
594 |
|
592 | |||
595 |
foreach (QLegendMarker* marker, m_ |
|
593 | foreach (QLegendMarker* marker, m_markers) { | |
596 | if (marker->series() == series) { |
|
594 | if (marker->series() == series) { | |
597 | marker->setVisible(series->isVisible()); |
|
595 | marker->setVisible(series->isVisible()); | |
598 | } |
|
596 | } | |
599 | } |
|
597 | } | |
600 | m_layout->invalidate(); |
|
598 | m_layout->invalidate(); | |
601 | } |
|
599 | } | |
602 |
|
600 | |||
603 | void QLegendPrivate::handleCountChanged() |
|
601 | void QLegendPrivate::handleCountChanged() | |
604 | { |
|
602 | { | |
605 | // Here we handle the changes in marker count. |
|
603 | // Here we handle the changes in marker count. | |
606 | // Can happen for example when pieslice(s) have been added to or removed from pieseries. |
|
604 | // Can happen for example when pieslice(s) have been added to or removed from pieseries. | |
607 |
|
605 | |||
608 | QAbstractSeries *series = qobject_cast<QAbstractSeries *> (sender()); |
|
606 | QAbstractSeries *series = qobject_cast<QAbstractSeries *> (sender()); | |
609 | QList<QLegendMarker *> createdMarkers = series->d_ptr->createLegendMarkers(q_ptr); |
|
607 | QList<QLegendMarker *> createdMarkers = series->d_ptr->createLegendMarkers(q_ptr); | |
610 |
|
608 | |||
611 | // Find out removed markers and created markers |
|
609 | // Find out removed markers and created markers | |
612 | QList<QLegendMarker *> removedMarkers; |
|
610 | QList<QLegendMarker *> removedMarkers; | |
613 |
foreach (QLegendMarker *oldMarker, m_ |
|
611 | foreach (QLegendMarker *oldMarker, m_markers) { | |
614 | // we have marker, which is related to sender. |
|
612 | // we have marker, which is related to sender. | |
615 | if (oldMarker->series() == series) { |
|
613 | if (oldMarker->series() == series) { | |
616 | bool found = false; |
|
614 | bool found = false; | |
617 | foreach(QLegendMarker *newMarker, createdMarkers) { |
|
615 | foreach(QLegendMarker *newMarker, createdMarkers) { | |
618 | // New marker considered existing if: |
|
616 | // New marker considered existing if: | |
619 | // - d_ptr->relatedObject() is same for both markers. |
|
617 | // - d_ptr->relatedObject() is same for both markers. | |
620 | if (newMarker->d_ptr->relatedObject() == oldMarker->d_ptr->relatedObject()) { |
|
618 | if (newMarker->d_ptr->relatedObject() == oldMarker->d_ptr->relatedObject()) { | |
621 | // Delete the new marker, since we already have existing marker, that might be connected on user side. |
|
619 | // Delete the new marker, since we already have existing marker, that might be connected on user side. | |
622 | found = true; |
|
620 | found = true; | |
623 | createdMarkers.removeOne(newMarker); |
|
621 | createdMarkers.removeOne(newMarker); | |
624 | delete newMarker; |
|
622 | delete newMarker; | |
625 | } |
|
623 | } | |
626 | } |
|
624 | } | |
627 | if (!found) { |
|
625 | if (!found) { | |
628 | // No related object found for marker, add to removedMarkers list |
|
626 | // No related object found for marker, add to removedMarkers list | |
629 | removedMarkers << oldMarker; |
|
627 | removedMarkers << oldMarker; | |
630 | } |
|
628 | } | |
631 | } |
|
629 | } | |
632 | } |
|
630 | } | |
633 |
|
631 | |||
634 | removeMarkers(removedMarkers); |
|
632 | removeMarkers(removedMarkers); | |
635 | decorateMarkers(createdMarkers); |
|
633 | decorateMarkers(createdMarkers); | |
636 | addMarkers(createdMarkers); |
|
634 | addMarkers(createdMarkers); | |
637 |
|
635 | |||
638 | q_ptr->layout()->invalidate(); |
|
636 | q_ptr->layout()->invalidate(); | |
639 | } |
|
637 | } | |
640 |
|
638 | |||
641 | void QLegendPrivate::addMarkers(QList<QLegendMarker *> markers) |
|
639 | void QLegendPrivate::addMarkers(QList<QLegendMarker *> markers) | |
642 | { |
|
640 | { | |
643 | foreach (QLegendMarker* marker, markers) { |
|
641 | foreach (QLegendMarker* marker, markers) { | |
644 | m_items->addToGroup(marker->d_ptr.data()->item()); |
|
642 | m_items->addToGroup(marker->d_ptr.data()->item()); | |
645 |
m_ |
|
643 | m_markers << marker; | |
646 | } |
|
644 | } | |
647 | } |
|
645 | } | |
648 |
|
646 | |||
649 | void QLegendPrivate::removeMarkers(QList<QLegendMarker *> markers) |
|
647 | void QLegendPrivate::removeMarkers(QList<QLegendMarker *> markers) | |
650 | { |
|
648 | { | |
651 | foreach (QLegendMarker *marker, markers) { |
|
649 | foreach (QLegendMarker *marker, markers) { | |
652 | marker->d_ptr->item()->setVisible(false); |
|
650 | marker->d_ptr->item()->setVisible(false); | |
653 | m_items->removeFromGroup(marker->d_ptr->item()); |
|
651 | m_items->removeFromGroup(marker->d_ptr->item()); | |
654 | delete marker; |
|
652 | delete marker; | |
655 |
m_ |
|
653 | m_markers.removeOne(marker); | |
656 | } |
|
654 | } | |
657 | } |
|
655 | } | |
658 |
|
656 | |||
659 | void QLegendPrivate::decorateMarkers(QList<QLegendMarker *> markers) |
|
657 | void QLegendPrivate::decorateMarkers(QList<QLegendMarker *> markers) | |
660 | { |
|
658 | { | |
661 | foreach (QLegendMarker* marker, markers) { |
|
659 | foreach (QLegendMarker* marker, markers) { | |
662 | marker->setFont(m_font); |
|
660 | marker->setFont(m_font); | |
663 | marker->setLabelBrush(m_labelBrush); |
|
661 | marker->setLabelBrush(m_labelBrush); | |
664 | } |
|
662 | } | |
665 | } |
|
663 | } | |
666 |
|
664 | |||
667 |
|
665 | |||
668 | #include "moc_qlegend.cpp" |
|
666 | #include "moc_qlegend.cpp" | |
669 | #include "moc_qlegend_p.cpp" |
|
667 | #include "moc_qlegend_p.cpp" | |
670 |
|
668 | |||
671 | QTCOMMERCIALCHART_END_NAMESPACE |
|
669 | QTCOMMERCIALCHART_END_NAMESPACE |
@@ -1,109 +1,109 | |||||
1 | /**************************************************************************** |
|
1 | /**************************************************************************** | |
2 | ** |
|
2 | ** | |
3 | ** Copyright (C) 2012 Digia Plc |
|
3 | ** Copyright (C) 2012 Digia Plc | |
4 | ** All rights reserved. |
|
4 | ** All rights reserved. | |
5 | ** For any questions to Digia, please use contact form at http://qt.digia.com |
|
5 | ** For any questions to Digia, please use contact form at http://qt.digia.com | |
6 | ** |
|
6 | ** | |
7 | ** This file is part of the Qt Commercial Charts Add-on. |
|
7 | ** This file is part of the Qt Commercial Charts Add-on. | |
8 | ** |
|
8 | ** | |
9 | ** $QT_BEGIN_LICENSE$ |
|
9 | ** $QT_BEGIN_LICENSE$ | |
10 | ** Licensees holding valid Qt Commercial licenses may use this file in |
|
10 | ** Licensees holding valid Qt Commercial licenses may use this file in | |
11 | ** accordance with the Qt Commercial License Agreement provided with the |
|
11 | ** accordance with the Qt Commercial License Agreement provided with the | |
12 | ** Software or, alternatively, in accordance with the terms contained in |
|
12 | ** Software or, alternatively, in accordance with the terms contained in | |
13 | ** a written agreement between you and Digia. |
|
13 | ** a written agreement between you and Digia. | |
14 | ** |
|
14 | ** | |
15 | ** If you have questions regarding the use of this file, please use |
|
15 | ** If you have questions regarding the use of this file, please use | |
16 | ** contact form at http://qt.digia.com |
|
16 | ** contact form at http://qt.digia.com | |
17 | ** $QT_END_LICENSE$ |
|
17 | ** $QT_END_LICENSE$ | |
18 | ** |
|
18 | ** | |
19 | ****************************************************************************/ |
|
19 | ****************************************************************************/ | |
20 |
|
20 | |||
21 | #ifndef QLEGEND_H |
|
21 | #ifndef QLEGEND_H | |
22 | #define QLEGEND_H |
|
22 | #define QLEGEND_H | |
23 |
|
23 | |||
24 | #include <qchartglobal.h> |
|
24 | #include <qchartglobal.h> | |
25 | #include <QGraphicsWidget> |
|
25 | #include <QGraphicsWidget> | |
26 | #include <QPen> |
|
26 | #include <QPen> | |
27 | #include <QBrush> |
|
27 | #include <QBrush> | |
28 |
|
28 | |||
29 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
29 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
30 |
|
30 | |||
31 | class QChart; |
|
31 | class QChart; | |
32 | class QLegendPrivate; |
|
32 | class QLegendPrivate; | |
33 | class QLegendMarker; |
|
33 | class QLegendMarker; | |
34 | class QAbstractSeries; |
|
34 | class QAbstractSeries; | |
35 |
|
35 | |||
36 | class QTCOMMERCIALCHART_EXPORT QLegend : public QGraphicsWidget |
|
36 | class QTCOMMERCIALCHART_EXPORT QLegend : public QGraphicsWidget | |
37 | { |
|
37 | { | |
38 | Q_OBJECT |
|
38 | Q_OBJECT | |
39 | Q_PROPERTY(Qt::Alignment alignment READ alignment WRITE setAlignment) |
|
39 | Q_PROPERTY(Qt::Alignment alignment READ alignment WRITE setAlignment) | |
40 | Q_PROPERTY(bool backgroundVisible READ isBackgroundVisible WRITE setBackgroundVisible NOTIFY backgroundVisibleChanged) |
|
40 | Q_PROPERTY(bool backgroundVisible READ isBackgroundVisible WRITE setBackgroundVisible NOTIFY backgroundVisibleChanged) | |
41 | Q_PROPERTY(QColor color READ color WRITE setColor NOTIFY colorChanged) |
|
41 | Q_PROPERTY(QColor color READ color WRITE setColor NOTIFY colorChanged) | |
42 | Q_PROPERTY(QColor borderColor READ borderColor WRITE setBorderColor NOTIFY borderColorChanged) |
|
42 | Q_PROPERTY(QColor borderColor READ borderColor WRITE setBorderColor NOTIFY borderColorChanged) | |
43 | Q_PROPERTY(QFont font READ font WRITE setFont NOTIFY fontChanged) |
|
43 | Q_PROPERTY(QFont font READ font WRITE setFont NOTIFY fontChanged) | |
44 | Q_PROPERTY(QColor labelColor READ labelColor WRITE setLabelColor NOTIFY labelColorChanged) |
|
44 | Q_PROPERTY(QColor labelColor READ labelColor WRITE setLabelColor NOTIFY labelColorChanged) | |
45 |
|
45 | |||
46 | private: |
|
46 | private: | |
47 | explicit QLegend(QChart *chart); |
|
47 | explicit QLegend(QChart *chart); | |
48 |
|
48 | |||
49 | public: |
|
49 | public: | |
50 | ~QLegend(); |
|
50 | ~QLegend(); | |
51 |
|
51 | |||
52 | void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget = 0); |
|
52 | void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget = 0); | |
53 |
|
53 | |||
54 | void setBrush(const QBrush &brush); |
|
54 | void setBrush(const QBrush &brush); | |
55 | QBrush brush() const; |
|
55 | QBrush brush() const; | |
56 | void setColor(QColor color); |
|
56 | void setColor(QColor color); | |
57 | QColor color(); |
|
57 | QColor color(); | |
58 |
|
58 | |||
59 | void setPen(const QPen &pen); |
|
59 | void setPen(const QPen &pen); | |
60 | QPen pen() const; |
|
60 | QPen pen() const; | |
61 | void setBorderColor(QColor color); |
|
61 | void setBorderColor(QColor color); | |
62 | QColor borderColor(); |
|
62 | QColor borderColor(); | |
63 |
|
63 | |||
64 | void setFont(const QFont &font); |
|
64 | void setFont(const QFont &font); | |
65 | QFont font() const; |
|
65 | QFont font() const; | |
66 | void setLabelBrush(const QBrush &brush); |
|
66 | void setLabelBrush(const QBrush &brush); | |
67 | QBrush labelBrush() const; |
|
67 | QBrush labelBrush() const; | |
68 |
|
68 | |||
69 | void setLabelColor(QColor color); |
|
69 | void setLabelColor(QColor color); | |
70 | QColor labelColor() const; |
|
70 | QColor labelColor() const; | |
71 |
|
71 | |||
72 | void setAlignment(Qt::Alignment alignment); |
|
72 | void setAlignment(Qt::Alignment alignment); | |
73 | Qt::Alignment alignment() const; |
|
73 | Qt::Alignment alignment() const; | |
74 |
|
74 | |||
75 | void detachFromChart(); |
|
75 | void detachFromChart(); | |
76 | void attachToChart(); |
|
76 | void attachToChart(); | |
77 | bool isAttachedToChart(); |
|
77 | bool isAttachedToChart(); | |
78 |
|
78 | |||
79 | void setBackgroundVisible(bool visible = true); |
|
79 | void setBackgroundVisible(bool visible = true); | |
80 | bool isBackgroundVisible() const; |
|
80 | bool isBackgroundVisible() const; | |
81 |
|
81 | |||
82 | // New stuff: |
|
82 | // New stuff: | |
83 | QList <QLegendMarker*> markers() const; |
|
83 | QList <QLegendMarker*> markers() const; | |
84 |
void a |
|
84 | void addSeries(QAbstractSeries* series); | |
85 | void removeSeries(QAbstractSeries* series); |
|
85 | void removeSeries(QAbstractSeries* series); | |
86 |
|
86 | |||
87 | protected: |
|
87 | protected: | |
88 | void hideEvent(QHideEvent *event); |
|
88 | void hideEvent(QHideEvent *event); | |
89 | void showEvent(QShowEvent *event); |
|
89 | void showEvent(QShowEvent *event); | |
90 |
|
90 | |||
91 | Q_SIGNALS: |
|
91 | Q_SIGNALS: | |
92 | void backgroundVisibleChanged(bool visible); |
|
92 | void backgroundVisibleChanged(bool visible); | |
93 | void colorChanged(QColor color); |
|
93 | void colorChanged(QColor color); | |
94 | void borderColorChanged(QColor color); |
|
94 | void borderColorChanged(QColor color); | |
95 | void fontChanged(QFont font); |
|
95 | void fontChanged(QFont font); | |
96 | void labelColorChanged(QColor color); |
|
96 | void labelColorChanged(QColor color); | |
97 |
|
97 | |||
98 | private: |
|
98 | private: | |
99 | QScopedPointer<QLegendPrivate> d_ptr; |
|
99 | QScopedPointer<QLegendPrivate> d_ptr; | |
100 | Q_DISABLE_COPY(QLegend) |
|
100 | Q_DISABLE_COPY(QLegend) | |
101 | friend class LegendScroller; |
|
101 | friend class LegendScroller; | |
102 | friend class LegendLayout; |
|
102 | friend class LegendLayout; | |
103 | friend class ChartLayout; |
|
103 | friend class ChartLayout; | |
104 | friend class LegendMarkerItem; |
|
104 | friend class LegendMarkerItem; | |
105 | }; |
|
105 | }; | |
106 |
|
106 | |||
107 | QTCOMMERCIALCHART_END_NAMESPACE |
|
107 | QTCOMMERCIALCHART_END_NAMESPACE | |
108 |
|
108 | |||
109 | #endif // QLEGEND_H |
|
109 | #endif // QLEGEND_H |
@@ -1,101 +1,101 | |||||
1 | /**************************************************************************** |
|
1 | /**************************************************************************** | |
2 | ** |
|
2 | ** | |
3 | ** Copyright (C) 2012 Digia Plc |
|
3 | ** Copyright (C) 2012 Digia Plc | |
4 | ** All rights reserved. |
|
4 | ** All rights reserved. | |
5 | ** For any questions to Digia, please use contact form at http://qt.digia.com |
|
5 | ** For any questions to Digia, please use contact form at http://qt.digia.com | |
6 | ** |
|
6 | ** | |
7 | ** This file is part of the Qt Commercial Charts Add-on. |
|
7 | ** This file is part of the Qt Commercial Charts Add-on. | |
8 | ** |
|
8 | ** | |
9 | ** $QT_BEGIN_LICENSE$ |
|
9 | ** $QT_BEGIN_LICENSE$ | |
10 | ** Licensees holding valid Qt Commercial licenses may use this file in |
|
10 | ** Licensees holding valid Qt Commercial licenses may use this file in | |
11 | ** accordance with the Qt Commercial License Agreement provided with the |
|
11 | ** accordance with the Qt Commercial License Agreement provided with the | |
12 | ** Software or, alternatively, in accordance with the terms contained in |
|
12 | ** Software or, alternatively, in accordance with the terms contained in | |
13 | ** a written agreement between you and Digia. |
|
13 | ** a written agreement between you and Digia. | |
14 | ** |
|
14 | ** | |
15 | ** If you have questions regarding the use of this file, please use |
|
15 | ** If you have questions regarding the use of this file, please use | |
16 | ** contact form at http://qt.digia.com |
|
16 | ** contact form at http://qt.digia.com | |
17 | ** $QT_END_LICENSE$ |
|
17 | ** $QT_END_LICENSE$ | |
18 | ** |
|
18 | ** | |
19 | ****************************************************************************/ |
|
19 | ****************************************************************************/ | |
20 |
|
20 | |||
21 | // W A R N I N G |
|
21 | // W A R N I N G | |
22 | // ------------- |
|
22 | // ------------- | |
23 | // |
|
23 | // | |
24 | // This file is not part of the QtCommercial Chart API. It exists purely as an |
|
24 | // This file is not part of the QtCommercial Chart API. It exists purely as an | |
25 | // implementation detail. This header file may change from version to |
|
25 | // implementation detail. This header file may change from version to | |
26 | // version without notice, or even be removed. |
|
26 | // version without notice, or even be removed. | |
27 | // |
|
27 | // | |
28 | // We mean it. |
|
28 | // We mean it. | |
29 |
|
29 | |||
30 | #ifndef QLEGEND_P_H |
|
30 | #ifndef QLEGEND_P_H | |
31 | #define QLEGEND_P_H |
|
31 | #define QLEGEND_P_H | |
32 |
|
32 | |||
33 | #include "qlegend.h" |
|
33 | #include "qlegend.h" | |
34 |
|
34 | |||
35 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
35 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
36 |
|
36 | |||
37 | class QChart; |
|
37 | class QChart; | |
38 | class ChartPresenter; |
|
38 | class ChartPresenter; | |
39 | class QAbstractSeries; |
|
39 | class QAbstractSeries; | |
40 | class LegendLayout; |
|
40 | class LegendLayout; | |
41 | class Domain; |
|
41 | class Domain; | |
42 | class QLegendMarker; |
|
42 | class QLegendMarker; | |
43 |
|
43 | |||
44 | class QLegendPrivate : public QObject |
|
44 | class QLegendPrivate : public QObject | |
45 | { |
|
45 | { | |
46 | Q_OBJECT |
|
46 | Q_OBJECT | |
47 | public: |
|
47 | public: | |
48 | QLegendPrivate(ChartPresenter *presenter, QChart *chart, QLegend *q); |
|
48 | QLegendPrivate(ChartPresenter *presenter, QChart *chart, QLegend *q); | |
49 | ~QLegendPrivate(); |
|
49 | ~QLegendPrivate(); | |
50 |
|
50 | |||
51 | void setOffset(qreal x, qreal y); |
|
51 | void setOffset(qreal x, qreal y); | |
52 | QPointF offset() const; |
|
52 | QPointF offset() const; | |
53 | int roundness(qreal size); |
|
53 | int roundness(qreal size); | |
54 |
|
54 | |||
55 | QGraphicsItemGroup* items() { return m_items; } |
|
55 | QGraphicsItemGroup* items() { return m_items; } | |
56 |
|
56 | |||
57 | // New stuff: |
|
57 | // New stuff: | |
58 |
QList<QLegendMarker*> |
|
58 | QList<QLegendMarker*> markers() { return m_markers; } | |
59 |
void a |
|
59 | void addSeries(QAbstractSeries* series); | |
60 | void removeSeries(QAbstractSeries* series); |
|
60 | void removeSeries(QAbstractSeries* series); | |
61 |
|
61 | |||
62 | public Q_SLOTS: |
|
62 | public Q_SLOTS: | |
63 | void handleSeriesAdded(QAbstractSeries *series); |
|
63 | void handleSeriesAdded(QAbstractSeries *series); | |
64 | void handleSeriesRemoved(QAbstractSeries *series); |
|
64 | void handleSeriesRemoved(QAbstractSeries *series); | |
65 | void handleSeriesVisibleChanged(); |
|
65 | void handleSeriesVisibleChanged(); | |
66 | void handleCountChanged(); |
|
66 | void handleCountChanged(); | |
67 |
|
67 | |||
68 | private: |
|
68 | private: | |
69 | // Internal helpers |
|
69 | // Internal helpers | |
70 | void addMarkers(QList<QLegendMarker *> markers); |
|
70 | void addMarkers(QList<QLegendMarker *> markers); | |
71 | void removeMarkers(QList<QLegendMarker *> markers); |
|
71 | void removeMarkers(QList<QLegendMarker *> markers); | |
72 | void decorateMarkers(QList<QLegendMarker *> markers); |
|
72 | void decorateMarkers(QList<QLegendMarker *> markers); | |
73 |
|
73 | |||
74 | private: |
|
74 | private: | |
75 | QLegend *q_ptr; |
|
75 | QLegend *q_ptr; | |
76 | ChartPresenter *m_presenter; |
|
76 | ChartPresenter *m_presenter; | |
77 | LegendLayout *m_layout; |
|
77 | LegendLayout *m_layout; | |
78 | QChart* m_chart; |
|
78 | QChart* m_chart; | |
79 | QGraphicsItemGroup* m_items; |
|
79 | QGraphicsItemGroup* m_items; | |
80 | Qt::Alignment m_alignment; |
|
80 | Qt::Alignment m_alignment; | |
81 | QBrush m_brush; |
|
81 | QBrush m_brush; | |
82 | QPen m_pen; |
|
82 | QPen m_pen; | |
83 | QFont m_font; |
|
83 | QFont m_font; | |
84 | QBrush m_labelBrush; |
|
84 | QBrush m_labelBrush; | |
85 |
|
85 | |||
86 | qreal m_diameter; |
|
86 | qreal m_diameter; | |
87 | bool m_attachedToChart; |
|
87 | bool m_attachedToChart; | |
88 | bool m_backgroundVisible; |
|
88 | bool m_backgroundVisible; | |
89 |
|
89 | |||
90 | friend class QLegend; |
|
90 | friend class QLegend; | |
91 | friend class LegendLayout; |
|
91 | friend class LegendLayout; | |
92 | QList<QLegendMarker*> m_legendMarkers; // TODO: rename to m_markers eventually. |
|
92 | QList<QLegendMarker*> m_markers; | |
93 | QList<QAbstractSeries*> m_series; |
|
93 | QList<QAbstractSeries*> m_series; | |
94 |
|
94 | |||
95 | friend class QLegend; |
|
95 | friend class QLegend; | |
96 | friend class LegendMarkerItem; |
|
96 | friend class LegendMarkerItem; | |
97 | }; |
|
97 | }; | |
98 |
|
98 | |||
99 | QTCOMMERCIALCHART_END_NAMESPACE |
|
99 | QTCOMMERCIALCHART_END_NAMESPACE | |
100 |
|
100 | |||
101 | #endif |
|
101 | #endif |
@@ -1,99 +1,96 | |||||
1 | /**************************************************************************** |
|
1 | /**************************************************************************** | |
2 | ** |
|
2 | ** | |
3 | ** Copyright (C) 2012 Digia Plc |
|
3 | ** Copyright (C) 2012 Digia Plc | |
4 | ** All rights reserved. |
|
4 | ** All rights reserved. | |
5 | ** For any questions to Digia, please use contact form at http://qt.digia.com |
|
5 | ** For any questions to Digia, please use contact form at http://qt.digia.com | |
6 | ** |
|
6 | ** | |
7 | ** This file is part of the Qt Commercial Charts Add-on. |
|
7 | ** This file is part of the Qt Commercial Charts Add-on. | |
8 | ** |
|
8 | ** | |
9 | ** $QT_BEGIN_LICENSE$ |
|
9 | ** $QT_BEGIN_LICENSE$ | |
10 | ** Licensees holding valid Qt Commercial licenses may use this file in |
|
10 | ** Licensees holding valid Qt Commercial licenses may use this file in | |
11 | ** accordance with the Qt Commercial License Agreement provided with the |
|
11 | ** accordance with the Qt Commercial License Agreement provided with the | |
12 | ** Software or, alternatively, in accordance with the terms contained in |
|
12 | ** Software or, alternatively, in accordance with the terms contained in | |
13 | ** a written agreement between you and Digia. |
|
13 | ** a written agreement between you and Digia. | |
14 | ** |
|
14 | ** | |
15 | ** If you have questions regarding the use of this file, please use |
|
15 | ** If you have questions regarding the use of this file, please use | |
16 | ** contact form at http://qt.digia.com |
|
16 | ** contact form at http://qt.digia.com | |
17 | ** $QT_END_LICENSE$ |
|
17 | ** $QT_END_LICENSE$ | |
18 | ** |
|
18 | ** | |
19 | ****************************************************************************/ |
|
19 | ****************************************************************************/ | |
20 |
|
20 | |||
21 | #include "qpielegendmarker.h" |
|
21 | #include "qpielegendmarker.h" | |
22 | #include "qpielegendmarker_p.h" |
|
22 | #include "qpielegendmarker_p.h" | |
23 | #include <QPieSeries> |
|
23 | #include <QPieSeries> | |
24 | #include <QPieSlice> |
|
24 | #include <QPieSlice> | |
25 | #include <QDebug> |
|
25 | #include <QDebug> | |
26 |
|
26 | |||
27 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
27 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
28 |
|
28 | |||
29 | QPieLegendMarker::QPieLegendMarker(QPieSeries* series, QPieSlice* slice, QLegend *legend, QObject *parent) : |
|
29 | QPieLegendMarker::QPieLegendMarker(QPieSeries* series, QPieSlice* slice, QLegend *legend, QObject *parent) : | |
30 | QLegendMarker(*new QPieLegendMarkerPrivate(this,series,slice,legend), parent) |
|
30 | QLegendMarker(*new QPieLegendMarkerPrivate(this,series,slice,legend), parent) | |
31 | { |
|
31 | { | |
32 | } |
|
32 | } | |
33 |
|
33 | |||
34 | QPieLegendMarker::~QPieLegendMarker() |
|
34 | QPieLegendMarker::~QPieLegendMarker() | |
35 | { |
|
35 | { | |
36 | // qDebug() << "deleting pie marker" << this; |
|
36 | // qDebug() << "deleting pie marker" << this; | |
37 | } |
|
37 | } | |
38 |
|
38 | |||
39 | /*! |
|
39 | /*! | |
40 | \internal |
|
40 | \internal | |
41 | */ |
|
41 | */ | |
42 | QPieLegendMarker::QPieLegendMarker(QPieLegendMarkerPrivate &d, QObject *parent) : |
|
42 | QPieLegendMarker::QPieLegendMarker(QPieLegendMarkerPrivate &d, QObject *parent) : | |
43 | QLegendMarker(d, parent) |
|
43 | QLegendMarker(d, parent) | |
44 | { |
|
44 | { | |
45 | } |
|
45 | } | |
46 |
|
46 | |||
47 | QPieSeries* QPieLegendMarker::series() |
|
47 | QPieSeries* QPieLegendMarker::series() | |
48 | { |
|
48 | { | |
49 | Q_D(QPieLegendMarker); |
|
49 | Q_D(QPieLegendMarker); | |
50 | return d->m_series; |
|
50 | return d->m_series; | |
51 | } |
|
51 | } | |
52 |
|
52 | |||
53 | QPieSlice* QPieLegendMarker::slice() |
|
53 | QPieSlice* QPieLegendMarker::slice() | |
54 | { |
|
54 | { | |
55 | Q_D(QPieLegendMarker); |
|
55 | Q_D(QPieLegendMarker); | |
56 | return d->m_slice; |
|
56 | return d->m_slice; | |
57 | } |
|
57 | } | |
58 |
|
58 | |||
59 | //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
|
59 | //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// | |
60 |
|
60 | |||
61 | QPieLegendMarkerPrivate::QPieLegendMarkerPrivate(QPieLegendMarker *q, QPieSeries *series, QPieSlice *slice, QLegend *legend) : |
|
61 | QPieLegendMarkerPrivate::QPieLegendMarkerPrivate(QPieLegendMarker *q, QPieSeries *series, QPieSlice *slice, QLegend *legend) : | |
62 | QLegendMarkerPrivate(q,legend), |
|
62 | QLegendMarkerPrivate(q,legend), | |
63 | m_series(series), |
|
63 | m_series(series), | |
64 | m_slice(slice) |
|
64 | m_slice(slice) | |
65 | { |
|
65 | { | |
66 | QObject::connect(m_slice, SIGNAL(labelChanged()), this, SLOT(updated())); |
|
66 | QObject::connect(m_slice, SIGNAL(labelChanged()), this, SLOT(updated())); | |
67 | QObject::connect(m_slice, SIGNAL(brushChanged()), this, SLOT(updated())); |
|
67 | QObject::connect(m_slice, SIGNAL(brushChanged()), this, SLOT(updated())); | |
68 | QObject::connect(m_slice, SIGNAL(penChanged()), this, SLOT(updated())); |
|
68 | QObject::connect(m_slice, SIGNAL(penChanged()), this, SLOT(updated())); | |
69 | updated(); |
|
69 | updated(); | |
70 | } |
|
70 | } | |
71 |
|
71 | |||
72 | QPieLegendMarkerPrivate::~QPieLegendMarkerPrivate() |
|
72 | QPieLegendMarkerPrivate::~QPieLegendMarkerPrivate() | |
73 | { |
|
73 | { | |
74 | QObject::disconnect(m_slice, SIGNAL(labelChanged()), this, SLOT(updated())); |
|
|||
75 | QObject::disconnect(m_slice, SIGNAL(brushChanged()), this, SLOT(updated())); |
|
|||
76 | QObject::disconnect(m_slice, SIGNAL(penChanged()), this, SLOT(updated())); |
|
|||
77 | } |
|
74 | } | |
78 |
|
75 | |||
79 | QPieSeries* QPieLegendMarkerPrivate::series() |
|
76 | QPieSeries* QPieLegendMarkerPrivate::series() | |
80 | { |
|
77 | { | |
81 | return m_series; |
|
78 | return m_series; | |
82 | } |
|
79 | } | |
83 |
|
80 | |||
84 | QObject* QPieLegendMarkerPrivate::relatedObject() |
|
81 | QObject* QPieLegendMarkerPrivate::relatedObject() | |
85 | { |
|
82 | { | |
86 | return m_slice; |
|
83 | return m_slice; | |
87 | } |
|
84 | } | |
88 |
|
85 | |||
89 | void QPieLegendMarkerPrivate::updated() |
|
86 | void QPieLegendMarkerPrivate::updated() | |
90 | { |
|
87 | { | |
91 | m_item->setPen(m_slice->pen()); |
|
88 | m_item->setPen(m_slice->pen()); | |
92 | m_item->setBrush(m_slice->brush()); |
|
89 | m_item->setBrush(m_slice->brush()); | |
93 | m_item->setLabel(m_slice->label()); |
|
90 | m_item->setLabel(m_slice->label()); | |
94 | } |
|
91 | } | |
95 |
|
92 | |||
96 | #include "moc_qpielegendmarker.cpp" |
|
93 | #include "moc_qpielegendmarker.cpp" | |
97 | #include "moc_qpielegendmarker_p.cpp" |
|
94 | #include "moc_qpielegendmarker_p.cpp" | |
98 |
|
95 | |||
99 | QTCOMMERCIALCHART_END_NAMESPACE |
|
96 | QTCOMMERCIALCHART_END_NAMESPACE |
@@ -1,95 +1,93 | |||||
1 | /**************************************************************************** |
|
1 | /**************************************************************************** | |
2 | ** |
|
2 | ** | |
3 | ** Copyright (C) 2012 Digia Plc |
|
3 | ** Copyright (C) 2012 Digia Plc | |
4 | ** All rights reserved. |
|
4 | ** All rights reserved. | |
5 | ** For any questions to Digia, please use contact form at http://qt.digia.com |
|
5 | ** For any questions to Digia, please use contact form at http://qt.digia.com | |
6 | ** |
|
6 | ** | |
7 | ** This file is part of the Qt Commercial Charts Add-on. |
|
7 | ** This file is part of the Qt Commercial Charts Add-on. | |
8 | ** |
|
8 | ** | |
9 | ** $QT_BEGIN_LICENSE$ |
|
9 | ** $QT_BEGIN_LICENSE$ | |
10 | ** Licensees holding valid Qt Commercial licenses may use this file in |
|
10 | ** Licensees holding valid Qt Commercial licenses may use this file in | |
11 | ** accordance with the Qt Commercial License Agreement provided with the |
|
11 | ** accordance with the Qt Commercial License Agreement provided with the | |
12 | ** Software or, alternatively, in accordance with the terms contained in |
|
12 | ** Software or, alternatively, in accordance with the terms contained in | |
13 | ** a written agreement between you and Digia. |
|
13 | ** a written agreement between you and Digia. | |
14 | ** |
|
14 | ** | |
15 | ** If you have questions regarding the use of this file, please use |
|
15 | ** If you have questions regarding the use of this file, please use | |
16 | ** contact form at http://qt.digia.com |
|
16 | ** contact form at http://qt.digia.com | |
17 | ** $QT_END_LICENSE$ |
|
17 | ** $QT_END_LICENSE$ | |
18 | ** |
|
18 | ** | |
19 | ****************************************************************************/ |
|
19 | ****************************************************************************/ | |
20 |
|
20 | |||
21 | #include "qxylegendmarker.h" |
|
21 | #include "qxylegendmarker.h" | |
22 | #include "qxylegendmarker_p.h" |
|
22 | #include "qxylegendmarker_p.h" | |
23 | #include "qxyseries_p.h" |
|
23 | #include "qxyseries_p.h" | |
24 | #include <QXYSeries> |
|
24 | #include <QXYSeries> | |
25 | #include <QDebug> |
|
25 | #include <QDebug> | |
26 |
|
26 | |||
27 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
27 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
28 |
|
28 | |||
29 | QXYLegendMarker::QXYLegendMarker(QXYSeries* series, QLegend *legend, QObject *parent) : |
|
29 | QXYLegendMarker::QXYLegendMarker(QXYSeries* series, QLegend *legend, QObject *parent) : | |
30 | QLegendMarker(*new QXYLegendMarkerPrivate(this,series,legend), parent) |
|
30 | QLegendMarker(*new QXYLegendMarkerPrivate(this,series,legend), parent) | |
31 | { |
|
31 | { | |
32 | } |
|
32 | } | |
33 |
|
33 | |||
34 | QXYLegendMarker::~QXYLegendMarker() |
|
34 | QXYLegendMarker::~QXYLegendMarker() | |
35 | { |
|
35 | { | |
36 | // qDebug() << "deleting xy marker" << this; |
|
36 | // qDebug() << "deleting xy marker" << this; | |
37 | } |
|
37 | } | |
38 |
|
38 | |||
39 | /*! |
|
39 | /*! | |
40 | \internal |
|
40 | \internal | |
41 | */ |
|
41 | */ | |
42 | QXYLegendMarker::QXYLegendMarker(QXYLegendMarkerPrivate &d, QObject *parent) : |
|
42 | QXYLegendMarker::QXYLegendMarker(QXYLegendMarkerPrivate &d, QObject *parent) : | |
43 | QLegendMarker(d, parent) |
|
43 | QLegendMarker(d, parent) | |
44 | { |
|
44 | { | |
45 | } |
|
45 | } | |
46 |
|
46 | |||
47 | QXYSeries* QXYLegendMarker::series() |
|
47 | QXYSeries* QXYLegendMarker::series() | |
48 | { |
|
48 | { | |
49 | Q_D(QXYLegendMarker); |
|
49 | Q_D(QXYLegendMarker); | |
50 | return d->m_series; |
|
50 | return d->m_series; | |
51 | } |
|
51 | } | |
52 |
|
52 | |||
53 | //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
|
53 | //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// | |
54 |
|
54 | |||
55 | QXYLegendMarkerPrivate::QXYLegendMarkerPrivate(QXYLegendMarker *q, QXYSeries *series, QLegend *legend) : |
|
55 | QXYLegendMarkerPrivate::QXYLegendMarkerPrivate(QXYLegendMarker *q, QXYSeries *series, QLegend *legend) : | |
56 | QLegendMarkerPrivate(q,legend), |
|
56 | QLegendMarkerPrivate(q,legend), | |
57 | m_series(series) |
|
57 | m_series(series) | |
58 | { |
|
58 | { | |
59 | QObject::connect(m_series, SIGNAL(nameChanged()), this, SLOT(updated())); |
|
59 | QObject::connect(m_series, SIGNAL(nameChanged()), this, SLOT(updated())); | |
60 | QObject::connect(m_series->d_func(), SIGNAL(updated()), this, SLOT(updated())); |
|
60 | QObject::connect(m_series->d_func(), SIGNAL(updated()), this, SLOT(updated())); | |
61 | updated(); |
|
61 | updated(); | |
62 | } |
|
62 | } | |
63 |
|
63 | |||
64 | QXYLegendMarkerPrivate::~QXYLegendMarkerPrivate() |
|
64 | QXYLegendMarkerPrivate::~QXYLegendMarkerPrivate() | |
65 | { |
|
65 | { | |
66 | QObject::disconnect(m_series->d_func(), SIGNAL(updated()), this, SLOT(updated())); |
|
|||
67 | QObject::disconnect(m_series, SIGNAL(nameChanged()), this, SLOT(updated())); |
|
|||
68 | } |
|
66 | } | |
69 |
|
67 | |||
70 | QAbstractSeries* QXYLegendMarkerPrivate::series() |
|
68 | QAbstractSeries* QXYLegendMarkerPrivate::series() | |
71 | { |
|
69 | { | |
72 | return m_series; |
|
70 | return m_series; | |
73 | } |
|
71 | } | |
74 |
|
72 | |||
75 | QObject* QXYLegendMarkerPrivate::relatedObject() |
|
73 | QObject* QXYLegendMarkerPrivate::relatedObject() | |
76 | { |
|
74 | { | |
77 | return m_series; |
|
75 | return m_series; | |
78 | } |
|
76 | } | |
79 |
|
77 | |||
80 | void QXYLegendMarkerPrivate::updated() |
|
78 | void QXYLegendMarkerPrivate::updated() | |
81 | { |
|
79 | { | |
82 | m_item->setLabel(m_series->name()); |
|
80 | m_item->setLabel(m_series->name()); | |
83 |
|
81 | |||
84 | if (m_series->type()== QAbstractSeries::SeriesTypeScatter) { |
|
82 | if (m_series->type()== QAbstractSeries::SeriesTypeScatter) { | |
85 | m_item->setBrush(m_series->brush()); |
|
83 | m_item->setBrush(m_series->brush()); | |
86 | } else { |
|
84 | } else { | |
87 | m_item->setBrush(QBrush(m_series->pen().color())); |
|
85 | m_item->setBrush(QBrush(m_series->pen().color())); | |
88 | } |
|
86 | } | |
89 | } |
|
87 | } | |
90 |
|
88 | |||
91 | #include "moc_qxylegendmarker.cpp" |
|
89 | #include "moc_qxylegendmarker.cpp" | |
92 | #include "moc_qxylegendmarker_p.cpp" |
|
90 | #include "moc_qxylegendmarker_p.cpp" | |
93 |
|
91 | |||
94 | QTCOMMERCIALCHART_END_NAMESPACE |
|
92 | QTCOMMERCIALCHART_END_NAMESPACE | |
95 |
|
93 |
General Comments 0
You need to be logged in to leave comments.
Login now