@@ -1,105 +1,99 | |||||
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 "qlineseries.h" |
|
21 | #include "qlineseries.h" | |
22 |
|
22 | |||
23 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
23 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
24 |
|
24 | |||
25 | /*! |
|
25 | /*! | |
26 | \class QLineSeries |
|
26 | \class QLineSeries | |
27 | \brief The QLineSeries class is used for making line charts. |
|
27 | \brief The QLineSeries class is used for making line charts. | |
28 |
|
28 | |||
29 | \mainclass |
|
29 | \mainclass | |
30 |
|
30 | |||
31 | A line chart is used to show information as a series of data points |
|
31 | A line chart is used to show information as a series of data points | |
32 | connected by straight lines. |
|
32 | connected by straight lines. | |
33 |
|
33 | |||
34 | \image linechart.png |
|
34 | \image linechart.png | |
35 |
|
35 | |||
36 | Creating basic line chart is simple: |
|
36 | Creating basic line chart is simple: | |
37 | \code |
|
37 | \code | |
38 | QLineSeries* series = new QLineSeries(); |
|
38 | QLineSeries* series = new QLineSeries(); | |
39 | series->append(0, 6); |
|
39 | series->append(0, 6); | |
40 | series->append(2, 4); |
|
40 | series->append(2, 4); | |
41 | ... |
|
41 | ... | |
42 | chartView->addSeries(series); |
|
42 | chartView->addSeries(series); | |
43 | \endcode |
|
43 | \endcode | |
44 | */ |
|
44 | */ | |
45 |
|
45 | |||
46 | /*! |
|
46 | /*! | |
47 | \fn virtual QSeriesType QLineSeries::type() const |
|
47 | \fn virtual QSeriesType QLineSeries::type() const | |
48 | \brief Returns type of series. |
|
48 | \brief Returns type of series. | |
49 | \sa QSeries, QSeriesType |
|
49 | \sa QSeries, QSeriesType | |
50 | */ |
|
50 | */ | |
51 |
|
51 | |||
52 | /*! |
|
52 | /*! | |
53 | \fn bool QLineSeries::pointsVisible() const |
|
53 | \fn bool QLineSeries::pointsVisible() const | |
54 | \brief Returns if the points are drawn for this series. |
|
54 | \brief Returns if the points are drawn for this series. | |
55 | \sa setPointsVisible() |
|
55 | \sa setPointsVisible() | |
56 | */ |
|
56 | */ | |
57 |
|
57 | |||
58 | /*! |
|
58 | /*! | |
59 | \fn QPen QLineSeries::linePen() const |
|
|||
60 | \brief Returns the pen used to draw line connecting points. |
|
|||
61 | \sa setPen() |
|
|||
62 | */ |
|
|||
63 |
|
||||
64 | /*! |
|
|||
65 | Constructs empty series object which is a child of \a parent. |
|
59 | Constructs empty series object which is a child of \a parent. | |
66 | When series object is added to QChartView or QChart instance ownerships is transfered. |
|
60 | When series object is added to QChartView or QChart instance ownerships is transfered. | |
67 | */ |
|
61 | */ | |
68 | QLineSeries::QLineSeries(QObject *parent) : QXYSeries(parent), |
|
62 | QLineSeries::QLineSeries(QObject *parent) : QXYSeries(parent), | |
69 | m_pointsVisible(false) |
|
63 | m_pointsVisible(false) | |
70 | { |
|
64 | { | |
71 |
|
65 | |||
72 | } |
|
66 | } | |
73 | /*! |
|
67 | /*! | |
74 | Destroys the object. Series added to QChartView or QChart instances are owned by those, |
|
68 | Destroys the object. Series added to QChartView or QChart instances are owned by those, | |
75 | and are deleted when mentioned object are destroyed. |
|
69 | and are deleted when mentioned object are destroyed. | |
76 | */ |
|
70 | */ | |
77 | QLineSeries::~QLineSeries() |
|
71 | QLineSeries::~QLineSeries() | |
78 | { |
|
72 | { | |
79 | } |
|
73 | } | |
80 |
|
74 | |||
81 | /*! |
|
75 | /*! | |
82 | Sets if data points are \a visible and should be drawn on line. |
|
76 | Sets if data points are \a visible and should be drawn on line. | |
83 | */ |
|
77 | */ | |
84 | void QLineSeries::setPointsVisible(bool visible) |
|
78 | void QLineSeries::setPointsVisible(bool visible) | |
85 | { |
|
79 | { | |
86 | if (m_pointsVisible != visible){ |
|
80 | if (m_pointsVisible != visible){ | |
87 | m_pointsVisible = visible; |
|
81 | m_pointsVisible = visible; | |
88 | emit QXYSeries::updated(); |
|
82 | emit QXYSeries::updated(); | |
89 | } |
|
83 | } | |
90 | } |
|
84 | } | |
91 |
|
85 | |||
92 |
|
86 | |||
93 | QDebug operator<< (QDebug debug, const QLineSeries series) |
|
87 | QDebug operator<< (QDebug debug, const QLineSeries series) | |
94 | { |
|
88 | { | |
95 | Q_ASSERT(series.m_x.size() == series.m_y.size()); |
|
89 | Q_ASSERT(series.m_x.size() == series.m_y.size()); | |
96 |
|
90 | |||
97 | int size = series.m_x.size(); |
|
91 | int size = series.m_x.size(); | |
98 |
|
92 | |||
99 | for (int i=0; i<size; i++) { |
|
93 | for (int i=0; i<size; i++) { | |
100 | debug.nospace() << "(" << series.m_x.at(i) << ','<< series.m_y.at(i) << ") "; |
|
94 | debug.nospace() << "(" << series.m_x.at(i) << ','<< series.m_y.at(i) << ") "; | |
101 | } |
|
95 | } | |
102 | return debug.space(); |
|
96 | return debug.space(); | |
103 | } |
|
97 | } | |
104 |
|
98 | |||
105 | QTCOMMERCIALCHART_END_NAMESPACE |
|
99 | QTCOMMERCIALCHART_END_NAMESPACE |
@@ -1,713 +1,721 | |||||
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 "qpieseries.h" |
|
21 | #include "qpieseries.h" | |
22 | #include "qpieseriesprivate_p.h" |
|
22 | #include "qpieseriesprivate_p.h" | |
23 | #include "qpieslice.h" |
|
23 | #include "qpieslice.h" | |
24 | #include "pieslicedata_p.h" |
|
24 | #include "pieslicedata_p.h" | |
25 | #include <QAbstractItemModel> |
|
25 | #include <QAbstractItemModel> | |
26 | #include <QDebug> |
|
26 | #include <QDebug> | |
27 |
|
27 | |||
28 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
28 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
29 |
|
29 | |||
30 | QPieSeriesPrivate::QPieSeriesPrivate(QPieSeries *parent) |
|
30 | QPieSeriesPrivate::QPieSeriesPrivate(QPieSeries *parent) | |
31 | :QObject(parent), |
|
31 | :QObject(parent), | |
32 | q_ptr(parent), |
|
32 | q_ptr(parent), | |
33 | m_pieRelativeHorPos(0.5), |
|
33 | m_pieRelativeHorPos(0.5), | |
34 | m_pieRelativeVerPos(0.5), |
|
34 | m_pieRelativeVerPos(0.5), | |
35 | m_pieRelativeSize(0.7), |
|
35 | m_pieRelativeSize(0.7), | |
36 | m_pieStartAngle(0), |
|
36 | m_pieStartAngle(0), | |
37 | m_pieEndAngle(360), |
|
37 | m_pieEndAngle(360), | |
38 | m_total(0), |
|
38 | m_total(0), | |
39 | m_mapValues(0), |
|
39 | m_mapValues(0), | |
40 | m_mapLabels(0), |
|
40 | m_mapLabels(0), | |
41 | m_mapOrientation(Qt::Horizontal) |
|
41 | m_mapOrientation(Qt::Horizontal) | |
42 | { |
|
42 | { | |
43 |
|
43 | |||
44 | } |
|
44 | } | |
45 |
|
45 | |||
46 | QPieSeriesPrivate::~QPieSeriesPrivate() |
|
46 | QPieSeriesPrivate::~QPieSeriesPrivate() | |
47 | { |
|
47 | { | |
48 |
|
48 | |||
49 | } |
|
49 | } | |
50 |
|
50 | |||
51 | void QPieSeriesPrivate::updateDerivativeData() |
|
51 | void QPieSeriesPrivate::updateDerivativeData() | |
52 | { |
|
52 | { | |
53 | m_total = 0; |
|
53 | m_total = 0; | |
54 |
|
54 | |||
55 | // nothing to do? |
|
55 | // nothing to do? | |
56 | if (m_slices.count() == 0) |
|
56 | if (m_slices.count() == 0) | |
57 | return; |
|
57 | return; | |
58 |
|
58 | |||
59 | // calculate total |
|
59 | // calculate total | |
60 | foreach (QPieSlice* s, m_slices) |
|
60 | foreach (QPieSlice* s, m_slices) | |
61 | m_total += s->value(); |
|
61 | m_total += s->value(); | |
62 |
|
62 | |||
63 | // nothing to show.. |
|
63 | // nothing to show.. | |
64 | if (qFuzzyIsNull(m_total)) |
|
64 | if (qFuzzyIsNull(m_total)) | |
65 | return; |
|
65 | return; | |
66 |
|
66 | |||
67 | // update slice attributes |
|
67 | // update slice attributes | |
68 | qreal sliceAngle = m_pieStartAngle; |
|
68 | qreal sliceAngle = m_pieStartAngle; | |
69 | qreal pieSpan = m_pieEndAngle - m_pieStartAngle; |
|
69 | qreal pieSpan = m_pieEndAngle - m_pieStartAngle; | |
70 | QVector<QPieSlice*> changed; |
|
70 | QVector<QPieSlice*> changed; | |
71 | foreach (QPieSlice* s, m_slices) { |
|
71 | foreach (QPieSlice* s, m_slices) { | |
72 |
|
72 | |||
73 | PieSliceData data = PieSliceData::data(s); |
|
73 | PieSliceData data = PieSliceData::data(s); | |
74 | data.m_percentage = s->value() / m_total; |
|
74 | data.m_percentage = s->value() / m_total; | |
75 | data.m_angleSpan = pieSpan * data.m_percentage; |
|
75 | data.m_angleSpan = pieSpan * data.m_percentage; | |
76 | data.m_startAngle = sliceAngle; |
|
76 | data.m_startAngle = sliceAngle; | |
77 | sliceAngle += data.m_angleSpan; |
|
77 | sliceAngle += data.m_angleSpan; | |
78 |
|
78 | |||
79 | if (PieSliceData::data(s) != data) { |
|
79 | if (PieSliceData::data(s) != data) { | |
80 | PieSliceData::data(s) = data; |
|
80 | PieSliceData::data(s) = data; | |
81 | changed << s; |
|
81 | changed << s; | |
82 | } |
|
82 | } | |
83 | } |
|
83 | } | |
84 |
|
84 | |||
85 | // emit signals |
|
85 | // emit signals | |
86 | foreach (QPieSlice* s, changed) |
|
86 | foreach (QPieSlice* s, changed) | |
87 | PieSliceData::data(s).emitChangedSignal(s); |
|
87 | PieSliceData::data(s).emitChangedSignal(s); | |
88 | } |
|
88 | } | |
89 |
|
89 | |||
90 | void QPieSeriesPrivate::sliceChanged() |
|
90 | void QPieSeriesPrivate::sliceChanged() | |
91 | { |
|
91 | { | |
92 | Q_ASSERT(m_slices.contains(qobject_cast<QPieSlice *>(sender()))); |
|
92 | Q_ASSERT(m_slices.contains(qobject_cast<QPieSlice *>(sender()))); | |
93 | updateDerivativeData(); |
|
93 | updateDerivativeData(); | |
94 | } |
|
94 | } | |
95 |
|
95 | |||
96 | void QPieSeriesPrivate::sliceClicked(Qt::MouseButtons buttons) |
|
96 | void QPieSeriesPrivate::sliceClicked(Qt::MouseButtons buttons) | |
97 | { |
|
97 | { | |
98 | QPieSlice* slice = qobject_cast<QPieSlice *>(sender()); |
|
98 | QPieSlice* slice = qobject_cast<QPieSlice *>(sender()); | |
99 | Q_ASSERT(m_slices.contains(slice)); |
|
99 | Q_ASSERT(m_slices.contains(slice)); | |
100 | Q_Q(QPieSeries); |
|
100 | Q_Q(QPieSeries); | |
101 | emit q->clicked(slice, buttons); |
|
101 | emit q->clicked(slice, buttons); | |
102 | } |
|
102 | } | |
103 |
|
103 | |||
104 | void QPieSeriesPrivate::sliceHoverEnter() |
|
104 | void QPieSeriesPrivate::sliceHoverEnter() | |
105 | { |
|
105 | { | |
106 | QPieSlice* slice = qobject_cast<QPieSlice *>(sender()); |
|
106 | QPieSlice* slice = qobject_cast<QPieSlice *>(sender()); | |
107 | Q_ASSERT(m_slices.contains(slice)); |
|
107 | Q_ASSERT(m_slices.contains(slice)); | |
108 | Q_Q(QPieSeries); |
|
108 | Q_Q(QPieSeries); | |
109 | emit q->hoverEnter(slice); |
|
109 | emit q->hoverEnter(slice); | |
110 | } |
|
110 | } | |
111 |
|
111 | |||
112 | void QPieSeriesPrivate::sliceHoverLeave() |
|
112 | void QPieSeriesPrivate::sliceHoverLeave() | |
113 | { |
|
113 | { | |
114 | QPieSlice* slice = qobject_cast<QPieSlice *>(sender()); |
|
114 | QPieSlice* slice = qobject_cast<QPieSlice *>(sender()); | |
115 | Q_ASSERT(m_slices.contains(slice)); |
|
115 | Q_ASSERT(m_slices.contains(slice)); | |
116 | Q_Q(QPieSeries); |
|
116 | Q_Q(QPieSeries); | |
117 | emit q->hoverLeave(slice); |
|
117 | emit q->hoverLeave(slice); | |
118 | } |
|
118 | } | |
119 |
|
119 | |||
120 | void QPieSeriesPrivate::modelUpdated(QModelIndex topLeft, QModelIndex bottomRight) |
|
120 | void QPieSeriesPrivate::modelUpdated(QModelIndex topLeft, QModelIndex bottomRight) | |
121 | { |
|
121 | { | |
122 | Q_UNUSED(bottomRight) |
|
122 | Q_UNUSED(bottomRight) | |
123 | Q_Q(QPieSeries); |
|
123 | Q_Q(QPieSeries); | |
124 |
|
124 | |||
125 | if (m_mapOrientation == Qt::Vertical) |
|
125 | if (m_mapOrientation == Qt::Vertical) | |
126 | { |
|
126 | { | |
127 | if (topLeft.column() == m_mapValues) |
|
127 | if (topLeft.column() == m_mapValues) | |
128 | if (m_mapValues == m_mapLabels) |
|
128 | if (m_mapValues == m_mapLabels) | |
129 | { |
|
129 | { | |
130 | m_slices.at(topLeft.row())->setValue(q->m_model->data(topLeft, Qt::DisplayRole).toDouble()); |
|
130 | m_slices.at(topLeft.row())->setValue(q->m_model->data(topLeft, Qt::DisplayRole).toDouble()); | |
131 | m_slices.at(topLeft.row())->setLabel(q->m_model->data(topLeft, Qt::DisplayRole).toString()); |
|
131 | m_slices.at(topLeft.row())->setLabel(q->m_model->data(topLeft, Qt::DisplayRole).toString()); | |
132 | } |
|
132 | } | |
133 | else |
|
133 | else | |
134 | { |
|
134 | { | |
135 | m_slices.at(topLeft.row())->setValue(q->m_model->data(topLeft, Qt::DisplayRole).toDouble()); |
|
135 | m_slices.at(topLeft.row())->setValue(q->m_model->data(topLeft, Qt::DisplayRole).toDouble()); | |
136 | } |
|
136 | } | |
137 | else if (topLeft.column() == m_mapLabels) |
|
137 | else if (topLeft.column() == m_mapLabels) | |
138 | m_slices.at(topLeft.row())->setLabel(q->m_model->data(topLeft, Qt::DisplayRole).toString()); |
|
138 | m_slices.at(topLeft.row())->setLabel(q->m_model->data(topLeft, Qt::DisplayRole).toString()); | |
139 | } |
|
139 | } | |
140 | else |
|
140 | else | |
141 | { |
|
141 | { | |
142 | if (topLeft.row() == m_mapValues) |
|
142 | if (topLeft.row() == m_mapValues) | |
143 | if (m_mapValues == m_mapLabels) |
|
143 | if (m_mapValues == m_mapLabels) | |
144 | { |
|
144 | { | |
145 | m_slices.at(topLeft.column())->setValue(q->m_model->data(topLeft, Qt::DisplayRole).toDouble()); |
|
145 | m_slices.at(topLeft.column())->setValue(q->m_model->data(topLeft, Qt::DisplayRole).toDouble()); | |
146 | m_slices.at(topLeft.column())->setLabel(q->m_model->data(topLeft, Qt::DisplayRole).toString()); |
|
146 | m_slices.at(topLeft.column())->setLabel(q->m_model->data(topLeft, Qt::DisplayRole).toString()); | |
147 | } |
|
147 | } | |
148 | else |
|
148 | else | |
149 | { |
|
149 | { | |
150 | m_slices.at(topLeft.column())->setValue(q->m_model->data(topLeft, Qt::DisplayRole).toDouble()); |
|
150 | m_slices.at(topLeft.column())->setValue(q->m_model->data(topLeft, Qt::DisplayRole).toDouble()); | |
151 | } |
|
151 | } | |
152 | else if (topLeft.row() == m_mapLabels) |
|
152 | else if (topLeft.row() == m_mapLabels) | |
153 | m_slices.at(topLeft.column())->setLabel(q->m_model->data(topLeft, Qt::DisplayRole).toString()); |
|
153 | m_slices.at(topLeft.column())->setLabel(q->m_model->data(topLeft, Qt::DisplayRole).toString()); | |
154 | } |
|
154 | } | |
155 | } |
|
155 | } | |
156 |
|
156 | |||
157 | void QPieSeriesPrivate::modelDataAdded(QModelIndex parent, int start, int end) |
|
157 | void QPieSeriesPrivate::modelDataAdded(QModelIndex parent, int start, int end) | |
158 | { |
|
158 | { | |
159 | Q_UNUSED(parent) |
|
159 | Q_UNUSED(parent) | |
160 | Q_UNUSED(end) |
|
160 | Q_UNUSED(end) | |
161 | Q_Q(QPieSeries); |
|
161 | Q_Q(QPieSeries); | |
162 |
|
162 | |||
163 | QPieSlice* newSlice = new QPieSlice; |
|
163 | QPieSlice* newSlice = new QPieSlice; | |
164 | newSlice->setLabelVisible(true); |
|
164 | newSlice->setLabelVisible(true); | |
165 | if (m_mapOrientation == Qt::Vertical) |
|
165 | if (m_mapOrientation == Qt::Vertical) | |
166 | { |
|
166 | { | |
167 | newSlice->setValue(q->m_model->data(q->m_model->index(start, m_mapValues), Qt::DisplayRole).toDouble()); |
|
167 | newSlice->setValue(q->m_model->data(q->m_model->index(start, m_mapValues), Qt::DisplayRole).toDouble()); | |
168 | newSlice->setLabel(q->m_model->data(q->m_model->index(start, m_mapLabels), Qt::DisplayRole).toString()); |
|
168 | newSlice->setLabel(q->m_model->data(q->m_model->index(start, m_mapLabels), Qt::DisplayRole).toString()); | |
169 | } |
|
169 | } | |
170 | else |
|
170 | else | |
171 | { |
|
171 | { | |
172 | newSlice->setValue(q->m_model->data(q->m_model->index(m_mapValues, start), Qt::DisplayRole).toDouble()); |
|
172 | newSlice->setValue(q->m_model->data(q->m_model->index(m_mapValues, start), Qt::DisplayRole).toDouble()); | |
173 | newSlice->setLabel(q->m_model->data(q->m_model->index(m_mapLabels, start), Qt::DisplayRole).toString()); |
|
173 | newSlice->setLabel(q->m_model->data(q->m_model->index(m_mapLabels, start), Qt::DisplayRole).toString()); | |
174 | } |
|
174 | } | |
175 |
|
175 | |||
176 | q->insert(start, newSlice); |
|
176 | q->insert(start, newSlice); | |
177 | } |
|
177 | } | |
178 |
|
178 | |||
179 | void QPieSeriesPrivate::modelDataRemoved(QModelIndex parent, int start, int end) |
|
179 | void QPieSeriesPrivate::modelDataRemoved(QModelIndex parent, int start, int end) | |
180 | { |
|
180 | { | |
181 | Q_UNUSED(parent) |
|
181 | Q_UNUSED(parent) | |
182 | Q_UNUSED(end) |
|
182 | Q_UNUSED(end) | |
183 | Q_Q(QPieSeries); |
|
183 | Q_Q(QPieSeries); | |
184 | q->remove(m_slices.at(start)); |
|
184 | q->remove(m_slices.at(start)); | |
185 | } |
|
185 | } | |
186 |
|
186 | |||
187 | bool QPieSeriesPrivate::setRealValue(qreal &value, qreal newValue, qreal max, qreal min) |
|
187 | bool QPieSeriesPrivate::setRealValue(qreal &value, qreal newValue, qreal max, qreal min) | |
188 | { |
|
188 | { | |
189 | // Remove rounding errors |
|
189 | // Remove rounding errors | |
190 | qreal roundedValue = newValue; |
|
190 | qreal roundedValue = newValue; | |
191 | if (qFuzzyIsNull(min) && qFuzzyIsNull(newValue)) |
|
191 | if (qFuzzyIsNull(min) && qFuzzyIsNull(newValue)) | |
192 | roundedValue = 0.0; |
|
192 | roundedValue = 0.0; | |
193 | else if (qFuzzyCompare(newValue, max)) |
|
193 | else if (qFuzzyCompare(newValue, max)) | |
194 | roundedValue = max; |
|
194 | roundedValue = max; | |
195 | else if (qFuzzyCompare(newValue, min)) |
|
195 | else if (qFuzzyCompare(newValue, min)) | |
196 | roundedValue = min; |
|
196 | roundedValue = min; | |
197 |
|
197 | |||
198 | // Check if the position is valid after removing the rounding errors |
|
198 | // Check if the position is valid after removing the rounding errors | |
199 | if (roundedValue < min || roundedValue > max) { |
|
199 | if (roundedValue < min || roundedValue > max) { | |
200 | qWarning("QPieSeries: Illegal value"); |
|
200 | qWarning("QPieSeries: Illegal value"); | |
201 | return false; |
|
201 | return false; | |
202 | } |
|
202 | } | |
203 |
|
203 | |||
204 | if (!qFuzzyIsNull(value - roundedValue)) { |
|
204 | if (!qFuzzyIsNull(value - roundedValue)) { | |
205 | value = roundedValue; |
|
205 | value = roundedValue; | |
206 | return true; |
|
206 | return true; | |
207 | } |
|
207 | } | |
208 |
|
208 | |||
209 | // The change was so small it is considered a rounding error |
|
209 | // The change was so small it is considered a rounding error | |
210 | return false; |
|
210 | return false; | |
211 | } |
|
211 | } | |
212 |
|
212 | |||
213 |
|
213 | |||
214 |
|
214 | |||
215 | /*! |
|
215 | /*! | |
216 | \class QPieSeries |
|
216 | \class QPieSeries | |
217 | \brief Pie series API for QtCommercial Charts |
|
217 | \brief Pie series API for QtCommercial Charts | |
218 |
|
218 | |||
219 | The pie series defines a pie chart which consists of pie slices which are QPieSlice objects. |
|
219 | The pie series defines a pie chart which consists of pie slices which are QPieSlice objects. | |
220 | The slices can have any values as the QPieSeries will calculate its relative value to the sum of all slices. |
|
220 | The slices can have any values as the QPieSeries will calculate its relative value to the sum of all slices. | |
221 | The actual slice size is determined by that relative value. |
|
221 | The actual slice size is determined by that relative value. | |
222 |
|
222 | |||
223 | By default the pie is defined as a full pie but it can be a partial pie. |
|
223 | By default the pie is defined as a full pie but it can be a partial pie. | |
224 | This can be done by setting a starting angle and angle span to the series. |
|
224 | This can be done by setting a starting angle and angle span to the series. | |
225 | */ |
|
225 | */ | |
226 |
|
226 | |||
227 | /*! |
|
227 | /*! | |
|
228 | \property qreal QPieSeries::horizontalPosition | |||
|
229 | \brief Pie horizontal postion property | |||
|
230 | ||||
|
231 | By default horizontal postion is 0 | |||
|
232 | */ | |||
|
233 | ||||
|
234 | ||||
|
235 | /*! | |||
228 | Constructs a series object which is a child of \a parent. |
|
236 | Constructs a series object which is a child of \a parent. | |
229 | */ |
|
237 | */ | |
230 | QPieSeries::QPieSeries(QObject *parent) : |
|
238 | QPieSeries::QPieSeries(QObject *parent) : | |
231 | QSeries(parent), |
|
239 | QSeries(parent), | |
232 | d_ptr(new QPieSeriesPrivate(this)) |
|
240 | d_ptr(new QPieSeriesPrivate(this)) | |
233 | { |
|
241 | { | |
234 |
|
242 | |||
235 | } |
|
243 | } | |
236 |
|
244 | |||
237 | /*! |
|
245 | /*! | |
238 | Destroys the object. Note that adding series to QChart transfers the ownership to the chart. |
|
246 | Destroys the object. Note that adding series to QChart transfers the ownership to the chart. | |
239 | */ |
|
247 | */ | |
240 | QPieSeries::~QPieSeries() |
|
248 | QPieSeries::~QPieSeries() | |
241 | { |
|
249 | { | |
242 | // NOTE: d_prt destroyed by QObject |
|
250 | // NOTE: d_prt destroyed by QObject | |
243 | } |
|
251 | } | |
244 |
|
252 | |||
245 | /*! |
|
253 | /*! | |
246 | Returns QChartSeries::SeriesTypePie. |
|
254 | Returns QChartSeries::SeriesTypePie. | |
247 | */ |
|
255 | */ | |
248 | QSeries::QSeriesType QPieSeries::type() const |
|
256 | QSeries::QSeriesType QPieSeries::type() const | |
249 | { |
|
257 | { | |
250 | return QSeries::SeriesTypePie; |
|
258 | return QSeries::SeriesTypePie; | |
251 | } |
|
259 | } | |
252 |
|
260 | |||
253 | /*! |
|
261 | /*! | |
254 | Sets an array of \a slices to the series replacing the existing slices. |
|
262 | Sets an array of \a slices to the series replacing the existing slices. | |
255 | Slice ownership is passed to the series. |
|
263 | Slice ownership is passed to the series. | |
256 | */ |
|
264 | */ | |
257 | void QPieSeries::replace(QList<QPieSlice*> slices) |
|
265 | void QPieSeries::replace(QList<QPieSlice*> slices) | |
258 | { |
|
266 | { | |
259 | clear(); |
|
267 | clear(); | |
260 | append(slices); |
|
268 | append(slices); | |
261 | } |
|
269 | } | |
262 |
|
270 | |||
263 | /*! |
|
271 | /*! | |
264 | Adds an array of \a slices to the series. |
|
272 | Adds an array of \a slices to the series. | |
265 | Slice ownership is passed to the series. |
|
273 | Slice ownership is passed to the series. | |
266 | */ |
|
274 | */ | |
267 | void QPieSeries::append(QList<QPieSlice*> slices) |
|
275 | void QPieSeries::append(QList<QPieSlice*> slices) | |
268 | { |
|
276 | { | |
269 | Q_D(QPieSeries); |
|
277 | Q_D(QPieSeries); | |
270 |
|
278 | |||
271 | foreach (QPieSlice* s, slices) { |
|
279 | foreach (QPieSlice* s, slices) { | |
272 | s->setParent(this); |
|
280 | s->setParent(this); | |
273 | d->m_slices << s; |
|
281 | d->m_slices << s; | |
274 | } |
|
282 | } | |
275 |
|
283 | |||
276 | d->updateDerivativeData(); |
|
284 | d->updateDerivativeData(); | |
277 |
|
285 | |||
278 | foreach (QPieSlice* s, slices) { |
|
286 | foreach (QPieSlice* s, slices) { | |
279 | connect(s, SIGNAL(changed()), d, SLOT(sliceChanged())); |
|
287 | connect(s, SIGNAL(changed()), d, SLOT(sliceChanged())); | |
280 | connect(s, SIGNAL(clicked(Qt::MouseButtons)), d, SLOT(sliceClicked(Qt::MouseButtons))); |
|
288 | connect(s, SIGNAL(clicked(Qt::MouseButtons)), d, SLOT(sliceClicked(Qt::MouseButtons))); | |
281 | connect(s, SIGNAL(hoverEnter()), d, SLOT(sliceHoverEnter())); |
|
289 | connect(s, SIGNAL(hoverEnter()), d, SLOT(sliceHoverEnter())); | |
282 | connect(s, SIGNAL(hoverLeave()), d, SLOT(sliceHoverLeave())); |
|
290 | connect(s, SIGNAL(hoverLeave()), d, SLOT(sliceHoverLeave())); | |
283 | } |
|
291 | } | |
284 |
|
292 | |||
285 | emit added(slices); |
|
293 | emit added(slices); | |
286 | } |
|
294 | } | |
287 |
|
295 | |||
288 | /*! |
|
296 | /*! | |
289 | Adds a single \a slice to the series. |
|
297 | Adds a single \a slice to the series. | |
290 | Slice ownership is passed to the series. |
|
298 | Slice ownership is passed to the series. | |
291 | */ |
|
299 | */ | |
292 | void QPieSeries::append(QPieSlice* slice) |
|
300 | void QPieSeries::append(QPieSlice* slice) | |
293 | { |
|
301 | { | |
294 | append(QList<QPieSlice*>() << slice); |
|
302 | append(QList<QPieSlice*>() << slice); | |
295 | } |
|
303 | } | |
296 |
|
304 | |||
297 | /*! |
|
305 | /*! | |
298 | Adds a single \a slice to the series and returns a reference to the series. |
|
306 | Adds a single \a slice to the series and returns a reference to the series. | |
299 | Slice ownership is passed to the series. |
|
307 | Slice ownership is passed to the series. | |
300 | */ |
|
308 | */ | |
301 | QPieSeries& QPieSeries::operator << (QPieSlice* slice) |
|
309 | QPieSeries& QPieSeries::operator << (QPieSlice* slice) | |
302 | { |
|
310 | { | |
303 | append(slice); |
|
311 | append(slice); | |
304 | return *this; |
|
312 | return *this; | |
305 | } |
|
313 | } | |
306 |
|
314 | |||
307 |
|
315 | |||
308 | /*! |
|
316 | /*! | |
309 | Appends a single slice to the series with give \a value and \a name. |
|
317 | Appends a single slice to the series with give \a value and \a name. | |
310 | Slice ownership is passed to the series. |
|
318 | Slice ownership is passed to the series. | |
311 | */ |
|
319 | */ | |
312 | QPieSlice* QPieSeries::append(qreal value, QString name) |
|
320 | QPieSlice* QPieSeries::append(qreal value, QString name) | |
313 | { |
|
321 | { | |
314 | QPieSlice* slice = new QPieSlice(value, name); |
|
322 | QPieSlice* slice = new QPieSlice(value, name); | |
315 | append(slice); |
|
323 | append(slice); | |
316 | return slice; |
|
324 | return slice; | |
317 | } |
|
325 | } | |
318 |
|
326 | |||
319 | /*! |
|
327 | /*! | |
320 | Inserts a single \a slice to the series before the slice at \a index position. |
|
328 | Inserts a single \a slice to the series before the slice at \a index position. | |
321 | Slice ownership is passed to the series. |
|
329 | Slice ownership is passed to the series. | |
322 | */ |
|
330 | */ | |
323 | void QPieSeries::insert(int index, QPieSlice* slice) |
|
331 | void QPieSeries::insert(int index, QPieSlice* slice) | |
324 | { |
|
332 | { | |
325 | Q_D(QPieSeries); |
|
333 | Q_D(QPieSeries); | |
326 | Q_ASSERT(index <= d->m_slices.count()); |
|
334 | Q_ASSERT(index <= d->m_slices.count()); | |
327 | slice->setParent(this); |
|
335 | slice->setParent(this); | |
328 | d->m_slices.insert(index, slice); |
|
336 | d->m_slices.insert(index, slice); | |
329 |
|
337 | |||
330 | d->updateDerivativeData(); |
|
338 | d->updateDerivativeData(); | |
331 |
|
339 | |||
332 | connect(slice, SIGNAL(changed()), d, SLOT(sliceChanged())); |
|
340 | connect(slice, SIGNAL(changed()), d, SLOT(sliceChanged())); | |
333 | connect(slice, SIGNAL(clicked(Qt::MouseButtons)), d, SLOT(sliceClicked(Qt::MouseButtons))); |
|
341 | connect(slice, SIGNAL(clicked(Qt::MouseButtons)), d, SLOT(sliceClicked(Qt::MouseButtons))); | |
334 | connect(slice, SIGNAL(hoverEnter()), d, SLOT(sliceHoverEnter())); |
|
342 | connect(slice, SIGNAL(hoverEnter()), d, SLOT(sliceHoverEnter())); | |
335 | connect(slice, SIGNAL(hoverLeave()), d, SLOT(sliceHoverLeave())); |
|
343 | connect(slice, SIGNAL(hoverLeave()), d, SLOT(sliceHoverLeave())); | |
336 |
|
344 | |||
337 | emit added(QList<QPieSlice*>() << slice); |
|
345 | emit added(QList<QPieSlice*>() << slice); | |
338 | } |
|
346 | } | |
339 |
|
347 | |||
340 | /*! |
|
348 | /*! | |
341 | Removes a single \a slice from the series and deletes the slice. |
|
349 | Removes a single \a slice from the series and deletes the slice. | |
342 |
|
350 | |||
343 | Do not reference this pointer after this call. |
|
351 | Do not reference this pointer after this call. | |
344 | */ |
|
352 | */ | |
345 | void QPieSeries::remove(QPieSlice* slice) |
|
353 | void QPieSeries::remove(QPieSlice* slice) | |
346 | { |
|
354 | { | |
347 | Q_D(QPieSeries); |
|
355 | Q_D(QPieSeries); | |
348 | if (!d->m_slices.removeOne(slice)) { |
|
356 | if (!d->m_slices.removeOne(slice)) { | |
349 | Q_ASSERT(0); // TODO: how should this be reported? |
|
357 | Q_ASSERT(0); // TODO: how should this be reported? | |
350 | return; |
|
358 | return; | |
351 | } |
|
359 | } | |
352 |
|
360 | |||
353 | d->updateDerivativeData(); |
|
361 | d->updateDerivativeData(); | |
354 |
|
362 | |||
355 | emit removed(QList<QPieSlice*>() << slice); |
|
363 | emit removed(QList<QPieSlice*>() << slice); | |
356 |
|
364 | |||
357 | delete slice; |
|
365 | delete slice; | |
358 | slice = 0; |
|
366 | slice = 0; | |
359 | } |
|
367 | } | |
360 |
|
368 | |||
361 | /*! |
|
369 | /*! | |
362 | Clears all slices from the series. |
|
370 | Clears all slices from the series. | |
363 | */ |
|
371 | */ | |
364 | void QPieSeries::clear() |
|
372 | void QPieSeries::clear() | |
365 | { |
|
373 | { | |
366 | Q_D(QPieSeries); |
|
374 | Q_D(QPieSeries); | |
367 | if (d->m_slices.count() == 0) |
|
375 | if (d->m_slices.count() == 0) | |
368 | return; |
|
376 | return; | |
369 |
|
377 | |||
370 | QList<QPieSlice*> slices = d->m_slices; |
|
378 | QList<QPieSlice*> slices = d->m_slices; | |
371 | foreach (QPieSlice* s, d->m_slices) { |
|
379 | foreach (QPieSlice* s, d->m_slices) { | |
372 | d->m_slices.removeOne(s); |
|
380 | d->m_slices.removeOne(s); | |
373 | delete s; |
|
381 | delete s; | |
374 | } |
|
382 | } | |
375 |
|
383 | |||
376 | d->updateDerivativeData(); |
|
384 | d->updateDerivativeData(); | |
377 |
|
385 | |||
378 | emit removed(slices); |
|
386 | emit removed(slices); | |
379 | } |
|
387 | } | |
380 |
|
388 | |||
381 | /*! |
|
389 | /*! | |
382 | Counts the number of the slices in this series. |
|
390 | Counts the number of the slices in this series. | |
383 | */ |
|
391 | */ | |
384 | int QPieSeries::count() const |
|
392 | int QPieSeries::count() const | |
385 | { |
|
393 | { | |
386 | Q_D(const QPieSeries); |
|
394 | Q_D(const QPieSeries); | |
387 | return d->m_slices.count(); |
|
395 | return d->m_slices.count(); | |
388 | } |
|
396 | } | |
389 |
|
397 | |||
390 | /*! |
|
398 | /*! | |
391 | Returns true is the series is empty. |
|
399 | Returns true is the series is empty. | |
392 | */ |
|
400 | */ | |
393 | bool QPieSeries::isEmpty() const |
|
401 | bool QPieSeries::isEmpty() const | |
394 | { |
|
402 | { | |
395 | Q_D(const QPieSeries); |
|
403 | Q_D(const QPieSeries); | |
396 | return d->m_slices.isEmpty(); |
|
404 | return d->m_slices.isEmpty(); | |
397 | } |
|
405 | } | |
398 |
|
406 | |||
399 | /*! |
|
407 | /*! | |
400 | Returns a list of slices that belong to this series. |
|
408 | Returns a list of slices that belong to this series. | |
401 | */ |
|
409 | */ | |
402 | QList<QPieSlice*> QPieSeries::slices() const |
|
410 | QList<QPieSlice*> QPieSeries::slices() const | |
403 | { |
|
411 | { | |
404 | Q_D(const QPieSeries); |
|
412 | Q_D(const QPieSeries); | |
405 | return d->m_slices; |
|
413 | return d->m_slices; | |
406 | } |
|
414 | } | |
407 |
|
415 | |||
408 | /*! |
|
416 | /*! | |
409 | Sets the horizontal center position of the pie to \relativePosition. If \relativePosition is |
|
417 | Sets the horizontal center position of the pie to \a relativePosition. If \a relativePosition is | |
410 | set to 0.0 the pie is drawn on the left side of the chart and if it's set to 1.0 the pie is |
|
418 | set to 0.0 the pie is drawn on the left side of the chart and if it's set to 1.0 the pie is | |
411 | drawn on right side of the chart. The default value 0.5 puts the pie in the middle. |
|
419 | drawn on right side of the chart. The default value 0.5 puts the pie in the middle. | |
412 |
|
420 | |||
413 | \sa setHorizontalPosition(), setPieSize() |
|
421 | \sa setHorizontalPosition(), setPieSize() | |
414 | */ |
|
422 | */ | |
415 | void QPieSeries::setHorizontalPosition(qreal relativePosition) |
|
423 | void QPieSeries::setHorizontalPosition(qreal relativePosition) | |
416 | { |
|
424 | { | |
417 | Q_D(QPieSeries); |
|
425 | Q_D(QPieSeries); | |
418 | if (d->setRealValue(d->m_pieRelativeHorPos, relativePosition, 1.0)) |
|
426 | if (d->setRealValue(d->m_pieRelativeHorPos, relativePosition, 1.0)) | |
419 | emit piePositionChanged(); |
|
427 | emit piePositionChanged(); | |
420 | } |
|
428 | } | |
421 |
|
429 | |||
422 | /*! |
|
430 | /*! | |
423 | Sets the vertical center position of the pie to \relativePosition. If \relativePosition is |
|
431 | Sets the vertical center position of the pie to \a relativePosition. If \a relativePosition is | |
424 | set to 0.0 the pie is drawn on the top of the chart and if it's set to 1.0 the pie is drawn |
|
432 | set to 0.0 the pie is drawn on the top of the chart and if it's set to 1.0 the pie is drawn | |
425 | on bottom of the chart. The default value 0.5 puts the pie in the middle. |
|
433 | on bottom of the chart. The default value 0.5 puts the pie in the middle. | |
426 |
|
434 | |||
427 | \sa setVerticalPosition(), setPieSize() |
|
435 | \sa setVerticalPosition(), setPieSize() | |
428 | */ |
|
436 | */ | |
429 | void QPieSeries::setVerticalPosition(qreal relativePosition) |
|
437 | void QPieSeries::setVerticalPosition(qreal relativePosition) | |
430 | { |
|
438 | { | |
431 | Q_D(QPieSeries); |
|
439 | Q_D(QPieSeries); | |
432 | if (d->setRealValue(d->m_pieRelativeVerPos, relativePosition, 1.0)) |
|
440 | if (d->setRealValue(d->m_pieRelativeVerPos, relativePosition, 1.0)) | |
433 | emit piePositionChanged(); |
|
441 | emit piePositionChanged(); | |
434 | } |
|
442 | } | |
435 |
|
443 | |||
436 | /*! |
|
444 | /*! | |
437 | Gets the horizontal position of the pie. |
|
445 | Gets the horizontal position of the pie. | |
438 |
|
446 | |||
439 | The returned value is relative to the chart rectangle where: |
|
447 | The returned value is relative to the chart rectangle where: | |
440 |
|
448 | |||
441 | 0.0 means the absolute left. |
|
449 | 0.0 means the absolute left. | |
442 | 1.0 means the absolute right. |
|
450 | 1.0 means the absolute right. | |
443 |
|
451 | |||
444 | By default it is 0.5 which puts the pie in the horizontal middle of the chart rectangle. |
|
452 | By default it is 0.5 which puts the pie in the horizontal middle of the chart rectangle. | |
445 |
|
453 | |||
446 | \sa verticalPosition(), setPieSize() |
|
454 | \sa verticalPosition(), setPieSize() | |
447 | */ |
|
455 | */ | |
448 | qreal QPieSeries::horizontalPosition() const |
|
456 | qreal QPieSeries::horizontalPosition() const | |
449 | { |
|
457 | { | |
450 | Q_D(const QPieSeries); |
|
458 | Q_D(const QPieSeries); | |
451 | return d->m_pieRelativeHorPos; |
|
459 | return d->m_pieRelativeHorPos; | |
452 | } |
|
460 | } | |
453 |
|
461 | |||
454 | /*! |
|
462 | /*! | |
455 | Gets the vertical position position of the pie. |
|
463 | Gets the vertical position position of the pie. | |
456 |
|
464 | |||
457 | The returned value is relative to the chart rectangle where: |
|
465 | The returned value is relative to the chart rectangle where: | |
458 |
|
466 | |||
459 | 0.0 means the absolute top. |
|
467 | 0.0 means the absolute top. | |
460 | 1.0 means the absolute bottom. |
|
468 | 1.0 means the absolute bottom. | |
461 |
|
469 | |||
462 | By default it is 0.5 which puts the pie in the vertical middle of the chart rectangle. |
|
470 | By default it is 0.5 which puts the pie in the vertical middle of the chart rectangle. | |
463 |
|
471 | |||
464 | \sa horizontalPosition(), setPieSize() |
|
472 | \sa horizontalPosition(), setPieSize() | |
465 | */ |
|
473 | */ | |
466 | qreal QPieSeries::verticalPosition() const |
|
474 | qreal QPieSeries::verticalPosition() const | |
467 | { |
|
475 | { | |
468 | Q_D(const QPieSeries); |
|
476 | Q_D(const QPieSeries); | |
469 | return d->m_pieRelativeVerPos; |
|
477 | return d->m_pieRelativeVerPos; | |
470 | } |
|
478 | } | |
471 |
|
479 | |||
472 | /*! |
|
480 | /*! | |
473 | Sets the relative size of the pie. |
|
481 | Sets the relative size of the pie. | |
474 |
|
482 | |||
475 | The \a relativeSize is defined so that the 1.0 is the maximum that can fit the given chart rectangle. |
|
483 | The \a relativeSize is defined so that the 1.0 is the maximum that can fit the given chart rectangle. | |
476 |
|
484 | |||
477 | Default value is 0.7. |
|
485 | Default value is 0.7. | |
478 |
|
486 | |||
479 | \sa pieSize(), setPiePosition(), pieVerticalPosition(), pieHorizontalPosition() |
|
487 | \sa pieSize(), setPiePosition(), pieVerticalPosition(), pieHorizontalPosition() | |
480 | */ |
|
488 | */ | |
481 | void QPieSeries::setPieSize(qreal relativeSize) |
|
489 | void QPieSeries::setPieSize(qreal relativeSize) | |
482 | { |
|
490 | { | |
483 | Q_D(QPieSeries); |
|
491 | Q_D(QPieSeries); | |
484 | if (d->setRealValue(d->m_pieRelativeSize, relativeSize, 1.0)) |
|
492 | if (d->setRealValue(d->m_pieRelativeSize, relativeSize, 1.0)) | |
485 | emit pieSizeChanged(); |
|
493 | emit pieSizeChanged(); | |
486 | } |
|
494 | } | |
487 |
|
495 | |||
488 | /*! |
|
496 | /*! | |
489 | Gets the relative size of the pie. |
|
497 | Gets the relative size of the pie. | |
490 |
|
498 | |||
491 | The size is defined so that the 1.0 is the maximum that can fit the given chart rectangle. |
|
499 | The size is defined so that the 1.0 is the maximum that can fit the given chart rectangle. | |
492 |
|
500 | |||
493 | Default value is 0.7. |
|
501 | Default value is 0.7. | |
494 |
|
502 | |||
495 | \sa setPieSize(), setPiePosition(), pieVerticalPosition(), pieHorizontalPosition() |
|
503 | \sa setPieSize(), setPiePosition(), pieVerticalPosition(), pieHorizontalPosition() | |
496 | */ |
|
504 | */ | |
497 | qreal QPieSeries::pieSize() const |
|
505 | qreal QPieSeries::pieSize() const | |
498 | { |
|
506 | { | |
499 | Q_D(const QPieSeries); |
|
507 | Q_D(const QPieSeries); | |
500 | return d->m_pieRelativeSize; |
|
508 | return d->m_pieRelativeSize; | |
501 | } |
|
509 | } | |
502 |
|
510 | |||
503 |
|
511 | |||
504 | /*! |
|
512 | /*! | |
505 | Sets the end angle of the pie. |
|
513 | Sets the end angle of the pie. | |
506 |
|
514 | |||
507 | Full pie is 360 degrees where 0 degrees is at 12 a'clock. |
|
515 | Full pie is 360 degrees where 0 degrees is at 12 a'clock. | |
508 |
|
516 | |||
509 | \a angle must be less than pie end angle. Default value is 0. |
|
517 | \a angle must be less than pie end angle. Default value is 0. | |
510 |
|
518 | |||
511 | \sa pieStartAngle(), pieEndAngle(), setPieEndAngle() |
|
519 | \sa pieStartAngle(), pieEndAngle(), setPieEndAngle() | |
512 | */ |
|
520 | */ | |
513 | void QPieSeries::setPieStartAngle(qreal angle) |
|
521 | void QPieSeries::setPieStartAngle(qreal angle) | |
514 | { |
|
522 | { | |
515 | Q_D(QPieSeries); |
|
523 | Q_D(QPieSeries); | |
516 | if (d->setRealValue(d->m_pieStartAngle, angle, d->m_pieEndAngle)) |
|
524 | if (d->setRealValue(d->m_pieStartAngle, angle, d->m_pieEndAngle)) | |
517 | d->updateDerivativeData(); |
|
525 | d->updateDerivativeData(); | |
518 | } |
|
526 | } | |
519 |
|
527 | |||
520 | /*! |
|
528 | /*! | |
521 | Gets the start angle of the pie. |
|
529 | Gets the start angle of the pie. | |
522 |
|
530 | |||
523 | Full pie is 360 degrees where 0 degrees is at 12 a'clock. Default value is 360. |
|
531 | Full pie is 360 degrees where 0 degrees is at 12 a'clock. Default value is 360. | |
524 |
|
532 | |||
525 | \sa setPieStartAngle(), pieEndAngle(), setPieEndAngle() |
|
533 | \sa setPieStartAngle(), pieEndAngle(), setPieEndAngle() | |
526 | */ |
|
534 | */ | |
527 | qreal QPieSeries::pieStartAngle() const |
|
535 | qreal QPieSeries::pieStartAngle() const | |
528 | { |
|
536 | { | |
529 | Q_D(const QPieSeries); |
|
537 | Q_D(const QPieSeries); | |
530 | return d->m_pieStartAngle; |
|
538 | return d->m_pieStartAngle; | |
531 | } |
|
539 | } | |
532 |
|
540 | |||
533 | /*! |
|
541 | /*! | |
534 | Sets the end angle of the pie. |
|
542 | Sets the end angle of the pie. | |
535 |
|
543 | |||
536 | Full pie is 360 degrees where 0 degrees is at 12 a'clock. |
|
544 | Full pie is 360 degrees where 0 degrees is at 12 a'clock. | |
537 |
|
545 | |||
538 | \a angle must be greater than start angle. |
|
546 | \a angle must be greater than start angle. | |
539 |
|
547 | |||
540 | \sa pieEndAngle(), pieStartAngle(), setPieStartAngle() |
|
548 | \sa pieEndAngle(), pieStartAngle(), setPieStartAngle() | |
541 | */ |
|
549 | */ | |
542 | void QPieSeries::setPieEndAngle(qreal angle) |
|
550 | void QPieSeries::setPieEndAngle(qreal angle) | |
543 | { |
|
551 | { | |
544 | Q_D(QPieSeries); |
|
552 | Q_D(QPieSeries); | |
545 |
|
553 | |||
546 | if (d->setRealValue(d->m_pieEndAngle, angle, 360.0, d->m_pieStartAngle)) |
|
554 | if (d->setRealValue(d->m_pieEndAngle, angle, 360.0, d->m_pieStartAngle)) | |
547 | d->updateDerivativeData(); |
|
555 | d->updateDerivativeData(); | |
548 | } |
|
556 | } | |
549 |
|
557 | |||
550 | /*! |
|
558 | /*! | |
551 | Returns the end angle of the pie. |
|
559 | Returns the end angle of the pie. | |
552 |
|
560 | |||
553 | Full pie is 360 degrees where 0 degrees is at 12 a'clock. |
|
561 | Full pie is 360 degrees where 0 degrees is at 12 a'clock. | |
554 |
|
562 | |||
555 | \sa setPieEndAngle(), pieStartAngle(), setPieStartAngle() |
|
563 | \sa setPieEndAngle(), pieStartAngle(), setPieStartAngle() | |
556 | */ |
|
564 | */ | |
557 | qreal QPieSeries::pieEndAngle() const |
|
565 | qreal QPieSeries::pieEndAngle() const | |
558 | { |
|
566 | { | |
559 | Q_D(const QPieSeries); |
|
567 | Q_D(const QPieSeries); | |
560 | return d->m_pieEndAngle; |
|
568 | return d->m_pieEndAngle; | |
561 | } |
|
569 | } | |
562 |
|
570 | |||
563 | /*! |
|
571 | /*! | |
564 | Sets the all the slice labels \a visible or invisible. |
|
572 | Sets the all the slice labels \a visible or invisible. | |
565 |
|
573 | |||
566 | \sa QPieSlice::isLabelVisible(), QPieSlice::setLabelVisible() |
|
574 | \sa QPieSlice::isLabelVisible(), QPieSlice::setLabelVisible() | |
567 | */ |
|
575 | */ | |
568 | void QPieSeries::setLabelsVisible(bool visible) |
|
576 | void QPieSeries::setLabelsVisible(bool visible) | |
569 | { |
|
577 | { | |
570 | Q_D(QPieSeries); |
|
578 | Q_D(QPieSeries); | |
571 | foreach (QPieSlice* s, d->m_slices) |
|
579 | foreach (QPieSlice* s, d->m_slices) | |
572 | s->setLabelVisible(visible); |
|
580 | s->setLabelVisible(visible); | |
573 | } |
|
581 | } | |
574 |
|
582 | |||
575 | /*! |
|
583 | /*! | |
576 | Returns the sum of all slice values in this series. |
|
584 | Returns the sum of all slice values in this series. | |
577 |
|
585 | |||
578 | \sa QPieSlice::value(), QPieSlice::setValue() |
|
586 | \sa QPieSlice::value(), QPieSlice::setValue() | |
579 | */ |
|
587 | */ | |
580 | qreal QPieSeries::total() const |
|
588 | qreal QPieSeries::total() const | |
581 | { |
|
589 | { | |
582 | Q_D(const QPieSeries); |
|
590 | Q_D(const QPieSeries); | |
583 | return d->m_total; |
|
591 | return d->m_total; | |
584 | } |
|
592 | } | |
585 |
|
593 | |||
586 | /*! |
|
594 | /*! | |
587 | \fn void QPieSeries::clicked(QPieSlice* slice, Qt::MouseButtons buttons) |
|
595 | \fn void QPieSeries::clicked(QPieSlice* slice, Qt::MouseButtons buttons) | |
588 |
|
596 | |||
589 | This signal is emitted when a \a slice has been clicked with mouse \a buttons. |
|
597 | This signal is emitted when a \a slice has been clicked with mouse \a buttons. | |
590 |
|
598 | |||
591 | \sa QPieSlice::clicked() |
|
599 | \sa QPieSlice::clicked() | |
592 | */ |
|
600 | */ | |
593 |
|
601 | |||
594 | /*! |
|
602 | /*! | |
595 | \fn void QPieSeries::hoverEnter(QPieSlice* slice) |
|
603 | \fn void QPieSeries::hoverEnter(QPieSlice* slice) | |
596 |
|
604 | |||
597 | This signal is emitted when user has hovered over a \a slice. |
|
605 | This signal is emitted when user has hovered over a \a slice. | |
598 |
|
606 | |||
599 | \sa QPieSlice::hoverEnter() |
|
607 | \sa QPieSlice::hoverEnter() | |
600 | */ |
|
608 | */ | |
601 |
|
609 | |||
602 | /*! |
|
610 | /*! | |
603 | \fn void QPieSeries::hoverLeave(QPieSlice* slice) |
|
611 | \fn void QPieSeries::hoverLeave(QPieSlice* slice) | |
604 |
|
612 | |||
605 | This signal is emitted when user has hovered away from a \a slice. |
|
613 | This signal is emitted when user has hovered away from a \a slice. | |
606 |
|
614 | |||
607 | \sa QPieSlice::hoverLeave() |
|
615 | \sa QPieSlice::hoverLeave() | |
608 | */ |
|
616 | */ | |
609 |
|
617 | |||
610 | /*! |
|
618 | /*! | |
611 | \fn void QPieSeries::added(QList<QPieSlice*> slices) |
|
619 | \fn void QPieSeries::added(QList<QPieSlice*> slices) | |
612 |
|
620 | |||
613 | This signal is emitted when \a slices has been added to the series. |
|
621 | This signal is emitted when \a slices has been added to the series. | |
614 |
|
622 | |||
615 | \sa append(), insert() |
|
623 | \sa append(), insert() | |
616 | */ |
|
624 | */ | |
617 |
|
625 | |||
618 | /*! |
|
626 | /*! | |
619 | \fn void QPieSeries::removed(QList<QPieSlice*> slices) |
|
627 | \fn void QPieSeries::removed(QList<QPieSlice*> slices) | |
620 |
|
628 | |||
621 | This signal is emitted when \a slices has been removed from the series. |
|
629 | This signal is emitted when \a slices has been removed from the series. | |
622 |
|
630 | |||
623 | \sa remove(), clear() |
|
631 | \sa remove(), clear() | |
624 | */ |
|
632 | */ | |
625 |
|
633 | |||
626 | /*! |
|
634 | /*! | |
627 | \fn void QPieSeries::piePositionChanged() |
|
635 | \fn void QPieSeries::piePositionChanged() | |
628 |
|
636 | |||
629 | This signal is emitted when pie position has changed. |
|
637 | This signal is emitted when pie position has changed. | |
630 |
|
638 | |||
631 | \sa verticalPosition(), setVerticalPosition(), horizontalPosition(), setHorizontalPosition() |
|
639 | \sa verticalPosition(), setVerticalPosition(), horizontalPosition(), setHorizontalPosition() | |
632 | */ |
|
640 | */ | |
633 |
|
641 | |||
634 | /*! |
|
642 | /*! | |
635 | \fn void QPieSeries::pieSizeChanged() |
|
643 | \fn void QPieSeries::pieSizeChanged() | |
636 |
|
644 | |||
637 | This signal is emitted when pie size has changed. |
|
645 | This signal is emitted when pie size has changed. | |
638 |
|
646 | |||
639 | \sa pieSize(), setPieSize() |
|
647 | \sa pieSize(), setPieSize() | |
640 | */ |
|
648 | */ | |
641 |
|
649 | |||
642 | /*! |
|
650 | /*! | |
643 | \fn bool QPieSeries::setModel(QAbstractItemModel *model) |
|
651 | \fn bool QPieSeries::setModel(QAbstractItemModel *model) | |
644 | Sets the \a model to be used as a data source |
|
652 | Sets the \a model to be used as a data source | |
645 | */ |
|
653 | */ | |
646 | bool QPieSeries::setModel(QAbstractItemModel* model) |
|
654 | bool QPieSeries::setModel(QAbstractItemModel* model) | |
647 | { |
|
655 | { | |
648 | Q_D(QPieSeries); |
|
656 | Q_D(QPieSeries); | |
649 | // disconnect signals from old model |
|
657 | // disconnect signals from old model | |
650 | if(m_model) |
|
658 | if(m_model) | |
651 | { |
|
659 | { | |
652 | disconnect(m_model, 0, this, 0); |
|
660 | disconnect(m_model, 0, this, 0); | |
653 | d->m_mapValues = -1; |
|
661 | d->m_mapValues = -1; | |
654 | d->m_mapLabels = -1; |
|
662 | d->m_mapLabels = -1; | |
655 | d->m_mapOrientation = Qt::Vertical; |
|
663 | d->m_mapOrientation = Qt::Vertical; | |
656 | } |
|
664 | } | |
657 |
|
665 | |||
658 | // set new model |
|
666 | // set new model | |
659 | if(model) |
|
667 | if(model) | |
660 | { |
|
668 | { | |
661 | m_model = model; |
|
669 | m_model = model; | |
662 | return true; |
|
670 | return true; | |
663 | } |
|
671 | } | |
664 | else |
|
672 | else | |
665 | { |
|
673 | { | |
666 | m_model = 0; |
|
674 | m_model = 0; | |
667 | return false; |
|
675 | return false; | |
668 | } |
|
676 | } | |
669 | } |
|
677 | } | |
670 |
|
678 | |||
671 | /*! |
|
679 | /*! | |
672 | \fn bool QPieSeries::setModelMapping(int modelValuesLine, int modelLabelsLine, Qt::Orientation orientation) |
|
680 | \fn bool QPieSeries::setModelMapping(int modelValuesLine, int modelLabelsLine, Qt::Orientation orientation) | |
673 | Sets column/row specified by \a modelValuesLine to be used as a list of pie slice values for the pie. |
|
681 | Sets column/row specified by \a modelValuesLine to be used as a list of pie slice values for the pie. | |
674 | Parameter \a modelValuesLine indicates the column/row where the values for the pie slices are located in the model. |
|
682 | Parameter \a modelValuesLine indicates the column/row where the values for the pie slices are located in the model. | |
675 | Parameter \a modelLabelsLine indicates the column/row where the labels for the pie slices are located in the model. |
|
683 | Parameter \a modelLabelsLine indicates the column/row where the labels for the pie slices are located in the model. | |
676 | The \a orientation paramater specifies whether the data is in columns or in rows. |
|
684 | The \a orientation paramater specifies whether the data is in columns or in rows. | |
677 | */ |
|
685 | */ | |
678 | void QPieSeries::setModelMapping(int modelValuesLine, int modelLabelsLine, Qt::Orientation orientation) |
|
686 | void QPieSeries::setModelMapping(int modelValuesLine, int modelLabelsLine, Qt::Orientation orientation) | |
679 | { |
|
687 | { | |
680 | Q_D(QPieSeries); |
|
688 | Q_D(QPieSeries); | |
681 |
|
689 | |||
682 | if (m_model == 0) |
|
690 | if (m_model == 0) | |
683 | return; |
|
691 | return; | |
684 |
|
692 | |||
685 | d->m_mapValues = modelValuesLine; |
|
693 | d->m_mapValues = modelValuesLine; | |
686 | d->m_mapLabels = modelLabelsLine; |
|
694 | d->m_mapLabels = modelLabelsLine; | |
687 | d->m_mapOrientation = orientation; |
|
695 | d->m_mapOrientation = orientation; | |
688 |
|
696 | |||
689 | // connect the signals |
|
697 | // connect the signals | |
690 | if (d->m_mapOrientation == Qt::Vertical) { |
|
698 | if (d->m_mapOrientation == Qt::Vertical) { | |
691 | connect(m_model, SIGNAL(dataChanged(QModelIndex,QModelIndex)), d, SLOT(modelUpdated(QModelIndex, QModelIndex))); |
|
699 | connect(m_model, SIGNAL(dataChanged(QModelIndex,QModelIndex)), d, SLOT(modelUpdated(QModelIndex, QModelIndex))); | |
692 | connect(m_model, SIGNAL(rowsInserted(QModelIndex, int, int)), d, SLOT(modelDataAdded(QModelIndex,int,int))); |
|
700 | connect(m_model, SIGNAL(rowsInserted(QModelIndex, int, int)), d, SLOT(modelDataAdded(QModelIndex,int,int))); | |
693 | connect(m_model, SIGNAL(rowsRemoved(QModelIndex, int, int)), d, SLOT(modelDataRemoved(QModelIndex,int,int))); |
|
701 | connect(m_model, SIGNAL(rowsRemoved(QModelIndex, int, int)), d, SLOT(modelDataRemoved(QModelIndex,int,int))); | |
694 | } else { |
|
702 | } else { | |
695 | connect(m_model, SIGNAL(dataChanged(QModelIndex,QModelIndex)), d, SLOT(modelUpdated(QModelIndex, QModelIndex))); |
|
703 | connect(m_model, SIGNAL(dataChanged(QModelIndex,QModelIndex)), d, SLOT(modelUpdated(QModelIndex, QModelIndex))); | |
696 | connect(m_model, SIGNAL(columnsInserted(QModelIndex, int, int)), d, SLOT(modelDataAdded(QModelIndex,int,int))); |
|
704 | connect(m_model, SIGNAL(columnsInserted(QModelIndex, int, int)), d, SLOT(modelDataAdded(QModelIndex,int,int))); | |
697 | connect(m_model, SIGNAL(columnsRemoved(QModelIndex, int, int)), d, SLOT(modelDataRemoved(QModelIndex,int,int))); |
|
705 | connect(m_model, SIGNAL(columnsRemoved(QModelIndex, int, int)), d, SLOT(modelDataRemoved(QModelIndex,int,int))); | |
698 | } |
|
706 | } | |
699 |
|
707 | |||
700 | // create the initial slices set |
|
708 | // create the initial slices set | |
701 | if (d->m_mapOrientation == Qt::Vertical) { |
|
709 | if (d->m_mapOrientation == Qt::Vertical) { | |
702 | for (int i = 0; i < m_model->rowCount(); i++) |
|
710 | for (int i = 0; i < m_model->rowCount(); i++) | |
703 | append(m_model->data(m_model->index(i, d->m_mapValues), Qt::DisplayRole).toDouble(), m_model->data(m_model->index(i, d->m_mapLabels), Qt::DisplayRole).toString()); |
|
711 | append(m_model->data(m_model->index(i, d->m_mapValues), Qt::DisplayRole).toDouble(), m_model->data(m_model->index(i, d->m_mapLabels), Qt::DisplayRole).toString()); | |
704 | } else { |
|
712 | } else { | |
705 | for (int i = 0; i < m_model->columnCount(); i++) |
|
713 | for (int i = 0; i < m_model->columnCount(); i++) | |
706 | append(m_model->data(m_model->index(d->m_mapValues, i), Qt::DisplayRole).toDouble(), m_model->data(m_model->index(d->m_mapLabels, i), Qt::DisplayRole).toString()); |
|
714 | append(m_model->data(m_model->index(d->m_mapValues, i), Qt::DisplayRole).toDouble(), m_model->data(m_model->index(d->m_mapLabels, i), Qt::DisplayRole).toString()); | |
707 | } |
|
715 | } | |
708 | } |
|
716 | } | |
709 |
|
717 | |||
710 | #include "moc_qpieseries.cpp" |
|
718 | #include "moc_qpieseries.cpp" | |
711 | #include "moc_qpieseriesprivate_p.cpp" |
|
719 | #include "moc_qpieseriesprivate_p.cpp" | |
712 |
|
720 | |||
713 | QTCOMMERCIALCHART_END_NAMESPACE |
|
721 | QTCOMMERCIALCHART_END_NAMESPACE |
@@ -1,400 +1,401 | |||||
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 "qpieslice.h" |
|
21 | #include "qpieslice.h" | |
22 | #include "pieslicedata_p.h" |
|
22 | #include "pieslicedata_p.h" | |
23 |
|
23 | |||
24 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
24 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
25 |
|
25 | |||
26 | /*! |
|
26 | /*! | |
27 | \class QPieSlice |
|
27 | \class QPieSlice | |
28 | \brief Defines a slice in pie series. |
|
28 | \brief Defines a slice in pie series. | |
29 |
|
29 | |||
30 | Holds all the data of a single slice in a QPieSeries and provides the means |
|
30 | Holds all the data of a single slice in a QPieSeries and provides the means | |
31 | to modify slice data and customize the visual appearance of the slice. |
|
31 | to modify slice data and customize the visual appearance of the slice. | |
32 |
|
32 | |||
33 | It also provides the means to customize user interaction with the slice by |
|
33 | It also provides the means to customize user interaction with the slice by | |
34 | providing signals for clicking and hover events. |
|
34 | providing signals for clicking and hover events. | |
35 | */ |
|
35 | */ | |
36 |
|
36 | |||
37 | /*! |
|
37 | /*! | |
38 | \property QPieSlice::label |
|
38 | \property QPieSlice::label | |
39 |
|
39 | |||
40 | Label of the slice. |
|
40 | Label of the slice. | |
41 | */ |
|
41 | */ | |
42 |
|
42 | |||
43 | /*! |
|
43 | /*! | |
44 | \property QPieSlice::value |
|
44 | \property QPieSlice::value | |
45 |
|
45 | |||
46 | Value of the slice. |
|
46 | Value of the slice. | |
47 | */ |
|
47 | */ | |
48 |
|
48 | |||
49 | /*! |
|
49 | /*! | |
50 | Constructs an empty slice with a \a parent. |
|
50 | Constructs an empty slice with a \a parent. | |
51 |
|
51 | |||
52 | Note that QPieSeries takes ownership of the slice when it is set/added. |
|
52 | Note that QPieSeries takes ownership of the slice when it is set/added. | |
53 |
|
53 | |||
54 | \sa QPieSeries::replace(), QPieSeries::append() |
|
54 | \sa QPieSeries::replace(), QPieSeries::append() | |
55 | */ |
|
55 | */ | |
56 | QPieSlice::QPieSlice(QObject *parent) |
|
56 | QPieSlice::QPieSlice(QObject *parent) | |
57 | :QObject(parent), |
|
57 | :QObject(parent), | |
58 | d(new PieSliceData()) |
|
58 | d(new PieSliceData()) | |
59 | { |
|
59 | { | |
60 |
|
60 | |||
61 | } |
|
61 | } | |
62 |
|
62 | |||
63 | /*! |
|
63 | /*! | |
64 | Constructs an empty slice with given \a value, \a label and a \a parent. |
|
64 | Constructs an empty slice with given \a value, \a label and a \a parent. | |
65 | Note that QPieSeries takes ownership of the slice when it is set/added. |
|
65 | Note that QPieSeries takes ownership of the slice when it is set/added. | |
66 | \sa QPieSeries::replace(), QPieSeries::append() |
|
66 | \sa QPieSeries::replace(), QPieSeries::append() | |
67 | */ |
|
67 | */ | |
68 | QPieSlice::QPieSlice(qreal value, QString label, QObject *parent) |
|
68 | QPieSlice::QPieSlice(qreal value, QString label, QObject *parent) | |
69 | :QObject(parent), |
|
69 | :QObject(parent), | |
70 | d(new PieSliceData()) |
|
70 | d(new PieSliceData()) | |
71 | { |
|
71 | { | |
72 | d->m_value = value; |
|
72 | d->m_value = value; | |
73 | d->m_labelText = label; |
|
73 | d->m_labelText = label; | |
74 | } |
|
74 | } | |
75 |
|
75 | |||
76 | /*! |
|
76 | /*! | |
77 | Destroys the slice. |
|
77 | Destroys the slice. | |
78 | User should not delete the slice if it has been added to the series. |
|
78 | User should not delete the slice if it has been added to the series. | |
79 | */ |
|
79 | */ | |
80 | QPieSlice::~QPieSlice() |
|
80 | QPieSlice::~QPieSlice() | |
81 | { |
|
81 | { | |
82 | delete d; |
|
82 | delete d; | |
83 | } |
|
83 | } | |
84 |
|
84 | |||
85 | /*! |
|
85 | /*! | |
86 | Gets the value of the slice. |
|
86 | Gets the value of the slice. | |
87 | Note that all values in the series |
|
87 | Note that all values in the series | |
88 | \sa setValue() |
|
88 | \sa setValue() | |
89 | */ |
|
89 | */ | |
90 | qreal QPieSlice::value() const |
|
90 | qreal QPieSlice::value() const | |
91 | { |
|
91 | { | |
92 | return d->m_value; |
|
92 | return d->m_value; | |
93 | } |
|
93 | } | |
94 |
|
94 | |||
95 | /*! |
|
95 | /*! | |
96 | Gets the label of the slice. |
|
96 | Gets the label of the slice. | |
97 | \sa setLabel() |
|
97 | \sa setLabel() | |
98 | */ |
|
98 | */ | |
99 | QString QPieSlice::label() const |
|
99 | QString QPieSlice::label() const | |
100 | { |
|
100 | { | |
101 | return d->m_labelText; |
|
101 | return d->m_labelText; | |
102 | } |
|
102 | } | |
103 |
|
103 | |||
104 | /*! |
|
104 | /*! | |
105 | Returns true if label is set as visible. |
|
105 | Returns true if label is set as visible. | |
106 | \sa setLabelVisible() |
|
106 | \sa setLabelVisible() | |
107 | */ |
|
107 | */ | |
108 | bool QPieSlice::isLabelVisible() const |
|
108 | bool QPieSlice::isLabelVisible() const | |
109 | { |
|
109 | { | |
110 | return d->m_isLabelVisible; |
|
110 | return d->m_isLabelVisible; | |
111 | } |
|
111 | } | |
112 |
|
112 | |||
113 | /*! |
|
113 | /*! | |
114 | Returns true if slice is exloded from the pie. |
|
114 | Returns true if slice is exloded from the pie. | |
115 | \sa setExploded(), setExplodeDistanceFactor() |
|
115 | \sa setExploded(), setExplodeDistanceFactor() | |
116 | */ |
|
116 | */ | |
117 | bool QPieSlice::isExploded() const |
|
117 | bool QPieSlice::isExploded() const | |
118 | { |
|
118 | { | |
119 | return d->m_isExploded; |
|
119 | return d->m_isExploded; | |
120 | } |
|
120 | } | |
121 |
|
121 | |||
122 | /*! |
|
122 | /*! | |
123 | Returns the explode distance factor. |
|
123 | Returns the explode distance factor. | |
124 |
|
124 | |||
125 | The factor is relative to pie radius. For example: |
|
125 | The factor is relative to pie radius. For example: | |
126 | 1.0 means the distance is the same as the radius. |
|
126 | 1.0 means the distance is the same as the radius. | |
127 | 0.5 means the distance is half of the radius. |
|
127 | 0.5 means the distance is half of the radius. | |
128 |
|
128 | |||
129 | Default value is 0.15. |
|
129 | Default value is 0.15. | |
130 |
|
130 | |||
131 | \sa setExplodeDistanceFactor() |
|
131 | \sa setExplodeDistanceFactor() | |
132 | */ |
|
132 | */ | |
133 | qreal QPieSlice::explodeDistanceFactor() const |
|
133 | qreal QPieSlice::explodeDistanceFactor() const | |
134 | { |
|
134 | { | |
135 | return d->m_explodeDistanceFactor; |
|
135 | return d->m_explodeDistanceFactor; | |
136 | } |
|
136 | } | |
137 |
|
137 | |||
138 | /*! |
|
138 | /*! | |
139 | Returns the percentage of this slice compared to all slices in the same series. |
|
139 | Returns the percentage of this slice compared to all slices in the same series. | |
140 | The returned value ranges from 0 to 1.0. |
|
140 | The returned value ranges from 0 to 1.0. | |
141 |
|
141 | |||
142 | Updated internally after the slice is added to the series. |
|
142 | Updated internally after the slice is added to the series. | |
143 | */ |
|
143 | */ | |
144 | qreal QPieSlice::percentage() const |
|
144 | qreal QPieSlice::percentage() const | |
145 | { |
|
145 | { | |
146 | return d->m_percentage; |
|
146 | return d->m_percentage; | |
147 | } |
|
147 | } | |
148 |
|
148 | |||
149 | /*! |
|
149 | /*! | |
150 | Returns the starting angle of this slice in the series it belongs to. |
|
150 | Returns the starting angle of this slice in the series it belongs to. | |
151 |
|
151 | |||
152 | Full pie is 360 degrees where 0 degrees is at 12 a'clock. |
|
152 | Full pie is 360 degrees where 0 degrees is at 12 a'clock. | |
153 |
|
153 | |||
154 | Updated internally after the slice is added to the series. |
|
154 | Updated internally after the slice is added to the series. | |
155 | */ |
|
155 | */ | |
156 | qreal QPieSlice::startAngle() const |
|
156 | qreal QPieSlice::startAngle() const | |
157 | { |
|
157 | { | |
158 | return d->m_startAngle; |
|
158 | return d->m_startAngle; | |
159 | } |
|
159 | } | |
160 |
|
160 | |||
161 | /*! |
|
161 | /*! | |
162 | Returns the end angle of this slice in the series it belongs to. |
|
162 | Returns the end angle of this slice in the series it belongs to. | |
163 |
|
163 | |||
164 | Full pie is 360 degrees where 0 degrees is at 12 a'clock. |
|
164 | Full pie is 360 degrees where 0 degrees is at 12 a'clock. | |
165 |
|
165 | |||
166 | Updated internally after the slice is added to the series. |
|
166 | Updated internally after the slice is added to the series. | |
167 | */ |
|
167 | */ | |
168 | qreal QPieSlice::endAngle() const |
|
168 | qreal QPieSlice::endAngle() const | |
169 | { |
|
169 | { | |
170 | return d->m_startAngle + d->m_angleSpan; |
|
170 | return d->m_startAngle + d->m_angleSpan; | |
171 | } |
|
171 | } | |
172 |
|
172 | |||
173 | /*! |
|
173 | /*! | |
174 | Returns the pen used to draw this slice. |
|
174 | Returns the pen used to draw this slice. | |
175 | \sa setPen() |
|
175 | \sa setPen() | |
176 | */ |
|
176 | */ | |
177 | QPen QPieSlice::pen() const |
|
177 | QPen QPieSlice::pen() const | |
178 | { |
|
178 | { | |
179 | return d->m_slicePen; |
|
179 | return d->m_slicePen; | |
180 | } |
|
180 | } | |
181 |
|
181 | |||
182 | /*! |
|
182 | /*! | |
183 | Returns the brush used to draw this slice. |
|
183 | Returns the brush used to draw this slice. | |
184 | \sa setBrush() |
|
184 | \sa setBrush() | |
185 | */ |
|
185 | */ | |
186 | QBrush QPieSlice::brush() const |
|
186 | QBrush QPieSlice::brush() const | |
187 | { |
|
187 | { | |
188 | return d->m_sliceBrush; |
|
188 | return d->m_sliceBrush; | |
189 | } |
|
189 | } | |
190 |
|
190 | |||
191 | /*! |
|
191 | /*! | |
192 | Returns the pen used to draw the label in this slice. |
|
192 | Returns the pen used to draw the label in this slice. | |
193 | \sa setLabelPen() |
|
193 | \sa setLabelPen() | |
194 | */ |
|
194 | */ | |
195 | QPen QPieSlice::labelPen() const |
|
195 | QPen QPieSlice::labelPen() const | |
196 | { |
|
196 | { | |
197 | return d->m_labelPen; |
|
197 | return d->m_labelPen; | |
198 | } |
|
198 | } | |
199 |
|
199 | |||
200 | /*! |
|
200 | /*! | |
201 | Returns the font used to draw label in this slice. |
|
201 | Returns the font used to draw label in this slice. | |
202 | \sa setLabelFont() |
|
202 | \sa setLabelFont() | |
203 | */ |
|
203 | */ | |
204 | QFont QPieSlice::labelFont() const |
|
204 | QFont QPieSlice::labelFont() const | |
205 | { |
|
205 | { | |
206 | return d->m_labelFont; |
|
206 | return d->m_labelFont; | |
207 | } |
|
207 | } | |
208 |
|
208 | |||
209 | /*! |
|
209 | /*! | |
210 | Gets the label arm length factor. |
|
210 | Gets the label arm length factor. | |
211 |
|
211 | |||
212 | The factor is relative to pie radius. For example: |
|
212 | The factor is relative to pie radius. For example: | |
213 | 1.0 means the length is the same as the radius. |
|
213 | 1.0 means the length is the same as the radius. | |
214 | 0.5 means the length is half of the radius. |
|
214 | 0.5 means the length is half of the radius. | |
215 |
|
215 | |||
216 | Default value is 0.15 |
|
216 | Default value is 0.15 | |
217 |
|
217 | |||
218 | \sa setLabelArmLengthFactor() |
|
218 | \sa setLabelArmLengthFactor() | |
219 | */ |
|
219 | */ | |
220 | qreal QPieSlice::labelArmLengthFactor() const |
|
220 | qreal QPieSlice::labelArmLengthFactor() const | |
221 | { |
|
221 | { | |
222 | return d->m_labelArmLengthFactor; |
|
222 | return d->m_labelArmLengthFactor; | |
223 | } |
|
223 | } | |
224 |
|
224 | |||
225 | /*! |
|
225 | /*! | |
226 | \fn void QPieSlice::clicked(Qt::MouseButtons buttons) |
|
226 | \fn void QPieSlice::clicked(Qt::MouseButtons buttons) | |
227 |
|
227 | |||
228 | This signal is emitted when user has clicked the slice. |
|
228 | This signal is emitted when user has clicked the slice. | |
|
229 | Parameter \a buttons hold the information about the clicked mouse buttons. | |||
229 |
|
230 | |||
230 | \sa QPieSeries::clicked() |
|
231 | \sa QPieSeries::clicked() | |
231 | */ |
|
232 | */ | |
232 |
|
233 | |||
233 | /*! |
|
234 | /*! | |
234 | \fn void QPieSlice::hoverEnter() |
|
235 | \fn void QPieSlice::hoverEnter() | |
235 |
|
236 | |||
236 | This signal is emitted when user has hovered over the slice. |
|
237 | This signal is emitted when user has hovered over the slice. | |
237 |
|
238 | |||
238 | \sa QPieSeries::hoverEnter() |
|
239 | \sa QPieSeries::hoverEnter() | |
239 | */ |
|
240 | */ | |
240 |
|
241 | |||
241 | /*! |
|
242 | /*! | |
242 | \fn void QPieSlice::hoverLeave() |
|
243 | \fn void QPieSlice::hoverLeave() | |
243 |
|
244 | |||
244 | This signal is emitted when user has hovered away from the slice. |
|
245 | This signal is emitted when user has hovered away from the slice. | |
245 |
|
246 | |||
246 | \sa QPieSeries::hoverLeave() |
|
247 | \sa QPieSeries::hoverLeave() | |
247 | */ |
|
248 | */ | |
248 |
|
249 | |||
249 | /*! |
|
250 | /*! | |
250 | \fn void QPieSlice::changed() |
|
251 | \fn void QPieSlice::changed() | |
251 |
|
252 | |||
252 | This signal emitted when something has changed in the slice. |
|
253 | This signal emitted when something has changed in the slice. | |
253 | */ |
|
254 | */ | |
254 |
|
255 | |||
255 | /*! |
|
256 | /*! | |
256 | Sets the \a value of this slice. |
|
257 | Sets the \a value of this slice. | |
257 | \sa value() |
|
258 | \sa value() | |
258 | */ |
|
259 | */ | |
259 | void QPieSlice::setValue(qreal value) |
|
260 | void QPieSlice::setValue(qreal value) | |
260 | { |
|
261 | { | |
261 | if (!qFuzzyIsNull(d->m_value - value)) { |
|
262 | if (!qFuzzyIsNull(d->m_value - value)) { | |
262 | d->m_value = value; |
|
263 | d->m_value = value; | |
263 | emit changed(); |
|
264 | emit changed(); | |
264 | } |
|
265 | } | |
265 | } |
|
266 | } | |
266 |
|
267 | |||
267 | /*! |
|
268 | /*! | |
268 | Sets the \a label of the slice. |
|
269 | Sets the \a label of the slice. | |
269 | \sa label() |
|
270 | \sa label() | |
270 | */ |
|
271 | */ | |
271 | void QPieSlice::setLabel(QString label) |
|
272 | void QPieSlice::setLabel(QString label) | |
272 | { |
|
273 | { | |
273 | if (d->m_labelText != label) { |
|
274 | if (d->m_labelText != label) { | |
274 | d->m_labelText = label; |
|
275 | d->m_labelText = label; | |
275 | emit changed(); |
|
276 | emit changed(); | |
276 | } |
|
277 | } | |
277 | } |
|
278 | } | |
278 |
|
279 | |||
279 | /*! |
|
280 | /*! | |
280 | Sets the label \a visible in this slice. |
|
281 | Sets the label \a visible in this slice. | |
281 | \sa isLabelVisible(), QPieSeries::setLabelsVisible() |
|
282 | \sa isLabelVisible(), QPieSeries::setLabelsVisible() | |
282 | */ |
|
283 | */ | |
283 | void QPieSlice::setLabelVisible(bool visible) |
|
284 | void QPieSlice::setLabelVisible(bool visible) | |
284 | { |
|
285 | { | |
285 | if (d->m_isLabelVisible != visible) { |
|
286 | if (d->m_isLabelVisible != visible) { | |
286 | d->m_isLabelVisible = visible; |
|
287 | d->m_isLabelVisible = visible; | |
287 | emit changed(); |
|
288 | emit changed(); | |
288 | } |
|
289 | } | |
289 | } |
|
290 | } | |
290 |
|
291 | |||
291 | /*! |
|
292 | /*! | |
292 | Sets this slice \a exploded. |
|
293 | Sets this slice \a exploded. | |
293 | \sa isExploded(), explodeDistanceFactor() |
|
294 | \sa isExploded(), explodeDistanceFactor() | |
294 | */ |
|
295 | */ | |
295 | void QPieSlice::setExploded(bool exploded) |
|
296 | void QPieSlice::setExploded(bool exploded) | |
296 | { |
|
297 | { | |
297 | if (d->m_isExploded != exploded) { |
|
298 | if (d->m_isExploded != exploded) { | |
298 | d->m_isExploded = exploded; |
|
299 | d->m_isExploded = exploded; | |
299 | emit changed(); |
|
300 | emit changed(); | |
300 | } |
|
301 | } | |
301 | } |
|
302 | } | |
302 |
|
303 | |||
303 | /*! |
|
304 | /*! | |
304 | Sets the explode distance \a factor. |
|
305 | Sets the explode distance \a factor. | |
305 |
|
306 | |||
306 | The factor is relative to pie radius. For example: |
|
307 | The factor is relative to pie radius. For example: | |
307 | 1.0 means the distance is the same as the radius. |
|
308 | 1.0 means the distance is the same as the radius. | |
308 | 0.5 means the distance is half of the radius. |
|
309 | 0.5 means the distance is half of the radius. | |
309 |
|
310 | |||
310 | Default value is 0.15 |
|
311 | Default value is 0.15 | |
311 |
|
312 | |||
312 | \sa explodeDistanceFactor() |
|
313 | \sa explodeDistanceFactor() | |
313 | */ |
|
314 | */ | |
314 | void QPieSlice::setExplodeDistanceFactor(qreal factor) |
|
315 | void QPieSlice::setExplodeDistanceFactor(qreal factor) | |
315 | { |
|
316 | { | |
316 | if (!qFuzzyIsNull(d->m_explodeDistanceFactor - factor)) { |
|
317 | if (!qFuzzyIsNull(d->m_explodeDistanceFactor - factor)) { | |
317 | d->m_explodeDistanceFactor = factor; |
|
318 | d->m_explodeDistanceFactor = factor; | |
318 | emit changed(); |
|
319 | emit changed(); | |
319 | } |
|
320 | } | |
320 | } |
|
321 | } | |
321 |
|
322 | |||
322 | /*! |
|
323 | /*! | |
323 | Sets the \a pen used to draw this slice. |
|
324 | Sets the \a pen used to draw this slice. | |
324 | Note that applying a theme will override this. |
|
325 | Note that applying a theme will override this. | |
325 | \sa pen() |
|
326 | \sa pen() | |
326 | */ |
|
327 | */ | |
327 | void QPieSlice::setPen(const QPen &pen) |
|
328 | void QPieSlice::setPen(const QPen &pen) | |
328 | { |
|
329 | { | |
329 | if (d->m_slicePen != pen) { |
|
330 | if (d->m_slicePen != pen) { | |
330 | d->m_slicePen = pen; |
|
331 | d->m_slicePen = pen; | |
331 | d->m_slicePen.setThemed(false); |
|
332 | d->m_slicePen.setThemed(false); | |
332 | emit changed(); |
|
333 | emit changed(); | |
333 | } |
|
334 | } | |
334 | } |
|
335 | } | |
335 |
|
336 | |||
336 | /*! |
|
337 | /*! | |
337 | Sets the \a brush used to draw this slice. |
|
338 | Sets the \a brush used to draw this slice. | |
338 | Note that applying a theme will override this. |
|
339 | Note that applying a theme will override this. | |
339 | \sa brush() |
|
340 | \sa brush() | |
340 | */ |
|
341 | */ | |
341 | void QPieSlice::setBrush(const QBrush &brush) |
|
342 | void QPieSlice::setBrush(const QBrush &brush) | |
342 | { |
|
343 | { | |
343 | if (d->m_sliceBrush != brush) { |
|
344 | if (d->m_sliceBrush != brush) { | |
344 | d->m_sliceBrush = brush; |
|
345 | d->m_sliceBrush = brush; | |
345 | d->m_sliceBrush.setThemed(false); |
|
346 | d->m_sliceBrush.setThemed(false); | |
346 | emit changed(); |
|
347 | emit changed(); | |
347 | } |
|
348 | } | |
348 | } |
|
349 | } | |
349 |
|
350 | |||
350 | /*! |
|
351 | /*! | |
351 | Sets the \a pen used to draw the label in this slice. |
|
352 | Sets the \a pen used to draw the label in this slice. | |
352 | Note that applying a theme will override this. |
|
353 | Note that applying a theme will override this. | |
353 | \sa labelPen() |
|
354 | \sa labelPen() | |
354 | */ |
|
355 | */ | |
355 | void QPieSlice::setLabelPen(const QPen &pen) |
|
356 | void QPieSlice::setLabelPen(const QPen &pen) | |
356 | { |
|
357 | { | |
357 | if (d->m_labelPen != pen) { |
|
358 | if (d->m_labelPen != pen) { | |
358 | d->m_labelPen = pen; |
|
359 | d->m_labelPen = pen; | |
359 | d->m_labelPen.setThemed(false); |
|
360 | d->m_labelPen.setThemed(false); | |
360 | emit changed(); |
|
361 | emit changed(); | |
361 | } |
|
362 | } | |
362 | } |
|
363 | } | |
363 |
|
364 | |||
364 | /*! |
|
365 | /*! | |
365 | Sets the \a font used to draw the label in this slice. |
|
366 | Sets the \a font used to draw the label in this slice. | |
366 | Note that applying a theme will override this. |
|
367 | Note that applying a theme will override this. | |
367 | \sa labelFont() |
|
368 | \sa labelFont() | |
368 | */ |
|
369 | */ | |
369 | void QPieSlice::setLabelFont(const QFont &font) |
|
370 | void QPieSlice::setLabelFont(const QFont &font) | |
370 | { |
|
371 | { | |
371 | if (d->m_labelFont != font) { |
|
372 | if (d->m_labelFont != font) { | |
372 | d->m_labelFont = font; |
|
373 | d->m_labelFont = font; | |
373 | d->m_labelFont.setThemed(false); |
|
374 | d->m_labelFont.setThemed(false); | |
374 | emit changed(); |
|
375 | emit changed(); | |
375 | } |
|
376 | } | |
376 | } |
|
377 | } | |
377 |
|
378 | |||
378 | /*! |
|
379 | /*! | |
379 | Sets the label arm length \a factor. |
|
380 | Sets the label arm length \a factor. | |
380 |
|
381 | |||
381 | The factor is relative to pie radius. For example: |
|
382 | The factor is relative to pie radius. For example: | |
382 | 1.0 means the length is the same as the radius. |
|
383 | 1.0 means the length is the same as the radius. | |
383 | 0.5 means the length is half of the radius. |
|
384 | 0.5 means the length is half of the radius. | |
384 |
|
385 | |||
385 | Default value is 0.15 |
|
386 | Default value is 0.15 | |
386 |
|
387 | |||
387 | \sa labelArmLengthFactor() |
|
388 | \sa labelArmLengthFactor() | |
388 | */ |
|
389 | */ | |
389 | void QPieSlice::setLabelArmLengthFactor(qreal factor) |
|
390 | void QPieSlice::setLabelArmLengthFactor(qreal factor) | |
390 | { |
|
391 | { | |
391 | if (!qFuzzyIsNull(d->m_labelArmLengthFactor - factor)) { |
|
392 | if (!qFuzzyIsNull(d->m_labelArmLengthFactor - factor)) { | |
392 | d->m_labelArmLengthFactor = factor; |
|
393 | d->m_labelArmLengthFactor = factor; | |
393 | emit changed(); |
|
394 | emit changed(); | |
394 | } |
|
395 | } | |
395 | } |
|
396 | } | |
396 |
|
397 | |||
397 | QTCOMMERCIALCHART_END_NAMESPACE |
|
398 | QTCOMMERCIALCHART_END_NAMESPACE | |
398 |
|
399 | |||
399 | QTCOMMERCIALCHART_USE_NAMESPACE |
|
400 | QTCOMMERCIALCHART_USE_NAMESPACE | |
400 | #include "moc_qpieslice.cpp" |
|
401 | #include "moc_qpieslice.cpp" |
@@ -1,382 +1,414 | |||||
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 "qchart.h" |
|
21 | #include "qchart.h" | |
22 | #include "qchart_p.h" |
|
22 | #include "qchart_p.h" | |
23 | #include <QGraphicsScene> |
|
23 | #include <QGraphicsScene> | |
24 | #include <QGraphicsSceneResizeEvent> |
|
24 | #include <QGraphicsSceneResizeEvent> | |
25 |
|
25 | |||
26 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
26 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
27 |
|
27 | |||
28 | /*! |
|
28 | /*! | |
29 | \enum QChart::ChartTheme |
|
29 | \enum QChart::ChartTheme | |
30 |
|
30 | |||
31 | This enum describes the theme used by the chart. |
|
31 | This enum describes the theme used by the chart. | |
32 |
|
32 | |||
33 | \value ChartThemeLight The default theme |
|
33 | \value ChartThemeLight The default theme | |
34 | \value ChartThemeBlueCerulean |
|
34 | \value ChartThemeBlueCerulean | |
35 | \value ChartThemeDark |
|
35 | \value ChartThemeDark | |
36 | \value ChartThemeBrownSand |
|
36 | \value ChartThemeBrownSand | |
37 | \value ChartThemeBlueNcs |
|
37 | \value ChartThemeBlueNcs | |
38 | \value ChartThemeHighContrast |
|
38 | \value ChartThemeHighContrast | |
39 | \value ChartThemeBlueIcy |
|
39 | \value ChartThemeBlueIcy | |
40 | \value ChartThemeCount Not really a theme; the total count of themes. |
|
40 | \value ChartThemeCount Not really a theme; the total count of themes. | |
41 | */ |
|
41 | */ | |
42 |
|
42 | |||
43 | /*! |
|
43 | /*! | |
44 | \enum QChart::AnimationOption |
|
44 | \enum QChart::AnimationOption | |
45 |
|
45 | |||
46 | For enabling/disabling animations. Defaults to NoAnimation. |
|
46 | For enabling/disabling animations. Defaults to NoAnimation. | |
47 |
|
47 | |||
48 | \value NoAnimation |
|
48 | \value NoAnimation | |
49 | \value GridAxisAnimations |
|
49 | \value GridAxisAnimations | |
50 | \value SeriesAnimations |
|
50 | \value SeriesAnimations | |
51 | \value AllAnimations |
|
51 | \value AllAnimations | |
52 | */ |
|
52 | */ | |
53 |
|
53 | |||
54 | /*! |
|
54 | /*! | |
55 | \class QChart |
|
55 | \class QChart | |
56 | \brief QtCommercial chart API. |
|
56 | \brief QtCommercial chart API. | |
57 |
|
57 | |||
58 | QChart is a QGraphicsWidget that you can show in a QGraphicsScene. It manages the graphical |
|
58 | QChart is a QGraphicsWidget that you can show in a QGraphicsScene. It manages the graphical | |
59 | representation of different types of QChartSeries and other chart related objects like |
|
59 | representation of different types of QChartSeries and other chart related objects like | |
60 | QChartAxis and QChartLegend. If you simply want to show a chart in a layout, you can use the |
|
60 | QChartAxis and QChartLegend. If you simply want to show a chart in a layout, you can use the | |
61 | convenience class QChartView instead of QChart. |
|
61 | convenience class QChartView instead of QChart. | |
62 | \sa QChartView |
|
62 | \sa QChartView | |
63 | */ |
|
63 | */ | |
64 |
|
64 | |||
65 | /*! |
|
65 | /*! | |
66 | Constructs a chart object which is a child of a\a parent. Parameter \a wFlags is passed to the QGraphicsWidget constructor. |
|
66 | Constructs a chart object which is a child of a\a parent. Parameter \a wFlags is passed to the QGraphicsWidget constructor. | |
67 | */ |
|
67 | */ | |
68 | QChart::QChart(QGraphicsItem *parent, Qt::WindowFlags wFlags) : QGraphicsWidget(parent,wFlags), |
|
68 | QChart::QChart(QGraphicsItem *parent, Qt::WindowFlags wFlags) : QGraphicsWidget(parent,wFlags), | |
69 | d_ptr(new QChartPrivate()) |
|
69 | d_ptr(new QChartPrivate()) | |
70 | { |
|
70 | { | |
71 | d_ptr->m_legend = new ScrolledQLegend(this); |
|
71 | d_ptr->m_legend = new ScrolledQLegend(this); | |
72 | d_ptr->m_legend->setVisible(false); |
|
72 | d_ptr->m_legend->setVisible(false); | |
73 | d_ptr->m_dataset = new ChartDataSet(this); |
|
73 | d_ptr->m_dataset = new ChartDataSet(this); | |
74 | d_ptr->m_presenter = new ChartPresenter(this,d_ptr->m_dataset); |
|
74 | d_ptr->m_presenter = new ChartPresenter(this,d_ptr->m_dataset); | |
75 | d_ptr->m_presenter->setTheme(QChart::ChartThemeLight, false); |
|
75 | d_ptr->m_presenter->setTheme(QChart::ChartThemeLight, false); | |
76 | d_ptr->createConnections(); |
|
76 | d_ptr->createConnections(); | |
77 | //TODO:fix me setMinimumSize(d_ptr->m_padding.left() * 3, d_ptr->m_padding.top() * 3); |
|
77 | //TODO:fix me setMinimumSize(d_ptr->m_padding.left() * 3, d_ptr->m_padding.top() * 3); | |
78 | } |
|
78 | } | |
79 |
|
79 | |||
80 | /*! |
|
80 | /*! | |
81 | Destroys the object and it's children, like QChartSeries and QChartAxis object added to it. |
|
81 | Destroys the object and it's children, like QChartSeries and QChartAxis object added to it. | |
82 | */ |
|
82 | */ | |
83 | QChart::~QChart() |
|
83 | QChart::~QChart() | |
84 | { |
|
84 | { | |
85 | //delete first presenter , since this is a root of all the graphical items |
|
85 | //delete first presenter , since this is a root of all the graphical items | |
86 | delete d_ptr->m_presenter; |
|
86 | delete d_ptr->m_presenter; | |
87 | d_ptr->m_presenter=0; |
|
87 | d_ptr->m_presenter=0; | |
88 | } |
|
88 | } | |
89 |
|
89 | |||
90 | /*! |
|
90 | /*! | |
91 | Adds the \a series and optional \a axisY onto the chart and takes the ownership of the objects. |
|
91 | Adds the \a series and optional \a axisY onto the chart and takes the ownership of the objects. | |
92 | If auto scaling is enabled, re-scales the axes the series is bound to (both the x axis and |
|
92 | If auto scaling is enabled, re-scales the axes the series is bound to (both the x axis and | |
93 | the y axis). |
|
93 | the y axis). | |
94 | */ |
|
94 | */ | |
95 | void QChart::addSeries(QSeries* series, QChartAxis* axisY) |
|
95 | void QChart::addSeries(QSeries* series, QChartAxis* axisY) | |
96 | { |
|
96 | { | |
97 | Q_ASSERT(series); |
|
97 | Q_ASSERT(series); | |
98 | d_ptr->m_dataset->addSeries(series, axisY); |
|
98 | d_ptr->m_dataset->addSeries(series, axisY); | |
99 | } |
|
99 | } | |
100 |
|
100 | |||
101 | /*! |
|
101 | /*! | |
102 | Removes the \a series specified in a perameter from the QChartView. |
|
102 | Removes the \a series specified in a perameter from the QChartView. | |
103 | It releses its ownership of the specified QChartSeries object. |
|
103 | It releses its ownership of the specified QChartSeries object. | |
104 | It does not delete the pointed QChartSeries data object |
|
104 | It does not delete the pointed QChartSeries data object | |
105 | \sa addSeries(), removeAllSeries() |
|
105 | \sa addSeries(), removeAllSeries() | |
106 | */ |
|
106 | */ | |
107 | void QChart::removeSeries(QSeries* series) |
|
107 | void QChart::removeSeries(QSeries* series) | |
108 | { |
|
108 | { | |
109 | Q_ASSERT(series); |
|
109 | Q_ASSERT(series); | |
110 | d_ptr->m_dataset->removeSeries(series); |
|
110 | d_ptr->m_dataset->removeSeries(series); | |
111 | } |
|
111 | } | |
112 |
|
112 | |||
113 | /*! |
|
113 | /*! | |
114 | Removes all the QChartSeries that have been added to the QChartView |
|
114 | Removes all the QChartSeries that have been added to the QChartView | |
115 | It also deletes the pointed QChartSeries data objects |
|
115 | It also deletes the pointed QChartSeries data objects | |
116 | \sa addSeries(), removeSeries() |
|
116 | \sa addSeries(), removeSeries() | |
117 | */ |
|
117 | */ | |
118 | void QChart::removeAllSeries() |
|
118 | void QChart::removeAllSeries() | |
119 | { |
|
119 | { | |
120 | d_ptr->m_dataset->removeAllSeries(); |
|
120 | d_ptr->m_dataset->removeAllSeries(); | |
121 | } |
|
121 | } | |
122 |
|
122 | |||
123 | /*! |
|
123 | /*! | |
124 | Sets the \a brush that is used for painting the background of the chart area. |
|
124 | Sets the \a brush that is used for painting the background of the chart area. | |
125 | */ |
|
125 | */ | |
126 | void QChart::setBackgroundBrush(const QBrush& brush) |
|
126 | void QChart::setBackgroundBrush(const QBrush& brush) | |
127 | { |
|
127 | { | |
128 | //TODO: refactor me |
|
128 | //TODO: refactor me | |
129 | d_ptr->m_presenter->createChartBackgroundItem(); |
|
129 | d_ptr->m_presenter->createChartBackgroundItem(); | |
130 | d_ptr->m_presenter->m_backgroundItem->setBrush(brush); |
|
130 | d_ptr->m_presenter->m_backgroundItem->setBrush(brush); | |
131 | d_ptr->m_presenter->m_backgroundItem->update(); |
|
131 | d_ptr->m_presenter->m_backgroundItem->update(); | |
132 | } |
|
132 | } | |
133 |
|
133 | |||
|
134 | /*! | |||
|
135 | Gets the brush that is used for painting the background of the chart area. | |||
|
136 | */ | |||
134 | QBrush QChart::backgroundBrush() const |
|
137 | QBrush QChart::backgroundBrush() const | |
135 | { |
|
138 | { | |
136 | //TODO: refactor me |
|
139 | //TODO: refactor me | |
137 | if (!d_ptr->m_presenter->m_backgroundItem) return QBrush(); |
|
140 | if (!d_ptr->m_presenter->m_backgroundItem) return QBrush(); | |
138 | return (d_ptr->m_presenter->m_backgroundItem)->brush(); |
|
141 | return (d_ptr->m_presenter->m_backgroundItem)->brush(); | |
139 | } |
|
142 | } | |
140 |
|
143 | |||
141 | /*! |
|
144 | /*! | |
142 | Sets the \a pen that is used for painting the background of the chart area. |
|
145 | Sets the \a pen that is used for painting the background of the chart area. | |
143 | */ |
|
146 | */ | |
144 | void QChart::setBackgroundPen(const QPen& pen) |
|
147 | void QChart::setBackgroundPen(const QPen& pen) | |
145 | { |
|
148 | { | |
146 | //TODO: refactor me |
|
149 | //TODO: refactor me | |
147 | d_ptr->m_presenter->createChartBackgroundItem(); |
|
150 | d_ptr->m_presenter->createChartBackgroundItem(); | |
148 | d_ptr->m_presenter->m_backgroundItem->setPen(pen); |
|
151 | d_ptr->m_presenter->m_backgroundItem->setPen(pen); | |
149 | d_ptr->m_presenter->m_backgroundItem->update(); |
|
152 | d_ptr->m_presenter->m_backgroundItem->update(); | |
150 | } |
|
153 | } | |
151 |
|
154 | |||
|
155 | /*! | |||
|
156 | Gets the pen that is used for painting the background of the chart area. | |||
|
157 | */ | |||
152 | QPen QChart::backgroundPen() const |
|
158 | QPen QChart::backgroundPen() const | |
153 | { |
|
159 | { | |
154 | //TODO: refactor me |
|
160 | //TODO: refactor me | |
155 | if (!d_ptr->m_presenter->m_backgroundItem) return QPen(); |
|
161 | if (!d_ptr->m_presenter->m_backgroundItem) return QPen(); | |
156 | return d_ptr->m_presenter->m_backgroundItem->pen(); |
|
162 | return d_ptr->m_presenter->m_backgroundItem->pen(); | |
157 | } |
|
163 | } | |
158 |
|
164 | |||
159 | /*! |
|
165 | /*! | |
160 | Sets the chart \a title. The description text that is drawn above the chart. |
|
166 | Sets the chart \a title. The description text that is drawn above the chart. | |
161 | */ |
|
167 | */ | |
162 | void QChart::setTitle(const QString& title) |
|
168 | void QChart::setTitle(const QString& title) | |
163 | { |
|
169 | { | |
164 | //TODO: refactor me |
|
170 | //TODO: refactor me | |
165 | d_ptr->m_presenter->createChartTitleItem(); |
|
171 | d_ptr->m_presenter->createChartTitleItem(); | |
166 | d_ptr->m_presenter->m_titleItem->setText(title); |
|
172 | d_ptr->m_presenter->m_titleItem->setText(title); | |
167 | d_ptr->m_presenter->updateLayout(); |
|
173 | d_ptr->m_presenter->updateLayout(); | |
168 | } |
|
174 | } | |
169 |
|
175 | |||
170 | /*! |
|
176 | /*! | |
171 | Returns the chart title. The description text that is drawn above the chart. |
|
177 | Returns the chart title. The description text that is drawn above the chart. | |
172 | */ |
|
178 | */ | |
173 | QString QChart::title() const |
|
179 | QString QChart::title() const | |
174 | { |
|
180 | { | |
175 | //TODO: refactor me |
|
181 | //TODO: refactor me | |
176 | if (d_ptr->m_presenter->m_titleItem) |
|
182 | if (d_ptr->m_presenter->m_titleItem) | |
177 | return d_ptr->m_presenter->m_titleItem->text(); |
|
183 | return d_ptr->m_presenter->m_titleItem->text(); | |
178 | else |
|
184 | else | |
179 | return QString(); |
|
185 | return QString(); | |
180 | } |
|
186 | } | |
181 |
|
187 | |||
182 | /*! |
|
188 | /*! | |
183 |
Sets the \a font that is used for |
|
189 | Sets the \a font that is used for drawing the chart description text that is rendered above the chart. | |
184 | */ |
|
190 | */ | |
185 | void QChart::setTitleFont(const QFont& font) |
|
191 | void QChart::setTitleFont(const QFont& font) | |
186 | { |
|
192 | { | |
187 | //TODO: refactor me |
|
193 | //TODO: refactor me | |
188 | d_ptr->m_presenter->createChartTitleItem(); |
|
194 | d_ptr->m_presenter->createChartTitleItem(); | |
189 | d_ptr->m_presenter->m_titleItem->setFont(font); |
|
195 | d_ptr->m_presenter->m_titleItem->setFont(font); | |
190 | d_ptr->m_presenter->updateLayout(); |
|
196 | d_ptr->m_presenter->updateLayout(); | |
191 | } |
|
197 | } | |
192 |
|
198 | |||
|
199 | /*! | |||
|
200 | Gets the font that is used for drawing the chart description text that is rendered above the chart. | |||
|
201 | */ | |||
193 | QFont QChart::titleFont() const |
|
202 | QFont QChart::titleFont() const | |
194 | { |
|
203 | { | |
195 | if (d_ptr->m_presenter->m_titleItem) |
|
204 | if (d_ptr->m_presenter->m_titleItem) | |
196 | return d_ptr->m_presenter->m_titleItem->font(); |
|
205 | return d_ptr->m_presenter->m_titleItem->font(); | |
197 | else |
|
206 | else | |
198 | return QFont(); |
|
207 | return QFont(); | |
199 | } |
|
208 | } | |
200 |
|
209 | |||
201 | /*! |
|
210 | /*! | |
202 | Sets the \a brush used for rendering the title text. |
|
211 | Sets the \a brush used for rendering the title text. | |
203 | */ |
|
212 | */ | |
204 | void QChart::setTitleBrush(const QBrush &brush) |
|
213 | void QChart::setTitleBrush(const QBrush &brush) | |
205 | { |
|
214 | { | |
206 | //TODO: refactor me |
|
215 | //TODO: refactor me | |
207 | d_ptr->m_presenter->createChartTitleItem(); |
|
216 | d_ptr->m_presenter->createChartTitleItem(); | |
208 | d_ptr->m_presenter->m_titleItem->setBrush(brush); |
|
217 | d_ptr->m_presenter->m_titleItem->setBrush(brush); | |
209 | d_ptr->m_presenter->updateLayout(); |
|
218 | d_ptr->m_presenter->updateLayout(); | |
210 | } |
|
219 | } | |
211 |
|
220 | |||
212 | /*! |
|
221 | /*! | |
213 | Returns the brush used for rendering the title text. |
|
222 | Returns the brush used for rendering the title text. | |
214 | */ |
|
223 | */ | |
215 | QBrush QChart::titleBrush() const |
|
224 | QBrush QChart::titleBrush() const | |
216 | { |
|
225 | { | |
217 | //TODO: refactor me |
|
226 | //TODO: refactor me | |
218 | if (!d_ptr->m_presenter->m_titleItem) return QBrush(); |
|
227 | if (!d_ptr->m_presenter->m_titleItem) return QBrush(); | |
219 | return d_ptr->m_presenter->m_titleItem->brush(); |
|
228 | return d_ptr->m_presenter->m_titleItem->brush(); | |
220 | } |
|
229 | } | |
221 |
|
230 | |||
222 | /*! |
|
231 | /*! | |
223 | Sets the \a theme used by the chart for rendering the graphical representation of the data |
|
232 | Sets the \a theme used by the chart for rendering the graphical representation of the data | |
224 | \sa theme() |
|
233 | \sa theme() | |
225 | */ |
|
234 | */ | |
226 | void QChart::setTheme(QChart::ChartTheme theme) |
|
235 | void QChart::setTheme(QChart::ChartTheme theme) | |
227 | { |
|
236 | { | |
228 | d_ptr->m_presenter->setTheme(theme); |
|
237 | d_ptr->m_presenter->setTheme(theme); | |
229 | } |
|
238 | } | |
230 |
|
239 | |||
231 | /*! |
|
240 | /*! | |
232 | Returns the theme enum used by the chart. |
|
241 | Returns the theme enum used by the chart. | |
233 | \sa ChartTheme, setTheme() |
|
242 | \sa ChartTheme, setTheme() | |
234 | */ |
|
243 | */ | |
235 | QChart::ChartTheme QChart::theme() const |
|
244 | QChart::ChartTheme QChart::theme() const | |
236 | { |
|
245 | { | |
237 | return d_ptr->m_presenter->theme(); |
|
246 | return d_ptr->m_presenter->theme(); | |
238 | } |
|
247 | } | |
239 |
|
248 | |||
240 | /*! |
|
249 | /*! | |
241 | Zooms in the view by a factor of 2 |
|
250 | Zooms in the view by a factor of 2 | |
242 | */ |
|
251 | */ | |
243 | void QChart::zoomIn() |
|
252 | void QChart::zoomIn() | |
244 | { |
|
253 | { | |
245 | d_ptr->m_presenter->zoomIn(); |
|
254 | d_ptr->m_presenter->zoomIn(); | |
246 | } |
|
255 | } | |
247 |
|
256 | |||
248 | /*! |
|
257 | /*! | |
249 | Zooms in the view to a maximum level at which \a rect is still fully visible. |
|
258 | Zooms in the view to a maximum level at which \a rect is still fully visible. | |
250 | */ |
|
259 | */ | |
251 | void QChart::zoomIn(const QRectF& rect) |
|
260 | void QChart::zoomIn(const QRectF& rect) | |
252 | { |
|
261 | { | |
253 | if (!rect.isValid()) return; |
|
262 | if (!rect.isValid()) return; | |
254 | d_ptr->m_presenter->zoomIn(rect); |
|
263 | d_ptr->m_presenter->zoomIn(rect); | |
255 | } |
|
264 | } | |
256 |
|
265 | |||
257 | /*! |
|
266 | /*! | |
258 | Restores the view zoom level to the previous one. |
|
267 | Restores the view zoom level to the previous one. | |
259 | */ |
|
268 | */ | |
260 | void QChart::zoomOut() |
|
269 | void QChart::zoomOut() | |
261 | { |
|
270 | { | |
262 | d_ptr->m_presenter->zoomOut(); |
|
271 | d_ptr->m_presenter->zoomOut(); | |
263 | } |
|
272 | } | |
264 |
|
273 | |||
265 | /*! |
|
274 | /*! | |
266 | Returns the pointer to the x axis object of the chart |
|
275 | Returns the pointer to the x axis object of the chart | |
267 | */ |
|
276 | */ | |
268 | QChartAxis* QChart::axisX() const |
|
277 | QChartAxis* QChart::axisX() const | |
269 | { |
|
278 | { | |
270 | return d_ptr->m_dataset->axisX(); |
|
279 | return d_ptr->m_dataset->axisX(); | |
271 | } |
|
280 | } | |
272 |
|
281 | |||
273 | /*! |
|
282 | /*! | |
274 |
Returns the pointer to the y axis object of the |
|
283 | Returns the pointer to the y axis object of the \a series | |
|
284 | If no \a series is provided then default Y axis of the chart is returned. | |||
275 | */ |
|
285 | */ | |
276 | QChartAxis* QChart::axisY(QSeries* series) const |
|
286 | QChartAxis* QChart::axisY(QSeries* series) const | |
277 | { |
|
287 | { | |
278 | return d_ptr->m_dataset->axisY(series); |
|
288 | return d_ptr->m_dataset->axisY(series); | |
279 | } |
|
289 | } | |
280 |
|
290 | |||
281 | /*! |
|
291 | /*! | |
282 | Returns the legend object of the chart. Ownership stays in chart. |
|
292 | Returns the legend object of the chart. Ownership stays in chart. | |
283 | */ |
|
293 | */ | |
284 | QLegend* QChart::legend() const |
|
294 | QLegend* QChart::legend() const | |
285 | { |
|
295 | { | |
286 | return d_ptr->m_legend; |
|
296 | return d_ptr->m_legend; | |
287 | } |
|
297 | } | |
288 |
|
298 | |||
|
299 | /*! | |||
|
300 | Returns the rect that contains information about margins (distance between chart widget edge and axes). | |||
|
301 | Individual margins can be obtained by calling left, top, right, bottom on the returned rect. | |||
|
302 | */ | |||
289 | QRectF QChart::margins() const |
|
303 | QRectF QChart::margins() const | |
290 | { |
|
304 | { | |
291 | return d_ptr->m_presenter->margins(); |
|
305 | return d_ptr->m_presenter->margins(); | |
292 | } |
|
306 | } | |
293 |
|
307 | |||
294 |
|
308 | |||
295 | /*! |
|
309 | /*! | |
296 | Resizes and updates the chart area using the \a event data |
|
310 | Resizes and updates the chart area using the \a event data | |
297 | */ |
|
311 | */ | |
298 | void QChart::resizeEvent(QGraphicsSceneResizeEvent *event) |
|
312 | void QChart::resizeEvent(QGraphicsSceneResizeEvent *event) | |
299 | { |
|
313 | { | |
300 | d_ptr->m_rect = QRectF(QPoint(0,0),event->newSize()); |
|
314 | d_ptr->m_rect = QRectF(QPoint(0,0),event->newSize()); | |
301 | QGraphicsWidget::resizeEvent(event); |
|
315 | QGraphicsWidget::resizeEvent(event); | |
302 | d_ptr->m_presenter->setGeometry(d_ptr->m_rect); |
|
316 | d_ptr->m_presenter->setGeometry(d_ptr->m_rect); | |
303 | } |
|
317 | } | |
304 |
|
318 | |||
305 | /*! |
|
319 | /*! | |
306 | Sets animation \a options for the chart |
|
320 | Sets animation \a options for the chart | |
307 | */ |
|
321 | */ | |
308 | void QChart::setAnimationOptions(AnimationOptions options) |
|
322 | void QChart::setAnimationOptions(AnimationOptions options) | |
309 | { |
|
323 | { | |
310 | d_ptr->m_presenter->setAnimationOptions(options); |
|
324 | d_ptr->m_presenter->setAnimationOptions(options); | |
311 | } |
|
325 | } | |
312 |
|
326 | |||
313 | /*! |
|
327 | /*! | |
314 | Returns animation options for the chart |
|
328 | Returns animation options for the chart | |
315 | */ |
|
329 | */ | |
316 | QChart::AnimationOptions QChart::animationOptions() const |
|
330 | QChart::AnimationOptions QChart::animationOptions() const | |
317 | { |
|
331 | { | |
318 | return d_ptr->m_presenter->animationOptions(); |
|
332 | return d_ptr->m_presenter->animationOptions(); | |
319 | } |
|
333 | } | |
320 |
|
334 | |||
|
335 | /*! | |||
|
336 | Scrolls the visible area of the chart to the left by the distance between two x axis ticks | |||
|
337 | */ | |||
321 | void QChart::scrollLeft() |
|
338 | void QChart::scrollLeft() | |
322 | { |
|
339 | { | |
323 | d_ptr->m_presenter->scroll(-d_ptr->m_presenter->chartGeometry().width()/(axisX()->ticksCount()-1),0); |
|
340 | d_ptr->m_presenter->scroll(-d_ptr->m_presenter->chartGeometry().width()/(axisX()->ticksCount()-1),0); | |
324 | } |
|
341 | } | |
325 |
|
342 | |||
|
343 | /*! | |||
|
344 | Scrolls the visible area of the chart to the right by the distance between two x axis ticks | |||
|
345 | */ | |||
326 | void QChart::scrollRight() |
|
346 | void QChart::scrollRight() | |
327 | { |
|
347 | { | |
328 | d_ptr->m_presenter->scroll(d_ptr->m_presenter->chartGeometry().width()/(axisX()->ticksCount()-1),0); |
|
348 | d_ptr->m_presenter->scroll(d_ptr->m_presenter->chartGeometry().width()/(axisX()->ticksCount()-1),0); | |
329 | } |
|
349 | } | |
330 |
|
350 | |||
|
351 | /*! | |||
|
352 | Scrolls the visible area of the chart up by the distance between two y axis ticks | |||
|
353 | */ | |||
331 | void QChart::scrollUp() |
|
354 | void QChart::scrollUp() | |
332 | { |
|
355 | { | |
333 | d_ptr->m_presenter->scroll(0,d_ptr->m_presenter->chartGeometry().width()/(axisY()->ticksCount()-1)); |
|
356 | d_ptr->m_presenter->scroll(0,d_ptr->m_presenter->chartGeometry().width()/(axisY()->ticksCount()-1)); | |
334 | } |
|
357 | } | |
335 |
|
358 | |||
|
359 | /*! | |||
|
360 | Scrolls the visible area of the chart down by the distance between two y axis ticks | |||
|
361 | */ | |||
336 | void QChart::scrollDown() |
|
362 | void QChart::scrollDown() | |
337 | { |
|
363 | { | |
338 | d_ptr->m_presenter->scroll(0,-d_ptr->m_presenter->chartGeometry().width()/(axisY()->ticksCount()-1)); |
|
364 | d_ptr->m_presenter->scroll(0,-d_ptr->m_presenter->chartGeometry().width()/(axisY()->ticksCount()-1)); | |
339 | } |
|
365 | } | |
340 |
|
366 | |||
|
367 | /*! | |||
|
368 | Sets the chart background visibility state to \a visible | |||
|
369 | */ | |||
341 | void QChart::setBackgroundVisible(bool visible) |
|
370 | void QChart::setBackgroundVisible(bool visible) | |
342 | { |
|
371 | { | |
343 | //TODO: refactor me |
|
372 | //TODO: refactor me | |
344 | d_ptr->m_presenter->createChartBackgroundItem(); |
|
373 | d_ptr->m_presenter->createChartBackgroundItem(); | |
345 | d_ptr->m_presenter->m_backgroundItem->setVisible(visible); |
|
374 | d_ptr->m_presenter->m_backgroundItem->setVisible(visible); | |
346 | } |
|
375 | } | |
347 |
|
376 | |||
|
377 | /*! | |||
|
378 | Returns the chart's background visibility state | |||
|
379 | */ | |||
348 | bool QChart::isBackgroundVisible() const |
|
380 | bool QChart::isBackgroundVisible() const | |
349 | { |
|
381 | { | |
350 | //TODO: refactor me |
|
382 | //TODO: refactor me | |
351 | if (!d_ptr->m_presenter->m_backgroundItem) return false; |
|
383 | if (!d_ptr->m_presenter->m_backgroundItem) return false; | |
352 | return d_ptr->m_presenter->m_backgroundItem->isVisible(); |
|
384 | return d_ptr->m_presenter->m_backgroundItem->isVisible(); | |
353 | } |
|
385 | } | |
354 |
|
386 | |||
355 | ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
|
387 | ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// | |
356 |
|
388 | |||
357 | QChartPrivate::QChartPrivate(): |
|
389 | QChartPrivate::QChartPrivate(): | |
358 | m_legend(0), |
|
390 | m_legend(0), | |
359 | m_dataset(0), |
|
391 | m_dataset(0), | |
360 | m_presenter(0) |
|
392 | m_presenter(0) | |
361 | { |
|
393 | { | |
362 |
|
394 | |||
363 | } |
|
395 | } | |
364 |
|
396 | |||
365 | QChartPrivate::~QChartPrivate() |
|
397 | QChartPrivate::~QChartPrivate() | |
366 | { |
|
398 | { | |
367 |
|
399 | |||
368 | } |
|
400 | } | |
369 |
|
401 | |||
370 | void QChartPrivate::createConnections() |
|
402 | void QChartPrivate::createConnections() | |
371 | { |
|
403 | { | |
372 | QObject::connect(m_dataset,SIGNAL(seriesAdded(QSeries*,Domain*)),m_legend,SLOT(handleSeriesAdded(QSeries*,Domain*))); |
|
404 | QObject::connect(m_dataset,SIGNAL(seriesAdded(QSeries*,Domain*)),m_legend,SLOT(handleSeriesAdded(QSeries*,Domain*))); | |
373 | QObject::connect(m_dataset,SIGNAL(seriesRemoved(QSeries*)),m_legend,SLOT(handleSeriesRemoved(QSeries*))); |
|
405 | QObject::connect(m_dataset,SIGNAL(seriesRemoved(QSeries*)),m_legend,SLOT(handleSeriesRemoved(QSeries*))); | |
374 | QObject::connect(m_dataset,SIGNAL(seriesAdded(QSeries*,Domain*)),m_presenter,SLOT(handleSeriesAdded(QSeries*,Domain*))); |
|
406 | QObject::connect(m_dataset,SIGNAL(seriesAdded(QSeries*,Domain*)),m_presenter,SLOT(handleSeriesAdded(QSeries*,Domain*))); | |
375 | QObject::connect(m_dataset,SIGNAL(seriesRemoved(QSeries*)),m_presenter,SLOT(handleSeriesRemoved(QSeries*))); |
|
407 | QObject::connect(m_dataset,SIGNAL(seriesRemoved(QSeries*)),m_presenter,SLOT(handleSeriesRemoved(QSeries*))); | |
376 | QObject::connect(m_dataset,SIGNAL(axisAdded(QChartAxis*,Domain*)),m_presenter,SLOT(handleAxisAdded(QChartAxis*,Domain*))); |
|
408 | QObject::connect(m_dataset,SIGNAL(axisAdded(QChartAxis*,Domain*)),m_presenter,SLOT(handleAxisAdded(QChartAxis*,Domain*))); | |
377 | QObject::connect(m_dataset,SIGNAL(axisRemoved(QChartAxis*)),m_presenter,SLOT(handleAxisRemoved(QChartAxis*))); |
|
409 | QObject::connect(m_dataset,SIGNAL(axisRemoved(QChartAxis*)),m_presenter,SLOT(handleAxisRemoved(QChartAxis*))); | |
378 | } |
|
410 | } | |
379 |
|
411 | |||
380 | #include "moc_qchart.cpp" |
|
412 | #include "moc_qchart.cpp" | |
381 |
|
413 | |||
382 | QTCOMMERCIALCHART_END_NAMESPACE |
|
414 | QTCOMMERCIALCHART_END_NAMESPACE |
@@ -1,92 +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 "qseries.h" |
|
21 | #include "qseries.h" | |
22 |
|
22 | |||
23 | /*! |
|
23 | /*! | |
24 | \class QSeries |
|
24 | \class QSeries | |
25 | \brief Base class for all QtCommercial Chart series. |
|
25 | \brief Base class for all QtCommercial Chart series. | |
26 | \mainclass |
|
26 | \mainclass | |
27 |
|
27 | |||
28 | Usually you use the series type specific inherited classes instead of the base class. |
|
28 | Usually you use the series type specific inherited classes instead of the base class. | |
29 | \sa QScatterSeries |
|
29 | \sa QScatterSeries | |
30 | */ |
|
30 | */ | |
31 |
|
31 | |||
32 | /*! |
|
32 | /*! | |
33 | \enum QSeries::QSeriesType |
|
33 | \enum QSeries::QSeriesType | |
34 |
|
34 | |||
35 | The type of the series object. |
|
35 | The type of the series object. | |
36 |
|
36 | |||
37 | \value SeriesTypeLine |
|
37 | \value SeriesTypeLine | |
38 | \value SeriesTypeArea |
|
38 | \value SeriesTypeArea | |
39 | \value SeriesTypeBar |
|
39 | \value SeriesTypeBar | |
40 | \value SeriesTypeStackedBar |
|
40 | \value SeriesTypeStackedBar | |
41 | \value SeriesTypePercentBar |
|
41 | \value SeriesTypePercentBar | |
42 | \value SeriesTypePie |
|
42 | \value SeriesTypePie | |
43 | \value SeriesTypeScatter |
|
43 | \value SeriesTypeScatter | |
44 | \value SeriesTypeSpline |
|
44 | \value SeriesTypeSpline | |
45 | */ |
|
45 | */ | |
46 |
|
46 | |||
47 | /*! |
|
47 | /*! | |
48 | \fn QSeries::QSeries(QObject *parent) |
|
48 | \fn QSeries::QSeries(QObject *parent) | |
49 | \brief Constructs ChartSeries object with \a parent. |
|
49 | \brief Constructs ChartSeries object with \a parent. | |
50 | */ |
|
50 | */ | |
51 |
|
51 | |||
52 | /*! |
|
52 | /*! | |
53 | \fn QSeries::~QSeries() |
|
53 | \fn QSeries::~QSeries() | |
54 | \brief Virtual destructor for the chart series. |
|
54 | \brief Virtual destructor for the chart series. | |
55 | */ |
|
55 | */ | |
56 |
|
56 | |||
57 | /*! |
|
57 | /*! | |
58 | \fn QSeriesType QSeries::type() const |
|
58 | \fn QSeriesType QSeries::type() const | |
59 | \brief The type of the series. |
|
59 | \brief The type of the series. | |
60 | */ |
|
60 | */ | |
61 |
|
61 | |||
62 | /*! |
|
62 | /*! | |
63 | \fn bool QSeries::setModel(QAbstractItemModel *model) |
|
63 | \fn bool QSeries::setModel(QAbstractItemModel *model) | |
64 | \brief Use the \a model to provide data for the series. The model overrides possible user data |
|
64 | \brief Use the \a model to provide data for the series. The model overrides possible user data | |
65 | set with QChartSeries type specific data setters. For example if you call both |
|
65 | set with QChartSeries type specific data setters. For example if you call both | |
66 | QScatterSeries::addData() and QScatterSeries::setModel, only the data provided by the model is |
|
66 | QScatterSeries::addData() and QScatterSeries::setModel, only the data provided by the model is | |
67 | used by the series. Returns true if the model is valid for the series. |
|
67 | used by the series. Returns true if the model is valid for the series. | |
68 | */ |
|
68 | */ | |
69 |
|
69 | |||
70 | /*! |
|
70 | /*! | |
|
71 | \fn QAbstractItemModel* QSeries::model() const | |||
|
72 | \brief Returns the pointer to the model that is used as the series data source | |||
|
73 | */ | |||
|
74 | ||||
|
75 | /*! | |||
71 | \property QString QSeries::name |
|
76 | \property QString QSeries::name | |
72 | \brief name of the series property |
|
77 | \brief name of the series property | |
73 | */ |
|
78 | */ | |
74 |
|
79 | |||
75 | /*! |
|
80 | /*! | |
76 | \fn void QSeries::setName(QString name) |
|
81 | \fn void QSeries::setName(QString name) | |
77 | \brief Sets a \a name for the series. |
|
82 | \brief Sets a \a name for the series. | |
78 |
|
83 | |||
79 | The name of a series is shown in the legend for QXYSeries. |
|
84 | The name of a series is shown in the legend for QXYSeries. | |
80 | \sa QChart::setTitle() |
|
85 | \sa QChart::setTitle() | |
81 | \sa QPieSlice::setLabel() |
|
86 | \sa QPieSlice::setLabel() | |
82 | \sa QBarSet::setName() |
|
87 | \sa QBarSet::setName() | |
83 | */ |
|
88 | */ | |
84 |
|
89 | |||
85 | /*! |
|
90 | /*! | |
86 | \fn QString QSeries::name() const |
|
91 | \fn QString QSeries::name() const | |
87 | \brief Returns the name of the series. |
|
92 | \brief Returns the name of the series. | |
88 | \sa setName() |
|
93 | \sa setName() | |
89 | */ |
|
94 | */ | |
90 |
|
95 | |||
91 | QTCOMMERCIALCHART_USE_NAMESPACE |
|
96 | QTCOMMERCIALCHART_USE_NAMESPACE | |
92 | #include "moc_qseries.cpp" |
|
97 | #include "moc_qseries.cpp" |
General Comments 0
You need to be logged in to leave comments.
Login now