-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy patheventmodel.cpp
198 lines (173 loc) · 6.17 KB
/
eventmodel.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
#include "eventmodel.h"
#include <string.h>
#include <QString>
#include <QDateTime>
#define EVENT_COLUMNS_COUNT 2
static const QString header_names[EVENT_COLUMNS_COUNT] = {
QObject::tr("Параметр"),
QObject::tr("Значение")
};
#define EVENT_COL_PARAM 0
#define EVENT_COL_VALUE 1
#define EVENT_ROW_ID 0
#define EVENT_ROW_TYPE 1
#define EVENT_ROW_STATE 2
#define EVENT_ROW_DIRECTION 3
#define EVENT_ROW_INIT_STATE 4
#define EVENT_ROW_CALIBR_STATE 5
#define EVENT_ROW_STARTING_STATE 6
#define EVENT_ROW_STOPPING_STATE 7
#define EVENT_ROW_ERR_STOPPING_STATE 8
#define EVENT_ROW_REFERENCE 9
#define EVENT_ROW_FLAGS 10
#define EVENT_ROW_WARNINGS 11
#define EVENT_ROW_ERRORS 12
#define EVENT_ROW_POWER_WARNINGS 13
#define EVENT_ROW_POWER_ERRORS 14
#define EVENT_ROW_PHASE_ERRORS 15
#ifdef USE_ZERO_SENSORS
#define EVENT_ROW_PHASE_A_TIME 16
#define EVENT_ROW_PHASE_B_TIME 17
#define EVENT_ROW_PHASE_C_TIME 18
#else
#define EVENT_ROW_PHASE_A_ANGLE 16
#define EVENT_ROW_PHASE_B_ANGLE 17
#define EVENT_ROW_PHASE_C_ANGLE 18
#endif //USE_ZERO_SENSORS
#define EVENT_ROW_TIME 19
#define EVENT_ROWS_COUNT 20
static const QString rows_names[EVENT_ROWS_COUNT] = {
QObject::tr("Идентификатор"),
QObject::tr("Тип"),
QObject::tr("Состояние"),
QObject::tr("Направление"),
QObject::tr("Сост. инициализ."),
QObject::tr("Сост. калибровки"),
QObject::tr("Сост. запуска"),
QObject::tr("Сост. останова"),
QObject::tr("Сост. ош. останова"),
QObject::tr("Задание"),
QObject::tr("Флаги"),
QObject::tr("Предупреждения"),
QObject::tr("Ошибки"),
QObject::tr("Предупреждения пит."),
QObject::tr("Ошибки пит."),
QObject::tr("Ошибки фаз"),
#ifdef USE_ZERO_SENSORS
QObject::tr("Время фазы A"),
QObject::tr("Время фазы B"),
QObject::tr("Время фазы C"),
#else
QObject::tr("Угол фазы A"),
QObject::tr("Угол фазы B"),
QObject::tr("Угол фазы C"),
#endif //USE_ZERO_SENSORS
QObject::tr("Время"),
};
EventModel::EventModel(QObject *parent)
:QAbstractItemModel(parent)
{
cur_event = nullptr;
}
EventModel::~EventModel()
{
delete cur_event;
}
QVariant EventModel::data(const QModelIndex &index, int role) const
{
if(role != Qt::DisplayRole) return QVariant();
if(!index.isValid()) return QVariant();
if(index.column() >= EVENT_COLUMNS_COUNT) return QVariant();
if(index.row() >= EVENT_ROWS_COUNT) return QVariant();
if(index.column() == EVENT_COL_PARAM) return rows_names[index.row()];
if(cur_event == nullptr || !cur_event->isValid()) return QVariant();
switch(index.row()){
case EVENT_ROW_ID:
return QString("%1").arg(cur_event->id(), 0, 10);
case EVENT_ROW_TYPE:
return QString("%1").arg(cur_event->type(), 0, 10);
case EVENT_ROW_STATE:
return QString("%1").arg(cur_event->state(), 0, 10);
case EVENT_ROW_DIRECTION:
return QString("%1").arg(cur_event->direction(), 0, 10);
case EVENT_ROW_INIT_STATE:
return QString("%1").arg(cur_event->initState(), 0, 10);
case EVENT_ROW_CALIBR_STATE:
return QString("%1").arg(cur_event->calibrationState(), 0, 10);
case EVENT_ROW_STARTING_STATE:
return QString("%1").arg(cur_event->startingState(), 0, 10);
case EVENT_ROW_STOPPING_STATE:
return QString("%1").arg(cur_event->stoppingState(), 0, 10);
case EVENT_ROW_ERR_STOPPING_STATE:
return QString("%1").arg(cur_event->errStoppingState(), 0, 10);
case EVENT_ROW_REFERENCE:
return QString("%1").arg(cur_event->reference(), 0, 10);
case EVENT_ROW_FLAGS:
return QString("0x%1").arg(cur_event->flags(), 0, 16);
case EVENT_ROW_WARNINGS:
return QString("0x%1").arg(cur_event->warnings(), 0, 16);
case EVENT_ROW_ERRORS:
return QString("0x%1").arg(cur_event->errors(), 0, 16);
case EVENT_ROW_POWER_WARNINGS:
return QString("0x%1").arg(cur_event->powerWarnings(), 0, 16);
case EVENT_ROW_POWER_ERRORS:
return QString("0x%1").arg(cur_event->powerErrors(), 0, 16);
case EVENT_ROW_PHASE_ERRORS:
return QString("0x%1").arg(cur_event->phaseErrors(), 0, 16);
#ifdef USE_ZERO_SENSORS
case EVENT_ROW_PHASE_A_TIME:
return QString("%1").arg(cur_event->phaseTimeA(), 0, 10);
case EVENT_ROW_PHASE_B_TIME:
return QString("%1").arg(cur_event->phaseTimeB(), 0, 10);
case EVENT_ROW_PHASE_C_TIME:
return QString("%1").arg(cur_event->phaseTimeC(), 0, 10);
#else
case EVENT_ROW_PHASE_A_ANGLE:
return QString("%1").arg(cur_event->phaseAngleA(), 0, 10);
case EVENT_ROW_PHASE_B_ANGLE:
return QString("%1").arg(cur_event->phaseAngleB(), 0, 10);
case EVENT_ROW_PHASE_C_ANGLE:
return QString("%1").arg(cur_event->phaseAngleC(), 0, 10);
#endif //USE_ZERO_SENSORS
case EVENT_ROW_TIME:
return QDateTime::fromTime_t(cur_event->time(), Qt::UTC, 0).toString("hh:mm:ss dd.MM.yyyy");
}
return QVariant();
}
Qt::ItemFlags EventModel::flags(const QModelIndex &index) const
{
if(!index.isValid()) return 0;
return QAbstractItemModel::flags(index);
}
QVariant EventModel::headerData(int section, Qt::Orientation orientation, int role) const
{
if(orientation != Qt::Horizontal) return QVariant();
if(role != Qt::DisplayRole) return QVariant();
if(section >= EVENT_COLUMNS_COUNT) return QVariant();
return header_names[section];
}
QModelIndex EventModel::index(int row, int column, const QModelIndex &parent) const
{
if(!hasIndex(row, column, parent)) return QModelIndex();
return createIndex(row, column);
}
QModelIndex EventModel::parent(const QModelIndex &/*index*/) const
{
return QModelIndex();
}
int EventModel::rowCount(const QModelIndex &parent) const
{
if(parent.isValid()) return 0;
return EVENT_ROWS_COUNT;
}
int EventModel::columnCount(const QModelIndex &/*parent*/) const
{
return EVENT_COLUMNS_COUNT;
}
void EventModel::setEvent(const DriveEvent *event)
{
emit beginResetModel();
delete cur_event;
cur_event = new DriveEvent(*event);
emit endResetModel();
}