##// END OF EJS Templates
Return empty brush/pen/font via API rather than the weird default one...
Return empty brush/pen/font via API rather than the weird default one Previously a non-initialized QPen()/QBrush()/QFont() was returned if axis/series hadn't been added to a chart yet and therefore had not been themed yet. To keep API somewhat consistent with old behavior, return non-initialized QPen()/QBrush()/QFont() instead of the weird default one in these cases. The new behavior is slightly different in that it is no longer possible to restore themed behavior by setting pen/brush/font to non-initialized one, but since there is no way to differentiate e.g. legitimate Qt::black pen from non-initialized pen, we can no longer support this behavior. Change-Id: I99f3d8853b329b5345e3073c040d8bfa8b9b75b4 Reviewed-by: Tomi Korpipää <tomi.korpipaa@digia.com>

File last commit:

r2483:f494279b6366
r2519:9ea7d7fe3500
Show More
cartesianchartlayout.cpp
246 lines | 8.5 KiB | text/x-c | CppLexer
/ src / layout / cartesianchartlayout.cpp
Michal Klocek
Adds missing license headers
r1535 /****************************************************************************
**
Miikka Heikkinen
Fixed the copyright year 2012 -> 2013
r2432 ** Copyright (C) 2013 Digia Plc
Michal Klocek
Adds missing license headers
r1535 ** 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$
**
****************************************************************************/
Miikka Heikkinen
Add Polar chart support...
r2483 #include "cartesianchartlayout_p.h"
Michal Klocek
Refactors layout managment...
r1534 #include "chartpresenter_p.h"
Miikka Heikkinen
Add Polar chart support...
r2483 #include "chartaxiselement_p.h"
Michal Klocek
Refactors layout:...
r2105 #include <QDebug>
Michal Klocek
Adds missing license headers
r1535
Michal Klocek
Refactors layout managment...
r1534 QTCOMMERCIALCHART_BEGIN_NAMESPACE
Miikka Heikkinen
Fix label truncate issues with multiple axes...
r2411 static const qreal maxAxisPortion = 0.4;
Michal Klocek
Refactors layout...
r1965
Miikka Heikkinen
Add Polar chart support...
r2483 CartesianChartLayout::CartesianChartLayout(ChartPresenter *presenter)
: AbstractChartLayout(presenter)
Michal Klocek
Refactors layout managment...
r1534 {
Michal Klocek
Refactors layout...
r1965 }
Miikka Heikkinen
Add Polar chart support...
r2483 CartesianChartLayout::~CartesianChartLayout()
Michal Klocek
Refactors layout...
r1965 {
}
Miikka Heikkinen
Add Polar chart support...
r2483 QRectF CartesianChartLayout::calculateAxisGeometry(const QRectF &geometry, const QList<ChartAxisElement *> &axes) const
Michal Klocek
Refactors layout...
r1965 {
Michal Klocek
Updates axis drawing code...
r2133 QSizeF left(0,0);
QSizeF minLeft(0,0);
QSizeF right(0,0);
QSizeF minRight(0,0);
QSizeF bottom(0,0);
QSizeF minBottom(0,0);
QSizeF top(0,0);
QSizeF minTop(0,0);
Miikka Heikkinen
Fix vanishing labels for first and last ticks....
r2443 QSizeF labelExtents(0,0);
Michal Klocek
Refactors layout:...
r2105 int leftCount = 0;
int rightCount = 0;
int topCount = 0;
int bottomCount = 0;
Miikka Heikkinen
Add Polar chart support...
r2483 foreach (ChartAxisElement *axis , axes) {
Michal Klocek
Refactors layout:...
r2105
Jani Honkonen
src folder: another massive victory for coding style police
r2131 if (!axis->isVisible())
continue;
Michal Klocek
Refactors layout:...
r2105
Miikka Heikkinen
Add Polar chart support...
r2483
Michal Klocek
Updates axis drawing code...
r2133 QSizeF size = axis->effectiveSizeHint(Qt::PreferredSize);
//this is used to get single thick font size
QSizeF minSize = axis->effectiveSizeHint(Qt::MinimumSize);
Michal Klocek
Refactors layout:...
r2105
Miikka Heikkinen
Add Polar chart support...
r2483 switch (axis->axis()->alignment()) {
Michal Klocek
Refactors layout:...
r2105 case Qt::AlignLeft:
Michal Klocek
Updates axis drawing code...
r2133 left.setWidth(left.width()+size.width());
left.setHeight(qMax(left.height(),size.height()));
minLeft.setWidth(minLeft.width()+minSize.width());
minLeft.setHeight(qMax(minLeft.height(),minSize.height()));
Miikka Heikkinen
Fix vanishing labels for first and last ticks....
r2443 labelExtents.setHeight(qMax(size.height(), labelExtents.height()));
Michal Klocek
Updates axis drawing code...
r2133 leftCount++;
break;
Michal Klocek
Refactors layout:...
r2105 case Qt::AlignRight:
Michal Klocek
Updates axis drawing code...
r2133 right.setWidth(right.width()+size.width());
right.setHeight(qMax(right.height(),size.height()));
minRight.setWidth(minRight.width()+minSize.width());
minRight.setHeight(qMax(minRight.height(),minSize.height()));
Miikka Heikkinen
Fix vanishing labels for first and last ticks....
r2443 labelExtents.setHeight(qMax(size.height(), labelExtents.height()));
Michal Klocek
Refactors layout:...
r2105 rightCount++;
break;
case Qt::AlignTop:
Michal Klocek
Updates axis drawing code...
r2133 top.setWidth(qMax(top.width(),size.width()));
top.setHeight(top.height()+size.height());
minTop.setWidth(qMax(minTop.width(),minSize.width()));
minTop.setHeight(minTop.height()+minSize.height());
Miikka Heikkinen
Fix vanishing labels for first and last ticks....
r2443 labelExtents.setWidth(qMax(size.width(), labelExtents.width()));
Michal Klocek
Refactors layout:...
r2105 topCount++;
break;
case Qt::AlignBottom:
Jani Honkonen
src folder: another massive victory for coding style police
r2131 bottom.setWidth(qMax(bottom.width(), size.width()));
Michal Klocek
Refactors layout:...
r2105 bottom.setHeight(bottom.height() + size.height());
Michal Klocek
Updates axis drawing code...
r2133 minBottom.setWidth(qMax(minBottom.width(),minSize.width()));
minBottom.setHeight(minBottom.height() + minSize.height());
Miikka Heikkinen
Fix vanishing labels for first and last ticks....
r2443 labelExtents.setWidth(qMax(size.width(), labelExtents.width()));
Michal Klocek
Refactors layout:...
r2105 bottomCount++;
break;
Michal Klocek
Refactors internals...
r2273 default:
qWarning()<<"Axis is without alignment !";
break;
Michal Klocek
Refactors layout...
r1965 }
Michal Klocek
Refactors layout managment...
r1534 }
Miikka Heikkinen
Add Polar chart support...
r2483 qreal totalVerticalAxes = leftCount + rightCount;
Miikka Heikkinen
Fix label truncate issues with multiple axes...
r2411 qreal leftSqueezeRatio = 1.0;
qreal rightSqueezeRatio = 1.0;
qreal vratio = 0;
Michal Klocek
Updates axis drawing code...
r2133
Miikka Heikkinen
Fix label truncate issues with multiple axes...
r2411 if (totalVerticalAxes > 0)
vratio = (maxAxisPortion * geometry.width()) / totalVerticalAxes;
if (leftCount > 0) {
int maxWidth = vratio * leftCount;
if (left.width() > maxWidth) {
leftSqueezeRatio = maxWidth / left.width();
left.setWidth(maxWidth);
}
}
if (rightCount > 0) {
int maxWidth = vratio * rightCount;
if (right.width() > maxWidth) {
rightSqueezeRatio = maxWidth / right.width();
right.setWidth(maxWidth);
}
}
Miikka Heikkinen
Add Polar chart support...
r2483 qreal totalHorizontalAxes = topCount + bottomCount;
Miikka Heikkinen
Fix label truncate issues with multiple axes...
r2411 qreal topSqueezeRatio = 1.0;
qreal bottomSqueezeRatio = 1.0;
qreal hratio = 0;
if (totalHorizontalAxes > 0)
hratio = (maxAxisPortion * geometry.height()) / totalHorizontalAxes;
if (topCount > 0) {
int maxHeight = hratio * topCount;
if (top.height() > maxHeight) {
topSqueezeRatio = maxHeight / top.height();
top.setHeight(maxHeight);
}
}
if (bottomCount > 0) {
int maxHeight = hratio * bottomCount;
if (bottom.height() > maxHeight) {
bottomSqueezeRatio = maxHeight / bottom.height();
bottom.setHeight(maxHeight);
}
}
Michal Klocek
Refactors layout:...
r2105
Michal Klocek
minAxisLayout increased by 1
r2354 qreal minHeight = qMax(minLeft.height(),minRight.height()) + 1;
qreal minWidth = qMax(minTop.width(),minBottom.width()) + 1;
Michal Klocek
Updates axis drawing code...
r2133
Miikka Heikkinen
Fix vanishing labels for first and last ticks....
r2443 // Ensure that there is enough space for first and last tick labels.
left.setWidth(qMax(labelExtents.width(), left.width()));
right.setWidth(qMax(labelExtents.width(), right.width()));
top.setHeight(qMax(labelExtents.height(), top.height()));
bottom.setHeight(qMax(labelExtents.height(), bottom.height()));
Michal Klocek
Updates axis drawing code...
r2133 QRectF chartRect = geometry.adjusted(qMax(left.width(),minWidth/2), qMax(top.height(), minHeight/2),-qMax(right.width(),minWidth/2),-qMax(bottom.height(),minHeight/2));
Michal Klocek
Refactors layout:...
r2105
Jani Honkonen
src folder: another massive victory for coding style police
r2131 qreal leftOffset = 0;
qreal rightOffset = 0;
qreal topOffset = 0;
qreal bottomOffset = 0;
Michal Klocek
Refactors layout:...
r2105
Miikka Heikkinen
Add Polar chart support...
r2483 foreach (ChartAxisElement *axis , axes) {
Michal Klocek
Refactors layout:...
r2105
Jani Honkonen
src folder: another massive victory for coding style police
r2131 if (!axis->isVisible())
continue;
Michal Klocek
Refactors layout:...
r2105
Michal Klocek
Updates axis drawing code...
r2133 QSizeF size = axis->effectiveSizeHint(Qt::PreferredSize);
Michal Klocek
Refactors layout:...
r2105
Miikka Heikkinen
Add Polar chart support...
r2483 switch (axis->axis()->alignment()){
Michal Klocek
Updates axis drawing code...
r2133 case Qt::AlignLeft:{
Miikka Heikkinen
Fix label truncate issues with multiple axes...
r2411 qreal width = size.width();
if (leftSqueezeRatio < 1.0)
width *= leftSqueezeRatio;
Michal Klocek
Updates axis drawing code...
r2133 leftOffset+=width;
axis->setGeometry(QRect(chartRect.left()-leftOffset, geometry.top(),width, geometry.bottom()),chartRect);
Michal Klocek
Refactors layout:...
r2105 break;
}
Michal Klocek
Updates axis drawing code...
r2133 case Qt::AlignRight:{
Miikka Heikkinen
Fix label truncate issues with multiple axes...
r2411 qreal width = size.width();
if (rightSqueezeRatio < 1.0)
width *= rightSqueezeRatio;
Michal Klocek
Updates axis drawing code...
r2133 axis->setGeometry(QRect(chartRect.right()+rightOffset,geometry.top(),width,geometry.bottom()),chartRect);
rightOffset+=width;
Michal Klocek
Refactors layout:...
r2105 break;
}
Miikka Heikkinen
Fix label truncate issues with multiple axes...
r2411 case Qt::AlignTop: {
qreal height = size.height();
if (topSqueezeRatio < 1.0)
height *= topSqueezeRatio;
axis->setGeometry(QRect(geometry.left(), chartRect.top() - topOffset - height, geometry.width(), height), chartRect);
topOffset += height;
Michal Klocek
Refactors layout:...
r2105 break;
Miikka Heikkinen
Fix label truncate issues with multiple axes...
r2411 }
Michal Klocek
Refactors layout:...
r2105 case Qt::AlignBottom:
Miikka Heikkinen
Fix label truncate issues with multiple axes...
r2411 qreal height = size.height();
if (bottomSqueezeRatio < 1.0)
height *= bottomSqueezeRatio;
axis->setGeometry(QRect(geometry.left(), chartRect.bottom() + bottomOffset, geometry.width(), height), chartRect);
bottomOffset += height;
Michal Klocek
Refactors layout:...
r2105 break;
Marek Rosa
Multiaxis support...
r2093 }
Michal Klocek
Refactors layout...
r1965 }
Michal Klocek
Implements minimumMargins...
r1883
Michal Klocek
Refactors layout:...
r2105 return chartRect;
Michal Klocek
Refactors layout...
r1965 }
Michal Klocek
Refactors layout managment...
r1534
Miikka Heikkinen
Add Polar chart support...
r2483 QRectF CartesianChartLayout::calculateAxisMinimum(const QRectF &minimum, const QList<ChartAxisElement *> &axes) const
Michal Klocek
Refactors layout...
r1965 {
Michal Klocek
Refactors layout:...
r2105 QSizeF left;
QSizeF right;
QSizeF bottom;
QSizeF top;
Miikka Heikkinen
Add Polar chart support...
r2483 foreach (ChartAxisElement *axis, axes) {
Michal Klocek
Refactors layout:...
r2105 QSizeF size = axis->effectiveSizeHint(Qt::MinimumSize);
Jani Honkonen
src folder: another massive victory for coding style police
r2131 if (!axis->isVisible())
continue;
Michal Klocek
Refactors layout:...
r2105
Miikka Heikkinen
Add Polar chart support...
r2483 switch (axis->axis()->alignment()) {
Jani Honkonen
src folder: another massive victory for coding style police
r2131 case Qt::AlignLeft:
left.setWidth(left.width() + size.width());
left.setHeight(qMax(left.height() * 2, size.height()));
Michal Klocek
Refactors layout:...
r2105 break;
Jani Honkonen
src folder: another massive victory for coding style police
r2131 case Qt::AlignRight:
right.setWidth(right.width() + size.width());
right.setHeight(qMax(right.height() * 2, size.height()));
Michal Klocek
Refactors layout:...
r2105 break;
Jani Honkonen
src folder: another massive victory for coding style police
r2131 case Qt::AlignTop:
top.setWidth(qMax(top.width(), size.width()));
top.setHeight(top.height() + size.height());
Michal Klocek
Refactors layout:...
r2105 break;
Jani Honkonen
src folder: another massive victory for coding style police
r2131 case Qt::AlignBottom:
bottom.setWidth(qMax(bottom.width(), size.width()));
Michal Klocek
Refactors layout:...
r2105 bottom.setHeight(bottom.height() + size.height());
break;
}
Michal Klocek
Refactors layout...
r1965 }
Jani Honkonen
src folder: another massive victory for coding style police
r2131 return minimum.adjusted(0, 0, left.width() + right.width() + qMax(top.width(), bottom.width()), top.height() + bottom.height() + qMax(left.height(), right.height()));
Michal Klocek
Refactors layout...
r1965 }
Michal Klocek
Refactors layout managment...
r1534
QTCOMMERCIALCHART_END_NAMESPACE