-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcanvasstrokepoint.cpp
More file actions
37 lines (30 loc) · 994 Bytes
/
canvasstrokepoint.cpp
File metadata and controls
37 lines (30 loc) · 994 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
#include "canvasstrokepoint.h"
#include <QFile>
#include <QJsonDocument>
#include <QJsonArray>
#include <QJsonValue>
std::vector<CanvasStrokePoint> CanvasStrokePoint::pointsFromFile(const QString &filename)
{
QFile file(filename);
if (!file.open(QIODevice::ReadOnly))
return {};
QJsonDocument const jsonDoc = QJsonDocument::fromJson(file.readAll());
if (!jsonDoc.isArray())
return {};
return pointsFromJSON(jsonDoc.array());
}
std::vector<CanvasStrokePoint> CanvasStrokePoint::pointsFromJSON(const QJsonArray &json)
{
std::vector<CanvasStrokePoint> result;
result.reserve(json.size());
for (auto const &child: json)
{
QJsonArray pointArray = child.toArray();
float x = pointArray.at(0).toDouble(0.0);
float y = pointArray.at(1).toDouble(0.0);
float p = pointArray.at(2).toDouble(1.0);
float dt = pointArray.at(3).toDouble(15);
result.push_back({x, y, p, dt});
}
return result;
}