From 0a00fd3020d4000eaed0cfb5e2d8130b285838dc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Luis=20=C3=81ngel=20San=20Mart=C3=ADn?= Date: Sun, 9 Oct 2022 11:22:06 +0200 Subject: [PATCH] Add a new type of role to ComicModel to display a title composed with the available info --- YACReaderLibrary/db/comic_model.cpp | 10 +++++++++- YACReaderLibrary/db/comic_model.h | 1 + 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/YACReaderLibrary/db/comic_model.cpp b/YACReaderLibrary/db/comic_model.cpp index 46af7159..0a0243e6 100644 --- a/YACReaderLibrary/db/comic_model.cpp +++ b/YACReaderLibrary/db/comic_model.cpp @@ -1,6 +1,7 @@ #include #include +#include #include #include "comic_item.h" @@ -237,6 +238,7 @@ QHash ComicModel::roleNames() const roles[HasBeenOpenedRole] = "has_been_opened"; roles[CoverPathRole] = "cover_path"; roles[PublicationDate] = "date"; + roles[ReadableTitle] = "readable_title"; return roles; } @@ -275,7 +277,13 @@ QVariant ComicModel::data(const QModelIndex &index, int role) const return item->data(Number); else if (role == TitleRole) return item->data(Title).isNull() ? item->data(FileName) : item->data(Title); - else if (role == FileNameRole) + else if (role == ReadableTitle) { + QString title; + if (!item->data(Number).isNull()) { + title = title % "#" % item->data(Number).toString() % " "; + } + return QVariant(title % (item->data(Title).isNull() ? item->data(FileName).toString() : item->data(Title).toString())); + } else if (role == FileNameRole) return item->data(FileName); else if (role == RatingRole) return item->data(Rating); diff --git a/YACReaderLibrary/db/comic_model.h b/YACReaderLibrary/db/comic_model.h index f66260e5..54548f8d 100644 --- a/YACReaderLibrary/db/comic_model.h +++ b/YACReaderLibrary/db/comic_model.h @@ -54,6 +54,7 @@ public: HasBeenOpenedRole, CoverPathRole, PublicationDateRole, + ReadableTitle, }; enum Mode {