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 <hjk@qt.io>
This commit is contained in:
Jarek Kobus
2024-02-01 17:58:54 +01:00
parent d89bb4ef1e
commit 0bd3fafb0a
6 changed files with 22 additions and 26 deletions

View File

@@ -78,8 +78,8 @@ class CustomWizardPrivate {
public:
CustomWizardPrivate() : m_context(new CustomWizardContext) {}
QSharedPointer<CustomWizardParameters> m_parameters;
QSharedPointer<CustomWizardContext> m_context;
std::shared_ptr<CustomWizardParameters> m_parameters;
std::shared_ptr<CustomWizardContext> 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 <class WizardPage>
// 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<CustomWizardContext> &ctx,
const QSharedPointer<CustomWizardParameters> &p)
static inline QString scriptWorkingDirectory(const std::shared_ptr<CustomWizardContext> &ctx,
const std::shared_ptr<CustomWizardParameters> &p)
{
if (p->filesGeneratorScriptWorkingDirectory.isEmpty())
return ctx->targetPath.toString();
@@ -476,7 +476,7 @@ void CustomProjectWizard::initProjectWizardDialog(BaseProjectWizardDialog *w,
const QList<QWizardPage *> &extensionPages) const
{
const CustomWizardParametersPtr pa = parameters();
QTC_ASSERT(!pa.isNull(), return);
QTC_ASSERT(pa, return);
const CustomWizardContextPtr ctx = context();
ctx->reset();

View File

@@ -7,7 +7,6 @@
#include <coreplugin/basefilewizardfactory.h>
#include <QSharedPointer>
#include <QList>
#include <QMap>
@@ -77,8 +76,8 @@ public:
static int verbose();
protected:
using CustomWizardParametersPtr = QSharedPointer<Internal::CustomWizardParameters>;
using CustomWizardContextPtr = QSharedPointer<Internal::CustomWizardContext>;
using CustomWizardParametersPtr = std::shared_ptr<Internal::CustomWizardParameters>;
using CustomWizardContextPtr = std::shared_ptr<Internal::CustomWizardContext>;
// generate files in path
Core::GeneratedFiles generateWizardFiles(QString *errorMessage) const;

View File

@@ -63,8 +63,8 @@ CustomWizardFieldPage::PathChooserData::PathChooserData(PathChooser *pe, const Q
{
}
CustomWizardFieldPage::CustomWizardFieldPage(const QSharedPointer<CustomWizardContext> &ctx,
const QSharedPointer<CustomWizardParameters> &parameters,
CustomWizardFieldPage::CustomWizardFieldPage(const std::shared_ptr<CustomWizardContext> &ctx,
const std::shared_ptr<CustomWizardParameters> &parameters,
QWidget *parent) :
QWizardPage(parent),
m_parameters(parameters),
@@ -376,7 +376,7 @@ bool CustomWizardFieldPage::validatePage()
}
QMap<QString, QString> CustomWizardFieldPage::replacementMap(const QWizard *w,
const QSharedPointer<CustomWizardContext> &ctx,
const std::shared_ptr<CustomWizardContext> &ctx,
const FieldList &f)
{
QMap<QString, QString> fieldReplacementMap = ctx->baseReplacements;
@@ -402,8 +402,8 @@ QMap<QString, QString> CustomWizardFieldPage::replacementMap(const QWizard *w,
\sa ProjectExplorer::CustomWizard
*/
CustomWizardPage::CustomWizardPage(const QSharedPointer<CustomWizardContext> &ctx,
const QSharedPointer<CustomWizardParameters> &parameters,
CustomWizardPage::CustomWizardPage(const std::shared_ptr<CustomWizardContext> &ctx,
const std::shared_ptr<CustomWizardParameters> &parameters,
QWidget *parent) :
CustomWizardFieldPage(ctx, parameters, parent),
m_pathChooser(new PathChooser)

View File

@@ -8,7 +8,6 @@
#include <QComboBox>
#include <QCheckBox>
#include <QWizardPage>
#include <QSharedPointer>
QT_BEGIN_NAMESPACE
class QFormLayout;
@@ -32,8 +31,8 @@ class CustomWizardFieldPage : public QWizardPage {
public:
using FieldList = QList<CustomWizardField>;
explicit CustomWizardFieldPage(const QSharedPointer<CustomWizardContext> &ctx,
const QSharedPointer<CustomWizardParameters> &parameters,
explicit CustomWizardFieldPage(const std::shared_ptr<CustomWizardContext> &ctx,
const std::shared_ptr<CustomWizardParameters> &parameters,
QWidget *parent = nullptr);
bool validatePage() override;
@@ -41,7 +40,7 @@ public:
void cleanupPage() override;
static QMap<QString, QString> replacementMap(const QWizard *w,
const QSharedPointer<CustomWizardContext> &ctx,
const std::shared_ptr<CustomWizardContext> &ctx,
const FieldList &f);
protected:
@@ -85,8 +84,8 @@ private:
const CustomWizardField &field);
void addField(const CustomWizardField &f);
const QSharedPointer<CustomWizardParameters> m_parameters;
const QSharedPointer<CustomWizardContext> m_context;
const std::shared_ptr<CustomWizardParameters> m_parameters;
const std::shared_ptr<CustomWizardContext> 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<CustomWizardContext> &ctx,
const QSharedPointer<CustomWizardParameters> &parameters,
explicit CustomWizardPage(const std::shared_ptr<CustomWizardContext> &ctx,
const std::shared_ptr<CustomWizardParameters> &parameters,
QWidget *parent = nullptr);
Utils::FilePath filePath() const;

View File

@@ -7,9 +7,8 @@
#include <utils/filepath.h>
#include <QStringList>
#include <QMap>
#include <QSharedPointer>
#include <QStringList>
QT_BEGIN_NAMESPACE
class QIODevice;
@@ -117,7 +116,7 @@ public:
class CustomWizardContext {
public:
using FieldReplacementMap = QMap<QString, QString>;
using TemporaryFilePtr = QSharedPointer<Utils::TemporaryFile>;
using TemporaryFilePtr = std::shared_ptr<Utils::TemporaryFile>;
using TemporaryFilePtrList = QList<TemporaryFilePtr>;
void reset();

View File

@@ -13,7 +13,6 @@
#include <QFileInfo>
#include <QDebug>
#include <QSharedPointer>
using namespace Utils;