##// END OF EJS Templates
Fixes detach legend layout logic
Michal Klocek -
r1536:b5727e9e0a5c
parent child
Show More
@@ -180,30 +180,31 void LegendLayout::setDettachedGeometry(const QRectF& rect)
180 180
181 181 QSizeF size(0,0);
182 182
183 if( m_legend->d_ptr->markers().isEmpty()) return;
183 QList<LegendMarker *> markers = m_legend->d_ptr->markers();
184 184
185 QList<QGraphicsItem *> items = m_legend->d_ptr->items()->childItems();
185 if(markers.isEmpty()) return;
186 186
187 187 switch (m_legend->alignment()) {
188 188 case Qt::AlignTop: {
189 189 QPointF point = rect.topLeft();
190 190 m_width = 0;
191 191 m_height = 0;
192 for (int i=0; i<items.count(); i++) {
193 QGraphicsItem *item = items.at(i);
194 if (item->isVisible()) {
195 const QRectF& boundingRect = item->boundingRect();
192 for (int i=0; i<markers.count(); i++) {
193 LegendMarker *marker = markers.at(i);
194 if (marker->isVisible()) {
195 marker->setGeometry(QRectF(QPoint(0,0),marker->effectiveSizeHint(Qt::PreferredSize)));
196 marker->setPos(point.x(),point.y());
197 const QRectF& boundingRect = marker->boundingRect();
196 198 qreal w = boundingRect.width();
197 199 qreal h = boundingRect.height();
198 200 m_width = qMax(m_width,w);
199 201 m_height = qMax(m_height,h);
200 item->setPos(point.x(),point.y());
201 202 point.setX(point.x() + w);
202 203 if (point.x() + w > rect.topLeft().x() + rect.width()) {
203 204 // Next item would go off rect.
204 205 point.setX(rect.topLeft().x());
205 206 point.setY(point.y() + h);
206 if (i+1 < items.count()) {
207 if (i+1 < markers.count()) {
207 208 m_height += h;
208 209 }
209 210 }
@@ -221,21 +222,22 void LegendLayout::setDettachedGeometry(const QRectF& rect)
221 222 QPointF point = rect.bottomLeft();
222 223 m_width = 0;
223 224 m_height = 0;
224 for (int i=0; i<items.count(); i++) {
225 QGraphicsItem *item = items.at(i);
226 if (item->isVisible()) {
227 const QRectF& boundingRect = item->boundingRect();
225 for (int i=0; i<markers.count(); i++) {
226 LegendMarker *marker = markers.at(i);
227 if (marker->isVisible()) {
228 marker->setGeometry(QRectF(QPoint(0,0),marker->effectiveSizeHint(Qt::PreferredSize)));
229 const QRectF& boundingRect = marker->boundingRect();
228 230 qreal w = boundingRect.width();
229 231 qreal h = boundingRect.height();
230 232 m_width = qMax(m_width,w);
231 233 m_height = qMax(m_height,h);
232 item->setPos(point.x(),point.y() - h);
234 marker->setPos(point.x(),point.y() - h);
233 235 point.setX(point.x() + w);
234 236 if (point.x() + w > rect.bottomLeft().x() + rect.width()) {
235 237 // Next item would go off rect.
236 238 point.setX(rect.bottomLeft().x());
237 239 point.setY(point.y() - h);
238 if (i+1 < items.count()) {
240 if (i+1 < markers.count()) {
239 241 m_height += h;
240 242 }
241 243 }
@@ -254,21 +256,22 void LegendLayout::setDettachedGeometry(const QRectF& rect)
254 256 m_width = 0;
255 257 m_height = 0;
256 258 qreal maxWidth = 0;
257 for (int i=0; i<items.count(); i++) {
258 QGraphicsItem *item = items.at(i);
259 if (item->isVisible()) {
260 const QRectF& boundingRect = item->boundingRect();
259 for (int i=0; i<markers.count(); i++) {
260 LegendMarker *marker = markers.at(i);
261 if (marker->isVisible()) {
262 marker->setGeometry(QRectF(QPoint(0,0),marker->effectiveSizeHint(Qt::PreferredSize)));
263 const QRectF& boundingRect = marker->boundingRect();
261 264 qreal w = boundingRect.width();
262 265 qreal h = boundingRect.height();
263 266 m_height = qMax(m_height,h);
264 267 maxWidth = qMax(maxWidth,w);
265 item->setPos(point.x(),point.y());
268 marker->setPos(point.x(),point.y());
266 269 point.setY(point.y() + h);
267 270 if (point.y() + h > rect.topLeft().y() + rect.height()) {
268 271 // Next item would go off rect.
269 272 point.setX(point.x() + maxWidth);
270 273 point.setY(rect.topLeft().y());
271 if (i+1 < items.count()) {
274 if (i+1 < markers.count()) {
272 275 m_width += maxWidth;
273 276 maxWidth = 0;
274 277 }
@@ -289,21 +292,22 void LegendLayout::setDettachedGeometry(const QRectF& rect)
289 292 m_width = 0;
290 293 m_height = 0;
291 294 qreal maxWidth = 0;
292 for (int i=0; i<items.count(); i++) {
293 QGraphicsItem *item = items.at(i);
294 if (item->isVisible()) {
295 const QRectF& boundingRect = item->boundingRect();
295 for (int i=0; i<markers.count(); i++) {
296 LegendMarker *marker = markers.at(i);
297 if (marker->isVisible()) {
298 marker->setGeometry(QRectF(QPoint(0,0),marker->effectiveSizeHint(Qt::PreferredSize)));
299 const QRectF& boundingRect = marker->boundingRect();
296 300 qreal w = boundingRect.width();
297 301 qreal h = boundingRect.height();
298 302 m_height = qMax(m_height,h);
299 303 maxWidth = qMax(maxWidth,w);
300 item->setPos(point.x() - w,point.y());
304 marker->setPos(point.x() - w,point.y());
301 305 point.setY(point.y() + h);
302 306 if (point.y() + h > rect.topLeft().y() + rect.height()) {
303 307 // Next item would go off rect.
304 308 point.setX(point.x() - maxWidth);
305 309 point.setY(rect.topLeft().y());
306 if (i+1 < items.count()) {
310 if (i+1 < markers.count()) {
307 311 m_width += maxWidth;
308 312 maxWidth = 0;
309 313 }
@@ -75,6 +75,7 QBrush LegendMarker::brush() const
75 75 void LegendMarker::setFont(const QFont &font)
76 76 {
77 77 m_textItem->setFont(font);
78 updateGeometry();
78 79 }
79 80
80 81 QFont LegendMarker::font() const
@@ -280,6 +280,7 void QLegend::setFont(const QFont &font)
280 280 foreach (LegendMarker *marker, d_ptr->markers()) {
281 281 marker->setFont(d_ptr->m_font);
282 282 }
283 layout()->invalidate();
283 284 emit fontChanged(font);
284 285 }
285 286 }
General Comments 0
You need to be logged in to leave comments. Login now