
#ifndef EVENT_MODEL_HH_
#define EVENT_MODEL_HH_

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

#include "history.hh"

class HistoryBase;

class EventModel : public QAbstractItemModel
{
public:

  EventModel(HistoryBase *hist, QObject *parent = 0);
  bool eventInfo(HistoryBase::event_info_s &i, const QModelIndex &index) const;

  virtual QModelIndex indexFromDate(HistoryBase::history_date_t date) const = 0;
  virtual void update() = 0;

protected:

  virtual bool eventInfo(int row) const = 0;

  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) const;
  QModelIndex parent(const QModelIndex &index) const;
  int columnCount(const QModelIndex &parent) const;

  HistoryBase *_hist;
  mutable HistoryBase::event_info_s _cache;
};

class EventModelAll : public EventModel
{
public:
  EventModelAll(HistoryBase *hist, QObject *parent = 0);

private:
  int rowCount(const QModelIndex &parent) const;
  bool eventInfo(int row) const;
  QModelIndex indexFromDate(HistoryBase::history_date_t date) const;
  void update();

  mutable HistoryBase::history_date_t _first;  //< date of oldest entry at snapshot time
  mutable HistoryBase::history_date_t _count;  //< number of entries at snapshot time
};

class EventModelMem : public EventModel
{
public:
  EventModelMem(HistoryBase *hist, uint64_t addr, QObject *parent = 0);

private:
  int rowCount(const QModelIndex &parent) const;
  bool eventInfo(int row) const;
  QModelIndex indexFromDate(HistoryBase::history_date_t date) const;
  void update();

  uint64_t _addr;

  mutable HistoryBase::history_date_t _last;  //< date of the most recent event
  mutable QList <HistoryBase::event_info_s> _info;
};

class EventModelReg : public EventModel
{
public:
  EventModelReg(HistoryBase *hist, unsigned cpu, unsigned reg, QObject *parent = 0);

private:
  int rowCount(const QModelIndex &parent) const;
  bool eventInfo(int row) const;
  QModelIndex indexFromDate(HistoryBase::history_date_t date) const;
  void update();

  unsigned _cpu;
  unsigned _reg;

  mutable HistoryBase::history_date_t _last;  //< date of the most recent event
  mutable QList <HistoryBase::event_info_s> _info;
};

#endif


