QBinaryTranslate/TranslateUI/convert_basic.cpp

73 lines
1.5 KiB
C++
Raw Normal View History

2025-08-01 01:47:41 +00:00
#include "convert_basic.h"
#include "extract_basic.h"
#include <QVariant>
using namespace convert;
AbstractValueConvert::AbstractValueConvert(const QString& nm, DataType in, DataType out)
2025-08-02 02:04:30 +00:00
: name_store(nm), _in_type(in), _out_type(out) {
2025-08-01 01:47:41 +00:00
}
QString AbstractValueConvert::name() const
{
2025-08-02 02:04:30 +00:00
return name_store;
2025-08-01 01:47:41 +00:00
}
DataType AbstractValueConvert::inType() const
{
return _in_type;
}
DataType AbstractValueConvert::outType() const
{
return _out_type;
}
void AbstractValueConvert::loadFrom(std::shared_ptr<TranslateBasic> core, const QJsonObject& obj)
2025-08-01 01:47:41 +00:00
{
auto int_in_type = (int)_in_type;
2025-08-02 07:02:35 +00:00
INT32_PEAK(int_in_type, obj);
2025-08-01 01:47:41 +00:00
_in_type = (DataType)int_in_type;
auto int_out_type = (int)_out_type;
2025-08-02 07:02:35 +00:00
INT32_PEAK(int_out_type, obj);
2025-08-01 01:47:41 +00:00
_out_type = (DataType)int_out_type;
}
void AbstractValueConvert::saveTo(QJsonObject& obj) const
{
auto int_in_type = (int)_in_type;
2025-08-02 07:02:35 +00:00
INT32_SAVE(int_in_type, obj);
2025-08-01 01:47:41 +00:00
auto int_out_type = (int)_out_type;
2025-08-02 07:02:35 +00:00
INT32_SAVE(int_out_type, obj);
2025-08-01 01:47:41 +00:00
}
DoubleWithLSB::DoubleWithLSB()
:AbstractValueConvert(NAME(DoubleWithLSB), DataType::Integer, DataType::Dbl64),
_lsb_value(1) {
}
void DoubleWithLSB::setLSB(double lsbv)
{
this->_lsb_value = lsbv;
}
double DoubleWithLSB::getLSB() const
{
return this->_lsb_value;
}
QVariant DoubleWithLSB::convert(const QVariant& value) const
{
if (value.canConvert<int64_t>())
return value.toLongLong() * this->_lsb_value;
return value.toULongLong() * this->_lsb_value;
}
std::shared_ptr<Serializable> DoubleWithLSB::newDefault() const
{
return std::make_shared<DoubleWithLSB>();
}