summaryrefslogtreecommitdiffstats
path: root/src/Authoring/Studio/Palettes/Project
diff options
context:
space:
mode:
authorMiikka Heikkinen <miikka.heikkinen@qt.io>2018-10-10 17:54:53 +0300
committerMiikka Heikkinen <miikka.heikkinen@qt.io>2018-10-12 08:56:33 +0000
commit19d87856c3dbea7c9d1e1ea17cf925e09a259e3e (patch)
tree31a197207cad8483426d7d7c05df7d8388407569 /src/Authoring/Studio/Palettes/Project
parentae21b21e95eb5a83f7f51939bb140daade02c129 (diff)
Make effect/material asset importing more robust
Refactored how effect and material assets are imported to remove code duplication and support also importing from another project rather than just from content library. Task-number: QT3DS-2476 Change-Id: I738e80d5df6a76a8ccc8834c2ce8308eac8f8512 Reviewed-by: Mahmoud Badri <mahmoud.badri@qt.io> Reviewed-by: Jere Tuliniemi <jere.tuliniemi@qt.io> Reviewed-by: Miikka Heikkinen <miikka.heikkinen@qt.io>
Diffstat (limited to 'src/Authoring/Studio/Palettes/Project')
-rw-r--r--src/Authoring/Studio/Palettes/Project/ProjectFileSystemModel.cpp71
1 files changed, 48 insertions, 23 deletions
diff --git a/src/Authoring/Studio/Palettes/Project/ProjectFileSystemModel.cpp b/src/Authoring/Studio/Palettes/Project/ProjectFileSystemModel.cpp
index 13fc58b3..ae2f5530 100644
--- a/src/Authoring/Studio/Palettes/Project/ProjectFileSystemModel.cpp
+++ b/src/Authoring/Studio/Palettes/Project/ProjectFileSystemModel.cpp
@@ -567,23 +567,42 @@ void ProjectFileSystemModel::importUrl(QDir &targetDir, const QUrl &url,
// For effect and custom material files, automatically copy related resources
if (CDialogs::IsEffectFileExtension(extension.toLatin1().data())
|| CDialogs::IsMaterialFileExtension(extension.toLatin1().data())) {
- std::vector<Q3DStudio::CString> effectFileSourcePaths;
- doc->GetDocumentReader().ParseSourcePathsOutOfEffectFile(
- Q3DStudio::CFilePath::GetAbsolutePath(CFilePath(sourceFile)),
- effectFileSourcePaths);
-
- const QDir fileDir = QFileInfo(sourceFile).dir();
- const QDir projectDir(g_StudioApp.GetCore()->getProjectFile().getProjectPath());
-
- for (const auto &effectFile : effectFileSourcePaths) {
- const QString sourcePath = fileDir.filePath(effectFile.toQString());
- const QString resultPath = projectDir.filePath(effectFile.toQString());
-
- const QFileInfo resultFileInfo(resultPath);
- if (!resultFileInfo.exists()) {
- resultFileInfo.dir().mkpath(".");
- QFile::copy(sourcePath, resultPath);
+ QHash<QString, QString> effectFileSourcePaths;
+ QString absSrcPath = fileInfo.absoluteFilePath();
+ QString projectPath
+ = QFileInfo(PresentationFile::findProjectFile(absSrcPath)).absolutePath();
+ g_StudioApp.GetCore()->GetDoc()->GetDocumentReader()
+ .ParseSourcePathsOutOfEffectFile(absSrcPath, effectFileSourcePaths, projectPath);
+
+ // TODO: Override choice needs to be unified across entire multi-import (QT3DS-2474)
+ // TODO: including all file types, not just effects and materials
+ // TODO: Also, there should not be override question if current multi-import
+ // TODO: copied the file in the first place, copying should just be auto-skipped.
+ int overrideChoice = QMessageBox::NoButton;
+ QHashIterator<QString, QString> pathIter(effectFileSourcePaths);
+ while (pathIter.hasNext()) {
+ pathIter.next();
+ const QString theSourcePath = pathIter.value();
+ const QString theResultPath
+ = QDir(g_StudioApp.GetCore()->getProjectFile().getProjectPath())
+ .absoluteFilePath(pathIter.key());
+ QFileInfo fi(theResultPath);
+ if (!fi.dir().exists())
+ fi.dir().mkpath(".");
+
+ if (fi.exists()) { // asset exists, show override / skip box
+ if (overrideChoice == QMessageBox::YesToAll) {
+ QFile::remove(theResultPath);
+ } else if (overrideChoice == QMessageBox::NoToAll) {
+ // QFile::copy() does not override files
+ } else {
+ overrideChoice = g_StudioApp.GetDialogs()
+ ->displayOverrideAssetBox(pathIter.key());
+ if (overrideChoice & (QMessageBox::Yes | QMessageBox::YesToAll))
+ QFile::remove(theResultPath);
+ }
}
+ QFile::copy(theSourcePath, theResultPath);
}
}
}
@@ -604,19 +623,26 @@ void ProjectFileSystemModel::importPresentationAssets(
const QFileInfo &uipSrc, const QFileInfo &uipTarget,
QHash<QString, QString> &outPresentationNodes, const int overrideChoice) const
{
- QList<QString> importSourcePaths;
+ QHash<QString, QString> importPathMap;
QString projPathSrc; // project absolute path for the source uip
- PresentationFile::getSourcePaths(uipSrc, uipTarget, importSourcePaths, projPathSrc,
+ PresentationFile::getSourcePaths(uipSrc, uipTarget, importPathMap, projPathSrc,
outPresentationNodes);
int overrideCh = overrideChoice;
- for (auto &path : qAsConst(importSourcePaths)) {
- QString srcAssetPath, targetAssetPath;
+
+ QHashIterator<QString, QString> pathIter(importPathMap);
+ while (pathIter.hasNext()) {
+ pathIter.next();
+ QString srcAssetPath = pathIter.value();
+ const QString path = pathIter.key();
+ QString targetAssetPath;
if (path.startsWith(QLatin1String("./"))) { // path from project root
- srcAssetPath = QDir(projPathSrc).absoluteFilePath(path);
+ if (srcAssetPath.isEmpty())
+ srcAssetPath = QDir(projPathSrc).absoluteFilePath(path);
targetAssetPath = QDir(g_StudioApp.GetCore()->getProjectFile().getProjectPath())
.absoluteFilePath(path);
} else { // relative path
- srcAssetPath = uipSrc.dir().absoluteFilePath(path);
+ if (srcAssetPath.isEmpty())
+ srcAssetPath = uipSrc.dir().absoluteFilePath(path);
targetAssetPath = uipTarget.dir().absoluteFilePath(path);
}
@@ -634,7 +660,6 @@ void ProjectFileSystemModel::importPresentationAssets(
QString pathFromRoot = QDir(g_StudioApp.GetCore()->getProjectFile()
.getProjectPath())
.relativeFilePath(targetAssetPath);
-
overrideCh = g_StudioApp.GetDialogs()->displayOverrideAssetBox(pathFromRoot);
if (overrideCh & (QMessageBox::Yes | QMessageBox::YesToAll))
QFile::remove(targetAssetPath);