##// END OF EJS Templates
tidying up legend marker code. Added QBarLegendMarker
sauimone -
r2174:c23be8282bab
parent child
Show More
@@ -0,0 +1,90
1 /****************************************************************************
2 **
3 ** Copyright (C) 2012 Digia Plc
4 ** All rights reserved.
5 ** For any questions to Digia, please use contact form at http://qt.digia.com
6 **
7 ** This file is part of the Qt Commercial Charts Add-on.
8 **
9 ** $QT_BEGIN_LICENSE$
10 ** Licensees holding valid Qt Commercial licenses may use this file in
11 ** accordance with the Qt Commercial License Agreement provided with the
12 ** Software or, alternatively, in accordance with the terms contained in
13 ** a written agreement between you and Digia.
14 **
15 ** If you have questions regarding the use of this file, please use
16 ** contact form at http://qt.digia.com
17 ** $QT_END_LICENSE$
18 **
19 ****************************************************************************/
20
21 #include "qbarlegendmarker.h"
22 #include "qbarlegendmarker_p.h"
23 #include <QAbstractBarSeries>
24 #include <QBarSet>
25 #include <QDebug>
26
27 QTCOMMERCIALCHART_BEGIN_NAMESPACE
28
29 QBarLegendMarker::QBarLegendMarker(QAbstractBarSeries* series, QBarSet* barset, QLegend *legend, QObject *parent) :
30 QLegendMarker(*new QBarLegendMarkerPrivate(this,series,barset,legend), parent)
31 {
32 }
33
34 QBarLegendMarker::~QBarLegendMarker()
35 {
36 // qDebug() << "deleting bar marker" << this;
37 }
38
39 /*!
40 \internal
41 */
42 QBarLegendMarker::QBarLegendMarker(QBarLegendMarkerPrivate &d, QObject *parent) :
43 QLegendMarker(d, parent)
44 {
45 }
46
47 QAbstractBarSeries *QBarLegendMarker::series()
48 {
49 Q_D(QBarLegendMarker);
50 return d->m_series;
51 }
52
53 QBarSet* QBarLegendMarker::peerObject()
54 {
55 Q_D(QBarLegendMarker);
56 return d->m_barset;
57 }
58
59 ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
60
61 QBarLegendMarkerPrivate::QBarLegendMarkerPrivate(QBarLegendMarker *q, QAbstractBarSeries *series, QBarSet *barset, QLegend *legend) :
62 QLegendMarkerPrivate(q,legend),
63 m_series(series),
64 m_barset(barset)
65 {
66 QObject::connect(m_barset, SIGNAL(penChanged()), this, SLOT(updated()));
67 QObject::connect(m_barset, SIGNAL(labelChanged()), this, SLOT(updated()));
68 QObject::connect(m_barset, SIGNAL(brushChanged()), this, SLOT(updated()));
69 updated();
70 }
71
72 QBarLegendMarkerPrivate::~QBarLegendMarkerPrivate()
73 {
74 QObject::disconnect(m_barset, SIGNAL(labelChanged()), this, SLOT(updated()));
75 QObject::disconnect(m_barset, SIGNAL(brushChanged()), this, SLOT(updated()));
76 QObject::disconnect(m_barset, SIGNAL(penChanged()), this, SLOT(updated()));
77 }
78
79 void QBarLegendMarkerPrivate::updated()
80 {
81 m_item->setPen(m_barset->pen());
82 m_item->setBrush(m_barset->brush());
83 m_item->setLabel(m_barset->label());
84 }
85
86 #include "moc_qbarlegendmarker.cpp"
87 #include "moc_qbarlegendmarker_p.cpp"
88
89 QTCOMMERCIALCHART_END_NAMESPACE
90
@@ -0,0 +1,59
1 /****************************************************************************
2 **
3 ** Copyright (C) 2012 Digia Plc
4 ** All rights reserved.
5 ** For any questions to Digia, please use contact form at http://qt.digia.com
6 **
7 ** This file is part of the Qt Commercial Charts Add-on.
8 **
9 ** $QT_BEGIN_LICENSE$
10 ** Licensees holding valid Qt Commercial licenses may use this file in
11 ** accordance with the Qt Commercial License Agreement provided with the
12 ** Software or, alternatively, in accordance with the terms contained in
13 ** a written agreement between you and Digia.
14 **
15 ** If you have questions regarding the use of this file, please use
16 ** contact form at http://qt.digia.com
17 ** $QT_END_LICENSE$
18 **
19 ****************************************************************************/
20 #ifndef QBARLEGENDMARKER_H
21 #define QBARLEGENDMARKER_H
22
23 #include <QChartGlobal>
24 #include <QLegendMarker>
25 #include <QAbstractBarSeries>
26 #include <QBarSet>
27 //#include "qbarlegendmarker_p.h"
28
29 QTCOMMERCIALCHART_BEGIN_NAMESPACE
30
31 class QLegend;
32 class QBarLegendMarkerPrivate;
33
34 class QTCOMMERCIALCHART_EXPORT QBarLegendMarker : public QLegendMarker
35 {
36 Q_OBJECT
37 public:
38 explicit QBarLegendMarker(QAbstractBarSeries* series, QBarSet* barset, QLegend *legend, QObject *parent = 0);
39 virtual ~QBarLegendMarker();
40
41 virtual QAbstractBarSeries* series();
42 virtual QBarSet* peerObject(); // TODO: rename to slice and remove these virtuals from base class?
43
44 protected:
45 QBarLegendMarker(QBarLegendMarkerPrivate &d, QObject *parent = 0);
46
47 //Q_SIGNALS:
48
49 //public Q_SLOTS:
50
51 private:
52 Q_DECLARE_PRIVATE(QBarLegendMarker)
53 Q_DISABLE_COPY(QBarLegendMarker)
54
55 };
56
57 QTCOMMERCIALCHART_END_NAMESPACE
58
59 #endif // QBARLEGENDMARKER_H
@@ -0,0 +1,67
1 /****************************************************************************
2 **
3 ** Copyright (C) 2012 Digia Plc
4 ** All rights reserved.
5 ** For any questions to Digia, please use contact form at http://qt.digia.com
6 **
7 ** This file is part of the Qt Commercial Charts Add-on.
8 **
9 ** $QT_BEGIN_LICENSE$
10 ** Licensees holding valid Qt Commercial licenses may use this file in
11 ** accordance with the Qt Commercial License Agreement provided with the
12 ** Software or, alternatively, in accordance with the terms contained in
13 ** a written agreement between you and Digia.
14 **
15 ** If you have questions regarding the use of this file, please use
16 ** contact form at http://qt.digia.com
17 ** $QT_END_LICENSE$
18 **
19 ****************************************************************************/
20
21 // W A R N I N G
22 // -------------
23 //
24 // This file is not part of the QtCommercial Chart API. It exists purely as an
25 // implementation detail. This header file may change from version to
26 // version without notice, or even be removed.
27 //
28 // We mean it.
29
30 #ifndef QBARLEGENDMARKER_P_H
31 #define QBARLEGENDMARKER_P_H
32
33 #include "qchartglobal.h"
34 #include "qlegendmarker_p.h"
35 #include "legendmarkeritem_p.h"
36 #include <QAbstractBarSeries>
37 #include <QBarSet>
38
39 #include <QDebug>
40
41 QTCOMMERCIALCHART_BEGIN_NAMESPACE
42
43 class QBarLegendMarker;
44
45 class QBarLegendMarkerPrivate : public QLegendMarkerPrivate
46 {
47 Q_OBJECT
48 public:
49 explicit QBarLegendMarkerPrivate(QBarLegendMarker *q, QAbstractBarSeries *series, QBarSet *barset, QLegend *legend);
50 virtual ~QBarLegendMarkerPrivate();
51
52 public Q_SLOTS:
53 virtual void updated();
54
55 private:
56 QBarLegendMarker *q_ptr;
57
58 QAbstractBarSeries* m_series;
59 QBarSet* m_barset;
60
61 friend class QLegendPrivate; // TODO: Is this needed?
62 Q_DECLARE_PUBLIC(QBarLegendMarker)
63 };
64
65 QTCOMMERCIALCHART_END_NAMESPACE
66
67 #endif // QBARLEGENDMARKER_P_H
@@ -1,827 +1,826
1 /****************************************************************************
1 /****************************************************************************
2 **
2 **
3 ** Copyright (C) 2012 Digia Plc
3 ** Copyright (C) 2012 Digia Plc
4 ** All rights reserved.
4 ** All rights reserved.
5 ** For any questions to Digia, please use contact form at http://qt.digia.com
5 ** For any questions to Digia, please use contact form at http://qt.digia.com
6 **
6 **
7 ** This file is part of the Qt Commercial Charts Add-on.
7 ** This file is part of the Qt Commercial Charts Add-on.
8 **
8 **
9 ** $QT_BEGIN_LICENSE$
9 ** $QT_BEGIN_LICENSE$
10 ** Licensees holding valid Qt Commercial licenses may use this file in
10 ** Licensees holding valid Qt Commercial licenses may use this file in
11 ** accordance with the Qt Commercial License Agreement provided with the
11 ** accordance with the Qt Commercial License Agreement provided with the
12 ** Software or, alternatively, in accordance with the terms contained in
12 ** Software or, alternatively, in accordance with the terms contained in
13 ** a written agreement between you and Digia.
13 ** a written agreement between you and Digia.
14 **
14 **
15 ** If you have questions regarding the use of this file, please use
15 ** If you have questions regarding the use of this file, please use
16 ** contact form at http://qt.digia.com
16 ** contact form at http://qt.digia.com
17 ** $QT_END_LICENSE$
17 ** $QT_END_LICENSE$
18 **
18 **
19 ****************************************************************************/
19 ****************************************************************************/
20
20
21 #include "qabstractbarseries.h"
21 #include "qabstractbarseries.h"
22 #include "qabstractbarseries_p.h"
22 #include "qabstractbarseries_p.h"
23 #include "qbarset.h"
23 #include "qbarset.h"
24 #include "qbarset_p.h"
24 #include "qbarset_p.h"
25 #include "domain_p.h"
25 #include "domain_p.h"
26 #include "legendmarker_p.h"
26 #include "legendmarker_p.h"
27 #include "chartdataset_p.h"
27 #include "chartdataset_p.h"
28 #include "charttheme_p.h"
28 #include "charttheme_p.h"
29 #include "qvalueaxis.h"
29 #include "qvalueaxis.h"
30 #include "qbarcategoryaxis.h"
30 #include "qbarcategoryaxis.h"
31
31
32 #include "qbarlegendmarker.h"
33
32 QTCOMMERCIALCHART_BEGIN_NAMESPACE
34 QTCOMMERCIALCHART_BEGIN_NAMESPACE
33
35
34 /*!
36 /*!
35 \class QAbstractBarSeries
37 \class QAbstractBarSeries
36 \brief Series for creating a bar chart
38 \brief Series for creating a bar chart
37 \mainclass
39 \mainclass
38
40
39 QAbstractBarSeries represents a series of data shown as bars. The purpose of this class is to draw bars to
41 QAbstractBarSeries represents a series of data shown as bars. The purpose of this class is to draw bars to
40 the position defined by data. Single bar is defined by QPointF, where x value is the x-coordinate of the bar
42 the position defined by data. Single bar is defined by QPointF, where x value is the x-coordinate of the bar
41 and y-value is the height of the bar. The category names are ignored with this series and x-axis
43 and y-value is the height of the bar. The category names are ignored with this series and x-axis
42 shows the x-values.
44 shows the x-values.
43
45
44 See the \l {BarChart Example} {bar chart example} to learn how to create a simple bar chart.
46 See the \l {BarChart Example} {bar chart example} to learn how to create a simple bar chart.
45 \image examples_barchart.png
47 \image examples_barchart.png
46
48
47 \sa QBarSet, QStackedBarSeries, QPercentBarSeries
49 \sa QBarSet, QStackedBarSeries, QPercentBarSeries
48 */
50 */
49 /*!
51 /*!
50 \qmlclass AbstractBarSeries QAbstractBarSeries
52 \qmlclass AbstractBarSeries QAbstractBarSeries
51 \inherits QAbstractSeries
53 \inherits QAbstractSeries
52
54
53 The following QML shows how to create a simple bar chart:
55 The following QML shows how to create a simple bar chart:
54 \snippet ../demos/qmlchart/qml/qmlchart/View6.qml 1
56 \snippet ../demos/qmlchart/qml/qmlchart/View6.qml 1
55
57
56 \beginfloatleft
58 \beginfloatleft
57 \image demos_qmlchart6.png
59 \image demos_qmlchart6.png
58 \endfloat
60 \endfloat
59 \clearfloat
61 \clearfloat
60 */
62 */
61
63
62 /*!
64 /*!
63 \property QAbstractBarSeries::barWidth
65 \property QAbstractBarSeries::barWidth
64 The width of the bars of the series. The unit of \a width is the unit of x-axis. The minimum width for bars
66 The width of the bars of the series. The unit of \a width is the unit of x-axis. The minimum width for bars
65 is zero and negative values are treated as zero. Setting the width to zero means that width of the bar on screen
67 is zero and negative values are treated as zero. Setting the width to zero means that width of the bar on screen
66 is one pixel no matter what the scale of x-axis is. Bars wider than zero are scaled with x-axis.
68 is one pixel no matter what the scale of x-axis is. Bars wider than zero are scaled with x-axis.
67 Note that with QBarSeries this value means the width of one group of bars instead of just one bar.
69 Note that with QBarSeries this value means the width of one group of bars instead of just one bar.
68 \sa QBarSeries
70 \sa QBarSeries
69 */
71 */
70 /*!
72 /*!
71 \qmlproperty real AbstractBarSeries::barWidth
73 \qmlproperty real AbstractBarSeries::barWidth
72 The width of the bars of the series. The unit of width is the unit of x-axis. The minimum width for bars
74 The width of the bars of the series. The unit of width is the unit of x-axis. The minimum width for bars
73 is zero and negative values are treated as zero. Setting the width to zero means that width of the bar on screen
75 is zero and negative values are treated as zero. Setting the width to zero means that width of the bar on screen
74 is one pixel no matter what the scale of x-axis is. Bars wider than zero are scaled with x-axis.
76 is one pixel no matter what the scale of x-axis is. Bars wider than zero are scaled with x-axis.
75 Note that with QBarSeries this value means the width of one group of bars instead of just one bar.
77 Note that with QBarSeries this value means the width of one group of bars instead of just one bar.
76 */
78 */
77
79
78 /*!
80 /*!
79 \property QAbstractBarSeries::count
81 \property QAbstractBarSeries::count
80 Holds the number of sets in series.
82 Holds the number of sets in series.
81 */
83 */
82 /*!
84 /*!
83 \qmlproperty int AbstractBarSeries::count
85 \qmlproperty int AbstractBarSeries::count
84 Holds the number of sets in series.
86 Holds the number of sets in series.
85 */
87 */
86
88
87 /*!
89 /*!
88 \property QAbstractBarSeries::labelsVisible
90 \property QAbstractBarSeries::labelsVisible
89 Defines the visibility of the labels in series
91 Defines the visibility of the labels in series
90 */
92 */
91 /*!
93 /*!
92 \qmlproperty bool AbstractBarSeries::labelsVisible
94 \qmlproperty bool AbstractBarSeries::labelsVisible
93 Defines the visibility of the labels in series
95 Defines the visibility of the labels in series
94 */
96 */
95
97
96 /*!
98 /*!
97 \fn void QAbstractBarSeries::clicked(int index, QBarSet *barset)
99 \fn void QAbstractBarSeries::clicked(int index, QBarSet *barset)
98 The signal is emitted if the user clicks with a mouse on top of QBarSet \a barset.
100 The signal is emitted if the user clicks with a mouse on top of QBarSet \a barset.
99 Clicked bar inside set is indexed by \a index
101 Clicked bar inside set is indexed by \a index
100 */
102 */
101 /*!
103 /*!
102 \qmlsignal AbstractBarSeries::onClicked(int index, BarSet barset)
104 \qmlsignal AbstractBarSeries::onClicked(int index, BarSet barset)
103 The signal is emitted if the user clicks with a mouse on top of BarSet.
105 The signal is emitted if the user clicks with a mouse on top of BarSet.
104 Clicked bar inside set is indexed by \a index
106 Clicked bar inside set is indexed by \a index
105 */
107 */
106
108
107 /*!
109 /*!
108 \fn void QAbstractBarSeries::hovered(bool status, QBarSet* barset)
110 \fn void QAbstractBarSeries::hovered(bool status, QBarSet* barset)
109
111
110 The signal is emitted if mouse is hovered on top of series.
112 The signal is emitted if mouse is hovered on top of series.
111 Parameter \a barset is the pointer of barset, where hover happened.
113 Parameter \a barset is the pointer of barset, where hover happened.
112 Parameter \a status is true, if mouse entered on top of series, false if mouse left from top of series.
114 Parameter \a status is true, if mouse entered on top of series, false if mouse left from top of series.
113 */
115 */
114 /*!
116 /*!
115 \qmlsignal AbstractBarSeries::onHovered(bool status, BarSet barset)
117 \qmlsignal AbstractBarSeries::onHovered(bool status, BarSet barset)
116
118
117 The signal is emitted if mouse is hovered on top of series.
119 The signal is emitted if mouse is hovered on top of series.
118 Parameter \a barset is the pointer of barset, where hover happened.
120 Parameter \a barset is the pointer of barset, where hover happened.
119 Parameter \a status is true, if mouse entered on top of series, false if mouse left from top of series.
121 Parameter \a status is true, if mouse entered on top of series, false if mouse left from top of series.
120 */
122 */
121
123
122 /*!
124 /*!
123 \fn void QAbstractBarSeries::countChanged()
125 \fn void QAbstractBarSeries::countChanged()
124 This signal is emitted when barset count has been changed, for example by append or remove.
126 This signal is emitted when barset count has been changed, for example by append or remove.
125 */
127 */
126 /*!
128 /*!
127 \qmlsignal AbstractBarSeries::onCountChanged()
129 \qmlsignal AbstractBarSeries::onCountChanged()
128 This signal is emitted when barset count has been changed, for example by append or remove.
130 This signal is emitted when barset count has been changed, for example by append or remove.
129 */
131 */
130
132
131 /*!
133 /*!
132 \fn void QAbstractBarSeries::labelsVisibleChanged()
134 \fn void QAbstractBarSeries::labelsVisibleChanged()
133 This signal is emitted when labels visibility have changed.
135 This signal is emitted when labels visibility have changed.
134 \sa isLabelsVisible(), setLabelsVisible()
136 \sa isLabelsVisible(), setLabelsVisible()
135 */
137 */
136
138
137 /*!
139 /*!
138 \fn void QAbstractBarSeries::barsetsAdded(QList<QBarSet*> sets)
140 \fn void QAbstractBarSeries::barsetsAdded(QList<QBarSet*> sets)
139 This signal is emitted when \a sets have been added to the series.
141 This signal is emitted when \a sets have been added to the series.
140 \sa append(), insert()
142 \sa append(), insert()
141 */
143 */
142 /*!
144 /*!
143 \qmlsignal AbstractBarSeries::onBarsetsAdded(BarSet barset)
145 \qmlsignal AbstractBarSeries::onBarsetsAdded(BarSet barset)
144 Emitted when \a barset has been added to the series.
146 Emitted when \a barset has been added to the series.
145 */
147 */
146
148
147 /*!
149 /*!
148 \fn void QAbstractBarSeries::barsetsRemoved(QList<QBarSet*> sets)
150 \fn void QAbstractBarSeries::barsetsRemoved(QList<QBarSet*> sets)
149 This signal is emitted when \a sets have been removed from the series.
151 This signal is emitted when \a sets have been removed from the series.
150 \sa remove()
152 \sa remove()
151 */
153 */
152 /*!
154 /*!
153 \qmlsignal AbstractBarSeries::onBarsetsRemoved(BarSet barset)
155 \qmlsignal AbstractBarSeries::onBarsetsRemoved(BarSet barset)
154 Emitted when \a barset has been removed from the series.
156 Emitted when \a barset has been removed from the series.
155 */
157 */
156
158
157 /*!
159 /*!
158 \qmlmethod BarSet AbstractBarSeries::at(int index)
160 \qmlmethod BarSet AbstractBarSeries::at(int index)
159 Returns bar set at \a index. Returns null if the index is not valid.
161 Returns bar set at \a index. Returns null if the index is not valid.
160 */
162 */
161
163
162 /*!
164 /*!
163 \qmlmethod BarSet AbstractBarSeries::append(string label, VariantList values)
165 \qmlmethod BarSet AbstractBarSeries::append(string label, VariantList values)
164 Adds a new bar set with \a label and \a values to \a index. Values is a list of reals.
166 Adds a new bar set with \a label and \a values to \a index. Values is a list of reals.
165 For example:
167 For example:
166 \code
168 \code
167 myBarSeries.append("set 1", [0, 0.2, 0.2, 0.5, 0.4, 1.5, 0.9]);
169 myBarSeries.append("set 1", [0, 0.2, 0.2, 0.5, 0.4, 1.5, 0.9]);
168 \endcode
170 \endcode
169 */
171 */
170
172
171 /*!
173 /*!
172 \qmlmethod BarSet AbstractBarSeries::insert(int index, string label, VariantList values)
174 \qmlmethod BarSet AbstractBarSeries::insert(int index, string label, VariantList values)
173 Inserts a new bar set with \a label and \a values to \a index. Values can be a list of reals or a list of XYPoints.
175 Inserts a new bar set with \a label and \a values to \a index. Values can be a list of reals or a list of XYPoints.
174 If index is zero or smaller, the new barset is prepended. If the index is count or bigger, the new barset is
176 If index is zero or smaller, the new barset is prepended. If the index is count or bigger, the new barset is
175 appended.
177 appended.
176 \sa AbstractBarSeries::append()
178 \sa AbstractBarSeries::append()
177 */
179 */
178
180
179 /*!
181 /*!
180 \qmlmethod bool AbstractBarSeries::remove(BarSet barset)
182 \qmlmethod bool AbstractBarSeries::remove(BarSet barset)
181 Removes the barset from the series. Returns true if successful, false otherwise.
183 Removes the barset from the series. Returns true if successful, false otherwise.
182 */
184 */
183
185
184 /*!
186 /*!
185 \qmlmethod AbstractBarSeries::clear()
187 \qmlmethod AbstractBarSeries::clear()
186 Removes all barsets from the series.
188 Removes all barsets from the series.
187 */
189 */
188
190
189 /*!
191 /*!
190 Destructs abstractbarseries and owned barsets.
192 Destructs abstractbarseries and owned barsets.
191 */
193 */
192 QAbstractBarSeries::~QAbstractBarSeries()
194 QAbstractBarSeries::~QAbstractBarSeries()
193 {
195 {
194
196
195 }
197 }
196
198
197 /*!
199 /*!
198 \internal
200 \internal
199 */
201 */
200 QAbstractBarSeries::QAbstractBarSeries(QAbstractBarSeriesPrivate &o, QObject *parent)
202 QAbstractBarSeries::QAbstractBarSeries(QAbstractBarSeriesPrivate &o, QObject *parent)
201 : QAbstractSeries(o, parent)
203 : QAbstractSeries(o, parent)
202 {
204 {
203 Q_D(QAbstractSeries);
205 Q_D(QAbstractSeries);
204 QObject::connect(this, SIGNAL(countChanged()), d, SIGNAL(countChanged()));
206 QObject::connect(this, SIGNAL(countChanged()), d, SIGNAL(countChanged()));
205 }
207 }
206
208
207 /*!
209 /*!
208 Sets the width of the bars of the series. The unit of \a width is the unit of x-axis. The minimum width for bars
210 Sets the width of the bars of the series. The unit of \a width is the unit of x-axis. The minimum width for bars
209 is zero and negative values are treated as zero. Setting the width to zero means that width of the bar on screen
211 is zero and negative values are treated as zero. Setting the width to zero means that width of the bar on screen
210 is one pixel no matter what the scale of x-axis is. Bars wider than zero are scaled with x-axis.
212 is one pixel no matter what the scale of x-axis is. Bars wider than zero are scaled with x-axis.
211 Note that with \link QBarSeries \endlink this value means the width of one group of bars instead of just one bar.
213 Note that with \link QBarSeries \endlink this value means the width of one group of bars instead of just one bar.
212 */
214 */
213 void QAbstractBarSeries::setBarWidth(qreal width)
215 void QAbstractBarSeries::setBarWidth(qreal width)
214 {
216 {
215 Q_D(QAbstractBarSeries);
217 Q_D(QAbstractBarSeries);
216 d->setBarWidth(width);
218 d->setBarWidth(width);
217 }
219 }
218
220
219 /*!
221 /*!
220 Returns the width of the bars of the series.
222 Returns the width of the bars of the series.
221 \sa setBarWidth()
223 \sa setBarWidth()
222 */
224 */
223 qreal QAbstractBarSeries::barWidth() const
225 qreal QAbstractBarSeries::barWidth() const
224 {
226 {
225 Q_D(const QAbstractBarSeries);
227 Q_D(const QAbstractBarSeries);
226 return d->barWidth();
228 return d->barWidth();
227 }
229 }
228
230
229 /*!
231 /*!
230 Adds a set of bars to series. Takes ownership of \a set. If the set is null or is already in series, it won't be appended.
232 Adds a set of bars to series. Takes ownership of \a set. If the set is null or is already in series, it won't be appended.
231 Returns true, if appending succeeded.
233 Returns true, if appending succeeded.
232 */
234 */
233 bool QAbstractBarSeries::append(QBarSet *set)
235 bool QAbstractBarSeries::append(QBarSet *set)
234 {
236 {
235 Q_D(QAbstractBarSeries);
237 Q_D(QAbstractBarSeries);
236 bool success = d->append(set);
238 bool success = d->append(set);
237 if (success) {
239 if (success) {
238 QList<QBarSet *> sets;
240 QList<QBarSet *> sets;
239 sets.append(set);
241 sets.append(set);
240 set->setParent(this);
242 set->setParent(this);
241 emit barsetsAdded(sets);
243 emit barsetsAdded(sets);
242 emit countChanged();
244 emit countChanged();
243 }
245 }
244 return success;
246 return success;
245 }
247 }
246
248
247 /*!
249 /*!
248 Removes barset from series. Releases ownership of \a set. Deletes the set, if remove
250 Removes barset from series. Releases ownership of \a set. Deletes the set, if remove
249 was successful.
251 was successful.
250 Returns true, if set was removed.
252 Returns true, if set was removed.
251 */
253 */
252 bool QAbstractBarSeries::remove(QBarSet *set)
254 bool QAbstractBarSeries::remove(QBarSet *set)
253 {
255 {
254 Q_D(QAbstractBarSeries);
256 Q_D(QAbstractBarSeries);
255 bool success = d->remove(set);
257 bool success = d->remove(set);
256 if (success) {
258 if (success) {
257 QList<QBarSet *> sets;
259 QList<QBarSet *> sets;
258 sets.append(set);
260 sets.append(set);
259 set->setParent(0);
261 set->setParent(0);
260 emit barsetsRemoved(sets);
262 emit barsetsRemoved(sets);
261 emit countChanged();
263 emit countChanged();
262 delete set;
264 delete set;
263 set = 0;
265 set = 0;
264 }
266 }
265 return success;
267 return success;
266 }
268 }
267
269
268 /*!
270 /*!
269 Takes a single \a set from the series. Does not delete the barset object.
271 Takes a single \a set from the series. Does not delete the barset object.
270
272
271 NOTE: The series remains as the barset's parent object. You must set the
273 NOTE: The series remains as the barset's parent object. You must set the
272 parent object to take full ownership.
274 parent object to take full ownership.
273
275
274 Returns true if take was successful.
276 Returns true if take was successful.
275 */
277 */
276 bool QAbstractBarSeries::take(QBarSet *set)
278 bool QAbstractBarSeries::take(QBarSet *set)
277 {
279 {
278 Q_D(QAbstractBarSeries);
280 Q_D(QAbstractBarSeries);
279 bool success = d->remove(set);
281 bool success = d->remove(set);
280 if (success) {
282 if (success) {
281 QList<QBarSet *> sets;
283 QList<QBarSet *> sets;
282 sets.append(set);
284 sets.append(set);
283 emit barsetsRemoved(sets);
285 emit barsetsRemoved(sets);
284 emit countChanged();
286 emit countChanged();
285 }
287 }
286 return success;
288 return success;
287 }
289 }
288
290
289 /*!
291 /*!
290 Adds a list of barsets to series. Takes ownership of \a sets.
292 Adds a list of barsets to series. Takes ownership of \a sets.
291 Returns true, if all sets were appended successfully. If any of the sets is null or is already appended to series,
293 Returns true, if all sets were appended successfully. If any of the sets is null or is already appended to series,
292 nothing is appended and function returns false. If any of the sets is in list more than once, nothing is appended
294 nothing is appended and function returns false. If any of the sets is in list more than once, nothing is appended
293 and function returns false.
295 and function returns false.
294 */
296 */
295 bool QAbstractBarSeries::append(QList<QBarSet *> sets)
297 bool QAbstractBarSeries::append(QList<QBarSet *> sets)
296 {
298 {
297 Q_D(QAbstractBarSeries);
299 Q_D(QAbstractBarSeries);
298 bool success = d->append(sets);
300 bool success = d->append(sets);
299 if (success) {
301 if (success) {
300 emit barsetsAdded(sets);
302 emit barsetsAdded(sets);
301 emit countChanged();
303 emit countChanged();
302 }
304 }
303 return success;
305 return success;
304 }
306 }
305
307
306 /*!
308 /*!
307 Insert a set of bars to series at \a index postion. Takes ownership of \a set. If the set is null or is already in series, it won't be appended.
309 Insert a set of bars to series at \a index postion. Takes ownership of \a set. If the set is null or is already in series, it won't be appended.
308 Returns true, if inserting succeeded.
310 Returns true, if inserting succeeded.
309
311
310 */
312 */
311 bool QAbstractBarSeries::insert(int index, QBarSet *set)
313 bool QAbstractBarSeries::insert(int index, QBarSet *set)
312 {
314 {
313 Q_D(QAbstractBarSeries);
315 Q_D(QAbstractBarSeries);
314 bool success = d->insert(index, set);
316 bool success = d->insert(index, set);
315 if (success) {
317 if (success) {
316 QList<QBarSet *> sets;
318 QList<QBarSet *> sets;
317 sets.append(set);
319 sets.append(set);
318 emit barsetsAdded(sets);
320 emit barsetsAdded(sets);
319 emit countChanged();
321 emit countChanged();
320 }
322 }
321 return success;
323 return success;
322 }
324 }
323
325
324 /*!
326 /*!
325 Removes all barsets from the series. Deletes removed sets.
327 Removes all barsets from the series. Deletes removed sets.
326 */
328 */
327 void QAbstractBarSeries::clear()
329 void QAbstractBarSeries::clear()
328 {
330 {
329 Q_D(QAbstractBarSeries);
331 Q_D(QAbstractBarSeries);
330 QList<QBarSet *> sets = barSets();
332 QList<QBarSet *> sets = barSets();
331 bool success = d->remove(sets);
333 bool success = d->remove(sets);
332 if (success) {
334 if (success) {
333 emit barsetsRemoved(sets);
335 emit barsetsRemoved(sets);
334 emit countChanged();
336 emit countChanged();
335 foreach (QBarSet *set, sets)
337 foreach (QBarSet *set, sets)
336 delete set;
338 delete set;
337 }
339 }
338 }
340 }
339
341
340 /*!
342 /*!
341 Returns number of sets in series.
343 Returns number of sets in series.
342 */
344 */
343 int QAbstractBarSeries::count() const
345 int QAbstractBarSeries::count() const
344 {
346 {
345 Q_D(const QAbstractBarSeries);
347 Q_D(const QAbstractBarSeries);
346 return d->m_barSets.count();
348 return d->m_barSets.count();
347 }
349 }
348
350
349 /*!
351 /*!
350 Returns a list of sets in series. Keeps ownership of sets.
352 Returns a list of sets in series. Keeps ownership of sets.
351 */
353 */
352 QList<QBarSet *> QAbstractBarSeries::barSets() const
354 QList<QBarSet *> QAbstractBarSeries::barSets() const
353 {
355 {
354 Q_D(const QAbstractBarSeries);
356 Q_D(const QAbstractBarSeries);
355 return d->m_barSets;
357 return d->m_barSets;
356 }
358 }
357
359
358 /*!
360 /*!
359 Sets the visibility of labels in series to \a visible
361 Sets the visibility of labels in series to \a visible
360 */
362 */
361 void QAbstractBarSeries::setLabelsVisible(bool visible)
363 void QAbstractBarSeries::setLabelsVisible(bool visible)
362 {
364 {
363 Q_D(QAbstractBarSeries);
365 Q_D(QAbstractBarSeries);
364 if (d->m_labelsVisible != visible) {
366 if (d->m_labelsVisible != visible) {
365 d->setLabelsVisible(visible);
367 d->setLabelsVisible(visible);
366 emit labelsVisibleChanged();
368 emit labelsVisibleChanged();
367 }
369 }
368 }
370 }
369
371
370 /*!
372 /*!
371 Returns the visibility of labels
373 Returns the visibility of labels
372 */
374 */
373 bool QAbstractBarSeries::isLabelsVisible() const
375 bool QAbstractBarSeries::isLabelsVisible() const
374 {
376 {
375 Q_D(const QAbstractBarSeries);
377 Q_D(const QAbstractBarSeries);
376 return d->m_labelsVisible;
378 return d->m_labelsVisible;
377 }
379 }
378
380
379 ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
381 ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
380
382
381 QAbstractBarSeriesPrivate::QAbstractBarSeriesPrivate(QAbstractBarSeries *q) :
383 QAbstractBarSeriesPrivate::QAbstractBarSeriesPrivate(QAbstractBarSeries *q) :
382 QAbstractSeriesPrivate(q),
384 QAbstractSeriesPrivate(q),
383 m_barWidth(0.5), // Default value is 50% of category width
385 m_barWidth(0.5), // Default value is 50% of category width
384 m_labelsVisible(false),
386 m_labelsVisible(false),
385 m_visible(true)
387 m_visible(true)
386 {
388 {
387 }
389 }
388
390
389 int QAbstractBarSeriesPrivate::categoryCount() const
391 int QAbstractBarSeriesPrivate::categoryCount() const
390 {
392 {
391 // No categories defined. return count of longest set.
393 // No categories defined. return count of longest set.
392 int count = 0;
394 int count = 0;
393 for (int i = 0; i < m_barSets.count(); i++) {
395 for (int i = 0; i < m_barSets.count(); i++) {
394 if (m_barSets.at(i)->count() > count)
396 if (m_barSets.at(i)->count() > count)
395 count = m_barSets.at(i)->count();
397 count = m_barSets.at(i)->count();
396 }
398 }
397
399
398 return count;
400 return count;
399 }
401 }
400
402
401 void QAbstractBarSeriesPrivate::setBarWidth(qreal width)
403 void QAbstractBarSeriesPrivate::setBarWidth(qreal width)
402 {
404 {
403 if (width < 0.0)
405 if (width < 0.0)
404 width = 0.0;
406 width = 0.0;
405 m_barWidth = width;
407 m_barWidth = width;
406 emit updatedLayout();
408 emit updatedLayout();
407 }
409 }
408
410
409 qreal QAbstractBarSeriesPrivate::barWidth() const
411 qreal QAbstractBarSeriesPrivate::barWidth() const
410 {
412 {
411 return m_barWidth;
413 return m_barWidth;
412 }
414 }
413
415
414 QBarSet *QAbstractBarSeriesPrivate::barsetAt(int index)
416 QBarSet *QAbstractBarSeriesPrivate::barsetAt(int index)
415 {
417 {
416 return m_barSets.at(index);
418 return m_barSets.at(index);
417 }
419 }
418
420
419 void QAbstractBarSeriesPrivate::setVisible(bool visible)
421 void QAbstractBarSeriesPrivate::setVisible(bool visible)
420 {
422 {
421 m_visible = visible;
423 m_visible = visible;
422 emit visibleChanged();
424 emit visibleChanged();
423 }
425 }
424
426
425 void QAbstractBarSeriesPrivate::setLabelsVisible(bool visible)
427 void QAbstractBarSeriesPrivate::setLabelsVisible(bool visible)
426 {
428 {
427 m_labelsVisible = visible;
429 m_labelsVisible = visible;
428 emit labelsVisibleChanged(visible);
430 emit labelsVisibleChanged(visible);
429 }
431 }
430
432
431 qreal QAbstractBarSeriesPrivate::min()
433 qreal QAbstractBarSeriesPrivate::min()
432 {
434 {
433 if (m_barSets.count() <= 0)
435 if (m_barSets.count() <= 0)
434 return 0;
436 return 0;
435
437
436 qreal min = INT_MAX;
438 qreal min = INT_MAX;
437
439
438 for (int i = 0; i < m_barSets.count(); i++) {
440 for (int i = 0; i < m_barSets.count(); i++) {
439 int categoryCount = m_barSets.at(i)->count();
441 int categoryCount = m_barSets.at(i)->count();
440 for (int j = 0; j < categoryCount; j++) {
442 for (int j = 0; j < categoryCount; j++) {
441 qreal temp = m_barSets.at(i)->at(j);
443 qreal temp = m_barSets.at(i)->at(j);
442 if (temp < min)
444 if (temp < min)
443 min = temp;
445 min = temp;
444 }
446 }
445 }
447 }
446 return min;
448 return min;
447 }
449 }
448
450
449 qreal QAbstractBarSeriesPrivate::max()
451 qreal QAbstractBarSeriesPrivate::max()
450 {
452 {
451 if (m_barSets.count() <= 0)
453 if (m_barSets.count() <= 0)
452 return 0;
454 return 0;
453
455
454 qreal max = INT_MIN;
456 qreal max = INT_MIN;
455
457
456 for (int i = 0; i < m_barSets.count(); i++) {
458 for (int i = 0; i < m_barSets.count(); i++) {
457 int categoryCount = m_barSets.at(i)->count();
459 int categoryCount = m_barSets.at(i)->count();
458 for (int j = 0; j < categoryCount; j++) {
460 for (int j = 0; j < categoryCount; j++) {
459 qreal temp = m_barSets.at(i)->at(j);
461 qreal temp = m_barSets.at(i)->at(j);
460 if (temp > max)
462 if (temp > max)
461 max = temp;
463 max = temp;
462 }
464 }
463 }
465 }
464
466
465 return max;
467 return max;
466 }
468 }
467
469
468 qreal QAbstractBarSeriesPrivate::valueAt(int set, int category)
470 qreal QAbstractBarSeriesPrivate::valueAt(int set, int category)
469 {
471 {
470 if ((set < 0) || (set >= m_barSets.count()))
472 if ((set < 0) || (set >= m_barSets.count()))
471 return 0; // No set, no value.
473 return 0; // No set, no value.
472 else if ((category < 0) || (category >= m_barSets.at(set)->count()))
474 else if ((category < 0) || (category >= m_barSets.at(set)->count()))
473 return 0; // No category, no value.
475 return 0; // No category, no value.
474
476
475 return m_barSets.at(set)->at(category);
477 return m_barSets.at(set)->at(category);
476 }
478 }
477
479
478 qreal QAbstractBarSeriesPrivate::percentageAt(int set, int category)
480 qreal QAbstractBarSeriesPrivate::percentageAt(int set, int category)
479 {
481 {
480 if ((set < 0) || (set >= m_barSets.count()))
482 if ((set < 0) || (set >= m_barSets.count()))
481 return 0; // No set, no value.
483 return 0; // No set, no value.
482 else if ((category < 0) || (category >= m_barSets.at(set)->count()))
484 else if ((category < 0) || (category >= m_barSets.at(set)->count()))
483 return 0; // No category, no value.
485 return 0; // No category, no value.
484
486
485 qreal value = m_barSets.at(set)->at(category);
487 qreal value = m_barSets.at(set)->at(category);
486 qreal sum = categorySum(category);
488 qreal sum = categorySum(category);
487 if (qFuzzyIsNull(sum))
489 if (qFuzzyIsNull(sum))
488 return 0;
490 return 0;
489
491
490 return value / sum;
492 return value / sum;
491 }
493 }
492
494
493 qreal QAbstractBarSeriesPrivate::categorySum(int category)
495 qreal QAbstractBarSeriesPrivate::categorySum(int category)
494 {
496 {
495 qreal sum(0);
497 qreal sum(0);
496 int count = m_barSets.count(); // Count sets
498 int count = m_barSets.count(); // Count sets
497 for (int set = 0; set < count; set++) {
499 for (int set = 0; set < count; set++) {
498 if (category < m_barSets.at(set)->count())
500 if (category < m_barSets.at(set)->count())
499 sum += m_barSets.at(set)->at(category);
501 sum += m_barSets.at(set)->at(category);
500 }
502 }
501 return sum;
503 return sum;
502 }
504 }
503
505
504 qreal QAbstractBarSeriesPrivate::absoluteCategorySum(int category)
506 qreal QAbstractBarSeriesPrivate::absoluteCategorySum(int category)
505 {
507 {
506 qreal sum(0);
508 qreal sum(0);
507 int count = m_barSets.count(); // Count sets
509 int count = m_barSets.count(); // Count sets
508 for (int set = 0; set < count; set++) {
510 for (int set = 0; set < count; set++) {
509 if (category < m_barSets.at(set)->count())
511 if (category < m_barSets.at(set)->count())
510 sum += qAbs(m_barSets.at(set)->at(category));
512 sum += qAbs(m_barSets.at(set)->at(category));
511 }
513 }
512 return sum;
514 return sum;
513 }
515 }
514
516
515 qreal QAbstractBarSeriesPrivate::maxCategorySum()
517 qreal QAbstractBarSeriesPrivate::maxCategorySum()
516 {
518 {
517 qreal max = INT_MIN;
519 qreal max = INT_MIN;
518 int count = categoryCount();
520 int count = categoryCount();
519 for (int i = 0; i < count; i++) {
521 for (int i = 0; i < count; i++) {
520 qreal sum = categorySum(i);
522 qreal sum = categorySum(i);
521 if (sum > max)
523 if (sum > max)
522 max = sum;
524 max = sum;
523 }
525 }
524 return max;
526 return max;
525 }
527 }
526
528
527 qreal QAbstractBarSeriesPrivate::minX()
529 qreal QAbstractBarSeriesPrivate::minX()
528 {
530 {
529 if (m_barSets.count() <= 0)
531 if (m_barSets.count() <= 0)
530 return 0;
532 return 0;
531
533
532 qreal min = INT_MAX;
534 qreal min = INT_MAX;
533
535
534 for (int i = 0; i < m_barSets.count(); i++) {
536 for (int i = 0; i < m_barSets.count(); i++) {
535 int categoryCount = m_barSets.at(i)->count();
537 int categoryCount = m_barSets.at(i)->count();
536 for (int j = 0; j < categoryCount; j++) {
538 for (int j = 0; j < categoryCount; j++) {
537 qreal temp = m_barSets.at(i)->d_ptr.data()->m_values.at(j).x();
539 qreal temp = m_barSets.at(i)->d_ptr.data()->m_values.at(j).x();
538 if (temp < min)
540 if (temp < min)
539 min = temp;
541 min = temp;
540 }
542 }
541 }
543 }
542 return min;
544 return min;
543 }
545 }
544
546
545 qreal QAbstractBarSeriesPrivate::maxX()
547 qreal QAbstractBarSeriesPrivate::maxX()
546 {
548 {
547 if (m_barSets.count() <= 0)
549 if (m_barSets.count() <= 0)
548 return 0;
550 return 0;
549
551
550 qreal max = INT_MIN;
552 qreal max = INT_MIN;
551
553
552 for (int i = 0; i < m_barSets.count(); i++) {
554 for (int i = 0; i < m_barSets.count(); i++) {
553 int categoryCount = m_barSets.at(i)->count();
555 int categoryCount = m_barSets.at(i)->count();
554 for (int j = 0; j < categoryCount; j++) {
556 for (int j = 0; j < categoryCount; j++) {
555 qreal temp = m_barSets.at(i)->d_ptr.data()->m_values.at(j).x();
557 qreal temp = m_barSets.at(i)->d_ptr.data()->m_values.at(j).x();
556 if (temp > max)
558 if (temp > max)
557 max = temp;
559 max = temp;
558 }
560 }
559 }
561 }
560
562
561 return max;
563 return max;
562 }
564 }
563
565
564 qreal QAbstractBarSeriesPrivate::categoryTop(int category)
566 qreal QAbstractBarSeriesPrivate::categoryTop(int category)
565 {
567 {
566 // Returns top (sum of all positive values) of category.
568 // Returns top (sum of all positive values) of category.
567 // Returns 0, if all values are negative
569 // Returns 0, if all values are negative
568 qreal top(0);
570 qreal top(0);
569 int count = m_barSets.count();
571 int count = m_barSets.count();
570 for (int set = 0; set < count; set++) {
572 for (int set = 0; set < count; set++) {
571 if (category < m_barSets.at(set)->count()) {
573 if (category < m_barSets.at(set)->count()) {
572 qreal temp = m_barSets.at(set)->at(category);
574 qreal temp = m_barSets.at(set)->at(category);
573 if (temp > 0) {
575 if (temp > 0) {
574 top += temp;
576 top += temp;
575 }
577 }
576 }
578 }
577 }
579 }
578 return top;
580 return top;
579 }
581 }
580
582
581 qreal QAbstractBarSeriesPrivate::categoryBottom(int category)
583 qreal QAbstractBarSeriesPrivate::categoryBottom(int category)
582 {
584 {
583 // Returns bottom (sum of all negative values) of category
585 // Returns bottom (sum of all negative values) of category
584 // Returns 0, if all values are positive
586 // Returns 0, if all values are positive
585 qreal bottom(0);
587 qreal bottom(0);
586 int count = m_barSets.count();
588 int count = m_barSets.count();
587 for (int set = 0; set < count; set++) {
589 for (int set = 0; set < count; set++) {
588 if (category < m_barSets.at(set)->count()) {
590 if (category < m_barSets.at(set)->count()) {
589 qreal temp = m_barSets.at(set)->at(category);
591 qreal temp = m_barSets.at(set)->at(category);
590 if (temp < 0) {
592 if (temp < 0) {
591 bottom += temp;
593 bottom += temp;
592 }
594 }
593 }
595 }
594 }
596 }
595 return bottom;
597 return bottom;
596 }
598 }
597
599
598 qreal QAbstractBarSeriesPrivate::top()
600 qreal QAbstractBarSeriesPrivate::top()
599 {
601 {
600 // Returns top of all categories
602 // Returns top of all categories
601 qreal top(0);
603 qreal top(0);
602 int count = categoryCount();
604 int count = categoryCount();
603 for (int i = 0; i < count; i++) {
605 for (int i = 0; i < count; i++) {
604 qreal temp = categoryTop(i);
606 qreal temp = categoryTop(i);
605 if (temp > top)
607 if (temp > top)
606 top = temp;
608 top = temp;
607 }
609 }
608 return top;
610 return top;
609 }
611 }
610
612
611 qreal QAbstractBarSeriesPrivate::bottom()
613 qreal QAbstractBarSeriesPrivate::bottom()
612 {
614 {
613 // Returns bottom of all categories
615 // Returns bottom of all categories
614 qreal bottom(0);
616 qreal bottom(0);
615 int count = categoryCount();
617 int count = categoryCount();
616 for (int i = 0; i < count; i++) {
618 for (int i = 0; i < count; i++) {
617 qreal temp = categoryBottom(i);
619 qreal temp = categoryBottom(i);
618 if (temp < bottom)
620 if (temp < bottom)
619 bottom = temp;
621 bottom = temp;
620 }
622 }
621 return bottom;
623 return bottom;
622 }
624 }
623
625
624
626
625 void QAbstractBarSeriesPrivate::scaleDomain(Domain &domain)
627 void QAbstractBarSeriesPrivate::scaleDomain(Domain &domain)
626 {
628 {
627 qreal minX(domain.minX());
629 qreal minX(domain.minX());
628 qreal minY(domain.minY());
630 qreal minY(domain.minY());
629 qreal maxX(domain.maxX());
631 qreal maxX(domain.maxX());
630 qreal maxY(domain.maxY());
632 qreal maxY(domain.maxY());
631
633
632 qreal seriesMinX = this->minX();
634 qreal seriesMinX = this->minX();
633 qreal seriesMaxX = this->maxX();
635 qreal seriesMaxX = this->maxX();
634 qreal y = max();
636 qreal y = max();
635 minX = qMin(minX, seriesMinX - (qreal)0.5);
637 minX = qMin(minX, seriesMinX - (qreal)0.5);
636 minY = qMin(minY, y);
638 minY = qMin(minY, y);
637 maxX = qMax(maxX, seriesMaxX + (qreal)0.5);
639 maxX = qMax(maxX, seriesMaxX + (qreal)0.5);
638 maxY = qMax(maxY, y);
640 maxY = qMax(maxY, y);
639
641
640 domain.setRange(minX, maxX, minY, maxY);
642 domain.setRange(minX, maxX, minY, maxY);
641 }
643 }
642
644
643 ChartElement *QAbstractBarSeriesPrivate::createGraphics(ChartPresenter *presenter)
645 ChartElement *QAbstractBarSeriesPrivate::createGraphics(ChartPresenter *presenter)
644 {
646 {
645 Q_UNUSED(presenter);
647 Q_UNUSED(presenter);
646 qWarning() << "QAbstractBarSeriesPrivate::createGraphics called";
648 qWarning() << "QAbstractBarSeriesPrivate::createGraphics called";
647 return 0;
649 return 0;
648 }
650 }
649
651
650 QList<LegendMarker *> QAbstractBarSeriesPrivate::createLegendMarker(QLegend *legend)
652 QList<LegendMarker *> QAbstractBarSeriesPrivate::createLegendMarker(QLegend *legend)
651 {
653 {
652 Q_Q(QAbstractBarSeries);
654 Q_Q(QAbstractBarSeries);
653 QList<LegendMarker *> markers;
655 QList<LegendMarker *> markers;
654 foreach (QBarSet *set, q->barSets()) {
656 foreach (QBarSet *set, q->barSets()) {
655 BarLegendMarker* marker = new BarLegendMarker(q, set, legend);
657 BarLegendMarker* marker = new BarLegendMarker(q, set, legend);
656 markers << marker;
658 markers << marker;
657 }
659 }
658
660
659 return markers;
661 return markers;
660 }
662 }
661
663
662 QList<QLegendMarker*> QAbstractBarSeriesPrivate::createLegendMarkers(QLegend* legend)
664 QList<QLegendMarker*> QAbstractBarSeriesPrivate::createLegendMarkers(QLegend* legend)
663 {
665 {
664 Q_UNUSED(legend);
666 Q_Q(QAbstractBarSeries);
665 // Q_Q(QAbstractBarSeries);
666 QList<QLegendMarker*> markers;
667 QList<QLegendMarker*> markers;
667 // TODO: when QBarLegendMarker is implemented
668
668 /*
669 foreach(QBarSet* set, q->barSets()) {
669 foreach(QBarSet* set, q->barSets()) {
670 BarLegendMarker* marker = new BarLegendMarker(q,set,legend);
670 QBarLegendMarker* marker = new QBarLegendMarker(q,set,legend);
671 markers << marker;
671 markers << marker;
672 }
672 }
673 */
674 return markers;
673 return markers;
675 }
674 }
676
675
677
676
678 bool QAbstractBarSeriesPrivate::append(QBarSet *set)
677 bool QAbstractBarSeriesPrivate::append(QBarSet *set)
679 {
678 {
680 if ((m_barSets.contains(set)) || (set == 0))
679 if ((m_barSets.contains(set)) || (set == 0))
681 return false; // Fail if set is already in list or set is null.
680 return false; // Fail if set is already in list or set is null.
682
681
683 m_barSets.append(set);
682 m_barSets.append(set);
684 QObject::connect(set->d_ptr.data(), SIGNAL(updatedLayout()), this, SIGNAL(updatedLayout()));
683 QObject::connect(set->d_ptr.data(), SIGNAL(updatedLayout()), this, SIGNAL(updatedLayout()));
685 QObject::connect(set->d_ptr.data(), SIGNAL(updatedBars()), this, SIGNAL(updatedBars()));
684 QObject::connect(set->d_ptr.data(), SIGNAL(updatedBars()), this, SIGNAL(updatedBars()));
686 QObject::connect(set->d_ptr.data(), SIGNAL(restructuredBars()), this, SIGNAL(restructuredBars()));
685 QObject::connect(set->d_ptr.data(), SIGNAL(restructuredBars()), this, SIGNAL(restructuredBars()));
687
686
688 emit restructuredBars(); // this notifies barchartitem
687 emit restructuredBars(); // this notifies barchartitem
689 return true;
688 return true;
690 }
689 }
691
690
692 bool QAbstractBarSeriesPrivate::remove(QBarSet *set)
691 bool QAbstractBarSeriesPrivate::remove(QBarSet *set)
693 {
692 {
694 if (!m_barSets.contains(set))
693 if (!m_barSets.contains(set))
695 return false; // Fail if set is not in list
694 return false; // Fail if set is not in list
696
695
697 m_barSets.removeOne(set);
696 m_barSets.removeOne(set);
698 QObject::disconnect(set->d_ptr.data(), SIGNAL(updatedLayout()), this, SIGNAL(updatedLayout()));
697 QObject::disconnect(set->d_ptr.data(), SIGNAL(updatedLayout()), this, SIGNAL(updatedLayout()));
699 QObject::disconnect(set->d_ptr.data(), SIGNAL(updatedBars()), this, SIGNAL(updatedBars()));
698 QObject::disconnect(set->d_ptr.data(), SIGNAL(updatedBars()), this, SIGNAL(updatedBars()));
700 QObject::disconnect(set->d_ptr.data(), SIGNAL(restructuredBars()), this, SIGNAL(restructuredBars()));
699 QObject::disconnect(set->d_ptr.data(), SIGNAL(restructuredBars()), this, SIGNAL(restructuredBars()));
701
700
702 emit restructuredBars(); // this notifies barchartitem
701 emit restructuredBars(); // this notifies barchartitem
703 return true;
702 return true;
704 }
703 }
705
704
706 bool QAbstractBarSeriesPrivate::append(QList<QBarSet * > sets)
705 bool QAbstractBarSeriesPrivate::append(QList<QBarSet * > sets)
707 {
706 {
708 foreach (QBarSet *set, sets) {
707 foreach (QBarSet *set, sets) {
709 if ((set == 0) || (m_barSets.contains(set)))
708 if ((set == 0) || (m_barSets.contains(set)))
710 return false; // Fail if any of the sets is null or is already appended.
709 return false; // Fail if any of the sets is null or is already appended.
711 if (sets.count(set) != 1)
710 if (sets.count(set) != 1)
712 return false; // Also fail if same set is more than once in given list.
711 return false; // Also fail if same set is more than once in given list.
713 }
712 }
714
713
715 foreach (QBarSet *set, sets) {
714 foreach (QBarSet *set, sets) {
716 m_barSets.append(set);
715 m_barSets.append(set);
717 QObject::connect(set->d_ptr.data(), SIGNAL(updatedLayout()), this, SIGNAL(updatedLayout()));
716 QObject::connect(set->d_ptr.data(), SIGNAL(updatedLayout()), this, SIGNAL(updatedLayout()));
718 QObject::connect(set->d_ptr.data(), SIGNAL(updatedBars()), this, SIGNAL(updatedBars()));
717 QObject::connect(set->d_ptr.data(), SIGNAL(updatedBars()), this, SIGNAL(updatedBars()));
719 QObject::connect(set->d_ptr.data(), SIGNAL(restructuredBars()), this, SIGNAL(restructuredBars()));
718 QObject::connect(set->d_ptr.data(), SIGNAL(restructuredBars()), this, SIGNAL(restructuredBars()));
720 }
719 }
721
720
722 emit restructuredBars(); // this notifies barchartitem
721 emit restructuredBars(); // this notifies barchartitem
723 return true;
722 return true;
724 }
723 }
725
724
726 bool QAbstractBarSeriesPrivate::remove(QList<QBarSet * > sets)
725 bool QAbstractBarSeriesPrivate::remove(QList<QBarSet * > sets)
727 {
726 {
728 if (sets.count() == 0)
727 if (sets.count() == 0)
729 return false;
728 return false;
730
729
731 foreach (QBarSet *set, sets) {
730 foreach (QBarSet *set, sets) {
732 if ((set == 0) || (!m_barSets.contains(set)))
731 if ((set == 0) || (!m_barSets.contains(set)))
733 return false; // Fail if any of the sets is null or is not in series
732 return false; // Fail if any of the sets is null or is not in series
734 if (sets.count(set) != 1)
733 if (sets.count(set) != 1)
735 return false; // Also fail if same set is more than once in given list.
734 return false; // Also fail if same set is more than once in given list.
736 }
735 }
737
736
738 foreach (QBarSet *set, sets) {
737 foreach (QBarSet *set, sets) {
739 m_barSets.removeOne(set);
738 m_barSets.removeOne(set);
740 QObject::disconnect(set->d_ptr.data(), SIGNAL(updatedLayout()), this, SIGNAL(updatedLayout()));
739 QObject::disconnect(set->d_ptr.data(), SIGNAL(updatedLayout()), this, SIGNAL(updatedLayout()));
741 QObject::disconnect(set->d_ptr.data(), SIGNAL(updatedBars()), this, SIGNAL(updatedBars()));
740 QObject::disconnect(set->d_ptr.data(), SIGNAL(updatedBars()), this, SIGNAL(updatedBars()));
742 QObject::disconnect(set->d_ptr.data(), SIGNAL(restructuredBars()), this, SIGNAL(restructuredBars()));
741 QObject::disconnect(set->d_ptr.data(), SIGNAL(restructuredBars()), this, SIGNAL(restructuredBars()));
743 }
742 }
744
743
745 emit restructuredBars(); // this notifies barchartitem
744 emit restructuredBars(); // this notifies barchartitem
746
745
747 return true;
746 return true;
748 }
747 }
749
748
750 bool QAbstractBarSeriesPrivate::insert(int index, QBarSet *set)
749 bool QAbstractBarSeriesPrivate::insert(int index, QBarSet *set)
751 {
750 {
752 if ((m_barSets.contains(set)) || (set == 0))
751 if ((m_barSets.contains(set)) || (set == 0))
753 return false; // Fail if set is already in list or set is null.
752 return false; // Fail if set is already in list or set is null.
754
753
755 m_barSets.insert(index, set);
754 m_barSets.insert(index, set);
756 QObject::connect(set->d_ptr.data(), SIGNAL(updatedLayout()), this, SIGNAL(updatedLayout()));
755 QObject::connect(set->d_ptr.data(), SIGNAL(updatedLayout()), this, SIGNAL(updatedLayout()));
757 QObject::connect(set->d_ptr.data(), SIGNAL(updatedBars()), this, SIGNAL(updatedBars()));
756 QObject::connect(set->d_ptr.data(), SIGNAL(updatedBars()), this, SIGNAL(updatedBars()));
758 QObject::connect(set->d_ptr.data(), SIGNAL(restructuredBars()), this, SIGNAL(restructuredBars()));
757 QObject::connect(set->d_ptr.data(), SIGNAL(restructuredBars()), this, SIGNAL(restructuredBars()));
759
758
760 emit restructuredBars(); // this notifies barchartitem
759 emit restructuredBars(); // this notifies barchartitem
761 return true;
760 return true;
762 }
761 }
763
762
764 void QAbstractBarSeriesPrivate::initializeAxis(QAbstractAxis *axis)
763 void QAbstractBarSeriesPrivate::initializeAxis(QAbstractAxis *axis)
765 {
764 {
766 Q_Q(QAbstractBarSeries);
765 Q_Q(QAbstractBarSeries);
767
766
768 if (axis->type() == QAbstractAxis::AxisTypeBarCategory) {
767 if (axis->type() == QAbstractAxis::AxisTypeBarCategory) {
769 switch (q->type()) {
768 switch (q->type()) {
770 case QAbstractSeries::SeriesTypeHorizontalBar:
769 case QAbstractSeries::SeriesTypeHorizontalBar:
771 case QAbstractSeries::SeriesTypeHorizontalPercentBar:
770 case QAbstractSeries::SeriesTypeHorizontalPercentBar:
772 case QAbstractSeries::SeriesTypeHorizontalStackedBar:
771 case QAbstractSeries::SeriesTypeHorizontalStackedBar:
773 if (axis->orientation() == Qt::Vertical)
772 if (axis->orientation() == Qt::Vertical)
774 populateCategories(qobject_cast<QBarCategoryAxis *>(axis));
773 populateCategories(qobject_cast<QBarCategoryAxis *>(axis));
775 break;
774 break;
776 case QAbstractSeries::SeriesTypeBar:
775 case QAbstractSeries::SeriesTypeBar:
777 case QAbstractSeries::SeriesTypePercentBar:
776 case QAbstractSeries::SeriesTypePercentBar:
778 case QAbstractSeries::SeriesTypeStackedBar:
777 case QAbstractSeries::SeriesTypeStackedBar:
779 if (axis->orientation() == Qt::Horizontal)
778 if (axis->orientation() == Qt::Horizontal)
780 populateCategories(qobject_cast<QBarCategoryAxis *>(axis));
779 populateCategories(qobject_cast<QBarCategoryAxis *>(axis));
781 break;
780 break;
782 default:
781 default:
783 qWarning() << "Unexpected series type";
782 qWarning() << "Unexpected series type";
784 break;
783 break;
785 }
784 }
786 }
785 }
787 }
786 }
788
787
789 QAbstractAxis::AxisType QAbstractBarSeriesPrivate::defaultAxisType(Qt::Orientation orientation) const
788 QAbstractAxis::AxisType QAbstractBarSeriesPrivate::defaultAxisType(Qt::Orientation orientation) const
790 {
789 {
791 Q_Q(const QAbstractBarSeries);
790 Q_Q(const QAbstractBarSeries);
792
791
793 switch (q->type()) {
792 switch (q->type()) {
794 case QAbstractSeries::SeriesTypeHorizontalBar:
793 case QAbstractSeries::SeriesTypeHorizontalBar:
795 case QAbstractSeries::SeriesTypeHorizontalPercentBar:
794 case QAbstractSeries::SeriesTypeHorizontalPercentBar:
796 case QAbstractSeries::SeriesTypeHorizontalStackedBar:
795 case QAbstractSeries::SeriesTypeHorizontalStackedBar:
797 if (orientation == Qt::Vertical)
796 if (orientation == Qt::Vertical)
798 return QAbstractAxis::AxisTypeBarCategory;
797 return QAbstractAxis::AxisTypeBarCategory;
799 break;
798 break;
800 case QAbstractSeries::SeriesTypeBar:
799 case QAbstractSeries::SeriesTypeBar:
801 case QAbstractSeries::SeriesTypePercentBar:
800 case QAbstractSeries::SeriesTypePercentBar:
802 case QAbstractSeries::SeriesTypeStackedBar:
801 case QAbstractSeries::SeriesTypeStackedBar:
803 if (orientation == Qt::Horizontal)
802 if (orientation == Qt::Horizontal)
804 return QAbstractAxis::AxisTypeBarCategory;
803 return QAbstractAxis::AxisTypeBarCategory;
805 break;
804 break;
806 default:
805 default:
807 qWarning() << "Unexpected series type";
806 qWarning() << "Unexpected series type";
808 break;
807 break;
809 }
808 }
810 return QAbstractAxis::AxisTypeValue;
809 return QAbstractAxis::AxisTypeValue;
811
810
812 }
811 }
813
812
814 void QAbstractBarSeriesPrivate::populateCategories(QBarCategoryAxis *axis)
813 void QAbstractBarSeriesPrivate::populateCategories(QBarCategoryAxis *axis)
815 {
814 {
816 QStringList categories;
815 QStringList categories;
817 if (axis->categories().isEmpty()) {
816 if (axis->categories().isEmpty()) {
818 for (int i(1); i < categoryCount() + 1; i++)
817 for (int i(1); i < categoryCount() + 1; i++)
819 categories << QString::number(i);
818 categories << QString::number(i);
820 axis->append(categories);
819 axis->append(categories);
821 }
820 }
822 }
821 }
823
822
824 #include "moc_qabstractbarseries.cpp"
823 #include "moc_qabstractbarseries.cpp"
825 #include "moc_qabstractbarseries_p.cpp"
824 #include "moc_qabstractbarseries_p.cpp"
826
825
827 QTCOMMERCIALCHART_END_NAMESPACE
826 QTCOMMERCIALCHART_END_NAMESPACE
@@ -1,25 +1,28
1 INCLUDEPATH += $$PWD
1 INCLUDEPATH += $$PWD
2 DEPENDPATH += $$PWD
2 DEPENDPATH += $$PWD
3
3
4 SOURCES += \
4 SOURCES += \
5 $$PWD/qlegend.cpp \
5 $$PWD/qlegend.cpp \
6 $$PWD/legendmarker.cpp \
6 $$PWD/legendmarker.cpp \
7 $$PWD/legendlayout.cpp \
7 $$PWD/legendlayout.cpp \
8 $$PWD/qlegendmarker.cpp \
8 $$PWD/qlegendmarker.cpp \
9 $$PWD/qpielegendmarker.cpp \
9 $$PWD/qpielegendmarker.cpp \
10 $$PWD/legendmarkeritem.cpp
10 $$PWD/legendmarkeritem.cpp \
11 $$PWD/qbarlegendmarker.cpp
11
12
12 PRIVATE_HEADERS += \
13 PRIVATE_HEADERS += \
13 $$PWD/legendmarker_p.h \
14 $$PWD/legendmarker_p.h \
14 $$PWD/legendscroller_p.h \
15 $$PWD/legendscroller_p.h \
15 $$PWD/qlegend_p.h \
16 $$PWD/qlegend_p.h \
16 $$PWD/legendlayout_p.h \
17 $$PWD/legendlayout_p.h \
17 $$PWD/qlegendmarker_p.h \
18 $$PWD/qlegendmarker_p.h \
18 $$PWD/legendmarkeritem_p.h \
19 $$PWD/legendmarkeritem_p.h \
19 $$PWD/qpielegendmarker_p.h
20 $$PWD/qpielegendmarker_p.h \
21 $$PWD/qbarlegendmarker_p.h
20
22
21
23
22 PUBLIC_HEADERS += \
24 PUBLIC_HEADERS += \
23 $$PWD/qlegend.h \
25 $$PWD/qlegend.h \
24 $$PWD/qlegendmarker.h \
26 $$PWD/qlegendmarker.h \
25 $$PWD/qpielegendmarker.h
27 $$PWD/qpielegendmarker.h \
28 $$PWD/qbarlegendmarker.h
@@ -1,170 +1,170
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 "legendmarkeritem_p.h"
21 #include "legendmarkeritem_p.h"
22 #include <QPainter>
22 #include <QPainter>
23 #include <QGraphicsSceneEvent>
23 #include <QGraphicsSceneEvent>
24 #include <QGraphicsSimpleTextItem>
24 #include <QGraphicsSimpleTextItem>
25 #include <QDebug>
25 #include <QDebug>
26
26
27 #include "qlegendmarker_p.h"
27 #include "qlegendmarker_p.h"
28
28
29 QTCOMMERCIALCHART_BEGIN_NAMESPACE
29 QTCOMMERCIALCHART_BEGIN_NAMESPACE
30
30
31 LegendMarkerItem::LegendMarkerItem(QLegendMarkerPrivate *marker, QGraphicsObject *parent) :
31 LegendMarkerItem::LegendMarkerItem(QLegendMarkerPrivate *marker, QGraphicsObject *parent) :
32 QGraphicsObject(parent),
32 QGraphicsObject(parent),
33 m_marker(marker),
33 m_marker(marker),
34 m_markerRect(0,0,10.0,10.0),
34 m_markerRect(0,0,10.0,10.0),
35 m_boundingRect(0,0,0,0),
35 m_boundingRect(0,0,0,0),
36 m_textItem(new QGraphicsSimpleTextItem(this)),
36 m_textItem(new QGraphicsSimpleTextItem(this)),
37 m_rectItem(new QGraphicsRectItem(this)),
37 m_rectItem(new QGraphicsRectItem(this)),
38 m_margin(4),
38 m_margin(4),
39 m_space(4)
39 m_space(4)
40 {
40 {
41 m_rectItem->setRect(m_markerRect);
41 m_rectItem->setRect(m_markerRect);
42 }
42 }
43
43
44 void LegendMarkerItem::setPen(const QPen &pen)
44 void LegendMarkerItem::setPen(const QPen &pen)
45 {
45 {
46 m_rectItem->setPen(pen);
46 m_rectItem->setPen(pen);
47 }
47 }
48
48
49 QPen LegendMarkerItem::pen() const
49 QPen LegendMarkerItem::pen() const
50 {
50 {
51 return m_rectItem->pen();
51 return m_rectItem->pen();
52 }
52 }
53
53
54 void LegendMarkerItem::setBrush(const QBrush &brush)
54 void LegendMarkerItem::setBrush(const QBrush &brush)
55 {
55 {
56 m_rectItem->setBrush(brush);
56 m_rectItem->setBrush(brush);
57 }
57 }
58
58
59 QBrush LegendMarkerItem::brush() const
59 QBrush LegendMarkerItem::brush() const
60 {
60 {
61 return m_rectItem->brush();
61 return m_rectItem->brush();
62 }
62 }
63
63
64 void LegendMarkerItem::setFont(const QFont &font)
64 void LegendMarkerItem::setFont(const QFont &font)
65 {
65 {
66 m_textItem->setFont(font);
66 m_textItem->setFont(font);
67 QFontMetrics fn(font);
67 QFontMetrics fn(font);
68 m_markerRect = QRectF(0,0,fn.height()/2,fn.height()/2);
68 m_markerRect = QRectF(0,0,fn.height()/2,fn.height()/2);
69 updateGeometry();
69 updateGeometry();
70 }
70 }
71
71
72 QFont LegendMarkerItem::font() const
72 QFont LegendMarkerItem::font() const
73 {
73 {
74 return m_textItem->font();
74 return m_textItem->font();
75 }
75 }
76
76
77 void LegendMarkerItem::setLabel(const QString label)
77 void LegendMarkerItem::setLabel(const QString label)
78 {
78 {
79 m_text = label;
79 m_label = label;
80 updateGeometry();
80 updateGeometry();
81 }
81 }
82
82
83 QString LegendMarkerItem::label() const
83 QString LegendMarkerItem::label() const
84 {
84 {
85 return m_text;
85 return m_label;
86 }
86 }
87
87
88 void LegendMarkerItem::setLabelBrush(const QBrush &brush)
88 void LegendMarkerItem::setLabelBrush(const QBrush &brush)
89 {
89 {
90 m_textItem->setBrush(brush);
90 m_textItem->setBrush(brush);
91 }
91 }
92
92
93 QBrush LegendMarkerItem::labelBrush() const
93 QBrush LegendMarkerItem::labelBrush() const
94 {
94 {
95 return m_textItem->brush();
95 return m_textItem->brush();
96 }
96 }
97
97
98 void LegendMarkerItem::setGeometry(const QRectF& rect)
98 void LegendMarkerItem::setGeometry(const QRectF& rect)
99 {
99 {
100 QFontMetrics fn (m_font);
100 QFontMetrics fn (m_font);
101
101
102 int width = rect.width();
102 int width = rect.width();
103 qreal x = m_margin + m_markerRect.width() + m_space + m_margin;
103 qreal x = m_margin + m_markerRect.width() + m_space + m_margin;
104 qreal y = qMax(m_markerRect.height()+2*m_margin,fn.height()+2*m_margin);
104 qreal y = qMax(m_markerRect.height()+2*m_margin,fn.height()+2*m_margin);
105
105
106 if (fn.boundingRect(m_text).width() + x > width)
106 if (fn.boundingRect(m_label).width() + x > width)
107 {
107 {
108 QString string = m_text + "...";
108 QString string = m_label + "...";
109 while(fn.boundingRect(string).width() + x > width && string.length() > 3)
109 while(fn.boundingRect(string).width() + x > width && string.length() > 3)
110 string.remove(string.length() - 4, 1);
110 string.remove(string.length() - 4, 1);
111 m_textItem->setText(string);
111 m_textItem->setText(string);
112 }
112 }
113 else
113 else
114 m_textItem->setText(m_text);
114 m_textItem->setText(m_label);
115
115
116 const QRectF& textRect = m_textItem->boundingRect();
116 const QRectF& textRect = m_textItem->boundingRect();
117
117
118
118
119 m_textItem->setPos(x-m_margin,y/2 - textRect.height()/2);
119 m_textItem->setPos(x-m_margin,y/2 - textRect.height()/2);
120 m_rectItem->setRect(m_markerRect);
120 m_rectItem->setRect(m_markerRect);
121 m_rectItem->setPos(m_margin,y/2 - m_markerRect.height()/2);
121 m_rectItem->setPos(m_margin,y/2 - m_markerRect.height()/2);
122
122
123 prepareGeometryChange();
123 prepareGeometryChange();
124 m_boundingRect = QRectF(0,0,x+textRect.width()+m_margin,y);
124 m_boundingRect = QRectF(0,0,x+textRect.width()+m_margin,y);
125 }
125 }
126
126
127 QRectF LegendMarkerItem::boundingRect() const
127 QRectF LegendMarkerItem::boundingRect() const
128 {
128 {
129 return m_boundingRect;
129 return m_boundingRect;
130 }
130 }
131
131
132 void LegendMarkerItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget)
132 void LegendMarkerItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget)
133 {
133 {
134 Q_UNUSED(option)
134 Q_UNUSED(option)
135 Q_UNUSED(widget)
135 Q_UNUSED(widget)
136 Q_UNUSED(painter)
136 Q_UNUSED(painter)
137 }
137 }
138
138
139 QSizeF LegendMarkerItem::sizeHint(Qt::SizeHint which, const QSizeF& constraint) const
139 QSizeF LegendMarkerItem::sizeHint(Qt::SizeHint which, const QSizeF& constraint) const
140 {
140 {
141 Q_UNUSED(constraint)
141 Q_UNUSED(constraint)
142
142
143 QFontMetrics fn(m_textItem->font());
143 QFontMetrics fn(m_textItem->font());
144 QSizeF sh;
144 QSizeF sh;
145
145
146 switch (which) {
146 switch (which) {
147 case Qt::MinimumSize:
147 case Qt::MinimumSize:
148 sh = QSizeF(fn.boundingRect("...").width() + 2*m_margin + m_space +m_markerRect.width(),qMax(m_markerRect.height()+2*m_margin,fn.height()+2*m_margin));
148 sh = QSizeF(fn.boundingRect("...").width() + 2*m_margin + m_space +m_markerRect.width(),qMax(m_markerRect.height()+2*m_margin,fn.height()+2*m_margin));
149 break;
149 break;
150 case Qt::PreferredSize:
150 case Qt::PreferredSize:
151 sh = QSizeF(fn.boundingRect(m_text).width() + 2*m_margin + m_space +m_markerRect.width(),qMax(m_markerRect.height()+2*m_margin,fn.height()+2*m_margin));
151 sh = QSizeF(fn.boundingRect(m_label).width() + 2*m_margin + m_space +m_markerRect.width(),qMax(m_markerRect.height()+2*m_margin,fn.height()+2*m_margin));
152 break;
152 break;
153 default:
153 default:
154 break;
154 break;
155 }
155 }
156
156
157 return sh;
157 return sh;
158 }
158 }
159
159
160 void LegendMarkerItem::mousePressEvent(QGraphicsSceneMouseEvent *event)
160 void LegendMarkerItem::mousePressEvent(QGraphicsSceneMouseEvent *event)
161 {
161 {
162 // QGraphicsObject::mousePressEvent(event);
162 // QGraphicsObject::mousePressEvent(event);
163 //TODO: selected signal removed for now
163 //TODO: selected signal removed for now
164 m_marker->handleMousePressEvent(event);
164 m_marker->handleMousePressEvent(event);
165 QGraphicsItem::mousePressEvent(event);
165 QGraphicsItem::mousePressEvent(event);
166 }
166 }
167
167
168 #include "moc_legendmarkeritem_p.cpp"
168 #include "moc_legendmarkeritem_p.cpp"
169
169
170 QTCOMMERCIALCHART_END_NAMESPACE
170 QTCOMMERCIALCHART_END_NAMESPACE
@@ -1,102 +1,102
1 /****************************************************************************
1 /****************************************************************************
2 **
2 **
3 ** Copyright (C) 2012 Digia Plc
3 ** Copyright (C) 2012 Digia Plc
4 ** All rights reserved.
4 ** All rights reserved.
5 ** For any questions to Digia, please use contact form at http://qt.digia.com
5 ** For any questions to Digia, please use contact form at http://qt.digia.com
6 **
6 **
7 ** This file is part of the Qt Commercial Charts Add-on.
7 ** This file is part of the Qt Commercial Charts Add-on.
8 **
8 **
9 ** $QT_BEGIN_LICENSE$
9 ** $QT_BEGIN_LICENSE$
10 ** Licensees holding valid Qt Commercial licenses may use this file in
10 ** Licensees holding valid Qt Commercial licenses may use this file in
11 ** accordance with the Qt Commercial License Agreement provided with the
11 ** accordance with the Qt Commercial License Agreement provided with the
12 ** Software or, alternatively, in accordance with the terms contained in
12 ** Software or, alternatively, in accordance with the terms contained in
13 ** a written agreement between you and Digia.
13 ** a written agreement between you and Digia.
14 **
14 **
15 ** If you have questions regarding the use of this file, please use
15 ** If you have questions regarding the use of this file, please use
16 ** contact form at http://qt.digia.com
16 ** contact form at http://qt.digia.com
17 ** $QT_END_LICENSE$
17 ** $QT_END_LICENSE$
18 **
18 **
19 ****************************************************************************/
19 ****************************************************************************/
20
20
21 // W A R N I N G
21 // W A R N I N G
22 // -------------
22 // -------------
23 //
23 //
24 // This file is not part of the QtCommercial Chart API. It exists purely as an
24 // This file is not part of the QtCommercial Chart API. It exists purely as an
25 // implementation detail. This header file may change from version to
25 // implementation detail. This header file may change from version to
26 // version without notice, or even be removed.
26 // version without notice, or even be removed.
27 //
27 //
28 // We mean it.
28 // We mean it.
29
29
30 #ifndef LEGENDMARKERITEM_P_H
30 #ifndef LEGENDMARKERITEM_P_H
31 #define LEGENDMARKERITEM_P_H
31 #define LEGENDMARKERITEM_P_H
32
32
33 #include "qchartglobal.h"
33 #include "qchartglobal.h"
34 #include <QGraphicsObject>
34 #include <QGraphicsObject>
35 #include <QFont>
35 #include <QFont>
36 #include <QBrush>
36 #include <QBrush>
37 #include <QPen>
37 #include <QPen>
38 #include <QGraphicsSimpleTextItem>
38 #include <QGraphicsSimpleTextItem>
39 #include <QGraphicsLayoutItem>
39 #include <QGraphicsLayoutItem>
40
40
41 QTCOMMERCIALCHART_BEGIN_NAMESPACE
41 QTCOMMERCIALCHART_BEGIN_NAMESPACE
42
42
43 class QLegendMarkerPrivate;
43 class QLegendMarkerPrivate;
44
44
45 class LegendMarkerItem : public QGraphicsObject, public QGraphicsLayoutItem
45 class LegendMarkerItem : public QGraphicsObject, public QGraphicsLayoutItem
46 {
46 {
47 Q_OBJECT
47 Q_OBJECT
48 Q_INTERFACES(QGraphicsLayoutItem)
48 Q_INTERFACES(QGraphicsLayoutItem)
49 public:
49 public:
50 explicit LegendMarkerItem(QLegendMarkerPrivate *marker, QGraphicsObject *parent = 0);
50 explicit LegendMarkerItem(QLegendMarkerPrivate *marker, QGraphicsObject *parent = 0);
51
51
52 void setPen(const QPen &pen);
52 void setPen(const QPen &pen);
53 QPen pen() const;
53 QPen pen() const;
54
54
55 void setBrush(const QBrush &brush);
55 void setBrush(const QBrush &brush);
56 QBrush brush() const;
56 QBrush brush() const;
57
57
58 void setFont(const QFont &font);
58 void setFont(const QFont &font);
59 QFont font() const;
59 QFont font() const;
60
60
61 void setLabel(const QString label);
61 void setLabel(const QString label);
62 QString label() const;
62 QString label() const;
63
63
64 void setLabelBrush(const QBrush &brush);
64 void setLabelBrush(const QBrush &brush);
65 QBrush labelBrush() const;
65 QBrush labelBrush() const;
66
66
67 void setGeometry(const QRectF& rect);
67 void setGeometry(const QRectF& rect);
68
68
69 QRectF boundingRect() const;
69 QRectF boundingRect() const;
70
70
71 void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget = 0);
71 void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget = 0);
72
72
73 QSizeF sizeHint (Qt::SizeHint which, const QSizeF& constraint) const;
73 QSizeF sizeHint (Qt::SizeHint which, const QSizeF& constraint) const;
74
74
75 protected:
75 protected:
76 // From QGraphicsObject
76 // From QGraphicsObject
77 void mousePressEvent(QGraphicsSceneMouseEvent *event);
77 void mousePressEvent(QGraphicsSceneMouseEvent *event);
78
78
79 protected:
79 protected:
80 QLegendMarkerPrivate *m_marker; // Knows
80 QLegendMarkerPrivate *m_marker; // Knows
81 QRectF m_markerRect;
81 QRectF m_markerRect;
82 QRectF m_boundingRect;
82 QRectF m_boundingRect;
83 QGraphicsSimpleTextItem *m_textItem;
83 QGraphicsSimpleTextItem *m_textItem;
84 QGraphicsRectItem *m_rectItem;
84 QGraphicsRectItem *m_rectItem;
85 qreal m_margin;
85 qreal m_margin;
86 qreal m_space;
86 qreal m_space;
87 QString m_text;
88
89 QString m_label;
87 QString m_label;
88
90 QBrush m_labelBrush;
89 QBrush m_labelBrush;
91 QFont m_font;
90 QFont m_font;
92 QPen m_pen;
91 QPen m_pen;
93 QBrush m_brush;
92 QBrush m_brush;
94 bool m_visible;
93 bool m_visible;
95
94
95 friend class QLegendMarker;
96 friend class QLegendMarkerPrivate;
96 friend class QLegendMarkerPrivate;
97 friend class LegendLayout;
97 friend class LegendLayout;
98 };
98 };
99
99
100 QTCOMMERCIALCHART_END_NAMESPACE
100 QTCOMMERCIALCHART_END_NAMESPACE
101
101
102 #endif // LEGENDMARKERITEM_P_H
102 #endif // LEGENDMARKERITEM_P_H
@@ -1,194 +1,126
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 "qlegendmarker.h"
21 #include "qlegendmarker.h"
22 #include "qlegendmarker_p.h"
22 #include "qlegendmarker_p.h"
23 #include "legendmarkeritem_p.h"
23 #include "legendmarkeritem_p.h"
24 #include "qlegend.h"
24 #include "qlegend.h"
25 #include <QDebug>
25 #include <QDebug>
26 #include <QFontMetrics>
26 #include <QFontMetrics>
27 #include <QGraphicsSceneEvent>
27 #include <QGraphicsSceneEvent>
28
28
29 QTCOMMERCIALCHART_BEGIN_NAMESPACE
29 QTCOMMERCIALCHART_BEGIN_NAMESPACE
30 /*
30
31 QLegendMarker::QLegendMarker(QAbstractSeries* series, QObject *parent) :
32 QObject(parent),
33 d_ptr(new QLegendMarkerPrivate(series, this))
34 {
35 }
36 */
37 QLegendMarker::QLegendMarker(QLegendMarkerPrivate &d, QObject *parent) :
31 QLegendMarker::QLegendMarker(QLegendMarkerPrivate &d, QObject *parent) :
38 QObject(parent),
32 QObject(parent),
39 d_ptr(&d)
33 d_ptr(&d)
40 {
34 {
41 }
35 }
42
36
43 QLegendMarker::~QLegendMarker()
37 QLegendMarker::~QLegendMarker()
44 {
38 {
45 }
39 }
46
40
47 QString QLegendMarker::label() const
41 QString QLegendMarker::label() const
48 {
42 {
49 return d_ptr->label();
43 return d_ptr->m_item->label();
50 }
44 }
51
45
52 void QLegendMarker::setLabel(const QString &label)
46 void QLegendMarker::setLabel(const QString &label)
53 {
47 {
54 d_ptr->setLabel(label);
48 d_ptr->m_item->setLabel(label);
55 }
49 }
56
50
57 QBrush QLegendMarker::labelBrush() const
51 QBrush QLegendMarker::labelBrush() const
58 {
52 {
59 return d_ptr->labelBrush();
53 return d_ptr->m_item->brush();
60 }
54 }
61
55
62 void QLegendMarker::setLabelBrush(const QBrush &brush)
56 void QLegendMarker::setLabelBrush(const QBrush &brush)
63 {
57 {
64 d_ptr->setLabelBrush(brush);
58 d_ptr->m_item->setLabelBrush(brush);
65 }
59 }
66
60
67 QFont QLegendMarker::font() const
61 QFont QLegendMarker::font() const
68 {
62 {
69 return d_ptr->font();
63 return d_ptr->m_item->font();
70 }
64 }
71
65
72 void QLegendMarker::setFont(const QFont &font)
66 void QLegendMarker::setFont(const QFont &font)
73 {
67 {
74 d_ptr->setFont(font);
68 d_ptr->m_item->setFont(font);
75 }
69 }
76
70
77 QPen QLegendMarker::pen() const
71 QPen QLegendMarker::pen() const
78 {
72 {
79 return d_ptr->pen();
73 return d_ptr->m_item->pen();
80 }
74 }
81
75
82 void QLegendMarker::setPen(const QPen &pen)
76 void QLegendMarker::setPen(const QPen &pen)
83 {
77 {
84 d_ptr->setPen(pen);
78 d_ptr->m_item->setPen(pen);
85 }
79 }
86
80
87 QBrush QLegendMarker::brush() const
81 QBrush QLegendMarker::brush() const
88 {
82 {
89 return d_ptr->brush();
83 return d_ptr->m_item->brush();
90 }
84 }
91
85
92 void QLegendMarker::setBrush(const QBrush &brush)
86 void QLegendMarker::setBrush(const QBrush &brush)
93 {
87 {
94 d_ptr->setBrush(brush);
88 d_ptr->m_item->setBrush(brush);
95 }
89 }
96
90
97 bool QLegendMarker::isVisible() const
91 bool QLegendMarker::isVisible() const
98 {
92 {
99 return d_ptr->isVisible();
93 return d_ptr->m_item->isVisible();
100 }
94 }
101
95
102 void QLegendMarker::setVisible(bool visible)
96 void QLegendMarker::setVisible(bool visible)
103 {
97 {
104 d_ptr->setVisible(visible);
98 d_ptr->m_item->setVisible(visible);
105 }
99 }
106
100
107 ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
101 ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
108 QLegendMarkerPrivate::QLegendMarkerPrivate(QLegendMarker *q, QLegend *legend) :
102 QLegendMarkerPrivate::QLegendMarkerPrivate(QLegendMarker *q, QLegend *legend) :
109 q_ptr(q),
103 q_ptr(q),
110 m_legend(legend)
104 m_legend(legend)
111 {
105 {
112 // qDebug() << "QLegendMarkerPrivate created";
113 m_item = new LegendMarkerItem(this);
106 m_item = new LegendMarkerItem(this);
114 }
107 }
115
108
116 QLegendMarkerPrivate::~QLegendMarkerPrivate()
109 QLegendMarkerPrivate::~QLegendMarkerPrivate()
117 {
110 {
118 }
111 }
119
112
120 void QLegendMarkerPrivate::handleMousePressEvent(QGraphicsSceneEvent *event)
113 void QLegendMarkerPrivate::handleMousePressEvent(QGraphicsSceneEvent *event)
121 {
114 {
122 // Just emit clicked signal for now (our default logic for events)
115 // Just emit clicked signal for now (our default logic for events)
123 // This could propably be on the LegendMarkerItem?
116 // This could propably be on the LegendMarkerItem?
124 // TODO: how to handle scrolling vs clicking? drag event?
117 // TODO: how to handle scrolling vs clicking? drag event?
125 event->accept();
118 event->accept();
126 Q_Q(QLegendMarker);
119 Q_Q(QLegendMarker);
127 emit q->clicked();
120 emit q->clicked();
128 }
121 }
129
122
130 void QLegendMarkerPrivate::setPen(const QPen &pen)
131 {
132 m_item->setPen(pen);
133 }
134
135 QPen QLegendMarkerPrivate::pen() const
136 {
137 return m_item->pen();
138 }
139
140 void QLegendMarkerPrivate::setBrush(const QBrush &brush)
141 {
142 m_item->setBrush(brush);
143 }
144
145 QBrush QLegendMarkerPrivate::brush() const
146 {
147 return m_item->brush();
148 }
149
150 void QLegendMarkerPrivate::setFont(const QFont &font)
151 {
152 m_item->setFont(font);
153 }
154
155 QFont QLegendMarkerPrivate::font() const
156 {
157 return m_item->font();
158 }
159
160 void QLegendMarkerPrivate::setLabel(const QString label)
161 {
162 m_item->setLabel(label);
163 }
164
165 QString QLegendMarkerPrivate::label() const
166 {
167 return m_item->label();
168 }
169
170 void QLegendMarkerPrivate::setLabelBrush(const QBrush &brush)
171 {
172 m_item->setLabelBrush(brush);
173 }
174
175 QBrush QLegendMarkerPrivate::labelBrush() const
176 {
177 return m_item->labelBrush();
178 }
179
180 bool QLegendMarkerPrivate::isVisible() const
181 {
182 return m_item->isVisible();
183 }
184
185 void QLegendMarkerPrivate::setVisible(bool visible)
186 {
187 m_item->setVisible(visible);
188 }
189
190
191 #include "moc_qlegendmarker.cpp"
123 #include "moc_qlegendmarker.cpp"
192 #include "moc_qlegendmarker_p.cpp"
124 #include "moc_qlegendmarker_p.cpp"
193
125
194 QTCOMMERCIALCHART_END_NAMESPACE
126 QTCOMMERCIALCHART_END_NAMESPACE
@@ -1,89 +1,89
1 /****************************************************************************
1 /****************************************************************************
2 **
2 **
3 ** Copyright (C) 2012 Digia Plc
3 ** Copyright (C) 2012 Digia Plc
4 ** All rights reserved.
4 ** All rights reserved.
5 ** For any questions to Digia, please use contact form at http://qt.digia.com
5 ** For any questions to Digia, please use contact form at http://qt.digia.com
6 **
6 **
7 ** This file is part of the Qt Commercial Charts Add-on.
7 ** This file is part of the Qt Commercial Charts Add-on.
8 **
8 **
9 ** $QT_BEGIN_LICENSE$
9 ** $QT_BEGIN_LICENSE$
10 ** Licensees holding valid Qt Commercial licenses may use this file in
10 ** Licensees holding valid Qt Commercial licenses may use this file in
11 ** accordance with the Qt Commercial License Agreement provided with the
11 ** accordance with the Qt Commercial License Agreement provided with the
12 ** Software or, alternatively, in accordance with the terms contained in
12 ** Software or, alternatively, in accordance with the terms contained in
13 ** a written agreement between you and Digia.
13 ** a written agreement between you and Digia.
14 **
14 **
15 ** If you have questions regarding the use of this file, please use
15 ** If you have questions regarding the use of this file, please use
16 ** contact form at http://qt.digia.com
16 ** contact form at http://qt.digia.com
17 ** $QT_END_LICENSE$
17 ** $QT_END_LICENSE$
18 **
18 **
19 ****************************************************************************/
19 ****************************************************************************/
20
20
21 #ifndef QLEGENDMARKER_H
21 #ifndef QLEGENDMARKER_H
22 #define QLEGENDMARKER_H
22 #define QLEGENDMARKER_H
23
23
24 #include <QChartGlobal>
24 #include <QChartGlobal>
25 #include <QObject>
25 #include <QObject>
26 #include <QPen>
26 #include <QPen>
27 #include <QBrush>
27 #include <QBrush>
28 #include <QFont>
28 #include <QFont>
29
29
30 QTCOMMERCIALCHART_BEGIN_NAMESPACE
30 QTCOMMERCIALCHART_BEGIN_NAMESPACE
31
31
32 class QLegendMarkerPrivate;
32 class QLegendMarkerPrivate;
33 class QAbstractSeries;
33 class QAbstractSeries;
34 class QLegend;
34 class QLegend;
35
35
36 // TODO: should this be QAbstractLegendMarker?
36 // TODO: should this be QAbstractLegendMarker?
37 class QTCOMMERCIALCHART_EXPORT QLegendMarker : public QObject
37 class QTCOMMERCIALCHART_EXPORT QLegendMarker : public QObject
38 {
38 {
39 Q_OBJECT
39 Q_OBJECT
40
40
41 // TODO: need for these?
41 // TODO: need for these?
42 // Q_PROPERTY(QString label READ label WRITE setlabel NOTIFY labelChanged);
42 // Q_PROPERTY(QString label READ label WRITE setlabel NOTIFY labelChanged);
43 // Q_PROPERTY(QPen pen READ pen WRITE setPen NOTIFY penChanged);
43 // Q_PROPERTY(QPen pen READ pen WRITE setPen NOTIFY penChanged);
44 // Q_PROPERTY(QBrush brush READ brush WRITE setBrush NOTIFY brushChanged);
44 // Q_PROPERTY(QBrush brush READ brush WRITE setBrush NOTIFY brushChanged);
45
45
46 public:
46 public:
47 // explicit QLegendMarker(QAbstractSeries* series, QObject *parent = 0);
47 // explicit QLegendMarker(QAbstractSeries* series, QObject *parent = 0);
48 virtual ~QLegendMarker();
48 virtual ~QLegendMarker();
49
49
50 QString label() const;
50 QString label() const;
51 void setLabel(const QString &label);
51 void setLabel(const QString &label);
52
52
53 QBrush labelBrush() const;
53 QBrush labelBrush() const;
54 void setLabelBrush(const QBrush &brush);
54 void setLabelBrush(const QBrush &brush);
55
55
56 QFont font() const;
56 QFont font() const;
57 void setFont(const QFont &font);
57 void setFont(const QFont &font);
58
58
59 QPen pen() const;
59 QPen pen() const;
60 void setPen(const QPen &pen);
60 void setPen(const QPen &pen);
61
61
62 QBrush brush() const;
62 QBrush brush() const;
63 void setBrush(const QBrush &brush);
63 void setBrush(const QBrush &brush);
64
64
65 bool isVisible() const;
65 bool isVisible() const;
66 void setVisible(bool visible);
66 void setVisible(bool visible);
67
67
68 // virtual QAbstractSeries::SeriesType type() = 0; // TODO?
68 // virtual QAbstractSeries::SeriesType type() = 0; // TODO? Or use LegendMarker type enum?
69 virtual QAbstractSeries* series() = 0;
69 virtual QAbstractSeries* series() = 0; // TODO: remove these and use specialised functions on derived classes?
70 virtual QObject* peerObject() = 0;
70 virtual QObject* peerObject() = 0;
71
71
72 protected:
72 protected:
73 explicit QLegendMarker(QLegendMarkerPrivate &d, QObject *parent = 0);
73 explicit QLegendMarker(QLegendMarkerPrivate &d, QObject *parent = 0);
74
74
75 Q_SIGNALS:
75 Q_SIGNALS:
76 void clicked();
76 void clicked();
77 void hovered(bool status);
77 void hovered(bool status);
78
78
79 protected:
79 protected:
80 QScopedPointer<QLegendMarkerPrivate> d_ptr;
80 QScopedPointer<QLegendMarkerPrivate> d_ptr;
81 Q_DISABLE_COPY(QLegendMarker)
81 Q_DISABLE_COPY(QLegendMarker)
82 friend class QLegendPrivate;
82 friend class QLegendPrivate;
83 friend class QLegendMarkerPrivate;
83 friend class QLegendMarkerPrivate;
84 friend class LegendLayout;
84 friend class LegendLayout;
85 };
85 };
86
86
87 QTCOMMERCIALCHART_END_NAMESPACE
87 QTCOMMERCIALCHART_END_NAMESPACE
88
88
89 #endif // QLEGENDMARKER_H
89 #endif // QLEGENDMARKER_H
@@ -1,115 +1,85
1 /****************************************************************************
1 /****************************************************************************
2 **
2 **
3 ** Copyright (C) 2012 Digia Plc
3 ** Copyright (C) 2012 Digia Plc
4 ** All rights reserved.
4 ** All rights reserved.
5 ** For any questions to Digia, please use contact form at http://qt.digia.com
5 ** For any questions to Digia, please use contact form at http://qt.digia.com
6 **
6 **
7 ** This file is part of the Qt Commercial Charts Add-on.
7 ** This file is part of the Qt Commercial Charts Add-on.
8 **
8 **
9 ** $QT_BEGIN_LICENSE$
9 ** $QT_BEGIN_LICENSE$
10 ** Licensees holding valid Qt Commercial licenses may use this file in
10 ** Licensees holding valid Qt Commercial licenses may use this file in
11 ** accordance with the Qt Commercial License Agreement provided with the
11 ** accordance with the Qt Commercial License Agreement provided with the
12 ** Software or, alternatively, in accordance with the terms contained in
12 ** Software or, alternatively, in accordance with the terms contained in
13 ** a written agreement between you and Digia.
13 ** a written agreement between you and Digia.
14 **
14 **
15 ** If you have questions regarding the use of this file, please use
15 ** If you have questions regarding the use of this file, please use
16 ** contact form at http://qt.digia.com
16 ** contact form at http://qt.digia.com
17 ** $QT_END_LICENSE$
17 ** $QT_END_LICENSE$
18 **
18 **
19 ****************************************************************************/
19 ****************************************************************************/
20
20
21 // W A R N I N G
21 // W A R N I N G
22 // -------------
22 // -------------
23 //
23 //
24 // This file is not part of the QtCommercial Chart API. It exists purely as an
24 // This file is not part of the QtCommercial Chart API. It exists purely as an
25 // implementation detail. This header file may change from version to
25 // implementation detail. This header file may change from version to
26 // version without notice, or even be removed.
26 // version without notice, or even be removed.
27 //
27 //
28 // We mean it.
28 // We mean it.
29
29
30 #ifndef QLEGENDMARKERPRIVATE_H
30 #ifndef QLEGENDMARKERPRIVATE_H
31 #define QLEGENDMARKERPRIVATE_H
31 #define QLEGENDMARKERPRIVATE_H
32
32
33 #include "qchartglobal.h"
33 #include "qchartglobal.h"
34 #include <QGraphicsObject>
34 #include <QGraphicsObject>
35 #include <QBrush>
35 #include <QBrush>
36 #include <QPen>
36 #include <QPen>
37 #include <QGraphicsSimpleTextItem>
37 #include <QGraphicsSimpleTextItem>
38 #include <QGraphicsLayoutItem>
38 #include <QGraphicsLayoutItem>
39 #include <QDebug>
39 #include <QDebug>
40
40
41 QTCOMMERCIALCHART_BEGIN_NAMESPACE
41 QTCOMMERCIALCHART_BEGIN_NAMESPACE
42
42
43 // TODO: check these
43 // TODO: check these
44 class QAbstractSeries;
44 class QAbstractSeries;
45 class QAreaSeries;
45 class QAreaSeries;
46 class QXYSeries;
46 class QXYSeries;
47 class QBarSet;
47 class QBarSet;
48 class QAbstractBarSeries;
48 class QAbstractBarSeries;
49 class QPieSlice;
49 class QPieSlice;
50 class QLegend;
50 class QLegend;
51 class QPieSeries;
51 class QPieSeries;
52
52
53 class QLegendMarker;
53 class QLegendMarker;
54 class LegendMarkerItem;
54 class LegendMarkerItem;
55
55
56 class QLegendMarkerPrivate : public QObject
56 class QLegendMarkerPrivate : public QObject
57 {
57 {
58 Q_OBJECT
58 Q_OBJECT
59 public:
59 public:
60 // explicit QLegendMarkerPrivate(QAbstractSeries *series, QLegendMarker *q);
61 explicit QLegendMarkerPrivate(QLegendMarker *q, QLegend *legend);
60 explicit QLegendMarkerPrivate(QLegendMarker *q, QLegend *legend);
62 virtual ~QLegendMarkerPrivate();
61 virtual ~QLegendMarkerPrivate();
63
62
64 // TODO: remove temporary setters/getters and use the m_item directly from public class via d_ptr
63 // Helper for now. (or deckare LegendLayout as friend)
65 void setPen(const QPen &pen);
66 QPen pen() const;
67
68 void setBrush(const QBrush &brush);
69 QBrush brush() const;
70
71 void setFont(const QFont &font);
72 QFont font() const;
73
74 void setLabel(const QString label);
75 QString label() const;
76
77 void setLabelBrush(const QBrush &brush);
78 QBrush labelBrush() const;
79
80 bool isVisible() const;
81 void setVisible(bool visible);
82
83 // Helper for now.
84 LegendMarkerItem* item() const { return m_item; }
64 LegendMarkerItem* item() const { return m_item; }
85
65
86 // Item gets the event, logic for event is here
66 // Item gets the event, logic for event is here
87 void handleMousePressEvent(QGraphicsSceneEvent *event);
67 void handleMousePressEvent(QGraphicsSceneEvent *event);
88
68
89 public Q_SLOTS:
69 public Q_SLOTS:
90 virtual void updated() {};
70 virtual void updated() {};
91
71
92 protected:
72 protected:
93 LegendMarkerItem *m_item;
73 LegendMarkerItem *m_item;
94 QLegend* m_legend;
74 QLegend* m_legend;
95
75
96 private:
76 private:
97 QLegendMarker *q_ptr;
77 QLegendMarker *q_ptr;
98
78
99 // New legend marker properties
100 // Moved to item.
101 /*
102 QString m_label;
103 QBrush m_labelBrush;
104 QFont m_font;
105 QPen m_pen;
106 QBrush m_brush;
107 bool m_visible;
108 */
109 friend class QLegendPrivate; // TODO: Is this needed?
79 friend class QLegendPrivate; // TODO: Is this needed?
110 Q_DECLARE_PUBLIC(QLegendMarker)
80 Q_DECLARE_PUBLIC(QLegendMarker)
111 };
81 };
112
82
113 QTCOMMERCIALCHART_END_NAMESPACE
83 QTCOMMERCIALCHART_END_NAMESPACE
114
84
115 #endif // QLEGENDMARKERPRIVATE_H
85 #endif // QLEGENDMARKERPRIVATE_H
@@ -1,87 +1,89
1 /****************************************************************************
1 /****************************************************************************
2 **
2 **
3 ** Copyright (C) 2012 Digia Plc
3 ** Copyright (C) 2012 Digia Plc
4 ** All rights reserved.
4 ** All rights reserved.
5 ** For any questions to Digia, please use contact form at http://qt.digia.com
5 ** For any questions to Digia, please use contact form at http://qt.digia.com
6 **
6 **
7 ** This file is part of the Qt Commercial Charts Add-on.
7 ** This file is part of the Qt Commercial Charts Add-on.
8 **
8 **
9 ** $QT_BEGIN_LICENSE$
9 ** $QT_BEGIN_LICENSE$
10 ** Licensees holding valid Qt Commercial licenses may use this file in
10 ** Licensees holding valid Qt Commercial licenses may use this file in
11 ** accordance with the Qt Commercial License Agreement provided with the
11 ** accordance with the Qt Commercial License Agreement provided with the
12 ** Software or, alternatively, in accordance with the terms contained in
12 ** Software or, alternatively, in accordance with the terms contained in
13 ** a written agreement between you and Digia.
13 ** a written agreement between you and Digia.
14 **
14 **
15 ** If you have questions regarding the use of this file, please use
15 ** If you have questions regarding the use of this file, please use
16 ** contact form at http://qt.digia.com
16 ** contact form at http://qt.digia.com
17 ** $QT_END_LICENSE$
17 ** $QT_END_LICENSE$
18 **
18 **
19 ****************************************************************************/
19 ****************************************************************************/
20
20
21 #include "qpielegendmarker.h"
21 #include "qpielegendmarker.h"
22 #include "qpielegendmarker_p.h"
22 #include "qpielegendmarker_p.h"
23 #include <QPieSeries>
23 #include <QPieSeries>
24 #include <QPieSlice>
24 #include <QDebug>
25 #include <QDebug>
25
26
26 QTCOMMERCIALCHART_BEGIN_NAMESPACE
27 QTCOMMERCIALCHART_BEGIN_NAMESPACE
27
28
28 QPieLegendMarker::QPieLegendMarker(QPieSeries* series, QPieSlice* slice, QLegend *legend, QObject *parent) :
29 QPieLegendMarker::QPieLegendMarker(QPieSeries* series, QPieSlice* slice, QLegend *legend, QObject *parent) :
29 QLegendMarker(*new QPieLegendMarkerPrivate(this,series,slice,legend), parent)
30 QLegendMarker(*new QPieLegendMarkerPrivate(this,series,slice,legend), parent)
30 {
31 {
31 }
32 }
32
33
33 QPieLegendMarker::~QPieLegendMarker()
34 QPieLegendMarker::~QPieLegendMarker()
34 {
35 {
35 qDebug() << "deleting pie marker" << this;
36 // qDebug() << "deleting pie marker" << this;
36 }
37 }
37
38
38 /*!
39 /*!
39 \internal
40 \internal
40 */
41 */
41 QPieLegendMarker::QPieLegendMarker(QPieLegendMarkerPrivate &d, QObject *parent) :
42 QPieLegendMarker::QPieLegendMarker(QPieLegendMarkerPrivate &d, QObject *parent) :
42 QLegendMarker(d, parent)
43 QLegendMarker(d, parent)
43 {
44 {
44 }
45 }
45
46
46 QAbstractSeries* QPieLegendMarker::series()
47 QPieSeries* QPieLegendMarker::series()
47 {
48 {
48 Q_D(QPieLegendMarker);
49 Q_D(QPieLegendMarker);
49 return d->m_series;
50 return d->m_series;
50 }
51 }
51
52
52 QPieSlice* QPieLegendMarker::peerObject()
53 QPieSlice* QPieLegendMarker::peerObject()
53 {
54 {
54 Q_D(QPieLegendMarker);
55 Q_D(QPieLegendMarker);
55 return d->m_slice;
56 return d->m_slice;
56 }
57 }
57
58
58 ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
59 ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
59
60
60 QPieLegendMarkerPrivate::QPieLegendMarkerPrivate(QPieLegendMarker *q, QPieSeries *series, QPieSlice *slice, QLegend *legend) :
61 QPieLegendMarkerPrivate::QPieLegendMarkerPrivate(QPieLegendMarker *q, QPieSeries *series, QPieSlice *slice, QLegend *legend) :
61 QLegendMarkerPrivate(q,legend),
62 QLegendMarkerPrivate(q,legend),
62 m_series(series),
63 m_series(series),
63 m_slice(slice)
64 m_slice(slice)
64 {
65 {
65 QObject::connect(m_slice, SIGNAL(labelChanged()), this, SLOT(updated()));
66 QObject::connect(m_slice, SIGNAL(labelChanged()), this, SLOT(updated()));
66 QObject::connect(m_slice, SIGNAL(brushChanged()), this, SLOT(updated()));
67 QObject::connect(m_slice, SIGNAL(brushChanged()), this, SLOT(updated()));
68 QObject::connect(m_slice, SIGNAL(penChanged()), this, SLOT(updated()));
67 updated();
69 updated();
68 }
70 }
69
71
70 QPieLegendMarkerPrivate::~QPieLegendMarkerPrivate()
72 QPieLegendMarkerPrivate::~QPieLegendMarkerPrivate()
71 {
73 {
72 QObject::disconnect(m_slice, SIGNAL(labelChanged()), this, SLOT(updated()));
74 QObject::disconnect(m_slice, SIGNAL(labelChanged()), this, SLOT(updated()));
73 QObject::disconnect(m_slice, SIGNAL(brushChanged()), this, SLOT(updated()));
75 QObject::disconnect(m_slice, SIGNAL(brushChanged()), this, SLOT(updated()));
76 QObject::disconnect(m_slice, SIGNAL(penChanged()), this, SLOT(updated()));
74 }
77 }
75
78
76 void QPieLegendMarkerPrivate::updated()
79 void QPieLegendMarkerPrivate::updated()
77 {
80 {
78 m_item->setBrush(m_slice->brush());
79 m_item->setLabel(m_slice->label());
80 m_item->setPen(m_slice->pen());
81 m_item->setPen(m_slice->pen());
81 m_item->setBrush(m_slice->brush());
82 m_item->setBrush(m_slice->brush());
83 m_item->setLabel(m_slice->label());
82 }
84 }
83
85
84 #include "moc_qpielegendmarker.cpp"
86 #include "moc_qpielegendmarker.cpp"
85 #include "moc_qpielegendmarker_p.cpp"
87 #include "moc_qpielegendmarker_p.cpp"
86
88
87 QTCOMMERCIALCHART_END_NAMESPACE
89 QTCOMMERCIALCHART_END_NAMESPACE
@@ -1,57 +1,60
1 /****************************************************************************
1 /****************************************************************************
2 **
2 **
3 ** Copyright (C) 2012 Digia Plc
3 ** Copyright (C) 2012 Digia Plc
4 ** All rights reserved.
4 ** All rights reserved.
5 ** For any questions to Digia, please use contact form at http://qt.digia.com
5 ** For any questions to Digia, please use contact form at http://qt.digia.com
6 **
6 **
7 ** This file is part of the Qt Commercial Charts Add-on.
7 ** This file is part of the Qt Commercial Charts Add-on.
8 **
8 **
9 ** $QT_BEGIN_LICENSE$
9 ** $QT_BEGIN_LICENSE$
10 ** Licensees holding valid Qt Commercial licenses may use this file in
10 ** Licensees holding valid Qt Commercial licenses may use this file in
11 ** accordance with the Qt Commercial License Agreement provided with the
11 ** accordance with the Qt Commercial License Agreement provided with the
12 ** Software or, alternatively, in accordance with the terms contained in
12 ** Software or, alternatively, in accordance with the terms contained in
13 ** a written agreement between you and Digia.
13 ** a written agreement between you and Digia.
14 **
14 **
15 ** If you have questions regarding the use of this file, please use
15 ** If you have questions regarding the use of this file, please use
16 ** contact form at http://qt.digia.com
16 ** contact form at http://qt.digia.com
17 ** $QT_END_LICENSE$
17 ** $QT_END_LICENSE$
18 **
18 **
19 ****************************************************************************/
19 ****************************************************************************/
20
20
21 #ifndef QPIELEGENDMARKER_H
21 #ifndef QPIELEGENDMARKER_H
22 #define QPIELEGENDMARKER_H
22 #define QPIELEGENDMARKER_H
23
23
24 #include <QChartGlobal>
24 #include <QChartGlobal>
25 #include <QLegendMarker>
25 #include <QLegendMarker>
26 #include <QPieSeries>
26 #include <QPieSlice>
27 #include <QPieSlice>
27 #include "qpielegendmarker_p.h"
28 //#include "qpielegendmarker_p.h"
28
29
29 QTCOMMERCIALCHART_BEGIN_NAMESPACE
30 QTCOMMERCIALCHART_BEGIN_NAMESPACE
30
31
31 // TODO: No export, make this private. QLegendMarker should be enough for user of the api (why expose the details?)
32 class QPieLegendMarkerPrivate;
33
34 // TODO: No export? make this private. QLegendMarker should be enough for user of the api (why expose the details?)
32 class QTCOMMERCIALCHART_EXPORT QPieLegendMarker : public QLegendMarker
35 class QTCOMMERCIALCHART_EXPORT QPieLegendMarker : public QLegendMarker
33 {
36 {
34 Q_OBJECT
37 Q_OBJECT
35
38
36 public:
39 public:
37 explicit QPieLegendMarker(QPieSeries* series, QPieSlice* slice, QLegend *legend, QObject *parent = 0);
40 explicit QPieLegendMarker(QPieSeries* series, QPieSlice* slice, QLegend *legend, QObject *parent = 0);
38 virtual ~QPieLegendMarker();
41 virtual ~QPieLegendMarker();
39
42
40 virtual QAbstractSeries* series();
43 virtual QPieSeries* series();
41 virtual QPieSlice* peerObject();
44 virtual QPieSlice* peerObject(); // TODO: rename to slice and remove these virtuals from base class?
42
45
43 protected:
46 protected:
44 QPieLegendMarker(QPieLegendMarkerPrivate &d, QObject *parent = 0);
47 QPieLegendMarker(QPieLegendMarkerPrivate &d, QObject *parent = 0);
45
48
46 //Q_SIGNALS:
49 //Q_SIGNALS:
47
50
48 //public Q_SLOTS:
51 //public Q_SLOTS:
49
52
50 private:
53 private:
51 Q_DECLARE_PRIVATE(QPieLegendMarker)
54 Q_DECLARE_PRIVATE(QPieLegendMarker)
52 Q_DISABLE_COPY(QPieLegendMarker)
55 Q_DISABLE_COPY(QPieLegendMarker)
53
56
54 };
57 };
55
58
56 QTCOMMERCIALCHART_END_NAMESPACE
59 QTCOMMERCIALCHART_END_NAMESPACE
57 #endif // QPIELEGENDMARKER_H
60 #endif // QPIELEGENDMARKER_H
@@ -1,68 +1,67
1 /****************************************************************************
1 /****************************************************************************
2 **
2 **
3 ** Copyright (C) 2012 Digia Plc
3 ** Copyright (C) 2012 Digia Plc
4 ** All rights reserved.
4 ** All rights reserved.
5 ** For any questions to Digia, please use contact form at http://qt.digia.com
5 ** For any questions to Digia, please use contact form at http://qt.digia.com
6 **
6 **
7 ** This file is part of the Qt Commercial Charts Add-on.
7 ** This file is part of the Qt Commercial Charts Add-on.
8 **
8 **
9 ** $QT_BEGIN_LICENSE$
9 ** $QT_BEGIN_LICENSE$
10 ** Licensees holding valid Qt Commercial licenses may use this file in
10 ** Licensees holding valid Qt Commercial licenses may use this file in
11 ** accordance with the Qt Commercial License Agreement provided with the
11 ** accordance with the Qt Commercial License Agreement provided with the
12 ** Software or, alternatively, in accordance with the terms contained in
12 ** Software or, alternatively, in accordance with the terms contained in
13 ** a written agreement between you and Digia.
13 ** a written agreement between you and Digia.
14 **
14 **
15 ** If you have questions regarding the use of this file, please use
15 ** If you have questions regarding the use of this file, please use
16 ** contact form at http://qt.digia.com
16 ** contact form at http://qt.digia.com
17 ** $QT_END_LICENSE$
17 ** $QT_END_LICENSE$
18 **
18 **
19 ****************************************************************************/
19 ****************************************************************************/
20
20
21 // W A R N I N G
21 // W A R N I N G
22 // -------------
22 // -------------
23 //
23 //
24 // This file is not part of the QtCommercial Chart API. It exists purely as an
24 // This file is not part of the QtCommercial Chart API. It exists purely as an
25 // implementation detail. This header file may change from version to
25 // implementation detail. This header file may change from version to
26 // version without notice, or even be removed.
26 // version without notice, or even be removed.
27 //
27 //
28 // We mean it.
28 // We mean it.
29
29
30 #ifndef QPIELEGENDMARKER_P_H
30 #ifndef QPIELEGENDMARKER_P_H
31 #define QPIELEGENDMARKER_P_H
31 #define QPIELEGENDMARKER_P_H
32
32
33 #include "qchartglobal.h"
33 #include "qchartglobal.h"
34 #include "qlegendmarker_p.h"
34 #include "qlegendmarker_p.h"
35 #include "legendmarkeritem_p.h"
35 #include "legendmarkeritem_p.h"
36 #include <QPieSeries>
36 #include <QPieSeries>
37 #include <QPieSlice>
37 #include <QPieSlice>
38
38
39 #include <QDebug>
39 #include <QDebug>
40
40
41 QTCOMMERCIALCHART_BEGIN_NAMESPACE
41 QTCOMMERCIALCHART_BEGIN_NAMESPACE
42
42
43 class QPieLegendMarker;
43 class QPieLegendMarker;
44
44
45 class QPieLegendMarkerPrivate : public QLegendMarkerPrivate
45 class QPieLegendMarkerPrivate : public QLegendMarkerPrivate
46 {
46 {
47 Q_OBJECT
47 Q_OBJECT
48 public:
48 public:
49 // explicit QPieLegendMarkerPrivate(QAbstractSeries *series, QPieLegendMarker *q);
50 explicit QPieLegendMarkerPrivate(QPieLegendMarker *q, QPieSeries *series, QPieSlice *slice, QLegend *legend);
49 explicit QPieLegendMarkerPrivate(QPieLegendMarker *q, QPieSeries *series, QPieSlice *slice, QLegend *legend);
51 virtual ~QPieLegendMarkerPrivate();
50 virtual ~QPieLegendMarkerPrivate();
52
51
53 public Q_SLOTS:
52 public Q_SLOTS:
54 virtual void updated();
53 virtual void updated();
55
54
56 private:
55 private:
57 QPieLegendMarker *q_ptr;
56 QPieLegendMarker *q_ptr;
58
57
59 QPieSeries* m_series;
58 QPieSeries* m_series;
60 QPieSlice* m_slice;
59 QPieSlice* m_slice;
61
60
62 friend class QLegendPrivate; // TODO: Is this needed?
61 friend class QLegendPrivate; // TODO: Is this needed?
63 Q_DECLARE_PUBLIC(QPieLegendMarker)
62 Q_DECLARE_PUBLIC(QPieLegendMarker)
64 };
63 };
65
64
66 QTCOMMERCIALCHART_END_NAMESPACE
65 QTCOMMERCIALCHART_END_NAMESPACE
67
66
68 #endif // QPIELEGENDMARKER_P_H
67 #endif // QPIELEGENDMARKER_P_H
General Comments 0
You need to be logged in to leave comments. Login now