aboutsummaryrefslogtreecommitdiffstats
path: root/src/plugins/autotest
diff options
context:
space:
mode:
authorChristian Stenger <christian.stenger@qt.io>2020-07-07 10:57:38 +0200
committerChristian Stenger <christian.stenger@qt.io>2020-07-13 06:26:12 +0000
commitdf49d6e40df4784733be34ffb71274e75c97d72c (patch)
tree8c331f97c95f565abfbb20cbacc28546cf430ac6 /src/plugins/autotest
parent8c97f870b9ee42f91e296ae39c968d3d3a092fb9 (diff)
AutoTest: Persist check state to project settings
Make it easier to switch between projects and restore the former check states of the found test items if we have these information. Change-Id: I99a5357388c36aa8cce6f5f82184d6ab2a8bf6e8 Reviewed-by: David Schulz <david.schulz@qt.io>
Diffstat (limited to 'src/plugins/autotest')
-rw-r--r--src/plugins/autotest/CMakeLists.txt1
-rw-r--r--src/plugins/autotest/autotest.pro1
-rw-r--r--src/plugins/autotest/autotest.qbs1
-rw-r--r--src/plugins/autotest/itemdatacache.h87
-rw-r--r--src/plugins/autotest/testnavigationwidget.h7
-rw-r--r--src/plugins/autotest/testprojectsettings.cpp4
-rw-r--r--src/plugins/autotest/testprojectsettings.h3
-rw-r--r--src/plugins/autotest/testtreemodel.cpp11
-rw-r--r--src/plugins/autotest/testtreemodel.h37
9 files changed, 110 insertions, 42 deletions
diff --git a/src/plugins/autotest/CMakeLists.txt b/src/plugins/autotest/CMakeLists.txt
index 1ee331dc5f..18521d7608 100644
--- a/src/plugins/autotest/CMakeLists.txt
+++ b/src/plugins/autotest/CMakeLists.txt
@@ -40,6 +40,7 @@ add_qtc_plugin(AutoTest
gtest/gtesttreeitem.cpp gtest/gtesttreeitem.h
gtest/gtestvisitors.cpp gtest/gtestvisitors.h
iframeworksettings.h
+ itemdatacache.h
itestframework.cpp itestframework.h
itestparser.cpp itestparser.h
projectsettingswidget.cpp projectsettingswidget.h
diff --git a/src/plugins/autotest/autotest.pro b/src/plugins/autotest/autotest.pro
index 5d1db25e3a..a751723017 100644
--- a/src/plugins/autotest/autotest.pro
+++ b/src/plugins/autotest/autotest.pro
@@ -79,6 +79,7 @@ HEADERS += \
autotesticons.h \
autotestplugin.h \
iframeworksettings.h \
+ itemdatacache.h \
itestframework.h \
itestparser.h \
projectsettingswidget.h \
diff --git a/src/plugins/autotest/autotest.qbs b/src/plugins/autotest/autotest.qbs
index ea014bc06d..92d6853b1a 100644
--- a/src/plugins/autotest/autotest.qbs
+++ b/src/plugins/autotest/autotest.qbs
@@ -37,6 +37,7 @@ QtcPlugin {
"autotestconstants.h",
"autotestplugin.cpp",
"autotestplugin.h",
+ "itemdatacache.h",
"projectsettingswidget.cpp",
"projectsettingswidget.h",
"testcodeparser.cpp",
diff --git a/src/plugins/autotest/itemdatacache.h b/src/plugins/autotest/itemdatacache.h
new file mode 100644
index 0000000000..ae5569075b
--- /dev/null
+++ b/src/plugins/autotest/itemdatacache.h
@@ -0,0 +1,87 @@
+/****************************************************************************
+**
+** Copyright (C) 2020 The Qt Company Ltd.
+** Contact: https://www.qt.io/licensing/
+**
+** This file is part of Qt Creator.
+**
+** Commercial License Usage
+** Licensees holding valid commercial Qt licenses may use this file in
+** accordance with the commercial license agreement provided with the
+** Software or, alternatively, in accordance with the terms contained in
+** a written agreement between you and The Qt Company. For licensing terms
+** and conditions see https://www.qt.io/terms-conditions. For further
+** information use the contact form at https://www.qt.io/contact-us.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3 as published by the Free Software
+** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
+** included in the packaging of this file. Please review the following
+** information to ensure the GNU General Public License requirements will
+** be met: https://www.gnu.org/licenses/gpl-3.0.html.
+**
+****************************************************************************/
+
+#pragma once
+
+#include "testtreeitem.h"
+
+#include <utils/optional.h>
+
+#include <QVariantHash>
+
+namespace Autotest {
+namespace Internal {
+
+template<class T>
+class ItemDataCache
+{
+public:
+ void insert(TestTreeItem *item, const T &value) { m_cache[item->cacheName()] = {0, value}; }
+ void evolve()
+ {
+ auto it = m_cache.begin(), end = m_cache.end();
+ while (it != end)
+ it = it->generation++ >= maxGen ? m_cache.erase(it) : ++it;
+ }
+
+ Utils::optional<T> get(TestTreeItem *item)
+ {
+ auto entry = m_cache.find(item->cacheName());
+ if (entry == m_cache.end())
+ return Utils::nullopt;
+ entry->generation = 0;
+ return Utils::make_optional(entry->value);
+ };
+
+ void clear() { m_cache.clear(); }
+ bool isEmpty() const { return m_cache.isEmpty(); }
+
+ QVariantHash toSettings() const
+ {
+ QVariantHash 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)
+ {
+ m_cache.clear();
+ for (auto it = stored.cbegin(), end = stored.cend(); it != end; ++it)
+ m_cache[it.key()] = {0, qvariant_cast<T>(it.value())};
+ }
+
+private:
+ static constexpr int maxGen = 10;
+ struct Entry
+ {
+ int generation = 0;
+ T value;
+ };
+ QHash<QString, Entry> m_cache;
+};
+
+} // namespace Internal
+} // namespace Autotest
diff --git a/src/plugins/autotest/testnavigationwidget.h b/src/plugins/autotest/testnavigationwidget.h
index 454f893c6b..f01bb6c3d5 100644
--- a/src/plugins/autotest/testnavigationwidget.h
+++ b/src/plugins/autotest/testnavigationwidget.h
@@ -25,10 +25,9 @@
#pragma once
+#include "itemdatacache.h"
#include "testrunner.h"
-#include "testtreemodel.h"
-
#include <coreplugin/inavigationwidgetfactory.h>
#include <utils/navigationtreeview.h>
@@ -49,8 +48,12 @@ class ProgressIndicator;
}
namespace Autotest {
+
+class TestTreeModel;
+
namespace Internal {
+class TestTreeSortFilterModel;
class TestTreeView;
class TestNavigationWidget : public QWidget
diff --git a/src/plugins/autotest/testprojectsettings.cpp b/src/plugins/autotest/testprojectsettings.cpp
index 2726bf9566..cfb3b60e31 100644
--- a/src/plugins/autotest/testprojectsettings.cpp
+++ b/src/plugins/autotest/testprojectsettings.cpp
@@ -35,6 +35,7 @@ namespace Internal {
static const char SK_ACTIVE_FRAMEWORKS[] = "AutoTest.ActiveFrameworks";
static const char SK_RUN_AFTER_BUILD[] = "AutoTest.RunAfterBuild";
+static const char SK_CHECK_STATES[] = "AutoTest.CheckStates";
static Q_LOGGING_CATEGORY(LOG, "qtc.autotest.frameworkmanager", QtWarningMsg)
@@ -93,6 +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());
}
void TestProjectSettings::save()
@@ -104,6 +106,8 @@ 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());
}
} // namespace Internal
diff --git a/src/plugins/autotest/testprojectsettings.h b/src/plugins/autotest/testprojectsettings.h
index a4ce6b34fc..7f7332197e 100644
--- a/src/plugins/autotest/testprojectsettings.h
+++ b/src/plugins/autotest/testprojectsettings.h
@@ -26,6 +26,7 @@
#pragma once
#include "testsettings.h"
+#include "testtreemodel.h"
#include <projectexplorer/project.h>
@@ -50,6 +51,7 @@ public:
{ m_activeTestFrameworks = enabledFrameworks; }
QMap<ITestFramework *, bool> activeFrameworks() const { return m_activeTestFrameworks; }
void activateFramework(const Utils::Id &id, bool activate);
+ Internal::ItemDataCache<Qt::CheckState> *checkStateCache() { return &m_checkStateCache; }
private:
void load();
void save();
@@ -58,6 +60,7 @@ private:
bool m_useGlobalSettings = true;
RunAfterBuildMode m_runAfterBuild = RunAfterBuildMode::None;
QMap<ITestFramework *, bool> m_activeTestFrameworks;
+ Internal::ItemDataCache<Qt::CheckState> m_checkStateCache;
};
} // namespace Internal
diff --git a/src/plugins/autotest/testtreemodel.cpp b/src/plugins/autotest/testtreemodel.cpp
index 95330d5fc9..b42e031148 100644
--- a/src/plugins/autotest/testtreemodel.cpp
+++ b/src/plugins/autotest/testtreemodel.cpp
@@ -91,7 +91,8 @@ void TestTreeModel::setupParsingConnections()
connect(sm, &SessionManager::startupProjectChanged, [this](Project *project) {
synchronizeTestFrameworks(); // we might have project settings
m_parser->onStartupProjectChanged(project);
- m_checkStateCache.clear(); // TODO persist to project settings?
+ m_checkStateCache = project ? AutotestPlugin::projectSettings(project)->checkStateCache()
+ : nullptr;
});
CppTools::CppModelManager *cppMM = CppTools::CppModelManager::instance();
@@ -294,12 +295,12 @@ void TestTreeModel::rebuild(const QList<Utils::Id> &frameworkIds)
void TestTreeModel::updateCheckStateCache()
{
- m_checkStateCache.evolve();
+ m_checkStateCache->evolve();
for (Utils::TreeItem *rootNode : *rootItem()) {
rootNode->forAllChildren([this](Utils::TreeItem *child) {
auto childItem = static_cast<TestTreeItem *>(child);
- m_checkStateCache.insert(childItem, childItem->checked());
+ m_checkStateCache->insert(childItem, childItem->checked());
});
}
}
@@ -425,7 +426,7 @@ void TestTreeModel::insertItemInParent(TestTreeItem *item, TestTreeItem *root, b
delete item;
} else {
// restore former check state if available
- Utils::optional<Qt::CheckState> cached = m_checkStateCache.get(item);
+ Utils::optional<Qt::CheckState> cached = m_checkStateCache->get(item);
if (cached.has_value())
item->setData(0, cached.value(), Qt::CheckStateRole);
else
@@ -515,7 +516,7 @@ void TestTreeModel::handleParseResult(const TestParseResult *result, TestTreeIte
// restore former check state if available
newItem->forAllChildren([this](Utils::TreeItem *child) {
auto childItem = static_cast<TestTreeItem *>(child);
- Utils::optional<Qt::CheckState> cached = m_checkStateCache.get(childItem);
+ Utils::optional<Qt::CheckState> cached = m_checkStateCache->get(childItem);
if (cached.has_value())
childItem->setData(0, cached.value(), Qt::CheckStateRole);
});
diff --git a/src/plugins/autotest/testtreemodel.h b/src/plugins/autotest/testtreemodel.h
index 4ca3cb27b4..34f51cf7bb 100644
--- a/src/plugins/autotest/testtreemodel.h
+++ b/src/plugins/autotest/testtreemodel.h
@@ -27,6 +27,7 @@
#include "autotest_global.h"
+#include "itemdatacache.h"
#include "testconfiguration.h"
#include "testtreeitem.h"
@@ -39,40 +40,6 @@ namespace Autotest {
namespace Internal {
class AutotestPluginPrivate;
class TestCodeParser;
-
-template<class T>
-class ItemDataCache
-{
-public:
- void insert(TestTreeItem *item, const T &value) { m_cache[item->cacheName()] = {0, value}; }
- void evolve()
- {
- auto it = m_cache.begin(), end = m_cache.end();
- while (it != end)
- it = it->generation++ >= maxGen ? m_cache.erase(it) : ++it;
- }
-
- Utils::optional<T> get(TestTreeItem *item)
- {
- auto entry = m_cache.find(item->cacheName());
- if (entry == m_cache.end())
- return Utils::nullopt;
- entry->generation = 0;
- return Utils::make_optional(entry->value);
- };
-
- void clear() { m_cache.clear(); }
-
-private:
- static constexpr int maxGen = 10;
- struct Entry
- {
- int generation = 0;
- T value;
- };
- QHash<QString, Entry> m_cache;
-};
-
} // namespace Internal
class TestParseResult;
@@ -139,7 +106,7 @@ private:
QList<TestTreeItem *> testItemsByName(TestTreeItem *root, const QString &testName);
Internal::TestCodeParser *m_parser = nullptr;
- Internal::ItemDataCache<Qt::CheckState> m_checkStateCache;
+ Internal::ItemDataCache<Qt::CheckState> *m_checkStateCache = nullptr; // not owned
};
namespace Internal {