##// END OF EJS Templates
Fixes blinking and minimal false size for legend
Michal Klocek -
r1538:8f0be28e5215
parent child
Show More
@@ -1,164 +1,166
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 "chartlayout_p.h"
21 #include "chartlayout_p.h"
22 #include "chartpresenter_p.h"
22 #include "chartpresenter_p.h"
23 #include "chartaxis_p.h"
23 #include "chartaxis_p.h"
24 #include <QDebug>
24
25
25 QTCOMMERCIALCHART_BEGIN_NAMESPACE
26 QTCOMMERCIALCHART_BEGIN_NAMESPACE
26
27
27 ChartLayout::ChartLayout(ChartPresenter* presenter):
28 ChartLayout::ChartLayout(ChartPresenter* presenter):
28 m_presenter(presenter),
29 m_presenter(presenter),
29 m_marginBig(60),
30 m_marginBig(60),
30 m_marginSmall(20),
31 m_marginSmall(20),
31 m_marginTiny(10),
32 m_marginTiny(10),
32 m_chartMargins(QPointF(m_marginBig,m_marginBig),QPointF(m_marginBig,m_marginBig))
33 m_chartMargins(QPointF(m_marginBig,m_marginBig),QPointF(m_marginBig,m_marginBig))
33 {
34 {
34
35
35 }
36 }
36
37
37 ChartLayout::~ChartLayout()
38 ChartLayout::~ChartLayout()
38 {
39 {
39
40
40 }
41 }
41
42
42 void ChartLayout::setGeometry(const QRectF& rect)
43 void ChartLayout::setGeometry(const QRectF& rect)
43 {
44 {
45
44 if (!rect.isValid()) return;
46 if (!rect.isValid()) return;
45
47
46 QGraphicsLayout::setGeometry(rect);
48 QGraphicsLayout::setGeometry(rect);
47
49
48 // check title size
50 // check title size
49
51
50 QSize titleSize = QSize(0,0);
52 QSize titleSize = QSize(0,0);
51
53
52 if (m_presenter->titleItem()) {
54 if (m_presenter->titleItem()) {
53 titleSize= m_presenter->titleItem()->boundingRect().size().toSize();
55 titleSize= m_presenter->titleItem()->boundingRect().size().toSize();
54 }
56 }
55
57
56 qreal axisHeight = 0;
58 qreal axisHeight = 0;
57 qreal axisWidth = 0;
59 qreal axisWidth = 0;
58
60
59 // check axis size
61 // check axis size
60
62
61 foreach (ChartAxis* axis,m_presenter->axisItems()){
63 foreach (ChartAxis* axis,m_presenter->axisItems()){
62 if(axis->axisType() == ChartAxis::X_AXIS)
64 if(axis->axisType() == ChartAxis::X_AXIS)
63 axisHeight = qMax(axis->minimumHeight(),axisHeight);
65 axisHeight = qMax(axis->minimumHeight(),axisHeight);
64 else
66 else
65 axisWidth = qMax(axis->minimumWidth(),axisWidth);
67 axisWidth = qMax(axis->minimumWidth(),axisWidth);
66 }
68 }
67
69
68 QLegend* legend = m_presenter->legend();
70 QLegend* legend = m_presenter->legend();
69
71
70 qreal titlePadding = m_chartMargins.top()/2;
72 qreal titlePadding = m_chartMargins.top()/2;
71
73
72 QRectF chartMargins = m_chartMargins;
74 QRectF chartMargins = m_chartMargins;
73
75
74 // recalculate legend position
76 // recalculate legend position
75 if (legend != 0 && legend->isVisible() && legend->isAttachedToChart()) {
77 if (legend != 0 && legend->isVisible() && legend->isAttachedToChart()) {
76
78
77 // Reserve some space for legend
79 // Reserve some space for legend
78 switch (legend->alignment()) {
80 switch (legend->alignment()) {
79
81
80 case Qt::AlignTop: {
82 case Qt::AlignTop: {
81 QSizeF legendSize = legend->effectiveSizeHint(Qt::PreferredSize,QSizeF(rect.width(),-1));
83 QSizeF legendSize = legend->effectiveSizeHint(Qt::PreferredSize,QSizeF(rect.width(),-1));
82 int topMargin = 2*m_marginTiny + titleSize.height() + legendSize.height() + m_marginTiny;
84 int topMargin = 2*m_marginTiny + titleSize.height() + legendSize.height() + m_marginTiny;
83 chartMargins = QRect(QPoint(m_chartMargins.left(),topMargin),QPoint(m_chartMargins.right(),m_chartMargins.bottom()));
85 chartMargins = QRect(QPoint(m_chartMargins.left(),topMargin),QPoint(m_chartMargins.right(),m_chartMargins.bottom()));
84 m_legendMargins = QRect(QPoint(chartMargins.left(),topMargin - (legendSize.height() + m_marginTiny)),QPoint(chartMargins.right(),rect.height()-topMargin + m_marginTiny));
86 m_legendMargins = QRect(QPoint(chartMargins.left(),topMargin - (legendSize.height() + m_marginTiny)),QPoint(chartMargins.right(),rect.height()-topMargin + m_marginTiny));
85 titlePadding = m_marginTiny + m_marginTiny;
87 titlePadding = m_marginTiny + m_marginTiny;
86 break;
88 break;
87 }
89 }
88 case Qt::AlignBottom: {
90 case Qt::AlignBottom: {
89 QSizeF legendSize = legend->effectiveSizeHint(Qt::PreferredSize,QSizeF(rect.width(),-1));
91 QSizeF legendSize = legend->effectiveSizeHint(Qt::PreferredSize,QSizeF(rect.width(),-1));
90 int bottomMargin = m_marginTiny + m_marginSmall + legendSize.height() + m_marginTiny + axisHeight;
92 int bottomMargin = m_marginTiny + m_marginSmall + legendSize.height() + m_marginTiny + axisHeight;
91 chartMargins = QRect(QPoint(m_chartMargins.left(),m_chartMargins.top()),QPoint(m_chartMargins.right(),bottomMargin));
93 chartMargins = QRect(QPoint(m_chartMargins.left(),m_chartMargins.top()),QPoint(m_chartMargins.right(),bottomMargin));
92 m_legendMargins = QRect(QPoint(chartMargins.left(),rect.height()-bottomMargin + m_marginTiny + axisHeight),QPoint(chartMargins.right(),m_marginTiny + m_marginSmall));
94 m_legendMargins = QRect(QPoint(chartMargins.left(),rect.height()-bottomMargin + m_marginTiny + axisHeight),QPoint(chartMargins.right(),m_marginTiny + m_marginSmall));
93 titlePadding = chartMargins.top()/2;
95 titlePadding = chartMargins.top()/2;
94 break;
96 break;
95 }
97 }
96 case Qt::AlignLeft: {
98 case Qt::AlignLeft: {
97 QSizeF legendSize = legend->effectiveSizeHint(Qt::PreferredSize,QSizeF(-1,rect.height()));
99 QSizeF legendSize = legend->effectiveSizeHint(Qt::PreferredSize,QSizeF(-1,rect.height()));
98 int leftPadding = m_marginTiny + m_marginSmall + legendSize.width() + m_marginTiny + axisWidth;
100 int leftPadding = m_marginTiny + m_marginSmall + legendSize.width() + m_marginTiny + axisWidth;
99 chartMargins = QRect(QPoint(leftPadding,m_chartMargins.top()),QPoint(m_chartMargins.right(),m_chartMargins.bottom()));
101 chartMargins = QRect(QPoint(leftPadding,m_chartMargins.top()),QPoint(m_chartMargins.right(),m_chartMargins.bottom()));
100 m_legendMargins = QRect(QPoint(m_marginTiny + m_marginSmall,chartMargins.top()),QPoint(rect.width()-leftPadding + m_marginTiny + axisWidth,chartMargins.bottom()));
102 m_legendMargins = QRect(QPoint(m_marginTiny + m_marginSmall,chartMargins.top()),QPoint(rect.width()-leftPadding + m_marginTiny + axisWidth,chartMargins.bottom()));
101 titlePadding = chartMargins.top()/2;
103 titlePadding = chartMargins.top()/2;
102 break;
104 break;
103 }
105 }
104 case Qt::AlignRight: {
106 case Qt::AlignRight: {
105 QSizeF legendSize = legend->effectiveSizeHint(Qt::PreferredSize,QSizeF(-1,rect.height()));
107 QSizeF legendSize = legend->effectiveSizeHint(Qt::PreferredSize,QSizeF(-1,rect.height()));
106 int rightPadding = m_marginTiny + m_marginSmall + legendSize.width() + m_marginTiny;
108 int rightPadding = m_marginTiny + m_marginSmall + legendSize.width() + m_marginTiny;
107 chartMargins = QRect(QPoint(m_chartMargins.left(),m_chartMargins.top()),QPoint(rightPadding,m_chartMargins.bottom()));
109 chartMargins = QRect(QPoint(m_chartMargins.left(),m_chartMargins.top()),QPoint(rightPadding,m_chartMargins.bottom()));
108 m_legendMargins = QRect(QPoint(rect.width()- rightPadding+ m_marginTiny ,chartMargins.top()),QPoint(m_marginTiny + m_marginSmall,chartMargins.bottom()));
110 m_legendMargins = QRect(QPoint(rect.width()- rightPadding+ m_marginTiny ,chartMargins.top()),QPoint(m_marginTiny + m_marginSmall,chartMargins.bottom()));
109 titlePadding = chartMargins.top()/2;
111 titlePadding = chartMargins.top()/2;
110 break;
112 break;
111 }
113 }
112 default: {
114 default: {
113 break;
115 break;
114 }
116 }
115 }
117 }
116
118
117 legend->setGeometry(rect.adjusted(m_legendMargins.left(),m_legendMargins.top(),-m_legendMargins.right(),-m_legendMargins.bottom()));
119 legend->setGeometry(rect.adjusted(m_legendMargins.left(),m_legendMargins.top(),-m_legendMargins.right(),-m_legendMargins.bottom()));
118 }
120 }
119
121
120 // recalculate title position
122 // recalculate title position
121 if (m_presenter->titleItem()) {
123 if (m_presenter->titleItem()) {
122 QPointF center = rect.center() - m_presenter->titleItem()->boundingRect().center();
124 QPointF center = rect.center() - m_presenter->titleItem()->boundingRect().center();
123 m_presenter->titleItem()->setPos(center.x(),titlePadding);
125 m_presenter->titleItem()->setPos(center.x(),titlePadding);
124 }
126 }
125
127
126 //recalculate background gradient
128 //recalculate background gradient
127 if (m_presenter->backgroundItem()) {
129 if (m_presenter->backgroundItem()) {
128 m_presenter->backgroundItem()->setRect(rect.adjusted(m_marginTiny,m_marginTiny, -m_marginTiny, -m_marginTiny));
130 m_presenter->backgroundItem()->setRect(rect.adjusted(m_marginTiny,m_marginTiny, -m_marginTiny, -m_marginTiny));
129 }
131 }
130
132
131 QRectF chartRect = rect.adjusted(chartMargins.left(),chartMargins.top(),-chartMargins.right(),-chartMargins.bottom());
133 QRectF chartRect = rect.adjusted(chartMargins.left(),chartMargins.top(),-chartMargins.right(),-chartMargins.bottom());
132
134
133 if(m_presenter->geometry()!=chartRect && chartRect.isValid()){
135 if(m_presenter->geometry()!=chartRect && chartRect.isValid()){
134 m_presenter->setGeometry(chartRect);
136 m_presenter->setGeometry(chartRect);
135 }else if(chartRect.size().isEmpty()){
137 }else if(chartRect.size().isEmpty()){
136 m_presenter->setGeometry(QRect(rect.width()/2,rect.height()/2,1,1));
138 m_presenter->setGeometry(QRect(rect.width()/2,rect.height()/2,1,1));
137 }
139 }
138
140
139 }
141 }
140
142
141
143
142 QSizeF ChartLayout::sizeHint ( Qt::SizeHint which, const QSizeF & constraint) const
144 QSizeF ChartLayout::sizeHint ( Qt::SizeHint which, const QSizeF & constraint) const
143 {
145 {
144 Q_UNUSED(constraint);
146 Q_UNUSED(constraint);
145 if(which == Qt::MinimumSize)
147 if(which == Qt::MinimumSize)
146 return QSize(2*(m_chartMargins.top()+m_chartMargins.bottom()),2*(m_chartMargins.top() + m_chartMargins.bottom()));
148 return QSize(2*(m_chartMargins.top()+m_chartMargins.bottom()),2*(m_chartMargins.top() + m_chartMargins.bottom()));
147 else
149 else
148 return QSize(-1,-1);
150 return QSize(-1,-1);
149 }
151 }
150
152
151 void ChartLayout::setMarginsMinimum(const QRectF& margins)
153 void ChartLayout::setMarginsMinimum(const QRectF& margins)
152 {
154 {
153 if(m_chartMargins != margins){
155 if(m_chartMargins != margins){
154 m_chartMargins = margins;
156 m_chartMargins = margins;
155 updateGeometry();
157 updateGeometry();
156 }
158 }
157 }
159 }
158
160
159 QRectF ChartLayout::margins() const
161 QRectF ChartLayout::margins() const
160 {
162 {
161 return m_chartMargins;
163 return m_chartMargins;
162 }
164 }
163
165
164 QTCOMMERCIALCHART_END_NAMESPACE
166 QTCOMMERCIALCHART_END_NAMESPACE
@@ -1,372 +1,380
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 "legendlayout_p.h"
21 #include "legendlayout_p.h"
22 #include "chartpresenter_p.h"
22 #include "chartpresenter_p.h"
23 #include "legendmarker_p.h"
23 #include "legendmarker_p.h"
24 #include "qlegend_p.h"
24 #include "qlegend_p.h"
25 #include <QDebug>
25
26
26 QTCOMMERCIALCHART_BEGIN_NAMESPACE
27 QTCOMMERCIALCHART_BEGIN_NAMESPACE
27
28
28 LegendLayout::LegendLayout(QLegend* legend):
29 LegendLayout::LegendLayout(QLegend* legend):
29 m_legend(legend)
30 m_legend(legend)
30 {
31 {
31
32
32 }
33 }
33
34
34 LegendLayout::~LegendLayout()
35 LegendLayout::~LegendLayout()
35 {
36 {
36
37
37 }
38 }
38
39
39 void LegendLayout::setOffset(qreal x, qreal y)
40 void LegendLayout::setOffset(qreal x, qreal y)
40 {
41 {
41 bool scrollHorizontal = true;
42 bool scrollHorizontal = true;
42 switch(m_legend->alignment()) {
43 switch(m_legend->alignment()) {
43 case Qt::AlignTop:
44 case Qt::AlignTop:
44 case Qt::AlignBottom: {
45 case Qt::AlignBottom: {
45 scrollHorizontal = true;
46 scrollHorizontal = true;
46 break;
47 break;
47 }
48 }
48 case Qt::AlignLeft:
49 case Qt::AlignLeft:
49 case Qt::AlignRight: {
50 case Qt::AlignRight: {
50 scrollHorizontal = false;
51 scrollHorizontal = false;
51 break;
52 break;
52 }
53 }
53 }
54 }
54
55
55 // If detached, the scrolling direction is vertical instead of horizontal and vice versa.
56 // If detached, the scrolling direction is vertical instead of horizontal and vice versa.
56 if (!m_legend->isAttachedToChart()) {
57 if (!m_legend->isAttachedToChart()) {
57 scrollHorizontal = !scrollHorizontal;
58 scrollHorizontal = !scrollHorizontal;
58 }
59 }
59
60
60 QRectF boundingRect = geometry();
61 QRectF boundingRect = geometry();
61
62
62 // Limit offset between m_minOffset and m_maxOffset
63 // Limit offset between m_minOffset and m_maxOffset
63 if (scrollHorizontal) {
64 if (scrollHorizontal) {
64 if(m_width<=boundingRect.width()) return;
65 if(m_width<=boundingRect.width()) return;
65
66
66 if (x != m_offsetX) {
67 if (x != m_offsetX) {
67 m_offsetX = qBound(m_minOffsetX, x, m_maxOffsetX);
68 m_offsetX = qBound(m_minOffsetX, x, m_maxOffsetX);
68 m_legend->d_ptr->items()->setPos(-m_offsetX,boundingRect.top());
69 m_legend->d_ptr->items()->setPos(-m_offsetX,boundingRect.top());
69 }
70 }
70 }
71 }
71 else {
72 else {
72 if(m_height<=boundingRect.height()) return;
73 if(m_height<=boundingRect.height()) return;
73
74
74 if (y != m_offsetY) {
75 if (y != m_offsetY) {
75 m_offsetY = qBound(m_minOffsetY, y, m_maxOffsetY);
76 m_offsetY = qBound(m_minOffsetY, y, m_maxOffsetY);
76 m_legend->d_ptr->items()->setPos(boundingRect.left(),-m_offsetY);
77 m_legend->d_ptr->items()->setPos(boundingRect.left(),-m_offsetY);
77 }
78 }
78 }
79 }
79 }
80 }
80
81
81 QPointF LegendLayout::offset() const
82 QPointF LegendLayout::offset() const
82 {
83 {
83 return QPointF(m_offsetX,m_offsetY);
84 return QPointF(m_offsetX,m_offsetY);
84 }
85 }
85
86
86 void LegendLayout::setGeometry(const QRectF& rect)
87 void LegendLayout::setGeometry(const QRectF& rect)
87 {
88 {
88 if (!rect.isValid()) return;
89
89
90 QGraphicsLayout::setGeometry(rect);
90 QGraphicsLayout::setGeometry(rect);
91
91
92 if(m_legend->isAttachedToChart()) {
92 if(m_legend->isAttachedToChart()) {
93 setAttachedGeometry(rect);
93 setAttachedGeometry(rect);
94 }
94 }
95 else {
95 else {
96 setDettachedGeometry(rect);
96 setDettachedGeometry(rect);
97 }
97 }
98 }
98 }
99
99
100 void LegendLayout::setAttachedGeometry(const QRectF& rect)
100 void LegendLayout::setAttachedGeometry(const QRectF& rect)
101 {
101 {
102 if (!rect.isValid()) return;
102
103
103 m_offsetX=0;
104 m_offsetX=0;
104 m_offsetY=0;
105 m_offsetY=0;
105
106
106 QSizeF size(0,0);
107 QSizeF size(0,0);
107
108
108 if( m_legend->d_ptr->markers().isEmpty()) return;
109 if( m_legend->d_ptr->markers().isEmpty()) return;
109
110
110 m_width=0;
111 m_width=0;
111 m_height=0;
112 m_height=0;
112
113
113 switch(m_legend->alignment()) {
114 switch(m_legend->alignment()) {
114
115
115 case Qt::AlignTop:
116 case Qt::AlignTop:
116
117
117 case Qt::AlignBottom: {
118 case Qt::AlignBottom: {
118 QPointF point(0,0);
119 QPointF point(0,0);
119 foreach (LegendMarker* marker, m_legend->d_ptr->markers()) {
120 foreach (LegendMarker* marker, m_legend->d_ptr->markers()) {
120 if (marker->isVisible()) {
121 if (marker->isVisible()) {
121 marker->setGeometry(QRectF(QPoint(0,0),marker->effectiveSizeHint(Qt::PreferredSize)));
122 marker->setGeometry(QRectF(QPoint(0,0),marker->effectiveSizeHint(Qt::PreferredSize)));
122 marker->setPos(point.x(),rect.height()/2 - marker->boundingRect().height()/2);
123 marker->setPos(point.x(),rect.height()/2 - marker->boundingRect().height()/2);
123 const QRectF& rect = marker->boundingRect();
124 const QRectF& rect = marker->boundingRect();
124 size = size.expandedTo(rect.size());
125 size = size.expandedTo(rect.size());
125 qreal w = rect.width();
126 qreal w = rect.width();
126 m_width+=w;
127 m_width+=w;
127 point.setX(point.x() + w);
128 point.setX(point.x() + w);
128 }
129 }
129 }
130 }
130 if(m_width<rect.width()) {
131 if(m_width<rect.width()) {
131 m_legend->d_ptr->items()->setPos(rect.width()/2-m_width/2,rect.top());
132 m_legend->d_ptr->items()->setPos(rect.width()/2-m_width/2,rect.top());
132
133
133 }
134 }
134 else {
135 else {
135 m_legend->d_ptr->items()->setPos(rect.topLeft());
136 m_legend->d_ptr->items()->setPos(rect.topLeft());
136 }
137 }
137 m_height=size.height();
138 m_height=size.height();
138 }
139 }
139 break;
140 break;
140 case Qt::AlignLeft:
141 case Qt::AlignLeft:
141 case Qt::AlignRight: {
142 case Qt::AlignRight: {
142 QPointF point(0,0);
143 QPointF point(0,0);
143 foreach (LegendMarker* marker, m_legend->d_ptr->markers()) {
144 foreach (LegendMarker* marker, m_legend->d_ptr->markers()) {
144 if (marker->isVisible()) {
145 if (marker->isVisible()) {
145 marker->setGeometry(QRectF(QPoint(0,0),marker->effectiveSizeHint(Qt::PreferredSize)));
146 marker->setGeometry(QRectF(QPoint(0,0),marker->effectiveSizeHint(Qt::PreferredSize)));
146 marker->setPos(point);
147 marker->setPos(point);
147 const QRectF& rect = marker->boundingRect();
148 const QRectF& rect = marker->boundingRect();
148 qreal h = rect.height();
149 qreal h = rect.height();
149 size = size.expandedTo(rect.size());
150 size = size.expandedTo(rect.size());
150 m_height+=h;
151 m_height+=h;
151 point.setY(point.y() + h);
152 point.setY(point.y() + h);
152 }
153 }
153 }
154 }
154 if(m_height<rect.height()) {
155 if(m_height<rect.height()) {
155 m_legend->d_ptr->items()->setPos(rect.left(),rect.height()/2-m_height/2);
156 m_legend->d_ptr->items()->setPos(rect.left(),rect.height()/2-m_height/2);
156 }
157 }
157 else {
158 else {
158 m_legend->d_ptr->items()->setPos(rect.topLeft());
159 m_legend->d_ptr->items()->setPos(rect.topLeft());
159 }
160 }
160 m_width=size.width();
161 m_width=size.width();
161 }
162 }
162 break;
163 break;
163 }
164 }
164
165
165 m_minOffsetX = 0;
166 m_minOffsetX = 0;
166 m_minOffsetY = 0;
167 m_minOffsetY = 0;
167 m_maxOffsetX = m_width - rect.width();
168 m_maxOffsetX = m_width - rect.width();
168 m_maxOffsetY = m_height - rect.height();
169 m_maxOffsetY = m_height - rect.height();
169 }
170 }
170
171
171 void LegendLayout::setDettachedGeometry(const QRectF& rect)
172 void LegendLayout::setDettachedGeometry(const QRectF& rect)
172 {
173 {
174 if (!rect.isValid()) return;
175
173 // Detached layout is different.
176 // Detached layout is different.
174 // In detached mode legend may have multiple rows and columns, so layout calculations
177 // In detached mode legend may have multiple rows and columns, so layout calculations
175 // differ a log from attached mode.
178 // differ a log from attached mode.
176 // Also the scrolling logic is bit different.
179 // Also the scrolling logic is bit different.
177
180
178 m_offsetX=0;
181 m_offsetX=0;
179 m_offsetY=0;
182 m_offsetY=0;
180
183
181 QSizeF size(0,0);
184 QSizeF size(0,0);
182
185
183 QList<LegendMarker *> markers = m_legend->d_ptr->markers();
186 QList<LegendMarker *> markers = m_legend->d_ptr->markers();
184
187
185 if(markers.isEmpty()) return;
188 if(markers.isEmpty()) return;
186
189
187 switch (m_legend->alignment()) {
190 switch (m_legend->alignment()) {
188 case Qt::AlignTop: {
191 case Qt::AlignTop: {
189 QPointF point = rect.topLeft();
192 QPointF point = rect.topLeft();
190 m_width = 0;
193 m_width = 0;
191 m_height = 0;
194 m_height = 0;
192 for (int i=0; i<markers.count(); i++) {
195 for (int i=0; i<markers.count(); i++) {
193 LegendMarker *marker = markers.at(i);
196 LegendMarker *marker = markers.at(i);
194 if (marker->isVisible()) {
197 if (marker->isVisible()) {
195 marker->setGeometry(QRectF(QPoint(0,0),marker->effectiveSizeHint(Qt::PreferredSize)));
198 marker->setGeometry(QRectF(QPoint(0,0),marker->effectiveSizeHint(Qt::PreferredSize)));
196 marker->setPos(point.x(),point.y());
199 marker->setPos(point.x(),point.y());
197 const QRectF& boundingRect = marker->boundingRect();
200 const QRectF& boundingRect = marker->boundingRect();
198 qreal w = boundingRect.width();
201 qreal w = boundingRect.width();
199 qreal h = boundingRect.height();
202 qreal h = boundingRect.height();
200 m_width = qMax(m_width,w);
203 m_width = qMax(m_width,w);
201 m_height = qMax(m_height,h);
204 m_height = qMax(m_height,h);
202 point.setX(point.x() + w);
205 point.setX(point.x() + w);
203 if (point.x() + w > rect.topLeft().x() + rect.width()) {
206 if (point.x() + w > rect.topLeft().x() + rect.width()) {
204 // Next item would go off rect.
207 // Next item would go off rect.
205 point.setX(rect.topLeft().x());
208 point.setX(rect.topLeft().x());
206 point.setY(point.y() + h);
209 point.setY(point.y() + h);
207 if (i+1 < markers.count()) {
210 if (i+1 < markers.count()) {
208 m_height += h;
211 m_height += h;
209 }
212 }
210 }
213 }
211 }
214 }
212 }
215 }
213 m_legend->d_ptr->items()->setPos(rect.topLeft());
216 m_legend->d_ptr->items()->setPos(rect.topLeft());
214
217
215 m_minOffsetX = 0;
218 m_minOffsetX = 0;
216 m_minOffsetY = 0;
219 m_minOffsetY = 0;
217 m_maxOffsetX = m_width - rect.width();
220 m_maxOffsetX = m_width - rect.width();
218 m_maxOffsetY = m_height - rect.height();
221 m_maxOffsetY = m_height - rect.height();
219 }
222 }
220 break;
223 break;
221 case Qt::AlignBottom: {
224 case Qt::AlignBottom: {
222 QPointF point = rect.bottomLeft();
225 QPointF point = rect.bottomLeft();
223 m_width = 0;
226 m_width = 0;
224 m_height = 0;
227 m_height = 0;
225 for (int i=0; i<markers.count(); i++) {
228 for (int i=0; i<markers.count(); i++) {
226 LegendMarker *marker = markers.at(i);
229 LegendMarker *marker = markers.at(i);
227 if (marker->isVisible()) {
230 if (marker->isVisible()) {
228 marker->setGeometry(QRectF(QPoint(0,0),marker->effectiveSizeHint(Qt::PreferredSize)));
231 marker->setGeometry(QRectF(QPoint(0,0),marker->effectiveSizeHint(Qt::PreferredSize)));
229 const QRectF& boundingRect = marker->boundingRect();
232 const QRectF& boundingRect = marker->boundingRect();
230 qreal w = boundingRect.width();
233 qreal w = boundingRect.width();
231 qreal h = boundingRect.height();
234 qreal h = boundingRect.height();
232 m_width = qMax(m_width,w);
235 m_width = qMax(m_width,w);
233 m_height = qMax(m_height,h);
236 m_height = qMax(m_height,h);
234 marker->setPos(point.x(),point.y() - h);
237 marker->setPos(point.x(),point.y() - h);
235 point.setX(point.x() + w);
238 point.setX(point.x() + w);
236 if (point.x() + w > rect.bottomLeft().x() + rect.width()) {
239 if (point.x() + w > rect.bottomLeft().x() + rect.width()) {
237 // Next item would go off rect.
240 // Next item would go off rect.
238 point.setX(rect.bottomLeft().x());
241 point.setX(rect.bottomLeft().x());
239 point.setY(point.y() - h);
242 point.setY(point.y() - h);
240 if (i+1 < markers.count()) {
243 if (i+1 < markers.count()) {
241 m_height += h;
244 m_height += h;
242 }
245 }
243 }
246 }
244 }
247 }
245 }
248 }
246 m_legend->d_ptr->items()->setPos(rect.topLeft());
249 m_legend->d_ptr->items()->setPos(rect.topLeft());
247
250
248 m_minOffsetX = 0;
251 m_minOffsetX = 0;
249 m_minOffsetY = qMin(rect.topLeft().y(), rect.topLeft().y() - m_height + rect.height());
252 m_minOffsetY = qMin(rect.topLeft().y(), rect.topLeft().y() - m_height + rect.height());
250 m_maxOffsetX = m_width - rect.width();
253 m_maxOffsetX = m_width - rect.width();
251 m_maxOffsetY = 0;
254 m_maxOffsetY = 0;
252 }
255 }
253 break;
256 break;
254 case Qt::AlignLeft: {
257 case Qt::AlignLeft: {
255 QPointF point = rect.topLeft();
258 QPointF point = rect.topLeft();
256 m_width = 0;
259 m_width = 0;
257 m_height = 0;
260 m_height = 0;
258 qreal maxWidth = 0;
261 qreal maxWidth = 0;
259 for (int i=0; i<markers.count(); i++) {
262 for (int i=0; i<markers.count(); i++) {
260 LegendMarker *marker = markers.at(i);
263 LegendMarker *marker = markers.at(i);
261 if (marker->isVisible()) {
264 if (marker->isVisible()) {
262 marker->setGeometry(QRectF(QPoint(0,0),marker->effectiveSizeHint(Qt::PreferredSize)));
265 marker->setGeometry(QRectF(QPoint(0,0),marker->effectiveSizeHint(Qt::PreferredSize)));
263 const QRectF& boundingRect = marker->boundingRect();
266 const QRectF& boundingRect = marker->boundingRect();
264 qreal w = boundingRect.width();
267 qreal w = boundingRect.width();
265 qreal h = boundingRect.height();
268 qreal h = boundingRect.height();
266 m_height = qMax(m_height,h);
269 m_height = qMax(m_height,h);
267 maxWidth = qMax(maxWidth,w);
270 maxWidth = qMax(maxWidth,w);
268 marker->setPos(point.x(),point.y());
271 marker->setPos(point.x(),point.y());
269 point.setY(point.y() + h);
272 point.setY(point.y() + h);
270 if (point.y() + h > rect.topLeft().y() + rect.height()) {
273 if (point.y() + h > rect.topLeft().y() + rect.height()) {
271 // Next item would go off rect.
274 // Next item would go off rect.
272 point.setX(point.x() + maxWidth);
275 point.setX(point.x() + maxWidth);
273 point.setY(rect.topLeft().y());
276 point.setY(rect.topLeft().y());
274 if (i+1 < markers.count()) {
277 if (i+1 < markers.count()) {
275 m_width += maxWidth;
278 m_width += maxWidth;
276 maxWidth = 0;
279 maxWidth = 0;
277 }
280 }
278 }
281 }
279 }
282 }
280 }
283 }
281 m_width += maxWidth;
284 m_width += maxWidth;
282 m_legend->d_ptr->items()->setPos(rect.topLeft());
285 m_legend->d_ptr->items()->setPos(rect.topLeft());
283
286
284 m_minOffsetX = 0;
287 m_minOffsetX = 0;
285 m_minOffsetY = 0;
288 m_minOffsetY = 0;
286 m_maxOffsetX = m_width - rect.width();
289 m_maxOffsetX = m_width - rect.width();
287 m_maxOffsetY = m_height - rect.height();
290 m_maxOffsetY = m_height - rect.height();
288 }
291 }
289 break;
292 break;
290 case Qt::AlignRight: {
293 case Qt::AlignRight: {
291 QPointF point = rect.topRight();
294 QPointF point = rect.topRight();
292 m_width = 0;
295 m_width = 0;
293 m_height = 0;
296 m_height = 0;
294 qreal maxWidth = 0;
297 qreal maxWidth = 0;
295 for (int i=0; i<markers.count(); i++) {
298 for (int i=0; i<markers.count(); i++) {
296 LegendMarker *marker = markers.at(i);
299 LegendMarker *marker = markers.at(i);
297 if (marker->isVisible()) {
300 if (marker->isVisible()) {
298 marker->setGeometry(QRectF(QPoint(0,0),marker->effectiveSizeHint(Qt::PreferredSize)));
301 marker->setGeometry(QRectF(QPoint(0,0),marker->effectiveSizeHint(Qt::PreferredSize)));
299 const QRectF& boundingRect = marker->boundingRect();
302 const QRectF& boundingRect = marker->boundingRect();
300 qreal w = boundingRect.width();
303 qreal w = boundingRect.width();
301 qreal h = boundingRect.height();
304 qreal h = boundingRect.height();
302 m_height = qMax(m_height,h);
305 m_height = qMax(m_height,h);
303 maxWidth = qMax(maxWidth,w);
306 maxWidth = qMax(maxWidth,w);
304 marker->setPos(point.x() - w,point.y());
307 marker->setPos(point.x() - w,point.y());
305 point.setY(point.y() + h);
308 point.setY(point.y() + h);
306 if (point.y() + h > rect.topLeft().y() + rect.height()) {
309 if (point.y() + h > rect.topLeft().y() + rect.height()) {
307 // Next item would go off rect.
310 // Next item would go off rect.
308 point.setX(point.x() - maxWidth);
311 point.setX(point.x() - maxWidth);
309 point.setY(rect.topLeft().y());
312 point.setY(rect.topLeft().y());
310 if (i+1 < markers.count()) {
313 if (i+1 < markers.count()) {
311 m_width += maxWidth;
314 m_width += maxWidth;
312 maxWidth = 0;
315 maxWidth = 0;
313 }
316 }
314 }
317 }
315 }
318 }
316 }
319 }
317 m_width += maxWidth;
320 m_width += maxWidth;
318 m_legend->d_ptr->items()->setPos(rect.topLeft());
321 m_legend->d_ptr->items()->setPos(rect.topLeft());
319
322
320 m_minOffsetX = qMin(rect.topLeft().x(), rect.topLeft().x() - m_width + rect.width());
323 m_minOffsetX = qMin(rect.topLeft().x(), rect.topLeft().x() - m_width + rect.width());
321 m_minOffsetY = 0;
324 m_minOffsetY = 0;
322 m_maxOffsetX = 0;
325 m_maxOffsetX = 0;
323 m_maxOffsetY = m_height - rect.height();
326 m_maxOffsetY = m_height - rect.height();
324 }
327 }
325 break;
328 break;
326 default:
329 default:
327 break;
330 break;
328 }
331 }
329
332
330 }
333 }
331
334
332 QSizeF LegendLayout::sizeHint ( Qt::SizeHint which, const QSizeF & constraint) const
335 QSizeF LegendLayout::sizeHint ( Qt::SizeHint which, const QSizeF & constraint) const
333 {
336 {
334 QSizeF size(0, 0);
337 QSizeF size(0, 0);
335 qreal left, top, right, bottom;
338 qreal left, top, right, bottom;
336 getContentsMargins(&left, &top, &right, &bottom);
339 getContentsMargins(&left, &top, &right, &bottom);
337
340
341 if(which!=Qt::PreferredSize) return QSizeF(-1,-1);
342
338 if(constraint.isValid()) {
343 if(constraint.isValid()) {
339 foreach(LegendMarker* marker, m_legend->d_ptr->markers()) {
344 foreach(LegendMarker* marker, m_legend->d_ptr->markers()) {
340 size = size.expandedTo(marker->effectiveSizeHint(which));
345 size = size.expandedTo(marker->effectiveSizeHint(which));
341 }
346 }
342 size = size.boundedTo(constraint);
347 size = size.boundedTo(constraint);
343 }
348 }
344 else if (constraint.width() >= 0) {
349 else if (constraint.width() >= 0) {
345 qreal width = 0;
350 qreal width = 0;
346 qreal height = 0;
351 qreal height = 0;
347 foreach(LegendMarker* marker, m_legend->d_ptr->markers()) {
352 foreach(LegendMarker* marker, m_legend->d_ptr->markers()) {
348 width+=marker->effectiveSizeHint(which).width();
353 width+=marker->effectiveSizeHint(which).width();
349 height=qMax(height,marker->effectiveSizeHint(which).height());
354 height=qMax(height,marker->effectiveSizeHint(which).height());
350 }
355 }
351
356
352 size = QSizeF(qMin(constraint.width(),width), height);
357 size = QSizeF(qMin(constraint.width(),width), height);
353 }
358 }
354 else if (constraint.height() >= 0) {
359 else if (constraint.height() >= 0) {
355 qreal width = 0;
360 qreal width = 0;
356 qreal height = 0;
361 qreal height = 0;
357 foreach(LegendMarker* marker, m_legend->d_ptr->markers()) {
362 foreach(LegendMarker* marker, m_legend->d_ptr->markers()) {
358 width=qMax(width,marker->effectiveSizeHint(which).width());
363 width=qMax(width,marker->effectiveSizeHint(which).width());
359 height+=height,marker->effectiveSizeHint(which).height();
364 height+=height,marker->effectiveSizeHint(which).height();
360 }
365 }
361 size = QSizeF(width,qMin(constraint.height(),height));
366 size = QSizeF(width,qMin(constraint.height(),height));
362 }
367 }
363 else {
368 else {
364 foreach(LegendMarker* marker, m_legend->d_ptr->markers()) {
369 foreach(LegendMarker* marker, m_legend->d_ptr->markers()) {
365 size = size.expandedTo(marker->effectiveSizeHint(which));
370 size = size.expandedTo(marker->effectiveSizeHint(which));
366 }
371 }
367 }
372 }
368 size += QSize(left + right, top + bottom);
373 size += QSize(left + right, top + bottom);
374
369 return size;
375 return size;
376
377
370 }
378 }
371
379
372 QTCOMMERCIALCHART_END_NAMESPACE
380 QTCOMMERCIALCHART_END_NAMESPACE
@@ -1,550 +1,551
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 "legendmarker_p.h"
27 #include "legendmarker_p.h"
28 #include "qxyseries.h"
28 #include "qxyseries.h"
29 #include "qlineseries.h"
29 #include "qlineseries.h"
30 #include "qareaseries.h"
30 #include "qareaseries.h"
31 #include "qscatterseries.h"
31 #include "qscatterseries.h"
32 #include "qsplineseries.h"
32 #include "qsplineseries.h"
33 #include "qbarseries.h"
33 #include "qbarseries.h"
34 #include "qstackedbarseries.h"
34 #include "qstackedbarseries.h"
35 #include "qpercentbarseries.h"
35 #include "qpercentbarseries.h"
36 #include "qbarset.h"
36 #include "qbarset.h"
37 #include "qpieseries.h"
37 #include "qpieseries.h"
38 #include "qpieseries_p.h"
38 #include "qpieseries_p.h"
39 #include "qpieslice.h"
39 #include "qpieslice.h"
40 #include "chartpresenter_p.h"
40 #include "chartpresenter_p.h"
41 #include <QPainter>
41 #include <QPainter>
42 #include <QPen>
42 #include <QPen>
43 #include <QTimer>
43 #include <QTimer>
44 #include <QGraphicsLayout>
44 #include <QGraphicsLayout>
45 #include <QGraphicsSceneEvent>
45 #include <QGraphicsSceneEvent>
46
46
47 QTCOMMERCIALCHART_BEGIN_NAMESPACE
47 QTCOMMERCIALCHART_BEGIN_NAMESPACE
48
48
49 /*!
49 /*!
50 \class QLegend
50 \class QLegend
51 \brief Legend object
51 \brief Legend object
52 \mainclass
52 \mainclass
53
53
54 QLegend is a graphical object, whics displays legend of the chart. Legend state is updated by QChart, when
54 QLegend is a graphical object, whics displays legend of the chart. Legend state is updated by QChart, when
55 series have been changed. By default, legend is drawn by QChart, but user can set a new parent to legend and
55 series have been changed. By default, legend is drawn by QChart, but user can set a new parent to legend and
56 handle the drawing manually.
56 handle the drawing manually.
57 User isn't supposed to create or delete legend objects, but can reference it via QChart class.
57 User isn't supposed to create or delete legend objects, but can reference it via QChart class.
58
58
59 \image examples_percentbarchart_legend.png
59 \image examples_percentbarchart_legend.png
60
60
61 \sa QChart
61 \sa QChart
62 */
62 */
63 /*!
63 /*!
64 \qmlclass Legend QLegend
64 \qmlclass Legend QLegend
65 \brief Legend is part of QtCommercial Chart QML API.
65 \brief Legend is part of QtCommercial Chart QML API.
66
66
67 Legend is a graphical object, whics displays legend of the chart. Legend state is updated by ChartView, when
67 Legend is a graphical object, whics displays legend of the chart. Legend state is updated by ChartView, when
68 series have been changed. Legend is used via ChartView class. For example:
68 series have been changed. Legend is used via ChartView class. For example:
69 \code
69 \code
70 ChartView {
70 ChartView {
71 legend.visible: true
71 legend.visible: true
72 legend.alignment: Qt.AlignBottom
72 legend.alignment: Qt.AlignBottom
73 // Add a few series...
73 // Add a few series...
74 }
74 }
75 \endcode
75 \endcode
76
76
77 \image examples_percentbarchart_legend.png
77 \image examples_percentbarchart_legend.png
78 */
78 */
79
79
80 /*!
80 /*!
81 \property QLegend::alignment
81 \property QLegend::alignment
82 \brief The alignment of the legend.
82 \brief The alignment of the legend.
83
83
84 Legend paints on the defined position in the chart. The following alignments are supported:
84 Legend paints on the defined position in the chart. The following alignments are supported:
85 Qt::AlignTop, Qt::AlignBottom, Qt::AlignLeft, Qt::AlignRight. If you set more than one flag the result is undefined.
85 Qt::AlignTop, Qt::AlignBottom, Qt::AlignLeft, Qt::AlignRight. If you set more than one flag the result is undefined.
86 */
86 */
87 /*!
87 /*!
88 \qmlproperty Qt.Alignment Legend::alignment
88 \qmlproperty Qt.Alignment Legend::alignment
89 \brief The alignment of the legend.
89 \brief The alignment of the legend.
90
90
91 Legend paints on the defined position in the chart. The following alignments are supported:
91 Legend paints on the defined position in the chart. The following alignments are supported:
92 Qt.AlignTop, Qt.AlignBottom, Qt.AlignLeft, Qt.AlignRight. If you set more than one flag the result is undefined.
92 Qt.AlignTop, Qt.AlignBottom, Qt.AlignLeft, Qt.AlignRight. If you set more than one flag the result is undefined.
93 */
93 */
94
94
95 /*!
95 /*!
96 \property QLegend::backgroundVisible
96 \property QLegend::backgroundVisible
97 Whether the legend background is visible or not.
97 Whether the legend background is visible or not.
98 */
98 */
99 /*!
99 /*!
100 \qmlproperty bool Legend::backgroundVisible
100 \qmlproperty bool Legend::backgroundVisible
101 Whether the legend background is visible or not.
101 Whether the legend background is visible or not.
102 */
102 */
103
103
104 /*!
104 /*!
105 \property QLegend::color
105 \property QLegend::color
106 The color of the legend, i.e. the background (brush) color. Note that if you change the color
106 The color of the legend, i.e. the background (brush) color. Note that if you change the color
107 of the legend, the style of the legend brush is set to Qt::SolidPattern.
107 of the legend, the style of the legend brush is set to Qt::SolidPattern.
108 */
108 */
109 /*!
109 /*!
110 \qmlproperty color Legend::color
110 \qmlproperty color Legend::color
111 The color of the legend, i.e. the background (brush) color.
111 The color of the legend, i.e. the background (brush) color.
112 */
112 */
113
113
114 /*!
114 /*!
115 \property QLegend::borderColor
115 \property QLegend::borderColor
116 The border color of the legend, i.e. the line color.
116 The border color of the legend, i.e. the line color.
117 */
117 */
118 /*!
118 /*!
119 \qmlproperty color Legend::borderColor
119 \qmlproperty color Legend::borderColor
120 The border color of the legend, i.e. the line color.
120 The border color of the legend, i.e. the line color.
121 */
121 */
122
122
123 /*!
123 /*!
124 \property QLegend::font
124 \property QLegend::font
125 The font of markers used by legend
125 The font of markers used by legend
126 */
126 */
127 /*!
127 /*!
128 \qmlproperty color Legend::font
128 \qmlproperty color Legend::font
129 The font of markers used by legend
129 The font of markers used by legend
130 */
130 */
131
131
132 /*!
132 /*!
133 \property QLegend::labelColor
133 \property QLegend::labelColor
134 The color of brush used to draw labels.
134 The color of brush used to draw labels.
135 */
135 */
136 /*!
136 /*!
137 \qmlproperty color QLegend::labelColor
137 \qmlproperty color QLegend::labelColor
138 The color of brush used to draw labels.
138 The color of brush used to draw labels.
139 */
139 */
140
140
141 /*!
141 /*!
142 \fn void QLegend::backgroundVisibleChanged(bool)
142 \fn void QLegend::backgroundVisibleChanged(bool)
143 The visibility of the legend background changed to \a visible.
143 The visibility of the legend background changed to \a visible.
144 */
144 */
145
145
146 /*!
146 /*!
147 \fn void QLegend::colorChanged(QColor)
147 \fn void QLegend::colorChanged(QColor)
148 The color of the legend background changed to \a color.
148 The color of the legend background changed to \a color.
149 */
149 */
150
150
151 /*!
151 /*!
152 \fn void QLegend::borderColorChanged(QColor)
152 \fn void QLegend::borderColorChanged(QColor)
153 The border color of the legend background changed to \a color.
153 The border color of the legend background changed to \a color.
154 */
154 */
155
155
156 /*!
156 /*!
157 \fn void QLegend::fontChanged(QFont)
157 \fn void QLegend::fontChanged(QFont)
158 The font of markers of the legend changed to \a font.
158 The font of markers of the legend changed to \a font.
159 */
159 */
160
160
161 /*!
161 /*!
162 \fn void QLegend::labelBrushChanged(QBrush brush)
162 \fn void QLegend::labelBrushChanged(QBrush brush)
163 This signal is emitted when the brush used to draw labels has changed to \a brush.
163 This signal is emitted when the brush used to draw labels has changed to \a brush.
164 */
164 */
165
165
166 /*!
166 /*!
167 \fn void QLegend::labelColorChanged(QColor color)
167 \fn void QLegend::labelColorChanged(QColor color)
168 This signal is emitted when the color of brush used to draw labels has changed to \a color.
168 This signal is emitted when the color of brush used to draw labels has changed to \a color.
169 */
169 */
170
170
171 /*!
171 /*!
172 \fn qreal QLegend::minWidth() const
172 \fn qreal QLegend::minWidth() const
173 Returns minimum width of the legend
173 Returns minimum width of the legend
174 */
174 */
175
175
176 /*!
176 /*!
177 \fn qreal QLegend::minHeight() const
177 \fn qreal QLegend::minHeight() const
178 Returns minimum height of the legend
178 Returns minimum height of the legend
179 */
179 */
180
180
181 /*!
181 /*!
182 Constructs the legend object and sets the parent to \a parent
182 Constructs the legend object and sets the parent to \a parent
183 */
183 */
184
184
185 QLegend::QLegend(QChart *chart):QGraphicsWidget(chart),
185 QLegend::QLegend(QChart *chart):QGraphicsWidget(chart),
186 d_ptr(new QLegendPrivate(chart->d_ptr->m_presenter,chart,this))
186 d_ptr(new QLegendPrivate(chart->d_ptr->m_presenter,chart,this))
187 {
187 {
188 setZValue(ChartPresenter::LegendZValue);
188 setZValue(ChartPresenter::LegendZValue);
189 setFlags(QGraphicsItem::ItemClipsChildrenToShape);
189 setFlags(QGraphicsItem::ItemClipsChildrenToShape);
190 QObject::connect(chart->d_ptr->m_dataset,SIGNAL(seriesAdded(QAbstractSeries*,Domain*)),d_ptr.data(),SLOT(handleSeriesAdded(QAbstractSeries*,Domain*)));
190 QObject::connect(chart->d_ptr->m_dataset,SIGNAL(seriesAdded(QAbstractSeries*,Domain*)),d_ptr.data(),SLOT(handleSeriesAdded(QAbstractSeries*,Domain*)));
191 QObject::connect(chart->d_ptr->m_dataset,SIGNAL(seriesRemoved(QAbstractSeries*)),d_ptr.data(),SLOT(handleSeriesRemoved(QAbstractSeries*)));
191 QObject::connect(chart->d_ptr->m_dataset,SIGNAL(seriesRemoved(QAbstractSeries*)),d_ptr.data(),SLOT(handleSeriesRemoved(QAbstractSeries*)));
192 QObject::connect(chart->d_ptr->m_dataset,SIGNAL(seriesUpdated(QAbstractSeries*)),d_ptr.data(),SLOT(handleSeriesUpdated(QAbstractSeries*)));
192 QObject::connect(chart->d_ptr->m_dataset,SIGNAL(seriesUpdated(QAbstractSeries*)),d_ptr.data(),SLOT(handleSeriesUpdated(QAbstractSeries*)));
193 setLayout(d_ptr->m_layout);
193 setLayout(d_ptr->m_layout);
194 }
194 }
195
195
196 /*!
196 /*!
197 Destroys the legend object. Legend is always owned by a QChart, so an application should never call this.
197 Destroys the legend object. Legend is always owned by a QChart, so an application should never call this.
198 */
198 */
199 QLegend::~QLegend()
199 QLegend::~QLegend()
200 {
200 {
201 }
201 }
202
202
203 /*!
203 /*!
204 \internal
204 \internal
205 */
205 */
206 void QLegend::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget)
206 void QLegend::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget)
207 {
207 {
208 Q_UNUSED(option)
208 Q_UNUSED(option)
209 Q_UNUSED(widget)
209 Q_UNUSED(widget)
210 if(!d_ptr->m_backgroundVisible) return;
210 if(!d_ptr->m_backgroundVisible) return;
211
211
212 painter->setOpacity(opacity());
212 painter->setOpacity(opacity());
213 painter->setPen(d_ptr->m_pen);
213 painter->setPen(d_ptr->m_pen);
214 painter->setBrush(d_ptr->m_brush);
214 painter->setBrush(d_ptr->m_brush);
215 painter->drawRoundRect(rect(),d_ptr->roundness(rect().width()),d_ptr->roundness(rect().height()));
215 painter->drawRoundRect(rect(),d_ptr->roundness(rect().width()),d_ptr->roundness(rect().height()));
216
216
217 }
217 }
218
218
219
219
220 /*!
220 /*!
221 Sets the \a brush of legend. Brush affects the background of legend.
221 Sets the \a brush of legend. Brush affects the background of legend.
222 */
222 */
223 void QLegend::setBrush(const QBrush &brush)
223 void QLegend::setBrush(const QBrush &brush)
224 {
224 {
225 if (d_ptr->m_brush != brush) {
225 if (d_ptr->m_brush != brush) {
226 d_ptr->m_brush = brush;
226 d_ptr->m_brush = brush;
227 update();
227 update();
228 }
228 }
229 }
229 }
230
230
231 /*!
231 /*!
232 Returns the brush used by legend.
232 Returns the brush used by legend.
233 */
233 */
234 QBrush QLegend::brush() const
234 QBrush QLegend::brush() const
235 {
235 {
236 return d_ptr->m_brush;
236 return d_ptr->m_brush;
237 }
237 }
238
238
239 void QLegend::setColor(QColor color)
239 void QLegend::setColor(QColor color)
240 {
240 {
241 QBrush b = d_ptr->m_brush;
241 QBrush b = d_ptr->m_brush;
242 if (b.style() != Qt::SolidPattern || b.color() != color) {
242 if (b.style() != Qt::SolidPattern || b.color() != color) {
243 b.setStyle(Qt::SolidPattern);
243 b.setStyle(Qt::SolidPattern);
244 b.setColor(color);
244 b.setColor(color);
245 setBrush(b);
245 setBrush(b);
246 emit colorChanged(color);
246 emit colorChanged(color);
247 }
247 }
248 }
248 }
249
249
250 QColor QLegend::color()
250 QColor QLegend::color()
251 {
251 {
252 return d_ptr->m_brush.color();
252 return d_ptr->m_brush.color();
253 }
253 }
254
254
255 /*!
255 /*!
256 Sets the \a pen of legend. Pen affects the legend borders.
256 Sets the \a pen of legend. Pen affects the legend borders.
257 */
257 */
258 void QLegend::setPen(const QPen &pen)
258 void QLegend::setPen(const QPen &pen)
259 {
259 {
260 if (d_ptr->m_pen != pen) {
260 if (d_ptr->m_pen != pen) {
261 d_ptr->m_pen = pen;
261 d_ptr->m_pen = pen;
262 update();
262 update();
263 }
263 }
264 }
264 }
265
265
266 /*!
266 /*!
267 Returns the pen used by legend
267 Returns the pen used by legend
268 */
268 */
269
269
270 QPen QLegend::pen() const
270 QPen QLegend::pen() const
271 {
271 {
272 return d_ptr->m_pen;
272 return d_ptr->m_pen;
273 }
273 }
274
274
275 void QLegend::setFont(const QFont &font)
275 void QLegend::setFont(const QFont &font)
276 {
276 {
277 if (d_ptr->m_font != font) {
277 if (d_ptr->m_font != font) {
278 d_ptr->m_font = font;
278 d_ptr->m_font = font;
279
279
280 foreach (LegendMarker *marker, d_ptr->markers()) {
280 foreach (LegendMarker *marker, d_ptr->markers()) {
281 marker->setFont(d_ptr->m_font);
281 marker->setFont(d_ptr->m_font);
282 }
282 }
283 layout()->invalidate();
283 layout()->invalidate();
284 emit fontChanged(font);
284 emit fontChanged(font);
285 }
285 }
286 }
286 }
287
287
288 QFont QLegend::font() const
288 QFont QLegend::font() const
289 {
289 {
290 return d_ptr->m_font;
290 return d_ptr->m_font;
291 }
291 }
292
292
293 void QLegend::setBorderColor(QColor color)
293 void QLegend::setBorderColor(QColor color)
294 {
294 {
295 QPen p = d_ptr->m_pen;
295 QPen p = d_ptr->m_pen;
296 if (p.color() != color) {
296 if (p.color() != color) {
297 p.setColor(color);
297 p.setColor(color);
298 setPen(p);
298 setPen(p);
299 emit borderColorChanged(color);
299 emit borderColorChanged(color);
300 }
300 }
301 }
301 }
302
302
303 QColor QLegend::borderColor()
303 QColor QLegend::borderColor()
304 {
304 {
305 return d_ptr->m_pen.color();
305 return d_ptr->m_pen.color();
306 }
306 }
307
307
308 /*!
308 /*!
309 Set brush used to draw labels to \a brush.
309 Set brush used to draw labels to \a brush.
310 */
310 */
311 void QLegend::setLabelBrush(const QBrush &brush)
311 void QLegend::setLabelBrush(const QBrush &brush)
312 {
312 {
313 if (d_ptr->m_labelBrush != brush) {
313 if (d_ptr->m_labelBrush != brush) {
314
314
315 d_ptr->m_labelBrush = brush;
315 d_ptr->m_labelBrush = brush;
316
316
317 foreach (LegendMarker *marker, d_ptr->markers()) {
317 foreach (LegendMarker *marker, d_ptr->markers()) {
318 marker->setLabelBrush(d_ptr->m_labelBrush);
318 marker->setLabelBrush(d_ptr->m_labelBrush);
319 }
319 }
320 emit labelBrushChanged(brush);
320 emit labelBrushChanged(brush);
321 }
321 }
322 }
322 }
323
323
324 /*!
324 /*!
325 Brush used to draw labels.
325 Brush used to draw labels.
326 */
326 */
327 QBrush QLegend::labelBrush() const
327 QBrush QLegend::labelBrush() const
328 {
328 {
329 return d_ptr->m_labelBrush;
329 return d_ptr->m_labelBrush;
330 }
330 }
331
331
332 void QLegend::setLabelColor(QColor color)
332 void QLegend::setLabelColor(QColor color)
333 {
333 {
334 QBrush b = d_ptr->m_labelBrush;
334 QBrush b = d_ptr->m_labelBrush;
335 if (b.style() != Qt::SolidPattern || b.color() != color) {
335 if (b.style() != Qt::SolidPattern || b.color() != color) {
336 b.setStyle(Qt::SolidPattern);
336 b.setStyle(Qt::SolidPattern);
337 b.setColor(color);
337 b.setColor(color);
338 setLabelBrush(b);
338 setLabelBrush(b);
339 emit labelColorChanged(color);
339 emit labelColorChanged(color);
340 }
340 }
341 }
341 }
342
342
343 QColor QLegend::labelColor() const
343 QColor QLegend::labelColor() const
344 {
344 {
345 return d_ptr->m_labelBrush.color();
345 return d_ptr->m_labelBrush.color();
346 }
346 }
347
347
348
348
349 void QLegend::setAlignment(Qt::Alignment alignment)
349 void QLegend::setAlignment(Qt::Alignment alignment)
350 {
350 {
351 if(d_ptr->m_alignment!=alignment) {
351 if(d_ptr->m_alignment!=alignment) {
352 d_ptr->m_alignment = alignment;
352 d_ptr->m_alignment = alignment;
353 updateGeometry();
353 updateGeometry();
354 if(isAttachedToChart()){
354 if(isAttachedToChart()){
355 d_ptr->m_presenter->layout()->invalidate();
355 d_ptr->m_presenter->layout()->invalidate();
356 }else{
356 }else{
357 layout()->invalidate();
357 layout()->invalidate();
358 }
358 }
359 }
359 }
360 }
360 }
361
361
362 Qt::Alignment QLegend::alignment() const
362 Qt::Alignment QLegend::alignment() const
363 {
363 {
364 return d_ptr->m_alignment;
364 return d_ptr->m_alignment;
365 }
365 }
366
366
367 /*!
367 /*!
368 Detaches the legend from chart. Chart won't change layout of the legend.
368 Detaches the legend from chart. Chart won't change layout of the legend.
369 */
369 */
370 void QLegend::detachFromChart()
370 void QLegend::detachFromChart()
371 {
371 {
372 d_ptr->m_attachedToChart = false;
372 d_ptr->m_attachedToChart = false;
373 d_ptr->m_layout->invalidate();
373 d_ptr->m_layout->invalidate();
374 setParent(0);
374 setParent(0);
375
375
376 }
376 }
377
377
378 /*!
378 /*!
379 Attaches the legend to chart. Chart may change layout of the legend.
379 Attaches the legend to chart. Chart may change layout of the legend.
380 */
380 */
381 void QLegend::attachToChart()
381 void QLegend::attachToChart()
382 {
382 {
383 d_ptr->m_attachedToChart = true;
383 d_ptr->m_attachedToChart = true;
384 d_ptr->m_layout->invalidate();
384 d_ptr->m_layout->invalidate();
385 setParent(d_ptr->m_chart);
385 setParent(d_ptr->m_chart);
386 }
386 }
387
387
388 /*!
388 /*!
389 Returns true, if legend is attached to chart.
389 Returns true, if legend is attached to chart.
390 */
390 */
391 bool QLegend::isAttachedToChart()
391 bool QLegend::isAttachedToChart()
392 {
392 {
393 return d_ptr->m_attachedToChart;
393 return d_ptr->m_attachedToChart;
394 }
394 }
395
395
396 /*!
396 /*!
397 Sets the visibility of legend background to \a visible
397 Sets the visibility of legend background to \a visible
398 */
398 */
399 void QLegend::setBackgroundVisible(bool visible)
399 void QLegend::setBackgroundVisible(bool visible)
400 {
400 {
401 if(d_ptr->m_backgroundVisible != visible) {
401 if(d_ptr->m_backgroundVisible != visible) {
402 d_ptr->m_backgroundVisible = visible;
402 d_ptr->m_backgroundVisible = visible;
403 update();
403 update();
404 emit backgroundVisibleChanged(visible);
404 emit backgroundVisibleChanged(visible);
405 }
405 }
406 }
406 }
407
407
408 /*!
408 /*!
409 Returns the visibility of legend background
409 Returns the visibility of legend background
410 */
410 */
411 bool QLegend::isBackgroundVisible() const
411 bool QLegend::isBackgroundVisible() const
412 {
412 {
413 return d_ptr->m_backgroundVisible;
413 return d_ptr->m_backgroundVisible;
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 QGraphicsWidget::hideEvent(event);
421 QGraphicsWidget::hideEvent(event);
422 d_ptr->m_presenter->layout()->invalidate();
422 d_ptr->m_presenter->layout()->invalidate();
423 }
423 }
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 QGraphicsWidget::showEvent(event);
430 QGraphicsWidget::showEvent(event);
431 d_ptr->m_presenter->layout()->invalidate();
431 d_ptr->m_presenter->layout()->invalidate();
432 }
432 }
433
433
434 ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
434 ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
435
435
436 QLegendPrivate::QLegendPrivate(ChartPresenter* presenter, QChart *chart, QLegend *q):
436 QLegendPrivate::QLegendPrivate(ChartPresenter* presenter, QChart *chart, QLegend *q):
437 q_ptr(q),
437 q_ptr(q),
438 m_presenter(presenter),
438 m_presenter(presenter),
439 m_layout(new LegendLayout(q)),
439 m_layout(new LegendLayout(q)),
440 m_chart(chart),
440 m_chart(chart),
441 m_items(new QGraphicsItemGroup(q)),
441 m_items(new QGraphicsItemGroup(q)),
442 m_alignment(Qt::AlignTop),
442 m_alignment(Qt::AlignTop),
443 m_brush(QBrush()),
443 m_brush(QBrush()),
444 m_pen(QPen()),
444 m_pen(QPen()),
445 m_labelBrush(QBrush()),
445 m_labelBrush(QBrush()),
446 m_diameter(5),
446 m_diameter(5),
447 m_attachedToChart(true),
447 m_attachedToChart(true),
448 m_backgroundVisible(false)
448 m_backgroundVisible(false)
449 {
449 {
450
450
451 }
451 }
452
452
453 QLegendPrivate::~QLegendPrivate()
453 QLegendPrivate::~QLegendPrivate()
454 {
454 {
455
455
456 }
456 }
457
457
458 void QLegendPrivate::setOffset(qreal x, qreal y)
458 void QLegendPrivate::setOffset(qreal x, qreal y)
459 {
459 {
460 m_layout->setOffset(x,y);
460 m_layout->setOffset(x,y);
461 }
461 }
462
462
463 QPointF QLegendPrivate::offset() const
463 QPointF QLegendPrivate::offset() const
464 {
464 {
465 return m_layout->offset();
465 return m_layout->offset();
466 }
466 }
467
467
468 int QLegendPrivate::roundness(qreal size)
468 int QLegendPrivate::roundness(qreal size)
469 {
469 {
470 return 100*m_diameter/int(size);
470 return 100*m_diameter/int(size);
471 }
471 }
472
472
473 void QLegendPrivate::handleSeriesAdded(QAbstractSeries *series, Domain *domain)
473 void QLegendPrivate::handleSeriesAdded(QAbstractSeries *series, Domain *domain)
474 {
474 {
475 Q_UNUSED(domain)
475 Q_UNUSED(domain)
476
476
477 QList<LegendMarker*> markers = series->d_ptr->createLegendMarker(q_ptr);
477 QList<LegendMarker*> markers = series->d_ptr->createLegendMarker(q_ptr);
478
478
479 foreach(LegendMarker* marker, markers) {
479 foreach(LegendMarker* marker, markers) {
480 marker->setFont(m_font);
480 marker->setFont(m_font);
481 marker->setLabelBrush(m_labelBrush);
481 marker->setLabelBrush(m_labelBrush);
482 m_items->addToGroup(marker);
482 m_items->addToGroup(marker);
483 m_markers<<marker;
483 m_markers<<marker;
484 }
484 }
485
485
486 QObject::connect(series, SIGNAL(visibleChanged()), this, SLOT(handleSeriesVisibleChanged()));
486 QObject::connect(series, SIGNAL(visibleChanged()), this, SLOT(handleSeriesVisibleChanged()));
487
487
488 if(series->type() == QAbstractSeries::SeriesTypePie) {
488 if(series->type() == QAbstractSeries::SeriesTypePie) {
489 QPieSeries *pieSeries = static_cast<QPieSeries *>(series);
489 QPieSeries *pieSeries = static_cast<QPieSeries *>(series);
490 QObject::connect(pieSeries, SIGNAL(added(QList<QPieSlice*>)), this, SLOT(handleUpdatePieSeries()));
490 QObject::connect(pieSeries, SIGNAL(added(QList<QPieSlice*>)), this, SLOT(handleUpdatePieSeries()));
491 QObject::connect(pieSeries, SIGNAL(removed(QList<QPieSlice*>)), this, SLOT(handleUpdatePieSeries()));
491 QObject::connect(pieSeries, SIGNAL(removed(QList<QPieSlice*>)), this, SLOT(handleUpdatePieSeries()));
492 }
492 }
493
493
494 q_ptr->layout()->invalidate();
494 q_ptr->layout()->invalidate();
495 q_ptr->layout()->activate();
495 }
496 }
496
497
497 void QLegendPrivate::handleSeriesRemoved(QAbstractSeries *series)
498 void QLegendPrivate::handleSeriesRemoved(QAbstractSeries *series)
498 {
499 {
499 foreach (LegendMarker *marker, m_markers) {
500 foreach (LegendMarker *marker, m_markers) {
500 if (marker->series() == series) {
501 if (marker->series() == series) {
501 delete marker;
502 delete marker;
502 m_markers.removeAll(marker);
503 m_markers.removeAll(marker);
503 }
504 }
504 }
505 }
505
506
506 if(series->type() == QAbstractSeries::SeriesTypePie)
507 if(series->type() == QAbstractSeries::SeriesTypePie)
507 {
508 {
508 QPieSeries *pieSeries = static_cast<QPieSeries *>(series);
509 QPieSeries *pieSeries = static_cast<QPieSeries *>(series);
509 QObject::disconnect(pieSeries, SIGNAL(added(QList<QPieSlice*>)), this, SLOT(handleUpdatePieSeries()));
510 QObject::disconnect(pieSeries, SIGNAL(added(QList<QPieSlice*>)), this, SLOT(handleUpdatePieSeries()));
510 QObject::disconnect(pieSeries, SIGNAL(removed(QList<QPieSlice*>)), this, SLOT(handleUpdatePieSeries()));
511 QObject::disconnect(pieSeries, SIGNAL(removed(QList<QPieSlice*>)), this, SLOT(handleUpdatePieSeries()));
511 }
512 }
512
513
513 q_ptr->layout()->invalidate();
514 q_ptr->layout()->invalidate();
514 }
515 }
515
516
516 void QLegendPrivate::handleSeriesUpdated(QAbstractSeries *series)
517 void QLegendPrivate::handleSeriesUpdated(QAbstractSeries *series)
517 {
518 {
518 // TODO: find out which markers are are added or removed. Update them
519 // TODO: find out which markers are are added or removed. Update them
519 // TODO: better implementation
520 // TODO: better implementation
520 handleSeriesRemoved(series);
521 handleSeriesRemoved(series);
521 Domain domain;
522 Domain domain;
522 handleSeriesAdded(series, &domain);
523 handleSeriesAdded(series, &domain);
523 }
524 }
524
525
525 void QLegendPrivate::handleUpdatePieSeries()
526 void QLegendPrivate::handleUpdatePieSeries()
526 {
527 {
527 //TODO: reimplement to be optimal
528 //TODO: reimplement to be optimal
528 QPieSeries* series = qobject_cast<QPieSeries *> (sender());
529 QPieSeries* series = qobject_cast<QPieSeries *> (sender());
529 Q_ASSERT(series);
530 Q_ASSERT(series);
530 handleSeriesRemoved(series);
531 handleSeriesRemoved(series);
531 handleSeriesAdded(series, 0);
532 handleSeriesAdded(series, 0);
532 }
533 }
533
534
534 void QLegendPrivate::handleSeriesVisibleChanged()
535 void QLegendPrivate::handleSeriesVisibleChanged()
535 {
536 {
536 QAbstractSeries* series = qobject_cast<QAbstractSeries *> (sender());
537 QAbstractSeries* series = qobject_cast<QAbstractSeries *> (sender());
537
538
538 foreach (LegendMarker* marker, m_markers) {
539 foreach (LegendMarker* marker, m_markers) {
539 if (marker->series() == series) {
540 if (marker->series() == series) {
540 marker->setVisible(!marker->isVisible());
541 marker->setVisible(!marker->isVisible());
541 }
542 }
542 }
543 }
543
544
544 q_ptr->layout()->invalidate();
545 q_ptr->layout()->invalidate();
545 }
546 }
546
547
547 #include "moc_qlegend.cpp"
548 #include "moc_qlegend.cpp"
548 #include "moc_qlegend_p.cpp"
549 #include "moc_qlegend_p.cpp"
549
550
550 QTCOMMERCIALCHART_END_NAMESPACE
551 QTCOMMERCIALCHART_END_NAMESPACE
General Comments 0
You need to be logged in to leave comments. Login now