CQtDeployer/UnitTests/qmlcreator.cpp

65 lines
1.4 KiB
C++
Raw Normal View History

2019-09-23 18:37:17 +03:00
/*
2019-12-08 13:57:20 +03:00
* Copyright (C) 2018-2020 QuasarApp.
2019-09-23 18:37:17 +03:00
* Distributed under the lgplv3 software license, see the accompanying
* Everyone is permitted to copy and distribute verbatim copies
* of this license document, but changing it is not allowed.
*/
2019-03-26 22:12:20 +03:00
#include "qmlcreator.h"
#include <QFile>
#include <QFileInfo>
QMap<QString, QStringList> QmlCreator::getQmlImports() const {
return qmlImports;
}
QStringList QmlCreator::getCopyedQml() const {
return copyedQml;
}
void QmlCreator::createQml(const QString &qmlFile, const QStringList &imports) {
QFile qml(qmlFile);
if (qml.open(QIODevice::ReadOnly)) {
QFile target(path + "/" + QFileInfo(qmlFile).fileName());
if (target.open(QIODevice::ReadWrite)) {
auto data = qml.readAll();
target.write(data.data(), data.size());
target.close();
copyedQml.push_back(target.fileName());
qmlImports.insert(target.fileName(), imports);
}
qml.close();
}
}
void QmlCreator::initQml() {
createQml(":/qmlFile.qml", {
2019-03-28 16:11:13 +03:00
"2#QtQuick",
"2#QtQuick/Controls/Material",
"2#QtQuick/Controls",
"1#QtQuick/Layouts"
2019-03-26 22:12:20 +03:00
});
}
QmlCreator::QmlCreator(const QString &path) {
this->path = path;
initQml();
}
QmlCreator::~QmlCreator() {
2020-01-12 16:43:03 +03:00
for(auto &lib : copyedQml) {
2019-03-26 22:12:20 +03:00
QFile::remove(lib);
}
}