scale_transform.cpp
Go to the documentation of this file.
1 #include "scale_transform.h"
2 #include <QDoubleValidator>
3 #include "ui_scale_transform.h"
4 
5 ScaleTransform::ScaleTransform() : _widget(new QWidget()), ui(new Ui::ScaleTransform)
6 {
7  ui->setupUi(_widget);
8 
9  ui->lineEditTimeOffset->setValidator(new QDoubleValidator());
10  ui->lineEditValueOffset->setValidator(new QDoubleValidator());
11  ui->lineEditValueScale->setValidator(new QDoubleValidator());
12 
13  connect(ui->buttonDegRad, &QPushButton::clicked, this, [=]() {
14  const double deg_rad = 3.14159265359 / 180;
15  ui->lineEditValueScale->setText(QString::number(deg_rad, 'g', 5));
16  emit parametersChanged();
17  });
18 
19  connect(ui->buttonRadDeg, &QPushButton::clicked, this, [=]() {
20  const double rad_deg = 180.0 / 3.14159265359;
21  ui->lineEditValueScale->setText(QString::number(rad_deg, 'g', 5));
22  emit parametersChanged();
23  });
24 
25  connect(ui->lineEditTimeOffset, &QLineEdit::editingFinished, this,
26  [=]() { emit parametersChanged(); });
27  connect(ui->lineEditValueOffset, &QLineEdit::editingFinished, this,
28  [=]() { emit parametersChanged(); });
29  connect(ui->lineEditValueScale, &QLineEdit::editingFinished, this,
30  [=]() { emit parametersChanged(); });
31 }
32 
34 {
35  delete ui;
36  delete _widget;
37 }
38 
40 {
41  return _widget;
42 }
43 
44 bool ScaleTransform::xmlSaveState(QDomDocument& doc, QDomElement& parent_element) const
45 {
46  QDomElement widget_el = doc.createElement("options");
47  widget_el.setAttribute("time_offset", ui->lineEditTimeOffset->text());
48  widget_el.setAttribute("value_offset", ui->lineEditValueOffset->text());
49  widget_el.setAttribute("value_scale", ui->lineEditValueScale->text());
50  parent_element.appendChild(widget_el);
51 
52  return true;
53 }
54 
55 bool ScaleTransform::xmlLoadState(const QDomElement& parent_element)
56 {
57  QDomElement widget_el = parent_element.firstChildElement("options");
58  if (widget_el.isNull())
59  {
60  return false;
61  }
62  ui->lineEditTimeOffset->setText(widget_el.attribute("time_offset"));
63  ui->lineEditValueOffset->setText(widget_el.attribute("value_offset"));
64  ui->lineEditValueScale->setText(widget_el.attribute("value_scale"));
65  return true;
66 }
67 
68 std::optional<PlotData::Point> ScaleTransform::calculateNextPoint(size_t index)
69 {
70  double off_x = ui->lineEditTimeOffset->text().toDouble();
71  double off_y = ui->lineEditValueOffset->text().toDouble();
72  double scale = ui->lineEditValueScale->text().toDouble();
73 
74  const auto& p = dataSource()->at(index);
75  PlotData::Point out = { p.x + off_x, scale * p.y + off_y };
76  return out;
77 }
ScaleTransform::ScaleTransform
ScaleTransform()
Definition: scale_transform.cpp:5
ScaleTransform::calculateNextPoint
std::optional< PlotData::Point > calculateNextPoint(size_t index) override
Definition: scale_transform.cpp:68
ScaleTransform::optionsWidget
QWidget * optionsWidget() override
optionsWidget pointer to a persistent widget used to set the plugin options .
Definition: scale_transform.cpp:39
ScaleTransform::ui
Ui::ScaleTransform * ui
Definition: scale_transform.h:39
Ui
Definition: cheatsheet_dialog.h:6
PJ::TimeseriesBase::Point
typename PlotDataBase< double, Value >::Point Point
Definition: timeseries.h:23
ScaleTransform::~ScaleTransform
~ScaleTransform() override
Definition: scale_transform.cpp:33
ScaleTransform::xmlLoadState
bool xmlLoadState(const QDomElement &parent_element) override
Override this method to load the status of the plugin from XML.
Definition: scale_transform.cpp:55
scale_transform.h
PJ::TransformFunction_SISO::dataSource
const PlotData * dataSource() const
Definition: transform_function.cpp:113
PJ::PlotDataBase::at
const Point & at(size_t index) const
Definition: plotdatabase.h:193
ScaleTransform
Definition: scale_transform.h:14
ScaleTransform::_widget
QWidget * _widget
Definition: scale_transform.h:38
ScaleTransform::xmlSaveState
bool xmlSaveState(QDomDocument &doc, QDomElement &parent_element) const override
Override this method to save the status of the plugin to XML.
Definition: scale_transform.cpp:44


plotjuggler
Author(s): Davide Faconti
autogenerated on Mon Nov 11 2024 03:23:46