diff options
author | Michael Mann <mmann78@netscape.net> | 2017-06-21 23:58:50 -0400 |
---|---|---|
committer | Michael Mann <mmann78@netscape.net> | 2017-06-22 13:07:11 +0000 |
commit | 29e726a606a5bb7b860d8a2f6ee2996c1b4a154e (patch) | |
tree | 361782ab965df7283993ebb45f035bb471b221fc /ui/qt | |
parent | 9fe90b93ce9bbb802f45b93632a78f5261b3f717 (diff) | |
download | wireshark-29e726a606a5bb7b860d8a2f6ee2996c1b4a154e.tar.gz |
Add support for "bool" and "display filter" types for UATs.
Filter expressions needs support for a checkbox (bool) and
string field that verifies display filters.
Change-Id: Idfbffd6cdb5abaee8914126a05d890e834c17306
Reviewed-on: https://code.wireshark.org/review/22340
Petri-Dish: Michael Mann <mmann78@netscape.net>
Tested-by: Petri Dish Buildbot <buildbot-no-reply@wireshark.org>
Reviewed-by: Michael Mann <mmann78@netscape.net>
Diffstat (limited to 'ui/qt')
-rw-r--r-- | ui/qt/uat_delegate.cpp | 14 | ||||
-rw-r--r-- | ui/qt/uat_dialog.cpp | 2 | ||||
-rw-r--r-- | ui/qt/uat_model.cpp | 44 |
3 files changed, 54 insertions, 6 deletions
diff --git a/ui/qt/uat_delegate.cpp b/ui/qt/uat_delegate.cpp index 641edbcc24..09e9ef848b 100644 --- a/ui/qt/uat_delegate.cpp +++ b/ui/qt/uat_delegate.cpp @@ -28,6 +28,9 @@ #include <QEvent> #include <QFileDialog> #include <QLineEdit> +#include <QCheckBox> + +#include "display_filter_edit.h" UatDelegate::UatDelegate(QObject *parent) : QStyledItemDelegate(parent) { @@ -66,6 +69,11 @@ QWidget *UatDelegate::createEditor(QWidget *parent, const QStyleOptionViewItem & // TODO add a live validator? Should SyntaxLineEdit be used? return QStyledItemDelegate::createEditor(parent, option, index); + case PT_TXTMOD_DISPLAY_FILTER: + { + DisplayFilterEdit *editor = new DisplayFilterEdit(parent); + return editor; + } case PT_TXTMOD_HEXBYTES: { // Requires input of the form "ab cd ef" (with possibly no or a colon @@ -81,6 +89,12 @@ QWidget *UatDelegate::createEditor(QWidget *parent, const QStyleOptionViewItem & return editor; } + case PT_TXTMOD_BOOL: + { + // model will handle creating checkbox + return 0; + } + case PT_TXTMOD_NONE: return 0; diff --git a/ui/qt/uat_dialog.cpp b/ui/qt/uat_dialog.cpp index 8a2459a251..ab4d4a9a2d 100644 --- a/ui/qt/uat_dialog.cpp +++ b/ui/qt/uat_dialog.cpp @@ -43,7 +43,7 @@ UatDialog::UatDialog(QWidget *parent, epan_uat *uat) : ui(new Ui::UatDialog), uat_model_(NULL), uat_delegate_(NULL), - uat_(NULL) + uat_(uat) { ui->setupUi(this); if (uat) loadGeometry(0, 0, uat->name); diff --git a/ui/qt/uat_model.cpp b/ui/qt/uat_model.cpp index 29f358a18f..c5310f3a07 100644 --- a/ui/qt/uat_model.cpp +++ b/ui/qt/uat_model.cpp @@ -47,7 +47,13 @@ Qt::ItemFlags UatModel::flags(const QModelIndex &index) const if (!index.isValid()) return 0; + uat_field_t *field = &uat_->fields[index.column()]; + Qt::ItemFlags flags = QAbstractTableModel::flags(index); + if (field->mode == PT_TXTMOD_BOOL) + { + flags |= Qt::ItemIsUserCheckable; + } flags |= Qt::ItemIsEditable; return flags; } @@ -71,6 +77,8 @@ QVariant UatModel::data(const QModelIndex &index, int role) const QString qstr(temp_str); wmem_free(NULL, temp_str); return qstr; + } else if (field->mode == PT_TXTMOD_BOOL) { + return ""; } else { QString qstr(str); g_free(str); @@ -78,6 +86,19 @@ QVariant UatModel::data(const QModelIndex &index, int role) const } } + if ((role == Qt::CheckStateRole) && (field->mode == PT_TXTMOD_BOOL)) + { + char *str = NULL; + guint length = 0; + enum Qt::CheckState state = Qt::Unchecked; + field->cb.tostr(rec, &str, &length, field->cbdata.tostr, field->fld_data); + if (g_strcmp0(str, "TRUE") == 0) + state = Qt::Checked; + + g_free(str); + return state; + } + if (role == Qt::UserRole) { return QVariant::fromValue(static_cast<void *>(field)); } @@ -133,7 +154,13 @@ int UatModel::columnCount(const QModelIndex &parent) const bool UatModel::setData(const QModelIndex &index, const QVariant &value, int role) { - if (!index.isValid() || role != Qt::EditRole) + if (!index.isValid()) + return false; + + uat_field_t *field = &uat_->fields[index.column()]; + + if ((role != Qt::EditRole) && + ((field->mode == PT_TXTMOD_BOOL) && (role != Qt::CheckStateRole))) return false; if (data(index, role) == value) { @@ -142,13 +169,20 @@ bool UatModel::setData(const QModelIndex &index, const QVariant &value, int role } const int row = index.row(); - uat_field_t *field = &uat_->fields[index.column()]; void *rec = UAT_INDEX_PTR(uat_, row); //qDebug() << "Changing (" << row << "," << index.column() << ") from " << data(index, Qt::EditRole) << " to " << value; - const QByteArray &str = value.toString().toUtf8(); - const QByteArray &bytes = field->mode == PT_TXTMOD_HEXBYTES ? QByteArray::fromHex(str) : str; - field->cb.set(rec, bytes.constData(), (unsigned) bytes.size(), field->cbdata.set, field->fld_data); + if (field->mode != PT_TXTMOD_BOOL) { + const QByteArray &str = value.toString().toUtf8(); + const QByteArray &bytes = field->mode == PT_TXTMOD_HEXBYTES ? QByteArray::fromHex(str) : str; + field->cb.set(rec, bytes.constData(), (unsigned) bytes.size(), field->cbdata.set, field->fld_data); + } else { + if (value == Qt::Checked) { + field->cb.set(rec, "TRUE", 4, field->cbdata.set, field->fld_data); + } else { + field->cb.set(rec, "FALSE", 5, field->cbdata.set, field->fld_data); + } + } QVector<int> roles; roles << role; |