Add a method for triggering the change of a comic cover from the model

Sad day for nice code.
This commit is contained in:
Luis Ángel San Martín 2023-08-17 19:41:13 +02:00
parent d0915024e2
commit ab9472cb58
2 changed files with 20 additions and 0 deletions

View File

@ -1165,6 +1165,25 @@ void ComicModel::resetComicRating(const QModelIndex &mi)
QSqlDatabase::removeDatabase(connectionName);
}
void ComicModel::notifyCoverChange(const ComicDB &comic)
{
auto it = std::find_if(_data.begin(), _data.end(), [comic](ComicItem *item) { return item->data(ComicModel::Id).toULongLong() == comic.id; });
auto itemIndex = std::distance(_data.begin(), it);
auto item = _data[itemIndex];
// emiting a dataChage doesn't work in QML for some reason, CoverPathRole is requested but the view doesn't update the image
// removing and reading again works with the flow views without any additional code, but it's not the best solution
beginRemoveRows(QModelIndex(), itemIndex, itemIndex);
_data.removeAt(itemIndex);
endRemoveRows();
beginInsertRows(QModelIndex(), itemIndex, itemIndex);
_data.insert(itemIndex, item);
endInsertRows();
// this doesn't work in QML -> emit dataChanged(index(itemIndex, 0), index(itemIndex, 0), QVector<int>() << CoverPathRole);
}
QUrl ComicModel::getCoverUrlPathForComicHash(const QString &hash) const
{
return QUrl("file:" + _databasePath + "/covers/" + hash + ".jpg");

View File

@ -124,6 +124,7 @@ public:
void reload();
void reload(const ComicDB &comic);
void resetComicRating(const QModelIndex &mi);
void notifyCoverChange(const ComicDB &comic);
Q_INVOKABLE QUrl getCoverUrlPathForComicHash(const QString &hash) const;