##// END OF EJS Templates
Removes useless const ref
Alexandre Leroux -
r157:863dff09bf68
parent child
Show More
@@ -1,117 +1,115
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 9 // Column indexes
10 10 const auto NAME_COLUMN = 0;
11 11 const auto UNIT_COLUMN = 1;
12 12 const auto MISSION_COLUMN = 2;
13 13 const auto NB_COLUMNS = 3;
14 14
15 15 } // namespace
16 16
17 17 struct VariableModel::VariableModelPrivate {
18 18 /// Variables created in SciQlop
19 19 std::vector<std::unique_ptr<Variable> > m_Variables;
20 20 };
21 21
22 22 VariableModel::VariableModel(QObject *parent)
23 23 : QAbstractTableModel{parent}, impl{spimpl::make_unique_impl<VariableModelPrivate>()}
24 24 {
25 25 }
26 26
27 27 Variable *VariableModel::createVariable(const QString &name) noexcept
28 28 {
29 29 auto insertIndex = rowCount();
30 30 beginInsertRows({}, insertIndex, insertIndex);
31 31
32 32 /// @todo For the moment, the other data of the variable is initialized with default values
33 33 auto variable
34 34 = std::make_unique<Variable>(name, QStringLiteral("unit"), QStringLiteral("mission"));
35 35 impl->m_Variables.push_back(std::move(variable));
36 36
37 37 endInsertRows();
38 38
39 39 return impl->m_Variables.at(insertIndex).get();
40 40 }
41 41
42 42 int VariableModel::columnCount(const QModelIndex &parent) const
43 43 {
44 44 Q_UNUSED(parent);
45 45
46 46 return NB_COLUMNS;
47 47 }
48 48
49 49 int VariableModel::rowCount(const QModelIndex &parent) const
50 50 {
51 51 Q_UNUSED(parent);
52 52
53 53 return impl->m_Variables.size();
54 54 }
55 55
56 56 QVariant VariableModel::data(const QModelIndex &index, int role) const
57 57 {
58 58 if (!index.isValid()) {
59 59 return QVariant{};
60 60 }
61 61
62 62 if (index.row() < 0 || index.row() >= rowCount()) {
63 63 return QVariant{};
64 64 }
65 65
66 66 if (role == Qt::DisplayRole) {
67 const auto &variable = impl->m_Variables.at(index.row());
68
69 if (variable) {
67 if (auto variable = impl->m_Variables.at(index.row()).get()) {
70 68 switch (index.column()) {
71 69 case NAME_COLUMN:
72 70 return variable->m_Name;
73 71 case UNIT_COLUMN:
74 72 return variable->m_Unit;
75 73 case MISSION_COLUMN:
76 74 return variable->m_Mission;
77 75 default:
78 76 // No action
79 77 break;
80 78 }
81 79
82 80 qWarning(LOG_VariableModel())
83 81 << tr("Can't get data (unknown column %1)").arg(index.column());
84 82 }
85 83 else {
86 84 qWarning(LOG_VariableModel()) << tr("Can't get data (no variable)");
87 85 }
88 86 }
89 87
90 88 return QVariant{};
91 89 }
92 90
93 91 QVariant VariableModel::headerData(int section, Qt::Orientation orientation, int role) const
94 92 {
95 93 if (role != Qt::DisplayRole) {
96 94 return QVariant{};
97 95 }
98 96
99 97 if (orientation == Qt::Horizontal) {
100 98 switch (section) {
101 99 case NAME_COLUMN:
102 100 return tr("Name");
103 101 case UNIT_COLUMN:
104 102 return tr("Unit");
105 103 case MISSION_COLUMN:
106 104 return tr("Mission");
107 105 default:
108 106 // No action
109 107 break;
110 108 }
111 109
112 110 qWarning(LOG_VariableModel())
113 111 << tr("Can't get header data (unknown column %1)").arg(section);
114 112 }
115 113
116 114 return QVariant{};
117 115 }
General Comments 0
You need to be logged in to leave comments. Login now