From 0dbf41133cdc9d8b73592f78db117396bc7bd2da Mon Sep 17 00:00:00 2001 From: Kitsune Ral Date: Mon, 8 Jan 2018 07:41:57 +0900 Subject: Avatar: Mark get() as const operation With all the liberty that pimpl idiom gives it's easy to get away without proper const's; but let's be consistent :) --- avatar.cpp | 22 +++++++++++----------- avatar.h | 4 ++-- 2 files changed, 13 insertions(+), 13 deletions(-) diff --git a/avatar.cpp b/avatar.cpp index eeb61f30..ee7db6ed 100644 --- a/avatar.cpp +++ b/avatar.cpp @@ -30,19 +30,19 @@ class Avatar::Private { public: Private(Connection* c, QIcon di) : _connection(c), _defaultIcon(di) { } - QImage get(QSize size, Avatar::notifier_t notifier); + QImage get(QSize size, Avatar::notifier_t notifier) const; Connection* _connection; const QIcon _defaultIcon; QUrl _url; - QImage _originalImage; - std::vector> _scaledImages; - - QSize _requestedSize; - bool _valid = false; - MediaThumbnailJob* _ongoingRequest = nullptr; - std::vector notifiers; + // The below are related to image caching, hence mutable + mutable QImage _originalImage; + mutable std::vector> _scaledImages; + mutable QSize _requestedSize; + mutable bool _valid = false; + mutable MediaThumbnailJob* _ongoingRequest = nullptr; + mutable std::vector notifiers; }; Avatar::Avatar(Connection* connection, QIcon defaultIcon) @@ -51,17 +51,17 @@ Avatar::Avatar(Connection* connection, QIcon defaultIcon) Avatar::~Avatar() = default; -QImage Avatar::get(int dimension, Avatar::notifier_t notifier) +QImage Avatar::get(int dimension, notifier_t notifier) const { return d->get({dimension, dimension}, notifier); } -QImage Avatar::get(int width, int height, Avatar::notifier_t notifier) +QImage Avatar::get(int width, int height, notifier_t notifier) const { return d->get({width, height}, notifier); } -QImage Avatar::Private::get(QSize size, Avatar::notifier_t notifier) +QImage Avatar::Private::get(QSize size, Avatar::notifier_t notifier) const { // FIXME: Alternating between longer-width and longer-height requests // is a sure way to trick the below code into constantly getting another diff --git a/avatar.h b/avatar.h index bf9cfdcd..28c16e4d 100644 --- a/avatar.h +++ b/avatar.h @@ -35,8 +35,8 @@ namespace QMatrixClient using notifier_t = std::function; - QImage get(int dimension, notifier_t notifier); - QImage get(int w, int h, notifier_t notifier); + QImage get(int dimension, notifier_t notifier) const; + QImage get(int w, int h, notifier_t notifier) const; QUrl url() const; bool updateUrl(const QUrl& newUrl); -- cgit v1.2.3