diff --git a/src/models/episodemodel.cpp b/src/models/episodemodel.cpp index 3b2da696..b3eae090 100644 --- a/src/models/episodemodel.cpp +++ b/src/models/episodemodel.cpp @@ -30,16 +30,25 @@ EpisodeModel::EpisodeModel() QVariant EpisodeModel::data(const QModelIndex &index, int role) const { - if (role != 0) + switch (role) { + case EntryRole: + return QVariant::fromValue(DataManager::instance().getEntry(m_entryIds[index.row()])); + case ReadRole: + return QVariant::fromValue(m_read[index.row()]); + case NewRole: + return QVariant::fromValue(m_new[index.row()]); + default: return QVariant(); - return QVariant::fromValue(DataManager::instance().getEntry(m_entryIds[index.row()])); + } } QHash EpisodeModel::roleNames() const { - QHash roleNames; - roleNames[0] = "entry"; - return roleNames; + return { + {EntryRole, "entry"}, + {ReadRole, "read"}, + {NewRole, "new"}, + }; } int EpisodeModel::rowCount(const QModelIndex &parent) const @@ -51,10 +60,14 @@ int EpisodeModel::rowCount(const QModelIndex &parent) const void EpisodeModel::updateInternalState() { m_entryIds.clear(); + m_read.clear(); + m_new.clear(); QSqlQuery query; - query.prepare(QStringLiteral("SELECT id FROM Entries ORDER BY updated DESC;")); + query.prepare(QStringLiteral("SELECT id, read, new FROM Entries ORDER BY updated DESC;")); Database::instance().execute(query); while (query.next()) { m_entryIds += query.value(QStringLiteral("id")).toString(); + m_read += query.value(QStringLiteral("read")).toBool(); + m_new += query.value(QStringLiteral("new")).toBool(); } } diff --git a/src/models/episodemodel.h b/src/models/episodemodel.h index 24fe778a..eff5058b 100644 --- a/src/models/episodemodel.h +++ b/src/models/episodemodel.h @@ -10,14 +10,21 @@ #include #include #include +#include class EpisodeModel : public QAbstractListModel { Q_OBJECT public: + enum Roles { + EntryRole = Qt::UserRole, + ReadRole, + NewRole, + }; + explicit EpisodeModel(); - QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const override; + QVariant data(const QModelIndex &index, int role = Qt::UserRole) const override; QHash roleNames() const override; int rowCount(const QModelIndex &parent) const override; @@ -25,4 +32,6 @@ private: void updateInternalState(); QStringList m_entryIds; + QVector m_read; + QVector m_new; };