From 8de0b7c96d22343ceddfeb17186d984239c2ac00 2017-06-19 09:05:38 From: Alexandre Leroux Date: 2017-06-19 09:05:38 Subject: [PATCH] Changes Variable from struct to class --- diff --git a/core/include/Variable/Variable.h b/core/include/Variable/Variable.h index ff5f718..dbdab81 100644 --- a/core/include/Variable/Variable.h +++ b/core/include/Variable/Variable.h @@ -1,20 +1,24 @@ #ifndef SCIQLOP_VARIABLE_H #define SCIQLOP_VARIABLE_H -#include +#include + +class QString; /** - * @brief The Variable struct represents a variable in SciQlop. + * @brief The Variable class represents a variable in SciQlop. */ -struct Variable { - explicit Variable(const QString &name, const QString &unit, const QString &mission) - : m_Name{name}, m_Unit{unit}, m_Mission{mission} - { - } +class Variable { +public: + explicit Variable(const QString &name, const QString &unit, const QString &mission); + + QString name() const noexcept; + QString mission() const noexcept; + QString unit() const noexcept; - QString m_Name; - QString m_Unit; - QString m_Mission; +private: + class VariablePrivate; + spimpl::unique_impl_ptr impl; }; #endif // SCIQLOP_VARIABLE_H diff --git a/core/src/Variable/Variable.cpp b/core/src/Variable/Variable.cpp new file mode 100644 index 0000000..22d3775 --- /dev/null +++ b/core/src/Variable/Variable.cpp @@ -0,0 +1,32 @@ +#include "Variable/Variable.h" + +struct Variable::VariablePrivate { + explicit VariablePrivate(const QString &name, const QString &unit, const QString &mission) + : m_Name{name}, m_Unit{unit}, m_Mission{mission} + { + } + + QString m_Name; + QString m_Unit; + QString m_Mission; +}; + +Variable::Variable(const QString &name, const QString &unit, const QString &mission) + : impl{spimpl::make_unique_impl(name, unit, mission)} +{ +} + +QString Variable::name() const noexcept +{ + return impl->m_Name; +} + +QString Variable::mission() const noexcept +{ + return impl->m_Mission; +} + +QString Variable::unit() const noexcept +{ + return impl->m_Unit; +} diff --git a/core/src/Variable/VariableModel.cpp b/core/src/Variable/VariableModel.cpp index 75389d5..30b5009 100644 --- a/core/src/Variable/VariableModel.cpp +++ b/core/src/Variable/VariableModel.cpp @@ -1,6 +1,6 @@ +#include #include -#include Q_LOGGING_CATEGORY(LOG_VariableModel, "VariableModel") @@ -67,11 +67,11 @@ QVariant VariableModel::data(const QModelIndex &index, int role) const if (auto variable = impl->m_Variables.at(index.row()).get()) { switch (index.column()) { case NAME_COLUMN: - return variable->m_Name; + return variable->name(); case UNIT_COLUMN: - return variable->m_Unit; + return variable->unit(); case MISSION_COLUMN: - return variable->m_Mission; + return variable->mission(); default: // No action break;