144 lines
4.3 KiB
C++
144 lines
4.3 KiB
C++
#include "StructuralRuleView.h"
|
|
#include <QGridLayout>
|
|
#include <QLabel>
|
|
#include <QComboBox>
|
|
#include <QPushButton>
|
|
#include <QSplitter>
|
|
#include <QGroupBox>
|
|
#include <QTabWidget>
|
|
#include "TranslateBasic.h"
|
|
|
|
StructuralRuleView::StructuralRuleView(QWidget* p /*= nullptr*/)
|
|
:QWidget(p),
|
|
_sequence_view(new SequenceRulesView(this)),
|
|
_configs_stack(new QStackedWidget(this))
|
|
{
|
|
auto layout = new QVBoxLayout(this);
|
|
auto split = new QSplitter(Qt::Horizontal, this);
|
|
layout->addWidget(split);
|
|
|
|
split->addWidget(_sequence_view);
|
|
split->addWidget(_configs_stack);
|
|
|
|
_configs_stack->addWidget(new EmptyConfiguration(this));
|
|
auto count_span = new CountWithinConfiguration(this);
|
|
_configs_stack->addWidget(count_span);
|
|
auto encode_config = new EncodingConfiguration(this);
|
|
_configs_stack->addWidget(encode_config);
|
|
|
|
connect(count_span, &CountWithinConfiguration::currentRuleChanged,
|
|
_sequence_view, &SequenceRulesView::currentRuleRefresh);
|
|
connect(encode_config, &EncodingConfiguration::currentRuleChanged,
|
|
_sequence_view, &SequenceRulesView::currentRuleRefresh);
|
|
|
|
connect(_sequence_view, &SequenceRulesView::currentRuleChanged,
|
|
[=](std::shared_ptr<ExtractUnit> u, const QModelIndex& i) {
|
|
switch (u->outType()) {
|
|
case DataType::TextString:
|
|
if (typeid(*u.get()) == typeid(extract::BytesAsString)) {
|
|
_configs_stack->setCurrentIndex(2);
|
|
encode_config->currentRuleAccept(u, i);
|
|
break;
|
|
}
|
|
case DataType::Integer:
|
|
case DataType::Unsigned:
|
|
_configs_stack->setCurrentIndex(1);
|
|
count_span->currentRuleAccept(u, i);
|
|
break;
|
|
default:
|
|
_configs_stack->setCurrentIndex(0);
|
|
break;
|
|
}
|
|
});
|
|
}
|
|
|
|
EmptyConfiguration::EmptyConfiguration(QWidget* p/*=nullptr*/)
|
|
{
|
|
auto layout = new QVBoxLayout(this);
|
|
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)
|
|
{
|
|
this->_bind_u = u;
|
|
this->_bind_index = i;
|
|
|
|
_count_input->setValue(u->countWithin());
|
|
}
|
|
|
|
#include <QTextCodec>
|
|
EncodingConfiguration::EncodingConfiguration(QWidget* p /*= nullptr*/)
|
|
: QWidget(p), _bind_u(nullptr), _count_input(new QSpinBox(this)),
|
|
_encoding_set(new QComboBox(this))
|
|
{
|
|
auto layout = new QGridLayout(this);
|
|
layout->addWidget(new QLabel(tr("BytesCount:")));
|
|
layout->addWidget(_count_input, 0, 1);
|
|
layout->addWidget(new QLabel(tr("Encoding:")), 1, 0);
|
|
layout->addWidget(_encoding_set, 1, 1);
|
|
layout->setRowStretch(2, 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);
|
|
}
|
|
}
|
|
});
|
|
|
|
auto codec_list = QTextCodec::availableCodecs();
|
|
for(auto codec : codec_list)
|
|
_encoding_set->addItem(QString::fromLatin1(codec));
|
|
connect(_encoding_set, QOverload<const QString&>::of(&QComboBox::currentIndexChanged),
|
|
[=](const QString &value) {
|
|
if (this->_bind_u) {
|
|
auto ptr = std::dynamic_pointer_cast<extract::BytesAsString>(this->_bind_u);
|
|
if (ptr) {
|
|
auto insx = QTextCodec::codecForName(value.toUtf8());
|
|
ptr->setStrCodec(insx);
|
|
emit this->currentRuleChanged(_bind_index);
|
|
}
|
|
}
|
|
});
|
|
}
|
|
|
|
void EncodingConfiguration::currentRuleAccept(std::shared_ptr<ExtractUnit> u, const QModelIndex& i)
|
|
{
|
|
this->_bind_u = u;
|
|
this->_bind_index = i;
|
|
|
|
_count_input->setValue(u->countWithin());
|
|
auto codec_name = std::dynamic_pointer_cast<extract::BytesAsString>(u)->codecName();
|
|
|
|
QSignalBlocker x(this->_encoding_set);
|
|
this->_encoding_set->setCurrentText(codec_name);
|
|
}
|