X-Git-Url: https://sigrok.org/gitweb/?a=blobdiff_plain;ds=sidebyside;f=pv%2Fviews%2Fdecoder_output%2Fview.cpp;h=5c3b031dec55f4c7dbd6f56d551ad1b58ee4cc77;hb=01ba5ed7e7094dead8002ee430d67bde106f8835;hp=8da1e84ae73499c506cff31e3bbf63e5d7c69e39;hpb=db29815836442ac83d453b3de2bf1755e9fd89f0;p=pulseview.git diff --git a/pv/views/decoder_output/view.cpp b/pv/views/decoder_output/view.cpp index 8da1e84a..5c3b031d 100644 --- a/pv/views/decoder_output/view.cpp +++ b/pv/views/decoder_output/view.cpp @@ -19,15 +19,18 @@ #include +#include #include #include #include #include "view.hpp" +#include "QHexView.hpp" #include "pv/session.hpp" #include "pv/util.hpp" +using pv::data::SignalBase; using pv::util::TimeUnit; using pv::util::Timestamp; @@ -38,17 +41,35 @@ namespace views { namespace decoder_output { View::View(Session &session, bool is_main_view, QMainWindow *parent) : - ViewBase(session, is_main_view, parent) + ViewBase(session, is_main_view, parent), // Note: Place defaults in View::reset_view_state(), not here + signal_selector_(new QComboBox()), + format_selector_(new QComboBox()), + stacked_widget_(new QStackedWidget()), + hex_view_(new QHexView()) { QVBoxLayout *root_layout = new QVBoxLayout(this); root_layout->setContentsMargins(0, 0, 0, 0); - QToolBar* tool_bar = new QToolBar(); - tool_bar->setContextMenuPolicy(Qt::PreventContextMenu); + // Create toolbar + QToolBar* toolbar = new QToolBar(); + toolbar->setContextMenuPolicy(Qt::PreventContextMenu); + parent->addToolBar(toolbar); - parent->addToolBar(tool_bar); + // Populate toolbar + toolbar->addWidget(new QLabel(tr("Decoder:"))); + toolbar->addWidget(signal_selector_); + toolbar->addSeparator(); + toolbar->addWidget(new QLabel(tr("Show data as"))); + toolbar->addWidget(format_selector_); + + // Add format types + format_selector_->addItem(tr("Hexdump"), qVariantFromValue(QString("text/hexdump"))); + + // Add widget stack + root_layout->addWidget(stacked_widget_); + stacked_widget_->addWidget(hex_view_); reset_view_state(); } @@ -74,17 +95,24 @@ void View::clear_signals() void View::clear_decode_signals() { + signal_selector_->clear(); + format_selector_->setCurrentIndex(0); } void View::add_decode_signal(shared_ptr signal) { connect(signal.get(), SIGNAL(name_changed(const QString&)), - this, SLOT(on_signal_name_changed())); + this, SLOT(on_signal_name_changed(const QString&))); + + signal_selector_->addItem(signal->name(), QVariant::fromValue(signal.get())); } void View::remove_decode_signal(shared_ptr signal) { - (void)signal; + int index = signal_selector_->findData(QVariant::fromValue(signal.get())); + + if (index != -1) + signal_selector_->removeItem(index); } void View::save_settings(QSettings &settings) const @@ -99,8 +127,14 @@ void View::restore_settings(QSettings &settings) (void)settings; } -void View::on_signal_name_changed() +void View::on_signal_name_changed(const QString &name) { + SignalBase *sb = qobject_cast(QObject::sender()); + assert(sb); + + int index = signal_selector_->findData(QVariant::fromValue(sb)); + if (index != -1) + signal_selector_->setItemText(index, name); } } // namespace decoder_output