添加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 offset_index = idx.sibling(idx.row(), 1);
|
||||
auto count_index = idx.sibling(idx.row(), 2);
|
||||
if (rule_insv) {
|
||||
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->setCountWithin(count_number);
|
||||
}
|
||||
|
||||
auto count_index = idx.sibling(idx.row(), 3);
|
||||
_sequence_model->setData(offset_index, new_inst->offsetSpan(), 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)
|
||||
{
|
||||
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 new_inst = std::dynamic_pointer_cast<ExtractUnit>(rule_nm->newDefault());
|
||||
_rule_sequence.replace(idx.row(), new_inst);
|
||||
|
@ -79,14 +77,13 @@ SequenceRulesView::SequenceRulesView(QWidget* p /*= nullptr*/)
|
|||
{
|
||||
this->setModel(_sequence_model);
|
||||
_sequence_model->setHorizontalHeaderLabels(QStringList()
|
||||
<< tr(u8"Field Name") << tr(u8"Bytes Offset") << tr(u8"Bytes Count")
|
||||
<< tr(u8"Translate Rule") << tr(u8"Arguments"));
|
||||
<< tr(u8"Field Name") << tr(u8"Bytes Offset") << tr(u8"Translate Rule")
|
||||
<< tr(u8"Bytes Count") << tr(u8"Arguments"));
|
||||
|
||||
auto int_delegate = new IntDelegate(0, INT_MAX);
|
||||
this->setItemDelegateForColumn(1, int_delegate);
|
||||
this->setItemDelegateForColumn(2, int_delegate);
|
||||
auto rule_delegate = new RuleSelectDelegate(base);
|
||||
this->setItemDelegateForColumn(3, rule_delegate);
|
||||
this->setItemDelegateForColumn(2, rule_delegate);
|
||||
|
||||
this->setContextMenuPolicy(Qt::CustomContextMenu);
|
||||
connect(this, &QTableView::customContextMenuRequested, this, &SequenceRulesView::customTranslateRuleEdit);
|
||||
|
@ -117,8 +114,9 @@ void SequenceRulesView::addTranslateUnit()
|
|||
QList<QStandardItem*> new_row;
|
||||
new_row << new QStandardItem(QString(u8"rule_%1").arg(row_cnt));
|
||||
new_row << new QStandardItem(u8"0");
|
||||
new_row << new QStandardItem(u8"1");
|
||||
new_row << new QStandardItem(base->defaultRule()->name());
|
||||
new_row << new QStandardItem(u8"1");
|
||||
new_row.last()->setEditable(false);
|
||||
|
||||
auto curr_rule = base->defaultRule()->newDefault();
|
||||
this->_rule_sequence << std::static_pointer_cast<AbstractExtractor>(curr_rule);
|
||||
|
|
|
@ -21,19 +21,24 @@ StructuralRuleView::StructuralRuleView(QWidget* p /*= nullptr*/)
|
|||
split->addWidget(_configs_stack);
|
||||
|
||||
_configs_stack->addWidget(new EmptyConfiguration(this));
|
||||
auto count_span = new CountWithinConfiguration(this);
|
||||
_configs_stack->addWidget(count_span);
|
||||
|
||||
|
||||
//connect(int_config, &IntegerConfiguration::ruleHasBeenChanged,
|
||||
// _sequence_view, &SequenceRulesView::currentRuleRefresh);
|
||||
connect(count_span, &CountWithinConfiguration::currentRuleChanged,
|
||||
_sequence_view, &SequenceRulesView::currentRuleRefresh);
|
||||
|
||||
connect(_sequence_view, &SequenceRulesView::currentRuleChanged,
|
||||
[=](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);
|
||||
int_config->setCurrent(i, u);
|
||||
}
|
||||
else */{
|
||||
count_span->currentRuleAccept(u, i);
|
||||
break;
|
||||
default:
|
||||
_configs_stack->setCurrentIndex(0);
|
||||
break;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
@ -44,4 +49,34 @@ EmptyConfiguration::EmptyConfiguration(QWidget* p/*=nullptr*/)
|
|||
auto label = new QLabel(u8"µ±Ç°¹æÔòÎÞÐèÅäÖÃ", this);
|
||||
label->setAlignment(Qt::AlignCenter);
|
||||
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);
|
||||
};
|
||||
|
||||
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
|
||||
{
|
||||
|
|
|
@ -110,7 +110,7 @@
|
|||
<ClInclude Include="extract_basic.h" />
|
||||
<ClInclude Include="ParseUntility.h" />
|
||||
<QtMoc Include="SequenceView.h" />
|
||||
<ClInclude Include="StructuralRuleView.h" />
|
||||
<QtMoc Include="StructuralRuleView.h" />
|
||||
<ClInclude Include="TranslateBasic.h" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
|
|
|
@ -66,9 +66,6 @@
|
|||
<ClInclude Include="TranslateBasic.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="StructuralRuleView.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="extract_basic.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
|
@ -86,5 +83,8 @@
|
|||
<QtMoc Include="SequenceView.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</QtMoc>
|
||||
<QtMoc Include="StructuralRuleView.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</QtMoc>
|
||||
</ItemGroup>
|
||||
</Project>
|
|
@ -5,7 +5,7 @@ using namespace extract;
|
|||
|
||||
|
||||
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)
|
||||
|
@ -43,11 +43,13 @@ int AbstractExtractor::countWithin() const
|
|||
void AbstractExtractor::loadFrom(const QJsonObject& obj)
|
||||
{
|
||||
INT32_PEAK(_byte_offset);
|
||||
INT32_PEAK(_byte_count);
|
||||
}
|
||||
|
||||
void AbstractExtractor::saveTo(QJsonObject& obj) const
|
||||
{
|
||||
INT32_SAVE(_byte_offset);
|
||||
INT32_SAVE(_byte_count);
|
||||
}
|
||||
|
||||
BytesAsHex::BytesAsHex()
|
||||
|
@ -232,16 +234,10 @@ std::shared_ptr<Serializable> BytesAsFloat::newDefault() const
|
|||
return std::make_shared<BytesAsFloat>();
|
||||
}
|
||||
|
||||
bool BytesAsFloat::setCountWithin(int bytes)
|
||||
{
|
||||
AbstractExtractor::setCountWithin(4);
|
||||
return true;
|
||||
}
|
||||
|
||||
BytesAsFloat::BytesAsFloat()
|
||||
:AbstractExtractor(NAME(BytesAsFloat), DataType::Flt32)
|
||||
{
|
||||
|
||||
this->setCountWithin(4);
|
||||
}
|
||||
|
||||
std::shared_ptr<Serializable> BytesAsDouble::newDefault() const
|
||||
|
@ -254,16 +250,10 @@ QVariant BytesAsDouble::parse(const QByteArray& bytes) const
|
|||
return *((double*)bytes.data());
|
||||
}
|
||||
|
||||
bool BytesAsDouble::setCountWithin(int bytes)
|
||||
{
|
||||
AbstractExtractor::setCountWithin(8);
|
||||
return true;
|
||||
}
|
||||
|
||||
BytesAsDouble::BytesAsDouble()
|
||||
:AbstractExtractor(NAME(BytesAsDouble), DataType::Dbl64)
|
||||
{
|
||||
|
||||
this->setCountWithin(8);
|
||||
}
|
||||
|
||||
BytesAsUnsigned::BytesAsUnsigned()
|
||||
|
|
|
@ -166,12 +166,6 @@ namespace extract {
|
|||
public:
|
||||
BytesAsFloat();
|
||||
|
||||
/// <summary>
|
||||
/// 设置解析字节数量
|
||||
/// </summary>
|
||||
/// <param name="bytes"></param>
|
||||
virtual bool setCountWithin(int bytes) override;
|
||||
|
||||
QVariant parse(const QByteArray& bytes) const override;
|
||||
std::shared_ptr<Serializable> newDefault() const override;
|
||||
};
|
||||
|
@ -180,12 +174,6 @@ namespace extract {
|
|||
public:
|
||||
BytesAsDouble();
|
||||
|
||||
/// <summary>
|
||||
/// 设置解析字节数量
|
||||
/// </summary>
|
||||
/// <param name="bytes"></param>
|
||||
virtual bool setCountWithin(int bytes) override;
|
||||
|
||||
QVariant parse(const QByteArray& bytes) const override;
|
||||
std::shared_ptr<Serializable> newDefault() const override;
|
||||
};
|
||||
|
|
Loading…
Reference in New Issue