updated tablemodel for future usages with QML

This commit is contained in:
Luis Ángel San Martín 2014-06-23 17:30:39 +02:00
parent 7c496c7e1f
commit e20ede86f8
2 changed files with 46 additions and 0 deletions

View File

@ -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<int, QByteArray> TableModel::roleNames()
{
QHash<int, QByteArray> 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);

View File

@ -56,6 +56,8 @@ public:
void reload(const ComicDB & comic);
void resetComicRating(const QModelIndex & mi);
QHash<int, QByteArray> 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();