EffectMaker: Focus view upon open, and correctly open new effects

Also don't open old effect maker when creating a new effect

Fixes: QDS-11359
Fixes: QDS-11364
Change-Id: Ie9659af991f10cafac29dc53cbe7163eb8995b2a
Reviewed-by: Miikka Heikkinen <miikka.heikkinen@qt.io>
Reviewed-by: Qt CI Patch Build Bot <ci_patchbuild_bot@qt.io>
This commit is contained in:
Mahmoud Badri
2023-11-22 15:28:54 +02:00
parent 3930deff29
commit c14dc9d2ba
3 changed files with 16 additions and 9 deletions

View File

@@ -558,6 +558,9 @@ void EffectMakerModel::openComposition(const QString &path)
{ {
clear(); clear();
const QString effectName = QFileInfo(path).baseName();
setCurrentComposition(effectName);
QFile compFile(path); QFile compFile(path);
if (!compFile.open(QIODevice::ReadOnly)) { if (!compFile.open(QIODevice::ReadOnly)) {
QString error = QString("Couldn't open composition file: '%1'").arg(path); QString error = QString("Couldn't open composition file: '%1'").arg(path);
@@ -567,6 +570,10 @@ void EffectMakerModel::openComposition(const QString &path)
} }
QByteArray data = compFile.readAll(); QByteArray data = compFile.readAll();
if (data.isEmpty())
return;
QJsonParseError parseError; QJsonParseError parseError;
QJsonDocument jsonDoc(QJsonDocument::fromJson(data, &parseError)); QJsonDocument jsonDoc(QJsonDocument::fromJson(data, &parseError));
if (parseError.error != QJsonParseError::NoError) { if (parseError.error != QJsonParseError::NoError) {
@@ -597,7 +604,6 @@ void EffectMakerModel::openComposition(const QString &path)
} }
// Get effects dir // Get effects dir
const QString effectName = QFileInfo(path).baseName();
const Utils::FilePath effectsResDir = QmlDesigner::ModelNodeOperations::getEffectsImportDirectory(); const Utils::FilePath effectsResDir = QmlDesigner::ModelNodeOperations::getEffectsImportDirectory();
const QString effectsResPath = effectsResDir.pathAppended(effectName).toString(); const QString effectsResPath = effectsResDir.pathAppended(effectName).toString();
@@ -613,8 +619,6 @@ void EffectMakerModel::openComposition(const QString &path)
setIsEmpty(m_nodes.isEmpty()); setIsEmpty(m_nodes.isEmpty());
bakeShaders(); bakeShaders();
} }
setCurrentComposition(effectName);
} }
void EffectMakerModel::exportResources(const QString &name) void EffectMakerModel::exportResources(const QString &name)

View File

@@ -8,6 +8,7 @@
#include "assetslibrarymodel.h" #include "assetslibrarymodel.h"
#include "assetslibraryview.h" #include "assetslibraryview.h"
#include "designeractionmanager.h" #include "designeractionmanager.h"
#include "designmodewidget.h"
#include "modelnodeoperations.h" #include "modelnodeoperations.h"
#include "qmldesignerconstants.h" #include "qmldesignerconstants.h"
#include "qmldesignerplugin.h" #include "qmldesignerplugin.h"
@@ -192,12 +193,12 @@ QString AssetsLibraryWidget::getUniqueEffectPath(const QString &parentFolder, co
return path; return path;
} }
bool AssetsLibraryWidget::createNewEffect(const QString &effectPath, bool openEffectMaker) bool AssetsLibraryWidget::createNewEffect(const QString &effectPath, bool openInEffectMaker)
{ {
bool created = QFile(effectPath).open(QIODevice::WriteOnly); bool created = QFile(effectPath).open(QIODevice::WriteOnly);
if (created && openEffectMaker) { if (created && openInEffectMaker) {
ModelNodeOperations::openEffectMaker(effectPath); openEffectMaker(effectPath);
emit directoryCreated(QFileInfo(effectPath).absolutePath()); emit directoryCreated(QFileInfo(effectPath).absolutePath());
} }
@@ -379,10 +380,12 @@ bool isEffectMakerActivated()
void AssetsLibraryWidget::openEffectMaker(const QString &filePath) void AssetsLibraryWidget::openEffectMaker(const QString &filePath)
{ {
if (isEffectMakerActivated()) if (isEffectMakerActivated()) { // new effect maker
m_assetsView->emitCustomNotification("open_effectmaker_composition", {}, {filePath}); m_assetsView->emitCustomNotification("open_effectmaker_composition", {}, {filePath});
else QmlDesignerPlugin::instance()->mainWidget()->showDockWidget("Effect Maker", true);
} else { // old effect maker
ModelNodeOperations::openEffectMaker(filePath); ModelNodeOperations::openEffectMaker(filePath);
}
} }
QString AssetsLibraryWidget::qmlSourcesPath() QString AssetsLibraryWidget::qmlSourcesPath()

View File

@@ -92,7 +92,7 @@ public:
Q_INVOKABLE void updateContextMenuActionsEnableState(); Q_INVOKABLE void updateContextMenuActionsEnableState();
Q_INVOKABLE QString getUniqueEffectPath(const QString &parentFolder, const QString &effectName); Q_INVOKABLE QString getUniqueEffectPath(const QString &parentFolder, const QString &effectName);
Q_INVOKABLE bool createNewEffect(const QString &effectPath, bool openEffectMaker = true); Q_INVOKABLE bool createNewEffect(const QString &effectPath, bool openInEffectMaker = true);
Q_INVOKABLE bool canCreateEffects() const; Q_INVOKABLE bool canCreateEffects() const;