-
Notifications
You must be signed in to change notification settings - Fork 9
Expand file tree
/
Copy pathappcore.cpp
More file actions
75 lines (56 loc) · 1.65 KB
/
appcore.cpp
File metadata and controls
75 lines (56 loc) · 1.65 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
#include "appcore.h"
#include <QDebug>
AppCore::AppCore(QObject *parent) : QObject(parent)
{
_parser = new SVGParser(this);
_qmlGenerator = new QMLGenerator(this);
}
QUrl AppCore::generatedQMLPath() const
{
return _generatedQMLPath;
}
/**
* @brief Парсим SVG
* @param source
* @return
*/
bool AppCore::parse(QUrl source)
{
if ( source.isEmpty() ) { return false; }
QFile file(source.toLocalFile());
if ( !file.open(QIODevice::ReadOnly) ) { qWarning()<<"Unable open file"; return false; }
qInfo()<<"Begin parse SVG"<<source.toLocalFile();
SVGParser::ParseStatus st = _parser->parse(&file);
if ( st!=SVGParser::PS_OK ) { qWarning()<<"Unable parse SVG file"; return false; }
qInfo()<<"SVG Parsed!";
return true;
}
/**
* @brief Создаём QML
* @param dest
* @return
*/
bool AppCore::generate(QUrl dest)
{
if ( dest.isEmpty() ) { return false; }
qInfo()<<"Begin create QML"<<dest.toLocalFile();
QFile fileQml(dest.toLocalFile());
if ( !fileQml.open(QIODevice::WriteOnly|QIODevice::Text) ) { qWarning()<<"Unable open file"; return false; }
SVGGenerator::GenerateStatus st = _qmlGenerator->generateQML(&fileQml, _parser->rootItem(), _parser->defs());
if ( st!=SVGGenerator::GS_OK ) { qWarning()<<"Unable generate QML"; return false; }
qInfo()<<"QML Created!";
_generatedQMLPath = dest;
emit generateQMLPathChanged();
return true;
}
/**
* @brief Парсим SVG и создём из него QML
* @param source
* @param dest
*/
bool AppCore::svg2qml(QUrl source, QUrl dest)
{
if ( !parse(source) ) { return false; }
if ( !generate(dest) ) { return false; }
return true;
}