diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-10 20:34:10 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-10 20:34:10 +0000 |
commit | e4ba6dbc3f1e76890b22773807ea37fe8fa2b1bc (patch) | |
tree | 68cb5ef9081156392f1dd62a00c6ccc1451b93df /ui/qt/models/pref_delegate.cpp | |
parent | Initial commit. (diff) | |
download | wireshark-e4ba6dbc3f1e76890b22773807ea37fe8fa2b1bc.tar.xz wireshark-e4ba6dbc3f1e76890b22773807ea37fe8fa2b1bc.zip |
Adding upstream version 4.2.2.upstream/4.2.2
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'ui/qt/models/pref_delegate.cpp')
-rw-r--r-- | ui/qt/models/pref_delegate.cpp | 85 |
1 files changed, 85 insertions, 0 deletions
diff --git a/ui/qt/models/pref_delegate.cpp b/ui/qt/models/pref_delegate.cpp new file mode 100644 index 00000000..e33bb13f --- /dev/null +++ b/ui/qt/models/pref_delegate.cpp @@ -0,0 +1,85 @@ +/* pref_delegate.cpp + * Delegates for editing prefereneces. + * + * Wireshark - Network traffic analyzer + * By Gerald Combs <gerald@wireshark.org> + * Copyright 1998 Gerald Combs + * + * SPDX-License-Identifier: GPL-2.0-or-later + */ + +#include <ui/qt/models/pref_delegate.h> +#include <epan/prefs-int.h> + +#include <ui/qt/manager/preference_manager.h> +#include <ui/qt/manager/wireshark_preference.h> + +AdvancedPrefDelegate::AdvancedPrefDelegate(QObject *parent) : QStyledItemDelegate(parent) +{ +} + +PrefsItem* AdvancedPrefDelegate::indexToPref(const QModelIndex &index) const +{ + const QVariant v = index.model()->data(index, Qt::UserRole); + return VariantPointer<PrefsItem>::asPtr(v); +} + +QWidget *AdvancedPrefDelegate::createEditor(QWidget *parent, const QStyleOptionViewItem &option, + const QModelIndex &index) const +{ + PrefsItem* pref; + QString filename; + + switch(index.column()) + { + case AdvancedPrefsModel::colName: + case AdvancedPrefsModel::colStatus: + case AdvancedPrefsModel::colType: + //If user clicks on any of these columns, reset preference back to default + //There is no need to launch an editor + const_cast<QAbstractItemModel*>(index.model())->setData(index, QVariant(), Qt::EditRole); + break; + case AdvancedPrefsModel::colValue: + pref = indexToPref(index); + WiresharkPreference * wspref = PreferenceManager::instance()->getPreference(pref); + if (wspref) { + QWidget *editor = wspref->editor(parent, option, index); + if (editor) { + editor->setAutoFillBackground(true); + } + return editor; + } + break; + } + + return Q_NULLPTR; +} + +void AdvancedPrefDelegate::setEditorData(QWidget *editor, const QModelIndex &index) const +{ + PrefsItem* pref = indexToPref(index); + + WiresharkPreference * wspref = PreferenceManager::instance()->getPreference(pref); + if (wspref) + { + wspref->setData(editor, index); + return; + } + + Q_ASSERT(FALSE); +} + +void AdvancedPrefDelegate::setModelData(QWidget *editor, QAbstractItemModel *model, + const QModelIndex &index) const +{ + PrefsItem* pref = indexToPref(index); + + WiresharkPreference * wspref = PreferenceManager::instance()->getPreference(pref); + if (wspref) + { + wspref->setModelData(editor, model, index); + return; + } + + Q_ASSERT(FALSE); +} |