AutoTest: Use normal object for settings

Ownership is clear here.

However, since this is accessed via the static plugin interface,
this needed some change that access.

Change-Id: I9488a242442303dee89006240f787677afab730a
Reviewed-by: Christian Stenger <christian.stenger@qt.io>
This commit is contained in:
hjk
2020-02-28 12:27:13 +01:00
parent 9da71b940a
commit 722705e1e7
6 changed files with 26 additions and 31 deletions

View File

@@ -90,8 +90,8 @@ public:
~AutotestPluginPrivate() override; ~AutotestPluginPrivate() override;
AutotestPlugin *q = nullptr; AutotestPlugin *q = nullptr;
TestFrameworkManager *m_frameworkManager = nullptr; TestFrameworkManager *m_frameworkManager = nullptr;
TestSettingsPage *m_testSettingPage = nullptr;
TestNavigationWidgetFactory *m_navigationWidgetFactory = nullptr; TestNavigationWidgetFactory *m_navigationWidgetFactory = nullptr;
TestResultsPane *m_resultsPane = nullptr; TestResultsPane *m_resultsPane = nullptr;
QMap<QString, ChoicePair> m_runconfigCache; QMap<QString, ChoicePair> m_runconfigCache;
@@ -101,30 +101,31 @@ public:
void onRunSelectedTriggered(); void onRunSelectedTriggered();
void onRunFileTriggered(); void onRunFileTriggered();
void onRunUnderCursorTriggered(TestRunMode mode); void onRunUnderCursorTriggered(TestRunMode mode);
TestSettings m_settings;
TestSettingsPage m_testSettingPage{&m_settings};
}; };
static AutotestPlugin *s_instance = nullptr; static AutotestPluginPrivate *dd = nullptr;
static QHash<ProjectExplorer::Project *, TestProjectSettings *> s_projectSettings; static QHash<ProjectExplorer::Project *, TestProjectSettings *> s_projectSettings;
AutotestPlugin::AutotestPlugin() AutotestPlugin::AutotestPlugin()
: m_settings(new TestSettings)
{ {
// needed to be used in QueuedConnection connects // needed to be used in QueuedConnection connects
qRegisterMetaType<TestResult>(); qRegisterMetaType<TestResult>();
qRegisterMetaType<TestTreeItem *>(); qRegisterMetaType<TestTreeItem *>();
qRegisterMetaType<TestCodeLocationAndType>(); qRegisterMetaType<TestCodeLocationAndType>();
s_instance = this;
} }
AutotestPlugin::~AutotestPlugin() AutotestPlugin::~AutotestPlugin()
{ {
delete d; delete dd;
} }
AutotestPluginPrivate::AutotestPluginPrivate(AutotestPlugin *parent) AutotestPluginPrivate::AutotestPluginPrivate(AutotestPlugin *parent)
: q(parent) : q(parent)
{ {
dd = this; // Needed as the code below access it via the static plugin interface
m_frameworkManager = TestFrameworkManager::instance(); m_frameworkManager = TestFrameworkManager::instance();
initializeMenuEntries(); initializeMenuEntries();
m_frameworkManager->registerTestFramework(new QtTestFramework); m_frameworkManager->registerTestFramework(new QtTestFramework);
@@ -133,7 +134,6 @@ AutotestPluginPrivate::AutotestPluginPrivate(AutotestPlugin *parent)
m_frameworkManager->registerTestFramework(new BoostTestFramework); m_frameworkManager->registerTestFramework(new BoostTestFramework);
m_frameworkManager->synchronizeSettings(ICore::settings()); m_frameworkManager->synchronizeSettings(ICore::settings());
m_testSettingPage = new TestSettingsPage(q->settings());
m_navigationWidgetFactory = new TestNavigationWidgetFactory; m_navigationWidgetFactory = new TestNavigationWidgetFactory;
m_resultsPane = TestResultsPane::instance(); m_resultsPane = TestResultsPane::instance();
@@ -146,7 +146,7 @@ AutotestPluginPrivate::AutotestPluginPrivate(AutotestPlugin *parent)
}); });
ProjectExplorer::ProjectPanelFactory::registerFactory(panelFactory); ProjectExplorer::ProjectPanelFactory::registerFactory(panelFactory);
m_frameworkManager->activateFrameworksFromSettings(q->settings()); m_frameworkManager->activateFrameworksFromSettings(&m_settings);
TestTreeModel::instance()->synchronizeTestFrameworks(); TestTreeModel::instance()->synchronizeTestFrameworks();
connect(ProjectExplorer::SessionManager::instance(), connect(ProjectExplorer::SessionManager::instance(),
@@ -160,13 +160,12 @@ AutotestPluginPrivate::~AutotestPluginPrivate()
{ {
delete m_navigationWidgetFactory; delete m_navigationWidgetFactory;
delete m_resultsPane; delete m_resultsPane;
delete m_testSettingPage;
delete m_frameworkManager; delete m_frameworkManager;
} }
QSharedPointer<TestSettings> AutotestPlugin::settings() TestSettings *AutotestPlugin::settings()
{ {
return s_instance->m_settings; return &dd->m_settings;
} }
TestProjectSettings *AutotestPlugin::projectSettings(ProjectExplorer::Project *project) TestProjectSettings *AutotestPlugin::projectSettings(ProjectExplorer::Project *project)
@@ -247,7 +246,7 @@ bool AutotestPlugin::initialize(const QStringList &arguments, QString *errorStri
Q_UNUSED(arguments) Q_UNUSED(arguments)
Q_UNUSED(errorString) Q_UNUSED(errorString)
d = new AutotestPluginPrivate(this); dd = new AutotestPluginPrivate(this);
return true; return true;
} }
@@ -263,7 +262,7 @@ void AutotestPlugin::extensionsInitialized()
Command *command = ActionManager::registerAction(action, Constants::ACTION_RUN_UCURSOR); Command *command = ActionManager::registerAction(action, Constants::ACTION_RUN_UCURSOR);
connect(action, &QAction::triggered, connect(action, &QAction::triggered,
std::bind(&AutotestPluginPrivate::onRunUnderCursorTriggered, d, TestRunMode::Run)); std::bind(&AutotestPluginPrivate::onRunUnderCursorTriggered, dd, TestRunMode::Run));
contextMenu->addSeparator(); contextMenu->addSeparator();
contextMenu->addAction(command); contextMenu->addAction(command);
@@ -273,7 +272,7 @@ void AutotestPlugin::extensionsInitialized()
command = ActionManager::registerAction(action, Constants::ACTION_RUN_DBG_UCURSOR); command = ActionManager::registerAction(action, Constants::ACTION_RUN_DBG_UCURSOR);
connect(action, &QAction::triggered, connect(action, &QAction::triggered,
std::bind(&AutotestPluginPrivate::onRunUnderCursorTriggered, d, TestRunMode::Debug)); std::bind(&AutotestPluginPrivate::onRunUnderCursorTriggered, dd, TestRunMode::Debug));
contextMenu->addAction(command); contextMenu->addAction(command);
contextMenu->addSeparator(); contextMenu->addSeparator();
} }
@@ -392,25 +391,25 @@ void AutotestPlugin::updateMenuItemsEnabledState()
void AutotestPlugin::cacheRunConfigChoice(const QString &buildTargetKey, const ChoicePair &choice) void AutotestPlugin::cacheRunConfigChoice(const QString &buildTargetKey, const ChoicePair &choice)
{ {
if (s_instance) if (dd)
s_instance->d->m_runconfigCache.insert(buildTargetKey, choice); dd->m_runconfigCache.insert(buildTargetKey, choice);
} }
ChoicePair AutotestPlugin::cachedChoiceFor(const QString &buildTargetKey) ChoicePair AutotestPlugin::cachedChoiceFor(const QString &buildTargetKey)
{ {
return s_instance ? s_instance->d->m_runconfigCache.value(buildTargetKey) : ChoicePair(); return dd ? dd->m_runconfigCache.value(buildTargetKey) : ChoicePair();
} }
void AutotestPlugin::clearChoiceCache() void AutotestPlugin::clearChoiceCache()
{ {
if (s_instance) if (dd)
s_instance->d->m_runconfigCache.clear(); dd->m_runconfigCache.clear();
} }
void AutotestPlugin::popupResultsPane() void AutotestPlugin::popupResultsPane()
{ {
if (s_instance) if (dd)
s_instance->d->m_resultsPane->popup(Core::IOutputPane::NoModeSwitch); dd->m_resultsPane->popup(Core::IOutputPane::NoModeSwitch);
} }
QVector<QObject *> AutotestPlugin::createTestObjects() const QVector<QObject *> AutotestPlugin::createTestObjects() const

