summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--.qmake.conf2
-rw-r--r--examples/charts/boxplotchart/boxdatareader.cpp4
-rw-r--r--src/charts/animations/baranimation.cpp1
-rw-r--r--src/charts/animations/boxwhiskersanimation.cpp1
-rw-r--r--src/charts/areachart/areachartitem.cpp4
-rw-r--r--src/charts/areachart/qareaseries.cpp5
-rw-r--r--src/charts/axis/axis.pri10
-rw-r--r--src/charts/axis/cartesianchartaxis.cpp73
-rw-r--r--src/charts/axis/cartesianchartaxis_p.h6
-rw-r--r--src/charts/axis/categoryaxis/polarchartcategoryaxisangular.cpp1
-rw-r--r--src/charts/axis/chartaxiselement.cpp82
-rw-r--r--src/charts/axis/chartaxiselement_p.h9
-rw-r--r--src/charts/axis/datetimeaxis/chartdatetimeaxisx.cpp1
-rw-r--r--src/charts/axis/datetimeaxis/chartdatetimeaxisy.cpp1
-rw-r--r--src/charts/axis/datetimeaxis/datetimeaxislabel.cpp98
-rw-r--r--src/charts/axis/datetimeaxis/datetimeaxislabel_p.h75
-rw-r--r--src/charts/axis/datetimeaxis/qdatetimeaxis.cpp4
-rw-r--r--src/charts/axis/editableaxislabel.cpp122
-rw-r--r--src/charts/axis/editableaxislabel_p.h78
-rw-r--r--src/charts/axis/qabstractaxis.cpp40
-rw-r--r--src/charts/axis/qabstractaxis.h5
-rw-r--r--src/charts/axis/qabstractaxis_p.h1
-rw-r--r--src/charts/axis/valueaxis/chartvalueaxisx.cpp2
-rw-r--r--src/charts/axis/valueaxis/chartvalueaxisy.cpp2
-rw-r--r--src/charts/axis/valueaxis/qvalueaxis.cpp1
-rw-r--r--src/charts/axis/valueaxis/valueaxislabel.cpp104
-rw-r--r--src/charts/axis/valueaxis/valueaxislabel_p.h71
-rw-r--r--src/charts/legend/qlegend.cpp3
-rw-r--r--src/charts/piechart/qpieslice.cpp2
-rw-r--r--src/charts/scatterchart/qscatterseries.cpp5
-rw-r--r--src/charts/xychart/qxyseries.cpp2
-rw-r--r--src/chartsqml2/declarativecategoryaxis.cpp4
-rw-r--r--src/chartsqml2/plugins.qmltypes6
33 files changed, 808 insertions, 17 deletions
diff --git a/.qmake.conf b/.qmake.conf
index 1bf9543a..f8cda0e7 100644
--- a/.qmake.conf
+++ b/.qmake.conf
@@ -1,3 +1,3 @@
load(qt_build_config)
-MODULE_VERSION = 5.12.3
+MODULE_VERSION = 5.13.0
diff --git a/examples/charts/boxplotchart/boxdatareader.cpp b/examples/charts/boxplotchart/boxdatareader.cpp
index 10591135..f634bd4e 100644
--- a/examples/charts/boxplotchart/boxdatareader.cpp
+++ b/examples/charts/boxplotchart/boxdatareader.cpp
@@ -29,6 +29,8 @@
#include "boxdatareader.h"
+#include <algorithm>
+
BoxDataReader::BoxDataReader(QIODevice *device) :
QTextStream(device)
{
@@ -56,7 +58,7 @@ QBoxSet *BoxDataReader::readBox()
for (int i = 1; i < strList.count(); i++)
sortedList.append(strList.at(i).toDouble());
- qSort(sortedList.begin(), sortedList.end());
+ std::sort(sortedList.begin(), sortedList.end());
//! [3]
int count = sortedList.count();
diff --git a/src/charts/animations/baranimation.cpp b/src/charts/animations/baranimation.cpp
index d5c5f7c1..a7752272 100644
--- a/src/charts/animations/baranimation.cpp
+++ b/src/charts/animations/baranimation.cpp
@@ -88,4 +88,3 @@ void BarAnimation::setup(const QVector<QRectF> &oldLayout, const QVector<QRectF>
QT_CHARTS_END_NAMESPACE
#include "moc_baranimation_p.cpp"
-
diff --git a/src/charts/animations/boxwhiskersanimation.cpp b/src/charts/animations/boxwhiskersanimation.cpp
index c8bf584f..141fadd8 100644
--- a/src/charts/animations/boxwhiskersanimation.cpp
+++ b/src/charts/animations/boxwhiskersanimation.cpp
@@ -118,4 +118,3 @@ void BoxWhiskersAnimation::setStartData(const BoxWhiskersData &endData)
QT_CHARTS_END_NAMESPACE
#include "moc_boxwhiskersanimation_p.cpp"
-
diff --git a/src/charts/areachart/areachartitem.cpp b/src/charts/areachart/areachartitem.cpp
index 58f2c367..e4ebf80a 100644
--- a/src/charts/areachart/areachartitem.cpp
+++ b/src/charts/areachart/areachartitem.cpp
@@ -278,7 +278,7 @@ void AreaChartItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *opt
presenter()->numberToString(m_series->upperSeries()->at(i).y()));
// Position text in relation to the point
- int pointLabelWidth = fm.width(pointLabel);
+ int pointLabelWidth = fm.horizontalAdvance(pointLabel);
QPointF position(m_upper->geometryPoints().at(i));
position.setX(position.x() - pointLabelWidth / 2);
position.setY(position.y() - m_series->upperSeries()->pen().width() / 2
@@ -296,7 +296,7 @@ void AreaChartItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *opt
presenter()->numberToString(m_series->lowerSeries()->at(i).y()));
// Position text in relation to the point
- int pointLabelWidth = fm.width(pointLabel);
+ int pointLabelWidth = fm.horizontalAdvance(pointLabel);
QPointF position(m_lower->geometryPoints().at(i));
position.setX(position.x() - pointLabelWidth / 2);
position.setY(position.y() - m_series->lowerSeries()->pen().width() / 2
diff --git a/src/charts/areachart/qareaseries.cpp b/src/charts/areachart/qareaseries.cpp
index f8401785..fd473c72 100644
--- a/src/charts/areachart/qareaseries.cpp
+++ b/src/charts/areachart/qareaseries.cpp
@@ -196,6 +196,11 @@ QT_CHARTS_BEGIN_NAMESPACE
*/
/*!
+ \qmlproperty brush AreaSeries::brush
+ The brush used to draw to draw the line for this series.
+*/
+
+/*!
\qmlproperty QString AreaSeries::brushFilename
The name of the file used as a brush image for the series.
*/
diff --git a/src/charts/axis/axis.pri b/src/charts/axis/axis.pri
index 340f5b35..c5efddc2 100644
--- a/src/charts/axis/axis.pri
+++ b/src/charts/axis/axis.pri
@@ -15,6 +15,7 @@ SOURCES += \
$$PWD/valueaxis/chartvalueaxisx.cpp \
$$PWD/valueaxis/chartvalueaxisy.cpp \
$$PWD/valueaxis/qvalueaxis.cpp \
+ $$PWD/valueaxis/valueaxislabel.cpp \
$$PWD/barcategoryaxis/chartbarcategoryaxisx.cpp \
$$PWD/barcategoryaxis/chartbarcategoryaxisy.cpp \
$$PWD/barcategoryaxis/qbarcategoryaxis.cpp \
@@ -23,7 +24,8 @@ SOURCES += \
$$PWD/categoryaxis/qcategoryaxis.cpp \
$$PWD/logvalueaxis/chartlogvalueaxisx.cpp \
$$PWD/logvalueaxis/chartlogvalueaxisy.cpp \
- $$PWD/logvalueaxis/qlogvalueaxis.cpp
+ $$PWD/logvalueaxis/qlogvalueaxis.cpp \
+ $$PWD/editableaxislabel.cpp
PRIVATE_HEADERS += \
$$PWD/chartaxiselement_p.h \
@@ -35,6 +37,7 @@ PRIVATE_HEADERS += \
$$PWD/valueaxis/chartvalueaxisx_p.h \
$$PWD/valueaxis/chartvalueaxisy_p.h \
$$PWD/valueaxis/qvalueaxis_p.h \
+ $$PWD/valueaxis/valueaxislabel_p.h \
$$PWD/barcategoryaxis/chartbarcategoryaxisx_p.h \
$$PWD/barcategoryaxis/chartbarcategoryaxisy_p.h \
$$PWD/barcategoryaxis/qbarcategoryaxis_p.h \
@@ -43,7 +46,8 @@ PRIVATE_HEADERS += \
$$PWD/categoryaxis/qcategoryaxis_p.h \
$$PWD/logvalueaxis/chartlogvalueaxisx_p.h \
$$PWD/logvalueaxis/chartlogvalueaxisy_p.h \
- $$PWD/logvalueaxis/qlogvalueaxis_p.h
+ $$PWD/logvalueaxis/qlogvalueaxis_p.h \
+ $$PWD/editableaxislabel_p.h
PUBLIC_HEADERS += \
$$PWD/qabstractaxis.h \
@@ -83,6 +87,7 @@ SOURCES += \
$$PWD/datetimeaxis/chartdatetimeaxisx.cpp \
$$PWD/datetimeaxis/chartdatetimeaxisy.cpp \
$$PWD/datetimeaxis/qdatetimeaxis.cpp \
+ $$PWD/datetimeaxis/datetimeaxislabel.cpp \
$$PWD/datetimeaxis/polarchartdatetimeaxisangular.cpp \
$$PWD/datetimeaxis/polarchartdatetimeaxisradial.cpp
@@ -90,6 +95,7 @@ PRIVATE_HEADERS += \
$$PWD/datetimeaxis/chartdatetimeaxisx_p.h \
$$PWD/datetimeaxis/chartdatetimeaxisy_p.h \
$$PWD/datetimeaxis/qdatetimeaxis_p.h \
+ $$PWD/datetimeaxis/datetimeaxislabel_p.h \
$$PWD/datetimeaxis/polarchartdatetimeaxisangular_p.h \
$$PWD/datetimeaxis/polarchartdatetimeaxisradial_p.h
diff --git a/src/charts/axis/cartesianchartaxis.cpp b/src/charts/axis/cartesianchartaxis.cpp
index 571af7a9..935a9601 100644
--- a/src/charts/axis/cartesianchartaxis.cpp
+++ b/src/charts/axis/cartesianchartaxis.cpp
@@ -81,7 +81,25 @@ void CartesianChartAxis::createItems(int count)
for (int i = 0; i < count; ++i) {
QGraphicsLineItem *arrow = new QGraphicsLineItem(this);
QGraphicsLineItem *grid = new QGraphicsLineItem(this);
- QGraphicsTextItem *label = new QGraphicsTextItem(this);
+ QGraphicsTextItem *label;
+ if (axis()->type() == QtCharts::QAbstractAxis::AxisTypeValue) {
+ label = new ValueAxisLabel(this);
+ connect(static_cast<ValueAxisLabel *>(label), &ValueAxisLabel::valueChanged,
+ this, &ChartAxisElement::valueLabelEdited);
+ if (labelsEditable())
+ static_cast<ValueAxisLabel *>(label)->setEditable(true);
+ } else if (axis()->type() == QtCharts::QAbstractAxis::AxisTypeDateTime) {
+ DateTimeAxisLabel *dateTimeLabel = new DateTimeAxisLabel(this);
+ label = dateTimeLabel;
+ connect(dateTimeLabel, &DateTimeAxisLabel::dateTimeChanged,
+ this, &ChartAxisElement::dateTimeLabelEdited);
+ if (labelsEditable())
+ dateTimeLabel->setEditable(true);
+ dateTimeLabel->setFormat(static_cast<QDateTimeAxis*>(axis())->format());
+ } else {
+ label = new QGraphicsTextItem(this);
+ }
+
label->document()->setDocumentMargin(ChartPresenter::textMargin());
arrow->setPen(axis()->linePen());
grid->setPen(axis()->gridLinePen());
@@ -271,6 +289,18 @@ QSizeF CartesianChartAxis::sizeHint(Qt::SizeHint which, const QSizeF &constraint
return QSizeF();
}
+void CartesianChartAxis::setDateTimeLabelsFormat(const QString &format)
+{
+ if (max() <= min()
+ || layout().size() < 1
+ || axis()->type() != QAbstractAxis::AxisTypeDateTime) {
+ return;
+ }
+
+ for (int i = 0; i < layout().size(); i++)
+ static_cast<DateTimeAxisLabel *>(labelItems().at(i))->setFormat(format);
+}
+
void CartesianChartAxis::handleArrowPenChanged(const QPen &pen)
{
foreach (QGraphicsItem *item, arrowItems())
@@ -327,6 +357,47 @@ void CartesianChartAxis::handleShadesPenChanged(const QPen &pen)
static_cast<QGraphicsRectItem *>(item)->setPen(pen);
}
+void CartesianChartAxis::updateLabelsValues(QValueAxis *axis)
+{
+ const QVector<qreal> &layout = ChartAxisElement::layout();
+ if (layout.isEmpty())
+ return;
+
+ if (axis->tickType() == QValueAxis::TicksFixed) {
+ for (int i = 0; i < layout.size(); ++i) {
+ qreal value = axis->isReverse()
+ ? min() + ((layout.size() - 1 - i) * (max() - min()) / (layout.size() - 1))
+ : min() + (i * (max() - min()) / (layout.size() - 1));
+ static_cast<ValueAxisLabel *>(labelItems().at(i))->setValue(value);
+ }
+ } else {
+ qreal value = axis->tickAnchor();
+ if (value > min())
+ value = value - int((value - min()) / axis->tickInterval()) * axis->tickInterval();
+ else
+ value = value + qCeil((min() - value) / axis->tickInterval()) * axis->tickInterval();
+
+ int i = axis->isReverse() ? labelItems().count()-1 : 0;
+ while (value <= max() || qFuzzyCompare(value, max())) {
+ static_cast<ValueAxisLabel *>(labelItems().at(i))->setValue(value);
+ value += axis->tickInterval();
+ i += axis->isReverse() ? -1 : 1;
+ }
+ }
+}
+
+void CartesianChartAxis::updateLabelsDateTimes()
+{
+ if (max() <= min() || layout().size() < 1)
+ return;
+
+ for (int i = 0; i < layout().size(); i++) {
+ qreal value = min() + (i * (max() - min()) / (layout().size() - 1));
+ static_cast<DateTimeAxisLabel *>(labelItems().at(i))->setValue(
+ QDateTime::fromMSecsSinceEpoch(value));
+ }
+}
+
QT_CHARTS_END_NAMESPACE
#include "moc_cartesianchartaxis_p.cpp"
diff --git a/src/charts/axis/cartesianchartaxis_p.h b/src/charts/axis/cartesianchartaxis_p.h
index 60cabd19..b619ed8b 100644
--- a/src/charts/axis/cartesianchartaxis_p.h
+++ b/src/charts/axis/cartesianchartaxis_p.h
@@ -62,6 +62,8 @@ public:
virtual QSizeF sizeHint(Qt::SizeHint which, const QSizeF &constraint = QSizeF()) const;
+ void setDateTimeLabelsFormat(const QString &format);
+
protected:
void setGeometry(const QRectF &size) { Q_UNUSED(size);}
virtual void updateGeometry() = 0;
@@ -77,6 +79,10 @@ public Q_SLOTS:
virtual void handleGridLineColorChanged(const QColor &color);
virtual void handleMinorGridLineColorChanged(const QColor &color);
+protected:
+ void updateLabelsValues(QValueAxis *axis);
+ void updateLabelsDateTimes();
+
private:
void createItems(int count);
void deleteItems(int count);
diff --git a/src/charts/axis/categoryaxis/polarchartcategoryaxisangular.cpp b/src/charts/axis/categoryaxis/polarchartcategoryaxisangular.cpp
index 08d6b8a4..890f0089 100644
--- a/src/charts/axis/categoryaxis/polarchartcategoryaxisangular.cpp
+++ b/src/charts/axis/categoryaxis/polarchartcategoryaxisangular.cpp
@@ -83,7 +83,6 @@ void PolarChartCategoryAxisAngular::handleCategoriesChanged()
presenter()->layout()->invalidate();
}
-
QT_CHARTS_END_NAMESPACE
#include "moc_polarchartcategoryaxisangular_p.cpp"
diff --git a/src/charts/axis/chartaxiselement.cpp b/src/charts/axis/chartaxiselement.cpp
index fc2b3e27..62da84f4 100644
--- a/src/charts/axis/chartaxiselement.cpp
+++ b/src/charts/axis/chartaxiselement.cpp
@@ -157,6 +157,60 @@ void ChartAxisElement::handleLabelsPositionChanged()
presenter()->layout()->invalidate();
}
+void ChartAxisElement::valueLabelEdited(qreal oldValue, qreal newValue)
+{
+ qreal range = max() - min();
+ qreal center = ((max() - min()) / 2.0) + min();
+ qreal newRange = 0.0;
+ auto label = static_cast<ValueAxisLabel *>(this->sender());
+ if ((oldValue >= center && newValue >= min())
+ || (oldValue < center && newValue >= max() && oldValue != min())) {
+ newRange = range * ((newValue - min()) / (oldValue - min()));
+ if (newRange > 0) {
+ m_axis->setRange(min(), min() + newRange);
+ return;
+ }
+ } else if ((oldValue >= center && newValue <= min() && max() != oldValue)
+ || (oldValue < center && newValue < max())) {
+ newRange = range * ((max() - newValue) / (max() - oldValue));
+ if (newRange > 0) {
+ m_axis->setRange(max() - newRange, max());
+ return;
+ }
+ }
+ label->reloadBeforeEditContent();
+}
+
+void ChartAxisElement::dateTimeLabelEdited(const QDateTime &oldTime, const QDateTime &newTime)
+{
+ qreal range = max() - min();
+ qreal center = ((max() - min()) / 2.0) + min();
+ qreal newRange = 0.0;
+ qint64 oldValue = oldTime.toMSecsSinceEpoch();
+ qint64 newValue = newTime.toMSecsSinceEpoch();
+ if ((oldValue >= center && newValue >= min())
+ || (oldValue < center && newValue >= max() && oldValue != min())) {
+ newRange = range * ((newValue - min()) / (oldValue - min()));
+ if (newRange > 0) {
+ m_axis->setRange(
+ QDateTime::fromMSecsSinceEpoch(min()),
+ QDateTime::fromMSecsSinceEpoch(min() + newRange));
+ return;
+ }
+ } else if ((oldValue >= center && newValue <= min() && max() != oldValue)
+ || (oldValue < center && newValue < max())) {
+ newRange = range * ((max() - newValue) / (max() - oldValue));
+ if (newRange > 0) {
+ m_axis->setRange(max() - newRange, max());
+ m_axis->setRange(
+ QDateTime::fromMSecsSinceEpoch(max() - newRange),
+ QDateTime::fromMSecsSinceEpoch(max()));
+ return;
+ }
+ }
+ static_cast<DateTimeAxisLabel *>(this->sender())->reloadBeforeEditContent();
+}
+
void ChartAxisElement::handleLabelsVisibleChanged(bool visible)
{
QGraphicsLayoutItem::updateGeometry();
@@ -502,6 +556,34 @@ QStringList ChartAxisElement::createDateTimeLabels(qreal min, qreal max,int tick
return labels;
}
+
+bool ChartAxisElement::labelsEditable() const
+{
+ return m_labelsEditable;
+}
+
+void ChartAxisElement::setLabelsEditable(bool labelsEditable)
+{
+ if (axis()->type() == QAbstractAxis::AxisTypeValue
+ || axis()->type() == QAbstractAxis::AxisTypeDateTime) {
+ labelGroup()->setHandlesChildEvents(!labelsEditable);
+ const QList<QGraphicsItem *> childItems = labelGroup()->childItems();
+ for (auto item : childItems) {
+ switch (axis()->type()) {
+ case QtCharts::QAbstractAxis::AxisTypeValue:
+ static_cast<ValueAxisLabel *>(item)->setEditable(labelsEditable);
+ break;
+ case QtCharts::QAbstractAxis::AxisTypeDateTime:
+ static_cast<DateTimeAxisLabel *>(item)->setEditable(labelsEditable);
+ break;
+ default:
+ break;
+ }
+ }
+ m_labelsEditable = labelsEditable;
+ }
+}
+
void ChartAxisElement::axisSelected()
{
emit clicked();
diff --git a/src/charts/axis/chartaxiselement_p.h b/src/charts/axis/chartaxiselement_p.h
index 7aced068..d421dc8b 100644
--- a/src/charts/axis/chartaxiselement_p.h
+++ b/src/charts/axis/chartaxiselement_p.h
@@ -43,8 +43,11 @@
#include <QtCharts/private/qchartglobal_p.h>
#include <private/chartelement_p.h>
#include <private/axisanimation_p.h>
+#include <private/datetimeaxislabel_p.h>
+#include <private/valueaxislabel_p.h>
#include <QtWidgets/QGraphicsItem>
#include <QtWidgets/QGraphicsLayoutItem>
+#include <QtCharts/qdatetimeaxis.h>
#include <QtCharts/QValueAxis>
#include <QtGui/QFont>
@@ -111,6 +114,9 @@ public:
{
}
+ bool labelsEditable() const;
+ void setLabelsEditable(bool labelsEditable);
+
protected:
virtual QVector<qreal> calculateLayout() const = 0;
virtual void updateLayout(QVector<qreal> &layout) = 0;
@@ -155,6 +161,8 @@ public Q_SLOTS:
void handleMinorArrowVisibleChanged(bool visible);
void handleMinorGridVisibleChanged(bool visible);
void handleLabelsPositionChanged();
+ void valueLabelEdited(qreal oldValue, qreal newValue);
+ void dateTimeLabelEdited(const QDateTime &oldTime, const QDateTime &newTime);
Q_SIGNALS:
void clicked();
@@ -179,6 +187,7 @@ private:
QScopedPointer<QGraphicsItemGroup> m_labels;
QScopedPointer<QGraphicsTextItem> m_title;
bool m_intervalAxis;
+ bool m_labelsEditable = false;
};
QT_CHARTS_END_NAMESPACE
diff --git a/src/charts/axis/datetimeaxis/chartdatetimeaxisx.cpp b/src/charts/axis/datetimeaxis/chartdatetimeaxisx.cpp
index 111b3526..7b304b6c 100644
--- a/src/charts/axis/datetimeaxis/chartdatetimeaxisx.cpp
+++ b/src/charts/axis/datetimeaxis/chartdatetimeaxisx.cpp
@@ -71,6 +71,7 @@ void ChartDateTimeAxisX::updateGeometry()
return;
setLabels(createDateTimeLabels(min(), max(), layout.size(), m_axis->format()));
HorizontalAxis::updateGeometry();
+ updateLabelsDateTimes();
}
void ChartDateTimeAxisX::handleTickCountChanged(int tick)
diff --git a/src/charts/axis/datetimeaxis/chartdatetimeaxisy.cpp b/src/charts/axis/datetimeaxis/chartdatetimeaxisy.cpp
index 489ba3cd..9f3a9eb3 100644
--- a/src/charts/axis/datetimeaxis/chartdatetimeaxisy.cpp
+++ b/src/charts/axis/datetimeaxis/chartdatetimeaxisy.cpp
@@ -72,6 +72,7 @@ void ChartDateTimeAxisY::updateGeometry()
return;
setLabels(createDateTimeLabels(min(), max(), layout.size(), m_axis->format()));
VerticalAxis::updateGeometry();
+ updateLabelsDateTimes();
}
void ChartDateTimeAxisY::handleTickCountChanged(int tick)
diff --git a/src/charts/axis/datetimeaxis/datetimeaxislabel.cpp b/src/charts/axis/datetimeaxis/datetimeaxislabel.cpp
new file mode 100644
index 00000000..90646ae5
--- /dev/null
+++ b/src/charts/axis/datetimeaxis/datetimeaxislabel.cpp
@@ -0,0 +1,98 @@
+/****************************************************************************
+**
+** Copyright (C) 2018 The Qt Company Ltd.
+** Contact: https://www.qt.io/licensing/
+**
+** This file is part of the Qt Charts module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:GPL$
+** Commercial License Usage
+** Licensees holding valid commercial Qt licenses may use this file in
+** accordance with the commercial license agreement provided with the
+** Software or, alternatively, in accordance with the terms contained in
+** a written agreement between you and The Qt Company. For licensing terms
+** and conditions see https://www.qt.io/terms-conditions. For further
+** information use the contact form at https://www.qt.io/contact-us.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3 or (at your option) any later version
+** approved by the KDE Free Qt Foundation. The licenses are as published by
+** the Free Software Foundation and appearing in the file LICENSE.GPL3
+** included in the packaging of this file. Please review the following
+** information to ensure the GNU General Public License requirements will
+** be met: https://www.gnu.org/licenses/gpl-3.0.html.
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+#include "datetimeaxislabel_p.h"
+
+#include <QtCore/qdatetime.h>
+
+QT_CHARTS_BEGIN_NAMESPACE
+
+DateTimeAxisLabel::DateTimeAxisLabel(QGraphicsItem *parent) :
+ EditableAxisLabel(parent)
+{
+
+}
+
+void DateTimeAxisLabel::finishEditing()
+{
+ QDateTime oldDateTime = m_dateTime;
+ QDateTime newDateTime = QDateTime::fromString(document()->toPlainText(), m_format);
+ if (newDateTime.isValid() && newDateTime != m_dateTime) {
+ m_dateTime = newDateTime;
+ emit dateTimeChanged(oldDateTime, newDateTime);
+ } else {
+ document()->setHtml(m_htmlBeforeEdit);
+ }
+}
+
+QDateTime DateTimeAxisLabel::value() const
+{
+ return m_dateTime;
+}
+
+void DateTimeAxisLabel::setValue(const QDateTime &value)
+{
+ setTextInteractionFlags(Qt::NoTextInteraction);
+ clearFocus();
+ m_dateTime = value;
+}
+
+void DateTimeAxisLabel::resetBeforeEditValue()
+{
+ m_dateTime = m_dateTimeBeforeEdit;
+}
+
+void DateTimeAxisLabel::setFormat(const QString &format)
+{
+ m_format = format;
+ // Labels should be edited as a single line regardless to their
+ // format because enter triggers applying the current text.
+ m_format.replace(QChar::fromLatin1('\n'), QChar::fromLatin1(' '));
+}
+
+void DateTimeAxisLabel::setInitialEditValue()
+{
+ m_dateTimeBeforeEdit = m_dateTime;
+ setHtml(m_dateTime.toString(m_format));
+}
+
+void DateTimeAxisLabel::keyPressEvent(QKeyEvent *event)
+{
+ if (isEditEndingKeyPress(event)) {
+ // prevent further event processing with a return
+ // because the focusOutEvent could have triggered
+ // a range change which might have invalidated the current label
+ return;
+ }
+
+ QGraphicsTextItem::keyPressEvent(event);
+}
+
+QT_CHARTS_END_NAMESPACE
+
+#include "moc_datetimeaxislabel_p.cpp"
diff --git a/src/charts/axis/datetimeaxis/datetimeaxislabel_p.h b/src/charts/axis/datetimeaxis/datetimeaxislabel_p.h
new file mode 100644
index 00000000..c06c6240
--- /dev/null
+++ b/src/charts/axis/datetimeaxis/datetimeaxislabel_p.h
@@ -0,0 +1,75 @@
+/****************************************************************************
+**
+** Copyright (C) 2018 The Qt Company Ltd.
+** Contact: https://www.qt.io/licensing/
+**
+** This file is part of the Qt Charts module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:GPL$
+** Commercial License Usage
+** Licensees holding valid commercial Qt licenses may use this file in
+** accordance with the commercial license agreement provided with the
+** Software or, alternatively, in accordance with the terms contained in
+** a written agreement between you and The Qt Company. For licensing terms
+** and conditions see https://www.qt.io/terms-conditions. For further
+** information use the contact form at https://www.qt.io/contact-us.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3 or (at your option) any later version
+** approved by the KDE Free Qt Foundation. The licenses are as published by
+** the Free Software Foundation and appearing in the file LICENSE.GPL3
+** included in the packaging of this file. Please review the following
+** information to ensure the GNU General Public License requirements will
+** be met: https://www.gnu.org/licenses/gpl-3.0.html.
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+// W A R N I N G
+// -------------
+//
+// This file is not part of the Qt Chart API. It exists purely as an
+// implementation detail. This header file may change from version to
+// version without notice, or even be removed.
+//
+// We mean it.
+
+#ifndef DATETIMEAXISLABEL_H
+#define DATETIMEAXISLABEL_H
+
+#include <private/editableaxislabel_p.h>
+
+#include <QtCore/qdatetime.h>
+
+QT_CHARTS_BEGIN_NAMESPACE
+
+class QT_CHARTS_PRIVATE_EXPORT DateTimeAxisLabel : public EditableAxisLabel
+{
+ Q_OBJECT
+public:
+ DateTimeAxisLabel(QGraphicsItem *parent = nullptr);
+
+ void keyPressEvent(QKeyEvent *event);
+
+ QDateTime value() const;
+ void setValue(const QDateTime &value);
+ void setFormat(const QString &format);
+
+private:
+ QDateTime m_dateTime;
+ QDateTime m_dateTimeBeforeEdit;
+ QString m_format;
+
+ void setInitialEditValue() override;
+ void finishEditing() override;
+ void resetBeforeEditValue() override;
+
+Q_SIGNALS:
+ void dateTimeChanged(const QDateTime &oldDateTime, const QDateTime &newDateTime);
+};
+
+QT_CHARTS_END_NAMESPACE
+
+#endif // VALUEAXISLABEL_H
diff --git a/src/charts/axis/datetimeaxis/qdatetimeaxis.cpp b/src/charts/axis/datetimeaxis/qdatetimeaxis.cpp
index a7ccd37b..dd32c299 100644
--- a/src/charts/axis/datetimeaxis/qdatetimeaxis.cpp
+++ b/src/charts/axis/datetimeaxis/qdatetimeaxis.cpp
@@ -259,6 +259,8 @@ void QDateTimeAxis::setFormat(QString format)
Q_D(QDateTimeAxis);
if (d->m_format != format) {
d->m_format = format;
+ if (d->axisItem())
+ static_cast<CartesianChartAxis*>(d->axisItem())->setDateTimeLabelsFormat(format);
emit formatChanged(format);
}
}
@@ -339,7 +341,6 @@ void QDateTimeAxisPrivate::setRange(qreal min,qreal max)
}
}
-
void QDateTimeAxisPrivate::setMin(const QVariant &min)
{
Q_Q(QDateTimeAxis);
@@ -371,6 +372,7 @@ void QDateTimeAxisPrivate::initializeGraphics(QGraphicsItem* parent)
axis = new ChartDateTimeAxisY(q,parent);
if (orientation() == Qt::Horizontal)
axis = new ChartDateTimeAxisX(q,parent);
+ axis->setLabelsEditable(q->labelsEditable());
}
if (m_chart->chartType() == QChart::ChartTypePolar) {
diff --git a/src/charts/axis/editableaxislabel.cpp b/src/charts/axis/editableaxislabel.cpp
new file mode 100644
index 00000000..aa4b0554
--- /dev/null
+++ b/src/charts/axis/editableaxislabel.cpp
@@ -0,0 +1,122 @@
+/****************************************************************************
+**
+** Copyright (C) 2018 The Qt Company Ltd.
+** Contact: https://www.qt.io/licensing/
+**
+** This file is part of the Qt Charts module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:GPL$
+** Commercial License Usage
+** Licensees holding valid commercial Qt licenses may use this file in
+** accordance with the commercial license agreement provided with the
+** Software or, alternatively, in accordance with the terms contained in
+** a written agreement between you and The Qt Company. For licensing terms
+** and conditions see https://www.qt.io/terms-conditions. For further
+** information use the contact form at https://www.qt.io/contact-us.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3 or (at your option) any later version
+** approved by the KDE Free Qt Foundation. The licenses are as published by
+** the Free Software Foundation and appearing in the file LICENSE.GPL3
+** included in the packaging of this file. Please review the following
+** information to ensure the GNU General Public License requirements will
+** be met: https://www.gnu.org/licenses/gpl-3.0.html.
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <private/editableaxislabel_p.h>
+
+#include <QtGui/qtextcursor.h>
+#include <QtGui/qtextdocument.h>
+
+QT_CHARTS_BEGIN_NAMESPACE
+
+EditableAxisLabel::EditableAxisLabel(QGraphicsItem *parent) :
+ QGraphicsTextItem(parent)
+{
+
+}
+
+void EditableAxisLabel::focusInEvent(QFocusEvent *event)
+{
+ m_htmlBeforeEdit = toHtml();
+ setTextWidth(-1);
+ setInitialEditValue();
+ m_editing = true;
+ QGraphicsTextItem::focusInEvent(event);
+}
+
+void EditableAxisLabel::focusOutEvent(QFocusEvent *event)
+{
+ // perform the modifications before calling finishEditing
+ // because finishEditing emits signals that can trigger
+ // range change which might invalidate the current label
+ QGraphicsTextItem::focusOutEvent(event);
+ setTextInteractionFlags(Qt::NoTextInteraction);
+ m_editing = false;
+
+ finishEditing();
+}
+
+bool EditableAxisLabel::sceneEvent(QEvent *event)
+{
+ if (m_editable && event->type() == QEvent::GraphicsSceneMouseDoubleClick) {
+ setTextInteractionFlags(Qt::TextEditorInteraction);
+
+ bool ret = QGraphicsTextItem::sceneEvent(event);
+ // QGraphicsTextItem::sceneevent needs to be processed before
+ // the focus and text selection
+ setFocus(Qt::MouseFocusReason);
+ QTextCursor cursor = textCursor();
+ cursor.select(QTextCursor::Document);
+ setTextCursor(cursor);
+ return ret;
+ }
+ return QGraphicsTextItem::sceneEvent(event);
+}
+
+void EditableAxisLabel::setEditable(bool editable)
+{
+ m_editable = editable;
+}
+
+void EditableAxisLabel::reloadBeforeEditContent()
+{
+ resetBeforeEditValue();
+ setHtml(m_htmlBeforeEdit);
+}
+
+QRectF EditableAxisLabel::boundingRect() const
+{
+ QRectF ret = QGraphicsTextItem::boundingRect();
+
+ // add 2px margin to allow the cursor to
+ // show up properly when editing
+ if (m_editing)
+ ret.setWidth(ret.width() + 2);
+ return ret;
+}
+
+bool EditableAxisLabel::isEditEndingKeyPress(QKeyEvent *event)
+{
+ if (event->text().length() >= 1) {
+ // finish editing with enter or ESC
+ if (event->key() == Qt::Key_Enter ||
+ event->key() == Qt::Key_Return) {
+ clearFocus();
+ return true;
+ } else if (event->key() == Qt::Key_Escape) {
+ document()->setHtml(m_htmlBeforeEdit);
+ clearFocus();
+ return true;
+ }
+ }
+ return false;
+}
+
+QT_CHARTS_END_NAMESPACE
+
+#include "moc_editableaxislabel_p.cpp"
diff --git a/src/charts/axis/editableaxislabel_p.h b/src/charts/axis/editableaxislabel_p.h
new file mode 100644
index 00000000..55c94e08
--- /dev/null
+++ b/src/charts/axis/editableaxislabel_p.h
@@ -0,0 +1,78 @@
+/****************************************************************************
+**
+** Copyright (C) 2018 The Qt Company Ltd.
+** Contact: https://www.qt.io/licensing/
+**
+** This file is part of the Qt Charts module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:GPL$
+** Commercial License Usage
+** Licensees holding valid commercial Qt licenses may use this file in
+** accordance with the commercial license agreement provided with the
+** Software or, alternatively, in accordance with the terms contained in
+** a written agreement between you and The Qt Company. For licensing terms
+** and conditions see https://www.qt.io/terms-conditions. For further
+** information use the contact form at https://www.qt.io/contact-us.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3 or (at your option) any later version
+** approved by the KDE Free Qt Foundation. The licenses are as published by
+** the Free Software Foundation and appearing in the file LICENSE.GPL3
+** included in the packaging of this file. Please review the following
+** information to ensure the GNU General Public License requirements will
+** be met: https://www.gnu.org/licenses/gpl-3.0.html.
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+// W A R N I N G
+// -------------
+//
+// This file is not part of the Qt Chart API. It exists purely as an
+// implementation detail. This header file may change from version to
+// version without notice, or even be removed.
+//
+// We mean it.
+
+#ifndef EDITABLEAXISLABEL_P_H
+#define EDITABLEAXISLABEL_P_H
+
+#include <QtCharts/private/qchartglobal_p.h>
+
+#include <QtWidgets/qgraphicsitem.h>
+#include <QtGui/qevent.h>
+#include <QtGui/qtextdocument.h>
+
+QT_CHARTS_BEGIN_NAMESPACE
+
+class QT_CHARTS_PRIVATE_EXPORT EditableAxisLabel : public QGraphicsTextItem
+{
+ Q_OBJECT
+public:
+ EditableAxisLabel(QGraphicsItem *parent = nullptr);
+
+ void focusInEvent(QFocusEvent *event);
+ void focusOutEvent(QFocusEvent *event);
+ bool sceneEvent(QEvent *event);
+ void setEditable(bool editable);
+ void reloadBeforeEditContent();
+
+ QRectF boundingRect() const;
+
+protected:
+ QString m_htmlBeforeEdit;
+ bool m_editing = false;
+ bool m_editable = false;
+
+ virtual void setInitialEditValue() = 0;
+ virtual void finishEditing() = 0;
+ virtual void resetBeforeEditValue() = 0;
+
+ bool isEditEndingKeyPress(QKeyEvent *event);
+};
+
+QT_CHARTS_END_NAMESPACE
+
+#endif // EDITABLEAXISLABEL_P_H
diff --git a/src/charts/axis/qabstractaxis.cpp b/src/charts/axis/qabstractaxis.cpp
index 73fa5920..bf7d7dfb 100644
--- a/src/charts/axis/qabstractaxis.cpp
+++ b/src/charts/axis/qabstractaxis.cpp
@@ -368,6 +368,12 @@ QT_CHARTS_BEGIN_NAMESPACE
*/
/*!
+ \fn void QAbstractAxis::labelsEditableChanged(bool editable)
+ \since 5.13
+ This signal is emitted when the labels editability changes.
+*/
+
+/*!
\fn void QAbstractAxis::gridVisibleChanged(bool visible)
This signal is emitted when the visibility of the grid lines of the axis changes to \a visible.
*/
@@ -948,6 +954,39 @@ bool QAbstractAxis::isReverse() const
return d_ptr->m_reverse;
}
+/*!
+ Sets axis labels editability to \a editable.
+
+ When the labels are editable the user will be able to change the range of the
+ axis conveniently by editing any of the labels. This feature is only supported
+ for the QValueAxis and the QDateTimeAxis.
+
+ By default, labels are not editable.
+ \since 5.13
+*/
+void QAbstractAxis::setLabelsEditable(bool editable)
+{
+ if (d_ptr->m_labelsEditable != editable) {
+ // In the case if the axis already added to a chart
+ // set the labels editability on the axisItem().
+ // Otherwise the labels editability will be set in the
+ // QValueAxisPrivate::initializeGraphics.
+ if (d_ptr->axisItem() != nullptr)
+ d_ptr->axisItem()->setLabelsEditable(editable);
+ d_ptr->m_labelsEditable = editable;
+ emit labelsEditableChanged(editable);
+ }
+}
+
+/*!
+ Returns \c true if axis labels are editable.
+ \since 5.13
+*/
+bool QAbstractAxis::labelsEditable() const
+{
+ return d_ptr->m_labelsEditable;
+}
+
void QAbstractAxis::setReverse(bool reverse)
{
if (d_ptr->m_reverse != reverse && type() != QAbstractAxis::AxisTypeBarCategory) {
@@ -972,6 +1011,7 @@ QAbstractAxisPrivate::QAbstractAxisPrivate(QAbstractAxis *q)
m_minorGridLineVisible(true),
m_minorGridLinePen(QChartPrivate::defaultPen()),
m_labelsVisible(true),
+ m_labelsEditable(false),
m_labelsBrush(QChartPrivate::defaultBrush()),
m_labelsFont(QChartPrivate::defaultFont()),
m_labelsAngle(0),
diff --git a/src/charts/axis/qabstractaxis.h b/src/charts/axis/qabstractaxis.h
index 4f902679..b7384155 100644
--- a/src/charts/axis/qabstractaxis.h
+++ b/src/charts/axis/qabstractaxis.h
@@ -173,6 +173,10 @@ public:
void setReverse(bool reverse = true);
bool isReverse() const;
+ //label editable handling
+ void setLabelsEditable(bool editable = true);
+ bool labelsEditable() const;
+
Q_SIGNALS:
void visibleChanged(bool visible);
void linePenChanged(const QPen &pen);
@@ -199,6 +203,7 @@ Q_SIGNALS:
void shadesPenChanged(const QPen &pen);
void shadesBrushChanged(const QBrush &brush);
void reverseChanged(bool reverse);
+ void labelsEditableChanged(bool editable);
protected:
QScopedPointer<QAbstractAxisPrivate> d_ptr;
diff --git a/src/charts/axis/qabstractaxis_p.h b/src/charts/axis/qabstractaxis_p.h
index 3a635d98..ee3af6a0 100644
--- a/src/charts/axis/qabstractaxis_p.h
+++ b/src/charts/axis/qabstractaxis_p.h
@@ -117,6 +117,7 @@ private:
QPen m_minorGridLinePen;
bool m_labelsVisible;
+ bool m_labelsEditable;
QBrush m_labelsBrush;
QFont m_labelsFont;
int m_labelsAngle;
diff --git a/src/charts/axis/valueaxis/chartvalueaxisx.cpp b/src/charts/axis/valueaxis/chartvalueaxisx.cpp
index 6eeda781..3eac86e0 100644
--- a/src/charts/axis/valueaxis/chartvalueaxisx.cpp
+++ b/src/charts/axis/valueaxis/chartvalueaxisx.cpp
@@ -32,6 +32,7 @@
#include <private/chartpresenter_p.h>
#include <QtCharts/QValueAxis>
#include <private/abstractchartlayout_p.h>
+#include <private/valueaxislabel_p.h>
#include <QtWidgets/QGraphicsLayout>
#include <QtCore/QtMath>
#include <QtCore/QDebug>
@@ -107,6 +108,7 @@ void ChartValueAxisX::updateGeometry()
setLabels(createValueLabels(min(), max(), layout.size(), m_axis->tickInterval(),
m_axis->tickAnchor(), m_axis->tickType(), m_axis->labelFormat()));
HorizontalAxis::updateGeometry();
+ updateLabelsValues(m_axis);
}
void ChartValueAxisX::handleTickCountChanged(int tick)
diff --git a/src/charts/axis/valueaxis/chartvalueaxisy.cpp b/src/charts/axis/valueaxis/chartvalueaxisy.cpp
index 961b292e..c4868fc2 100644
--- a/src/charts/axis/valueaxis/chartvalueaxisy.cpp
+++ b/src/charts/axis/valueaxis/chartvalueaxisy.cpp
@@ -32,6 +32,7 @@
#include <private/chartpresenter_p.h>
#include <QtCharts/QValueAxis>
#include <private/abstractchartlayout_p.h>
+#include <private/valueaxislabel_p.h>
#include <QtWidgets/QGraphicsLayout>
#include <QtCore/QtMath>
#include <QtCore/QDebug>
@@ -108,6 +109,7 @@ void ChartValueAxisY::updateGeometry()
setLabels(createValueLabels(min(), max(), layout.size(), m_axis->tickInterval(),
m_axis->tickAnchor(), m_axis->tickType(), m_axis->labelFormat()));
VerticalAxis::updateGeometry();
+ updateLabelsValues(m_axis);
}
void ChartValueAxisY::handleTickCountChanged(int tick)
diff --git a/src/charts/axis/valueaxis/qvalueaxis.cpp b/src/charts/axis/valueaxis/qvalueaxis.cpp
index 1d179e43..905168d7 100644
--- a/src/charts/axis/valueaxis/qvalueaxis.cpp
+++ b/src/charts/axis/valueaxis/qvalueaxis.cpp
@@ -533,6 +533,7 @@ void QValueAxisPrivate::initializeGraphics(QGraphicsItem *parent)
axis = new ChartValueAxisY(q,parent);
if (orientation() == Qt::Horizontal)
axis = new ChartValueAxisX(q,parent);
+ axis->setLabelsEditable(q->labelsEditable());
}
if (m_chart->chartType() == QChart::ChartTypePolar) {
diff --git a/src/charts/axis/valueaxis/valueaxislabel.cpp b/src/charts/axis/valueaxis/valueaxislabel.cpp
new file mode 100644
index 00000000..ecd1cb46
--- /dev/null
+++ b/src/charts/axis/valueaxis/valueaxislabel.cpp
@@ -0,0 +1,104 @@
+/****************************************************************************
+**
+** Copyright (C) 2018 The Qt Company Ltd.
+** Contact: https://www.qt.io/licensing/
+**
+** This file is part of the Qt Charts module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:GPL$
+** Commercial License Usage
+** Licensees holding valid commercial Qt licenses may use this file in
+** accordance with the commercial license agreement provided with the
+** Software or, alternatively, in accordance with the terms contained in
+** a written agreement between you and The Qt Company. For licensing terms
+** and conditions see https://www.qt.io/terms-conditions. For further
+** information use the contact form at https://www.qt.io/contact-us.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3 or (at your option) any later version
+** approved by the KDE Free Qt Foundation. The licenses are as published by
+** the Free Software Foundation and appearing in the file LICENSE.GPL3
+** included in the packaging of this file. Please review the following
+** information to ensure the GNU General Public License requirements will
+** be met: https://www.gnu.org/licenses/gpl-3.0.html.
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+#include <private/valueaxislabel_p.h>
+
+#include <QtCore/qlocale.h>
+
+QT_CHARTS_BEGIN_NAMESPACE
+
+ValueAxisLabel::ValueAxisLabel(QGraphicsItem *parent) :
+ EditableAxisLabel(parent)
+{
+
+}
+
+void ValueAxisLabel::finishEditing()
+{
+ bool ok = false;
+ QLocale locale;
+ qreal oldValue = m_value;
+ qreal newValue = locale.toDouble(document()->toPlainText(), &ok);
+ if (ok && newValue != m_value) {
+ m_value = newValue;
+ emit valueChanged(oldValue, newValue);
+ } else {
+ document()->setHtml(m_htmlBeforeEdit);
+ }
+}
+
+void ValueAxisLabel::resetBeforeEditValue()
+{
+ m_value = m_valueBeforeEdit;
+}
+
+qreal ValueAxisLabel::value() const
+{
+ return m_value;
+}
+
+void ValueAxisLabel::setValue(const qreal &value)
+{
+ setTextInteractionFlags(Qt::NoTextInteraction);
+ clearFocus();
+ m_value = value;
+}
+
+void ValueAxisLabel::setInitialEditValue()
+{
+ m_valueBeforeEdit = m_value;
+ setHtml(QString::number(m_value));
+}
+
+void ValueAxisLabel::keyPressEvent(QKeyEvent *event)
+{
+ if (isEditEndingKeyPress(event)) {
+ // prevent further event processing with a return
+ // because the focusOutEvent could have triggered
+ // a range change which might have invalidated the current label
+ return;
+ }
+
+ if (event->text().length() >= 1) {
+ QLocale locale;
+ if (!event->text().at(0).isDigit()
+ && event->text().at(0) != locale.decimalPoint()
+ && event->text().at(0) != locale.negativeSign()
+ && event->text().at(0) != locale.exponential()
+ && event->key() != Qt::Key_Backspace
+ && event->key() != Qt::Key_Delete) {
+ event->ignore();
+ return;
+ }
+ }
+ QGraphicsTextItem::keyPressEvent(event);
+}
+
+QT_CHARTS_END_NAMESPACE
+
+#include "moc_valueaxislabel_p.cpp"
diff --git a/src/charts/axis/valueaxis/valueaxislabel_p.h b/src/charts/axis/valueaxis/valueaxislabel_p.h
new file mode 100644
index 00000000..4fe3c1aa
--- /dev/null
+++ b/src/charts/axis/valueaxis/valueaxislabel_p.h
@@ -0,0 +1,71 @@
+/****************************************************************************
+**
+** Copyright (C) 2018 The Qt Company Ltd.
+** Contact: https://www.qt.io/licensing/
+**
+** This file is part of the Qt Charts module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:GPL$
+** Commercial License Usage
+** Licensees holding valid commercial Qt licenses may use this file in
+** accordance with the commercial license agreement provided with the
+** Software or, alternatively, in accordance with the terms contained in
+** a written agreement between you and The Qt Company. For licensing terms
+** and conditions see https://www.qt.io/terms-conditions. For further
+** information use the contact form at https://www.qt.io/contact-us.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3 or (at your option) any later version
+** approved by the KDE Free Qt Foundation. The licenses are as published by
+** the Free Software Foundation and appearing in the file LICENSE.GPL3
+** included in the packaging of this file. Please review the following
+** information to ensure the GNU General Public License requirements will
+** be met: https://www.gnu.org/licenses/gpl-3.0.html.
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+// W A R N I N G
+// -------------
+//
+// This file is not part of the Qt Chart API. It exists purely as an
+// implementation detail. This header file may change from version to
+// version without notice, or even be removed.
+//
+// We mean it.
+
+#ifndef VALUEAXISLABEL_H
+#define VALUEAXISLABEL_H
+
+#include <private/editableaxislabel_p.h>
+
+QT_CHARTS_BEGIN_NAMESPACE
+
+class QT_CHARTS_PRIVATE_EXPORT ValueAxisLabel : public EditableAxisLabel
+{
+ Q_OBJECT
+public:
+ ValueAxisLabel(QGraphicsItem *parent = nullptr);
+
+ void keyPressEvent(QKeyEvent *event);
+
+ qreal value() const;
+ void setValue(const qreal &value);
+
+private:
+ qreal m_value = 0.0;
+ qreal m_valueBeforeEdit = 0.0;
+
+ void setInitialEditValue() override;
+ void finishEditing() override;
+ void resetBeforeEditValue() override;
+
+Q_SIGNALS:
+ void valueChanged(qreal oldValue, qreal newValue);
+};
+
+QT_CHARTS_END_NAMESPACE
+
+#endif // VALUEAXISLABEL_H
diff --git a/src/charts/legend/qlegend.cpp b/src/charts/legend/qlegend.cpp
index 6cc9c7b6..6f5c2bb1 100644
--- a/src/charts/legend/qlegend.cpp
+++ b/src/charts/legend/qlegend.cpp
@@ -289,7 +289,8 @@ void QLegend::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, Q
painter->setOpacity(opacity());
painter->setPen(d_ptr->m_pen);
painter->setBrush(d_ptr->m_brush);
- painter->drawRoundRect(rect(), d_ptr->roundness(rect().width()), d_ptr->roundness(rect().height()));
+ painter->drawRoundedRect(rect(), d_ptr->roundness(rect().width()), d_ptr->roundness(rect().height()),
+ Qt::RelativeSize);
}
diff --git a/src/charts/piechart/qpieslice.cpp b/src/charts/piechart/qpieslice.cpp
index ca5ac413..f36f93a3 100644
--- a/src/charts/piechart/qpieslice.cpp
+++ b/src/charts/piechart/qpieslice.cpp
@@ -837,7 +837,5 @@ void QPieSlicePrivate::setAngleSpan(qreal span)
QT_CHARTS_END_NAMESPACE
-QT_CHARTS_USE_NAMESPACE
-
#include "moc_qpieslice.cpp"
#include "moc_qpieslice_p.cpp"
diff --git a/src/charts/scatterchart/qscatterseries.cpp b/src/charts/scatterchart/qscatterseries.cpp
index fe58fd9e..ee4ff411 100644
--- a/src/charts/scatterchart/qscatterseries.cpp
+++ b/src/charts/scatterchart/qscatterseries.cpp
@@ -100,6 +100,11 @@
*/
/*!
+ \qmlproperty brush ScatterSeries::brush
+ The brush used to draw the scatter series markers.
+*/
+
+/*!
\property QScatterSeries::color
\brief The color used to fill the series markers.
diff --git a/src/charts/xychart/qxyseries.cpp b/src/charts/xychart/qxyseries.cpp
index 039fe247..a290f6d4 100644
--- a/src/charts/xychart/qxyseries.cpp
+++ b/src/charts/xychart/qxyseries.cpp
@@ -1022,7 +1022,7 @@ void QXYSeriesPrivate::drawSeriesPointLabels(QPainter *painter, const QVector<QP
pointLabel.replace(yPointTag, presenter()->numberToString(m_points.at(i).y()));
// Position text in relation to the point
- int pointLabelWidth = fm.width(pointLabel);
+ int pointLabelWidth = fm.horizontalAdvance(pointLabel);
QPointF position(points.at(i));
position.setX(position.x() - pointLabelWidth / 2);
position.setY(position.y() - labelOffset);
diff --git a/src/chartsqml2/declarativecategoryaxis.cpp b/src/chartsqml2/declarativecategoryaxis.cpp
index bf6afa58..1b1826fd 100644
--- a/src/chartsqml2/declarativecategoryaxis.cpp
+++ b/src/chartsqml2/declarativecategoryaxis.cpp
@@ -30,6 +30,8 @@
#include "declarativecategoryaxis_p.h"
#include <QtCore/QDebug>
+#include <algorithm>
+
QT_CHARTS_BEGIN_NAMESPACE
/*!
@@ -83,7 +85,7 @@ void DeclarativeCategoryAxis::componentComplete()
}
// Sort and append the range objects according to end value
- qSort(ranges.begin(), ranges.end(), endValueLessThan);
+ std::sort(ranges.begin(), ranges.end(), endValueLessThan);
for (int i(0); i < ranges.count(); i++)
append(ranges.at(i).first, ranges.at(i).second);
}
diff --git a/src/chartsqml2/plugins.qmltypes b/src/chartsqml2/plugins.qmltypes
index 9acec4ce..139c191a 100644
--- a/src/chartsqml2/plugins.qmltypes
+++ b/src/chartsqml2/plugins.qmltypes
@@ -7,7 +7,7 @@ import QtQuick.tooling 1.2
// 'qmlplugindump -nonrelocatable -qapp QtCharts 2.3'
Module {
- dependencies: ["QtQuick 2.12"]
+ dependencies: ["QtQuick 2.0"]
Component {
name: "QGraphicsObject"
defaultProperty: "children"
@@ -1831,6 +1831,10 @@ Module {
name: "reverseChanged"
Parameter { name: "reverse"; type: "bool" }
}
+ Signal {
+ name: "labelsEditableChanged"
+ Parameter { name: "editable"; type: "bool" }
+ }
}
Component {
name: "QtCharts::QAbstractBarSeries"