/
pi_coder
/
ByteMachine
Обзор
Документация
Войти
/
pi_coder
/
ByteMachine
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
0
CI/CD
Аналитика
Безопасность
master
src/nodes/forms/form_dump_node.cpp
302 строки
11 KB
pimenov-and
Восстановление функционала старой версии
28 июл 2026, 20:04
28 июл 2026, 20:04
98412d0
Код
Авторство
О чём код?
//////////////////////////////////////////////////////////////// // ByteMachine // Виджет для настройки узла Dump //////////////////////////////////////////////////////////////// #include "form_dump_node.h" #include "../show_node_state.h" #include "global_settings.h" #include "icons.h" //============================================================== // Конструктор с параметрами //============================================================== FormDumpNode::FormDumpNode(DumpNode *node, QWidget *parent) : QWidget{parent} { Q_ASSERT(node != nullptr); ui_.setupUi(this); setNode(node); setConnections(); correctColorScheme(); #ifdef Q_OS_WASM const QFont font{"Segoe UI", 10}; setFont(font); ui_.labelName_->setFont(font); ui_.lineEditName_->setFont(font); ui_.labelByteWidth_->setFont(font); ui_.comboBoxByteWidth_->setFont(font); ui_.labelDumpMode_->setFont(font); ui_.comboBoxDumpMode_->setFont(font); ui_.checkBoxBypass_->setFont(font); ui_.labelComment_->setFont(font); ui_.lineEditComment_->setFont(font); ui_.labelState_->setFont(font); ui_.plainTextEditState_->setFont(font); #endif // Q_OS_WASM } //============================================================== // Функция вызывается при изменении свойств узла //============================================================== void FormDumpNode:: slotChangedNodeProp(PropValue value) { if (value.name == "name") { const QString name = node_->name(); ui_.lineEditName_->setText(name); ui_.lineEditName_->setToolTip(name); } else if (value.name == "byteWidth") { const ByteWidths byteWidth = node_->byteWidth(); const int byteWidthIndex = byteWidthToIndex(byteWidth); Q_ASSERT(byteWidthIndex != -1); ui_.comboBoxByteWidth_->setCurrentIndex(byteWidthIndex); const bool isByteWidthModified = node_->isByteWidthModified(); ui_.pushBtnResetByteWidth_->setEnabled(isByteWidthModified); } else if (value.name == "dumpMode") { const DumpModes mode = node_->dumpMode(); const int modeIndex = dumpModeToInt(mode); Q_ASSERT(modeIndex != -1); ui_.comboBoxDumpMode_->setCurrentIndex(modeIndex); const bool isModeModified = node_->isDumpModeModified(); ui_.pushBtnResetDumpMode_->setEnabled(isModeModified); } else if (value.name == "bypass") { const bool isBypass = node_->isBypass(); ui_.checkBoxBypass_->setChecked(isBypass); const bool isBypassModified = node_->isBypassModified(); ui_.pushBtnResetBypass_->setEnabled(isBypassModified); } else if (value.name == "comment") { const QString comment = node_->comment(); ui_.lineEditComment_->setText(comment); ui_.lineEditComment_->setToolTip(comment); const bool isCommentChanged = node_->isCommentModified(); ui_.pushBtnResetComment_->setEnabled(isCommentChanged); } } //==============================================================+ // Функция вызывается при изменении состояния узла //============================================================== void FormDumpNode::slotChangedNodeState(const NodeStateInfo &stateInfo) { showNodeState(stateInfo, ui_.plainTextEditState_); } //============================================================== // Функция вызывается при завершении редактирования имени //============================================================== void FormDumpNode::slotEditingFinishedName() { const QString name = ui_.lineEditName_->text(); node_->setName(name); } //============================================================== // Изменение ширины в байтах //============================================================== void FormDumpNode::slotChangedByteWidth(int index) { if (index == -1) { return; } const ByteWidths byteWidth = indexToByteWidth(index); node_->setByteWidth(byteWidth); } //============================================================== // Сброс ширины в байтах //============================================================== void FormDumpNode::slotResetByteWidth() { node_->resetByteWidth(); ui_.comboBoxByteWidth_->setFocus(); } //============================================================== // Изменение режима дампа //============================================================== void FormDumpNode::slotChangeDumpMode(int index) { if (index == -1) { return; } const DumpModes mode = intToDumpMode(index); node_->setDumpMode(mode); } //============================================================== // Сброс режима дампа //============================================================== void FormDumpNode::slotResetDumpMode() { node_->resetDumpMode(); ui_.comboBoxDumpMode_->setFocus(); } //============================================================== // Функция вызывается при изменении признака пропуска //============================================================== void FormDumpNode::slotChangedBypass(int state) { const bool bypass = static_cast<bool>(state); node_->setBypass(bypass); } //============================================================== // Сброс признака пропуска //============================================================== void FormDumpNode::slotResetBypass() { node_->resetBypass(); ui_.checkBoxBypass_->setFocus(); } //============================================================== // Функция вызывается при завершении редактирования комментария //============================================================== void FormDumpNode::slotEditingFinishedComment() { const QString comment = ui_.lineEditComment_->text(); node_->setComment(comment); } //============================================================== // Сброс комментария //============================================================== void FormDumpNode::slotResetComment() { node_->resetComment(); ui_.lineEditComment_->setFocus(); } //============================================================== // Функция вызывается при изменении состояния формы //============================================================== void FormDumpNode::changeEvent(QEvent *event) { if (event->type() == QEvent::LanguageChange) { ui_.retranslateUi(this); } else if (event->type() == QEvent::PaletteChange) { correctColorScheme(); } QWidget::changeEvent(event); } //============================================================== // Задание соединений //============================================================== void FormDumpNode::setConnections() { connect(node_, &DumpNode::sigChangedProp, this, &FormDumpNode::slotChangedNodeProp); connect(node_, &DumpNode::sigChangedState, this, &FormDumpNode::slotChangedNodeState); connect(ui_.lineEditName_, &QLineEdit::editingFinished, this, &FormDumpNode::slotEditingFinishedName); connect(ui_.comboBoxByteWidth_, qOverload<int>(&QComboBox::currentIndexChanged), this, &FormDumpNode::slotChangedByteWidth); connect(ui_.pushBtnResetByteWidth_, &QPushButton::clicked, this, &FormDumpNode::slotResetByteWidth); connect(ui_.comboBoxDumpMode_, qOverload<int>(&QComboBox::currentIndexChanged), this, &FormDumpNode::slotChangeDumpMode); connect(ui_.pushBtnResetDumpMode_, &QPushButton::clicked, this, &FormDumpNode::slotResetDumpMode); connect(ui_.checkBoxBypass_, &QCheckBox::stateChanged, this, &FormDumpNode::slotChangedBypass); connect(ui_.pushBtnResetBypass_, &QPushButton::clicked, this, &FormDumpNode::slotResetBypass); connect(ui_.lineEditComment_, &QLineEdit::editingFinished, this, &FormDumpNode::slotEditingFinishedComment); connect(ui_.pushBtnResetComment_, &QPushButton::clicked, this, &FormDumpNode::slotResetComment); } //============================================================== // Задание узла //============================================================== void FormDumpNode::setNode(DumpNode *node) { Q_ASSERT(node != nullptr); node_ = node; // Задание имени const QString name = node_->name(); ui_.lineEditName_->setText(name); ui_.lineEditName_->setToolTip(name); // Задание ширины в байтах const ByteWidths byteWidth = node_->byteWidth(); const int byteWidthIndex = byteWidthToIndex(byteWidth); Q_ASSERT(byteWidthIndex != -1); ui_.comboBoxByteWidth_->setCurrentIndex(byteWidthIndex); const bool isByteWidthModified = node_->isByteWidthModified(); ui_.pushBtnResetByteWidth_->setEnabled(isByteWidthModified); // Задание режима const DumpModes mode = node_->dumpMode(); const int modeIndex = dumpModeToInt(mode); Q_ASSERT(modeIndex != -1); ui_.comboBoxDumpMode_->setCurrentIndex(modeIndex); const bool isModeModified = node_->isDumpModeModified(); ui_.pushBtnResetDumpMode_->setEnabled(isModeModified); // Задание признака пропуска const bool isBypass = node_->isBypass(); ui_.checkBoxBypass_->setChecked(isBypass); const bool isBypassModified = node_->isBypassModified(); ui_.pushBtnResetBypass_->setEnabled(isBypassModified); // Задание комментария const QString comment = node_->comment(); ui_.lineEditComment_->setText(comment); ui_.lineEditComment_->setToolTip(comment); const bool isCommentChanged = node_->isCommentModified(); ui_.pushBtnResetComment_->setEnabled(isCommentChanged); // Задание состояния узла const NodeStateInfo stateInfo = node_->stateInfo(); showNodeState(stateInfo, ui_.plainTextEditState_); } //============================================================== // Корректировка цветовой схемы //============================================================== void FormDumpNode::correctColorScheme() { const ColorThemes theme = globalSettings()->colorTheme(); const QPixmap resetIcon = Icons::resetValue(theme); ui_.pushBtnResetBypass_->setIcon(resetIcon); ui_.pushBtnResetByteWidth_->setIcon(resetIcon); ui_.pushBtnResetDumpMode_->setIcon(resetIcon); ui_.pushBtnResetComment_->setIcon(resetIcon); }