bigsnitch/historymodel.h
2020-09-03 00:23:37 +02:00

51 lines
1.6 KiB
C++

#pragma once
#include <includes.h>
#include <QAbstractTableModel>
#include <QSortFilterProxyModel>
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;
std::string request_http_version;
std::map<std::string, std::string> request_headers;
std::string request_content;
std::string response_http_version;
std::map<std::string, std::string> response_headers;
std::string response_content;
};
class HistoryModel : public QAbstractTableModel
{
Q_OBJECT
private:
mutable std::mutex history_mutex;
std::vector<HistoryItem>* current_items = nullptr;
std::string getRequestHeader(const HistoryItem& item) const;
std::string getResponseHeader(const HistoryItem& item) const;
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;
QVariant headerData(int section, Qt::Orientation orientation, int role) const override;
void update(std::vector<HistoryItem>* items);
};
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;
};