settings and render for setUseColorsByCanId

This commit is contained in:
Daniele Baggio
2026-03-18 10:31:22 +01:00
parent ad65cf78a8
commit fb6881eeaa
7 changed files with 124 additions and 18 deletions
+38 -17
View File
@@ -3,6 +3,8 @@
#include <QFile>
#include <QApplication>
#include <QPalette>
#include <QColor>
#include <QBrush>
#include <QDateTime>
#include <QSettings>
#include "utility.h"
@@ -76,6 +78,7 @@ CANFrameModel::CANFrameModel(QObject *parent)
overwriteDups = false;
filtersPersistDuringClear = false;
useHexMode = true;
useColorsByCanId = false;
timeStyle = TS_MICROS;
timeOffset = 0;
needFilterRefresh = false;
@@ -101,6 +104,16 @@ void CANFrameModel::setHexMode(bool mode)
}
}
void CANFrameModel::setUseColorsByCanId(bool mode)
{
if (useColorsByCanId != mode)
{
this->beginResetModel();
useColorsByCanId = mode;
this->endResetModel();
}
}
void CANFrameModel::setTimeStyle(TimeStyle newStyle)
{
if (timeStyle != newStyle)
@@ -401,7 +414,6 @@ QVariant CANFrameModel::data(const QModelIndex &index, int role) const
{
QString tempString;
CANFrame thisFrame;
static bool rowFlip = false;
QVariant ts;
if (!index.isValid())
@@ -425,9 +437,31 @@ QVariant CANFrameModel::data(const QModelIndex &index, int role) const
return msg->bgColor;
}
}
rowFlip = (index.row() % 2);
if (rowFlip) return QApplication::palette().color(QPalette::Base);
else return QApplication::palette().color(QPalette::AlternateBase);
if (useColorsByCanId)
{
QString frameStr = Utility::formatCANID(thisFrame.frameId(), thisFrame.hasExtendedFrameFormat());
// Color rows by the value in the "category" column
return QBrush(Utility::colorForString(frameStr));
}
return (index.row() % 2) ?
QApplication::palette().color(QPalette::Base) :
QApplication::palette().color(QPalette::AlternateBase);
}
if (role == Qt::ForegroundRole)
{
if (dbcHandler != nullptr && interpretFrames && !ignoreDBCColors)
{
DBC_MESSAGE *msg = dbcHandler->findMessage(thisFrame);
if (msg != nullptr)
{
return msg->fgColor;
}
}
return QApplication::palette().color(QPalette::WindowText);
}
if (role == Qt::TextAlignmentRole)
@@ -448,19 +482,6 @@ QVariant CANFrameModel::data(const QModelIndex &index, int role) const
}
}
if (role == Qt::ForegroundRole)
{
if (dbcHandler != nullptr && interpretFrames && !ignoreDBCColors)
{
DBC_MESSAGE *msg = dbcHandler->findMessage(thisFrame);
if (msg != nullptr)
{
return msg->fgColor;
}
}
return QApplication::palette().color(QPalette::WindowText);
}
if (role == Qt::DisplayRole) {
switch (Column(index.column()))
{