diff --git a/src/mainwindow.cpp b/src/mainwindow.cpp index a261c34d..11b8b444 100644 --- a/src/mainwindow.cpp +++ b/src/mainwindow.cpp @@ -50,6 +50,8 @@ #include #include +#include + /** * From QDlt. * Must be a "C" include to interpret the imports correctly @@ -516,6 +518,9 @@ void MainWindow::initView() connect(searchTextbox, SIGNAL(returnPressed()), this, SLOT(on_actionFindNext())); connect(searchTextbox, SIGNAL(returnPressed()),searchDlg,SLOT(findNextClicked())); connect(searchDlg, SIGNAL(searchProgressChanged(bool)), this, SLOT(onSearchProgressChanged(bool))); + connect(searchDlg, &SearchDialog::searchProgressValueChanged, this, [this](int progress){ + searchProgressBar->setValue(progress); + }); connect(settingsDlg, SIGNAL(FilterPathChanged()), this, SLOT(on_actionDefault_Filter_Reload_triggered())); connect(settingsDlg, SIGNAL(PluginsAutoloadChanged()), this, SLOT(triggerPluginsAutoload())); @@ -581,8 +586,29 @@ void MainWindow::initSignalConnections() connect(searchDlg,SIGNAL(addActionHistory()),this,SLOT(onAddActionToHistory())); /* Insert search text box to search toolbar, before previous button */ + searchProgressBar = new QProgressBar(); + searchProgressBar->setRange(0, 100); + + + QWidget* widget = new QWidget(); + QPushButton *button1 = new QPushButton("Abort"); + connect (button1, &QPushButton::clicked, this, [this]{ + searchDlg->cancelSearch(); + }); + + QHBoxLayout *layout = new QHBoxLayout(); + layout->addWidget(searchProgressBar); + layout->addWidget(button1); + + widget->setLayout(layout); + + stackedWidget = new QStackedWidget(); + + stackedWidget->addWidget(searchComboBox); + stackedWidget->addWidget(widget); + QAction *before = m_searchActions.at(ToolbarPosition::FindPrevious); - ui->searchToolbar->insertWidget(before, searchComboBox); + ui->searchToolbar->insertWidget(before, stackedWidget); /* adding shortcuts - regard: in the search window, the signal is caught by another way, this here only catches the keys when main window is active */ m_shortcut_searchnext = new QShortcut(QKeySequence("F3"), this); @@ -8402,7 +8428,15 @@ void MainWindow::onSearchProgressChanged(bool isInProgress) isSearchOngoing = isInProgress; ui->menuBar->setEnabled(!isInProgress); ui->mainToolBar->setEnabled(!isInProgress); - ui->searchToolbar->setEnabled(!isInProgress); + if(!isInProgress) + searchProgressBar->setValue(0); + + ui->actionFindNext->setEnabled(!isInProgress); + ui->actionFindPrevious->setEnabled(!isInProgress); + ui->actionFind->setEnabled(!isInProgress); + ui->actionRegExp->setEnabled(!isInProgress); + stackedWidget->setCurrentIndex(isInProgress ? 1 : 0); + ui->dockWidgetProject->setEnabled(!isInProgress); } diff --git a/src/mainwindow.h b/src/mainwindow.h index aaf969a0..acfaaad6 100644 --- a/src/mainwindow.h +++ b/src/mainwindow.h @@ -30,6 +30,7 @@ #include #include #include +#include #include "tablemodel.h" #include "settingsdialog.h" @@ -140,6 +141,8 @@ class MainWindow : public QMainWindow QLabel *statusSyncFoundReceived; QProgressBar *statusProgressBar; + QStackedWidget* stackedWidget; + unsigned long totalBytesRcvd; unsigned long totalByteErrorsRcvd; unsigned long totalSyncFoundRcvd; @@ -148,6 +151,7 @@ class MainWindow : public QMainWindow SearchDialog *searchDlg; QShortcut *m_shortcut_searchnext; QShortcut *m_shortcut_searchprev; + QProgressBar* searchProgressBar; /* Export */ ExporterDialog exporterDialog; diff --git a/src/searchdialog.cpp b/src/searchdialog.cpp index 3e0d3386..ad19f055 100644 --- a/src/searchdialog.cpp +++ b/src/searchdialog.cpp @@ -85,6 +85,11 @@ void SearchDialog::appendLineEdit(QLineEdit *lineEdit){ lineEdits->append(lineEd QString SearchDialog::getText() { return ui->lineEditText->text(); } +void SearchDialog::cancelSearch() +{ + isSearchCancelled = true; +} + bool SearchDialog::getHeader() { return (ui->checkBoxHeader->checkState() == Qt::Checked); @@ -203,6 +208,8 @@ void SearchDialog::focusRow(long int searchLine) int SearchDialog::find() { + isSearchCancelled = false; + emit addActionHistory(); QRegularExpression searchTextRegExpression; is_TimeStampSearchSelected = false; @@ -410,11 +417,6 @@ void SearchDialog::findMessages(long int searchLine, long int searchBorder, QReg m_searchtablemodel->clear_SearchResults(); - QProgressDialog fileprogress("Searching...", "Abort", 0, file->sizeFilter(), this); - fileprogress.setWindowTitle("DLT Viewer"); - fileprogress.setWindowModality(Qt::NonModal); - fileprogress.show(); - bool msgIdEnabled=QDltSettingsManager::getInstance()->value("startup/showMsgId", true).toBool(); QString msgIdFormat=QDltSettingsManager::getInstance()->value("startup/msgIdFormat", "0x%x").toString(); @@ -441,15 +443,14 @@ void SearchDialog::findMessages(long int searchLine, long int searchBorder, QReg } } - /* Update progress every 0.5% */ - if(searchLine%1000==0) + // Update progress every 0.5% + if(searchLine%1000 == 0) { - fileprogress.setValue(ctr); - if(fileprogress.wasCanceled()) - { + QApplication::processEvents(); + if (isSearchCancelled) { break; } - QApplication::processEvents(); + emit searchProgressValueChanged(static_cast(ctr * 100.0 / file->sizeFilter())); } /* get the message with the selected item id */ diff --git a/src/searchdialog.h b/src/searchdialog.h index 3891a278..1db63e8f 100644 --- a/src/searchdialog.h +++ b/src/searchdialog.h @@ -62,6 +62,8 @@ class SearchDialog : public QDialog void clearCacheHistory(); QString getText(); + void cancelSearch(); + void registerSearchTableModel(SearchTableModel *model); /** * @brief foundLine @@ -78,6 +80,8 @@ class SearchDialog : public QDialog Ui::SearchDialog *ui; SearchTableModel *m_searchtablemodel; + bool isSearchCancelled{false}; + long int startLine; long searchseconds; bool nextClicked; @@ -171,6 +175,7 @@ public slots: void refreshedSearchIndex(); void addActionHistory(); void searchProgressChanged(bool isInProgress); + void searchProgressValueChanged(int progress); }; #endif // SEARCHDIALOG_H