##// END OF EJS Templates
first prototry of QLegendMarker API
sauimone -
r2160:5f63b94a2ef5
parent child
Show More
@@ -0,0 +1,80
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 "qlegendmarker.h"
22 //#include "qlegendmarker_p.h"
23 #include <QDebug>
24
25 QTCOMMERCIALCHART_BEGIN_NAMESPACE
26
27 QLegendMarker::QLegendMarker(QObject *parent) :
28 QObject(parent)//,
29 // d_ptr(new QLegendMarkerPrivate(this))
30 {
31 }
32
33 QLegendMarker::~QLegendMarker()
34 {
35 }
36
37 QString QLegendMarker::label() const
38 {
39 return m_label;
40 }
41
42 void QLegendMarker::setLabel(const QString &label)
43 {
44 m_label = label;
45 }
46
47 QPen QLegendMarker::pen() const
48 {
49 return m_pen;
50 }
51
52 void QLegendMarker::setPen(const QPen &pen)
53 {
54 m_pen = pen;
55 }
56
57 QBrush QLegendMarker::brush() const
58 {
59 return m_brush;
60 }
61
62 void QLegendMarker::setBrush(const QBrush &brush)
63 {
64 m_brush = brush;
65 }
66
67 bool QLegendMarker::isVisible() const
68 {
69 return m_visible;
70 }
71
72 void QLegendMarker::setVisible(bool visible)
73 {
74 m_visible = visible;
75 }
76
77 #include "moc_qlegendmarker.cpp"
78 //#include "moc_qlegendmarker_p.cpp"
79
80 QTCOMMERCIALCHART_END_NAMESPACE
@@ -0,0 +1,81
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 #ifndef QLEGENDMARKER_H
22 #define QLEGENDMARKER_H
23
24 #include <QChartGlobal>
25 #include <QObject>
26 #include <QPen>
27 #include <QBrush>
28
29 QTCOMMERCIALCHART_BEGIN_NAMESPACE
30
31 // TODO:
32 //class QLegendMarkerPrivate;
33
34 // TODO: should this be abstract?
35 class QTCOMMERCIALCHART_EXPORT QLegendMarker : public QObject
36 {
37 Q_OBJECT
38
39 // TODO: need for these?
40 // Q_PROPERTY(QString label READ label WRITE setlabel NOTIFY labelChanged);
41 // Q_PROPERTY(QPen pen READ pen WRITE setPen NOTIFY penChanged);
42 // Q_PROPERTY(QBrush brush READ brush WRITE setBrush NOTIFY brushChanged);
43
44 public:
45 explicit QLegendMarker(QObject *parent = 0);
46 virtual ~QLegendMarker();
47
48 QString label() const;
49 void setLabel(const QString &label);
50
51 QPen pen() const;
52 void setPen(const QPen &pen);
53
54 QBrush brush() const;
55 void setBrush(const QBrush &brush);
56
57 bool isVisible() const;
58 void setVisible(bool visible);
59
60 Q_SIGNALS:
61 void clicked();
62 void hovered(bool status);
63
64 public Q_SLOTS:
65 void markersUpdated(); // TODO: private? Idea is that series signals, when for example pieslices have been added/removed.
66
67 public:
68 // TODO:
69 // QScopedPointer<QLegendMarkerPrivate> d_ptr;
70 Q_DISABLE_COPY(QLegendMarker)
71
72 // TODO: move to PIMPL
73 QString m_label;
74 QPen m_pen;
75 QBrush m_brush;
76 bool m_visible;
77 };
78
79 QTCOMMERCIALCHART_END_NAMESPACE
80
81 #endif // QLEGENDMARKER_H
@@ -1,17 +1,19
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
9
9 PRIVATE_HEADERS += \
10 PRIVATE_HEADERS += \
10 $$PWD/legendmarker_p.h \
11 $$PWD/legendmarker_p.h \
11 $$PWD/legendscroller_p.h \
12 $$PWD/legendscroller_p.h \
12 $$PWD/qlegend_p.h \
13 $$PWD/qlegend_p.h \
13 $$PWD/legendlayout_p.h
14 $$PWD/legendlayout_p.h
14
15
15
16
16 PUBLIC_HEADERS += \
17 PUBLIC_HEADERS += \
17 $$PWD/qlegend.h No newline at end of file
18 $$PWD/qlegend.h \
19 $$PWD/qlegendmarker.h
@@ -1,514 +1,522
1 /****************************************************************************
1 /****************************************************************************
2 **
2 **
3 ** Copyright (C) 2012 Digia Plc
3 ** Copyright (C) 2012 Digia Plc
4 ** All rights reserved.
4 ** All rights reserved.
5 ** For any questions to Digia, please use contact form at http://qt.digia.com
5 ** For any questions to Digia, please use contact form at http://qt.digia.com
6 **
6 **
7 ** This file is part of the Qt Commercial Charts Add-on.
7 ** This file is part of the Qt Commercial Charts Add-on.
8 **
8 **
9 ** $QT_BEGIN_LICENSE$
9 ** $QT_BEGIN_LICENSE$
10 ** Licensees holding valid Qt Commercial licenses may use this file in
10 ** Licensees holding valid Qt Commercial licenses may use this file in
11 ** accordance with the Qt Commercial License Agreement provided with the
11 ** accordance with the Qt Commercial License Agreement provided with the
12 ** Software or, alternatively, in accordance with the terms contained in
12 ** Software or, alternatively, in accordance with the terms contained in
13 ** a written agreement between you and Digia.
13 ** a written agreement between you and Digia.
14 **
14 **
15 ** If you have questions regarding the use of this file, please use
15 ** If you have questions regarding the use of this file, please use
16 ** contact form at http://qt.digia.com
16 ** contact form at http://qt.digia.com
17 ** $QT_END_LICENSE$
17 ** $QT_END_LICENSE$
18 **
18 **
19 ****************************************************************************/
19 ****************************************************************************/
20
20
21 #include "qlegend.h"
21 #include "qlegend.h"
22 #include "qlegend_p.h"
22 #include "qlegend_p.h"
23 #include "qabstractseries.h"
23 #include "qabstractseries.h"
24 #include "qabstractseries_p.h"
24 #include "qabstractseries_p.h"
25 #include "qchart_p.h"
25 #include "qchart_p.h"
26 #include "legendlayout_p.h"
26 #include "legendlayout_p.h"
27 #include "legendmarker_p.h"
27 #include "legendmarker_p.h"
28 #include "qxyseries.h"
28 #include "qxyseries.h"
29 #include "qlineseries.h"
29 #include "qlineseries.h"
30 #include "qareaseries.h"
30 #include "qareaseries.h"
31 #include "qscatterseries.h"
31 #include "qscatterseries.h"
32 #include "qsplineseries.h"
32 #include "qsplineseries.h"
33 #include "qabstractbarseries.h"
33 #include "qabstractbarseries.h"
34 #include "qstackedbarseries.h"
34 #include "qstackedbarseries.h"
35 #include "qpercentbarseries.h"
35 #include "qpercentbarseries.h"
36 #include "qbarset.h"
36 #include "qbarset.h"
37 #include "qpieseries.h"
37 #include "qpieseries.h"
38 #include "qpieseries_p.h"
38 #include "qpieseries_p.h"
39 #include "qpieslice.h"
39 #include "qpieslice.h"
40 #include "chartpresenter_p.h"
40 #include "chartpresenter_p.h"
41 #include "chartlayout_p.h"
41 #include "chartlayout_p.h"
42 #include <QPainter>
42 #include <QPainter>
43 #include <QPen>
43 #include <QPen>
44 #include <QTimer>
44 #include <QTimer>
45 #include <QGraphicsSceneEvent>
45 #include <QGraphicsSceneEvent>
46
46
47 QTCOMMERCIALCHART_BEGIN_NAMESPACE
47 QTCOMMERCIALCHART_BEGIN_NAMESPACE
48
48
49 /*!
49 /*!
50 \class QLegend
50 \class QLegend
51 \brief Legend object
51 \brief Legend object
52 \mainclass
52 \mainclass
53
53
54 QLegend is a graphical object, whics displays legend of the chart. Legend state is updated by QChart, when
54 QLegend is a graphical object, whics displays legend of the chart. Legend state is updated by QChart, when
55 series have been changed. By default, legend is drawn by QChart, but user can set a new parent to legend and
55 series have been changed. By default, legend is drawn by QChart, but user can set a new parent to legend and
56 handle the drawing manually.
56 handle the drawing manually.
57 User isn't supposed to create or delete legend objects, but can reference it via QChart class.
57 User isn't supposed to create or delete legend objects, but can reference it via QChart class.
58
58
59 \image examples_percentbarchart_legend.png
59 \image examples_percentbarchart_legend.png
60
60
61 \sa QChart
61 \sa QChart
62 */
62 */
63 /*!
63 /*!
64 \qmlclass Legend QLegend
64 \qmlclass Legend QLegend
65 \brief Legend is part of QtCommercial Chart QML API.
65 \brief Legend is part of QtCommercial Chart QML API.
66
66
67 Legend is a graphical object, whics displays legend of the chart. Legend state is updated by ChartView, when
67 Legend is a graphical object, whics displays legend of the chart. Legend state is updated by ChartView, when
68 series have been changed. Legend is used via ChartView class. For example:
68 series have been changed. Legend is used via ChartView class. For example:
69 \code
69 \code
70 ChartView {
70 ChartView {
71 legend.visible: true
71 legend.visible: true
72 legend.alignment: Qt.AlignBottom
72 legend.alignment: Qt.AlignBottom
73 // Add a few series...
73 // Add a few series...
74 }
74 }
75 \endcode
75 \endcode
76
76
77 \image examples_percentbarchart_legend.png
77 \image examples_percentbarchart_legend.png
78 */
78 */
79
79
80 /*!
80 /*!
81 \property QLegend::alignment
81 \property QLegend::alignment
82 \brief The alignment of the legend.
82 \brief The alignment of the legend.
83
83
84 Legend paints on the defined position in the chart. The following alignments are supported:
84 Legend paints on the defined position in the chart. The following alignments are supported:
85 Qt::AlignTop, Qt::AlignBottom, Qt::AlignLeft, Qt::AlignRight. If you set more than one flag the result is undefined.
85 Qt::AlignTop, Qt::AlignBottom, Qt::AlignLeft, Qt::AlignRight. If you set more than one flag the result is undefined.
86 */
86 */
87 /*!
87 /*!
88 \qmlproperty Qt.Alignment Legend::alignment
88 \qmlproperty Qt.Alignment Legend::alignment
89 \brief The alignment of the legend.
89 \brief The alignment of the legend.
90
90
91 Legend paints on the defined position in the chart. The following alignments are supported:
91 Legend paints on the defined position in the chart. The following alignments are supported:
92 Qt.AlignTop, Qt.AlignBottom, Qt.AlignLeft, Qt.AlignRight. If you set more than one flag the result is undefined.
92 Qt.AlignTop, Qt.AlignBottom, Qt.AlignLeft, Qt.AlignRight. If you set more than one flag the result is undefined.
93 */
93 */
94
94
95 /*!
95 /*!
96 \property QLegend::backgroundVisible
96 \property QLegend::backgroundVisible
97 Whether the legend background is visible or not.
97 Whether the legend background is visible or not.
98 */
98 */
99 /*!
99 /*!
100 \qmlproperty bool Legend::backgroundVisible
100 \qmlproperty bool Legend::backgroundVisible
101 Whether the legend background is visible or not.
101 Whether the legend background is visible or not.
102 */
102 */
103
103
104 /*!
104 /*!
105 \property QLegend::color
105 \property QLegend::color
106 The color of the legend, i.e. the background (brush) color. Note that if you change the color
106 The color of the legend, i.e. the background (brush) color. Note that if you change the color
107 of the legend, the style of the legend brush is set to Qt::SolidPattern.
107 of the legend, the style of the legend brush is set to Qt::SolidPattern.
108 */
108 */
109 /*!
109 /*!
110 \qmlproperty color Legend::color
110 \qmlproperty color Legend::color
111 The color of the legend, i.e. the background (brush) color.
111 The color of the legend, i.e. the background (brush) color.
112 */
112 */
113
113
114 /*!
114 /*!
115 \property QLegend::borderColor
115 \property QLegend::borderColor
116 The border color of the legend, i.e. the line color.
116 The border color of the legend, i.e. the line color.
117 */
117 */
118 /*!
118 /*!
119 \qmlproperty color Legend::borderColor
119 \qmlproperty color Legend::borderColor
120 The border color of the legend, i.e. the line color.
120 The border color of the legend, i.e. the line color.
121 */
121 */
122
122
123 /*!
123 /*!
124 \property QLegend::font
124 \property QLegend::font
125 The font of markers used by legend
125 The font of markers used by legend
126 */
126 */
127 /*!
127 /*!
128 \qmlproperty Font Legend::font
128 \qmlproperty Font Legend::font
129 The font of markers used by legend
129 The font of markers used by legend
130 */
130 */
131
131
132 /*!
132 /*!
133 \property QLegend::labelColor
133 \property QLegend::labelColor
134 The color of brush used to draw labels.
134 The color of brush used to draw labels.
135 */
135 */
136 /*!
136 /*!
137 \qmlproperty color QLegend::labelColor
137 \qmlproperty color QLegend::labelColor
138 The color of brush used to draw labels.
138 The color of brush used to draw labels.
139 */
139 */
140
140
141 /*!
141 /*!
142 \fn void QLegend::backgroundVisibleChanged(bool)
142 \fn void QLegend::backgroundVisibleChanged(bool)
143 The visibility of the legend background changed to \a visible.
143 The visibility of the legend background changed to \a visible.
144 */
144 */
145
145
146 /*!
146 /*!
147 \fn void QLegend::colorChanged(QColor)
147 \fn void QLegend::colorChanged(QColor)
148 The color of the legend background changed to \a color.
148 The color of the legend background changed to \a color.
149 */
149 */
150
150
151 /*!
151 /*!
152 \fn void QLegend::borderColorChanged(QColor)
152 \fn void QLegend::borderColorChanged(QColor)
153 The border color of the legend background changed to \a color.
153 The border color of the legend background changed to \a color.
154 */
154 */
155
155
156 /*!
156 /*!
157 \fn void QLegend::fontChanged(QFont)
157 \fn void QLegend::fontChanged(QFont)
158 The font of markers of the legend changed to \a font.
158 The font of markers of the legend changed to \a font.
159 */
159 */
160
160
161 /*!
161 /*!
162 \fn void QLegend::labelColorChanged(QColor color)
162 \fn void QLegend::labelColorChanged(QColor color)
163 This signal is emitted when the color of brush used to draw labels has changed to \a color.
163 This signal is emitted when the color of brush used to draw labels has changed to \a color.
164 */
164 */
165
165
166 /*!
166 /*!
167 Constructs the legend object and sets the parent to \a parent
167 Constructs the legend object and sets the parent to \a parent
168 */
168 */
169
169
170 QLegend::QLegend(QChart *chart): QGraphicsWidget(chart),
170 QLegend::QLegend(QChart *chart): QGraphicsWidget(chart),
171 d_ptr(new QLegendPrivate(chart->d_ptr->m_presenter, chart, this))
171 d_ptr(new QLegendPrivate(chart->d_ptr->m_presenter, chart, this))
172 {
172 {
173 setZValue(ChartPresenter::LegendZValue);
173 setZValue(ChartPresenter::LegendZValue);
174 setFlags(QGraphicsItem::ItemClipsChildrenToShape);
174 setFlags(QGraphicsItem::ItemClipsChildrenToShape);
175 QObject::connect(chart->d_ptr->m_dataset, SIGNAL(seriesAdded(QAbstractSeries*,Domain*)), d_ptr.data(), SLOT(handleSeriesAdded(QAbstractSeries*,Domain*)));
175 QObject::connect(chart->d_ptr->m_dataset, SIGNAL(seriesAdded(QAbstractSeries*,Domain*)), d_ptr.data(), SLOT(handleSeriesAdded(QAbstractSeries*,Domain*)));
176 QObject::connect(chart->d_ptr->m_dataset, SIGNAL(seriesRemoved(QAbstractSeries*)), d_ptr.data(), SLOT(handleSeriesRemoved(QAbstractSeries*)));
176 QObject::connect(chart->d_ptr->m_dataset, SIGNAL(seriesRemoved(QAbstractSeries*)), d_ptr.data(), SLOT(handleSeriesRemoved(QAbstractSeries*)));
177 // QObject::connect(chart->d_ptr->m_dataset,SIGNAL(seriesUpdated(QAbstractSeries*)),d_ptr.data(),SLOT(handleSeriesUpdated(QAbstractSeries*)));
177 // QObject::connect(chart->d_ptr->m_dataset,SIGNAL(seriesUpdated(QAbstractSeries*)),d_ptr.data(),SLOT(handleSeriesUpdated(QAbstractSeries*)));
178 setLayout(d_ptr->m_layout);
178 setLayout(d_ptr->m_layout);
179 }
179 }
180
180
181 /*!
181 /*!
182 Destroys the legend object. Legend is always owned by a QChart, so an application should never call this.
182 Destroys the legend object. Legend is always owned by a QChart, so an application should never call this.
183 */
183 */
184 QLegend::~QLegend()
184 QLegend::~QLegend()
185 {
185 {
186 }
186 }
187
187
188 /*!
188 /*!
189 \internal
189 \internal
190 */
190 */
191 void QLegend::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget)
191 void QLegend::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget)
192 {
192 {
193 Q_UNUSED(option)
193 Q_UNUSED(option)
194 Q_UNUSED(widget)
194 Q_UNUSED(widget)
195
195
196 if (!d_ptr->m_backgroundVisible)
196 if (!d_ptr->m_backgroundVisible)
197 return;
197 return;
198
198
199 painter->setOpacity(opacity());
199 painter->setOpacity(opacity());
200 painter->setPen(d_ptr->m_pen);
200 painter->setPen(d_ptr->m_pen);
201 painter->setBrush(d_ptr->m_brush);
201 painter->setBrush(d_ptr->m_brush);
202 painter->drawRoundRect(rect(), d_ptr->roundness(rect().width()), d_ptr->roundness(rect().height()));
202 painter->drawRoundRect(rect(), d_ptr->roundness(rect().width()), d_ptr->roundness(rect().height()));
203 }
203 }
204
204
205
205
206 /*!
206 /*!
207 Sets the \a brush of legend. Brush affects the background of legend.
207 Sets the \a brush of legend. Brush affects the background of legend.
208 */
208 */
209 void QLegend::setBrush(const QBrush &brush)
209 void QLegend::setBrush(const QBrush &brush)
210 {
210 {
211 if (d_ptr->m_brush != brush) {
211 if (d_ptr->m_brush != brush) {
212 d_ptr->m_brush = brush;
212 d_ptr->m_brush = brush;
213 update();
213 update();
214 emit colorChanged(brush.color());
214 emit colorChanged(brush.color());
215 }
215 }
216 }
216 }
217
217
218 /*!
218 /*!
219 Returns the brush used by legend.
219 Returns the brush used by legend.
220 */
220 */
221 QBrush QLegend::brush() const
221 QBrush QLegend::brush() const
222 {
222 {
223 return d_ptr->m_brush;
223 return d_ptr->m_brush;
224 }
224 }
225
225
226 void QLegend::setColor(QColor color)
226 void QLegend::setColor(QColor color)
227 {
227 {
228 QBrush b = d_ptr->m_brush;
228 QBrush b = d_ptr->m_brush;
229 if (b.style() != Qt::SolidPattern || b.color() != color) {
229 if (b.style() != Qt::SolidPattern || b.color() != color) {
230 b.setStyle(Qt::SolidPattern);
230 b.setStyle(Qt::SolidPattern);
231 b.setColor(color);
231 b.setColor(color);
232 setBrush(b);
232 setBrush(b);
233 }
233 }
234 }
234 }
235
235
236 QColor QLegend::color()
236 QColor QLegend::color()
237 {
237 {
238 return d_ptr->m_brush.color();
238 return d_ptr->m_brush.color();
239 }
239 }
240
240
241 /*!
241 /*!
242 Sets the \a pen of legend. Pen affects the legend borders.
242 Sets the \a pen of legend. Pen affects the legend borders.
243 */
243 */
244 void QLegend::setPen(const QPen &pen)
244 void QLegend::setPen(const QPen &pen)
245 {
245 {
246 if (d_ptr->m_pen != pen) {
246 if (d_ptr->m_pen != pen) {
247 d_ptr->m_pen = pen;
247 d_ptr->m_pen = pen;
248 update();
248 update();
249 emit borderColorChanged(pen.color());
249 emit borderColorChanged(pen.color());
250 }
250 }
251 }
251 }
252
252
253 /*!
253 /*!
254 Returns the pen used by legend
254 Returns the pen used by legend
255 */
255 */
256
256
257 QPen QLegend::pen() const
257 QPen QLegend::pen() const
258 {
258 {
259 return d_ptr->m_pen;
259 return d_ptr->m_pen;
260 }
260 }
261
261
262 void QLegend::setFont(const QFont &font)
262 void QLegend::setFont(const QFont &font)
263 {
263 {
264 if (d_ptr->m_font != font) {
264 if (d_ptr->m_font != font) {
265 d_ptr->m_font = font;
265 d_ptr->m_font = font;
266 foreach (LegendMarker *marker, d_ptr->markers())
266 foreach (LegendMarker *marker, d_ptr->markers())
267 marker->setFont(d_ptr->m_font);
267 marker->setFont(d_ptr->m_font);
268 layout()->invalidate();
268 layout()->invalidate();
269 emit fontChanged(font);
269 emit fontChanged(font);
270 }
270 }
271 }
271 }
272
272
273 QFont QLegend::font() const
273 QFont QLegend::font() const
274 {
274 {
275 return d_ptr->m_font;
275 return d_ptr->m_font;
276 }
276 }
277
277
278 void QLegend::setBorderColor(QColor color)
278 void QLegend::setBorderColor(QColor color)
279 {
279 {
280 QPen p = d_ptr->m_pen;
280 QPen p = d_ptr->m_pen;
281 if (p.color() != color) {
281 if (p.color() != color) {
282 p.setColor(color);
282 p.setColor(color);
283 setPen(p);
283 setPen(p);
284 }
284 }
285 }
285 }
286
286
287 QColor QLegend::borderColor()
287 QColor QLegend::borderColor()
288 {
288 {
289 return d_ptr->m_pen.color();
289 return d_ptr->m_pen.color();
290 }
290 }
291
291
292 /*!
292 /*!
293 Set brush used to draw labels to \a brush.
293 Set brush used to draw labels to \a brush.
294 */
294 */
295 void QLegend::setLabelBrush(const QBrush &brush)
295 void QLegend::setLabelBrush(const QBrush &brush)
296 {
296 {
297 if (d_ptr->m_labelBrush != brush) {
297 if (d_ptr->m_labelBrush != brush) {
298 d_ptr->m_labelBrush = brush;
298 d_ptr->m_labelBrush = brush;
299 foreach (LegendMarker *marker, d_ptr->markers()) {
299 foreach (LegendMarker *marker, d_ptr->markers()) {
300 marker->setLabelBrush(d_ptr->m_labelBrush);
300 marker->setLabelBrush(d_ptr->m_labelBrush);
301 // Note: The pen of the marker rectangle could be exposed in the public QLegend API
301 // Note: The pen of the marker rectangle could be exposed in the public QLegend API
302 // instead of mapping it from label brush color
302 // instead of mapping it from label brush color
303 marker->setPen(brush.color());
303 marker->setPen(brush.color());
304 }
304 }
305 emit labelColorChanged(brush.color());
305 emit labelColorChanged(brush.color());
306 }
306 }
307 }
307 }
308
308
309 /*!
309 /*!
310 Brush used to draw labels.
310 Brush used to draw labels.
311 */
311 */
312 QBrush QLegend::labelBrush() const
312 QBrush QLegend::labelBrush() const
313 {
313 {
314 return d_ptr->m_labelBrush;
314 return d_ptr->m_labelBrush;
315 }
315 }
316
316
317 void QLegend::setLabelColor(QColor color)
317 void QLegend::setLabelColor(QColor color)
318 {
318 {
319 QBrush b = d_ptr->m_labelBrush;
319 QBrush b = d_ptr->m_labelBrush;
320 if (b.style() != Qt::SolidPattern || b.color() != color) {
320 if (b.style() != Qt::SolidPattern || b.color() != color) {
321 b.setStyle(Qt::SolidPattern);
321 b.setStyle(Qt::SolidPattern);
322 b.setColor(color);
322 b.setColor(color);
323 setLabelBrush(b);
323 setLabelBrush(b);
324 }
324 }
325 }
325 }
326
326
327 QColor QLegend::labelColor() const
327 QColor QLegend::labelColor() const
328 {
328 {
329 return d_ptr->m_labelBrush.color();
329 return d_ptr->m_labelBrush.color();
330 }
330 }
331
331
332
332
333 void QLegend::setAlignment(Qt::Alignment alignment)
333 void QLegend::setAlignment(Qt::Alignment alignment)
334 {
334 {
335 if (d_ptr->m_alignment != alignment) {
335 if (d_ptr->m_alignment != alignment) {
336 d_ptr->m_alignment = alignment;
336 d_ptr->m_alignment = alignment;
337 layout()->invalidate();
337 layout()->invalidate();
338 }
338 }
339 }
339 }
340
340
341 Qt::Alignment QLegend::alignment() const
341 Qt::Alignment QLegend::alignment() const
342 {
342 {
343 return d_ptr->m_alignment;
343 return d_ptr->m_alignment;
344 }
344 }
345
345
346 /*!
346 /*!
347 Detaches the legend from chart. Chart won't change layout of the legend.
347 Detaches the legend from chart. Chart won't change layout of the legend.
348 */
348 */
349 void QLegend::detachFromChart()
349 void QLegend::detachFromChart()
350 {
350 {
351 d_ptr->m_attachedToChart = false;
351 d_ptr->m_attachedToChart = false;
352 layout()->invalidate();
352 layout()->invalidate();
353 setParent(0);
353 setParent(0);
354
354
355 }
355 }
356
356
357 /*!
357 /*!
358 Attaches the legend to chart. Chart may change layout of the legend.
358 Attaches the legend to chart. Chart may change layout of the legend.
359 */
359 */
360 void QLegend::attachToChart()
360 void QLegend::attachToChart()
361 {
361 {
362 d_ptr->m_attachedToChart = true;
362 d_ptr->m_attachedToChart = true;
363 layout()->invalidate();
363 layout()->invalidate();
364 setParent(d_ptr->m_chart);
364 setParent(d_ptr->m_chart);
365 }
365 }
366
366
367 /*!
367 /*!
368 Returns true, if legend is attached to chart.
368 Returns true, if legend is attached to chart.
369 */
369 */
370 bool QLegend::isAttachedToChart()
370 bool QLegend::isAttachedToChart()
371 {
371 {
372 return d_ptr->m_attachedToChart;
372 return d_ptr->m_attachedToChart;
373 }
373 }
374
374
375 /*!
375 /*!
376 Sets the visibility of legend background to \a visible
376 Sets the visibility of legend background to \a visible
377 */
377 */
378 void QLegend::setBackgroundVisible(bool visible)
378 void QLegend::setBackgroundVisible(bool visible)
379 {
379 {
380 if (d_ptr->m_backgroundVisible != visible) {
380 if (d_ptr->m_backgroundVisible != visible) {
381 d_ptr->m_backgroundVisible = visible;
381 d_ptr->m_backgroundVisible = visible;
382 update();
382 update();
383 emit backgroundVisibleChanged(visible);
383 emit backgroundVisibleChanged(visible);
384 }
384 }
385 }
385 }
386
386
387 /*!
387 /*!
388 Returns the visibility of legend background
388 Returns the visibility of legend background
389 */
389 */
390 bool QLegend::isBackgroundVisible() const
390 bool QLegend::isBackgroundVisible() const
391 {
391 {
392 return d_ptr->m_backgroundVisible;
392 return d_ptr->m_backgroundVisible;
393 }
393 }
394
394
395
396 QList<QLegendMarker*> QLegend::markers() const
397 {
398 // TODO: name of PIMPL method will change.
399 return d_ptr->legendMarkers();
400 }
401
402
395 /*!
403 /*!
396 \internal \a event see QGraphicsWidget for details
404 \internal \a event see QGraphicsWidget for details
397 */
405 */
398 void QLegend::hideEvent(QHideEvent *event)
406 void QLegend::hideEvent(QHideEvent *event)
399 {
407 {
400 if (isAttachedToChart())
408 if (isAttachedToChart())
401 d_ptr->m_presenter->layout()->invalidate();
409 d_ptr->m_presenter->layout()->invalidate();
402 QGraphicsWidget::hideEvent(event);
410 QGraphicsWidget::hideEvent(event);
403 }
411 }
404 /*!
412 /*!
405 \internal \a event see QGraphicsWidget for details
413 \internal \a event see QGraphicsWidget for details
406 */
414 */
407 void QLegend::showEvent(QShowEvent *event)
415 void QLegend::showEvent(QShowEvent *event)
408 {
416 {
409 if (isAttachedToChart()) {
417 if (isAttachedToChart()) {
410 d_ptr->items()->setVisible(false);
418 d_ptr->items()->setVisible(false);
411 layout()->invalidate();
419 layout()->invalidate();
412 }
420 }
413 QGraphicsWidget::showEvent(event);
421 QGraphicsWidget::showEvent(event);
414 //layout activation will show the items
422 //layout activation will show the items
415 }
423 }
416
424
417 ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
425 ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
418
426
419 QLegendPrivate::QLegendPrivate(ChartPresenter *presenter, QChart *chart, QLegend *q)
427 QLegendPrivate::QLegendPrivate(ChartPresenter *presenter, QChart *chart, QLegend *q)
420 : q_ptr(q),
428 : q_ptr(q),
421 m_presenter(presenter),
429 m_presenter(presenter),
422 m_layout(new LegendLayout(q)),
430 m_layout(new LegendLayout(q)),
423 m_chart(chart),
431 m_chart(chart),
424 m_items(new QGraphicsItemGroup(q)),
432 m_items(new QGraphicsItemGroup(q)),
425 m_alignment(Qt::AlignTop),
433 m_alignment(Qt::AlignTop),
426 m_brush(QBrush()),
434 m_brush(QBrush()),
427 m_pen(QPen()),
435 m_pen(QPen()),
428 m_labelBrush(QBrush()),
436 m_labelBrush(QBrush()),
429 m_diameter(5),
437 m_diameter(5),
430 m_attachedToChart(true),
438 m_attachedToChart(true),
431 m_backgroundVisible(false)
439 m_backgroundVisible(false)
432 {
440 {
433
441
434 }
442 }
435
443
436 QLegendPrivate::~QLegendPrivate()
444 QLegendPrivate::~QLegendPrivate()
437 {
445 {
438
446
439 }
447 }
440
448
441 void QLegendPrivate::setOffset(qreal x, qreal y)
449 void QLegendPrivate::setOffset(qreal x, qreal y)
442 {
450 {
443 m_layout->setOffset(x, y);
451 m_layout->setOffset(x, y);
444 }
452 }
445
453
446 QPointF QLegendPrivate::offset() const
454 QPointF QLegendPrivate::offset() const
447 {
455 {
448 return m_layout->offset();
456 return m_layout->offset();
449 }
457 }
450
458
451 int QLegendPrivate::roundness(qreal size)
459 int QLegendPrivate::roundness(qreal size)
452 {
460 {
453 return 100 * m_diameter / int(size);
461 return 100 * m_diameter / int(size);
454 }
462 }
455
463
456 void QLegendPrivate::handleSeriesAdded(QAbstractSeries *series, Domain *domain)
464 void QLegendPrivate::handleSeriesAdded(QAbstractSeries *series, Domain *domain)
457 {
465 {
458 Q_UNUSED(domain)
466 Q_UNUSED(domain)
459
467
460 QList<LegendMarker *> markers = series->d_ptr->createLegendMarker(q_ptr);
468 QList<LegendMarker *> markers = series->d_ptr->createLegendMarker(q_ptr);
461
469
462 foreach (LegendMarker *marker, markers) {
470 foreach (LegendMarker *marker, markers) {
463 marker->setFont(m_font);
471 marker->setFont(m_font);
464 marker->setLabelBrush(m_labelBrush);
472 marker->setLabelBrush(m_labelBrush);
465 marker->setVisible(series->isVisible());
473 marker->setVisible(series->isVisible());
466 m_items->addToGroup(marker);
474 m_items->addToGroup(marker);
467 m_markers << marker;
475 m_markers << marker;
468 }
476 }
469
477
470 QObject::connect(series, SIGNAL(visibleChanged()), this, SLOT(handleSeriesVisibleChanged()));
478 QObject::connect(series, SIGNAL(visibleChanged()), this, SLOT(handleSeriesVisibleChanged()));
471 QObject::connect(series->d_ptr.data(), SIGNAL(countChanged()), this, SLOT(handleCountChanged()));
479 QObject::connect(series->d_ptr.data(), SIGNAL(countChanged()), this, SLOT(handleCountChanged()));
472
480
473 m_items->setVisible(false);
481 m_items->setVisible(false);
474 m_layout->invalidate();
482 m_layout->invalidate();
475 }
483 }
476
484
477 void QLegendPrivate::handleSeriesRemoved(QAbstractSeries *series)
485 void QLegendPrivate::handleSeriesRemoved(QAbstractSeries *series)
478 {
486 {
479 foreach (LegendMarker *marker, m_markers) {
487 foreach (LegendMarker *marker, m_markers) {
480 if (marker->series() == series) {
488 if (marker->series() == series) {
481 delete marker;
489 delete marker;
482 m_markers.removeAll(marker);
490 m_markers.removeAll(marker);
483 }
491 }
484 }
492 }
485
493
486 QObject::disconnect(series, SIGNAL(visibleChanged()), this, SLOT(handleSeriesVisibleChanged()));
494 QObject::disconnect(series, SIGNAL(visibleChanged()), this, SLOT(handleSeriesVisibleChanged()));
487 QObject::disconnect(series->d_ptr.data(), SIGNAL(countChanged()), this, SLOT(handleCountChanged()));
495 QObject::disconnect(series->d_ptr.data(), SIGNAL(countChanged()), this, SLOT(handleCountChanged()));
488 m_layout->invalidate();
496 m_layout->invalidate();
489 }
497 }
490
498
491 void QLegendPrivate::handleSeriesVisibleChanged()
499 void QLegendPrivate::handleSeriesVisibleChanged()
492 {
500 {
493 QAbstractSeries *series = qobject_cast<QAbstractSeries *> (sender());
501 QAbstractSeries *series = qobject_cast<QAbstractSeries *> (sender());
494 Q_ASSERT(series);
502 Q_ASSERT(series);
495
503
496 foreach (LegendMarker *marker, m_markers) {
504 foreach (LegendMarker *marker, m_markers) {
497 if (marker->series() == series)
505 if (marker->series() == series)
498 marker->setVisible(series->isVisible());
506 marker->setVisible(series->isVisible());
499 }
507 }
500 m_layout->invalidate();
508 m_layout->invalidate();
501 }
509 }
502
510
503 void QLegendPrivate::handleCountChanged()
511 void QLegendPrivate::handleCountChanged()
504 {
512 {
505 QAbstractSeriesPrivate *series = qobject_cast<QAbstractSeriesPrivate *> (sender());
513 QAbstractSeriesPrivate *series = qobject_cast<QAbstractSeriesPrivate *> (sender());
506 Q_ASSERT(series);
514 Q_ASSERT(series);
507 handleSeriesRemoved(series->q_ptr);
515 handleSeriesRemoved(series->q_ptr);
508 handleSeriesAdded(series->q_ptr, 0);
516 handleSeriesAdded(series->q_ptr, 0);
509 }
517 }
510
518
511 #include "moc_qlegend.cpp"
519 #include "moc_qlegend.cpp"
512 #include "moc_qlegend_p.cpp"
520 #include "moc_qlegend_p.cpp"
513
521
514 QTCOMMERCIALCHART_END_NAMESPACE
522 QTCOMMERCIALCHART_END_NAMESPACE
@@ -1,107 +1,111
1 /****************************************************************************
1 /****************************************************************************
2 **
2 **
3 ** Copyright (C) 2012 Digia Plc
3 ** Copyright (C) 2012 Digia Plc
4 ** All rights reserved.
4 ** All rights reserved.
5 ** For any questions to Digia, please use contact form at http://qt.digia.com
5 ** For any questions to Digia, please use contact form at http://qt.digia.com
6 **
6 **
7 ** This file is part of the Qt Commercial Charts Add-on.
7 ** This file is part of the Qt Commercial Charts Add-on.
8 **
8 **
9 ** $QT_BEGIN_LICENSE$
9 ** $QT_BEGIN_LICENSE$
10 ** Licensees holding valid Qt Commercial licenses may use this file in
10 ** Licensees holding valid Qt Commercial licenses may use this file in
11 ** accordance with the Qt Commercial License Agreement provided with the
11 ** accordance with the Qt Commercial License Agreement provided with the
12 ** Software or, alternatively, in accordance with the terms contained in
12 ** Software or, alternatively, in accordance with the terms contained in
13 ** a written agreement between you and Digia.
13 ** a written agreement between you and Digia.
14 **
14 **
15 ** If you have questions regarding the use of this file, please use
15 ** If you have questions regarding the use of this file, please use
16 ** contact form at http://qt.digia.com
16 ** contact form at http://qt.digia.com
17 ** $QT_END_LICENSE$
17 ** $QT_END_LICENSE$
18 **
18 **
19 ****************************************************************************/
19 ****************************************************************************/
20
20
21 #ifndef QLEGEND_H
21 #ifndef QLEGEND_H
22 #define QLEGEND_H
22 #define QLEGEND_H
23
23
24 #include <qchartglobal.h>
24 #include <qchartglobal.h>
25 #include <QGraphicsWidget>
25 #include <QGraphicsWidget>
26 #include <QPen>
26 #include <QPen>
27 #include <QBrush>
27 #include <QBrush>
28
28
29 QTCOMMERCIALCHART_BEGIN_NAMESPACE
29 QTCOMMERCIALCHART_BEGIN_NAMESPACE
30
30
31 class QPieSlice;
31 class QPieSlice;
32 class QXYSeries;
32 class QXYSeries;
33 class QBarSet;
33 class QBarSet;
34 class QAbstractBarSeries;
34 class QAbstractBarSeries;
35 class QPieSeries;
35 class QPieSeries;
36 class QAreaSeries;
36 class QAreaSeries;
37 class QChart;
37 class QChart;
38 class QLegendPrivate;
38 class QLegendPrivate;
39 class QLegendMarker;
39
40
40 class QTCOMMERCIALCHART_EXPORT QLegend : public QGraphicsWidget
41 class QTCOMMERCIALCHART_EXPORT QLegend : public QGraphicsWidget
41 {
42 {
42 Q_OBJECT
43 Q_OBJECT
43 Q_PROPERTY(Qt::Alignment alignment READ alignment WRITE setAlignment)
44 Q_PROPERTY(Qt::Alignment alignment READ alignment WRITE setAlignment)
44 Q_PROPERTY(bool backgroundVisible READ isBackgroundVisible WRITE setBackgroundVisible NOTIFY backgroundVisibleChanged)
45 Q_PROPERTY(bool backgroundVisible READ isBackgroundVisible WRITE setBackgroundVisible NOTIFY backgroundVisibleChanged)
45 Q_PROPERTY(QColor color READ color WRITE setColor NOTIFY colorChanged)
46 Q_PROPERTY(QColor color READ color WRITE setColor NOTIFY colorChanged)
46 Q_PROPERTY(QColor borderColor READ borderColor WRITE setBorderColor NOTIFY borderColorChanged)
47 Q_PROPERTY(QColor borderColor READ borderColor WRITE setBorderColor NOTIFY borderColorChanged)
47 Q_PROPERTY(QFont font READ font WRITE setFont NOTIFY fontChanged)
48 Q_PROPERTY(QFont font READ font WRITE setFont NOTIFY fontChanged)
48 Q_PROPERTY(QColor labelColor READ labelColor WRITE setLabelColor NOTIFY labelColorChanged)
49 Q_PROPERTY(QColor labelColor READ labelColor WRITE setLabelColor NOTIFY labelColorChanged)
49
50
50 private:
51 private:
51 explicit QLegend(QChart *chart);
52 explicit QLegend(QChart *chart);
52
53
53 public:
54 public:
54 ~QLegend();
55 ~QLegend();
55
56
56 void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget = 0);
57 void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget = 0);
57
58
58 void setBrush(const QBrush &brush);
59 void setBrush(const QBrush &brush);
59 QBrush brush() const;
60 QBrush brush() const;
60 void setColor(QColor color);
61 void setColor(QColor color);
61 QColor color();
62 QColor color();
62
63
63 void setPen(const QPen &pen);
64 void setPen(const QPen &pen);
64 QPen pen() const;
65 QPen pen() const;
65 void setBorderColor(QColor color);
66 void setBorderColor(QColor color);
66 QColor borderColor();
67 QColor borderColor();
67
68
68 void setFont(const QFont &font);
69 void setFont(const QFont &font);
69 QFont font() const;
70 QFont font() const;
70 void setLabelBrush(const QBrush &brush);
71 void setLabelBrush(const QBrush &brush);
71 QBrush labelBrush() const;
72 QBrush labelBrush() const;
72
73
73 void setLabelColor(QColor color);
74 void setLabelColor(QColor color);
74 QColor labelColor() const;
75 QColor labelColor() const;
75
76
76 void setAlignment(Qt::Alignment alignment);
77 void setAlignment(Qt::Alignment alignment);
77 Qt::Alignment alignment() const;
78 Qt::Alignment alignment() const;
78
79
79 void detachFromChart();
80 void detachFromChart();
80 void attachToChart();
81 void attachToChart();
81 bool isAttachedToChart();
82 bool isAttachedToChart();
82
83
83 void setBackgroundVisible(bool visible = true);
84 void setBackgroundVisible(bool visible = true);
84 bool isBackgroundVisible() const;
85 bool isBackgroundVisible() const;
85
86
87 // New stuff:
88 QList <QLegendMarker*> markers() const;
89
86 protected:
90 protected:
87 void hideEvent(QHideEvent *event);
91 void hideEvent(QHideEvent *event);
88 void showEvent(QShowEvent *event);
92 void showEvent(QShowEvent *event);
89
93
90 Q_SIGNALS:
94 Q_SIGNALS:
91 void backgroundVisibleChanged(bool visible);
95 void backgroundVisibleChanged(bool visible);
92 void colorChanged(QColor color);
96 void colorChanged(QColor color);
93 void borderColorChanged(QColor color);
97 void borderColorChanged(QColor color);
94 void fontChanged(QFont font);
98 void fontChanged(QFont font);
95 void labelColorChanged(QColor color);
99 void labelColorChanged(QColor color);
96
100
97 private:
101 private:
98 QScopedPointer<QLegendPrivate> d_ptr;
102 QScopedPointer<QLegendPrivate> d_ptr;
99 Q_DISABLE_COPY(QLegend)
103 Q_DISABLE_COPY(QLegend)
100 friend class LegendScroller;
104 friend class LegendScroller;
101 friend class LegendLayout;
105 friend class LegendLayout;
102 friend class ChartLayout;
106 friend class ChartLayout;
103 };
107 };
104
108
105 QTCOMMERCIALCHART_END_NAMESPACE
109 QTCOMMERCIALCHART_END_NAMESPACE
106
110
107 #endif // QLEGEND_H
111 #endif // QLEGEND_H
@@ -1,87 +1,92
1 /****************************************************************************
1 /****************************************************************************
2 **
2 **
3 ** Copyright (C) 2012 Digia Plc
3 ** Copyright (C) 2012 Digia Plc
4 ** All rights reserved.
4 ** All rights reserved.
5 ** For any questions to Digia, please use contact form at http://qt.digia.com
5 ** For any questions to Digia, please use contact form at http://qt.digia.com
6 **
6 **
7 ** This file is part of the Qt Commercial Charts Add-on.
7 ** This file is part of the Qt Commercial Charts Add-on.
8 **
8 **
9 ** $QT_BEGIN_LICENSE$
9 ** $QT_BEGIN_LICENSE$
10 ** Licensees holding valid Qt Commercial licenses may use this file in
10 ** Licensees holding valid Qt Commercial licenses may use this file in
11 ** accordance with the Qt Commercial License Agreement provided with the
11 ** accordance with the Qt Commercial License Agreement provided with the
12 ** Software or, alternatively, in accordance with the terms contained in
12 ** Software or, alternatively, in accordance with the terms contained in
13 ** a written agreement between you and Digia.
13 ** a written agreement between you and Digia.
14 **
14 **
15 ** If you have questions regarding the use of this file, please use
15 ** If you have questions regarding the use of this file, please use
16 ** contact form at http://qt.digia.com
16 ** contact form at http://qt.digia.com
17 ** $QT_END_LICENSE$
17 ** $QT_END_LICENSE$
18 **
18 **
19 ****************************************************************************/
19 ****************************************************************************/
20
20
21 // W A R N I N G
21 // W A R N I N G
22 // -------------
22 // -------------
23 //
23 //
24 // This file is not part of the QtCommercial Chart API. It exists purely as an
24 // This file is not part of the QtCommercial Chart API. It exists purely as an
25 // implementation detail. This header file may change from version to
25 // implementation detail. This header file may change from version to
26 // version without notice, or even be removed.
26 // version without notice, or even be removed.
27 //
27 //
28 // We mean it.
28 // We mean it.
29
29
30 #ifndef QLEGEND_P_H
30 #ifndef QLEGEND_P_H
31 #define QLEGEND_P_H
31 #define QLEGEND_P_H
32
32
33 #include "qlegend.h"
33 #include "qlegend.h"
34
34
35 QTCOMMERCIALCHART_BEGIN_NAMESPACE
35 QTCOMMERCIALCHART_BEGIN_NAMESPACE
36
36
37 class QChart;
37 class QChart;
38 class ChartPresenter;
38 class ChartPresenter;
39 class QAbstractSeries;
39 class QAbstractSeries;
40 class LegendLayout;
40 class LegendLayout;
41 class LegendMarker;
41 class LegendMarker;
42 class Domain;
42 class Domain;
43
43
44 class QLegendPrivate : public QObject
44 class QLegendPrivate : public QObject
45 {
45 {
46 Q_OBJECT
46 Q_OBJECT
47 public:
47 public:
48 QLegendPrivate(ChartPresenter *presenter, QChart *chart, QLegend *q);
48 QLegendPrivate(ChartPresenter *presenter, QChart *chart, QLegend *q);
49 ~QLegendPrivate();
49 ~QLegendPrivate();
50
50
51 void setOffset(qreal x, qreal y);
51 void setOffset(qreal x, qreal y);
52 QPointF offset() const;
52 QPointF offset() const;
53 int roundness(qreal size);
53 int roundness(qreal size);
54
54
55 QList<LegendMarker *> markers() { return m_markers; }
55 QList<LegendMarker*> markers() { return m_markers; } // TODO: this will be removed
56 QGraphicsItemGroup *items() { return m_items; }
56 QGraphicsItemGroup* items() { return m_items; }
57
58 // New stuff:
59 QList<QLegendMarker*> legendMarkers() { return m_legendMarkers; } // TODO: function name will change
57
60
58 public Q_SLOTS:
61 public Q_SLOTS:
59 void handleSeriesAdded(QAbstractSeries *series, Domain *domain);
62 void handleSeriesAdded(QAbstractSeries *series, Domain *domain);
60 void handleSeriesRemoved(QAbstractSeries *series);
63 void handleSeriesRemoved(QAbstractSeries *series);
61 void handleSeriesVisibleChanged();
64 void handleSeriesVisibleChanged();
62 void handleCountChanged();
65 void handleCountChanged();
63
66
64 private:
67 private:
65 QLegend *q_ptr;
68 QLegend *q_ptr;
66 ChartPresenter *m_presenter;
69 ChartPresenter *m_presenter;
67 LegendLayout *m_layout;
70 LegendLayout *m_layout;
68 QChart *m_chart;
71 QChart* m_chart;
69 QGraphicsItemGroup *m_items;
72 QGraphicsItemGroup* m_items;
70 QList<LegendMarker *> m_markers;
73 QList<LegendMarker*> m_markers; // TODO: this will be removed
71 Qt::Alignment m_alignment;
74 Qt::Alignment m_alignment;
72 QBrush m_brush;
75 QBrush m_brush;
73 QPen m_pen;
76 QPen m_pen;
74 QFont m_font;
77 QFont m_font;
75 QBrush m_labelBrush;
78 QBrush m_labelBrush;
76
79
77 qreal m_diameter;
80 qreal m_diameter;
78 bool m_attachedToChart;
81 bool m_attachedToChart;
79 bool m_backgroundVisible;
82 bool m_backgroundVisible;
80
83
81 friend class QLegend;
84 friend class QLegend;
82 friend class LegendLayout;
85 friend class LegendLayout;
86 QList<QLegendMarker*> m_legendMarkers; // TODO: rename to m_markers eventually.
87
83 };
88 };
84
89
85 QTCOMMERCIALCHART_END_NAMESPACE
90 QTCOMMERCIALCHART_END_NAMESPACE
86
91
87 #endif
92 #endif
General Comments 0
You need to be logged in to leave comments. Login now