2020-11-25 23:47:29 +08:00
|
|
|
#include "tracemath.h"
|
|
|
|
|
|
|
|
TraceMath::TraceMath()
|
|
|
|
{
|
|
|
|
input = nullptr;
|
|
|
|
dataType = DataType::Invalid;
|
2020-11-28 20:57:22 +08:00
|
|
|
error("Invalid input");
|
2020-11-25 23:47:29 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
TraceMath::Data TraceMath::getSample(unsigned int index)
|
|
|
|
{
|
|
|
|
return data.at(index);
|
|
|
|
}
|
|
|
|
|
|
|
|
unsigned int TraceMath::numSamples()
|
|
|
|
{
|
|
|
|
return data.size();
|
|
|
|
}
|
|
|
|
|
|
|
|
void TraceMath::removeInput()
|
|
|
|
{
|
|
|
|
if(input) {
|
|
|
|
// disconnect everything from the input
|
|
|
|
disconnect(input, nullptr, this, nullptr);
|
|
|
|
input = nullptr;
|
|
|
|
data.clear();
|
|
|
|
dataType = DataType::Invalid;
|
|
|
|
emit outputTypeChanged(dataType);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void TraceMath::assignInput(TraceMath *input)
|
|
|
|
{
|
|
|
|
Q_ASSERT(input != nullptr);
|
|
|
|
if(input != this->input) {
|
|
|
|
removeInput();
|
|
|
|
this->input = input;
|
|
|
|
inputTypeChanged(input->dataType);
|
|
|
|
// do initial calculation
|
2020-11-27 23:31:05 +08:00
|
|
|
inputSamplesChanged(0, input->data.size());
|
2020-11-25 23:47:29 +08:00
|
|
|
// connect to input
|
2020-11-27 23:31:05 +08:00
|
|
|
connect(input, &TraceMath::outputSamplesChanged, this, &TraceMath::inputSamplesChanged);
|
2020-11-25 23:47:29 +08:00
|
|
|
connect(input, &TraceMath::outputTypeChanged, this, &TraceMath::inputTypeChanged);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void TraceMath::inputTypeChanged(TraceMath::DataType type)
|
|
|
|
{
|
|
|
|
auto newType = outputType(type);
|
|
|
|
if(newType != dataType) {
|
|
|
|
dataType = newType;
|
|
|
|
data.clear();
|
2020-11-27 23:31:05 +08:00
|
|
|
inputSamplesChanged(0, input->data.size());
|
2020-11-25 23:47:29 +08:00
|
|
|
emit outputTypeChanged(dataType);
|
2020-11-28 20:57:22 +08:00
|
|
|
if(dataType == DataType::Invalid) {
|
|
|
|
error("Invalid input data");
|
|
|
|
}
|
2020-11-25 23:47:29 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-11-28 20:57:22 +08:00
|
|
|
void TraceMath::warning(QString warn)
|
|
|
|
{
|
|
|
|
statusString = warn;
|
|
|
|
status = Status::Warning;
|
|
|
|
emit statusChanged();
|
|
|
|
}
|
|
|
|
|
|
|
|
void TraceMath::error(QString err)
|
|
|
|
{
|
|
|
|
statusString = err;
|
|
|
|
status = Status::Error;
|
|
|
|
emit statusChanged();
|
|
|
|
}
|
|
|
|
|
|
|
|
void TraceMath::success()
|
|
|
|
{
|
|
|
|
if(status != Status::Ok) {
|
|
|
|
status = Status::Ok;
|
|
|
|
emit statusChanged();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
QString TraceMath::getStatusDescription() const
|
|
|
|
{
|
|
|
|
return statusString;
|
|
|
|
}
|
|
|
|
|
|
|
|
TraceMath::Status TraceMath::getStatus() const
|
|
|
|
{
|
|
|
|
return status;
|
|
|
|
}
|
|
|
|
|
2020-11-25 23:47:29 +08:00
|
|
|
TraceMath::DataType TraceMath::getDataType() const
|
|
|
|
{
|
|
|
|
return dataType;
|
|
|
|
}
|