Initial commit of color coding for DBC messages. It kind of works but there are many little kinks to work out yet.

This commit is contained in:
Collin Kidder
2017-01-18 19:54:19 -05:00
parent 50a2683dd4
commit 6af5cfadf4
3 changed files with 176 additions and 11 deletions
+33 -2
View File
@@ -1,6 +1,8 @@
#include "canframemodel.h" #include "canframemodel.h"
#include <QFile> #include <QFile>
#include <QApplication>
#include <QPalette>
#include "utility.h" #include "utility.h"
@@ -194,14 +196,43 @@ QVariant CANFrameModel::data(const QModelIndex &index, int role) const
{ {
int dLen; int dLen;
QString tempString; QString tempString;
CANFrame thisFrame;
if (!index.isValid()) if (!index.isValid())
return QVariant(); return QVariant();
if (index.row() >= (filteredFrames.count())) if (index.row() >= (filteredFrames.count()))
return QVariant(); return QVariant();
thisFrame = filteredFrames.at(index.row());
if (role == Qt::BackgroundColorRole)
{
if (dbcHandler != NULL && interpretFrames)
{
DBC_MESSAGE *msg = dbcHandler->findMessage(thisFrame);
if (msg != NULL)
{
return msg->bgColor;
}
}
return QApplication::palette().color(QPalette::Window);
}
if (role == Qt::TextColorRole)
{
if (dbcHandler != NULL && interpretFrames)
{
DBC_MESSAGE *msg = dbcHandler->findMessage(thisFrame);
if (msg != NULL)
{
return msg->fgColor;
}
}
return QApplication::palette().color(QPalette::WindowText);
}
if (role == Qt::DisplayRole) { if (role == Qt::DisplayRole) {
CANFrame thisFrame = filteredFrames.at(index.row());
switch (index.column()) switch (index.column())
{ {
case 0: //timestamp case 0: //timestamp
@@ -249,7 +280,7 @@ QVariant CANFrameModel::data(const QModelIndex &index, int role) const
tempString.append(sigString); tempString.append(sigString);
tempString.append("\n"); tempString.append("\n");
} }
} }
} }
} }
return tempString; return tempString;
+71
View File
@@ -5,6 +5,8 @@
#include <QDebug> #include <QDebug>
#include <QMessageBox> #include <QMessageBox>
#include <QFileDialog> #include <QFileDialog>
#include <QApplication>
#include <QPalette>
#include "utility.h" #include "utility.h"
DBCHandler* DBCHandler::instance = NULL; DBCHandler* DBCHandler::instance = NULL;
@@ -732,6 +734,53 @@ void DBCFile::loadFile(QString fileName)
} }
} }
} }
//upon loading the file add our custom foreground and background color attributes if they don't exist already
DBC_ATTRIBUTE *bgAttr = findAttributeByName("GenMsgBackgroundColor");
if (!bgAttr)
{
attr.attrType = MESSAGE;
attr.defaultValue = QApplication::palette().color(QPalette::WindowText).name();
attr.enumVals.clear();
attr.lower = 0;
attr.upper = 0;
attr.name = "GenMsgBackgroundColor";
attr.valType = QSTRING;
dbc_attributes.append(attr);
bgAttr = findAttributeByName("GenMsgBackgroundColor");
}
DBC_ATTRIBUTE *fgAttr = findAttributeByName("GenMsgForegroundColor");
if (!fgAttr)
{
attr.attrType = MESSAGE;
attr.defaultValue = QApplication::palette().color(QPalette::Window).name();
attr.enumVals.clear();
attr.lower = 0;
attr.upper = 0;
attr.name = "GenMsgForegroundColor";
attr.valType = QSTRING;
dbc_attributes.append(attr);
fgAttr = findAttributeByName("GenMsgForegroundColor");
}
QColor DefaultBG = QColor(bgAttr->defaultValue.toString());
QColor DefaultFG = QColor(fgAttr->defaultValue.toString());
DBC_ATTRIBUTE_VALUE *thisBG;
DBC_ATTRIBUTE_VALUE *thisFG;
for (int x = 0; x < messageHandler->getCount(); x++)
{
DBC_MESSAGE *msg = messageHandler->findMsgByIdx(x);
msg->bgColor = DefaultBG;
msg->fgColor = DefaultFG;
thisBG = msg->findAttrValByName("GenMsgBackgroundColor");
thisFG = msg->findAttrValByName("GenMsgForegroundColor");
if (thisBG) msg->bgColor = QColor(thisBG->value.toString());
if (thisFG) msg->fgColor = QColor(thisFG->value.toString());
}
if (numSigFaults > 0 || numMsgFaults > 0) if (numSigFaults > 0 || numMsgFaults > 0)
{ {
QMessageBox msgBox; QMessageBox msgBox;
@@ -950,6 +999,7 @@ void DBCFile::saveFile(QString fileName)
for (int x = 0; x < messageHandler->getCount(); x++) for (int x = 0; x < messageHandler->getCount(); x++)
{ {
DBC_MESSAGE *msg = messageHandler->findMsgByIdx(x); DBC_MESSAGE *msg = messageHandler->findMsgByIdx(x);
msgOutput.append("BO_ " + QString::number(msg->ID) + " " + msg->name + ": " + QString::number(msg->len) + msgOutput.append("BO_ " + QString::number(msg->ID) + " " + msg->name + ": " + QString::number(msg->len) +
" " + msg->sender->name + "\n"); " " + msg->sender->name + "\n");
if (msg->comment.length() > 0) if (msg->comment.length() > 0)
@@ -1166,6 +1216,27 @@ void DBCHandler::saveDBCFile(int idx)
int DBCHandler::createBlankFile() int DBCHandler::createBlankFile()
{ {
DBCFile newFile; DBCFile newFile;
DBC_ATTRIBUTE attr;
//add our custom attributes to the new file so that we know they're already there.
attr.attrType = MESSAGE;
attr.defaultValue = QApplication::palette().color(QPalette::WindowText).name();
attr.enumVals.clear();
attr.lower = 0;
attr.upper = 0;
attr.name = "GenMsgBackgroundColor";
attr.valType = QSTRING;
newFile.dbc_attributes.append(attr);
attr.attrType = MESSAGE;
attr.defaultValue = QApplication::palette().color(QPalette::Window).name();
attr.enumVals.clear();
attr.lower = 0;
attr.upper = 0;
attr.name = "GenMsgForegroundColor";
attr.valType = QSTRING;
newFile.dbc_attributes.append(attr);
loadedFiles.append(newFile); loadedFiles.append(newFile);
return loadedFiles.count(); return loadedFiles.count();
} }
+72 -9
View File
@@ -4,8 +4,7 @@
#include <QMenu> #include <QMenu>
#include <QMessageBox> #include <QMessageBox>
#include <QSettings> #include <QSettings>
#include <QColorDialog>
#define MT_COLUMN_COUNT 5
DBCMainEditor::DBCMainEditor( const QVector<CANFrame> *frames, QWidget *parent) : DBCMainEditor::DBCMainEditor( const QVector<CANFrame> *frames, QWidget *parent) :
QDialog(parent), QDialog(parent),
@@ -27,13 +26,15 @@ DBCMainEditor::DBCMainEditor( const QVector<CANFrame> *frames, QWidget *parent)
ui->NodesTable->horizontalHeader()->setStretchLastSection(true); ui->NodesTable->horizontalHeader()->setStretchLastSection(true);
QStringList headers2; QStringList headers2;
headers2 << "Msg ID" << "Msg Name" << "Data Len" << "Signals" << "Comment"; headers2 << "Msg ID" << "Msg Name" << "Data Len" << "Signals" << "Fg" << "Bg" << "Comment";
ui->MessagesTable->setColumnCount(MT_COLUMN_COUNT); ui->MessagesTable->setColumnCount(headers2.count());
ui->MessagesTable->setColumnWidth(0, 80); ui->MessagesTable->setColumnWidth(0, 80);
ui->MessagesTable->setColumnWidth(1, 240); ui->MessagesTable->setColumnWidth(1, 200);
ui->MessagesTable->setColumnWidth(2, 80); ui->MessagesTable->setColumnWidth(2, 80);
ui->MessagesTable->setColumnWidth(3, 80); ui->MessagesTable->setColumnWidth(3, 80);
ui->MessagesTable->setColumnWidth(4, 340); ui->MessagesTable->setColumnWidth(4, 40);
ui->MessagesTable->setColumnWidth(5, 40);
ui->MessagesTable->setColumnWidth(6, 300);
ui->MessagesTable->setHorizontalHeaderLabels(headers2); ui->MessagesTable->setHorizontalHeaderLabels(headers2);
ui->MessagesTable->horizontalHeader()->setStretchLastSection(true); ui->MessagesTable->horizontalHeader()->setStretchLastSection(true);
@@ -277,7 +278,7 @@ void DBCMainEditor::onCellChangedMessage(int row,int col)
item->setFlags(item->flags() & ~Qt::ItemIsEditable); item->setFlags(item->flags() & ~Qt::ItemIsEditable);
item->setText(Utility::formatNumber(msgID)); item->setText(Utility::formatNumber(msgID));
for(int i=1 ; i<MT_COLUMN_COUNT ; i++) for(int i=1 ; i < ui->MessagesTable->columnCount(); i++)
{ {
item = ui->MessagesTable->item(row, i); item = ui->MessagesTable->item(row, i);
item->setFlags(item->flags() | Qt::ItemIsEditable); item->setFlags(item->flags() | Qt::ItemIsEditable);
@@ -324,7 +325,7 @@ void DBCMainEditor::onCellChangedMessage(int row,int col)
} }
case 3: //signals (number) - we don't handle anything here. User cannot directly change this value case 3: //signals (number) - we don't handle anything here. User cannot directly change this value
break; break;
case 4: //comment case 6: //comment
{ {
QString msgComment = ui->MessagesTable->item(row, col)->text().simplified(); QString msgComment = ui->MessagesTable->item(row, col)->text().simplified();
if( ret && (msgComment!=NULL) ) if( ret && (msgComment!=NULL) )
@@ -359,6 +360,12 @@ void DBCMainEditor::onCellClickedNode(int row, int col)
void DBCMainEditor::onCellClickedMessage(int row, int col) void DBCMainEditor::onCellClickedMessage(int row, int col)
{ {
QTableWidgetItem* thisItem = ui->MessagesTable->item(row, col);
QTableWidgetItem* firstCol = ui->MessagesTable->item(row, 0);
bool ret = false;
DBC_MESSAGE *msg;
int msgID;
if (col == 3) //3 is the signals field. If clicked we go to the signals dialog if (col == 3) //3 is the signals field. If clicked we go to the signals dialog
{ {
QTableWidgetItem* msg = ui->MessagesTable->item(row, 0); QTableWidgetItem* msg = ui->MessagesTable->item(row, 0);
@@ -375,6 +382,60 @@ void DBCMainEditor::onCellClickedMessage(int row, int col)
inhibitCellChanged = false; inhibitCellChanged = false;
} }
} }
if (col == 4)
{
QColor newColor = QColorDialog::getColor(thisItem->backgroundColor());
thisItem->setBackgroundColor(newColor);
if(!firstCol) return;
msgID = Utility::ParseStringToNum2(firstCol->text(), &ret);
msg = dbcFile->messageHandler->findMsgByID(msgID);
if (msg)
{
msg->fgColor = newColor;
DBC_ATTRIBUTE_VALUE *val = msg->findAttrValByName("GenMsgForegroundColor");
if (val)
{
val->value = newColor.name();
}
else
{
DBC_ATTRIBUTE_VALUE newVal;
newVal.attrName = "GenMsgForegroundColor";
newVal.value = newColor.name();
msg->attributes.append(newVal);
}
}
}
if (col == 5)
{
QColor newColor = QColorDialog::getColor(thisItem->backgroundColor());
thisItem->setBackgroundColor(newColor);
if(!firstCol) return;
msgID = Utility::ParseStringToNum2(firstCol->text(), &ret);
msg = dbcFile->messageHandler->findMsgByID(msgID);
if (msg)
{
msg->bgColor = newColor;
DBC_ATTRIBUTE_VALUE *val = msg->findAttrValByName("GenMsgBackgroundColor");
if (val)
{
val->value = newColor.name();
}
else
{
DBC_ATTRIBUTE_VALUE newVal;
newVal.attrName = "GenMsgBackgroundColor";
newVal.value = newColor.name();
msg->attributes.append(newVal);
}
}
}
} }
void DBCMainEditor::refreshNodesTable() void DBCMainEditor::refreshNodesTable()
@@ -453,9 +514,11 @@ void DBCMainEditor::insertBlankRow()
{ {
int rowIdx = ui->MessagesTable->rowCount(); int rowIdx = ui->MessagesTable->rowCount();
ui->MessagesTable->insertRow(rowIdx); ui->MessagesTable->insertRow(rowIdx);
for(int i=1 ; i<MT_COLUMN_COUNT ; i++) for(int i=1 ; i < ui->MessagesTable->columnCount(); i++)
{ {
QTableWidgetItem *item = new QTableWidgetItem(""); QTableWidgetItem *item = new QTableWidgetItem("");
if (i == 4) item->setBackgroundColor(QApplication::palette().color(QPalette::WindowText)); //foreground color
//if (i == 5) item->setBackgroundColor(ui->MessagesTable->palette().color(ui->MessagesTable->backgroundRole())); //background color
item->setFlags(item->flags() & ~Qt::ItemIsEditable); item->setFlags(item->flags() & ~Qt::ItemIsEditable);
ui->MessagesTable->setItem(rowIdx, i, item); ui->MessagesTable->setItem(rowIdx, i, item);
} }