refact
This commit is contained in:
parent
36649a7d8e
commit
fbf498de9d
|
@ -38,7 +38,7 @@ void SequenceView::tidyRuleAt(const QModelIndex& idx)
|
|||
auto rule_idx = idx.sibling(idx.row(), 3);
|
||||
auto rule_nm = base->extactors()[rule_idx.data(Qt::DisplayRole).toString()];
|
||||
auto new_inst = std::dynamic_pointer_cast<ExtractUnit>(rule_nm->newDefault());
|
||||
_rule_list.replace(idx.row(), new_inst);
|
||||
_rule_sequence.replace(idx.row(), new_inst);
|
||||
|
||||
auto offset_index = idx.sibling(idx.row(), 1);
|
||||
auto offset_number = offset_index.data(Qt::DisplayRole).toInt();
|
||||
|
@ -51,14 +51,14 @@ void SequenceView::tidyRuleAt(const QModelIndex& idx)
|
|||
rule_insv->setCountWithinParse(count_number);
|
||||
}
|
||||
|
||||
_seqs_model->setData(offset_index, new_inst->offsetFromPrevious(), Qt::EditRole);
|
||||
_seqs_model->setData(count_index, new_inst->countWithinParse(), Qt::EditRole);
|
||||
_sequence_model->setData(offset_index, new_inst->offsetFromPrevious(), Qt::EditRole);
|
||||
_sequence_model->setData(count_index, new_inst->countWithinParse(), Qt::EditRole);
|
||||
|
||||
auto param_index = idx.sibling(idx.row(), 4);
|
||||
QJsonObject obj;
|
||||
rule_insv->saveTo(obj);
|
||||
auto bytes = QJsonDocument(obj).toJson(QJsonDocument::Compact);
|
||||
_seqs_model->setData(param_index, QString::fromUtf8(bytes));
|
||||
_sequence_model->setData(param_index, QString::fromUtf8(bytes));
|
||||
|
||||
this->resizeColumnsToContents();
|
||||
}
|
||||
|
@ -66,11 +66,11 @@ void SequenceView::tidyRuleAt(const QModelIndex& idx)
|
|||
#include <QItemSelectionModel>
|
||||
SequenceView::SequenceView(QWidget* p /*= nullptr*/)
|
||||
:QTableView(p),
|
||||
_seqs_model(new QStandardItemModel),
|
||||
_sequence_model(new QStandardItemModel),
|
||||
base(std::make_shared<TranslateBasic>())
|
||||
{
|
||||
this->setModel(_seqs_model);
|
||||
_seqs_model->setHorizontalHeaderLabels(QStringList()
|
||||
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"));
|
||||
|
||||
|
@ -86,9 +86,11 @@ SequenceView::SequenceView(QWidget* p /*= nullptr*/)
|
|||
connect(int_delegate, &IntDelegate::valueChanged, this, &SequenceView::tidyRuleAt);
|
||||
|
||||
auto select_model = this->selectionModel();
|
||||
connect(select_model, &QItemSelectionModel::currentRowChanged, [=](const QModelIndex &curr){
|
||||
emit this->currentRuleChanged(_rule_list[curr.row()]);
|
||||
});
|
||||
connect(select_model, &QItemSelectionModel::currentRowChanged, [=](const QModelIndex& curr) {
|
||||
if (!curr.isValid())
|
||||
return;
|
||||
|
||||
emit this->currentRuleChanged(_rule_sequence[curr.row()]); });
|
||||
}
|
||||
|
||||
#include <QMenu>
|
||||
|
@ -102,7 +104,7 @@ void SequenceView::customTranslateRuleEdit(const QPoint& pos)
|
|||
|
||||
void SequenceView::addTranslateUnit()
|
||||
{
|
||||
auto row_cnt = this->_seqs_model->rowCount();
|
||||
auto row_cnt = this->_sequence_model->rowCount();
|
||||
|
||||
QList<QStandardItem*> new_row;
|
||||
new_row << new QStandardItem(QString(u8"rule_%1").arg(row_cnt));
|
||||
|
@ -111,7 +113,7 @@ void SequenceView::addTranslateUnit()
|
|||
new_row << new QStandardItem(base->defaultRule()->name());
|
||||
|
||||
auto curr_rule = base->defaultRule()->newDefault();
|
||||
this->_rule_list << std::static_pointer_cast<AbstractExtractor>(curr_rule);
|
||||
this->_rule_sequence << std::static_pointer_cast<AbstractExtractor>(curr_rule);
|
||||
|
||||
auto hex_rule = std::static_pointer_cast<BytesAsHex>(curr_rule);
|
||||
hex_rule->setCountWithinParse(1);
|
||||
|
@ -122,12 +124,18 @@ void SequenceView::addTranslateUnit()
|
|||
auto json_doc = QString::fromUtf8(bytes);
|
||||
new_row << new QStandardItem(json_doc);
|
||||
|
||||
this->_seqs_model->appendRow(new_row);
|
||||
this->_sequence_model->appendRow(new_row);
|
||||
this->resizeColumnsToContents();
|
||||
}
|
||||
|
||||
void SequenceView::removeTranslateUnit()
|
||||
{
|
||||
auto idx_curr = this->currentIndex();
|
||||
if (!idx_curr.isValid())
|
||||
return;
|
||||
|
||||
_rule_sequence.removeAt(idx_curr.row());
|
||||
_sequence_model->removeRow(idx_curr.row());
|
||||
}
|
||||
|
||||
TranslateBasic::TranslateBasic()
|
||||
|
|
|
@ -4,30 +4,13 @@
|
|||
#include <QStandardItemModel>
|
||||
#include <QStyledItemDelegate>
|
||||
#include <QItemDelegate>
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
class IntDelegate : public QStyledItemDelegate {
|
||||
Q_OBJECT
|
||||
private:
|
||||
int _min_value, _max_value;
|
||||
|
||||
signals:
|
||||
void valueChanged(const QModelIndex &idx) const;
|
||||
|
||||
public:
|
||||
IntDelegate(int min, int max);
|
||||
|
||||
virtual QWidget* createEditor(QWidget* parent, const QStyleOptionViewItem& option, const QModelIndex& index) const override;
|
||||
virtual void setEditorData(QWidget* editor, const QModelIndex& index) const override;
|
||||
virtual void setModelData(QWidget* editor, QAbstractItemModel* model, const QModelIndex& index) const override;
|
||||
virtual void updateEditorGeometry(QWidget* editor, const QStyleOptionViewItem& option, const QModelIndex& index) const override;
|
||||
};
|
||||
|
||||
#include <QHash>
|
||||
#include <memory>
|
||||
class ExtractUnit;
|
||||
|
||||
/// <summary>
|
||||
/// 翻译程序核心
|
||||
/// </summary>
|
||||
class TranslateBasic {
|
||||
private:
|
||||
QHash<QString, std::shared_ptr<ExtractUnit>> _extractor_types;
|
||||
|
@ -41,6 +24,31 @@ public:
|
|||
|
||||
};
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 整形修改代理
|
||||
/// </summary>
|
||||
class IntDelegate : public QStyledItemDelegate {
|
||||
Q_OBJECT
|
||||
private:
|
||||
int _min_value, _max_value;
|
||||
|
||||
signals:
|
||||
void valueChanged(const QModelIndex& idx) const;
|
||||
|
||||
public:
|
||||
IntDelegate(int min, int max);
|
||||
|
||||
virtual QWidget* createEditor(QWidget* parent, const QStyleOptionViewItem& option, const QModelIndex& index) const override;
|
||||
virtual void setEditorData(QWidget* editor, const QModelIndex& index) const override;
|
||||
virtual void setModelData(QWidget* editor, QAbstractItemModel* model, const QModelIndex& index) const override;
|
||||
virtual void updateEditorGeometry(QWidget* editor, const QStyleOptionViewItem& option, const QModelIndex& index) const override;
|
||||
};
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 翻译规则编辑代理
|
||||
/// </summary>
|
||||
class RuleSelectDelegate : public QStyledItemDelegate {
|
||||
Q_OBJECT
|
||||
private:
|
||||
|
@ -58,12 +66,16 @@ public:
|
|||
virtual void updateEditorGeometry(QWidget* editor, const QStyleOptionViewItem& option, const QModelIndex& index) const override;
|
||||
};
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 序列化规则视图
|
||||
/// </summary>
|
||||
class SequenceView : public QTableView {
|
||||
Q_OBJECT
|
||||
private:
|
||||
QStandardItemModel* const _seqs_model;
|
||||
QStandardItemModel* const _sequence_model;
|
||||
std::shared_ptr<TranslateBasic> base = nullptr;
|
||||
QList<std::shared_ptr<ExtractUnit>> _rule_list;
|
||||
QList<std::shared_ptr<ExtractUnit>> _rule_sequence;
|
||||
|
||||
signals:
|
||||
void currentRuleChanged(std::shared_ptr<ExtractUnit> u) const;
|
||||
|
|
Loading…
Reference in New Issue