From 790757a8e8092e490bb6455a7ce290b35138fe50 Mon Sep 17 00:00:00 2001 From: Christian Stenger Date: Mon, 17 Aug 2020 17:41:42 +0200 Subject: [PATCH] AutoTest: Fix persisting of check states Persistent settings cannot handle QVariantHash and when reading the check state the meta type system seems to have the need to have used the check state already before, otherwise it will fail to convert until it uses it. This happened e.g. when re-opening a project that had former check states stored inside the project settings directly from the Welcome page after starting QC. Amends df49d6e40df47. Change-Id: Id2b85373c151efb5890fe5fb7392bdbc11adda50 Reviewed-by: Eike Ziller Reviewed-by: David Schulz --- src/plugins/autotest/autotestplugin.cpp | 2 ++ src/plugins/autotest/itemdatacache.h | 6 +++--- src/plugins/autotest/testprojectsettings.cpp | 5 ++--- 3 files changed, 7 insertions(+), 6 deletions(-) diff --git a/src/plugins/autotest/autotestplugin.cpp b/src/plugins/autotest/autotestplugin.cpp index 9e01a295ced..bf0b3e70197 100644 --- a/src/plugins/autotest/autotestplugin.cpp +++ b/src/plugins/autotest/autotestplugin.cpp @@ -118,6 +118,8 @@ AutotestPlugin::AutotestPlugin() qRegisterMetaType(); qRegisterMetaType(); qRegisterMetaType(); + // warm up meta type system to be able to read Qt::CheckState with persistent settings + qRegisterMetaType(); } AutotestPlugin::~AutotestPlugin() diff --git a/src/plugins/autotest/itemdatacache.h b/src/plugins/autotest/itemdatacache.h index ae5569075b6..6db21388421 100644 --- a/src/plugins/autotest/itemdatacache.h +++ b/src/plugins/autotest/itemdatacache.h @@ -58,15 +58,15 @@ public: void clear() { m_cache.clear(); } bool isEmpty() const { return m_cache.isEmpty(); } - QVariantHash toSettings() const + QVariantMap toSettings() const { - QVariantHash result; + QVariantMap result; for (auto it = m_cache.cbegin(), end = m_cache.cend(); it != end; ++it) result.insert(it.key(), QVariant::fromValue(it.value().value)); return result; } - void fromSettings(const QVariantHash &stored) + void fromSettings(const QVariantMap &stored) { m_cache.clear(); for (auto it = stored.cbegin(), end = stored.cend(); it != end; ++it) diff --git a/src/plugins/autotest/testprojectsettings.cpp b/src/plugins/autotest/testprojectsettings.cpp index cfb3b60e31f..61a2c99b4de 100644 --- a/src/plugins/autotest/testprojectsettings.cpp +++ b/src/plugins/autotest/testprojectsettings.cpp @@ -94,7 +94,7 @@ void TestProjectSettings::load() const QVariant runAfterBuild = m_project->namedSettings(SK_RUN_AFTER_BUILD); m_runAfterBuild = runAfterBuild.isValid() ? RunAfterBuildMode(runAfterBuild.toInt()) : RunAfterBuildMode::None; - m_checkStateCache.fromSettings(m_project->namedSettings(SK_CHECK_STATES).toHash()); + m_checkStateCache.fromSettings(m_project->namedSettings(SK_CHECK_STATES).toMap()); } void TestProjectSettings::save() @@ -106,8 +106,7 @@ void TestProjectSettings::save() activeFrameworks.insert(it.key()->id().toString(), it.value()); m_project->setNamedSettings(SK_ACTIVE_FRAMEWORKS, activeFrameworks); m_project->setNamedSettings(SK_RUN_AFTER_BUILD, int(m_runAfterBuild)); - if (!m_checkStateCache.isEmpty()) - m_project->setNamedSettings(SK_CHECK_STATES, m_checkStateCache.toSettings()); + m_project->setNamedSettings(SK_CHECK_STATES, m_checkStateCache.toSettings()); } } // namespace Internal