##// END OF EJS Templates
Fix to domain initialization when log base was preset on axis before adding it to chart
Fix to domain initialization when log base was preset on axis before adding it to chart

File last commit:

r2196:aa4c8d495212
r2295:8468c10170a2
Show More
legendlayout.cpp
408 lines | 13.2 KiB | text/x-c | CppLexer
Michal Klocek
Adds missing license headers
r1535 /****************************************************************************
**
** Copyright (C) 2012 Digia Plc
** All rights reserved.
** For any questions to Digia, please use contact form at http://qt.digia.com
**
** This file is part of the Qt Commercial Charts Add-on.
**
** $QT_BEGIN_LICENSE$
** Licensees holding valid Qt Commercial licenses may use this file in
** accordance with the Qt Commercial License Agreement provided with the
** Software or, alternatively, in accordance with the terms contained in
** a written agreement between you and Digia.
**
** If you have questions regarding the use of this file, please use
** contact form at http://qt.digia.com
** $QT_END_LICENSE$
**
****************************************************************************/
Michal Klocek
Refactors layout managment...
r1534 #include "legendlayout_p.h"
#include "chartpresenter_p.h"
#include "qlegend_p.h"
Michal Klocek
Refactors layout:...
r2105 #include "chartlayout_p.h"
Michal Klocek
Adds missing license headers
r1535
sauimone
layout work started
r2168 #include "qlegendmarker_p.h"
#include "legendmarkeritem_p.h"
#include "qlegendmarker.h"
Michal Klocek
Refactors layout managment...
r1534 QTCOMMERCIALCHART_BEGIN_NAMESPACE
Jani Honkonen
more coding style fixes for src-folder...
r2104 LegendLayout::LegendLayout(QLegend *legend)
sauimone
legend markers example. bugfix to legend scrolling
r2196 : m_legend(legend),
m_offsetX(0),
m_offsetY(0)
Michal Klocek
Refactors layout managment...
r1534 {
}
LegendLayout::~LegendLayout()
{
}
void LegendLayout::setOffset(qreal x, qreal y)
{
bool scrollHorizontal = true;
Jani Honkonen
astyle and manual coding style fixes for src-folder
r2097 switch (m_legend->alignment()) {
case Qt::AlignTop:
case Qt::AlignBottom:
scrollHorizontal = true;
break;
case Qt::AlignLeft:
case Qt::AlignRight:
scrollHorizontal = false;
break;
Michal Klocek
Refactors layout managment...
r1534 }
// If detached, the scrolling direction is vertical instead of horizontal and vice versa.
Jani Honkonen
astyle and manual coding style fixes for src-folder
r2097 if (!m_legend->isAttachedToChart())
Michal Klocek
Refactors layout managment...
r1534 scrollHorizontal = !scrollHorizontal;
QRectF boundingRect = geometry();
Michal Klocek
Refactors layout...
r1965 qreal left, top, right, bottom;
getContentsMargins(&left, &top, &right, &bottom);
Jani Honkonen
astyle and manual coding style fixes for src-folder
r2097 boundingRect.adjust(left, top, -right, -bottom);
Michal Klocek
Refactors layout managment...
r1534
// Limit offset between m_minOffset and m_maxOffset
if (scrollHorizontal) {
Jani Honkonen
astyle and manual coding style fixes for src-folder
r2097 if (m_width <= boundingRect.width())
return;
Michal Klocek
Refactors layout managment...
r1534
if (x != m_offsetX) {
m_offsetX = qBound(m_minOffsetX, x, m_maxOffsetX);
Jani Honkonen
astyle and manual coding style fixes for src-folder
r2097 m_legend->d_ptr->items()->setPos(-m_offsetX, boundingRect.top());
Michal Klocek
Refactors layout managment...
r1534 }
Jani Honkonen
astyle and manual coding style fixes for src-folder
r2097 } else {
if (m_height <= boundingRect.height())
return;
Michal Klocek
Refactors layout managment...
r1534
if (y != m_offsetY) {
m_offsetY = qBound(m_minOffsetY, y, m_maxOffsetY);
Jani Honkonen
astyle and manual coding style fixes for src-folder
r2097 m_legend->d_ptr->items()->setPos(boundingRect.left(), -m_offsetY);
Michal Klocek
Refactors layout managment...
r1534 }
}
}
QPointF LegendLayout::offset() const
{
Jani Honkonen
astyle and manual coding style fixes for src-folder
r2097 return QPointF(m_offsetX, m_offsetY);
Michal Klocek
Refactors layout managment...
r1534 }
Michal Klocek
Fix title font resize does not invalidate layout
r2088 void LegendLayout::invalidate()
{
QGraphicsLayout::invalidate();
Jani Honkonen
astyle and manual coding style fixes for src-folder
r2097 if (m_legend->isAttachedToChart())
Michal Klocek
Fix title font resize does not invalidate layout
r2088 m_legend->d_ptr->m_presenter->layout()->invalidate();
}
Jani Honkonen
more coding style fixes for src-folder...
r2104 void LegendLayout::setGeometry(const QRectF &rect)
Michal Klocek
Refactors layout managment...
r1534 {
Michal Klocek
Bugfixes for layout...
r1837 m_legend->d_ptr->items()->setVisible(m_legend->isVisible());
Michal Klocek
Refactors layout managment...
r1534
Michal Klocek
fixes legend not vibile after showEvent
r2082 QGraphicsLayout::setGeometry(rect);
Michal Klocek
Bugfixes for layout...
r1837
Jani Honkonen
astyle and manual coding style fixes for src-folder
r2097 if (m_legend->isAttachedToChart())
Michal Klocek
Refactors layout managment...
r1534 setAttachedGeometry(rect);
Jani Honkonen
astyle and manual coding style fixes for src-folder
r2097 else
Michal Klocek
Refactors layout managment...
r1534 setDettachedGeometry(rect);
}
Jani Honkonen
more coding style fixes for src-folder...
r2104 void LegendLayout::setAttachedGeometry(const QRectF &rect)
Michal Klocek
Refactors layout managment...
r1534 {
Jani Honkonen
astyle and manual coding style fixes for src-folder
r2097 if (!rect.isValid())
return;
Michal Klocek
Refactors layout managment...
r1534
sauimone
legend markers example. bugfix to legend scrolling
r2196 qreal oldOffsetX = m_offsetX;
qreal oldOffsetY = m_offsetY;
Jani Honkonen
astyle and manual coding style fixes for src-folder
r2097 m_offsetX = 0;
m_offsetY = 0;
Michal Klocek
Refactors layout managment...
r1534
Jani Honkonen
astyle and manual coding style fixes for src-folder
r2097 QSizeF size(0, 0);
Michal Klocek
Refactors layout managment...
r1534
sauimone
code inspection round 1 fixes
r2185 if (m_legend->d_ptr->markers().isEmpty()) {
Jani Honkonen
astyle and manual coding style fixes for src-folder
r2097 return;
sauimone
commenting out usage of old marker implementation from legend. Legend now uses new markers.
r2170 }
Jani Honkonen
astyle and manual coding style fixes for src-folder
r2097
m_width = 0;
m_height = 0;
Michal Klocek
Refactors layout managment...
r1534
Michal Klocek
Refactors layout...
r1965 qreal left, top, right, bottom;
getContentsMargins(&left, &top, &right, &bottom);
Jani Honkonen
astyle and manual coding style fixes for src-folder
r2097 QRectF geometry = rect.adjusted(left, top, -right, -bottom);
Michal Klocek
Refactors layout managment...
r1534
sauimone
layout work started
r2168 switch(m_legend->alignment()) {
Jani Honkonen
astyle and manual coding style fixes for src-folder
r2097 case Qt::AlignTop:
case Qt::AlignBottom: {
sauimone
layout work started
r2168 QPointF point(0,0);
sauimone
optional series parameter to markers function. code style fixes
r2193 foreach (QLegendMarker *marker, m_legend->d_ptr->markers()) {
LegendMarkerItem *item = marker->d_ptr->item();
sauimone
commenting out usage of old marker implementation from legend. Legend now uses new markers.
r2170 if (item->isVisible()) {
sauimone
layout work started
r2168 item->setGeometry(geometry);
item->setPos(point.x(),geometry.height()/2 - item->boundingRect().height()/2);
sauimone
optional series parameter to markers function. code style fixes
r2193 const QRectF &rect = item->boundingRect();
sauimone
layout work started
r2168 size = size.expandedTo(rect.size());
qreal w = rect.width();
m_width+=w;
point.setX(point.x() + w);
}
Michal Klocek
Refactors layout managment...
r1534 }
sauimone
layout work started
r2168 if (m_width < geometry.width())
m_legend->d_ptr->items()->setPos(geometry.width() / 2 - m_width / 2, geometry.top());
else
m_legend->d_ptr->items()->setPos(geometry.topLeft());
m_height = size.height();
Michal Klocek
Refactors layout managment...
r1534 }
sauimone
layout work started
r2168 break;
Jani Honkonen
astyle and manual coding style fixes for src-folder
r2097 case Qt::AlignLeft:
case Qt::AlignRight: {
sauimone
layout work started
r2168 QPointF point(0,0);
sauimone
optional series parameter to markers function. code style fixes
r2193 foreach (QLegendMarker *marker, m_legend->d_ptr->markers()) {
LegendMarkerItem *item = marker->d_ptr->item();
sauimone
commenting out usage of old marker implementation from legend. Legend now uses new markers.
r2170 if (item->isVisible()) {
sauimone
layout work started
r2168 item->setGeometry(geometry);
item->setPos(point);
sauimone
optional series parameter to markers function. code style fixes
r2193 const QRectF &rect = item->boundingRect();
sauimone
layout work started
r2168 qreal h = rect.height();
size = size.expandedTo(rect.size());
m_height+=h;
point.setY(point.y() + h);
}
}
if (m_height < geometry.height())
m_legend->d_ptr->items()->setPos(geometry.left(), geometry.height() / 2 - m_height / 2);
else
m_legend->d_ptr->items()->setPos(geometry.topLeft());
m_width = size.width();
break;
Michal Klocek
Refactors layout managment...
r1534 }
}
Jani Honkonen
astyle and manual coding style fixes for src-folder
r2097
Michal Klocek
Refactors layout...
r1965 m_minOffsetX = -left;
m_minOffsetY = - top;
m_maxOffsetX = m_width - geometry.width() - right;
m_maxOffsetY = m_height - geometry.height() - bottom;
sauimone
legend markers example. bugfix to legend scrolling
r2196
setOffset(oldOffsetX, oldOffsetY);
Michal Klocek
Refactors layout managment...
r1534 }
Jani Honkonen
more coding style fixes for src-folder...
r2104 void LegendLayout::setDettachedGeometry(const QRectF &rect)
Michal Klocek
Refactors layout managment...
r1534 {
Jani Honkonen
astyle and manual coding style fixes for src-folder
r2097 if (!rect.isValid())
return;
Michal Klocek
Fixes blinking and minimal false size for legend
r1538
Michal Klocek
Refactors layout managment...
r1534 // Detached layout is different.
// In detached mode legend may have multiple rows and columns, so layout calculations
// differ a log from attached mode.
// Also the scrolling logic is bit different.
sauimone
legend markers example. bugfix to legend scrolling
r2196 qreal oldOffsetX = m_offsetX;
qreal oldOffsetY = m_offsetY;
Jani Honkonen
astyle and manual coding style fixes for src-folder
r2097 m_offsetX = 0;
m_offsetY = 0;
Michal Klocek
Refactors layout managment...
r1534
Michal Klocek
Refactors layout...
r1965 qreal left, top, right, bottom;
getContentsMargins(&left, &top, &right, &bottom);
Jani Honkonen
astyle and manual coding style fixes for src-folder
r2097 QRectF geometry = rect.adjusted(left, top, -right, -bottom);
Michal Klocek
Refactors layout...
r1965
Jani Honkonen
astyle and manual coding style fixes for src-folder
r2097 QSizeF size(0, 0);
Michal Klocek
Refactors layout managment...
r1534
sauimone
code inspection round 1 fixes
r2185 QList<QLegendMarker *> markers = m_legend->d_ptr->markers();
Michal Klocek
Refactors layout managment...
r1534
Jani Honkonen
astyle and manual coding style fixes for src-folder
r2097 if (markers.isEmpty())
return;
Michal Klocek
Refactors layout managment...
r1534
switch (m_legend->alignment()) {
Jani Honkonen
astyle and manual coding style fixes for src-folder
r2097 case Qt::AlignTop: {
Jani Honkonen
src folder: another massive victory for coding style police
r2131 QPointF point(0, 0);
m_width = 0;
m_height = 0;
for (int i = 0; i < markers.count(); i++) {
sauimone
commenting out usage of old marker implementation from legend. Legend now uses new markers.
r2170 LegendMarkerItem *item = markers.at(i)->d_ptr->item();
if (item->isVisible()) {
item->setGeometry(geometry);
item->setPos(point.x(),point.y());
sauimone
optional series parameter to markers function. code style fixes
r2193 const QRectF &boundingRect = item->boundingRect();
sauimone
commenting out usage of old marker implementation from legend. Legend now uses new markers.
r2170 qreal w = boundingRect.width();
qreal h = boundingRect.height();
m_width = qMax(m_width,w);
m_height = qMax(m_height,h);
point.setX(point.x() + w);
if (point.x() + w > geometry.left() + geometry.width() - right) {
// Next item would go off rect.
point.setX(0);
point.setY(point.y() + h);
if (i+1 < markers.count()) {
Jani Honkonen
src folder: another massive victory for coding style police
r2131 m_height += h;
Michal Klocek
Refactors layout managment...
r1534 }
}
}
}
Jani Honkonen
src folder: another massive victory for coding style police
r2131 m_legend->d_ptr->items()->setPos(geometry.topLeft());
m_minOffsetX = -left;
m_minOffsetY = -top;
m_maxOffsetX = m_width - geometry.width() - right;
m_maxOffsetY = m_height - geometry.height() - bottom;
}
break;
Jani Honkonen
astyle and manual coding style fixes for src-folder
r2097 case Qt::AlignBottom: {
Jani Honkonen
src folder: another massive victory for coding style police
r2131 QPointF point(0, geometry.height());
m_width = 0;
m_height = 0;
for (int i = 0; i < markers.count(); i++) {
sauimone
commenting out usage of old marker implementation from legend. Legend now uses new markers.
r2170 LegendMarkerItem *item = markers.at(i)->d_ptr->item();
if (item->isVisible()) {
item->setGeometry(geometry);
sauimone
optional series parameter to markers function. code style fixes
r2193 const QRectF &boundingRect = item->boundingRect();
sauimone
commenting out usage of old marker implementation from legend. Legend now uses new markers.
r2170 qreal w = boundingRect.width();
qreal h = boundingRect.height();
m_width = qMax(m_width,w);
m_height = qMax(m_height,h);
item->setPos(point.x(),point.y() - h);
point.setX(point.x() + w);
if (point.x() + w > geometry.left() + geometry.width() - right) {
// Next item would go off rect.
point.setX(0);
point.setY(point.y() - h);
if (i+1 < markers.count()) {
Jani Honkonen
src folder: another massive victory for coding style police
r2131 m_height += h;
Michal Klocek
Refactors layout managment...
r1534 }
}
}
}
sauimone
removing old commented code. removing domain parameter from handleseriesadded of pimpl. adding QLegend parameter to marker construction
r2171 m_legend->d_ptr->items()->setPos(geometry.topLeft());
Jani Honkonen
src folder: another massive victory for coding style police
r2131
sauimone
removing old commented code. removing domain parameter from handleseriesadded of pimpl. adding QLegend parameter to marker construction
r2171 m_minOffsetX = -left;
m_minOffsetY = -m_height + geometry.height() - top;
m_maxOffsetX = m_width - geometry.width() - right;
m_maxOffsetY = -bottom;
Jani Honkonen
src folder: another massive victory for coding style police
r2131 }
break;
Jani Honkonen
astyle and manual coding style fixes for src-folder
r2097 case Qt::AlignLeft: {
Jani Honkonen
src folder: another massive victory for coding style police
r2131 QPointF point(0, 0);
m_width = 0;
m_height = 0;
qreal maxWidth = 0;
for (int i = 0; i < markers.count(); i++) {
sauimone
commenting out usage of old marker implementation from legend. Legend now uses new markers.
r2170 LegendMarkerItem *item = markers.at(i)->d_ptr->item();
if (item->isVisible()) {
item->setGeometry(geometry);
sauimone
optional series parameter to markers function. code style fixes
r2193 const QRectF &boundingRect = item->boundingRect();
Jani Honkonen
src folder: another massive victory for coding style police
r2131 qreal w = boundingRect.width();
qreal h = boundingRect.height();
sauimone
commenting out usage of old marker implementation from legend. Legend now uses new markers.
r2170 m_height = qMax(m_height,h);
maxWidth = qMax(maxWidth,w);
item->setPos(point.x(),point.y());
Jani Honkonen
src folder: another massive victory for coding style police
r2131 point.setY(point.y() + h);
if (point.y() + h > geometry.bottom() - bottom) {
// Next item would go off rect.
point.setX(point.x() + maxWidth);
point.setY(0);
sauimone
commenting out usage of old marker implementation from legend. Legend now uses new markers.
r2170 if (i+1 < markers.count()) {
Jani Honkonen
src folder: another massive victory for coding style police
r2131 m_width += maxWidth;
maxWidth = 0;
Michal Klocek
Refactors layout managment...
r1534 }
}
}
}
sauimone
removing old commented code. removing domain parameter from handleseriesadded of pimpl. adding QLegend parameter to marker construction
r2171 m_width += maxWidth;
m_legend->d_ptr->items()->setPos(geometry.topLeft());
Jani Honkonen
src folder: another massive victory for coding style police
r2131
sauimone
removing old commented code. removing domain parameter from handleseriesadded of pimpl. adding QLegend parameter to marker construction
r2171 m_minOffsetX = -left;
m_minOffsetY = -top;
m_maxOffsetX = m_width - geometry.width() - right;
m_maxOffsetY = m_height - geometry.height() - bottom;
Jani Honkonen
src folder: another massive victory for coding style police
r2131 }
break;
Jani Honkonen
astyle and manual coding style fixes for src-folder
r2097 case Qt::AlignRight: {
Jani Honkonen
src folder: another massive victory for coding style police
r2131 QPointF point(geometry.width(), 0);
m_width = 0;
m_height = 0;
qreal maxWidth = 0;
for (int i = 0; i < markers.count(); i++) {
sauimone
commenting out usage of old marker implementation from legend. Legend now uses new markers.
r2170 LegendMarkerItem *item = markers.at(i)->d_ptr->item();
if (item->isVisible()) {
item->setGeometry(geometry);
sauimone
optional series parameter to markers function. code style fixes
r2193 const QRectF &boundingRect = item->boundingRect();
sauimone
commenting out usage of old marker implementation from legend. Legend now uses new markers.
r2170 qreal w = boundingRect.width();
qreal h = boundingRect.height();
m_height = qMax(m_height,h);
maxWidth = qMax(maxWidth,w);
item->setPos(point.x() - w,point.y());
point.setY(point.y() + h);
if (point.y() + h > geometry.bottom()-bottom) {
Jani Honkonen
src folder: another massive victory for coding style police
r2131 // Next item would go off rect.
point.setX(point.x() - maxWidth);
point.setY(0);
sauimone
commenting out usage of old marker implementation from legend. Legend now uses new markers.
r2170 if (i+1 < markers.count()) {
Jani Honkonen
src folder: another massive victory for coding style police
r2131 m_width += maxWidth;
maxWidth = 0;
Michal Klocek
Refactors layout managment...
r1534 }
}
}
}
sauimone
removing old commented code. removing domain parameter from handleseriesadded of pimpl. adding QLegend parameter to marker construction
r2171 m_width += maxWidth;
m_legend->d_ptr->items()->setPos(geometry.topLeft());
Jani Honkonen
src folder: another massive victory for coding style police
r2131
sauimone
removing old commented code. removing domain parameter from handleseriesadded of pimpl. adding QLegend parameter to marker construction
r2171 m_minOffsetX = - m_width + geometry.width() - left;
m_minOffsetY = -top;
m_maxOffsetX = - right;
m_maxOffsetY = m_height - geometry.height() - bottom;
Jani Honkonen
src folder: another massive victory for coding style police
r2131 }
break;
Jani Honkonen
astyle and manual coding style fixes for src-folder
r2097 default:
Michal Klocek
Refactors layout managment...
r1534 break;
}
sauimone
legend markers example. bugfix to legend scrolling
r2196 setOffset(oldOffsetX, oldOffsetY);
Michal Klocek
Refactors layout managment...
r1534 }
Jani Honkonen
more coding style fixes for src-folder...
r2104 QSizeF LegendLayout::sizeHint(Qt::SizeHint which, const QSizeF &constraint) const
Michal Klocek
Refactors layout managment...
r1534 {
sauimone
layout work started
r2168 QSizeF size(0, 0);
qreal left, top, right, bottom;
getContentsMargins(&left, &top, &right, &bottom);
if(constraint.isValid()) {
sauimone
optional series parameter to markers function. code style fixes
r2193 foreach(QLegendMarker *marker, m_legend->d_ptr->markers()) {
sauimone
commenting out usage of old marker implementation from legend. Legend now uses new markers.
r2170 LegendMarkerItem *item = marker->d_ptr->item();
sauimone
layout work started
r2168 size = size.expandedTo(item->effectiveSizeHint(which));
}
size = size.boundedTo(constraint);
}
else if (constraint.width() >= 0) {
qreal width = 0;
qreal height = 0;
sauimone
optional series parameter to markers function. code style fixes
r2193 foreach(QLegendMarker *marker, m_legend->d_ptr->markers()) {
sauimone
commenting out usage of old marker implementation from legend. Legend now uses new markers.
r2170 LegendMarkerItem *item = marker->d_ptr->item();
sauimone
layout work started
r2168 width+=item->effectiveSizeHint(which).width();
height=qMax(height,item->effectiveSizeHint(which).height());
}
size = QSizeF(qMin(constraint.width(),width), height);
}
else if (constraint.height() >= 0) {
qreal width = 0;
qreal height = 0;
sauimone
optional series parameter to markers function. code style fixes
r2193 foreach(QLegendMarker *marker, m_legend->d_ptr->markers()) {
sauimone
commenting out usage of old marker implementation from legend. Legend now uses new markers.
r2170 LegendMarkerItem *item = marker->d_ptr->item();
sauimone
layout work started
r2168 width=qMax(width,item->effectiveSizeHint(which).width());
height+=height,item->effectiveSizeHint(which).height();
}
size = QSizeF(width,qMin(constraint.height(),height));
}
else {
sauimone
optional series parameter to markers function. code style fixes
r2193 foreach(QLegendMarker *marker, m_legend->d_ptr->markers()) {
sauimone
commenting out usage of old marker implementation from legend. Legend now uses new markers.
r2170 LegendMarkerItem *item = marker->d_ptr->item();
sauimone
layout work started
r2168 size = size.expandedTo(item->effectiveSizeHint(which));
}
}
size += QSize(left + right, top + bottom);
return size;
Michal Klocek
Refactors layout managment...
r1534 }
QTCOMMERCIALCHART_END_NAMESPACE