-
Notifications
You must be signed in to change notification settings - Fork 19
/
Copy pathUwxErrorCode.cpp
312 lines (284 loc) · 9.87 KB
/
UwxErrorCode.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
304
305
306
307
308
309
310
311
312
/******************************************************************************
** Copyright (C) 2016-2023 Laird Connectivity
**
** Project: UwTerminalX
**
** Module: UwxErrorCode.cpp
**
** Notes:
**
** License: This program is free software: you can redistribute it and/or
** modify it under the terms of the GNU General Public License as
** published by the Free Software Foundation, version 3.
**
** This program is distributed in the hope that it will be useful,
** but WITHOUT ANY WARRANTY; without even the implied warranty of
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
** GNU General Public License for more details.
**
** You should have received a copy of the GNU General Public License
** along with this program. If not, see http://www.gnu.org/licenses/
**
** SPDX-License-Identifier: GPL-3.0
**
*******************************************************************************/
/******************************************************************************/
// Include Files
/******************************************************************************/
#include "UwxErrorCode.h"
#include "ui_UwxErrorCode.h"
/******************************************************************************/
// Local Functions or Private Members
/******************************************************************************/
UwxErrorCode::UwxErrorCode(QWidget *parent) : QDialog(parent), ui(new Ui::UwxErrorCode)
{
//Setup UI
ui->setupUi(this);
//Set complete object to null
mcmpErrors = 0;
//Setup fonts
QFont fntTmpFnt = QFontDatabase::systemFont(QFontDatabase::FixedFont);
ui->list_Search->setFont(fntTmpFnt);
ui->list_Codes->setFont(fntTmpFnt);
//Create status bar
msbStatusBar = new QStatusBar;
ui->StatusBarLayout->addWidget(msbStatusBar);
msbStatusBar->showMessage("");
//Remove question mark button from window title
this->setWindowFlags((Qt::Window | Qt::WindowCloseButtonHint));
}
//=============================================================================
//=============================================================================
UwxErrorCode::~UwxErrorCode()
{
//Clear up
if (mcmpErrors != 0)
{
//Delete completer object
delete mcmpErrors;
mcmpErrors = 0;
}
delete msbStatusBar;
delete ui;
}
//=============================================================================
//=============================================================================
void
UwxErrorCode::on_combo_Code_currentTextChanged(
const QString &strComboText
)
{
//Error code entered into combo box
unsigned int uiErrCode = QString("0x").append(strComboText).toUInt(NULL, 16);
QString strErrorCode = QString::number(uiErrCode);
if (mpErrorMessages->value(strErrorCode).isValid())
{
//Valid error
ui->edit_Result->setText(mpErrorMessages->value(strErrorCode).toString());
}
else
{
//Invalid error
ui->edit_Result->setText("Invalid.");
}
ui->edit_Result->setCursorPosition(0);
}
//=============================================================================
//=============================================================================
void
UwxErrorCode::on_list_Codes_currentRowChanged(
int iListRow
)
{
//Selection in full error list object changed
if (iListRow >= 0)
{
//Item selected
ui->edit_Result->setText(ui->list_Codes->item(iListRow)->text());
}
else
{
//No item selected
ui->edit_Result->setText("Invalid.");
}
ui->edit_Result->setCursorPosition(0);
}
//=============================================================================
//=============================================================================
void
UwxErrorCode::on_edit_Search_returnPressed(
)
{
//Search for error
QString SearchStr = ui->edit_Search->text().toLower();
ui->list_Search->clear();
foreach (const QString &strKey, mpErrorMessages->childKeys())
{
if (mpErrorMessages->value(strKey).toString().toLower().indexOf(SearchStr) != -1)
{
//Potential match. One short at a time, convert the data to hex
quint16 ThisByte = strKey.toUInt();
QString strThisHex;
strThisHex.setNum(ThisByte, 16);
strThisHex = strThisHex.toUpper();
while (strThisHex.length() < 4)
{
//Expand to 4 characters
strThisHex.prepend('0');
}
//Add error to list
ui->list_Search->addItem(QString(strThisHex).append(": ").append(mpErrorMessages->value(strKey).toString()));
}
}
//Sort items in ascending order
ui->list_Search->sortItems(Qt::AscendingOrder);
}
//=============================================================================
//=============================================================================
void
UwxErrorCode::on_btn_Search_clicked(
)
{
//Search button pressed
on_edit_Search_returnPressed();
}
//=============================================================================
//=============================================================================
void
UwxErrorCode::SetErrorObject(
QSettings *pErrorMessages
)
{
//Update the error code objects
if (mcmpErrors != 0)
{
//Remove old object
ui->combo_Code->setCompleter(0);
delete mcmpErrors;
mcmpErrors = 0;
}
if (pErrorMessages != 0 && !pErrorMessages->value("Version").isNull())
{
//Mark errors as loaded
mpErrorMessages = pErrorMessages;
//Show error code file version
msbStatusBar->showMessage(QString("Error code file version ").append(mpErrorMessages->value("Version", "Unknown").toString()));
//String list to store error code values in
QStringList slErrorCodes;
//Iterate through all values
foreach (const QString &strKey, mpErrorMessages->childKeys())
{
//Check if this key is the version string
if (strKey[0] != 'V')
{
//One short at a time, convert the data to hex
quint16 ThisByte = strKey.toUInt();
QString strThisHex;
strThisHex.setNum(ThisByte, 16);
strThisHex = strThisHex.toUpper();
while (strThisHex.length() < 4)
{
//Expand to 4 characters
strThisHex.prepend('0');
}
//Append error code to list of error codes
slErrorCodes << strThisHex;
//Add error code to listview
ui->list_Codes->addItem(QString(strThisHex).append(": ").append(mpErrorMessages->value(strKey).toString()));
}
}
//Sort all items in ascending order
ui->list_Codes->sortItems(Qt::AscendingOrder);
//Create a new completer and apply it to the combo box
mcmpErrors = new QCompleter(slErrorCodes, this);
mcmpErrors->setCaseSensitivity(Qt::CaseInsensitive);
ui->combo_Code->setCompleter(mcmpErrors);
//Enable all options
SetObjectStatus(true);
}
else
{
//Error code file not loaded
msbStatusBar->showMessage(QString("Error code file not present, download from the update tab."));
ui->list_Codes->clear();
ui->list_Search->clear();
ui->edit_Result->clear();
SetObjectStatus(false);
}
}
//=============================================================================
//=============================================================================
void
UwxErrorCode::on_list_Search_currentRowChanged(
int iSearchRow
)
{
//Search list object row selection changed
if (iSearchRow >= 0)
{
//Item selected
ui->edit_Result->setText(ui->list_Search->item(iSearchRow)->text());
}
else
{
//No item selected
ui->edit_Result->setText("Invalid.");
}
ui->edit_Result->setCursorPosition(0);
}
//=============================================================================
//=============================================================================
void
UwxErrorCode::SetObjectStatus(
bool bStatus
)
{
//Enable or disable the form items
ui->btn_Search->setEnabled(bStatus);
ui->combo_Code->setEnabled(bStatus);
ui->edit_Search->setEnabled(bStatus);
ui->list_Codes->setEnabled(bStatus);
ui->list_Search->setEnabled(bStatus);
ui->selector_Tab->setEnabled(bStatus);
ui->btn_Copy->setEnabled(bStatus);
}
//=============================================================================
//=============================================================================
void
UwxErrorCode::on_selector_Tab_currentChanged(
int iTabIndex
)
{
//Tab has been changed
if (iTabIndex == ErrorCodeLookupTab)
{
//Get error code from 4-character value
on_combo_Code_currentTextChanged(ui->combo_Code->currentText());
}
else if (iTabIndex == ErrorCodeListTab)
{
//Get error code from full list
on_list_Codes_currentRowChanged(ui->list_Codes->currentRow());
}
else if (iTabIndex == ErrorCodeSearchTab)
{
//Get error code from search
on_list_Search_currentRowChanged(ui->list_Search->currentRow());
}
}
//=============================================================================
//=============================================================================
void
UwxErrorCode::on_btn_Copy_clicked(
)
{
//Copy button clicked
if (!ui->edit_Result->text().isEmpty())
{
//Copy to clipboard
QApplication::clipboard()->setText(ui->edit_Result->text());
}
}
/******************************************************************************/
// END OF FILE
/******************************************************************************/