From 60eef9a674fc71271c56300c304b68f6ad408901 2017-06-13 08:10:52 From: Alexandre Leroux Date: 2017-06-13 08:10:52 Subject: [PATCH] Creates the variable model The variable model holds a vector of variables. The Variable struct will be completed afterwards --- diff --git a/core/include/Variable/Variable.h b/core/include/Variable/Variable.h new file mode 100644 index 0000000..ff5f718 --- /dev/null +++ b/core/include/Variable/Variable.h @@ -0,0 +1,20 @@ +#ifndef SCIQLOP_VARIABLE_H +#define SCIQLOP_VARIABLE_H + +#include + +/** + * @brief The Variable struct 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} + { + } + + QString m_Name; + QString m_Unit; + QString m_Mission; +}; + +#endif // SCIQLOP_VARIABLE_H diff --git a/core/include/Variable/VariableModel.h b/core/include/Variable/VariableModel.h new file mode 100644 index 0000000..ad2e627 --- /dev/null +++ b/core/include/Variable/VariableModel.h @@ -0,0 +1,31 @@ +#ifndef SCIQLOP_VARIABLEMODEL_H +#define SCIQLOP_VARIABLEMODEL_H + +#include + +#include + +Q_DECLARE_LOGGING_CATEGORY(LOG_VariableModel) + +class Variable; + +/** + * @brief The VariableModel class aims to hold the variables that have been created in SciQlop + */ +class VariableModel { +public: + explicit VariableModel(); + + /** + * Creates a new variable in the model + * @param name the name of the new variable + * @return the variable if it was created successfully, nullptr otherwise + */ + Variable *createVariable(const QString &name) noexcept; + +private: + class VariableModelPrivate; + spimpl::unique_impl_ptr impl; +}; + +#endif // SCIQLOP_VARIABLEMODEL_H diff --git a/core/src/Variable/VariableModel.cpp b/core/src/Variable/VariableModel.cpp new file mode 100644 index 0000000..7758670 --- /dev/null +++ b/core/src/Variable/VariableModel.cpp @@ -0,0 +1,24 @@ +#include + +#include + +Q_LOGGING_CATEGORY(LOG_VariableModel, "VariableModel") + +struct VariableModel::VariableModelPrivate { + /// Variables created in SciQlop + std::vector > m_Variables; +}; + +VariableModel::VariableModel() : impl{spimpl::make_unique_impl()} +{ +} + +Variable *VariableModel::createVariable(const QString &name) noexcept +{ + /// @todo For the moment, the other data of the variable is initialized with default values + auto variable + = std::make_unique(name, QStringLiteral("unit"), QStringLiteral("mission")); + impl->m_Variables.push_back(std::move(variable)); + + return impl->m_Variables.back().get(); +}