gcc Pepega
This commit is contained in:
+10
-9
@@ -3,8 +3,7 @@
|
|||||||
#include <QObject>
|
#include <QObject>
|
||||||
#include <type_traits>
|
#include <type_traits>
|
||||||
|
|
||||||
namespace chatterino
|
namespace chatterino {
|
||||||
{
|
|
||||||
/// Holds a pointer to a QObject and resets it to nullptr if the QObject
|
/// Holds a pointer to a QObject and resets it to nullptr if the QObject
|
||||||
/// gets destroyed.
|
/// gets destroyed.
|
||||||
template <typename T>
|
template <typename T>
|
||||||
@@ -20,17 +19,18 @@ namespace chatterino
|
|||||||
{
|
{
|
||||||
static_assert(std::is_base_of_v<QObject, T>);
|
static_assert(std::is_base_of_v<QObject, T>);
|
||||||
|
|
||||||
this->swap(t);
|
this->set(t);
|
||||||
}
|
}
|
||||||
|
|
||||||
~QObjectRef()
|
~QObjectRef()
|
||||||
{
|
{
|
||||||
this->swap(nullptr);
|
this->set(nullptr);
|
||||||
}
|
}
|
||||||
|
|
||||||
QObjectRef &operator=(T *t)
|
QObjectRef &operator=(T *t)
|
||||||
{
|
{
|
||||||
this->swap(t);
|
this->set(t);
|
||||||
|
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -49,7 +49,8 @@ namespace chatterino
|
|||||||
return t_;
|
return t_;
|
||||||
}
|
}
|
||||||
|
|
||||||
QObject* swap(T* other)
|
private:
|
||||||
|
void set(T *other)
|
||||||
{
|
{
|
||||||
// old
|
// old
|
||||||
if (this->conn_)
|
if (this->conn_)
|
||||||
@@ -60,14 +61,14 @@ namespace chatterino
|
|||||||
// new
|
// new
|
||||||
if (other)
|
if (other)
|
||||||
{
|
{
|
||||||
|
this->conn_ =
|
||||||
QObject::connect(other, &QObject::destroyed,
|
QObject::connect(other, &QObject::destroyed,
|
||||||
[this]() { this->swap(nullptr); });
|
[this](QObject *) { this->set(nullptr); });
|
||||||
}
|
}
|
||||||
|
|
||||||
return std::exchange(this->t_, other);
|
this->t_ = other;
|
||||||
}
|
}
|
||||||
|
|
||||||
private:
|
|
||||||
T *t_{};
|
T *t_{};
|
||||||
QMetaObject::Connection conn_;
|
QMetaObject::Connection conn_;
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -2,6 +2,7 @@
|
|||||||
|
|
||||||
#include "util/QObjectRef.hpp"
|
#include "util/QObjectRef.hpp"
|
||||||
#include "widgets/BaseWidget.hpp"
|
#include "widgets/BaseWidget.hpp"
|
||||||
|
#include "widgets/dialogs/EmotePopup.hpp"
|
||||||
|
|
||||||
#include <QHBoxLayout>
|
#include <QHBoxLayout>
|
||||||
#include <QLabel>
|
#include <QLabel>
|
||||||
|
|||||||
Reference in New Issue
Block a user