From 0bd3fafb0a24fa7f3b2ff210c497ad1587e6f1a1 Mon Sep 17 00:00:00 2001 From: Jarek Kobus Date: Thu, 1 Feb 2024 17:58:54 +0100 Subject: [PATCH] CustomWizard: Replace QSharedPointer with std::shared_ptr According to https://wiki.qt.io/Things_To_Look_Out_For_In_Reviews QSharedPointer impl is poor and it's going to be removed from Qt 7. Change-Id: I7b7a715c1e2b8092ce7cb5f3686c3a3a02e0ad9e Reviewed-by: hjk --- .../projectexplorer/customwizard/customwizard.cpp | 12 ++++++------ .../projectexplorer/customwizard/customwizard.h | 5 ++--- .../customwizard/customwizardpage.cpp | 10 +++++----- .../customwizard/customwizardpage.h | 15 +++++++-------- .../customwizard/customwizardparameters.h | 5 ++--- .../customwizard/customwizardscriptgenerator.cpp | 1 - 6 files changed, 22 insertions(+), 26 deletions(-) diff --git a/src/plugins/projectexplorer/customwizard/customwizard.cpp b/src/plugins/projectexplorer/customwizard/customwizard.cpp index c18926cbfc9..c2ff5082bbb 100644 --- a/src/plugins/projectexplorer/customwizard/customwizard.cpp +++ b/src/plugins/projectexplorer/customwizard/customwizard.cpp @@ -78,8 +78,8 @@ class CustomWizardPrivate { public: CustomWizardPrivate() : m_context(new CustomWizardContext) {} - QSharedPointer m_parameters; - QSharedPointer m_context; + std::shared_ptr m_parameters; + std::shared_ptr m_context; static int verbose; }; @@ -140,7 +140,7 @@ void CustomWizard::setParameters(const CustomWizardParametersPtr &p) BaseFileWizard *CustomWizard::create(QWidget *parent, const WizardDialogParameters &p) const { - QTC_ASSERT(!d->m_parameters.isNull(), return nullptr); + QTC_ASSERT(d->m_parameters, return nullptr); auto wizard = new BaseFileWizard(this, p.extraValues(), parent); d->m_context->reset(); @@ -217,8 +217,8 @@ template // Determine where to run the generator script. The user may specify // an expression subject to field replacement, default is the target path. -static inline QString scriptWorkingDirectory(const QSharedPointer &ctx, - const QSharedPointer &p) +static inline QString scriptWorkingDirectory(const std::shared_ptr &ctx, + const std::shared_ptr &p) { if (p->filesGeneratorScriptWorkingDirectory.isEmpty()) return ctx->targetPath.toString(); @@ -476,7 +476,7 @@ void CustomProjectWizard::initProjectWizardDialog(BaseProjectWizardDialog *w, const QList &extensionPages) const { const CustomWizardParametersPtr pa = parameters(); - QTC_ASSERT(!pa.isNull(), return); + QTC_ASSERT(pa, return); const CustomWizardContextPtr ctx = context(); ctx->reset(); diff --git a/src/plugins/projectexplorer/customwizard/customwizard.h b/src/plugins/projectexplorer/customwizard/customwizard.h index c0a50a2fab7..e1c1813f31c 100644 --- a/src/plugins/projectexplorer/customwizard/customwizard.h +++ b/src/plugins/projectexplorer/customwizard/customwizard.h @@ -7,7 +7,6 @@ #include -#include #include #include @@ -77,8 +76,8 @@ public: static int verbose(); protected: - using CustomWizardParametersPtr = QSharedPointer; - using CustomWizardContextPtr = QSharedPointer; + using CustomWizardParametersPtr = std::shared_ptr; + using CustomWizardContextPtr = std::shared_ptr; // generate files in path Core::GeneratedFiles generateWizardFiles(QString *errorMessage) const; diff --git a/src/plugins/projectexplorer/customwizard/customwizardpage.cpp b/src/plugins/projectexplorer/customwizard/customwizardpage.cpp index 1337e2183f6..a479627fa9a 100644 --- a/src/plugins/projectexplorer/customwizard/customwizardpage.cpp +++ b/src/plugins/projectexplorer/customwizard/customwizardpage.cpp @@ -63,8 +63,8 @@ CustomWizardFieldPage::PathChooserData::PathChooserData(PathChooser *pe, const Q { } -CustomWizardFieldPage::CustomWizardFieldPage(const QSharedPointer &ctx, - const QSharedPointer ¶meters, +CustomWizardFieldPage::CustomWizardFieldPage(const std::shared_ptr &ctx, + const std::shared_ptr ¶meters, QWidget *parent) : QWizardPage(parent), m_parameters(parameters), @@ -376,7 +376,7 @@ bool CustomWizardFieldPage::validatePage() } QMap CustomWizardFieldPage::replacementMap(const QWizard *w, - const QSharedPointer &ctx, + const std::shared_ptr &ctx, const FieldList &f) { QMap fieldReplacementMap = ctx->baseReplacements; @@ -402,8 +402,8 @@ QMap CustomWizardFieldPage::replacementMap(const QWizard *w, \sa ProjectExplorer::CustomWizard */ -CustomWizardPage::CustomWizardPage(const QSharedPointer &ctx, - const QSharedPointer ¶meters, +CustomWizardPage::CustomWizardPage(const std::shared_ptr &ctx, + const std::shared_ptr ¶meters, QWidget *parent) : CustomWizardFieldPage(ctx, parameters, parent), m_pathChooser(new PathChooser) diff --git a/src/plugins/projectexplorer/customwizard/customwizardpage.h b/src/plugins/projectexplorer/customwizard/customwizardpage.h index 347fbf31c05..d4fa3947e8f 100644 --- a/src/plugins/projectexplorer/customwizard/customwizardpage.h +++ b/src/plugins/projectexplorer/customwizard/customwizardpage.h @@ -8,7 +8,6 @@ #include #include #include -#include QT_BEGIN_NAMESPACE class QFormLayout; @@ -32,8 +31,8 @@ class CustomWizardFieldPage : public QWizardPage { public: using FieldList = QList; - explicit CustomWizardFieldPage(const QSharedPointer &ctx, - const QSharedPointer ¶meters, + explicit CustomWizardFieldPage(const std::shared_ptr &ctx, + const std::shared_ptr ¶meters, QWidget *parent = nullptr); bool validatePage() override; @@ -41,7 +40,7 @@ public: void cleanupPage() override; static QMap replacementMap(const QWizard *w, - const QSharedPointer &ctx, + const std::shared_ptr &ctx, const FieldList &f); protected: @@ -85,8 +84,8 @@ private: const CustomWizardField &field); void addField(const CustomWizardField &f); - const QSharedPointer m_parameters; - const QSharedPointer m_context; + const std::shared_ptr m_parameters; + const std::shared_ptr m_context; QFormLayout *m_formLayout; LineEditDataList m_lineEdits; TextEditDataList m_textEdits; @@ -100,8 +99,8 @@ class CustomWizardPage : public CustomWizardFieldPage Q_OBJECT public: - explicit CustomWizardPage(const QSharedPointer &ctx, - const QSharedPointer ¶meters, + explicit CustomWizardPage(const std::shared_ptr &ctx, + const std::shared_ptr ¶meters, QWidget *parent = nullptr); Utils::FilePath filePath() const; diff --git a/src/plugins/projectexplorer/customwizard/customwizardparameters.h b/src/plugins/projectexplorer/customwizard/customwizardparameters.h index 8cc11ed903e..28ae1862f54 100644 --- a/src/plugins/projectexplorer/customwizard/customwizardparameters.h +++ b/src/plugins/projectexplorer/customwizard/customwizardparameters.h @@ -7,9 +7,8 @@ #include -#include #include -#include +#include QT_BEGIN_NAMESPACE class QIODevice; @@ -117,7 +116,7 @@ public: class CustomWizardContext { public: using FieldReplacementMap = QMap; - using TemporaryFilePtr = QSharedPointer; + using TemporaryFilePtr = std::shared_ptr; using TemporaryFilePtrList = QList; void reset(); diff --git a/src/plugins/projectexplorer/customwizard/customwizardscriptgenerator.cpp b/src/plugins/projectexplorer/customwizard/customwizardscriptgenerator.cpp index 7562abbe6e5..fa1f455af4a 100644 --- a/src/plugins/projectexplorer/customwizard/customwizardscriptgenerator.cpp +++ b/src/plugins/projectexplorer/customwizard/customwizardscriptgenerator.cpp @@ -13,7 +13,6 @@ #include #include -#include using namespace Utils;