AssetExport: Let user cancel the export

Change-Id: I6c2ee983bf9633744a74ad1c1f01fda4cdefd0ca
Reviewed-by: Tim Jenssen <tim.jenssen@qt.io>
This commit is contained in:
Vikas Pachdha
2020-06-26 21:03:05 +02:00
parent fbb1fb3bf2
commit d8e3bc43b5
3 changed files with 21 additions and 5 deletions

View File

@@ -97,6 +97,7 @@ AssetExportDialog::AssetExportDialog(const Utils::FilePath &exportPath,
switchView(false); switchView(false);
connect(m_ui->buttonBox->button(QDialogButtonBox::Cancel), &QPushButton::clicked, [this]() { connect(m_ui->buttonBox->button(QDialogButtonBox::Cancel), &QPushButton::clicked, [this]() {
m_ui->buttonBox->button(QDialogButtonBox::Cancel)->setEnabled(false);
m_assetExporter.cancel(); m_assetExporter.cancel();
}); });

View File

@@ -129,8 +129,11 @@ void AssetExporter::exportQml(const Utils::FilePaths &qmlFiles, const Utils::Fil
void AssetExporter::cancel() void AssetExporter::cancel()
{ {
// TODO Cancel export if (!m_cancelled) {
m_assetDumper.reset(); ExportNotification::addInfo(tr("Cancelling export."));
m_assetDumper.reset();
m_cancelled = true;
}
} }
bool AssetExporter::isBusy() const bool AssetExporter::isBusy() const
@@ -142,8 +145,11 @@ bool AssetExporter::isBusy() const
Utils::FilePath AssetExporter::exportAsset(const QmlObjectNode &node, const QString &uuid) Utils::FilePath AssetExporter::exportAsset(const QmlObjectNode &node, const QString &uuid)
{ {
if (m_cancelled)
return {};
Utils::FilePath assetPath = m_exportPath.pathAppended(QString("assets/%1.png").arg(uuid)); Utils::FilePath assetPath = m_exportPath.pathAppended(QString("assets/%1.png").arg(uuid));
m_assetDumper->dumpAsset(node.toQmlItemNode().instanceRenderPixmap(), assetPath); if (m_assetDumper)
m_assetDumper->dumpAsset(node.toQmlItemNode().instanceRenderPixmap(), assetPath);
return assetPath; return assetPath;
} }
@@ -207,7 +213,7 @@ void AssetExporter::triggerLoadNextFile()
void AssetExporter::loadNextFile() void AssetExporter::loadNextFile()
{ {
if (m_exportFiles.isEmpty()) { if (m_cancelled || m_exportFiles.isEmpty()) {
notifyProgress(0.8); notifyProgress(0.8);
m_currentState.change(ParsingState::ParsingFinished); m_currentState.change(ParsingState::ParsingFinished);
writeMetadata(); writeMetadata();
@@ -223,6 +229,13 @@ void AssetExporter::loadNextFile()
void AssetExporter::writeMetadata() const void AssetExporter::writeMetadata() const
{ {
if (m_cancelled) {
notifyProgress(1.0);
ExportNotification::addInfo(tr("Export cancelled."));
m_currentState.change(ParsingState::ExportingDone);
return;
}
Utils::FilePath metadataPath = m_exportPath.pathAppended(m_exportPath.fileName() + ".metadata"); Utils::FilePath metadataPath = m_exportPath.pathAppended(m_exportPath.fileName() + ".metadata");
ExportNotification::addInfo(tr("Writing metadata to file %1."). ExportNotification::addInfo(tr("Writing metadata to file %1.").
arg(metadataPath.toUserOutput())); arg(metadataPath.toUserOutput()));
@@ -243,7 +256,8 @@ void AssetExporter::writeMetadata() const
} }
notifyProgress(1.0); notifyProgress(1.0);
ExportNotification::addInfo(tr("Export finished.")); ExportNotification::addInfo(tr("Export finished."));
m_assetDumper->quitDumper(); if (m_assetDumper)
m_assetDumper->quitDumper();
m_currentState.change(ParsingState::ExportingDone); m_currentState.change(ParsingState::ExportingDone);
} }

View File

@@ -104,6 +104,7 @@ private:
QJsonArray m_components; QJsonArray m_components;
QSet<QByteArray> m_usedHashes; QSet<QByteArray> m_usedHashes;
std::unique_ptr<AssetDumper> m_assetDumper; std::unique_ptr<AssetDumper> m_assetDumper;
bool m_cancelled = false;
}; };
QDebug operator<< (QDebug os, const QmlDesigner::AssetExporter::ParsingState& s); QDebug operator<< (QDebug os, const QmlDesigner::AssetExporter::ParsingState& s);