From fb91a094fc3898d2233ec6726e404373bc39715e Mon Sep 17 00:00:00 2001 From: Srivats P Date: Sat, 11 Dec 2021 12:36:33 +0530 Subject: [PATCH] Show find-replace progress bar --- client/findreplace.cpp | 3 +++ client/findreplace.h | 1 + client/streamswidget.cpp | 16 +++++++++++++++- 3 files changed, 19 insertions(+), 1 deletion(-) diff --git a/client/findreplace.cpp b/client/findreplace.cpp index e75189b..ef2a1a5 100644 --- a/client/findreplace.cpp +++ b/client/findreplace.cpp @@ -139,6 +139,9 @@ void FindReplaceDialog::on_field_currentIndexChanged(int index) void FindReplaceDialog::on_buttonBox_accepted() { FieldAttrib fieldAttrib = fieldAttrib_.at(field->currentIndex()); + action_->protocolField = QString("%1 %2") + .arg(protocol->currentText()) + .arg(field->currentText()); action_->protocolNumber = protocolId_; action_->fieldIndex = fieldAttrib.index; action_->fieldBitSize = fieldAttrib.bitSize; diff --git a/client/findreplace.h b/client/findreplace.h index 0e52879..129c2d0 100644 --- a/client/findreplace.h +++ b/client/findreplace.h @@ -45,6 +45,7 @@ private: struct FindReplaceDialog::Action { + QString protocolField; quint32 protocolNumber; quint32 fieldIndex; int fieldBitSize; diff --git a/client/streamswidget.cpp b/client/streamswidget.cpp index a43b474..b4ba28c 100644 --- a/client/streamswidget.cpp +++ b/client/streamswidget.cpp @@ -312,11 +312,18 @@ void StreamsWidget::on_actionFind_Replace_triggered() FindReplaceDialog findReplace(&action, this); if (findReplace.exec() == QDialog::Accepted) { + QProgressDialog progress(this); + progress.setLabelText(tr("Replacing %1 ...").arg(action.protocolField)); + progress.setWindowModality(Qt::WindowModal); int c, fc = 0, sc = 0; // replace counts Port &port = plm->port(currentPortIndex_); // TODO: progress bar if (action.selectedStreamsOnly) { - foreach(QModelIndex index, selectionModel->selectedRows()) { + QModelIndexList selected = selectionModel->selectedRows(); + int count = selected.size(); + progress.setMaximum(count); + for (int i = 0; i < count; i++) { + QModelIndex index = selected.at(i); Stream *stream = port.mutableStreamByIndex(index.row(), false); c = stream->protocolFieldReplace(action.protocolNumber, action.fieldIndex, @@ -329,9 +336,13 @@ void StreamsWidget::on_actionFind_Replace_triggered() fc += c; sc++; } + progress.setValue(i+1); + if (progress.wasCanceled()) + break; } } else { int count = tvStreamList->model()->rowCount(); + progress.setMaximum(count); for (int i = 0; i < count; i++) { Stream *stream = port.mutableStreamByIndex(i, false); c = stream->protocolFieldReplace(action.protocolNumber, @@ -345,6 +356,9 @@ void StreamsWidget::on_actionFind_Replace_triggered() fc += c; sc++; } + progress.setValue(i+1); + if (progress.wasCanceled()) + break; } }