View File

@@ -29,8 +29,6 @@
#include <extensionsystem/iplugin.h> #include <extensionsystem/iplugin.h>
#include <QMap>
namespace ProjectExplorer { namespace ProjectExplorer {
class Project; class Project;
class RunConfiguration; class RunConfiguration;
@@ -65,7 +63,7 @@ public:
void extensionsInitialized() override; void extensionsInitialized() override;
ShutdownFlag aboutToShutdown() override; ShutdownFlag aboutToShutdown() override;
static QSharedPointer<TestSettings> settings(); static TestSettings *settings();
static TestProjectSettings *projectSettings(ProjectExplorer::Project *project); static TestProjectSettings *projectSettings(ProjectExplorer::Project *project);
static void updateMenuItemsEnabledState(); static void updateMenuItemsEnabledState();
static void cacheRunConfigChoice(const QString &buildTargetKey, const ChoicePair &choice); static void cacheRunConfigChoice(const QString &buildTargetKey, const ChoicePair &choice);
@@ -75,8 +73,6 @@ public:
private: private:
QVector<QObject *> createTestObjects() const override; QVector<QObject *> createTestObjects() const override;
class AutotestPluginPrivate *d = nullptr;
const QSharedPointer<TestSettings> m_settings;
}; };
} // namespace Internal } // namespace Internal

