mirror of
https://github.com/YACReader/yacreader
synced 2025-07-22 15:04:40 -04:00
added rating feature
This commit is contained in:
@ -64,11 +64,11 @@ QVariant TableModel::data(const QModelIndex &index, int role) const
|
||||
if (!index.isValid())
|
||||
return QVariant();
|
||||
|
||||
if (index.column() == Columns::Rating && role == Qt::DecorationRole)
|
||||
/*if (index.column() == Columns::Rating && role == Qt::DecorationRole)
|
||||
{
|
||||
TableItem *item = static_cast<TableItem*>(index.internalPointer());
|
||||
return QPixmap(QString(":/images/rating%1.png").arg(item->data(index.column()).toInt()));
|
||||
}
|
||||
}*/
|
||||
|
||||
if (role == Qt::DecorationRole)
|
||||
{
|
||||
@ -116,7 +116,8 @@ Qt::ItemFlags TableModel::flags(const QModelIndex &index) const
|
||||
{
|
||||
if (!index.isValid())
|
||||
return 0;
|
||||
|
||||
if(index.column() == Columns::Rating)
|
||||
return Qt::ItemIsEnabled | Qt::ItemIsSelectable | Qt::ItemIsEditable;
|
||||
return Qt::ItemIsEnabled | Qt::ItemIsSelectable;
|
||||
}
|
||||
//! [4]
|
||||
@ -612,4 +613,21 @@ void TableModel::reload(const ComicDB & comic)
|
||||
}
|
||||
if(found)
|
||||
emit dataChanged(index(row,Columns::CurrentPage),index(row,Columns::CurrentPage));
|
||||
}
|
||||
|
||||
void TableModel::updateRating(int rating, QModelIndex mi)
|
||||
{
|
||||
ComicDB comic = getComic(mi);
|
||||
|
||||
QSqlDatabase db = DataBaseManagement::loadDatabase(_databasePath);
|
||||
//TODO optimize update
|
||||
|
||||
comic.info.rating = rating;
|
||||
_data[mi.row()]->setData(Columns::Rating,rating);
|
||||
DBHelper::update(&(comic.info),db);
|
||||
|
||||
emit dataChanged(mi,mi);
|
||||
|
||||
db.close();
|
||||
QSqlDatabase::removeDatabase(_databasePath);
|
||||
}
|
@ -58,6 +58,7 @@ public slots:
|
||||
void remove(int row);
|
||||
void startTransaction();
|
||||
void finishTransaction();
|
||||
void updateRating(int rating, QModelIndex mi);
|
||||
|
||||
private:
|
||||
void setupModelData( QSqlQuery &sqlquery);
|
||||
|
@ -197,7 +197,7 @@ void DBHelper::update(const QString & libraryName, ComicInfo & comicInfo)
|
||||
db.close();
|
||||
QSqlDatabase::removeDatabase(libraryPath);
|
||||
}
|
||||
|
||||
#include <QMessageBox>
|
||||
void DBHelper::update(ComicInfo * comicInfo, QSqlDatabase & db)
|
||||
{
|
||||
QSqlQuery updateComicInfo(db);
|
||||
@ -246,7 +246,8 @@ void DBHelper::update(ComicInfo * comicInfo, QSqlDatabase & db)
|
||||
"bookmark3 = :bookmark3,"
|
||||
"brightness = :brightness,"
|
||||
"contrast = :contrast, "
|
||||
"gamma = :gamma"
|
||||
"gamma = :gamma,"
|
||||
"rating = :rating"
|
||||
//--
|
||||
" WHERE id = :id ");
|
||||
bindField(":title",comicInfo->title,updateComicInfo);
|
||||
@ -294,8 +295,10 @@ void DBHelper::update(ComicInfo * comicInfo, QSqlDatabase & db)
|
||||
updateComicInfo.bindValue(":brightness", comicInfo->brightness);
|
||||
updateComicInfo.bindValue(":contrast", comicInfo->contrast);
|
||||
updateComicInfo.bindValue(":gamma", comicInfo->gamma);
|
||||
updateComicInfo.bindValue(":rating", comicInfo->rating);
|
||||
|
||||
updateComicInfo.exec();
|
||||
if(!updateComicInfo.exec())
|
||||
QMessageBox::critical(0,"",updateComicInfo.lastError().text());
|
||||
}
|
||||
|
||||
void DBHelper::updateRead(ComicInfo * comicInfo, QSqlDatabase & db)
|
||||
|
@ -672,6 +672,7 @@ void LibraryWindow::createConnections()
|
||||
|
||||
connect(comicView, SIGNAL(pressed(QModelIndex)), this, SLOT(centerComicFlow(QModelIndex)));
|
||||
connect(comicFlow, SIGNAL(centerIndexChanged(int)), this, SLOT(updateComicView(int)));
|
||||
connect(comicView, SIGNAL(comicRated(int,QModelIndex)), dmCV, SLOT(updateRating(int,QModelIndex)));
|
||||
|
||||
//actions
|
||||
connect(createLibraryAction,SIGNAL(triggered()),this,SLOT(createLibrary()));
|
||||
|
Reference in New Issue
Block a user