-
-
Notifications
You must be signed in to change notification settings - Fork 635
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
2d2a5dd
commit 8a297ad
Showing
5 changed files
with
209 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
#include "samples_count.h" | ||
#include "ui_samples_count.h" | ||
|
||
#include <QSpinBox> | ||
|
||
SamplesCountFilter::SamplesCountFilter() | ||
: ui(new Ui::SamplesCount) | ||
, _widget(new QWidget()) | ||
{ | ||
ui->setupUi(_widget); | ||
|
||
connect(ui->spinBoxMilliseconds, | ||
qOverload<int>(&QSpinBox::valueChanged), this, | ||
[=](int) { emit parametersChanged(); }); | ||
} | ||
|
||
SamplesCountFilter::~SamplesCountFilter() | ||
{ | ||
delete ui; | ||
delete _widget; | ||
} | ||
|
||
QWidget* SamplesCountFilter::optionsWidget() | ||
{ | ||
return _widget; | ||
} | ||
|
||
bool SamplesCountFilter::xmlSaveState(QDomDocument& doc, | ||
QDomElement& parent_element) const | ||
{ | ||
QDomElement widget_el = doc.createElement("options"); | ||
widget_el.setAttribute("milliseconds", ui->spinBoxMilliseconds->value()); | ||
parent_element.appendChild(widget_el); | ||
return true; | ||
} | ||
|
||
bool SamplesCountFilter::xmlLoadState(const QDomElement& parent_element) | ||
{ | ||
QDomElement widget_el = parent_element.firstChildElement("options"); | ||
if(widget_el.isNull()) | ||
{ | ||
return false; | ||
} | ||
int ms = widget_el.attribute("milliseconds", "1000").toInt(); | ||
ui->spinBoxMilliseconds->setValue(ms); | ||
return true; | ||
} | ||
|
||
std::optional<PJ::PlotData::Point> SamplesCountFilter::calculateNextPoint(size_t index) | ||
{ | ||
if(dataSource()->size() == 0) { | ||
return std::nullopt; | ||
} | ||
const double delta = 0.001 * double(ui->spinBoxMilliseconds->value()); | ||
const auto& point = dataSource()->at(index); | ||
if(index == 0) { | ||
interval_end_ = point.x + delta; | ||
count_ = 0; | ||
} | ||
count_++; | ||
|
||
if(point.x > interval_end_ || index == (dataSource()->size() - 1)) | ||
{ | ||
auto out = PJ::PlotData::Point{ interval_end_, double(count_) }; | ||
while(point.x > interval_end_) { | ||
interval_end_ += delta; | ||
} | ||
count_ = 0; | ||
return out; | ||
} | ||
return std::nullopt; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
#pragma once | ||
|
||
#include <QWidget> | ||
#include "PlotJuggler/transform_function.h" | ||
|
||
using namespace PJ; | ||
|
||
namespace Ui | ||
{ | ||
class SamplesCount; | ||
} | ||
|
||
class SamplesCountFilter : public TransformFunction_SISO | ||
{ | ||
public: | ||
explicit SamplesCountFilter(); | ||
|
||
~SamplesCountFilter() override; | ||
|
||
static const char* transformName() | ||
{ | ||
return "Samples Counter"; | ||
} | ||
|
||
const char* name() const override | ||
{ | ||
return transformName(); | ||
} | ||
|
||
QWidget* optionsWidget() override; | ||
|
||
bool xmlSaveState(QDomDocument& doc, QDomElement& parent_element) const override; | ||
|
||
bool xmlLoadState(const QDomElement& parent_element) override; | ||
|
||
private: | ||
Ui::SamplesCount* ui; | ||
QWidget* _widget; | ||
|
||
int count_ = 0; | ||
double interval_end_ = 0; | ||
|
||
std::optional<PlotData::Point> calculateNextPoint(size_t index) override; | ||
}; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<ui version="4.0"> | ||
<class>SamplesCount</class> | ||
<widget class="QWidget" name="SamplesCount"> | ||
<property name="geometry"> | ||
<rect> | ||
<x>0</x> | ||
<y>0</y> | ||
<width>400</width> | ||
<height>300</height> | ||
</rect> | ||
</property> | ||
<property name="windowTitle"> | ||
<string>Form</string> | ||
</property> | ||
<layout class="QVBoxLayout" name="verticalLayout"> | ||
<item> | ||
<widget class="QLabel" name="label"> | ||
<property name="text"> | ||
<string>Count the number of data points in the given time interval:</string> | ||
</property> | ||
<property name="wordWrap"> | ||
<bool>true</bool> | ||
</property> | ||
</widget> | ||
</item> | ||
<item> | ||
<layout class="QHBoxLayout" name="horizontalLayout"> | ||
<item> | ||
<widget class="QLabel" name="label_2"> | ||
<property name="text"> | ||
<string>Milliseconds:</string> | ||
</property> | ||
</widget> | ||
</item> | ||
<item> | ||
<widget class="QSpinBox" name="spinBoxMilliseconds"> | ||
<property name="minimumSize"> | ||
<size> | ||
<width>100</width> | ||
<height>0</height> | ||
</size> | ||
</property> | ||
<property name="minimum"> | ||
<number>1</number> | ||
</property> | ||
<property name="maximum"> | ||
<number>999999</number> | ||
</property> | ||
<property name="value"> | ||
<number>1000</number> | ||
</property> | ||
</widget> | ||
</item> | ||
<item> | ||
<spacer name="horizontalSpacer"> | ||
<property name="orientation"> | ||
<enum>Qt::Horizontal</enum> | ||
</property> | ||
<property name="sizeHint" stdset="0"> | ||
<size> | ||
<width>40</width> | ||
<height>20</height> | ||
</size> | ||
</property> | ||
</spacer> | ||
</item> | ||
</layout> | ||
</item> | ||
<item> | ||
<spacer name="verticalSpacer"> | ||
<property name="orientation"> | ||
<enum>Qt::Vertical</enum> | ||
</property> | ||
<property name="sizeHint" stdset="0"> | ||
<size> | ||
<width>20</width> | ||
<height>40</height> | ||
</size> | ||
</property> | ||
</spacer> | ||
</item> | ||
</layout> | ||
</widget> | ||
<resources/> | ||
<connections/> | ||
</ui> |