Skip to content

Commit

Permalink
Remove QObjectRef in favor of QPointer (#4666)
Browse files Browse the repository at this point in the history
* replace usage of QObjectRef with QPointer

* delete QObjectRef class

* inlucde QPointer header

* Add changelog entry

* use isNull() instead of ! data()

---------

Co-authored-by: Rasmus Karlsson <[email protected]>
  • Loading branch information
4rneee and pajlada authored Jun 4, 2023
1 parent e803b6d commit 6681ed5
Show file tree
Hide file tree
Showing 7 changed files with 20 additions and 105 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
- Dev: Expanded upon `$$$` test channels. (#4655)
- Dev: Added tools to help debug image GC. (#4578)
- Dev: Removed duplicate license when having plugins enabled. (#4665)
- Dev: Replace our QObjectRef class with Qt's QPointer class. (#4666)

## 2.4.4

Expand Down
10 changes: 5 additions & 5 deletions src/common/NetworkPrivate.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ void loadUncached(std::shared_ptr<NetworkData> &&data)
}

auto handleReply = [data, reply]() mutable {
if (data->hasCaller_ && !data->caller_.get())
if (data->hasCaller_ && data->caller_.isNull())
{
return;
}
Expand Down Expand Up @@ -350,7 +350,7 @@ void loadCached(std::shared_ptr<NetworkData> &&data)
// XXX: If outcome is Failure, we should invalidate the cache file
// somehow/somewhere
/*auto outcome =*/
if (data->hasCaller_ && !data->caller_.get())
if (data->hasCaller_ && data->caller_.isNull())
{
return;
}
Expand All @@ -359,7 +359,7 @@ void loadCached(std::shared_ptr<NetworkData> &&data)
else
{
postToThread([data, result]() {
if (data->hasCaller_ && !data->caller_.get())
if (data->hasCaller_ && data->caller_.isNull())
{
return;
}
Expand All @@ -373,7 +373,7 @@ void loadCached(std::shared_ptr<NetworkData> &&data)
{
if (data->executeConcurrently_ || isGuiThread())
{
if (data->hasCaller_ && !data->caller_.get())
if (data->hasCaller_ && data->caller_.isNull())
{
return;
}
Expand All @@ -383,7 +383,7 @@ void loadCached(std::shared_ptr<NetworkData> &&data)
else
{
postToThread([data]() {
if (data->hasCaller_ && !data->caller_.get())
if (data->hasCaller_ && data->caller_.isNull())
{
return;
}
Expand Down
4 changes: 2 additions & 2 deletions src/common/NetworkPrivate.hpp
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
#pragma once

#include "common/NetworkCommon.hpp"
#include "util/QObjectRef.hpp"

#include <QHttpMultiPart>
#include <QNetworkRequest>
#include <QPointer>
#include <QTimer>

#include <functional>
Expand Down Expand Up @@ -38,7 +38,7 @@ struct NetworkData {

QNetworkRequest request_;
bool hasCaller_{};
QObjectRef<QObject> caller_;
QPointer<QObject> caller_;
bool cache_{};
bool executeConcurrently_{};

Expand Down
4 changes: 2 additions & 2 deletions src/providers/irc/IrcServer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@
#include "providers/twitch/TwitchIrcServer.hpp" // NOTE: Included to access the mentions channel
#include "singletons/Settings.hpp"
#include "util/IrcHelpers.hpp"
#include "util/QObjectRef.hpp"

#include <QMetaEnum>
#include <QPointer>

#include <cassert>
#include <cstdlib>
Expand Down Expand Up @@ -151,7 +151,7 @@ void IrcServer::initializeConnection(IrcConnection *connection,
[[fallthrough]];
case IrcAuthType::Pass:
this->data_->getPassword(
this, [conn = new QObjectRef(connection) /* can't copy */,
this, [conn = new QPointer(connection) /* can't copy */,
this](const QString &password) mutable {
if (*conn)
{
Expand Down
86 changes: 0 additions & 86 deletions src/util/QObjectRef.hpp

This file was deleted.

14 changes: 7 additions & 7 deletions src/widgets/splits/SplitInput.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -630,7 +630,7 @@ bool SplitInput::eventFilter(QObject *obj, QEvent *event)
if (event->type() == QEvent::ShortcutOverride ||
event->type() == QEvent::Shortcut)
{
if (auto popup = this->inputCompletionPopup_.get())
if (auto popup = this->inputCompletionPopup_.data())
{
if (popup->isVisible())
{
Expand All @@ -650,7 +650,7 @@ void SplitInput::installKeyPressedEvent()
{
this->ui_.textEdit->keyPressed.disconnectAll();
this->ui_.textEdit->keyPressed.connect([this](QKeyEvent *event) {
if (auto *popup = this->inputCompletionPopup_.get())
if (auto *popup = this->inputCompletionPopup_.data())
{
if (popup->isVisible())
{
Expand Down Expand Up @@ -764,20 +764,20 @@ void SplitInput::updateCompletionPopup()

void SplitInput::showCompletionPopup(const QString &text, bool emoteCompletion)
{
if (!this->inputCompletionPopup_.get())
if (this->inputCompletionPopup_.isNull())
{
this->inputCompletionPopup_ = new InputCompletionPopup(this);
this->inputCompletionPopup_->setInputAction(
[that = QObjectRef(this)](const QString &text) mutable {
if (auto *this2 = that.get())
[that = QPointer(this)](const QString &text) mutable {
if (auto *this2 = that.data())
{
this2->insertCompletionText(text);
this2->hideCompletionPopup();
}
});
}

auto *popup = this->inputCompletionPopup_.get();
auto *popup = this->inputCompletionPopup_.data();
assert(popup);

if (emoteCompletion)
Expand All @@ -798,7 +798,7 @@ void SplitInput::showCompletionPopup(const QString &text, bool emoteCompletion)

void SplitInput::hideCompletionPopup()
{
if (auto *popup = this->inputCompletionPopup_.get())
if (auto *popup = this->inputCompletionPopup_.data())
{
popup->hide();
}
Expand Down
6 changes: 3 additions & 3 deletions src/widgets/splits/SplitInput.hpp
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
#pragma once

#include "util/QObjectRef.hpp"
#include "widgets/BaseWidget.hpp"

#include <QHBoxLayout>
#include <QLabel>
#include <QLineEdit>
#include <QPaintEvent>
#include <QPointer>
#include <QTextEdit>
#include <QVBoxLayout>
#include <QWidget>
Expand Down Expand Up @@ -113,8 +113,8 @@ class SplitInput : public BaseWidget

Split *const split_;
ChannelView *const channelView_;
QObjectRef<EmotePopup> emotePopup_;
QObjectRef<InputCompletionPopup> inputCompletionPopup_;
QPointer<EmotePopup> emotePopup_;
QPointer<InputCompletionPopup> inputCompletionPopup_;

struct {
ResizingTextEdit *textEdit;
Expand Down

0 comments on commit 6681ed5

Please sign in to comment.