diff --git a/core/include/Variable/VariableModel.h b/core/include/Variable/VariableModel.h index ad2e627..074da18 100644 --- a/core/include/Variable/VariableModel.h +++ b/core/include/Variable/VariableModel.h @@ -3,6 +3,7 @@ #include +#include #include Q_DECLARE_LOGGING_CATEGORY(LOG_VariableModel) @@ -12,9 +13,9 @@ class Variable; /** * @brief The VariableModel class aims to hold the variables that have been created in SciQlop */ -class VariableModel { +class VariableModel : public QAbstractTableModel { public: - explicit VariableModel(); + explicit VariableModel(QObject *parent = nullptr); /** * Creates a new variable in the model @@ -23,6 +24,15 @@ public: */ Variable *createVariable(const QString &name) noexcept; + // /////////////////////////// // + // QAbstractTableModel methods // + // /////////////////////////// // + virtual int columnCount(const QModelIndex &parent = QModelIndex{}) const override; + virtual int rowCount(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; + private: class VariableModelPrivate; spimpl::unique_impl_ptr impl; diff --git a/core/src/Variable/VariableModel.cpp b/core/src/Variable/VariableModel.cpp index 7758670..75c2585 100644 --- a/core/src/Variable/VariableModel.cpp +++ b/core/src/Variable/VariableModel.cpp @@ -4,12 +4,19 @@ Q_LOGGING_CATEGORY(LOG_VariableModel, "VariableModel") +namespace { + +const auto NB_COLUMNS = 3; + +} // namespace + struct VariableModel::VariableModelPrivate { /// Variables created in SciQlop std::vector > m_Variables; }; -VariableModel::VariableModel() : impl{spimpl::make_unique_impl()} +VariableModel::VariableModel(QObject *parent) + : QAbstractTableModel{parent}, impl{spimpl::make_unique_impl()} { } @@ -22,3 +29,28 @@ Variable *VariableModel::createVariable(const QString &name) noexcept return impl->m_Variables.back().get(); } + +int VariableModel::columnCount(const QModelIndex &parent) const +{ + Q_UNUSED(parent); + + return NB_COLUMNS; +} + +int VariableModel::rowCount(const QModelIndex &parent) const +{ + Q_UNUSED(parent); + + return impl->m_Variables.size(); +} + +QVariant VariableModel::data(const QModelIndex &index, int role) const +{ + return QVariant{}; +} + +QVariant VariableModel::headerData(int section, Qt::Orientation orientation, int role) const +{ + + return QVariant{}; +}