diff options
author | Thomas Hartmann <thomas.hartmann@qt.io> | 2017-06-22 17:10:49 +0200 |
---|---|---|
committer | Thomas Hartmann <thomas.hartmann@qt.io> | 2017-06-23 08:52:36 +0000 |
commit | 7062fd5138054a7eace18322ac5ae9f086cd1dc3 (patch) | |
tree | c6917c8712e84774cc6b4a0b6d6c6bf110ec4390 | |
parent | 3944c73c512bf601d4b48552f313765cb3c722c8 (diff) | |
download | qt-creator-7062fd5138054a7eace18322ac5ae9f086cd1dc3.tar.gz |
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>
4 files changed, 40 insertions, 17 deletions
diff --git a/src/plugins/qmldesigner/components/propertyeditor/gradientmodel.cpp b/src/plugins/qmldesigner/components/propertyeditor/gradientmodel.cpp index dbb100d8a1..c1aff9dabd 100644 --- a/src/plugins/qmldesigner/components/propertyeditor/gradientmodel.cpp +++ b/src/plugins/qmldesigner/components/propertyeditor/gradientmodel.cpp @@ -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; +} diff --git a/src/plugins/qmldesigner/components/propertyeditor/gradientmodel.h b/src/plugins/qmldesigner/components/propertyeditor/gradientmodel.h index 39f1b57698..943d6ae22b 100644 --- a/src/plugins/qmldesigner/components/propertyeditor/gradientmodel.h +++ b/src/plugins/qmldesigner/components/propertyeditor/gradientmodel.h @@ -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; }; diff --git a/src/plugins/qmldesigner/components/propertyeditor/propertyeditorview.cpp b/src/plugins/qmldesigner/components/propertyeditor/propertyeditorview.cpp index b28fec7c51..fcdb04d2a2 100644 --- a/src/plugins/qmldesigner/components/propertyeditor/propertyeditorview.cpp +++ b/src/plugins/qmldesigner/components/propertyeditor/propertyeditorview.cpp @@ -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) diff --git a/src/plugins/qmldesigner/components/propertyeditor/propertyeditorview.h b/src/plugins/qmldesigner/components/propertyeditor/propertyeditorview.h index 0707397623..b9028aad3d 100644 --- a/src/plugins/qmldesigner/components/propertyeditor/propertyeditorview.h +++ b/src/plugins/qmldesigner/components/propertyeditor/propertyeditorview.h @@ -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); |