From e20ede86f89fb495ae74405cd01c5f89afdec739 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Luis=20=C3=81ngel=20San=20Mart=C3=ADn?= Date: Mon, 23 Jun 2014 17:30:39 +0200 Subject: [PATCH] updated tablemodel for future usages with QML --- YACReaderLibrary/db/tablemodel.cpp | 25 +++++++++++++++++++++++++ YACReaderLibrary/db/tablemodel.h | 21 +++++++++++++++++++++ 2 files changed, 46 insertions(+) diff --git a/YACReaderLibrary/db/tablemodel.cpp b/YACReaderLibrary/db/tablemodel.cpp index 52092ce8..e04bed06 100644 --- a/YACReaderLibrary/db/tablemodel.cpp +++ b/YACReaderLibrary/db/tablemodel.cpp @@ -81,6 +81,9 @@ QVariant TableModel::data(const QModelIndex &index, int role) const } + //TODO check here if any view is asking for TableModel::Roles + //these roles will be used from QML/GridView + if (role != Qt::DisplayRole) return QVariant(); @@ -597,6 +600,28 @@ void TableModel::resetComicRating(const QModelIndex &mi) QSqlDatabase::removeDatabase(_databasePath); } +QHash TableModel::roleNames() +{ + QHash roles; + + roles[NumberRole] = "number"; + roles[TitleRole] = "title"; + roles[FileNameRole] = "file_name"; + roles[NumPagesRole] = "num_pages"; + roles[IdRole] = "id"; + roles[Parent_IdRole] = "parent_id"; + roles[PathRole] = "path"; + roles[HashRole] = "hash"; + roles[ReadColumnRole] = "read"; + roles[IsBisRole] = "is_bis"; + roles[CurrentPageRole] = "current_page"; + roles[RatingRole] = "rating"; + roles[HasBeenOpenedRole] = "has_been_opened"; + roles[CoverPathRole] = "cover_path"; + + return roles; +} + void TableModel::updateRating(int rating, QModelIndex mi) { ComicDB comic = getComic(mi); diff --git a/YACReaderLibrary/db/tablemodel.h b/YACReaderLibrary/db/tablemodel.h index e17aab83..88913bc4 100644 --- a/YACReaderLibrary/db/tablemodel.h +++ b/YACReaderLibrary/db/tablemodel.h @@ -56,6 +56,8 @@ public: void reload(const ComicDB & comic); void resetComicRating(const QModelIndex & mi); + QHash roleNames(); + enum Columns { Number = 0, Title = 1, @@ -71,6 +73,25 @@ public: Rating = 11, HasBeenOpened = 12 }; + + enum Roles { + NumberRole = Qt::UserRole + 1, + TitleRole, + FileNameRole, + NumPagesRole, + IdRole, + Parent_IdRole, + PathRole, + HashRole, + ReadColumnRole, + IsBisRole, + CurrentPageRole, + RatingRole, + HasBeenOpenedRole, + CoverPathRole + + }; + public slots: void remove(int row); void startTransaction();