Add the possibility to show a recently added/updated indicator

This commit is contained in:
Luis Ángel San Martín
2023-05-20 16:17:40 +02:00
parent 11df4a9b42
commit 6a6a239cc7
25 changed files with 234 additions and 59 deletions

View File

@ -17,12 +17,13 @@
#include "QsLog.h"
ComicModel::ComicModel(QObject *parent)
: QAbstractItemModel(parent)
: QAbstractItemModel(parent), showRecent(false)
{
}
ComicModel::ComicModel(QSqlQuery &sqlquery, QObject *parent)
: QAbstractItemModel(parent)
: QAbstractItemModel(parent), showRecent(false)
{
setupModelData(sqlquery);
}
@ -239,7 +240,9 @@ QHash<int, QByteArray> ComicModel::roleNames() const
roles[CoverPathRole] = "cover_path";
roles[PublicationDate] = "date";
roles[ReadableTitle] = "readable_title";
roles[Added] = "added_date";
roles[AddedRole] = "added_date";
roles[TypeRole] = "type";
roles[ShowRecentRole] = "show_recent";
return roles;
}
@ -306,6 +309,8 @@ QVariant ComicModel::data(const QModelIndex &index, int role) const
return item->data(Added);
else if (role == TypeRole)
return item->data(Type);
else if (role == ShowRecentRole)
return showRecent;
if (role != Qt::DisplayRole)
return QVariant();
@ -1129,6 +1134,16 @@ bool ComicModel::isFavorite(const QModelIndex &index)
return isFavorite;
}
void ComicModel::setShowRecent(bool showRecent)
{
if (this->showRecent == showRecent)
return;
this->showRecent = showRecent;
emit dataChanged(index(0, 0), index(rowCount() - 1, 0), { ComicModel::ShowRecentRole });
}
void ComicModel::updateRating(int rating, QModelIndex mi)
{
ComicDB comic = getComic(mi);

View File

@ -59,6 +59,7 @@ public:
ReadableTitle,
AddedRole,
TypeRole,
ShowRecentRole,
};
enum Mode {
@ -139,6 +140,8 @@ public:
ComicModel::Mode getMode() { return mode; }
unsigned long long int getSourceId() { return sourceId; }
void setShowRecent(bool visible);
QHash<int, QByteArray> roleNames() const override;
public slots:
@ -168,6 +171,8 @@ private:
qulonglong sourceId;
QString localizedDate(const QString &dbDate) const;
bool showRecent;
signals:
void isEmpty();
void searchNumResults(int);

View File

@ -52,12 +52,12 @@ void drawMacOSXFinishedFolderIcon()
#define ROOT 1
FolderModel::FolderModel(QObject *parent)
: QAbstractItemModel(parent), isSubfolder(false), rootItem(nullptr), folderIcon(YACReader::noHighlightedIcon(":/images/sidebar/folder.svg")), folderFinishedIcon(YACReader::noHighlightedIcon(":/images/sidebar/folder_finished.svg"))
: QAbstractItemModel(parent), isSubfolder(false), rootItem(nullptr), folderIcon(YACReader::noHighlightedIcon(":/images/sidebar/folder.svg")), folderFinishedIcon(YACReader::noHighlightedIcon(":/images/sidebar/folder_finished.svg")), showRecent(false)
{
}
FolderModel::FolderModel(QSqlQuery &sqlquery, QObject *parent)
: QAbstractItemModel(parent), isSubfolder(false), rootItem(nullptr)
: QAbstractItemModel(parent), isSubfolder(false), rootItem(nullptr), showRecent(false)
{
QList<QVariant> rootData;
rootData << "root"; // id 1, parent 1, title "root"
@ -99,6 +99,7 @@ QHash<int, QByteArray> FolderModel::roleNames() const
roles[TypeRole] = "type";
roles[AddedRole] = "added";
roles[UpdatedRole] = "updated";
roles[ShowRecentRole] = "show_recent";
return roles;
}
@ -181,6 +182,9 @@ QVariant FolderModel::data(const QModelIndex &index, int role) const
if (role == FolderModel::UpdatedRole)
return item->data(Updated);
if (role == FolderModel::ShowRecentRole)
return showRecent;
if (role != Qt::DisplayRole)
return QVariant();
@ -195,7 +199,8 @@ Qt::ItemFlags FolderModel::flags(const QModelIndex &index) const
return Qt::ItemIsEnabled | Qt::ItemIsSelectable | Qt::ItemIsDropEnabled | Qt::ItemIsDragEnabled;
}
QVariant FolderModel::headerData(int section, Qt::Orientation orientation,
QVariant FolderModel::headerData(int section,
Qt::Orientation orientation,
int role) const
{
if (rootItem == nullptr) {
@ -401,7 +406,7 @@ void FolderModel::updateFolderCompletedStatus(const QModelIndexList &list, bool
}
QSqlDatabase::removeDatabase(connectionName);
emit dataChanged(index(list.first().row(), FolderModel::Name), index(list.last().row(), FolderModel::FirstChildHash));
emit dataChanged(index(list.first().row(), FolderModel::Name), index(list.last().row(), FolderModel::Updated));
}
void FolderModel::updateFolderFinishedStatus(const QModelIndexList &list, bool status)
@ -640,6 +645,16 @@ QUrl FolderModel::getCoverUrlPathForComicHash(const QString &hash) const
return QUrl("file:" + _databasePath + "/covers/" + hash + ".jpg");
}
void FolderModel::setShowRecent(bool showRecent)
{
if (this->showRecent == showRecent)
return;
this->showRecent = showRecent;
emit dataChanged(index(0, 0), index(rowCount() - 1, 0), { FolderModel::ShowRecentRole });
}
void FolderModel::deleteFolder(const QModelIndex &mi)
{
beginRemoveRows(mi.parent(), mi.row(), mi.row());

View File

@ -81,6 +81,8 @@ public:
Q_INVOKABLE QUrl getCoverUrlPathForComicHash(const QString &hash) const;
void setShowRecent(bool showRecent);
enum Columns {
Name = 0,
Path,
@ -106,6 +108,7 @@ public:
TypeRole,
AddedRole,
UpdatedRole,
ShowRecentRole,
};
bool isSubfolder;
@ -125,6 +128,8 @@ private:
QIcon folderIcon;
QIcon folderFinishedIcon;
bool showRecent;
};
#endif