mirror of
https://github.com/YACReader/yacreader
synced 2025-07-25 08:25:03 -04:00
code refactoring for adding support to multiple "comics views"
two "comics views" added, classic (flow+table_view) and grid (based on qml/qtquick) TODO: the views are only interchangeable in compilation time, some more work is needed for doing it in run time. fixed reloadCovers
This commit is contained in:
@ -15,7 +15,7 @@
|
||||
|
||||
|
||||
TableModel::TableModel(QObject *parent)
|
||||
: QAbstractItemModel(parent)
|
||||
: QAbstractItemModel(parent)
|
||||
{
|
||||
connect(this,SIGNAL(beforeReset()),this,SIGNAL(modelAboutToBeReset()));
|
||||
connect(this,SIGNAL(reset()),this,SIGNAL(modelReset()));
|
||||
@ -23,7 +23,7 @@ TableModel::TableModel(QObject *parent)
|
||||
|
||||
//! [0]
|
||||
TableModel::TableModel( QSqlQuery &sqlquery, QObject *parent)
|
||||
: QAbstractItemModel(parent)
|
||||
: QAbstractItemModel(parent)
|
||||
{
|
||||
setupModelData(sqlquery);
|
||||
}
|
||||
@ -46,6 +46,27 @@ int TableModel::columnCount(const QModelIndex &parent) const
|
||||
}
|
||||
//! [2]
|
||||
|
||||
QHash<int, QByteArray> TableModel::roleNames() const {
|
||||
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_column";
|
||||
roles[IsBisRole] = "is_bis";
|
||||
roles[CurrentPageRole] = "current_page";
|
||||
roles[RatingRole] = "rating";
|
||||
roles[HasBeenOpenedRole] = "has_been_opened";
|
||||
roles[CoverPathRole] = "cover_path";
|
||||
|
||||
return roles;
|
||||
}
|
||||
|
||||
//! [3]
|
||||
QVariant TableModel::data(const QModelIndex &index, int role) const
|
||||
{
|
||||
@ -84,10 +105,28 @@ 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();
|
||||
|
||||
TableItem *item = static_cast<TableItem*>(index.internalPointer());
|
||||
|
||||
if (role == NumberRole)
|
||||
return item->data(Number);
|
||||
else if (role == TitleRole)
|
||||
return item->data(Title).isNull()?item->data(FileName):item->data(Title);
|
||||
else if (role == RatingRole)
|
||||
return item->data(Rating);
|
||||
else if (role == CoverPathRole)
|
||||
return "file:///"+_databasePath+"/covers/"+item->data(Hash).toString()+".jpg";
|
||||
else if (role == NumPagesRole)
|
||||
return item->data(NumPages);
|
||||
else if (role == CurrentPageRole)
|
||||
return item->data(CurrentPage);
|
||||
else if (role == ReadColumnRole)
|
||||
return item->data(ReadColumn).toBool();
|
||||
else if (role == HasBeenOpenedRole)
|
||||
return item->data(TableModel::HasBeenOpened);
|
||||
|
||||
if (role != Qt::DisplayRole)
|
||||
return QVariant();
|
||||
|
||||
if(index.column() == TableModel::Hash)
|
||||
return QString::number(item->data(index.column()).toString().right(item->data(index.column()).toString().length()-40).toInt()/1024.0/1024.0,'f',2)+"Mb";
|
||||
if(index.column() == TableModel::ReadColumn)
|
||||
@ -467,7 +506,7 @@ QVector<YACReaderComicReadStatus> TableModel::setComicsRead(QList<QModelIndex> l
|
||||
db.close();
|
||||
QSqlDatabase::removeDatabase(_databasePath);
|
||||
|
||||
emit dataChanged(index(list.first().row(),TableModel::ReadColumn),index(list.last().row(),TableModel::CurrentPage+1));
|
||||
emit dataChanged(index(list.first().row(),TableModel::ReadColumn),index(list.last().row(),TableModel::HasBeenOpened),QVector<int>() = {ReadColumnRole,CurrentPageRole,HasBeenOpenedRole});
|
||||
|
||||
return getReadList();
|
||||
}
|
||||
@ -553,10 +592,10 @@ void TableModel::remove(ComicDB * comic, int row)
|
||||
endRemoveRows();
|
||||
}
|
||||
|
||||
ComicDB TableModel::getComic(int row)
|
||||
/*ComicDB TableModel::getComic(int row)
|
||||
{
|
||||
return getComic(index(row,0));
|
||||
}
|
||||
}*/
|
||||
|
||||
void TableModel::remove(int row)
|
||||
{
|
||||
@ -580,8 +619,8 @@ void TableModel::reload(const ComicDB & comic)
|
||||
}
|
||||
row++;
|
||||
}
|
||||
if(found)
|
||||
emit dataChanged(index(row,TableModel::CurrentPage),index(row,TableModel::CurrentPage));
|
||||
if(found)
|
||||
emit dataChanged(index(row,ReadColumn),index(row,HasBeenOpened), QVector<int>() = {ReadColumnRole,CurrentPageRole,HasBeenOpenedRole});
|
||||
}
|
||||
|
||||
void TableModel::resetComicRating(const QModelIndex &mi)
|
||||
@ -600,27 +639,6 @@ 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)
|
||||
{
|
||||
|
@ -24,7 +24,7 @@ public:
|
||||
TableModel(QObject *parent = 0);
|
||||
TableModel( QSqlQuery &sqlquery, QObject *parent = 0);
|
||||
~TableModel();
|
||||
|
||||
|
||||
QVariant data(const QModelIndex &index, int role) const;
|
||||
Qt::ItemFlags flags(const QModelIndex &index) const;
|
||||
QVariant headerData(int section, Qt::Orientation orientation,
|
||||
@ -39,8 +39,9 @@ public:
|
||||
//M<>todos de conveniencia
|
||||
QStringList getPaths(const QString & _source);
|
||||
QString getComicPath(QModelIndex mi);
|
||||
QString getCurrentPath(){return QString(_databasePath).remove("/.yacreaderlibrary");};
|
||||
ComicDB getComic(const QModelIndex & mi); //--> para la edici<63>n
|
||||
ComicDB getComic(int row);
|
||||
//ComicDB getComic(int row);
|
||||
QVector<YACReaderComicReadStatus> getReadList();
|
||||
QVector<YACReaderComicReadStatus> setAllComicsRead(YACReaderComicReadStatus readStatus);
|
||||
QList<ComicDB> getComics(QList<QModelIndex> list); //--> recupera la informaci<63>n com<6F>n a los comics seleccionados
|
||||
@ -56,7 +57,7 @@ public:
|
||||
void reload(const ComicDB & comic);
|
||||
void resetComicRating(const QModelIndex & mi);
|
||||
|
||||
QHash<int, QByteArray> roleNames();
|
||||
QHash<int, QByteArray> roleNames() const;
|
||||
|
||||
enum Columns {
|
||||
Number = 0,
|
||||
@ -98,6 +99,8 @@ public slots:
|
||||
void finishTransaction();
|
||||
void updateRating(int rating, QModelIndex mi);
|
||||
|
||||
protected:
|
||||
|
||||
private:
|
||||
void setupModelData( QSqlQuery &sqlquery);
|
||||
ComicDB _getComic(const QModelIndex & mi);
|
||||
|
Reference in New Issue
Block a user