##// END OF EJS Templates
Implements headerData() method
Alexandre Leroux -
r141:1e5ae025cbab
parent child
Show More
@@ -1,56 +1,80
1 #include <Variable/VariableModel.h>
1 #include <Variable/VariableModel.h>
2
2
3 #include <Variable/Variable.h>
3 #include <Variable/Variable.h>
4
4
5 Q_LOGGING_CATEGORY(LOG_VariableModel, "VariableModel")
5 Q_LOGGING_CATEGORY(LOG_VariableModel, "VariableModel")
6
6
7 namespace {
7 namespace {
8
8
9 // Column indexes
10 const auto NAME_COLUMN = 0;
11 const auto UNIT_COLUMN = 1;
12 const auto MISSION_COLUMN = 2;
9 const auto NB_COLUMNS = 3;
13 const auto NB_COLUMNS = 3;
10
14
11 } // namespace
15 } // namespace
12
16
13 struct VariableModel::VariableModelPrivate {
17 struct VariableModel::VariableModelPrivate {
14 /// Variables created in SciQlop
18 /// Variables created in SciQlop
15 std::vector<std::unique_ptr<Variable> > m_Variables;
19 std::vector<std::unique_ptr<Variable> > m_Variables;
16 };
20 };
17
21
18 VariableModel::VariableModel(QObject *parent)
22 VariableModel::VariableModel(QObject *parent)
19 : QAbstractTableModel{parent}, impl{spimpl::make_unique_impl<VariableModelPrivate>()}
23 : QAbstractTableModel{parent}, impl{spimpl::make_unique_impl<VariableModelPrivate>()}
20 {
24 {
21 }
25 }
22
26
23 Variable *VariableModel::createVariable(const QString &name) noexcept
27 Variable *VariableModel::createVariable(const QString &name) noexcept
24 {
28 {
25 /// @todo For the moment, the other data of the variable is initialized with default values
29 /// @todo For the moment, the other data of the variable is initialized with default values
26 auto variable
30 auto variable
27 = std::make_unique<Variable>(name, QStringLiteral("unit"), QStringLiteral("mission"));
31 = std::make_unique<Variable>(name, QStringLiteral("unit"), QStringLiteral("mission"));
28 impl->m_Variables.push_back(std::move(variable));
32 impl->m_Variables.push_back(std::move(variable));
29
33
30 return impl->m_Variables.back().get();
34 return impl->m_Variables.back().get();
31 }
35 }
32
36
33 int VariableModel::columnCount(const QModelIndex &parent) const
37 int VariableModel::columnCount(const QModelIndex &parent) const
34 {
38 {
35 Q_UNUSED(parent);
39 Q_UNUSED(parent);
36
40
37 return NB_COLUMNS;
41 return NB_COLUMNS;
38 }
42 }
39
43
40 int VariableModel::rowCount(const QModelIndex &parent) const
44 int VariableModel::rowCount(const QModelIndex &parent) const
41 {
45 {
42 Q_UNUSED(parent);
46 Q_UNUSED(parent);
43
47
44 return impl->m_Variables.size();
48 return impl->m_Variables.size();
45 }
49 }
46
50
47 QVariant VariableModel::data(const QModelIndex &index, int role) const
51 QVariant VariableModel::data(const QModelIndex &index, int role) const
48 {
52 {
49 return QVariant{};
53 return QVariant{};
50 }
54 }
51
55
52 QVariant VariableModel::headerData(int section, Qt::Orientation orientation, int role) const
56 QVariant VariableModel::headerData(int section, Qt::Orientation orientation, int role) const
53 {
57 {
58 if (role != Qt::DisplayRole) {
59 return QVariant{};
60 }
61
62 if (orientation == Qt::Horizontal) {
63 switch (section) {
64 case NAME_COLUMN:
65 return tr("Name");
66 case UNIT_COLUMN:
67 return tr("Unit");
68 case MISSION_COLUMN:
69 return tr("Mission");
70 default:
71 // No action
72 break;
73 }
74
75 qWarning(LOG_VariableModel())
76 << tr("Can't get header data (unknown column %1)").arg(section);
77 }
54
78
55 return QVariant{};
79 return QVariant{};
56 }
80 }
General Comments 4
Under Review
author

Pull request updated. Auto status change to "Under Review"

Changed commits:
  * 1 added
  * 0 removed

Changed files:
  * M core/src/Variable/VariableModel.cpp
Approved
author

Status change > Approved

You need to be logged in to leave comments. Login now