添加StringEncoding配置
This commit is contained in:
parent
c6e1604e3c
commit
bf6e6d694f
|
@ -23,14 +23,23 @@ StructuralRuleView::StructuralRuleView(QWidget* p /*= nullptr*/)
|
|||
_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);
|
||||
|
@ -73,10 +82,62 @@ CountWithinConfiguration::CountWithinConfiguration(QWidget* p /*= nullptr*/)
|
|||
});
|
||||
}
|
||||
|
||||
void CountWithinConfiguration::currentRuleAccept(std::shared_ptr<ExtractUnit> u, const QModelIndex& i) const
|
||||
void CountWithinConfiguration::currentRuleAccept(std::shared_ptr<ExtractUnit> u, const QModelIndex& i)
|
||||
{
|
||||
const_cast<CountWithinConfiguration*>(this)->_bind_u = u;
|
||||
const_cast<CountWithinConfiguration*>(this)->_bind_index = 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);
|
||||
}
|
||||
|
|
|
@ -27,7 +27,24 @@ private:
|
|||
public:
|
||||
CountWithinConfiguration(QWidget* p = nullptr);
|
||||
|
||||
void currentRuleAccept(std::shared_ptr<ExtractUnit> u, const QModelIndex& i) const;
|
||||
void currentRuleAccept(std::shared_ptr<ExtractUnit> u, const QModelIndex& i);
|
||||
|
||||
signals:
|
||||
void currentRuleChanged(const QModelIndex& idx);
|
||||
};
|
||||
|
||||
class EncodingConfiguration : public QWidget {
|
||||
Q_OBJECT
|
||||
private:
|
||||
std::shared_ptr<ExtractUnit> _bind_u;
|
||||
QModelIndex _bind_index;
|
||||
QSpinBox* const _count_input;
|
||||
QComboBox* const _encoding_set;
|
||||
|
||||
public:
|
||||
EncodingConfiguration(QWidget* p = nullptr);
|
||||
|
||||
void currentRuleAccept(std::shared_ptr<ExtractUnit> u, const QModelIndex& i);
|
||||
|
||||
signals:
|
||||
void currentRuleChanged(const QModelIndex& idx);
|
||||
|
|
Loading…
Reference in New Issue