mirror of
https://github.com/YACReader/yacreader
synced 2025-06-04 01:28:55 -04:00
added preliminar comics filter/search
This commit is contained in:
parent
e4ddf4cfb4
commit
090be54bc1
@ -11,7 +11,7 @@
|
|||||||
#include "db_helper.h"
|
#include "db_helper.h"
|
||||||
|
|
||||||
//ci.number,ci.title,c.fileName,ci.numPages,c.id,c.parentId,c.path,ci.hash,ci.read
|
//ci.number,ci.title,c.fileName,ci.numPages,c.id,c.parentId,c.path,ci.hash,ci.read
|
||||||
|
#include "QsLog.h"
|
||||||
|
|
||||||
|
|
||||||
TableModel::TableModel(QObject *parent)
|
TableModel::TableModel(QObject *parent)
|
||||||
@ -291,14 +291,14 @@ void TableModel::setupModelData(unsigned long long int folderId,const QString &
|
|||||||
{
|
{
|
||||||
//crear la consulta
|
//crear la consulta
|
||||||
//timer.restart();
|
//timer.restart();
|
||||||
QSqlQuery selectQuery(db); //TODO check
|
QSqlQuery selectQuery(db);
|
||||||
selectQuery.prepare("select ci.number,ci.title,c.fileName,ci.numPages,c.id,c.parentId,c.path,ci.hash,ci.read,ci.isBis,ci.currentPage,ci.rating,ci.hasBeenOpened from comic c inner join comic_info ci on (c.comicInfoId = ci.id) where c.parentId = :parentId");
|
selectQuery.prepare("select ci.number,ci.title,c.fileName,ci.numPages,c.id,c.parentId,c.path,ci.hash,ci.read,ci.isBis,ci.currentPage,ci.rating,ci.hasBeenOpened from comic c inner join comic_info ci on (c.comicInfoId = ci.id) where c.parentId = :parentId");
|
||||||
selectQuery.bindValue(":parentId", folderId);
|
selectQuery.bindValue(":parentId", folderId);
|
||||||
selectQuery.exec();
|
selectQuery.exec();
|
||||||
//txtS << "TABLEMODEL: Tiempo de consulta: " << timer.elapsed() << "ms\r\n";
|
//txtS << "TABLEMODEL: Tiempo de consulta: " << timer.elapsed() << "ms\r\n";
|
||||||
//timer.restart();
|
//timer.restart();
|
||||||
setupModelData(selectQuery);
|
setupModelData(selectQuery);
|
||||||
//txtS << "TABLEMODEL: Tiempo de creación del modelo: " << timer.elapsed() << "ms\r\n";
|
//txtS << "TABLEMODEL: Tiempo de creaci�n del modelo: " << timer.elapsed() << "ms\r\n";
|
||||||
//selectQuery.finish();
|
//selectQuery.finish();
|
||||||
}
|
}
|
||||||
db.close();
|
db.close();
|
||||||
@ -309,6 +309,47 @@ void TableModel::setupModelData(unsigned long long int folderId,const QString &
|
|||||||
emit isEmpty();
|
emit isEmpty();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void TableModel::setupModelData(const QString &filter, const QString &databasePath)
|
||||||
|
{
|
||||||
|
//QFile f(QCoreApplication::applicationDirPath()+"/performance.txt");
|
||||||
|
//f.open(QIODevice::Append);
|
||||||
|
beginResetModel();
|
||||||
|
//QElapsedTimer timer;
|
||||||
|
//timer.start();
|
||||||
|
qDeleteAll(_data);
|
||||||
|
_data.clear();
|
||||||
|
|
||||||
|
//QTextStream txtS(&f);
|
||||||
|
//txtS << "TABLEMODEL: Tiempo de borrado: " << timer.elapsed() << "ms\r\n";
|
||||||
|
_databasePath = databasePath;
|
||||||
|
QSqlDatabase db = DataBaseManagement::loadDatabase(databasePath);
|
||||||
|
{
|
||||||
|
//crear la consulta
|
||||||
|
//timer.restart();
|
||||||
|
QSqlQuery selectQuery(db);
|
||||||
|
selectQuery.prepare("SELECT ci.number,ci.title,c.fileName,ci.numPages,c.id,c.parentId,c.path,ci.hash,ci.read,ci.isBis,ci.currentPage,ci.rating,ci.hasBeenOpened "
|
||||||
|
"FROM comic c INNER JOIN comic_info ci ON (c.comicInfoId = ci.id) "
|
||||||
|
"WHERE UPPER(ci.title) LIKE UPPER(:filter) OR UPPER(c.fileName) LIKE UPPER(:filter) LIMIT :limit");
|
||||||
|
selectQuery.bindValue(":filter", "%%"+filter+"%%");
|
||||||
|
selectQuery.bindValue(":limit",500); //TODO, load this value from settings
|
||||||
|
selectQuery.exec();
|
||||||
|
|
||||||
|
QLOG_DEBUG() << selectQuery.lastError() << "--";
|
||||||
|
|
||||||
|
//txtS << "TABLEMODEL: Tiempo de consulta: " << timer.elapsed() << "ms\r\n";
|
||||||
|
//timer.restart();
|
||||||
|
setupModelData(selectQuery);
|
||||||
|
//txtS << "TABLEMODEL: Tiempo de creaci�n del modelo: " << timer.elapsed() << "ms\r\n";
|
||||||
|
//selectQuery.finish();
|
||||||
|
}
|
||||||
|
db.close();
|
||||||
|
QSqlDatabase::removeDatabase(_databasePath);
|
||||||
|
endResetModel();
|
||||||
|
|
||||||
|
if(_data.length()==0)
|
||||||
|
emit isEmpty();
|
||||||
|
}
|
||||||
|
|
||||||
QString TableModel::getComicPath(QModelIndex mi)
|
QString TableModel::getComicPath(QModelIndex mi)
|
||||||
{
|
{
|
||||||
if(mi.isValid())
|
if(mi.isValid())
|
||||||
@ -373,7 +414,7 @@ void TableModel::setupModelData(QSqlQuery &sqlquery)
|
|||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
if(!lessThan) //si se ha encontrado un elemento menor que current, se inserta justo después
|
if(!lessThan) //si se ha encontrado un elemento menor que current, se inserta justo despu�s
|
||||||
{
|
{
|
||||||
if(numberCurrent != max)
|
if(numberCurrent != max)
|
||||||
{
|
{
|
||||||
|
@ -35,21 +35,23 @@ public:
|
|||||||
int rowCount(const QModelIndex &parent = QModelIndex()) const;
|
int rowCount(const QModelIndex &parent = QModelIndex()) const;
|
||||||
int columnCount(const QModelIndex &parent = QModelIndex()) const;
|
int columnCount(const QModelIndex &parent = QModelIndex()) const;
|
||||||
void setupModelData(unsigned long long int parentFolder,const QString & databasePath);
|
void setupModelData(unsigned long long int parentFolder,const QString & databasePath);
|
||||||
|
//configures the model for showing the comics matching the filter criteria.
|
||||||
|
void setupModelData(const QString & filter, const QString & databasePath);
|
||||||
|
|
||||||
//Métodos de conveniencia
|
//Métodos de conveniencia
|
||||||
QStringList getPaths(const QString & _source);
|
QStringList getPaths(const QString & _source);
|
||||||
QString getComicPath(QModelIndex mi);
|
QString getComicPath(QModelIndex mi);
|
||||||
QString getCurrentPath(){return QString(_databasePath).remove("/.yacreaderlibrary");};
|
QString getCurrentPath(){return QString(_databasePath).remove("/.yacreaderlibrary");};
|
||||||
ComicDB getComic(const QModelIndex & mi); //--> para la edición
|
ComicDB getComic(const QModelIndex & mi); //--> para la edición
|
||||||
//ComicDB getComic(int row);
|
//ComicDB getComic(int row);
|
||||||
QVector<YACReaderComicReadStatus> getReadList();
|
QVector<YACReaderComicReadStatus> getReadList();
|
||||||
QVector<YACReaderComicReadStatus> setAllComicsRead(YACReaderComicReadStatus readStatus);
|
QVector<YACReaderComicReadStatus> setAllComicsRead(YACReaderComicReadStatus readStatus);
|
||||||
QList<ComicDB> getComics(QList<QModelIndex> list); //--> recupera la información común a los comics seleccionados
|
QList<ComicDB> getComics(QList<QModelIndex> list); //--> recupera la información común a los comics seleccionados
|
||||||
QList<ComicDB> getAllComics();
|
QList<ComicDB> getAllComics();
|
||||||
QModelIndex getIndexFromId(quint64 id);
|
QModelIndex getIndexFromId(quint64 id);
|
||||||
//setcomicInfo(QModelIndex & mi); --> inserta en la base datos
|
//setcomicInfo(QModelIndex & mi); --> inserta en la base datos
|
||||||
//setComicInfoForAllComics(); --> inserta la información común a todos los cómics de una sola vez.
|
//setComicInfoForAllComics(); --> inserta la información común a todos los cómics de una sola vez.
|
||||||
//setComicInfoForSelectedComis(QList<QModelIndex> list); -->inserta la información común para los comics seleccionados
|
//setComicInfoForSelectedComis(QList<QModelIndex> list); -->inserta la información común para los comics seleccionados
|
||||||
QVector<YACReaderComicReadStatus> setComicsRead(QList<QModelIndex> list,YACReaderComicReadStatus read);
|
QVector<YACReaderComicReadStatus> setComicsRead(QList<QModelIndex> list,YACReaderComicReadStatus read);
|
||||||
qint64 asignNumbers(QList<QModelIndex> list,int startingNumber);
|
qint64 asignNumbers(QList<QModelIndex> list,int startingNumber);
|
||||||
void remove(ComicDB * comic, int row);
|
void remove(ComicDB * comic, int row);
|
||||||
|
@ -104,7 +104,7 @@ void LibraryWindow::setupUI()
|
|||||||
libraryCreator = new LibraryCreator();
|
libraryCreator = new LibraryCreator();
|
||||||
packageManager = new PackageManager();
|
packageManager = new PackageManager();
|
||||||
|
|
||||||
settings = new QSettings(YACReader::getSettingsPath()+"/YACReaderLibrary.ini",QSettings::IniFormat); //TODO unificar la creación del fichero de config con el servidor
|
settings = new QSettings(YACReader::getSettingsPath()+"/YACReaderLibrary.ini",QSettings::IniFormat); //TODO unificar la creación del fichero de config con el servidor
|
||||||
settings->beginGroup("libraryConfig");
|
settings->beginGroup("libraryConfig");
|
||||||
|
|
||||||
createActions();
|
createActions();
|
||||||
@ -1048,7 +1048,7 @@ void LibraryWindow::loadLibrary(const QString & name)
|
|||||||
QString path=libraries.getPath(name)+"/.yacreaderlibrary";
|
QString path=libraries.getPath(name)+"/.yacreaderlibrary";
|
||||||
QDir d; //TODO change this by static methods (utils class?? with delTree for example)
|
QDir d; //TODO change this by static methods (utils class?? with delTree for example)
|
||||||
QString dbVersion;
|
QString dbVersion;
|
||||||
if(d.exists(path) && d.exists(path+"/library.ydb") && (dbVersion = DataBaseManagement::checkValidDB(path+"/library.ydb")) != "") //si existe en disco la biblioteca seleccionada, y es válida..
|
if(d.exists(path) && d.exists(path+"/library.ydb") && (dbVersion = DataBaseManagement::checkValidDB(path+"/library.ydb")) != "") //si existe en disco la biblioteca seleccionada, y es válida..
|
||||||
{
|
{
|
||||||
int comparation = DataBaseManagement::compareVersions(dbVersion,VERSION);
|
int comparation = DataBaseManagement::compareVersions(dbVersion,VERSION);
|
||||||
bool updated = false;
|
bool updated = false;
|
||||||
@ -1066,13 +1066,13 @@ void LibraryWindow::loadLibrary(const QString & name)
|
|||||||
comicsView->setModel(NULL);
|
comicsView->setModel(NULL);
|
||||||
foldersView->setModel(NULL);
|
foldersView->setModel(NULL);
|
||||||
disableAllActions();//TODO comprobar que se deben deshabilitar
|
disableAllActions();//TODO comprobar que se deben deshabilitar
|
||||||
//será possible renombrar y borrar estas bibliotecas
|
//será possible renombrar y borrar estas bibliotecas
|
||||||
renameLibraryAction->setEnabled(true);
|
renameLibraryAction->setEnabled(true);
|
||||||
removeLibraryAction->setEnabled(true);
|
removeLibraryAction->setEnabled(true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if(comparation == 0 || updated) //en caso de que la versión se igual que la actual
|
if(comparation == 0 || updated) //en caso de que la versión se igual que la actual
|
||||||
{
|
{
|
||||||
index = 0;
|
index = 0;
|
||||||
|
|
||||||
@ -1086,7 +1086,7 @@ void LibraryWindow::loadLibrary(const QString & name)
|
|||||||
|
|
||||||
d.setCurrent(libraries.getPath(name));
|
d.setCurrent(libraries.getPath(name));
|
||||||
d.setFilter(QDir::AllDirs | QDir::Files | QDir::Hidden | QDir::NoSymLinks | QDir::NoDotAndDotDot);
|
d.setFilter(QDir::AllDirs | QDir::Files | QDir::Hidden | QDir::NoSymLinks | QDir::NoDotAndDotDot);
|
||||||
if(d.count()<=1) //librería de sólo lectura
|
if(d.count()<=1) //librería de sólo lectura
|
||||||
{
|
{
|
||||||
//QMessageBox::critical(NULL,QString::number(d.count()),QString::number(d.count()));
|
//QMessageBox::critical(NULL,QString::number(d.count()),QString::number(d.count()));
|
||||||
disableLibrariesActions(false);
|
disableLibrariesActions(false);
|
||||||
@ -1097,14 +1097,14 @@ void LibraryWindow::loadLibrary(const QString & name)
|
|||||||
|
|
||||||
importedCovers = true;
|
importedCovers = true;
|
||||||
}
|
}
|
||||||
else //librería normal abierta
|
else //librería normal abierta
|
||||||
{
|
{
|
||||||
disableLibrariesActions(false);
|
disableLibrariesActions(false);
|
||||||
importedCovers = false;
|
importedCovers = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
setRootIndex();
|
setRootIndex();
|
||||||
//TODO encontrar el bug que provoca que no se carguen adecuadamente las carátulas en root.
|
//TODO encontrar el bug que provoca que no se carguen adecuadamente las carátulas en root.
|
||||||
setRootIndex();
|
setRootIndex();
|
||||||
|
|
||||||
foldersFilter->clear();
|
foldersFilter->clear();
|
||||||
@ -1118,7 +1118,7 @@ void LibraryWindow::loadLibrary(const QString & name)
|
|||||||
comicsView->setModel(NULL);
|
comicsView->setModel(NULL);
|
||||||
foldersView->setModel(NULL);
|
foldersView->setModel(NULL);
|
||||||
disableAllActions();//TODO comprobar que se deben deshabilitar
|
disableAllActions();//TODO comprobar que se deben deshabilitar
|
||||||
//será possible renombrar y borrar estas bibliotecas
|
//será possible renombrar y borrar estas bibliotecas
|
||||||
renameLibraryAction->setEnabled(true);
|
renameLibraryAction->setEnabled(true);
|
||||||
removeLibraryAction->setEnabled(true);
|
removeLibraryAction->setEnabled(true);
|
||||||
}
|
}
|
||||||
@ -1129,7 +1129,7 @@ void LibraryWindow::loadLibrary(const QString & name)
|
|||||||
foldersView->setModel(NULL);
|
foldersView->setModel(NULL);
|
||||||
disableAllActions();//TODO comprobar que se deben deshabilitar
|
disableAllActions();//TODO comprobar que se deben deshabilitar
|
||||||
|
|
||||||
//si la librería no existe en disco, se ofrece al usuario la posibiliad de eliminarla
|
//si la librería no existe en disco, se ofrece al usuario la posibiliad de eliminarla
|
||||||
if(!d.exists(path))
|
if(!d.exists(path))
|
||||||
{
|
{
|
||||||
QString currentLibrary = selectedLibrary->currentText();
|
QString currentLibrary = selectedLibrary->currentText();
|
||||||
@ -1137,19 +1137,19 @@ void LibraryWindow::loadLibrary(const QString & name)
|
|||||||
{
|
{
|
||||||
deleteCurrentLibrary();
|
deleteCurrentLibrary();
|
||||||
}
|
}
|
||||||
//será possible renombrar y borrar estas bibliotecas
|
//será possible renombrar y borrar estas bibliotecas
|
||||||
renameLibraryAction->setEnabled(true);
|
renameLibraryAction->setEnabled(true);
|
||||||
removeLibraryAction->setEnabled(true);
|
removeLibraryAction->setEnabled(true);
|
||||||
|
|
||||||
}
|
}
|
||||||
else//si existe el path, puede ser que la librería sea alguna versión pre-5.0 ó que esté corrupta o que no haya drivers sql
|
else//si existe el path, puede ser que la librería sea alguna versión pre-5.0 ó que esté corrupta o que no haya drivers sql
|
||||||
{
|
{
|
||||||
|
|
||||||
if(d.exists(path+"/library.ydb"))
|
if(d.exists(path+"/library.ydb"))
|
||||||
{
|
{
|
||||||
QSqlDatabase db = DataBaseManagement::loadDatabase(path);
|
QSqlDatabase db = DataBaseManagement::loadDatabase(path);
|
||||||
manageOpeningLibraryError(db.lastError().databaseText() + "-" + db.lastError().driverText());
|
manageOpeningLibraryError(db.lastError().databaseText() + "-" + db.lastError().driverText());
|
||||||
//será possible renombrar y borrar estas bibliotecas
|
//será possible renombrar y borrar estas bibliotecas
|
||||||
renameLibraryAction->setEnabled(true);
|
renameLibraryAction->setEnabled(true);
|
||||||
removeLibraryAction->setEnabled(true);
|
removeLibraryAction->setEnabled(true);
|
||||||
}
|
}
|
||||||
@ -1165,7 +1165,7 @@ void LibraryWindow::loadLibrary(const QString & name)
|
|||||||
createLibraryDialog->setDataAndStart(currentLibrary,path);
|
createLibraryDialog->setDataAndStart(currentLibrary,path);
|
||||||
//create(path,path+"/.yacreaderlibrary",currentLibrary);
|
//create(path,path+"/.yacreaderlibrary",currentLibrary);
|
||||||
}
|
}
|
||||||
//será possible renombrar y borrar estas bibliotecas
|
//será possible renombrar y borrar estas bibliotecas
|
||||||
renameLibraryAction->setEnabled(true);
|
renameLibraryAction->setEnabled(true);
|
||||||
removeLibraryAction->setEnabled(true);
|
removeLibraryAction->setEnabled(true);
|
||||||
}
|
}
|
||||||
@ -1592,13 +1592,17 @@ void LibraryWindow::setSearchFilter(QString filter)
|
|||||||
foldersView->scrollTo(mi,QAbstractItemView::PositionAtTop);
|
foldersView->scrollTo(mi,QAbstractItemView::PositionAtTop);
|
||||||
updateHistory(mi);
|
updateHistory(mi);
|
||||||
foldersView->setCurrentIndex(mi);
|
foldersView->setCurrentIndex(mi);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
reloadCovers();
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
if(!filter.isEmpty())
|
if(!filter.isEmpty())
|
||||||
{
|
{
|
||||||
foldersModel->setFilter(filter, true);//includeComicsCheckBox->isChecked());
|
foldersModel->setFilter(filter, true);//includeComicsCheckBox->isChecked());
|
||||||
|
comicsModel->setupModelData(filter, foldersModel->getDatabase());
|
||||||
foldersView->expandAll();
|
foldersView->expandAll();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -1926,7 +1930,7 @@ bool lessThanModelIndexRow(const QModelIndex & m1, const QModelIndex & m2)
|
|||||||
|
|
||||||
QModelIndexList LibraryWindow::getSelectedComics()
|
QModelIndexList LibraryWindow::getSelectedComics()
|
||||||
{
|
{
|
||||||
//se fuerza a que haya almenos una fila seleccionada TODO comprobar se se puede forzar a la tabla a que lo haga automáticamente
|
//se fuerza a que haya almenos una fila seleccionada TODO comprobar se se puede forzar a la tabla a que lo haga automáticamente
|
||||||
//avoid selection.count()==0 forcing selection in comicsView
|
//avoid selection.count()==0 forcing selection in comicsView
|
||||||
QModelIndexList selection = comicsView->selectionModel()->selectedRows();
|
QModelIndexList selection = comicsView->selectionModel()->selectedRows();
|
||||||
QLOG_INFO() << "selection count " << selection.length();
|
QLOG_INFO() << "selection count " << selection.length();
|
||||||
|
Loading…
x
Reference in New Issue
Block a user