From 9c143c2b12029fa311ba4922f9c94e80b7301741 Mon Sep 17 00:00:00 2001 From: Collin Kidder Date: Thu, 2 Apr 2020 21:47:20 -0400 Subject: [PATCH] Add two new buttons to expand or collapse all signals. --- mainwindow.cpp | 44 ++++++++++++++++++++++++++++++++++++++++++++ mainwindow.h | 2 ++ ui/mainwindow.ui | 40 ++++++++++++++++++++++++++++++++++------ utility.h | 4 ++++ 4 files changed, 84 insertions(+), 6 deletions(-) diff --git a/mainwindow.cpp b/mainwindow.cpp index 08a096e..ab8e7c5 100644 --- a/mainwindow.cpp +++ b/mainwindow.cpp @@ -129,6 +129,8 @@ MainWindow::MainWindow(QWidget *parent) : connect(ui->actionSignal_Viewer, &QAction::triggered, this, &MainWindow::showSignalViewer); connect(ui->actionSave_Continuous_Logfile, &QAction::triggered, this, &MainWindow::handleContinousLogging); connect(ui->actionTemporal_Graph, &QAction::triggered, this, &MainWindow::showTemporalGraphWindow); + connect(ui->btnExpandAll, &QAbstractButton::clicked, this, &MainWindow::expandAllRows); + connect(ui->btnCollapseAll, &QAbstractButton::clicked, this, &MainWindow::collapseAllRows); connect(CANConManager::getInstance(), &CANConManager::framesReceived, model, &CANFrameModel::addFrames); @@ -382,6 +384,48 @@ void MainWindow::headerClicked(int logicalIndex) model->sortByColumn(logicalIndex); } +void MainWindow::expandAllRows() +{ + bool goAhead = false; + int numRows = ui->canFramesView->model()->rowCount(); + + if (numRows > 20000) + { + QMessageBox::StandardButton confirmDialog; + confirmDialog = QMessageBox::question(this, "Really?", "It's not recommended to use this\non more than 20000 frames.\nIt can take a long time.\n\nYou have been warned!\nStill do it?", + QMessageBox::Yes|QMessageBox::No); + + if (confirmDialog == QMessageBox::Yes) goAhead = true; + } + else goAhead = true; + + if (goAhead) + { + ui->canFramesView->resizeRowsToContents(); + } +} + +void MainWindow::collapseAllRows() +{ + bool goAhead = false; + int numRows = ui->canFramesView->model()->rowCount(); + + if (numRows > 50000) + { + QMessageBox::StandardButton confirmDialog; + confirmDialog = QMessageBox::question(this, "Really?", "It's not recommended to use this\non more than 50000 frames.\nIt can take a long time.\n\nYou have been warned!\nStill do it?", + QMessageBox::Yes|QMessageBox::No); + + if (confirmDialog == QMessageBox::Yes) goAhead = true; + } + else goAhead = true; + + if (goAhead) + { + for (int i = 0; i < numRows; i++) ui->canFramesView->setRowHeight(i, normalRowHeight); + } +} + void MainWindow::gridClicked(QModelIndex idx) { //qDebug() << "Grid Clicked"; diff --git a/mainwindow.h b/mainwindow.h index e780f88..d3a45dd 100644 --- a/mainwindow.h +++ b/mainwindow.h @@ -63,6 +63,8 @@ private slots: void showGraphingWindow(); void showFrameDataAnalysis(); void clearFrames(); + void expandAllRows(); + void collapseAllRows(); void showPlaybackWindow(); void showFlowViewWindow(); void showFrameSenderWindow(); diff --git a/ui/mainwindow.ui b/ui/mainwindow.ui index 1bda8d1..46acf44 100644 --- a/ui/mainwindow.ui +++ b/ui/mainwindow.ui @@ -191,6 +191,23 @@ + + + + true + + + Overwrite Mode + + + + + + + Qt::Horizontal + + + @@ -199,12 +216,23 @@ - - - true - + - Overwrite Mode + Expand All Rows + + + + + + + Collapse All Rows + + + + + + + Qt::Horizontal @@ -265,7 +293,7 @@ 0 0 800 - 22 + 23 diff --git a/utility.h b/utility.h index 090b0a3..ab2d44d 100644 --- a/utility.h +++ b/utility.h @@ -194,6 +194,8 @@ public: for (int bitpos = 0; bitpos < sigSize; bitpos++) { if (bit < 64) { + int bytePos = bit / 8; + if (bytePos >= data.count()) return 0; //error! if (data[bit / 8] & (1 << (bit % 8))) result += (1ULL << bitpos); } @@ -206,6 +208,8 @@ public: for (int bitpos = 0; bitpos < sigSize; bitpos++) { if (bit < 64) { + int bytePos = bit / 8; + if (bytePos >= data.count()) return 0; //error! if (data[bit / 8] & (1 << (bit % 8))) result += (1ULL << (sigSize - bitpos - 1)); }