forked from qt-creator/qt-creator
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>
This commit is contained in:
@@ -44,7 +44,7 @@ QColorDialog *BackgroundColorSelection::createColorDialog(QWidget *parent,
|
|||||||
|
|
||||||
QObject::connect(dialog, &QColorDialog::currentColorChanged, dialog,
|
QObject::connect(dialog, &QColorDialog::currentColorChanged, dialog,
|
||||||
[actionType, view](const QColor &color) {
|
[actionType, view](const QColor &color) {
|
||||||
Edit3DViewConfig::setColor(view, actionType, color);
|
Edit3DViewConfig::setColors(view, actionType, {color});
|
||||||
});
|
});
|
||||||
|
|
||||||
QObject::connect(dialog, &QColorDialog::colorSelected, dialog,
|
QObject::connect(dialog, &QColorDialog::colorSelected, dialog,
|
||||||
@@ -52,13 +52,13 @@ QColorDialog *BackgroundColorSelection::createColorDialog(QWidget *parent,
|
|||||||
if (colorSelected)
|
if (colorSelected)
|
||||||
colorSelected();
|
colorSelected();
|
||||||
|
|
||||||
Edit3DViewConfig::saveColor(key, color);
|
Edit3DViewConfig::saveColors(key, {color});
|
||||||
});
|
});
|
||||||
|
|
||||||
if (Edit3DViewConfig::isColorValid(oldColorConfig)) {
|
if (Edit3DViewConfig::colorsValid(oldColorConfig)) {
|
||||||
QObject::connect(dialog, &QColorDialog::rejected, dialog,
|
QObject::connect(dialog, &QColorDialog::rejected, dialog,
|
||||||
[actionType, oldColorConfig, view]() {
|
[actionType, oldColorConfig, view]() {
|
||||||
Edit3DViewConfig::setColor(view, actionType, oldColorConfig);
|
Edit3DViewConfig::setColors(view, actionType, oldColorConfig);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -389,12 +389,12 @@ Edit3DAction *Edit3DView::createResetColorAction(QAction *syncBackgroundColorAct
|
|||||||
|
|
||||||
auto operation = [this, syncBackgroundColorAction](const SelectionContext &) {
|
auto operation = [this, syncBackgroundColorAction](const SelectionContext &) {
|
||||||
QList<QColor> bgColors = {QRgb(0x222222), QRgb(0x999999)};
|
QList<QColor> bgColors = {QRgb(0x222222), QRgb(0x999999)};
|
||||||
Edit3DViewConfig::setColor(this, View3DActionType::SelectBackgroundColor, bgColors);
|
Edit3DViewConfig::setColors(this, View3DActionType::SelectBackgroundColor, bgColors);
|
||||||
Edit3DViewConfig::saveColor(DesignerSettingsKey::EDIT3DVIEW_BACKGROUND_COLOR, bgColors);
|
Edit3DViewConfig::saveColors(DesignerSettingsKey::EDIT3DVIEW_BACKGROUND_COLOR, bgColors);
|
||||||
|
|
||||||
QColor gridColor{0xaaaaaa};
|
QColor gridColor{0xaaaaaa};
|
||||||
Edit3DViewConfig::setColor(this, View3DActionType::SelectGridColor, gridColor);
|
Edit3DViewConfig::setColors(this, View3DActionType::SelectGridColor, {gridColor});
|
||||||
Edit3DViewConfig::saveColor(DesignerSettingsKey::EDIT3DVIEW_GRID_COLOR, gridColor);
|
Edit3DViewConfig::saveColors(DesignerSettingsKey::EDIT3DVIEW_GRID_COLOR, {gridColor});
|
||||||
|
|
||||||
if (syncBackgroundColorAction->isChecked()) {
|
if (syncBackgroundColorAction->isChecked()) {
|
||||||
Edit3DViewConfig::set(this, View3DActionType::SyncBackgroundColor, false);
|
Edit3DViewConfig::set(this, View3DActionType::SyncBackgroundColor, false);
|
||||||
|
@@ -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)
|
setVariant(view, type, QVariant::fromValue(colorConfig));
|
||||||
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));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename T>
|
template <typename T>
|
||||||
@@ -47,7 +39,7 @@ public:
|
|||||||
setVariant(view, type, QVariant::fromValue(value));
|
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) {
|
QStringList colorNames = Utils::transform(colorConfig, [](const QColor &color) {
|
||||||
return color.name();
|
return color.name();
|
||||||
@@ -56,12 +48,7 @@ public:
|
|||||||
saveVariant(key, QVariant::fromValue(colorNames));
|
saveVariant(key, QVariant::fromValue(colorNames));
|
||||||
}
|
}
|
||||||
|
|
||||||
static void saveColor(const QByteArray &key, const QColor &color)
|
static bool colorsValid(const QList<QColor> &colorConfig) { return !colorConfig.isEmpty(); }
|
||||||
{
|
|
||||||
saveVariant(key, QVariant::fromValue(color.name()));
|
|
||||||
}
|
|
||||||
|
|
||||||
static bool isColorValid(const QList<QColor> &colorConfig) { return !colorConfig.isEmpty(); }
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
static void setVariant(AbstractView *view, View3DActionType type, const QVariant &colorConfig)
|
static void setVariant(AbstractView *view, View3DActionType type, const QVariant &colorConfig)
|
||||||
|
@@ -194,24 +194,18 @@ Item {
|
|||||||
function updateViewStates(viewStates)
|
function updateViewStates(viewStates)
|
||||||
{
|
{
|
||||||
if ("selectBackgroundColor" in viewStates) {
|
if ("selectBackgroundColor" in viewStates) {
|
||||||
if (Array.isArray(viewStates.selectBackgroundColor)) {
|
var colors = viewStates.selectBackgroundColor
|
||||||
var colors = viewStates.selectBackgroundColor
|
if (colors.length === 1) {
|
||||||
if (colors.length === 1) {
|
backgroundGradientColorStart = colors[0];
|
||||||
backgroundGradientColorStart = colors[0];
|
backgroundGradientColorEnd = colors[0];
|
||||||
backgroundGradientColorEnd = colors[0];
|
|
||||||
} else {
|
|
||||||
backgroundGradientColorStart = colors[0];
|
|
||||||
backgroundGradientColorEnd = colors[1];
|
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
var color = viewStates.selectBackgroundColor
|
backgroundGradientColorStart = colors[0];
|
||||||
backgroundGradientColorStart = color;
|
backgroundGradientColorEnd = colors[1];
|
||||||
backgroundGradientColorEnd = color;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if ("selectGridColor" in viewStates)
|
if ("selectGridColor" in viewStates && viewStates.selectGridColor.length === 1)
|
||||||
viewRoot.gridColor = viewStates.selectGridColor
|
viewRoot.gridColor = viewStates.selectGridColor[0]
|
||||||
}
|
}
|
||||||
|
|
||||||
// If resetToDefault is true, tool states not specifically set to anything will be reset to
|
// If resetToDefault is true, tool states not specifically set to anything will be reset to
|
||||||
|
@@ -921,9 +921,9 @@ void Qt5InformationNodeInstanceServer::updateActiveSceneToEditView3D([[maybe_unu
|
|||||||
if (toolStates.contains("syncBackgroundColor")) {
|
if (toolStates.contains("syncBackgroundColor")) {
|
||||||
bool sync = toolStates["syncBackgroundColor"].toBool();
|
bool sync = toolStates["syncBackgroundColor"].toBool();
|
||||||
if (sync) {
|
if (sync) {
|
||||||
QColor color = helper->sceneEnvironmentColor(sceneId);
|
QList<QColor> colors = {helper->sceneEnvironmentColor(sceneId)};
|
||||||
View3DActionCommand cmd(View3DActionType::SelectBackgroundColor,
|
View3DActionCommand cmd(View3DActionType::SelectBackgroundColor,
|
||||||
QVariant::fromValue(color));
|
QVariant::fromValue(colors));
|
||||||
view3DAction(cmd);
|
view3DAction(cmd);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -2274,9 +2274,10 @@ void Qt5InformationNodeInstanceServer::setSceneEnvironmentColor(const PropertyVa
|
|||||||
|
|
||||||
if (toolStates.contains("syncBackgroundColor")) {
|
if (toolStates.contains("syncBackgroundColor")) {
|
||||||
bool sync = toolStates["syncBackgroundColor"].toBool();
|
bool sync = toolStates["syncBackgroundColor"].toBool();
|
||||||
|
QList<QColor> colors = {color};
|
||||||
if (sync) {
|
if (sync) {
|
||||||
View3DActionCommand cmd(View3DActionType::SelectBackgroundColor,
|
View3DActionCommand cmd(View3DActionType::SelectBackgroundColor,
|
||||||
QVariant::fromValue(color));
|
QVariant::fromValue(colors));
|
||||||
view3DAction(cmd);
|
view3DAction(cmd);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user