2018-08-12 16:45:39 +02:00
|
|
|
#ifndef SEARCHWORKER_H
|
|
|
|
#define SEARCHWORKER_H
|
|
|
|
#include <QObject>
|
|
|
|
#include <QSqlDatabase>
|
|
|
|
#include <QSqlQuery>
|
|
|
|
#include <QString>
|
|
|
|
#include <QVector>
|
2019-04-22 21:07:41 +02:00
|
|
|
#include "../shared/searchresult.h"
|
2018-08-12 16:45:39 +02:00
|
|
|
|
|
|
|
class SearchWorker : public QObject
|
|
|
|
{
|
2018-09-02 12:27:23 +02:00
|
|
|
class Command
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
QString key;
|
|
|
|
QString value;
|
|
|
|
|
|
|
|
Command(QString key="", QString value="")
|
|
|
|
{
|
|
|
|
this->key = key;
|
|
|
|
this->value = value;
|
|
|
|
}
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2018-08-12 16:45:39 +02:00
|
|
|
Q_OBJECT
|
|
|
|
private:
|
2018-09-02 12:27:23 +02:00
|
|
|
QVector<Command> tokenize(QString expression);
|
|
|
|
QString createSql(const Command &cmd);
|
|
|
|
QString makeSql(const QVector<Command> &tokens);
|
|
|
|
QSqlDatabase db;
|
2018-08-12 16:45:39 +02:00
|
|
|
public:
|
|
|
|
SearchWorker();
|
|
|
|
SearchWorker(const QString &dbpath);
|
2018-09-02 13:54:27 +02:00
|
|
|
bool checkParanthesis(QString expression);
|
2018-08-12 16:45:39 +02:00
|
|
|
public slots:
|
2018-09-02 12:27:23 +02:00
|
|
|
void search(const QString &query);
|
2018-08-12 16:45:39 +02:00
|
|
|
signals:
|
|
|
|
void searchResultsReady(const QVector<SearchResult> &results);
|
|
|
|
void searchCancelled();
|
2018-09-02 13:54:27 +02:00
|
|
|
void searchError(QString e);
|
2018-08-12 16:45:39 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
#endif // SEARCHWORKER_H
|