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 <orgads@gmail.com>
This commit is contained in:
Jarek Kobus
2024-02-01 15:46:01 +01:00
parent 2853237fd0
commit 243d063cb9
12 changed files with 48 additions and 55 deletions

View File

@@ -44,8 +44,8 @@ namespace Internal {
static const int maxTitleWidth = 350; static const int maxTitleWidth = 350;
GerritDialog::GerritDialog(const QSharedPointer<GerritParameters> &p, GerritDialog::GerritDialog(const std::shared_ptr<GerritParameters> &p,
const QSharedPointer<GerritServer> &s, const std::shared_ptr<GerritServer> &s,
const FilePath &repository, const FilePath &repository,
QWidget *parent) QWidget *parent)
: QDialog(parent) : QDialog(parent)
@@ -286,7 +286,7 @@ void GerritDialog::showEvent(QShowEvent *event)
void GerritDialog::remoteChanged() void GerritDialog::remoteChanged()
{ {
const GerritServer server = m_remoteComboBox->currentServer(); const GerritServer server = m_remoteComboBox->currentServer();
if (QSharedPointer<GerritServer> modelServer = m_model->server()) { if (std::shared_ptr<GerritServer> modelServer = m_model->server()) {
if (*modelServer == server) if (*modelServer == server)
return; return;
} }
@@ -335,7 +335,7 @@ void GerritDialog::slotCurrentChanged()
updateButtons(); updateButtons();
} }
void GerritDialog::fetchStarted(const QSharedPointer<GerritChange> &change) void GerritDialog::fetchStarted(const std::shared_ptr<GerritChange> &change)
{ {
// Disable buttons to prevent parallel gerrit operations which can cause mix-ups. // Disable buttons to prevent parallel gerrit operations which can cause mix-ups.
m_fetchRunning = true; m_fetchRunning = true;

View File

@@ -6,7 +6,6 @@
#include <utils/filepath.h> #include <utils/filepath.h>
#include <QDialog> #include <QDialog>
#include <QSharedPointer>
#include <QTimer> #include <QTimer>
#include <functional> #include <functional>
@@ -40,22 +39,22 @@ class GerritDialog : public QDialog
{ {
Q_OBJECT Q_OBJECT
public: public:
explicit GerritDialog(const QSharedPointer<GerritParameters> &p, explicit GerritDialog(const std::shared_ptr<GerritParameters> &p,
const QSharedPointer<GerritServer> &s, const std::shared_ptr<GerritServer> &s,
const Utils::FilePath &repository, const Utils::FilePath &repository,
QWidget *parent = nullptr); QWidget *parent = nullptr);
~GerritDialog() override; ~GerritDialog() override;
Utils::FilePath repositoryPath() const; Utils::FilePath repositoryPath() const;
void setCurrentPath(const Utils::FilePath &path); void setCurrentPath(const Utils::FilePath &path);
void fetchStarted(const QSharedPointer<Gerrit::Internal::GerritChange> &change); void fetchStarted(const std::shared_ptr<Gerrit::Internal::GerritChange> &change);
void fetchFinished(); void fetchFinished();
void refresh(); void refresh();
void scheduleUpdateRemotes(); void scheduleUpdateRemotes();
signals: signals:
void fetchDisplay(const QSharedPointer<Gerrit::Internal::GerritChange> &); void fetchDisplay(const std::shared_ptr<Gerrit::Internal::GerritChange> &);
void fetchCherryPick(const QSharedPointer<Gerrit::Internal::GerritChange> &); void fetchCherryPick(const std::shared_ptr<Gerrit::Internal::GerritChange> &);
void fetchCheckout(const QSharedPointer<Gerrit::Internal::GerritChange> &); void fetchCheckout(const std::shared_ptr<Gerrit::Internal::GerritChange> &);
private: private:
void slotCurrentChanged(); void slotCurrentChanged();
@@ -76,8 +75,8 @@ private:
QPushButton *addActionButton(const QString &text, const std::function<void ()> &buttonSlot); QPushButton *addActionButton(const QString &text, const std::function<void ()> &buttonSlot);
void updateButtons(); void updateButtons();
const QSharedPointer<GerritParameters> m_parameters; const std::shared_ptr<GerritParameters> m_parameters;
const QSharedPointer<GerritServer> m_server; const std::shared_ptr<GerritServer> m_server;
QSortFilterProxyModel *m_filterModel; QSortFilterProxyModel *m_filterModel;
GerritModel *m_model; GerritModel *m_model;
QStringListModel *m_queryModel; QStringListModel *m_queryModel;

View File

@@ -64,7 +64,7 @@ QDebug operator<<(QDebug d, const GerritChange &c)
} }
// Format default Url for a change // Format default Url for a change
static inline QString defaultUrl(const QSharedPointer<GerritParameters> &p, static inline QString defaultUrl(const std::shared_ptr<GerritParameters> &p,
const GerritServer &server, const GerritServer &server,
int gerritNumber) int gerritNumber)
{ {
@@ -208,7 +208,7 @@ class QueryContext : public QObject
Q_OBJECT Q_OBJECT
public: public:
QueryContext(const QString &query, QueryContext(const QString &query,
const QSharedPointer<GerritParameters> &p, const std::shared_ptr<GerritParameters> &p,
const GerritServer &server, const GerritServer &server,
QObject *parent = nullptr); QObject *parent = nullptr);
@@ -236,7 +236,7 @@ private:
enum { timeOutMS = 30000 }; enum { timeOutMS = 30000 };
QueryContext::QueryContext(const QString &query, QueryContext::QueryContext(const QString &query,
const QSharedPointer<GerritParameters> &p, const std::shared_ptr<GerritParameters> &p,
const GerritServer &server, const GerritServer &server,
QObject *parent) QObject *parent)
: QObject(parent) : QObject(parent)
@@ -338,7 +338,7 @@ void QueryContext::timeout()
m_timer.start(); m_timer.start();
} }
GerritModel::GerritModel(const QSharedPointer<GerritParameters> &p, QObject *parent) GerritModel::GerritModel(const std::shared_ptr<GerritParameters> &p, QObject *parent)
: QStandardItemModel(0, ColumnCount, parent) : QStandardItemModel(0, ColumnCount, parent)
, m_parameters(p) , m_parameters(p)
{ {
@@ -445,7 +445,7 @@ QStandardItem *GerritModel::itemForNumber(int number) const
return nullptr; return nullptr;
} }
void GerritModel::refresh(const QSharedPointer<GerritServer> &server, const QString &query) void GerritModel::refresh(const std::shared_ptr<GerritServer> &server, const QString &query)
{ {
if (m_query) if (m_query)
m_query->terminate(); m_query->terminate();
@@ -731,7 +731,7 @@ static GerritChangePtr parseRestOutput(const QJsonObject &object, const GerritSe
return change; return change;
} }
static bool parseOutput(const QSharedPointer<GerritParameters> &parameters, static bool parseOutput(const std::shared_ptr<GerritParameters> &parameters,
const GerritServer &server, const GerritServer &server,
const QByteArray &output, const QByteArray &output,
QList<GerritChangePtr> &result) QList<GerritChangePtr> &result)

View File

@@ -7,7 +7,6 @@
#include "gerritserver.h" #include "gerritserver.h"
#include <QStandardItemModel> #include <QStandardItemModel>
#include <QSharedPointer>
#include <QDateTime> #include <QDateTime>
namespace Gerrit { namespace Gerrit {
@@ -57,7 +56,7 @@ public:
int depth = -1; int depth = -1;
}; };
using GerritChangePtr = QSharedPointer<GerritChange>; using GerritChangePtr = std::shared_ptr<GerritChange>;
class GerritModel : public QStandardItemModel class GerritModel : public QStandardItemModel
{ {
@@ -79,7 +78,7 @@ public:
GerritChangeRole = Qt::UserRole + 2, GerritChangeRole = Qt::UserRole + 2,
SortRole = Qt::UserRole + 3 SortRole = Qt::UserRole + 3
}; };
GerritModel(const QSharedPointer<GerritParameters> &, QObject *parent = nullptr); GerritModel(const std::shared_ptr<GerritParameters> &, QObject *parent = nullptr);
~GerritModel() override; ~GerritModel() override;
QVariant data(const QModelIndex &index, int role) const override; QVariant data(const QModelIndex &index, int role) const override;
@@ -88,12 +87,12 @@ public:
QString toHtml(const QModelIndex &index) const; QString toHtml(const QModelIndex &index) const;
QStandardItem *itemForNumber(int number) const; QStandardItem *itemForNumber(int number) const;
QSharedPointer<GerritServer> server() const { return m_server; } std::shared_ptr<GerritServer> server() const { return m_server; }
enum QueryState { Idle, Running, Ok, Error }; enum QueryState { Idle, Running, Ok, Error };
QueryState state() const { return m_state; } QueryState state() const { return m_state; }
void refresh(const QSharedPointer<GerritServer> &server, const QString &query); void refresh(const std::shared_ptr<GerritServer> &server, const QString &query);
signals: signals:
void refreshStateChanged(bool isRefreshing); // For disabling the "Refresh" button. void refreshStateChanged(bool isRefreshing); // For disabling the "Refresh" button.
@@ -111,13 +110,11 @@ private:
const QString &serverPrefix) const; const QString &serverPrefix) const;
QList<QStandardItem *> changeToRow(const GerritChangePtr &c) const; QList<QStandardItem *> changeToRow(const GerritChangePtr &c) const;
const QSharedPointer<GerritParameters> m_parameters; const std::shared_ptr<GerritParameters> m_parameters;
QSharedPointer<GerritServer> m_server; std::shared_ptr<GerritServer> m_server;
QueryContext *m_query = nullptr; QueryContext *m_query = nullptr;
QueryState m_state = Idle; QueryState m_state = Idle;
}; };
} // namespace Internal } // namespace Internal
} // namespace Gerrit } // namespace Gerrit
Q_DECLARE_METATYPE(Gerrit::Internal::GerritChangePtr)

