summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorSami Varanka <sami.varanka@qt.io>2021-10-13 15:51:26 +0300
committerSami Varanka <sami.varanka@qt.io>2021-10-15 10:55:50 +0300
commit11e785a4a67a89999fd15124e418ff324c375224 (patch)
tree4d98cb58aec6a32939d4d0a46fbee340504fbf6c /src
parent06cd1b8e80920133b4de6c845456f08b43dcb6e7 (diff)
Fix: Resize chart after hiding axis labels
Modified sizehint in each axis to ignore label size if labels are not visible. Fixes: QTBUG-60529 Change-Id: Ib4a69f95a23f42849ff13f0d24f7799f84f87c6a Reviewed-by: Miikka Heikkinen <miikka.heikkinen@qt.io>
Diffstat (limited to 'src')
-rw-r--r--src/charts/axis/barcategoryaxis/chartbarcategoryaxisx.cpp26
-rw-r--r--src/charts/axis/barcategoryaxis/chartbarcategoryaxisy.cpp34
-rw-r--r--src/charts/axis/categoryaxis/chartcategoryaxisx.cpp26
-rw-r--r--src/charts/axis/categoryaxis/chartcategoryaxisy.cpp26
-rw-r--r--src/charts/axis/chartaxiselement.cpp5
-rw-r--r--src/charts/axis/chartaxiselement_p.h1
-rw-r--r--src/charts/axis/coloraxis/chartcoloraxisx.cpp44
-rw-r--r--src/charts/axis/coloraxis/chartcoloraxisy.cpp48
-rw-r--r--src/charts/axis/datetimeaxis/chartdatetimeaxisx.cpp40
-rw-r--r--src/charts/axis/datetimeaxis/chartdatetimeaxisy.cpp40
-rw-r--r--src/charts/axis/logvalueaxis/chartlogvalueaxisx.cpp40
-rw-r--r--src/charts/axis/logvalueaxis/chartlogvalueaxisy.cpp40
-rw-r--r--src/charts/axis/valueaxis/chartvalueaxisx.cpp40
-rw-r--r--src/charts/axis/valueaxis/chartvalueaxisy.cpp36
14 files changed, 282 insertions, 164 deletions
diff --git a/src/charts/axis/barcategoryaxis/chartbarcategoryaxisx.cpp b/src/charts/axis/barcategoryaxis/chartbarcategoryaxisx.cpp
index 9f973813..f52ffe65 100644
--- a/src/charts/axis/barcategoryaxis/chartbarcategoryaxisx.cpp
+++ b/src/charts/axis/barcategoryaxis/chartbarcategoryaxisx.cpp
@@ -121,20 +121,28 @@ QSizeF ChartBarCategoryAxisX::sizeHint(Qt::SizeHint which, const QSizeF &constra
switch (which) {
case Qt::MinimumSize: {
- QRectF boundingRect = ChartPresenter::textBoundingRect(axis()->labelsFont(),
- QStringLiteral("..."),
- axis()->labelsAngle());
- height = boundingRect.height() + labelPadding() + base.height() + 1.0;
+ if (labelsVisible()) {
+ QRectF boundingRect = ChartPresenter::textBoundingRect(axis()->labelsFont(),
+ QStringLiteral("..."),
+ axis()->labelsAngle());
+ height = boundingRect.height() + labelPadding() + base.height() + 1.0;
+ } else {
+ height = base.height() + 1.0;
+ }
sh = QSizeF(width, height);
break;
}
case Qt::PreferredSize:{
- qreal labelHeight = 0.0;
- foreach (const QString& s, ticksList) {
- QRectF rect = ChartPresenter::textBoundingRect(axis()->labelsFont(), s, axis()->labelsAngle());
- labelHeight = qMax(rect.height(), labelHeight);
+ if (labelsVisible()) {
+ qreal labelHeight = 0.0;
+ foreach (const QString& s, ticksList) {
+ QRectF rect = ChartPresenter::textBoundingRect(axis()->labelsFont(), s, axis()->labelsAngle());
+ labelHeight = qMax(rect.height(), labelHeight);
+ }
+ height = labelHeight + labelPadding() + base.height() + 1.0;
+ } else {
+ height = base.height() + 1.0;
}
- height = labelHeight + labelPadding() + base.height() + 1.0;
sh = QSizeF(width, height);
break;
}
diff --git a/src/charts/axis/barcategoryaxis/chartbarcategoryaxisy.cpp b/src/charts/axis/barcategoryaxis/chartbarcategoryaxisy.cpp
index a936279d..8481225a 100644
--- a/src/charts/axis/barcategoryaxis/chartbarcategoryaxisy.cpp
+++ b/src/charts/axis/barcategoryaxis/chartbarcategoryaxisy.cpp
@@ -119,24 +119,32 @@ QSizeF ChartBarCategoryAxisY::sizeHint(Qt::SizeHint which, const QSizeF &constra
switch (which) {
case Qt::MinimumSize: {
- QRectF boundingRect = ChartPresenter::textBoundingRect(axis()->labelsFont(),
- QStringLiteral("..."),
- axis()->labelsAngle());
- width = boundingRect.width() + labelPadding() + base.width() + 1.0;
- if (base.width() > 0.0)
- width += labelPadding();
+ if (labelsVisible()) {
+ QRectF boundingRect = ChartPresenter::textBoundingRect(axis()->labelsFont(),
+ QStringLiteral("..."),
+ axis()->labelsAngle());
+ width = boundingRect.width() + labelPadding() + base.width() + 1.0;
+ if (base.width() > 0.0)
+ width += labelPadding();
+ } else {
+ width = base.width() + 1.0;
+ }
sh = QSizeF(width, height);
break;
}
case Qt::PreferredSize:{
- qreal labelWidth = 0.0;
- foreach (const QString& s, ticksList) {
- QRectF rect = ChartPresenter::textBoundingRect(axis()->labelsFont(), s, axis()->labelsAngle());
- labelWidth = qMax(rect.width(), labelWidth);
+ if (labelsVisible()) {
+ qreal labelWidth = 0.0;
+ foreach (const QString& s, ticksList) {
+ QRectF rect = ChartPresenter::textBoundingRect(axis()->labelsFont(), s, axis()->labelsAngle());
+ labelWidth = qMax(rect.width(), labelWidth);
+ }
+ width = labelWidth + labelPadding() + base.width() + 1.0;
+ if (base.width() > 0.0)
+ width += labelPadding();
+ } else {
+ width = base.width() + 1.0;
}
- width = labelWidth + labelPadding() + base.width() + 1.0;
- if (base.width() > 0.0)
- width += labelPadding();
sh = QSizeF(width, height);
break;
}
diff --git a/src/charts/axis/categoryaxis/chartcategoryaxisx.cpp b/src/charts/axis/categoryaxis/chartcategoryaxisx.cpp
index d7ba118b..7ff1d379 100644
--- a/src/charts/axis/categoryaxis/chartcategoryaxisx.cpp
+++ b/src/charts/axis/categoryaxis/chartcategoryaxisx.cpp
@@ -93,20 +93,28 @@ QSizeF ChartCategoryAxisX::sizeHint(Qt::SizeHint which, const QSizeF &constraint
switch (which) {
case Qt::MinimumSize: {
- QRectF boundingRect = ChartPresenter::textBoundingRect(axis()->labelsFont(),
- QStringLiteral("..."),
- axis()->labelsAngle());
- height = boundingRect.height() + labelPadding() + base.height() + 1.0;
+ if (labelsVisible()) {
+ QRectF boundingRect = ChartPresenter::textBoundingRect(axis()->labelsFont(),
+ QStringLiteral("..."),
+ axis()->labelsAngle());
+ height = boundingRect.height() + labelPadding() + base.height() + 1.0;
+ } else {
+ height = base.height() + 1.0;
+ }
sh = QSizeF(width, height);
break;
}
case Qt::PreferredSize: {
- qreal labelHeight = 0.0;
- foreach (const QString& s, ticksList) {
- QRectF rect = ChartPresenter::textBoundingRect(axis()->labelsFont(), s, axis()->labelsAngle());
- labelHeight = qMax(rect.height(), labelHeight);
+ if (labelsVisible()) {
+ qreal labelHeight = 0.0;
+ foreach (const QString& s, ticksList) {
+ QRectF rect = ChartPresenter::textBoundingRect(axis()->labelsFont(), s, axis()->labelsAngle());
+ labelHeight = qMax(rect.height(), labelHeight);
+ }
+ height = labelHeight + labelPadding() + base.height() + 1.0;
+ } else {
+ height = base.height() + 1.0;
}
- height = labelHeight + labelPadding() + base.height() + 1.0;
sh = QSizeF(width, height);
break;
}
diff --git a/src/charts/axis/categoryaxis/chartcategoryaxisy.cpp b/src/charts/axis/categoryaxis/chartcategoryaxisy.cpp
index 9658bae0..db831351 100644
--- a/src/charts/axis/categoryaxis/chartcategoryaxisy.cpp
+++ b/src/charts/axis/categoryaxis/chartcategoryaxisy.cpp
@@ -94,20 +94,28 @@ QSizeF ChartCategoryAxisY::sizeHint(Qt::SizeHint which, const QSizeF &constraint
switch (which) {
case Qt::MinimumSize: {
- QRectF boundingRect = ChartPresenter::textBoundingRect(axis()->labelsFont(),
- QStringLiteral("..."),
- axis()->labelsAngle());
- width = boundingRect.width() + labelPadding() + base.width() + 1.0;
+ if (labelsVisible()) {
+ QRectF boundingRect = ChartPresenter::textBoundingRect(axis()->labelsFont(),
+ QStringLiteral("..."),
+ axis()->labelsAngle());
+ width = boundingRect.width() + labelPadding() + base.width() + 1.0;
+ } else {
+ width = base.width() + 1.0;
+ }
sh = QSizeF(width, height);
break;
}
case Qt::PreferredSize: {
- qreal labelWidth = 0.0;
- foreach (const QString& s, ticksList) {
- QRectF rect = ChartPresenter::textBoundingRect(axis()->labelsFont(), s, axis()->labelsAngle());
- labelWidth = qMax(rect.width(), labelWidth);
+ if (labelsVisible()) {
+ qreal labelWidth = 0.0;
+ foreach (const QString& s, ticksList) {
+ QRectF rect = ChartPresenter::textBoundingRect(axis()->labelsFont(), s, axis()->labelsAngle());
+ labelWidth = qMax(rect.width(), labelWidth);
+ }
+ width = labelWidth + labelPadding() + base.width() + 1.0;
+ } else {
+ width = base.width() + 1.0;
}
- width = labelWidth + labelPadding() + base.width() + 1.0;
sh = QSizeF(width, height);
break;
}
diff --git a/src/charts/axis/chartaxiselement.cpp b/src/charts/axis/chartaxiselement.cpp
index f0ed39fd..71f8e24d 100644
--- a/src/charts/axis/chartaxiselement.cpp
+++ b/src/charts/axis/chartaxiselement.cpp
@@ -660,6 +660,11 @@ void ChartAxisElement::setLabelsEditable(bool labelsEditable)
}
}
+bool ChartAxisElement::labelsVisible() const
+{
+ return m_labels->isVisible();
+}
+
void ChartAxisElement::axisSelected()
{
emit clicked();
diff --git a/src/charts/axis/chartaxiselement_p.h b/src/charts/axis/chartaxiselement_p.h
index 7a63ca5c..7ab53db1 100644
--- a/src/charts/axis/chartaxiselement_p.h
+++ b/src/charts/axis/chartaxiselement_p.h
@@ -124,6 +124,7 @@ public:
bool labelsEditable() const;
void setLabelsEditable(bool labelsEditable);
+ bool labelsVisible() const;
protected:
virtual QList<qreal> calculateLayout() const = 0;
diff --git a/src/charts/axis/coloraxis/chartcoloraxisx.cpp b/src/charts/axis/coloraxis/chartcoloraxisx.cpp
index 43806164..65ebff28 100644
--- a/src/charts/axis/coloraxis/chartcoloraxisx.cpp
+++ b/src/charts/axis/coloraxis/chartcoloraxisx.cpp
@@ -61,28 +61,38 @@ QSizeF ChartColorAxisX::sizeHint(Qt::SizeHint which, const QSizeF &constraint) c
switch (which) {
case Qt::MinimumSize: {
- QRectF boundingRect = ChartPresenter::textBoundingRect(
- axis()->labelsFont(), QStringLiteral("..."), axis()->labelsAngle());
- width = boundingRect.width() / 2.0;
- height = boundingRect.height() + labelPadding() + base.height() + m_axis->size()
- + colorScalePadding() + 1.0;
+ if (labelsVisible()) {
+ QRectF boundingRect = ChartPresenter::textBoundingRect(
+ axis()->labelsFont(), QStringLiteral("..."), axis()->labelsAngle());
+ width = boundingRect.width() / 2.0;
+ height = boundingRect.height() + labelPadding() + base.height() + m_axis->size()
+ + colorScalePadding() + 1.0;
+ } else {
+ width = 0;
+ height = base.height() + m_axis->size() + colorScalePadding() + 1.0;
+ }
sh = QSizeF(width, height);
break;
}
case Qt::PreferredSize: {
- qreal labelHeight = 0.0;
- qreal firstWidth = -1.0;
- for (const QString &s : ticksList) {
- QRectF rect = ChartPresenter::textBoundingRect(axis()->labelsFont(), s,
- axis()->labelsAngle());
- labelHeight = qMax(rect.height(), labelHeight);
- width = rect.width();
- if (firstWidth < 0.0)
- firstWidth = width;
+ if (labelsVisible()) {
+ qreal labelHeight = 0.0;
+ qreal firstWidth = -1.0;
+ for (const QString &s : ticksList) {
+ QRectF rect = ChartPresenter::textBoundingRect(axis()->labelsFont(), s,
+ axis()->labelsAngle());
+ labelHeight = qMax(rect.height(), labelHeight);
+ width = rect.width();
+ if (firstWidth < 0.0)
+ firstWidth = width;
+ }
+ height = labelHeight + labelPadding() + base.height() + m_axis->size() + colorScalePadding()
+ + 1.0;
+ width = qMax(width, firstWidth) / 2.0;
+ } else {
+ height = base.height() + m_axis->size() + colorScalePadding() + 1.0;
+ width = 0;
}
- height = labelHeight + labelPadding() + base.height() + m_axis->size() + colorScalePadding()
- + 1.0;
- width = qMax(width, firstWidth) / 2.0;
sh = QSizeF(width, height);
break;
}
diff --git a/src/charts/axis/coloraxis/chartcoloraxisy.cpp b/src/charts/axis/coloraxis/chartcoloraxisy.cpp
index 24a4bf8d..b5b40605 100644
--- a/src/charts/axis/coloraxis/chartcoloraxisy.cpp
+++ b/src/charts/axis/coloraxis/chartcoloraxisy.cpp
@@ -84,36 +84,46 @@ QSizeF ChartColorAxisY::sizeHint(Qt::SizeHint which, const QSizeF &constraint) c
switch (which) {
case Qt::MinimumSize: {
- QRectF boundingRect = ChartPresenter::textBoundingRect(axis()->labelsFont(),
- QStringLiteral("..."),
- axis()->labelsAngle());
- width = boundingRect.width() + labelPadding() + base.width() + m_axis->size()
- + colorScalePadding() + 1.0;
- height = boundingRect.height() / 2.0;
+ if (labelsVisible()) {
+ QRectF boundingRect = ChartPresenter::textBoundingRect(axis()->labelsFont(),
+ QStringLiteral("..."),
+ axis()->labelsAngle());
+ width = boundingRect.width() + labelPadding() + base.width() + m_axis->size()
+ + colorScalePadding() + 1.0;
+ height = boundingRect.height() / 2.0;
+ } else {
+ width = base.width() + m_axis->size() + colorScalePadding() + 1.0;
+ height = 0;
+ }
sh = QSizeF(width, height);
break;
}
case Qt::PreferredSize: {
- qreal labelWidth = 0.0;
- qreal firstHeight = -1.0;
- for (const QString &s : ticksList) {
- QRectF rect = ChartPresenter::textBoundingRect(axis()->labelsFont(), s,
- axis()->labelsAngle());
- labelWidth = qMax(rect.width(), labelWidth);
- height = rect.height();
- if (firstHeight < 0.0)
- firstHeight = height;
+ if (labelsVisible()) {
+ qreal labelWidth = 0.0;
+ qreal firstHeight = -1.0;
+ for (const QString &s : ticksList) {
+ QRectF rect = ChartPresenter::textBoundingRect(axis()->labelsFont(), s,
+ axis()->labelsAngle());
+ labelWidth = qMax(rect.width(), labelWidth);
+ height = rect.height();
+ if (firstHeight < 0.0)
+ firstHeight = height;
+ }
+ width = labelWidth + labelPadding() + base.width() + m_axis->size() + colorScalePadding()
+ + 2.0; // two pixels of tolerance
+ height = qMax(height, firstHeight) / 2.0;
+ } else {
+ width = base.width() + m_axis->size() + colorScalePadding()
+ + 2.0; // two pixels of tolerance
+ height = 0;
}
- width = labelWidth + labelPadding() + base.width() + m_axis->size() + colorScalePadding()
- + 2.0; // two pixels of tolerance
- height = qMax(height, firstHeight) / 2.0;
sh = QSizeF(width, height);
break;
}
default:
break;
}
-
return sh;
}
diff --git a/src/charts/axis/datetimeaxis/chartdatetimeaxisx.cpp b/src/charts/axis/datetimeaxis/chartdatetimeaxisx.cpp
index 1285d9ba..d0699529 100644
--- a/src/charts/axis/datetimeaxis/chartdatetimeaxisx.cpp
+++ b/src/charts/axis/datetimeaxis/chartdatetimeaxisx.cpp
@@ -108,26 +108,36 @@ QSizeF ChartDateTimeAxisX::sizeHint(Qt::SizeHint which, const QSizeF &constraint
switch (which) {
case Qt::MinimumSize: {
- QRectF boundingRect = ChartPresenter::textBoundingRect(axis()->labelsFont(),
- QStringLiteral("..."),
- axis()->labelsAngle());
- width = boundingRect.width() / 2.0;
- height = boundingRect.height() + labelPadding() + base.height() + 1.0;
+ if (labelsVisible()) {
+ QRectF boundingRect = ChartPresenter::textBoundingRect(axis()->labelsFont(),
+ QStringLiteral("..."),
+ axis()->labelsAngle());
+ width = boundingRect.width() / 2.0;
+ height = boundingRect.height() + labelPadding() + base.height() + 1.0;
+ } else {
+ width = 0;
+ height = base.height() + 1.0;
+ }
sh = QSizeF(width, height);
break;
}
case Qt::PreferredSize: {
- qreal labelHeight = 0.0;
- qreal firstWidth = -1.0;
- foreach (const QString& s, ticksList) {
- QRectF rect = ChartPresenter::textBoundingRect(axis()->labelsFont(), s, axis()->labelsAngle());
- labelHeight = qMax(rect.height(), labelHeight);
- width = rect.width();
- if (firstWidth < 0.0)
- firstWidth = width;
+ if (labelsVisible()) {
+ qreal labelHeight = 0.0;
+ qreal firstWidth = -1.0;
+ foreach (const QString& s, ticksList) {
+ QRectF rect = ChartPresenter::textBoundingRect(axis()->labelsFont(), s, axis()->labelsAngle());
+ labelHeight = qMax(rect.height(), labelHeight);
+ width = rect.width();
+ if (firstWidth < 0.0)
+ firstWidth = width;
+ }
+ height = labelHeight + labelPadding() + base.height() + 1.0;
+ width = qMax(width, firstWidth) / 2.0;
+ } else {
+ height = base.height() + 1.0;
+ width = 0;
}
- height = labelHeight + labelPadding() + base.height() + 1.0;
- width = qMax(width, firstWidth) / 2.0;
sh = QSizeF(width, height);
break;
}
diff --git a/src/charts/axis/datetimeaxis/chartdatetimeaxisy.cpp b/src/charts/axis/datetimeaxis/chartdatetimeaxisy.cpp
index 6b767241..fee9de53 100644
--- a/src/charts/axis/datetimeaxis/chartdatetimeaxisy.cpp
+++ b/src/charts/axis/datetimeaxis/chartdatetimeaxisy.cpp
@@ -109,26 +109,36 @@ QSizeF ChartDateTimeAxisY::sizeHint(Qt::SizeHint which, const QSizeF &constraint
switch (which) {
case Qt::MinimumSize: {
- QRectF boundingRect = ChartPresenter::textBoundingRect(axis()->labelsFont(),
- QStringLiteral("..."),
- axis()->labelsAngle());
- width = boundingRect.width() + labelPadding() + base.width() + 1.0;
- height = boundingRect.height() / 2.0;
+ if (labelsVisible()) {
+ QRectF boundingRect = ChartPresenter::textBoundingRect(axis()->labelsFont(),
+ QStringLiteral("..."),
+ axis()->labelsAngle());
+ width = boundingRect.width() + labelPadding() + base.width() + 1.0;
+ height = boundingRect.height() / 2.0;
+ } else {
+ width = base.width() + 1.0;
+ height = 0;
+ }
sh = QSizeF(width, height);
break;
}
case Qt::PreferredSize: {
- qreal labelWidth = 0.0;
- qreal firstHeight = -1.0;
- foreach (const QString& s, ticksList) {
- QRectF rect = ChartPresenter::textBoundingRect(axis()->labelsFont(), s, axis()->labelsAngle());
- labelWidth = qMax(rect.width(), labelWidth);
- height = rect.height();
- if (firstHeight < 0.0)
- firstHeight = height;
+ if (labelsVisible()) {
+ qreal labelWidth = 0.0;
+ qreal firstHeight = -1.0;
+ foreach (const QString& s, ticksList) {
+ QRectF rect = ChartPresenter::textBoundingRect(axis()->labelsFont(), s, axis()->labelsAngle());
+ labelWidth = qMax(rect.width(), labelWidth);
+ height = rect.height();
+ if (firstHeight < 0.0)
+ firstHeight = height;
+ }
+ width = labelWidth + labelPadding() + base.width() + 2.0; //two pixels of tolerance
+ height = qMax(height, firstHeight) / 2.0;
+ } else {
+ width = base.width() + 2.0;
+ height = 0;
}
- width = labelWidth + labelPadding() + base.width() + 2.0; //two pixels of tolerance
- height = qMax(height, firstHeight) / 2.0;
sh = QSizeF(width, height);
break;
}
diff --git a/src/charts/axis/logvalueaxis/chartlogvalueaxisx.cpp b/src/charts/axis/logvalueaxis/chartlogvalueaxisx.cpp
index 43abf724..5bdcf043 100644
--- a/src/charts/axis/logvalueaxis/chartlogvalueaxisx.cpp
+++ b/src/charts/axis/logvalueaxis/chartlogvalueaxisx.cpp
@@ -115,26 +115,36 @@ QSizeF ChartLogValueAxisX::sizeHint(Qt::SizeHint which, const QSizeF &constraint
switch (which) {
case Qt::MinimumSize:{
- QRectF boundingRect = ChartPresenter::textBoundingRect(axis()->labelsFont(),
- QStringLiteral("..."),
- axis()->labelsAngle());
- width = boundingRect.width() / 2.0;
- height = boundingRect.height() + labelPadding() + base.height() + 1.0;
+ if (labelsVisible()) {
+ QRectF boundingRect = ChartPresenter::textBoundingRect(axis()->labelsFont(),
+ QStringLiteral("..."),
+ axis()->labelsAngle());
+ width = boundingRect.width() / 2.0;
+ height = boundingRect.height() + labelPadding() + base.height() + 1.0;
+ } else {
+ width = 0;
+ height = base.height() + 1.0;
+ }
sh = QSizeF(width, height);
break;
}
case Qt::PreferredSize: {
- qreal labelHeight = 0.0;
- qreal firstWidth = -1.0;
- foreach (const QString& s, ticksList) {
- QRectF rect = ChartPresenter::textBoundingRect(axis()->labelsFont(), s, axis()->labelsAngle());
- labelHeight = qMax(rect.height(), labelHeight);
- width = rect.width();
- if (firstWidth < 0.0)
- firstWidth = width;
+ if (labelsVisible()) {
+ qreal labelHeight = 0.0;
+ qreal firstWidth = -1.0;
+ foreach (const QString& s, ticksList) {
+ QRectF rect = ChartPresenter::textBoundingRect(axis()->labelsFont(), s, axis()->labelsAngle());
+ labelHeight = qMax(rect.height(), labelHeight);
+ width = rect.width();
+ if (firstWidth < 0.0)
+ firstWidth = width;
+ }
+ height = labelHeight + labelPadding() + base.height() + 1.0;
+ width = qMax(width, firstWidth) / 2.0;
+ } else {
+ height = base.height() + 1.0;
+ width = 0;
}
- height = labelHeight + labelPadding() + base.height() + 1.0;
- width = qMax(width, firstWidth) / 2.0;
sh = QSizeF(width, height);
break;
}
diff --git a/src/charts/axis/logvalueaxis/chartlogvalueaxisy.cpp b/src/charts/axis/logvalueaxis/chartlogvalueaxisy.cpp
index 8c65aa54..dd96cc3d 100644
--- a/src/charts/axis/logvalueaxis/chartlogvalueaxisy.cpp
+++ b/src/charts/axis/logvalueaxis/chartlogvalueaxisy.cpp
@@ -116,26 +116,36 @@ QSizeF ChartLogValueAxisY::sizeHint(Qt::SizeHint which, const QSizeF &constraint
switch (which) {
case Qt::MinimumSize: {
- QRectF boundingRect = ChartPresenter::textBoundingRect(axis()->labelsFont(),
- QStringLiteral("..."),
- axis()->labelsAngle());
- width = boundingRect.width() + labelPadding() + base.width() + 1.0;
- height = boundingRect.height() / 2.0;
+ if (labelsVisible()) {
+ QRectF boundingRect = ChartPresenter::textBoundingRect(axis()->labelsFont(),
+ QStringLiteral("..."),
+ axis()->labelsAngle());
+ width = boundingRect.width() + labelPadding() + base.width() + 1.0;
+ height = boundingRect.height() / 2.0;
+ } else {
+ width = base.width() + 1.0;
+ height = 0;
+ }
sh = QSizeF(width, height);
break;
}
case Qt::PreferredSize: {
- qreal labelWidth = 0.0;
- qreal firstHeight = -1.0;
- foreach (const QString& s, ticksList) {
- QRectF rect = ChartPresenter::textBoundingRect(axis()->labelsFont(), s, axis()->labelsAngle());
- labelWidth = qMax(rect.width(), labelWidth);
- height = rect.height();
- if (firstHeight < 0.0)
- firstHeight = height;
+ if (labelsVisible()) {
+ qreal labelWidth = 0.0;
+ qreal firstHeight = -1.0;
+ foreach (const QString& s, ticksList) {
+ QRectF rect = ChartPresenter::textBoundingRect(axis()->labelsFont(), s, axis()->labelsAngle());
+ labelWidth = qMax(rect.width(), labelWidth);
+ height = rect.height();
+ if (firstHeight < 0.0)
+ firstHeight = height;
+ }
+ width = labelWidth + labelPadding() + base.width() + 2.0; //two pixels of tolerance
+ height = qMax(height, firstHeight) / 2.0;
+ } else {
+ width = base.width() + 2.0;
+ height = 0;
}
- width = labelWidth + labelPadding() + base.width() + 2.0; //two pixels of tolerance
- height = qMax(height, firstHeight) / 2.0;
sh = QSizeF(width, height);
break;
}
diff --git a/src/charts/axis/valueaxis/chartvalueaxisx.cpp b/src/charts/axis/valueaxis/chartvalueaxisx.cpp
index a69c6669..99ee76cd 100644
--- a/src/charts/axis/valueaxis/chartvalueaxisx.cpp
+++ b/src/charts/axis/valueaxis/chartvalueaxisx.cpp
@@ -170,26 +170,36 @@ QSizeF ChartValueAxisX::sizeHint(Qt::SizeHint which, const QSizeF &constraint) c
switch (which) {
case Qt::MinimumSize: {
- QRectF boundingRect = ChartPresenter::textBoundingRect(axis()->labelsFont(),
- QStringLiteral("..."),
- axis()->labelsAngle());
- width = boundingRect.width() / 2.0;
- height = boundingRect.height() + labelPadding() + base.height() + 1.0;
+ if (labelsVisible()) {
+ QRectF boundingRect = ChartPresenter::textBoundingRect(axis()->labelsFont(),
+ QStringLiteral("..."),
+ axis()->labelsAngle());
+ width = boundingRect.width() / 2.0;
+ height = boundingRect.height() + labelPadding() + base.height() + 1.0;
+ } else {
+ width = 0;
+ height = base.height() + 1.0;
+ }
sh = QSizeF(width, height);
break;
}
case Qt::PreferredSize: {
- qreal labelHeight = 0.0;
- qreal firstWidth = -1.0;
- foreach (const QString& s, ticksList) {
- QRectF rect = ChartPresenter::textBoundingRect(axis()->labelsFont(), s, axis()->labelsAngle());
- labelHeight = qMax(rect.height(), labelHeight);
- width = rect.width();
- if (firstWidth < 0.0)
- firstWidth = width;
+ if (labelsVisible()) {
+ qreal labelHeight = 0.0;
+ qreal firstWidth = -1.0;
+ foreach (const QString& s, ticksList) {
+ QRectF rect = ChartPresenter::textBoundingRect(axis()->labelsFont(), s, axis()->labelsAngle());
+ labelHeight = qMax(rect.height(), labelHeight);
+ width = rect.width();
+ if (firstWidth < 0.0)
+ firstWidth = width;
+ }
+ height = labelHeight + labelPadding() + base.height() + 1.0;
+ width = qMax(width, firstWidth) / 2.0;
+ } else {
+ height = base.height() + 1.0;
+ width = 0;
}
- height = labelHeight + labelPadding() + base.height() + 1.0;
- width = qMax(width, firstWidth) / 2.0;
sh = QSizeF(width, height);
break;
}
diff --git a/src/charts/axis/valueaxis/chartvalueaxisy.cpp b/src/charts/axis/valueaxis/chartvalueaxisy.cpp
index 1b48e446..315220cd 100644
--- a/src/charts/axis/valueaxis/chartvalueaxisy.cpp
+++ b/src/charts/axis/valueaxis/chartvalueaxisy.cpp
@@ -168,26 +168,36 @@ QSizeF ChartValueAxisY::sizeHint(Qt::SizeHint which, const QSizeF &constraint) c
switch (which) {
case Qt::MinimumSize: {
- QRectF boundingRect = ChartPresenter::textBoundingRect(axis()->labelsFont(),
+ if (labelsVisible()) {
+ QRectF boundingRect = ChartPresenter::textBoundingRect(axis()->labelsFont(),
QStringLiteral("..."),
axis()->labelsAngle());
- width = boundingRect.width() + labelPadding() + base.width() + 1.0;
- height = boundingRect.height() / 2.0;
+ width = boundingRect.width() + labelPadding() + base.width() + 1.0;
+ height = boundingRect.height() / 2.0;
+ } else {
+ width = base.width() + 1.0;
+ height = 0;
+ }
sh = QSizeF(width, height);
break;
}
case Qt::PreferredSize: {
- qreal labelWidth = 0.0;
- qreal firstHeight = -1.0;
- foreach (const QString& s, ticksList) {
- QRectF rect = ChartPresenter::textBoundingRect(axis()->labelsFont(), s, axis()->labelsAngle());
- labelWidth = qMax(rect.width(), labelWidth);
- height = rect.height();
- if (firstHeight < 0.0)
- firstHeight = height;
+ if (labelsVisible()) {
+ qreal labelWidth = 0.0;
+ qreal firstHeight = -1.0;
+ foreach (const QString& s, ticksList) {
+ QRectF rect = ChartPresenter::textBoundingRect(axis()->labelsFont(), s, axis()->labelsAngle());
+ labelWidth = qMax(rect.width(), labelWidth);
+ height = rect.height();
+ if (firstHeight < 0.0)
+ firstHeight = height;
+ }
+ width = labelWidth + labelPadding() + base.width() + 2.0; //two pixels of tolerance
+ height = qMax(height, firstHeight) / 2.0;
+ } else {
+ width = base.width() + 2.0; //two pixels of tolerance
+ height = 0;
}
- width = labelWidth + labelPadding() + base.width() + 2.0; //two pixels of tolerance
- height = qMax(height, firstHeight) / 2.0;
sh = QSizeF(width, height);
break;
}