QmlDesigner: Avoid accidentally changing gradients

The designer was changing gradient stops if the item "selected"
in the edit mode has a gradient. The first gradient stop was set to white.
There is still an issue with setting up the gradient editor in this case,
but the file is not changed anymore.

Task-number: QTCREATORBUG-18421
Change-Id: Ifd6829590a8a7b5217c53f49054f8738bdb71563
Reviewed-by: Tim Jenssen <tim.jenssen@qt.io>
This commit is contained in:
Thomas Hartmann
2017-06-22 17:10:49 +02:00
parent 3944c73c51
commit 7062fd5138
4 changed files with 40 additions and 17 deletions

View File

@@ -26,6 +26,7 @@
#include "gradientmodel.h"
#include "qmlanchorbindingproxy.h"
#include "propertyeditorview.h"
#include <nodeproperty.h>
#include <nodelistproperty.h>
@@ -35,7 +36,7 @@
#include <rewritertransaction.h>
GradientModel::GradientModel(QObject *parent) :
QAbstractListModel(parent), m_lock(false)
QAbstractListModel(parent), m_locked(false)
{
}
@@ -93,7 +94,7 @@ QVariant GradientModel::data(const QModelIndex &index, int role) const
int GradientModel::addStop(qreal position, const QColor &color)
{
if (m_lock)
if (m_locked)
return -1;
if (!m_itemNode.isValid() || gradientPropertyName().isEmpty())
@@ -131,7 +132,7 @@ int GradientModel::addStop(qreal position, const QColor &color)
void GradientModel::addGradient()
{
if (m_lock)
if (m_locked)
return;
if (!m_itemNode.isValid() || gradientPropertyName().isEmpty())
@@ -174,7 +175,7 @@ void GradientModel::addGradient()
void GradientModel::setColor(int index, const QColor &color)
{
if (m_lock)
if (locked())
return;
if (!m_itemNode.modelNode().isSelected())
@@ -191,7 +192,7 @@ void GradientModel::setColor(int index, const QColor &color)
void GradientModel::setPosition(int index, qreal positition)
{
if (m_lock)
if (locked())
return;
if (index < rowCount()) {
@@ -266,12 +267,12 @@ void GradientModel::deleteGradient()
void GradientModel::lock()
{
m_lock = true;
m_locked = true;
}
void GradientModel::unlock()
{
m_lock = false;
m_locked = false;
}
void GradientModel::registerDeclarativeType()
@@ -281,11 +282,11 @@ void GradientModel::registerDeclarativeType()
void GradientModel::setupModel()
{
m_lock = true;
m_locked = true;
beginResetModel();
endResetModel();
m_lock = false;
m_locked = false;
}
void GradientModel::setAnchorBackend(const QVariant &anchorBackend)
@@ -300,12 +301,12 @@ void GradientModel::setAnchorBackend(const QVariant &anchorBackend)
setupModel();
m_lock = true;
m_locked = true;
emit anchorBackendChanged();
emit hasGradientChanged();
m_lock = false;
m_locked = false;
}
QString GradientModel::gradientPropertyName() const
@@ -323,3 +324,16 @@ bool GradientModel::hasGradient() const
return m_itemNode.isValid()
&& m_itemNode.modelNode().hasProperty(gradientPropertyName().toUtf8());
}
bool GradientModel::locked() const
{
if (m_locked)
return true;
QmlDesigner::PropertyEditorView *view = qobject_cast<QmlDesigner::PropertyEditorView*>(m_itemNode.view());
if (view && view->locked())
return true;
return false;
}

View File

@@ -76,11 +76,12 @@ private:
QString gradientPropertyName() const;
void setGradientPropertyName(const QString &name);
bool hasGradient() const;
bool locked() const;
private:
QmlDesigner::QmlItemNode m_itemNode;
QString m_gradientPropertyName;
bool m_lock;
bool m_locked;
};

View File

@@ -135,7 +135,7 @@ void PropertyEditorView::changeValue(const QString &name)
if (propertyName.isNull())
return;
if (m_locked)
if (locked())
return;
if (propertyName == "className")
@@ -231,7 +231,7 @@ void PropertyEditorView::changeExpression(const QString &propertyName)
if (name.isNull())
return;
if (m_locked)
if (locked())
return;
if (!m_selectedNode.isValid())
@@ -306,7 +306,7 @@ void PropertyEditorView::exportPopertyAsAlias(const QString &name)
if (name.isNull())
return;
if (m_locked)
if (locked())
return;
if (!m_selectedNode.isValid())
@@ -340,7 +340,7 @@ void PropertyEditorView::removeAliasExport(const QString &name)
if (name.isNull())
return;
if (m_locked)
if (locked())
return;
if (!m_selectedNode.isValid())
@@ -362,6 +362,11 @@ void PropertyEditorView::removeAliasExport(const QString &name)
}
}
bool PropertyEditorView::locked() const
{
return m_locked;
}
void PropertyEditorView::updateSize()
{
if (!m_qmlBackEndForCurrentType)
@@ -527,7 +532,6 @@ void PropertyEditorView::modelAttached(Model *model)
m_locked = true;
resetView();
if (!m_setupCompleted) {
m_singleShotTimer->setSingleShot(true);
m_singleShotTimer->setInterval(100);
@@ -536,6 +540,8 @@ void PropertyEditorView::modelAttached(Model *model)
}
m_locked = false;
resetView();
}
void PropertyEditorView::modelAboutToBeDetached(Model *model)

View File

@@ -92,6 +92,8 @@ public:
void exportPopertyAsAlias(const QString &name);
void removeAliasExport(const QString &name);
bool locked() const;
protected:
void timerEvent(QTimerEvent *event) override;
void setupPane(const TypeName &typeName);