Skip to content

Commit

Permalink
replace progress dialog with built-in progress bar
Browse files Browse the repository at this point in the history
  • Loading branch information
vifactor committed Jul 25, 2024
1 parent 7024a1a commit 8b33d96
Show file tree
Hide file tree
Showing 4 changed files with 57 additions and 13 deletions.
38 changes: 36 additions & 2 deletions src/mainwindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,8 @@
#include <QTemporaryFile>
#include <QtEndian>

#include <QStackedWidget>

/**
* From QDlt.
* Must be a "C" include to interpret the imports correctly
Expand Down Expand Up @@ -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()));

Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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);
}

Expand Down
4 changes: 4 additions & 0 deletions src/mainwindow.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
#include <QProgressBar>
#include <QCompleter>
#include <QStringListModel>
#include <QStackedWidget>

#include "tablemodel.h"
#include "settingsdialog.h"
Expand Down Expand Up @@ -140,6 +141,8 @@ class MainWindow : public QMainWindow
QLabel *statusSyncFoundReceived;
QProgressBar *statusProgressBar;

QStackedWidget* stackedWidget;

unsigned long totalBytesRcvd;
unsigned long totalByteErrorsRcvd;
unsigned long totalSyncFoundRcvd;
Expand All @@ -148,6 +151,7 @@ class MainWindow : public QMainWindow
SearchDialog *searchDlg;
QShortcut *m_shortcut_searchnext;
QShortcut *m_shortcut_searchprev;
QProgressBar* searchProgressBar;

/* Export */
ExporterDialog exporterDialog;
Expand Down
23 changes: 12 additions & 11 deletions src/searchdialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -203,6 +208,8 @@ void SearchDialog::focusRow(long int searchLine)

int SearchDialog::find()
{
isSearchCancelled = false;

emit addActionHistory();
QRegularExpression searchTextRegExpression;
is_TimeStampSearchSelected = false;
Expand Down Expand Up @@ -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();

Expand All @@ -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<int>(ctr * 100.0 / file->sizeFilter()));
}

/* get the message with the selected item id */
Expand Down
5 changes: 5 additions & 0 deletions src/searchdialog.h
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,8 @@ class SearchDialog : public QDialog
void clearCacheHistory();
QString getText();

void cancelSearch();

void registerSearchTableModel(SearchTableModel *model);
/**
* @brief foundLine
Expand All @@ -78,6 +80,8 @@ class SearchDialog : public QDialog
Ui::SearchDialog *ui;
SearchTableModel *m_searchtablemodel;

bool isSearchCancelled{false};

long int startLine;
long searchseconds;
bool nextClicked;
Expand Down Expand Up @@ -171,6 +175,7 @@ public slots:
void refreshedSearchIndex();
void addActionHistory();
void searchProgressChanged(bool isInProgress);
void searchProgressValueChanged(int progress);
};

#endif // SEARCHDIALOG_H

0 comments on commit 8b33d96

Please sign in to comment.