120 lines
2.5 KiB
C++
120 lines
2.5 KiB
C++
#ifndef RECORDQUERY_H
|
|
#define RECORDQUERY_H
|
|
|
|
#include <QWidget>
|
|
#include <QDateTime>
|
|
#include <memory>
|
|
#include <vector>
|
|
#include <qcombobox.h>
|
|
|
|
#include "spdlog/spdlog.h"
|
|
#include "sqlite3pp.h"
|
|
|
|
enum class Channel{
|
|
Uhf,
|
|
S,
|
|
BeiDou,
|
|
};
|
|
|
|
enum class CommType{
|
|
Call,
|
|
ShortMessage,
|
|
};
|
|
|
|
enum class CommDirection{
|
|
Send,
|
|
Receive,
|
|
};
|
|
|
|
struct Record{
|
|
QDateTime beginTime;
|
|
Channel channel;
|
|
CommType type;
|
|
CommDirection direction;
|
|
QString number;
|
|
QString content;
|
|
bool isUnread;
|
|
int callDuration;//s
|
|
};
|
|
struct DbRecord{
|
|
uint64_t id;
|
|
std::string beginTime;
|
|
int channel;
|
|
int type;
|
|
int direction;
|
|
std::string number;
|
|
std::string content;
|
|
int callDuration;//s
|
|
};
|
|
|
|
// ------------------------ 基础工具与枚举 ------------------------
|
|
|
|
enum class NumberKind { Call, USMsg, BdMsg };
|
|
|
|
|
|
namespace Ui {
|
|
class RecordQuery;
|
|
}
|
|
|
|
class QTableWidgetItem;
|
|
class RecordQuery : public QWidget
|
|
{
|
|
Q_OBJECT
|
|
|
|
public:
|
|
explicit RecordQuery(QWidget *parent = nullptr);
|
|
~RecordQuery();
|
|
void InsertRecord(const Record& data);
|
|
void InsertRecords(const std::vector<Record>& data);
|
|
bool saveNumber(NumberKind kind, const QString& number);
|
|
void refreshNumberCombo(QComboBox* combo, NumberKind kind);
|
|
void setupNumberCombo(QObject* owner, QComboBox* combo, NumberKind kind);
|
|
private slots:
|
|
void on_btnQuery_clicked();
|
|
|
|
void on_btnFirstPage_clicked();
|
|
|
|
void on_btnPreviousPage_clicked();
|
|
|
|
void on_btnNextPage_clicked();
|
|
|
|
void on_btnLastPage_clicked();
|
|
|
|
void on_spbGoToPage_valueChanged(int arg1);
|
|
|
|
void on_tblRecordList_currentItemChanged(QTableWidgetItem *current, QTableWidgetItem *previous);
|
|
|
|
void on_chbTime_stateChanged(int arg1);
|
|
|
|
void on_chbChannel_stateChanged(int arg1);
|
|
|
|
void on_chbType_stateChanged(int arg1);
|
|
|
|
void on_chbDirection_stateChanged(int arg1);
|
|
|
|
void on_chbNumber_stateChanged(int arg1);
|
|
|
|
private:
|
|
Ui::RecordQuery *ui;
|
|
|
|
std::shared_ptr<spdlog::logger> m_logger;
|
|
|
|
void InitDatabase();
|
|
void ensureSchema(sqlite3pp::database& db);
|
|
void ensureKeepTop20Triggers(sqlite3pp::database& db);
|
|
QStringList queryNumbers(NumberKind kind, int limit);
|
|
bool clearNumbers(NumberKind kind);
|
|
|
|
void UpdateRecordList(const std::vector<DbRecord>& r);
|
|
|
|
QString getQueryCondition(bool isCountQuery = false);
|
|
void getQueryRecords(sqlite3pp::query&qry,std::vector<DbRecord>& records);
|
|
|
|
std::shared_ptr<sqlite3pp::database> m_db;
|
|
int m_currentPageIndex = 0;
|
|
int m_maxPageIndex = 0;
|
|
int m_limit = 30;
|
|
};
|
|
|
|
#endif // RECORDQUERY_H
|