aboutsummaryrefslogtreecommitdiffstats
path: root/ui/qt/widgets/pref_module_view.cpp
blob: bd86590f88aef5410d953a9a05d3a0538b712d42 (plain)
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
100
101
102
103
104
105
106
/* 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::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()) {
        newIndex = findModule(appearanceIndex, pane_name);
    }

    //Look through protocol children
    if (!newIndex.isValid()) {
        newIndex = findModule(protocolIndex, pane_name);
    }

    //Look through stat children
    if (!newIndex.isValid()) {
        newIndex = findModule(statIndex, pane_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;
        }
    }

    return findIndex;
}


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:
 */