diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 0656d7a..682ece8 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -14,11 +14,13 @@ include(compiler) set( SRC_LIST ${CMAKE_CURRENT_SOURCE_DIR}/tablemodel/tablemodel.cpp ${CMAKE_CURRENT_SOURCE_DIR}/tablemodel/modeldataitem.cpp + ${CMAKE_CURRENT_SOURCE_DIR}/memorymodel/memorymodel.cpp ) include(qtmoc) create_mocs( SRC_LIST MOC_LIST ${CMAKE_CURRENT_SOURCE_DIR}/tablemodel/tablemodel.h + ${CMAKE_CURRENT_SOURCE_DIR}/memorymodel/memorymodel.h ) link_directories( diff --git a/src/memorymodel/memorymodel.cpp b/src/memorymodel/memorymodel.cpp new file mode 100644 index 0000000..9a9e077 --- /dev/null +++ b/src/memorymodel/memorymodel.cpp @@ -0,0 +1,72 @@ +#include "memorymodel.h" + +MemoryModel::MemoryModel(int segments, int registers_per_segment, QObject *parent) + : QAbstractItemModel(parent) + , m_memoryData() +{ + for(int nCount = 0; nCount < segments; nCount++) + { + m_memoryData.insert( nCount, QVector(registers_per_segment, 0x00) ); + } +} + +int MemoryModel::columnCount(const QModelIndex &parent) const +{ + if(rowCount(parent) > 0) + { + return m_memoryData.value(0).count(); + } + return 0; +} + +QVariant MemoryModel::data(const QModelIndex &index, int role) const +{ + int segment = index.row(); + int reg = index.column(); + + switch(role) + { + case Qt::DisplayRole: + return QVariant(m_memoryData.value(segment).at(reg)); + + default: + return QVariant(); + } +} + +QVariant MemoryModel::headerData(int section, Qt::Orientation orientation, int role) const +{ + // Make sure we stay within the header boundaries... + // ColumnNames + if(role == Qt::DisplayRole && orientation == Qt::Horizontal && section < m_headers.size()) + { + return m_headers.at(section); + } + return QVariant(); +} + +QModelIndex MemoryModel::index(int row, int column, const QModelIndex &parent) const +{ + +} + +QModelIndex MemoryModel::parent(const QModelIndex &index) const +{ + Q_UNUSED(index) + return QModelIndex(); +} + +int MemoryModel::rowCount(const QModelIndex &parent) const +{ + return m_memoryData.count(); +} + +bool MemoryModel::setData(const QModelIndex &index, const QVariant &value, int role) +{ + +} + +bool MemoryModel::setHeaderData(int section, Qt::Orientation orientation, const QVariant &value, int role) +{ + +} diff --git a/src/memorymodel/memorymodel.h b/src/memorymodel/memorymodel.h new file mode 100644 index 0000000..8cff292 --- /dev/null +++ b/src/memorymodel/memorymodel.h @@ -0,0 +1,27 @@ +#pragma once + +#include +#include +#include + +class MemoryModel : public QAbstractItemModel +{ + Q_OBJECT + +public: + explicit MemoryModel(int segments = 10, int registers_per_segment = 10, QObject *parent = nullptr); + virtual ~MemoryModel() override {} + + virtual int columnCount(const QModelIndex &parent = QModelIndex()) const override; + virtual QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const override; + virtual QVariant headerData(int section, Qt::Orientation orientation, int role = Qt::DisplayRole) const override; + virtual QModelIndex index(int row, int column, const QModelIndex &parent = QModelIndex()) const override; + virtual QModelIndex parent(const QModelIndex &index) const override; + virtual int rowCount(const QModelIndex &parent = QModelIndex()) const override; + virtual bool setData(const QModelIndex &index, const QVariant &value, int role = Qt::EditRole) override; + virtual bool setHeaderData(int section, Qt::Orientation orientation, const QVariant &value, int role = Qt::EditRole) override; + +private: + QHash> m_memoryData; + QStringList m_headers; +};