添加CountWIthin配置面板
This commit is contained in:
parent
9ba8763873
commit
c6e1604e3c
|
@ -41,14 +41,12 @@ void SequenceRulesView::currentRuleRefresh(const QModelIndex& idx)
|
||||||
auto rule_insv = std::dynamic_pointer_cast<AbstractExtractor>(new_inst);
|
auto rule_insv = std::dynamic_pointer_cast<AbstractExtractor>(new_inst);
|
||||||
|
|
||||||
auto offset_index = idx.sibling(idx.row(), 1);
|
auto offset_index = idx.sibling(idx.row(), 1);
|
||||||
auto count_index = idx.sibling(idx.row(), 2);
|
|
||||||
if (rule_insv) {
|
if (rule_insv) {
|
||||||
auto offset_number = offset_index.data(Qt::DisplayRole).toInt();
|
auto offset_number = offset_index.data(Qt::DisplayRole).toInt();
|
||||||
auto count_number = count_index.data(Qt::DisplayRole).toInt();
|
|
||||||
rule_insv->setOffsetSpan(offset_number);
|
rule_insv->setOffsetSpan(offset_number);
|
||||||
rule_insv->setCountWithin(count_number);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
auto count_index = idx.sibling(idx.row(), 3);
|
||||||
_sequence_model->setData(offset_index, new_inst->offsetSpan(), Qt::EditRole);
|
_sequence_model->setData(offset_index, new_inst->offsetSpan(), Qt::EditRole);
|
||||||
_sequence_model->setData(count_index, new_inst->countWithin(), Qt::EditRole);
|
_sequence_model->setData(count_index, new_inst->countWithin(), Qt::EditRole);
|
||||||
|
|
||||||
|
@ -63,7 +61,7 @@ void SequenceRulesView::currentRuleRefresh(const QModelIndex& idx)
|
||||||
|
|
||||||
void SequenceRulesView::peersRuleChanged(const QModelIndex& idx)
|
void SequenceRulesView::peersRuleChanged(const QModelIndex& idx)
|
||||||
{
|
{
|
||||||
auto rule_idx = idx.sibling(idx.row(), 3);
|
auto rule_idx = idx.sibling(idx.row(), 2);
|
||||||
auto rule_nm = base->extactors()[rule_idx.data(Qt::DisplayRole).toString()];
|
auto rule_nm = base->extactors()[rule_idx.data(Qt::DisplayRole).toString()];
|
||||||
auto new_inst = std::dynamic_pointer_cast<ExtractUnit>(rule_nm->newDefault());
|
auto new_inst = std::dynamic_pointer_cast<ExtractUnit>(rule_nm->newDefault());
|
||||||
_rule_sequence.replace(idx.row(), new_inst);
|
_rule_sequence.replace(idx.row(), new_inst);
|
||||||
|
@ -79,14 +77,13 @@ SequenceRulesView::SequenceRulesView(QWidget* p /*= nullptr*/)
|
||||||
{
|
{
|
||||||
this->setModel(_sequence_model);
|
this->setModel(_sequence_model);
|
||||||
_sequence_model->setHorizontalHeaderLabels(QStringList()
|
_sequence_model->setHorizontalHeaderLabels(QStringList()
|
||||||
<< tr(u8"Field Name") << tr(u8"Bytes Offset") << tr(u8"Bytes Count")
|
<< tr(u8"Field Name") << tr(u8"Bytes Offset") << tr(u8"Translate Rule")
|
||||||
<< tr(u8"Translate Rule") << tr(u8"Arguments"));
|
<< tr(u8"Bytes Count") << tr(u8"Arguments"));
|
||||||
|
|
||||||
auto int_delegate = new IntDelegate(0, INT_MAX);
|
auto int_delegate = new IntDelegate(0, INT_MAX);
|
||||||
this->setItemDelegateForColumn(1, int_delegate);
|
this->setItemDelegateForColumn(1, int_delegate);
|
||||||
this->setItemDelegateForColumn(2, int_delegate);
|
|
||||||
auto rule_delegate = new RuleSelectDelegate(base);
|
auto rule_delegate = new RuleSelectDelegate(base);
|
||||||
this->setItemDelegateForColumn(3, rule_delegate);
|
this->setItemDelegateForColumn(2, rule_delegate);
|
||||||
|
|
||||||
this->setContextMenuPolicy(Qt::CustomContextMenu);
|
this->setContextMenuPolicy(Qt::CustomContextMenu);
|
||||||
connect(this, &QTableView::customContextMenuRequested, this, &SequenceRulesView::customTranslateRuleEdit);
|
connect(this, &QTableView::customContextMenuRequested, this, &SequenceRulesView::customTranslateRuleEdit);
|
||||||
|
@ -117,8 +114,9 @@ void SequenceRulesView::addTranslateUnit()
|
||||||
QList<QStandardItem*> new_row;
|
QList<QStandardItem*> new_row;
|
||||||
new_row << new QStandardItem(QString(u8"rule_%1").arg(row_cnt));
|
new_row << new QStandardItem(QString(u8"rule_%1").arg(row_cnt));
|
||||||
new_row << new QStandardItem(u8"0");
|
new_row << new QStandardItem(u8"0");
|
||||||
new_row << new QStandardItem(u8"1");
|
|
||||||
new_row << new QStandardItem(base->defaultRule()->name());
|
new_row << new QStandardItem(base->defaultRule()->name());
|
||||||
|
new_row << new QStandardItem(u8"1");
|
||||||
|
new_row.last()->setEditable(false);
|
||||||
|
|
||||||
auto curr_rule = base->defaultRule()->newDefault();
|
auto curr_rule = base->defaultRule()->newDefault();
|
||||||
this->_rule_sequence << std::static_pointer_cast<AbstractExtractor>(curr_rule);
|
this->_rule_sequence << std::static_pointer_cast<AbstractExtractor>(curr_rule);
|
||||||
|
|
|
@ -21,19 +21,24 @@ StructuralRuleView::StructuralRuleView(QWidget* p /*= nullptr*/)
|
||||||
split->addWidget(_configs_stack);
|
split->addWidget(_configs_stack);
|
||||||
|
|
||||||
_configs_stack->addWidget(new EmptyConfiguration(this));
|
_configs_stack->addWidget(new EmptyConfiguration(this));
|
||||||
|
auto count_span = new CountWithinConfiguration(this);
|
||||||
|
_configs_stack->addWidget(count_span);
|
||||||
|
|
||||||
|
connect(count_span, &CountWithinConfiguration::currentRuleChanged,
|
||||||
//connect(int_config, &IntegerConfiguration::ruleHasBeenChanged,
|
_sequence_view, &SequenceRulesView::currentRuleRefresh);
|
||||||
// _sequence_view, &SequenceRulesView::currentRuleRefresh);
|
|
||||||
|
|
||||||
connect(_sequence_view, &SequenceRulesView::currentRuleChanged,
|
connect(_sequence_view, &SequenceRulesView::currentRuleChanged,
|
||||||
[=](std::shared_ptr<ExtractUnit> u, const QModelIndex& i) {
|
[=](std::shared_ptr<ExtractUnit> u, const QModelIndex& i) {
|
||||||
/*if (u->name() == extract::BytesAsInteger().name()) {
|
switch (u->outType()) {
|
||||||
|
case DataType::TextString:
|
||||||
|
case DataType::Integer:
|
||||||
|
case DataType::Unsigned:
|
||||||
_configs_stack->setCurrentIndex(1);
|
_configs_stack->setCurrentIndex(1);
|
||||||
int_config->setCurrent(i, u);
|
count_span->currentRuleAccept(u, i);
|
||||||
}
|
break;
|
||||||
else */{
|
default:
|
||||||
_configs_stack->setCurrentIndex(0);
|
_configs_stack->setCurrentIndex(0);
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
@ -45,3 +50,33 @@ EmptyConfiguration::EmptyConfiguration(QWidget* p/*=nullptr*/)
|
||||||
label->setAlignment(Qt::AlignCenter);
|
label->setAlignment(Qt::AlignCenter);
|
||||||
layout->addWidget(label);
|
layout->addWidget(label);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#include "extract_basic.h"
|
||||||
|
CountWithinConfiguration::CountWithinConfiguration(QWidget* p /*= nullptr*/)
|
||||||
|
: QWidget(p), _bind_u(nullptr), _count_input(new QSpinBox(this))
|
||||||
|
{
|
||||||
|
auto layout = new QGridLayout(this);
|
||||||
|
layout->addWidget(new QLabel(tr("BytesCount:")));
|
||||||
|
layout->addWidget(_count_input, 0, 1);
|
||||||
|
_count_input->setRange(1, 100);
|
||||||
|
layout->setRowStretch(1, 1);
|
||||||
|
layout->setColumnStretch(1, 1);
|
||||||
|
|
||||||
|
connect(_count_input, QOverload<int>::of(&QSpinBox::valueChanged), [=](int value) {
|
||||||
|
if (this->_bind_u) {
|
||||||
|
auto ptr = std::dynamic_pointer_cast<extract::AbstractExtractor>(this->_bind_u);
|
||||||
|
if (ptr) {
|
||||||
|
ptr->setCountWithin(value);
|
||||||
|
emit this->currentRuleChanged(_bind_index);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
void CountWithinConfiguration::currentRuleAccept(std::shared_ptr<ExtractUnit> u, const QModelIndex& i) const
|
||||||
|
{
|
||||||
|
const_cast<CountWithinConfiguration*>(this)->_bind_u = u;
|
||||||
|
const_cast<CountWithinConfiguration*>(this)->_bind_index = i;
|
||||||
|
|
||||||
|
_count_input->setValue(u->countWithin());
|
||||||
|
}
|
||||||
|
|
|
@ -17,7 +17,21 @@ public:
|
||||||
EmptyConfiguration(QWidget* p = nullptr);
|
EmptyConfiguration(QWidget* p = nullptr);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
class CountWithinConfiguration : public QWidget {
|
||||||
|
Q_OBJECT
|
||||||
|
private:
|
||||||
|
std::shared_ptr<ExtractUnit> _bind_u;
|
||||||
|
QModelIndex _bind_index;
|
||||||
|
QSpinBox *const _count_input;
|
||||||
|
|
||||||
|
public:
|
||||||
|
CountWithinConfiguration(QWidget* p = nullptr);
|
||||||
|
|
||||||
|
void currentRuleAccept(std::shared_ptr<ExtractUnit> u, const QModelIndex& i) const;
|
||||||
|
|
||||||
|
signals:
|
||||||
|
void currentRuleChanged(const QModelIndex& idx);
|
||||||
|
};
|
||||||
|
|
||||||
class StructuralRuleView : public QWidget
|
class StructuralRuleView : public QWidget
|
||||||
{
|
{
|
||||||
|
|
|
@ -110,7 +110,7 @@
|
||||||
<ClInclude Include="extract_basic.h" />
|
<ClInclude Include="extract_basic.h" />
|
||||||
<ClInclude Include="ParseUntility.h" />
|
<ClInclude Include="ParseUntility.h" />
|
||||||
<QtMoc Include="SequenceView.h" />
|
<QtMoc Include="SequenceView.h" />
|
||||||
<ClInclude Include="StructuralRuleView.h" />
|
<QtMoc Include="StructuralRuleView.h" />
|
||||||
<ClInclude Include="TranslateBasic.h" />
|
<ClInclude Include="TranslateBasic.h" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
|
|
|
@ -66,9 +66,6 @@
|
||||||
<ClInclude Include="TranslateBasic.h">
|
<ClInclude Include="TranslateBasic.h">
|
||||||
<Filter>Header Files</Filter>
|
<Filter>Header Files</Filter>
|
||||||
</ClInclude>
|
</ClInclude>
|
||||||
<ClInclude Include="StructuralRuleView.h">
|
|
||||||
<Filter>Header Files</Filter>
|
|
||||||
</ClInclude>
|
|
||||||
<ClInclude Include="extract_basic.h">
|
<ClInclude Include="extract_basic.h">
|
||||||
<Filter>Header Files</Filter>
|
<Filter>Header Files</Filter>
|
||||||
</ClInclude>
|
</ClInclude>
|
||||||
|
@ -86,5 +83,8 @@
|
||||||
<QtMoc Include="SequenceView.h">
|
<QtMoc Include="SequenceView.h">
|
||||||
<Filter>Header Files</Filter>
|
<Filter>Header Files</Filter>
|
||||||
</QtMoc>
|
</QtMoc>
|
||||||
|
<QtMoc Include="StructuralRuleView.h">
|
||||||
|
<Filter>Header Files</Filter>
|
||||||
|
</QtMoc>
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
</Project>
|
</Project>
|
|
@ -5,7 +5,7 @@ using namespace extract;
|
||||||
|
|
||||||
|
|
||||||
AbstractExtractor::AbstractExtractor(const QString& name, DataType data)
|
AbstractExtractor::AbstractExtractor(const QString& name, DataType data)
|
||||||
:_name_store(name), _type_store(data), _byte_offset(0), _byte_count(0) {
|
:_name_store(name), _type_store(data), _byte_offset(0), _byte_count(1) {
|
||||||
}
|
}
|
||||||
|
|
||||||
bool AbstractExtractor::setOffsetSpan(int bytes)
|
bool AbstractExtractor::setOffsetSpan(int bytes)
|
||||||
|
@ -43,11 +43,13 @@ int AbstractExtractor::countWithin() const
|
||||||
void AbstractExtractor::loadFrom(const QJsonObject& obj)
|
void AbstractExtractor::loadFrom(const QJsonObject& obj)
|
||||||
{
|
{
|
||||||
INT32_PEAK(_byte_offset);
|
INT32_PEAK(_byte_offset);
|
||||||
|
INT32_PEAK(_byte_count);
|
||||||
}
|
}
|
||||||
|
|
||||||
void AbstractExtractor::saveTo(QJsonObject& obj) const
|
void AbstractExtractor::saveTo(QJsonObject& obj) const
|
||||||
{
|
{
|
||||||
INT32_SAVE(_byte_offset);
|
INT32_SAVE(_byte_offset);
|
||||||
|
INT32_SAVE(_byte_count);
|
||||||
}
|
}
|
||||||
|
|
||||||
BytesAsHex::BytesAsHex()
|
BytesAsHex::BytesAsHex()
|
||||||
|
@ -232,16 +234,10 @@ std::shared_ptr<Serializable> BytesAsFloat::newDefault() const
|
||||||
return std::make_shared<BytesAsFloat>();
|
return std::make_shared<BytesAsFloat>();
|
||||||
}
|
}
|
||||||
|
|
||||||
bool BytesAsFloat::setCountWithin(int bytes)
|
|
||||||
{
|
|
||||||
AbstractExtractor::setCountWithin(4);
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
BytesAsFloat::BytesAsFloat()
|
BytesAsFloat::BytesAsFloat()
|
||||||
:AbstractExtractor(NAME(BytesAsFloat), DataType::Flt32)
|
:AbstractExtractor(NAME(BytesAsFloat), DataType::Flt32)
|
||||||
{
|
{
|
||||||
|
this->setCountWithin(4);
|
||||||
}
|
}
|
||||||
|
|
||||||
std::shared_ptr<Serializable> BytesAsDouble::newDefault() const
|
std::shared_ptr<Serializable> BytesAsDouble::newDefault() const
|
||||||
|
@ -254,16 +250,10 @@ QVariant BytesAsDouble::parse(const QByteArray& bytes) const
|
||||||
return *((double*)bytes.data());
|
return *((double*)bytes.data());
|
||||||
}
|
}
|
||||||
|
|
||||||
bool BytesAsDouble::setCountWithin(int bytes)
|
|
||||||
{
|
|
||||||
AbstractExtractor::setCountWithin(8);
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
BytesAsDouble::BytesAsDouble()
|
BytesAsDouble::BytesAsDouble()
|
||||||
:AbstractExtractor(NAME(BytesAsDouble), DataType::Dbl64)
|
:AbstractExtractor(NAME(BytesAsDouble), DataType::Dbl64)
|
||||||
{
|
{
|
||||||
|
this->setCountWithin(8);
|
||||||
}
|
}
|
||||||
|
|
||||||
BytesAsUnsigned::BytesAsUnsigned()
|
BytesAsUnsigned::BytesAsUnsigned()
|
||||||
|
|
|
@ -166,12 +166,6 @@ namespace extract {
|
||||||
public:
|
public:
|
||||||
BytesAsFloat();
|
BytesAsFloat();
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// 设置解析字节数量
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="bytes"></param>
|
|
||||||
virtual bool setCountWithin(int bytes) override;
|
|
||||||
|
|
||||||
QVariant parse(const QByteArray& bytes) const override;
|
QVariant parse(const QByteArray& bytes) const override;
|
||||||
std::shared_ptr<Serializable> newDefault() const override;
|
std::shared_ptr<Serializable> newDefault() const override;
|
||||||
};
|
};
|
||||||
|
@ -180,12 +174,6 @@ namespace extract {
|
||||||
public:
|
public:
|
||||||
BytesAsDouble();
|
BytesAsDouble();
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// 设置解析字节数量
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="bytes"></param>
|
|
||||||
virtual bool setCountWithin(int bytes) override;
|
|
||||||
|
|
||||||
QVariant parse(const QByteArray& bytes) const override;
|
QVariant parse(const QByteArray& bytes) const override;
|
||||||
std::shared_ptr<Serializable> newDefault() const override;
|
std::shared_ptr<Serializable> newDefault() const override;
|
||||||
};
|
};
|
||||||
|
|
Loading…
Reference in New Issue