void Session::register_view(shared_ptr<views::ViewBase> view)
{
- if (views_.empty()) {
+ if (views_.empty())
main_view_ = view;
- }
views_.push_back(view);
update_signals();
// Add all other signals
- unordered_set< shared_ptr<data::SignalBase> > view_signalbases =
- view->signalbases();
-
- views::trace::View *trace_view =
- qobject_cast<views::trace::View*>(view.get());
-
- if (trace_view) {
- for (const shared_ptr<data::SignalBase>& signalbase : signalbases_) {
- const int sb_exists = count_if(
- view_signalbases.cbegin(), view_signalbases.cend(),
- [&](const shared_ptr<data::SignalBase> &sb) {
- return sb == signalbase;
- });
- // Add the signal to the view as it doesn't have it yet
- if (!sb_exists)
- switch (signalbase->type()) {
- case data::SignalBase::AnalogChannel:
- case data::SignalBase::LogicChannel:
- case data::SignalBase::DecodeChannel:
+ unordered_set< shared_ptr<data::SignalBase> > view_signalbases = view->signalbases();
+
+ for (const shared_ptr<data::SignalBase>& signalbase : signalbases_) {
+ const int sb_exists = count_if(
+ view_signalbases.cbegin(), view_signalbases.cend(),
+ [&](const shared_ptr<data::SignalBase> &sb) {
+ return sb == signalbase;
+ });
+
+ // Add the signal to the view if it doesn't have it yet
+ if (!sb_exists)
+ switch (signalbase->type()) {
+ case data::SignalBase::AnalogChannel:
+ case data::SignalBase::LogicChannel:
+ case data::SignalBase::MathChannel:
+ view->add_signalbase(signalbase);
+ break;
+ case data::SignalBase::DecodeChannel:
#ifdef ENABLE_DECODE
- trace_view->add_decode_signal(
- dynamic_pointer_cast<data::DecodeSignal>(signalbase));
+ view->add_decode_signal(dynamic_pointer_cast<data::DecodeSignal>(signalbase));
#endif
- break;
- case data::SignalBase::MathChannel:
- // TBD
- break;
- }
- }
+ break;
+ }
}
signals_changed();
#include <libsigrokdecode/libsigrokdecode.h>
+#include <QLabel>
#include <QMenu>
#include <QToolBar>
#include <QVBoxLayout>
#include "pv/session.hpp"
#include "pv/util.hpp"
+using pv::data::SignalBase;
using pv::util::TimeUnit;
using pv::util::Timestamp;
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())
{
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_);
reset_view_state();
}
void View::clear_decode_signals()
{
+ signal_selector_->clear();
}
void View::add_decode_signal(shared_ptr<data::DecodeSignal> 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(), qVariantFromValue(signal.get()));
}
void View::remove_decode_signal(shared_ptr<data::DecodeSignal> signal)
{
- (void)signal;
+ int index = signal_selector_->findData(qVariantFromValue(signal.get()));
+
+ if (index != -1)
+ signal_selector_->removeItem(index);
}
void View::save_settings(QSettings &settings) const
(void)settings;
}
-void View::on_signal_name_changed()
+void View::on_signal_name_changed(const QString &name)
{
+ SignalBase *sb = qobject_cast<SignalBase*>(QObject::sender());
+ assert(sb);
+
+ int index = signal_selector_->findData(qVariantFromValue(sb));
+ if (index != -1)
+ signal_selector_->setItemText(index, name);
}
} // namespace decoder_output