From 6c633f8720e8393d570aa1153802609cc765fcc9 Mon Sep 17 00:00:00 2001 From: Collin Kidder Date: Tue, 19 Feb 2019 20:53:46 -0500 Subject: [PATCH] Overwrite mode now has a warning message before you can really enable it. Also, it alters the main frame list to show just the one frame per ID so it is extremely obvious that you're in overwrite mode. --- canframemodel.cpp | 33 ++++++++++++++------------------- mainwindow.cpp | 12 +++++++++++- 2 files changed, 25 insertions(+), 20 deletions(-) diff --git a/canframemodel.cpp b/canframemodel.cpp index bc35c39..eea4ae0 100644 --- a/canframemodel.cpp +++ b/canframemodel.cpp @@ -160,6 +160,7 @@ void CANFrameModel::setOverwriteMode(bool mode) { beginResetModel(); overwriteDups = mode; + recalcOverwrite(); endResetModel(); } @@ -191,26 +192,20 @@ void CANFrameModel::recalcOverwrite() mutex.lock(); beginResetModel(); - for (int i = 1; i < frames.count(); i++) - { - found = false; - for (int j = 0; j <= lastUnique; j++) - { - if (frames[i].ID == frames[j].ID) - { - frames.replace(j, frames[i]); - found = true; - break; - } - } - if (!found) - { - lastUnique++; - frames.replace(lastUnique, frames[i]); - } - } - while (frames.count() > lastUnique) frames.removeLast(); + //Look at the current list of frames and turn it into just a list of unique IDs + QHash overWriteFrames; + foreach(CANFrame frame, frames) + { + if (!overWriteFrames.contains(frame.ID)) + { + overWriteFrames.insert(frame.ID, frame); + } + else overWriteFrames[frame.ID] = frame; + } + //Then replace the old list of frames with just the unique list + frames.clear(); + frames.append(overWriteFrames.values().toVector()); filteredFrames.clear(); filteredFrames.reserve(preallocSize); diff --git a/mainwindow.cpp b/mainwindow.cpp index b3910c8..1d6f896 100644 --- a/mainwindow.cpp +++ b/mainwindow.cpp @@ -399,7 +399,17 @@ void MainWindow::interpretToggled(bool state) void MainWindow::overwriteToggled(bool state) { - model->setOverwriteMode(state); + if (state) + { + QMessageBox::StandardButton confirmDialog; + confirmDialog = QMessageBox::question(this, "Danger Will Robinson", "Enabling Overwrite mode will\ndelete your captured frames\nand replace them with one\nframe per ID.\n\nAre you ready to do that?", + QMessageBox::Yes|QMessageBox::No); + if (confirmDialog == QMessageBox::Yes) + { + model->setOverwriteMode(state); + } + else ui->cbOverwrite->setCheckState(Qt::Unchecked); + } } void MainWindow::updateFilterList()