
#ifndef MEM_MODEL_HH_
#define MEM_MODEL_HH_

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

#include "history.hh"

class MemModel : public QAbstractItemModel
{
  Q_OBJECT;
public:

  MemModel(HistoryBase *hist,
           uint64_t addr, uint64_t size,
           QObject *parent = 0);

  uint64_t getAddress(const QModelIndex &index) const;
  QModelIndex getIndex(uint64_t addr) const;
  QItemSelection getSelection(uint64_t first, uint64_t last) const;
  bool selectedAddrRows(uint64_t &first, uint64_t &last, const QItemSelectionModel *sm) const;

  void getAddrRange(uint64_t &first, uint64_t &last) const;

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

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 uint64_t _cache_addr;
  mutable bool _cache_ok;
  mutable HistoryBase::mem_info_s _cache;

  HistoryBase::history_date_t _date;
  uint64_t _addr;
  uint64_t _size;
  HistoryBase *_hist;
};

#endif

