2 * This file is part of the PulseView project.
4 * Copyright (C) 2019 Soeren Apel <soeren@apelpie.net>
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.
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.
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/>.
20 #include <libsigrokdecode/libsigrokdecode.h>
25 #include <QVBoxLayout>
28 #include "QHexView.hpp"
30 #include "pv/session.hpp"
31 #include "pv/util.hpp"
33 using pv::data::SignalBase;
34 using pv::util::TimeUnit;
35 using pv::util::Timestamp;
37 using std::shared_ptr;
41 namespace decoder_output {
43 View::View(Session &session, bool is_main_view, QMainWindow *parent) :
44 ViewBase(session, is_main_view, parent),
46 // Note: Place defaults in View::reset_view_state(), not here
47 signal_selector_(new QComboBox()),
48 format_selector_(new QComboBox()),
49 stacked_widget_(new QStackedWidget()),
50 hex_view_(new QHexView())
52 QVBoxLayout *root_layout = new QVBoxLayout(this);
53 root_layout->setContentsMargins(0, 0, 0, 0);
56 QToolBar* toolbar = new QToolBar();
57 toolbar->setContextMenuPolicy(Qt::PreventContextMenu);
58 parent->addToolBar(toolbar);
61 toolbar->addWidget(new QLabel(tr("Decoder:")));
62 toolbar->addWidget(signal_selector_);
63 toolbar->addSeparator();
64 toolbar->addWidget(new QLabel(tr("Show data as")));
65 toolbar->addWidget(format_selector_);
68 format_selector_->addItem(tr("Hexdump"), qVariantFromValue(QString("text/hexdump")));
71 root_layout->addWidget(stacked_widget_);
72 stacked_widget_->addWidget(hex_view_);
81 ViewType View::get_type() const
83 return ViewTypeDecoderOutput;
86 void View::reset_view_state()
88 ViewBase::reset_view_state();
91 void View::clear_signals()
93 ViewBase::clear_signalbases();
96 void View::clear_decode_signals()
98 signal_selector_->clear();
99 format_selector_->setCurrentIndex(0);
102 void View::add_decode_signal(shared_ptr<data::DecodeSignal> signal)
104 connect(signal.get(), SIGNAL(name_changed(const QString&)),
105 this, SLOT(on_signal_name_changed(const QString&)));
107 signal_selector_->addItem(signal->name(), QVariant::fromValue(signal.get()));
110 void View::remove_decode_signal(shared_ptr<data::DecodeSignal> signal)
112 int index = signal_selector_->findData(QVariant::fromValue(signal.get()));
115 signal_selector_->removeItem(index);
118 void View::save_settings(QSettings &settings) const
123 void View::restore_settings(QSettings &settings)
125 // Note: It is assumed that this function is only called once,
126 // immediately after restoring a previous session.
130 void View::on_signal_name_changed(const QString &name)
132 SignalBase *sb = qobject_cast<SignalBase*>(QObject::sender());
135 int index = signal_selector_->findData(QVariant::fromValue(sb));
137 signal_selector_->setItemText(index, name);
140 } // namespace decoder_output