2 * This file is part of the PulseView project.
4 * Copyright (C) 2020 Soeren Apel <soeren@apelpie.net>
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, see <http://www.gnu.org/licenses/>.
24 #include <QFormLayout>
25 #include <QGridLayout>
29 #include "mathsignal.hpp"
31 #include "pv/data/signalbase.hpp"
33 using pv::data::SignalBase;
39 #define MATHSIGNAL_INPUT_TIMEOUT (2000)
41 MathSignal::MathSignal(
43 shared_ptr<data::SignalBase> base) :
44 AnalogSignal(session, base),
45 math_signal_(dynamic_pointer_cast<pv::data::MathSignal>(base))
47 delayed_expr_updater_.setSingleShot(true);
48 delayed_expr_updater_.setInterval(MATHSIGNAL_INPUT_TIMEOUT);
49 connect(&delayed_expr_updater_, &QTimer::timeout,
50 this, [this]() { math_signal_->set_expression(expression_edit_->text()); });
53 void MathSignal::populate_popup_form(QWidget *parent, QFormLayout *form)
55 AnalogSignal::populate_popup_form(parent, form);
57 expression_edit_ = new QLineEdit();
58 expression_edit_->setText(math_signal_->get_expression());
59 connect(expression_edit_, SIGNAL(textEdited(QString)),
60 this, SLOT(on_expression_changed(QString)));
61 form->addRow(tr("Expression"), expression_edit_);
63 sample_count_cb_ = new QComboBox();
64 sample_count_cb_->setEditable(true);
65 sample_count_cb_->addItem(tr("same as session"));
66 sample_count_cb_->addItem(tr("100"));
67 sample_count_cb_->addItem(tr("10000"));
68 sample_count_cb_->addItem(tr("1000000"));
69 connect(sample_count_cb_, SIGNAL(editTextChanged(QString)),
70 this, SLOT(on_sample_count_changed(QString)));
71 form->addRow(tr("Number of Samples"), sample_count_cb_);
73 sample_rate_cb_ = new QComboBox();
74 sample_rate_cb_->setEditable(true);
75 sample_rate_cb_->addItem(tr("same as session"));
76 sample_rate_cb_->addItem(tr("100"));
77 sample_rate_cb_->addItem(tr("10000"));
78 sample_rate_cb_->addItem(tr("1000000"));
79 form->addRow(tr("Sample rate"), sample_rate_cb_);
82 void MathSignal::on_expression_changed(const QString &text)
86 // Restart update timer
87 delayed_expr_updater_.start();
90 void MathSignal::on_sample_count_changed(const QString &text)