summaryrefslogtreecommitdiffstats
path: root/src/charts/axis/verticalaxis.cpp
diff options
context:
space:
mode:
authorTitta Heikkala <titta.heikkala@theqtcompany.com>2015-06-11 12:08:58 +0300
committerTitta Heikkala <titta.heikkala@theqtcompany.com>2015-06-17 11:02:08 +0300
commit740f4f94adf83f2613161f2ff578ff37eeb89dc6 (patch)
treee13a491e6fbcf5b7887c284464edce8798fb737b /src/charts/axis/verticalaxis.cpp
parentce2af37ac88e8bcca6ab0490f2998b5c9e056acf (diff)
Added possibility to set labels position for QCategoryAxis
The position of the labels in QCategyAxis can now be set to center of the category or to the high end of the category. The first and the last labels may overlap with other axes labels when positioned on value. Change-Id: Ide0f12b723ffabf6682001e03ea5080f9642da22 Task-number: QTRD-1715 Reviewed-by: Miikka Heikkinen <miikka.heikkinen@theqtcompany.com>
Diffstat (limited to 'src/charts/axis/verticalaxis.cpp')
-rw-r--r--src/charts/axis/verticalaxis.cpp35
1 files changed, 28 insertions, 7 deletions
diff --git a/src/charts/axis/verticalaxis.cpp b/src/charts/axis/verticalaxis.cpp
index 50ce37e1..89760c3a 100644
--- a/src/charts/axis/verticalaxis.cpp
+++ b/src/charts/axis/verticalaxis.cpp
@@ -19,6 +19,7 @@
#include <private/verticalaxis_p.h>
#include <QtCharts/QAbstractAxis>
#include <private/chartpresenter_p.h>
+#include <QtCharts/QCategoryAxis>
#include <QtCore/QDebug>
QT_CHARTS_BEGIN_NAMESPACE
@@ -140,23 +141,43 @@ void VerticalAxis::updateGeometry()
//label in between
bool forceHide = false;
+ bool labelOnValue = false;
if (intervalAxis() && (i + 1) != layout.size()) {
qreal lowerBound = qMin(layout[i], gridRect.bottom());
qreal upperBound = qMax(layout[i + 1], gridRect.top());
const qreal delta = lowerBound - upperBound;
- // Hide label in case visible part of the category at the grid edge is too narrow
- if (delta < boundingRect.height()
- && (lowerBound == gridRect.bottom() || upperBound == gridRect.top())) {
- forceHide = true;
+ if (axis()->type() != QAbstractAxis::AxisTypeCategory) {
+ // Hide label in case visible part of the category at the grid edge is too narrow
+ if (delta < boundingRect.height()
+ && (lowerBound == gridRect.bottom() || upperBound == gridRect.top())) {
+ forceHide = true;
+ } else {
+ labelItem->setPos(labelItem->pos().x(),
+ lowerBound - (delta / 2.0) - center.y());
+ }
} else {
- labelItem->setPos(labelItem->pos().x() , lowerBound - (delta / 2.0) - center.y());
+ QCategoryAxis *categoryAxis = static_cast<QCategoryAxis *>(axis());
+ if (categoryAxis->labelsPosition() == QCategoryAxis::AxisLabelsPositionCenter) {
+ if (delta < boundingRect.height()
+ && (lowerBound == gridRect.bottom() || upperBound == gridRect.top())) {
+ forceHide = true;
+ } else {
+ labelItem->setPos(labelItem->pos().x(),
+ lowerBound - (delta / 2.0) - center.y());
+ }
+ } else if (categoryAxis->labelsPosition()
+ == QCategoryAxis::AxisLabelsPositionOnValue) {
+ labelOnValue = true;
+ labelItem->setPos(labelItem->pos().x(), upperBound - center.y());
+ }
}
}
//label overlap detection - compensate one pixel for rounding errors
if (labelItem->pos().y() + boundingRect.height() > height || forceHide ||
- (labelItem->pos().y() + (heightDiff / 2.0) - 1.0) > axisRect.bottom() ||
- labelItem->pos().y() + (heightDiff / 2.0) < (axisRect.top() - 1.0)) {
+ ((labelItem->pos().y() + (heightDiff / 2.0) - 1.0) > axisRect.bottom()
+ && !labelOnValue) ||
+ (labelItem->pos().y() + (heightDiff / 2.0) < (axisRect.top() - 1.0) && !labelOnValue)) {
labelItem->setVisible(false);
}
else {