mirror of
https://github.com/YACReader/yacreader
synced 2025-06-04 01:28:55 -04:00
vuelve a funcionar el marcado de c?mics le?dos (se alamacena en comic_info)
vuelve a funcionar el scroll autom?tico, adem?s se recuerda la selecci?n del ?rbol si se cancela el filtro
This commit is contained in:
parent
2bc1c4f4c3
commit
c0b000bdda
@ -48,7 +48,8 @@ QList<LibraryItem *> Comic::getComicsFromParent(qulonglong parentId, QSqlDatabas
|
||||
currentItem->id = record.value(0).toLongLong();
|
||||
currentItem->parentId = record.value(1).toLongLong();
|
||||
currentItem->name = record.value(2).toString();
|
||||
currentItem->info.load(record.value(3).toString(),db);
|
||||
currentItem->path = record.value(3).toString();
|
||||
currentItem->info.load(record.value(4).toString(),db);
|
||||
int lessThan = 0;
|
||||
if(list.isEmpty())
|
||||
list.append(currentItem);
|
||||
@ -78,7 +79,23 @@ QList<LibraryItem *> Comic::getComicsFromParent(qulonglong parentId, QSqlDatabas
|
||||
|
||||
bool Comic::load(qulonglong id, QSqlDatabase & db)
|
||||
{
|
||||
return true;
|
||||
|
||||
QSqlQuery selectQuery(db); //TODO check
|
||||
selectQuery.prepare("select c.id,c.parentId,c.fileName,c.path,ci.hash from comic c inner join comic_info ci on (c.comicInfoId = ci.id) where c.id = :id");
|
||||
selectQuery.bindValue(":id", id);
|
||||
selectQuery.exec();
|
||||
|
||||
if(selectQuery.next())
|
||||
{
|
||||
QSqlRecord record = selectQuery.record();
|
||||
id = record.value(0).toLongLong();
|
||||
parentId = record.value(1).toLongLong();
|
||||
name = record.value(2).toString();
|
||||
info.load(record.value(4).toString(),db);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
|
||||
}
|
||||
|
||||
qulonglong Comic::insert(QSqlDatabase & db)
|
||||
@ -170,5 +187,12 @@ void ComicInfo::removeFromDB(QSqlDatabase & db)
|
||||
}
|
||||
void ComicInfo::update(QSqlDatabase & db)
|
||||
{
|
||||
|
||||
//db.open();
|
||||
QSqlQuery findComicInfo(db);
|
||||
findComicInfo.prepare("UPDATE comic_info SET name = :name, read = :read WHERE id = :id ");
|
||||
findComicInfo.bindValue(":name", name);
|
||||
findComicInfo.bindValue(":read", read?1:0);
|
||||
findComicInfo.bindValue(":id", id);
|
||||
findComicInfo.exec();
|
||||
//db.close();
|
||||
}
|
||||
|
@ -156,7 +156,7 @@ void TableModel::setupModelData(unsigned long long int folderId,QSqlDatabase & d
|
||||
//crear la consulta
|
||||
//timer.restart();
|
||||
QSqlQuery selectQuery(db); //TODO check
|
||||
selectQuery.prepare("select c.id,c.parentId,c.fileName,c.path,ci.hash from comic c inner join comic_info ci on (c.comicInfoId = ci.id) where c.parentId = :parentId");
|
||||
selectQuery.prepare("select c.id,c.parentId,c.fileName,c.path,ci.hash,ci.read from comic c inner join comic_info ci on (c.comicInfoId = ci.id) where c.parentId = :parentId");
|
||||
selectQuery.bindValue(":parentId", folderId);
|
||||
selectQuery.exec();
|
||||
//txtS << "TABLEMODEL: Tiempo de consulta: " << timer.elapsed() << "ms\r\n";
|
||||
@ -164,6 +164,7 @@ void TableModel::setupModelData(unsigned long long int folderId,QSqlDatabase & d
|
||||
setupModelData(selectQuery);
|
||||
//txtS << "TABLEMODEL: Tiempo de creación del modelo: " << timer.elapsed() << "ms\r\n";
|
||||
db.close();
|
||||
_database = db;
|
||||
emit(reset());
|
||||
//f.close();
|
||||
}
|
||||
@ -208,4 +209,47 @@ void TableModel::setupModelData(QSqlQuery &sqlquery)
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Comic TableModel::getComic(QModelIndex & mi)
|
||||
{
|
||||
Comic c;
|
||||
_database.open();
|
||||
c.load(_data.at(mi.row())->data(0).toLongLong(),_database);
|
||||
_database.close();
|
||||
return c;
|
||||
}
|
||||
|
||||
QVector<bool> TableModel::getReadList()
|
||||
{
|
||||
int numComics = _data.count();
|
||||
QVector<bool> readList(numComics);
|
||||
for(int i=0;i<numComics;i++)
|
||||
{
|
||||
//TODO reemplazar el acceso a las columnas con enteros por defines
|
||||
readList[i] = _data.value(i)->data(5).toBool();
|
||||
}
|
||||
return readList;
|
||||
}
|
||||
|
||||
QVector<bool> TableModel::setAllComicsRead(bool read)
|
||||
{
|
||||
_database.open();
|
||||
_database.transaction();
|
||||
int numComics = _data.count();
|
||||
QVector<bool> readList(numComics);
|
||||
for(int i=0;i<numComics;i++)
|
||||
{
|
||||
//TODO reemplazar el acceso a las columnas con enteros por defines
|
||||
readList[i] = read;
|
||||
_data.value(i)->data(5) = QVariant(true);
|
||||
Comic c;
|
||||
c.load(_data.value(i)->data(0).toLongLong(),_database);
|
||||
c.info.read = read;
|
||||
c.info.update(_database);
|
||||
}
|
||||
_database.commit();
|
||||
_database.close();
|
||||
|
||||
return readList;
|
||||
}
|
@ -7,6 +7,8 @@
|
||||
#include <QSqlQuery>
|
||||
#include <QSqlDatabase>
|
||||
|
||||
#include "comic.h"
|
||||
|
||||
class TableItem;
|
||||
|
||||
//! [0]
|
||||
@ -33,7 +35,9 @@ public:
|
||||
//Métodos de conveniencia
|
||||
QStringList getPaths(const QString & _source);
|
||||
QString getComicPath(QModelIndex & mi);
|
||||
//getComicInfo(QModelIndex & mi); --> para la edición
|
||||
Comic getComic(QModelIndex & mi); //--> para la edición
|
||||
QVector<bool> getReadList();
|
||||
QVector<bool> setAllComicsRead(bool read);
|
||||
//getComicsInfo(QList<QModelIndex> list); --> recupera la información común a los comics seleccionados
|
||||
//setcomicInfo(QModelIndex & mi); --> inserta en la base datos
|
||||
//setComicInfoForAllComics(); --> inserta la información común a todos los cómics de una sola vez.
|
||||
@ -43,6 +47,8 @@ private:
|
||||
|
||||
QList<TableItem *> _data;
|
||||
|
||||
QSqlDatabase _database;
|
||||
|
||||
signals:
|
||||
void beforeReset();
|
||||
void reset();
|
||||
|
@ -64,8 +64,7 @@ public:
|
||||
TreeItem *parentItem;
|
||||
unsigned long long int id;
|
||||
QList<QString> comicNames;
|
||||
QModelIndex index;
|
||||
QModelIndex originalIndex;
|
||||
TreeItem * originalItem;
|
||||
private:
|
||||
QList<TreeItem*> childItems;
|
||||
QList<QVariant> itemData;
|
||||
|
@ -70,6 +70,7 @@ TreeModel::TreeModel( QSqlQuery &sqlquery, QObject *parent)
|
||||
rootData << "root"; //id 0, padre 0, title "root" (el id, y el id del padre van a ir en la clase TreeItem)
|
||||
rootItem = new TreeItem(rootData);
|
||||
rootItem->id = ROOT;
|
||||
rootItem->parentItem = 0;
|
||||
setupModelData(sqlquery, rootItem);
|
||||
}
|
||||
//! [0]
|
||||
@ -146,10 +147,7 @@ QModelIndex TreeModel::index(int row, int column, const QModelIndex &parent)
|
||||
|
||||
TreeItem *childItem = parentItem->child(row);
|
||||
if (childItem)
|
||||
{
|
||||
childItem->index = createIndex(row, column, childItem);
|
||||
return childItem->index;
|
||||
}
|
||||
return createIndex(row, column, childItem);
|
||||
else
|
||||
return QModelIndex();
|
||||
}
|
||||
@ -167,11 +165,20 @@ QModelIndex TreeModel::parent(const QModelIndex &index) const
|
||||
if (parentItem == rootItem)
|
||||
return QModelIndex();
|
||||
|
||||
parentItem->index = createIndex(parentItem->row(), 0, parentItem);
|
||||
return parentItem->index;
|
||||
return createIndex(parentItem->row(), 0, parentItem);
|
||||
}
|
||||
//! [7]
|
||||
|
||||
QModelIndex TreeModel::indexFromItem(TreeItem * item,int column)
|
||||
{
|
||||
//if(item->parent() != 0)
|
||||
// return index(item->row(),column,parent(indexFromItem(item->parent(),column-1)));
|
||||
//else
|
||||
// return index(item->row(),0,QModelIndex());
|
||||
return createIndex(item->row(), column, item);
|
||||
}
|
||||
|
||||
|
||||
//! [8]
|
||||
int TreeModel::rowCount(const QModelIndex &parent) const
|
||||
{
|
||||
@ -201,6 +208,7 @@ void TreeModel::setupModelData(QString path)
|
||||
rootData << "root"; //id 0, padre 0, title "root" (el id, y el id del padre van a ir en la clase TreeItem)
|
||||
rootItem = new TreeItem(rootData);
|
||||
rootItem->id = ROOT;
|
||||
rootItem->parentItem = 0;
|
||||
|
||||
//cargar la base de datos
|
||||
if(_database.isOpen())
|
||||
@ -255,6 +263,7 @@ void TreeModel::setupFilteredModelData()
|
||||
rootData << "root"; //id 1, padre 1, title "root" (el id, y el id del padre van a ir en la clase TreeItem)
|
||||
rootItem = new TreeItem(rootData);
|
||||
rootItem->id = ROOT;
|
||||
rootItem->parentItem = 0;
|
||||
|
||||
//cargar la base de datos
|
||||
if(_database.isValid())
|
||||
@ -268,8 +277,9 @@ void TreeModel::setupFilteredModelData()
|
||||
}
|
||||
else
|
||||
{
|
||||
selectQuery.prepare("select distinct f.id, f.parentId, f.name, f.path from folder f inner join comic c on (f.id = c.parentId) where f.id <> 1 and upper(c.fileName) like upper(:filter) order by f.parentId,f.name");
|
||||
selectQuery.prepare("SELECT DISTINCT f.id, f.parentId, f.name, f.path FROM folder f INNER JOIN comic c ON (f.id = c.parentId) WHERE f.id <> 1 AND ((UPPER(c.fileName) like UPPER(:filter)) OR (UPPER(f.name) like UPPER(:filter2))) ORDER BY f.parentId,f.name");
|
||||
selectQuery.bindValue(":filter", "%%"+filter+"%%");
|
||||
selectQuery.bindValue(":filter2", "%%"+filter+"%%");
|
||||
}
|
||||
selectQuery.exec();
|
||||
setupFilteredModelData(selectQuery,rootItem);
|
||||
@ -301,7 +311,7 @@ void TreeModel::setupFilteredModelData(QSqlQuery &sqlquery, TreeItem *parent)
|
||||
filteredItems.insert(item->id,item);
|
||||
|
||||
//es necesario conocer las coordenadas de origen para poder realizar scroll automático en la vista
|
||||
item->originalIndex = items.value(item->id)->index;
|
||||
item->originalItem = items.value(item->id);
|
||||
|
||||
//si el padre ya existe en el modelo, el item se añade como hijo
|
||||
if(filteredItems.contains(parentId))
|
||||
@ -320,7 +330,7 @@ void TreeModel::setupFilteredModelData(QSqlQuery &sqlquery, TreeItem *parent)
|
||||
TreeItem * newparentItem = new TreeItem(parentItem->getData()); //padre que se añadirá a la estructura de directorios filtrados
|
||||
newparentItem->id = parentId;
|
||||
|
||||
newparentItem->originalIndex = parentItem->index;
|
||||
newparentItem->originalItem = parentItem;
|
||||
|
||||
//si el modelo contiene al padre, se añade el item actual como hijo
|
||||
if(filteredItems.contains(parentId))
|
||||
|
@ -66,6 +66,10 @@ public:
|
||||
QModelIndex index(int row, int column,
|
||||
const QModelIndex &parent = QModelIndex()) const;
|
||||
QModelIndex parent(const QModelIndex &index) const;
|
||||
QModelIndex indexFromItem(TreeItem * item, int column);
|
||||
/*QModelIndex _indexFromItem(TreeItem * item, int column);
|
||||
int column;*/
|
||||
|
||||
int rowCount(const QModelIndex &parent = QModelIndex()) const;
|
||||
int columnCount(const QModelIndex &parent = QModelIndex()) const;
|
||||
void setupModelData(QString path);
|
||||
|
@ -82,6 +82,7 @@ void LibraryWindow::doLayout()
|
||||
foldersView->setContextMenuPolicy(Qt::ActionsContextMenu);
|
||||
foldersView->header()->hide();
|
||||
foldersView->setUniformRowHeights(true);
|
||||
foldersView->setSelectionBehavior(QAbstractItemView::SelectRows);
|
||||
|
||||
comicView->setAlternatingRowColors(true);
|
||||
//comicView->setStyleSheet("alternate-background-color: #e7e7d7;background-color: white;");
|
||||
@ -126,7 +127,9 @@ void LibraryWindow::doLayout()
|
||||
searchLayout->addWidget(new QLabel(tr("Search folders/comics"),this));
|
||||
|
||||
searchLayout->addLayout(filter);
|
||||
searchLayout->addWidget(includeComicsCheckBox = new QCheckBox(tr("Include files (slower)"),this));
|
||||
includeComicsCheckBox = new QCheckBox(tr("Include files (slower)"),this);
|
||||
includeComicsCheckBox->setChecked(true);
|
||||
searchLayout->addWidget(includeComicsCheckBox);
|
||||
|
||||
l->addLayout(searchLayout);
|
||||
l->setSpacing(1);
|
||||
@ -189,6 +192,7 @@ void LibraryWindow::doModels()
|
||||
//dirmodels
|
||||
dm = new TreeModel();
|
||||
dmCV = new TableModel();
|
||||
sm = new QItemSelectionModel(dm);
|
||||
|
||||
|
||||
/*proxyFilter = new YACReaderTreeSearch();
|
||||
@ -558,6 +562,8 @@ void LibraryWindow::loadLibrary(const QString & name)
|
||||
QDir d; //TODO change this by static methods (utils class?? with delTree for example)
|
||||
if(d.exists(path))
|
||||
{
|
||||
index = 0;
|
||||
sm->clear();
|
||||
dm->setupModelData(path);
|
||||
foldersView->setModel(dm);
|
||||
|
||||
@ -600,10 +606,17 @@ void LibraryWindow::loadCovers(const QModelIndex & mi)
|
||||
//setFoldersFilter("");
|
||||
if(mi.isValid())
|
||||
{
|
||||
index = static_cast<TreeItem *>(mi.internalPointer())->originalIndex;
|
||||
index = static_cast<TreeItem *>(mi.internalPointer())->originalItem;
|
||||
column = mi.column();
|
||||
foldersFilter->clear();
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
index = static_cast<TreeItem *>(mi.internalPointer());
|
||||
column = mi.column();
|
||||
}
|
||||
|
||||
unsigned long long int folderId = 0;
|
||||
if(mi.isValid())
|
||||
{
|
||||
@ -620,6 +633,7 @@ void LibraryWindow::loadCovers(const QModelIndex & mi)
|
||||
|
||||
QStringList paths = dmCV->getPaths(currentPath());
|
||||
comicFlow->setImagePaths(paths);
|
||||
comicFlow->setMarks(dmCV->getReadList());
|
||||
comicFlow->setFocus(Qt::OtherFocusReason);
|
||||
|
||||
if(paths.size()>0 && !importedCovers)
|
||||
@ -689,73 +703,38 @@ void LibraryWindow::setCurrentComicReaded()
|
||||
{
|
||||
comicFlow->markSlide(comicFlow->centerIndex());
|
||||
comicFlow->updateMarks();
|
||||
|
||||
Comic c = dmCV->getComic(comicView->currentIndex());
|
||||
c.info.read = true;
|
||||
QSqlDatabase db = dm->getDatabase();
|
||||
db.open();
|
||||
c.info.update(db);
|
||||
db.close();
|
||||
}
|
||||
|
||||
void LibraryWindow::setComicsReaded()
|
||||
{
|
||||
/*QModelIndex mi = proxyFilter->mapToSource(foldersView->currentIndex());
|
||||
QString path;
|
||||
|
||||
if(mi.isValid())
|
||||
path = QDir::cleanPath(dm->filePath(mi));
|
||||
else
|
||||
path = dm->rootPath();
|
||||
|
||||
QDir d(path,"*.jpg");
|
||||
d.setFilter(QDir::Files | QDir::NoSymLinks | QDir::NoDotAndDotDot);
|
||||
QFileInfoList list = d.entryInfoList();
|
||||
int nFiles = list.size();
|
||||
for(int i=0;i<nFiles;i++)
|
||||
{
|
||||
QFileInfo info = list.at(i);
|
||||
QString filePath = info.absoluteFilePath();
|
||||
QFile f(filePath.remove(filePath.size()-3,3)+"r");
|
||||
f.open(QIODevice::WriteOnly);
|
||||
f.close();
|
||||
comicFlow->markSlide(i);
|
||||
}*/
|
||||
|
||||
comicFlow->setMarks(dmCV->setAllComicsRead(true));
|
||||
comicFlow->updateMarks();
|
||||
}
|
||||
|
||||
void LibraryWindow::setCurrentComicUnreaded()
|
||||
{
|
||||
comicFlow->unmarkSlide(comicFlow->centerIndex());
|
||||
/*QModelIndex mi = comicView->currentIndex();
|
||||
QString path = QDir::cleanPath(dmCV->filePath(mi));
|
||||
QFile f(path.remove(path.size()-3,3)+"r");
|
||||
f.open(QIODevice::WriteOnly);
|
||||
f.remove();
|
||||
f.close();*/
|
||||
|
||||
comicFlow->updateMarks();
|
||||
|
||||
Comic c = dmCV->getComic(comicView->currentIndex());
|
||||
c.info.read = false;
|
||||
QSqlDatabase db = dm->getDatabase();
|
||||
db.open();
|
||||
c.info.update(db);
|
||||
db.close();
|
||||
|
||||
}
|
||||
|
||||
void LibraryWindow::setComicsUnreaded()
|
||||
{
|
||||
/*QModelIndex mi = proxyFilter->mapToSource(foldersView->currentIndex());
|
||||
QString path;
|
||||
|
||||
if(mi.isValid())
|
||||
path = QDir::cleanPath(dm->filePath(mi));
|
||||
else
|
||||
path = dm->rootPath();
|
||||
|
||||
QDir d(path,"*.jpg");
|
||||
d.setFilter(QDir::Files | QDir::NoSymLinks | QDir::NoDotAndDotDot);
|
||||
QFileInfoList list = d.entryInfoList();
|
||||
int nFiles = list.size();
|
||||
for(int i=0;i<nFiles;i++)
|
||||
{
|
||||
QFileInfo info = list.at(i);
|
||||
QString filePath = info.absoluteFilePath();
|
||||
QFile f(filePath.remove(filePath.size()-3,3)+"r");
|
||||
f.open(QIODevice::WriteOnly);
|
||||
f.remove();
|
||||
f.close();
|
||||
comicFlow->unmarkSlide(i);
|
||||
}
|
||||
*/
|
||||
comicFlow->setMarks(dmCV->setAllComicsRead(false));
|
||||
comicFlow->updateMarks();
|
||||
}
|
||||
|
||||
@ -838,20 +817,13 @@ void LibraryWindow::saveLibraries()
|
||||
|
||||
void LibraryWindow::updateLibrary()
|
||||
{
|
||||
/*delete dm;
|
||||
delete dmCV;
|
||||
delete proxyFilter;
|
||||
dm = 0;
|
||||
dmCV = 0;
|
||||
proxyFilter = 0;*/
|
||||
|
||||
QString currentLibrary = selectedLibrary->currentText();
|
||||
QString path = libraries.value(currentLibrary);
|
||||
_lastAdded = currentLibrary;
|
||||
updateLibraryDialog->show();
|
||||
libraryCreator->updateLibrary(path,path+"/.yacreaderlibrary");
|
||||
libraryCreator->start();
|
||||
|
||||
|
||||
}
|
||||
|
||||
void LibraryWindow::deleteLibrary()
|
||||
@ -990,27 +962,17 @@ void LibraryWindow::toNormal()
|
||||
|
||||
void LibraryWindow::setFoldersFilter(QString filter)
|
||||
{
|
||||
/*if(filter.contains(previousFilter))
|
||||
proxyFilter->softReset();
|
||||
else
|
||||
proxyFilter->reset();
|
||||
previousFilter = filter;
|
||||
if(!filter.isEmpty())
|
||||
{
|
||||
proxyFilter->setFilterRegExp(QRegExp(filter,Qt::CaseInsensitive,QRegExp::FixedString));
|
||||
foldersView->expandAll();
|
||||
}
|
||||
else
|
||||
{
|
||||
proxyFilter->setFilterRegExp(QRegExp());
|
||||
foldersView->scrollTo(foldersView->currentIndex(),QAbstractItemView::PositionAtTop);
|
||||
foldersView->collapseAll();
|
||||
}*/
|
||||
if(filter.isEmpty() && dm->isFilterEnabled())
|
||||
{
|
||||
dm->resetFilter();
|
||||
foldersView->collapseAll();
|
||||
foldersView->scrollTo(index,QAbstractItemView::PositionAtTop);
|
||||
//foldersView->collapseAll();
|
||||
if(index != 0)
|
||||
{
|
||||
QModelIndex mi = dm->indexFromItem(index,column);
|
||||
foldersView->scrollTo(mi,QAbstractItemView::PositionAtTop);
|
||||
sm->select(mi,QItemSelectionModel::Select);
|
||||
foldersView->setSelectionModel(sm);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@ -25,6 +25,7 @@
|
||||
#include "package_manager.h"
|
||||
#include "treemodel.h"
|
||||
#include "tablemodel.h"
|
||||
#include "treeitem.h"
|
||||
|
||||
class LibraryWindow : public QMainWindow
|
||||
{
|
||||
@ -52,7 +53,8 @@ private:
|
||||
QSize slideSizeF;
|
||||
//search filter
|
||||
QLineEdit * foldersFilter;
|
||||
QModelIndex index; //index al que hay que hacer scroll después de pulsar sobre un folder filtrado
|
||||
TreeItem * index; //index al que hay que hacer scroll después de pulsar sobre un folder filtrado
|
||||
int column;
|
||||
QString previousFilter;
|
||||
QPushButton * clearFoldersFilter;
|
||||
QCheckBox * includeComicsCheckBox;
|
||||
@ -61,6 +63,7 @@ private:
|
||||
QTreeView * foldersView;
|
||||
QComboBox * selectedLibrary;
|
||||
TreeModel * dm;
|
||||
QItemSelectionModel * sm;
|
||||
TableModel * dmCV;
|
||||
//QStringList paths;
|
||||
QMap<QString,QString> libraries;
|
||||
|
Loading…
x
Reference in New Issue
Block a user