From 7a6cace6517f282a7054e1d73e3ac2d5fb8022dc Mon Sep 17 00:00:00 2001 From: Collin Kidder Date: Tue, 13 Dec 2022 21:19:25 -0500 Subject: [PATCH] Switched to using set colors for signal view instead of random generation. --- candatagrid.cpp | 73 +++++++++++++++++++++++++++++++---------- candatagrid.h | 3 +- dbc/dbcsignaleditor.cpp | 4 +++ 3 files changed, 62 insertions(+), 18 deletions(-) diff --git a/candatagrid.cpp b/candatagrid.cpp index 46ededa..4a5552c 100644 --- a/candatagrid.cpp +++ b/candatagrid.cpp @@ -6,6 +6,57 @@ #include #include +//The program used to generate new colors every time the grid was displayed but that's ugly +//and disorienting. Instead use this list colors I've picked because they're "bright". +//It may need a bit of reorganizing to keep like colors apart and feel free to add some more +//if you want. The program will wrap around if the number of signals in a single message exceeds +//this amount of colors. +//Colors here were generated with: https://colordesigner.io/random-color-generator set to random +//hue bright colors and 40 total colors. I clicked until I kind of liked it. +QVector signalColors = +{ + QColor(101, 104, 159), + QColor(237, 35, 109), + QColor(216, 53, 221), + QColor(37, 252, 220), + QColor(8, 160, 53), + QColor(226, 111, 11), + QColor(216, 59, 2), + QColor(249, 246, 27), + QColor(214, 21, 34), + QColor(178, 219, 74), + QColor(214, 55, 71), + QColor(80, 198, 206), + QColor(83, 214, 201), + QColor(35, 210, 237), + QColor(25, 170, 105), + QColor(110, 221, 55), + QColor(30, 38, 181), + QColor(79, 124, 209), + QColor(7, 91, 175), + QColor(14, 234, 208), + QColor(125, 45, 168), + QColor(176, 211, 80), + QColor(255, 206, 48), + QColor(202, 226, 93), + QColor(201, 99, 232), + QColor(13, 72, 135), + QColor(32, 45, 219), + QColor(197, 26, 216), + QColor(119, 15, 216), + QColor(97, 18, 150), + QColor(242, 16, 242), + QColor(177, 5, 196), + QColor(214, 10, 102), + QColor(9, 50, 155), + QColor(201, 38, 76), + QColor(202, 234, 72), + QColor(59, 191, 57), + QColor(0, 25, 170), + QColor(7, 186, 93), + QColor(29, 211, 147) +}; + CANDataGrid::CANDataGrid(QWidget *parent) : QWidget(parent), ui(new Ui::CANDataGrid) @@ -117,7 +168,6 @@ void CANDataGrid::clearSignalNames() { signalNames.clear(); signalNames.resize(40); - signalColors.clear(); } void CANDataGrid::setUsedSignalNum(int bit, int signal) @@ -257,21 +307,6 @@ void CANDataGrid::paintGridCells() int usedSigNum; QString prevSigName; - //if this is true then generate unique colors for each signal - if ((signalColors.count() == 0) && (signalNames.count() > 0) && gridMode == GridMode::SIGNAL_VIEW) - { - qDebug() << "Generating colors"; - signalColors.resize(signalNames.count()); - for (int i = 0; i < signalNames.count(); i++) - { - QColor newColor; - while (newColor.saturation() < 40) - newColor.setRgb(QRandomGenerator::global()->bounded(160) + 60,QRandomGenerator::global()->bounded(160) + 60, QRandomGenerator::global()->bounded(160) + 60); - qDebug() << newColor; - signalColors[i] = newColor; - } - } - //now, color the bitfield by seeing if a given bit is freshly set/unset in the new data //compared to the old. Bits that are not set in either are white, bits set in both are black //bits that used to be set but now are unset are red, bits that used to be unset but now are set @@ -321,7 +356,11 @@ void CANDataGrid::paintGridCells() grayBrush = QBrush(QColor(0xB6, 0xB6, 0xB6), Qt::BDiagPattern); painter->setBrush(grayBrush); } - else painter->setBrush(QBrush(signalColors[usedSigNum])); + else + { + int idx = usedSigNum % signalColors.length(); //can only use as many colors as have been defined + painter->setBrush(QBrush(signalColors[idx])); + } } else painter->setBrush(whiteBrush); } diff --git a/candatagrid.h b/candatagrid.h index 1fc11da..5e021a6 100644 --- a/candatagrid.h +++ b/candatagrid.h @@ -39,6 +39,8 @@ enum GridMode SIGNAL_VIEW //special view for DBC window where we draw the signals in the bits they take up }; +extern QVector signalColors; + class CANDataGrid : public QWidget { Q_OBJECT @@ -75,7 +77,6 @@ private: unsigned char usedData[64]; int usedSignalNum[512]; //so we can specify which signal claims this bit QVector signalNames; - QVector signalColors; GridTextState textStates[64][8]; //first dimension is bytes, second is bits QPoint upperLeft, gridSize; GridMode gridMode; diff --git a/dbc/dbcsignaleditor.cpp b/dbc/dbcsignaleditor.cpp index 9922d5c..80e309e 100644 --- a/dbc/dbcsignaleditor.cpp +++ b/dbc/dbcsignaleditor.cpp @@ -463,6 +463,10 @@ void DBCSignalEditor::deleteCurrentValue() /* WARNING: fillSignalForm can be called recursively since it is in the listener of cbIntelFormat */ void DBCSignalEditor::fillSignalForm(DBC_SIGNAL *sig) { + //sanity checks + if (!dbcMessage) return; + if (!dbcMessage->sigHandler) return; + inhibitMsgProc = true; if (sig == nullptr) {