-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathutils.cpp
69 lines (61 loc) · 2.08 KB
/
utils.cpp
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
#include "utils.h"
#include <QFile>
#include <QFileInfo>
#include <QDebug>
#include "note.h"
#include <QtXml>
namespace Utils {
void checkBookmarksFile(QFile* f){
QFileInfo fi(*f);
if (!fi.exists()) {
if (!f->open(QIODevice::WriteOnly)) {
qDebug() << "Unable to open the XML file for writing";
}
QTextStream stream(f);
stream << "<root>\n <bookmarks>\n </bookmarks>\n <notes>\n </notes>\n</root>" << endl;
f->close();
}
}
QString bookmarksFileName(QString filename) {
return filename.replace(QRegExp("\\.pdf$"), QString("")) + QString(".pdq");
}
void writeDocToFile(QDomDocument &doc, QFile *f) {
if (!f->open(QIODevice::WriteOnly | QIODevice::Truncate)) {
qDebug() << "Unable to open the XML file for writing";
}
QTextStream stream(f);
stream << doc.toString() << endl;
f->close();
}
void readDocFromFile(QDomDocument &doc, QFile *f) {
if (!f->open(QIODevice::ReadOnly) || !doc.setContent(f)) {
qDebug() << "Unable to open the XML file for reading";
}
f->close();
}
QList<Note>* getNotesFromDoc(QDomDocument &doc) {
QDomNodeList notes = doc.elementsByTagName("note");
QList<Note>* a = new QList<Note>();
for (int i=0; i< notes.size(); i++) {
QDomNode nt = notes.item(i);
QDomNamedNodeMap attrs = nt.attributes();
QString xstr(attrs.namedItem(QString("x")).nodeValue());
QString ystr(attrs.namedItem(QString("y")).nodeValue());
qreal xr = xstr.toFloat();
qreal yr = ystr.toFloat();
//qDebug() << xstr << xr ;
//qDebug() << ystr << yr ;
a->append(Note(
attrs.namedItem(QString("page")).nodeValue().toInt(),
xr,
yr,
attrs.namedItem(QString("r")).nodeValue().toInt(),
attrs.namedItem(QString("g")).nodeValue().toInt(),
attrs.namedItem(QString("b")).nodeValue().toInt(),
nt.firstChild().toText().data()
)
);
}
return a;
}
}