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