mirror of
https://github.com/YACReader/yacreader
synced 2025-07-27 09:24:57 -04:00
added support for search modifiers, added [read] [unread] as examples
This commit is contained in:
@ -309,7 +309,7 @@ void TableModel::setupModelData(unsigned long long int folderId,const QString &
|
||||
emit isEmpty();
|
||||
}
|
||||
|
||||
void TableModel::setupModelData(const QString &filter, const QString &databasePath)
|
||||
void TableModel::setupModelData(const SearchModifiers modifier, const QString &filter, const QString &databasePath)
|
||||
{
|
||||
//QFile f(QCoreApplication::applicationDirPath()+"/performance.txt");
|
||||
//f.open(QIODevice::Append);
|
||||
@ -327,11 +327,38 @@ void TableModel::setupModelData(const QString &filter, const QString &databasePa
|
||||
//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
|
||||
|
||||
switch (modifier) {
|
||||
case YACReader::NoModifiers:
|
||||
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
|
||||
break;
|
||||
|
||||
case YACReader::OnlyRead:
|
||||
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)) AND ci.read = 1 LIMIT :limit");
|
||||
selectQuery.bindValue(":filter", "%%"+filter+"%%");
|
||||
selectQuery.bindValue(":limit",500); //TODO, load this value from settings
|
||||
break;
|
||||
|
||||
case YACReader::OnlyUnread:
|
||||
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)) AND ci.read = 0 LIMIT :limit");
|
||||
selectQuery.bindValue(":filter", "%%"+filter+"%%");
|
||||
selectQuery.bindValue(":limit",500); //TODO, load this value from settings
|
||||
break;
|
||||
|
||||
default:
|
||||
QLOG_ERROR() << "not implemented";
|
||||
break;
|
||||
}
|
||||
|
||||
|
||||
selectQuery.exec();
|
||||
|
||||
QLOG_DEBUG() << selectQuery.lastError() << "--";
|
||||
|
@ -36,7 +36,7 @@ public:
|
||||
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);
|
||||
void setupModelData(const SearchModifiers modifier, const QString & filter, const QString & databasePath);
|
||||
|
||||
//Métodos de conveniencia
|
||||
QStringList getPaths(const QString & _source);
|
||||
|
@ -55,6 +55,8 @@
|
||||
#include "db_helper.h"
|
||||
#include "qnaturalsorting.h"
|
||||
|
||||
#include "QsLog.h"
|
||||
|
||||
#ifdef Q_OS_MAC
|
||||
#include <QFileIconProvider>
|
||||
QIcon finishedFolderIcon;
|
||||
@ -369,11 +371,41 @@ void TreeModel::setupFilteredModelData()
|
||||
selectQuery.prepare("select * from folder where id <> 1 and upper(name) like upper(:filter) order by parentId,name ");
|
||||
selectQuery.bindValue(":filter", "%%"+filter+"%%");
|
||||
}
|
||||
else
|
||||
{
|
||||
selectQuery.prepare("SELECT DISTINCT f.id, f.parentId, f.name, f.path, f.finished, f.completed FROM folder f LEFT 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+"%%");
|
||||
else
|
||||
{
|
||||
switch(modifier)
|
||||
{
|
||||
case YACReader::NoModifiers:
|
||||
selectQuery.prepare("SELECT DISTINCT f.id, f.parentId, f.name, f.path, f.finished, f.completed "
|
||||
"FROM folder f LEFT 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+"%%");
|
||||
break;
|
||||
|
||||
case YACReader::OnlyRead:
|
||||
selectQuery.prepare("SELECT DISTINCT f.id, f.parentId, f.name, f.path, f.finished, f.completed "
|
||||
"FROM folder f LEFT JOIN (comic c INNER JOIN comic_info ci ON (c.comicInfoId = ci.id)) ON (f.id = c.parentId) "
|
||||
"WHERE f.id <> 1 AND ((UPPER(c.fileName) like UPPER(:filter)) OR (UPPER(f.name) like UPPER(:filter2))) AND ci.read = 1 ORDER BY f.parentId,f.name;");
|
||||
selectQuery.bindValue(":filter", "%%"+filter+"%%");
|
||||
selectQuery.bindValue(":filter2", "%%"+filter+"%%");
|
||||
break;
|
||||
|
||||
case YACReader::OnlyUnread:
|
||||
selectQuery.prepare("SELECT DISTINCT f.id, f.parentId, f.name, f.path, f.finished, f.completed "
|
||||
"FROM folder f LEFT JOIN (comic c INNER JOIN comic_info ci ON (c.comicInfoId = ci.id)) ON (f.id = c.parentId) "
|
||||
"WHERE f.id <> 1 AND ((UPPER(c.fileName) like UPPER(:filter)) OR (UPPER(f.name) like UPPER(:filter2))) AND ci.read = 0 ORDER BY f.parentId,f.name;");
|
||||
selectQuery.bindValue(":filter", "%%"+filter+"%%");
|
||||
selectQuery.bindValue(":filter2", "%%"+filter+"%%");
|
||||
break;
|
||||
|
||||
default:
|
||||
QLOG_ERROR() << "not implemented";
|
||||
break;
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
selectQuery.exec();
|
||||
|
||||
@ -476,10 +508,11 @@ QString TreeModel::getFolderPath(const QModelIndex &folder)
|
||||
return static_cast<TreeItem*>(folder.internalPointer())->data(TreeModel::Path).toString();
|
||||
}
|
||||
|
||||
void TreeModel::setFilter(QString filter, bool includeComics)
|
||||
void TreeModel::setFilter(const YACReader::SearchModifiers modifier, QString filter, bool includeComics)
|
||||
{
|
||||
this->filter = filter;
|
||||
this->includeComics = includeComics;
|
||||
this->modifier = modifier;
|
||||
filterEnabled = true;
|
||||
setupFilteredModelData();
|
||||
}
|
||||
|
@ -47,6 +47,8 @@
|
||||
#include <QSqlQuery>
|
||||
#include <QSqlDatabase>
|
||||
|
||||
#include "yacreader_global.h"
|
||||
|
||||
class TreeItem;
|
||||
|
||||
//! [0]
|
||||
@ -78,7 +80,7 @@ public:
|
||||
//Métodos de conveniencia
|
||||
QString getFolderPath(const QModelIndex &folder);
|
||||
|
||||
void setFilter(QString filter, bool includeComics);
|
||||
void setFilter(const YACReader::SearchModifiers modifier, QString filter, bool includeComics);
|
||||
void resetFilter();
|
||||
bool isFilterEnabled(){return filterEnabled;};
|
||||
|
||||
@ -118,6 +120,8 @@ private:
|
||||
bool includeComics;
|
||||
QString filter;
|
||||
bool filterEnabled;
|
||||
|
||||
YACReader::SearchModifiers modifier;
|
||||
signals:
|
||||
void beforeReset();
|
||||
void reset();
|
||||
|
Reference in New Issue
Block a user