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();
const QString effectName = QFileInfo(path).baseName();
setCurrentComposition(effectName);
QFile compFile(path);
if (!compFile.open(QIODevice::ReadOnly)) {
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();
if (data.isEmpty())
return;
QJsonParseError parseError;
QJsonDocument jsonDoc(QJsonDocument::fromJson(data, &parseError));
if (parseError.error != QJsonParseError::NoError) {
@@ -597,7 +604,6 @@ void EffectMakerModel::openComposition(const QString &path)
}
// Get effects dir
const QString effectName = QFileInfo(path).baseName();
const Utils::FilePath effectsResDir = QmlDesigner::ModelNodeOperations::getEffectsImportDirectory();
const QString effectsResPath = effectsResDir.pathAppended(effectName).toString();
@@ -613,8 +619,6 @@ void EffectMakerModel::openComposition(const QString &path)
setIsEmpty(m_nodes.isEmpty());
bakeShaders();
}
setCurrentComposition(effectName);
}
void EffectMakerModel::exportResources(const QString &name)

View File

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

View File

@@ -92,7 +92,7 @@ public:
Q_INVOKABLE void updateContextMenuActionsEnableState();
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;