bigsnitch/historymodel.h

44 lines
1.5 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-09-04 00:26:25 +00:00
#include <mutex>
2021-03-03 16:12:12 +00:00
#include <sstream>
2020-08-26 18:58:36 +00:00
2021-03-20 21:56:03 +00:00
//! The HistoryModel implements the AbstractTableModel for interacting with the view.
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;
2020-09-02 22:23:37 +00:00
std::string getRequestHeader(const HistoryItem& item) const;
std::string getResponseHeader(const HistoryItem& item) const;
2020-08-26 18:58:36 +00:00
public:
2021-03-20 21:56:03 +00:00
//! HistoryModel constructor
2020-08-26 18:58:36 +00:00
HistoryModel(QObject *parent = nullptr);
2021-03-20 21:56:03 +00:00
//! rowCount
2020-08-26 18:58:36 +00:00
int rowCount(const QModelIndex &parent = QModelIndex()) const override;
2021-03-20 21:56:03 +00:00
//! columnCount
2020-08-26 18:58:36 +00:00
int columnCount(const QModelIndex &parent = QModelIndex()) const override;
2021-03-20 21:56:03 +00:00
//! data
2020-08-26 18:58:36 +00:00
QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const override;
2021-03-20 21:56:03 +00:00
//! headerData
2020-08-28 23:09:41 +00:00
QVariant headerData(int section, Qt::Orientation orientation, int role) const override;
2021-03-20 21:56:03 +00:00
//! update
2020-08-26 18:58:36 +00:00
void update(std::vector<HistoryItem>* items);
};
2020-08-28 23:09:41 +00:00
2021-03-20 21:56:03 +00:00
//! HistoryProxyModel implements a SortFilterProxyModel for interacting with the view
2020-08-28 23:09:41 +00:00
class HistoryProxyModel : public QSortFilterProxyModel
{
Q_OBJECT
private:
public:
2021-03-20 21:56:03 +00:00
//! lessThan
2020-08-28 23:09:41 +00:00
bool lessThan(const QModelIndex &source_left, const QModelIndex &source_right) const override;
2021-03-20 21:56:03 +00:00
//! filterAcceptsRow
2020-08-28 23:09:41 +00:00
bool filterAcceptsRow(int source_row, const QModelIndex &source_parent) const override;
};