forked from miikasyvanen/FastECU
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathprotocol_select.cpp
303 lines (263 loc) · 12.9 KB
/
protocol_select.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
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
#include "protocol_select.h"
#include "ui_protocol_select.h"
ProtocolSelect::ProtocolSelect(FileActions::ConfigValuesStructure *configValues, QWidget *parent)
: QDialog(parent),
ui(new Ui::ProtocolSelectWindow)
{
ui->setupUi(this);
this->setParent(parent);
QScreen *screen = QGuiApplication::primaryScreen();
QRect screenGeometry = screen->geometry();
this->move(screenGeometry.center() - this->rect().center());
//this->show();
this->configValues = configValues;
ui->select_button->setEnabled(false);
ui->car_make_tree_widget->setHeaderLabel("Manufacturer");
ui->car_model_tree_widget->setHeaderLabel("Model");
QStringList car_version_tree_widget_headers = {"Version","Type","kW","HP","Fuel","Year","ECU","Mode","CHK","RD","WR","Family"};
ui->car_version_tree_widget->setHeaderLabels(car_version_tree_widget_headers);
ui->car_version_tree_widget->setColumnWidth(0, 175);
ui->car_version_tree_widget->setColumnWidth(1, 125);
ui->car_version_tree_widget->setColumnWidth(2, 50);
ui->car_version_tree_widget->setColumnWidth(3, 50);
ui->car_version_tree_widget->setColumnWidth(4, 50);
ui->car_version_tree_widget->setColumnWidth(5, 50);
ui->car_version_tree_widget->setColumnWidth(6, 175);
ui->car_version_tree_widget->setColumnWidth(7, 50);
ui->car_version_tree_widget->setColumnWidth(8, 40);
ui->car_version_tree_widget->setColumnWidth(9, 40);
ui->car_version_tree_widget->setColumnWidth(10, 40);
ui->car_version_tree_widget->setColumnWidth(11, 125);
int width = 0;
for (int i = 0; i < ui->car_version_tree_widget->columnCount(); i++)
width += ui->car_version_tree_widget->columnWidth(i);
//qDebug() << "Full width =" << width;
ui->car_version_tree_widget->setFixedWidth(width);
int height = width / 4 * 2.5 + 18;
this->setFixedHeight(height);
font = ui->car_make_tree_widget->font();
font.setPointSize(header_font_size);
font.setBold(header_font_bold);
font.setFamily(header_font_family);
ui->car_make_tree_widget->setFont(font);
ui->car_model_tree_widget->setFont(font);
ui->car_version_tree_widget->setFont(font);
int index = configValues->flash_protocol_selected_id.toInt();
configValues->flash_protocol_selected_id = configValues->flash_protocol_selected_id;
configValues->flash_protocol_selected_mcu = configValues->flash_protocol_mcu.at(index);
configValues->flash_protocol_selected_make = configValues->flash_protocol_make.at(index);
configValues->flash_protocol_selected_model = configValues->flash_protocol_model.at(index);
configValues->flash_protocol_selected_version = configValues->flash_protocol_version.at(index);
configValues->flash_protocol_selected_family = configValues->flash_protocol_family.at(index);
configValues->flash_protocol_selected_description = configValues->flash_protocol_description.at(index);
QStringList car_makes;
QStringList car_makes_sorted;
for (int i = 0; i < configValues->flash_protocol_id.length(); i++)
{
if (!car_makes.contains(configValues->flash_protocol_make.at(i)))
{
//qDebug() << "Make found:" << configValues->flash_protocol_make.at(i);
car_makes.append(configValues->flash_protocol_make.at(i));
}
}
car_makes_sorted = car_makes;
sort(car_makes_sorted.begin(), car_makes_sorted.end(), less<QString>());
for (int i = 0; i < car_makes_sorted.length(); i++)
{
QTreeWidgetItem *item = new QTreeWidgetItem();
font = item->font(0);
font.setPointSize(font_size);
font.setBold(font_bold);
font.setFamily(font_family);
item->setFont(0, font);
item->setText(0, car_makes_sorted.at(i));
item->setFirstColumnSpanned(true);
ui->car_make_tree_widget->addTopLevelItem(item);
if (car_makes_sorted.at(i) == configValues->flash_protocol_selected_make)
ui->car_make_tree_widget->setCurrentItem(item);
else if (i == 0)
ui->car_make_tree_widget->setCurrentItem(item);
}
connect(ui->car_make_tree_widget, SIGNAL(itemSelectionChanged()), this, SLOT(car_make_treewidget_item_selected()));
connect(ui->car_model_tree_widget, SIGNAL(itemSelectionChanged()), this, SLOT(car_model_treewidget_item_selected()));
connect(ui->car_version_tree_widget, SIGNAL(itemSelectionChanged()), this, SLOT(car_version_treewidget_item_selected()));
connect(ui->cancel_button, SIGNAL(clicked(bool)), this, SLOT(close()));
connect(ui->select_button, SIGNAL(clicked(bool)), this, SLOT(car_model_selected()));
//connect(ui->select_button, SIGNAL(clicked()), this, SLOT(accept()));
//connect(ui->cancel_button, SIGNAL(clicked()), this, SLOT(reject()));
const QModelIndex make_index = ui->car_make_tree_widget->selectionModel()->currentIndex();
ui->car_make_tree_widget->setCurrentIndex(make_index);
emit ui->car_make_tree_widget->itemSelectionChanged();
/*
const QModelIndex model_index = ui->car_model_tree_widget->selectionModel()->currentIndex();
ui->car_model_tree_widget->setCurrentIndex(model_index);
emit ui->car_model_tree_widget->itemSelectionChanged();
const QModelIndex version_index = ui->car_version_tree_widget->selectionModel()->currentIndex();
ui->car_version_tree_widget->setCurrentIndex(version_index);
emit ui->car_version_tree_widget->itemSelectionChanged();
*/
}
ProtocolSelect::~ProtocolSelect()
{
reject();
}
void ProtocolSelect::car_model_selected()
{
configValues->flash_protocol_selected_id = flash_protocol_id;
configValues->flash_protocol_selected_make = flash_protocol_make;
configValues->flash_protocol_selected_model = flash_protocol_model;
configValues->flash_protocol_selected_version = flash_protocol_version;
configValues->flash_protocol_selected_family = flash_protocol_family;
configValues->flash_protocol_selected_description = flash_protocol_description;
configValues->flash_protocol_selected_log_protocol = configValues->flash_protocol_log_protocol.at(configValues->flash_protocol_selected_id.toInt());
configValues->flash_protocol_selected_mcu = configValues->flash_protocol_mcu.at(configValues->flash_protocol_selected_id.toInt());
qDebug() << "Selected MCU:" << configValues->flash_protocol_selected_mcu;
accept();
close();
}
void ProtocolSelect::car_make_treewidget_item_selected()
{
QTreeWidgetItem *item = ui->car_make_tree_widget->selectedItems().at(0);
if (item)//ui->car_make_tree_widget->topLevelItemCount())
{
QTreeWidgetItem *item = ui->car_make_tree_widget->selectedItems().at(0);
QString selected_text = item->text(0);
//qDebug() << "Check models for manufacturer:" << selected_text;
QString car_make = selected_text;
flash_protocol_id.clear();
flash_protocol_make = car_make;
flash_protocol_model.clear();
flash_protocol_version.clear();
QStringList car_models;
QStringList car_models_sorted;
ui->car_model_tree_widget->clear();
for (int i = 0; i < configValues->flash_protocol_id.length(); i++)
{
if (!car_models.contains(configValues->flash_protocol_model.at(i)) && configValues->flash_protocol_make.at(i) == car_make && configValues->flash_protocol_model.at(i) != "")
{
//qDebug() << "Model found:" << configValues->flash_protocol_model.at(i);
car_models.append(configValues->flash_protocol_model.at(i));
}
}
car_models_sorted = car_models;
sort(car_models_sorted.begin(), car_models_sorted.end(), less<QString>());
for (int i = 0; i < car_models_sorted.length(); i++)
{
QTreeWidgetItem *item = new QTreeWidgetItem();
item->setText(0, car_models_sorted.at(i));
item->setFirstColumnSpanned(true);
ui->car_model_tree_widget->addTopLevelItem(item);
if (car_models_sorted.at(i) == configValues->flash_protocol_selected_model)
ui->car_model_tree_widget->setCurrentItem(item);
else if (i == 0)
ui->car_model_tree_widget->setCurrentItem(item);
}
}
}
void ProtocolSelect::car_model_treewidget_item_selected()
{
QTreeWidgetItem *item = ui->car_model_tree_widget->selectedItems().at(0);
if (item)//ui->car_model_tree_widget->topLevelItemCount())
{
QTreeWidgetItem *item = ui->car_model_tree_widget->selectedItems().at(0);
QString selected_text = item->text(0);
//qDebug() << "Check versions for model:" << selected_text;
QString car_model = selected_text;
flash_protocol_id.clear();
flash_protocol_model = car_model;
flash_protocol_version.clear();
QStringList id;
QStringList version;
QStringList type;
QStringList kw;
QStringList hp;
QStringList fuel;
QStringList year;
QStringList ecu;
QStringList mcu;
QStringList mode;
QStringList checksum;
QStringList read;
QStringList write;
QStringList family;
QStringList description;
ui->car_version_tree_widget->clear();
for (int i = 0; i < configValues->flash_protocol_id.length(); i++)
{
if (configValues->flash_protocol_model.at(i) == car_model && configValues->flash_protocol_make.at(i) == flash_protocol_make)
{
//qDebug() << "Model found:" << configValues->flash_protocol_model.at(i);
id.append(configValues->flash_protocol_id.at(i));
version.append(configValues->flash_protocol_version.at(i));
type.append(configValues->flash_protocol_type.at(i));
kw.append(configValues->flash_protocol_kw.at(i));
hp.append(configValues->flash_protocol_hp.at(i));
fuel.append(configValues->flash_protocol_fuel.at(i));
year.append(configValues->flash_protocol_year.at(i));
ecu.append(configValues->flash_protocol_ecu.at(i));
mcu.append(configValues->flash_protocol_mcu.at(i));
mode.append(configValues->flash_protocol_mode.at(i));
checksum.append(configValues->flash_protocol_checksum.at(i));
read.append(configValues->flash_protocol_read.at(i));
write.append(configValues->flash_protocol_write.at(i));
family.append(configValues->flash_protocol_family.at(i));
description.append(configValues->flash_protocol_description.at(i));
}
}
for (int i = 0; i < version.length(); i++)
{
QTreeWidgetItem *item = new QTreeWidgetItem();
item->setText(0, version.at(i));
item->setText(1, type.at(i));
item->setText(2, kw.at(i));
item->setText(3, hp.at(i));
item->setText(4, fuel.at(i));
item->setText(5, year.at(i));
item->setText(6, ecu.at(i));
item->setText(7, mode.at(i));
if (checksum.at(i) == "yes")
item->setCheckState(8, Qt::Checked);
else if (checksum.at(i) == "no")
item->setCheckState(8, Qt::Unchecked);
else
item->setText(8, "n/a");
if (read.at(i) == "yes")
item->setCheckState(9, Qt::Checked);
else
item->setCheckState(9, Qt::Unchecked);
if (write.at(i) == "yes")
item->setCheckState(10, Qt::Checked);
else
item->setCheckState(10, Qt::Unchecked);
item->setText(11, family.at(i));
item->setToolTip(11, family.at(i));
item->setText(12, id.at(i));
item->setText(13, description.at(i));
//topLevelCarVersionTreeItem->setFirstColumnSpanned(true);
ui->car_version_tree_widget->addTopLevelItem(item);
if (id.at(i) == configValues->flash_protocol_selected_id)
ui->car_version_tree_widget->setCurrentItem(item);
else if (i == 0)
ui->car_version_tree_widget->setCurrentItem(item);
}
}
}
void ProtocolSelect::car_version_treewidget_item_selected()
{
QTreeWidgetItem *item = ui->car_version_tree_widget->selectedItems().at(0);
if (item)//ui->car_version_tree_widget->topLevelItemCount())
{
QTreeWidgetItem *item = ui->car_version_tree_widget->selectedItems().at(0);
QString selected_text = item->text(0);
//qDebug() << "Selected version for model" << flash_protocol_model << "is" << selected_text;
ui->select_button->setEnabled(true);
QString car_version = selected_text;
flash_protocol_version.clear();
flash_protocol_version = car_version;
flash_protocol_family = item->text(11);
flash_protocol_id = item->text(12);
flash_protocol_description = item->text(13);
//flash_protocol_id = selected_text;//car_version_treewidget_item->text(11);
//qDebug() << "Protocol ID:" << flash_protocol_id;
}
}