This commit is contained in:
parent
f82c6e67df
commit
6027701a36
|
|
@ -45,12 +45,12 @@ void SequenceRulesView::currentRuleRefresh(const QModelIndex& idx)
|
|||
if (rule_insv) {
|
||||
auto offset_number = offset_index.data(Qt::DisplayRole).toInt();
|
||||
auto count_number = count_index.data(Qt::DisplayRole).toInt();
|
||||
rule_insv->setOffsetFromPrevious(offset_number);
|
||||
rule_insv->setCountWithinParse(count_number);
|
||||
rule_insv->setOffsetSpan(offset_number);
|
||||
rule_insv->setCountWithin(count_number);
|
||||
}
|
||||
|
||||
_sequence_model->setData(offset_index, new_inst->offsetFromPrevious(), Qt::EditRole);
|
||||
_sequence_model->setData(count_index, new_inst->countWithinParse(), Qt::EditRole);
|
||||
_sequence_model->setData(offset_index, new_inst->offsetSpan(), Qt::EditRole);
|
||||
_sequence_model->setData(count_index, new_inst->countWithin(), Qt::EditRole);
|
||||
|
||||
auto param_index = idx.sibling(idx.row(), 4);
|
||||
QJsonObject obj;
|
||||
|
|
@ -124,7 +124,7 @@ void SequenceRulesView::addTranslateUnit()
|
|||
this->_rule_sequence << std::static_pointer_cast<AbstractExtractor>(curr_rule);
|
||||
|
||||
auto hex_rule = std::static_pointer_cast<BytesAsHex>(curr_rule);
|
||||
hex_rule->setCountWithinParse(1);
|
||||
hex_rule->setCountWithin(1);
|
||||
|
||||
QJsonObject obj;
|
||||
curr_rule->saveTo(obj);
|
||||
|
|
@ -155,6 +155,9 @@ TranslateBasic::TranslateBasic()
|
|||
u_ptr = std::make_shared<BytesAsInteger>();
|
||||
_extractor_types[u_ptr->name()] = u_ptr;
|
||||
|
||||
u_ptr = std::make_shared<BytesAsUnsigned>();
|
||||
_extractor_types[u_ptr->name()] = u_ptr;
|
||||
|
||||
u_ptr = std::make_shared<BytesAsString>();
|
||||
_extractor_types[u_ptr->name()] = u_ptr;
|
||||
|
||||
|
|
|
|||
|
|
@ -21,20 +21,18 @@ StructuralRuleView::StructuralRuleView(QWidget* p /*= nullptr*/)
|
|||
split->addWidget(_configs_stack);
|
||||
|
||||
_configs_stack->addWidget(new EmptyConfiguration(this));
|
||||
auto int_config = new IntegerConfiguration(this);
|
||||
_configs_stack->addWidget(int_config);
|
||||
|
||||
|
||||
connect(int_config, &IntegerConfiguration::ruleHasBeenChanged,
|
||||
_sequence_view, &SequenceRulesView::currentRuleRefresh);
|
||||
//connect(int_config, &IntegerConfiguration::ruleHasBeenChanged,
|
||||
// _sequence_view, &SequenceRulesView::currentRuleRefresh);
|
||||
|
||||
connect(_sequence_view, &SequenceRulesView::currentRuleChanged,
|
||||
[=](std::shared_ptr<ExtractUnit> u, const QModelIndex& i) {
|
||||
if (u->name() == extract::BytesAsInteger().name()) {
|
||||
/*if (u->name() == extract::BytesAsInteger().name()) {
|
||||
_configs_stack->setCurrentIndex(1);
|
||||
int_config->setCurrent(i, u);
|
||||
}
|
||||
else {
|
||||
else */{
|
||||
_configs_stack->setCurrentIndex(0);
|
||||
}
|
||||
});
|
||||
|
|
@ -46,27 +44,4 @@ EmptyConfiguration::EmptyConfiguration(QWidget* p/*=nullptr*/)
|
|||
auto label = new QLabel(u8"µ±Ç°¹æÔòÎÞÐèÅäÖÃ", this);
|
||||
label->setAlignment(Qt::AlignCenter);
|
||||
layout->addWidget(label);
|
||||
}
|
||||
|
||||
IntegerConfiguration::IntegerConfiguration(QWidget* p)
|
||||
:_unsigned_mark(new QCheckBox(this))
|
||||
{
|
||||
auto layout = new QGridLayout(this);
|
||||
layout->addWidget(new QLabel(u8"ÎÞ·ûºÅ£¿£º"), 0, 0);
|
||||
layout->addWidget(_unsigned_mark, 0, 1, 1, 2);
|
||||
layout->setRowStretch(2, 1);
|
||||
|
||||
connect(_unsigned_mark, &QCheckBox::stateChanged, [=](){
|
||||
auto checkmark = _unsigned_mark->isChecked();
|
||||
_current_extractor->setUnsignedMark(checkmark);
|
||||
emit this->ruleHasBeenChanged(_target_modelindex);
|
||||
});
|
||||
}
|
||||
|
||||
void IntegerConfiguration::setCurrent(const QModelIndex& idx, std::shared_ptr<ExtractUnit> u)
|
||||
{
|
||||
this->_target_modelindex = idx;
|
||||
_current_extractor = std::dynamic_pointer_cast<extract::BytesAsInteger>(u);
|
||||
|
||||
this->_unsigned_mark->setChecked(_current_extractor->unsignedMark());
|
||||
}
|
||||
}
|
||||
|
|
@ -17,22 +17,6 @@ public:
|
|||
EmptyConfiguration(QWidget* p = nullptr);
|
||||
};
|
||||
|
||||
namespace extract { class BytesAsInteger; }
|
||||
class IntegerConfiguration : public QWidget {
|
||||
Q_OBJECT
|
||||
private:
|
||||
std::shared_ptr<extract::BytesAsInteger> _current_extractor = nullptr;
|
||||
QModelIndex _target_modelindex;
|
||||
QCheckBox* const _unsigned_mark;
|
||||
|
||||
signals:
|
||||
void ruleHasBeenChanged(const QModelIndex& idx);
|
||||
|
||||
public:
|
||||
IntegerConfiguration(QWidget* p = nullptr);
|
||||
|
||||
void setCurrent(const QModelIndex& idx, std::shared_ptr<ExtractUnit> u);
|
||||
};
|
||||
|
||||
|
||||
class StructuralRuleView : public QWidget
|
||||
|
|
|
|||
|
|
@ -7,13 +7,13 @@ AbstractExtractor::AbstractExtractor(const QString& name, DataType data)
|
|||
:_name_store(name), _type_store(data), _byte_offset(0), _byte_count(0) {
|
||||
}
|
||||
|
||||
bool AbstractExtractor::setOffsetFromPrevious(int bytes)
|
||||
bool AbstractExtractor::setOffsetSpan(int bytes)
|
||||
{
|
||||
this->_byte_offset = bytes;
|
||||
return true;
|
||||
}
|
||||
|
||||
bool AbstractExtractor::setCountWithinParse(int bytes)
|
||||
bool AbstractExtractor::setCountWithin(int bytes)
|
||||
{
|
||||
this->_byte_count = bytes;
|
||||
return true;
|
||||
|
|
@ -29,12 +29,12 @@ DataType AbstractExtractor::outType() const
|
|||
return _type_store;
|
||||
}
|
||||
|
||||
int AbstractExtractor::offsetFromPrevious() const
|
||||
int AbstractExtractor::offsetSpan() const
|
||||
{
|
||||
return _byte_offset;
|
||||
}
|
||||
|
||||
int AbstractExtractor::countWithinParse() const
|
||||
int AbstractExtractor::countWithin() const
|
||||
{
|
||||
return _byte_count;
|
||||
}
|
||||
|
|
@ -52,7 +52,7 @@ void AbstractExtractor::saveTo(QJsonObject& obj) const
|
|||
}
|
||||
|
||||
BytesAsHex::BytesAsHex()
|
||||
: AbstractExtractor(NAME(BytesAsHex), DataType::ValueSequenceString) {
|
||||
: AbstractExtractor(NAME(BytesAsHex), DataType::TextString) {
|
||||
}
|
||||
|
||||
QVariant BytesAsHex::parse(const QByteArray& bytes) const
|
||||
|
|
@ -61,7 +61,7 @@ QVariant BytesAsHex::parse(const QByteArray& bytes) const
|
|||
for (auto char_v : bytes) {
|
||||
result += QString("%1").arg(char_v, 2, 16, QChar('0'));
|
||||
}
|
||||
return result + "H";
|
||||
return result;
|
||||
}
|
||||
|
||||
std::shared_ptr<Serializable> BytesAsHex::newDefault() const
|
||||
|
|
@ -77,7 +77,7 @@ BytesAsBitCombine::BytesAsBitCombine()
|
|||
|
||||
bool BytesAsBitCombine::setSwitchOption(int bit_index, const QString& keyword)
|
||||
{
|
||||
if (bit_index >= 0 && bit_index <= this->countWithinParse() * 8) {
|
||||
if (bit_index >= 0 && bit_index <= this->countWithin() * 8) {
|
||||
_switch_options[bit_index] = keyword;
|
||||
return true;
|
||||
}
|
||||
|
|
@ -141,76 +141,44 @@ std::shared_ptr<Serializable> BytesAsBitCombine::newDefault() const
|
|||
return std::make_shared<BytesAsBitCombine>();
|
||||
}
|
||||
|
||||
void BytesAsInteger::loadFrom(const QJsonObject& obj)
|
||||
{
|
||||
AbstractExtractor::loadFrom(obj);
|
||||
INT32_PEAK(unsigned_mark);
|
||||
}
|
||||
|
||||
void BytesAsInteger::saveTo(QJsonObject& obj) const
|
||||
{
|
||||
AbstractExtractor::saveTo(obj);
|
||||
INT32_SAVE(unsigned_mark);
|
||||
}
|
||||
|
||||
std::shared_ptr<Serializable> BytesAsInteger::newDefault() const
|
||||
{
|
||||
return std::make_shared<BytesAsInteger>();
|
||||
}
|
||||
|
||||
BytesAsInteger::BytesAsInteger()
|
||||
:AbstractExtractor(NAME(BytesAsInteger), DataType::Int64) {
|
||||
:AbstractExtractor(NAME(BytesAsInteger), DataType::Integer) {
|
||||
}
|
||||
|
||||
void BytesAsInteger::setUnsignedMark(bool ste)
|
||||
{
|
||||
this->unsigned_mark = ste;
|
||||
}
|
||||
|
||||
bool BytesAsInteger::unsignedMark() const
|
||||
{
|
||||
return unsigned_mark;
|
||||
}
|
||||
|
||||
bool BytesAsInteger::setCountWithinParse(int bytes)
|
||||
bool BytesAsInteger::setCountWithin(int bytes)
|
||||
{
|
||||
bytes = std::min(8, std::max(bytes, 0));
|
||||
return AbstractExtractor::setCountWithinParse(bytes);
|
||||
return AbstractExtractor::setCountWithin(bytes);
|
||||
}
|
||||
|
||||
QVariant BytesAsInteger::parse(const QByteArray& bytes) const
|
||||
{
|
||||
if (unsigned_mark) {
|
||||
unsigned long long value = 0;
|
||||
for (auto vidx = bytes.size() - 1; vidx >= 0; vidx--) {
|
||||
auto vchar = bytes.at(vidx);
|
||||
value = value << 8;
|
||||
value += (uchar)vchar;
|
||||
}
|
||||
return value;
|
||||
auto last = bytes[bytes.size() - 1];
|
||||
auto mark = last == 0 ? 0 : last / std::abs(last);
|
||||
|
||||
auto xbuffer = bytes;
|
||||
if (mark >= 0) {
|
||||
xbuffer.append(8 - bytes.size(), 0);
|
||||
}
|
||||
else {
|
||||
auto last = bytes[bytes.size() - 1];
|
||||
auto mark = last == 0 ? 0 : last / std::abs(last);
|
||||
|
||||
auto xbuffer = bytes;
|
||||
if (mark >= 0) {
|
||||
xbuffer.append(8 - bytes.size(), 0);
|
||||
}
|
||||
else {
|
||||
xbuffer.append(8 - bytes.size(), 0xff);
|
||||
}
|
||||
|
||||
unsigned long long value = 0;
|
||||
for (auto vidx = xbuffer.size() - 1; vidx >= 0; vidx--) {
|
||||
auto vchar = xbuffer.at(vidx);
|
||||
value = value << 8;
|
||||
value += (uchar)vchar;
|
||||
}
|
||||
return *((long long*)(&value));
|
||||
xbuffer.append(8 - bytes.size(), 0xff);
|
||||
}
|
||||
|
||||
unsigned long long value = 0;
|
||||
for (auto vidx = xbuffer.size() - 1; vidx >= 0; vidx--) {
|
||||
auto vchar = xbuffer.at(vidx);
|
||||
value = value << 8;
|
||||
value += (uchar)vchar;
|
||||
}
|
||||
return *((long long*)(&value));
|
||||
}
|
||||
|
||||
|
||||
#include <QTextCodec>
|
||||
|
||||
BytesAsString::BytesAsString()
|
||||
|
|
@ -295,11 +263,8 @@ void AbstractValueConvert::saveTo(QJsonObject& obj) const
|
|||
}
|
||||
|
||||
DoubleWithLSB::DoubleWithLSB()
|
||||
:AbstractValueConvert(NAME(DoubleWithLSB), DataType::Int64, DataType::Dbl64),
|
||||
_lsb_value(0)
|
||||
{
|
||||
|
||||
}
|
||||
:AbstractValueConvert(NAME(DoubleWithLSB), DataType::Integer, DataType::Dbl64),
|
||||
_lsb_value(1) {}
|
||||
|
||||
void DoubleWithLSB::setLSB(double lsbv)
|
||||
{
|
||||
|
|
@ -333,9 +298,9 @@ std::shared_ptr<Serializable> BytesAsFloat::newDefault() const
|
|||
return std::make_shared<BytesAsFloat>();
|
||||
}
|
||||
|
||||
bool BytesAsFloat::setCountWithinParse(int bytes)
|
||||
bool BytesAsFloat::setCountWithin(int bytes)
|
||||
{
|
||||
AbstractExtractor::setCountWithinParse(4);
|
||||
AbstractExtractor::setCountWithin(4);
|
||||
return true;
|
||||
}
|
||||
|
||||
|
|
@ -355,9 +320,9 @@ QVariant BytesAsDouble::parse(const QByteArray& bytes) const
|
|||
return *((double*)bytes.data());
|
||||
}
|
||||
|
||||
bool BytesAsDouble::setCountWithinParse(int bytes)
|
||||
bool BytesAsDouble::setCountWithin(int bytes)
|
||||
{
|
||||
AbstractExtractor::setCountWithinParse(8);
|
||||
AbstractExtractor::setCountWithin(8);
|
||||
return true;
|
||||
}
|
||||
|
||||
|
|
@ -366,3 +331,31 @@ BytesAsDouble::BytesAsDouble()
|
|||
{
|
||||
|
||||
}
|
||||
|
||||
BytesAsUnsigned::BytesAsUnsigned()
|
||||
:AbstractExtractor(NAME(BytesAsUnsigned), DataType::Unsigned)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
bool BytesAsUnsigned::setCountWithin(int bytes)
|
||||
{
|
||||
auto count = std::max(1, std::min(8, bytes));
|
||||
return AbstractExtractor::setCountWithin(count);
|
||||
}
|
||||
|
||||
QVariant BytesAsUnsigned::parse(const QByteArray& bytes) const
|
||||
{
|
||||
unsigned long long value = 0;
|
||||
for (auto vidx = bytes.size() - 1; vidx >= 0; vidx--) {
|
||||
auto vchar = bytes.at(vidx);
|
||||
value = value << 8;
|
||||
value += (uchar)vchar;
|
||||
}
|
||||
return value;
|
||||
}
|
||||
|
||||
std::shared_ptr<Serializable> BytesAsUnsigned::newDefault() const
|
||||
{
|
||||
return std::make_shared<BytesAsUnsigned>();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -27,20 +27,19 @@ public:
|
|||
virtual std::shared_ptr<Serializable> newDefault() const = 0;
|
||||
};
|
||||
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 内部使用的数据类型
|
||||
/// </summary>
|
||||
enum class DataType {
|
||||
ValueSequenceString,
|
||||
TextString,
|
||||
Int64, // 64λÕûÐλòÎÞ·ûºÅÕûÐÎ
|
||||
Integer, // 整形
|
||||
Unsigned,// 无符号整形
|
||||
Flt32,
|
||||
Dbl64,
|
||||
};
|
||||
|
||||
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 翻译单元抽象接口
|
||||
/// </summary>
|
||||
|
|
@ -64,12 +63,12 @@ public:
|
|||
/// 从上一个单元字节偏移字节数量
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
virtual int offsetFromPrevious() const = 0;
|
||||
virtual int offsetSpan() const = 0;
|
||||
/// <summary>
|
||||
/// 解析所用的字节数量
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
virtual int countWithinParse() const = 0;
|
||||
virtual int countWithin() const = 0;
|
||||
|
||||
/// <summary>
|
||||
/// 执行解析过程
|
||||
|
|
@ -92,18 +91,18 @@ namespace extract {
|
|||
/// 设置偏移字节数量
|
||||
/// </summary>
|
||||
/// <param name="bytes"></param>
|
||||
virtual bool setOffsetFromPrevious(int bytes);
|
||||
virtual bool setOffsetSpan(int bytes);
|
||||
/// <summary>
|
||||
/// 设置解析字节数量
|
||||
/// </summary>
|
||||
/// <param name="bytes"></param>
|
||||
virtual bool setCountWithinParse(int bytes);
|
||||
virtual bool setCountWithin(int bytes);
|
||||
|
||||
// ExtractUnit ===========================
|
||||
QString name() const override;
|
||||
virtual DataType outType() const;
|
||||
int offsetFromPrevious() const override;
|
||||
int countWithinParse() const override;
|
||||
int offsetSpan() const override;
|
||||
int countWithin() const override;
|
||||
|
||||
// Serializable ==============================
|
||||
void loadFrom(const QJsonObject& obj) override;
|
||||
|
|
@ -156,22 +155,28 @@ namespace extract {
|
|||
/// 转换源数据为整形
|
||||
/// </summary>
|
||||
class BytesAsInteger : public AbstractExtractor {
|
||||
private:
|
||||
bool unsigned_mark = false;
|
||||
|
||||
public:
|
||||
BytesAsInteger();
|
||||
|
||||
void setUnsignedMark(bool ste);
|
||||
bool unsignedMark() const;
|
||||
|
||||
// ExtractUnit ============================
|
||||
bool setCountWithinParse(int bytes) override;
|
||||
bool setCountWithin(int bytes) override;
|
||||
QVariant parse(const QByteArray& bytes) const override;
|
||||
|
||||
// Serializable ==============================
|
||||
std::shared_ptr<Serializable> newDefault() const override;
|
||||
};
|
||||
/// <summary>
|
||||
/// 转换源数据为整形
|
||||
/// </summary>
|
||||
class BytesAsUnsigned : public AbstractExtractor {
|
||||
public:
|
||||
BytesAsUnsigned();
|
||||
|
||||
// ExtractUnit ============================
|
||||
bool setCountWithin(int bytes) override;
|
||||
QVariant parse(const QByteArray& bytes) const override;
|
||||
|
||||
// Serializable ==============================
|
||||
void loadFrom(const QJsonObject& obj) override;
|
||||
void saveTo(QJsonObject& obj) const override;
|
||||
std::shared_ptr<Serializable> newDefault() const override;
|
||||
};
|
||||
|
||||
|
|
@ -205,7 +210,7 @@ namespace extract {
|
|||
/// 设置解析字节数量
|
||||
/// </summary>
|
||||
/// <param name="bytes"></param>
|
||||
virtual bool setCountWithinParse(int bytes) override;
|
||||
virtual bool setCountWithin(int bytes) override;
|
||||
|
||||
QVariant parse(const QByteArray& bytes) const override;
|
||||
std::shared_ptr<Serializable> newDefault() const override;
|
||||
|
|
@ -219,7 +224,7 @@ namespace extract {
|
|||
/// 设置解析字节数量
|
||||
/// </summary>
|
||||
/// <param name="bytes"></param>
|
||||
virtual bool setCountWithinParse(int bytes) override;
|
||||
virtual bool setCountWithin(int bytes) override;
|
||||
|
||||
QVariant parse(const QByteArray& bytes) const override;
|
||||
std::shared_ptr<Serializable> newDefault() const override;
|
||||
|
|
|
|||
|
|
@ -105,7 +105,7 @@
|
|||
<ItemGroup>
|
||||
<ClInclude Include="ParseUntility.h" />
|
||||
<QtMoc Include="SequenceView.h" />
|
||||
<QtMoc Include="StructuralRuleView.h" />
|
||||
<ClInclude Include="StructuralRuleView.h" />
|
||||
<ClInclude Include="TranslateBasic.h" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
|
|
|
|||
|
|
@ -40,9 +40,6 @@
|
|||
<ClCompile Include="main.cpp">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="StructView.cpp">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="ParseUntility.cpp">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
|
|
@ -52,17 +49,20 @@
|
|||
<ClCompile Include="SequenceView.cpp">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="StructuralRuleView.cpp">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClInclude Include="StructView.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="ParseUntility.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="TranslateBasic.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="StructuralRuleView.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<None Include="ReadMe.md" />
|
||||
|
|
|
|||
Loading…
Reference in New Issue