aboutsummaryrefslogtreecommitdiffstats
path: root/src/activitypub/apattachment.cpp
diff options
context:
space:
mode:
authorConfuSomu2024-03-24 21:23:07 -0400
committerConfuSomu2024-03-24 21:23:07 -0400
commit7024480b84ec1ef7ba4d371a51511bd04c48e816 (patch)
treedb03b06bf9d27e29ec4b90ada127f1aaeb6ff382 /src/activitypub/apattachment.cpp
parent4142690acd68dde59d0a6b16ccdda12f9195f304 (diff)
downloadActorViewer-7024480b84ec1ef7ba4d371a51511bd04c48e816.tar
ActorViewer-7024480b84ec1ef7ba4d371a51511bd04c48e816.tar.gz
ActorViewer-7024480b84ec1ef7ba4d371a51511bd04c48e816.zip
Use shared pointer in APAttachment::get_pixmap()
Necessary as the pixmap may be deleted at any moment if another caller requests a differently sized pixmap.
Diffstat (limited to 'src/activitypub/apattachment.cpp')
-rw-r--r--src/activitypub/apattachment.cpp15
1 files changed, 8 insertions, 7 deletions
diff --git a/src/activitypub/apattachment.cpp b/src/activitypub/apattachment.cpp
index db305ba..83d0bea 100644
--- a/src/activitypub/apattachment.cpp
+++ b/src/activitypub/apattachment.cpp
@@ -1,6 +1,7 @@
#include "apattachment.h"
#include <QFileInfo>
#include <QDebug>
+#include <memory>
APAttachment::APAttachment() {}
@@ -29,11 +30,11 @@ QString APAttachment::get_html_render(HtmlRenderDetails info) {
return html;
}
-const QPixmap& APAttachment::get_pixmap(int width, int height) {
- // Recreating the pixmap if it doesn't have the requested dimensions is quite inefficent. So it's better for the callee to resize the image instead of relying on this function.
- if (pixmap and pixmap_dimens.is_equal(width, height)) return *pixmap;
+std::shared_ptr<QPixmap> APAttachment::get_pixmap(int width, int height) {
+ // Recreating the pixmap if it doesn't have the requested dimensions is quite inefficent. So it's better for the callee to scale elsewhere the pixmap instead of relying on this function, if possible.
+ if (pixmap and pixmap_dimens.is_equal(width, height)) return pixmap;
else if (pixmap)
- delete pixmap;
+ pixmap.reset();
// pixmap_dimens are correctly based on the requested/function argument width and height, and not the actual dimentions of the pixmap!
pixmap_dimens.height = height;
@@ -52,13 +53,13 @@ const QPixmap& APAttachment::get_pixmap(int width, int height) {
else if (width == 0)
width = (height * image.width()) / image.height();
- pixmap = new QPixmap(image.scaled(QSize(width, height)));
+ pixmap = std::make_shared<QPixmap>(image.scaled(QSize(width, height)));
} else {
- pixmap = new QPixmap;
+ pixmap = std::make_shared<QPixmap>();
if (not pixmap->load(path_url))
qDebug() << "failed to load" << path_url;
}
- return *pixmap;
+ return pixmap;
}
QString APAttachmentList::get_html_render(HtmlRenderDetails render_info) {