From 243d063cb9c8d82089f3162186d2b7d6c19b4222 Mon Sep 17 00:00:00 2001 From: Jarek Kobus Date: Thu, 1 Feb 2024 15:46:01 +0100 Subject: [PATCH] Gerrit: 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: I2954186d7e1df0f6e07fa840204f2a4b00fed73e Reviewed-by: Orgad Shaneh --- src/plugins/git/gerrit/gerritdialog.cpp | 8 ++++---- src/plugins/git/gerrit/gerritdialog.h | 17 ++++++++--------- src/plugins/git/gerrit/gerritmodel.cpp | 12 ++++++------ src/plugins/git/gerrit/gerritmodel.h | 15 ++++++--------- src/plugins/git/gerrit/gerritoptionspage.cpp | 6 +++--- src/plugins/git/gerrit/gerritoptionspage.h | 4 +--- src/plugins/git/gerrit/gerritplugin.cpp | 16 ++++++++-------- src/plugins/git/gerrit/gerritplugin.h | 9 ++++----- src/plugins/git/gerrit/gerritpushdialog.cpp | 6 ++++-- src/plugins/git/gerrit/gerritpushdialog.h | 3 +-- src/plugins/git/gerrit/gerritremotechooser.cpp | 2 +- src/plugins/git/gerrit/gerritremotechooser.h | 5 ++--- 12 files changed, 48 insertions(+), 55 deletions(-) diff --git a/src/plugins/git/gerrit/gerritdialog.cpp b/src/plugins/git/gerrit/gerritdialog.cpp index e4d38219bbb..ad43ede6411 100644 --- a/src/plugins/git/gerrit/gerritdialog.cpp +++ b/src/plugins/git/gerrit/gerritdialog.cpp @@ -44,8 +44,8 @@ namespace Internal { static const int maxTitleWidth = 350; -GerritDialog::GerritDialog(const QSharedPointer &p, - const QSharedPointer &s, +GerritDialog::GerritDialog(const std::shared_ptr &p, + const std::shared_ptr &s, const FilePath &repository, QWidget *parent) : QDialog(parent) @@ -286,7 +286,7 @@ void GerritDialog::showEvent(QShowEvent *event) void GerritDialog::remoteChanged() { const GerritServer server = m_remoteComboBox->currentServer(); - if (QSharedPointer modelServer = m_model->server()) { + if (std::shared_ptr modelServer = m_model->server()) { if (*modelServer == server) return; } @@ -335,7 +335,7 @@ void GerritDialog::slotCurrentChanged() updateButtons(); } -void GerritDialog::fetchStarted(const QSharedPointer &change) +void GerritDialog::fetchStarted(const std::shared_ptr &change) { // Disable buttons to prevent parallel gerrit operations which can cause mix-ups. m_fetchRunning = true; diff --git a/src/plugins/git/gerrit/gerritdialog.h b/src/plugins/git/gerrit/gerritdialog.h index a3c69721e67..c2909b250ac 100644 --- a/src/plugins/git/gerrit/gerritdialog.h +++ b/src/plugins/git/gerrit/gerritdialog.h @@ -6,7 +6,6 @@ #include #include -#include #include #include @@ -40,22 +39,22 @@ class GerritDialog : public QDialog { Q_OBJECT public: - explicit GerritDialog(const QSharedPointer &p, - const QSharedPointer &s, + explicit GerritDialog(const std::shared_ptr &p, + const std::shared_ptr &s, const Utils::FilePath &repository, QWidget *parent = nullptr); ~GerritDialog() override; Utils::FilePath repositoryPath() const; void setCurrentPath(const Utils::FilePath &path); - void fetchStarted(const QSharedPointer &change); + void fetchStarted(const std::shared_ptr &change); void fetchFinished(); void refresh(); void scheduleUpdateRemotes(); signals: - void fetchDisplay(const QSharedPointer &); - void fetchCherryPick(const QSharedPointer &); - void fetchCheckout(const QSharedPointer &); + void fetchDisplay(const std::shared_ptr &); + void fetchCherryPick(const std::shared_ptr &); + void fetchCheckout(const std::shared_ptr &); private: void slotCurrentChanged(); @@ -76,8 +75,8 @@ private: QPushButton *addActionButton(const QString &text, const std::function &buttonSlot); void updateButtons(); - const QSharedPointer m_parameters; - const QSharedPointer m_server; + const std::shared_ptr m_parameters; + const std::shared_ptr m_server; QSortFilterProxyModel *m_filterModel; GerritModel *m_model; QStringListModel *m_queryModel; diff --git a/src/plugins/git/gerrit/gerritmodel.cpp b/src/plugins/git/gerrit/gerritmodel.cpp index 231933c9cb4..b11458393e8 100644 --- a/src/plugins/git/gerrit/gerritmodel.cpp +++ b/src/plugins/git/gerrit/gerritmodel.cpp @@ -64,7 +64,7 @@ QDebug operator<<(QDebug d, const GerritChange &c) } // Format default Url for a change -static inline QString defaultUrl(const QSharedPointer &p, +static inline QString defaultUrl(const std::shared_ptr &p, const GerritServer &server, int gerritNumber) { @@ -208,7 +208,7 @@ class QueryContext : public QObject Q_OBJECT public: QueryContext(const QString &query, - const QSharedPointer &p, + const std::shared_ptr &p, const GerritServer &server, QObject *parent = nullptr); @@ -236,7 +236,7 @@ private: enum { timeOutMS = 30000 }; QueryContext::QueryContext(const QString &query, - const QSharedPointer &p, + const std::shared_ptr &p, const GerritServer &server, QObject *parent) : QObject(parent) @@ -338,7 +338,7 @@ void QueryContext::timeout() m_timer.start(); } -GerritModel::GerritModel(const QSharedPointer &p, QObject *parent) +GerritModel::GerritModel(const std::shared_ptr &p, QObject *parent) : QStandardItemModel(0, ColumnCount, parent) , m_parameters(p) { @@ -445,7 +445,7 @@ QStandardItem *GerritModel::itemForNumber(int number) const return nullptr; } -void GerritModel::refresh(const QSharedPointer &server, const QString &query) +void GerritModel::refresh(const std::shared_ptr &server, const QString &query) { if (m_query) m_query->terminate(); @@ -731,7 +731,7 @@ static GerritChangePtr parseRestOutput(const QJsonObject &object, const GerritSe return change; } -static bool parseOutput(const QSharedPointer ¶meters, +static bool parseOutput(const std::shared_ptr ¶meters, const GerritServer &server, const QByteArray &output, QList &result) diff --git a/src/plugins/git/gerrit/gerritmodel.h b/src/plugins/git/gerrit/gerritmodel.h index 74ae457b572..e5b8c78c84c 100644 --- a/src/plugins/git/gerrit/gerritmodel.h +++ b/src/plugins/git/gerrit/gerritmodel.h @@ -7,7 +7,6 @@ #include "gerritserver.h" #include -#include #include namespace Gerrit { @@ -57,7 +56,7 @@ public: int depth = -1; }; -using GerritChangePtr = QSharedPointer; +using GerritChangePtr = std::shared_ptr; class GerritModel : public QStandardItemModel { @@ -79,7 +78,7 @@ public: GerritChangeRole = Qt::UserRole + 2, SortRole = Qt::UserRole + 3 }; - GerritModel(const QSharedPointer &, QObject *parent = nullptr); + GerritModel(const std::shared_ptr &, QObject *parent = nullptr); ~GerritModel() override; QVariant data(const QModelIndex &index, int role) const override; @@ -88,12 +87,12 @@ public: QString toHtml(const QModelIndex &index) const; QStandardItem *itemForNumber(int number) const; - QSharedPointer server() const { return m_server; } + std::shared_ptr server() const { return m_server; } enum QueryState { Idle, Running, Ok, Error }; QueryState state() const { return m_state; } - void refresh(const QSharedPointer &server, const QString &query); + void refresh(const std::shared_ptr &server, const QString &query); signals: void refreshStateChanged(bool isRefreshing); // For disabling the "Refresh" button. @@ -111,13 +110,11 @@ private: const QString &serverPrefix) const; QList changeToRow(const GerritChangePtr &c) const; - const QSharedPointer m_parameters; - QSharedPointer m_server; + const std::shared_ptr m_parameters; + std::shared_ptr m_server; QueryContext *m_query = nullptr; QueryState m_state = Idle; }; } // namespace Internal } // namespace Gerrit - -Q_DECLARE_METATYPE(Gerrit::Internal::GerritChangePtr) diff --git a/src/plugins/git/gerrit/gerritoptionspage.cpp b/src/plugins/git/gerrit/gerritoptionspage.cpp index 3d77c26aa46..8954db43aa8 100644 --- a/src/plugins/git/gerrit/gerritoptionspage.cpp +++ b/src/plugins/git/gerrit/gerritoptionspage.cpp @@ -23,7 +23,7 @@ namespace Gerrit::Internal { class GerritOptionsWidget : public Core::IOptionsPageWidget { public: - GerritOptionsWidget(const QSharedPointer &p, + GerritOptionsWidget(const std::shared_ptr &p, const std::function &onChanged) : m_parameters(p) { @@ -87,12 +87,12 @@ public: } private: - const QSharedPointer &m_parameters; + const std::shared_ptr &m_parameters; }; // GerritOptionsPage -GerritOptionsPage::GerritOptionsPage(const QSharedPointer &p, +GerritOptionsPage::GerritOptionsPage(const std::shared_ptr &p, const std::function &onChanged) { setId("Gerrit"); diff --git a/src/plugins/git/gerrit/gerritoptionspage.h b/src/plugins/git/gerrit/gerritoptionspage.h index 96caab06092..12b2e37dc2d 100644 --- a/src/plugins/git/gerrit/gerritoptionspage.h +++ b/src/plugins/git/gerrit/gerritoptionspage.h @@ -5,8 +5,6 @@ #include -#include - namespace Gerrit::Internal { class GerritParameters; @@ -14,7 +12,7 @@ class GerritParameters; class GerritOptionsPage : public Core::IOptionsPage { public: - GerritOptionsPage(const QSharedPointer &p, + GerritOptionsPage(const std::shared_ptr &p, const std::function &onChanged); }; diff --git a/src/plugins/git/gerrit/gerritplugin.cpp b/src/plugins/git/gerrit/gerritplugin.cpp index 69025b11e91..802c921409a 100644 --- a/src/plugins/git/gerrit/gerritplugin.cpp +++ b/src/plugins/git/gerrit/gerritplugin.cpp @@ -60,7 +60,7 @@ class FetchContext : public QObject { Q_OBJECT public: - FetchContext(const QSharedPointer &change, + FetchContext(const std::shared_ptr &change, const FilePath &repository, const FilePath &git, const GerritServer &server, FetchMode fm, QObject *parent = nullptr); @@ -73,7 +73,7 @@ private: void cherryPick(); void checkout(); - const QSharedPointer m_change; + const std::shared_ptr m_change; const FilePath m_repository; const FetchMode m_fetchMode; const Utils::FilePath m_git; @@ -81,7 +81,7 @@ private: Process m_process; }; -FetchContext::FetchContext(const QSharedPointer &change, +FetchContext::FetchContext(const std::shared_ptr &change, const FilePath &repository, const FilePath &git, const GerritServer &server, FetchMode fm, QObject *parent) @@ -241,11 +241,11 @@ void GerritPlugin::openView() gd->setModal(false); ICore::registerWindow(gd, Context("Git.Gerrit")); connect(gd, &GerritDialog::fetchDisplay, this, - [this](const QSharedPointer &change) { fetch(change, FetchDisplay); }); + [this](const std::shared_ptr &change) { fetch(change, FetchDisplay); }); connect(gd, &GerritDialog::fetchCherryPick, this, - [this](const QSharedPointer &change) { fetch(change, FetchCherryPick); }); + [this](const std::shared_ptr &change) { fetch(change, FetchCherryPick); }); connect(gd, &GerritDialog::fetchCheckout, this, - [this](const QSharedPointer &change) { fetch(change, FetchCheckout); }); + [this](const std::shared_ptr &change) { fetch(change, FetchCheckout); }); connect(this, &GerritPlugin::fetchStarted, gd, &GerritDialog::fetchStarted); connect(this, &GerritPlugin::fetchFinished, gd, &GerritDialog::fetchFinished); m_dialog = gd; @@ -276,7 +276,7 @@ QString GerritPlugin::branch(const FilePath &repository) return gitClient().synchronousCurrentLocalBranch(repository); } -void GerritPlugin::fetch(const QSharedPointer &change, int mode) +void GerritPlugin::fetch(const std::shared_ptr &change, int mode) { // Locate git. const Utils::FilePath git = gitClient().vcsBinary(); @@ -287,7 +287,7 @@ void GerritPlugin::fetch(const QSharedPointer &change, int mode) FilePath repository; bool verifiedRepository = false; - if (!m_dialog.isNull() && !m_parameters.isNull() && m_dialog->repositoryPath().exists()) + if (m_dialog && m_parameters && m_dialog->repositoryPath().exists()) repository = m_dialog->repositoryPath(); if (!repository.isEmpty()) { diff --git a/src/plugins/git/gerrit/gerritplugin.h b/src/plugins/git/gerrit/gerritplugin.h index b7e0de29d81..b083d6a1883 100644 --- a/src/plugins/git/gerrit/gerritplugin.h +++ b/src/plugins/git/gerrit/gerritplugin.h @@ -7,7 +7,6 @@ #include #include -#include #include namespace Core { @@ -45,7 +44,7 @@ public: void updateActions(const VcsBase::VcsBasePluginState &state); signals: - void fetchStarted(const QSharedPointer &change); + void fetchStarted(const std::shared_ptr &change); void fetchFinished(); private: @@ -53,10 +52,10 @@ private: void push(); Utils::FilePath findLocalRepository(const QString &project, const QString &branch) const; - void fetch(const QSharedPointer &change, int mode); + void fetch(const std::shared_ptr &change, int mode); - QSharedPointer m_parameters; - QSharedPointer m_server; + std::shared_ptr m_parameters; + std::shared_ptr m_server; QPointer m_dialog; Core::Command *m_gerritCommand = nullptr; Core::Command *m_pushToGerritCommand = nullptr; diff --git a/src/plugins/git/gerrit/gerritpushdialog.cpp b/src/plugins/git/gerrit/gerritpushdialog.cpp index a7d28060faf..acbf62c9ee0 100644 --- a/src/plugins/git/gerrit/gerritpushdialog.cpp +++ b/src/plugins/git/gerrit/gerritpushdialog.cpp @@ -106,8 +106,10 @@ void GerritPushDialog::initRemoteBranches() m_remoteComboBox->updateRemotes(false); } -GerritPushDialog::GerritPushDialog(const Utils::FilePath &workingDir, const QString &reviewerList, - QSharedPointer parameters, QWidget *parent) +GerritPushDialog::GerritPushDialog(const Utils::FilePath &workingDir, + const QString &reviewerList, + std::shared_ptr parameters, + QWidget *parent) : QDialog(parent) , m_localBranchComboBox(new BranchComboBox) , m_remoteComboBox(new GerritRemoteChooser) diff --git a/src/plugins/git/gerrit/gerritpushdialog.h b/src/plugins/git/gerrit/gerritpushdialog.h index 88d8c746741..cd1d52ead3c 100644 --- a/src/plugins/git/gerrit/gerritpushdialog.h +++ b/src/plugins/git/gerrit/gerritpushdialog.h @@ -8,7 +8,6 @@ #include #include #include -#include QT_BEGIN_NAMESPACE class QCheckBox; @@ -33,7 +32,7 @@ class GerritPushDialog : public QDialog public: GerritPushDialog(const Utils::FilePath &workingDir, const QString &reviewerList, - QSharedPointer parameters, QWidget *parent); + std::shared_ptr parameters, QWidget *parent); QString selectedCommit() const; QString selectedRemoteName() const; diff --git a/src/plugins/git/gerrit/gerritremotechooser.cpp b/src/plugins/git/gerrit/gerritremotechooser.cpp index d3363051857..8d8bf17419e 100644 --- a/src/plugins/git/gerrit/gerritremotechooser.cpp +++ b/src/plugins/git/gerrit/gerritremotechooser.cpp @@ -51,7 +51,7 @@ void GerritRemoteChooser::setRepository(const FilePath &repository) m_repository = repository; } -void GerritRemoteChooser::setParameters(QSharedPointer parameters) +void GerritRemoteChooser::setParameters(std::shared_ptr parameters) { m_parameters = parameters; } diff --git a/src/plugins/git/gerrit/gerritremotechooser.h b/src/plugins/git/gerrit/gerritremotechooser.h index 2b182884cdf..f124479e2b3 100644 --- a/src/plugins/git/gerrit/gerritremotechooser.h +++ b/src/plugins/git/gerrit/gerritremotechooser.h @@ -8,7 +8,6 @@ #include #include -#include #include #include @@ -26,7 +25,7 @@ class GerritRemoteChooser : public QWidget public: GerritRemoteChooser(QWidget *parent = nullptr); void setRepository(const Utils::FilePath &repository); - void setParameters(QSharedPointer parameters); + void setParameters(std::shared_ptr parameters); void setFallbackEnabled(bool value); void setAllowDups(bool value); bool setCurrentRemote(const QString &remoteName); @@ -44,7 +43,7 @@ private: void handleRemoteChanged(); Utils::FilePath m_repository; - QSharedPointer m_parameters; + std::shared_ptr m_parameters; QComboBox *m_remoteComboBox = nullptr; QToolButton *m_resetRemoteButton = nullptr; bool m_updatingRemotes = false;