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>
This commit is contained in:
Tapani Mattila
2021-05-26 12:29:18 +03:00
parent e956873db3
commit f087e70e80
3 changed files with 23 additions and 6 deletions

View File

@@ -32,6 +32,8 @@
#include <coreplugin/icore.h> #include <coreplugin/icore.h>
#include <projectexplorer/task.h> #include <projectexplorer/task.h>
#include <projectexplorer/taskhub.h> #include <projectexplorer/taskhub.h>
#include <projectexplorer/project.h>
#include <projectexplorer/session.h>
#include <utils/fileutils.h> #include <utils/fileutils.h>
#include <utils/outputformatter.h> #include <utils/outputformatter.h>
@@ -80,8 +82,13 @@ AssetExportDialog::AssetExportDialog(const Utils::FilePath &exportPath,
{ {
m_ui->setupUi(this); m_ui->setupUi(this);
m_ui->exportPath->setFilePath(exportPath); m_ui->exportPath->setExpectedKind(Utils::PathChooser::Kind::SaveFile);
m_ui->exportPath->setPromptDialogTitle(tr("Choose Export Path")); 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->lineEdit()->setReadOnly(true);
m_ui->exportPath->addButton(tr("Open"), this, [this]() { m_ui->exportPath->addButton(tr("Open"), this, [this]() {
Core::FileUtils::showInGraphicalShell(Core::ICore::mainWindow(), m_ui->exportPath->path()); 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); m_ui->advancedOptions->setWidget(optionsWidget);
auto optionsLayout = new QHBoxLayout(optionsWidget); auto optionsLayout = new QHBoxLayout(optionsWidget);
optionsLayout->setContentsMargins(8, 8, 8, 8); optionsLayout->setContentsMargins(8, 8, 8, 8);
m_exportAssetsCheck = new QCheckBox(tr("Export assets"), this); m_exportAssetsCheck = new QCheckBox(tr("Export assets"), this);
m_exportAssetsCheck->setChecked(true); m_exportAssetsCheck->setChecked(true);
optionsLayout->addWidget(m_exportAssetsCheck); optionsLayout->addWidget(m_exportAssetsCheck);
@@ -153,7 +161,12 @@ void AssetExportDialog::onExport()
TaskHub::clearTasks(Constants::TASK_CATEGORY_ASSET_EXPORT); TaskHub::clearTasks(Constants::TASK_CATEGORY_ASSET_EXPORT);
m_exportLogs->clear(); 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_exportAssetsCheck->isChecked(),
m_perComponentExportCheck->isChecked()); m_perComponentExportCheck->isChecked());
} }

View File

@@ -123,7 +123,9 @@ void AssetExporter::exportQml(const Utils::FilePaths &qmlFiles, const Utils::Fil
{ {
m_perComponentExport = perComponentExport; m_perComponentExport = perComponentExport;
ExportNotification::addInfo(tr("Export root directory: %1.\nExporting assets: %2") 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"))); .arg(exportAssets? tr("Yes") : tr("No")));
if (m_perComponentExport) if (m_perComponentExport)
@@ -134,7 +136,8 @@ void AssetExporter::exportQml(const Utils::FilePaths &qmlFiles, const Utils::Fil
m_totalFileCount = m_exportFiles.count(); m_totalFileCount = m_exportFiles.count();
m_components.clear(); m_components.clear();
m_componentUuidCache.clear(); m_componentUuidCache.clear();
m_exportPath = exportPath; m_exportPath = exportPath.isDir() ? exportPath : exportPath.parentDir();
m_exportFile = exportPath.fileName();
m_currentState.change(ParsingState::Parsing); m_currentState.change(ParsingState::Parsing);
if (exportAssets) if (exportAssets)
m_assetDumper = make_unique<AssetDumper>(); m_assetDumper = make_unique<AssetDumper>();
@@ -437,7 +440,7 @@ void AssetExporter::writeMetadata() const
QJsonArray artboards; QJsonArray artboards;
std::transform(m_components.cbegin(), m_components.cend(), back_inserter(artboards), std::transform(m_components.cbegin(), m_components.cend(), back_inserter(artboards),
[](const unique_ptr<Component> &c) {return c->json(); }); [](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); notifyProgress(1.0);
ExportNotification::addInfo(tr("Export finished.")); ExportNotification::addInfo(tr("Export finished."));

View File

@@ -112,6 +112,7 @@ private:
Utils::FilePaths m_exportFiles; Utils::FilePaths m_exportFiles;
unsigned int m_totalFileCount = 0; unsigned int m_totalFileCount = 0;
Utils::FilePath m_exportPath; Utils::FilePath m_exportPath;
QString m_exportFile;
bool m_perComponentExport = false; bool m_perComponentExport = false;
std::vector<std::unique_ptr<Component>> m_components; std::vector<std::unique_ptr<Component>> m_components;
QHash<QString, QString> m_componentUuidCache; QHash<QString, QString> m_componentUuidCache;