diff options
Diffstat (limited to 'qtmips_gui')
-rw-r--r-- | qtmips_gui/memorymodel.cpp | 29 | ||||
-rw-r--r-- | qtmips_gui/memorymodel.h | 6 |
2 files changed, 22 insertions, 13 deletions
diff --git a/qtmips_gui/memorymodel.cpp b/qtmips_gui/memorymodel.cpp index 5596b35..71df4ce 100644 --- a/qtmips_gui/memorymodel.cpp +++ b/qtmips_gui/memorymodel.cpp @@ -40,20 +40,10 @@ MemoryModel::MemoryModel(QObject *parent) cell_size = CELLSIZE_WORD; cells_per_row = 1; index0_offset = 0; - updateHeaderLabels(); -} - -void MemoryModel::updateHeaderLabels() { - setHeaderData(0, Qt::Horizontal, QString("Address")); - for (unsigned int i = 0; i < cells_per_row; i++) { - std::uint32_t addr = i * cellSizeBytes(); - setHeaderData(i + 1, Qt::Horizontal, QString("+0x") + - QString::number(addr, 16)); - } } int MemoryModel::rowCount(const QModelIndex & /*parent*/) const { - std::uint64_t rows = (0x10000000 + cells_per_row - 1) / cells_per_row; + std::uint64_t rows = (0x100 + cells_per_row - 1) / cells_per_row; return rows; } @@ -61,6 +51,23 @@ int MemoryModel::columnCount(const QModelIndex & /*parent*/) const { return 2; } +QVariant MemoryModel::headerData(int section, Qt::Orientation orientation, int role) const +{ + if(orientation == Qt::Horizontal) { + if(role == Qt::DisplayRole) { + if(section == 0) { + return tr("Address"); + } + else { + std::uint32_t addr = (section - 1) * cellSizeBytes(); + QString ret = "+0x" + QString::number(addr, 16); + return ret; + } + } + } + return Super::headerData(section, orientation, role); +} + QVariant MemoryModel::data(const QModelIndex &index, int role) const { if (role == Qt::DisplayRole) { diff --git a/qtmips_gui/memorymodel.h b/qtmips_gui/memorymodel.h index badb224..8a01531 100644 --- a/qtmips_gui/memorymodel.h +++ b/qtmips_gui/memorymodel.h @@ -41,6 +41,8 @@ class MemoryModel : public QAbstractTableModel { Q_OBJECT + + using Super = QAbstractTableModel; public: enum MemoryCellSize { CELLSIZE_BYTE, @@ -51,10 +53,10 @@ public: MemoryModel(QObject *parent); int rowCount(const QModelIndex &parent = QModelIndex()) const override ; int columnCount(const QModelIndex &parent = QModelIndex()) const override; + QVariant headerData(int section, Qt::Orientation orientation, int role) const override; QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const override; private: - void updateHeaderLabels(); - inline unsigned int cellSizeBytes() { + inline unsigned int cellSizeBytes() const { switch (cell_size) { case CELLSIZE_BYTE: return 1; |