]>
Commit | Line | Data |
---|---|---|
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" | |
28 | ||
29 | #include "pv/session.hpp" | |
30 | #include "pv/util.hpp" | |
31 | ||
bdbc561f | 32 | using pv::data::SignalBase; |
2bdc5796 SA |
33 | using pv::util::TimeUnit; |
34 | using pv::util::Timestamp; | |
35 | ||
36 | using std::shared_ptr; | |
37 | ||
38 | namespace pv { | |
39 | namespace views { | |
40 | namespace decoder_output { | |
41 | ||
a24412db | 42 | View::View(Session &session, bool is_main_view, QMainWindow *parent) : |
bdbc561f | 43 | ViewBase(session, is_main_view, parent), |
2bdc5796 SA |
44 | |
45 | // Note: Place defaults in View::reset_view_state(), not here | |
861ab3a4 SA |
46 | signal_selector_(new QComboBox()), |
47 | format_selector_(new QComboBox()) | |
2bdc5796 SA |
48 | { |
49 | QVBoxLayout *root_layout = new QVBoxLayout(this); | |
50 | root_layout->setContentsMargins(0, 0, 0, 0); | |
51 | ||
bdbc561f SA |
52 | // Create toolbar |
53 | QToolBar* toolbar = new QToolBar(); | |
54 | toolbar->setContextMenuPolicy(Qt::PreventContextMenu); | |
55 | parent->addToolBar(toolbar); | |
a24412db | 56 | |
bdbc561f SA |
57 | // Populate toolbar |
58 | toolbar->addWidget(new QLabel(tr("Decoder:"))); | |
59 | toolbar->addWidget(signal_selector_); | |
861ab3a4 SA |
60 | toolbar->addSeparator(); |
61 | toolbar->addWidget(new QLabel(tr("Show data as"))); | |
62 | toolbar->addWidget(format_selector_); | |
63 | ||
64 | // Add format types | |
65 | format_selector_->addItem(tr("Hexdump"), qVariantFromValue(QString("text/hexdump"))); | |
a24412db | 66 | |
2bdc5796 SA |
67 | reset_view_state(); |
68 | } | |
69 | ||
70 | View::~View() | |
71 | { | |
72 | } | |
73 | ||
db298158 SA |
74 | ViewType View::get_type() const |
75 | { | |
76 | return ViewTypeDecoderOutput; | |
77 | } | |
78 | ||
2bdc5796 SA |
79 | void View::reset_view_state() |
80 | { | |
81 | ViewBase::reset_view_state(); | |
82 | } | |
83 | ||
84 | void View::clear_signals() | |
85 | { | |
86 | ViewBase::clear_signalbases(); | |
87 | } | |
88 | ||
89 | void View::clear_decode_signals() | |
90 | { | |
bdbc561f | 91 | signal_selector_->clear(); |
861ab3a4 | 92 | format_selector_->setCurrentIndex(0); |
2bdc5796 SA |
93 | } |
94 | ||
95 | void View::add_decode_signal(shared_ptr<data::DecodeSignal> signal) | |
96 | { | |
97 | connect(signal.get(), SIGNAL(name_changed(const QString&)), | |
bdbc561f SA |
98 | this, SLOT(on_signal_name_changed(const QString&))); |
99 | ||
861ab3a4 | 100 | signal_selector_->addItem(signal->name(), QVariant::fromValue(signal.get())); |
2bdc5796 SA |
101 | } |
102 | ||
103 | void View::remove_decode_signal(shared_ptr<data::DecodeSignal> signal) | |
104 | { | |
861ab3a4 | 105 | int index = signal_selector_->findData(QVariant::fromValue(signal.get())); |
bdbc561f SA |
106 | |
107 | if (index != -1) | |
108 | signal_selector_->removeItem(index); | |
2bdc5796 SA |
109 | } |
110 | ||
111 | void View::save_settings(QSettings &settings) const | |
112 | { | |
113 | (void)settings; | |
114 | } | |
115 | ||
116 | void View::restore_settings(QSettings &settings) | |
117 | { | |
118 | // Note: It is assumed that this function is only called once, | |
119 | // immediately after restoring a previous session. | |
120 | (void)settings; | |
121 | } | |
122 | ||
bdbc561f | 123 | void View::on_signal_name_changed(const QString &name) |
2bdc5796 | 124 | { |
bdbc561f SA |
125 | SignalBase *sb = qobject_cast<SignalBase*>(QObject::sender()); |
126 | assert(sb); | |
127 | ||
861ab3a4 | 128 | int index = signal_selector_->findData(QVariant::fromValue(sb)); |
bdbc561f SA |
129 | if (index != -1) |
130 | signal_selector_->setItemText(index, name); | |
2bdc5796 SA |
131 | } |
132 | ||
133 | } // namespace decoder_output | |
134 | } // namespace views | |
135 | } // namespace pv |