aboutsummaryrefslogtreecommitdiffstats
path: root/ui
diff options
context:
space:
mode:
authorRoland Knall <rknall@gmail.com>2019-08-29 11:26:34 +0200
committerRoland Knall <rknall@gmail.com>2019-08-29 10:26:02 +0000
commit6e240e6727279d47c4060695f3afaaf8e37949a3 (patch)
treef717996c721a53042ab49263ac4742526aa1ef18 /ui
parentcd8f720251c7c0ecbdd375cbfebb8b39273f6b84 (diff)
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 <rknall@gmail.com>
Diffstat (limited to 'ui')
-rw-r--r--ui/qt/enabled_protocols_dialog.cpp33
-rw-r--r--ui/qt/enabled_protocols_dialog.h5
-rw-r--r--ui/qt/enabled_protocols_dialog.ui53
-rw-r--r--ui/qt/models/enabled_protocols_model.cpp89
-rw-r--r--ui/qt/models/enabled_protocols_model.h28
5 files changed, 120 insertions, 88 deletions
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<EnabledProtocolsProxyModel::SearchType>() )
+ type = ui->cmbSearchType->currentData().value<EnabledProtocolsProxyModel::SearchType>();
+
+ 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
@@ -15,6 +15,23 @@
</property>
<layout class="QVBoxLayout" name="verticalLayout">
<item>
+ <layout class="QHBoxLayout" name="horizontalLayout_2">
+ <item>
+ <widget class="QLabel" name="label">
+ <property name="text">
+ <string>Search:</string>
+ </property>
+ </widget>
+ </item>
+ <item>
+ <widget class="QLineEdit" name="search_line_edit_"/>
+ </item>
+ <item>
+ <widget class="QComboBox" name="cmbSearchType"/>
+ </item>
+ </layout>
+ </item>
+ <item>
<widget class="QTreeView" name="protocol_tree_">
<property name="sortingEnabled">
<bool>true</bool>
@@ -34,29 +51,6 @@
<item>
<layout class="QHBoxLayout" name="horizontalLayout">
<item>
- <widget class="QLabel" name="label">
- <property name="text">
- <string>Search:</string>
- </property>
- </widget>
- </item>
- <item>
- <widget class="QLineEdit" name="search_line_edit_"/>
- </item>
- <item>
- <spacer name="horizontalSpacer">
- <property name="orientation">
- <enum>Qt::Horizontal</enum>
- </property>
- <property name="sizeHint" stdset="0">
- <size>
- <width>40</width>
- <height>20</height>
- </size>
- </property>
- </spacer>
- </item>
- <item>
<widget class="QPushButton" name="enable_all_button_">
<property name="text">
<string>Enable All</string>
@@ -77,6 +71,19 @@
</property>
</widget>
</item>
+ <item>
+ <spacer name="horizontalSpacer">
+ <property name="orientation">
+ <enum>Qt::Horizontal</enum>
+ </property>
+ <property name="sizeHint" stdset="0">
+ <size>
+ <width>40</width>
+ <height>20</height>
+ </size>
+ </property>
+ </spacer>
+ </item>
</layout>
</item>
<item>
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<EnabledProtocolItem*>(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<Qt::CheckState>();
+ 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_;
};