summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTapani Mattila <tapani.mattila@qt.io>2021-05-26 12:29:18 +0300
committerTapani Mattila <tapani.mattila@qt.io>2021-06-08 07:32:12 +0000
commitf087e70e80bb086931c01fc85d63f8a1ef8f770b (patch)
treeaf54d26bcd00f21c330c0f5b29f0da3fd8d6e06f
parente956873db34ae32e0ef730e64eb401aa38ce92fc (diff)
downloadqt-creator-f087e70e80bb086931c01fc85d63f8a1ef8f770b.tar.gz
AssetExport: Enable setting custom metadata file name for exported components
Task-number: QDS-4384 Change-Id: I5d41ab00f7f90137355289f341defcb87ddf3b44 Reviewed-by: Vikas Pachdha <vikas.pachdha@qt.io>
-rw-r--r--src/plugins/qmldesigner/assetexporterplugin/assetexportdialog.cpp19
-rw-r--r--src/plugins/qmldesigner/assetexporterplugin/assetexporter.cpp9
-rw-r--r--src/plugins/qmldesigner/assetexporterplugin/assetexporter.h1
3 files changed, 23 insertions, 6 deletions
diff --git a/src/plugins/qmldesigner/assetexporterplugin/assetexportdialog.cpp b/src/plugins/qmldesigner/assetexporterplugin/assetexportdialog.cpp
index 0c6a8a46f7..a80d30830f 100644
--- a/src/plugins/qmldesigner/assetexporterplugin/assetexportdialog.cpp
+++ b/src/plugins/qmldesigner/assetexporterplugin/assetexportdialog.cpp
@@ -32,6 +32,8 @@
#include <coreplugin/icore.h>
#include <projectexplorer/task.h>
#include <projectexplorer/taskhub.h>
+#include <projectexplorer/project.h>
+#include <projectexplorer/session.h>
#include <utils/fileutils.h>
#include <utils/outputformatter.h>
@@ -80,8 +82,13 @@ AssetExportDialog::AssetExportDialog(const Utils::FilePath &exportPath,
{
m_ui->setupUi(this);
- m_ui->exportPath->setFilePath(exportPath);
- m_ui->exportPath->setPromptDialogTitle(tr("Choose Export Path"));
+ m_ui->exportPath->setExpectedKind(Utils::PathChooser::Kind::SaveFile);
+ m_ui->exportPath->setFilePath(
+ exportPath.pathAppended(
+ ProjectExplorer::SessionManager::startupProject()->displayName() + ".metadata"
+ ));
+ m_ui->exportPath->setPromptDialogTitle(tr("Choose Export File"));
+ m_ui->exportPath->setPromptDialogFilter(tr("Metadata file (*.metadata)"));
m_ui->exportPath->lineEdit()->setReadOnly(true);
m_ui->exportPath->addButton(tr("Open"), this, [this]() {
Core::FileUtils::showInGraphicalShell(Core::ICore::mainWindow(), m_ui->exportPath->path());
@@ -92,6 +99,7 @@ AssetExportDialog::AssetExportDialog(const Utils::FilePath &exportPath,
m_ui->advancedOptions->setWidget(optionsWidget);
auto optionsLayout = new QHBoxLayout(optionsWidget);
optionsLayout->setContentsMargins(8, 8, 8, 8);
+
m_exportAssetsCheck = new QCheckBox(tr("Export assets"), this);
m_exportAssetsCheck->setChecked(true);
optionsLayout->addWidget(m_exportAssetsCheck);
@@ -153,7 +161,12 @@ void AssetExportDialog::onExport()
TaskHub::clearTasks(Constants::TASK_CATEGORY_ASSET_EXPORT);
m_exportLogs->clear();
- m_assetExporter.exportQml(m_filePathModel.files(), m_ui->exportPath->filePath(),
+ Utils::FilePath selectedPath = m_ui->exportPath->filePath();
+ Utils::FilePath exportPath = m_perComponentExportCheck->isChecked() ?
+ (selectedPath.isDir() ? selectedPath : selectedPath.parentDir()) :
+ selectedPath;
+
+ m_assetExporter.exportQml(m_filePathModel.files(), exportPath,
m_exportAssetsCheck->isChecked(),
m_perComponentExportCheck->isChecked());
}
diff --git a/src/plugins/qmldesigner/assetexporterplugin/assetexporter.cpp b/src/plugins/qmldesigner/assetexporterplugin/assetexporter.cpp
index 7e0cf0d084..22796c5afd 100644
--- a/src/plugins/qmldesigner/assetexporterplugin/assetexporter.cpp
+++ b/src/plugins/qmldesigner/assetexporterplugin/assetexporter.cpp
@@ -123,7 +123,9 @@ void AssetExporter::exportQml(const Utils::FilePaths &qmlFiles, const Utils::Fil
{
m_perComponentExport = perComponentExport;
ExportNotification::addInfo(tr("Export root directory: %1.\nExporting assets: %2")
- .arg(exportPath.toUserOutput())
+ .arg(exportPath.isDir()
+ ? exportPath.toUserOutput()
+ : exportPath.parentDir().toUserOutput())
.arg(exportAssets? tr("Yes") : tr("No")));
if (m_perComponentExport)
@@ -134,7 +136,8 @@ void AssetExporter::exportQml(const Utils::FilePaths &qmlFiles, const Utils::Fil
m_totalFileCount = m_exportFiles.count();
m_components.clear();
m_componentUuidCache.clear();
- m_exportPath = exportPath;
+ m_exportPath = exportPath.isDir() ? exportPath : exportPath.parentDir();
+ m_exportFile = exportPath.fileName();
m_currentState.change(ParsingState::Parsing);
if (exportAssets)
m_assetDumper = make_unique<AssetDumper>();
@@ -437,7 +440,7 @@ void AssetExporter::writeMetadata() const
QJsonArray artboards;
std::transform(m_components.cbegin(), m_components.cend(), back_inserter(artboards),
[](const unique_ptr<Component> &c) {return c->json(); });
- writeFile(m_exportPath.pathAppended(projectName + ".metadata"), artboards);
+ writeFile(m_exportPath.pathAppended(m_exportFile), artboards);
}
notifyProgress(1.0);
ExportNotification::addInfo(tr("Export finished."));
diff --git a/src/plugins/qmldesigner/assetexporterplugin/assetexporter.h b/src/plugins/qmldesigner/assetexporterplugin/assetexporter.h
index adfc71a115..6eac814b6a 100644
--- a/src/plugins/qmldesigner/assetexporterplugin/assetexporter.h
+++ b/src/plugins/qmldesigner/assetexporterplugin/assetexporter.h
@@ -112,6 +112,7 @@ private:
Utils::FilePaths m_exportFiles;
unsigned int m_totalFileCount = 0;
Utils::FilePath m_exportPath;
+ QString m_exportFile;
bool m_perComponentExport = false;
std::vector<std::unique_ptr<Component>> m_components;
QHash<QString, QString> m_componentUuidCache;