##// END OF EJS Templates
Fix legend marker brush for series with black pen....
Miikka Heikkinen -
r2515:58f023bc109e
parent child
Show More
@@ -1,134 +1,137
1 /****************************************************************************
1 /****************************************************************************
2 **
2 **
3 ** Copyright (C) 2013 Digia Plc
3 ** Copyright (C) 2013 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 /*!
28 /*!
29 \class QXYLegendMarker
29 \class QXYLegendMarker
30 \brief QXYLegendMarker object
30 \brief QXYLegendMarker object
31 \mainclass
31 \mainclass
32
32
33 QXYLegendMarker is related to QXYSeries derived classes. Each marker is related to one series.
33 QXYLegendMarker is related to QXYSeries derived classes. Each marker is related to one series.
34
34
35 \sa QLegend QXYSeries QSplineSeries QScatterSeries QLineSeries
35 \sa QLegend QXYSeries QSplineSeries QScatterSeries QLineSeries
36 */
36 */
37
37
38 /*!
38 /*!
39 \fn virtual LegendMarkerType QXYLegendMarker::type()
39 \fn virtual LegendMarkerType QXYLegendMarker::type()
40 Returns QLegendMarker::LegendMarkerTypeXY
40 Returns QLegendMarker::LegendMarkerTypeXY
41 */
41 */
42
42
43 /*!
43 /*!
44 \internal
44 \internal
45 */
45 */
46 QXYLegendMarker::QXYLegendMarker(QXYSeries *series, QLegend *legend, QObject *parent) :
46 QXYLegendMarker::QXYLegendMarker(QXYSeries *series, QLegend *legend, QObject *parent) :
47 QLegendMarker(*new QXYLegendMarkerPrivate(this,series,legend), parent)
47 QLegendMarker(*new QXYLegendMarkerPrivate(this,series,legend), parent)
48 {
48 {
49 d_ptr->updated();
49 d_ptr->updated();
50 }
50 }
51
51
52 /*!
52 /*!
53 Destructor
53 Destructor
54 */
54 */
55 QXYLegendMarker::~QXYLegendMarker()
55 QXYLegendMarker::~QXYLegendMarker()
56 {
56 {
57 }
57 }
58
58
59 /*!
59 /*!
60 \internal
60 \internal
61 */
61 */
62 QXYLegendMarker::QXYLegendMarker(QXYLegendMarkerPrivate &d, QObject *parent) :
62 QXYLegendMarker::QXYLegendMarker(QXYLegendMarkerPrivate &d, QObject *parent) :
63 QLegendMarker(d, parent)
63 QLegendMarker(d, parent)
64 {
64 {
65 }
65 }
66
66
67 /*!
67 /*!
68 Returns the related series
68 Returns the related series
69 */
69 */
70 QXYSeries* QXYLegendMarker::series()
70 QXYSeries* QXYLegendMarker::series()
71 {
71 {
72 Q_D(QXYLegendMarker);
72 Q_D(QXYLegendMarker);
73 return d->m_series;
73 return d->m_series;
74 }
74 }
75
75
76 ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
76 ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
77
77
78 QXYLegendMarkerPrivate::QXYLegendMarkerPrivate(QXYLegendMarker *q, QXYSeries *series, QLegend *legend) :
78 QXYLegendMarkerPrivate::QXYLegendMarkerPrivate(QXYLegendMarker *q, QXYSeries *series, QLegend *legend) :
79 QLegendMarkerPrivate(q,legend),
79 QLegendMarkerPrivate(q,legend),
80 q_ptr(q),
80 q_ptr(q),
81 m_series(series)
81 m_series(series)
82 {
82 {
83 QObject::connect(m_series, SIGNAL(nameChanged()), this, SLOT(updated()));
83 QObject::connect(m_series, SIGNAL(nameChanged()), this, SLOT(updated()));
84 QObject::connect(m_series->d_func(), SIGNAL(updated()), this, SLOT(updated()));
84 QObject::connect(m_series->d_func(), SIGNAL(updated()), this, SLOT(updated()));
85 }
85 }
86
86
87 QXYLegendMarkerPrivate::~QXYLegendMarkerPrivate()
87 QXYLegendMarkerPrivate::~QXYLegendMarkerPrivate()
88 {
88 {
89 }
89 }
90
90
91 QAbstractSeries* QXYLegendMarkerPrivate::series()
91 QAbstractSeries* QXYLegendMarkerPrivate::series()
92 {
92 {
93 return m_series;
93 return m_series;
94 }
94 }
95
95
96 QObject* QXYLegendMarkerPrivate::relatedObject()
96 QObject* QXYLegendMarkerPrivate::relatedObject()
97 {
97 {
98 return m_series;
98 return m_series;
99 }
99 }
100
100
101 void QXYLegendMarkerPrivate::updated()
101 void QXYLegendMarkerPrivate::updated()
102 {
102 {
103 bool labelChanged = false;
103 bool labelChanged = false;
104 bool brushChanged = false;
104 bool brushChanged = false;
105
105
106 if (!m_customLabel && (m_item->label() != m_series->name())) {
106 if (!m_customLabel && (m_item->label() != m_series->name())) {
107 m_item->setLabel(m_series->name());
107 m_item->setLabel(m_series->name());
108 labelChanged = true;
108 labelChanged = true;
109 }
109 }
110
110
111 if (m_series->type()== QAbstractSeries::SeriesTypeScatter) {
111 if (m_series->type()== QAbstractSeries::SeriesTypeScatter) {
112 if (!m_customBrush && (m_item->brush() != m_series->brush())) {
112 if (!m_customBrush && (m_item->brush() != m_series->brush())) {
113 m_item->setBrush(m_series->brush());
113 m_item->setBrush(m_series->brush());
114 brushChanged = true;
114 brushChanged = true;
115 }
115 }
116 } else {
116 } else {
117 if (!m_customBrush && (m_item->brush().color() != m_series->pen().color())) {
117 QBrush emptyBrush;
118 if (!m_customBrush
119 && (m_item->brush() == emptyBrush
120 || m_item->brush().color() != m_series->pen().color())) {
118 m_item->setBrush(QBrush(m_series->pen().color()));
121 m_item->setBrush(QBrush(m_series->pen().color()));
119 brushChanged = true;
122 brushChanged = true;
120 }
123 }
121 }
124 }
122 invalidateLegend();
125 invalidateLegend();
123
126
124 if (labelChanged)
127 if (labelChanged)
125 emit q_ptr->labelChanged();
128 emit q_ptr->labelChanged();
126 if (brushChanged)
129 if (brushChanged)
127 emit q_ptr->brushChanged();
130 emit q_ptr->brushChanged();
128 }
131 }
129
132
130 #include "moc_qxylegendmarker.cpp"
133 #include "moc_qxylegendmarker.cpp"
131 #include "moc_qxylegendmarker_p.cpp"
134 #include "moc_qxylegendmarker_p.cpp"
132
135
133 QTCOMMERCIALCHART_END_NAMESPACE
136 QTCOMMERCIALCHART_END_NAMESPACE
134
137
General Comments 0
You need to be logged in to leave comments. Login now