forked from qt-creator/qt-creator
QmlDesigner: Allow saving effects to non-default folder
Fixes: QDS-13573 Change-Id: Ia441534597752ad32b5f013aabb3299632628525 Reviewed-by: Miikka Heikkinen <miikka.heikkinen@qt.io> Reviewed-by: Mahmoud Badri <mahmoud.badri@qt.io>
This commit is contained in:
@@ -14,6 +14,7 @@
|
|||||||
|
|
||||||
#include <qtsupport/qtkitaspect.h>
|
#include <qtsupport/qtkitaspect.h>
|
||||||
|
|
||||||
|
#include <uniquename.h>
|
||||||
#include <utils/qtcassert.h>
|
#include <utils/qtcassert.h>
|
||||||
#include <utils/qtcprocess.h>
|
#include <utils/qtcprocess.h>
|
||||||
|
|
||||||
@@ -202,8 +203,10 @@ void EffectComposerModel::clear(bool clearName)
|
|||||||
m_nodes.clear();
|
m_nodes.clear();
|
||||||
endResetModel();
|
endResetModel();
|
||||||
|
|
||||||
if (clearName)
|
if (clearName) {
|
||||||
setCurrentComposition("");
|
setCurrentComposition("");
|
||||||
|
setCompositionPath("");
|
||||||
|
}
|
||||||
|
|
||||||
setHasUnsavedChanges(!m_currentComposition.isEmpty());
|
setHasUnsavedChanges(!m_currentComposition.isEmpty());
|
||||||
|
|
||||||
@@ -221,20 +224,19 @@ void EffectComposerModel::assignToSelected()
|
|||||||
QString EffectComposerModel::getUniqueEffectName() const
|
QString EffectComposerModel::getUniqueEffectName() const
|
||||||
{
|
{
|
||||||
const QString effectsDir = QmlDesigner::ModelNodeOperations::getEffectsDefaultDirectory();
|
const QString effectsDir = QmlDesigner::ModelNodeOperations::getEffectsDefaultDirectory();
|
||||||
const QString path = effectsDir + '/' + "Effect%1.qep";
|
const QString path = !m_compositionPath.isEmpty() ? m_compositionPath.parentDir().pathAppended("%1.qep").toString()
|
||||||
|
: effectsDir + '/' + "%1" + ".qep";
|
||||||
|
|
||||||
int num = 0;
|
return QmlDesigner::UniqueName::generate("Effect01", [&] (const QString &effectName) {
|
||||||
|
return QFile::exists(path.arg(effectName));
|
||||||
while (QFile::exists(path.arg(++num, 2, 10, QChar('0'))))
|
});
|
||||||
; // empty body
|
|
||||||
|
|
||||||
return QString("Effect%1").arg(num, 2, 10, QChar('0'));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool EffectComposerModel::nameExists(const QString &name) const
|
bool EffectComposerModel::nameExists(const QString &name) const
|
||||||
{
|
{
|
||||||
const QString effectsDir = QmlDesigner::ModelNodeOperations::getEffectsDefaultDirectory();
|
const QString effectsDir = QmlDesigner::ModelNodeOperations::getEffectsDefaultDirectory();
|
||||||
const QString path = effectsDir + '/' + "%1" + ".qep";
|
const QString path = !m_compositionPath.isEmpty() ? m_compositionPath.parentDir().pathAppended("%1.qep").toString()
|
||||||
|
: effectsDir + '/' + "%1" + ".qep";
|
||||||
|
|
||||||
return QFile::exists(path.arg(name));
|
return QFile::exists(path.arg(name));
|
||||||
}
|
}
|
||||||
@@ -947,7 +949,10 @@ void EffectComposerModel::saveComposition(const QString &name)
|
|||||||
}
|
}
|
||||||
|
|
||||||
const QString effectsAssetsDir = QmlDesigner::ModelNodeOperations::getEffectsDefaultDirectory();
|
const QString effectsAssetsDir = QmlDesigner::ModelNodeOperations::getEffectsDefaultDirectory();
|
||||||
const QString path = effectsAssetsDir + '/' + name + ".qep";
|
|
||||||
|
const QString path = !m_compositionPath.isEmpty() ? m_compositionPath.parentDir().pathAppended(name + ".qep").toString()
|
||||||
|
: effectsAssetsDir + '/' + name + ".qep";
|
||||||
|
|
||||||
auto saveFile = QFile(path);
|
auto saveFile = QFile(path);
|
||||||
if (!saveFile.open(QIODevice::WriteOnly)) {
|
if (!saveFile.open(QIODevice::WriteOnly)) {
|
||||||
QString error = QString("Error: Couldn't save composition file: '%1'").arg(path);
|
QString error = QString("Error: Couldn't save composition file: '%1'").arg(path);
|
||||||
@@ -977,7 +982,9 @@ void EffectComposerModel::saveComposition(const QString &name)
|
|||||||
|
|
||||||
saveFile.write(jsonDoc.toJson());
|
saveFile.write(jsonDoc.toJson());
|
||||||
saveFile.close();
|
saveFile.close();
|
||||||
|
|
||||||
setCurrentComposition(name);
|
setCurrentComposition(name);
|
||||||
|
setCompositionPath(Utils::FilePath::fromString(path));
|
||||||
|
|
||||||
saveResources(name);
|
saveResources(name);
|
||||||
setHasUnsavedChanges(false);
|
setHasUnsavedChanges(false);
|
||||||
@@ -988,7 +995,9 @@ void EffectComposerModel::openComposition(const QString &path)
|
|||||||
clear(true);
|
clear(true);
|
||||||
|
|
||||||
const QString effectName = QFileInfo(path).baseName();
|
const QString effectName = QFileInfo(path).baseName();
|
||||||
|
|
||||||
setCurrentComposition(effectName);
|
setCurrentComposition(effectName);
|
||||||
|
setCompositionPath(Utils::FilePath::fromString(path));
|
||||||
|
|
||||||
QFile compFile(path);
|
QFile compFile(path);
|
||||||
if (!compFile.open(QIODevice::ReadOnly)) {
|
if (!compFile.open(QIODevice::ReadOnly)) {
|
||||||
@@ -2044,6 +2053,19 @@ void EffectComposerModel::setCurrentComposition(const QString &newCurrentComposi
|
|||||||
emit currentCompositionChanged();
|
emit currentCompositionChanged();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Utils::FilePath EffectComposerModel::compositionPath() const
|
||||||
|
{
|
||||||
|
return m_compositionPath;
|
||||||
|
}
|
||||||
|
|
||||||
|
void EffectComposerModel::setCompositionPath(const Utils::FilePath &newCompositionPath)
|
||||||
|
{
|
||||||
|
if (m_compositionPath == newCompositionPath)
|
||||||
|
return;
|
||||||
|
|
||||||
|
m_compositionPath = newCompositionPath;
|
||||||
|
}
|
||||||
|
|
||||||
bool EffectComposerModel::hasUnsavedChanges() const
|
bool EffectComposerModel::hasUnsavedChanges() const
|
||||||
{
|
{
|
||||||
return m_hasUnsavedChanges;
|
return m_hasUnsavedChanges;
|
||||||
|
@@ -105,6 +105,9 @@ public:
|
|||||||
QString currentComposition() const;
|
QString currentComposition() const;
|
||||||
void setCurrentComposition(const QString &newCurrentComposition);
|
void setCurrentComposition(const QString &newCurrentComposition);
|
||||||
|
|
||||||
|
Utils::FilePath compositionPath() const;
|
||||||
|
void setCompositionPath(const Utils::FilePath &newCompositionPath);
|
||||||
|
|
||||||
bool hasUnsavedChanges() const;
|
bool hasUnsavedChanges() const;
|
||||||
void setHasUnsavedChanges(bool val);
|
void setHasUnsavedChanges(bool val);
|
||||||
|
|
||||||
@@ -226,6 +229,7 @@ private:
|
|||||||
QTimer m_rebakeTimer;
|
QTimer m_rebakeTimer;
|
||||||
int m_extraMargin = 0;
|
int m_extraMargin = 0;
|
||||||
QString m_effectTypePrefix;
|
QString m_effectTypePrefix;
|
||||||
|
Utils::FilePath m_compositionPath;
|
||||||
|
|
||||||
const QRegularExpression m_spaceReg = QRegularExpression("\\s+");
|
const QRegularExpression m_spaceReg = QRegularExpression("\\s+");
|
||||||
};
|
};
|
||||||
|
Reference in New Issue
Block a user