diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 6877e1cc..0397328f 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -48,8 +48,11 @@ add_executable(dlt-viewer dltfileindexerdefaultfilterthread.cpp mcudpsocket.cpp sortfilterproxymodel.cpp + searchform.h + searchform.cpp ${UI_RESOURCES_RCC} - resources/dlt_viewer.rc) + resources/dlt_viewer.rc + ) target_link_libraries(dlt-viewer qdlt diff --git a/src/mainwindow.cpp b/src/mainwindow.cpp index 438f31a5..04033c96 100644 --- a/src/mainwindow.cpp +++ b/src/mainwindow.cpp @@ -509,26 +509,25 @@ void MainWindow::initView() statusBar()->addWidget(statusProgressBar); /* Create search text box */ - searchTextbox = new QLineEdit(); - searchDlg->appendLineEdit(searchTextbox); + searchInput = new SearchForm; + connect(searchInput, &SearchForm::abortSearch, searchDlg, &SearchDialog::abortSearch); + searchDlg->appendLineEdit(searchInput->input()); - connect(searchTextbox, SIGNAL(textChanged(QString)),searchDlg,SLOT(textEditedFromToolbar(QString))); - connect(searchTextbox, SIGNAL(returnPressed()), this, SLOT(on_actionFindNext())); - connect(searchTextbox, SIGNAL(returnPressed()),searchDlg,SLOT(findNextClicked())); + connect(searchInput->input(), SIGNAL(textChanged(QString)),searchDlg,SLOT(textEditedFromToolbar(QString))); + connect(searchInput->input(), SIGNAL(returnPressed()), this, SLOT(on_actionFindNext())); + connect(searchInput->input(), SIGNAL(returnPressed()),searchDlg,SLOT(findNextClicked())); connect(searchDlg, SIGNAL(searchProgressChanged(bool)), this, SLOT(onSearchProgressChanged(bool))); + connect(searchDlg, &SearchDialog::searchProgressValueChanged, this, [this](int progress){ + searchInput->setProgress(progress); + }); connect(settingsDlg, SIGNAL(FilterPathChanged()), this, SLOT(on_actionDefault_Filter_Reload_triggered())); connect(settingsDlg, SIGNAL(PluginsAutoloadChanged()), this, SLOT(triggerPluginsAutoload())); QAction *focusSearchTextbox = new QAction(this); focusSearchTextbox->setShortcut(Qt::Key_L | Qt::CTRL); - connect(focusSearchTextbox, SIGNAL(triggered()), searchTextbox, SLOT(setFocus())); + connect(focusSearchTextbox, SIGNAL(triggered()), searchInput->input(), SLOT(setFocus())); addAction(focusSearchTextbox); - searchComboBox = new QComboBox(); - searchComboBox->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed); - searchComboBox->setLineEdit(searchTextbox); - searchComboBox->setInsertPolicy(QComboBox::InsertAtTop); - /* Initialize toolbars. Most of the construction and connection is done via the * UI file. See mainwindow.ui, ActionEditor and Signal & Slots editor */ QList mainActions = ui->mainToolBar->actions(); @@ -581,8 +580,9 @@ void MainWindow::initSignalConnections() connect(searchDlg,SIGNAL(addActionHistory()),this,SLOT(onAddActionToHistory())); /* Insert search text box to search toolbar, before previous button */ + QAction *before = m_searchActions.at(ToolbarPosition::FindPrevious); - ui->searchToolbar->insertWidget(before, searchComboBox); + ui->searchToolbar->insertWidget(before, searchInput); /* 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); @@ -2372,9 +2372,9 @@ void MainWindow::on_action_menuFile_Quit_triggered() void MainWindow::on_actionFindNext() { //qDebug() << "on_actionFindNext" << __LINE__; - if(!searchTextbox->text().isEmpty() && !list.contains(searchTextbox->text())) + if(!searchInput->input()->text().isEmpty() && !list.contains(searchInput->input()->text())) { - list.append(searchTextbox->text()); + list.append(searchInput->input()->text()); } QString title = "Search Results"; @@ -2385,7 +2385,7 @@ void MainWindow::on_actionFindNext() ui->dockWidgetSearchIndex->setWindowTitle(title); ui->dockWidgetSearchIndex->show(); m_CompleterModel.setStringList(list); - searchTextbox->setCompleter(newCompleter); + searchInput->input()->setCompleter(newCompleter); } void MainWindow::on_action_menuProject_New_triggered() @@ -8411,7 +8411,15 @@ void MainWindow::onSearchProgressChanged(bool isInProgress) isSearchOngoing = isInProgress; ui->menuBar->setEnabled(!isInProgress); ui->mainToolBar->setEnabled(!isInProgress); - ui->searchToolbar->setEnabled(!isInProgress); + if(!isInProgress) + searchInput->resetProgress(); + + ui->actionFindNext->setEnabled(!isInProgress); + ui->actionFindPrevious->setEnabled(!isInProgress); + ui->actionFind->setEnabled(!isInProgress); + ui->actionRegExp->setEnabled(!isInProgress); + searchInput->setState(isInProgress ? SearchForm::State::PROGRESS : SearchForm::State::INPUT); + ui->dockWidgetProject->setEnabled(!isInProgress); } diff --git a/src/mainwindow.h b/src/mainwindow.h index aaf969a0..de79fb22 100644 --- a/src/mainwindow.h +++ b/src/mainwindow.h @@ -41,6 +41,7 @@ #include "searchtablemodel.h" #include "sortfilterproxymodel.h" #include "ui_mainwindow.h" +#include "searchform.h" /** @@ -148,6 +149,7 @@ class MainWindow : public QMainWindow SearchDialog *searchDlg; QShortcut *m_shortcut_searchnext; QShortcut *m_shortcut_searchprev; + SearchForm* searchInput; /* Export */ ExporterDialog exporterDialog; @@ -155,8 +157,6 @@ class MainWindow : public QMainWindow /* Settings dialog containing also the settings parameter itself */ SettingsDialog *settingsDlg; QDltSettingsManager *settings; - QLineEdit *searchTextbox; - QComboBox *searchComboBox; /* injections */ QString injectionAplicationId; diff --git a/src/searchdialog.cpp b/src/searchdialog.cpp index afb04580..5370ff50 100644 --- a/src/searchdialog.cpp +++ b/src/searchdialog.cpp @@ -84,6 +84,11 @@ void SearchDialog::appendLineEdit(QLineEdit *lineEdit){ lineEdits->append(lineEd QString SearchDialog::getText() { return ui->lineEditText->text(); } +void SearchDialog::abortSearch() +{ + isSearchCancelled = true; +} + bool SearchDialog::getHeader() { return (ui->checkBoxHeader->checkState() == Qt::Checked); @@ -189,6 +194,8 @@ void SearchDialog::focusRow(long int searchLine) int SearchDialog::find() { + isSearchCancelled = false; + emit addActionHistory(); QRegularExpression searchTextRegExpression; is_TimeStampSearchSelected = false; @@ -371,11 +378,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(); @@ -413,15 +415,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 0513a844..65538609 100644 --- a/src/searchdialog.h +++ b/src/searchdialog.h @@ -78,6 +78,8 @@ class SearchDialog : public QDialog Ui::SearchDialog *ui; SearchTableModel *m_searchtablemodel; + bool isSearchCancelled{false}; + long int startLine; long searchseconds; bool nextClicked; @@ -155,11 +157,13 @@ public slots: void findNextClicked(); void findPreviousClicked(); void loadSearchHistory(); + void abortSearch(); signals: void refreshedSearchIndex(); void addActionHistory(); void searchProgressChanged(bool isInProgress); + void searchProgressValueChanged(int progress); }; #endif // SEARCHDIALOG_H diff --git a/src/searchform.cpp b/src/searchform.cpp new file mode 100644 index 00000000..25d33024 --- /dev/null +++ b/src/searchform.cpp @@ -0,0 +1,48 @@ +#include "searchform.h" +#include "ui_searchform.h" + +#include + +SearchForm::SearchForm(QWidget *parent) + : QWidget(parent) + , ui(new Ui::SearchForm) +{ + ui->setupUi(this); + + ui->comboBox->setLineEdit(new QLineEdit); + ui->comboBox->setInsertPolicy(QComboBox::InsertAtTop); + + connect (ui->abortButton, &QPushButton::clicked, this, &SearchForm::abortSearch); +} + +SearchForm::~SearchForm() +{ + delete ui; +} + +QLineEdit *SearchForm::input() const +{ + return ui->comboBox->lineEdit(); +} + +void SearchForm::setState(State state) +{ + switch(state) { + case State::INPUT: + ui->stackedWidget->setCurrentIndex(0); + break; + case State::PROGRESS: + ui->stackedWidget->setCurrentIndex(1); + break; + } +} + +void SearchForm::setProgress(int val) +{ + ui->progressBar->setValue(val); +} + +void SearchForm::resetProgress() +{ + setProgress(0); +} diff --git a/src/searchform.h b/src/searchform.h new file mode 100644 index 00000000..117a8a17 --- /dev/null +++ b/src/searchform.h @@ -0,0 +1,38 @@ +#ifndef SEARCHFORM_H +#define SEARCHFORM_H + +#include + +namespace Ui { +class SearchForm; +} + +class QLineEdit; + +class SearchForm : public QWidget +{ + Q_OBJECT + +public: + enum class State { + INPUT, + PROGRESS + }; + + explicit SearchForm(QWidget *parent = nullptr); + ~SearchForm(); + + QLineEdit* input() const; + + void setState(State state); + void setProgress(int val); + void resetProgress(); + +signals: + void abortSearch(); + +private: + Ui::SearchForm *ui; +}; + +#endif // SEARCHFORM_H diff --git a/src/searchform.ui b/src/searchform.ui new file mode 100644 index 00000000..c862576c --- /dev/null +++ b/src/searchform.ui @@ -0,0 +1,81 @@ + + + SearchForm + + + + 0 + 0 + 260 + 40 + + + + Form + + + + 0 + + + 0 + + + + + + + 0 + + + 0 + + + + + + 1 + 0 + + + + + + + + + + 0 + + + 0 + + + + + + 1 + 0 + + + + 24 + + + + + + + Abort + + + + + + + + + + + + diff --git a/src/src.pro b/src/src.pro index e79c94df..423afb2b 100644 --- a/src/src.pro +++ b/src/src.pro @@ -131,6 +131,7 @@ SOURCES += main.cpp \ settingsdialog.cpp \ injectiondialog.cpp \ searchdialog.cpp \ + searchform.cpp \ multiplecontextdialog.cpp \ sortfilterproxymodel.cpp \ tablemodel.cpp \ @@ -161,6 +162,7 @@ HEADERS += mainwindow.h \ settingsdialog.h \ injectiondialog.h \ searchdialog.h \ + searchform.h \ sortfilterproxymodel.h \ version.h \ multiplecontextdialog.h \ @@ -189,6 +191,7 @@ FORMS += mainwindow.ui \ contextdialog.ui \ filterdialog.ui \ plugindialog.ui \ + searchform.ui \ settingsdialog.ui \ injectiondialog.ui \ searchdialog.ui \