@@ -1,79 +1,89 | |||||
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 | #include <QDebug> |
|
25 | #include <QDebug> | |
26 |
|
26 | |||
27 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
27 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
28 |
|
28 | |||
29 | QAreaLegendMarker::QAreaLegendMarker(QAreaSeries* series, QLegend *legend, QObject *parent) : |
|
29 | QAreaLegendMarker::QAreaLegendMarker(QAreaSeries* series, QLegend *legend, QObject *parent) : | |
30 | QLegendMarker(*new QAreaLegendMarkerPrivate(this,series,legend), parent) |
|
30 | QLegendMarker(*new QAreaLegendMarkerPrivate(this,series,legend), parent) | |
31 | { |
|
31 | { | |
32 | } |
|
32 | } | |
33 |
|
33 | |||
34 | QAreaLegendMarker::~QAreaLegendMarker() |
|
34 | QAreaLegendMarker::~QAreaLegendMarker() | |
35 | { |
|
35 | { | |
36 | // qDebug() << "deleting Area marker" << this; |
|
36 | // qDebug() << "deleting Area marker" << this; | |
37 | } |
|
37 | } | |
38 |
|
38 | |||
39 | /*! |
|
39 | /*! | |
40 | \internal |
|
40 | \internal | |
41 | */ |
|
41 | */ | |
42 | QAreaLegendMarker::QAreaLegendMarker(QAreaLegendMarkerPrivate &d, QObject *parent) : |
|
42 | QAreaLegendMarker::QAreaLegendMarker(QAreaLegendMarkerPrivate &d, QObject *parent) : | |
43 | QLegendMarker(d, parent) |
|
43 | QLegendMarker(d, parent) | |
44 | { |
|
44 | { | |
45 | } |
|
45 | } | |
46 |
|
46 | |||
47 | QAreaSeries* QAreaLegendMarker::series() |
|
47 | QAreaSeries* QAreaLegendMarker::series() | |
48 | { |
|
48 | { | |
49 | Q_D(QAreaLegendMarker); |
|
49 | Q_D(QAreaLegendMarker); | |
50 | return d->m_series; |
|
50 | return d->m_series; | |
51 | } |
|
51 | } | |
52 |
|
52 | |||
53 | //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
|
53 | //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// | |
54 |
|
54 | |||
55 | QAreaLegendMarkerPrivate::QAreaLegendMarkerPrivate(QAreaLegendMarker *q, QAreaSeries *series, QLegend *legend) : |
|
55 | QAreaLegendMarkerPrivate::QAreaLegendMarkerPrivate(QAreaLegendMarker *q, QAreaSeries *series, QLegend *legend) : | |
56 | QLegendMarkerPrivate(q,legend), |
|
56 | QLegendMarkerPrivate(q,legend), | |
57 | m_series(series) |
|
57 | m_series(series) | |
58 | { |
|
58 | { | |
59 | QObject::connect(m_series->d_func(),SIGNAL(updated()), this, SLOT(updated())); |
|
59 | QObject::connect(m_series->d_func(),SIGNAL(updated()), this, SLOT(updated())); | |
60 | QObject::connect(m_series, SIGNAL(nameChanged()), this, SLOT(updated())); |
|
60 | QObject::connect(m_series, SIGNAL(nameChanged()), this, SLOT(updated())); | |
61 | updated(); |
|
61 | updated(); | |
62 | } |
|
62 | } | |
63 |
|
63 | |||
64 | QAreaLegendMarkerPrivate::~QAreaLegendMarkerPrivate() |
|
64 | QAreaLegendMarkerPrivate::~QAreaLegendMarkerPrivate() | |
65 | { |
|
65 | { | |
66 | QObject::disconnect(m_series->d_func(),SIGNAL(updated()), this, SLOT(updated())); |
|
66 | QObject::disconnect(m_series->d_func(),SIGNAL(updated()), this, SLOT(updated())); | |
67 | QObject::disconnect(m_series, SIGNAL(nameChanged()), this, SLOT(updated())); |
|
67 | QObject::disconnect(m_series, SIGNAL(nameChanged()), this, SLOT(updated())); | |
68 | } |
|
68 | } | |
69 |
|
69 | |||
|
70 | QAreaSeries* QAreaLegendMarkerPrivate::series() | |||
|
71 | { | |||
|
72 | return m_series; | |||
|
73 | } | |||
|
74 | ||||
|
75 | QObject* QAreaLegendMarkerPrivate::relatedObject() | |||
|
76 | { | |||
|
77 | return m_series; | |||
|
78 | } | |||
|
79 | ||||
70 | void QAreaLegendMarkerPrivate::updated() |
|
80 | void QAreaLegendMarkerPrivate::updated() | |
71 | { |
|
81 | { | |
72 | m_item->setBrush(m_series->brush()); |
|
82 | m_item->setBrush(m_series->brush()); | |
73 | m_item->setLabel(m_series->name()); |
|
83 | m_item->setLabel(m_series->name()); | |
74 | } |
|
84 | } | |
75 |
|
85 | |||
76 | #include "moc_qarealegendmarker.cpp" |
|
86 | #include "moc_qarealegendmarker.cpp" | |
77 | #include "moc_qarealegendmarker_p.cpp" |
|
87 | #include "moc_qarealegendmarker_p.cpp" | |
78 |
|
88 | |||
79 | QTCOMMERCIALCHART_END_NAMESPACE |
|
89 | QTCOMMERCIALCHART_END_NAMESPACE |
@@ -1,65 +1,69 | |||||
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 QAREALEGENDMARKER_P_H |
|
30 | #ifndef QAREALEGENDMARKER_P_H | |
31 | #define QAREALEGENDMARKER_P_H |
|
31 | #define QAREALEGENDMARKER_P_H | |
32 |
|
32 | |||
33 | #include "qchartglobal.h" |
|
33 | #include "qchartglobal.h" | |
34 | #include "qlegendmarker_p.h" |
|
34 | #include "qlegendmarker_p.h" | |
35 | #include "legendmarkeritem_p.h" |
|
35 | #include "legendmarkeritem_p.h" | |
36 | #include <QAreaSeries> |
|
36 | #include <QAreaSeries> | |
37 |
|
37 | |||
38 | #include <QDebug> |
|
38 | #include <QDebug> | |
39 |
|
39 | |||
40 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
40 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
41 |
|
41 | |||
42 | class QAreaLegendMarker; |
|
42 | class QAreaLegendMarker; | |
43 |
|
43 | |||
44 | class QAreaLegendMarkerPrivate : public QLegendMarkerPrivate |
|
44 | class QAreaLegendMarkerPrivate : public QLegendMarkerPrivate | |
45 | { |
|
45 | { | |
46 | Q_OBJECT |
|
46 | Q_OBJECT | |
47 | public: |
|
47 | public: | |
48 | explicit QAreaLegendMarkerPrivate(QAreaLegendMarker *q, QAreaSeries *series, QLegend *legend); |
|
48 | explicit QAreaLegendMarkerPrivate(QAreaLegendMarker *q, QAreaSeries *series, QLegend *legend); | |
49 | virtual ~QAreaLegendMarkerPrivate(); |
|
49 | virtual ~QAreaLegendMarkerPrivate(); | |
50 |
|
50 | |||
|
51 | // internal | |||
|
52 | virtual QAreaSeries* series(); | |||
|
53 | virtual QObject* relatedObject(); | |||
|
54 | ||||
51 | public Q_SLOTS: |
|
55 | public Q_SLOTS: | |
52 | virtual void updated(); |
|
56 | virtual void updated(); | |
53 |
|
57 | |||
54 | private: |
|
58 | private: | |
55 | QAreaLegendMarker *q_ptr; |
|
59 | QAreaLegendMarker *q_ptr; | |
56 |
|
60 | |||
57 | QAreaSeries* m_series; |
|
61 | QAreaSeries* m_series; | |
58 |
|
62 | |||
59 | friend class QLegendPrivate; // TODO: Is this needed? |
|
63 | friend class QLegendPrivate; // TODO: Is this needed? | |
60 | Q_DECLARE_PUBLIC(QAreaLegendMarker) |
|
64 | Q_DECLARE_PUBLIC(QAreaLegendMarker) | |
61 | }; |
|
65 | }; | |
62 |
|
66 | |||
63 | QTCOMMERCIALCHART_END_NAMESPACE |
|
67 | QTCOMMERCIALCHART_END_NAMESPACE | |
64 |
|
68 | |||
65 | #endif // QAREALEGENDMARKER_P_H |
|
69 | #endif // QAREALEGENDMARKER_P_H |
@@ -1,90 +1,100 | |||||
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 | #include <QDebug> |
|
25 | #include <QDebug> | |
26 |
|
26 | |||
27 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
27 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
28 |
|
28 | |||
29 | QBarLegendMarker::QBarLegendMarker(QAbstractBarSeries* series, QBarSet* barset, QLegend *legend, QObject *parent) : |
|
29 | QBarLegendMarker::QBarLegendMarker(QAbstractBarSeries* series, QBarSet* barset, QLegend *legend, QObject *parent) : | |
30 | QLegendMarker(*new QBarLegendMarkerPrivate(this,series,barset,legend), parent) |
|
30 | QLegendMarker(*new QBarLegendMarkerPrivate(this,series,barset,legend), parent) | |
31 | { |
|
31 | { | |
32 | } |
|
32 | } | |
33 |
|
33 | |||
34 | QBarLegendMarker::~QBarLegendMarker() |
|
34 | QBarLegendMarker::~QBarLegendMarker() | |
35 | { |
|
35 | { | |
36 | // qDebug() << "deleting bar marker" << this; |
|
36 | // qDebug() << "deleting bar marker" << this; | |
37 | } |
|
37 | } | |
38 |
|
38 | |||
39 | /*! |
|
39 | /*! | |
40 | \internal |
|
40 | \internal | |
41 | */ |
|
41 | */ | |
42 | QBarLegendMarker::QBarLegendMarker(QBarLegendMarkerPrivate &d, QObject *parent) : |
|
42 | QBarLegendMarker::QBarLegendMarker(QBarLegendMarkerPrivate &d, QObject *parent) : | |
43 | QLegendMarker(d, parent) |
|
43 | QLegendMarker(d, parent) | |
44 | { |
|
44 | { | |
45 | } |
|
45 | } | |
46 |
|
46 | |||
47 | QAbstractBarSeries *QBarLegendMarker::series() |
|
47 | QAbstractBarSeries *QBarLegendMarker::series() | |
48 | { |
|
48 | { | |
49 | Q_D(QBarLegendMarker); |
|
49 | Q_D(QBarLegendMarker); | |
50 | return d->m_series; |
|
50 | return d->m_series; | |
51 | } |
|
51 | } | |
52 |
|
52 | |||
53 | QBarSet* QBarLegendMarker::barset() |
|
53 | QBarSet* QBarLegendMarker::barset() | |
54 | { |
|
54 | { | |
55 | Q_D(QBarLegendMarker); |
|
55 | Q_D(QBarLegendMarker); | |
56 | return d->m_barset; |
|
56 | return d->m_barset; | |
57 | } |
|
57 | } | |
58 |
|
58 | |||
59 | //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
|
59 | //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// | |
60 |
|
60 | |||
61 | QBarLegendMarkerPrivate::QBarLegendMarkerPrivate(QBarLegendMarker *q, QAbstractBarSeries *series, QBarSet *barset, QLegend *legend) : |
|
61 | QBarLegendMarkerPrivate::QBarLegendMarkerPrivate(QBarLegendMarker *q, QAbstractBarSeries *series, QBarSet *barset, QLegend *legend) : | |
62 | QLegendMarkerPrivate(q,legend), |
|
62 | QLegendMarkerPrivate(q,legend), | |
63 | m_series(series), |
|
63 | m_series(series), | |
64 | m_barset(barset) |
|
64 | m_barset(barset) | |
65 | { |
|
65 | { | |
66 | QObject::connect(m_barset, SIGNAL(penChanged()), this, SLOT(updated())); |
|
66 | QObject::connect(m_barset, SIGNAL(penChanged()), this, SLOT(updated())); | |
67 | QObject::connect(m_barset, SIGNAL(labelChanged()), this, SLOT(updated())); |
|
67 | QObject::connect(m_barset, SIGNAL(labelChanged()), this, SLOT(updated())); | |
68 | QObject::connect(m_barset, SIGNAL(brushChanged()), this, SLOT(updated())); |
|
68 | QObject::connect(m_barset, SIGNAL(brushChanged()), this, SLOT(updated())); | |
69 | updated(); |
|
69 | updated(); | |
70 | } |
|
70 | } | |
71 |
|
71 | |||
72 | QBarLegendMarkerPrivate::~QBarLegendMarkerPrivate() |
|
72 | QBarLegendMarkerPrivate::~QBarLegendMarkerPrivate() | |
73 | { |
|
73 | { | |
74 | QObject::disconnect(m_barset, SIGNAL(labelChanged()), this, SLOT(updated())); |
|
74 | QObject::disconnect(m_barset, SIGNAL(labelChanged()), this, SLOT(updated())); | |
75 | QObject::disconnect(m_barset, SIGNAL(brushChanged()), this, SLOT(updated())); |
|
75 | QObject::disconnect(m_barset, SIGNAL(brushChanged()), this, SLOT(updated())); | |
76 | QObject::disconnect(m_barset, SIGNAL(penChanged()), this, SLOT(updated())); |
|
76 | QObject::disconnect(m_barset, SIGNAL(penChanged()), this, SLOT(updated())); | |
77 | } |
|
77 | } | |
78 |
|
78 | |||
|
79 | QAbstractBarSeries* QBarLegendMarkerPrivate::series() | |||
|
80 | { | |||
|
81 | return m_series; | |||
|
82 | } | |||
|
83 | ||||
|
84 | QObject* QBarLegendMarkerPrivate::relatedObject() | |||
|
85 | { | |||
|
86 | return m_barset; | |||
|
87 | } | |||
|
88 | ||||
79 | void QBarLegendMarkerPrivate::updated() |
|
89 | void QBarLegendMarkerPrivate::updated() | |
80 | { |
|
90 | { | |
81 | m_item->setPen(m_barset->pen()); |
|
91 | m_item->setPen(m_barset->pen()); | |
82 | m_item->setBrush(m_barset->brush()); |
|
92 | m_item->setBrush(m_barset->brush()); | |
83 | m_item->setLabel(m_barset->label()); |
|
93 | m_item->setLabel(m_barset->label()); | |
84 | } |
|
94 | } | |
85 |
|
95 | |||
86 | #include "moc_qbarlegendmarker.cpp" |
|
96 | #include "moc_qbarlegendmarker.cpp" | |
87 | #include "moc_qbarlegendmarker_p.cpp" |
|
97 | #include "moc_qbarlegendmarker_p.cpp" | |
88 |
|
98 | |||
89 | QTCOMMERCIALCHART_END_NAMESPACE |
|
99 | QTCOMMERCIALCHART_END_NAMESPACE | |
90 |
|
100 |
@@ -1,67 +1,70 | |||||
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 QBARLEGENDMARKER_P_H |
|
30 | #ifndef QBARLEGENDMARKER_P_H | |
31 | #define QBARLEGENDMARKER_P_H |
|
31 | #define QBARLEGENDMARKER_P_H | |
32 |
|
32 | |||
33 | #include "qchartglobal.h" |
|
33 | #include "qchartglobal.h" | |
34 | #include "qlegendmarker_p.h" |
|
34 | #include "qlegendmarker_p.h" | |
35 | #include "legendmarkeritem_p.h" |
|
35 | #include "legendmarkeritem_p.h" | |
36 | #include <QAbstractBarSeries> |
|
36 | #include <QAbstractBarSeries> | |
37 | #include <QBarSet> |
|
37 | #include <QBarSet> | |
38 |
|
38 | |||
39 | #include <QDebug> |
|
39 | #include <QDebug> | |
40 |
|
40 | |||
41 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
41 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
42 |
|
42 | |||
43 | class QBarLegendMarker; |
|
43 | class QBarLegendMarker; | |
44 |
|
44 | |||
45 | class QBarLegendMarkerPrivate : public QLegendMarkerPrivate |
|
45 | class QBarLegendMarkerPrivate : public QLegendMarkerPrivate | |
46 | { |
|
46 | { | |
47 | Q_OBJECT |
|
47 | Q_OBJECT | |
48 | public: |
|
48 | public: | |
49 | explicit QBarLegendMarkerPrivate(QBarLegendMarker *q, QAbstractBarSeries *series, QBarSet *barset, QLegend *legend); |
|
49 | explicit QBarLegendMarkerPrivate(QBarLegendMarker *q, QAbstractBarSeries *series, QBarSet *barset, QLegend *legend); | |
50 | virtual ~QBarLegendMarkerPrivate(); |
|
50 | virtual ~QBarLegendMarkerPrivate(); | |
51 |
|
51 | |||
|
52 | virtual QAbstractBarSeries* series(); | |||
|
53 | virtual QObject* relatedObject(); | |||
|
54 | ||||
52 | public Q_SLOTS: |
|
55 | public Q_SLOTS: | |
53 | virtual void updated(); |
|
56 | virtual void updated(); | |
54 |
|
57 | |||
55 | private: |
|
58 | private: | |
56 | QBarLegendMarker *q_ptr; |
|
59 | QBarLegendMarker *q_ptr; | |
57 |
|
60 | |||
58 | QAbstractBarSeries* m_series; |
|
61 | QAbstractBarSeries* m_series; | |
59 | QBarSet* m_barset; |
|
62 | QBarSet* m_barset; | |
60 |
|
63 | |||
61 | friend class QLegendPrivate; // TODO: Is this needed? |
|
64 | friend class QLegendPrivate; // TODO: Is this needed? | |
62 | Q_DECLARE_PUBLIC(QBarLegendMarker) |
|
65 | Q_DECLARE_PUBLIC(QBarLegendMarker) | |
63 | }; |
|
66 | }; | |
64 |
|
67 | |||
65 | QTCOMMERCIALCHART_END_NAMESPACE |
|
68 | QTCOMMERCIALCHART_END_NAMESPACE | |
66 |
|
69 | |||
67 | #endif // QBARLEGENDMARKER_P_H |
|
70 | #endif // QBARLEGENDMARKER_P_H |
@@ -1,626 +1,671 | |||||
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 "qxyseries.h" |
|
27 | #include "qxyseries.h" | |
28 | #include "qlineseries.h" |
|
28 | #include "qlineseries.h" | |
29 | #include "qareaseries.h" |
|
29 | #include "qareaseries.h" | |
30 | #include "qscatterseries.h" |
|
30 | #include "qscatterseries.h" | |
31 | #include "qsplineseries.h" |
|
31 | #include "qsplineseries.h" | |
32 | #include "qabstractbarseries.h" |
|
32 | #include "qabstractbarseries.h" | |
33 | #include "qstackedbarseries.h" |
|
33 | #include "qstackedbarseries.h" | |
34 | #include "qpercentbarseries.h" |
|
34 | #include "qpercentbarseries.h" | |
35 | #include "qbarset.h" |
|
35 | #include "qbarset.h" | |
36 | #include "qpieseries.h" |
|
36 | #include "qpieseries.h" | |
37 | #include "qpieseries_p.h" |
|
37 | #include "qpieseries_p.h" | |
38 | #include "qpieslice.h" |
|
38 | #include "qpieslice.h" | |
39 | #include "chartpresenter_p.h" |
|
39 | #include "chartpresenter_p.h" | |
40 | #include "chartlayout_p.h" |
|
40 | #include "chartlayout_p.h" | |
41 | #include <QPainter> |
|
41 | #include <QPainter> | |
42 | #include <QPen> |
|
42 | #include <QPen> | |
43 | #include <QTimer> |
|
43 | #include <QTimer> | |
44 | #include <QGraphicsSceneEvent> |
|
44 | #include <QGraphicsSceneEvent> | |
45 |
|
45 | |||
46 |
#include |
|
46 | #include "qlegendmarker.h" | |
47 | #include "qlegendmarker_p.h" |
|
47 | #include "qlegendmarker_p.h" | |
48 | #include "legendmarkeritem_p.h" |
|
48 | #include "legendmarkeritem_p.h" | |
49 |
|
49 | |||
50 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
50 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
51 |
|
51 | |||
52 | /*! |
|
52 | /*! | |
53 | \class QLegend |
|
53 | \class QLegend | |
54 | \brief Legend object |
|
54 | \brief Legend object | |
55 | \mainclass |
|
55 | \mainclass | |
56 |
|
56 | |||
57 | QLegend is a graphical object, whics displays legend of the chart. Legend state is updated by QChart, when |
|
57 | QLegend is a graphical object, whics displays legend of the chart. Legend state is updated by QChart, when | |
58 | series have been changed. By default, legend is drawn by QChart, but user can set a new parent to legend and |
|
58 | series have been changed. By default, legend is drawn by QChart, but user can set a new parent to legend and | |
59 | handle the drawing manually. |
|
59 | handle the drawing manually. | |
60 | User isn't supposed to create or delete legend objects, but can reference it via QChart class. |
|
60 | User isn't supposed to create or delete legend objects, but can reference it via QChart class. | |
61 |
|
61 | |||
62 | \image examples_percentbarchart_legend.png |
|
62 | \image examples_percentbarchart_legend.png | |
63 |
|
63 | |||
64 | \sa QChart |
|
64 | \sa QChart | |
65 | */ |
|
65 | */ | |
66 | /*! |
|
66 | /*! | |
67 | \qmlclass Legend QLegend |
|
67 | \qmlclass Legend QLegend | |
68 | \brief Legend is part of QtCommercial Chart QML API. |
|
68 | \brief Legend is part of QtCommercial Chart QML API. | |
69 |
|
69 | |||
70 | Legend is a graphical object, whics displays legend of the chart. Legend state is updated by ChartView, when |
|
70 | Legend is a graphical object, whics displays legend of the chart. Legend state is updated by ChartView, when | |
71 | series have been changed. Legend is used via ChartView class. For example: |
|
71 | series have been changed. Legend is used via ChartView class. For example: | |
72 | \code |
|
72 | \code | |
73 | ChartView { |
|
73 | ChartView { | |
74 | legend.visible: true |
|
74 | legend.visible: true | |
75 | legend.alignment: Qt.AlignBottom |
|
75 | legend.alignment: Qt.AlignBottom | |
76 | // Add a few series... |
|
76 | // Add a few series... | |
77 | } |
|
77 | } | |
78 | \endcode |
|
78 | \endcode | |
79 |
|
79 | |||
80 | \image examples_percentbarchart_legend.png |
|
80 | \image examples_percentbarchart_legend.png | |
81 | */ |
|
81 | */ | |
82 |
|
82 | |||
83 | /*! |
|
83 | /*! | |
84 | \property QLegend::alignment |
|
84 | \property QLegend::alignment | |
85 | \brief The alignment of the legend. |
|
85 | \brief The alignment of the legend. | |
86 |
|
86 | |||
87 | Legend paints on the defined position in the chart. The following alignments are supported: |
|
87 | Legend paints on the defined position in the chart. The following alignments are supported: | |
88 | Qt::AlignTop, Qt::AlignBottom, Qt::AlignLeft, Qt::AlignRight. If you set more than one flag the result is undefined. |
|
88 | Qt::AlignTop, Qt::AlignBottom, Qt::AlignLeft, Qt::AlignRight. If you set more than one flag the result is undefined. | |
89 | */ |
|
89 | */ | |
90 | /*! |
|
90 | /*! | |
91 | \qmlproperty Qt.Alignment Legend::alignment |
|
91 | \qmlproperty Qt.Alignment Legend::alignment | |
92 | \brief The alignment of the legend. |
|
92 | \brief The alignment of the legend. | |
93 |
|
93 | |||
94 | Legend paints on the defined position in the chart. The following alignments are supported: |
|
94 | Legend paints on the defined position in the chart. The following alignments are supported: | |
95 | Qt.AlignTop, Qt.AlignBottom, Qt.AlignLeft, Qt.AlignRight. If you set more than one flag the result is undefined. |
|
95 | Qt.AlignTop, Qt.AlignBottom, Qt.AlignLeft, Qt.AlignRight. If you set more than one flag the result is undefined. | |
96 | */ |
|
96 | */ | |
97 |
|
97 | |||
98 | /*! |
|
98 | /*! | |
99 | \property QLegend::backgroundVisible |
|
99 | \property QLegend::backgroundVisible | |
100 | Whether the legend background is visible or not. |
|
100 | Whether the legend background is visible or not. | |
101 | */ |
|
101 | */ | |
102 | /*! |
|
102 | /*! | |
103 | \qmlproperty bool Legend::backgroundVisible |
|
103 | \qmlproperty bool Legend::backgroundVisible | |
104 | Whether the legend background is visible or not. |
|
104 | Whether the legend background is visible or not. | |
105 | */ |
|
105 | */ | |
106 |
|
106 | |||
107 | /*! |
|
107 | /*! | |
108 | \property QLegend::color |
|
108 | \property QLegend::color | |
109 | The color of the legend, i.e. the background (brush) color. Note that if you change the color |
|
109 | The color of the legend, i.e. the background (brush) color. Note that if you change the color | |
110 | of the legend, the style of the legend brush is set to Qt::SolidPattern. |
|
110 | of the legend, the style of the legend brush is set to Qt::SolidPattern. | |
111 | */ |
|
111 | */ | |
112 | /*! |
|
112 | /*! | |
113 | \qmlproperty color Legend::color |
|
113 | \qmlproperty color Legend::color | |
114 | The color of the legend, i.e. the background (brush) color. |
|
114 | The color of the legend, i.e. the background (brush) color. | |
115 | */ |
|
115 | */ | |
116 |
|
116 | |||
117 | /*! |
|
117 | /*! | |
118 | \property QLegend::borderColor |
|
118 | \property QLegend::borderColor | |
119 | The border color of the legend, i.e. the line color. |
|
119 | The border color of the legend, i.e. the line color. | |
120 | */ |
|
120 | */ | |
121 | /*! |
|
121 | /*! | |
122 | \qmlproperty color Legend::borderColor |
|
122 | \qmlproperty color Legend::borderColor | |
123 | The border color of the legend, i.e. the line color. |
|
123 | The border color of the legend, i.e. the line color. | |
124 | */ |
|
124 | */ | |
125 |
|
125 | |||
126 | /*! |
|
126 | /*! | |
127 | \property QLegend::font |
|
127 | \property QLegend::font | |
128 | The font of markers used by legend |
|
128 | The font of markers used by legend | |
129 | */ |
|
129 | */ | |
130 | /*! |
|
130 | /*! | |
131 | \qmlproperty Font Legend::font |
|
131 | \qmlproperty Font Legend::font | |
132 | The font of markers used by legend |
|
132 | The font of markers used by legend | |
133 | */ |
|
133 | */ | |
134 |
|
134 | |||
135 | /*! |
|
135 | /*! | |
136 | \property QLegend::labelColor |
|
136 | \property QLegend::labelColor | |
137 | The color of brush used to draw labels. |
|
137 | The color of brush used to draw labels. | |
138 | */ |
|
138 | */ | |
139 | /*! |
|
139 | /*! | |
140 | \qmlproperty color QLegend::labelColor |
|
140 | \qmlproperty color QLegend::labelColor | |
141 | The color of brush used to draw labels. |
|
141 | The color of brush used to draw labels. | |
142 | */ |
|
142 | */ | |
143 |
|
143 | |||
144 | /*! |
|
144 | /*! | |
145 | \fn void QLegend::backgroundVisibleChanged(bool) |
|
145 | \fn void QLegend::backgroundVisibleChanged(bool) | |
146 | The visibility of the legend background changed to \a visible. |
|
146 | The visibility of the legend background changed to \a visible. | |
147 | */ |
|
147 | */ | |
148 |
|
148 | |||
149 | /*! |
|
149 | /*! | |
150 | \fn void QLegend::colorChanged(QColor) |
|
150 | \fn void QLegend::colorChanged(QColor) | |
151 | The color of the legend background changed to \a color. |
|
151 | The color of the legend background changed to \a color. | |
152 | */ |
|
152 | */ | |
153 |
|
153 | |||
154 | /*! |
|
154 | /*! | |
155 | \fn void QLegend::borderColorChanged(QColor) |
|
155 | \fn void QLegend::borderColorChanged(QColor) | |
156 | The border color of the legend background changed to \a color. |
|
156 | The border color of the legend background changed to \a color. | |
157 | */ |
|
157 | */ | |
158 |
|
158 | |||
159 | /*! |
|
159 | /*! | |
160 | \fn void QLegend::fontChanged(QFont) |
|
160 | \fn void QLegend::fontChanged(QFont) | |
161 | The font of markers of the legend changed to \a font. |
|
161 | The font of markers of the legend changed to \a font. | |
162 | */ |
|
162 | */ | |
163 |
|
163 | |||
164 | /*! |
|
164 | /*! | |
165 | \fn void QLegend::labelColorChanged(QColor color) |
|
165 | \fn void QLegend::labelColorChanged(QColor color) | |
166 | This signal is emitted when the color of brush used to draw labels has changed to \a color. |
|
166 | This signal is emitted when the color of brush used to draw labels has changed to \a color. | |
167 | */ |
|
167 | */ | |
168 |
|
168 | |||
169 | /*! |
|
169 | /*! | |
170 | Constructs the legend object and sets the parent to \a parent |
|
170 | Constructs the legend object and sets the parent to \a parent | |
171 | */ |
|
171 | */ | |
172 |
|
172 | |||
173 | QLegend::QLegend(QChart *chart): QGraphicsWidget(chart), |
|
173 | QLegend::QLegend(QChart *chart): QGraphicsWidget(chart), | |
174 | d_ptr(new QLegendPrivate(chart->d_ptr->m_presenter, chart, this)) |
|
174 | d_ptr(new QLegendPrivate(chart->d_ptr->m_presenter, chart, this)) | |
175 | { |
|
175 | { | |
176 | setZValue(ChartPresenter::LegendZValue); |
|
176 | setZValue(ChartPresenter::LegendZValue); | |
177 | setFlags(QGraphicsItem::ItemClipsChildrenToShape); |
|
177 | setFlags(QGraphicsItem::ItemClipsChildrenToShape); | |
178 | QObject::connect(chart->d_ptr->m_dataset, SIGNAL(seriesAdded(QAbstractSeries*,Domain*)), d_ptr.data(), SLOT(handleSeriesAdded(QAbstractSeries*))); |
|
178 | QObject::connect(chart->d_ptr->m_dataset, SIGNAL(seriesAdded(QAbstractSeries*,Domain*)), d_ptr.data(), SLOT(handleSeriesAdded(QAbstractSeries*))); | |
179 | QObject::connect(chart->d_ptr->m_dataset, SIGNAL(seriesRemoved(QAbstractSeries*)), d_ptr.data(), SLOT(handleSeriesRemoved(QAbstractSeries*))); |
|
179 | QObject::connect(chart->d_ptr->m_dataset, SIGNAL(seriesRemoved(QAbstractSeries*)), d_ptr.data(), SLOT(handleSeriesRemoved(QAbstractSeries*))); | |
180 | // QObject::connect(chart->d_ptr->m_dataset,SIGNAL(seriesUpdated(QAbstractSeries*)),d_ptr.data(),SLOT(handleSeriesUpdated(QAbstractSeries*))); |
|
180 | // QObject::connect(chart->d_ptr->m_dataset,SIGNAL(seriesUpdated(QAbstractSeries*)),d_ptr.data(),SLOT(handleSeriesUpdated(QAbstractSeries*))); | |
181 | setLayout(d_ptr->m_layout); |
|
181 | setLayout(d_ptr->m_layout); | |
182 | } |
|
182 | } | |
183 |
|
183 | |||
184 | /*! |
|
184 | /*! | |
185 | Destroys the legend object. Legend is always owned by a QChart, so an application should never call this. |
|
185 | Destroys the legend object. Legend is always owned by a QChart, so an application should never call this. | |
186 | */ |
|
186 | */ | |
187 | QLegend::~QLegend() |
|
187 | QLegend::~QLegend() | |
188 | { |
|
188 | { | |
189 | } |
|
189 | } | |
190 |
|
190 | |||
191 | /*! |
|
191 | /*! | |
192 | \internal |
|
192 | \internal | |
193 | */ |
|
193 | */ | |
194 | void QLegend::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) |
|
194 | void QLegend::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) | |
195 | { |
|
195 | { | |
196 | Q_UNUSED(option) |
|
196 | Q_UNUSED(option) | |
197 | Q_UNUSED(widget) |
|
197 | Q_UNUSED(widget) | |
198 |
|
198 | |||
199 | if (!d_ptr->m_backgroundVisible) |
|
199 | if (!d_ptr->m_backgroundVisible) | |
200 | return; |
|
200 | return; | |
201 |
|
201 | |||
202 | painter->setOpacity(opacity()); |
|
202 | painter->setOpacity(opacity()); | |
203 | painter->setPen(d_ptr->m_pen); |
|
203 | painter->setPen(d_ptr->m_pen); | |
204 | painter->setBrush(d_ptr->m_brush); |
|
204 | painter->setBrush(d_ptr->m_brush); | |
205 | painter->drawRoundRect(rect(), d_ptr->roundness(rect().width()), d_ptr->roundness(rect().height())); |
|
205 | painter->drawRoundRect(rect(), d_ptr->roundness(rect().width()), d_ptr->roundness(rect().height())); | |
206 | } |
|
206 | } | |
207 |
|
207 | |||
208 |
|
208 | |||
209 | /*! |
|
209 | /*! | |
210 | Sets the \a brush of legend. Brush affects the background of legend. |
|
210 | Sets the \a brush of legend. Brush affects the background of legend. | |
211 | */ |
|
211 | */ | |
212 | void QLegend::setBrush(const QBrush &brush) |
|
212 | void QLegend::setBrush(const QBrush &brush) | |
213 | { |
|
213 | { | |
214 | if (d_ptr->m_brush != brush) { |
|
214 | if (d_ptr->m_brush != brush) { | |
215 | d_ptr->m_brush = brush; |
|
215 | d_ptr->m_brush = brush; | |
216 | update(); |
|
216 | update(); | |
217 | emit colorChanged(brush.color()); |
|
217 | emit colorChanged(brush.color()); | |
218 | } |
|
218 | } | |
219 | } |
|
219 | } | |
220 |
|
220 | |||
221 | /*! |
|
221 | /*! | |
222 | Returns the brush used by legend. |
|
222 | Returns the brush used by legend. | |
223 | */ |
|
223 | */ | |
224 | QBrush QLegend::brush() const |
|
224 | QBrush QLegend::brush() const | |
225 | { |
|
225 | { | |
226 | return d_ptr->m_brush; |
|
226 | return d_ptr->m_brush; | |
227 | } |
|
227 | } | |
228 |
|
228 | |||
229 | void QLegend::setColor(QColor color) |
|
229 | void QLegend::setColor(QColor color) | |
230 | { |
|
230 | { | |
231 | QBrush b = d_ptr->m_brush; |
|
231 | QBrush b = d_ptr->m_brush; | |
232 | if (b.style() != Qt::SolidPattern || b.color() != color) { |
|
232 | if (b.style() != Qt::SolidPattern || b.color() != color) { | |
233 | b.setStyle(Qt::SolidPattern); |
|
233 | b.setStyle(Qt::SolidPattern); | |
234 | b.setColor(color); |
|
234 | b.setColor(color); | |
235 | setBrush(b); |
|
235 | setBrush(b); | |
236 | } |
|
236 | } | |
237 | } |
|
237 | } | |
238 |
|
238 | |||
239 | QColor QLegend::color() |
|
239 | QColor QLegend::color() | |
240 | { |
|
240 | { | |
241 | return d_ptr->m_brush.color(); |
|
241 | return d_ptr->m_brush.color(); | |
242 | } |
|
242 | } | |
243 |
|
243 | |||
244 | /*! |
|
244 | /*! | |
245 | Sets the \a pen of legend. Pen affects the legend borders. |
|
245 | Sets the \a pen of legend. Pen affects the legend borders. | |
246 | */ |
|
246 | */ | |
247 | void QLegend::setPen(const QPen &pen) |
|
247 | void QLegend::setPen(const QPen &pen) | |
248 | { |
|
248 | { | |
249 | if (d_ptr->m_pen != pen) { |
|
249 | if (d_ptr->m_pen != pen) { | |
250 | d_ptr->m_pen = pen; |
|
250 | d_ptr->m_pen = pen; | |
251 | update(); |
|
251 | update(); | |
252 | emit borderColorChanged(pen.color()); |
|
252 | emit borderColorChanged(pen.color()); | |
253 | } |
|
253 | } | |
254 | } |
|
254 | } | |
255 |
|
255 | |||
256 | /*! |
|
256 | /*! | |
257 | Returns the pen used by legend |
|
257 | Returns the pen used by legend | |
258 | */ |
|
258 | */ | |
259 |
|
259 | |||
260 | QPen QLegend::pen() const |
|
260 | QPen QLegend::pen() const | |
261 | { |
|
261 | { | |
262 | return d_ptr->m_pen; |
|
262 | return d_ptr->m_pen; | |
263 | } |
|
263 | } | |
264 |
|
264 | |||
265 | void QLegend::setFont(const QFont &font) |
|
265 | void QLegend::setFont(const QFont &font) | |
266 | { |
|
266 | { | |
267 | if (d_ptr->m_font != font) |
|
267 | if (d_ptr->m_font != font) | |
268 | d_ptr->m_font = font; |
|
268 | d_ptr->m_font = font; | |
269 |
|
269 | |||
270 | foreach (QLegendMarker *marker, d_ptr->legendMarkers()) { |
|
270 | foreach (QLegendMarker *marker, d_ptr->legendMarkers()) { | |
271 | marker->setFont(d_ptr->m_font); |
|
271 | marker->setFont(d_ptr->m_font); | |
272 | layout()->invalidate(); |
|
272 | layout()->invalidate(); | |
273 | emit fontChanged(font); |
|
273 | emit fontChanged(font); | |
274 | } |
|
274 | } | |
275 | } |
|
275 | } | |
276 |
|
276 | |||
277 | QFont QLegend::font() const |
|
277 | QFont QLegend::font() const | |
278 | { |
|
278 | { | |
279 | return d_ptr->m_font; |
|
279 | return d_ptr->m_font; | |
280 | } |
|
280 | } | |
281 |
|
281 | |||
282 | void QLegend::setBorderColor(QColor color) |
|
282 | void QLegend::setBorderColor(QColor color) | |
283 | { |
|
283 | { | |
284 | QPen p = d_ptr->m_pen; |
|
284 | QPen p = d_ptr->m_pen; | |
285 | if (p.color() != color) { |
|
285 | if (p.color() != color) { | |
286 | p.setColor(color); |
|
286 | p.setColor(color); | |
287 | setPen(p); |
|
287 | setPen(p); | |
288 | } |
|
288 | } | |
289 | } |
|
289 | } | |
290 |
|
290 | |||
291 | QColor QLegend::borderColor() |
|
291 | QColor QLegend::borderColor() | |
292 | { |
|
292 | { | |
293 | return d_ptr->m_pen.color(); |
|
293 | return d_ptr->m_pen.color(); | |
294 | } |
|
294 | } | |
295 |
|
295 | |||
296 | /*! |
|
296 | /*! | |
297 | Set brush used to draw labels to \a brush. |
|
297 | Set brush used to draw labels to \a brush. | |
298 | */ |
|
298 | */ | |
299 | void QLegend::setLabelBrush(const QBrush &brush) |
|
299 | void QLegend::setLabelBrush(const QBrush &brush) | |
300 | { |
|
300 | { | |
301 | if (d_ptr->m_labelBrush != brush) { |
|
301 | if (d_ptr->m_labelBrush != brush) { | |
302 | d_ptr->m_labelBrush = brush; |
|
302 | d_ptr->m_labelBrush = brush; | |
303 | foreach (QLegendMarker *marker, d_ptr->legendMarkers()) { |
|
303 | foreach (QLegendMarker *marker, d_ptr->legendMarkers()) { | |
304 | marker->setLabelBrush(d_ptr->m_labelBrush); |
|
304 | marker->setLabelBrush(d_ptr->m_labelBrush); | |
305 | // Note: The pen of the marker rectangle could be exposed in the public QLegend API |
|
305 | // Note: The pen of the marker rectangle could be exposed in the public QLegend API | |
306 | // instead of mapping it from label brush color |
|
306 | // instead of mapping it from label brush color | |
307 | marker->setPen(brush.color()); |
|
307 | marker->setPen(brush.color()); | |
308 | } |
|
308 | } | |
309 | emit labelColorChanged(brush.color()); |
|
309 | emit labelColorChanged(brush.color()); | |
310 | } |
|
310 | } | |
311 | } |
|
311 | } | |
312 |
|
312 | |||
313 | /*! |
|
313 | /*! | |
314 | Brush used to draw labels. |
|
314 | Brush used to draw labels. | |
315 | */ |
|
315 | */ | |
316 | QBrush QLegend::labelBrush() const |
|
316 | QBrush QLegend::labelBrush() const | |
317 | { |
|
317 | { | |
318 | return d_ptr->m_labelBrush; |
|
318 | return d_ptr->m_labelBrush; | |
319 | } |
|
319 | } | |
320 |
|
320 | |||
321 | void QLegend::setLabelColor(QColor color) |
|
321 | void QLegend::setLabelColor(QColor color) | |
322 | { |
|
322 | { | |
323 | QBrush b = d_ptr->m_labelBrush; |
|
323 | QBrush b = d_ptr->m_labelBrush; | |
324 | if (b.style() != Qt::SolidPattern || b.color() != color) { |
|
324 | if (b.style() != Qt::SolidPattern || b.color() != color) { | |
325 | b.setStyle(Qt::SolidPattern); |
|
325 | b.setStyle(Qt::SolidPattern); | |
326 | b.setColor(color); |
|
326 | b.setColor(color); | |
327 | setLabelBrush(b); |
|
327 | setLabelBrush(b); | |
328 | } |
|
328 | } | |
329 | } |
|
329 | } | |
330 |
|
330 | |||
331 | QColor QLegend::labelColor() const |
|
331 | QColor QLegend::labelColor() const | |
332 | { |
|
332 | { | |
333 | return d_ptr->m_labelBrush.color(); |
|
333 | return d_ptr->m_labelBrush.color(); | |
334 | } |
|
334 | } | |
335 |
|
335 | |||
336 |
|
336 | |||
337 | void QLegend::setAlignment(Qt::Alignment alignment) |
|
337 | void QLegend::setAlignment(Qt::Alignment alignment) | |
338 | { |
|
338 | { | |
339 | if (d_ptr->m_alignment != alignment) { |
|
339 | if (d_ptr->m_alignment != alignment) { | |
340 | d_ptr->m_alignment = alignment; |
|
340 | d_ptr->m_alignment = alignment; | |
341 | layout()->invalidate(); |
|
341 | layout()->invalidate(); | |
342 | } |
|
342 | } | |
343 | } |
|
343 | } | |
344 |
|
344 | |||
345 | Qt::Alignment QLegend::alignment() const |
|
345 | Qt::Alignment QLegend::alignment() const | |
346 | { |
|
346 | { | |
347 | return d_ptr->m_alignment; |
|
347 | return d_ptr->m_alignment; | |
348 | } |
|
348 | } | |
349 |
|
349 | |||
350 | /*! |
|
350 | /*! | |
351 | Detaches the legend from chart. Chart won't change layout of the legend. |
|
351 | Detaches the legend from chart. Chart won't change layout of the legend. | |
352 | */ |
|
352 | */ | |
353 | void QLegend::detachFromChart() |
|
353 | void QLegend::detachFromChart() | |
354 | { |
|
354 | { | |
355 | d_ptr->m_attachedToChart = false; |
|
355 | d_ptr->m_attachedToChart = false; | |
356 | layout()->invalidate(); |
|
356 | layout()->invalidate(); | |
357 | setParent(0); |
|
357 | setParent(0); | |
358 |
|
358 | |||
359 | } |
|
359 | } | |
360 |
|
360 | |||
361 | /*! |
|
361 | /*! | |
362 | Attaches the legend to chart. Chart may change layout of the legend. |
|
362 | Attaches the legend to chart. Chart may change layout of the legend. | |
363 | */ |
|
363 | */ | |
364 | void QLegend::attachToChart() |
|
364 | void QLegend::attachToChart() | |
365 | { |
|
365 | { | |
366 | d_ptr->m_attachedToChart = true; |
|
366 | d_ptr->m_attachedToChart = true; | |
367 | layout()->invalidate(); |
|
367 | layout()->invalidate(); | |
368 | setParent(d_ptr->m_chart); |
|
368 | setParent(d_ptr->m_chart); | |
369 | } |
|
369 | } | |
370 |
|
370 | |||
371 | /*! |
|
371 | /*! | |
372 | Returns true, if legend is attached to chart. |
|
372 | Returns true, if legend is attached to chart. | |
373 | */ |
|
373 | */ | |
374 | bool QLegend::isAttachedToChart() |
|
374 | bool QLegend::isAttachedToChart() | |
375 | { |
|
375 | { | |
376 | return d_ptr->m_attachedToChart; |
|
376 | return d_ptr->m_attachedToChart; | |
377 | } |
|
377 | } | |
378 |
|
378 | |||
379 | /*! |
|
379 | /*! | |
380 | Sets the visibility of legend background to \a visible |
|
380 | Sets the visibility of legend background to \a visible | |
381 | */ |
|
381 | */ | |
382 | void QLegend::setBackgroundVisible(bool visible) |
|
382 | void QLegend::setBackgroundVisible(bool visible) | |
383 | { |
|
383 | { | |
384 | if (d_ptr->m_backgroundVisible != visible) { |
|
384 | if (d_ptr->m_backgroundVisible != visible) { | |
385 | d_ptr->m_backgroundVisible = visible; |
|
385 | d_ptr->m_backgroundVisible = visible; | |
386 | update(); |
|
386 | update(); | |
387 | emit backgroundVisibleChanged(visible); |
|
387 | emit backgroundVisibleChanged(visible); | |
388 | } |
|
388 | } | |
389 | } |
|
389 | } | |
390 |
|
390 | |||
391 | /*! |
|
391 | /*! | |
392 | Returns the visibility of legend background |
|
392 | Returns the visibility of legend background | |
393 | */ |
|
393 | */ | |
394 | bool QLegend::isBackgroundVisible() const |
|
394 | bool QLegend::isBackgroundVisible() const | |
395 | { |
|
395 | { | |
396 | return d_ptr->m_backgroundVisible; |
|
396 | return d_ptr->m_backgroundVisible; | |
397 | } |
|
397 | } | |
398 |
|
398 | |||
399 |
|
399 | |||
400 | QList<QLegendMarker*> QLegend::markers() const |
|
400 | QList<QLegendMarker*> QLegend::markers() const | |
401 | { |
|
401 | { | |
402 | // TODO: name of PIMPL method will change. |
|
402 | // TODO: name of PIMPL method will change. | |
403 | return d_ptr->legendMarkers(); |
|
403 | return d_ptr->legendMarkers(); | |
404 | } |
|
404 | } | |
405 |
|
405 | |||
406 | void QLegend::appendSeries(QAbstractSeries* series) |
|
406 | void QLegend::appendSeries(QAbstractSeries* series) | |
407 | { |
|
407 | { | |
408 | d_ptr->appendSeries(series); |
|
408 | d_ptr->appendSeries(series); | |
409 | } |
|
409 | } | |
410 |
|
410 | |||
411 | void QLegend::removeSeries(QAbstractSeries* series) |
|
411 | void QLegend::removeSeries(QAbstractSeries* series) | |
412 | { |
|
412 | { | |
413 | d_ptr->removeSeries(series); |
|
413 | d_ptr->removeSeries(series); | |
414 | } |
|
414 | } | |
415 |
|
415 | |||
416 | /*! |
|
416 | /*! | |
417 | \internal \a event see QGraphicsWidget for details |
|
417 | \internal \a event see QGraphicsWidget for details | |
418 | */ |
|
418 | */ | |
419 | void QLegend::hideEvent(QHideEvent *event) |
|
419 | void QLegend::hideEvent(QHideEvent *event) | |
420 | { |
|
420 | { | |
421 | if (isAttachedToChart()) |
|
421 | if (isAttachedToChart()) | |
422 | d_ptr->m_presenter->layout()->invalidate(); |
|
422 | d_ptr->m_presenter->layout()->invalidate(); | |
423 | QGraphicsWidget::hideEvent(event); |
|
423 | QGraphicsWidget::hideEvent(event); | |
424 | } |
|
424 | } | |
425 | /*! |
|
425 | /*! | |
426 | \internal \a event see QGraphicsWidget for details |
|
426 | \internal \a event see QGraphicsWidget for details | |
427 | */ |
|
427 | */ | |
428 | void QLegend::showEvent(QShowEvent *event) |
|
428 | void QLegend::showEvent(QShowEvent *event) | |
429 | { |
|
429 | { | |
430 | if (isAttachedToChart()) { |
|
430 | if (isAttachedToChart()) { | |
431 | d_ptr->items()->setVisible(false); |
|
431 | d_ptr->items()->setVisible(false); | |
432 | layout()->invalidate(); |
|
432 | layout()->invalidate(); | |
433 | } |
|
433 | } | |
434 | QGraphicsWidget::showEvent(event); |
|
434 | QGraphicsWidget::showEvent(event); | |
435 | //layout activation will show the items |
|
435 | //layout activation will show the items | |
436 | } |
|
436 | } | |
437 |
|
437 | |||
438 | //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
|
438 | //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// | |
439 |
|
439 | |||
440 | QLegendPrivate::QLegendPrivate(ChartPresenter *presenter, QChart *chart, QLegend *q) |
|
440 | QLegendPrivate::QLegendPrivate(ChartPresenter *presenter, QChart *chart, QLegend *q) | |
441 | : q_ptr(q), |
|
441 | : q_ptr(q), | |
442 | m_presenter(presenter), |
|
442 | m_presenter(presenter), | |
443 | m_layout(new LegendLayout(q)), |
|
443 | m_layout(new LegendLayout(q)), | |
444 | m_chart(chart), |
|
444 | m_chart(chart), | |
445 | m_items(new QGraphicsItemGroup(q)), |
|
445 | m_items(new QGraphicsItemGroup(q)), | |
446 | m_alignment(Qt::AlignTop), |
|
446 | m_alignment(Qt::AlignTop), | |
447 | m_brush(QBrush()), |
|
447 | m_brush(QBrush()), | |
448 | m_pen(QPen()), |
|
448 | m_pen(QPen()), | |
449 | m_labelBrush(QBrush()), |
|
449 | m_labelBrush(QBrush()), | |
450 | m_diameter(5), |
|
450 | m_diameter(5), | |
451 | m_attachedToChart(true), |
|
451 | m_attachedToChart(true), | |
452 | m_backgroundVisible(false) |
|
452 | m_backgroundVisible(false) | |
453 | { |
|
453 | { | |
454 | m_items->setHandlesChildEvents(false); |
|
454 | m_items->setHandlesChildEvents(false); | |
455 | } |
|
455 | } | |
456 |
|
456 | |||
457 | QLegendPrivate::~QLegendPrivate() |
|
457 | QLegendPrivate::~QLegendPrivate() | |
458 | { |
|
458 | { | |
459 |
|
459 | |||
460 | } |
|
460 | } | |
461 |
|
461 | |||
462 | void QLegendPrivate::setOffset(qreal x, qreal y) |
|
462 | void QLegendPrivate::setOffset(qreal x, qreal y) | |
463 | { |
|
463 | { | |
464 | m_layout->setOffset(x, y); |
|
464 | m_layout->setOffset(x, y); | |
465 | } |
|
465 | } | |
466 |
|
466 | |||
467 | QPointF QLegendPrivate::offset() const |
|
467 | QPointF QLegendPrivate::offset() const | |
468 | { |
|
468 | { | |
469 | return m_layout->offset(); |
|
469 | return m_layout->offset(); | |
470 | } |
|
470 | } | |
471 |
|
471 | |||
472 | int QLegendPrivate::roundness(qreal size) |
|
472 | int QLegendPrivate::roundness(qreal size) | |
473 | { |
|
473 | { | |
474 | return 100 * m_diameter / int(size); |
|
474 | return 100 * m_diameter / int(size); | |
475 | } |
|
475 | } | |
476 |
|
476 | |||
477 | void QLegendPrivate::appendSeries(QAbstractSeries* series) |
|
477 | void QLegendPrivate::appendSeries(QAbstractSeries* series) | |
478 | { |
|
478 | { | |
479 | // Only allow one instance of series |
|
479 | // Only allow one instance of series | |
480 | if (m_series.contains(series)) { |
|
480 | if (m_series.contains(series)) { | |
481 | qDebug() << "series already added" << series; |
|
481 | qDebug() << "series already added" << series; | |
482 | return; |
|
482 | return; | |
483 | } |
|
483 | } | |
484 |
|
484 | |||
485 | QList<QLegendMarker*> newMarkers = series->d_ptr->createLegendMarkers(q_ptr); |
|
485 | QList<QLegendMarker*> newMarkers = series->d_ptr->createLegendMarkers(q_ptr); | |
486 | foreach (QLegendMarker* marker, newMarkers) { |
|
486 | decorateMarkers(newMarkers); | |
487 | marker->setFont(m_font); |
|
487 | addMarkers(newMarkers); | |
488 | marker->setLabelBrush(m_labelBrush); |
|
|||
489 | marker->setVisible(series->isVisible()); |
|
|||
490 | m_items->addToGroup(marker->d_ptr.data()->item()); |
|
|||
491 | m_legendMarkers << marker; |
|
|||
492 | } |
|
|||
493 |
|
488 | |||
494 | // TODO: This is the part I don't like. There should be better solution. |
|
489 | // TODO: This is the part I don't like. There should be better solution. | |
495 | // On the other hand. It is only one switch case for appending and another for removing series |
|
490 | // On the other hand. It is only one switch case for appending and another for removing series | |
496 | // If countChanged signal were on QAbstractSeries, there would be no need for switch at all. |
|
491 | // If countChanged signal were on QAbstractSeries, there would be no need for switch at all. | |
497 | switch (series->type()) |
|
492 | switch (series->type()) | |
498 | { |
|
493 | { | |
499 | case QAbstractSeries::SeriesTypePie: { |
|
494 | case QAbstractSeries::SeriesTypePie: { | |
500 | QPieSeries *s = qobject_cast<QPieSeries *> (series); |
|
495 | QPieSeries *s = qobject_cast<QPieSeries *> (series); | |
501 | QObject::connect(s, SIGNAL(countChanged()), this, SLOT(handleSeriesUpdated())); |
|
496 | QObject::connect(s, SIGNAL(countChanged()), this, SLOT(handleSeriesUpdated())); | |
502 | break; |
|
497 | break; | |
503 | } |
|
498 | } | |
504 | case QAbstractSeries::SeriesTypeBar: |
|
499 | case QAbstractSeries::SeriesTypeBar: | |
505 | case QAbstractSeries::SeriesTypeStackedBar: |
|
500 | case QAbstractSeries::SeriesTypeStackedBar: | |
506 | case QAbstractSeries::SeriesTypePercentBar: |
|
501 | case QAbstractSeries::SeriesTypePercentBar: | |
507 | case QAbstractSeries::SeriesTypeHorizontalBar: |
|
502 | case QAbstractSeries::SeriesTypeHorizontalBar: | |
508 | case QAbstractSeries::SeriesTypeHorizontalStackedBar: |
|
503 | case QAbstractSeries::SeriesTypeHorizontalStackedBar: | |
509 | case QAbstractSeries::SeriesTypeHorizontalPercentBar: { |
|
504 | case QAbstractSeries::SeriesTypeHorizontalPercentBar: { | |
510 | QAbstractBarSeries *s = qobject_cast<QAbstractBarSeries *> (series); |
|
505 | QAbstractBarSeries *s = qobject_cast<QAbstractBarSeries *> (series); | |
511 | QObject::connect(s, SIGNAL(countChanged()), this, SLOT(handleSeriesUpdated())); |
|
506 | QObject::connect(s, SIGNAL(countChanged()), this, SLOT(handleSeriesUpdated())); | |
512 | break; |
|
507 | break; | |
513 | } |
|
508 | } | |
514 | case QAbstractSeries::SeriesTypeLine: |
|
509 | case QAbstractSeries::SeriesTypeLine: | |
515 | case QAbstractSeries::SeriesTypeArea: |
|
510 | case QAbstractSeries::SeriesTypeArea: | |
516 | case QAbstractSeries::SeriesTypeScatter: |
|
511 | case QAbstractSeries::SeriesTypeScatter: | |
517 | case QAbstractSeries::SeriesTypeSpline: |
|
512 | case QAbstractSeries::SeriesTypeSpline: | |
518 | default: { |
|
513 | default: { | |
519 | // No need to connect any series related signals. We have no series level |
|
514 | // No need to connect any series related signals. We have no series level | |
520 | // changes, that would generate or delete markers |
|
515 | // changes, that would generate or delete markers | |
521 | } |
|
516 | } | |
522 | } |
|
517 | } | |
523 |
|
518 | |||
524 | QObject::connect(series, SIGNAL(visibleChanged()), this, SLOT(handleSeriesVisibleChanged())); |
|
519 | QObject::connect(series, SIGNAL(visibleChanged()), this, SLOT(handleSeriesVisibleChanged())); | |
525 |
|
520 | |||
526 | m_series.append(series); |
|
521 | m_series.append(series); | |
527 | m_items->setVisible(false); |
|
522 | m_items->setVisible(false); | |
528 | m_layout->invalidate(); |
|
523 | m_layout->invalidate(); | |
529 | } |
|
524 | } | |
530 |
|
525 | |||
531 | void QLegendPrivate::removeSeries(QAbstractSeries* series) |
|
526 | void QLegendPrivate::removeSeries(QAbstractSeries* series) | |
532 | { |
|
527 | { | |
533 | if (m_series.contains(series)) { |
|
528 | if (m_series.contains(series)) { | |
534 | m_series.removeOne(series); |
|
529 | m_series.removeOne(series); | |
535 | } |
|
530 | } | |
536 |
|
531 | |||
537 | foreach (QLegendMarker *marker, m_legendMarkers) { |
|
532 | // Find out, which markers to remove | |
538 | if (marker->series() == series) { |
|
533 | QList<QLegendMarker *> removed; | |
539 | marker->d_ptr.data()->item()->setVisible(false); |
|
534 | foreach (QLegendMarker *m, m_legendMarkers) { | |
540 | m_items->removeFromGroup(marker->d_ptr.data()->item()); |
|
535 | if (m->series() == series) { | |
541 |
|
|
536 | removed << m; | |
542 | m_legendMarkers.removeAll(marker); |
|
|||
543 | } |
|
537 | } | |
544 | } |
|
538 | } | |
|
539 | removeMarkers(removed); | |||
545 |
|
540 | |||
546 | switch (series->type()) |
|
541 | switch (series->type()) | |
547 | { |
|
542 | { | |
548 | case QAbstractSeries::SeriesTypePie: { |
|
543 | case QAbstractSeries::SeriesTypePie: { | |
549 | QPieSeries *s = qobject_cast<QPieSeries *> (series); |
|
544 | QPieSeries *s = qobject_cast<QPieSeries *> (series); | |
550 | QObject::disconnect(s, SIGNAL(countChanged()), this, SLOT(handleSeriesUpdated())); |
|
545 | QObject::disconnect(s, SIGNAL(countChanged()), this, SLOT(handleSeriesUpdated())); | |
551 | break; |
|
546 | break; | |
552 | } |
|
547 | } | |
553 | case QAbstractSeries::SeriesTypeBar: |
|
548 | case QAbstractSeries::SeriesTypeBar: | |
554 | case QAbstractSeries::SeriesTypeStackedBar: |
|
549 | case QAbstractSeries::SeriesTypeStackedBar: | |
555 | case QAbstractSeries::SeriesTypePercentBar: |
|
550 | case QAbstractSeries::SeriesTypePercentBar: | |
556 | case QAbstractSeries::SeriesTypeHorizontalBar: |
|
551 | case QAbstractSeries::SeriesTypeHorizontalBar: | |
557 | case QAbstractSeries::SeriesTypeHorizontalStackedBar: |
|
552 | case QAbstractSeries::SeriesTypeHorizontalStackedBar: | |
558 | case QAbstractSeries::SeriesTypeHorizontalPercentBar: { |
|
553 | case QAbstractSeries::SeriesTypeHorizontalPercentBar: { | |
559 | QAbstractBarSeries *s = qobject_cast<QAbstractBarSeries *> (series); |
|
554 | QAbstractBarSeries *s = qobject_cast<QAbstractBarSeries *> (series); | |
560 | QObject::disconnect(s, SIGNAL(countChanged()), this, SLOT(handleSeriesUpdated())); |
|
555 | QObject::disconnect(s, SIGNAL(countChanged()), this, SLOT(handleSeriesUpdated())); | |
561 | break; |
|
556 | break; | |
562 | } |
|
557 | } | |
563 | // TODO: |
|
558 | // TODO: | |
564 | case QAbstractSeries::SeriesTypeLine: |
|
559 | case QAbstractSeries::SeriesTypeLine: | |
565 | case QAbstractSeries::SeriesTypeArea: |
|
560 | case QAbstractSeries::SeriesTypeArea: | |
566 | case QAbstractSeries::SeriesTypeScatter: |
|
561 | case QAbstractSeries::SeriesTypeScatter: | |
567 | case QAbstractSeries::SeriesTypeSpline: |
|
562 | case QAbstractSeries::SeriesTypeSpline: | |
568 | default: { |
|
563 | default: { | |
569 | // No need to disconnect any series related signals |
|
564 | // No need to disconnect any series related signals | |
570 | break; |
|
565 | break; | |
571 | } |
|
566 | } | |
572 | } |
|
567 | } | |
573 |
|
568 | |||
574 |
|
||||
575 | QObject::disconnect(series, SIGNAL(visibleChanged()), this, SLOT(handleSeriesVisibleChanged())); |
|
569 | QObject::disconnect(series, SIGNAL(visibleChanged()), this, SLOT(handleSeriesVisibleChanged())); | |
576 | // QObject::disconnect(series->d_ptr.data(), SIGNAL(legendPropertiesUpdated(QAbstractSeries*)), this, SLOT(handleLegendPropertiesUpdated(QAbstractSeries*))); |
|
|||
577 |
|
570 | |||
578 | m_layout->invalidate(); |
|
571 | m_layout->invalidate(); | |
579 | // q_ptr->layout()->activate(); |
|
572 | // q_ptr->layout()->activate(); | |
580 | } |
|
573 | } | |
581 |
|
574 | |||
582 | void QLegendPrivate::handleSeriesAdded(QAbstractSeries *series) |
|
575 | void QLegendPrivate::handleSeriesAdded(QAbstractSeries *series) | |
583 | { |
|
576 | { | |
584 | // Moved to appendSeries |
|
577 | // Moved to appendSeries | |
585 | // This slot is just to make old code work for now. |
|
578 | // This slot is just to make old code work for now. | |
586 | appendSeries(series); |
|
579 | appendSeries(series); | |
587 | } |
|
580 | } | |
588 |
|
581 | |||
589 | void QLegendPrivate::handleSeriesRemoved(QAbstractSeries *series) |
|
582 | void QLegendPrivate::handleSeriesRemoved(QAbstractSeries *series) | |
590 | { |
|
583 | { | |
591 | // Moved to removeSeries |
|
584 | // Moved to removeSeries | |
592 | // This slot is just to make old code work for now. |
|
585 | // This slot is just to make old code work for now. | |
593 | removeSeries(series); |
|
586 | removeSeries(series); | |
594 | } |
|
587 | } | |
595 |
|
588 | |||
596 | void QLegendPrivate::handleSeriesVisibleChanged() |
|
589 | void QLegendPrivate::handleSeriesVisibleChanged() | |
597 | { |
|
590 | { | |
598 | QAbstractSeries *series = qobject_cast<QAbstractSeries *> (sender()); |
|
591 | QAbstractSeries *series = qobject_cast<QAbstractSeries *> (sender()); | |
599 | Q_ASSERT(series); |
|
592 | Q_ASSERT(series); | |
600 |
|
593 | |||
601 | foreach (QLegendMarker* marker, m_legendMarkers) { |
|
594 | foreach (QLegendMarker* marker, m_legendMarkers) { | |
602 | if (marker->series() == series) { |
|
595 | if (marker->series() == series) { | |
603 | marker->setVisible(series->isVisible()); |
|
596 | marker->setVisible(series->isVisible()); | |
604 | } |
|
597 | } | |
605 | } |
|
598 | } | |
606 | m_layout->invalidate(); |
|
599 | m_layout->invalidate(); | |
607 | } |
|
600 | } | |
608 |
|
601 | |||
609 | void QLegendPrivate::handleCountChanged() |
|
602 | void QLegendPrivate::handleCountChanged() | |
610 | { |
|
603 | { | |
611 | // TODO: With new markers, the series should notify markers directly. |
|
604 | // Here we handle the changes in marker count. | |
612 | // TODO: Better way to handle updates. Remove/Add series again seems like overkill. |
|
605 | // Can happen for example when pieslice(s) have been added to or removed from pieseries. | |
613 |
|
606 | |||
614 | QAbstractSeries *series = qobject_cast<QAbstractSeries *> (sender()); |
|
607 | QAbstractSeries *series = qobject_cast<QAbstractSeries *> (sender()); | |
615 | qDebug() << "QLegendPrivate::handleSeriesUpdated" << series; |
|
608 | qDebug() << "QLegendPrivate::handleSeriesUpdated" << series; | |
616 |
|
609 | |||
617 | // Handle new or removed markers |
|
610 | QList<QLegendMarker *> createdMarkers = series->d_ptr->createLegendMarkers(q_ptr); | |
618 | // Handle changes of marker pen/brush/label. every property that legend is interested |
|
611 | ||
619 | handleSeriesRemoved(series); |
|
612 | // Find out removed markers and created markers | |
620 | handleSeriesAdded(series); |
|
613 | QList<QLegendMarker *> removedMarkers; | |
|
614 | foreach (QLegendMarker *oldMarker, m_legendMarkers) { | |||
|
615 | // we have marker, which is related to sender. | |||
|
616 | if (oldMarker->series() == series) { | |||
|
617 | bool found = false; | |||
|
618 | foreach(QLegendMarker *newMarker, createdMarkers) { | |||
|
619 | // New marker considered existing if: | |||
|
620 | // - d_ptr->relatedObject() is same for both markers. | |||
|
621 | if (newMarker->d_ptr->relatedObject() == oldMarker->d_ptr->relatedObject()) { | |||
|
622 | // Delete the new marker, since we already have existing marker, that might be connected on user side. | |||
|
623 | found = true; | |||
|
624 | createdMarkers.removeOne(newMarker); | |||
|
625 | delete newMarker; | |||
|
626 | } | |||
|
627 | } | |||
|
628 | if (!found) { | |||
|
629 | // No related object found for marker, add to removedMarkers list | |||
|
630 | removedMarkers << oldMarker; | |||
|
631 | } | |||
|
632 | } | |||
|
633 | } | |||
|
634 | ||||
|
635 | removeMarkers(removedMarkers); | |||
|
636 | addMarkers(createdMarkers); | |||
|
637 | ||||
|
638 | q_ptr->layout()->invalidate(); | |||
|
639 | } | |||
|
640 | ||||
|
641 | void QLegendPrivate::addMarkers(QList<QLegendMarker *> markers) | |||
|
642 | { | |||
|
643 | foreach (QLegendMarker* marker, markers) { | |||
|
644 | m_items->addToGroup(marker->d_ptr.data()->item()); | |||
|
645 | m_legendMarkers << marker; | |||
|
646 | } | |||
|
647 | } | |||
|
648 | ||||
|
649 | void QLegendPrivate::removeMarkers(QList<QLegendMarker *> markers) | |||
|
650 | { | |||
|
651 | foreach (QLegendMarker *marker, markers) { | |||
|
652 | marker->d_ptr->item()->setVisible(false); | |||
|
653 | m_items->removeFromGroup(marker->d_ptr->item()); | |||
|
654 | delete marker; | |||
|
655 | m_legendMarkers.removeOne(marker); | |||
|
656 | } | |||
|
657 | } | |||
|
658 | ||||
|
659 | void QLegendPrivate::decorateMarkers(QList<QLegendMarker *> markers) | |||
|
660 | { | |||
|
661 | foreach (QLegendMarker* marker, markers) { | |||
|
662 | marker->setFont(m_font); | |||
|
663 | marker->setLabelBrush(m_labelBrush); | |||
|
664 | } | |||
621 | } |
|
665 | } | |
622 |
|
666 | |||
|
667 | ||||
623 | #include "moc_qlegend.cpp" |
|
668 | #include "moc_qlegend.cpp" | |
624 | #include "moc_qlegend_p.cpp" |
|
669 | #include "moc_qlegend_p.cpp" | |
625 |
|
670 | |||
626 | QTCOMMERCIALCHART_END_NAMESPACE |
|
671 | QTCOMMERCIALCHART_END_NAMESPACE |
@@ -1,93 +1,99 | |||||
1 | /**************************************************************************** |
|
1 | /**************************************************************************** | |
2 | ** |
|
2 | ** | |
3 | ** Copyright (C) 2012 Digia Plc |
|
3 | ** Copyright (C) 2012 Digia Plc | |
4 | ** All rights reserved. |
|
4 | ** All rights reserved. | |
5 | ** For any questions to Digia, please use contact form at http://qt.digia.com |
|
5 | ** For any questions to Digia, please use contact form at http://qt.digia.com | |
6 | ** |
|
6 | ** | |
7 | ** This file is part of the Qt Commercial Charts Add-on. |
|
7 | ** This file is part of the Qt Commercial Charts Add-on. | |
8 | ** |
|
8 | ** | |
9 | ** $QT_BEGIN_LICENSE$ |
|
9 | ** $QT_BEGIN_LICENSE$ | |
10 | ** Licensees holding valid Qt Commercial licenses may use this file in |
|
10 | ** Licensees holding valid Qt Commercial licenses may use this file in | |
11 | ** accordance with the Qt Commercial License Agreement provided with the |
|
11 | ** accordance with the Qt Commercial License Agreement provided with the | |
12 | ** Software or, alternatively, in accordance with the terms contained in |
|
12 | ** Software or, alternatively, in accordance with the terms contained in | |
13 | ** a written agreement between you and Digia. |
|
13 | ** a written agreement between you and Digia. | |
14 | ** |
|
14 | ** | |
15 | ** If you have questions regarding the use of this file, please use |
|
15 | ** If you have questions regarding the use of this file, please use | |
16 | ** contact form at http://qt.digia.com |
|
16 | ** contact form at http://qt.digia.com | |
17 | ** $QT_END_LICENSE$ |
|
17 | ** $QT_END_LICENSE$ | |
18 | ** |
|
18 | ** | |
19 | ****************************************************************************/ |
|
19 | ****************************************************************************/ | |
20 |
|
20 | |||
21 | // W A R N I N G |
|
21 | // W A R N I N G | |
22 | // ------------- |
|
22 | // ------------- | |
23 | // |
|
23 | // | |
24 | // This file is not part of the QtCommercial Chart API. It exists purely as an |
|
24 | // This file is not part of the QtCommercial Chart API. It exists purely as an | |
25 | // implementation detail. This header file may change from version to |
|
25 | // implementation detail. This header file may change from version to | |
26 | // version without notice, or even be removed. |
|
26 | // version without notice, or even be removed. | |
27 | // |
|
27 | // | |
28 | // We mean it. |
|
28 | // We mean it. | |
29 |
|
29 | |||
30 | #ifndef QLEGEND_P_H |
|
30 | #ifndef QLEGEND_P_H | |
31 | #define QLEGEND_P_H |
|
31 | #define QLEGEND_P_H | |
32 |
|
32 | |||
33 | #include "qlegend.h" |
|
33 | #include "qlegend.h" | |
34 |
|
34 | |||
35 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
35 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
36 |
|
36 | |||
37 | class QChart; |
|
37 | class QChart; | |
38 | class ChartPresenter; |
|
38 | class ChartPresenter; | |
39 | class QAbstractSeries; |
|
39 | class QAbstractSeries; | |
40 | class LegendLayout; |
|
40 | class LegendLayout; | |
41 | class Domain; |
|
41 | class Domain; | |
42 | class QLegendMarker; |
|
42 | class QLegendMarker; | |
43 |
|
43 | |||
44 | class QLegendPrivate : public QObject |
|
44 | class QLegendPrivate : public QObject | |
45 | { |
|
45 | { | |
46 | Q_OBJECT |
|
46 | Q_OBJECT | |
47 | public: |
|
47 | public: | |
48 | QLegendPrivate(ChartPresenter *presenter, QChart *chart, QLegend *q); |
|
48 | QLegendPrivate(ChartPresenter *presenter, QChart *chart, QLegend *q); | |
49 | ~QLegendPrivate(); |
|
49 | ~QLegendPrivate(); | |
50 |
|
50 | |||
51 | void setOffset(qreal x, qreal y); |
|
51 | void setOffset(qreal x, qreal y); | |
52 | QPointF offset() const; |
|
52 | QPointF offset() const; | |
53 | int roundness(qreal size); |
|
53 | int roundness(qreal size); | |
54 |
|
54 | |||
55 | QGraphicsItemGroup* items() { return m_items; } |
|
55 | QGraphicsItemGroup* items() { return m_items; } | |
56 |
|
56 | |||
57 | // New stuff: |
|
57 | // New stuff: | |
58 | QList<QLegendMarker*> legendMarkers() { return m_legendMarkers; } |
|
58 | QList<QLegendMarker*> legendMarkers() { return m_legendMarkers; } | |
59 | void appendSeries(QAbstractSeries* series); |
|
59 | void appendSeries(QAbstractSeries* series); | |
60 | void removeSeries(QAbstractSeries* series); |
|
60 | void removeSeries(QAbstractSeries* series); | |
61 |
|
61 | |||
62 | public Q_SLOTS: |
|
62 | public Q_SLOTS: | |
63 | void handleSeriesAdded(QAbstractSeries *series); |
|
63 | void handleSeriesAdded(QAbstractSeries *series); | |
64 | void handleSeriesRemoved(QAbstractSeries *series); |
|
64 | void handleSeriesRemoved(QAbstractSeries *series); | |
65 | void handleSeriesVisibleChanged(); |
|
65 | void handleSeriesVisibleChanged(); | |
66 | void handleCountChanged(); |
|
66 | void handleCountChanged(); | |
67 |
|
67 | |||
68 | private: |
|
68 | private: | |
|
69 | // Internal helpers | |||
|
70 | void addMarkers(QList<QLegendMarker *> markers); | |||
|
71 | void removeMarkers(QList<QLegendMarker *> markers); | |||
|
72 | void decorateMarkers(QList<QLegendMarker *> markers); | |||
|
73 | ||||
|
74 | private: | |||
69 | QLegend *q_ptr; |
|
75 | QLegend *q_ptr; | |
70 | ChartPresenter *m_presenter; |
|
76 | ChartPresenter *m_presenter; | |
71 | LegendLayout *m_layout; |
|
77 | LegendLayout *m_layout; | |
72 | QChart* m_chart; |
|
78 | QChart* m_chart; | |
73 | QGraphicsItemGroup* m_items; |
|
79 | QGraphicsItemGroup* m_items; | |
74 | Qt::Alignment m_alignment; |
|
80 | Qt::Alignment m_alignment; | |
75 | QBrush m_brush; |
|
81 | QBrush m_brush; | |
76 | QPen m_pen; |
|
82 | QPen m_pen; | |
77 | QFont m_font; |
|
83 | QFont m_font; | |
78 | QBrush m_labelBrush; |
|
84 | QBrush m_labelBrush; | |
79 |
|
85 | |||
80 | qreal m_diameter; |
|
86 | qreal m_diameter; | |
81 | bool m_attachedToChart; |
|
87 | bool m_attachedToChart; | |
82 | bool m_backgroundVisible; |
|
88 | bool m_backgroundVisible; | |
83 |
|
89 | |||
84 | friend class QLegend; |
|
90 | friend class QLegend; | |
85 | friend class LegendLayout; |
|
91 | friend class LegendLayout; | |
86 | QList<QLegendMarker*> m_legendMarkers; // TODO: rename to m_markers eventually. |
|
92 | QList<QLegendMarker*> m_legendMarkers; // TODO: rename to m_markers eventually. | |
87 | QList<QAbstractSeries*> m_series; |
|
93 | QList<QAbstractSeries*> m_series; | |
88 |
|
94 | |||
89 | }; |
|
95 | }; | |
90 |
|
96 | |||
91 | QTCOMMERCIALCHART_END_NAMESPACE |
|
97 | QTCOMMERCIALCHART_END_NAMESPACE | |
92 |
|
98 | |||
93 | #endif |
|
99 | #endif |
@@ -1,126 +1,129 | |||||
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 <QDebug> |
|
25 | #include <QDebug> | |
26 | #include <QFontMetrics> |
|
26 | #include <QFontMetrics> | |
27 | #include <QGraphicsSceneEvent> |
|
27 | #include <QGraphicsSceneEvent> | |
|
28 | #include <QAbstractSeries> | |||
28 |
|
29 | |||
29 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
30 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
30 |
|
31 | |||
31 | QLegendMarker::QLegendMarker(QLegendMarkerPrivate &d, QObject *parent) : |
|
32 | QLegendMarker::QLegendMarker(QLegendMarkerPrivate &d, QObject *parent) : | |
32 | QObject(parent), |
|
33 | QObject(parent), | |
33 | d_ptr(&d) |
|
34 | d_ptr(&d) | |
34 | { |
|
35 | { | |
|
36 | d_ptr->m_item->setVisible(d_ptr->series()->isVisible()); | |||
35 | } |
|
37 | } | |
36 |
|
38 | |||
37 | QLegendMarker::~QLegendMarker() |
|
39 | QLegendMarker::~QLegendMarker() | |
38 | { |
|
40 | { | |
39 | } |
|
41 | } | |
40 |
|
42 | |||
41 | QString QLegendMarker::label() const |
|
43 | QString QLegendMarker::label() const | |
42 | { |
|
44 | { | |
43 | return d_ptr->m_item->label(); |
|
45 | return d_ptr->m_item->label(); | |
44 | } |
|
46 | } | |
45 |
|
47 | |||
46 | void QLegendMarker::setLabel(const QString &label) |
|
48 | void QLegendMarker::setLabel(const QString &label) | |
47 | { |
|
49 | { | |
48 | d_ptr->m_item->setLabel(label); |
|
50 | d_ptr->m_item->setLabel(label); | |
49 | } |
|
51 | } | |
50 |
|
52 | |||
51 | QBrush QLegendMarker::labelBrush() const |
|
53 | QBrush QLegendMarker::labelBrush() const | |
52 | { |
|
54 | { | |
53 | return d_ptr->m_item->brush(); |
|
55 | return d_ptr->m_item->brush(); | |
54 | } |
|
56 | } | |
55 |
|
57 | |||
56 | void QLegendMarker::setLabelBrush(const QBrush &brush) |
|
58 | void QLegendMarker::setLabelBrush(const QBrush &brush) | |
57 | { |
|
59 | { | |
58 | d_ptr->m_item->setLabelBrush(brush); |
|
60 | d_ptr->m_item->setLabelBrush(brush); | |
59 | } |
|
61 | } | |
60 |
|
62 | |||
61 | QFont QLegendMarker::font() const |
|
63 | QFont QLegendMarker::font() const | |
62 | { |
|
64 | { | |
63 | return d_ptr->m_item->font(); |
|
65 | return d_ptr->m_item->font(); | |
64 | } |
|
66 | } | |
65 |
|
67 | |||
66 | void QLegendMarker::setFont(const QFont &font) |
|
68 | void QLegendMarker::setFont(const QFont &font) | |
67 | { |
|
69 | { | |
68 | d_ptr->m_item->setFont(font); |
|
70 | d_ptr->m_item->setFont(font); | |
69 | } |
|
71 | } | |
70 |
|
72 | |||
71 | QPen QLegendMarker::pen() const |
|
73 | QPen QLegendMarker::pen() const | |
72 | { |
|
74 | { | |
73 | return d_ptr->m_item->pen(); |
|
75 | return d_ptr->m_item->pen(); | |
74 | } |
|
76 | } | |
75 |
|
77 | |||
76 | void QLegendMarker::setPen(const QPen &pen) |
|
78 | void QLegendMarker::setPen(const QPen &pen) | |
77 | { |
|
79 | { | |
78 | d_ptr->m_item->setPen(pen); |
|
80 | d_ptr->m_item->setPen(pen); | |
79 | } |
|
81 | } | |
80 |
|
82 | |||
81 | QBrush QLegendMarker::brush() const |
|
83 | QBrush QLegendMarker::brush() const | |
82 | { |
|
84 | { | |
83 | return d_ptr->m_item->brush(); |
|
85 | return d_ptr->m_item->brush(); | |
84 | } |
|
86 | } | |
85 |
|
87 | |||
86 | void QLegendMarker::setBrush(const QBrush &brush) |
|
88 | void QLegendMarker::setBrush(const QBrush &brush) | |
87 | { |
|
89 | { | |
88 | d_ptr->m_item->setBrush(brush); |
|
90 | d_ptr->m_item->setBrush(brush); | |
89 | } |
|
91 | } | |
90 |
|
92 | |||
91 | bool QLegendMarker::isVisible() const |
|
93 | bool QLegendMarker::isVisible() const | |
92 | { |
|
94 | { | |
93 | return d_ptr->m_item->isVisible(); |
|
95 | return d_ptr->m_item->isVisible(); | |
94 | } |
|
96 | } | |
95 |
|
97 | |||
96 | void QLegendMarker::setVisible(bool visible) |
|
98 | void QLegendMarker::setVisible(bool visible) | |
97 | { |
|
99 | { | |
98 | d_ptr->m_item->setVisible(visible); |
|
100 | d_ptr->m_item->setVisible(visible); | |
99 | } |
|
101 | } | |
100 |
|
102 | |||
101 | //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
|
103 | //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// | |
102 | QLegendMarkerPrivate::QLegendMarkerPrivate(QLegendMarker *q, QLegend *legend) : |
|
104 | QLegendMarkerPrivate::QLegendMarkerPrivate(QLegendMarker *q, QLegend *legend) : | |
103 | q_ptr(q), |
|
105 | q_ptr(q), | |
104 | m_legend(legend) |
|
106 | m_legend(legend) | |
105 | { |
|
107 | { | |
106 | m_item = new LegendMarkerItem(this); |
|
108 | m_item = new LegendMarkerItem(this); | |
|
109 | // m_item->setVisible(q->series()->isVisible()); | |||
107 | } |
|
110 | } | |
108 |
|
111 | |||
109 | QLegendMarkerPrivate::~QLegendMarkerPrivate() |
|
112 | QLegendMarkerPrivate::~QLegendMarkerPrivate() | |
110 | { |
|
113 | { | |
111 | } |
|
114 | } | |
112 |
|
115 | |||
113 | void QLegendMarkerPrivate::handleMousePressEvent(QGraphicsSceneEvent *event) |
|
116 | void QLegendMarkerPrivate::handleMousePressEvent(QGraphicsSceneEvent *event) | |
114 | { |
|
117 | { | |
115 | // Just emit clicked signal for now (our default logic for events) |
|
118 | // Just emit clicked signal for now (our default logic for events) | |
116 | // This could propably be on the LegendMarkerItem? |
|
119 | // This could propably be on the LegendMarkerItem? | |
117 | // TODO: how to handle scrolling vs clicking? drag event? |
|
120 | // TODO: how to handle scrolling vs clicking? drag event? | |
118 | event->accept(); |
|
121 | event->accept(); | |
119 | Q_Q(QLegendMarker); |
|
122 | Q_Q(QLegendMarker); | |
120 | emit q->clicked(); |
|
123 | emit q->clicked(); | |
121 | } |
|
124 | } | |
122 |
|
125 | |||
123 | #include "moc_qlegendmarker.cpp" |
|
126 | #include "moc_qlegendmarker.cpp" | |
124 | #include "moc_qlegendmarker_p.cpp" |
|
127 | #include "moc_qlegendmarker_p.cpp" | |
125 |
|
128 | |||
126 | QTCOMMERCIALCHART_END_NAMESPACE |
|
129 | QTCOMMERCIALCHART_END_NAMESPACE |
@@ -1,94 +1,93 | |||||
1 | /**************************************************************************** |
|
1 | /**************************************************************************** | |
2 | ** |
|
2 | ** | |
3 | ** Copyright (C) 2012 Digia Plc |
|
3 | ** Copyright (C) 2012 Digia Plc | |
4 | ** All rights reserved. |
|
4 | ** All rights reserved. | |
5 | ** For any questions to Digia, please use contact form at http://qt.digia.com |
|
5 | ** For any questions to Digia, please use contact form at http://qt.digia.com | |
6 | ** |
|
6 | ** | |
7 | ** This file is part of the Qt Commercial Charts Add-on. |
|
7 | ** This file is part of the Qt Commercial Charts Add-on. | |
8 | ** |
|
8 | ** | |
9 | ** $QT_BEGIN_LICENSE$ |
|
9 | ** $QT_BEGIN_LICENSE$ | |
10 | ** Licensees holding valid Qt Commercial licenses may use this file in |
|
10 | ** Licensees holding valid Qt Commercial licenses may use this file in | |
11 | ** accordance with the Qt Commercial License Agreement provided with the |
|
11 | ** accordance with the Qt Commercial License Agreement provided with the | |
12 | ** Software or, alternatively, in accordance with the terms contained in |
|
12 | ** Software or, alternatively, in accordance with the terms contained in | |
13 | ** a written agreement between you and Digia. |
|
13 | ** a written agreement between you and Digia. | |
14 | ** |
|
14 | ** | |
15 | ** If you have questions regarding the use of this file, please use |
|
15 | ** If you have questions regarding the use of this file, please use | |
16 | ** contact form at http://qt.digia.com |
|
16 | ** contact form at http://qt.digia.com | |
17 | ** $QT_END_LICENSE$ |
|
17 | ** $QT_END_LICENSE$ | |
18 | ** |
|
18 | ** | |
19 | ****************************************************************************/ |
|
19 | ****************************************************************************/ | |
20 |
|
20 | |||
21 | #ifndef QLEGENDMARKER_H |
|
21 | #ifndef QLEGENDMARKER_H | |
22 | #define QLEGENDMARKER_H |
|
22 | #define QLEGENDMARKER_H | |
23 |
|
23 | |||
24 | #include <QChartGlobal> |
|
24 | #include <QChartGlobal> | |
25 | #include <QObject> |
|
25 | #include <QObject> | |
26 | #include <QPen> |
|
26 | #include <QPen> | |
27 | #include <QBrush> |
|
27 | #include <QBrush> | |
28 | #include <QFont> |
|
28 | #include <QFont> | |
29 |
|
29 | |||
30 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
30 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
31 |
|
31 | |||
32 | class QLegendMarkerPrivate; |
|
32 | class QLegendMarkerPrivate; | |
33 | class QAbstractSeries; |
|
33 | class QAbstractSeries; | |
34 | class QLegend; |
|
34 | class QLegend; | |
35 |
|
35 | |||
36 | class QTCOMMERCIALCHART_EXPORT QLegendMarker : public QObject |
|
36 | class QTCOMMERCIALCHART_EXPORT QLegendMarker : public QObject | |
37 | { |
|
37 | { | |
38 | Q_OBJECT |
|
38 | Q_OBJECT | |
39 |
|
39 | |||
40 | public: |
|
40 | public: | |
41 | enum LegendMarkerType { |
|
41 | enum LegendMarkerType { | |
42 | LegendMarkerTypeArea, |
|
42 | LegendMarkerTypeArea, | |
43 | LegendMarkerTypeBar, |
|
43 | LegendMarkerTypeBar, | |
44 | LegendMarkerTypePie, |
|
44 | LegendMarkerTypePie, | |
45 | LegendMarkerTypeXY |
|
45 | LegendMarkerTypeXY | |
46 | }; |
|
46 | }; | |
47 |
|
47 | |||
48 | // TODO: |
|
48 | // TODO: | |
49 | // Q_PROPERTY(QString label READ label WRITE setlabel NOTIFY labelChanged); |
|
49 | // Q_PROPERTY(QString label READ label WRITE setlabel NOTIFY labelChanged); | |
50 | // Q_PROPERTY(QPen pen READ pen WRITE setPen NOTIFY penChanged); |
|
50 | // Q_PROPERTY(QPen pen READ pen WRITE setPen NOTIFY penChanged); | |
51 | // Q_PROPERTY(QBrush brush READ brush WRITE setBrush NOTIFY brushChanged); |
|
51 | // Q_PROPERTY(QBrush brush READ brush WRITE setBrush NOTIFY brushChanged); | |
52 |
|
52 | |||
53 | public: |
|
53 | public: | |
54 | virtual ~QLegendMarker(); |
|
54 | virtual ~QLegendMarker(); | |
55 | virtual LegendMarkerType type() = 0; |
|
55 | virtual LegendMarkerType type() = 0; | |
56 |
|
56 | |||
57 | QString label() const; |
|
57 | QString label() const; | |
58 | void setLabel(const QString &label); |
|
58 | void setLabel(const QString &label); | |
59 |
|
59 | |||
60 | QBrush labelBrush() const; |
|
60 | QBrush labelBrush() const; | |
61 | void setLabelBrush(const QBrush &brush); |
|
61 | void setLabelBrush(const QBrush &brush); | |
62 |
|
62 | |||
63 | QFont font() const; |
|
63 | QFont font() const; | |
64 | void setFont(const QFont &font); |
|
64 | void setFont(const QFont &font); | |
65 |
|
65 | |||
66 | QPen pen() const; |
|
66 | QPen pen() const; | |
67 | void setPen(const QPen &pen); |
|
67 | void setPen(const QPen &pen); | |
68 |
|
68 | |||
69 | QBrush brush() const; |
|
69 | QBrush brush() const; | |
70 | void setBrush(const QBrush &brush); |
|
70 | void setBrush(const QBrush &brush); | |
71 |
|
71 | |||
72 | bool isVisible() const; |
|
72 | bool isVisible() const; | |
73 | void setVisible(bool visible); |
|
73 | void setVisible(bool visible); | |
74 |
|
74 | |||
75 | virtual QAbstractSeries* series() = 0; |
|
75 | virtual QAbstractSeries* series() = 0; | |
76 |
|
76 | |||
77 | protected: |
|
|||
78 | explicit QLegendMarker(QLegendMarkerPrivate &d, QObject *parent = 0); |
|
|||
79 |
|
||||
80 | Q_SIGNALS: |
|
77 | Q_SIGNALS: | |
81 | void clicked(); |
|
78 | void clicked(); | |
82 | void hovered(bool status); |
|
79 | void hovered(bool status); | |
83 |
|
80 | |||
84 | protected: |
|
81 | protected: | |
|
82 | explicit QLegendMarker(QLegendMarkerPrivate &d, QObject *parent = 0); | |||
|
83 | ||||
85 | QScopedPointer<QLegendMarkerPrivate> d_ptr; |
|
84 | QScopedPointer<QLegendMarkerPrivate> d_ptr; | |
86 | Q_DISABLE_COPY(QLegendMarker) |
|
85 | Q_DISABLE_COPY(QLegendMarker) | |
87 | friend class QLegendPrivate; |
|
86 | friend class QLegendPrivate; | |
88 | friend class QLegendMarkerPrivate; |
|
87 | friend class QLegendMarkerPrivate; | |
89 | friend class LegendLayout; |
|
88 | friend class LegendLayout; | |
90 | }; |
|
89 | }; | |
91 |
|
90 | |||
92 | QTCOMMERCIALCHART_END_NAMESPACE |
|
91 | QTCOMMERCIALCHART_END_NAMESPACE | |
93 |
|
92 | |||
94 | #endif // QLEGENDMARKER_H |
|
93 | #endif // QLEGENDMARKER_H |
@@ -1,85 +1,89 | |||||
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 | #include <QDebug> |
|
39 | #include <QDebug> | |
40 |
|
40 | |||
41 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
41 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
42 |
|
42 | |||
43 | // TODO: check these |
|
43 | // TODO: check these | |
44 | class QAbstractSeries; |
|
44 | class QAbstractSeries; | |
45 | class QAreaSeries; |
|
45 | class QAreaSeries; | |
46 | class QXYSeries; |
|
46 | class QXYSeries; | |
47 | class QBarSet; |
|
47 | class QBarSet; | |
48 | class QAbstractBarSeries; |
|
48 | class QAbstractBarSeries; | |
49 | class QPieSlice; |
|
49 | class QPieSlice; | |
50 | class QLegend; |
|
50 | class QLegend; | |
51 | class QPieSeries; |
|
51 | class QPieSeries; | |
52 |
|
52 | |||
53 | class QLegendMarker; |
|
53 | class QLegendMarker; | |
54 | class LegendMarkerItem; |
|
54 | class LegendMarkerItem; | |
55 |
|
55 | |||
56 | class QLegendMarkerPrivate : public QObject |
|
56 | class QLegendMarkerPrivate : public QObject | |
57 | { |
|
57 | { | |
58 | Q_OBJECT |
|
58 | Q_OBJECT | |
59 | public: |
|
59 | public: | |
60 | explicit QLegendMarkerPrivate(QLegendMarker *q, QLegend *legend); |
|
60 | explicit QLegendMarkerPrivate(QLegendMarker *q, QLegend *legend); | |
61 | virtual ~QLegendMarkerPrivate(); |
|
61 | virtual ~QLegendMarkerPrivate(); | |
62 |
|
62 | |||
63 | // Helper for now. (or deckare LegendLayout as friend) |
|
63 | // Helper for now. (or deckare LegendLayout as friend) | |
64 | LegendMarkerItem* item() const { return m_item; } |
|
64 | LegendMarkerItem* item() const { return m_item; } | |
65 |
|
65 | |||
66 | // Item gets the event, logic for event is here |
|
66 | // Item gets the event, logic for event is here | |
67 | void handleMousePressEvent(QGraphicsSceneEvent *event); |
|
67 | void handleMousePressEvent(QGraphicsSceneEvent *event); | |
68 |
|
68 | |||
|
69 | // internal | |||
|
70 | virtual QAbstractSeries* series() = 0; | |||
|
71 | virtual QObject* relatedObject() = 0; | |||
|
72 | ||||
69 | public Q_SLOTS: |
|
73 | public Q_SLOTS: | |
70 | virtual void updated() {}; |
|
74 | virtual void updated() {}; | |
71 |
|
75 | |||
72 | protected: |
|
76 | protected: | |
73 | LegendMarkerItem *m_item; |
|
77 | LegendMarkerItem *m_item; | |
74 | QLegend* m_legend; |
|
78 | QLegend* m_legend; | |
75 |
|
79 | |||
76 | private: |
|
80 | private: | |
77 | QLegendMarker *q_ptr; |
|
81 | QLegendMarker *q_ptr; | |
78 |
|
82 | |||
79 | friend class QLegendPrivate; // TODO: Is this needed? |
|
83 | friend class QLegendPrivate; // TODO: Is this needed? | |
80 | Q_DECLARE_PUBLIC(QLegendMarker) |
|
84 | Q_DECLARE_PUBLIC(QLegendMarker) | |
81 | }; |
|
85 | }; | |
82 |
|
86 | |||
83 | QTCOMMERCIALCHART_END_NAMESPACE |
|
87 | QTCOMMERCIALCHART_END_NAMESPACE | |
84 |
|
88 | |||
85 | #endif // QLEGENDMARKERPRIVATE_H |
|
89 | #endif // QLEGENDMARKERPRIVATE_H |
@@ -1,89 +1,99 | |||||
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 | #include <QDebug> |
|
25 | #include <QDebug> | |
26 |
|
26 | |||
27 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
27 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
28 |
|
28 | |||
29 | QPieLegendMarker::QPieLegendMarker(QPieSeries* series, QPieSlice* slice, QLegend *legend, QObject *parent) : |
|
29 | QPieLegendMarker::QPieLegendMarker(QPieSeries* series, QPieSlice* slice, QLegend *legend, QObject *parent) : | |
30 | QLegendMarker(*new QPieLegendMarkerPrivate(this,series,slice,legend), parent) |
|
30 | QLegendMarker(*new QPieLegendMarkerPrivate(this,series,slice,legend), parent) | |
31 | { |
|
31 | { | |
32 | } |
|
32 | } | |
33 |
|
33 | |||
34 | QPieLegendMarker::~QPieLegendMarker() |
|
34 | QPieLegendMarker::~QPieLegendMarker() | |
35 | { |
|
35 | { | |
36 | // qDebug() << "deleting pie marker" << this; |
|
36 | // qDebug() << "deleting pie marker" << this; | |
37 | } |
|
37 | } | |
38 |
|
38 | |||
39 | /*! |
|
39 | /*! | |
40 | \internal |
|
40 | \internal | |
41 | */ |
|
41 | */ | |
42 | QPieLegendMarker::QPieLegendMarker(QPieLegendMarkerPrivate &d, QObject *parent) : |
|
42 | QPieLegendMarker::QPieLegendMarker(QPieLegendMarkerPrivate &d, QObject *parent) : | |
43 | QLegendMarker(d, parent) |
|
43 | QLegendMarker(d, parent) | |
44 | { |
|
44 | { | |
45 | } |
|
45 | } | |
46 |
|
46 | |||
47 | QPieSeries* QPieLegendMarker::series() |
|
47 | QPieSeries* QPieLegendMarker::series() | |
48 | { |
|
48 | { | |
49 | Q_D(QPieLegendMarker); |
|
49 | Q_D(QPieLegendMarker); | |
50 | return d->m_series; |
|
50 | return d->m_series; | |
51 | } |
|
51 | } | |
52 |
|
52 | |||
53 | QPieSlice* QPieLegendMarker::slice() |
|
53 | QPieSlice* QPieLegendMarker::slice() | |
54 | { |
|
54 | { | |
55 | Q_D(QPieLegendMarker); |
|
55 | Q_D(QPieLegendMarker); | |
56 | return d->m_slice; |
|
56 | return d->m_slice; | |
57 | } |
|
57 | } | |
58 |
|
58 | |||
59 | //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
|
59 | //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// | |
60 |
|
60 | |||
61 | QPieLegendMarkerPrivate::QPieLegendMarkerPrivate(QPieLegendMarker *q, QPieSeries *series, QPieSlice *slice, QLegend *legend) : |
|
61 | QPieLegendMarkerPrivate::QPieLegendMarkerPrivate(QPieLegendMarker *q, QPieSeries *series, QPieSlice *slice, QLegend *legend) : | |
62 | QLegendMarkerPrivate(q,legend), |
|
62 | QLegendMarkerPrivate(q,legend), | |
63 | m_series(series), |
|
63 | m_series(series), | |
64 | m_slice(slice) |
|
64 | m_slice(slice) | |
65 | { |
|
65 | { | |
66 | QObject::connect(m_slice, SIGNAL(labelChanged()), this, SLOT(updated())); |
|
66 | QObject::connect(m_slice, SIGNAL(labelChanged()), this, SLOT(updated())); | |
67 | QObject::connect(m_slice, SIGNAL(brushChanged()), this, SLOT(updated())); |
|
67 | QObject::connect(m_slice, SIGNAL(brushChanged()), this, SLOT(updated())); | |
68 | QObject::connect(m_slice, SIGNAL(penChanged()), this, SLOT(updated())); |
|
68 | QObject::connect(m_slice, SIGNAL(penChanged()), this, SLOT(updated())); | |
69 | updated(); |
|
69 | updated(); | |
70 | } |
|
70 | } | |
71 |
|
71 | |||
72 | QPieLegendMarkerPrivate::~QPieLegendMarkerPrivate() |
|
72 | QPieLegendMarkerPrivate::~QPieLegendMarkerPrivate() | |
73 | { |
|
73 | { | |
74 | QObject::disconnect(m_slice, SIGNAL(labelChanged()), this, SLOT(updated())); |
|
74 | QObject::disconnect(m_slice, SIGNAL(labelChanged()), this, SLOT(updated())); | |
75 | QObject::disconnect(m_slice, SIGNAL(brushChanged()), this, SLOT(updated())); |
|
75 | QObject::disconnect(m_slice, SIGNAL(brushChanged()), this, SLOT(updated())); | |
76 | QObject::disconnect(m_slice, SIGNAL(penChanged()), this, SLOT(updated())); |
|
76 | QObject::disconnect(m_slice, SIGNAL(penChanged()), this, SLOT(updated())); | |
77 | } |
|
77 | } | |
78 |
|
78 | |||
|
79 | QPieSeries* QPieLegendMarkerPrivate::series() | |||
|
80 | { | |||
|
81 | return m_series; | |||
|
82 | } | |||
|
83 | ||||
|
84 | QObject* QPieLegendMarkerPrivate::relatedObject() | |||
|
85 | { | |||
|
86 | return m_slice; | |||
|
87 | } | |||
|
88 | ||||
79 | void QPieLegendMarkerPrivate::updated() |
|
89 | void QPieLegendMarkerPrivate::updated() | |
80 | { |
|
90 | { | |
81 | m_item->setPen(m_slice->pen()); |
|
91 | m_item->setPen(m_slice->pen()); | |
82 | m_item->setBrush(m_slice->brush()); |
|
92 | m_item->setBrush(m_slice->brush()); | |
83 | m_item->setLabel(m_slice->label()); |
|
93 | m_item->setLabel(m_slice->label()); | |
84 | } |
|
94 | } | |
85 |
|
95 | |||
86 | #include "moc_qpielegendmarker.cpp" |
|
96 | #include "moc_qpielegendmarker.cpp" | |
87 | #include "moc_qpielegendmarker_p.cpp" |
|
97 | #include "moc_qpielegendmarker_p.cpp" | |
88 |
|
98 | |||
89 | QTCOMMERCIALCHART_END_NAMESPACE |
|
99 | QTCOMMERCIALCHART_END_NAMESPACE |
@@ -1,67 +1,71 | |||||
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 QPIELEGENDMARKER_P_H |
|
30 | #ifndef QPIELEGENDMARKER_P_H | |
31 | #define QPIELEGENDMARKER_P_H |
|
31 | #define QPIELEGENDMARKER_P_H | |
32 |
|
32 | |||
33 | #include "qchartglobal.h" |
|
33 | #include "qchartglobal.h" | |
34 | #include "qlegendmarker_p.h" |
|
34 | #include "qlegendmarker_p.h" | |
35 | #include "legendmarkeritem_p.h" |
|
35 | #include "legendmarkeritem_p.h" | |
36 | #include <QPieSeries> |
|
36 | #include <QPieSeries> | |
37 | #include <QPieSlice> |
|
37 | #include <QPieSlice> | |
38 |
|
38 | |||
39 | #include <QDebug> |
|
39 | #include <QDebug> | |
40 |
|
40 | |||
41 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
41 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
42 |
|
42 | |||
43 | class QPieLegendMarker; |
|
43 | class QPieLegendMarker; | |
44 |
|
44 | |||
45 | class QPieLegendMarkerPrivate : public QLegendMarkerPrivate |
|
45 | class QPieLegendMarkerPrivate : public QLegendMarkerPrivate | |
46 | { |
|
46 | { | |
47 | Q_OBJECT |
|
47 | Q_OBJECT | |
48 | public: |
|
48 | public: | |
49 | explicit QPieLegendMarkerPrivate(QPieLegendMarker *q, QPieSeries *series, QPieSlice *slice, QLegend *legend); |
|
49 | explicit QPieLegendMarkerPrivate(QPieLegendMarker *q, QPieSeries *series, QPieSlice *slice, QLegend *legend); | |
50 | virtual ~QPieLegendMarkerPrivate(); |
|
50 | virtual ~QPieLegendMarkerPrivate(); | |
51 |
|
51 | |||
|
52 | // internal | |||
|
53 | virtual QPieSeries* series(); | |||
|
54 | virtual QObject* relatedObject(); | |||
|
55 | ||||
52 | public Q_SLOTS: |
|
56 | public Q_SLOTS: | |
53 | virtual void updated(); |
|
57 | virtual void updated(); | |
54 |
|
58 | |||
55 | private: |
|
59 | private: | |
56 | QPieLegendMarker *q_ptr; |
|
60 | QPieLegendMarker *q_ptr; | |
57 |
|
61 | |||
58 | QPieSeries* m_series; |
|
62 | QPieSeries* m_series; | |
59 | QPieSlice* m_slice; |
|
63 | QPieSlice* m_slice; | |
60 |
|
64 | |||
61 | friend class QLegendPrivate; // TODO: Is this needed? |
|
65 | friend class QLegendPrivate; // TODO: Is this needed? | |
62 | Q_DECLARE_PUBLIC(QPieLegendMarker) |
|
66 | Q_DECLARE_PUBLIC(QPieLegendMarker) | |
63 | }; |
|
67 | }; | |
64 |
|
68 | |||
65 | QTCOMMERCIALCHART_END_NAMESPACE |
|
69 | QTCOMMERCIALCHART_END_NAMESPACE | |
66 |
|
70 | |||
67 | #endif // QPIELEGENDMARKER_P_H |
|
71 | #endif // QPIELEGENDMARKER_P_H |
@@ -1,85 +1,95 | |||||
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 | #include <QDebug> |
|
25 | #include <QDebug> | |
26 |
|
26 | |||
27 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
27 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
28 |
|
28 | |||
29 | QXYLegendMarker::QXYLegendMarker(QXYSeries* series, QLegend *legend, QObject *parent) : |
|
29 | QXYLegendMarker::QXYLegendMarker(QXYSeries* series, QLegend *legend, QObject *parent) : | |
30 | QLegendMarker(*new QXYLegendMarkerPrivate(this,series,legend), parent) |
|
30 | QLegendMarker(*new QXYLegendMarkerPrivate(this,series,legend), parent) | |
31 | { |
|
31 | { | |
32 | } |
|
32 | } | |
33 |
|
33 | |||
34 | QXYLegendMarker::~QXYLegendMarker() |
|
34 | QXYLegendMarker::~QXYLegendMarker() | |
35 | { |
|
35 | { | |
36 | // qDebug() << "deleting xy marker" << this; |
|
36 | // qDebug() << "deleting xy marker" << this; | |
37 | } |
|
37 | } | |
38 |
|
38 | |||
39 | /*! |
|
39 | /*! | |
40 | \internal |
|
40 | \internal | |
41 | */ |
|
41 | */ | |
42 | QXYLegendMarker::QXYLegendMarker(QXYLegendMarkerPrivate &d, QObject *parent) : |
|
42 | QXYLegendMarker::QXYLegendMarker(QXYLegendMarkerPrivate &d, QObject *parent) : | |
43 | QLegendMarker(d, parent) |
|
43 | QLegendMarker(d, parent) | |
44 | { |
|
44 | { | |
45 | } |
|
45 | } | |
46 |
|
46 | |||
47 | QXYSeries* QXYLegendMarker::series() |
|
47 | QXYSeries* QXYLegendMarker::series() | |
48 | { |
|
48 | { | |
49 | Q_D(QXYLegendMarker); |
|
49 | Q_D(QXYLegendMarker); | |
50 | return d->m_series; |
|
50 | return d->m_series; | |
51 | } |
|
51 | } | |
52 |
|
52 | |||
53 | //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
|
53 | //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// | |
54 |
|
54 | |||
55 | QXYLegendMarkerPrivate::QXYLegendMarkerPrivate(QXYLegendMarker *q, QXYSeries *series, QLegend *legend) : |
|
55 | QXYLegendMarkerPrivate::QXYLegendMarkerPrivate(QXYLegendMarker *q, QXYSeries *series, QLegend *legend) : | |
56 | QLegendMarkerPrivate(q,legend), |
|
56 | QLegendMarkerPrivate(q,legend), | |
57 | m_series(series) |
|
57 | m_series(series) | |
58 | { |
|
58 | { | |
59 | QObject::connect(m_series, SIGNAL(nameChanged()), this, SLOT(updated())); |
|
59 | QObject::connect(m_series, SIGNAL(nameChanged()), this, SLOT(updated())); | |
60 | QObject::connect(m_series->d_func(), SIGNAL(updated()), this, SLOT(updated())); |
|
60 | QObject::connect(m_series->d_func(), SIGNAL(updated()), this, SLOT(updated())); | |
61 | updated(); |
|
61 | updated(); | |
62 | } |
|
62 | } | |
63 |
|
63 | |||
64 | QXYLegendMarkerPrivate::~QXYLegendMarkerPrivate() |
|
64 | QXYLegendMarkerPrivate::~QXYLegendMarkerPrivate() | |
65 | { |
|
65 | { | |
66 | QObject::disconnect(m_series->d_func(), SIGNAL(updated()), this, SLOT(updated())); |
|
66 | QObject::disconnect(m_series->d_func(), SIGNAL(updated()), this, SLOT(updated())); | |
67 | QObject::disconnect(m_series, SIGNAL(nameChanged()), this, SLOT(updated())); |
|
67 | QObject::disconnect(m_series, SIGNAL(nameChanged()), this, SLOT(updated())); | |
68 | } |
|
68 | } | |
69 |
|
69 | |||
|
70 | QAbstractSeries* QXYLegendMarkerPrivate::series() | |||
|
71 | { | |||
|
72 | return m_series; | |||
|
73 | } | |||
|
74 | ||||
|
75 | QObject* QXYLegendMarkerPrivate::relatedObject() | |||
|
76 | { | |||
|
77 | return m_series; | |||
|
78 | } | |||
|
79 | ||||
70 | void QXYLegendMarkerPrivate::updated() |
|
80 | void QXYLegendMarkerPrivate::updated() | |
71 | { |
|
81 | { | |
72 | m_item->setLabel(m_series->name()); |
|
82 | m_item->setLabel(m_series->name()); | |
73 |
|
83 | |||
74 | if (m_series->type()== QAbstractSeries::SeriesTypeScatter) { |
|
84 | if (m_series->type()== QAbstractSeries::SeriesTypeScatter) { | |
75 | m_item->setBrush(m_series->brush()); |
|
85 | m_item->setBrush(m_series->brush()); | |
76 | } else { |
|
86 | } else { | |
77 | m_item->setBrush(QBrush(m_series->pen().color())); |
|
87 | m_item->setBrush(QBrush(m_series->pen().color())); | |
78 | } |
|
88 | } | |
79 | } |
|
89 | } | |
80 |
|
90 | |||
81 | #include "moc_qxylegendmarker.cpp" |
|
91 | #include "moc_qxylegendmarker.cpp" | |
82 | #include "moc_qxylegendmarker_p.cpp" |
|
92 | #include "moc_qxylegendmarker_p.cpp" | |
83 |
|
93 | |||
84 | QTCOMMERCIALCHART_END_NAMESPACE |
|
94 | QTCOMMERCIALCHART_END_NAMESPACE | |
85 |
|
95 |
@@ -1,65 +1,69 | |||||
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 QXYLEGENDMARKER_P_H |
|
30 | #ifndef QXYLEGENDMARKER_P_H | |
31 | #define QXYLEGENDMARKER_P_H |
|
31 | #define QXYLEGENDMARKER_P_H | |
32 |
|
32 | |||
33 | #include "qchartglobal.h" |
|
33 | #include "qchartglobal.h" | |
34 | #include "qlegendmarker_p.h" |
|
34 | #include "qlegendmarker_p.h" | |
35 | #include "legendmarkeritem_p.h" |
|
35 | #include "legendmarkeritem_p.h" | |
36 | #include <QXYSeries> |
|
36 | #include <QXYSeries> | |
37 |
|
37 | |||
38 | #include <QDebug> |
|
38 | #include <QDebug> | |
39 |
|
39 | |||
40 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
40 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
41 |
|
41 | |||
42 | class QXYLegendMarker; |
|
42 | class QXYLegendMarker; | |
43 |
|
43 | |||
44 | class QXYLegendMarkerPrivate : public QLegendMarkerPrivate |
|
44 | class QXYLegendMarkerPrivate : public QLegendMarkerPrivate | |
45 | { |
|
45 | { | |
46 | Q_OBJECT |
|
46 | Q_OBJECT | |
47 | public: |
|
47 | public: | |
48 | explicit QXYLegendMarkerPrivate(QXYLegendMarker *q, QXYSeries *series, QLegend *legend); |
|
48 | explicit QXYLegendMarkerPrivate(QXYLegendMarker *q, QXYSeries *series, QLegend *legend); | |
49 | virtual ~QXYLegendMarkerPrivate(); |
|
49 | virtual ~QXYLegendMarkerPrivate(); | |
50 |
|
50 | |||
|
51 | // internal | |||
|
52 | virtual QAbstractSeries* series(); | |||
|
53 | virtual QObject* relatedObject(); | |||
|
54 | ||||
51 | public Q_SLOTS: |
|
55 | public Q_SLOTS: | |
52 | virtual void updated(); |
|
56 | virtual void updated(); | |
53 |
|
57 | |||
54 | private: |
|
58 | private: | |
55 | QXYLegendMarker *q_ptr; |
|
59 | QXYLegendMarker *q_ptr; | |
56 |
|
60 | |||
57 | QXYSeries* m_series; |
|
61 | QXYSeries* m_series; | |
58 |
|
62 | |||
59 | friend class QLegendPrivate; // TODO: Is this needed? |
|
63 | friend class QLegendPrivate; // TODO: Is this needed? | |
60 | Q_DECLARE_PUBLIC(QXYLegendMarker) |
|
64 | Q_DECLARE_PUBLIC(QXYLegendMarker) | |
61 | }; |
|
65 | }; | |
62 |
|
66 | |||
63 | QTCOMMERCIALCHART_END_NAMESPACE |
|
67 | QTCOMMERCIALCHART_END_NAMESPACE | |
64 |
|
68 | |||
65 | #endif // QXYLEGENDMARKER_P_H |
|
69 | #endif // QXYLEGENDMARKER_P_H |
General Comments 0
You need to be logged in to leave comments.
Login now