From cb94cac2057cab2121bccfce0f4255e100e017bb Mon Sep 17 00:00:00 2001 From: Andy Huska Date: Mon, 19 Sep 2022 13:47:57 -0500 Subject: [PATCH 1/2] Fixed issue where filteredFrames was having its capacity changed when adjusting filters due to appending a QVector of frames which appears to change the capacity to the number of items appended. Also fixed bug where preallocsize was being locally defined and therefore the global version wasn't being updated with unknown effets. --- canframemodel.cpp | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/canframemodel.cpp b/canframemodel.cpp index c4a8309..cdcaa19 100644 --- a/canframemodel.cpp +++ b/canframemodel.cpp @@ -59,7 +59,7 @@ CANFrameModel::CANFrameModel(QObject *parent) } QSettings settings; - int preallocSize = settings.value("Main/MaximumFrames", maxFramesDefault).toInt(); + preallocSize = settings.value("Main/MaximumFrames", maxFramesDefault).toInt(); frames.reserve(preallocSize); filteredFrames.reserve(preallocSize); //the goal is to prevent a reallocation from ever happening @@ -752,15 +752,15 @@ void CANFrameModel::addFrames(const CANConnection*, const QVector& pFr { if(frames.length() > frames.capacity() * 0.99) { - qDebug() << "Frames count: " << frames.length() << " of " << frames.capacity() << " capacity, removing first " << frames.capacity() * 0.05 << " frames"; - frames.remove(0, frames.capacity() * 0.05); + qDebug() << "Frames count: " << frames.length() << " of " << frames.capacity() << " capacity, removing first " << (int)(frames.capacity() * 0.05) << " frames"; + frames.remove(0, (int)(frames.capacity() * 0.05)); qDebug() << "Frames removed, new count: " << frames.length(); } if(filteredFrames.length() > filteredFrames.capacity() * 0.99) { - qDebug() << "filteredFrames count: " << filteredFrames.length() << " of " << filteredFrames.capacity() << " capacity, removing first " << filteredFrames.capacity() * 0.05 << " frames"; - filteredFrames.remove(0, filteredFrames.capacity() * 0.05); + qDebug() << "filteredFrames count: " << filteredFrames.length() << " of " << filteredFrames.capacity() << " capacity, removing first " << (int)(filteredFrames.capacity() * 0.05) << " frames"; + filteredFrames.remove(0, (int)(filteredFrames.capacity() * 0.05)); qDebug() << "filteredFrames removed, new count: " << filteredFrames.length(); } @@ -790,8 +790,8 @@ void CANFrameModel::sendRefresh() mutex.lock(); beginResetModel(); filteredFrames.clear(); - filteredFrames.reserve(preallocSize); filteredFrames.append(tempContainer); + filteredFrames.reserve(preallocSize); lastUpdateNumFrames = 0; endResetModel(); From 13c920f97110128ece5642c41f31d2208a71d5f4 Mon Sep 17 00:00:00 2001 From: Andy Huska Date: Tue, 20 Sep 2022 07:46:30 -0500 Subject: [PATCH 2/2] Fixed regression where non-commented node would not delete Fixed odd crash due to dbcNode being null on refresh --- dbc/dbchandler.cpp | 6 +++++- dbc/dbcnodeeditor.cpp | 7 +++++-- 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/dbc/dbchandler.cpp b/dbc/dbchandler.cpp index 6e29ad7..d60dd1b 100644 --- a/dbc/dbchandler.cpp +++ b/dbc/dbchandler.cpp @@ -351,7 +351,11 @@ DBC_NODE* DBCFile::findNodeByNameAndComment(QString fullname) if (dbc_nodes.length() == 0) return nullptr; for (int i = 0; i < dbc_nodes.length(); i++) { - nameAndComment = dbc_nodes[i].name + " - " + dbc_nodes[i].comment; + if(dbc_nodes[i].comment.isEmpty()) + nameAndComment = dbc_nodes[i].name; + else + nameAndComment = dbc_nodes[i].name + " - " + dbc_nodes[i].comment; + if (fullname.compare(nameAndComment, Qt::CaseInsensitive) == 0) { return &dbc_nodes[i]; diff --git a/dbc/dbcnodeeditor.cpp b/dbc/dbcnodeeditor.cpp index e8363a3..f553fb4 100644 --- a/dbc/dbcnodeeditor.cpp +++ b/dbc/dbcnodeeditor.cpp @@ -111,8 +111,11 @@ void DBCNodeEditor::showEvent(QShowEvent* event) void DBCNodeEditor::refreshView() { - ui->lineComment->setText(dbcNode->comment); - ui->lineMsgName->setText(dbcNode->name); + if(dbcNode) + { + ui->lineComment->setText(dbcNode->comment); + ui->lineMsgName->setText(dbcNode->name); + } //generateSampleText(); }