View File

@@ -91,7 +91,7 @@ bool TestFrameworkManager::registerTestFramework(ITestFramework *framework)
return true; return true;
} }
void TestFrameworkManager::activateFrameworksFromSettings(QSharedPointer<Internal::TestSettings> settings) void TestFrameworkManager::activateFrameworksFromSettings(const Internal::TestSettings *settings)
{ {
FrameworkIterator it = m_registeredFrameworks.begin(); FrameworkIterator it = m_registeredFrameworks.begin();
FrameworkIterator end = m_registeredFrameworks.end(); FrameworkIterator end = m_registeredFrameworks.end();

View File

@@ -57,7 +57,7 @@ public:
virtual ~TestFrameworkManager(); virtual ~TestFrameworkManager();
bool registerTestFramework(ITestFramework *framework); bool registerTestFramework(ITestFramework *framework);
void activateFrameworksFromSettings(QSharedPointer<Internal::TestSettings> settings); void activateFrameworksFromSettings(const Internal::TestSettings *settings);
QString frameworkNameForId(const Core::Id &id) const; QString frameworkNameForId(const Core::Id &id) const;
QList<Core::Id> registeredFrameworkIds() const; QList<Core::Id> registeredFrameworkIds() const;
QList<Core::Id> sortedRegisteredFrameworkIds() const; QList<Core::Id> sortedRegisteredFrameworkIds() const;

View File

@@ -140,7 +140,7 @@ void TestSettingsWidget::onFrameworkItemChanged()
m_ui.frameworksWarn->setVisible(true); m_ui.frameworksWarn->setVisible(true);
} }
TestSettingsPage::TestSettingsPage(const QSharedPointer<TestSettings> &settings) TestSettingsPage::TestSettingsPage(TestSettings *settings)
: m_settings(settings) : m_settings(settings)
{ {
setId("A.AutoTest.0.General"); setId("A.AutoTest.0.General");

View File

@@ -57,14 +57,14 @@ class TestSettingsPage : public Core::IOptionsPage
{ {
Q_OBJECT Q_OBJECT
public: public:
explicit TestSettingsPage(const QSharedPointer<TestSettings> &settings); explicit TestSettingsPage(TestSettings *settings);
QWidget *widget() override; QWidget *widget() override;
void apply() override; void apply() override;
void finish() override { } void finish() override { }
private: private:
QSharedPointer<TestSettings> m_settings; TestSettings *m_settings;
QPointer<TestSettingsWidget> m_widget; QPointer<TestSettingsWidget> m_widget;
}; };