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);
connect(m_ui->buttonBox->button(QDialogButtonBox::Cancel), &QPushButton::clicked, [this]() {
m_ui->buttonBox->button(QDialogButtonBox::Cancel)->setEnabled(false);
m_assetExporter.cancel();
});

View File

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

View File

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