Commit 25f07764423af70cf3f4daa2590969f8595613f6
1 parent
1dce31e3
Implementing the memorymodel
Showing
3 changed files
with
101 additions
and
0 deletions
src/CMakeLists.txt
| @@ -14,11 +14,13 @@ include(compiler) | @@ -14,11 +14,13 @@ include(compiler) | ||
| 14 | set( SRC_LIST | 14 | set( SRC_LIST |
| 15 | ${CMAKE_CURRENT_SOURCE_DIR}/tablemodel/tablemodel.cpp | 15 | ${CMAKE_CURRENT_SOURCE_DIR}/tablemodel/tablemodel.cpp |
| 16 | ${CMAKE_CURRENT_SOURCE_DIR}/tablemodel/modeldataitem.cpp | 16 | ${CMAKE_CURRENT_SOURCE_DIR}/tablemodel/modeldataitem.cpp |
| 17 | + ${CMAKE_CURRENT_SOURCE_DIR}/memorymodel/memorymodel.cpp | ||
| 17 | ) | 18 | ) |
| 18 | 19 | ||
| 19 | include(qtmoc) | 20 | include(qtmoc) |
| 20 | create_mocs( SRC_LIST MOC_LIST | 21 | create_mocs( SRC_LIST MOC_LIST |
| 21 | ${CMAKE_CURRENT_SOURCE_DIR}/tablemodel/tablemodel.h | 22 | ${CMAKE_CURRENT_SOURCE_DIR}/tablemodel/tablemodel.h |
| 23 | + ${CMAKE_CURRENT_SOURCE_DIR}/memorymodel/memorymodel.h | ||
| 22 | ) | 24 | ) |
| 23 | 25 | ||
| 24 | link_directories( | 26 | link_directories( |
src/memorymodel/memorymodel.cpp
0 → 100644
| 1 | +#include "memorymodel.h" | ||
| 2 | + | ||
| 3 | +MemoryModel::MemoryModel(int segments, int registers_per_segment, QObject *parent) | ||
| 4 | + : QAbstractItemModel(parent) | ||
| 5 | + , m_memoryData() | ||
| 6 | +{ | ||
| 7 | + for(int nCount = 0; nCount < segments; nCount++) | ||
| 8 | + { | ||
| 9 | + m_memoryData.insert( nCount, QVector<uint16_t>(registers_per_segment, 0x00) ); | ||
| 10 | + } | ||
| 11 | +} | ||
| 12 | + | ||
| 13 | +int MemoryModel::columnCount(const QModelIndex &parent) const | ||
| 14 | +{ | ||
| 15 | + if(rowCount(parent) > 0) | ||
| 16 | + { | ||
| 17 | + return m_memoryData.value(0).count(); | ||
| 18 | + } | ||
| 19 | + return 0; | ||
| 20 | +} | ||
| 21 | + | ||
| 22 | +QVariant MemoryModel::data(const QModelIndex &index, int role) const | ||
| 23 | +{ | ||
| 24 | + int segment = index.row(); | ||
| 25 | + int reg = index.column(); | ||
| 26 | + | ||
| 27 | + switch(role) | ||
| 28 | + { | ||
| 29 | + case Qt::DisplayRole: | ||
| 30 | + return QVariant(m_memoryData.value(segment).at(reg)); | ||
| 31 | + | ||
| 32 | + default: | ||
| 33 | + return QVariant(); | ||
| 34 | + } | ||
| 35 | +} | ||
| 36 | + | ||
| 37 | +QVariant MemoryModel::headerData(int section, Qt::Orientation orientation, int role) const | ||
| 38 | +{ | ||
| 39 | + // Make sure we stay within the header boundaries... | ||
| 40 | + // ColumnNames | ||
| 41 | + if(role == Qt::DisplayRole && orientation == Qt::Horizontal && section < m_headers.size()) | ||
| 42 | + { | ||
| 43 | + return m_headers.at(section); | ||
| 44 | + } | ||
| 45 | + return QVariant(); | ||
| 46 | +} | ||
| 47 | + | ||
| 48 | +QModelIndex MemoryModel::index(int row, int column, const QModelIndex &parent) const | ||
| 49 | +{ | ||
| 50 | + | ||
| 51 | +} | ||
| 52 | + | ||
| 53 | +QModelIndex MemoryModel::parent(const QModelIndex &index) const | ||
| 54 | +{ | ||
| 55 | + Q_UNUSED(index) | ||
| 56 | + return QModelIndex(); | ||
| 57 | +} | ||
| 58 | + | ||
| 59 | +int MemoryModel::rowCount(const QModelIndex &parent) const | ||
| 60 | +{ | ||
| 61 | + return m_memoryData.count(); | ||
| 62 | +} | ||
| 63 | + | ||
| 64 | +bool MemoryModel::setData(const QModelIndex &index, const QVariant &value, int role) | ||
| 65 | +{ | ||
| 66 | + | ||
| 67 | +} | ||
| 68 | + | ||
| 69 | +bool MemoryModel::setHeaderData(int section, Qt::Orientation orientation, const QVariant &value, int role) | ||
| 70 | +{ | ||
| 71 | + | ||
| 72 | +} |
src/memorymodel/memorymodel.h
0 → 100644
| 1 | +#pragma once | ||
| 2 | + | ||
| 3 | +#include <QAbstractItemModel> | ||
| 4 | +#include <QVector> | ||
| 5 | +#include <QHash> | ||
| 6 | + | ||
| 7 | +class MemoryModel : public QAbstractItemModel | ||
| 8 | +{ | ||
| 9 | + Q_OBJECT | ||
| 10 | + | ||
| 11 | +public: | ||
| 12 | + explicit MemoryModel(int segments = 10, int registers_per_segment = 10, QObject *parent = nullptr); | ||
| 13 | + virtual ~MemoryModel() override {} | ||
| 14 | + | ||
| 15 | + virtual int columnCount(const QModelIndex &parent = QModelIndex()) const override; | ||
| 16 | + virtual QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const override; | ||
| 17 | + virtual QVariant headerData(int section, Qt::Orientation orientation, int role = Qt::DisplayRole) const override; | ||
| 18 | + virtual QModelIndex index(int row, int column, const QModelIndex &parent = QModelIndex()) const override; | ||
| 19 | + virtual QModelIndex parent(const QModelIndex &index) const override; | ||
| 20 | + virtual int rowCount(const QModelIndex &parent = QModelIndex()) const override; | ||
| 21 | + virtual bool setData(const QModelIndex &index, const QVariant &value, int role = Qt::EditRole) override; | ||
| 22 | + virtual bool setHeaderData(int section, Qt::Orientation orientation, const QVariant &value, int role = Qt::EditRole) override; | ||
| 23 | + | ||
| 24 | +private: | ||
| 25 | + QHash<int, QVector<uint16_t>> m_memoryData; | ||
| 26 | + QStringList m_headers; | ||
| 27 | +}; |