1
1
#include " chip_db_table_model.h"
2
2
#include < limits>
3
3
4
+ #define CHIP_DB_TABLE_MODEL_MIN_CYCLES 1
4
5
#define CHIP_DB_TABLE_MODEL_MAX_CYCLES 4
5
6
6
7
ChipDbTableModel::ChipDbTableModel (ChipDb *chipDb, QObject *parent) :
@@ -22,6 +23,7 @@ int ChipDbTableModel::columnCount(const QModelIndex & /*parent*/) const
22
23
QVariant ChipDbTableModel::data (const QModelIndex &index, int role) const
23
24
{
24
25
int column;
26
+ QString paramStr;
25
27
26
28
if (role != Qt::DisplayRole && role != Qt::EditRole)
27
29
return QVariant ();
@@ -51,17 +53,23 @@ QVariant ChipDbTableModel::data(const QModelIndex &index, int role) const
51
53
case CHIP_PARAM_T_REA:
52
54
case CHIP_PARAM_ROW_CYCLES:
53
55
case CHIP_PARAM_COL_CYCLES:
56
+ case CHIP_PARAM_BB_MARK_OFF:
57
+ return (*chipDb)[index.row ()]->params [column];
54
58
case CHIP_PARAM_READ1_CMD:
55
- case CHIP_PARAM_READ2_CMD:
56
59
case CHIP_PARAM_READ_ID_CMD:
57
60
case CHIP_PARAM_RESET_CMD:
58
61
case CHIP_PARAM_WRITE1_CMD:
59
- case CHIP_PARAM_WRITE2_CMD:
60
62
case CHIP_PARAM_ERASE1_CMD:
61
- case CHIP_PARAM_ERASE2_CMD:
62
63
case CHIP_PARAM_STATUS_CMD:
63
- case CHIP_PARAM_BB_MARK_OFF:
64
- return (*chipDb)[index.row ()]->params [column];
64
+ chipDb->getStringFromParam ((*chipDb)[index.row ()]->params [column],
65
+ paramStr);
66
+ return paramStr;
67
+ case CHIP_PARAM_READ2_CMD:
68
+ case CHIP_PARAM_WRITE2_CMD:
69
+ case CHIP_PARAM_ERASE2_CMD:
70
+ chipDb->getStringFromOptParam ((*chipDb)[index.row ()]->params [column],
71
+ paramStr);
72
+ return paramStr;
65
73
}
66
74
67
75
return QVariant ();
@@ -190,7 +198,6 @@ Qt::ItemFlags ChipDbTableModel::flags (const QModelIndex &index) const
190
198
bool ChipDbTableModel::setData (const QModelIndex &index, const QVariant &value,
191
199
int role)
192
200
{
193
- bool convOk;
194
201
uint32_t paramVal;
195
202
196
203
if (role != Qt::EditRole)
@@ -219,34 +226,40 @@ bool ChipDbTableModel::setData(const QModelIndex &index, const QVariant &value,
219
226
case CHIP_PARAM_T_WC:
220
227
case CHIP_PARAM_T_RC:
221
228
case CHIP_PARAM_T_REA:
222
- paramVal = value. toUInt (&convOk);
223
- if (!convOk )
229
+ case CHIP_PARAM_BB_MARK_OFF:
230
+ if (chipDb-> getParamFromString (value. toString (), paramVal) )
224
231
return false ;
225
232
(*chipDb)[index.row ()]->params [index.column ()] = paramVal;
226
233
return true ;
227
234
case CHIP_PARAM_ROW_CYCLES:
228
235
case CHIP_PARAM_COL_CYCLES:
229
- paramVal = value.toUInt (&convOk);
230
- if (!convOk)
236
+ if (chipDb->getParamFromString (value.toString (), paramVal))
231
237
return false ;
232
- if (paramVal > CHIP_DB_TABLE_MODEL_MAX_CYCLES)
238
+ if (!chipDb->isParamValid (paramVal, CHIP_DB_TABLE_MODEL_MIN_CYCLES,
239
+ CHIP_DB_TABLE_MODEL_MAX_CYCLES))
240
+ {
233
241
return false ;
242
+ }
234
243
(*chipDb)[index.row ()]->params [index.column ()] = paramVal;
235
244
return true ;
236
245
case CHIP_PARAM_READ1_CMD:
237
- case CHIP_PARAM_READ2_CMD:
238
246
case CHIP_PARAM_READ_ID_CMD:
239
247
case CHIP_PARAM_RESET_CMD:
240
248
case CHIP_PARAM_WRITE1_CMD:
241
- case CHIP_PARAM_WRITE2_CMD:
242
249
case CHIP_PARAM_ERASE1_CMD:
243
- case CHIP_PARAM_ERASE2_CMD:
244
250
case CHIP_PARAM_STATUS_CMD:
245
- case CHIP_PARAM_BB_MARK_OFF:
246
- paramVal = value.toUInt (&convOk);
247
- if (!convOk)
251
+ if (chipDb->getParamFromString (value.toString (), paramVal))
252
+ return false ;
253
+ if (!chipDb->isParamValid (paramVal, 0x00 , 0xFF ))
254
+ return false ;
255
+ (*chipDb)[index.row ()]->params [index.column ()] = paramVal;
256
+ return true ;
257
+ case CHIP_PARAM_READ2_CMD:
258
+ case CHIP_PARAM_WRITE2_CMD:
259
+ case CHIP_PARAM_ERASE2_CMD:
260
+ if (chipDb->getOptParamFromString (value.toString (), paramVal))
248
261
return false ;
249
- if (paramVal > std::numeric_limits< uint8_t >:: max ( ))
262
+ if (!chipDb-> isOptParamValid ( paramVal, 0x00 , 0xFF ))
250
263
return false ;
251
264
(*chipDb)[index.row ()]->params [index.column ()] = paramVal;
252
265
return true ;
0 commit comments