diff --git a/dbc/dbchandler.cpp b/dbc/dbchandler.cpp index a8d09da..10cacbd 100644 --- a/dbc/dbchandler.cpp +++ b/dbc/dbchandler.cpp @@ -151,6 +151,20 @@ DBC_MESSAGE* DBCMessageHandler::findMsgByName(QString name) return nullptr; } +//allow for finding a message just by part of the name +DBC_MESSAGE* DBCMessageHandler::findMsgByPartialName(QString name) +{ + if (messages.count() == 0) return nullptr; + for (int i = 0; i < messages.count(); i++) + { + if (messages[i].name.contains(name, Qt::CaseInsensitive)) + { + return &messages[i]; + } + } + return nullptr; +} + bool DBCMessageHandler::addMessage(DBC_MESSAGE &msg) { messages.append(msg); diff --git a/dbc/dbchandler.h b/dbc/dbchandler.h index f7b6c25..5e83525 100644 --- a/dbc/dbchandler.h +++ b/dbc/dbchandler.h @@ -40,6 +40,7 @@ public: DBC_MESSAGE *findMsgByID(uint32_t id); DBC_MESSAGE *findMsgByIdx(int idx); DBC_MESSAGE *findMsgByName(QString name); + DBC_MESSAGE *findMsgByPartialName(QString name); bool addMessage(DBC_MESSAGE &msg); bool removeMessage(DBC_MESSAGE *msg); bool removeMessageByIndex(int idx); diff --git a/dbc/dbcmaineditor.cpp b/dbc/dbcmaineditor.cpp index df2e906..f7e3386 100644 --- a/dbc/dbcmaineditor.cpp +++ b/dbc/dbcmaineditor.cpp @@ -5,6 +5,7 @@ #include #include #include +#include #include #include "helpwindow.h" @@ -50,6 +51,9 @@ DBCMainEditor::DBCMainEditor( const QVector *frames, QWidget *parent) connect(ui->MessagesTable, SIGNAL(customContextMenuRequested(QPoint)), this, SLOT(onCustomMenuMessage(QPoint))); ui->MessagesTable->setContextMenuPolicy(Qt::CustomContextMenu); + connect(ui->btnSearch, &QAbstractButton::clicked, this, &DBCMainEditor::handleSearch); + connect(ui->lineSearch, &QLineEdit::returnPressed, this, &DBCMainEditor::handleSearch); + sigEditor = new DBCSignalEditor(this); installEventFilter(this); @@ -179,6 +183,81 @@ void DBCMainEditor::deleteCurrentMessage() } } +void DBCMainEditor::handleSearch() +{ + uint32_t msgId = Utility::ParseStringToNum(ui->lineSearch->text()); + if (ui->radioID->isChecked()) + { + DBC_MESSAGE *msg = dbcFile->messageHandler->findMsgByID(msgId); + if (msg) + { + DBC_NODE *node = msg->sender; + if (node) + { + QString nodeName = node->name; + for (int i = 0; i < ui->NodesTable->rowCount(); i++) + { + QTableWidgetItem *item = ui->NodesTable->item(i, 0); + if (item->text() == nodeName) + { + item->setSelected(true); + ui->NodesTable->scrollToItem(item); + onCellClickedNode(i, 0); + for (int j = 0; j < ui->MessagesTable->rowCount(); j++) + { + QTableWidgetItem *msgItem = ui->MessagesTable->item(j, 0); + if (!msgItem) break; + if (Utility::ParseStringToNum(msgItem->text()) == msgId) + { + msgItem->setSelected(true); + ui->MessagesTable->scrollToItem(msgItem); + onCellClickedMessage(j, 0); + break; + } + } + break; + } + } + } + } + } + if (ui->radioName->isChecked()) + { + DBC_MESSAGE *msg = dbcFile->messageHandler->findMsgByPartialName(ui->lineSearch->text()); + if (msg) + { + DBC_NODE *node = msg->sender; + if (node) + { + QString nodeName = node->name; + for (int i = 0; i < ui->NodesTable->rowCount(); i++) + { + QTableWidgetItem *item = ui->NodesTable->item(i, 0); + if (item->text() == nodeName) + { + item->setSelected(true); + ui->NodesTable->scrollToItem(item); + onCellClickedNode(i, 0); + for (int j = 0; j < ui->MessagesTable->rowCount(); j++) + { + QTableWidgetItem *msgItem = ui->MessagesTable->item(j, 1); + if (!msgItem) break; + if (msgItem->text().contains(ui->lineSearch->text(), Qt::CaseInsensitive)) + { + msgItem->setSelected(true); + ui->MessagesTable->scrollToItem(msgItem); + onCellClickedMessage(j, 0); + break; + } + } + break; + } + } + } + } + } +} + void DBCMainEditor::onCellChangedNode(int row,int col) { if (inhibitCellChanged) return; diff --git a/dbc/dbcmaineditor.h b/dbc/dbcmaineditor.h index b92815d..c369c2c 100644 --- a/dbc/dbcmaineditor.h +++ b/dbc/dbcmaineditor.h @@ -29,6 +29,7 @@ private slots: void onCustomMenuMessage(QPoint); void deleteCurrentNode(); void deleteCurrentMessage(); + void handleSearch(); private: Ui::DBCMainEditor *ui; diff --git a/dbc/dbcsignaleditor.cpp b/dbc/dbcsignaleditor.cpp index 6c579ec..4cd27b6 100644 --- a/dbc/dbcsignaleditor.cpp +++ b/dbc/dbcsignaleditor.cpp @@ -4,6 +4,7 @@ #include #include #include +#include #include #include "helpwindow.h" @@ -15,8 +16,6 @@ DBCSignalEditor::DBCSignalEditor(QWidget *parent) : readSettings(); - qsrand(QDateTime::currentMSecsSinceEpoch()); - dbcHandler = DBCHandler::getReference(); dbcMessage = nullptr; currentSignal = nullptr; @@ -345,7 +344,7 @@ void DBCSignalEditor::onCustomMenuValues(QPoint point) void DBCSignalEditor::addNewSignal() { - int num = qrand() % 70000; + int num = QRandomGenerator::global()->bounded(70000); QString newName = "SIGNAL" + QString::number(num); DBC_SIGNAL newSig; newSig.name = newName; @@ -373,7 +372,7 @@ void DBCSignalEditor::addNewSignal() void DBCSignalEditor::cloneSignal() { - int num = qrand() % 100; + int num = QRandomGenerator::global()->bounded(100); int idx = ui->signalsList->currentRow(); if (idx < 0) return; diff --git a/re/fuzzingwindow.cpp b/re/fuzzingwindow.cpp index b2c016b..f510f7a 100644 --- a/re/fuzzingwindow.cpp +++ b/re/fuzzingwindow.cpp @@ -2,6 +2,7 @@ #include "ui_fuzzingwindow.h" #include "utility.h" #include +#include #include "mainwindow.h" #include "helpwindow.h" #include "connections/canconmanager.h" @@ -250,12 +251,12 @@ void FuzzingWindow::calcNextID() if (rangeIDSelect) { int range = endID - startID; - if (range != 0) currentID = startID + qrand() % range; + if (range != 0) currentID = startID + QRandomGenerator::global()->bounded(range); else currentID = startID; } else //IDs by filter so pick a random selected ID from the filter list { - currentIdx = qrand() % selectedIDs.length(); + currentIdx = QRandomGenerator::global()->bounded(selectedIDs.length()); currentID = selectedIDs[currentIdx]; } } @@ -277,7 +278,7 @@ void FuzzingWindow::calcNextBitPattern() thisBit = bitGrid[byt * 8 + bit]; if (thisBit == 1) { - if ((qrand() % 2) == 1) currentBytes[byt] |= (1 << bit); + if ((QRandomGenerator::global()->bounded(2)) == 1) currentBytes[byt] |= (1 << bit); } if (thisBit == 2) currentBytes[byt] |= (1 << bit); } @@ -391,12 +392,12 @@ void FuzzingWindow::toggleFuzzing() if (rangeIDSelect) { int range = endID - startID; - if (range != 0) currentID = startID + qrand() % range; + if (range != 0) currentID = startID + QRandomGenerator::global()->bounded(range); else currentID = startID; } else //IDs by filter so pick a random selected ID from the filter list { - currentIdx = qrand() % selectedIDs.length(); + currentIdx = QRandomGenerator::global()->bounded(selectedIDs.length()); currentID = selectedIDs[currentIdx]; } } diff --git a/re/newgraphdialog.cpp b/re/newgraphdialog.cpp index 541458c..f9917c7 100644 --- a/re/newgraphdialog.cpp +++ b/re/newgraphdialog.cpp @@ -1,6 +1,7 @@ #include "newgraphdialog.h" #include "ui_newgraphdialog.h" #include +#include #include "utility.h" #include "helpwindow.h" @@ -15,13 +16,9 @@ NewGraphDialog::NewGraphDialog(DBCHandler *handler, QWidget *parent) : connect(ui->colorSwatch, SIGNAL(clicked(bool)), this, SLOT(colorSwatchClick())); connect(ui->btnAddGraph, SIGNAL(clicked(bool)), this, SLOT(addButtonClicked())); - // Seed the random generator with current time - QTime time = QTime::currentTime(); - qsrand((uint)time.msec()); - QPalette p = ui->colorSwatch->palette(); //using 160 instead of 255 so that colors are always at least a little dark - p.setColor(QPalette::Button, QColor(qrand() % 160,qrand() % 160,qrand() % 160)); + p.setColor(QPalette::Button, QColor(QRandomGenerator::global()->bounded(160),QRandomGenerator::global()->bounded(160), QRandomGenerator::global()->bounded(160))); ui->colorSwatch->setPalette(p); connect(ui->cbMessages, SIGNAL(currentIndexChanged(int)), this, SLOT(loadSignals(int))); diff --git a/ui/dbcmaineditor.ui b/ui/dbcmaineditor.ui index dedb4a2..126452b 100644 --- a/ui/dbcmaineditor.ui +++ b/ui/dbcmaineditor.ui @@ -40,6 +40,44 @@ + + + + + + Find DBC Message: + + + + + + + + + + Msg ID + + + true + + + + + + + Msg Name + + + + + + + Search + + + + +