From 910126867da290f25bac0f9c10b314ee587abc95 Mon Sep 17 00:00:00 2001 From: hjk Date: Tue, 9 Jan 2024 16:07:57 +0100 Subject: [PATCH] Squish: Use new setup pattern for SquishNavigationWidgetFactory Change-Id: I44ac6a84f68b9b1fb22d9906921647e13d78de19 Reviewed-by: Christian Stenger --- src/plugins/squish/squishnavigationwidget.cpp | 46 +++++++++++-------- src/plugins/squish/squishnavigationwidget.h | 11 +---- src/plugins/squish/squishplugin.cpp | 2 +- 3 files changed, 28 insertions(+), 31 deletions(-) diff --git a/src/plugins/squish/squishnavigationwidget.cpp b/src/plugins/squish/squishnavigationwidget.cpp index b6e68aad871..7f99e52775a 100644 --- a/src/plugins/squish/squishnavigationwidget.cpp +++ b/src/plugins/squish/squishnavigationwidget.cpp @@ -15,6 +15,7 @@ #include #include #include +#include #include #include @@ -30,12 +31,12 @@ namespace Squish::Internal { const int defaultSectionSize = 17; -class SquishNavigationWidget : public QWidget +class SquishNavigationWidget final : public QWidget { public: - explicit SquishNavigationWidget(QWidget *parent = nullptr); - ~SquishNavigationWidget() override; - void contextMenuEvent(QContextMenuEvent *event) override; + SquishNavigationWidget(); + + void contextMenuEvent(QContextMenuEvent *event) final; static QList createToolButtons(); private: @@ -54,9 +55,7 @@ private: SquishTestTreeSortModel *m_sortModel; }; - -SquishNavigationWidget::SquishNavigationWidget(QWidget *parent) - : QWidget(parent) +SquishNavigationWidget::SquishNavigationWidget() { setWindowTitle(Tr::tr("Squish")); m_view = new SquishTestTreeView(this); @@ -105,8 +104,6 @@ SquishNavigationWidget::SquishNavigationWidget(QWidget *parent) }); } -SquishNavigationWidget::~SquishNavigationWidget() {} - void SquishNavigationWidget::contextMenuEvent(QContextMenuEvent *event) { QMenu menu; @@ -356,20 +353,29 @@ void SquishNavigationWidget::onNewTestCaseTriggered(const QModelIndex &index) m_view->edit(m_sortModel->mapFromSource(added)); } -SquishNavigationWidgetFactory::SquishNavigationWidgetFactory() +class SquishNavigationWidgetFactory final : public Core::INavigationWidgetFactory { - setDisplayName(Tr::tr("Squish")); - setId(Squish::Constants::SQUISH_ID); - setPriority(777); -} +public: + SquishNavigationWidgetFactory() + { + setDisplayName(Tr::tr("Squish")); + setId(Squish::Constants::SQUISH_ID); + setPriority(777); + } -Core::NavigationView SquishNavigationWidgetFactory::createWidget() + Core::NavigationView createWidget() final + { + SquishNavigationWidget *squishNavigationWidget = new SquishNavigationWidget; + Core::NavigationView view; + view.widget = squishNavigationWidget; + view.dockToolBarWidgets = squishNavigationWidget->createToolButtons(); + return view; + } +}; + +void setupSquishNavigationWidgetFactory() { - SquishNavigationWidget *squishNavigationWidget = new SquishNavigationWidget; - Core::NavigationView view; - view.widget = squishNavigationWidget; - view.dockToolBarWidgets = squishNavigationWidget->createToolButtons(); - return view; + static SquishNavigationWidgetFactory squishNavigationWidgetFactory; } } // Squish::Internal diff --git a/src/plugins/squish/squishnavigationwidget.h b/src/plugins/squish/squishnavigationwidget.h index c0d9f0af203..e609b6cf75c 100644 --- a/src/plugins/squish/squishnavigationwidget.h +++ b/src/plugins/squish/squishnavigationwidget.h @@ -3,17 +3,8 @@ #pragma once -#include - namespace Squish::Internal { -class SquishNavigationWidgetFactory : public Core::INavigationWidgetFactory -{ -public: - SquishNavigationWidgetFactory(); - -private: - Core::NavigationView createWidget() override; -}; +void setupSquishNavigationWidgetFactory(); } // Squish::Internal diff --git a/src/plugins/squish/squishplugin.cpp b/src/plugins/squish/squishplugin.cpp index 5c701efd9e9..75707657b44 100644 --- a/src/plugins/squish/squishplugin.cpp +++ b/src/plugins/squish/squishplugin.cpp @@ -39,7 +39,6 @@ public: bool initializeGlobalScripts(); - SquishNavigationWidgetFactory m_navigationWidgetFactory; ObjectsMapEditorFactory m_objectsMapEditorFactory; SquishOutputPane m_outputPane; SquishTools m_squishTools; @@ -109,6 +108,7 @@ private: d.reset(new SquishPluginPrivate); setupSquishWizardPages(); + setupSquishNavigationWidgetFactory(); ProjectExplorer::JsonWizardFactory::addWizardPath(":/squish/wizard/"); }