
#ifndef REG_MODEL_HH_
#define REG_MODEL_HH_

#include <QAbstractItemModel>
#include <QItemSelection>
#include <stdint.h>

#include "history.hh"

class RegModel : public QAbstractItemModel
{
  Q_OBJECT;
public:

  RegModel(HistoryBase *hist, QObject *parent = 0);

  bool getReg(unsigned &cpu, unsigned &reg, const QModelIndex &index) const;
  QModelIndex getIndex(unsigned cpu, unsigned reg) const;

public slots:
  void setDate(int date = -1);
  void resetEvent(unsigned cpu);

private:
  static const unsigned int bytes_per_rows = 16;

  QVariant data(const QModelIndex &index, int role) const;
  Qt::ItemFlags flags(const QModelIndex &index) const;
  QVariant headerData(int section, Qt::Orientation orientation, int role = Qt::DisplayRole) const;
  QModelIndex index(int row, int column, const QModelIndex &parent = QModelIndex()) const;
  QModelIndex parent(const QModelIndex &index) const;
  int rowCount(const QModelIndex &parent) const;
  int columnCount(const QModelIndex &parent) const;

  mutable unsigned _cache_reg_id;
  mutable unsigned _cache_cpu_id;
  mutable bool _cache_ok;
  mutable HistoryBase::reg_info_s _cache;

  unsigned _cpu_count;
  unsigned _max_reg_count;
  HistoryBase::history_date_t _date;
  uint64_t _addr;
  uint64_t _size;
  HistoryBase *_hist;
};

#endif

