diff --git a/canframemodel.cpp b/canframemodel.cpp index e82238f..4221e4f 100644 --- a/canframemodel.cpp +++ b/canframemodel.cpp @@ -134,25 +134,33 @@ void CANFrameModel::setTimeFormat(QString format) endResetModel(); } +/* + * Scan all frames for the smallest timestamp and offset all timestamps so that smallest one is at 0 +*/ void CANFrameModel::normalizeTiming() { mutex.lock(); if (frames.count() == 0) return; timeOffset = frames[0].timestamp; + + //find the absolute lowest timestamp in the whole time. Needed because maybe timestamp was reset in the middle. for (int j = 0; j < frames.count(); j++) { if (frames[j].timestamp < timeOffset) timeOffset = frames[j].timestamp; } + for (int i = 0; i < frames.count(); i++) { frames[i].timestamp -= timeOffset; } + this->beginResetModel(); for (int i = 0; i < filteredFrames.count(); i++) { filteredFrames[i].timestamp -= timeOffset; } this->endResetModel(); + mutex.unlock(); } @@ -228,6 +236,7 @@ QVariant CANFrameModel::data(const QModelIndex &index, int role) const QString tempString; CANFrame thisFrame; static bool rowFlip = false; + QVariant ts; if (!index.isValid()) return QVariant(); @@ -274,7 +283,11 @@ QVariant CANFrameModel::data(const QModelIndex &index, int role) const switch (Column(index.column())) { case Column::TimeStamp: - return Utility::formatTimestamp(thisFrame.timestamp); + //Reformatting the output a bit with custom code + ts = Utility::formatTimestamp(thisFrame.timestamp); + if (ts.type() == QVariant::Double) return QString::number(ts.toDouble(), 'f', 5); //never scientific notation, 5 decimal places + if (ts.type() == QVariant::LongLong) return QString::number(ts.toLongLong()); //never scientific notion, all digits shown + if (ts.type() == QVariant::DateTime) return ts.toDateTime().toString(timeFormat); //custom set format for dates and times case Column::FrameId: return Utility::formatCANID(thisFrame.ID, thisFrame.extended); case Column::Extended: diff --git a/frameviewdelegate.cpp b/frameviewdelegate.cpp new file mode 100644 index 0000000..e6c87b2 --- /dev/null +++ b/frameviewdelegate.cpp @@ -0,0 +1,6 @@ +#include "frameviewdelegate.h" + +FrameViewDelegate::FrameViewDelegate() +{ + +} diff --git a/frameviewdelegate.h b/frameviewdelegate.h new file mode 100644 index 0000000..0075264 --- /dev/null +++ b/frameviewdelegate.h @@ -0,0 +1,11 @@ +#ifndef FRAMEVIEWDELEGATE_H +#define FRAMEVIEWDELEGATE_H + + +class FrameViewDelegate +{ +public: + FrameViewDelegate(); +}; + +#endif // FRAMEVIEWDELEGATE_H \ No newline at end of file