View File

@@ -23,7 +23,7 @@ namespace Gerrit::Internal {
class GerritOptionsWidget : public Core::IOptionsPageWidget class GerritOptionsWidget : public Core::IOptionsPageWidget
{ {
public: public:
GerritOptionsWidget(const QSharedPointer<GerritParameters> &p, GerritOptionsWidget(const std::shared_ptr<GerritParameters> &p,
const std::function<void()> &onChanged) const std::function<void()> &onChanged)
: m_parameters(p) : m_parameters(p)
{ {
@@ -87,12 +87,12 @@ public:
} }
private: private:
const QSharedPointer<GerritParameters> &m_parameters; const std::shared_ptr<GerritParameters> &m_parameters;
}; };
// GerritOptionsPage // GerritOptionsPage
GerritOptionsPage::GerritOptionsPage(const QSharedPointer<GerritParameters> &p, GerritOptionsPage::GerritOptionsPage(const std::shared_ptr<GerritParameters> &p,
const std::function<void()> &onChanged) const std::function<void()> &onChanged)
{ {
setId("Gerrit"); setId("Gerrit");

View File

@@ -5,8 +5,6 @@
#include <coreplugin/dialogs/ioptionspage.h> #include <coreplugin/dialogs/ioptionspage.h>
#include <QSharedPointer>
namespace Gerrit::Internal { namespace Gerrit::Internal {
class GerritParameters; class GerritParameters;
@@ -14,7 +12,7 @@ class GerritParameters;
class GerritOptionsPage : public Core::IOptionsPage class GerritOptionsPage : public Core::IOptionsPage
{ {
public: public:
GerritOptionsPage(const QSharedPointer<GerritParameters> &p, GerritOptionsPage(const std::shared_ptr<GerritParameters> &p,
const std::function<void()> &onChanged); const std::function<void()> &onChanged);
}; };

View File

@@ -60,7 +60,7 @@ class FetchContext : public QObject
{ {
Q_OBJECT Q_OBJECT
public: public:
FetchContext(const QSharedPointer<GerritChange> &change, FetchContext(const std::shared_ptr<GerritChange> &change,
const FilePath &repository, const FilePath &git, const FilePath &repository, const FilePath &git,
const GerritServer &server, const GerritServer &server,
FetchMode fm, QObject *parent = nullptr); FetchMode fm, QObject *parent = nullptr);
@@ -73,7 +73,7 @@ private:
void cherryPick(); void cherryPick();
void checkout(); void checkout();
const QSharedPointer<GerritChange> m_change; const std::shared_ptr<GerritChange> m_change;
const FilePath m_repository; const FilePath m_repository;
const FetchMode m_fetchMode; const FetchMode m_fetchMode;
const Utils::FilePath m_git; const Utils::FilePath m_git;
@@ -81,7 +81,7 @@ private:
Process m_process; Process m_process;
}; };
FetchContext::FetchContext(const QSharedPointer<GerritChange> &change, FetchContext::FetchContext(const std::shared_ptr<GerritChange> &change,
const FilePath &repository, const FilePath &git, const FilePath &repository, const FilePath &git,
const GerritServer &server, const GerritServer &server,
FetchMode fm, QObject *parent) FetchMode fm, QObject *parent)
@@ -241,11 +241,11 @@ void GerritPlugin::openView()
gd->setModal(false); gd->setModal(false);
ICore::registerWindow(gd, Context("Git.Gerrit")); ICore::registerWindow(gd, Context("Git.Gerrit"));
connect(gd, &GerritDialog::fetchDisplay, this, connect(gd, &GerritDialog::fetchDisplay, this,
[this](const QSharedPointer<GerritChange> &change) { fetch(change, FetchDisplay); }); [this](const std::shared_ptr<GerritChange> &change) { fetch(change, FetchDisplay); });
connect(gd, &GerritDialog::fetchCherryPick, this, connect(gd, &GerritDialog::fetchCherryPick, this,
[this](const QSharedPointer<GerritChange> &change) { fetch(change, FetchCherryPick); }); [this](const std::shared_ptr<GerritChange> &change) { fetch(change, FetchCherryPick); });
connect(gd, &GerritDialog::fetchCheckout, this, connect(gd, &GerritDialog::fetchCheckout, this,
[this](const QSharedPointer<GerritChange> &change) { fetch(change, FetchCheckout); }); [this](const std::shared_ptr<GerritChange> &change) { fetch(change, FetchCheckout); });
connect(this, &GerritPlugin::fetchStarted, gd, &GerritDialog::fetchStarted); connect(this, &GerritPlugin::fetchStarted, gd, &GerritDialog::fetchStarted);
connect(this, &GerritPlugin::fetchFinished, gd, &GerritDialog::fetchFinished); connect(this, &GerritPlugin::fetchFinished, gd, &GerritDialog::fetchFinished);
m_dialog = gd; m_dialog = gd;
@@ -276,7 +276,7 @@ QString GerritPlugin::branch(const FilePath &repository)
return gitClient().synchronousCurrentLocalBranch(repository); return gitClient().synchronousCurrentLocalBranch(repository);
} }
void GerritPlugin::fetch(const QSharedPointer<GerritChange> &change, int mode) void GerritPlugin::fetch(const std::shared_ptr<GerritChange> &change, int mode)
{ {
// Locate git. // Locate git.
const Utils::FilePath git = gitClient().vcsBinary(); const Utils::FilePath git = gitClient().vcsBinary();
@@ -287,7 +287,7 @@ void GerritPlugin::fetch(const QSharedPointer<GerritChange> &change, int mode)
FilePath repository; FilePath repository;
bool verifiedRepository = false; 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(); repository = m_dialog->repositoryPath();
if (!repository.isEmpty()) { if (!repository.isEmpty()) {

View File

@@ -7,7 +7,6 @@
#include <QObject> #include <QObject>
#include <QPointer> #include <QPointer>
#include <QSharedPointer>
#include <QPair> #include <QPair>
namespace Core { namespace Core {
@@ -45,7 +44,7 @@ public:
void updateActions(const VcsBase::VcsBasePluginState &state); void updateActions(const VcsBase::VcsBasePluginState &state);
signals: signals:
void fetchStarted(const QSharedPointer<Gerrit::Internal::GerritChange> &change); void fetchStarted(const std::shared_ptr<Gerrit::Internal::GerritChange> &change);
void fetchFinished(); void fetchFinished();
private: private:
@@ -53,10 +52,10 @@ private:
void push(); void push();
Utils::FilePath findLocalRepository(const QString &project, const QString &branch) const; Utils::FilePath findLocalRepository(const QString &project, const QString &branch) const;
void fetch(const QSharedPointer<GerritChange> &change, int mode); void fetch(const std::shared_ptr<GerritChange> &change, int mode);
QSharedPointer<GerritParameters> m_parameters; std::shared_ptr<GerritParameters> m_parameters;
QSharedPointer<GerritServer> m_server; std::shared_ptr<GerritServer> m_server;
QPointer<GerritDialog> m_dialog; QPointer<GerritDialog> m_dialog;
Core::Command *m_gerritCommand = nullptr; Core::Command *m_gerritCommand = nullptr;
Core::Command *m_pushToGerritCommand = nullptr; Core::Command *m_pushToGerritCommand = nullptr;

View File

@@ -106,8 +106,10 @@ void GerritPushDialog::initRemoteBranches()
m_remoteComboBox->updateRemotes(false); m_remoteComboBox->updateRemotes(false);
} }
GerritPushDialog::GerritPushDialog(const Utils::FilePath &workingDir, const QString &reviewerList, GerritPushDialog::GerritPushDialog(const Utils::FilePath &workingDir,
QSharedPointer<GerritParameters> parameters, QWidget *parent) const QString &reviewerList,
std::shared_ptr<GerritParameters> parameters,
QWidget *parent)
: QDialog(parent) : QDialog(parent)
, m_localBranchComboBox(new BranchComboBox) , m_localBranchComboBox(new BranchComboBox)
, m_remoteComboBox(new GerritRemoteChooser) , m_remoteComboBox(new GerritRemoteChooser)

View File

@@ -8,7 +8,6 @@
#include <QDialog> #include <QDialog>
#include <QMultiMap> #include <QMultiMap>
#include <QDate> #include <QDate>
#include <QSharedPointer>
QT_BEGIN_NAMESPACE QT_BEGIN_NAMESPACE
class QCheckBox; class QCheckBox;
@@ -33,7 +32,7 @@ class GerritPushDialog : public QDialog
public: public:
GerritPushDialog(const Utils::FilePath &workingDir, const QString &reviewerList, GerritPushDialog(const Utils::FilePath &workingDir, const QString &reviewerList,
QSharedPointer<GerritParameters> parameters, QWidget *parent); std::shared_ptr<GerritParameters> parameters, QWidget *parent);
QString selectedCommit() const; QString selectedCommit() const;
QString selectedRemoteName() const; QString selectedRemoteName() const;

View File

@@ -51,7 +51,7 @@ void GerritRemoteChooser::setRepository(const FilePath &repository)
m_repository = repository; m_repository = repository;
} }
void GerritRemoteChooser::setParameters(QSharedPointer<GerritParameters> parameters) void GerritRemoteChooser::setParameters(std::shared_ptr<GerritParameters> parameters)
{ {
m_parameters = parameters; m_parameters = parameters;
} }

View File

@@ -8,7 +8,6 @@
#include <utils/filepath.h> #include <utils/filepath.h>
#include <QComboBox> #include <QComboBox>
#include <QSharedPointer>
#include <QToolButton> #include <QToolButton>
#include <QWidget> #include <QWidget>
@@ -26,7 +25,7 @@ class GerritRemoteChooser : public QWidget
public: public:
GerritRemoteChooser(QWidget *parent = nullptr); GerritRemoteChooser(QWidget *parent = nullptr);
void setRepository(const Utils::FilePath &repository); void setRepository(const Utils::FilePath &repository);
void setParameters(QSharedPointer<GerritParameters> parameters); void setParameters(std::shared_ptr<GerritParameters> parameters);
void setFallbackEnabled(bool value); void setFallbackEnabled(bool value);
void setAllowDups(bool value); void setAllowDups(bool value);
bool setCurrentRemote(const QString &remoteName); bool setCurrentRemote(const QString &remoteName);
@@ -44,7 +43,7 @@ private:
void handleRemoteChanged(); void handleRemoteChanged();
Utils::FilePath m_repository; Utils::FilePath m_repository;
QSharedPointer<GerritParameters> m_parameters; std::shared_ptr<GerritParameters> m_parameters;
QComboBox *m_remoteComboBox = nullptr; QComboBox *m_remoteComboBox = nullptr;
QToolButton *m_resetRemoteButton = nullptr; QToolButton *m_resetRemoteButton = nullptr;
bool m_updatingRemotes = false; bool m_updatingRemotes = false;