bigsnitch/historymodel.h

48 lines
1.4 KiB
C
Raw Normal View History

2020-08-26 18:58:36 +00:00
#pragma once
#include <includes.h>
#include <QAbstractTableModel>
2020-08-28 23:09:41 +00:00
#include <QSortFilterProxyModel>
2020-08-26 18:58:36 +00:00
struct HistoryItem {
int id = -1;
double timestamp = 0;
std::string method;
std::string scheme;
std::string host;
unsigned short port = 0;
std::string path;
int status_code = 0;
std::string reason;
double rtt = 0.0;
size_t size = 0;
2020-09-02 12:13:03 +00:00
std::string request_content;
std::string response_content;
std::map<std::string, std::string> request_headers;
std::map<std::string, std::string> response_headers;
2020-08-26 18:58:36 +00:00
};
class HistoryModel : public QAbstractTableModel
{
Q_OBJECT
private:
2020-09-01 12:55:49 +00:00
mutable std::mutex history_mutex;
2020-08-26 18:58:36 +00:00
std::vector<HistoryItem>* current_items = nullptr;
public:
HistoryModel(QObject *parent = nullptr);
int rowCount(const QModelIndex &parent = QModelIndex()) const override;
int columnCount(const QModelIndex &parent = QModelIndex()) const override;
QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const override;
2020-08-28 23:09:41 +00:00
QVariant headerData(int section, Qt::Orientation orientation, int role) const override;
2020-08-26 18:58:36 +00:00
void update(std::vector<HistoryItem>* items);
};
2020-08-28 23:09:41 +00:00
class HistoryProxyModel : public QSortFilterProxyModel
{
Q_OBJECT
private:
public:
bool lessThan(const QModelIndex &source_left, const QModelIndex &source_right) const override;
bool filterAcceptsRow(int source_row, const QModelIndex &source_parent) const override;
};