Skip to content
Snippets Groups Projects

QDS-11394 DS templates are not working out of the box

Merged Burak Hançerli requested to merge QDS-11394/ds-templates-are-not-working into master
1 file
+ 90
4
Compare changes
  • Side-by-side
  • Inline
+ 90
4
@@ -163,7 +163,84 @@ QString DesignViewer::unpackProject(const QByteArray &project, bool extractZip)
projectLocation = ":" + resourcePath;
}
return projectLocation;
// create a temporary directory and copy the project there
QTemporaryDir tempDir;
tempDir.setAutoRemove(false);
if (!tempDir.isValid()) {
printErr("Could not create a temporary directory.");
return "";
}
const QString tempDirPath = tempDir.path();
printLog("Temporary directory: " + tempDirPath);
QDir tempDirDir(tempDirPath);
if (!tempDirDir.exists()) {
printErr("Temporary directory does not exist.");
return "";
}
if (!QDir(projectLocation).exists()) {
printErr("Project directory does not exist.");
return "";
}
// copy all files and directories from projectLocation to tempDirPath
QDirIterator it(projectLocation,
QDir::AllEntries | QDir::NoDotAndDotDot,
QDirIterator::Subdirectories);
printLog("Files in project location: " + projectLocation);
while (it.hasNext()) {
const QString filePath = it.next();
printLog("Found file: " + filePath);
const QFileInfo fileInfo(filePath);
const QString relativeFilePath = fileInfo.filePath().remove(projectLocation);
const QString newFilePath = tempDirPath + relativeFilePath;
printLog("Copying file: " + filePath + " to " + newFilePath);
if (fileInfo.isDir()) {
QDir().mkpath(newFilePath);
} else if (!QFile::copy(filePath, newFilePath)) {
printErr("Could not copy file: " + filePath + " to " + newFilePath);
return "";
}
}
// find all .qml files in the temporary directory and remove the Qt versions from 6.5 to 6.9
// at the end of the import statements. example "import <modulename> 6.5" -> "import <modulename>"
QDirIterator it2(tempDirPath, {"*.qml"}, QDir::Files, QDirIterator::Subdirectories);
printLog("Files in temporary directory: " + tempDirPath);
while (it2.hasNext()) {
const QString filePath = it2.next();
QFile file(filePath);
// set file permissions to read and write
file.setPermissions(QFile::ReadOwner | QFile::WriteOwner);
if (!file.open(QIODevice::ReadWrite)) {
printErr("Could not open file: " + filePath);
return "";
}
const QRegularExpression importRegExp("import\\s+\\S+\\s+6\\.[5-9]");
QString content = QString::fromUtf8(file.readAll());
while (content.contains(importRegExp)) {
const QRegularExpressionMatch match = importRegExp.match(content);
const QStringList textList = match.capturedTexts();
for (const QString &text : textList) {
const QString newText = QString(text).remove(QRegularExpression("\\s+6\\.[5-9]"));
printLog("Found text to replace: " + text + " with " + newText + " in file "
+ filePath);
content.replace(text, newText);
}
}
file.resize(0);
file.write(content.toUtf8());
file.close();
}
// return the temporary directory path
return tempDirPath;
}
QString DesignViewer::findFile(const QString &dir, const QString &filter)
@@ -246,6 +323,16 @@ bool DesignViewer::runProject(const QByteArray &projectData, const QString &proj
printLog("Original project name: " + projectName);
printLog("New project name: " + newProjectName);
// list all files in the project location
// QDirIterator it(projectLocation,
// QDir::AllEntries | QDir::NoDotAndDotDot,
// QDirIterator::Subdirectories);
// printLog("Files in project location: " + projectLocation);
// while (it.hasNext()) {
// const QString filePath = it.next();
// printLog("Found file: " + filePath);
// }
QString mainQmlFilePath;
QStringList importPaths;
@@ -277,9 +364,8 @@ bool DesignViewer::runProject(const QByteArray &projectData, const QString &proj
printLog("Found mainQmlFile: " + mainQmlFilePath);
QUrl mainQmlUrl = QUrl::fromUserInput(mainQmlFilePath);
QFile file(mainQmlUrl.path().prepend(":"));
if (!file.open(QIODevice::ReadOnly))
{
QFile file(mainQmlUrl.path());
if (!file.open(QIODevice::ReadOnly)) {
printErr("Could not open mainQmlfile for reading! " + file.fileName() + ": " + file.errorString());
return false;
}
Loading