Skip to content

Commit

Permalink
QmlDesigner: Don't override existing content lib user textures
Browse files Browse the repository at this point in the history
Better solution to ask for overriding or not is for the future.

Fixes: QDS-12626
Change-Id: Ib147121d3b9cb783f45a79a96fa432d371750a0e
Reviewed-by: Qt CI Patch Build Bot <ci_patchbuild_bot@qt.io>
Reviewed-by: Miikka Heikkinen <miikka.heikkinen@qt.io>
  • Loading branch information
mbadri-qt committed May 14, 2024
1 parent 22657af commit c2778b2
Showing 1 changed file with 12 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -631,19 +631,28 @@ void ContentLibraryView::addLibAssets(const QStringList &paths)
auto bundlePath = Utils::FilePath::fromString(Paths::bundlesPathSetting() + "/User/textures");
QStringList pathsInBundle;

const QStringList existingTextures = Utils::transform(bundlePath.dirEntries(QDir::Files),
[](const Utils::FilePath &path) {
return path.fileName();
});

for (const QString &path : paths) {
auto assetFilePath = Utils::FilePath::fromString(path);
if (existingTextures.contains(assetFilePath.fileName()))
continue;

Asset asset(path);
auto assetPath = Utils::FilePath::fromString(path);

// save icon
QString iconSavePath = bundlePath.pathAppended("icons/" + assetPath.baseName() + ".png").toString();
QString iconSavePath = bundlePath.pathAppended("icons/" + assetFilePath.baseName() + ".png")
.toString();
QPixmap icon = asset.pixmap({120, 120});
bool iconSaved = icon.save(iconSavePath);
if (!iconSaved)
qWarning() << __FUNCTION__ << "icon save failed";

// save asset
auto result = assetPath.copyFile(bundlePath.pathAppended(asset.fileName()));
auto result = assetFilePath.copyFile(bundlePath.pathAppended(asset.fileName()));
if (!result)
qWarning() << __FUNCTION__ << result.error();

Expand Down

0 comments on commit c2778b2

Please sign in to comment.