From 6e240e6727279d47c4060695f3afaaf8e37949a3 Mon Sep 17 00:00:00 2001 From: Roland Knall Date: Thu, 29 Aug 2019 11:26:34 +0200 Subject: Qt: Apply Invert/Enable/Disable only to selected list Also, put the search field on top, as this is the default for search fields and apply the change of enable/disable and invert-all only to the selected items, instead of all items. Bug: 16013 Change-Id: If4ef1c5ce63eef6fa72db679cdcbf52dcb0e8fb6 Reviewed-on: https://code.wireshark.org/review/34393 Reviewed-by: Roland Knall --- docbook/release-notes.adoc | 2 +- ui/qt/enabled_protocols_dialog.cpp | 33 ++++++++++-- ui/qt/enabled_protocols_dialog.h | 5 +- ui/qt/enabled_protocols_dialog.ui | 53 ++++++++++--------- ui/qt/models/enabled_protocols_model.cpp | 89 +++++++++++++------------------- ui/qt/models/enabled_protocols_model.h | 28 ++++++++-- 6 files changed, 121 insertions(+), 89 deletions(-) diff --git a/docbook/release-notes.adoc b/docbook/release-notes.adoc index 4bb4310898..79334e161a 100644 --- a/docbook/release-notes.adoc +++ b/docbook/release-notes.adoc @@ -58,7 +58,7 @@ since version 3.0.0: * Editcap can now split files on floating point intervals. * Windows .msi packages are now https://support.microsoft.com/en-us/help/4472027/2019-sha-2-code-signing-support-requirement-for-windows-and-wsus[signed using SHA-2]. .exe installers are still dual-signed using SHA-1 and SHA-2. - +* "Enable Protocols" Dialog now only enables/disables and inverts protocols based on the set filter selection // === Removed Features and Support diff --git a/ui/qt/enabled_protocols_dialog.cpp b/ui/qt/enabled_protocols_dialog.cpp index c9437bce9e..a9fdd94c86 100644 --- a/ui/qt/enabled_protocols_dialog.cpp +++ b/ui/qt/enabled_protocols_dialog.cpp @@ -35,6 +35,10 @@ EnabledProtocolsDialog::EnabledProtocolsDialog(QWidget *parent) : int one_em = ui->protocol_tree_->fontMetrics().height(); ui->protocol_tree_->setColumnWidth(EnabledProtocolsModel::colProtocol, one_em * 18); + ui->cmbSearchType->addItem(tr("Everywhere"), qVariantFromValue(EnabledProtocolsProxyModel::EveryWhere)); + ui->cmbSearchType->addItem(tr("Only Protocols"), qVariantFromValue(EnabledProtocolsProxyModel::OnlyProtocol)); + ui->cmbSearchType->addItem(tr("Only Description"), qVariantFromValue(EnabledProtocolsProxyModel::OnlyDescription)); + QTimer::singleShot(0, this, SLOT(fillTree())); } @@ -55,27 +59,46 @@ void EnabledProtocolsDialog::fillTree() void EnabledProtocolsDialog::on_invert_button__clicked() { - enabled_protocols_model_->invertEnabled(); + proxyModel_->setItemsEnable(EnabledProtocolsProxyModel::Invert); + ui->protocol_tree_->expandAll(); } void EnabledProtocolsDialog::on_enable_all_button__clicked() { - enabled_protocols_model_->enableAll(); + proxyModel_->setItemsEnable(EnabledProtocolsProxyModel::Enable); + ui->protocol_tree_->expandAll(); } void EnabledProtocolsDialog::on_disable_all_button__clicked() { - enabled_protocols_model_->disableAll(); + proxyModel_->setItemsEnable(EnabledProtocolsProxyModel::Disable); + ui->protocol_tree_->expandAll(); } -void EnabledProtocolsDialog::on_search_line_edit__textChanged(const QString &search_re) +void EnabledProtocolsDialog::searchFilterChange() { - proxyModel_->setFilter(search_re); + EnabledProtocolsProxyModel::SearchType type = EnabledProtocolsProxyModel::EveryWhere; + QString search_re = ui->search_line_edit_->text(); + + if ( ui->cmbSearchType->currentData().canConvert() ) + type = ui->cmbSearchType->currentData().value(); + + proxyModel_->setFilter(search_re, type); /* If items are filtered out, then filtered back in, the tree remains collapsed Force an expansion */ ui->protocol_tree_->expandAll(); } +void EnabledProtocolsDialog::on_search_line_edit__textChanged(const QString &) +{ + searchFilterChange(); +} + +void EnabledProtocolsDialog::on_cmbSearchType_currentIndexChanged(int) +{ + searchFilterChange(); +} + void EnabledProtocolsDialog::on_buttonBox_accepted() { enabled_protocols_model_->applyChanges(); diff --git a/ui/qt/enabled_protocols_dialog.h b/ui/qt/enabled_protocols_dialog.h index b42c9189dd..e5a88d2f5e 100644 --- a/ui/qt/enabled_protocols_dialog.h +++ b/ui/qt/enabled_protocols_dialog.h @@ -30,7 +30,8 @@ private slots: void on_invert_button__clicked(); void on_enable_all_button__clicked(); void on_disable_all_button__clicked(); - void on_search_line_edit__textChanged(const QString &search_re); + void on_search_line_edit__textChanged(const QString &); + void on_cmbSearchType_currentIndexChanged(int); void on_buttonBox_accepted(); void on_buttonBox_helpRequested(); void fillTree(); @@ -40,6 +41,8 @@ private: EnabledProtocolsModel* enabled_protocols_model_; EnabledProtocolsProxyModel* proxyModel_; + + void searchFilterChange(); }; #endif // ENABLED_PROTOCOLS_DIALOG_H diff --git a/ui/qt/enabled_protocols_dialog.ui b/ui/qt/enabled_protocols_dialog.ui index 8b2ca7ce50..1c3baf20c5 100644 --- a/ui/qt/enabled_protocols_dialog.ui +++ b/ui/qt/enabled_protocols_dialog.ui @@ -14,6 +14,23 @@ Dialog + + + + + + Search: + + + + + + + + + + + @@ -33,29 +50,6 @@ - - - - Search: - - - - - - - - - - Qt::Horizontal - - - - 40 - 20 - - - - @@ -77,6 +71,19 @@ + + + + Qt::Horizontal + + + + 40 + 20 + + + + diff --git a/ui/qt/models/enabled_protocols_model.cpp b/ui/qt/models/enabled_protocols_model.cpp index e65ac7edd5..a1f5907283 100644 --- a/ui/qt/models/enabled_protocols_model.cpp +++ b/ui/qt/models/enabled_protocols_model.cpp @@ -289,54 +289,6 @@ void EnabledProtocolsModel::populate() emit endResetModel(); } -void EnabledProtocolsModel::invertEnabled() -{ - emit beginResetModel(); - - for (int proto_index = 0; proto_index < root_->childCount(); proto_index++) { - EnabledProtocolItem* proto = root_->child(proto_index); - proto->setEnabled(!proto->enabled()); - for (int heur_index = 0; heur_index < proto->childCount(); heur_index++) { - EnabledProtocolItem* heur = proto->child(heur_index); - heur->setEnabled(!heur->enabled()); - } - } - - emit endResetModel(); -} - -void EnabledProtocolsModel::enableAll() -{ - emit beginResetModel(); - - for (int proto_index = 0; proto_index < root_->childCount(); proto_index++) { - EnabledProtocolItem* proto = root_->child(proto_index); - proto->setEnabled(true); - for (int heur_index = 0; heur_index < proto->childCount(); heur_index++) { - EnabledProtocolItem* heur = proto->child(heur_index); - heur->setEnabled(true); - } - } - - emit endResetModel(); -} - -void EnabledProtocolsModel::disableAll() -{ - emit beginResetModel(); - - for (int proto_index = 0; proto_index < root_->childCount(); proto_index++) { - EnabledProtocolItem* proto = root_->child(proto_index); - proto->setEnabled(false); - for (int heur_index = 0; heur_index < proto->childCount(); heur_index++) { - EnabledProtocolItem* heur = proto->child(heur_index); - heur->setEnabled(false); - } - } - - emit endResetModel(); -} - void EnabledProtocolsModel::applyChanges(bool writeChanges) { bool redissect = false; @@ -377,9 +329,9 @@ void EnabledProtocolsModel::saveChanges(bool writeChanges) EnabledProtocolsProxyModel::EnabledProtocolsProxyModel(QObject * parent) : QSortFilterProxyModel(parent), +type_(EnabledProtocolsProxyModel::EveryWhere), filter_() -{ -} +{} bool EnabledProtocolsProxyModel::lessThan(const QModelIndex &left, const QModelIndex &right) const { @@ -407,10 +359,10 @@ bool EnabledProtocolsProxyModel::filterAcceptItem(EnabledProtocolItem& item) con { QRegExp regex(filter_, Qt::CaseInsensitive); - if (item.name().contains(regex)) + if (item.name().contains(regex) && type_ != OnlyDescription) return true; - if (item.description().contains(regex)) + if (item.description().contains(regex) && type_ != OnlyProtocol) return true; return false; @@ -418,7 +370,6 @@ bool EnabledProtocolsProxyModel::filterAcceptItem(EnabledProtocolItem& item) con bool EnabledProtocolsProxyModel::filterAcceptsRow(int sourceRow, const QModelIndex &sourceParent) const { - QModelIndex nameIdx = sourceModel()->index(sourceRow, EnabledProtocolsModel::colProtocol, sourceParent); EnabledProtocolItem* item = static_cast(nameIdx.internalPointer()); if (item == NULL) @@ -445,12 +396,42 @@ bool EnabledProtocolsProxyModel::filterAcceptsRow(int sourceRow, const QModelInd return true; } -void EnabledProtocolsProxyModel::setFilter(const QString& filter) +void EnabledProtocolsProxyModel::setFilter(const QString& filter, EnabledProtocolsProxyModel::SearchType type) { filter_ = filter; + type_ = type; invalidateFilter(); } +void EnabledProtocolsProxyModel::setItemsEnable(EnabledProtocolsProxyModel::EnableType enableType, QModelIndex parent) +{ + if ( ! sourceModel() ) + return; + + if ( ! parent.isValid() ) + emit beginResetModel(); + + for ( int row = 0; row < rowCount(parent); row++ ) + { + QModelIndex idx = index(row, EnabledProtocolsModel::colProtocol, parent); + + Qt::CheckState enable = idx.data(Qt::CheckStateRole).value(); + if ( enableType == Enable ) + enable = Qt::Checked; + else if ( enableType == Disable ) + enable = Qt::Unchecked; + else + enable = enable == Qt::Checked ? Qt::Unchecked : Qt::Checked; + + sourceModel()->setData(mapToSource(idx), qVariantFromValue(enable), Qt::CheckStateRole); + + setItemsEnable(enableType, idx); + } + + + if ( ! parent.isValid() ) + emit endResetModel(); +} /* * Editor modelines diff --git a/ui/qt/models/enabled_protocols_model.h b/ui/qt/models/enabled_protocols_model.h index a7d6339ca6..89cf3baa7f 100644 --- a/ui/qt/models/enabled_protocols_model.h +++ b/ui/qt/models/enabled_protocols_model.h @@ -55,6 +55,10 @@ public: colLast }; + enum EnableProtocolData { + DATA_ENABLE = Qt::UserRole + }; + QModelIndex index(int row, int column, const QModelIndex & = QModelIndex()) const; QModelIndex parent(const QModelIndex &) const; @@ -69,9 +73,6 @@ public: int columnCount(const QModelIndex &parent = QModelIndex()) const; void populate(); - void invertEnabled(); - void enableAll(); - void disableAll(); void applyChanges(bool writeChanges = true); static void disableProtocol(struct _protocol *protocol); @@ -88,18 +89,35 @@ class EnabledProtocolsProxyModel : public QSortFilterProxyModel Q_OBJECT public: + enum SearchType + { + EveryWhere, + OnlyProtocol, + OnlyDescription + }; + Q_ENUM(SearchType) + explicit EnabledProtocolsProxyModel(QObject * parent = Q_NULLPTR); virtual bool filterAcceptsRow(int sourceRow, const QModelIndex &sourceParent) const; - void setFilter(const QString& filter); + void setFilter(const QString& filter, EnabledProtocolsProxyModel::SearchType type); + + enum EnableType + { + Enable, + Disable, + Invert + }; + + void setItemsEnable(EnabledProtocolsProxyModel::EnableType enable, QModelIndex parent = QModelIndex()); protected: bool lessThan(const QModelIndex &source_left, const QModelIndex &source_right) const; bool filterAcceptItem(EnabledProtocolItem& item) const; private: - + EnabledProtocolsProxyModel::SearchType type_; QString filter_; }; -- cgit v1.2.3