NOISSUE rename QObjectPtr to shared_qobject_ptr, introduce unique_qobject_ptr, refactor MainWindow to match

This commit is contained in:
Petr Mrázek
2015-10-20 17:18:53 +02:00
parent 9ad99ac481
commit 125abf5027
9 changed files with 170 additions and 216 deletions

View File

@ -1,26 +1,43 @@
#pragma once
#include <memory>
#include <QObject>
namespace details
{
struct DeleteQObjectLater
{
void operator()(QObject *obj) const
{
obj->deleteLater();
}
};
}
/**
* A unique pointer class with unique pointer semantics intended for derivates of QObject
* Calls deleteLater() instead of destroying the contained object immediately
*/
template<typename T> using unique_qobject_ptr = std::unique_ptr<T, details::DeleteQObjectLater>;
/**
* A pointer class with the usual shared pointer semantics intended for derivates of QObject
* A shared pointer class with shared pointer semantics intended for derivates of QObject
* Calls deleteLater() instead of destroying the contained object immediately
*/
template <typename T>
class QObjectPtr
class shared_qobject_ptr
{
public:
QObjectPtr(){}
QObjectPtr(T * wrap)
shared_qobject_ptr(){}
shared_qobject_ptr(T * wrap)
{
reset(wrap);
}
QObjectPtr(const QObjectPtr<T>& other)
shared_qobject_ptr(const shared_qobject_ptr<T>& other)
{
m_ptr = other.m_ptr;
}
template<typename Derived>
QObjectPtr(const QObjectPtr<Derived> &other)
shared_qobject_ptr(const shared_qobject_ptr<Derived> &other)
{
m_ptr = other.unwrap();
}

View File

@ -424,7 +424,7 @@ void ForgeListLoadTask::listDownloaded()
void ForgeListLoadTask::listFailed()
{
auto reply = listDownload->m_reply;
auto &reply = listDownload->m_reply;
if (reply)
{
qCritical() << "Getting forge version list failed: " << reply->errorString();
@ -437,7 +437,7 @@ void ForgeListLoadTask::listFailed()
void ForgeListLoadTask::gradleListFailed()
{
auto reply = gradleListDownload->m_reply;
auto &reply = gradleListDownload->m_reply;
if (reply)
{
qCritical() << "Getting forge version list failed: " << reply->errorString();

View File

@ -61,7 +61,7 @@ public:
public:
/// the network reply
QObjectPtr<QNetworkReply> m_reply;
unique_qobject_ptr<QNetworkReply> m_reply;
/// the content of the content-type header
QString m_content_type;

View File

@ -27,7 +27,7 @@
#include "multimc_logic_export.h"
class NetJob;
typedef QObjectPtr<NetJob> NetJobPtr;
typedef shared_qobject_ptr<NetJob> NetJobPtr;
class MULTIMC_LOGIC_EXPORT NetJob : public Task
{