summaryrefslogtreecommitdiff
path: root/src/plugins
diff options
context:
space:
mode:
authorSamuel Ghinet <samuel.ghinet@qt.io>2022-12-15 16:38:38 +0200
committerSamuel Ghinet <samuel.ghinet@qt.io>2022-12-16 13:59:25 +0000
commit965fa9450c3e3424e5e9e4a1bec3612a66594059 (patch)
tree201ae4f2f91fe8241fa6763d576dd3f0db051f19 /src/plugins
parentbb37d782ca9fa4ccb56957a6273822ae393fbebd (diff)
downloadqt-creator-965fa9450c3e3424e5e9e4a1bec3612a66594059.tar.gz
QmlDesigner: Fix cancel button not reverting background color
In the 3D view, when the user experiments with different background colors, but then decides to cancel, upon pressing the Cancel button and closing the dialog, the last color picked remained set. This happened on Qt6.4 and not on Qt6.3. The reason for this was the usage of Array.isArray() on an object exposed from C++ to QML of type QVariant that could hold either a QList<QColor> or a a QColor. It looks like there is no supported way from qml/js to see if a variable is a list / sequence or a scalar. So the best way would be to always work with QList<QColor> even though in most cases only one single QColor is being used. Task-number: QDS-8143 Change-Id: Ia7e8e1facad24439ad244305c213bb12e286105b Reviewed-by: Miikka Heikkinen <miikka.heikkinen@qt.io> Reviewed-by: Mahmoud Badri <mahmoud.badri@qt.io>
Diffstat (limited to 'src/plugins')
-rw-r--r--src/plugins/qmldesigner/components/edit3d/backgroundcolorselection.cpp8
-rw-r--r--src/plugins/qmldesigner/components/edit3d/edit3dview.cpp8
-rw-r--r--src/plugins/qmldesigner/components/edit3d/edit3dviewconfig.h21
3 files changed, 12 insertions, 25 deletions
diff --git a/src/plugins/qmldesigner/components/edit3d/backgroundcolorselection.cpp b/src/plugins/qmldesigner/components/edit3d/backgroundcolorselection.cpp
index 07d65cb3c3..42f5bc45dd 100644
--- a/src/plugins/qmldesigner/components/edit3d/backgroundcolorselection.cpp
+++ b/src/plugins/qmldesigner/components/edit3d/backgroundcolorselection.cpp
@@ -44,7 +44,7 @@ QColorDialog *BackgroundColorSelection::createColorDialog(QWidget *parent,
QObject::connect(dialog, &QColorDialog::currentColorChanged, dialog,
[actionType, view](const QColor &color) {
- Edit3DViewConfig::setColor(view, actionType, color);
+ Edit3DViewConfig::setColors(view, actionType, {color});
});
QObject::connect(dialog, &QColorDialog::colorSelected, dialog,
@@ -52,13 +52,13 @@ QColorDialog *BackgroundColorSelection::createColorDialog(QWidget *parent,
if (colorSelected)
colorSelected();
- Edit3DViewConfig::saveColor(key, color);
+ Edit3DViewConfig::saveColors(key, {color});
});
- if (Edit3DViewConfig::isColorValid(oldColorConfig)) {
+ if (Edit3DViewConfig::colorsValid(oldColorConfig)) {
QObject::connect(dialog, &QColorDialog::rejected, dialog,
[actionType, oldColorConfig, view]() {
- Edit3DViewConfig::setColor(view, actionType, oldColorConfig);
+ Edit3DViewConfig::setColors(view, actionType, oldColorConfig);
});
}
diff --git a/src/plugins/qmldesigner/components/edit3d/edit3dview.cpp b/src/plugins/qmldesigner/components/edit3d/edit3dview.cpp
index b7efef60d6..75c2138ffc 100644
--- a/src/plugins/qmldesigner/components/edit3d/edit3dview.cpp
+++ b/src/plugins/qmldesigner/components/edit3d/edit3dview.cpp
@@ -389,12 +389,12 @@ Edit3DAction *Edit3DView::createResetColorAction(QAction *syncBackgroundColorAct
auto operation = [this, syncBackgroundColorAction](const SelectionContext &) {
QList<QColor> bgColors = {QRgb(0x222222), QRgb(0x999999)};
- Edit3DViewConfig::setColor(this, View3DActionType::SelectBackgroundColor, bgColors);
- Edit3DViewConfig::saveColor(DesignerSettingsKey::EDIT3DVIEW_BACKGROUND_COLOR, bgColors);
+ Edit3DViewConfig::setColors(this, View3DActionType::SelectBackgroundColor, bgColors);
+ Edit3DViewConfig::saveColors(DesignerSettingsKey::EDIT3DVIEW_BACKGROUND_COLOR, bgColors);
QColor gridColor{0xaaaaaa};
- Edit3DViewConfig::setColor(this, View3DActionType::SelectGridColor, gridColor);
- Edit3DViewConfig::saveColor(DesignerSettingsKey::EDIT3DVIEW_GRID_COLOR, gridColor);
+ Edit3DViewConfig::setColors(this, View3DActionType::SelectGridColor, {gridColor});
+ Edit3DViewConfig::saveColors(DesignerSettingsKey::EDIT3DVIEW_GRID_COLOR, {gridColor});
if (syncBackgroundColorAction->isChecked()) {
Edit3DViewConfig::set(this, View3DActionType::SyncBackgroundColor, false);
diff --git a/src/plugins/qmldesigner/components/edit3d/edit3dviewconfig.h b/src/plugins/qmldesigner/components/edit3d/edit3dviewconfig.h
index 267e27042c..e0eba1115c 100644
--- a/src/plugins/qmldesigner/components/edit3d/edit3dviewconfig.h
+++ b/src/plugins/qmldesigner/components/edit3d/edit3dviewconfig.h
@@ -28,17 +28,9 @@ public:
});
}
- static void setColor(AbstractView *view, View3DActionType type, const QList<QColor> &colorConfig)
+ static void setColors(AbstractView *view, View3DActionType type, const QList<QColor> &colorConfig)
{
- if (colorConfig.size() == 1)
- setColor(view, type, colorConfig.at(0));
- else
- setVariant(view, type, QVariant::fromValue(colorConfig));
- }
-
- static void setColor(AbstractView *view, View3DActionType type, const QColor &color)
- {
- setVariant(view, type, QVariant::fromValue(color));
+ setVariant(view, type, QVariant::fromValue(colorConfig));
}
template <typename T>
@@ -47,7 +39,7 @@ public:
setVariant(view, type, QVariant::fromValue(value));
}
- static void saveColor(const QByteArray &key, const QList<QColor> &colorConfig)
+ static void saveColors(const QByteArray &key, const QList<QColor> &colorConfig)
{
QStringList colorNames = Utils::transform(colorConfig, [](const QColor &color) {
return color.name();
@@ -56,12 +48,7 @@ public:
saveVariant(key, QVariant::fromValue(colorNames));
}
- static void saveColor(const QByteArray &key, const QColor &color)
- {
- saveVariant(key, QVariant::fromValue(color.name()));
- }
-
- static bool isColorValid(const QList<QColor> &colorConfig) { return !colorConfig.isEmpty(); }
+ static bool colorsValid(const QList<QColor> &colorConfig) { return !colorConfig.isEmpty(); }
private:
static void setVariant(AbstractView *view, View3DActionType type, const QVariant &colorConfig)