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