aboutsummaryrefslogtreecommitdiffstats
path: root/ui/qt/models/decode_as_delegate.cpp
diff options
context:
space:
mode:
authorJohn Thacker <johnthacker@gmail.com>2022-06-14 22:38:34 -0400
committerA Wireshark GitLab Utility <gerald+gitlab-utility@wireshark.org>2022-06-16 03:15:08 +0000
commit2efe338b2e106bd42d63854c7bf5254f25339fff (patch)
treeee36780d5856ce384787c02ed655d8b915fee0ac /ui/qt/models/decode_as_delegate.cpp
parenta159fe125e0ffd5b1d5fc2c06f7dc826c1acf24a (diff)
Qt: Use a combobox for Decode As selectors if there are packet values
Don't require there to be at least two values in a packet for a dissector table in order to have a combobox instead of a single text box. While perhaps having an editable combobox with only one drop down option looks a bit funny, that is outweighed by the UI advantages of being able to easily select the values that occur in the packet. This makes it possible to change the dissector for the currently selected packet's IP protocol or Ethertype when those are not the last protocol layer without having to type it in manually, for example.
Diffstat (limited to 'ui/qt/models/decode_as_delegate.cpp')
-rw-r--r--ui/qt/models/decode_as_delegate.cpp64
1 files changed, 30 insertions, 34 deletions
diff --git a/ui/qt/models/decode_as_delegate.cpp b/ui/qt/models/decode_as_delegate.cpp
index 94c3b8ba39..d2898a46e7 100644
--- a/ui/qt/models/decode_as_delegate.cpp
+++ b/ui/qt/models/decode_as_delegate.cpp
@@ -109,8 +109,7 @@ bool DecodeAsDelegate::isSelectorCombo(DecodeAsItem* item) const
decode_as_t *entry = (decode_as_t *) cur->data;
if ((g_strcmp0(proto_name, entry->name) == 0) &&
(g_strcmp0(item->tableName_, entry->table_name) == 0) &&
- (cap_file_ && cap_file_->edt) &&
- (entry->num_items > 1)) {
+ (cap_file_ && cap_file_->edt)) {
return true;
}
}
@@ -191,6 +190,7 @@ QWidget* DecodeAsDelegate::createEditor(QWidget *parentWidget, const QStyleOptio
}
proto_name = proto.proto_name;
//XXX - break? Or do we always want the last layer of tunnelled protocols?
+ //XXX - Or do we want to add *all* the values from all the layers where the protocol appears to the combobox?
}
}
@@ -199,40 +199,36 @@ QWidget* DecodeAsDelegate::createEditor(QWidget *parentWidget, const QStyleOptio
if ((g_strcmp0(proto_name, entry->name) == 0) &&
(g_strcmp0(item->tableName_, entry->table_name) == 0)) {
if (edt_present) {
- if (entry->num_items > 1)
- {
- //only create a combobox if there is a choice of values, otherwise it looks funny
- cb_editor = new QComboBox(parentWidget);
-
- //Don't limit user to just what's in combo box
- cb_editor->setEditable(true);
-
- cb_editor->setSizeAdjustPolicy(QComboBox::AdjustToContents);
-
- //add the current value of the column
- const QString& current_value = index.model()->data(index, Qt::EditRole).toString();
- if (!current_value.isEmpty())
- cb_editor->addItem(current_value);
-
- //get the value(s) from the packet
- for (uint ni = 0; ni < entry->num_items; ni++) {
- if (entry->values[ni].num_values == 1) { // Skip over multi-value ("both") entries
- QString entryStr = DecodeAsModel::entryString(entry->table_name,
- entry->values[ni].build_values[0](&cap_file_->edt->pi));
- //don't duplicate entries
- if (cb_editor->findText(entryStr) < 0)
- cb_editor->addItem(entryStr);
- }
+ //create a combobox to add the entries from the packet
+ cb_editor = new QComboBox(parentWidget);
+
+ //Don't limit user to just what's in combo box
+ cb_editor->setEditable(true);
+
+ cb_editor->setSizeAdjustPolicy(QComboBox::AdjustToContents);
+
+ //add the current value of the column
+ const QString& current_value = index.model()->data(index, Qt::EditRole).toString();
+ if (!current_value.isEmpty())
+ cb_editor->addItem(current_value);
+
+ //get the value(s) from the packet
+ for (uint ni = 0; ni < entry->num_items; ni++) {
+ if (entry->values[ni].num_values == 1) { // Skip over multi-value ("both") entries
+ QString entryStr = DecodeAsModel::entryString(entry->table_name,
+ entry->values[ni].build_values[0](&cap_file_->edt->pi));
+ //don't duplicate entries
+ if (cb_editor->findText(entryStr) < 0)
+ cb_editor->addItem(entryStr);
}
- cb_editor->setCurrentIndex(entry->default_index_value);
-
- //Make sure the combo box is at least as wide as the column
- QTreeView* parentTree = (QTreeView*)parent();
- int protoColWidth = parentTree->columnWidth(index.column());
- if (protoColWidth > cb_editor->size().width())
- cb_editor->setFixedWidth(protoColWidth);
-
}
+ cb_editor->setCurrentIndex(entry->default_index_value);
+
+ //Make sure the combo box is at least as wide as the column
+ QTreeView* parentTree = (QTreeView*)parent();
+ int protoColWidth = parentTree->columnWidth(index.column());
+ if (protoColWidth > cb_editor->size().width())
+ cb_editor->setFixedWidth(protoColWidth);
}
break;
}