samples_count.cpp
Go to the documentation of this file.
1 #include "samples_count.h"
2 #include "ui_samples_count.h"
3 
4 #include <QSpinBox>
5 
7  : ui(new Ui::SamplesCount), _widget(new QWidget())
8 {
9  ui->setupUi(_widget);
10 
11  connect(ui->spinBoxMilliseconds, qOverload<int>(&QSpinBox::valueChanged), this,
12  [=](int) { emit parametersChanged(); });
13 }
14 
16 {
17  delete ui;
18  delete _widget;
19 }
20 
22 {
23  return _widget;
24 }
25 
26 bool SamplesCountFilter::xmlSaveState(QDomDocument& doc,
27  QDomElement& parent_element) const
28 {
29  QDomElement widget_el = doc.createElement("options");
30  widget_el.setAttribute("milliseconds", ui->spinBoxMilliseconds->value());
31  parent_element.appendChild(widget_el);
32  return true;
33 }
34 
35 bool SamplesCountFilter::xmlLoadState(const QDomElement& parent_element)
36 {
37  QDomElement widget_el = parent_element.firstChildElement("options");
38  if (widget_el.isNull())
39  {
40  return false;
41  }
42  int ms = widget_el.attribute("milliseconds", "1000").toInt();
43  ui->spinBoxMilliseconds->setValue(ms);
44  return true;
45 }
46 
47 std::optional<PJ::PlotData::Point> SamplesCountFilter::calculateNextPoint(size_t index)
48 {
49  if (dataSource()->size() == 0)
50  {
51  return std::nullopt;
52  }
53 
54  const auto& point = dataSource()->at(index);
55  const double delta = 0.001 * double(ui->spinBoxMilliseconds->value());
56  const double min_time = point.x - delta;
57  auto min_index = dataSource()->getIndexFromX(min_time);
58  return PJ::PlotData::Point{ point.x, double(index - min_index) };
59 }
SamplesCountFilter::ui
Ui::SamplesCount * ui
Definition: samples_count.h:37
SamplesCountFilter::~SamplesCountFilter
~SamplesCountFilter() override
Definition: samples_count.cpp:15
SamplesCountFilter::xmlSaveState
bool xmlSaveState(QDomDocument &doc, QDomElement &parent_element) const override
Override this method to save the status of the plugin to XML.
Definition: samples_count.cpp:26
SamplesCountFilter::_widget
QWidget * _widget
Definition: samples_count.h:38
SamplesCountFilter::xmlLoadState
bool xmlLoadState(const QDomElement &parent_element) override
Override this method to load the status of the plugin from XML.
Definition: samples_count.cpp:35
nonstd::span_lite::size
span_constexpr std::size_t size(span< T, Extent > const &spn)
Definition: span.hpp:1554
Ui
Definition: cheatsheet_dialog.h:6
SamplesCountFilter::SamplesCountFilter
SamplesCountFilter()
Definition: samples_count.cpp:6
PJ::TimeseriesBase::Point
typename PlotDataBase< double, Value >::Point Point
Definition: timeseries.h:23
PJ::TimeseriesBase::getIndexFromX
int getIndexFromX(double x) const
Definition: timeseries.h:106
samples_count.h
SamplesCountFilter::calculateNextPoint
std::optional< PlotData::Point > calculateNextPoint(size_t index) override
Definition: samples_count.cpp:47
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
SamplesCountFilter::optionsWidget
QWidget * optionsWidget() override
optionsWidget pointer to a persistent widget used to set the plugin options .
Definition: samples_count.cpp:21
eprosima::fastcdr::nullopt
static constexpr nullopt_t nullopt
nullopt is a constant of type nullopt_t that is used to indicate optional type with uninitialized sta...
Definition: optional.hpp:40


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