diff --git a/client/findreplace.cpp b/client/findreplace.cpp index 077ef65..eced806 100644 --- a/client/findreplace.cpp +++ b/client/findreplace.cpp @@ -19,12 +19,36 @@ along with this program. If not, see #include "findreplace.h" -FindReplaceDialog::FindReplaceDialog(QWidget *parent) - : QDialog(parent) +#include "../common/protocolmanager.h" + +extern ProtocolManager *OstProtocolManager; + +FindReplaceDialog::FindReplaceDialog(Action *action, QWidget *parent) + : QDialog(parent), action_(action) { setupUi(this); // Keep things simple and don't use mask(s) (default) useFindMask->setChecked(false); useReplaceMask->setChecked(false); + + protocol->addItems(OstProtocolManager->protocolDatabase()); +#if QT_VERSION >= QT_VERSION_CHECK(5, 15, 0) + protocol->setPlaceholderText(tr("Select")); +#endif + protocol->setCurrentIndex(-1); + +#if QT_VERSION >= QT_VERSION_CHECK(5, 15, 0) + field->setPlaceholderText(tr("Select")); +#endif + + // Enable this setting if we have streams selected on input + selectedStreamsOnly->setEnabled(action->selectedStreamsOnly); + + // Reset for user input + action->selectedStreamsOnly = false; +} + +void FindReplaceDialog::on_protocol_currentIndexChanged(const QString &/*name*/) +{ } diff --git a/client/findreplace.h b/client/findreplace.h index c1f37a2..72d858f 100644 --- a/client/findreplace.h +++ b/client/findreplace.h @@ -26,7 +26,27 @@ class FindReplaceDialog: public QDialog, public Ui::FindReplace { Q_OBJECT public: - FindReplaceDialog(QWidget *parent = 0); + struct Action; + + FindReplaceDialog(Action *action, QWidget *parent = 0); + +private slots: + void on_protocol_currentIndexChanged(const QString &name); + +private: + Action *action_{nullptr}; +}; + +struct FindReplaceDialog::Action +{ + quint32 protocolNumber; + quint32 fieldIndex; + QVariant findValue; + QVariant findMask; + QVariant replaceValue; + QVariant replaceMask; + + bool selectedStreamsOnly; // in-out param }; #endif diff --git a/client/streamswidget.cpp b/client/streamswidget.cpp index df245fe..2e46f15 100644 --- a/client/streamswidget.cpp +++ b/client/streamswidget.cpp @@ -304,9 +304,43 @@ void StreamsWidget::on_actionFind_Replace_triggered() { qDebug("Find & Replace Action"); - FindReplaceDialog findReplace(this); + QItemSelectionModel* selectionModel = tvStreamList->selectionModel(); + FindReplaceDialog::Action action; + + action.selectedStreamsOnly = selectionModel->selection().size() > 0 ? + true : false; + + FindReplaceDialog findReplace(&action, this); if (findReplace.exec() == QDialog::Accepted) { - // TODO + int changed = 0; + Port &port = plm->port(currentPortIndex_); + if (action.selectedStreamsOnly) { + foreach(QModelIndex index, selectionModel->selectedRows()) { + Stream *stream = port.mutableStreamByIndex(index.row(), false); + if (stream->findReplace(action.protocolNumber, + action.fieldIndex, + action.findValue, + action.findMask, + action.replaceValue, + action.replaceMask)) + changed++; + } + } else { + int count = tvStreamList->model()->rowCount(); + for (int i = 0; i < count; i++) { + Stream *stream = port.mutableStreamByIndex(i, false); + if (stream->findReplace(action.protocolNumber, + action.fieldIndex, + action.findValue, + action.findMask, + action.replaceValue, + action.replaceMask)) + changed++; + } + } + + if (changed) + port.setLocalConfigChanged(true); } } diff --git a/common/streambase.cpp b/common/streambase.cpp index 36b3c57..a86e3e8 100644 --- a/common/streambase.cpp +++ b/common/streambase.cpp @@ -598,6 +598,14 @@ int StreamBase::frameValue(uchar *buf, int bufMaxSize, int frameIndex, return len; } +bool StreamBase::findReplace(quint32 /*protocolNumber*/, int /*fieldIndex*/, + QVariant /*findValue*/, QVariant /*findMask*/, + QVariant /*replaceValue*/, QVariant /*replaceMask*/) +{ + // TODO + return false; +} + quint64 StreamBase::deviceMacAddress(int frameIndex) const { return getDeviceMacAddress(portId_, int(mStreamId->id()), frameIndex); diff --git a/common/streambase.h b/common/streambase.h index 8a72096..7b496d9 100644 --- a/common/streambase.h +++ b/common/streambase.h @@ -22,6 +22,7 @@ along with this program. If not, see #include #include +#include #include "protocol.pb.h" @@ -141,6 +142,10 @@ public: int frameValue(uchar *buf, int bufMaxSize, int frameIndex, FrameValueAttrib *attrib = nullptr) const; + bool findReplace(quint32 protocolNumber, int fieldIndex, + QVariant findValue, QVariant findMask, + QVariant replaceValue, QVariant replaceMask); + quint64 deviceMacAddress(int frameIndex) const; quint64 neighborMacAddress(int frameIndex) const;