CanFrameModel: Convert switches to enumeration and add documentation

And add or remove default labels to silence Clang compiler warnings.
This commit is contained in:
Andre Hartmann
2017-11-26 18:00:40 +01:00
parent 1b24b1677a
commit f5ccd9df05
+26 -18
View File
@@ -215,6 +215,16 @@ void CANFrameModel::recalcOverwrite()
mutex.unlock(); mutex.unlock();
} }
enum class Column {
TimeStamp = 0, ///< The timestamp when the frame was transmitted or received
FrameId = 1, ///< The frames CAN identifier (Standard: 11 or Extended: 29 bit)
Extended = 2, ///< True if the frames CAN identifier is 29 bit
Direction = 3, ///< Whether the frame was transmitted or received
Bus = 4, ///< The bus where the frame was transmitted or received
Length = 5, ///< The frames payload data length
Data = 6 ///< The frames payload data
};
QVariant CANFrameModel::data(const QModelIndex &index, int role) const QVariant CANFrameModel::data(const QModelIndex &index, int role) const
{ {
int dLen; int dLen;
@@ -257,22 +267,22 @@ QVariant CANFrameModel::data(const QModelIndex &index, int role) const
} }
if (role == Qt::DisplayRole) { if (role == Qt::DisplayRole) {
switch (index.column()) switch (Column(index.column()))
{ {
case 0: //timestamp case Column::TimeStamp:
return Utility::formatTimestamp(thisFrame.timestamp); return Utility::formatTimestamp(thisFrame.timestamp);
case 1: //id case Column::FrameId:
return Utility::formatNumber(thisFrame.ID); return Utility::formatNumber(thisFrame.ID);
case 2: //ext case Column::Extended:
return QString::number(thisFrame.extended); return QString::number(thisFrame.extended);
case 3: //direction case Column::Direction:
if (thisFrame.isReceived) return QString(tr("Rx")); if (thisFrame.isReceived) return QString(tr("Rx"));
return QString(tr("Tx")); return QString(tr("Tx"));
case 4: //bus case Column::Bus:
return QString::number(thisFrame.bus); return QString::number(thisFrame.bus);
case 5: //len case Column::Length:
return QString::number(thisFrame.len); return QString::number(thisFrame.len);
case 6: //data case Column::Data:
dLen = thisFrame.len; dLen = thisFrame.len;
if (dLen < 0) dLen = 0; if (dLen < 0) dLen = 0;
if (dLen > 8) dLen = 8; if (dLen > 8) dLen = 8;
@@ -301,8 +311,6 @@ QVariant CANFrameModel::data(const QModelIndex &index, int role) const
} }
} }
return tempString; return tempString;
default:
return QVariant();
} }
} }
@@ -317,21 +325,21 @@ QVariant CANFrameModel::headerData(int section, Qt::Orientation orientation,
if (orientation == Qt::Horizontal) if (orientation == Qt::Horizontal)
{ {
switch (section) switch (Column(section))
{ {
case 0: case Column::TimeStamp:
return QString(tr("Timestamp")); return QString(tr("Timestamp"));
case 1: case Column::FrameId:
return QString(tr("ID")); return QString(tr("ID"));
case 2: case Column::Extended:
return QString(tr("Ext")); return QString(tr("Ext"));
case 3: case Column::Direction:
return QString(tr("Dir")); return QString(tr("Dir"));
case 4: case Column::Bus:
return QString(tr("Bus")); return QString(tr("Bus"));
case 5: case Column::Length:
return QString(tr("Len")); return QString(tr("Len"));
case 6: case Column::Data:
return QString(tr("Data")); return QString(tr("Data"));
} }
} }