QtDesignStudio: Fix assets library external drop

Fix external drops onto assets library for ubuntu. The file paths were
missing the leading slash ("/") which caused external drops to fail.

Change-Id: I4c554df2ac4422d935ec06b835ce34de25b9e2e8
Reviewed-by: Mahmoud Badri <mahmoud.badri@qt.io>
This commit is contained in:
Henning Gruendl
2022-05-10 10:59:47 +02:00
committed by Henning Gründl
parent bbc44cfb90
commit 42857ce43f
3 changed files with 16 additions and 13 deletions

View File

@@ -59,9 +59,6 @@ Item {
var complexSuffixes = rootView.supportedAssetSuffixes(true); var complexSuffixes = rootView.supportedAssetSuffixes(true);
for (const u of drag.urls) { for (const u of drag.urls) {
var url = u.toString(); var url = u.toString();
if (url.startsWith("file:///")) // remove file scheme (happens on Windows)
url = url.substr(8)
var ext = '*.' + url.slice(url.lastIndexOf('.') + 1).toLowerCase() var ext = '*.' + url.slice(url.lastIndexOf('.') + 1).toLowerCase()
if (simpleSuffixes.includes(ext)) if (simpleSuffixes.includes(ext))
root.dropSimpleExtFiles.push(url) root.dropSimpleExtFiles.push(url)

View File

@@ -213,26 +213,32 @@ void AssetsLibraryWidget::handleAddAsset()
addResources({}); addResources({});
} }
void AssetsLibraryWidget::handleExtFilesDrop(const QStringList &simpleFilesPaths, void AssetsLibraryWidget::handleExtFilesDrop(const QList<QUrl> &simpleFilePaths,
const QStringList &complexFilesPaths, const QList<QUrl> &complexFilePaths,
const QString &targetDirPath) const QString &targetDirPath)
{ {
if (!simpleFilesPaths.isEmpty()) { auto toLocalFile = [](const QUrl &url) { return url.toLocalFile(); };
QStringList simpleFilePathStrings = Utils::transform<QStringList>(simpleFilePaths, toLocalFile);
QStringList complexFilePathStrings = Utils::transform<QStringList>(complexFilePaths,
toLocalFile);
if (!simpleFilePathStrings.isEmpty()) {
if (targetDirPath.isEmpty()) { if (targetDirPath.isEmpty()) {
addResources(simpleFilesPaths); addResources(simpleFilePathStrings);
} else { } else {
AddFilesResult result = ModelNodeOperations::addFilesToProject(simpleFilesPaths, AddFilesResult result = ModelNodeOperations::addFilesToProject(simpleFilePathStrings,
targetDirPath); targetDirPath);
if (result == AddFilesResult::Failed) { if (result == AddFilesResult::Failed) {
Core::AsynchronousMessageBox::warning(tr("Failed to Add Files"), Core::AsynchronousMessageBox::warning(tr("Failed to Add Files"),
tr("Could not add %1 to project.") tr("Could not add %1 to project.")
.arg(simpleFilesPaths.join(' '))); .arg(simpleFilePathStrings.join(' ')));
} }
} }
} }
if (!complexFilesPaths.empty()) if (!complexFilePathStrings.empty())
addResources(complexFilesPaths); addResources(complexFilePathStrings);
} }
QSet<QString> AssetsLibraryWidget::supportedAssetSuffixes(bool complex) QSet<QString> AssetsLibraryWidget::supportedAssetSuffixes(bool complex)

View File

@@ -79,8 +79,8 @@ public:
Q_INVOKABLE void startDragAsset(const QStringList &assetPaths, const QPointF &mousePos); Q_INVOKABLE void startDragAsset(const QStringList &assetPaths, const QPointF &mousePos);
Q_INVOKABLE void handleAddAsset(); Q_INVOKABLE void handleAddAsset();
Q_INVOKABLE void handleSearchfilterChanged(const QString &filterText); Q_INVOKABLE void handleSearchfilterChanged(const QString &filterText);
Q_INVOKABLE void handleExtFilesDrop(const QStringList &simpleFilesPaths, Q_INVOKABLE void handleExtFilesDrop(const QList<QUrl> &simpleFilePaths,
const QStringList &complexFilesPaths, const QList<QUrl> &complexFilePaths,
const QString &targetDirPath = {}); const QString &targetDirPath = {});
Q_INVOKABLE QSet<QString> supportedAssetSuffixes(bool complex); Q_INVOKABLE QSet<QString> supportedAssetSuffixes(bool complex);