From 7f935665f90daa5947ba44822f7748642c08338b Mon Sep 17 00:00:00 2001 From: pajlada Date: Mon, 15 Jan 2024 22:30:34 +0100 Subject: [PATCH] refactor: Remove the `NullablePtr` class (#5091) --- CHANGELOG.md | 2 +- src/common/NullablePtr.hpp | 73 ------------------------------------ src/widgets/splits/Split.cpp | 3 +- src/widgets/splits/Split.hpp | 4 +- 4 files changed, 4 insertions(+), 78 deletions(-) delete mode 100644 src/common/NullablePtr.hpp diff --git a/CHANGELOG.md b/CHANGELOG.md index cee952cf9..2b1d1f0b3 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -109,7 +109,7 @@ - Dev: Fixed deadlock and use-after-free in tests. (#4981) - Dev: Moved all `.clang-format` files to the root directory. (#5037) - Dev: Load less message history upon reconnects. (#5001, #5018) -- Dev: Load less message history upon reconnects. (#5001) +- Dev: Removed the `NullablePtr` class. (#5091) - Dev: BREAKING: Replace custom `import()` with normal Lua `require()`. (#5014) - Dev: Fixed most compiler warnings. (#5028) - Dev: Added the ability to show `ChannelView`s without a `Split`. (#4747) diff --git a/src/common/NullablePtr.hpp b/src/common/NullablePtr.hpp deleted file mode 100644 index 9fa1b9fb6..000000000 --- a/src/common/NullablePtr.hpp +++ /dev/null @@ -1,73 +0,0 @@ -#pragma once - -#include - -namespace chatterino { - -template -class NullablePtr -{ -public: - NullablePtr() - : element_(nullptr) - { - } - - NullablePtr(T *element) - : element_(element) - { - } - - T *operator->() const - { - assert(this->hasElement()); - - return element_; - } - - typename std::add_lvalue_reference::type operator*() const - { - assert(this->hasElement()); - - return *element_; - } - - T *get() const - { - assert(this->hasElement()); - - return this->element_; - } - - bool isNull() const - { - return this->element_ == nullptr; - } - - bool hasElement() const - { - return this->element_ != nullptr; - } - - operator bool() const - { - return this->hasElement(); - } - - bool operator!() const - { - return !this->hasElement(); - } - - template ::value>> - operator NullablePtr() const - { - return NullablePtr(this->element_); - } - -private: - T *element_; -}; - -} // namespace chatterino diff --git a/src/widgets/splits/Split.cpp b/src/widgets/splits/Split.cpp index 134a36de2..b36503071 100644 --- a/src/widgets/splits/Split.cpp +++ b/src/widgets/splits/Split.cpp @@ -911,7 +911,7 @@ void Split::insertTextToInput(const QString &text) void Split::showChangeChannelPopup(const char *dialogTitle, bool empty, std::function callback) { - if (this->selectChannelDialog_.hasElement()) + if (!this->selectChannelDialog_.isNull()) { this->selectChannelDialog_->raise(); @@ -935,7 +935,6 @@ void Split::showChangeChannelPopup(const char *dialogTitle, bool empty, } callback(dialog->hasSeletedChannel()); - this->selectChannelDialog_ = nullptr; }); this->selectChannelDialog_ = dialog; } diff --git a/src/widgets/splits/Split.hpp b/src/widgets/splits/Split.hpp index 644a892a9..bc98de5e7 100644 --- a/src/widgets/splits/Split.hpp +++ b/src/widgets/splits/Split.hpp @@ -2,13 +2,13 @@ #include "common/Aliases.hpp" #include "common/Channel.hpp" -#include "common/NullablePtr.hpp" #include "widgets/BaseWidget.hpp" #include "widgets/splits/SplitCommon.hpp" #include #include #include +#include #include #include #include @@ -155,7 +155,7 @@ private: SplitInput *const input_; SplitOverlay *const overlay_; - NullablePtr selectChannelDialog_; + QPointer selectChannelDialog_; pajlada::Signals::Connection channelIDChangedConnection_; pajlada::Signals::Connection usermodeChangedConnection_;