summaryrefslogtreecommitdiffstats
path: root/src/charts/axis/chartaxiselement.cpp
diff options
context:
space:
mode:
authorLukas Kosinski <lukasz@scythe-studio.com>2021-05-24 22:50:53 +0200
committerLukas Kosinski <lukasz@scythe-studio.com>2021-06-02 13:09:06 +0200
commitad94166fefba448805d145d6c61a6b30209aa146 (patch)
tree0085338059ce59d27275d6804f66cee38df1f1f3 /src/charts/axis/chartaxiselement.cpp
parent92b136373dcca34ae2a32872885a84b0833d0143 (diff)
Add optional labels truncation to QAbstractAxis
This is a feature that allows users to switch off labels truncation that is by default performed if there is too little space for the label. By default truncateLabels is true, so it doesn't change previous behavior. If user doesn't want to have truncated labels, he can switch them off explicitly. There is also a labelsTruncated method added that returns true if there is at least one truncated label and false otherwise. The reason for this is to be able to programmatically check if labels are truncated. Task-number: QTBUG-89444 Change-Id: I8ab18a8d0335ddf31baf443a2046fee89ce58b38 Reviewed-by: Leena Miettinen <riitta-leena.miettinen@qt.io> Reviewed-by: Miikka Heikkinen <miikka.heikkinen@qt.io>
Diffstat (limited to 'src/charts/axis/chartaxiselement.cpp')
-rw-r--r--src/charts/axis/chartaxiselement.cpp8
1 files changed, 8 insertions, 0 deletions
diff --git a/src/charts/axis/chartaxiselement.cpp b/src/charts/axis/chartaxiselement.cpp
index 06d919f4..93cbebda 100644
--- a/src/charts/axis/chartaxiselement.cpp
+++ b/src/charts/axis/chartaxiselement.cpp
@@ -122,6 +122,8 @@ void ChartAxisElement::connectSlots()
this, SLOT(handleGridLineColorChanged(const QColor&)));
QObject::connect(axis(), SIGNAL(minorGridLineColorChanged(const QColor&)),
this, SLOT(handleMinorGridLineColorChanged(const QColor&)));
+ QObject::connect(axis(), &QAbstractAxis::truncateLabelsChanged,
+ this, &ChartAxisElement::handleTruncateLabelsChanged);
if (axis()->type() == QAbstractAxis::AxisTypeCategory) {
QCategoryAxis *categoryAxis = static_cast<QCategoryAxis *>(axis());
@@ -157,6 +159,12 @@ void ChartAxisElement::handleLabelsPositionChanged()
presenter()->layout()->invalidate();
}
+void ChartAxisElement::handleTruncateLabelsChanged()
+{
+ QGraphicsLayoutItem::updateGeometry();
+ presenter()->layout()->invalidate();
+}
+
void ChartAxisElement::valueLabelEdited(qreal oldValue, qreal newValue)
{
qreal range = max() - min();