##// END OF EJS Templates
fixed crash in legendmarker when calling update from private constructor
sauimone -
r2227:d68dfe34c17e
parent child
Show More
@@ -1,181 +1,195
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 "mainwidget.h"
21 #include "mainwidget.h"
22 #include <QChart>
22 #include <QChart>
23 #include <QChartView>
23 #include <QChartView>
24 #include <QPushButton>
24 #include <QPushButton>
25 #include <QLabel>
25 #include <QLabel>
26 #include <QDebug>
26 #include <QDebug>
27 #include <QLegend>
27 #include <QLegend>
28 #include <QFormLayout>
28 #include <QFormLayout>
29 #include <QLegendMarker>
29 #include <QLegendMarker>
30 #include <QLineSeries>
30 #include <QLineSeries>
31 #include <QXYLegendMarker>
31 #include <QXYLegendMarker>
32 #include <qmath.h>
32 #include <qmath.h>
33
33
34 QTCOMMERCIALCHART_USE_NAMESPACE
34 QTCOMMERCIALCHART_USE_NAMESPACE
35
35
36 MainWidget::MainWidget(QWidget *parent) :
36 MainWidget::MainWidget(QWidget *parent) :
37 QWidget(parent)
37 QWidget(parent)
38 {
38 {
39 // Create buttons for ui
39 // Create buttons for ui
40 m_buttonLayout = new QGridLayout();
40 m_buttonLayout = new QGridLayout();
41
41
42 QPushButton *addSliceButton = new QPushButton("add series");
42 QPushButton *addSliceButton = new QPushButton("add series");
43 connect(addSliceButton, SIGNAL(clicked()), this, SLOT(addSeries()));
43 connect(addSliceButton, SIGNAL(clicked()), this, SLOT(addSeries()));
44 m_buttonLayout->addWidget(addSliceButton, 1, 0);
44 m_buttonLayout->addWidget(addSliceButton, 1, 0);
45
45
46 QPushButton *removeSliceButton = new QPushButton("remove series");
46 QPushButton *removeSliceButton = new QPushButton("remove series");
47 connect(removeSliceButton, SIGNAL(clicked()), this, SLOT(removeSeries()));
47 connect(removeSliceButton, SIGNAL(clicked()), this, SLOT(removeSeries()));
48 m_buttonLayout->addWidget(removeSliceButton, 2, 0);
48 m_buttonLayout->addWidget(removeSliceButton, 2, 0);
49
49
50 QPushButton *connectButton = new QPushButton("Connect markers");
50 QPushButton *connectButton = new QPushButton("Connect markers");
51 connect(connectButton, SIGNAL(clicked()), this, SLOT(connectMarkers()));
51 connect(connectButton, SIGNAL(clicked()), this, SLOT(connectMarkers()));
52 m_buttonLayout->addWidget(connectButton, 3, 0);
52 m_buttonLayout->addWidget(connectButton, 3, 0);
53
53
54 QPushButton *disConnectButton = new QPushButton("Disconnect markers");
54 QPushButton *disConnectButton = new QPushButton("Disconnect markers");
55 connect(disConnectButton, SIGNAL(clicked()), this, SLOT(disconnectMarkers()));
55 connect(disConnectButton, SIGNAL(clicked()), this, SLOT(disconnectMarkers()));
56 m_buttonLayout->addWidget(disConnectButton, 4, 0);
56 m_buttonLayout->addWidget(disConnectButton, 4, 0);
57
57
58 // Create chart view with the chart
58 // Create chart view with the chart
59 m_chart = new QChart();
59 m_chart = new QChart();
60 m_chartView = new QChartView(m_chart, this);
60 m_chartView = new QChartView(m_chart, this);
61
61
62 // Create layout for grid and detached legend
62 // Create layout for grid and detached legend
63 m_mainLayout = new QGridLayout();
63 m_mainLayout = new QGridLayout();
64 m_mainLayout->addLayout(m_buttonLayout, 0, 0);
64 m_mainLayout->addLayout(m_buttonLayout, 0, 0);
65 m_mainLayout->addWidget(m_chartView, 0, 1, 3, 1);
65 m_mainLayout->addWidget(m_chartView, 0, 1, 3, 1);
66 setLayout(m_mainLayout);
66 setLayout(m_mainLayout);
67
67
68 // Add few series
68 // Add few series
69 addSeries();
69 addSeries();
70 addSeries();
70 addSeries();
71 addSeries();
71 addSeries();
72 addSeries();
72 addSeries();
73
73
74 // Set the title and show legend
74 // Set the title and show legend
75 m_chart->setTitle("Legendmarker example");
75 m_chart->setTitle("Legendmarker example");
76 m_chart->legend()->setVisible(true);
76 m_chart->legend()->setVisible(true);
77 m_chart->legend()->setAlignment(Qt::AlignBottom);
77 m_chart->legend()->setAlignment(Qt::AlignBottom);
78
78
79 m_chartView->setRenderHint(QPainter::Antialiasing);
79 m_chartView->setRenderHint(QPainter::Antialiasing);
80 }
80 }
81
81
82 void MainWidget::addSeries()
82 void MainWidget::addSeries()
83 {
83 {
84 QLineSeries *series = new QLineSeries();
84 QLineSeries *series = new QLineSeries();
85 m_series.append(series);
85 m_series.append(series);
86
86
87 series->setName(QString("line " + QString::number(m_series.count())));
87 series->setName(QString("line " + QString::number(m_series.count())));
88
88
89 // Make some sine wave for data
89 // Make some sine wave for data
90 QList<QPointF> data;
90 QList<QPointF> data;
91 int offset = m_chart->series().count();
91 int offset = m_chart->series().count();
92 for (int i = 0; i < 360; i++) {
92 for (int i = 0; i < 360; i++) {
93 qreal x = offset * 20 + i;
93 qreal x = offset * 20 + i;
94 data.append(QPointF(i, qSin(2.0 * 3.141592 * x / 360.0)));
94 data.append(QPointF(i, qSin(2.0 * 3.141592 * x / 360.0)));
95 }
95 }
96
96
97 series->append(data);
97 series->append(data);
98 m_chart->addSeries(series);
98 m_chart->addSeries(series);
99
99
100 if (m_series.count() == 1) {
100 if (m_series.count() == 1) {
101 m_chart->createDefaultAxes();
101 m_chart->createDefaultAxes();
102 }
102 }
103 }
103 }
104
104
105 void MainWidget::removeSeries()
105 void MainWidget::removeSeries()
106 {
106 {
107 // Remove last series from chart
107 // Remove last series from chart
108 if (m_series.count() > 0) {
108 if (m_series.count() > 0) {
109 QLineSeries *series = m_series.last();
109 QLineSeries *series = m_series.last();
110 m_chart->removeSeries(series);
110 m_chart->removeSeries(series);
111 m_series.removeLast();
111 m_series.removeLast();
112 delete series;
112 delete series;
113 }
113 }
114 }
114 }
115
115
116 void MainWidget::connectMarkers()
116 void MainWidget::connectMarkers()
117 {
117 {
118 //![1]
118 //![1]
119 // Connect all markers to handler
119 // Connect all markers to handler
120 foreach (QLegendMarker* marker, m_chart->legend()->markers()) {
120 foreach (QLegendMarker* marker, m_chart->legend()->markers()) {
121 // Disconnect possible existing connection to avoid multiple connections
121 // Disconnect possible existing connection to avoid multiple connections
122 QObject::disconnect(marker, SIGNAL(clicked()), this, SLOT(handleMarkerClicked()));
122 QObject::disconnect(marker, SIGNAL(clicked()), this, SLOT(handleMarkerClicked()));
123 QObject::connect(marker, SIGNAL(clicked()), this, SLOT(handleMarkerClicked()));
123 QObject::connect(marker, SIGNAL(clicked()), this, SLOT(handleMarkerClicked()));
124 }
124 }
125 //![1]
125 //![1]
126 }
126 }
127
127
128 void MainWidget::disconnectMarkers()
128 void MainWidget::disconnectMarkers()
129 {
129 {
130 //![2]
130 //![2]
131 foreach (QLegendMarker* marker, m_chart->legend()->markers()) {
131 foreach (QLegendMarker* marker, m_chart->legend()->markers()) {
132 QObject::disconnect(marker, SIGNAL(clicked()), this, SLOT(handleMarkerClicked()));
132 QObject::disconnect(marker, SIGNAL(clicked()), this, SLOT(handleMarkerClicked()));
133 }
133 }
134 //![2]
134 //![2]
135 }
135 }
136
136
137 void MainWidget::handleMarkerClicked()
137 void MainWidget::handleMarkerClicked()
138 {
138 {
139 //![3]
139 //![3]
140 QLegendMarker* marker = qobject_cast<QLegendMarker*> (sender());
140 QLegendMarker* marker = qobject_cast<QLegendMarker*> (sender());
141 Q_ASSERT(marker);
141 Q_ASSERT(marker);
142 //![3]
142 //![3]
143
143
144 //![4]
144 //![4]
145 switch (marker->type())
145 switch (marker->type())
146 //![4]
146 //![4]
147 {
147 {
148 case QLegendMarker::LegendMarkerTypeXY:
148 case QLegendMarker::LegendMarkerTypeXY:
149 {
149 {
150 //![5]
150 //![5]
151 // Toggle visibility of series
151 // Toggle visibility of series
152 marker->series()->setVisible(!marker->series()->isVisible());
152 marker->series()->setVisible(!marker->series()->isVisible());
153
153
154 // Turn legend marker back to visible, since hiding series also hides the marker
154 // Turn legend marker back to visible, since hiding series also hides the marker
155 // and we don't want it to happen now.
155 // and we don't want it to happen now.
156 marker->setVisible(true);
156 marker->setVisible(true);
157 //![5]
157 //![5]
158
158
159 //![6]
159 //![6]
160 // Dim the marker, if series is not visible
160 // Dim the marker, if series is not visible
161 QBrush labelBrush = marker->labelBrush();
161 qreal alpha = 1.0;
162 QColor color = labelBrush.color();
163
162
164 if (marker->series()->isVisible()) {
163 if (!marker->series()->isVisible()) {
165 color.setAlphaF(1.0);
164 alpha = 0.5;
166 } else {
167 color.setAlphaF(0.5);
168 }
165 }
169
166
170 labelBrush.setColor(color);
167 QColor color;
171 marker->setLabelBrush(labelBrush);
168 QBrush brush = marker->labelBrush();
169 color = brush.color();
170 color.setAlphaF(alpha);
171 brush.setColor(color);
172 marker->setLabelBrush(brush);
173
174 brush = marker->brush();
175 color = brush.color();
176 color.setAlphaF(alpha);
177 brush.setColor(color);
178 marker->setBrush(brush);
179
180 QPen pen = marker->pen();
181 color = pen.color();
182 color.setAlphaF(alpha);
183 pen.setColor(color);
184 marker->setPen(pen);
185
172 //![6]
186 //![6]
173 break;
187 break;
174 }
188 }
175 default:
189 default:
176 {
190 {
177 qDebug() << "Unknown marker type";
191 qDebug() << "Unknown marker type";
178 break;
192 break;
179 }
193 }
180 }
194 }
181 }
195 }
@@ -1,124 +1,125
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 /*!
28 /*!
29 \class QAreaLegendMarker
29 \class QAreaLegendMarker
30 \brief QAreaLegendMarker object
30 \brief QAreaLegendMarker object
31 \mainclass
31 \mainclass
32
32
33 QAreaLegendMarker is related to QAreaSeries. One QAreaSeries results in one marker.
33 QAreaLegendMarker is related to QAreaSeries. One QAreaSeries results in one marker.
34
34
35 \sa QLegend QAreaSeries
35 \sa QLegend QAreaSeries
36 */
36 */
37
37
38 /*!
38 /*!
39 \fn virtual LegendMarkerType QAreaLegendMarker::type()
39 \fn virtual LegendMarkerType QAreaLegendMarker::type()
40 Returns QLegendMarker::LegendMarkerTypeArea
40 Returns QLegendMarker::LegendMarkerTypeArea
41 */
41 */
42
42
43 /*!
43 /*!
44 Constructor
44 Constructor
45 */
45 */
46 QAreaLegendMarker::QAreaLegendMarker(QAreaSeries *series, QLegend *legend, QObject *parent) :
46 QAreaLegendMarker::QAreaLegendMarker(QAreaSeries *series, QLegend *legend, QObject *parent) :
47 QLegendMarker(*new QAreaLegendMarkerPrivate(this,series,legend), parent)
47 QLegendMarker(*new QAreaLegendMarkerPrivate(this,series,legend), parent)
48 {
48 {
49 d_ptr->updated();
49 }
50 }
50
51
51 /*!
52 /*!
52 Destructor
53 Destructor
53 */
54 */
54 QAreaLegendMarker::~QAreaLegendMarker()
55 QAreaLegendMarker::~QAreaLegendMarker()
55 {
56 {
56 }
57 }
57
58
58 /*!
59 /*!
59 \internal
60 \internal
60 */
61 */
61 QAreaLegendMarker::QAreaLegendMarker(QAreaLegendMarkerPrivate &d, QObject *parent) :
62 QAreaLegendMarker::QAreaLegendMarker(QAreaLegendMarkerPrivate &d, QObject *parent) :
62 QLegendMarker(d, parent)
63 QLegendMarker(d, parent)
63 {
64 {
64 }
65 }
65
66
66 /*!
67 /*!
67 Returns related series of marker
68 Returns related series of marker
68 */
69 */
69 QAreaSeries* QAreaLegendMarker::series()
70 QAreaSeries* QAreaLegendMarker::series()
70 {
71 {
71 Q_D(QAreaLegendMarker);
72 Q_D(QAreaLegendMarker);
72 return d->m_series;
73 return d->m_series;
73 }
74 }
74
75
75 ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
76 ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
76
77
77 QAreaLegendMarkerPrivate::QAreaLegendMarkerPrivate(QAreaLegendMarker *q, QAreaSeries *series, QLegend *legend) :
78 QAreaLegendMarkerPrivate::QAreaLegendMarkerPrivate(QAreaLegendMarker *q, QAreaSeries *series, QLegend *legend) :
78 QLegendMarkerPrivate(q,legend),
79 QLegendMarkerPrivate(q,legend),
80 q_ptr(q),
79 m_series(series)
81 m_series(series)
80 {
82 {
81 QObject::connect(m_series->d_func(),SIGNAL(updated()), this, SLOT(updated()));
83 QObject::connect(m_series->d_func(),SIGNAL(updated()), this, SLOT(updated()));
82 QObject::connect(m_series, SIGNAL(nameChanged()), this, SLOT(updated()));
84 QObject::connect(m_series, SIGNAL(nameChanged()), this, SLOT(updated()));
83 updated();
84 }
85 }
85
86
86 QAreaLegendMarkerPrivate::~QAreaLegendMarkerPrivate()
87 QAreaLegendMarkerPrivate::~QAreaLegendMarkerPrivate()
87 {
88 {
88 }
89 }
89
90
90 QAreaSeries* QAreaLegendMarkerPrivate::series()
91 QAreaSeries* QAreaLegendMarkerPrivate::series()
91 {
92 {
92 return m_series;
93 return m_series;
93 }
94 }
94
95
95 QObject* QAreaLegendMarkerPrivate::relatedObject()
96 QObject* QAreaLegendMarkerPrivate::relatedObject()
96 {
97 {
97 return m_series;
98 return m_series;
98 }
99 }
99
100
100 void QAreaLegendMarkerPrivate::updated()
101 void QAreaLegendMarkerPrivate::updated()
101 {
102 {
102 bool labelChanged = false;
103 bool labelChanged = false;
103 bool brushChanged = false;
104 bool brushChanged = false;
104
105
105 if (m_item->brush() != m_series->brush()) {
106 if (m_item->brush() != m_series->brush()) {
106 m_item->setBrush(m_series->brush());
107 m_item->setBrush(m_series->brush());
107 brushChanged = true;
108 brushChanged = true;
108 }
109 }
109 if (m_item->label() != m_series->name()) {
110 if (m_item->label() != m_series->name()) {
110 m_item->setLabel(m_series->name());
111 m_item->setLabel(m_series->name());
111 labelChanged = true;
112 labelChanged = true;
112 }
113 }
113 invalidateLegend();
114 invalidateLegend();
114
115
115 if (labelChanged)
116 if (labelChanged)
116 emit q_ptr->labelChanged();
117 emit q_ptr->labelChanged();
117 if (brushChanged)
118 if (brushChanged)
118 emit q_ptr->brushChanged();
119 emit q_ptr->brushChanged();
119 }
120 }
120
121
121 #include "moc_qarealegendmarker.cpp"
122 #include "moc_qarealegendmarker.cpp"
122 #include "moc_qarealegendmarker_p.cpp"
123 #include "moc_qarealegendmarker_p.cpp"
123
124
124 QTCOMMERCIALCHART_END_NAMESPACE
125 QTCOMMERCIALCHART_END_NAMESPACE
@@ -1,143 +1,144
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 /*!
28 /*!
29 \class QBarLegendMarker
29 \class QBarLegendMarker
30 \brief QBarLegendMarker object
30 \brief QBarLegendMarker object
31 \mainclass
31 \mainclass
32
32
33 QBarLegendMarker is related to QAbstractBarSeries derived classes. With bar series, each marker is related to one QBarSet.
33 QBarLegendMarker is related to QAbstractBarSeries derived classes. With bar series, each marker is related to one QBarSet.
34
34
35 \sa QLegend QAbstractBarSeries QBarSet
35 \sa QLegend QAbstractBarSeries QBarSet
36 */
36 */
37
37
38 /*!
38 /*!
39 \fn virtual LegendMarkerType QBarLegendMarker::type()
39 \fn virtual LegendMarkerType QBarLegendMarker::type()
40 Returns QLegendMarker::LegendMarkerTypeBar
40 Returns QLegendMarker::LegendMarkerTypeBar
41 */
41 */
42
42
43 /*!
43 /*!
44 Constructor
44 Constructor
45 */
45 */
46 QBarLegendMarker::QBarLegendMarker(QAbstractBarSeries *series, QBarSet *barset, QLegend *legend, QObject *parent) :
46 QBarLegendMarker::QBarLegendMarker(QAbstractBarSeries *series, QBarSet *barset, QLegend *legend, QObject *parent) :
47 QLegendMarker(*new QBarLegendMarkerPrivate(this,series,barset,legend), parent)
47 QLegendMarker(*new QBarLegendMarkerPrivate(this,series,barset,legend), parent)
48 {
48 {
49 d_ptr->updated();
49 }
50 }
50
51
51 /*!
52 /*!
52 Desturctor
53 Desturctor
53 */
54 */
54 QBarLegendMarker::~QBarLegendMarker()
55 QBarLegendMarker::~QBarLegendMarker()
55 {
56 {
56 }
57 }
57
58
58 /*!
59 /*!
59 \internal
60 \internal
60 */
61 */
61 QBarLegendMarker::QBarLegendMarker(QBarLegendMarkerPrivate &d, QObject *parent) :
62 QBarLegendMarker::QBarLegendMarker(QBarLegendMarkerPrivate &d, QObject *parent) :
62 QLegendMarker(d, parent)
63 QLegendMarker(d, parent)
63 {
64 {
64 }
65 }
65
66
66 /*!
67 /*!
67 Returns the related series of marker
68 Returns the related series of marker
68 */
69 */
69 QAbstractBarSeries *QBarLegendMarker::series()
70 QAbstractBarSeries *QBarLegendMarker::series()
70 {
71 {
71 Q_D(QBarLegendMarker);
72 Q_D(QBarLegendMarker);
72 return d->m_series;
73 return d->m_series;
73 }
74 }
74
75
75 /*!
76 /*!
76 Returns the related barset of marker
77 Returns the related barset of marker
77 */
78 */
78 QBarSet* QBarLegendMarker::barset()
79 QBarSet* QBarLegendMarker::barset()
79 {
80 {
80 Q_D(QBarLegendMarker);
81 Q_D(QBarLegendMarker);
81 return d->m_barset;
82 return d->m_barset;
82 }
83 }
83
84
84 ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
85 ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
85
86
86 QBarLegendMarkerPrivate::QBarLegendMarkerPrivate(QBarLegendMarker *q, QAbstractBarSeries *series, QBarSet *barset, QLegend *legend) :
87 QBarLegendMarkerPrivate::QBarLegendMarkerPrivate(QBarLegendMarker *q, QAbstractBarSeries *series, QBarSet *barset, QLegend *legend) :
87 QLegendMarkerPrivate(q,legend),
88 QLegendMarkerPrivate(q,legend),
89 q_ptr(q),
88 m_series(series),
90 m_series(series),
89 m_barset(barset)
91 m_barset(barset)
90 {
92 {
91 QObject::connect(m_barset, SIGNAL(penChanged()), this, SLOT(updated()));
93 QObject::connect(m_barset, SIGNAL(penChanged()), this, SLOT(updated()));
92 QObject::connect(m_barset, SIGNAL(labelChanged()), this, SLOT(updated()));
94 QObject::connect(m_barset, SIGNAL(labelChanged()), this, SLOT(updated()));
93 QObject::connect(m_barset, SIGNAL(brushChanged()), this, SLOT(updated()));
95 QObject::connect(m_barset, SIGNAL(brushChanged()), this, SLOT(updated()));
94 updated();
95 }
96 }
96
97
97 QBarLegendMarkerPrivate::~QBarLegendMarkerPrivate()
98 QBarLegendMarkerPrivate::~QBarLegendMarkerPrivate()
98 {
99 {
99 }
100 }
100
101
101 QAbstractBarSeries* QBarLegendMarkerPrivate::series()
102 QAbstractBarSeries* QBarLegendMarkerPrivate::series()
102 {
103 {
103 return m_series;
104 return m_series;
104 }
105 }
105
106
106 QObject* QBarLegendMarkerPrivate::relatedObject()
107 QObject* QBarLegendMarkerPrivate::relatedObject()
107 {
108 {
108 return m_barset;
109 return m_barset;
109 }
110 }
110
111
111 void QBarLegendMarkerPrivate::updated()
112 void QBarLegendMarkerPrivate::updated()
112 {
113 {
113 bool labelChanged = false;
114 bool labelChanged = false;
114 bool brushChanged = false;
115 bool brushChanged = false;
115 bool penChanged = false;
116 bool penChanged = false;
116
117
117 if (m_item->pen() != m_barset->pen()) {
118 if (m_item->pen() != m_barset->pen()) {
118 m_item->setPen(m_barset->pen());
119 m_item->setPen(m_barset->pen());
119 penChanged = true;
120 penChanged = true;
120 }
121 }
121 if (m_item->brush() != m_barset->brush()) {
122 if (m_item->brush() != m_barset->brush()) {
122 m_item->setBrush(m_barset->brush());
123 m_item->setBrush(m_barset->brush());
123 brushChanged = true;
124 brushChanged = true;
124 }
125 }
125 if (m_item->label() != m_barset->label()) {
126 if (m_item->label() != m_barset->label()) {
126 m_item->setLabel(m_barset->label());
127 m_item->setLabel(m_barset->label());
127 labelChanged = true;
128 labelChanged = true;
128 }
129 }
129 invalidateLegend();
130 invalidateLegend();
130
131
131 if (labelChanged)
132 if (labelChanged)
132 emit q_ptr->labelChanged();
133 emit q_ptr->labelChanged();
133 if (brushChanged)
134 if (brushChanged)
134 emit q_ptr->brushChanged();
135 emit q_ptr->brushChanged();
135 if (penChanged)
136 if (penChanged)
136 emit q_ptr->penChanged();
137 emit q_ptr->penChanged();
137 }
138 }
138
139
139 #include "moc_qbarlegendmarker.cpp"
140 #include "moc_qbarlegendmarker.cpp"
140 #include "moc_qbarlegendmarker_p.cpp"
141 #include "moc_qbarlegendmarker_p.cpp"
141
142
142 QTCOMMERCIALCHART_END_NAMESPACE
143 QTCOMMERCIALCHART_END_NAMESPACE
143
144
@@ -1,87 +1,87
1 /****************************************************************************
1 /****************************************************************************
2 **
2 **
3 ** Copyright (C) 2012 Digia Plc
3 ** Copyright (C) 2012 Digia Plc
4 ** All rights reserved.
4 ** All rights reserved.
5 ** For any questions to Digia, please use contact form at http://qt.digia.com
5 ** For any questions to Digia, please use contact form at http://qt.digia.com
6 **
6 **
7 ** This file is part of the Qt Commercial Charts Add-on.
7 ** This file is part of the Qt Commercial Charts Add-on.
8 **
8 **
9 ** $QT_BEGIN_LICENSE$
9 ** $QT_BEGIN_LICENSE$
10 ** Licensees holding valid Qt Commercial licenses may use this file in
10 ** Licensees holding valid Qt Commercial licenses may use this file in
11 ** accordance with the Qt Commercial License Agreement provided with the
11 ** accordance with the Qt Commercial License Agreement provided with the
12 ** Software or, alternatively, in accordance with the terms contained in
12 ** Software or, alternatively, in accordance with the terms contained in
13 ** a written agreement between you and Digia.
13 ** a written agreement between you and Digia.
14 **
14 **
15 ** If you have questions regarding the use of this file, please use
15 ** If you have questions regarding the use of this file, please use
16 ** contact form at http://qt.digia.com
16 ** contact form at http://qt.digia.com
17 ** $QT_END_LICENSE$
17 ** $QT_END_LICENSE$
18 **
18 **
19 ****************************************************************************/
19 ****************************************************************************/
20
20
21 // W A R N I N G
21 // W A R N I N G
22 // -------------
22 // -------------
23 //
23 //
24 // This file is not part of the QtCommercial Chart API. It exists purely as an
24 // This file is not part of the QtCommercial Chart API. It exists purely as an
25 // implementation detail. This header file may change from version to
25 // implementation detail. This header file may change from version to
26 // version without notice, or even be removed.
26 // version without notice, or even be removed.
27 //
27 //
28 // We mean it.
28 // We mean it.
29
29
30 #ifndef QLEGENDMARKERPRIVATE_H
30 #ifndef QLEGENDMARKERPRIVATE_H
31 #define QLEGENDMARKERPRIVATE_H
31 #define QLEGENDMARKERPRIVATE_H
32
32
33 #include "qchartglobal.h"
33 #include "qchartglobal.h"
34 #include <QGraphicsObject>
34 #include <QGraphicsObject>
35 #include <QBrush>
35 #include <QBrush>
36 #include <QPen>
36 #include <QPen>
37 #include <QGraphicsSimpleTextItem>
37 #include <QGraphicsSimpleTextItem>
38 #include <QGraphicsLayoutItem>
38 #include <QGraphicsLayoutItem>
39
39
40 QTCOMMERCIALCHART_BEGIN_NAMESPACE
40 QTCOMMERCIALCHART_BEGIN_NAMESPACE
41
41
42 // TODO: check these
42 // TODO: check these
43 class QAbstractSeries;
43 class QAbstractSeries;
44 class QAreaSeries;
44 class QAreaSeries;
45 class QXYSeries;
45 class QXYSeries;
46 class QBarSet;
46 class QBarSet;
47 class QAbstractBarSeries;
47 class QAbstractBarSeries;
48 class QPieSlice;
48 class QPieSlice;
49 class QLegend;
49 class QLegend;
50 class QPieSeries;
50 class QPieSeries;
51
51
52 class QLegendMarker;
52 class QLegendMarker;
53 class LegendMarkerItem;
53 class LegendMarkerItem;
54
54
55 class QLegendMarkerPrivate : public QObject
55 class QLegendMarkerPrivate : public QObject
56 {
56 {
57 Q_OBJECT
57 Q_OBJECT
58 public:
58 public:
59 explicit QLegendMarkerPrivate(QLegendMarker *q, QLegend *legend);
59 explicit QLegendMarkerPrivate(QLegendMarker *q, QLegend *legend);
60 virtual ~QLegendMarkerPrivate();
60 virtual ~QLegendMarkerPrivate();
61
61
62 // Helper for now. (or declare LegendLayout as friend)
62 // Helper for now. (or declare LegendLayout as friend)
63 LegendMarkerItem* item() const { return m_item; }
63 LegendMarkerItem* item() const { return m_item; }
64
64
65 virtual QAbstractSeries* series() = 0;
65 virtual QAbstractSeries* series() = 0;
66 virtual QObject* relatedObject() = 0;
66 virtual QObject* relatedObject() = 0;
67
67
68 void invalidateLegend();
68 void invalidateLegend();
69
69
70 public Q_SLOTS:
70 public Q_SLOTS:
71 virtual void updated() { invalidateLegend(); }
71 virtual void updated() = 0;
72
72
73 protected:
73 protected:
74 LegendMarkerItem *m_item;
74 LegendMarkerItem *m_item;
75 QLegend *m_legend;
75 QLegend *m_legend;
76
76
77 private:
77 private:
78 QLegendMarker *q_ptr;
78 QLegendMarker *q_ptr;
79
79
80 friend class QLegendPrivate;
80 friend class QLegendPrivate;
81 friend class LegendMarkerItem;
81 friend class LegendMarkerItem;
82 Q_DECLARE_PUBLIC(QLegendMarker)
82 Q_DECLARE_PUBLIC(QLegendMarker)
83 };
83 };
84
84
85 QTCOMMERCIALCHART_END_NAMESPACE
85 QTCOMMERCIALCHART_END_NAMESPACE
86
86
87 #endif // QLEGENDMARKERPRIVATE_H
87 #endif // QLEGENDMARKERPRIVATE_H
@@ -1,142 +1,143
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 /*!
28 /*!
29 \class QPieLegendMarker
29 \class QPieLegendMarker
30 \brief LegendMarker object
30 \brief LegendMarker object
31 \mainclass
31 \mainclass
32
32
33 QPieLegendMarker is related to QPieSeries. With QPieSeries, each slice of pie is related to one marker in QLegend.
33 QPieLegendMarker is related to QPieSeries. With QPieSeries, each slice of pie is related to one marker in QLegend.
34
34
35 \sa QLegend QPieSeries QPieSlice
35 \sa QLegend QPieSeries QPieSlice
36 */
36 */
37
37
38 /*!
38 /*!
39 \fn virtual LegendMarkerType QPieLegendMarker::type()
39 \fn virtual LegendMarkerType QPieLegendMarker::type()
40 Returns QLegendMarker::LegendMarkerTypePie
40 Returns QLegendMarker::LegendMarkerTypePie
41 */
41 */
42
42
43 /*!
43 /*!
44 Constructor
44 Constructor
45 */
45 */
46 QPieLegendMarker::QPieLegendMarker(QPieSeries *series, QPieSlice *slice, QLegend *legend, QObject *parent) :
46 QPieLegendMarker::QPieLegendMarker(QPieSeries *series, QPieSlice *slice, QLegend *legend, QObject *parent) :
47 QLegendMarker(*new QPieLegendMarkerPrivate(this,series,slice,legend), parent)
47 QLegendMarker(*new QPieLegendMarkerPrivate(this,series,slice,legend), parent)
48 {
48 {
49 d_ptr->updated();
49 }
50 }
50
51
51 /*!
52 /*!
52 Destructor
53 Destructor
53 */
54 */
54 QPieLegendMarker::~QPieLegendMarker()
55 QPieLegendMarker::~QPieLegendMarker()
55 {
56 {
56 }
57 }
57
58
58 /*!
59 /*!
59 \internal
60 \internal
60 */
61 */
61 QPieLegendMarker::QPieLegendMarker(QPieLegendMarkerPrivate &d, QObject *parent) :
62 QPieLegendMarker::QPieLegendMarker(QPieLegendMarkerPrivate &d, QObject *parent) :
62 QLegendMarker(d, parent)
63 QLegendMarker(d, parent)
63 {
64 {
64 }
65 }
65
66
66 /*!
67 /*!
67 Returns the related series of marker.
68 Returns the related series of marker.
68 */
69 */
69 QPieSeries* QPieLegendMarker::series()
70 QPieSeries* QPieLegendMarker::series()
70 {
71 {
71 Q_D(QPieLegendMarker);
72 Q_D(QPieLegendMarker);
72 return d->m_series;
73 return d->m_series;
73 }
74 }
74
75
75 /*!
76 /*!
76 Returns the related slice of marker.
77 Returns the related slice of marker.
77 */
78 */
78 QPieSlice* QPieLegendMarker::slice()
79 QPieSlice* QPieLegendMarker::slice()
79 {
80 {
80 Q_D(QPieLegendMarker);
81 Q_D(QPieLegendMarker);
81 return d->m_slice;
82 return d->m_slice;
82 }
83 }
83
84
84 ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
85 ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
85
86
86 QPieLegendMarkerPrivate::QPieLegendMarkerPrivate(QPieLegendMarker *q, QPieSeries *series, QPieSlice *slice, QLegend *legend) :
87 QPieLegendMarkerPrivate::QPieLegendMarkerPrivate(QPieLegendMarker *q, QPieSeries *series, QPieSlice *slice, QLegend *legend) :
87 QLegendMarkerPrivate(q,legend),
88 QLegendMarkerPrivate(q,legend),
89 q_ptr(q),
88 m_series(series),
90 m_series(series),
89 m_slice(slice)
91 m_slice(slice)
90 {
92 {
91 QObject::connect(m_slice, SIGNAL(labelChanged()), this, SLOT(updated()));
93 QObject::connect(m_slice, SIGNAL(labelChanged()), this, SLOT(updated()));
92 QObject::connect(m_slice, SIGNAL(brushChanged()), this, SLOT(updated()));
94 QObject::connect(m_slice, SIGNAL(brushChanged()), this, SLOT(updated()));
93 QObject::connect(m_slice, SIGNAL(penChanged()), this, SLOT(updated()));
95 QObject::connect(m_slice, SIGNAL(penChanged()), this, SLOT(updated()));
94 updated();
95 }
96 }
96
97
97 QPieLegendMarkerPrivate::~QPieLegendMarkerPrivate()
98 QPieLegendMarkerPrivate::~QPieLegendMarkerPrivate()
98 {
99 {
99 }
100 }
100
101
101 QPieSeries* QPieLegendMarkerPrivate::series()
102 QPieSeries* QPieLegendMarkerPrivate::series()
102 {
103 {
103 return m_series;
104 return m_series;
104 }
105 }
105
106
106 QObject* QPieLegendMarkerPrivate::relatedObject()
107 QObject* QPieLegendMarkerPrivate::relatedObject()
107 {
108 {
108 return m_slice;
109 return m_slice;
109 }
110 }
110
111
111 void QPieLegendMarkerPrivate::updated()
112 void QPieLegendMarkerPrivate::updated()
112 {
113 {
113 bool labelChanged = false;
114 bool labelChanged = false;
114 bool brushChanged = false;
115 bool brushChanged = false;
115 bool penChanged = false;
116 bool penChanged = false;
116
117
117 if (m_item->pen() != m_slice->pen()) {
118 if (m_item->pen() != m_slice->pen()) {
118 m_item->setPen(m_slice->pen());
119 m_item->setPen(m_slice->pen());
119 penChanged = true;
120 penChanged = true;
120 }
121 }
121 if (m_item->brush() != m_slice->brush()) {
122 if (m_item->brush() != m_slice->brush()) {
122 m_item->setBrush(m_slice->brush());
123 m_item->setBrush(m_slice->brush());
123 brushChanged = true;
124 brushChanged = true;
124 }
125 }
125 if (m_item->label() != m_slice->label()) {
126 if (m_item->label() != m_slice->label()) {
126 m_item->setLabel(m_slice->label());
127 m_item->setLabel(m_slice->label());
127 labelChanged = true;
128 labelChanged = true;
128 }
129 }
129 invalidateLegend();
130 invalidateLegend();
130
131
131 if (labelChanged)
132 if (labelChanged)
132 emit q_ptr->labelChanged();
133 emit q_ptr->labelChanged();
133 if (brushChanged)
134 if (brushChanged)
134 emit q_ptr->brushChanged();
135 emit q_ptr->brushChanged();
135 if (penChanged)
136 if (penChanged)
136 emit q_ptr->penChanged();
137 emit q_ptr->penChanged();
137 }
138 }
138
139
139 #include "moc_qpielegendmarker.cpp"
140 #include "moc_qpielegendmarker.cpp"
140 #include "moc_qpielegendmarker_p.cpp"
141 #include "moc_qpielegendmarker_p.cpp"
141
142
142 QTCOMMERCIALCHART_END_NAMESPACE
143 QTCOMMERCIALCHART_END_NAMESPACE
@@ -1,135 +1,134
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 /*!
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 Constructor
44 Constructor
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 }
50 }
50
51
51 /*!
52 /*!
52 Destructor
53 Destructor
53 */
54 */
54 QXYLegendMarker::~QXYLegendMarker()
55 QXYLegendMarker::~QXYLegendMarker()
55 {
56 {
56 }
57 }
57
58
58 /*!
59 /*!
59 \internal
60 \internal
60 */
61 */
61 QXYLegendMarker::QXYLegendMarker(QXYLegendMarkerPrivate &d, QObject *parent) :
62 QXYLegendMarker::QXYLegendMarker(QXYLegendMarkerPrivate &d, QObject *parent) :
62 QLegendMarker(d, parent)
63 QLegendMarker(d, parent)
63 {
64 {
64 }
65 }
65
66
66 /*!
67 /*!
67 Returns the related series
68 Returns the related series
68 */
69 */
69 QXYSeries* QXYLegendMarker::series()
70 QXYSeries* QXYLegendMarker::series()
70 {
71 {
71 Q_D(QXYLegendMarker);
72 Q_D(QXYLegendMarker);
72 return d->m_series;
73 return d->m_series;
73 }
74 }
74
75
75 ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
76 ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
76
77
77 QXYLegendMarkerPrivate::QXYLegendMarkerPrivate(QXYLegendMarker *q, QXYSeries *series, QLegend *legend) :
78 QXYLegendMarkerPrivate::QXYLegendMarkerPrivate(QXYLegendMarker *q, QXYSeries *series, QLegend *legend) :
78 QLegendMarkerPrivate(q,legend),
79 QLegendMarkerPrivate(q,legend),
80 q_ptr(q),
79 m_series(series)
81 m_series(series)
80 {
82 {
81 QObject::connect(m_series, SIGNAL(nameChanged()), this, SLOT(updated()));
83 QObject::connect(m_series, SIGNAL(nameChanged()), this, SLOT(updated()));
82 QObject::connect(m_series->d_func(), SIGNAL(updated()), this, SLOT(updated()));
84 QObject::connect(m_series->d_func(), SIGNAL(updated()), this, SLOT(updated()));
83 updated();
84 }
85 }
85
86
86 QXYLegendMarkerPrivate::~QXYLegendMarkerPrivate()
87 QXYLegendMarkerPrivate::~QXYLegendMarkerPrivate()
87 {
88 {
88 }
89 }
89
90
90 QAbstractSeries* QXYLegendMarkerPrivate::series()
91 QAbstractSeries* QXYLegendMarkerPrivate::series()
91 {
92 {
92 return m_series;
93 return m_series;
93 }
94 }
94
95
95 QObject* QXYLegendMarkerPrivate::relatedObject()
96 QObject* QXYLegendMarkerPrivate::relatedObject()
96 {
97 {
97 return m_series;
98 return m_series;
98 }
99 }
99
100
100 void QXYLegendMarkerPrivate::updated()
101 void QXYLegendMarkerPrivate::updated()
101 {
102 {
102 bool labelChanged = false;
103 bool labelChanged = false;
103 bool brushChanged = false;
104 bool brushChanged = false;
104
105
105 if (m_item->label() != m_series->name()) {
106 if (m_item->label() != m_series->name()) {
106 m_item->setLabel(m_series->name());
107 m_item->setLabel(m_series->name());
107 labelChanged = true;
108 labelChanged = true;
108 }
109 }
109
110
110 if (m_series->type()== QAbstractSeries::SeriesTypeScatter) {
111 if (m_series->type()== QAbstractSeries::SeriesTypeScatter) {
111 if (m_item->brush() != m_series->brush()) {
112 if (m_item->brush() != m_series->brush()) {
112 m_item->setBrush(m_series->brush());
113 m_item->setBrush(m_series->brush());
113 brushChanged = true;
114 brushChanged = true;
114 }
115 }
115 } else {
116 } else {
116 if (m_item->brush().color() != m_series->pen().color()) {
117 if (m_item->brush().color() != m_series->pen().color()) {
117 QBrush b = m_item->brush();
118 m_item->setBrush(QBrush(m_series->pen().color()));
118 b.setColor(m_series->pen().color());
119 m_item->setBrush(b);
120 brushChanged = true;
119 brushChanged = true;
121 }
120 }
122 }
121 }
123 invalidateLegend();
122 invalidateLegend();
124
123
125 if (labelChanged)
124 if (labelChanged)
126 emit q_ptr->labelChanged();
125 emit q_ptr->labelChanged();
127 if (brushChanged)
126 if (brushChanged)
128 emit q_ptr->brushChanged();
127 emit q_ptr->brushChanged();
129 }
128 }
130
129
131 #include "moc_qxylegendmarker.cpp"
130 #include "moc_qxylegendmarker.cpp"
132 #include "moc_qxylegendmarker_p.cpp"
131 #include "moc_qxylegendmarker_p.cpp"
133
132
134 QTCOMMERCIALCHART_END_NAMESPACE
133 QTCOMMERCIALCHART_END_NAMESPACE
135
134
General Comments 0
You need to be logged in to leave comments. Login now