SingleBaseUnit配置
This commit is contained in:
parent
6670a333c2
commit
7a9ae2812c
|
|
@ -5,19 +5,22 @@
|
|||
#include <QGridLayout>
|
||||
#include <QLabel>
|
||||
#include <QComboBox>
|
||||
#include <QJsonDocument>
|
||||
#include <QPushButton>
|
||||
#include <QSplitter>
|
||||
#include <QGroupBox>
|
||||
#include <QTabWidget>
|
||||
#include <QTextCodec>
|
||||
#include <QMenu>
|
||||
#include <QHeaderView>
|
||||
|
||||
using namespace unit_configurations;
|
||||
using namespace size_provider;
|
||||
using namespace extract;
|
||||
|
||||
ExtractRuleView::ExtractRuleView(std::shared_ptr<TranslateBasic> base,
|
||||
std::shared_ptr<extract::AsRuleSet> inst_r, QWidget* p /*= nullptr*/)
|
||||
: QWidget(p), _rule_base(inst_r),
|
||||
: QWidget(p), _rule_base(inst_r), _base_bind(base),
|
||||
_member_units(new QTableView(this)),
|
||||
_member_model(new QStandardItemModel(this)),
|
||||
_configs_stack(new QStackedWidget(this))
|
||||
|
|
@ -33,8 +36,81 @@ ExtractRuleView::ExtractRuleView(std::shared_ptr<TranslateBasic> base,
|
|||
|
||||
_configs_stack->addWidget(new configurations::EmptyConfiguration(this));
|
||||
auto single_configs = new SingleBasedConfiguration(base, this);
|
||||
_configs_stack->addWidget(single_configs);
|
||||
auto list_configs = new ListBasedConfiguration(base, this);
|
||||
_configs_stack->addWidget(list_configs);
|
||||
auto union_configs = new UnionBasedConfiguration(base, this);
|
||||
_configs_stack->addWidget(union_configs);
|
||||
|
||||
connect(_member_units, &QTableView::clicked, [=](const QModelIndex& target) {
|
||||
if (!target.isValid())
|
||||
return;
|
||||
|
||||
auto unit = _rule_base->operator[](target.row());
|
||||
if (unit->baseType() == SingleBasedUnit::topic()) {
|
||||
_configs_stack->setCurrentIndex(1);
|
||||
single_configs->currentAccept(unit, target);
|
||||
}
|
||||
else {
|
||||
_configs_stack->setCurrentIndex(0);
|
||||
}
|
||||
});
|
||||
|
||||
_member_units->setModel(_member_model);
|
||||
_member_model->setHorizontalHeaderLabels(QStringList() << "FieldName" << "OffsetSpan"<< "UnitType" );
|
||||
_member_units->setContextMenuPolicy(Qt::CustomContextMenu);
|
||||
connect(_member_units, &QTableView::customContextMenuRequested, [=](const QPoint& pt) {
|
||||
QMenu m;
|
||||
m.addAction("Append Unit", this, &ExtractRuleView::appendUnit);
|
||||
m.exec(_member_units->mapToGlobal(pt));
|
||||
});
|
||||
}
|
||||
|
||||
void ExtractRuleView::reload()
|
||||
{
|
||||
auto cnt = _member_model->rowCount();
|
||||
_member_model->removeRows(0, cnt);
|
||||
|
||||
auto list = _rule_base->fieldNames();
|
||||
for (auto key : list) {
|
||||
auto field_mbr = _rule_base->operator[](key);
|
||||
QList<QStandardItem*> row;
|
||||
row << new QStandardItem(field_mbr->name());
|
||||
row << new QStandardItem(QString("%1").arg(field_mbr->offsetSpan()));
|
||||
row.last()->setEditable(false);
|
||||
row << new QStandardItem(field_mbr->baseType());
|
||||
_member_model->appendRow(row);
|
||||
}
|
||||
_member_units->resizeColumnsToContents();
|
||||
}
|
||||
|
||||
#include <QInputDialog>
|
||||
void ExtractRuleView::appendUnit()
|
||||
{
|
||||
auto name_u = QInputDialog::getText(this, "FieldName Enter", "Name");
|
||||
if (name_u == "")
|
||||
return;
|
||||
|
||||
auto inst_u = _base_bind->defaultExtractUnitType()->newDefault();
|
||||
auto new_unit = std::dynamic_pointer_cast<SingleBasedUnit>(inst_u);
|
||||
new_unit->setName(name_u);
|
||||
auto delt_key = _base_bind->delegateAlias().first();
|
||||
auto delt_o = _base_bind->operator[](delt_key);
|
||||
auto delt_u = delt_o->newDefault();
|
||||
QJsonObject content;
|
||||
delt_o->saveTo(content);
|
||||
delt_u->loadFrom(_base_bind, content);
|
||||
new_unit->setDelegate(std::dynamic_pointer_cast<ExtractDelegate>(delt_u));
|
||||
this->_rule_base->append(new_unit);
|
||||
|
||||
reload();
|
||||
}
|
||||
|
||||
void ExtractRuleView::showEvent(QShowEvent* e)
|
||||
{
|
||||
QWidget::showEvent(e);
|
||||
|
||||
reload();
|
||||
}
|
||||
|
||||
ListBasedConfiguration::ListBasedConfiguration(
|
||||
|
|
@ -62,9 +138,56 @@ ListBasedConfiguration::ListBasedConfiguration(
|
|||
layout->setColumnStretch(1, 1);
|
||||
}
|
||||
|
||||
SingleBasedConfiguration::SingleBasedConfiguration(std::shared_ptr<TranslateBasic> core, QWidget* p /*= nullptr*/)
|
||||
{
|
||||
|
||||
SingleBasedConfiguration::SingleBasedConfiguration(std::shared_ptr<TranslateBasic> core, QWidget* p /*= nullptr*/)
|
||||
: QWidget(p), _bind_core(core),
|
||||
_offset_enter(new QSpinBox(this)),
|
||||
_delegate_changed(new QComboBox(this)),
|
||||
_delegate_sync(new QPushButton("Sync", this)),
|
||||
_content_display(new QTextBrowser(this))
|
||||
{
|
||||
auto layout = new QGridLayout(this);
|
||||
layout->addWidget(new QLabel("Offset:", this), 0, 0);
|
||||
layout->addWidget(this->_offset_enter, 0, 1);
|
||||
layout->addWidget(this->_delegate_sync, 0, 2);
|
||||
layout->addWidget(new QLabel("Delegate:", this), 1, 0);
|
||||
layout->addWidget(this->_delegate_changed, 1, 1, 1, 2);
|
||||
layout->addWidget(this->_content_display, 2, 0, 3, 3);
|
||||
layout->setColumnStretch(1, 1);
|
||||
|
||||
connect(this->_offset_enter, QOverload<int>::of(&QSpinBox::valueChanged),
|
||||
[=](int v_offset) {
|
||||
inst_current->setOffsetSpan(v_offset);
|
||||
emit this->reloadRequest();
|
||||
});
|
||||
connect(this->_delegate_changed, QOverload<const QString&>::of(&QComboBox::currentTextChanged),
|
||||
[=](const QString& current_alias) {
|
||||
auto vinst = _bind_core->operator[](current_alias)->newDefault();
|
||||
inst_current->setDelegate(std::dynamic_pointer_cast<ExtractDelegate>(vinst));
|
||||
emit this->reloadRequest();
|
||||
});
|
||||
}
|
||||
|
||||
void SingleBasedConfiguration::currentAccept(std::shared_ptr<ExtractUnit> inst_u, const QModelIndex& idx)
|
||||
{
|
||||
inst_current = std::dynamic_pointer_cast<SingleBasedUnit>(inst_u);
|
||||
idx_current = idx;
|
||||
|
||||
QSignalBlocker b(_offset_enter);
|
||||
_offset_enter->setRange(0, INT_MAX);
|
||||
_offset_enter->setValue(inst_u->offsetSpan());
|
||||
|
||||
QSignalBlocker v(_delegate_changed);
|
||||
_delegate_changed->clear();
|
||||
_delegate_changed->addItems(_bind_core->delegateAlias());
|
||||
auto conv = std::dynamic_pointer_cast<SingleBasedUnit>(inst_u);
|
||||
_delegate_changed->setCurrentText(conv->delegateInst()->aliasName());
|
||||
|
||||
QJsonObject contents;
|
||||
inst_u->saveTo(contents);
|
||||
this->_content_display->setPlainText(QString::fromUtf8(
|
||||
QJsonDocument(contents).toJson()
|
||||
));
|
||||
}
|
||||
|
||||
UnionBasedConfiguration::UnionBasedConfiguration(std::shared_ptr<TranslateBasic> core, QWidget* p /*= nullptr*/)
|
||||
|
|
|
|||
|
|
@ -6,14 +6,35 @@
|
|||
#include <QLineEdit>
|
||||
#include <QStackedWidget>
|
||||
#include <QSpinBox>
|
||||
#include <QPushButton>
|
||||
#include <QCheckBox>
|
||||
#include <QTextBrowser>
|
||||
#include "extract_basic.h"
|
||||
#include "TranslateBasic.h"
|
||||
|
||||
namespace extract {
|
||||
class SingleBasedUnit;
|
||||
}
|
||||
|
||||
namespace unit_configurations {
|
||||
class SingleBasedConfiguration : public QWidget {
|
||||
Q_OBJECT
|
||||
private:
|
||||
std::shared_ptr<TranslateBasic> _bind_core;
|
||||
QSpinBox* const _offset_enter;
|
||||
QComboBox* const _delegate_changed;
|
||||
QPushButton* const _delegate_sync;
|
||||
QTextBrowser* const _content_display;
|
||||
|
||||
std::shared_ptr<extract::SingleBasedUnit> inst_current = nullptr;
|
||||
QModelIndex idx_current;
|
||||
|
||||
public:
|
||||
SingleBasedConfiguration(std::shared_ptr<TranslateBasic> core, QWidget* p = nullptr);
|
||||
void currentAccept(std::shared_ptr<ExtractUnit> inst_u, const QModelIndex& idx);
|
||||
|
||||
signals:
|
||||
void reloadRequest();
|
||||
};
|
||||
|
||||
/// <summary>
|
||||
|
|
@ -51,10 +72,19 @@ private:
|
|||
QStackedWidget* const _configs_stack;
|
||||
|
||||
std::shared_ptr<extract::AsRuleSet> _rule_base;
|
||||
std::shared_ptr<TranslateBasic> _base_bind;
|
||||
std::shared_ptr<FieldManagerLayer> _current_fields_cache = nullptr;
|
||||
|
||||
public:
|
||||
ExtractRuleView(std::shared_ptr<TranslateBasic> base,
|
||||
std::shared_ptr<extract::AsRuleSet> inst_r, QWidget* p = nullptr);
|
||||
ExtractRuleView(
|
||||
std::shared_ptr<TranslateBasic> base,
|
||||
std::shared_ptr<extract::AsRuleSet> inst_r,
|
||||
QWidget* p = nullptr);
|
||||
|
||||
void reload();
|
||||
void appendUnit();
|
||||
|
||||
protected:
|
||||
void showEvent(QShowEvent *e) override;
|
||||
};
|
||||
|
||||
|
|
|
|||
|
|
@ -49,12 +49,12 @@ TranslateBasic::TranslateBasic()
|
|||
|
||||
}
|
||||
|
||||
std::shared_ptr<ExtractDelegate> TranslateBasic::defaultExtractDelegate() const
|
||||
std::shared_ptr<ExtractDelegate> TranslateBasic::defaultExtractDelegateType() const
|
||||
{
|
||||
return _default_translate_rule;
|
||||
}
|
||||
|
||||
QHash<QString, std::shared_ptr<ExtractDelegate>> TranslateBasic::extractorMap() const
|
||||
QHash<QString, std::shared_ptr<ExtractDelegate>> TranslateBasic::extractDelegateTypeMap() const
|
||||
{
|
||||
return _basic_extractor_types;
|
||||
}
|
||||
|
|
@ -146,12 +146,12 @@ QHash<QString, std::shared_ptr<RuleMatch>> TranslateBasic::ruleMatchMap() const
|
|||
return _rule_match_types;
|
||||
}
|
||||
|
||||
std::shared_ptr<ExtractUnit> TranslateBasic::defaultExtractUnit() const
|
||||
std::shared_ptr<ExtractUnit> TranslateBasic::defaultExtractUnitType() const
|
||||
{
|
||||
return _default_process_unit;
|
||||
}
|
||||
|
||||
QHash<QString, std::shared_ptr<ExtractUnit>> TranslateBasic::extractUnitMap() const
|
||||
QHash<QString, std::shared_ptr<ExtractUnit>> TranslateBasic::extractUnitTypeMap() const
|
||||
{
|
||||
return _process_unit_types;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -130,14 +130,14 @@ private:
|
|||
public:
|
||||
TranslateBasic();
|
||||
|
||||
std::shared_ptr<ExtractDelegate> defaultExtractDelegate() const;
|
||||
QHash<QString, std::shared_ptr<ExtractDelegate>> extractorMap() const;
|
||||
std::shared_ptr<ExtractDelegate> defaultExtractDelegateType() const;
|
||||
QHash<QString, std::shared_ptr<ExtractDelegate>> extractDelegateTypeMap() const;
|
||||
std::shared_ptr<SizeProvider> defaultSizeProvider() const;
|
||||
QHash<QString, std::shared_ptr<SizeProvider>> sizeProviderMap() const;
|
||||
std::shared_ptr<RuleMatch> defaultRuleMatch() const;
|
||||
QHash<QString, std::shared_ptr<RuleMatch>> ruleMatchMap() const;
|
||||
std::shared_ptr<ExtractUnit> defaultExtractUnit() const;
|
||||
QHash<QString, std::shared_ptr<ExtractUnit>> extractUnitMap() const;
|
||||
std::shared_ptr<ExtractUnit> defaultExtractUnitType() const;
|
||||
QHash<QString, std::shared_ptr<ExtractUnit>> extractUnitTypeMap() const;
|
||||
|
||||
void addDelegate(std::shared_ptr<ExtractDelegate> inst);
|
||||
void removeDelegate(const QString& alias);
|
||||
|
|
|
|||
|
|
@ -7,7 +7,7 @@
|
|||
using namespace configurations;
|
||||
|
||||
WrapConfigs::WrapConfigs(std::shared_ptr<TranslateBasic> _base, QWidget* p)
|
||||
: QWidget(p), _bind_base(_base),
|
||||
: QDialog(p), _bind_base(_base),
|
||||
_alias_view(new QTableView(this)),
|
||||
_alias_model(new QStandardItemModel(this)),
|
||||
_configurations(new QStackedWidget(this))
|
||||
|
|
@ -129,7 +129,7 @@ void WrapConfigs::aliasAppend()
|
|||
while (exists.contains(name))
|
||||
name += "#";
|
||||
|
||||
auto ins = _bind_base->defaultExtractDelegate()->newDefault();
|
||||
auto ins = _bind_base->defaultExtractDelegateType()->newDefault();
|
||||
auto nins = std::dynamic_pointer_cast<ExtractDelegate>(ins);
|
||||
nins->setAlias(name);
|
||||
|
||||
|
|
@ -173,7 +173,7 @@ void WrapConfigs::dataChanged(QStandardItem* cell)
|
|||
auto origin_key = total_alias_set.at(cell->row());
|
||||
|
||||
auto new_type = cell->text();
|
||||
auto new_ins = _bind_base->extractorMap()[new_type]->newDefault();
|
||||
auto new_ins = _bind_base->extractUnitTypeMap()[new_type]->newDefault();
|
||||
auto new_delegate = std::dynamic_pointer_cast<ExtractDelegate>(new_ins);
|
||||
new_delegate->setAlias(origin_key);
|
||||
_bind_base->replaceDelegate(origin_key, new_delegate);
|
||||
|
|
@ -197,7 +197,7 @@ QWidget* RuleSelectDelegate::createEditor(QWidget* parent, const QStyleOptionVie
|
|||
|
||||
void RuleSelectDelegate::setEditorData(QWidget* editor, const QModelIndex& index) const
|
||||
{
|
||||
auto rule_names = this->_kernel->extractorMap().keys();
|
||||
auto rule_names = this->_kernel->extractUnitTypeMap().keys();
|
||||
std::sort(rule_names.begin(), rule_names.end());
|
||||
|
||||
auto combo = dynamic_cast<QComboBox*>(editor);
|
||||
|
|
|
|||
|
|
@ -3,6 +3,7 @@
|
|||
#include <QStandardItemModel>
|
||||
#include <QTableView>
|
||||
#include <QStackedWidget>
|
||||
#include <QDialog>
|
||||
#include <QStyledItemDelegate>
|
||||
#include "TranslateBasic.h"
|
||||
|
||||
|
|
@ -24,7 +25,7 @@ public:
|
|||
virtual void updateEditorGeometry(QWidget* editor, const QStyleOptionViewItem& option, const QModelIndex& index) const override;
|
||||
};
|
||||
|
||||
class WrapConfigs : public QWidget {
|
||||
class WrapConfigs : public QDialog {
|
||||
private:
|
||||
std::shared_ptr<TranslateBasic> _bind_base;
|
||||
|
||||
|
|
|
|||
|
|
@ -384,7 +384,7 @@ void AsRuleSet::loadFrom(std::shared_ptr<TranslateBasic> core, const QJsonObject
|
|||
QJsonObject match_obj;
|
||||
OBJECT_PEAK(match_obj, rule_obj);
|
||||
|
||||
auto xdev = core->extractUnitMap()[unit_type]->newDefault();
|
||||
auto xdev = core->extractUnitTypeMap()[unit_type]->newDefault();
|
||||
xdev->loadFrom(core, match_obj);
|
||||
_bind.sub_units << std::dynamic_pointer_cast<ExtractUnit>(xdev);
|
||||
}
|
||||
|
|
@ -566,6 +566,11 @@ int SingleBasedUnit::countWithin() const
|
|||
}
|
||||
|
||||
QString SingleBasedUnit::baseType() const
|
||||
{
|
||||
return topic();
|
||||
}
|
||||
|
||||
QString SingleBasedUnit::topic()
|
||||
{
|
||||
return NAME(SingleBasedUnit);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -287,6 +287,7 @@ namespace extract {
|
|||
void setDelegate(std::shared_ptr<ExtractDelegate> inst);
|
||||
|
||||
public:
|
||||
static QString topic();
|
||||
QString baseType() const;
|
||||
QString name() const override;
|
||||
void setName(const QString& name) override;
|
||||
|
|
|
|||
|
|
@ -4,14 +4,19 @@
|
|||
#include "TranslateBasic.h"
|
||||
#include <cmath>
|
||||
#include "WrapConfigs.h"
|
||||
#include "ExtractRuleView.h"
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
QApplication app(argc, argv);
|
||||
|
||||
auto core = std::make_shared<TranslateBasic>();
|
||||
WrapConfigs w(core);
|
||||
w.show();
|
||||
WrapConfigs v(core);
|
||||
v.exec();
|
||||
|
||||
auto rule = std::make_shared<extract::AsRuleSet>();
|
||||
ExtractRuleView view(core, rule);
|
||||
view.show();
|
||||
|
||||
return app.exec();
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue