diff options
author | Kitsune Ral <Kitsune-Ral@users.sf.net> | 2020-07-29 08:34:16 +0200 |
---|---|---|
committer | Kitsune Ral <Kitsune-Ral@users.sf.net> | 2020-07-29 08:34:16 +0200 |
commit | 7cba88bad28e1d3aa7a37b345b40325918030505 (patch) | |
tree | 4c9a1a9e5839aedf7b16b6036e33085ab1bedf04 | |
parent | 776c2fd5b3caa60903a3a15db728a00753e02d67 (diff) | |
download | libquotient-7cba88bad28e1d3aa7a37b345b40325918030505.tar.gz libquotient-7cba88bad28e1d3aa7a37b345b40325918030505.zip |
User: don't spend another pointer on Connection
Users are always parented to their Connection; there's no need to store
a pointer to the connection on top of the one already stored by QObject.
-rw-r--r-- | lib/user.cpp | 16 |
1 files changed, 7 insertions, 9 deletions
diff --git a/lib/user.cpp b/lib/user.cpp index 4ad74da2..522ae197 100644 --- a/lib/user.cpp +++ b/lib/user.cpp @@ -45,14 +45,12 @@ class User::Private { public: static Avatar makeAvatar(QUrl url) { return Avatar(move(url)); } - Private(QString userId, Connection* connection) + Private(QString userId) : userId(move(userId)) - , connection(connection) , hueF(stringToHueF(this->userId)) {} QString userId; - Connection* connection; QString mostUsedName; QMultiHash<QString, const Room*> otherNames; @@ -110,7 +108,7 @@ void User::Private::setNameForRoom(const Room* r, QString newName, et.start(); } - for (auto* r1: connection->allRooms()) + for (auto* r1: r->connection()->allRooms()) if (nameForRoom(r1) == mostUsedName) otherNames.insert(mostUsedName, r1); @@ -174,7 +172,7 @@ void User::Private::setAvatarForRoom(const Room* r, const QUrl& newUrl, nextMostUsedIt = otherAvatars.end() - 1; } std::swap(mostUsedAvatar, *nextMostUsedIt); - for (const auto* r1: connection->allRooms()) + for (const auto* r1: r->connection()->allRooms()) if (avatarUrlForRoom(r1) == nextMostUsedIt->url()) avatarsToRooms.insert(nextMostUsedIt->url(), r1); @@ -189,15 +187,15 @@ void User::Private::setAvatarForRoom(const Room* r, const QUrl& newUrl, } User::User(QString userId, Connection* connection) - : QObject(connection), d(new Private(move(userId), connection)) + : QObject(connection), d(new Private(move(userId))) { setObjectName(userId); } Connection* User::connection() const { - Q_ASSERT(d->connection); - return d->connection; + Q_ASSERT(parent()); + return static_cast<Connection*>(parent()); } User::~User() = default; @@ -338,7 +336,7 @@ QImage User::avatar(int width, int height, const Room* room) QImage User::avatar(int width, int height, const Room* room, const Avatar::get_callback_t& callback) { - return avatarObject(room).get(d->connection, width, height, [=] { + return avatarObject(room).get(connection(), width, height, [=] { emit avatarChanged(this, room); callback(); }); |