summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorOwais Akhtar <[email protected]>2025-05-08 08:32:59 +0300
committerOwais Akhtar <[email protected]>2025-06-05 10:30:03 +0000
commit82428c0f79de0c2307641ad35acf8e849fd08a7c (patch)
treec88d104c4cc910230b553f3baa674ced81936a30 /src
parent4c03576ce10b3a60be4486e117694c6bf6ac96bc (diff)
Add option to set timezone for QDateTimeAxisHEADdev
Fixes: QTBUG-128220 Change-Id: Ib360fa08d66aa58f044ecbe7dab10d5cc00e25c9 Reviewed-by: Sami Varanka <[email protected]>
Diffstat (limited to 'src')
-rw-r--r--src/graphs2d/axis/datetimeaxis/qdatetimeaxis.cpp55
-rw-r--r--src/graphs2d/axis/datetimeaxis/qdatetimeaxis.h6
-rw-r--r--src/graphs2d/axis/datetimeaxis/qdatetimeaxis_p.h1
3 files changed, 57 insertions, 5 deletions
diff --git a/src/graphs2d/axis/datetimeaxis/qdatetimeaxis.cpp b/src/graphs2d/axis/datetimeaxis/qdatetimeaxis.cpp
index 36f485f7..d2add223 100644
--- a/src/graphs2d/axis/datetimeaxis/qdatetimeaxis.cpp
+++ b/src/graphs2d/axis/datetimeaxis/qdatetimeaxis.cpp
@@ -96,6 +96,18 @@ QT_BEGIN_NAMESPACE
The default value is 0, which means that intervals are automatically calculated
based on the min and max range.
*/
+/*!
+ \property QDateTimeAxis::timeZone
+ \brief The time zone that will be used to display labels of the axis.
+ The accepted values are based on IANA time zone IDs. The default time zone is UTC.
+ \since 6.10
+*/
+/*!
+ \qmlproperty string DateTimeAxis::timeZone
+ The time zone that will be used to display labels of the axis.
+ The accepted values are based on IANA time zone IDs. The default time zone is UTC.
+ \since 6.10
+*/
/*!
\property QDateTimeAxis::labelFormat
@@ -137,14 +149,18 @@ QT_BEGIN_NAMESPACE
This signal is emitted when the tick interval value, specified by
\a tickInterval, changes.
*/
+/*!
+ \qmlsignal DateTimeAxis::timeZoneChanged()
+ This signal is emitted when the time zone is changed. It represents a string value for the
+ IANA time zone ID that was set.
+ \since 6.10
+*/
QDateTimeAxis::QDateTimeAxis(QObject *parent)
: QAbstractAxis(*(new QDateTimeAxisPrivate), parent)
{}
-QDateTimeAxis::~QDateTimeAxis()
-{
-}
+QDateTimeAxis::~QDateTimeAxis() {}
QAbstractAxis::AxisType QDateTimeAxis::type() const
{
@@ -163,7 +179,7 @@ void QDateTimeAxis::setMin(const QDateTime &min)
QDateTime QDateTimeAxis::min() const
{
Q_D(const QDateTimeAxis);
- return QDateTime::fromMSecsSinceEpoch(d->m_min, QTimeZone::UTC);
+ return QDateTime::fromMSecsSinceEpoch(d->m_min, d->m_timeZone);
}
void QDateTimeAxis::setMax(const QDateTime &max)
@@ -178,7 +194,7 @@ void QDateTimeAxis::setMax(const QDateTime &max)
QDateTime QDateTimeAxis::max() const
{
Q_D(const QDateTimeAxis);
- return QDateTime::fromMSecsSinceEpoch(d->m_max, QTimeZone::UTC);
+ return QDateTime::fromMSecsSinceEpoch(d->m_max, d->m_timeZone);
}
void QDateTimeAxis::setLabelFormat(const QString &format)
@@ -237,6 +253,35 @@ void QDateTimeAxis::setSubTickCount(int newSubTickCount)
emit update();
}
+QString QDateTimeAxis::timeZone() const
+{
+#if QT_CONFIG(timezone)
+ Q_D(const QDateTimeAxis);
+
+ return QString::fromUtf8(d->m_timeZone.id());
+#else
+ return QString::fromUtf8("UTC");
+#endif
+}
+
+void QDateTimeAxis::setTimeZone(const QString &zoneId)
+{
+ Q_D(QDateTimeAxis);
+
+#if QT_CONFIG(timezone)
+ auto zone = QTimeZone(zoneId.toUtf8());
+#else
+ auto zone = QTimeZone(QTimeZone::Initialization::UTC);
+#endif
+
+ if (!zone.isValid())
+ return;
+
+ d->m_timeZone = zone;
+ emit timeZoneChanged(zoneId);
+ emit update();
+}
+
///////////////////////////////////////////////////////////////////////////////
QDateTimeAxisPrivate::QDateTimeAxisPrivate() {}
diff --git a/src/graphs2d/axis/datetimeaxis/qdatetimeaxis.h b/src/graphs2d/axis/datetimeaxis/qdatetimeaxis.h
index b4abffb9..2d8dadab 100644
--- a/src/graphs2d/axis/datetimeaxis/qdatetimeaxis.h
+++ b/src/graphs2d/axis/datetimeaxis/qdatetimeaxis.h
@@ -21,6 +21,8 @@ class Q_GRAPHS_EXPORT QDateTimeAxis : public QAbstractAxis
int subTickCount READ subTickCount WRITE setSubTickCount NOTIFY subTickCountChanged FINAL)
Q_PROPERTY(
qreal tickInterval READ tickInterval WRITE setTickInterval NOTIFY tickIntervalChanged FINAL)
+ Q_PROPERTY(
+ QString timeZone READ timeZone WRITE setTimeZone NOTIFY timeZoneChanged REVISION(6, 10))
QML_NAMED_ELEMENT(DateTimeAxis)
public:
@@ -48,12 +50,16 @@ public:
int subTickCount() const;
void setSubTickCount(int newSubTickCount);
+ Q_REVISION(6, 10) QString timeZone() const;
+ Q_REVISION(6, 10) void setTimeZone(const QString &zoneId);
+
Q_SIGNALS:
void minChanged(const QDateTime &min);
void maxChanged(const QDateTime &max);
void labelFormatChanged(const QString &format);
void tickIntervalChanged();
void subTickCountChanged();
+ Q_REVISION(6, 10) void timeZoneChanged(const QString &timeZone);
private:
Q_DECLARE_PRIVATE(QDateTimeAxis)
diff --git a/src/graphs2d/axis/datetimeaxis/qdatetimeaxis_p.h b/src/graphs2d/axis/datetimeaxis/qdatetimeaxis_p.h
index cbd31dc6..0421b415 100644
--- a/src/graphs2d/axis/datetimeaxis/qdatetimeaxis_p.h
+++ b/src/graphs2d/axis/datetimeaxis/qdatetimeaxis_p.h
@@ -27,6 +27,7 @@ public:
protected:
qreal m_min = QDateTime::fromMSecsSinceEpoch(0, QTimeZone::UTC).toMSecsSinceEpoch();
qreal m_max = QDateTime::fromMSecsSinceEpoch(0, QTimeZone::UTC).addYears(10).toMSecsSinceEpoch();
+ QTimeZone m_timeZone = QTimeZone::UTC;
qreal m_tickInterval = 0.0;
qsizetype m_subTickCount = 0;
QString m_format = QStringLiteral("dd-MMMM-yy");