]> sigrok.org Git - pulseview.git/blob - pv/views/trace/mathsignal.hpp
Session: Fix issue #67 by improving error handling
[pulseview.git] / pv / views / trace / mathsignal.hpp
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 #ifndef PULSEVIEW_PV_VIEWS_TRACE_MATHSIGNAL_HPP
21 #define PULSEVIEW_PV_VIEWS_TRACE_MATHSIGNAL_HPP
22
23 #include <memory>
24 #include <vector>
25
26 #include <QComboBox>
27 #include <QDialog>
28 #include <QPlainTextEdit>
29 #include <QString>
30 #include <QTimer>
31
32 #include <pv/data/mathsignal.hpp>
33 #include <pv/views/trace/analogsignal.hpp>
34
35 using std::pair;
36 using std::shared_ptr;
37 using std::string;
38 using std::vector;
39
40 namespace pv {
41 namespace views {
42 namespace trace {
43
44 class MathEditDialog : public QDialog
45 {
46         Q_OBJECT
47
48 private:
49         static const vector< pair<string, string> > Examples;
50
51 public:
52         MathEditDialog(pv::Session &session, shared_ptr<pv::data::MathSignal> math_signal,
53                 QWidget *parent = nullptr);
54
55         void set_expr(const QString &expr);
56
57 private Q_SLOTS:
58         void accept();
59         void reject();
60
61 private:
62         pv::Session &session_;
63         shared_ptr<pv::data::MathSignal> math_signal_;
64         QString old_expression_;
65
66         QPlainTextEdit *expr_edit_;
67 };
68
69
70 class MathSignal : public AnalogSignal
71 {
72         Q_OBJECT
73
74 public:
75         MathSignal(pv::Session &session, shared_ptr<data::SignalBase> base);
76
77 protected:
78         void populate_popup_form(QWidget *parent, QFormLayout *form);
79
80         shared_ptr<pv::data::MathSignal> math_signal_;
81
82 private Q_SLOTS:
83         void on_expression_changed(const QString &text);
84         void on_sample_count_changed(const QString &text);
85
86         void on_edit_clicked();
87
88 private:
89         QLineEdit *expression_edit_;
90         QComboBox *sample_count_cb_, *sample_rate_cb_;
91         QString sample_count_text_, sample_rate_text_;
92         QTimer delayed_expr_updater_, delayed_count_updater_, delayed_rate_updater_;
93 };
94
95 } // namespace trace
96 } // namespace views
97 } // namespace pv
98
99 #endif // PULSEVIEW_PV_VIEWS_TRACE_MATHSIGNAL_HPP