From a292a18c38482e0899d18427b9cd3f9bcb74e79d Mon Sep 17 00:00:00 2001 From: hjk Date: Wed, 17 Mar 2021 07:42:50 +0100 Subject: [PATCH] Utils: Shortcut Aspect::isDirty for aspects that were never visible Also do not access Aspect::volatileValue if aspect was never shown In this case, user-induced unsaved changes cannot exist. This also avoids QTC_ASSERT in the volatileValue() implementations in these cases. Silences the contained QTC_ASSERTs properly and avoids returning a null-variant that's likely not identical to the default value. Change-Id: Idba89997d0b0b4f9b7dcac0881afe36b35ccdf7c Reviewed-by: Christian Stenger --- src/libs/utils/aspects.cpp | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/src/libs/utils/aspects.cpp b/src/libs/utils/aspects.cpp index c05c5c3679f..a793065cd4c 100644 --- a/src/libs/utils/aspects.cpp +++ b/src/libs/utils/aspects.cpp @@ -406,7 +406,8 @@ void BaseAspect::addToLayout(LayoutBuilder &) void BaseAspect::apply() { QTC_CHECK(!d->m_autoApply); - setValue(volatileValue()); + if (isDirty()) + setValue(volatileValue()); } /*! @@ -418,7 +419,8 @@ void BaseAspect::apply() void BaseAspect::cancel() { QTC_CHECK(!d->m_autoApply); - setVolatileValue(d->m_value); + if (!d->m_subWidgets.isEmpty()) + setVolatileValue(d->m_value); } void BaseAspect::finish() @@ -434,6 +436,9 @@ bool BaseAspect::hasAction() const bool BaseAspect::isDirty() const { QTC_CHECK(!isAutoApply()); + // Aspects that were never shown cannot contain unsaved user changes. + if (d->m_subWidgets.isEmpty()) + return false; return volatileValue() != d->m_value; }