From 009febce6e5907d4eb530a88bf52b5f99013db08 Mon Sep 17 00:00:00 2001 From: hjk Date: Thu, 18 Jan 2024 08:15:25 +0100 Subject: [PATCH] QtSupport: Use setupXXX for welcome page contributions Change-Id: I5ff8a5527c908381bb67f011d39aaeb926a89c40 Reviewed-by: Jarek Kobus --- .../qtsupport/gettingstartedwelcomepage.cpp | 46 +++++++++++++------ .../qtsupport/gettingstartedwelcomepage.h | 32 ++----------- src/plugins/qtsupport/qtsupportplugin.cpp | 4 +- 3 files changed, 35 insertions(+), 47 deletions(-) diff --git a/src/plugins/qtsupport/gettingstartedwelcomepage.cpp b/src/plugins/qtsupport/gettingstartedwelcomepage.cpp index 39420845ca6..7256afc050a 100644 --- a/src/plugins/qtsupport/gettingstartedwelcomepage.cpp +++ b/src/plugins/qtsupport/gettingstartedwelcomepage.cpp @@ -10,6 +10,7 @@ #include #include #include +#include #include #include #include @@ -42,17 +43,27 @@ using namespace Core; using namespace Utils; -namespace QtSupport { -namespace Internal { +namespace QtSupport::Internal { const char C_FALLBACK_ROOT[] = "ProjectsFallbackRoot"; Q_GLOBAL_STATIC(ExampleSetModel, s_exampleSetModel) -ExamplesWelcomePage::ExamplesWelcomePage(bool showExamples) - : m_showExamples(showExamples) +class ExamplesWelcomePage final : public Core::IWelcomePage { -} +public: + explicit ExamplesWelcomePage(bool showExamples) + : m_showExamples(showExamples) + {} + + QString title() const final; + int priority() const final; + Id id() const final; + QWidget *createWidget() const final; + +private: + const bool m_showExamples; +}; QString ExamplesWelcomePage::title() const { @@ -69,9 +80,9 @@ Id ExamplesWelcomePage::id() const return m_showExamples ? "Examples" : "Tutorials"; } -FilePath ExamplesWelcomePage::copyToAlternativeLocation(const FilePath &proFile, - FilePaths &filesToOpen, - const FilePaths &dependencies) +static FilePath copyToAlternativeLocation(const FilePath &proFile, + FilePaths &filesToOpen, + const FilePaths &dependencies) { const FilePath projectDir = proFile.canonicalPath().parentDir(); QDialog d(ICore::dialogParent()); @@ -106,12 +117,12 @@ FilePath ExamplesWelcomePage::copyToAlternativeLocation(const FilePath &proFile, enum { Copy = QDialog::Accepted + 1, Keep = QDialog::Accepted + 2 }; auto bb = new QDialogButtonBox; QPushButton *copyBtn = bb->addButton(Tr::tr("&Copy Project and Open"), QDialogButtonBox::AcceptRole); - connect(copyBtn, &QAbstractButton::released, &d, [&d] { d.done(Copy); }); + QObject::connect(copyBtn, &QAbstractButton::released, &d, [&d] { d.done(Copy); }); copyBtn->setDefault(true); QPushButton *keepBtn = bb->addButton(Tr::tr("&Keep Project and Open"), QDialogButtonBox::RejectRole); - connect(keepBtn, &QAbstractButton::released, &d, [&d] { d.done(Keep); }); + QObject::connect(keepBtn, &QAbstractButton::released, &d, [&d] { d.done(Keep); }); lay->addWidget(bb, 2, 0, 1, 2); - connect(chooser, &PathChooser::validChanged, copyBtn, &QWidget::setEnabled); + QObject::connect(chooser, &PathChooser::validChanged, copyBtn, &QWidget::setEnabled); int code = d.exec(); if (code == Copy) { const QString exampleDirName = projectDir.fileName(); @@ -162,7 +173,7 @@ FilePath ExamplesWelcomePage::copyToAlternativeLocation(const FilePath &proFile, return {}; } -void ExamplesWelcomePage::openProject(const ExampleItem *item) +static void openProject(const ExampleItem *item) { using namespace ProjectExplorer; FilePath proFile = item->projectPath; @@ -220,7 +231,7 @@ protected: if (exampleItem->isVideo) QDesktopServices::openUrl(QUrl::fromUserInput(exampleItem->videoUrl)); else if (exampleItem->hasSourceCode) - ExamplesWelcomePage::openProject(exampleItem); + openProject(exampleItem); else HelpManager::showHelpUrl(QUrl::fromUserInput(exampleItem->docUrl), HelpManager::ExternalHelpAlways); @@ -345,5 +356,10 @@ QWidget *ExamplesWelcomePage::createWidget() const return new ExamplesPageWidget(m_showExamples); } -} // namespace Internal -} // namespace QtSupport +void setupGettingStartedWelcomePage() +{ + static ExamplesWelcomePage examplesPage{true}; + static ExamplesWelcomePage tutorialPage{false}; +} + +} // QtSupport::Internal diff --git a/src/plugins/qtsupport/gettingstartedwelcomepage.h b/src/plugins/qtsupport/gettingstartedwelcomepage.h index aa07f669167..ed3dcc9c3a1 100644 --- a/src/plugins/qtsupport/gettingstartedwelcomepage.h +++ b/src/plugins/qtsupport/gettingstartedwelcomepage.h @@ -3,34 +3,8 @@ #pragma once -#include -#include +namespace QtSupport::Internal { -namespace QtSupport { -namespace Internal { +void setupGettingStartedWelcomePage(); -class ExampleItem; - -class ExamplesWelcomePage : public Core::IWelcomePage -{ - Q_OBJECT - -public: - explicit ExamplesWelcomePage(bool showExamples); - - QString title() const final; - int priority() const final; - Utils::Id id() const final; - QWidget *createWidget() const final; - - static void openProject(const ExampleItem *item); - -private: - static Utils::FilePath copyToAlternativeLocation(const Utils::FilePath &fileInfo, - Utils::FilePaths &filesToOpen, - const Utils::FilePaths &dependencies); - const bool m_showExamples; -}; - -} // namespace Internal -} // namespace QtSupport +} // QtSupport::Internal diff --git a/src/plugins/qtsupport/qtsupportplugin.cpp b/src/plugins/qtsupport/qtsupportplugin.cpp index 4ff5e4659f1..19f3e620c70 100644 --- a/src/plugins/qtsupport/qtsupportplugin.cpp +++ b/src/plugins/qtsupport/qtsupportplugin.cpp @@ -50,9 +50,6 @@ class QtSupportPluginPrivate public: QtOptionsPage qtOptionsPage; - ExamplesWelcomePage examplesPage{true}; - ExamplesWelcomePage tutorialPage{false}; - QtOutputFormatterFactory qtOutputFormatterFactory; UicGeneratorFactory uicGeneratorFactory; @@ -113,6 +110,7 @@ void QtSupportPlugin::initialize() setupDesktopQtVersion(); setupEmbeddedLinuxQtVersion(); + setupGettingStartedWelcomePage(); theProcessRunner() = processRunnerCallback;