#include <extdef.h>
#include <assert.h>
-#include <math.h>
+#include <cmath>
#include <QApplication>
#include <QFormLayout>
#include <QLineEdit>
#include <QMenu>
-#include <libsigrok/libsigrok.hpp>
+#include <libsigrokcxx/libsigrokcxx.hpp>
-#include "signal.h"
-#include "view.h"
+#include "signal.hpp"
+#include "view.hpp"
using std::shared_ptr;
+using std::make_shared;
using sigrok::Channel;
"IN",
"OUT",
"RST",
- "Tx",
- "Rx",
+ "TX",
+ "RX",
"EN",
"SCLK",
"MOSI",
"SCL"
};
-Signal::Signal(shared_ptr<Channel> channel) :
- Trace(channel->name().c_str()),
- _channel(channel),
- _name_widget(NULL),
- _updating_name_widget(false)
+Signal::Signal(pv::Session &session,
+ std::shared_ptr<sigrok::Channel> channel) :
+ Trace(QString::fromUtf8(channel->name().c_str())),
+ session_(session),
+ channel_(channel),
+ scale_handle_(make_shared<SignalScaleHandle>(*this)),
+ items_({scale_handle_}),
+ name_widget_(nullptr)
{
- assert(_channel);
+ assert(channel_);
}
void Signal::set_name(QString name)
{
Trace::set_name(name);
- _updating_name_widget = true;
- _name_widget->setEditText(name);
- _updating_name_widget = false;
+
+ if (name != name_widget_->currentText())
+ name_widget_->setEditText(name);
+
+ // Store the channel name in sigrok::Channel so that it
+ // will end up in the .sr file upon save.
+ channel_->set_name(name.toUtf8().constData());
}
bool Signal::enabled() const
{
- return _channel->enabled();
+ return channel_->enabled();
}
void Signal::enable(bool enable)
{
- _channel->set_enabled(enable);
- visibility_changed();
+ channel_->set_enabled(enable);
+
+ if (owner_)
+ owner_->extents_changed(true, true);
}
shared_ptr<Channel> Signal::channel() const
{
- return _channel;
+ return channel_;
}
-void Signal::populate_popup_form(QWidget *parent, QFormLayout *form)
+const ViewItemOwner::item_list& Signal::child_items() const
+{
+ return items_;
+}
+
+void Signal::paint_back(QPainter &p, const ViewItemPaintParams &pp)
{
- int index;
+ if (channel_->enabled())
+ Trace::paint_back(p, pp);
+}
- _name_widget = new QComboBox(parent);
- _name_widget->setEditable(true);
+void Signal::populate_popup_form(QWidget *parent, QFormLayout *form)
+{
+ name_widget_ = new QComboBox(parent);
+ name_widget_->setEditable(true);
+ name_widget_->setCompleter(nullptr);
- for(unsigned int i = 0; i < countof(ChannelNames); i++)
- _name_widget->insertItem(i, ChannelNames[i]);
+ for (unsigned int i = 0; i < countof(ChannelNames); i++)
+ name_widget_->insertItem(i, ChannelNames[i]);
- index = _name_widget->findText(_name, Qt::MatchExactly);
+ const int index = name_widget_->findText(name_, Qt::MatchExactly);
if (index == -1) {
- _name_widget->insertItem(0, _name);
- _name_widget->setCurrentIndex(0);
+ name_widget_->insertItem(0, name_);
+ name_widget_->setCurrentIndex(0);
} else {
- _name_widget->setCurrentIndex(index);
+ name_widget_->setCurrentIndex(index);
}
- connect(_name_widget, SIGNAL(editTextChanged(const QString&)),
+ connect(name_widget_, SIGNAL(editTextChanged(const QString&)),
this, SLOT(on_text_changed(const QString&)));
- form->addRow(tr("Name"), _name_widget);
+ form->addRow(tr("Name"), name_widget_);
add_colour_option(parent, form);
}