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 df49d6e40d.

Change-Id: Id2b85373c151efb5890fe5fb7392bdbc11adda50
Reviewed-by: Eike Ziller <eike.ziller@qt.io>
Reviewed-by: David Schulz <david.schulz@qt.io>
This commit is contained in:
Christian Stenger
2020-08-17 17:41:42 +02:00
parent abffbe3806
commit 790757a8e8
3 changed files with 7 additions and 6 deletions

View File

@@ -118,6 +118,8 @@ AutotestPlugin::AutotestPlugin()
qRegisterMetaType<TestResult>();
qRegisterMetaType<TestTreeItem *>();
qRegisterMetaType<TestCodeLocationAndType>();
// warm up meta type system to be able to read Qt::CheckState with persistent settings
qRegisterMetaType<Qt::CheckState>();
}
AutotestPlugin::~AutotestPlugin()

View File

@@ -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)

View File

@@ -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