]> sigrok.org Git - pulseview.git/blame - pv/views/trace/mathsignal.cpp
Fix #1596 by making memory management more robust
[pulseview.git] / pv / views / trace / mathsignal.cpp
CommitLineData
4640a84e
SA
1/*
2 * This file is part of the PulseView project.
3 *
4 * Copyright (C) 2020 Soeren Apel <soeren@apelpie.net>
5 *
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.
10 *
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.
15 *
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/>.
18 */
19
20#include <extdef.h>
21
22#include <QComboBox>
23#include <QDebug>
24#include <QFormLayout>
25#include <QGridLayout>
26#include <QLineEdit>
27#include <QString>
28
29#include "mathsignal.hpp"
30
31#include "pv/data/signalbase.hpp"
32
33using pv::data::SignalBase;
34
35namespace pv {
36namespace views {
37namespace trace {
38
39#define MATHSIGNAL_INPUT_TIMEOUT (2000)
40
41MathSignal::MathSignal(
42 pv::Session &session,
43 shared_ptr<data::SignalBase> base) :
44 AnalogSignal(session, base),
45 math_signal_(dynamic_pointer_cast<pv::data::MathSignal>(base))
46{
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()); });
51}
52
53void MathSignal::populate_popup_form(QWidget *parent, QFormLayout *form)
54{
55 AnalogSignal::populate_popup_form(parent, form);
56
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_);
62
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_);
72
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_);
80}
81
82void MathSignal::on_expression_changed(const QString &text)
83{
84 (void)text;
85
86 // Restart update timer
87 delayed_expr_updater_.start();
88}
89
90void MathSignal::on_sample_count_changed(const QString &text)
91{
92 (void)text;
93}
94
95} // namespace trace
96} // namespace views
97} // namespace pv