settings and render for setUseColorsByCanId
This commit is contained in:
+38
-17
@@ -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()))
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user