From 125abf502769c2ef092a2f5516d303f0333ae802 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Petr=20Mr=C3=A1zek?= Date: Tue, 20 Oct 2015 17:18:53 +0200 Subject: NOISSUE rename QObjectPtr to shared_qobject_ptr, introduce unique_qobject_ptr, refactor MainWindow to match --- logic/QObjectPtr.h | 29 +++++++++++++++++++++++------ logic/forge/ForgeVersionList.cpp | 4 ++-- logic/net/NetAction.h | 2 +- logic/net/NetJob.h | 2 +- 4 files changed, 27 insertions(+), 10 deletions(-) (limited to 'logic') diff --git a/logic/QObjectPtr.h b/logic/QObjectPtr.h index 32e59bd9..b81b3234 100644 --- a/logic/QObjectPtr.h +++ b/logic/QObjectPtr.h @@ -1,26 +1,43 @@ #pragma once #include +#include + +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 using unique_qobject_ptr = std::unique_ptr; /** - * 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 -class QObjectPtr +class shared_qobject_ptr { public: - QObjectPtr(){} - QObjectPtr(T * wrap) + shared_qobject_ptr(){} + shared_qobject_ptr(T * wrap) { reset(wrap); } - QObjectPtr(const QObjectPtr& other) + shared_qobject_ptr(const shared_qobject_ptr& other) { m_ptr = other.m_ptr; } template - QObjectPtr(const QObjectPtr &other) + shared_qobject_ptr(const shared_qobject_ptr &other) { m_ptr = other.unwrap(); } diff --git a/logic/forge/ForgeVersionList.cpp b/logic/forge/ForgeVersionList.cpp index 7f2176fd..a05ced99 100644 --- a/logic/forge/ForgeVersionList.cpp +++ b/logic/forge/ForgeVersionList.cpp @@ -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(); diff --git a/logic/net/NetAction.h b/logic/net/NetAction.h index faf4dbe0..1d7eb94b 100644 --- a/logic/net/NetAction.h +++ b/logic/net/NetAction.h @@ -61,7 +61,7 @@ public: public: /// the network reply - QObjectPtr m_reply; + unique_qobject_ptr m_reply; /// the content of the content-type header QString m_content_type; diff --git a/logic/net/NetJob.h b/logic/net/NetJob.h index 85a8bf83..45f6dacf 100644 --- a/logic/net/NetJob.h +++ b/logic/net/NetJob.h @@ -27,7 +27,7 @@ #include "multimc_logic_export.h" class NetJob; -typedef QObjectPtr NetJobPtr; +typedef shared_qobject_ptr NetJobPtr; class MULTIMC_LOGIC_EXPORT NetJob : public Task { -- cgit v1.2.3