1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
|
/* 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-or-later
*/
#include "pref_module_view.h"
#include <ui/qt/models/pref_models.h>
#include <QHeaderView>
PrefModuleTreeView::PrefModuleTreeView(QWidget *parent) : QTreeView(parent),
appearanceName_(PrefsModel::typeToString(PrefsModel::Appearance))
{
}
void PrefModuleTreeView::setPane(const QString module_name)
{
QModelIndex newIndex, modelIndex, appearanceIndex, protocolIndex, statIndex;
QString moduleName;
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);
moduleName = model()->data(modelIndex, ModulePrefsModel::ModuleName).toString();
if (moduleName.compare(appearanceName_) == 0) {
appearanceIndex = modelIndex;
} else if (moduleName.compare("Protocols") == 0) {
protocolIndex = modelIndex;
} else if (moduleName.compare("Statistics") == 0) {
statIndex = modelIndex;
}
if (moduleName.compare(module_name) == 0) {
newIndex = modelIndex;
break;
}
}
//Look through appearance children
if (!newIndex.isValid()) {
newIndex = findModule(appearanceIndex, module_name);
}
//Look through protocol children
if (!newIndex.isValid()) {
newIndex = findModule(protocolIndex, module_name);
}
//Look through stat children
if (!newIndex.isValid()) {
newIndex = findModule(statIndex, module_name);
}
setCurrentIndex(newIndex);
}
QModelIndex PrefModuleTreeView::findModule(QModelIndex& parent, const QString& name)
{
QModelIndex findIndex, modelIndex;
QString module_name;
for (int row = 0; row < model()->rowCount(parent); row++)
{
modelIndex = model()->index(row, ModulePrefsModel::colName, parent);
module_name = model()->data(modelIndex, ModulePrefsModel::ModuleName).toString();
if (name.compare(module_name) == 0) {
findIndex = modelIndex;
break;
}
if (model()->rowCount(modelIndex) > 0) {
findIndex = findModule(modelIndex, name);
if (findIndex.isValid())
break;
}
}
return findIndex;
}
void PrefModuleTreeView::currentChanged(const QModelIndex ¤t, const QModelIndex &previous)
{
if (current.isValid())
{
QString module_name = model()->data(current, ModulePrefsModel::ModuleName).toString();
emit goToPane(module_name);
}
QTreeView::currentChanged(current, previous);
}
|