* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
+ * along with this program; if not, see <http://www.gnu.org/licenses/>.
*/
#include <extdef.h>
-#include <assert.h>
+#include <cassert>
#include <cmath>
#include <QApplication>
#include <libsigrokcxx/libsigrokcxx.hpp>
+#include "pv/data/signalbase.hpp"
+
#include "signal.hpp"
#include "view.hpp"
using std::shared_ptr;
-
-using sigrok::Channel;
+using std::make_shared;
namespace pv {
-namespace view {
+namespace views {
+namespace TraceView {
const char *const ChannelNames[] = {
"CLK",
};
Signal::Signal(pv::Session &session,
- std::shared_ptr<sigrok::Channel> channel) :
- Trace(QString::fromUtf8(channel->name().c_str())),
+ shared_ptr<data::SignalBase> channel) :
+ Trace(channel),
session_(session),
- channel_(channel),
- name_widget_(nullptr),
- updating_name_widget_(false)
+ scale_handle_(make_shared<SignalScaleHandle>(*this)),
+ items_({scale_handle_}),
+ name_widget_(nullptr)
{
- assert(channel_);
+ assert(base_);
+
+ connect(base_.get(), SIGNAL(enabled_changed(bool)),
+ this, SLOT(on_enabled_changed(bool)));
}
void Signal::set_name(QString name)
{
Trace::set_name(name);
- 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());
+ if (name != name_widget_->currentText())
+ name_widget_->setEditText(name);
}
bool Signal::enabled() const
{
- return channel_->enabled();
+ return base_->enabled();
}
-void Signal::enable(bool enable)
+shared_ptr<data::SignalBase> Signal::base() const
{
- channel_->set_enabled(enable);
+ return base_;
+}
- if (owner_)
- owner_->extents_changed(true, true);
+void Signal::save_settings(QSettings &settings) const
+{
+ (void)settings;
}
-shared_ptr<Channel> Signal::channel() const
+void Signal::restore_settings(QSettings &settings)
{
- return channel_;
+ (void)settings;
}
-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 (base_->enabled())
+ Trace::paint_back(p, pp);
+}
+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++)
+ 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(base_->name(), Qt::MatchExactly);
if (index == -1) {
- name_widget_->insertItem(0, name_);
+ name_widget_->insertItem(0, base_->name());
name_widget_->setCurrentIndex(0);
} else {
name_widget_->setCurrentIndex(index);
}
connect(name_widget_, SIGNAL(editTextChanged(const QString&)),
- this, SLOT(on_text_changed(const QString&)));
+ this, SLOT(on_nameedit_changed(const QString&)));
form->addRow(tr("Name"), name_widget_);
on_disable();
}
+void Signal::on_name_changed(const QString &text)
+{
+ // On startup, this event is fired when a session restores signal
+ // names. However, the name widget hasn't yet been created.
+ if (!name_widget_)
+ return;
+
+ if (text != name_widget_->currentText())
+ name_widget_->setEditText(text);
+
+ Trace::on_name_changed(text);
+}
+
void Signal::on_disable()
{
- enable(false);
+ base_->set_enabled(false);
+}
+
+void Signal::on_enabled_changed(bool enabled)
+{
+ (void)enabled;
+
+ if (owner_)
+ owner_->extents_changed(true, true);
}
-} // namespace view
+} // namespace TraceView
+} // namespace views
} // namespace pv