From d239da264c5d0ca2ecfd609ae3eccced939a4c46 Mon Sep 17 00:00:00 2001 From: Michael Mann Date: Fri, 29 Dec 2017 11:23:07 -0500 Subject: Convert preference dialog to use more models. Convert Advanced view and Modules view to use a single base model, loading the preferences once and then filter and display what they need with QSortFilterProxyModel derived classes. Convert the PreferencePane "types" to just strings. This allows a more straightforward relationship between the "special" modules that need custom widgets for preference manipulation and it also removes dependency on preferences_dialog.h for many files. Change-Id: I091deb3061564aa4d1564e9ca1c792715961b083 Reviewed-on: https://code.wireshark.org/review/25134 Reviewed-by: Michael Mann Petri-Dish: Michael Mann Tested-by: Petri Dish Buildbot Reviewed-by: Roland Knall --- ui/qt/widgets/display_filter_edit.cpp | 18 ++---- ui/qt/widgets/display_filter_edit.h | 17 +---- ui/qt/widgets/pref_module_view.cpp | 117 ++++++++++++++++++++++++++++++++++ ui/qt/widgets/pref_module_view.h | 48 ++++++++++++++ 4 files changed, 171 insertions(+), 29 deletions(-) create mode 100644 ui/qt/widgets/pref_module_view.cpp create mode 100644 ui/qt/widgets/pref_module_view.h (limited to 'ui/qt/widgets') diff --git a/ui/qt/widgets/display_filter_edit.cpp b/ui/qt/widgets/display_filter_edit.cpp index 97cdbe96e6..46f832d8dc 100644 --- a/ui/qt/widgets/display_filter_edit.cpp +++ b/ui/qt/widgets/display_filter_edit.cpp @@ -4,19 +4,7 @@ * By Gerald Combs * Copyright 1998 Gerald Combs * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License - * as published by the Free Software Foundation; either version 2 - * of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + * SPDX-License-Identifier: GPL-2.0+ */ #include "config.h" @@ -34,6 +22,8 @@ #include #include #include +#include +#include "wireshark_application.h" #include #include @@ -519,7 +509,7 @@ void DisplayFilterEdit::showFilters() void DisplayFilterEdit::showExpressionPrefs() { - emit showPreferencesDialog(PreferencesDialog::ppFilterExpressions); + emit showPreferencesDialog(PrefsModel::FILTER_BUTTONS_PREFERENCE_TREE_NAME); } void DisplayFilterEdit::applyOrPrepareFilter() diff --git a/ui/qt/widgets/display_filter_edit.h b/ui/qt/widgets/display_filter_edit.h index 84c6307fd4..447d969671 100644 --- a/ui/qt/widgets/display_filter_edit.h +++ b/ui/qt/widgets/display_filter_edit.h @@ -4,19 +4,7 @@ * By Gerald Combs * Copyright 1998 Gerald Combs * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License - * as published by the Free Software Foundation; either version 2 - * of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + * SPDX-License-Identifier: GPL-2.0+ */ #ifndef DISPLAYFILTEREDIT_H @@ -24,7 +12,6 @@ #include -#include #include class QEvent; @@ -87,7 +74,7 @@ signals: void popFilterSyntaxStatus(); void pushFilterSyntaxWarning(const QString&); void filterPackets(QString new_filter, bool force); - void showPreferencesDialog(PreferencesDialog::PreferencesPane start_pane); + void showPreferencesDialog(QString pane_name); }; #endif // DISPLAYFILTEREDIT_H diff --git a/ui/qt/widgets/pref_module_view.cpp b/ui/qt/widgets/pref_module_view.cpp new file mode 100644 index 0000000000..388839260d --- /dev/null +++ b/ui/qt/widgets/pref_module_view.cpp @@ -0,0 +1,117 @@ +/* pref_module_view.cpp + * Tree view of preference module data. + * + * Wireshark - Network traffic analyzer + * By Gerald Combs + * Copyright 1998 Gerald Combs + * + * SPDX-License-Identifier: GPL-2.0+ + */ + +#include "pref_module_view.h" +#include + +#include + +PrefModuleTreeView::PrefModuleTreeView(QWidget *parent) : QTreeView(parent), + appearanceName_(PrefsModel::APPEARANCE_PREFERENCE_TREE_NAME) +{ +} + +void PrefModuleTreeView::setPane(const QString pane_name) +{ + QModelIndex newIndex, modelIndex, appearanceIndex, protocolIndex, statIndex; + QString modelTreeName; + int row; + + //look for the pane name in the main tree before trying children + for (row = 0; row < model()->rowCount(); row++) + { + modelIndex = model()->index(row, ModulePrefsModel::colName); + modelTreeName = model()->data(modelIndex, Qt::DisplayRole).toString(); + + if (modelTreeName.compare(appearanceName_) == 0) { + appearanceIndex = modelIndex; + } else if (modelTreeName.compare("Protocols") == 0) { + protocolIndex = modelIndex; + } else if (modelTreeName.compare("Statistics") == 0) { + statIndex = modelIndex; + } + + if (modelTreeName.compare(pane_name) == 0) { + newIndex = modelIndex; + break; + } + } + + //Look through appearance children + if (!newIndex.isValid()) { + for (row = 0; row < model()->rowCount(appearanceIndex); row++) + { + modelIndex = model()->index(row, ModulePrefsModel::colName, appearanceIndex); + modelTreeName = model()->data(modelIndex, Qt::DisplayRole).toString(); + + if (modelTreeName.compare(pane_name) == 0) { + newIndex = modelIndex; + break; + } + } + } + + //Look through protocol children + if (!newIndex.isValid()) { + for (row = 0; row < model()->rowCount(protocolIndex); row++) + { + modelIndex = model()->index(row, ModulePrefsModel::colName, protocolIndex); + PrefsItem* proto_pref = VariantPointer::asPtr(model()->data(modelIndex, Qt::UserRole)); + if (proto_pref != NULL) { + if (pane_name.compare(proto_pref->getModuleName()) == 0) { + newIndex = modelIndex; + break; + } + } + } + } + + //Look through stat children + if (!newIndex.isValid()) { + for (row = 0; row < model()->rowCount(protocolIndex); row++) + { + modelIndex = model()->index(row, ModulePrefsModel::colName, protocolIndex); + PrefsItem* stat_pref = VariantPointer::asPtr(model()->data(modelIndex, Qt::UserRole)); + if (stat_pref != NULL) { + if (pane_name.compare(stat_pref->getModuleName()) == 0) { + newIndex = modelIndex; + break; + } + } + } + } + + setCurrentIndex(newIndex); +} + + +void PrefModuleTreeView::currentChanged(const QModelIndex ¤t, const QModelIndex &previous) +{ + if (current.isValid()) + { + QString pane_name = model()->data(current, ModulePrefsModel::ModuleName).toString(); + + emit goToPane(pane_name); + } + + QTreeView::currentChanged(current, previous); +} + +/* * Editor modelines + * + * Local Variables: + * c-basic-offset: 4 + * tab-width: 8 + * indent-tabs-mode: nil + * End: + * + * ex: set shiftwidth=4 tabstop=8 expandtab: + * :indentSize=4:tabSize=8:noTabs=true: + */ diff --git a/ui/qt/widgets/pref_module_view.h b/ui/qt/widgets/pref_module_view.h new file mode 100644 index 0000000000..8a1b871bfc --- /dev/null +++ b/ui/qt/widgets/pref_module_view.h @@ -0,0 +1,48 @@ +/* pref_module_view.h + * Tree view of preference module data. + * + * Wireshark - Network traffic analyzer + * By Gerald Combs + * Copyright 1998 Gerald Combs + * + * SPDX-License-Identifier: GPL-2.0+ + */ + +#ifndef PREFERENCE_MODULE_VIEW_H +#define PREFERENCE_MODULE_VIEW_H + +#include +#include + +class PrefModuleTreeView : public QTreeView +{ + Q_OBJECT +public: + PrefModuleTreeView(QWidget *parent = 0); + + void setPane(const QString pane_name); + +signals: + void goToPane(QString pane); + +protected slots: + void currentChanged(const QModelIndex ¤t, const QModelIndex &previous); + +private: + //cache the translation of the module names we check frequently + QString appearanceName_; +}; +#endif // PREFERENCE_MODULE_VIEW_H + +/* + * Editor modelines + * + * Local Variables: + * c-basic-offset: 4 + * tab-width: 8 + * indent-tabs-mode: nil + * End: + * + * ex: set shiftwidth=4 tabstop=8 expandtab: + * :indentSize=4:tabSize=8:noTabs=true: + */ -- cgit v1.2.3