From: Soeren Apel Date: Wed, 2 Sep 2020 20:28:22 +0000 (+0200) Subject: MathSignal: Add config dialog X-Git-Url: https://sigrok.org/gitaction?a=commitdiff_plain;h=86eeec3bfdc8bb6389d7142caa4039455e8029cc;p=pulseview.git MathSignal: Add config dialog --- diff --git a/icons/math.svg b/icons/math.svg new file mode 100644 index 00000000..afdaeb63 --- /dev/null +++ b/icons/math.svg @@ -0,0 +1,197 @@ + + + + + + + + + + image/svg+xml + + + + + + + + + + + + + + + + + + + - + + + - + + + + + diff --git a/pulseview.qrc b/pulseview.qrc index ceda06df..706fe8d0 100644 --- a/pulseview.qrc +++ b/pulseview.qrc @@ -10,6 +10,7 @@ icons/document-new.png icons/document-open.png icons/document-save-as.png + icons/math.svg icons/edit-paste.svg icons/help-browser.png icons/information.svg diff --git a/pv/dialogs/settings.hpp b/pv/dialogs/settings.hpp index 157fa6ba..18920b81 100644 --- a/pv/dialogs/settings.hpp +++ b/pv/dialogs/settings.hpp @@ -53,10 +53,10 @@ public: QWidget *get_about_page(QWidget *parent) const; QWidget *get_logging_page(QWidget *parent) const; +private Q_SLOTS: void accept(); void reject(); -private Q_SLOTS: void on_page_changed(QListWidgetItem *current, QListWidgetItem *previous); void on_general_language_changed(const QString &text); void on_general_theme_changed(int value); diff --git a/pv/views/trace/mathsignal.cpp b/pv/views/trace/mathsignal.cpp index 772e2d79..13dd0665 100644 --- a/pv/views/trace/mathsignal.cpp +++ b/pv/views/trace/mathsignal.cpp @@ -21,6 +21,7 @@ #include #include +#include #include #include #include @@ -38,6 +39,42 @@ namespace trace { #define MATHSIGNAL_INPUT_TIMEOUT (2000) + +MathEditDialog::MathEditDialog(pv::Session &session, + shared_ptr math_signal, QWidget *parent) : + QDialog(parent), + session_(session), + math_signal_(math_signal), + expression_(math_signal->get_expression()), + old_expression_(math_signal->get_expression()) +{ + setWindowTitle(tr("Math Expression Editor")); + + // Create the rest of the dialog + QDialogButtonBox *button_box = new QDialogButtonBox( + QDialogButtonBox::Ok | QDialogButtonBox::Cancel); + + QVBoxLayout* root_layout = new QVBoxLayout(this); +// root_layout->addLayout(tab_layout); + root_layout->addWidget(button_box); + + connect(button_box, SIGNAL(accepted()), this, SLOT(accept())); + connect(button_box, SIGNAL(rejected()), this, SLOT(reject())); +} + +void MathEditDialog::accept() +{ + math_signal_->set_expression(expression_); + QDialog::accept(); +} + +void MathEditDialog::reject() +{ + math_signal_->set_expression(old_expression_); + QDialog::reject(); +} + + MathSignal::MathSignal( pv::Session &session, shared_ptr base) : @@ -56,8 +93,15 @@ void MathSignal::populate_popup_form(QWidget *parent, QFormLayout *form) expression_edit_ = new QLineEdit(); expression_edit_->setText(math_signal_->get_expression()); + + const QIcon edit_icon(QIcon::fromTheme("edit", QIcon(":/icons/math.svg"))); + QAction *edit_action = + expression_edit_->addAction(edit_icon, QLineEdit::TrailingPosition); + connect(expression_edit_, SIGNAL(textEdited(QString)), this, SLOT(on_expression_changed(QString))); + connect(edit_action, SIGNAL(triggered(bool)), + this, SLOT(on_edit_clicked())); form->addRow(tr("Expression"), expression_edit_); sample_count_cb_ = new QComboBox(); @@ -92,6 +136,13 @@ void MathSignal::on_sample_count_changed(const QString &text) (void)text; } +void MathSignal::on_edit_clicked() +{ + MathEditDialog dlg(session_, math_signal_); + + dlg.exec(); +} + } // namespace trace } // namespace views } // namespace pv diff --git a/pv/views/trace/mathsignal.hpp b/pv/views/trace/mathsignal.hpp index 461fd4b7..4b8fcb18 100644 --- a/pv/views/trace/mathsignal.hpp +++ b/pv/views/trace/mathsignal.hpp @@ -21,6 +21,7 @@ #define PULSEVIEW_PV_VIEWS_TRACE_MATHSIGNAL_HPP #include +#include #include #include @@ -33,6 +34,25 @@ namespace pv { namespace views { namespace trace { +class MathEditDialog : public QDialog +{ + Q_OBJECT + +public: + MathEditDialog(pv::Session &session, shared_ptr math_signal, + QWidget *parent = nullptr); + +private Q_SLOTS: + void accept(); + void reject(); + +private: + pv::Session &session_; + shared_ptr math_signal_; + QString expression_, old_expression_; +}; + + class MathSignal : public AnalogSignal { Q_OBJECT @@ -49,6 +69,8 @@ private Q_SLOTS: void on_expression_changed(const QString &text); void on_sample_count_changed(const QString &text); + void on_edit_clicked(); + private: QLineEdit *expression_edit_; QComboBox *sample_count_cb_, *sample_rate_cb_;