Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
What's new
10
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Open sidebar
PIM
Itinerary
Commits
12350f78
Commit
12350f78
authored
Dec 25, 2018
by
Volker Krause
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add de/serialization of date/time values
Kinda important, now this actually works.
parent
7ee76e1c
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
26 additions
and
0 deletions
+26
-0
src/publictransport/datatypes/json.cpp
src/publictransport/datatypes/json.cpp
+26
-0
No files found.
src/publictransport/datatypes/json.cpp
View file @
12350f78
...
...
@@ -18,8 +18,10 @@
#include "json.h"
#include <QColor>
#include <QDateTime>
#include <QMetaObject>
#include <QMetaProperty>
#include <QTimeZone>
#include <QVariant>
using
namespace
KPublicTransport
;
...
...
@@ -37,6 +39,20 @@ static QJsonValue variantToJson(const QVariant &v)
return
v
.
toDouble
();
case
QMetaType
::
Int
:
return
v
.
toInt
();
case
QVariant
::
DateTime
:
{
const
auto
dt
=
v
.
toDateTime
();
if
(
!
dt
.
isValid
())
{
return
{};
}
if
(
dt
.
timeSpec
()
==
Qt
::
TimeZone
)
{
QJsonObject
dtObj
;
dtObj
.
insert
(
QLatin1String
(
"value"
),
dt
.
toString
(
Qt
::
ISODate
));
dtObj
.
insert
(
QLatin1String
(
"timezone"
),
QString
::
fromUtf8
(
dt
.
timeZone
().
id
()));
return
dtObj
;
}
return
v
.
toDateTime
().
toString
(
Qt
::
ISODate
);
}
}
if
(
v
.
userType
()
==
qMetaTypeId
<
QColor
>
())
{
...
...
@@ -76,6 +92,16 @@ static QVariant variantFromJson(const QJsonValue &v, int mt)
return
v
.
toDouble
();
case
QMetaType
::
Int
:
return
v
.
toInt
();
case
QVariant
::
DateTime
:
{
if
(
v
.
isObject
())
{
const
auto
dtObj
=
v
.
toObject
();
auto
dt
=
QDateTime
::
fromString
(
dtObj
.
value
(
QLatin1String
(
"value"
)).
toString
(),
Qt
::
ISODate
);
dt
.
setTimeZone
(
QTimeZone
(
dtObj
.
value
(
QLatin1String
(
"timezone"
)).
toString
().
toUtf8
()));
return
dt
;
}
return
QDateTime
::
fromString
(
v
.
toString
(),
Qt
::
ISODate
);
}
}
if
(
mt
==
qMetaTypeId
<
QColor
>
())
{
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment