added preliminar comics filter/search

This commit is contained in:
Luis Ángel San Martín
2014-10-04 09:35:36 +02:00
parent e4ddf4cfb4
commit 090be54bc1
3 changed files with 70 additions and 23 deletions

View File

@ -11,7 +11,7 @@
#include "db_helper.h"
//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)
@ -291,14 +291,14 @@ void TableModel::setupModelData(unsigned long long int folderId,const QString &
{
//crear la consulta
//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.bindValue(":parentId", folderId);
selectQuery.exec();
//txtS << "TABLEMODEL: Tiempo de consulta: " << timer.elapsed() << "ms\r\n";
//timer.restart();
setupModelData(selectQuery);
//txtS << "TABLEMODEL: Tiempo de creaci<EFBFBD>n del modelo: " << timer.elapsed() << "ms\r\n";
//txtS << "TABLEMODEL: Tiempo de creaci�n del modelo: " << timer.elapsed() << "ms\r\n";
//selectQuery.finish();
}
db.close();
@ -309,6 +309,47 @@ void TableModel::setupModelData(unsigned long long int folderId,const QString &
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)
{
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<EFBFBD>s
if(!lessThan) //si se ha encontrado un elemento menor que current, se inserta justo despu�s
{
if(numberCurrent != max)
{

View File

@ -35,21 +35,23 @@ public:
int rowCount(const QModelIndex &parent = QModelIndex()) const;
int columnCount(const QModelIndex &parent = QModelIndex()) const;
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<EFBFBD>todos de conveniencia
//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<EFBFBD>n
ComicDB getComic(const QModelIndex & mi); //--> para la edición
//ComicDB getComic(int row);
QVector<YACReaderComicReadStatus> getReadList();
QVector<YACReaderComicReadStatus> setAllComicsRead(YACReaderComicReadStatus readStatus);
QList<ComicDB> getComics(QList<QModelIndex> list); //--> recupera la informaci<EFBFBD>n com<EFBFBD>n a los comics seleccionados
QList<ComicDB> getComics(QList<QModelIndex> list); //--> recupera la información común a los comics seleccionados
QList<ComicDB> getAllComics();
QModelIndex getIndexFromId(quint64 id);
//setcomicInfo(QModelIndex & mi); --> inserta en la base datos
//setComicInfoForAllComics(); --> inserta la informaci<EFBFBD>n com<EFBFBD>n a todos los c<EFBFBD>mics de una sola vez.
//setComicInfoForSelectedComis(QList<QModelIndex> list); -->inserta la informaci<EFBFBD>n com<EFBFBD>n para los comics seleccionados
//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
QVector<YACReaderComicReadStatus> setComicsRead(QList<QModelIndex> list,YACReaderComicReadStatus read);
qint64 asignNumbers(QList<QModelIndex> list,int startingNumber);
void remove(ComicDB * comic, int row);