Show affected field and stream count post replace

This commit is contained in:
Srivats P 2021-12-09 10:14:47 +05:30
parent c1610f4c99
commit a7aa93b9e9

View File

@ -312,42 +312,47 @@ void StreamsWidget::on_actionFind_Replace_triggered()
FindReplaceDialog findReplace(&action, this); FindReplaceDialog findReplace(&action, this);
if (findReplace.exec() == QDialog::Accepted) { if (findReplace.exec() == QDialog::Accepted) {
int changed = 0; int c, fc = 0, sc = 0; // replace counts
Port &port = plm->port(currentPortIndex_); Port &port = plm->port(currentPortIndex_);
// TODO: progress bar // TODO: progress bar
if (action.selectedStreamsOnly) { if (action.selectedStreamsOnly) {
foreach(QModelIndex index, selectionModel->selectedRows()) { foreach(QModelIndex index, selectionModel->selectedRows()) {
Stream *stream = port.mutableStreamByIndex(index.row(), false); Stream *stream = port.mutableStreamByIndex(index.row(), false);
if (stream->protocolFieldReplace(action.protocolNumber, c = stream->protocolFieldReplace(action.protocolNumber,
action.fieldIndex, action.fieldIndex,
action.fieldBitSize, action.fieldBitSize,
action.findValue, action.findValue,
action.findMask, action.findMask,
action.replaceValue, action.replaceValue,
action.replaceMask)) action.replaceMask);
changed++; if (c) {
fc += c;
sc++;
}
} }
} else { } else {
int count = tvStreamList->model()->rowCount(); int count = tvStreamList->model()->rowCount();
for (int i = 0; i < count; i++) { for (int i = 0; i < count; i++) {
Stream *stream = port.mutableStreamByIndex(i, false); Stream *stream = port.mutableStreamByIndex(i, false);
if (stream->protocolFieldReplace(action.protocolNumber, c = stream->protocolFieldReplace(action.protocolNumber,
action.fieldIndex, action.fieldIndex,
action.fieldBitSize, action.fieldBitSize,
action.findValue, action.findValue,
action.findMask, action.findMask,
action.replaceValue, action.replaceValue,
action.replaceMask)) action.replaceMask);
changed++; if (c) {
fc += c;
sc++;
}
} }
} }
if (changed) if (fc)
port.setLocalConfigChanged(true); port.setLocalConfigChanged(true);
// TODO: count # of fields and # of streams changed
QMessageBox::information(this, tr("Find & Replace"), QMessageBox::information(this, tr("Find & Replace"),
tr("%1 streams changed").arg(changed)); tr("%1 fields replaced in %2 streams").arg(fc).arg(sc));
} }
} }