]> sigrok.org Git - pulseview.git/blame - pv/views/decoder_output/view.cpp
Simplify QHexView interfaces
[pulseview.git] / pv / views / decoder_output / view.cpp
CommitLineData
2bdc5796
SA
1/*
2 * This file is part of the PulseView project.
3 *
4 * Copyright (C) 2019 Soeren Apel <soeren@apelpie.net>
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, see <http://www.gnu.org/licenses/>.
18 */
19
20#include <libsigrokdecode/libsigrokdecode.h>
21
bdbc561f 22#include <QLabel>
2bdc5796 23#include <QMenu>
a24412db 24#include <QToolBar>
2bdc5796
SA
25#include <QVBoxLayout>
26
27#include "view.hpp"
560f8377 28#include "QHexView.hpp"
2bdc5796
SA
29
30#include "pv/session.hpp"
31#include "pv/util.hpp"
32
bdbc561f 33using pv::data::SignalBase;
2bdc5796
SA
34using pv::util::TimeUnit;
35using pv::util::Timestamp;
36
37using std::shared_ptr;
38
39namespace pv {
40namespace views {
41namespace decoder_output {
42
a24412db 43View::View(Session &session, bool is_main_view, QMainWindow *parent) :
bdbc561f 44 ViewBase(session, is_main_view, parent),
2bdc5796
SA
45
46 // Note: Place defaults in View::reset_view_state(), not here
861ab3a4 47 signal_selector_(new QComboBox()),
560f8377
SA
48 format_selector_(new QComboBox()),
49 stacked_widget_(new QStackedWidget()),
50 hex_view_(new QHexView())
2bdc5796
SA
51{
52 QVBoxLayout *root_layout = new QVBoxLayout(this);
53 root_layout->setContentsMargins(0, 0, 0, 0);
54
bdbc561f
SA
55 // Create toolbar
56 QToolBar* toolbar = new QToolBar();
57 toolbar->setContextMenuPolicy(Qt::PreventContextMenu);
58 parent->addToolBar(toolbar);
a24412db 59
bdbc561f
SA
60 // Populate toolbar
61 toolbar->addWidget(new QLabel(tr("Decoder:")));
62 toolbar->addWidget(signal_selector_);
861ab3a4
SA
63 toolbar->addSeparator();
64 toolbar->addWidget(new QLabel(tr("Show data as")));
65 toolbar->addWidget(format_selector_);
66
67 // Add format types
68 format_selector_->addItem(tr("Hexdump"), qVariantFromValue(QString("text/hexdump")));
a24412db 69
560f8377
SA
70 // Add widget stack
71 root_layout->addWidget(stacked_widget_);
72 stacked_widget_->addWidget(hex_view_);
73
2bdc5796
SA
74 reset_view_state();
75}
76
77View::~View()
78{
79}
80
db298158
SA
81ViewType View::get_type() const
82{
83 return ViewTypeDecoderOutput;
84}
85
2bdc5796
SA
86void View::reset_view_state()
87{
88 ViewBase::reset_view_state();
89}
90
91void View::clear_signals()
92{
93 ViewBase::clear_signalbases();
94}
95
96void View::clear_decode_signals()
97{
bdbc561f 98 signal_selector_->clear();
861ab3a4 99 format_selector_->setCurrentIndex(0);
2bdc5796
SA
100}
101
102void View::add_decode_signal(shared_ptr<data::DecodeSignal> signal)
103{
104 connect(signal.get(), SIGNAL(name_changed(const QString&)),
bdbc561f
SA
105 this, SLOT(on_signal_name_changed(const QString&)));
106
861ab3a4 107 signal_selector_->addItem(signal->name(), QVariant::fromValue(signal.get()));
2bdc5796
SA
108}
109
110void View::remove_decode_signal(shared_ptr<data::DecodeSignal> signal)
111{
861ab3a4 112 int index = signal_selector_->findData(QVariant::fromValue(signal.get()));
bdbc561f
SA
113
114 if (index != -1)
115 signal_selector_->removeItem(index);
2bdc5796
SA
116}
117
118void View::save_settings(QSettings &settings) const
119{
120 (void)settings;
121}
122
123void View::restore_settings(QSettings &settings)
124{
125 // Note: It is assumed that this function is only called once,
126 // immediately after restoring a previous session.
127 (void)settings;
128}
129
bdbc561f 130void View::on_signal_name_changed(const QString &name)
2bdc5796 131{
bdbc561f
SA
132 SignalBase *sb = qobject_cast<SignalBase*>(QObject::sender());
133 assert(sb);
134
861ab3a4 135 int index = signal_selector_->findData(QVariant::fromValue(sb));
bdbc561f
SA
136 if (index != -1)
137 signal_selector_->setItemText(index, name);
2bdc5796
SA
138}
139
140} // namespace decoder_output
141} // namespace views
142} // namespace pv