bigsnitch/historymodel.h
Tim Blume 600d7146d3 foo
2021-03-20 22:56:03 +01:00

43 lines
1.5 KiB
C++

#pragma once
#include <includes.h>
#include <QAbstractTableModel>
#include <QSortFilterProxyModel>
#include <mutex>
#include <sstream>
//! The HistoryModel implements the AbstractTableModel for interacting with the view.
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 constructor
HistoryModel(QObject *parent = nullptr);
//! rowCount
int rowCount(const QModelIndex &parent = QModelIndex()) const override;
//! columnCount
int columnCount(const QModelIndex &parent = QModelIndex()) const override;
//! data
QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const override;
//! headerData
QVariant headerData(int section, Qt::Orientation orientation, int role) const override;
//! update
void update(std::vector<HistoryItem>* items);
};
//! HistoryProxyModel implements a SortFilterProxyModel for interacting with the view
class HistoryProxyModel : public QSortFilterProxyModel
{
Q_OBJECT
private:
public:
//! lessThan
bool lessThan(const QModelIndex &source_left, const QModelIndex &source_right) const override;
//! filterAcceptsRow
bool filterAcceptsRow(int source_row, const QModelIndex &source_parent) const override;
};