##// END OF EJS Templates
documentation of legendmarkers
sauimone -
r2216:e42f56711736
parent child
Show More
@@ -1,91 +1,96
1 /*!
1 /*!
2 \page classes.html
2 \page classes.html
3 \title QtCommercial Charts API
3 \title QtCommercial Charts API
4 \keyword All Classes
4 \keyword All Classes
5
5
6 Charts API is build on top of Qt Graphics View Framework. Charts can be displayed as QGraphicsWidget using QChart class. However
6 Charts API is build on top of Qt Graphics View Framework. Charts can be displayed as QGraphicsWidget using QChart class. However
7 there is also convenience class QChartView which is QWidget based. These lets quickly use QCharts as normal Qt widget.
7 there is also convenience class QChartView which is QWidget based. These lets quickly use QCharts as normal Qt widget.
8
8
9 Each chart type is represented by QAbstractSeries derived class. To create given chart type users have to use instance of related series class and add it to QChart instance.
9 Each chart type is represented by QAbstractSeries derived class. To create given chart type users have to use instance of related series class and add it to QChart instance.
10 \code
10 \code
11 QLineSeries* series = new QLineSeries();
11 QLineSeries* series = new QLineSeries();
12 series->add(0, 6);
12 series->add(0, 6);
13 series->add(2, 4);
13 series->add(2, 4);
14 ...
14 ...
15 chartView->chart()->addSeries(series);
15 chartView->chart()->addSeries(series);
16 chartView->chart()->createDefaultAxes();
16 chartView->chart()->createDefaultAxes();
17 \endcode
17 \endcode
18
18
19 \raw HTML
19 \raw HTML
20 <table cellpadding="2" cellspacing="1" border="0" width="100%" class="indextable">
20 <table cellpadding="2" cellspacing="1" border="0" width="100%" class="indextable">
21 <tr>
21 <tr>
22 <th class="titleheader" width="25%">
22 <th class="titleheader" width="25%">
23 Common and global
23 Common and global
24 </th>
24 </th>
25 <th class="titleheader" width="25%">
25 <th class="titleheader" width="25%">
26 XY chart
26 XY chart
27 </th>
27 </th>
28 </tr>
28 </tr>
29 <tr>
29 <tr>
30 <td valign="top">
30 <td valign="top">
31 <ul>
31 <ul>
32 <li><a href="qchart.html">QChart</a></li>
32 <li><a href="qchart.html">QChart</a></li>
33 <li><a href="qchartview.html">QChartView</a></li>
33 <li><a href="qchartview.html">QChartView</a></li>
34 <li><a href="qabstractaxis.html">QAbstractAxis</a></li>
34 <li><a href="qabstractaxis.html">QAbstractAxis</a></li>
35 <li><a href="qvalueaxis.html">QValueAxis</a></li>
35 <li><a href="qvalueaxis.html">QValueAxis</a></li>
36 <li><a href="qbarcategoryaxis.html">QBarCategoryAxis</a></li>
36 <li><a href="qbarcategoryaxis.html">QBarCategoryAxis</a></li>
37 <li><a href="qcategoryaxis.html">QCategoryAxis</a></li>
37 <li><a href="qcategoryaxis.html">QCategoryAxis</a></li>
38 <li><a href="qdatetimeaxis.html">QDateTimeAxis</a></li>
38 <li><a href="qdatetimeaxis.html">QDateTimeAxis</a></li>
39 <li><a href="qlegend.html">QLegend</a></li>
39 <li><a href="qlegend.html">QLegend</a></li>
40 <li><a href="qlegendmarker.html">QLegendMarker</a></li>
41 <li><a href="qpielegendmarker.html">QPieLegendMarker</a></li>
42 <li><a href="qxylegendmarker.html">QXYLegendMarker</a></li>
43 <li><a href="qbarlegendmarker.html">QBarLegendMarker</a></li>
44 <li><a href="qarealegendmarker.html">QAreaLegendMarker</a></li>
40 <li><a href="qabstractseries.html">QAbstractSeries</a></li>
45 <li><a href="qabstractseries.html">QAbstractSeries</a></li>
41 <li><a href="qchartglobal.html">QChartGlobal</a></li>
46 <li><a href="qchartglobal.html">QChartGlobal</a></li>
42 </ul>
47 </ul>
43 </td>
48 </td>
44 <td valign="top">
49 <td valign="top">
45 <ul>
50 <ul>
46 <li><a href="qxyseries.html">QXYSeries</a></li>
51 <li><a href="qxyseries.html">QXYSeries</a></li>
47 <li><a href="qlineseries.html">QLineSeries</a></li>
52 <li><a href="qlineseries.html">QLineSeries</a></li>
48 <li><a href="qareaseries.html">QAreaSeries</a></li>
53 <li><a href="qareaseries.html">QAreaSeries</a></li>
49 <li><a href="qscatterseries.html">QScatterSeries</a></li>
54 <li><a href="qscatterseries.html">QScatterSeries</a></li>
50 <li><a href="qsplineseries.html">QSplineSeries</a></li>
55 <li><a href="qsplineseries.html">QSplineSeries</a></li>
51 <li><a href="qhxymodelmapper.html">QHXYModelMapper</a></li>
56 <li><a href="qhxymodelmapper.html">QHXYModelMapper</a></li>
52 <li><a href="qvxymodelmapper.html">QVXYModelMapper</a></li>
57 <li><a href="qvxymodelmapper.html">QVXYModelMapper</a></li>
53 </ul>
58 </ul>
54 </td>
59 </td>
55 </tr>
60 </tr>
56 </table>
61 </table>
57 <table cellpadding="2" cellspacing="1" border="0" width="100%" class="indextable">
62 <table cellpadding="2" cellspacing="1" border="0" width="100%" class="indextable">
58 <tr>
63 <tr>
59 <th class="titleheader" width="25%">
64 <th class="titleheader" width="25%">
60 Pie chart
65 Pie chart
61 </th>
66 </th>
62 <th class="titleheader" width="25%">
67 <th class="titleheader" width="25%">
63 Bar chart
68 Bar chart
64 </th>
69 </th>
65 <tr>
70 <tr>
66 <td valign="top">
71 <td valign="top">
67 <ul>
72 <ul>
68 <li><a href="qpieseries.html">QPieSeries</a></li>
73 <li><a href="qpieseries.html">QPieSeries</a></li>
69 <li><a href="qpieslice.html">QPieSlice</a></li>
74 <li><a href="qpieslice.html">QPieSlice</a></li>
70 <li><a href="qhpiemodelmapper.html">QHPieModelMapper</a></li>
75 <li><a href="qhpiemodelmapper.html">QHPieModelMapper</a></li>
71 <li><a href="qvpiemodelmapper.html">QVPieModelMapper</a></li>
76 <li><a href="qvpiemodelmapper.html">QVPieModelMapper</a></li>
72 </ul>
77 </ul>
73 </td>
78 </td>
74 <td valign="top">
79 <td valign="top">
75 <ul>
80 <ul>
76 <li><a href="qbarseries.html">QBarSeries</a></li>
81 <li><a href="qbarseries.html">QBarSeries</a></li>
77 <li><a href="qbarset.html">QBarSet</a></li>
82 <li><a href="qbarset.html">QBarSet</a></li>
78 <li><a href="qpercentbarseries.html">QPercentBarSeries</a></li>
83 <li><a href="qpercentbarseries.html">QPercentBarSeries</a></li>
79 <li><a href="qstackedbarseries.html">QStackedBarSeries</a></li>
84 <li><a href="qstackedbarseries.html">QStackedBarSeries</a></li>
80 <li><a href="qhbarmodelmapper.html">QHBarModelMapper</a></li>
85 <li><a href="qhbarmodelmapper.html">QHBarModelMapper</a></li>
81 <li><a href="qvbarmodelmapper.html">QVBarModelMapper</a></li>
86 <li><a href="qvbarmodelmapper.html">QVBarModelMapper</a></li>
82 <li><a href="qhorizontalbarseries.html">QHorizontalBarSeries</a></li>
87 <li><a href="qhorizontalbarseries.html">QHorizontalBarSeries</a></li>
83 <li><a href="qhorizontalstackedbarseries.html">QHorizontalStackedBarSeries</a></li>
88 <li><a href="qhorizontalstackedbarseries.html">QHorizontalStackedBarSeries</a></li>
84 <li><a href="qhorizontalpercentbarseries.html">QHorizontalPercentBarSeries</a></li>
89 <li><a href="qhorizontalpercentbarseries.html">QHorizontalPercentBarSeries</a></li>
85 </ul>
90 </ul>
86 </td>
91 </td>
87 </tr>
92 </tr>
88 </table>
93 </table>
89 \endraw
94 \endraw
90
95
91 */
96 */
@@ -1,86 +1,110
1 /****************************************************************************
1 /****************************************************************************
2 **
2 **
3 ** Copyright (C) 2012 Digia Plc
3 ** Copyright (C) 2012 Digia Plc
4 ** All rights reserved.
4 ** All rights reserved.
5 ** For any questions to Digia, please use contact form at http://qt.digia.com
5 ** For any questions to Digia, please use contact form at http://qt.digia.com
6 **
6 **
7 ** This file is part of the Qt Commercial Charts Add-on.
7 ** This file is part of the Qt Commercial Charts Add-on.
8 **
8 **
9 ** $QT_BEGIN_LICENSE$
9 ** $QT_BEGIN_LICENSE$
10 ** Licensees holding valid Qt Commercial licenses may use this file in
10 ** Licensees holding valid Qt Commercial licenses may use this file in
11 ** accordance with the Qt Commercial License Agreement provided with the
11 ** accordance with the Qt Commercial License Agreement provided with the
12 ** Software or, alternatively, in accordance with the terms contained in
12 ** Software or, alternatively, in accordance with the terms contained in
13 ** a written agreement between you and Digia.
13 ** a written agreement between you and Digia.
14 **
14 **
15 ** If you have questions regarding the use of this file, please use
15 ** If you have questions regarding the use of this file, please use
16 ** contact form at http://qt.digia.com
16 ** contact form at http://qt.digia.com
17 ** $QT_END_LICENSE$
17 ** $QT_END_LICENSE$
18 **
18 **
19 ****************************************************************************/
19 ****************************************************************************/
20
20
21 #include "qarealegendmarker.h"
21 #include "qarealegendmarker.h"
22 #include "qarealegendmarker_p.h"
22 #include "qarealegendmarker_p.h"
23 #include "qareaseries_p.h"
23 #include "qareaseries_p.h"
24 #include <QAreaSeries>
24 #include <QAreaSeries>
25
25
26 QTCOMMERCIALCHART_BEGIN_NAMESPACE
26 QTCOMMERCIALCHART_BEGIN_NAMESPACE
27
27
28 /*!
29 \class QAreaLegendMarker
30 \brief QAreaLegendMarker object
31 \mainclass
32
33 QAreaLegendMarker is related to QAreaSeries. One QAreaSeries results in one marker.
34
35 \sa QLegend QAreaSeries
36 */
37
38 /*!
39 \fn virtual LegendMarkerType QAreaLegendMarker::type()
40 Returns QLegendMarker::LegendMarkerTypeArea
41 */
42
43 /*!
44 Constructor
45 */
28 QAreaLegendMarker::QAreaLegendMarker(QAreaSeries *series, QLegend *legend, QObject *parent) :
46 QAreaLegendMarker::QAreaLegendMarker(QAreaSeries *series, QLegend *legend, QObject *parent) :
29 QLegendMarker(*new QAreaLegendMarkerPrivate(this,series,legend), parent)
47 QLegendMarker(*new QAreaLegendMarkerPrivate(this,series,legend), parent)
30 {
48 {
31 }
49 }
32
50
51 /*!
52 Destructor
53 */
33 QAreaLegendMarker::~QAreaLegendMarker()
54 QAreaLegendMarker::~QAreaLegendMarker()
34 {
55 {
35 }
56 }
36
57
37 /*!
58 /*!
38 \internal
59 \internal
39 */
60 */
40 QAreaLegendMarker::QAreaLegendMarker(QAreaLegendMarkerPrivate &d, QObject *parent) :
61 QAreaLegendMarker::QAreaLegendMarker(QAreaLegendMarkerPrivate &d, QObject *parent) :
41 QLegendMarker(d, parent)
62 QLegendMarker(d, parent)
42 {
63 {
43 }
64 }
44
65
66 /*!
67 Returns related series of marker
68 */
45 QAreaSeries* QAreaLegendMarker::series()
69 QAreaSeries* QAreaLegendMarker::series()
46 {
70 {
47 Q_D(QAreaLegendMarker);
71 Q_D(QAreaLegendMarker);
48 return d->m_series;
72 return d->m_series;
49 }
73 }
50
74
51 ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
75 ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
52
76
53 QAreaLegendMarkerPrivate::QAreaLegendMarkerPrivate(QAreaLegendMarker *q, QAreaSeries *series, QLegend *legend) :
77 QAreaLegendMarkerPrivate::QAreaLegendMarkerPrivate(QAreaLegendMarker *q, QAreaSeries *series, QLegend *legend) :
54 QLegendMarkerPrivate(q,legend),
78 QLegendMarkerPrivate(q,legend),
55 m_series(series)
79 m_series(series)
56 {
80 {
57 QObject::connect(m_series->d_func(),SIGNAL(updated()), this, SLOT(updated()));
81 QObject::connect(m_series->d_func(),SIGNAL(updated()), this, SLOT(updated()));
58 QObject::connect(m_series, SIGNAL(nameChanged()), this, SLOT(updated()));
82 QObject::connect(m_series, SIGNAL(nameChanged()), this, SLOT(updated()));
59 updated();
83 updated();
60 }
84 }
61
85
62 QAreaLegendMarkerPrivate::~QAreaLegendMarkerPrivate()
86 QAreaLegendMarkerPrivate::~QAreaLegendMarkerPrivate()
63 {
87 {
64 }
88 }
65
89
66 QAreaSeries* QAreaLegendMarkerPrivate::series()
90 QAreaSeries* QAreaLegendMarkerPrivate::series()
67 {
91 {
68 return m_series;
92 return m_series;
69 }
93 }
70
94
71 QObject* QAreaLegendMarkerPrivate::relatedObject()
95 QObject* QAreaLegendMarkerPrivate::relatedObject()
72 {
96 {
73 return m_series;
97 return m_series;
74 }
98 }
75
99
76 void QAreaLegendMarkerPrivate::updated()
100 void QAreaLegendMarkerPrivate::updated()
77 {
101 {
78 m_item->setBrush(m_series->brush());
102 m_item->setBrush(m_series->brush());
79 m_item->setLabel(m_series->name());
103 m_item->setLabel(m_series->name());
80 invalidateLegend();
104 invalidateLegend();
81 }
105 }
82
106
83 #include "moc_qarealegendmarker.cpp"
107 #include "moc_qarealegendmarker.cpp"
84 #include "moc_qarealegendmarker_p.cpp"
108 #include "moc_qarealegendmarker_p.cpp"
85
109
86 QTCOMMERCIALCHART_END_NAMESPACE
110 QTCOMMERCIALCHART_END_NAMESPACE
@@ -1,96 +1,123
1 /****************************************************************************
1 /****************************************************************************
2 **
2 **
3 ** Copyright (C) 2012 Digia Plc
3 ** Copyright (C) 2012 Digia Plc
4 ** All rights reserved.
4 ** All rights reserved.
5 ** For any questions to Digia, please use contact form at http://qt.digia.com
5 ** For any questions to Digia, please use contact form at http://qt.digia.com
6 **
6 **
7 ** This file is part of the Qt Commercial Charts Add-on.
7 ** This file is part of the Qt Commercial Charts Add-on.
8 **
8 **
9 ** $QT_BEGIN_LICENSE$
9 ** $QT_BEGIN_LICENSE$
10 ** Licensees holding valid Qt Commercial licenses may use this file in
10 ** Licensees holding valid Qt Commercial licenses may use this file in
11 ** accordance with the Qt Commercial License Agreement provided with the
11 ** accordance with the Qt Commercial License Agreement provided with the
12 ** Software or, alternatively, in accordance with the terms contained in
12 ** Software or, alternatively, in accordance with the terms contained in
13 ** a written agreement between you and Digia.
13 ** a written agreement between you and Digia.
14 **
14 **
15 ** If you have questions regarding the use of this file, please use
15 ** If you have questions regarding the use of this file, please use
16 ** contact form at http://qt.digia.com
16 ** contact form at http://qt.digia.com
17 ** $QT_END_LICENSE$
17 ** $QT_END_LICENSE$
18 **
18 **
19 ****************************************************************************/
19 ****************************************************************************/
20
20
21 #include "qbarlegendmarker.h"
21 #include "qbarlegendmarker.h"
22 #include "qbarlegendmarker_p.h"
22 #include "qbarlegendmarker_p.h"
23 #include <QAbstractBarSeries>
23 #include <QAbstractBarSeries>
24 #include <QBarSet>
24 #include <QBarSet>
25
25
26 QTCOMMERCIALCHART_BEGIN_NAMESPACE
26 QTCOMMERCIALCHART_BEGIN_NAMESPACE
27
27
28 /*!
29 \class QBarLegendMarker
30 \brief QBarLegendMarker object
31 \mainclass
32
33 QBarLegendMarker is related to QAbstractBarSeries derived classes. With bar series, each marker is related to one QBarSet.
34
35 \sa QLegend QAbstractBarSeries QBarSet
36 */
37
38 /*!
39 \fn virtual LegendMarkerType QBarLegendMarker::type()
40 Returns QLegendMarker::LegendMarkerTypeBar
41 */
42
43 /*!
44 Constructor
45 */
28 QBarLegendMarker::QBarLegendMarker(QAbstractBarSeries *series, QBarSet *barset, QLegend *legend, QObject *parent) :
46 QBarLegendMarker::QBarLegendMarker(QAbstractBarSeries *series, QBarSet *barset, QLegend *legend, QObject *parent) :
29 QLegendMarker(*new QBarLegendMarkerPrivate(this,series,barset,legend), parent)
47 QLegendMarker(*new QBarLegendMarkerPrivate(this,series,barset,legend), parent)
30 {
48 {
31 }
49 }
32
50
51 /*!
52 Desturctor
53 */
33 QBarLegendMarker::~QBarLegendMarker()
54 QBarLegendMarker::~QBarLegendMarker()
34 {
55 {
35 }
56 }
36
57
37 /*!
58 /*!
38 \internal
59 \internal
39 */
60 */
40 QBarLegendMarker::QBarLegendMarker(QBarLegendMarkerPrivate &d, QObject *parent) :
61 QBarLegendMarker::QBarLegendMarker(QBarLegendMarkerPrivate &d, QObject *parent) :
41 QLegendMarker(d, parent)
62 QLegendMarker(d, parent)
42 {
63 {
43 }
64 }
44
65
66 /*!
67 Returns the related series of marker
68 */
45 QAbstractBarSeries *QBarLegendMarker::series()
69 QAbstractBarSeries *QBarLegendMarker::series()
46 {
70 {
47 Q_D(QBarLegendMarker);
71 Q_D(QBarLegendMarker);
48 return d->m_series;
72 return d->m_series;
49 }
73 }
50
74
75 /*!
76 Returns the related barset of marker
77 */
51 QBarSet* QBarLegendMarker::barset()
78 QBarSet* QBarLegendMarker::barset()
52 {
79 {
53 Q_D(QBarLegendMarker);
80 Q_D(QBarLegendMarker);
54 return d->m_barset;
81 return d->m_barset;
55 }
82 }
56
83
57 ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
84 ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
58
85
59 QBarLegendMarkerPrivate::QBarLegendMarkerPrivate(QBarLegendMarker *q, QAbstractBarSeries *series, QBarSet *barset, QLegend *legend) :
86 QBarLegendMarkerPrivate::QBarLegendMarkerPrivate(QBarLegendMarker *q, QAbstractBarSeries *series, QBarSet *barset, QLegend *legend) :
60 QLegendMarkerPrivate(q,legend),
87 QLegendMarkerPrivate(q,legend),
61 m_series(series),
88 m_series(series),
62 m_barset(barset)
89 m_barset(barset)
63 {
90 {
64 QObject::connect(m_barset, SIGNAL(penChanged()), this, SLOT(updated()));
91 QObject::connect(m_barset, SIGNAL(penChanged()), this, SLOT(updated()));
65 QObject::connect(m_barset, SIGNAL(labelChanged()), this, SLOT(updated()));
92 QObject::connect(m_barset, SIGNAL(labelChanged()), this, SLOT(updated()));
66 QObject::connect(m_barset, SIGNAL(brushChanged()), this, SLOT(updated()));
93 QObject::connect(m_barset, SIGNAL(brushChanged()), this, SLOT(updated()));
67 updated();
94 updated();
68 }
95 }
69
96
70 QBarLegendMarkerPrivate::~QBarLegendMarkerPrivate()
97 QBarLegendMarkerPrivate::~QBarLegendMarkerPrivate()
71 {
98 {
72 }
99 }
73
100
74 QAbstractBarSeries* QBarLegendMarkerPrivate::series()
101 QAbstractBarSeries* QBarLegendMarkerPrivate::series()
75 {
102 {
76 return m_series;
103 return m_series;
77 }
104 }
78
105
79 QObject* QBarLegendMarkerPrivate::relatedObject()
106 QObject* QBarLegendMarkerPrivate::relatedObject()
80 {
107 {
81 return m_barset;
108 return m_barset;
82 }
109 }
83
110
84 void QBarLegendMarkerPrivate::updated()
111 void QBarLegendMarkerPrivate::updated()
85 {
112 {
86 m_item->setPen(m_barset->pen());
113 m_item->setPen(m_barset->pen());
87 m_item->setBrush(m_barset->brush());
114 m_item->setBrush(m_barset->brush());
88 m_item->setLabel(m_barset->label());
115 m_item->setLabel(m_barset->label());
89 invalidateLegend();
116 invalidateLegend();
90 }
117 }
91
118
92 #include "moc_qbarlegendmarker.cpp"
119 #include "moc_qbarlegendmarker.cpp"
93 #include "moc_qbarlegendmarker_p.cpp"
120 #include "moc_qbarlegendmarker_p.cpp"
94
121
95 QTCOMMERCIALCHART_END_NAMESPACE
122 QTCOMMERCIALCHART_END_NAMESPACE
96
123
@@ -1,589 +1,593
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 "chartpresenter_p.h"
27 #include "chartpresenter_p.h"
28 #include "chartlayout_p.h"
28 #include "chartlayout_p.h"
29 #include "qlegendmarker.h"
29 #include "qlegendmarker.h"
30 #include "qlegendmarker_p.h"
30 #include "qlegendmarker_p.h"
31 #include "legendmarkeritem_p.h"
31 #include "legendmarkeritem_p.h"
32 #include <QPainter>
32 #include <QPainter>
33 #include <QPen>
33 #include <QPen>
34 #include <QGraphicsItemGroup>
34 #include <QGraphicsItemGroup>
35
35
36 QTCOMMERCIALCHART_BEGIN_NAMESPACE
36 QTCOMMERCIALCHART_BEGIN_NAMESPACE
37
37
38 /*!
38 /*!
39 \class QLegend
39 \class QLegend
40 \brief Legend object
40 \brief Legend object
41 \mainclass
41 \mainclass
42
42
43 QLegend is a graphical object, whics displays legend of the chart. Legend state is updated by QChart, when
43 QLegend is a graphical object, whics displays legend of the chart. Legend state is updated by QChart, when
44 series have been changed. By default, legend is drawn by QChart, but user can set a new parent to legend and
44 series have been changed. By default, legend is drawn by QChart, but user can set a new parent to legend and
45 handle the drawing manually.
45 handle the drawing manually.
46 User isn't supposed to create or delete legend objects, but can reference it via QChart class.
46 User isn't supposed to create or delete legend objects, but can reference it via QChart class.
47
47
48 \image examples_percentbarchart_legend.png
48 \image examples_percentbarchart_legend.png
49
49
50 \sa QChart
50 \sa QChart
51 */
51 */
52 /*!
52 /*!
53 \qmlclass Legend QLegend
53 \qmlclass Legend QLegend
54 \brief Legend is part of QtCommercial Chart QML API.
54 \brief Legend is part of QtCommercial Chart QML API.
55
55
56 Legend is a graphical object, whics displays legend of the chart. Legend state is updated by ChartView, when
56 Legend is a graphical object, whics displays legend of the chart. Legend state is updated by ChartView, when
57 series have been changed. Legend is used via ChartView class. For example:
57 series have been changed. Legend is used via ChartView class. For example:
58 \code
58 \code
59 ChartView {
59 ChartView {
60 legend.visible: true
60 legend.visible: true
61 legend.alignment: Qt.AlignBottom
61 legend.alignment: Qt.AlignBottom
62 // Add a few series...
62 // Add a few series...
63 }
63 }
64 \endcode
64 \endcode
65
65
66 \image examples_percentbarchart_legend.png
66 \image examples_percentbarchart_legend.png
67 */
67 */
68
68
69 /*!
69 /*!
70 \property QLegend::alignment
70 \property QLegend::alignment
71 \brief The alignment of the legend.
71 \brief The alignment of the legend.
72
72
73 Legend paints on the defined position in the chart. The following alignments are supported:
73 Legend paints on the defined position in the chart. The following alignments are supported:
74 Qt::AlignTop, Qt::AlignBottom, Qt::AlignLeft, Qt::AlignRight. If you set more than one flag the result is undefined.
74 Qt::AlignTop, Qt::AlignBottom, Qt::AlignLeft, Qt::AlignRight. If you set more than one flag the result is undefined.
75 */
75 */
76 /*!
76 /*!
77 \qmlproperty Qt.Alignment Legend::alignment
77 \qmlproperty Qt.Alignment Legend::alignment
78 \brief The alignment of the legend.
78 \brief The alignment of the legend.
79
79
80 Legend paints on the defined position in the chart. The following alignments are supported:
80 Legend paints on the defined position in the chart. The following alignments are supported:
81 Qt.AlignTop, Qt.AlignBottom, Qt.AlignLeft, Qt.AlignRight. If you set more than one flag the result is undefined.
81 Qt.AlignTop, Qt.AlignBottom, Qt.AlignLeft, Qt.AlignRight. If you set more than one flag the result is undefined.
82 */
82 */
83
83
84 /*!
84 /*!
85 \property QLegend::backgroundVisible
85 \property QLegend::backgroundVisible
86 Whether the legend background is visible or not.
86 Whether the legend background is visible or not.
87 */
87 */
88 /*!
88 /*!
89 \qmlproperty bool Legend::backgroundVisible
89 \qmlproperty bool Legend::backgroundVisible
90 Whether the legend background is visible or not.
90 Whether the legend background is visible or not.
91 */
91 */
92
92
93 /*!
93 /*!
94 \property QLegend::color
94 \property QLegend::color
95 The color of the legend, i.e. the background (brush) color. Note that if you change the color
95 The color of the legend, i.e. the background (brush) color. Note that if you change the color
96 of the legend, the style of the legend brush is set to Qt::SolidPattern.
96 of the legend, the style of the legend brush is set to Qt::SolidPattern.
97 */
97 */
98 /*!
98 /*!
99 \qmlproperty color Legend::color
99 \qmlproperty color Legend::color
100 The color of the legend, i.e. the background (brush) color.
100 The color of the legend, i.e. the background (brush) color.
101 */
101 */
102
102
103 /*!
103 /*!
104 \property QLegend::borderColor
104 \property QLegend::borderColor
105 The border color of the legend, i.e. the line color.
105 The border color of the legend, i.e. the line color.
106 */
106 */
107 /*!
107 /*!
108 \qmlproperty color Legend::borderColor
108 \qmlproperty color Legend::borderColor
109 The border color of the legend, i.e. the line color.
109 The border color of the legend, i.e. the line color.
110 */
110 */
111
111
112 /*!
112 /*!
113 \property QLegend::font
113 \property QLegend::font
114 The font of markers used by legend
114 The font of markers used by legend
115 */
115 */
116 /*!
116 /*!
117 \qmlproperty Font Legend::font
117 \qmlproperty Font Legend::font
118 The font of markers used by legend
118 The font of markers used by legend
119 */
119 */
120
120
121 /*!
121 /*!
122 \property QLegend::labelColor
122 \property QLegend::labelColor
123 The color of brush used to draw labels.
123 The color of brush used to draw labels.
124 */
124 */
125 /*!
125 /*!
126 \qmlproperty color QLegend::labelColor
126 \qmlproperty color QLegend::labelColor
127 The color of brush used to draw labels.
127 The color of brush used to draw labels.
128 */
128 */
129
129
130 /*!
130 /*!
131 \fn void QLegend::backgroundVisibleChanged(bool)
131 \fn void QLegend::backgroundVisibleChanged(bool)
132 The visibility of the legend background changed to \a visible.
132 The visibility of the legend background changed to \a visible.
133 */
133 */
134
134
135 /*!
135 /*!
136 \fn void QLegend::colorChanged(QColor)
136 \fn void QLegend::colorChanged(QColor)
137 The color of the legend background changed to \a color.
137 The color of the legend background changed to \a color.
138 */
138 */
139
139
140 /*!
140 /*!
141 \fn void QLegend::borderColorChanged(QColor)
141 \fn void QLegend::borderColorChanged(QColor)
142 The border color of the legend background changed to \a color.
142 The border color of the legend background changed to \a color.
143 */
143 */
144
144
145 /*!
145 /*!
146 \fn void QLegend::fontChanged(QFont)
146 \fn void QLegend::fontChanged(QFont)
147 The font of markers of the legend changed to \a font.
147 The font of markers of the legend changed to \a font.
148 */
148 */
149
149
150 /*!
150 /*!
151 \fn void QLegend::labelColorChanged(QColor color)
151 \fn void QLegend::labelColorChanged(QColor color)
152 This signal is emitted when the color of brush used to draw labels has changed to \a color.
152 This signal is emitted when the color of brush used to draw labels has changed to \a color.
153 */
153 */
154
154
155 /*!
155 /*!
156 Constructs the legend object and sets the parent to \a parent
156 Constructs the legend object and sets the parent to \a parent
157 */
157 */
158
158
159 QLegend::QLegend(QChart *chart): QGraphicsWidget(chart),
159 QLegend::QLegend(QChart *chart): QGraphicsWidget(chart),
160 d_ptr(new QLegendPrivate(chart->d_ptr->m_presenter, chart, this))
160 d_ptr(new QLegendPrivate(chart->d_ptr->m_presenter, chart, this))
161 {
161 {
162 setZValue(ChartPresenter::LegendZValue);
162 setZValue(ChartPresenter::LegendZValue);
163 setFlags(QGraphicsItem::ItemClipsChildrenToShape);
163 setFlags(QGraphicsItem::ItemClipsChildrenToShape);
164 QObject::connect(chart->d_ptr->m_dataset, SIGNAL(seriesAdded(QAbstractSeries*,Domain*)), d_ptr.data(), SLOT(handleSeriesAdded(QAbstractSeries*)));
164 QObject::connect(chart->d_ptr->m_dataset, SIGNAL(seriesAdded(QAbstractSeries*,Domain*)), d_ptr.data(), SLOT(handleSeriesAdded(QAbstractSeries*)));
165 QObject::connect(chart->d_ptr->m_dataset, SIGNAL(seriesRemoved(QAbstractSeries*)), d_ptr.data(), SLOT(handleSeriesRemoved(QAbstractSeries*)));
165 QObject::connect(chart->d_ptr->m_dataset, SIGNAL(seriesRemoved(QAbstractSeries*)), d_ptr.data(), SLOT(handleSeriesRemoved(QAbstractSeries*)));
166 setLayout(d_ptr->m_layout);
166 setLayout(d_ptr->m_layout);
167 }
167 }
168
168
169 /*!
169 /*!
170 Destroys the legend object. Legend is always owned by a QChart, so an application should never call this.
170 Destroys the legend object. Legend is always owned by a QChart, so an application should never call this.
171 */
171 */
172 QLegend::~QLegend()
172 QLegend::~QLegend()
173 {
173 {
174 }
174 }
175
175
176 /*!
176 /*!
177 \internal
177 \internal
178 */
178 */
179 void QLegend::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget)
179 void QLegend::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget)
180 {
180 {
181 Q_UNUSED(option)
181 Q_UNUSED(option)
182 Q_UNUSED(widget)
182 Q_UNUSED(widget)
183
183
184 if (!d_ptr->m_backgroundVisible)
184 if (!d_ptr->m_backgroundVisible)
185 return;
185 return;
186
186
187 painter->setOpacity(opacity());
187 painter->setOpacity(opacity());
188 painter->setPen(d_ptr->m_pen);
188 painter->setPen(d_ptr->m_pen);
189 painter->setBrush(d_ptr->m_brush);
189 painter->setBrush(d_ptr->m_brush);
190 painter->drawRoundRect(rect(), d_ptr->roundness(rect().width()), d_ptr->roundness(rect().height()));
190 painter->drawRoundRect(rect(), d_ptr->roundness(rect().width()), d_ptr->roundness(rect().height()));
191 }
191 }
192
192
193
193
194 /*!
194 /*!
195 Sets the \a brush of legend. Brush affects the background of legend.
195 Sets the \a brush of legend. Brush affects the background of legend.
196 */
196 */
197 void QLegend::setBrush(const QBrush &brush)
197 void QLegend::setBrush(const QBrush &brush)
198 {
198 {
199 if (d_ptr->m_brush != brush) {
199 if (d_ptr->m_brush != brush) {
200 d_ptr->m_brush = brush;
200 d_ptr->m_brush = brush;
201 update();
201 update();
202 emit colorChanged(brush.color());
202 emit colorChanged(brush.color());
203 }
203 }
204 }
204 }
205
205
206 /*!
206 /*!
207 Returns the brush used by legend.
207 Returns the brush used by legend.
208 */
208 */
209 QBrush QLegend::brush() const
209 QBrush QLegend::brush() const
210 {
210 {
211 return d_ptr->m_brush;
211 return d_ptr->m_brush;
212 }
212 }
213
213
214 void QLegend::setColor(QColor color)
214 void QLegend::setColor(QColor color)
215 {
215 {
216 QBrush b = d_ptr->m_brush;
216 QBrush b = d_ptr->m_brush;
217 if (b.style() != Qt::SolidPattern || b.color() != color) {
217 if (b.style() != Qt::SolidPattern || b.color() != color) {
218 b.setStyle(Qt::SolidPattern);
218 b.setStyle(Qt::SolidPattern);
219 b.setColor(color);
219 b.setColor(color);
220 setBrush(b);
220 setBrush(b);
221 }
221 }
222 }
222 }
223
223
224 QColor QLegend::color()
224 QColor QLegend::color()
225 {
225 {
226 return d_ptr->m_brush.color();
226 return d_ptr->m_brush.color();
227 }
227 }
228
228
229 /*!
229 /*!
230 Sets the \a pen of legend. Pen affects the legend borders.
230 Sets the \a pen of legend. Pen affects the legend borders.
231 */
231 */
232 void QLegend::setPen(const QPen &pen)
232 void QLegend::setPen(const QPen &pen)
233 {
233 {
234 if (d_ptr->m_pen != pen) {
234 if (d_ptr->m_pen != pen) {
235 d_ptr->m_pen = pen;
235 d_ptr->m_pen = pen;
236 update();
236 update();
237 emit borderColorChanged(pen.color());
237 emit borderColorChanged(pen.color());
238 }
238 }
239 }
239 }
240
240
241 /*!
241 /*!
242 Returns the pen used by legend
242 Returns the pen used by legend
243 */
243 */
244
244
245 QPen QLegend::pen() const
245 QPen QLegend::pen() const
246 {
246 {
247 return d_ptr->m_pen;
247 return d_ptr->m_pen;
248 }
248 }
249
249
250 void QLegend::setFont(const QFont &font)
250 void QLegend::setFont(const QFont &font)
251 {
251 {
252 if (d_ptr->m_font != font)
252 if (d_ptr->m_font != font)
253 d_ptr->m_font = font;
253 d_ptr->m_font = font;
254
254
255 foreach (QLegendMarker *marker, d_ptr->markers()) {
255 foreach (QLegendMarker *marker, d_ptr->markers()) {
256 marker->setFont(d_ptr->m_font);
256 marker->setFont(d_ptr->m_font);
257 }
257 }
258 layout()->invalidate();
258 layout()->invalidate();
259 emit fontChanged(font);
259 emit fontChanged(font);
260 }
260 }
261
261
262 QFont QLegend::font() const
262 QFont QLegend::font() const
263 {
263 {
264 return d_ptr->m_font;
264 return d_ptr->m_font;
265 }
265 }
266
266
267 void QLegend::setBorderColor(QColor color)
267 void QLegend::setBorderColor(QColor color)
268 {
268 {
269 QPen p = d_ptr->m_pen;
269 QPen p = d_ptr->m_pen;
270 if (p.color() != color) {
270 if (p.color() != color) {
271 p.setColor(color);
271 p.setColor(color);
272 setPen(p);
272 setPen(p);
273 }
273 }
274 }
274 }
275
275
276 QColor QLegend::borderColor()
276 QColor QLegend::borderColor()
277 {
277 {
278 return d_ptr->m_pen.color();
278 return d_ptr->m_pen.color();
279 }
279 }
280
280
281 /*!
281 /*!
282 Set brush used to draw labels to \a brush.
282 Set brush used to draw labels to \a brush.
283 */
283 */
284 void QLegend::setLabelBrush(const QBrush &brush)
284 void QLegend::setLabelBrush(const QBrush &brush)
285 {
285 {
286 if (d_ptr->m_labelBrush != brush) {
286 if (d_ptr->m_labelBrush != brush) {
287 d_ptr->m_labelBrush = brush;
287 d_ptr->m_labelBrush = brush;
288 foreach (QLegendMarker *marker, d_ptr->markers()) {
288 foreach (QLegendMarker *marker, d_ptr->markers()) {
289 marker->setLabelBrush(d_ptr->m_labelBrush);
289 marker->setLabelBrush(d_ptr->m_labelBrush);
290 // Note: The pen of the marker rectangle could be exposed in the public QLegend API
290 // Note: The pen of the marker rectangle could be exposed in the public QLegend API
291 // instead of mapping it from label brush color
291 // instead of mapping it from label brush color
292 marker->setPen(brush.color());
292 marker->setPen(brush.color());
293 }
293 }
294 emit labelColorChanged(brush.color());
294 emit labelColorChanged(brush.color());
295 }
295 }
296 }
296 }
297
297
298 /*!
298 /*!
299 Brush used to draw labels.
299 Brush used to draw labels.
300 */
300 */
301 QBrush QLegend::labelBrush() const
301 QBrush QLegend::labelBrush() const
302 {
302 {
303 return d_ptr->m_labelBrush;
303 return d_ptr->m_labelBrush;
304 }
304 }
305
305
306 void QLegend::setLabelColor(QColor color)
306 void QLegend::setLabelColor(QColor color)
307 {
307 {
308 QBrush b = d_ptr->m_labelBrush;
308 QBrush b = d_ptr->m_labelBrush;
309 if (b.style() != Qt::SolidPattern || b.color() != color) {
309 if (b.style() != Qt::SolidPattern || b.color() != color) {
310 b.setStyle(Qt::SolidPattern);
310 b.setStyle(Qt::SolidPattern);
311 b.setColor(color);
311 b.setColor(color);
312 setLabelBrush(b);
312 setLabelBrush(b);
313 }
313 }
314 }
314 }
315
315
316 QColor QLegend::labelColor() const
316 QColor QLegend::labelColor() const
317 {
317 {
318 return d_ptr->m_labelBrush.color();
318 return d_ptr->m_labelBrush.color();
319 }
319 }
320
320
321
321
322 void QLegend::setAlignment(Qt::Alignment alignment)
322 void QLegend::setAlignment(Qt::Alignment alignment)
323 {
323 {
324 if (d_ptr->m_alignment != alignment) {
324 if (d_ptr->m_alignment != alignment) {
325 d_ptr->m_alignment = alignment;
325 d_ptr->m_alignment = alignment;
326 layout()->invalidate();
326 layout()->invalidate();
327 }
327 }
328 }
328 }
329
329
330 Qt::Alignment QLegend::alignment() const
330 Qt::Alignment QLegend::alignment() const
331 {
331 {
332 return d_ptr->m_alignment;
332 return d_ptr->m_alignment;
333 }
333 }
334
334
335 /*!
335 /*!
336 Detaches the legend from chart. Chart won't change layout of the legend.
336 Detaches the legend from chart. Chart won't change layout of the legend.
337 */
337 */
338 void QLegend::detachFromChart()
338 void QLegend::detachFromChart()
339 {
339 {
340 d_ptr->m_attachedToChart = false;
340 d_ptr->m_attachedToChart = false;
341 layout()->invalidate();
341 layout()->invalidate();
342 setParent(0);
342 setParent(0);
343
343
344 }
344 }
345
345
346 /*!
346 /*!
347 Attaches the legend to chart. Chart may change layout of the legend.
347 Attaches the legend to chart. Chart may change layout of the legend.
348 */
348 */
349 void QLegend::attachToChart()
349 void QLegend::attachToChart()
350 {
350 {
351 d_ptr->m_attachedToChart = true;
351 d_ptr->m_attachedToChart = true;
352 layout()->invalidate();
352 layout()->invalidate();
353 setParent(d_ptr->m_chart);
353 setParent(d_ptr->m_chart);
354 }
354 }
355
355
356 /*!
356 /*!
357 Returns true, if legend is attached to chart.
357 Returns true, if legend is attached to chart.
358 */
358 */
359 bool QLegend::isAttachedToChart()
359 bool QLegend::isAttachedToChart()
360 {
360 {
361 return d_ptr->m_attachedToChart;
361 return d_ptr->m_attachedToChart;
362 }
362 }
363
363
364 /*!
364 /*!
365 Sets the visibility of legend background to \a visible
365 Sets the visibility of legend background to \a visible
366 */
366 */
367 void QLegend::setBackgroundVisible(bool visible)
367 void QLegend::setBackgroundVisible(bool visible)
368 {
368 {
369 if (d_ptr->m_backgroundVisible != visible) {
369 if (d_ptr->m_backgroundVisible != visible) {
370 d_ptr->m_backgroundVisible = visible;
370 d_ptr->m_backgroundVisible = visible;
371 update();
371 update();
372 emit backgroundVisibleChanged(visible);
372 emit backgroundVisibleChanged(visible);
373 }
373 }
374 }
374 }
375
375
376 /*!
376 /*!
377 Returns the visibility of legend background
377 Returns the visibility of legend background
378 */
378 */
379 bool QLegend::isBackgroundVisible() const
379 bool QLegend::isBackgroundVisible() const
380 {
380 {
381 return d_ptr->m_backgroundVisible;
381 return d_ptr->m_backgroundVisible;
382 }
382 }
383
383
384 /*!
385 Returns the list of markers in legend. The list can be filtered with \a series parameter.
386 If \a series is given, only markers related to that series are returned.
387 */
384 QList<QLegendMarker*> QLegend::markers(QAbstractSeries *series) const
388 QList<QLegendMarker*> QLegend::markers(QAbstractSeries *series) const
385 {
389 {
386 return d_ptr->markers(series);
390 return d_ptr->markers(series);
387 }
391 }
388
392
389 /*!
393 /*!
390 \internal \a event see QGraphicsWidget for details
394 \internal \a event see QGraphicsWidget for details
391 */
395 */
392 void QLegend::hideEvent(QHideEvent *event)
396 void QLegend::hideEvent(QHideEvent *event)
393 {
397 {
394 if (isAttachedToChart())
398 if (isAttachedToChart())
395 d_ptr->m_presenter->layout()->invalidate();
399 d_ptr->m_presenter->layout()->invalidate();
396 QGraphicsWidget::hideEvent(event);
400 QGraphicsWidget::hideEvent(event);
397 }
401 }
398 /*!
402 /*!
399 \internal \a event see QGraphicsWidget for details
403 \internal \a event see QGraphicsWidget for details
400 */
404 */
401 void QLegend::showEvent(QShowEvent *event)
405 void QLegend::showEvent(QShowEvent *event)
402 {
406 {
403 if (isAttachedToChart()) {
407 if (isAttachedToChart()) {
404 d_ptr->items()->setVisible(false);
408 d_ptr->items()->setVisible(false);
405 layout()->invalidate();
409 layout()->invalidate();
406 }
410 }
407 QGraphicsWidget::showEvent(event);
411 QGraphicsWidget::showEvent(event);
408 //layout activation will show the items
412 //layout activation will show the items
409 }
413 }
410
414
411 ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
415 ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
412
416
413 QLegendPrivate::QLegendPrivate(ChartPresenter *presenter, QChart *chart, QLegend *q)
417 QLegendPrivate::QLegendPrivate(ChartPresenter *presenter, QChart *chart, QLegend *q)
414 : q_ptr(q),
418 : q_ptr(q),
415 m_presenter(presenter),
419 m_presenter(presenter),
416 m_layout(new LegendLayout(q)),
420 m_layout(new LegendLayout(q)),
417 m_chart(chart),
421 m_chart(chart),
418 m_items(new QGraphicsItemGroup(q)),
422 m_items(new QGraphicsItemGroup(q)),
419 m_alignment(Qt::AlignTop),
423 m_alignment(Qt::AlignTop),
420 m_brush(QBrush()),
424 m_brush(QBrush()),
421 m_pen(QPen()),
425 m_pen(QPen()),
422 m_labelBrush(QBrush()),
426 m_labelBrush(QBrush()),
423 m_diameter(5),
427 m_diameter(5),
424 m_attachedToChart(true),
428 m_attachedToChart(true),
425 m_backgroundVisible(false)
429 m_backgroundVisible(false)
426 {
430 {
427 m_items->setHandlesChildEvents(false);
431 m_items->setHandlesChildEvents(false);
428 }
432 }
429
433
430 QLegendPrivate::~QLegendPrivate()
434 QLegendPrivate::~QLegendPrivate()
431 {
435 {
432
436
433 }
437 }
434
438
435 void QLegendPrivate::setOffset(const QPointF &offset)
439 void QLegendPrivate::setOffset(const QPointF &offset)
436 {
440 {
437 m_layout->setOffset(offset.x(), offset.y());
441 m_layout->setOffset(offset.x(), offset.y());
438 }
442 }
439
443
440 QPointF QLegendPrivate::offset() const
444 QPointF QLegendPrivate::offset() const
441 {
445 {
442 return m_layout->offset();
446 return m_layout->offset();
443 }
447 }
444
448
445 int QLegendPrivate::roundness(qreal size)
449 int QLegendPrivate::roundness(qreal size)
446 {
450 {
447 return 100 * m_diameter / int(size);
451 return 100 * m_diameter / int(size);
448 }
452 }
449
453
450 QList<QLegendMarker*> QLegendPrivate::markers(QAbstractSeries *series)
454 QList<QLegendMarker*> QLegendPrivate::markers(QAbstractSeries *series)
451 {
455 {
452 // Return all markers
456 // Return all markers
453 if (!series) {
457 if (!series) {
454 return m_markers;
458 return m_markers;
455 }
459 }
456
460
457 // Create filtered list
461 // Create filtered list
458 QList<QLegendMarker *> markers;
462 QList<QLegendMarker *> markers;
459 foreach (QLegendMarker *marker, m_markers) {
463 foreach (QLegendMarker *marker, m_markers) {
460 if (marker->series() == series) {
464 if (marker->series() == series) {
461 markers.append(marker);
465 markers.append(marker);
462 }
466 }
463 }
467 }
464 return markers;
468 return markers;
465 }
469 }
466
470
467 void QLegendPrivate::handleSeriesAdded(QAbstractSeries *series)
471 void QLegendPrivate::handleSeriesAdded(QAbstractSeries *series)
468 {
472 {
469 if (m_series.contains(series)) {
473 if (m_series.contains(series)) {
470 return;
474 return;
471 }
475 }
472
476
473 QList<QLegendMarker*> newMarkers = series->d_ptr->createLegendMarkers(q_ptr);
477 QList<QLegendMarker*> newMarkers = series->d_ptr->createLegendMarkers(q_ptr);
474 decorateMarkers(newMarkers);
478 decorateMarkers(newMarkers);
475 addMarkers(newMarkers);
479 addMarkers(newMarkers);
476
480
477 QObject::connect(series->d_ptr.data(), SIGNAL(countChanged()), this, SLOT(handleCountChanged()));
481 QObject::connect(series->d_ptr.data(), SIGNAL(countChanged()), this, SLOT(handleCountChanged()));
478 QObject::connect(series, SIGNAL(visibleChanged()), this, SLOT(handleSeriesVisibleChanged()));
482 QObject::connect(series, SIGNAL(visibleChanged()), this, SLOT(handleSeriesVisibleChanged()));
479
483
480 m_series.append(series);
484 m_series.append(series);
481 m_items->setVisible(false);
485 m_items->setVisible(false);
482 m_layout->invalidate();
486 m_layout->invalidate();
483 }
487 }
484
488
485 void QLegendPrivate::handleSeriesRemoved(QAbstractSeries *series)
489 void QLegendPrivate::handleSeriesRemoved(QAbstractSeries *series)
486 {
490 {
487 if (m_series.contains(series)) {
491 if (m_series.contains(series)) {
488 m_series.removeOne(series);
492 m_series.removeOne(series);
489 }
493 }
490
494
491 // Find out, which markers to remove
495 // Find out, which markers to remove
492 QList<QLegendMarker *> removed;
496 QList<QLegendMarker *> removed;
493 foreach (QLegendMarker *m, m_markers) {
497 foreach (QLegendMarker *m, m_markers) {
494 if (m->series() == series) {
498 if (m->series() == series) {
495 removed << m;
499 removed << m;
496 }
500 }
497 }
501 }
498 removeMarkers(removed);
502 removeMarkers(removed);
499
503
500 QObject::disconnect(series->d_ptr.data(), SIGNAL(countChanged()), this, SLOT(handleCountChanged()));
504 QObject::disconnect(series->d_ptr.data(), SIGNAL(countChanged()), this, SLOT(handleCountChanged()));
501 QObject::disconnect(series, SIGNAL(visibleChanged()), this, SLOT(handleSeriesVisibleChanged()));
505 QObject::disconnect(series, SIGNAL(visibleChanged()), this, SLOT(handleSeriesVisibleChanged()));
502
506
503 m_layout->invalidate();
507 m_layout->invalidate();
504 }
508 }
505
509
506 void QLegendPrivate::handleSeriesVisibleChanged()
510 void QLegendPrivate::handleSeriesVisibleChanged()
507 {
511 {
508 QAbstractSeries *series = qobject_cast<QAbstractSeries *> (sender());
512 QAbstractSeries *series = qobject_cast<QAbstractSeries *> (sender());
509 Q_ASSERT(series);
513 Q_ASSERT(series);
510
514
511 foreach (QLegendMarker *marker, m_markers) {
515 foreach (QLegendMarker *marker, m_markers) {
512 if (marker->series() == series) {
516 if (marker->series() == series) {
513 marker->setVisible(series->isVisible());
517 marker->setVisible(series->isVisible());
514 }
518 }
515 }
519 }
516 m_layout->invalidate();
520 m_layout->invalidate();
517 }
521 }
518
522
519 void QLegendPrivate::handleCountChanged()
523 void QLegendPrivate::handleCountChanged()
520 {
524 {
521 // Here we handle the changes in marker count.
525 // Here we handle the changes in marker count.
522 // Can happen for example when pieslice(s) have been added to or removed from pieseries.
526 // Can happen for example when pieslice(s) have been added to or removed from pieseries.
523
527
524 QAbstractSeriesPrivate *series = qobject_cast<QAbstractSeriesPrivate *> (sender());
528 QAbstractSeriesPrivate *series = qobject_cast<QAbstractSeriesPrivate *> (sender());
525 QList<QLegendMarker *> createdMarkers = series->createLegendMarkers(q_ptr);
529 QList<QLegendMarker *> createdMarkers = series->createLegendMarkers(q_ptr);
526
530
527 // Find out removed markers and created markers
531 // Find out removed markers and created markers
528 QList<QLegendMarker *> removedMarkers;
532 QList<QLegendMarker *> removedMarkers;
529 foreach (QLegendMarker *oldMarker, m_markers) {
533 foreach (QLegendMarker *oldMarker, m_markers) {
530 // we have marker, which is related to sender.
534 // we have marker, which is related to sender.
531 if (oldMarker->series() == series->q_ptr) {
535 if (oldMarker->series() == series->q_ptr) {
532 bool found = false;
536 bool found = false;
533 foreach(QLegendMarker *newMarker, createdMarkers) {
537 foreach(QLegendMarker *newMarker, createdMarkers) {
534 // New marker considered existing if:
538 // New marker considered existing if:
535 // - d_ptr->relatedObject() is same for both markers.
539 // - d_ptr->relatedObject() is same for both markers.
536 if (newMarker->d_ptr->relatedObject() == oldMarker->d_ptr->relatedObject()) {
540 if (newMarker->d_ptr->relatedObject() == oldMarker->d_ptr->relatedObject()) {
537 // Delete the new marker, since we already have existing marker, that might be connected on user side.
541 // Delete the new marker, since we already have existing marker, that might be connected on user side.
538 found = true;
542 found = true;
539 createdMarkers.removeOne(newMarker);
543 createdMarkers.removeOne(newMarker);
540 delete newMarker;
544 delete newMarker;
541 }
545 }
542 }
546 }
543 if (!found) {
547 if (!found) {
544 // No related object found for marker, add to removedMarkers list
548 // No related object found for marker, add to removedMarkers list
545 removedMarkers << oldMarker;
549 removedMarkers << oldMarker;
546 }
550 }
547 }
551 }
548 }
552 }
549
553
550 removeMarkers(removedMarkers);
554 removeMarkers(removedMarkers);
551 decorateMarkers(createdMarkers);
555 decorateMarkers(createdMarkers);
552 addMarkers(createdMarkers);
556 addMarkers(createdMarkers);
553
557
554 q_ptr->layout()->invalidate();
558 q_ptr->layout()->invalidate();
555 }
559 }
556
560
557 void QLegendPrivate::addMarkers(QList<QLegendMarker *> markers)
561 void QLegendPrivate::addMarkers(QList<QLegendMarker *> markers)
558 {
562 {
559 foreach (QLegendMarker *marker, markers) {
563 foreach (QLegendMarker *marker, markers) {
560 m_items->addToGroup(marker->d_ptr.data()->item());
564 m_items->addToGroup(marker->d_ptr.data()->item());
561 m_markers << marker;
565 m_markers << marker;
562 m_markerHash.insert(marker->d_ptr->item(), marker);
566 m_markerHash.insert(marker->d_ptr->item(), marker);
563 }
567 }
564 }
568 }
565
569
566 void QLegendPrivate::removeMarkers(QList<QLegendMarker *> markers)
570 void QLegendPrivate::removeMarkers(QList<QLegendMarker *> markers)
567 {
571 {
568 foreach (QLegendMarker *marker, markers) {
572 foreach (QLegendMarker *marker, markers) {
569 marker->d_ptr->item()->setVisible(false);
573 marker->d_ptr->item()->setVisible(false);
570 m_items->removeFromGroup(marker->d_ptr->item());
574 m_items->removeFromGroup(marker->d_ptr->item());
571 m_markers.removeOne(marker);
575 m_markers.removeOne(marker);
572 m_markerHash.remove(marker->d_ptr->item());
576 m_markerHash.remove(marker->d_ptr->item());
573 delete marker;
577 delete marker;
574 }
578 }
575 }
579 }
576
580
577 void QLegendPrivate::decorateMarkers(QList<QLegendMarker *> markers)
581 void QLegendPrivate::decorateMarkers(QList<QLegendMarker *> markers)
578 {
582 {
579 foreach (QLegendMarker *marker, markers) {
583 foreach (QLegendMarker *marker, markers) {
580 marker->setFont(m_font);
584 marker->setFont(m_font);
581 marker->setLabelBrush(m_labelBrush);
585 marker->setLabelBrush(m_labelBrush);
582 }
586 }
583 }
587 }
584
588
585
589
586 #include "moc_qlegend.cpp"
590 #include "moc_qlegend.cpp"
587 #include "moc_qlegend_p.cpp"
591 #include "moc_qlegend_p.cpp"
588
592
589 QTCOMMERCIALCHART_END_NAMESPACE
593 QTCOMMERCIALCHART_END_NAMESPACE
@@ -1,127 +1,210
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 "qlegend_p.h"
25 #include "qlegend_p.h"
26 #include "legendlayout_p.h"
26 #include "legendlayout_p.h"
27 #include <QFontMetrics>
27 #include <QFontMetrics>
28 #include <QGraphicsSceneEvent>
28 #include <QGraphicsSceneEvent>
29 #include <QAbstractSeries>
29 #include <QAbstractSeries>
30
30
31 QTCOMMERCIALCHART_BEGIN_NAMESPACE
31 QTCOMMERCIALCHART_BEGIN_NAMESPACE
32
32
33 /*!
34 \class QLegendMarker
35 \brief LegendMarker object
36 \mainclass
37
38 QLegendMarker is abstract object that can be used to access markers inside QLegend. The QLegendMarker is always connected
39 to some series
40
41 \image examples_legendmarkers.png
42
43 \sa QLegend
44 */
45 /*!
46 \enum QLegendMarker::LegendMarkerType
47
48 The type of the legendmarker object.
49
50 \value LegendMarkerTypeArea
51 \value LegendMarkerTypeBar
52 \value LegendMarkerTypePie
53 \value LegendMarkerTypeXY
54 */
55
56 /*!
57 \fn virtual LegendMarkerType QLegendMarker::type() = 0;
58 Returns the type of legendmarker. Type depends of the related series. LegendMarkerTypeXY is used for all QXYSeries derived
59 classes.
60 */
61
62 /*!
63 \fn virtual QAbstractSeries* QLegendMarker::series() = 0;
64 Returns pointer to series, which is related to this marker. Marker is always related to some series.
65 */
66
67 /*!
68 \fn void QLegendMarker::clicked();
69 This signal is emitted, when marker is clicked with mouse.
70 */
71
72 /*!
73 \fn void QLegendMarker::hovered(bool status);
74 This signal is emitted, when mouse is hovered over marker. \a status is true, when mouse enters the marker
75 and false when it leaves the marker.
76 */
77
78 /*!
79 Constructor of marker
80 */
33 QLegendMarker::QLegendMarker(QLegendMarkerPrivate &d, QObject *parent) :
81 QLegendMarker::QLegendMarker(QLegendMarkerPrivate &d, QObject *parent) :
34 QObject(parent),
82 QObject(parent),
35 d_ptr(&d)
83 d_ptr(&d)
36 {
84 {
37 d_ptr->m_item->setVisible(d_ptr->series()->isVisible());
85 d_ptr->m_item->setVisible(d_ptr->series()->isVisible());
38 }
86 }
39
87
88 /*!
89 Destructor of marker
90 */
40 QLegendMarker::~QLegendMarker()
91 QLegendMarker::~QLegendMarker()
41 {
92 {
42 }
93 }
43
94
95 /*!
96 Returns the label of the marker.
97 */
44 QString QLegendMarker::label() const
98 QString QLegendMarker::label() const
45 {
99 {
46 return d_ptr->m_item->label();
100 return d_ptr->m_item->label();
47 }
101 }
48
102
103 /*!
104 Sets the \a label of marker. Note that changing name of series will also change label of its marker.
105 */
49 void QLegendMarker::setLabel(const QString &label)
106 void QLegendMarker::setLabel(const QString &label)
50 {
107 {
51 d_ptr->m_item->setLabel(label);
108 d_ptr->m_item->setLabel(label);
52 }
109 }
53
110 /*!
111 Returns the brush which is used to draw label.
112 */
54 QBrush QLegendMarker::labelBrush() const
113 QBrush QLegendMarker::labelBrush() const
55 {
114 {
56 return d_ptr->m_item->labelBrush();
115 return d_ptr->m_item->labelBrush();
57 }
116 }
58
117
118 /*!
119 Sets the \a brush of label
120 */
59 void QLegendMarker::setLabelBrush(const QBrush &brush)
121 void QLegendMarker::setLabelBrush(const QBrush &brush)
60 {
122 {
61 d_ptr->m_item->setLabelBrush(brush);
123 d_ptr->m_item->setLabelBrush(brush);
62 }
124 }
63
125
126 /*!
127 Retuns the font of label
128 */
64 QFont QLegendMarker::font() const
129 QFont QLegendMarker::font() const
65 {
130 {
66 return d_ptr->m_item->font();
131 return d_ptr->m_item->font();
67 }
132 }
68
133
134 /*!
135 Sets the \a font of label
136 */
69 void QLegendMarker::setFont(const QFont &font)
137 void QLegendMarker::setFont(const QFont &font)
70 {
138 {
71 d_ptr->m_item->setFont(font);
139 d_ptr->m_item->setFont(font);
72 }
140 }
73
141
142 /*!
143 Returns the pen of marker item
144 */
74 QPen QLegendMarker::pen() const
145 QPen QLegendMarker::pen() const
75 {
146 {
76 return d_ptr->m_item->pen();
147 return d_ptr->m_item->pen();
77 }
148 }
78
149
150 /*!
151 Sets the \a pen of marker item
152 */
79 void QLegendMarker::setPen(const QPen &pen)
153 void QLegendMarker::setPen(const QPen &pen)
80 {
154 {
81 d_ptr->m_item->setPen(pen);
155 d_ptr->m_item->setPen(pen);
82 }
156 }
83
157
158 /*!
159 Returns the brush of marker item
160 */
84 QBrush QLegendMarker::brush() const
161 QBrush QLegendMarker::brush() const
85 {
162 {
86 return d_ptr->m_item->brush();
163 return d_ptr->m_item->brush();
87 }
164 }
88
165
166 /*!
167 Sets the \a brush of marker item. Note that changing color of the series also changes this.
168 */
89 void QLegendMarker::setBrush(const QBrush &brush)
169 void QLegendMarker::setBrush(const QBrush &brush)
90 {
170 {
91 d_ptr->m_item->setBrush(brush);
171 d_ptr->m_item->setBrush(brush);
92 }
172 }
93
173
174 /*!
175 Returns visibility of the marker
176 */
94 bool QLegendMarker::isVisible() const
177 bool QLegendMarker::isVisible() const
95 {
178 {
96 return d_ptr->m_item->isVisible();
179 return d_ptr->m_item->isVisible();
97 }
180 }
98
181
182 /*!
183 Sets markers visibility to \a visible
184 */
99 void QLegendMarker::setVisible(bool visible)
185 void QLegendMarker::setVisible(bool visible)
100 {
186 {
101 d_ptr->m_item->setVisible(visible);
187 d_ptr->m_item->setVisible(visible);
102 }
188 }
103
189
104 ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
190 ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
105 QLegendMarkerPrivate::QLegendMarkerPrivate(QLegendMarker *q, QLegend *legend) :
191 QLegendMarkerPrivate::QLegendMarkerPrivate(QLegendMarker *q, QLegend *legend) :
106 m_legend(legend),
192 m_legend(legend),
107 q_ptr(q)
193 q_ptr(q)
108 {
194 {
109 m_item = new LegendMarkerItem(this);
195 m_item = new LegendMarkerItem(this);
110 // m_item->setVisible(q->series()->isVisible());
111 }
196 }
112
197
113 QLegendMarkerPrivate::~QLegendMarkerPrivate()
198 QLegendMarkerPrivate::~QLegendMarkerPrivate()
114 {
199 {
115 }
200 }
116
201
117 void QLegendMarkerPrivate::invalidateLegend()
202 void QLegendMarkerPrivate::invalidateLegend()
118 {
203 {
119 m_legend->d_ptr->m_layout->invalidate();
204 m_legend->d_ptr->m_layout->invalidate();
120 }
205 }
121
206
122
123
124 #include "moc_qlegendmarker.cpp"
207 #include "moc_qlegendmarker.cpp"
125 #include "moc_qlegendmarker_p.cpp"
208 #include "moc_qlegendmarker_p.cpp"
126
209
127 QTCOMMERCIALCHART_END_NAMESPACE
210 QTCOMMERCIALCHART_END_NAMESPACE
@@ -1,95 +1,122
1 /****************************************************************************
1 /****************************************************************************
2 **
2 **
3 ** Copyright (C) 2012 Digia Plc
3 ** Copyright (C) 2012 Digia Plc
4 ** All rights reserved.
4 ** All rights reserved.
5 ** For any questions to Digia, please use contact form at http://qt.digia.com
5 ** For any questions to Digia, please use contact form at http://qt.digia.com
6 **
6 **
7 ** This file is part of the Qt Commercial Charts Add-on.
7 ** This file is part of the Qt Commercial Charts Add-on.
8 **
8 **
9 ** $QT_BEGIN_LICENSE$
9 ** $QT_BEGIN_LICENSE$
10 ** Licensees holding valid Qt Commercial licenses may use this file in
10 ** Licensees holding valid Qt Commercial licenses may use this file in
11 ** accordance with the Qt Commercial License Agreement provided with the
11 ** accordance with the Qt Commercial License Agreement provided with the
12 ** Software or, alternatively, in accordance with the terms contained in
12 ** Software or, alternatively, in accordance with the terms contained in
13 ** a written agreement between you and Digia.
13 ** a written agreement between you and Digia.
14 **
14 **
15 ** If you have questions regarding the use of this file, please use
15 ** If you have questions regarding the use of this file, please use
16 ** contact form at http://qt.digia.com
16 ** contact form at http://qt.digia.com
17 ** $QT_END_LICENSE$
17 ** $QT_END_LICENSE$
18 **
18 **
19 ****************************************************************************/
19 ****************************************************************************/
20
20
21 #include "qpielegendmarker.h"
21 #include "qpielegendmarker.h"
22 #include "qpielegendmarker_p.h"
22 #include "qpielegendmarker_p.h"
23 #include <QPieSeries>
23 #include <QPieSeries>
24 #include <QPieSlice>
24 #include <QPieSlice>
25
25
26 QTCOMMERCIALCHART_BEGIN_NAMESPACE
26 QTCOMMERCIALCHART_BEGIN_NAMESPACE
27
27
28 /*!
29 \class QPieLegendMarker
30 \brief LegendMarker object
31 \mainclass
32
33 QPieLegendMarker is related to QPieSeries. With QPieSeries, each slice of pie is related to one marker in QLegend.
34
35 \sa QLegend QPieSeries QPieSlice
36 */
37
38 /*!
39 \fn virtual LegendMarkerType QPieLegendMarker::type()
40 Returns QLegendMarker::LegendMarkerTypePie
41 */
42
43 /*!
44 Constructor
45 */
28 QPieLegendMarker::QPieLegendMarker(QPieSeries *series, QPieSlice *slice, QLegend *legend, QObject *parent) :
46 QPieLegendMarker::QPieLegendMarker(QPieSeries *series, QPieSlice *slice, QLegend *legend, QObject *parent) :
29 QLegendMarker(*new QPieLegendMarkerPrivate(this,series,slice,legend), parent)
47 QLegendMarker(*new QPieLegendMarkerPrivate(this,series,slice,legend), parent)
30 {
48 {
31 }
49 }
32
50
51 /*!
52 Destructor
53 */
33 QPieLegendMarker::~QPieLegendMarker()
54 QPieLegendMarker::~QPieLegendMarker()
34 {
55 {
35 }
56 }
36
57
37 /*!
58 /*!
38 \internal
59 \internal
39 */
60 */
40 QPieLegendMarker::QPieLegendMarker(QPieLegendMarkerPrivate &d, QObject *parent) :
61 QPieLegendMarker::QPieLegendMarker(QPieLegendMarkerPrivate &d, QObject *parent) :
41 QLegendMarker(d, parent)
62 QLegendMarker(d, parent)
42 {
63 {
43 }
64 }
44
65
66 /*!
67 Returns the related series of marker.
68 */
45 QPieSeries* QPieLegendMarker::series()
69 QPieSeries* QPieLegendMarker::series()
46 {
70 {
47 Q_D(QPieLegendMarker);
71 Q_D(QPieLegendMarker);
48 return d->m_series;
72 return d->m_series;
49 }
73 }
50
74
75 /*!
76 Returns the related slice of marker.
77 */
51 QPieSlice* QPieLegendMarker::slice()
78 QPieSlice* QPieLegendMarker::slice()
52 {
79 {
53 Q_D(QPieLegendMarker);
80 Q_D(QPieLegendMarker);
54 return d->m_slice;
81 return d->m_slice;
55 }
82 }
56
83
57 ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
84 ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
58
85
59 QPieLegendMarkerPrivate::QPieLegendMarkerPrivate(QPieLegendMarker *q, QPieSeries *series, QPieSlice *slice, QLegend *legend) :
86 QPieLegendMarkerPrivate::QPieLegendMarkerPrivate(QPieLegendMarker *q, QPieSeries *series, QPieSlice *slice, QLegend *legend) :
60 QLegendMarkerPrivate(q,legend),
87 QLegendMarkerPrivate(q,legend),
61 m_series(series),
88 m_series(series),
62 m_slice(slice)
89 m_slice(slice)
63 {
90 {
64 QObject::connect(m_slice, SIGNAL(labelChanged()), this, SLOT(updated()));
91 QObject::connect(m_slice, SIGNAL(labelChanged()), this, SLOT(updated()));
65 QObject::connect(m_slice, SIGNAL(brushChanged()), this, SLOT(updated()));
92 QObject::connect(m_slice, SIGNAL(brushChanged()), this, SLOT(updated()));
66 QObject::connect(m_slice, SIGNAL(penChanged()), this, SLOT(updated()));
93 QObject::connect(m_slice, SIGNAL(penChanged()), this, SLOT(updated()));
67 updated();
94 updated();
68 }
95 }
69
96
70 QPieLegendMarkerPrivate::~QPieLegendMarkerPrivate()
97 QPieLegendMarkerPrivate::~QPieLegendMarkerPrivate()
71 {
98 {
72 }
99 }
73
100
74 QPieSeries* QPieLegendMarkerPrivate::series()
101 QPieSeries* QPieLegendMarkerPrivate::series()
75 {
102 {
76 return m_series;
103 return m_series;
77 }
104 }
78
105
79 QObject* QPieLegendMarkerPrivate::relatedObject()
106 QObject* QPieLegendMarkerPrivate::relatedObject()
80 {
107 {
81 return m_slice;
108 return m_slice;
82 }
109 }
83
110
84 void QPieLegendMarkerPrivate::updated()
111 void QPieLegendMarkerPrivate::updated()
85 {
112 {
86 m_item->setPen(m_slice->pen());
113 m_item->setPen(m_slice->pen());
87 m_item->setBrush(m_slice->brush());
114 m_item->setBrush(m_slice->brush());
88 m_item->setLabel(m_slice->label());
115 m_item->setLabel(m_slice->label());
89 invalidateLegend();
116 invalidateLegend();
90 }
117 }
91
118
92 #include "moc_qpielegendmarker.cpp"
119 #include "moc_qpielegendmarker.cpp"
93 #include "moc_qpielegendmarker_p.cpp"
120 #include "moc_qpielegendmarker_p.cpp"
94
121
95 QTCOMMERCIALCHART_END_NAMESPACE
122 QTCOMMERCIALCHART_END_NAMESPACE
@@ -1,92 +1,116
1 /****************************************************************************
1 /****************************************************************************
2 **
2 **
3 ** Copyright (C) 2012 Digia Plc
3 ** Copyright (C) 2012 Digia Plc
4 ** All rights reserved.
4 ** All rights reserved.
5 ** For any questions to Digia, please use contact form at http://qt.digia.com
5 ** For any questions to Digia, please use contact form at http://qt.digia.com
6 **
6 **
7 ** This file is part of the Qt Commercial Charts Add-on.
7 ** This file is part of the Qt Commercial Charts Add-on.
8 **
8 **
9 ** $QT_BEGIN_LICENSE$
9 ** $QT_BEGIN_LICENSE$
10 ** Licensees holding valid Qt Commercial licenses may use this file in
10 ** Licensees holding valid Qt Commercial licenses may use this file in
11 ** accordance with the Qt Commercial License Agreement provided with the
11 ** accordance with the Qt Commercial License Agreement provided with the
12 ** Software or, alternatively, in accordance with the terms contained in
12 ** Software or, alternatively, in accordance with the terms contained in
13 ** a written agreement between you and Digia.
13 ** a written agreement between you and Digia.
14 **
14 **
15 ** If you have questions regarding the use of this file, please use
15 ** If you have questions regarding the use of this file, please use
16 ** contact form at http://qt.digia.com
16 ** contact form at http://qt.digia.com
17 ** $QT_END_LICENSE$
17 ** $QT_END_LICENSE$
18 **
18 **
19 ****************************************************************************/
19 ****************************************************************************/
20
20
21 #include "qxylegendmarker.h"
21 #include "qxylegendmarker.h"
22 #include "qxylegendmarker_p.h"
22 #include "qxylegendmarker_p.h"
23 #include "qxyseries_p.h"
23 #include "qxyseries_p.h"
24 #include <QXYSeries>
24 #include <QXYSeries>
25
25
26 QTCOMMERCIALCHART_BEGIN_NAMESPACE
26 QTCOMMERCIALCHART_BEGIN_NAMESPACE
27
27
28 /*!
29 \class QXYLegendMarker
30 \brief QXYLegendMarker object
31 \mainclass
32
33 QXYLegendMarker is related to QXYSeries derived classes. Each marker is related to one series.
34
35 \sa QLegend QXYSeries QSplineSeries QScatterSeries QLineSeries
36 */
37
38 /*!
39 \fn virtual LegendMarkerType QXYLegendMarker::type()
40 Returns QLegendMarker::LegendMarkerTypeXY
41 */
42
43 /*!
44 Constructor
45 */
28 QXYLegendMarker::QXYLegendMarker(QXYSeries *series, QLegend *legend, QObject *parent) :
46 QXYLegendMarker::QXYLegendMarker(QXYSeries *series, QLegend *legend, QObject *parent) :
29 QLegendMarker(*new QXYLegendMarkerPrivate(this,series,legend), parent)
47 QLegendMarker(*new QXYLegendMarkerPrivate(this,series,legend), parent)
30 {
48 {
31 }
49 }
32
50
51 /*!
52 Destructor
53 */
33 QXYLegendMarker::~QXYLegendMarker()
54 QXYLegendMarker::~QXYLegendMarker()
34 {
55 {
35 }
56 }
36
57
37 /*!
58 /*!
38 \internal
59 \internal
39 */
60 */
40 QXYLegendMarker::QXYLegendMarker(QXYLegendMarkerPrivate &d, QObject *parent) :
61 QXYLegendMarker::QXYLegendMarker(QXYLegendMarkerPrivate &d, QObject *parent) :
41 QLegendMarker(d, parent)
62 QLegendMarker(d, parent)
42 {
63 {
43 }
64 }
44
65
66 /*!
67 Returns the related series
68 */
45 QXYSeries* QXYLegendMarker::series()
69 QXYSeries* QXYLegendMarker::series()
46 {
70 {
47 Q_D(QXYLegendMarker);
71 Q_D(QXYLegendMarker);
48 return d->m_series;
72 return d->m_series;
49 }
73 }
50
74
51 ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
75 ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
52
76
53 QXYLegendMarkerPrivate::QXYLegendMarkerPrivate(QXYLegendMarker *q, QXYSeries *series, QLegend *legend) :
77 QXYLegendMarkerPrivate::QXYLegendMarkerPrivate(QXYLegendMarker *q, QXYSeries *series, QLegend *legend) :
54 QLegendMarkerPrivate(q,legend),
78 QLegendMarkerPrivate(q,legend),
55 m_series(series)
79 m_series(series)
56 {
80 {
57 QObject::connect(m_series, SIGNAL(nameChanged()), this, SLOT(updated()));
81 QObject::connect(m_series, SIGNAL(nameChanged()), this, SLOT(updated()));
58 QObject::connect(m_series->d_func(), SIGNAL(updated()), this, SLOT(updated()));
82 QObject::connect(m_series->d_func(), SIGNAL(updated()), this, SLOT(updated()));
59 updated();
83 updated();
60 }
84 }
61
85
62 QXYLegendMarkerPrivate::~QXYLegendMarkerPrivate()
86 QXYLegendMarkerPrivate::~QXYLegendMarkerPrivate()
63 {
87 {
64 }
88 }
65
89
66 QAbstractSeries* QXYLegendMarkerPrivate::series()
90 QAbstractSeries* QXYLegendMarkerPrivate::series()
67 {
91 {
68 return m_series;
92 return m_series;
69 }
93 }
70
94
71 QObject* QXYLegendMarkerPrivate::relatedObject()
95 QObject* QXYLegendMarkerPrivate::relatedObject()
72 {
96 {
73 return m_series;
97 return m_series;
74 }
98 }
75
99
76 void QXYLegendMarkerPrivate::updated()
100 void QXYLegendMarkerPrivate::updated()
77 {
101 {
78 m_item->setLabel(m_series->name());
102 m_item->setLabel(m_series->name());
79
103
80 if (m_series->type()== QAbstractSeries::SeriesTypeScatter) {
104 if (m_series->type()== QAbstractSeries::SeriesTypeScatter) {
81 m_item->setBrush(m_series->brush());
105 m_item->setBrush(m_series->brush());
82 } else {
106 } else {
83 m_item->setBrush(QBrush(m_series->pen().color()));
107 m_item->setBrush(QBrush(m_series->pen().color()));
84 }
108 }
85 invalidateLegend();
109 invalidateLegend();
86 }
110 }
87
111
88 #include "moc_qxylegendmarker.cpp"
112 #include "moc_qxylegendmarker.cpp"
89 #include "moc_qxylegendmarker_p.cpp"
113 #include "moc_qxylegendmarker_p.cpp"
90
114
91 QTCOMMERCIALCHART_END_NAMESPACE
115 QTCOMMERCIALCHART_END_NAMESPACE
92
116
General Comments 0
You need to be logged in to leave comments. Login now