-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfileOperations.cpp
More file actions
118 lines (114 loc) · 2.7 KB
/
fileOperations.cpp
File metadata and controls
118 lines (114 loc) · 2.7 KB
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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
#include "fileOperations.h"
#include <QDebug>
#include <QFile>
#include <QFileInfo>
#include <QDir>
#include <QQmlEngine>
FileOperations::FileOperations(QObject *parent) : QObject(parent)
{
}
QDir FileOperations::getDataDirectory()
{
//working 6.5 const QString qPath("/home/user1/dev/pub/qtWrite/data/" + glyphID + ".json");
//failed 6.5 const QString qPath("qrc:///qml/data/" + glyphID + ".json");
//failed 6.5 const QString qPath("data/" + glyphID + ".json");
//failed 6.5 const QString qPath("qrc://data/" + glyphID + ".json");
QDir dir = QDir::current();
if(dir.dirName() == "build")
{
if(!dir.cd("../data"))
{
qmlEngine(this)->throwError(tr("Bad path to ./build/../data"));
}
}
else
{
if(!dir.cd("data"))
{
qmlEngine(this)->throwError(tr("Bad path to ./data"));
}
}
return dir;
}
void FileOperations::printMessage(QString txt)
{
qDebug() << "Message from QML: " << txt;
}
void FileOperations::saveDataToFile(QString glyphID, QString dataToSave)
{
QDir dir = getDataDirectory();
QFile qFile(dir.absoluteFilePath(glyphID + ".json"));
if(qFile.open(QIODevice::WriteOnly))
{
QTextStream out(&qFile); out << dataToSave;
qFile.close();
}
}
void FileOperations::saveGlyphs(QString fileName, QString dataToSave)
{
QDir dir = getDataDirectory();
QFile qFile(dir.absoluteFilePath(fileName));
if(qFile.open(QIODevice::WriteOnly))
{
QTextStream out(&qFile); out << dataToSave;
qFile.close();
}
}
void FileOperations::saveSVG(QString dataToSave)
{
QDir dir = getDataDirectory();
QFile qFile(dir.absoluteFilePath("savedGlyph.svg"));
if(qFile.open(QIODevice::WriteOnly))
{
QTextStream out(&qFile); out << dataToSave;
qFile.close();
}
}
QString FileOperations::loadLetter(QString glyphID)
{
QDir dir = getDataDirectory();
QFile qFile(dir.absoluteFilePath(glyphID + ".json"));
if(qFile.exists())
{
if (!qFile.open(QIODevice::ReadOnly | QIODevice::Text))
{
return "{}";
}
else
{
QTextStream in(&qFile);
QString fileContents = in.readAll();
qFile.close();
return fileContents;
}
}
else
{
return "null";
}
}
QString FileOperations::loadHelpSVG()
{
QDir dir = getDataDirectory();
QFile qFile(dir.absoluteFilePath("helpDoc.svg"));
if(qFile.exists())
{
if (!qFile.open(QIODevice::ReadOnly | QIODevice::Text))
{
return "data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 400 200'><path fill='orange' stroke='royalblue' d='L 150 50 L 100 150 z' /></svg>";
}
else
{
QTextStream in(&qFile);
QString fileContents = in.readAll();
qFile.close();
return "data:image/svg+xml;utf8," + fileContents;
}
}
else
{
return "null";
}
}
//virtual FileOperations::~FileOperations() {};
//void FileOperations::~FileOperations() {};