diff options
author | Petr Mrázek <peterix@gmail.com> | 2015-10-20 17:18:53 +0200 |
---|---|---|
committer | Petr Mrázek <peterix@gmail.com> | 2015-10-20 17:18:53 +0200 |
commit | 125abf502769c2ef092a2f5516d303f0333ae802 (patch) | |
tree | 25af0ffea303f1e549ac1a298c03b6862b1b71a3 /logic/QObjectPtr.h | |
parent | 9ad99ac4816cb879ec9f1805e7b8d7d3774a9588 (diff) | |
download | MultiMC-125abf502769c2ef092a2f5516d303f0333ae802.tar MultiMC-125abf502769c2ef092a2f5516d303f0333ae802.tar.gz MultiMC-125abf502769c2ef092a2f5516d303f0333ae802.tar.lz MultiMC-125abf502769c2ef092a2f5516d303f0333ae802.tar.xz MultiMC-125abf502769c2ef092a2f5516d303f0333ae802.zip |
NOISSUE rename QObjectPtr to shared_qobject_ptr, introduce unique_qobject_ptr, refactor MainWindow to match
Diffstat (limited to 'logic/QObjectPtr.h')
-rw-r--r-- | logic/QObjectPtr.h | 29 |
1 files changed, 23 insertions, 6 deletions
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 <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(); } |