##// END OF EJS Templates
Adapts VariableModel to be a QabstractTableModel...
Alexandre Leroux -
r149:5bdc904b0565
parent child
Show More
@@ -1,31 +1,41
1 1 #ifndef SCIQLOP_VARIABLEMODEL_H
2 2 #define SCIQLOP_VARIABLEMODEL_H
3 3
4 4 #include <Common/spimpl.h>
5 5
6 #include <QAbstractTableModel>
6 7 #include <QLoggingCategory>
7 8
8 9 Q_DECLARE_LOGGING_CATEGORY(LOG_VariableModel)
9 10
10 11 class Variable;
11 12
12 13 /**
13 14 * @brief The VariableModel class aims to hold the variables that have been created in SciQlop
14 15 */
15 class VariableModel {
16 class VariableModel : public QAbstractTableModel {
16 17 public:
17 explicit VariableModel();
18 explicit VariableModel(QObject *parent = nullptr);
18 19
19 20 /**
20 21 * Creates a new variable in the model
21 22 * @param name the name of the new variable
22 23 * @return the variable if it was created successfully, nullptr otherwise
23 24 */
24 25 Variable *createVariable(const QString &name) noexcept;
25 26
27 // /////////////////////////// //
28 // QAbstractTableModel methods //
29 // /////////////////////////// //
30 virtual int columnCount(const QModelIndex &parent = QModelIndex{}) const override;
31 virtual int rowCount(const QModelIndex &parent = QModelIndex{}) const override;
32 virtual QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const override;
33 virtual QVariant headerData(int section, Qt::Orientation orientation,
34 int role = Qt::DisplayRole) const override;
35
26 36 private:
27 37 class VariableModelPrivate;
28 38 spimpl::unique_impl_ptr<VariableModelPrivate> impl;
29 39 };
30 40
31 41 #endif // SCIQLOP_VARIABLEMODEL_H
@@ -1,24 +1,56
1 1 #include <Variable/VariableModel.h>
2 2
3 3 #include <Variable/Variable.h>
4 4
5 5 Q_LOGGING_CATEGORY(LOG_VariableModel, "VariableModel")
6 6
7 namespace {
8
9 const auto NB_COLUMNS = 3;
10
11 } // namespace
12
7 13 struct VariableModel::VariableModelPrivate {
8 14 /// Variables created in SciQlop
9 15 std::vector<std::unique_ptr<Variable> > m_Variables;
10 16 };
11 17
12 VariableModel::VariableModel() : impl{spimpl::make_unique_impl<VariableModelPrivate>()}
18 VariableModel::VariableModel(QObject *parent)
19 : QAbstractTableModel{parent}, impl{spimpl::make_unique_impl<VariableModelPrivate>()}
13 20 {
14 21 }
15 22
16 23 Variable *VariableModel::createVariable(const QString &name) noexcept
17 24 {
18 25 /// @todo For the moment, the other data of the variable is initialized with default values
19 26 auto variable
20 27 = std::make_unique<Variable>(name, QStringLiteral("unit"), QStringLiteral("mission"));
21 28 impl->m_Variables.push_back(std::move(variable));
22 29
23 30 return impl->m_Variables.back().get();
24 31 }
32
33 int VariableModel::columnCount(const QModelIndex &parent) const
34 {
35 Q_UNUSED(parent);
36
37 return NB_COLUMNS;
38 }
39
40 int VariableModel::rowCount(const QModelIndex &parent) const
41 {
42 Q_UNUSED(parent);
43
44 return impl->m_Variables.size();
45 }
46
47 QVariant VariableModel::data(const QModelIndex &index, int role) const
48 {
49 return QVariant{};
50 }
51
52 QVariant VariableModel::headerData(int section, Qt::Orientation orientation, int role) const
53 {
54
55 return QVariant{};
56 }
General Comments 0
You need to be logged in to leave comments. Login now