Fleshed out some of the find-replace code
This commit is contained in:
parent
990c13e67a
commit
e19083ed3f
@ -19,12 +19,36 @@ along with this program. If not, see <http://www.gnu.org/licenses/>
|
|||||||
|
|
||||||
#include "findreplace.h"
|
#include "findreplace.h"
|
||||||
|
|
||||||
FindReplaceDialog::FindReplaceDialog(QWidget *parent)
|
#include "../common/protocolmanager.h"
|
||||||
: QDialog(parent)
|
|
||||||
|
extern ProtocolManager *OstProtocolManager;
|
||||||
|
|
||||||
|
FindReplaceDialog::FindReplaceDialog(Action *action, QWidget *parent)
|
||||||
|
: QDialog(parent), action_(action)
|
||||||
{
|
{
|
||||||
setupUi(this);
|
setupUi(this);
|
||||||
|
|
||||||
// Keep things simple and don't use mask(s) (default)
|
// Keep things simple and don't use mask(s) (default)
|
||||||
useFindMask->setChecked(false);
|
useFindMask->setChecked(false);
|
||||||
useReplaceMask->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*/)
|
||||||
|
{
|
||||||
}
|
}
|
||||||
|
@ -26,7 +26,27 @@ class FindReplaceDialog: public QDialog, public Ui::FindReplace
|
|||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
public:
|
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
|
#endif
|
||||||
|
@ -304,9 +304,43 @@ void StreamsWidget::on_actionFind_Replace_triggered()
|
|||||||
{
|
{
|
||||||
qDebug("Find & Replace Action");
|
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) {
|
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);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -598,6 +598,14 @@ int StreamBase::frameValue(uchar *buf, int bufMaxSize, int frameIndex,
|
|||||||
return len;
|
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
|
quint64 StreamBase::deviceMacAddress(int frameIndex) const
|
||||||
{
|
{
|
||||||
return getDeviceMacAddress(portId_, int(mStreamId->id()), frameIndex);
|
return getDeviceMacAddress(portId_, int(mStreamId->id()), frameIndex);
|
||||||
|
@ -22,6 +22,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>
|
|||||||
|
|
||||||
#include <QString>
|
#include <QString>
|
||||||
#include <QLinkedList>
|
#include <QLinkedList>
|
||||||
|
#include <QVariant>
|
||||||
|
|
||||||
#include "protocol.pb.h"
|
#include "protocol.pb.h"
|
||||||
|
|
||||||
@ -141,6 +142,10 @@ public:
|
|||||||
int frameValue(uchar *buf, int bufMaxSize, int frameIndex,
|
int frameValue(uchar *buf, int bufMaxSize, int frameIndex,
|
||||||
FrameValueAttrib *attrib = nullptr) const;
|
FrameValueAttrib *attrib = nullptr) const;
|
||||||
|
|
||||||
|
bool findReplace(quint32 protocolNumber, int fieldIndex,
|
||||||
|
QVariant findValue, QVariant findMask,
|
||||||
|
QVariant replaceValue, QVariant replaceMask);
|
||||||
|
|
||||||
quint64 deviceMacAddress(int frameIndex) const;
|
quint64 deviceMacAddress(int frameIndex) const;
|
||||||
quint64 neighborMacAddress(int frameIndex) const;
|
quint64 neighborMacAddress(int frameIndex) const;
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user