aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMahmoud Badri <mahmoud.badri@qt.io>2024-04-29 11:25:21 +0300
committerMahmoud Badri <mahmoud.badri@qt.io>2024-04-29 12:10:40 +0000
commitc9c3303ad889b011460cb0d5a7a0cb5ccc290789 (patch)
treef6e8c437a9f26ce705a7f9c5fbfbe7f9f012f75d
parent6bd4daa53f6c3cd7772107fe97487c54ccf49f5a (diff)
QmlDesigner: Refactor bundle importer
so that it can be shared by more than 1 bundle. Also some relevant tweaks. Change-Id: I421648c26ac4a0d51612f21a5475f0938dfff331 Reviewed-by: Miikka Heikkinen <miikka.heikkinen@qt.io> Reviewed-by: Qt CI Patch Build Bot <ci_patchbuild_bot@qt.io>
-rw-r--r--share/qtcreator/qmldesigner/contentLibraryQmlSource/ContentLibraryMaterial.qml2
-rw-r--r--src/plugins/qmldesigner/components/contentlibrary/contentlibrarybundleimporter.cpp122
-rw-r--r--src/plugins/qmldesigner/components/contentlibrary/contentlibrarybundleimporter.h26
-rw-r--r--src/plugins/qmldesigner/components/contentlibrary/contentlibraryeffect.cpp2
-rw-r--r--src/plugins/qmldesigner/components/contentlibrary/contentlibraryeffect.h1
-rw-r--r--src/plugins/qmldesigner/components/contentlibrary/contentlibraryeffectsmodel.cpp18
-rw-r--r--src/plugins/qmldesigner/components/contentlibrary/contentlibraryeffectsmodel.h9
-rw-r--r--src/plugins/qmldesigner/components/contentlibrary/contentlibrarymaterial.cpp2
-rw-r--r--src/plugins/qmldesigner/components/contentlibrary/contentlibrarymaterial.h4
-rw-r--r--src/plugins/qmldesigner/components/contentlibrary/contentlibrarymaterialsmodel.cpp33
-rw-r--r--src/plugins/qmldesigner/components/contentlibrary/contentlibrarymaterialsmodel.h5
-rw-r--r--src/plugins/qmldesigner/components/contentlibrary/contentlibraryusermodel.cpp17
-rw-r--r--src/plugins/qmldesigner/components/contentlibrary/contentlibraryusermodel.h3
-rw-r--r--src/plugins/qmldesigner/components/contentlibrary/contentlibraryview.cpp8
14 files changed, 102 insertions, 150 deletions
diff --git a/share/qtcreator/qmldesigner/contentLibraryQmlSource/ContentLibraryMaterial.qml b/share/qtcreator/qmldesigner/contentLibraryQmlSource/ContentLibraryMaterial.qml
index 0e9fc4903eb..775e5811936 100644
--- a/share/qtcreator/qmldesigner/contentLibraryQmlSource/ContentLibraryMaterial.qml
+++ b/share/qtcreator/qmldesigner/contentLibraryQmlSource/ContentLibraryMaterial.qml
@@ -186,7 +186,7 @@ Item {
baseUrl: modelData.bundleMaterialBaseWebUrl
files: modelData.bundleMaterialFiles
- targetDirPath: modelData.bundleMaterialParentPath
+ targetDirPath: modelData.bundleMaterialDirPath
onDownloadStarting: {
root.downloadState = "downloading"
diff --git a/src/plugins/qmldesigner/components/contentlibrary/contentlibrarybundleimporter.cpp b/src/plugins/qmldesigner/components/contentlibrary/contentlibrarybundleimporter.cpp
index 5c8d42a3065..85d42f9d128 100644
--- a/src/plugins/qmldesigner/components/contentlibrary/contentlibrarybundleimporter.cpp
+++ b/src/plugins/qmldesigner/components/contentlibrary/contentlibrarybundleimporter.cpp
@@ -12,7 +12,6 @@
#include <qmljs/qmljsmodelmanagerinterface.h>
-#include <QFileInfo>
#include <QJsonDocument>
#include <QJsonObject>
#include <QStringList>
@@ -21,14 +20,8 @@ using namespace Utils;
namespace QmlDesigner::Internal {
-ContentLibraryBundleImporter::ContentLibraryBundleImporter(const QString &bundleDir,
- const QString &bundleId,
- const QStringList &sharedFiles,
- QObject *parent)
+ContentLibraryBundleImporter::ContentLibraryBundleImporter(QObject *parent)
: QObject(parent)
- , m_bundleDir(FilePath::fromString(bundleDir))
- , m_bundleId(bundleId)
- , m_sharedFiles(sharedFiles)
{
m_importTimer.setInterval(200);
connect(&m_importTimer, &QTimer::timeout, this, &ContentLibraryBundleImporter::handleImportTimer);
@@ -38,47 +31,38 @@ ContentLibraryBundleImporter::ContentLibraryBundleImporter(const QString &bundle
// Note that there is also an asynchronous portion to the import, which will only
// be done if this method returns success. Once the asynchronous portion of the
// import is completed, importFinished signal will be emitted.
-QString ContentLibraryBundleImporter::importComponent(const QString &qmlFile,
+QString ContentLibraryBundleImporter::importComponent(const QString &bundleDir,
+ const TypeName &type,
+ const QString &qmlFile,
const QStringList &files)
{
- FilePath bundleImportPath = resolveBundleImportPath();
+ QString module = QString::fromLatin1(type.left(type.lastIndexOf('.')));
+ QString bundleId = module.mid(module.lastIndexOf('.') + 1);
+
+ FilePath bundleDirPath = FilePath::fromString(bundleDir); // source dir
+ FilePath bundleImportPath = resolveBundleImportPath(bundleId); // target dir
+
if (bundleImportPath.isEmpty())
return "Failed to resolve bundle import folder";
- bool bundleImportPathExists = bundleImportPath.exists();
-
- if (!bundleImportPathExists && !bundleImportPath.createDir())
+ if (!bundleImportPath.exists() && !bundleImportPath.createDir())
return QStringLiteral("Failed to create bundle import folder: '%1'").arg(bundleImportPath.toString());
- for (const QString &file : std::as_const(m_sharedFiles)) {
- FilePath target = bundleImportPath.resolvePath(file);
- if (!target.exists()) {
- FilePath parentDir = target.parentDir();
- if (!parentDir.exists() && !parentDir.createDir())
- return QStringLiteral("Failed to create folder for: '%1'").arg(target.toString());
- FilePath source = m_bundleDir.resolvePath(file);
- if (!source.copyFile(target))
- return QStringLiteral("Failed to copy shared file: '%1'").arg(source.toString());
- }
- }
-
- FilePath qmldirPath = bundleImportPath.resolvePath(QStringLiteral("qmldir"));
+ FilePath qmldirPath = bundleImportPath.pathAppended("qmldir");
QString qmldirContent = QString::fromUtf8(qmldirPath.fileContents().value_or(QByteArray()));
if (qmldirContent.isEmpty()) {
qmldirContent.append("module ");
- qmldirContent.append(moduleName());
+ qmldirContent.append(module);
qmldirContent.append('\n');
}
- FilePath qmlSourceFile = bundleImportPath.resolvePath(FilePath::fromString(qmlFile));
+ FilePath qmlSourceFile = bundleImportPath.pathAppended(qmlFile);
const bool qmlFileExists = qmlSourceFile.exists();
const QString qmlType = qmlSourceFile.baseName();
- const QString fullTypeName = QStringLiteral("%1.%2.%3")
- .arg(QmlDesignerPlugin::instance()->documentManager()
- .generatedComponentUtils().componentBundlesTypePrefix(),
- m_bundleId, qmlType);
- if (m_pendingTypes.contains(fullTypeName) && !m_pendingTypes[fullTypeName])
- return QStringLiteral("Unable to import while unimporting the same type: '%1'").arg(fullTypeName);
+
+ if (m_pendingTypes.contains(type) && !m_pendingTypes.value(type))
+ return QStringLiteral("Unable to import while unimporting the same type: '%1'").arg(QLatin1String(type));
+
if (!qmldirContent.contains(qmlFile)) {
qmldirContent.append(qmlType);
qmldirContent.append(" 1.0 ");
@@ -91,12 +75,12 @@ QString ContentLibraryBundleImporter::importComponent(const QString &qmlFile,
allFiles.append(files);
allFiles.append(qmlFile);
for (const QString &file : std::as_const(allFiles)) {
- FilePath target = bundleImportPath.resolvePath(file);
+ FilePath target = bundleImportPath.pathAppended(file);
FilePath parentDir = target.parentDir();
if (!parentDir.exists() && !parentDir.createDir())
return QStringLiteral("Failed to create folder for: '%1'").arg(target.toString());
- FilePath source = m_bundleDir.resolvePath(file);
+ FilePath source = bundleDirPath.pathAppended(file);
if (target.exists()) {
if (source.lastModified() == target.lastModified())
continue;
@@ -125,23 +109,23 @@ QString ContentLibraryBundleImporter::importComponent(const QString &qmlFile,
if (!model)
return "Model not available, cannot add import statement or update code model";
- Import import = Import::createLibraryImport(moduleName(), "1.0");
+ Import import = Import::createLibraryImport(module, "1.0");
if (!model->hasImport(import)) {
if (model->possibleImports().contains(import)) {
- m_importAddPending = false;
+ m_pendingImport.clear();
try {
model->changeImports({import}, {});
} catch (const RewritingException &) {
// No point in trying to add import asynchronously either, so just fail out
- return QStringLiteral("Failed to add import statement for: '%1'").arg(moduleName());
+ return QStringLiteral("Failed to add import statement for: '%1'").arg(module);
}
} else {
// If import is not yet possible, import statement needs to be added asynchronously to
// avoid errors, as code model update takes a while.
- m_importAddPending = true;
+ m_pendingImport = module;
}
}
- m_pendingTypes.insert(fullTypeName, true);
+ m_pendingTypes.insert(type, true);
m_importTimerCount = 0;
m_importTimer.start();
@@ -153,14 +137,14 @@ void ContentLibraryBundleImporter::handleImportTimer()
auto handleFailure = [this] {
m_importTimer.stop();
m_fullReset = false;
- m_importAddPending = false;
+ m_pendingImport.clear();
m_importTimerCount = 0;
// Emit dummy finished signals for all pending types
- const QStringList pendingTypes = m_pendingTypes.keys();
- for (const QString &pendingType : pendingTypes) {
+ const QList<TypeName> pendingTypes = m_pendingTypes.keys();
+ for (const TypeName &pendingType : pendingTypes) {
m_pendingTypes.remove(pendingType);
- if (m_pendingTypes[pendingType])
+ if (m_pendingTypes.value(pendingType))
emit importFinished({});
else
emit unimportFinished({});
@@ -185,12 +169,12 @@ void ContentLibraryBundleImporter::handleImportTimer()
QmlDesignerPlugin::instance()->documentManager().resetPossibleImports();
- if (m_importAddPending) {
+ if (!m_pendingImport.isEmpty()) {
try {
- Import import = Import::createLibraryImport(moduleName(), "1.0");
+ Import import = Import::createLibraryImport(m_pendingImport, "1.0");
if (model->possibleImports().contains(import)) {
model->changeImports({import}, {});
- m_importAddPending = false;
+ m_pendingImport.clear();
}
} catch (const RewritingException &) {
// Import adding is unlikely to succeed later, either, so just bail out
@@ -200,16 +184,16 @@ void ContentLibraryBundleImporter::handleImportTimer()
}
// Detect when the code model has the new material(s) fully available
- const QStringList pendingTypes = m_pendingTypes.keys();
- for (const QString &pendingType : pendingTypes) {
- NodeMetaInfo metaInfo = model->metaInfo(pendingType.toUtf8());
- const bool isImport = m_pendingTypes[pendingType];
+ const QList<TypeName> pendingTypes = m_pendingTypes.keys();
+ for (const TypeName &pendingType : pendingTypes) {
+ NodeMetaInfo metaInfo = model->metaInfo(pendingType);
+ const bool isImport = m_pendingTypes.value(pendingType);
const bool typeComplete = metaInfo.isValid() && !metaInfo.prototypes().empty();
if (isImport == typeComplete) {
m_pendingTypes.remove(pendingType);
if (isImport)
#ifdef QDS_USE_PROJECTSTORAGE
- emit importFinished(pendingType.toUtf8());
+ emit importFinished(pendingType);
#else
emit importFinished(metaInfo);
#endif
@@ -252,16 +236,12 @@ void ContentLibraryBundleImporter::writeAssetRefMap(const Utils::FilePath &bundl
}
}
-QString ContentLibraryBundleImporter::moduleName()
+QString ContentLibraryBundleImporter::unimportComponent(const TypeName &type, const QString &qmlFile)
{
- return QStringLiteral("%1.%2").arg(QmlDesignerPlugin::instance()->documentManager()
- .generatedComponentUtils().componentBundlesTypePrefix(),
- m_bundleId);
-}
+ QString module = QString::fromLatin1(type.left(type.lastIndexOf('.')));
+ QString bundleId = module.mid(module.lastIndexOf('.') + 1);
-QString ContentLibraryBundleImporter::unimportComponent(const QString &qmlFile)
-{
- FilePath bundleImportPath = resolveBundleImportPath();
+ FilePath bundleImportPath = resolveBundleImportPath(bundleId);
if (bundleImportPath.isEmpty())
return QStringLiteral("Failed to resolve bundle import folder for: '%1'").arg(qmlFile);
@@ -280,12 +260,10 @@ QString ContentLibraryBundleImporter::unimportComponent(const QString &qmlFile)
QByteArray newContent;
QString qmlType = qmlFilePath.baseName();
- const QString fullTypeName = QStringLiteral("%1.%2.%3")
- .arg(QmlDesignerPlugin::instance()->documentManager()
- .generatedComponentUtils().componentBundlesTypePrefix(),
- m_bundleId, qmlType);
- if (m_pendingTypes.contains(fullTypeName) && m_pendingTypes[fullTypeName])
- return QStringLiteral("Unable to unimport while importing the same type: '%1'").arg(fullTypeName);
+ if (m_pendingTypes.contains(type) && m_pendingTypes.value(type)) {
+ return QStringLiteral("Unable to unimport while importing the same type: '%1'")
+ .arg(QString::fromLatin1(type));
+ }
if (qmldirContent) {
int typeIndex = qmldirContent->indexOf(qmlType.toUtf8());
@@ -301,7 +279,7 @@ QString ContentLibraryBundleImporter::unimportComponent(const QString &qmlFile)
}
}
- m_pendingTypes.insert(fullTypeName, false);
+ m_pendingTypes.insert(type, false);
QVariantHash assetRefMap = loadAssetRefMap(bundleImportPath);
bool writeAssetRefs = false;
@@ -335,7 +313,7 @@ QString ContentLibraryBundleImporter::unimportComponent(const QString &qmlFile)
auto doc = QmlDesignerPlugin::instance()->currentDesignDocument();
Model *model = doc ? doc->currentModel() : nullptr;
if (model) {
- Import import = Import::createLibraryImport(moduleName(), "1.0");
+ Import import = Import::createLibraryImport(module, "1.0");
if (model->imports().contains(import))
model->changeImports({}, {import});
}
@@ -348,14 +326,14 @@ QString ContentLibraryBundleImporter::unimportComponent(const QString &qmlFile)
return {};
}
-FilePath ContentLibraryBundleImporter::resolveBundleImportPath()
+FilePath ContentLibraryBundleImporter::resolveBundleImportPath(const QString &bundleId)
{
FilePath bundleImportPath = QmlDesignerPlugin::instance()->documentManager()
.generatedComponentUtils().componentBundlesBasePath();
if (bundleImportPath.isEmpty())
- return bundleImportPath;
+ return {};
- return bundleImportPath.resolvePath(m_bundleId);
+ return bundleImportPath.resolvePath(bundleId);
}
} // namespace QmlDesigner::Internal
diff --git a/src/plugins/qmldesigner/components/contentlibrary/contentlibrarybundleimporter.h b/src/plugins/qmldesigner/components/contentlibrary/contentlibrarybundleimporter.h
index 7fb2a48886d..3a7c22a52e1 100644
--- a/src/plugins/qmldesigner/components/contentlibrary/contentlibrarybundleimporter.h
+++ b/src/plugins/qmldesigner/components/contentlibrary/contentlibrarybundleimporter.h
@@ -3,16 +3,13 @@
#pragma once
-#include <utils/filepath.h>
+#include <nodemetainfo.h>
-#include "nodemetainfo.h"
+#include <utils/filepath.h>
#include <QTimer>
#include <QVariantHash>
-QT_BEGIN_NAMESPACE
-QT_END_NAMESPACE
-
namespace QmlDesigner::Internal {
class ContentLibraryBundleImporter : public QObject
@@ -20,16 +17,13 @@ class ContentLibraryBundleImporter : public QObject
Q_OBJECT
public:
- ContentLibraryBundleImporter(const QString &bundleDir,
- const QString &bundleId,
- const QStringList &sharedFiles,
- QObject *parent = nullptr);
+ ContentLibraryBundleImporter(QObject *parent = nullptr);
~ContentLibraryBundleImporter() = default;
- QString importComponent(const QString &qmlFile,
+ QString importComponent(const QString &bundleDir, const TypeName &type, const QString &qmlFile,
const QStringList &files);
- QString unimportComponent(const QString &qmlFile);
- Utils::FilePath resolveBundleImportPath();
+ QString unimportComponent(const TypeName &type, const QString &qmlFile);
+ Utils::FilePath resolveBundleImportPath(const QString &bundleId);
signals:
// The metaInfo parameter will be invalid if an error was encountered during
@@ -46,16 +40,12 @@ private:
void handleImportTimer();
QVariantHash loadAssetRefMap(const Utils::FilePath &bundlePath);
void writeAssetRefMap(const Utils::FilePath &bundlePath, const QVariantHash &assetRefMap);
- QString moduleName();
- Utils::FilePath m_bundleDir;
- QString m_bundleId;
- QStringList m_sharedFiles;
QTimer m_importTimer;
int m_importTimerCount = 0;
- bool m_importAddPending = false;
+ QString m_pendingImport;
bool m_fullReset = false;
- QHash<QString, bool> m_pendingTypes; // <type, isImport>
+ QHash<TypeName, bool> m_pendingTypes; // <type, isImport>
};
} // namespace QmlDesigner::Internal
diff --git a/src/plugins/qmldesigner/components/contentlibrary/contentlibraryeffect.cpp b/src/plugins/qmldesigner/components/contentlibrary/contentlibraryeffect.cpp
index f572fbe65f4..0ae800a3690 100644
--- a/src/plugins/qmldesigner/components/contentlibrary/contentlibraryeffect.cpp
+++ b/src/plugins/qmldesigner/components/contentlibrary/contentlibraryeffect.cpp
@@ -3,8 +3,6 @@
#include "contentlibraryeffect.h"
-#include <QFileInfo>
-
namespace QmlDesigner {
ContentLibraryEffect::ContentLibraryEffect(QObject *parent,
diff --git a/src/plugins/qmldesigner/components/contentlibrary/contentlibraryeffect.h b/src/plugins/qmldesigner/components/contentlibrary/contentlibraryeffect.h
index fdb302b6139..cbfbf7ce3e3 100644
--- a/src/plugins/qmldesigner/components/contentlibrary/contentlibraryeffect.h
+++ b/src/plugins/qmldesigner/components/contentlibrary/contentlibraryeffect.h
@@ -39,7 +39,6 @@ public:
bool setImported(bool imported);
bool imported() const;
- QString parentDirPath() const;
QStringList allFiles() const;
signals:
diff --git a/src/plugins/qmldesigner/components/contentlibrary/contentlibraryeffectsmodel.cpp b/src/plugins/qmldesigner/components/contentlibrary/contentlibraryeffectsmodel.cpp
index 157290c2d53..f6c3f855baa 100644
--- a/src/plugins/qmldesigner/components/contentlibrary/contentlibraryeffectsmodel.cpp
+++ b/src/plugins/qmldesigner/components/contentlibrary/contentlibraryeffectsmodel.cpp
@@ -88,10 +88,9 @@ QHash<int, QByteArray> ContentLibraryEffectsModel::roleNames() const
return roles;
}
-void ContentLibraryEffectsModel::createImporter(const QString &bundlePath, const QString &bundleId,
- const QStringList &sharedFiles)
+void ContentLibraryEffectsModel::createImporter()
{
- m_importer = new Internal::ContentLibraryBundleImporter(bundlePath, bundleId, sharedFiles);
+ m_importer = new Internal::ContentLibraryBundleImporter();
#ifdef QDS_USE_PROJECTSTORAGE
connect(m_importer,
&Internal::ContentLibraryBundleImporter::importFinished,
@@ -200,13 +199,13 @@ void ContentLibraryEffectsModel::loadBundle()
m_bundleCategories.append(category);
}
- QStringList sharedFiles;
+ m_importerSharedFiles.clear();
const QJsonArray sharedFilesArr = m_bundleObj.value("sharedFiles").toArray();
for (const QJsonValueConstRef &file : sharedFilesArr)
- sharedFiles.append(file.toString());
-
- createImporter(bundleDir.path(), bundleId, sharedFiles);
+ m_importerSharedFiles.append(file.toString());
+ createImporter();
+ m_bundlePath = bundleDir.path();
m_bundleExists = true;
emit bundleExistsChanged();
}
@@ -280,7 +279,8 @@ void ContentLibraryEffectsModel::resetModel()
void ContentLibraryEffectsModel::addInstance(ContentLibraryEffect *bundleItem)
{
- QString err = m_importer->importComponent(bundleItem->qml(), bundleItem->files());
+ QString err = m_importer->importComponent(m_bundlePath, bundleItem->type(), bundleItem->qml(),
+ bundleItem->files() + m_importerSharedFiles);
if (err.isEmpty()) {
m_importerRunning = true;
@@ -294,7 +294,7 @@ void ContentLibraryEffectsModel::removeFromProject(ContentLibraryEffect *bundleI
{
emit bundleItemAboutToUnimport(bundleItem->type());
- QString err = m_importer->unimportComponent(bundleItem->qml());
+ QString err = m_importer->unimportComponent(bundleItem->type(), bundleItem->qml());
if (err.isEmpty()) {
m_importerRunning = true;
diff --git a/src/plugins/qmldesigner/components/contentlibrary/contentlibraryeffectsmodel.h b/src/plugins/qmldesigner/components/contentlibrary/contentlibraryeffectsmodel.h
index 5d67ac3da8b..5ac40bbef4b 100644
--- a/src/plugins/qmldesigner/components/contentlibrary/contentlibraryeffectsmodel.h
+++ b/src/plugins/qmldesigner/components/contentlibrary/contentlibraryeffectsmodel.h
@@ -69,11 +69,12 @@ signals:
private:
bool isValidIndex(int idx) const;
- void createImporter(const QString &bundlePath, const QString &bundleId,
- const QStringList &sharedFiles);
+ void createImporter();
ContentLibraryWidget *m_widget = nullptr;
QString m_searchText;
+ QString m_bundlePath;
+ QStringList m_importerSharedFiles;
QList<ContentLibraryEffectsCategory *> m_bundleCategories;
QJsonObject m_bundleObj;
Internal::ContentLibraryBundleImporter *m_importer = nullptr;
@@ -85,10 +86,6 @@ private:
int m_quick3dMajorVersion = -1;
int m_quick3dMinorVersion = -1;
-
- QString m_importerBundlePath;
- QString m_importerBundleId;
- QStringList m_importerSharedFiles;
};
} // namespace QmlDesigner
diff --git a/src/plugins/qmldesigner/components/contentlibrary/contentlibrarymaterial.cpp b/src/plugins/qmldesigner/components/contentlibrary/contentlibrarymaterial.cpp
index 1d30b0217d8..25d15231991 100644
--- a/src/plugins/qmldesigner/components/contentlibrary/contentlibrarymaterial.cpp
+++ b/src/plugins/qmldesigner/components/contentlibrary/contentlibrarymaterial.cpp
@@ -89,7 +89,7 @@ QString ContentLibraryMaterial::qmlFilePath() const
return m_downloadPath + "/" + m_qml;
}
-QString ContentLibraryMaterial::parentDirPath() const
+QString ContentLibraryMaterial::dirPath() const
{
return m_downloadPath;
}
diff --git a/src/plugins/qmldesigner/components/contentlibrary/contentlibrarymaterial.h b/src/plugins/qmldesigner/components/contentlibrary/contentlibrarymaterial.h
index a2f53b7e3cf..d965f25014d 100644
--- a/src/plugins/qmldesigner/components/contentlibrary/contentlibrarymaterial.h
+++ b/src/plugins/qmldesigner/components/contentlibrary/contentlibrarymaterial.h
@@ -19,7 +19,7 @@ class ContentLibraryMaterial : public QObject
Q_PROPERTY(bool bundleMaterialVisible MEMBER m_visible NOTIFY materialVisibleChanged)
Q_PROPERTY(bool bundleMaterialImported READ imported WRITE setImported NOTIFY materialImportedChanged)
Q_PROPERTY(QString bundleMaterialBaseWebUrl MEMBER m_baseWebUrl CONSTANT)
- Q_PROPERTY(QString bundleMaterialParentPath READ parentDirPath CONSTANT)
+ Q_PROPERTY(QString bundleMaterialDirPath READ dirPath CONSTANT)
Q_PROPERTY(QStringList bundleMaterialFiles READ allFiles CONSTANT)
Q_PROPERTY(QString itemType MEMBER m_itemType CONSTANT)
@@ -47,7 +47,7 @@ public:
bool setImported(bool imported);
bool imported() const;
- QString parentDirPath() const;
+ QString dirPath() const;
QStringList allFiles() const;
signals:
diff --git a/src/plugins/qmldesigner/components/contentlibrary/contentlibrarymaterialsmodel.cpp b/src/plugins/qmldesigner/components/contentlibrary/contentlibrarymaterialsmodel.cpp
index a2aef7b47f9..b60ac841d58 100644
--- a/src/plugins/qmldesigner/components/contentlibrary/contentlibrarymaterialsmodel.cpp
+++ b/src/plugins/qmldesigner/components/contentlibrary/contentlibrarymaterialsmodel.cpp
@@ -198,8 +198,7 @@ void ContentLibraryMaterialsModel::downloadSharedFiles(const QDir &targetDir, co
QObject::connect(extractor, &FileExtractor::finishedChanged, this, [this, downloader, extractor]() {
downloader->deleteLater();
extractor->deleteLater();
-
- createImporter(m_importerBundlePath, m_importerBundleId, m_importerSharedFiles);
+ createImporter();
});
extractor->extract();
@@ -208,10 +207,9 @@ void ContentLibraryMaterialsModel::downloadSharedFiles(const QDir &targetDir, co
downloader->start();
}
-void ContentLibraryMaterialsModel::createImporter(const QString &bundlePath, const QString &bundleId,
- const QStringList &sharedFiles)
+void ContentLibraryMaterialsModel::createImporter()
{
- m_importer = new Internal::ContentLibraryBundleImporter(bundlePath, bundleId, sharedFiles);
+ m_importer = new Internal::ContentLibraryBundleImporter();
#ifdef QDS_USE_PROJECTSTORAGE
connect(m_importer,
&Internal::ContentLibraryBundleImporter::importFinished,
@@ -303,27 +301,21 @@ void ContentLibraryMaterialsModel::loadMaterialBundle(const QDir &matBundleDir)
m_bundleCategories.append(category);
}
- QStringList sharedFiles;
+ m_importerSharedFiles.clear();
const QJsonArray sharedFilesArr = m_matBundleObj.value("sharedFiles").toArray();
for (const QJsonValueConstRef &file : sharedFilesArr)
- sharedFiles.append(file.toString());
+ m_importerSharedFiles.append(file.toString());
QStringList missingSharedFiles;
- for (const QString &s : std::as_const(sharedFiles)) {
- const QString fullSharedFilePath = matBundleDir.filePath(s);
-
- if (!QFileInfo::exists(fullSharedFilePath))
+ for (const QString &s : std::as_const(m_importerSharedFiles)) {
+ if (!QFileInfo::exists(matBundleDir.filePath(s)))
missingSharedFiles.push_back(s);
}
- if (missingSharedFiles.length() > 0) {
- m_importerBundlePath = matBundleDir.path();
- m_importerBundleId = bundleId;
- m_importerSharedFiles = sharedFiles;
+ if (missingSharedFiles.length() > 0)
downloadSharedFiles(matBundleDir, missingSharedFiles);
- } else {
- createImporter(matBundleDir.path(), bundleId, sharedFiles);
- }
+ else
+ createImporter();
m_matBundleExists = true;
emit matBundleExistsChanged();
@@ -403,7 +395,8 @@ void ContentLibraryMaterialsModel::applyToSelected(ContentLibraryMaterial *mat,
void ContentLibraryMaterialsModel::addToProject(ContentLibraryMaterial *mat)
{
- QString err = m_importer->importComponent(mat->qml(), mat->files());
+ QString err = m_importer->importComponent(mat->dirPath(), mat->type(),
+ mat->qml(), mat->files() + m_importerSharedFiles);
if (err.isEmpty()) {
m_importerRunning = true;
@@ -417,7 +410,7 @@ void ContentLibraryMaterialsModel::removeFromProject(ContentLibraryMaterial *mat
{
emit bundleMaterialAboutToUnimport(mat->type());
- QString err = m_importer->unimportComponent(mat->qml());
+ QString err = m_importer->unimportComponent(mat->type(), mat->qml());
if (err.isEmpty()) {
m_importerRunning = true;
diff --git a/src/plugins/qmldesigner/components/contentlibrary/contentlibrarymaterialsmodel.h b/src/plugins/qmldesigner/components/contentlibrary/contentlibrarymaterialsmodel.h
index a2c2e90ce1e..c37ffd39fbf 100644
--- a/src/plugins/qmldesigner/components/contentlibrary/contentlibrarymaterialsmodel.h
+++ b/src/plugins/qmldesigner/components/contentlibrary/contentlibrarymaterialsmodel.h
@@ -81,8 +81,7 @@ private:
bool fetchBundleMetadata(const QDir &bundleDir);
bool isValidIndex(int idx) const;
void downloadSharedFiles(const QDir &targetDir, const QStringList &files);
- void createImporter(const QString &bundlePath, const QString &bundleId,
- const QStringList &sharedFiles);
+ void createImporter();
ContentLibraryWidget *m_widget = nullptr;
QString m_searchText;
@@ -101,8 +100,6 @@ private:
QString m_downloadPath;
QString m_baseUrl;
- QString m_importerBundlePath;
- QString m_importerBundleId;
QStringList m_importerSharedFiles;
};
diff --git a/src/plugins/qmldesigner/components/contentlibrary/contentlibraryusermodel.cpp b/src/plugins/qmldesigner/components/contentlibrary/contentlibraryusermodel.cpp
index 34cbadfb8ba..9b53ae4f064 100644
--- a/src/plugins/qmldesigner/components/contentlibrary/contentlibraryusermodel.cpp
+++ b/src/plugins/qmldesigner/components/contentlibrary/contentlibraryusermodel.cpp
@@ -4,7 +4,6 @@
#include "contentlibraryusermodel.h"
#include "contentlibrarybundleimporter.h"
-#include "contentlibraryeffect.h"
#include "contentlibrarymaterial.h"
#include "contentlibrarymaterialscategory.h"
#include "contentlibrarytexture.h"
@@ -224,10 +223,9 @@ QHash<int, QByteArray> ContentLibraryUserModel::roleNames() const
return roles;
}
-void ContentLibraryUserModel::createImporter(const QString &bundlePath, const QString &bundleId,
- const QStringList &sharedFiles)
+void ContentLibraryUserModel::createImporter()
{
- m_importer = new Internal::ContentLibraryBundleImporter(bundlePath, bundleId, sharedFiles);
+ m_importer = new Internal::ContentLibraryBundleImporter();
#ifdef QDS_USE_PROJECTSTORAGE
connect(m_importer,
&Internal::ContentLibraryBundleImporter::importFinished,
@@ -325,12 +323,12 @@ void ContentLibraryUserModel::loadMaterialBundle()
m_userMaterials.append(userMat);
}
- QStringList sharedFiles;
+ m_importerSharedFiles.clear();
const QJsonArray sharedFilesArr = m_bundleObj.value("sharedFiles").toArray();
for (const QJsonValueConstRef &file : sharedFilesArr)
- sharedFiles.append(file.toString());
+ m_importerSharedFiles.append(file.toString());
- createImporter(bundleDir.path(), m_bundleId, sharedFiles);
+ createImporter();
m_matBundleExists = true;
emit matBundleExistsChanged();
@@ -433,7 +431,8 @@ void ContentLibraryUserModel::applyToSelected(ContentLibraryMaterial *mat, bool
void ContentLibraryUserModel::addToProject(ContentLibraryMaterial *mat)
{
- QString err = m_importer->importComponent(mat->qml(), mat->files());
+ QString err = m_importer->importComponent(mat->dirPath(), mat->type(), mat->qml(),
+ mat->files() + m_importerSharedFiles);
if (err.isEmpty()) {
m_importerRunning = true;
@@ -447,7 +446,7 @@ void ContentLibraryUserModel::removeFromProject(ContentLibraryMaterial *mat)
{
emit bundleMaterialAboutToUnimport(mat->type());
- QString err = m_importer->unimportComponent(mat->qml());
+ QString err = m_importer->unimportComponent(mat->type(), mat->qml());
if (err.isEmpty()) {
m_importerRunning = true;
diff --git a/src/plugins/qmldesigner/components/contentlibrary/contentlibraryusermodel.h b/src/plugins/qmldesigner/components/contentlibrary/contentlibraryusermodel.h
index 1bda49674a8..6ac2160e9b8 100644
--- a/src/plugins/qmldesigner/components/contentlibrary/contentlibraryusermodel.h
+++ b/src/plugins/qmldesigner/components/contentlibrary/contentlibraryusermodel.h
@@ -101,8 +101,7 @@ signals:
private:
bool isValidIndex(int idx) const;
- void createImporter(const QString &bundlePath, const QString &bundleId,
- const QStringList &sharedFiles);
+ void createImporter();
ContentLibraryWidget *m_widget = nullptr;
QString m_searchText;
diff --git a/src/plugins/qmldesigner/components/contentlibrary/contentlibraryview.cpp b/src/plugins/qmldesigner/components/contentlibrary/contentlibraryview.cpp
index 9cbc0f73393..5981907f6c5 100644
--- a/src/plugins/qmldesigner/components/contentlibrary/contentlibraryview.cpp
+++ b/src/plugins/qmldesigner/components/contentlibrary/contentlibraryview.cpp
@@ -778,7 +778,9 @@ void ContentLibraryView::updateBundleMaterialsImportedState()
QStringList importedBundleMats;
- FilePath materialBundlePath = m_widget->materialsModel()->bundleImporter()->resolveBundleImportPath();
+ // TODO: this will be refactored next: no need for the round trip from model to view then back to model
+ // (same applies for the similar cases for effects and user material bundles)
+ FilePath materialBundlePath = m_widget->materialsModel()->bundleImporter()->resolveBundleImportPath("MaterialBundle");
if (materialBundlePath.exists()) {
importedBundleMats = transform(materialBundlePath.dirEntries({{"*.qml"}, QDir::Files}),
@@ -797,7 +799,7 @@ void ContentLibraryView::updateBundleUserMaterialsImportedState()
QStringList importedBundleMats;
- FilePath bundlePath = m_widget->userModel()->bundleImporter()->resolveBundleImportPath();
+ FilePath bundlePath = m_widget->userModel()->bundleImporter()->resolveBundleImportPath("UserMaterialBundle");
if (bundlePath.exists()) {
importedBundleMats = transform(bundlePath.dirEntries({{"*.qml"}, QDir::Files}),
@@ -816,7 +818,7 @@ void ContentLibraryView::updateBundleEffectsImportedState()
QStringList importedBundleEffs;
- FilePath bundlePath = m_widget->effectsModel()->bundleImporter()->resolveBundleImportPath();
+ FilePath bundlePath = m_widget->effectsModel()->bundleImporter()->resolveBundleImportPath("EffectBundle");
if (bundlePath.exists()) {
importedBundleEffs = transform(bundlePath.dirEntries({{"*.qml"}, QDir::Files}),