2019-12-19 11:58:52 +00:00
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include <QAbstractTableModel>
|
2019-12-21 18:05:47 +00:00
|
|
|
#include <functional>
|
2019-12-19 11:58:52 +00:00
|
|
|
|
2019-12-21 18:05:47 +00:00
|
|
|
#include "Types.h"
|
2019-12-19 11:58:52 +00:00
|
|
|
|
2019-12-21 18:05:47 +00:00
|
|
|
class CQtMemoryViewModel : public QAbstractTableModel
|
2019-12-19 11:58:52 +00:00
|
|
|
{
|
|
|
|
Q_OBJECT
|
|
|
|
public:
|
2019-12-21 18:05:47 +00:00
|
|
|
typedef std::function<uint8(uint32)> getByteProto;
|
|
|
|
|
|
|
|
typedef std::string (CQtMemoryViewModel::*UnitRenderer)(uint32) const;
|
2019-12-19 11:58:52 +00:00
|
|
|
struct UNITINFO
|
|
|
|
{
|
|
|
|
unsigned int bytesPerUnit = 0;
|
|
|
|
unsigned int charsPerUnit = 0;
|
|
|
|
UnitRenderer renderer = nullptr;
|
|
|
|
const char* description = nullptr;
|
|
|
|
};
|
|
|
|
|
2019-12-21 18:05:47 +00:00
|
|
|
CQtMemoryViewModel(QObject*, getByteProto, int);
|
|
|
|
~CQtMemoryViewModel();
|
2019-12-19 11:58:52 +00:00
|
|
|
|
|
|
|
int rowCount(const QModelIndex& parent = QModelIndex()) const Q_DECL_OVERRIDE;
|
|
|
|
int columnCount(const QModelIndex& parent = QModelIndex()) const Q_DECL_OVERRIDE;
|
|
|
|
QVariant data(const QModelIndex& index, int role = Qt::DisplayRole) const Q_DECL_OVERRIDE;
|
|
|
|
void DoubleClicked(const QModelIndex& index, QWidget* parent = nullptr);
|
|
|
|
|
|
|
|
void Redraw();
|
|
|
|
|
|
|
|
unsigned int UnitsForCurrentLine() const;
|
|
|
|
unsigned int BytesForCurrentLine() const;
|
|
|
|
void SetUnitsForCurrentLine(unsigned int);
|
|
|
|
unsigned int CharsPerUnit() const;
|
|
|
|
|
|
|
|
void SetActiveUnit(int);
|
|
|
|
int GetActiveUnit();
|
|
|
|
int GetBytesPerUnit();
|
|
|
|
|
|
|
|
static std::vector<UNITINFO> g_units;
|
|
|
|
|
|
|
|
protected:
|
|
|
|
QVariant headerData(int section, Qt::Orientation orientation, int role) const Q_DECL_OVERRIDE;
|
|
|
|
|
|
|
|
private:
|
|
|
|
uint8 GetByte(uint32) const;
|
|
|
|
std::string RenderByteUnit(uint32) const;
|
|
|
|
std::string RenderWordUnit(uint32) const;
|
|
|
|
std::string RenderSingleUnit(uint32) const;
|
|
|
|
|
2019-12-21 18:05:47 +00:00
|
|
|
getByteProto m_getByte;
|
2019-12-19 11:58:52 +00:00
|
|
|
int m_activeUnit;
|
|
|
|
unsigned int m_size;
|
|
|
|
std::atomic<unsigned int> m_unitsForCurrentLine = 0x20;
|
|
|
|
};
|