Make UploadedImageModel use loadPixmapFromUrl

This commit is contained in:
Mm2PL 2024-05-14 14:50:24 +02:00
parent 6c11b2400a
commit 645cb38893
No known key found for this signature in database
GPG key ID: 94AC9B80EFA15ED9
2 changed files with 19 additions and 29 deletions

View file

@ -3,8 +3,10 @@
#include "common/SignalVectorModel.hpp" #include "common/SignalVectorModel.hpp"
#include "messages/Image.hpp" #include "messages/Image.hpp"
#include "singletons/imageuploader/ImageUploader.hpp" #include "singletons/imageuploader/ImageUploader.hpp"
#include "singletons/Resources.hpp"
#include "util/LoadPixmap.hpp"
#include "util/PostToThread.hpp"
#include "util/StandardItemHelper.hpp" #include "util/StandardItemHelper.hpp"
#include "widgets/listview/ImagePtrItemDelegate.hpp"
#include <qdatetime.h> #include <qdatetime.h>
#include <qlocale.h> #include <qlocale.h>
@ -14,13 +16,12 @@
namespace chatterino { namespace chatterino {
UploadedImageModel::UploadedImageModel(QObject *parent) UploadedImageModel::UploadedImageModel(QObject *parent)
: SignalVectorModel<UploadedImage>(4, parent) : SignalVectorModel<UploadedImage>(1, parent)
{ {
} }
// image, path, delete url
UploadedImage UploadedImageModel::getItemFromRow( UploadedImage UploadedImageModel::getItemFromRow(
std::vector<QStandardItem *> &row, const UploadedImage &original) std::vector<QStandardItem *> & /* row */, const UploadedImage &original)
{ {
return original; return original;
} }
@ -28,34 +29,22 @@ UploadedImage UploadedImageModel::getItemFromRow(
void UploadedImageModel::getRowFromItem(const UploadedImage &item, void UploadedImageModel::getRowFromItem(const UploadedImage &item,
std::vector<QStandardItem *> &row) std::vector<QStandardItem *> &row)
{ {
row[0]->setData(item.imageLink, ImagePtrItemDelegate::IMAGE_URL_ROLE); row[0]->setData(item.imageLink, Qt::DisplayRole);
row[0]->setData(item.imageLink, UploadedImageModel::DOUBLE_CLICK_LINK_ROLE); row[0]->setData(item.imageLink, UploadedImageModel::DOUBLE_CLICK_LINK_ROLE);
row[0]->setFlags(Qt::ItemIsEnabled | Qt::ItemIsSelectable); row[0]->setFlags(Qt::ItemIsEnabled | Qt::ItemIsSelectable);
auto locale = QLocale::system(); loadPixmapFromUrl({item.imageLink},
setStringItem(row[1], [row](const QPixmap &pixmap) {
locale.toString(QDateTime::fromSecsSinceEpoch(item.timestamp), postToThread([pixmap, row]() {
QLocale::ShortFormat), row[0]->setData(pixmap, Qt::DecorationRole);
false); });
},
if (item.deletionLink.isNull()) {[row]() {
{ postToThread([row]() {
setStringItem(row[2], "N/A", false); row[0]->setData(getResources().imageFailedToLoad,
} Qt::DecorationRole);
else });
{ }});
setStringItem(row[2], "[Double click to open]", false);
row[2]->setData(item.deletionLink, DOUBLE_CLICK_LINK_ROLE);
}
if (item.localPath.isNull())
{
setStringItem(row[3], "n/a", false);
}
else
{
setStringItem(row[3], item.localPath, true);
}
} }
} // namespace chatterino } // namespace chatterino

View file

@ -8,6 +8,7 @@
namespace chatterino { namespace chatterino {
struct UploadedImage;
class UploadedImageModel : public SignalVectorModel<UploadedImage> class UploadedImageModel : public SignalVectorModel<UploadedImage>
{ {
explicit UploadedImageModel(QObject *parent); explicit UploadedImageModel(QObject *parent);