aboutsummaryrefslogtreecommitdiffstats
path: root/ui/qt/widgets
diff options
context:
space:
mode:
authorMichael Mann <mmann78@netscape.net>2017-12-29 11:23:07 -0500
committerRoland Knall <rknall@gmail.com>2018-01-04 21:20:59 +0000
commitd239da264c5d0ca2ecfd609ae3eccced939a4c46 (patch)
treeaa5b490fa2d9c1b4b6899a411bbcca03ccc0659d /ui/qt/widgets
parenta79b7986cddf40a8ade57638916951323fff581e (diff)
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 <mmann78@netscape.net> Petri-Dish: Michael Mann <mmann78@netscape.net> Tested-by: Petri Dish Buildbot Reviewed-by: Roland Knall <rknall@gmail.com>
Diffstat (limited to 'ui/qt/widgets')
-rw-r--r--ui/qt/widgets/display_filter_edit.cpp18
-rw-r--r--ui/qt/widgets/display_filter_edit.h17
-rw-r--r--ui/qt/widgets/pref_module_view.cpp117
-rw-r--r--ui/qt/widgets/pref_module_view.h48
4 files changed, 171 insertions, 29 deletions
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 <gerald@wireshark.org>
* 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 <ui/qt/widgets/stock_icon_tool_button.h>
#include <ui/qt/widgets/syntax_line_edit.h>
#include <ui/qt/utils/wireshark_mime_data.h>
+#include <ui/qt/models/pref_models.h>
+#include "wireshark_application.h"
#include <QAction>
#include <QAbstractItemView>
@@ -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 <gerald@wireshark.org>
* 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 <QDrag>
-#include <ui/qt/preferences_dialog.h>
#include <ui/qt/widgets/syntax_line_edit.h>
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 <gerald@wireshark.org>
+ * Copyright 1998 Gerald Combs
+ *
+ * SPDX-License-Identifier: GPL-2.0+
+ */
+
+#include "pref_module_view.h"
+#include <ui/qt/models/pref_models.h>
+
+#include <QHeaderView>
+
+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<PrefsItem>::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<PrefsItem>::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 &current, 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 <gerald@wireshark.org>
+ * Copyright 1998 Gerald Combs
+ *
+ * SPDX-License-Identifier: GPL-2.0+
+ */
+
+#ifndef PREFERENCE_MODULE_VIEW_H
+#define PREFERENCE_MODULE_VIEW_H
+
+#include <config.h>
+#include <QTreeView>
+
+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 &current, 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:
+ */