#include <extdef.h>
#include <assert.h>
-#include <math.h>
+#include <cmath>
#include <QApplication>
#include <QFormLayout>
#include <QLineEdit>
#include <QMenu>
-#include <libsigrok/libsigrok.h>
+#include <libsigrokcxx/libsigrokcxx.hpp>
-#include "signal.h"
-#include "view.h"
-
-#include <pv/device/devinst.h>
+#include "signal.hpp"
+#include "view.hpp"
using std::shared_ptr;
+using sigrok::Channel;
+
namespace pv {
namespace view {
"IN",
"OUT",
"RST",
- "Tx",
- "Rx",
+ "TX",
+ "RX",
"EN",
"SCLK",
"MOSI",
"SCL"
};
-Signal::Signal(shared_ptr<pv::device::DevInst> dev_inst,
- const sr_channel *const channel) :
- Trace(channel->name),
- _dev_inst(dev_inst),
- _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),
+ name_widget_(nullptr),
+ updating_name_widget_(false)
{
- 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;
+ updating_name_widget_ = true;
+ name_widget_->setEditText(name);
+ updating_name_widget_ = false;
+
+ // 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)
{
- _dev_inst->enable_channel(_channel, enable);
- visibility_changed();
+ channel_->set_enabled(enable);
+
+ if (owner_)
+ owner_->extents_changed(true, true);
}
-const sr_channel* Signal::channel() const
+shared_ptr<Channel> Signal::channel() const
{
- return _channel;
+ return channel_;
}
void Signal::populate_popup_form(QWidget *parent, QFormLayout *form)
{
- int index;
-
- _name_widget = new QComboBox(parent);
- _name_widget->setEditable(true);
+ name_widget_ = new QComboBox(parent);
+ name_widget_->setEditable(true);
+ name_widget_->setCompleter(0);
for(unsigned int i = 0; i < countof(ChannelNames); i++)
- _name_widget->insertItem(i, 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);
}
- _name_widget->lineEdit()->selectAll();
- _name_widget->setFocus();
-
- 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);
}