AssetExporter: Add import notification task

Task-number: QDS-1560
Change-Id: I09c14c22206c299f7a50f1a843c6dc4ebac670e2
Reviewed-by: Leena Miettinen <riitta-leena.miettinen@qt.io>
Reviewed-by: Thomas Hartmann <thomas.hartmann@qt.io>
This commit is contained in:
Vikas Pachdha
2020-06-11 19:56:53 +02:00
parent e1e7a1786f
commit 7f1b286264
8 changed files with 114 additions and 4 deletions

View File

@@ -50,6 +50,7 @@ add_qtc_plugin(assetexporterplugin
assetexporterplugin/assetexporterview.h assetexporterplugin/assetexporterview.cpp assetexporterplugin/assetexporterview.h assetexporterplugin/assetexporterview.cpp
assetexporterplugin/assetexportpluginconstants.h assetexporterplugin/assetexportpluginconstants.h
assetexporterplugin/componentexporter.h assetexporterplugin/componentexporter.cpp assetexporterplugin/componentexporter.h assetexporterplugin/componentexporter.cpp
assetexporterplugin/exportnotification.h assetexporterplugin/exportnotification.cpp
assetexporterplugin/parsers/modelitemnodeparser.h assetexporterplugin/parsers/modelitemnodeparser.cpp assetexporterplugin/parsers/modelitemnodeparser.h assetexporterplugin/parsers/modelitemnodeparser.cpp
assetexporterplugin/parsers/modelnodeparser.h assetexporterplugin/parsers/modelnodeparser.cpp assetexporterplugin/parsers/modelnodeparser.h assetexporterplugin/parsers/modelnodeparser.cpp
assetexporterplugin/assetexporterplugin.qrc assetexporterplugin/assetexporterplugin.qrc

View File

@@ -24,6 +24,7 @@
****************************************************************************/ ****************************************************************************/
#include "assetexporter.h" #include "assetexporter.h"
#include "componentexporter.h" #include "componentexporter.h"
#include "exportnotification.h"
#include "plaintexteditmodifier.h" #include "plaintexteditmodifier.h"
#include "rewriterview.h" #include "rewriterview.h"
@@ -134,6 +135,9 @@ bool AssetExporter::preProcessProject()
void AssetExporter::exportQml(const Utils::FilePaths &qmlFiles, const Utils::FilePath &exportPath, void AssetExporter::exportQml(const Utils::FilePaths &qmlFiles, const Utils::FilePath &exportPath,
bool exportAssets) bool exportAssets)
{ {
ExportNotification::addInfo(tr("Exporting metadata at %1. Export assets: ")
.arg(exportPath.toUserOutput())
.arg(exportAssets? tr("Yes") : tr("No")));
// TODO Asset export // TODO Asset export
Q_UNUSED(exportAssets); Q_UNUSED(exportAssets);
m_exportFiles = qmlFiles; m_exportFiles = qmlFiles;
@@ -145,6 +149,7 @@ void AssetExporter::exportQml(const Utils::FilePaths &qmlFiles, const Utils::Fil
void AssetExporter::cancel() void AssetExporter::cancel()
{ {
ExportNotification::addInfo("Cancelling export.");
if (m_preprocessWatcher && !m_preprocessWatcher->isCanceled() && if (m_preprocessWatcher && !m_preprocessWatcher->isCanceled() &&
!m_preprocessWatcher->isFinished()) { !m_preprocessWatcher->isFinished()) {
m_preprocessWatcher->cancel(); m_preprocessWatcher->cancel();
@@ -181,8 +186,8 @@ void AssetExporter::notifyLoadError(AssetExporterView::LoadState state)
default: default:
return; return;
} }
// TODO. Communicate errors to user
qCDebug(loggerError) << "QML load error:" << errorStr; qCDebug(loggerError) << "QML load error:" << errorStr;
ExportNotification::addError(tr("Loading QML failed. %1").arg(errorStr));
} }
void AssetExporter::onQmlFileLoaded() void AssetExporter::onQmlFileLoaded()
@@ -208,24 +213,27 @@ void AssetExporter::loadNextFile()
// Load the next pending file. // Load the next pending file.
const Utils::FilePath file = m_exportFiles.takeFirst(); const Utils::FilePath file = m_exportFiles.takeFirst();
ExportNotification::addInfo(tr("Exporting file %1.").arg(file.toUserOutput()));
qCDebug(loggerInfo) << "Loading next file" << file; qCDebug(loggerInfo) << "Loading next file" << file;
m_view->loadQmlFile(file); m_view->loadQmlFile(file);
} }
void AssetExporter::writeMetadata() const void AssetExporter::writeMetadata() const
{ {
qCDebug(loggerInfo) << "Writing metadata"; ExportNotification::addInfo(tr("Writing metadata to file %1.").
arg(m_exportPath.toUserOutput()));
m_currentState.change(ParsingState::WritingJson); m_currentState.change(ParsingState::WritingJson);
QJsonObject jsonRoot; // TODO: Write plugin info to root QJsonObject jsonRoot; // TODO: Write plugin info to root
jsonRoot.insert("artboards", m_components); jsonRoot.insert("artboards", m_components);
QJsonDocument doc(jsonRoot); QJsonDocument doc(jsonRoot);
if (doc.isNull() || doc.isEmpty()) { if (doc.isNull() || doc.isEmpty()) {
qCDebug(loggerWarn) << "Empty JSON document"; ExportNotification::addError(tr("Empty JSON document."));
} else { } else {
Utils::FileSaver saver(m_exportPath.toString(), QIODevice::Text); Utils::FileSaver saver(m_exportPath.toString(), QIODevice::Text);
saver.write(doc.toJson(QJsonDocument::Indented)); saver.write(doc.toJson(QJsonDocument::Indented));
if (!saver.finalize()) { if (!saver.finalize()) {
qCDebug(loggerError) << "Cannot write Metadata file: " << saver.errorString(); ExportNotification::addError(tr("Writing metadata failed. %1").
arg(saver.errorString()));
} }
} }
m_currentState.change(ParsingState::ExportingDone); m_currentState.change(ParsingState::ExportingDone);

View File

@@ -41,6 +41,7 @@
#include "projectexplorer/session.h" #include "projectexplorer/session.h"
#include "projectexplorer/project.h" #include "projectexplorer/project.h"
#include "projectexplorer/session.h" #include "projectexplorer/session.h"
#include "projectexplorer/taskhub.h"
#include "extensionsystem/pluginmanager.h" #include "extensionsystem/pluginmanager.h"
#include "extensionsystem/pluginspec.h" #include "extensionsystem/pluginspec.h"
@@ -57,6 +58,9 @@ namespace QmlDesigner {
AssetExporterPlugin::AssetExporterPlugin() : AssetExporterPlugin::AssetExporterPlugin() :
m_view(new AssetExporterView) m_view(new AssetExporterView)
{ {
ProjectExplorer::TaskHub::addCategory( Constants::TASK_CATEGORY_ASSET_EXPORT,
tr("Asset Export"), false);
auto *designerPlugin = QmlDesigner::QmlDesignerPlugin::instance(); auto *designerPlugin = QmlDesigner::QmlDesignerPlugin::instance();
auto &viewManager = designerPlugin->viewManager(); auto &viewManager = designerPlugin->viewManager();
viewManager.registerViewTakingOwnership(m_view); viewManager.registerViewTakingOwnership(m_view);

View File

@@ -13,6 +13,7 @@ HEADERS += \
assetexporterview.h \ assetexporterview.h \
assetexportpluginconstants.h \ assetexportpluginconstants.h \
componentexporter.h \ componentexporter.h \
exportnotification.h \
parsers/modelitemnodeparser.h \ parsers/modelitemnodeparser.h \
parsers/modelnodeparser.h parsers/modelnodeparser.h
@@ -22,6 +23,7 @@ SOURCES += \
assetexporterplugin.cpp \ assetexporterplugin.cpp \
assetexporterview.cpp \ assetexporterview.cpp \
componentexporter.cpp \ componentexporter.cpp \
exportnotification.cpp \
parsers/modelitemnodeparser.cpp \ parsers/modelitemnodeparser.cpp \
parsers/modelnodeparser.cpp parsers/modelnodeparser.cpp

View File

@@ -43,6 +43,8 @@ QtcProduct {
"assetexportpluginconstants.h", "assetexportpluginconstants.h",
"componentexporter.cpp", "componentexporter.cpp",
"componentexporter.h", "componentexporter.h",
"exportnotification.cpp",
"exportnotification.h",
"parsers/modelitemnodeparser.cpp", "parsers/modelitemnodeparser.cpp",
"parsers/modelitemnodeparser.h", "parsers/modelitemnodeparser.h",
"parsers/modelnodeparser.cpp", "parsers/modelnodeparser.cpp",

View File

@@ -29,5 +29,7 @@ namespace Constants {
const char EXPORT_QML[] = "Designer.ExportPlugin.ExportQml"; const char EXPORT_QML[] = "Designer.ExportPlugin.ExportQml";
const char TASK_CATEGORY_ASSET_EXPORT[] = "AssetExporter.Export";
} }
} }

View File

@@ -0,0 +1,58 @@
/****************************************************************************
**
** Copyright (C) 2020 The Qt Company Ltd
** All rights reserved.
** For any questions to The Qt Company, please use contact form at http://www.qt.io/contact-us
**
** This file is part of the Qt Asset Importer module.
**
** Commercial License Usage
** Licensees holding valid commercial Qt licenses may use this file in
** accordance with the commercial license agreement provided with the
** Software or, alternatively, in accordance with the terms contained in
** a written agreement between you and The Qt Company. For licensing terms
** and conditions see http://www.qt.io/terms-conditions. For further
** information use the contact form at http://www.qt.io/contact-us.
**
** If you have questions regarding the use of this file, please use
** contact form at http://www.qt.io/contact-us
**
******************************************************************************/
#include "exportnotification.h"
#include "assetexportpluginconstants.h"
#include "projectexplorer/taskhub.h"
#include <QLoggingCategory>
namespace {
Q_LOGGING_CATEGORY(loggerDebug, "qtc.designer.assetExportPlugin.exportNotification", QtDebugMsg)
}
using namespace ProjectExplorer;
namespace {
static void addTask(Task::TaskType type, const QString &desc)
{
qCDebug(loggerDebug) << desc;
Task task(type, desc, {}, -1, QmlDesigner::Constants::TASK_CATEGORY_ASSET_EXPORT);
TaskHub::addTask(task);
}
}
namespace QmlDesigner {
void ExportNotification::addError(const QString &errMsg)
{
addTask(Task::Error, errMsg);
}
void ExportNotification::addWarning(const QString &warningMsg)
{
addTask(Task::Warning, warningMsg);
}
void ExportNotification::addInfo(const QString &infoMsg)
{
addTask(Task::Unknown, infoMsg);
}
} // QmlDesigner

View File

@@ -0,0 +1,33 @@
/****************************************************************************
**
** Copyright (C) 2020 The Qt Company Ltd
** All rights reserved.
** For any questions to The Qt Company, please use contact form at http://www.qt.io/contact-us
**
** This file is part of the Qt Asset Importer module.
**
** Commercial License Usage
** Licensees holding valid commercial Qt licenses may use this file in
** accordance with the commercial license agreement provided with the
** Software or, alternatively, in accordance with the terms contained in
** a written agreement between you and The Qt Company. For licensing terms
** and conditions see http://www.qt.io/terms-conditions. For further
** information use the contact form at http://www.qt.io/contact-us.
**
** If you have questions regarding the use of this file, please use
** contact form at http://www.qt.io/contact-us
**
******************************************************************************/
#pragma once
#include <QString>
namespace QmlDesigner {
class ExportNotification
{
public:
static void addError(const QString &errMsg);
static void addWarning(const QString &warningMsg);
static void addInfo(const QString &infoMsg);
};
} // QmlDesigner