QmlDesigner: Fix color dialog removing property

Fix color dialog removing color property after rejecting the dialog when
color is binding.

Task-number: QDS-4826
Change-Id: I4cae3b70b18a0131ac555d5b8502d05de5409070
Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
Reviewed-by: Thomas Hartmann <thomas.hartmann@qt.io>
This commit is contained in:
Henning Gruendl
2021-09-03 17:43:44 +02:00
committed by Henning Gründl
parent 1393aa8505
commit 6d3248e669
2 changed files with 19 additions and 10 deletions

View File

@@ -35,6 +35,7 @@
#include "nodemetainfo.h"
#include "qmlitemnode.h"
#include "bindingproperty.h"
#include <qmldesignerplugin.h>
#include <abstractaction.h>
#include <designeractionmanager.h>
@@ -162,14 +163,17 @@ void ColorTool::itemsAboutToRemoved(const QList<FormEditorItem*> &removedItemLis
void ColorTool::selectedItemsChanged(const QList<FormEditorItem*> &itemList)
{
if (m_colorDialog.data()
&& m_oldColor.isValid())
if (m_colorDialog.data() && m_oldColor.isValid())
m_formEditorItem->qmlItemNode().setVariantProperty("color", m_oldColor);
if (!itemList.isEmpty()
&& itemList.constFirst()->qmlItemNode().modelNode().metaInfo().hasProperty("color")) {
m_formEditorItem = itemList.constFirst();
m_oldColor = m_formEditorItem->qmlItemNode().modelValue("color").value<QColor>();
if (m_formEditorItem->qmlItemNode().hasBindingProperty("color"))
m_oldExpression = m_formEditorItem->qmlItemNode().modelNode().bindingProperty("color").expression();
else
m_oldColor = m_formEditorItem->qmlItemNode().modelValue("color").value<QColor>();
if (m_colorDialog.isNull()) {
m_colorDialog = new QColorDialog(view()->formEditorWidget()->parentWidget());
@@ -217,27 +221,31 @@ QString ColorTool::name() const
void ColorTool::colorDialogAccepted()
{
m_oldExpression.clear();
view()->changeToSelectionTool();
}
void ColorTool::colorDialogRejected()
{
if (m_formEditorItem) {
if (m_oldColor.isValid())
m_formEditorItem->qmlItemNode().setVariantProperty("color", m_oldColor);
else
m_formEditorItem->qmlItemNode().removeProperty("color");
if (!m_oldExpression.isEmpty())
m_formEditorItem->qmlItemNode().setBindingProperty("color", m_oldExpression);
else {
if (m_oldColor.isValid())
m_formEditorItem->qmlItemNode().setVariantProperty("color", m_oldColor);
else
m_formEditorItem->qmlItemNode().removeProperty("color");
}
}
m_oldExpression.clear();
view()->changeToSelectionTool();
}
void ColorTool::currentColorChanged(const QColor &color)
{
if (m_formEditorItem) {
if (m_formEditorItem)
m_formEditorItem->qmlItemNode().setVariantProperty("color", color);
}
}
}

View File

@@ -84,6 +84,7 @@ private:
QPointer<QColorDialog> m_colorDialog;
FormEditorItem *m_formEditorItem = nullptr;
QColor m_oldColor;
QString m_oldExpression;
};
}