Added searching to DBC window to make it easier to find messages. Replaced deprecated random number calls with new method.
This commit is contained in:
@@ -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);
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -5,6 +5,7 @@
|
||||
#include <QMessageBox>
|
||||
#include <QSettings>
|
||||
#include <QColorDialog>
|
||||
#include <QTableWidgetItem>
|
||||
#include <qevent.h>
|
||||
#include "helpwindow.h"
|
||||
|
||||
@@ -50,6 +51,9 @@ DBCMainEditor::DBCMainEditor( const QVector<CANFrame> *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;
|
||||
|
||||
@@ -29,6 +29,7 @@ private slots:
|
||||
void onCustomMenuMessage(QPoint);
|
||||
void deleteCurrentNode();
|
||||
void deleteCurrentMessage();
|
||||
void handleSearch();
|
||||
|
||||
private:
|
||||
Ui::DBCMainEditor *ui;
|
||||
|
||||
@@ -4,6 +4,7 @@
|
||||
#include <QDebug>
|
||||
#include <QMenu>
|
||||
#include <QSettings>
|
||||
#include <QRandomGenerator>
|
||||
#include <qevent.h>
|
||||
#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;
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
#include "ui_fuzzingwindow.h"
|
||||
#include "utility.h"
|
||||
#include <QDebug>
|
||||
#include <QRandomGenerator>
|
||||
#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];
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
#include "newgraphdialog.h"
|
||||
#include "ui_newgraphdialog.h"
|
||||
#include <QColorDialog>
|
||||
#include <QRandomGenerator>
|
||||
#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)));
|
||||
|
||||
@@ -40,6 +40,44 @@
|
||||
<item>
|
||||
<widget class="QTableWidget" name="MessagesTable"/>
|
||||
</item>
|
||||
<item>
|
||||
<layout class="QHBoxLayout" name="horizontalLayout">
|
||||
<item>
|
||||
<widget class="QLabel" name="label_3">
|
||||
<property name="text">
|
||||
<string>Find DBC Message:</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QLineEdit" name="lineSearch"/>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QRadioButton" name="radioID">
|
||||
<property name="text">
|
||||
<string>Msg ID</string>
|
||||
</property>
|
||||
<property name="checked">
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QRadioButton" name="radioName">
|
||||
<property name="text">
|
||||
<string>Msg Name</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QPushButton" name="btnSearch">
|
||||
<property name="text">
|
||||
<string>Search</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
</layout>
|
||||
|
||||
Reference in New Issue
Block a user