mirror of
https://github.com/qbittorrent/qBittorrent.git
synced 2024-12-13 07:42:26 +03:00
Replace QScopedPointer with std::unqiue_ptr
These 2 types are very similar and we should prefer the one from C++ standard library, this reduces the number of types in our code base. Also see: https://stackoverflow.com/questions/40346393/should-i-use-qscopedpointer-or-stdunique-ptr#comment67966940_40346991
This commit is contained in:
parent
78ab0e4ba9
commit
5e3fddf456
7 changed files with 18 additions and 16 deletions
|
@ -30,13 +30,13 @@
|
||||||
#include <QtGlobal>
|
#include <QtGlobal>
|
||||||
|
|
||||||
#include <cstdlib>
|
#include <cstdlib>
|
||||||
|
#include <memory>
|
||||||
|
|
||||||
#if !defined Q_OS_WIN && !defined Q_OS_HAIKU
|
#if !defined Q_OS_WIN && !defined Q_OS_HAIKU
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#include <QDebug>
|
#include <QDebug>
|
||||||
#include <QScopedPointer>
|
|
||||||
#include <QThread>
|
#include <QThread>
|
||||||
|
|
||||||
#ifndef DISABLE_GUI
|
#ifndef DISABLE_GUI
|
||||||
|
@ -117,7 +117,7 @@ int main(int argc, char *argv[])
|
||||||
try {
|
try {
|
||||||
// Create Application
|
// Create Application
|
||||||
const QString appId = QLatin1String("qBittorrent-") + Utils::Misc::getUserIDString();
|
const QString appId = QLatin1String("qBittorrent-") + Utils::Misc::getUserIDString();
|
||||||
QScopedPointer<Application> app(new Application(appId, argc, argv));
|
std::unique_ptr<Application> app(new Application(appId, argc, argv));
|
||||||
|
|
||||||
const QBtCommandLineParameters params = app->commandLineArgs();
|
const QBtCommandLineParameters params = app->commandLineArgs();
|
||||||
|
|
||||||
|
|
|
@ -29,8 +29,6 @@
|
||||||
|
|
||||||
#include "profile.h"
|
#include "profile.h"
|
||||||
|
|
||||||
#include <QCoreApplication>
|
|
||||||
|
|
||||||
#include "private/profile_p.h"
|
#include "private/profile_p.h"
|
||||||
|
|
||||||
Profile *Profile::m_instance = nullptr;
|
Profile *Profile::m_instance = nullptr;
|
||||||
|
@ -50,14 +48,14 @@ Profile::~Profile() = default;
|
||||||
void Profile::initialize(const QString &rootProfilePath, const QString &configurationName,
|
void Profile::initialize(const QString &rootProfilePath, const QString &configurationName,
|
||||||
bool convertPathsToProfileRelative)
|
bool convertPathsToProfileRelative)
|
||||||
{
|
{
|
||||||
QScopedPointer<Private::Profile> profile(rootProfilePath.isEmpty()
|
std::unique_ptr<Private::Profile> profile(rootProfilePath.isEmpty()
|
||||||
? static_cast<Private::Profile *>(new Private::DefaultProfile(configurationName))
|
? static_cast<Private::Profile *>(new Private::DefaultProfile(configurationName))
|
||||||
: static_cast<Private::Profile *>(new Private::CustomProfile(rootProfilePath, configurationName)));
|
: static_cast<Private::Profile *>(new Private::CustomProfile(rootProfilePath, configurationName)));
|
||||||
|
|
||||||
QScopedPointer<Private::PathConverter> converter(convertPathsToProfileRelative
|
std::unique_ptr<Private::PathConverter> converter(convertPathsToProfileRelative
|
||||||
? static_cast<Private::PathConverter *>(new Private::Converter(profile->baseDirectory()))
|
? static_cast<Private::PathConverter *>(new Private::Converter(profile->baseDirectory()))
|
||||||
: static_cast<Private::PathConverter *>(new Private::NoConvertConverter()));
|
: static_cast<Private::PathConverter *>(new Private::NoConvertConverter()));
|
||||||
m_instance = new Profile(profile.take(), converter.take());
|
m_instance = new Profile(profile.release(), converter.release());
|
||||||
}
|
}
|
||||||
|
|
||||||
const Profile &Profile::instance()
|
const Profile &Profile::instance()
|
||||||
|
|
|
@ -32,7 +32,6 @@
|
||||||
|
|
||||||
#include <memory>
|
#include <memory>
|
||||||
|
|
||||||
#include <QScopedPointer>
|
|
||||||
#include <QSettings>
|
#include <QSettings>
|
||||||
#include <QString>
|
#include <QString>
|
||||||
|
|
||||||
|
@ -78,8 +77,8 @@ private:
|
||||||
bool convertPathsToProfileRelative);
|
bool convertPathsToProfileRelative);
|
||||||
void ensureDirectoryExists(SpecialFolder folder);
|
void ensureDirectoryExists(SpecialFolder folder);
|
||||||
|
|
||||||
QScopedPointer<Private::Profile> m_profileImpl;
|
const std::unique_ptr<Private::Profile> m_profileImpl;
|
||||||
QScopedPointer<Private::PathConverter> m_pathConverterImpl;
|
const std::unique_ptr<Private::PathConverter> m_pathConverterImpl;
|
||||||
static Profile *m_instance;
|
static Profile *m_instance;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -39,7 +39,6 @@
|
||||||
#include <QJsonDocument>
|
#include <QJsonDocument>
|
||||||
#include <QJsonObject>
|
#include <QJsonObject>
|
||||||
#include <QJsonValue>
|
#include <QJsonValue>
|
||||||
#include <QScopedPointer>
|
|
||||||
#include <QUrl>
|
#include <QUrl>
|
||||||
|
|
||||||
#include "../asyncfilestorage.h"
|
#include "../asyncfilestorage.h"
|
||||||
|
|
|
@ -29,8 +29,9 @@
|
||||||
#ifndef ADDNEWTORRENTDIALOG_H
|
#ifndef ADDNEWTORRENTDIALOG_H
|
||||||
#define ADDNEWTORRENTDIALOG_H
|
#define ADDNEWTORRENTDIALOG_H
|
||||||
|
|
||||||
|
#include <memory>
|
||||||
|
|
||||||
#include <QDialog>
|
#include <QDialog>
|
||||||
#include <QScopedPointer>
|
|
||||||
#include <QShortcut>
|
#include <QShortcut>
|
||||||
|
|
||||||
#include "base/bittorrent/addtorrentparams.h"
|
#include "base/bittorrent/addtorrentparams.h"
|
||||||
|
@ -113,7 +114,7 @@ private:
|
||||||
BitTorrent::TorrentInfo m_torrentInfo;
|
BitTorrent::TorrentInfo m_torrentInfo;
|
||||||
QByteArray m_headerState;
|
QByteArray m_headerState;
|
||||||
int m_oldIndex;
|
int m_oldIndex;
|
||||||
QScopedPointer<TorrentFileGuard> m_torrentGuard;
|
std::unique_ptr<TorrentFileGuard> m_torrentGuard;
|
||||||
BitTorrent::AddTorrentParams m_torrentParams;
|
BitTorrent::AddTorrentParams m_torrentParams;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -28,6 +28,8 @@
|
||||||
|
|
||||||
#include "fspathedit.h"
|
#include "fspathedit.h"
|
||||||
|
|
||||||
|
#include <memory>
|
||||||
|
|
||||||
#include <QAction>
|
#include <QAction>
|
||||||
#include <QApplication>
|
#include <QApplication>
|
||||||
#include <QCoreApplication>
|
#include <QCoreApplication>
|
||||||
|
@ -74,7 +76,7 @@ class FileSystemPathEdit::FileSystemPathEditPrivate
|
||||||
QString dialogCaptionOrDefault() const;
|
QString dialogCaptionOrDefault() const;
|
||||||
|
|
||||||
FileSystemPathEdit *q_ptr;
|
FileSystemPathEdit *q_ptr;
|
||||||
QScopedPointer<Private::FileEditorWithCompletion> m_editor;
|
std::unique_ptr<Private::FileEditorWithCompletion> m_editor;
|
||||||
QAction *m_browseAction;
|
QAction *m_browseAction;
|
||||||
QToolButton *m_browseBtn;
|
QToolButton *m_browseBtn;
|
||||||
QString m_fileNameFilter;
|
QString m_fileNameFilter;
|
||||||
|
@ -192,7 +194,10 @@ FileSystemPathEdit::FileSystemPathEdit(Private::FileEditorWithCompletion *editor
|
||||||
connect(d->m_browseAction, &QAction::triggered, this, [this]() { this->d_func()->browseActionTriggered(); });
|
connect(d->m_browseAction, &QAction::triggered, this, [this]() { this->d_func()->browseActionTriggered(); });
|
||||||
}
|
}
|
||||||
|
|
||||||
FileSystemPathEdit::~FileSystemPathEdit() = default;
|
FileSystemPathEdit::~FileSystemPathEdit()
|
||||||
|
{
|
||||||
|
delete d_ptr;
|
||||||
|
}
|
||||||
|
|
||||||
QString FileSystemPathEdit::selectedPath() const
|
QString FileSystemPathEdit::selectedPath() const
|
||||||
{
|
{
|
||||||
|
|
|
@ -105,7 +105,7 @@ private:
|
||||||
Q_DISABLE_COPY(FileSystemPathEdit)
|
Q_DISABLE_COPY(FileSystemPathEdit)
|
||||||
class FileSystemPathEditPrivate;
|
class FileSystemPathEditPrivate;
|
||||||
Q_DECLARE_PRIVATE(FileSystemPathEdit)
|
Q_DECLARE_PRIVATE(FileSystemPathEdit)
|
||||||
QScopedPointer<FileSystemPathEditPrivate> const d_ptr;
|
FileSystemPathEditPrivate *d_ptr;
|
||||||
};
|
};
|
||||||
|
|
||||||
/// Widget which uses QLineEdit for path editing
|
/// Widget which uses QLineEdit for path editing
|
||||||
|
|
Loading…
Reference in a new issue