mirror of
https://github.com/YACReader/yacreader
synced 2025-05-28 03:10:27 -04:00
Added support for knowing if a comic is in favorites or not.
This commit is contained in:
parent
11456f8a1d
commit
bcc51241b3
@ -28,6 +28,8 @@ void ComicsView::updateInfoForIndex(int index)
|
||||
ComicInfo *comicInfo = &(comicDB->info);
|
||||
ctxt->setContextProperty("comic", comicDB);
|
||||
ctxt->setContextProperty("comicInfo", comicInfo);
|
||||
|
||||
ctxt->setContextProperty("is_favorite", model->isFavorite(model->index(index,0)));
|
||||
}
|
||||
|
||||
void ComicsView::dragEnterEvent(QDragEnterEvent *event)
|
||||
|
@ -1155,6 +1155,19 @@ void ComicModel::deleteComicsFromModel(const QList<QModelIndex> &comicsList)
|
||||
emit isEmpty();
|
||||
}
|
||||
|
||||
bool ComicModel::isFavorite(const QModelIndex &index)
|
||||
{
|
||||
bool isFavorite;
|
||||
|
||||
QSqlDatabase db = DataBaseManagement::loadDatabase(_databasePath);
|
||||
|
||||
isFavorite = DBHelper::isFavoriteComic(_data[index.row()]->data(Id).toLongLong(),db);
|
||||
|
||||
db.close();
|
||||
QSqlDatabase::removeDatabase(_databasePath);
|
||||
|
||||
return isFavorite;
|
||||
}
|
||||
|
||||
void ComicModel::updateRating(int rating, QModelIndex mi)
|
||||
{
|
||||
|
@ -81,6 +81,8 @@ public:
|
||||
|
||||
void deleteComicsFromModel(const QList<QModelIndex> &comicsList);
|
||||
|
||||
bool isFavorite(const QModelIndex &index);
|
||||
|
||||
QHash<int, QByteArray> roleNames() const;
|
||||
|
||||
enum Columns {
|
||||
|
@ -1062,3 +1062,18 @@ QList<QString> DBHelper::loadSubfoldersNames(qulonglong folderId, QSqlDatabase &
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
bool DBHelper::isFavoriteComic(qulonglong id, QSqlDatabase &db)
|
||||
{
|
||||
QSqlQuery selectQuery(db);
|
||||
selectQuery.prepare("SELECT * FROM comic_default_reading_list cl WHERE cl.comic_id = :comic_id AND cl.default_reading_list_id = 1");
|
||||
selectQuery.bindValue(":comic_id", id);
|
||||
selectQuery.exec();
|
||||
|
||||
if(selectQuery.next())
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
@ -76,6 +76,8 @@ public:
|
||||
static ComicDB loadComic(QString cname, QString cpath, QString chash, QSqlDatabase & database);
|
||||
static ComicInfo loadComicInfo(QString hash, QSqlDatabase & db);
|
||||
static QList<QString> loadSubfoldersNames(qulonglong folderId, QSqlDatabase & db);
|
||||
//queries
|
||||
static bool isFavoriteComic(qulonglong id, QSqlDatabase & db);
|
||||
};
|
||||
|
||||
#endif
|
||||
|
@ -98,6 +98,8 @@ Rectangle {
|
||||
Layout.topMargin: 1
|
||||
Layout.rightMargin: 17
|
||||
Layout.alignment: Qt.AlignTop
|
||||
|
||||
active: is_favorite
|
||||
}
|
||||
|
||||
InfoRating {
|
||||
@ -137,6 +139,8 @@ Rectangle {
|
||||
Layout.topMargin: 1
|
||||
Layout.rightMargin: 17
|
||||
Layout.alignment: Qt.AlignTop
|
||||
|
||||
active: is_favorite
|
||||
}
|
||||
|
||||
InfoRating {
|
||||
|
Loading…
Reference in New Issue
Block a user