##// END OF EJS Templates
Implements headerData() method
Alexandre Leroux -
r141:1e5ae025cbab
parent child
Show More
@@ -1,56 +1,80
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 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 13 const auto NB_COLUMNS = 3;
10 14
11 15 } // namespace
12 16
13 17 struct VariableModel::VariableModelPrivate {
14 18 /// Variables created in SciQlop
15 19 std::vector<std::unique_ptr<Variable> > m_Variables;
16 20 };
17 21
18 22 VariableModel::VariableModel(QObject *parent)
19 23 : QAbstractTableModel{parent}, impl{spimpl::make_unique_impl<VariableModelPrivate>()}
20 24 {
21 25 }
22 26
23 27 Variable *VariableModel::createVariable(const QString &name) noexcept
24 28 {
25 29 /// @todo For the moment, the other data of the variable is initialized with default values
26 30 auto variable
27 31 = std::make_unique<Variable>(name, QStringLiteral("unit"), QStringLiteral("mission"));
28 32 impl->m_Variables.push_back(std::move(variable));
29 33
30 34 return impl->m_Variables.back().get();
31 35 }
32 36
33 37 int VariableModel::columnCount(const QModelIndex &parent) const
34 38 {
35 39 Q_UNUSED(parent);
36 40
37 41 return NB_COLUMNS;
38 42 }
39 43
40 44 int VariableModel::rowCount(const QModelIndex &parent) const
41 45 {
42 46 Q_UNUSED(parent);
43 47
44 48 return impl->m_Variables.size();
45 49 }
46 50
47 51 QVariant VariableModel::data(const QModelIndex &index, int role) const
48 52 {
49 53 return QVariant{};
50 54 }
51 55
52 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 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