/
pi_coder
/
ByteMachine
Обзор
Документация
Войти
/
pi_coder
/
ByteMachine
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
0
CI/CD
Аналитика
Безопасность
master
src/nodes/forms/form_output_file_node.cpp
268 строк
10 KB
pimenov-and
Восстановление функционала старой версии
28 июл 2026, 20:04
28 июл 2026, 20:04
98412d0
Код
Авторство
О чём код?
//////////////////////////////////////////////////////////////// // ByteMachine // Узел для сохранения данных в файл //////////////////////////////////////////////////////////////// #include "form_output_file_node.h" #include "../show_node_state.h" #include "global_settings.h" #include "icons.h" #include <QFileDialog> //============================================================== // Конструктор с параметрами //============================================================== FormOutputFileNode::FormOutputFileNode(OutputFileNode *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_.labelFilePath_->setFont(font); ui_.lineEditFilePath_->setFont(font); ui_.pushBtnResetFilePath_->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 FormOutputFileNode::slotChangedNodeProp(PropValue value) { // Имя if (value.name == "name") { const QString name = node_->name(); ui_.lineEditName_->setText(name); ui_.lineEditName_->setToolTip(name); } // Путь к файлу else if (value.name == "filePath") { const QString filePath = node_->filePath(); ui_.lineEditFilePath_->setText(filePath); ui_.lineEditFilePath_->setToolTip(filePath); const bool isFilePathModified = node_->isFilePathModified(); ui_.pushBtnResetFilePath_->setEnabled(isFilePathModified); } // Признак пропуска 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 FormOutputFileNode::slotChangedNodeState(const NodeStateInfo &stateInfo) { showNodeState(stateInfo, ui_.plainTextEditState_); } //============================================================== // Функция вызывается при завершении редактирования имени //============================================================== void FormOutputFileNode::slotEditingFinishedName() { const QString name = ui_.lineEditName_->text(); node_->setName(name); } //============================================================== // Функция вызывается при завершении редактирования пути к файлу //============================================================== void FormOutputFileNode::slotEditingFinishedFilePath() { const QString path = ui_.lineEditFilePath_->text(); node_->setFilePath(path); } //============================================================== // Функция изменения пути к файлу //============================================================== void FormOutputFileNode::slotChangedFilePath() { const QString caption = "Save File"; const QString dir = ui_.lineEditFilePath_->text(); const QString path = QFileDialog::getOpenFileName(this, caption, dir); if (!path.isEmpty()) { node_->setFilePath(path); } } //============================================================== // Функция сброса пути к файлу //============================================================== void FormOutputFileNode::slotResetFilePath() { node_->resetFilePath(); ui_.lineEditFilePath_->setFocus(); } //============================================================== // Функция вызывается при изменении признака пропуска //============================================================== void FormOutputFileNode::slotChangedBypass(int state) { const bool bypass = static_cast<bool>(state); node_->setBypass(bypass); } //============================================================== // Функция сброса признака пропуска //============================================================== void FormOutputFileNode::slotResetBypass() { node_->resetBypass(); ui_.checkBoxBypass_->setFocus(); } //============================================================== // Функция вызывается при завершении редактирования комментария //============================================================== void FormOutputFileNode::slotEditingFinishedComment() { const QString comment = ui_.lineEditComment_->text(); node_->setComment(comment); } //============================================================== // Сброс комментария //============================================================== void FormOutputFileNode::slotResetComment() { node_->resetComment(); ui_.lineEditComment_->setFocus(); } //============================================================== // Функция вызывается при изменении состояния формы //============================================================== void FormOutputFileNode::changeEvent(QEvent *event) { if (event->type() == QEvent::LanguageChange) { ui_.retranslateUi(this); } else if (event->type() == QEvent::PaletteChange) { correctColorScheme(); } QWidget::changeEvent(event); } //============================================================== // Задание узла //============================================================== void FormOutputFileNode::setNode(OutputFileNode *node) { Q_ASSERT(node != nullptr); node_ = node; // Задание имени const QString name = node_->name(); ui_.lineEditName_->setText(name); ui_.lineEditName_->setToolTip(name); // Задание пути к файлу const QString filePath = node_->filePath(); ui_.lineEditFilePath_->setText(filePath); ui_.lineEditFilePath_->setToolTip(filePath); const bool isFilePathModified = node_->isFilePathModified(); ui_.pushBtnResetFilePath_->setEnabled(isFilePathModified); // Задание признака пропуска 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 isCommentModified = node_->isCommentModified(); ui_.pushBtnResetComment_->setEnabled(isCommentModified); // Задание состояния showNodeState(node_->stateInfo(), ui_.plainTextEditState_); } //============================================================== // Задание соединений //============================================================== void FormOutputFileNode::setConnections() { connect(node_, &BaseNode::sigChangedProp, this, &FormOutputFileNode::slotChangedNodeProp); connect(node_, &OutputFileNode::sigChangedState, this, &FormOutputFileNode::slotChangedNodeState); connect(ui_.lineEditName_, &QLineEdit::editingFinished, this, &FormOutputFileNode::slotEditingFinishedName); connect(ui_.lineEditFilePath_, &QLineEdit::editingFinished, this, &FormOutputFileNode::slotEditingFinishedFilePath); connect(ui_.pushBtnChangeFilePath_, &QPushButton::clicked, this, &FormOutputFileNode::slotChangedFilePath); connect(ui_.pushBtnResetFilePath_, &QPushButton::clicked, this, &FormOutputFileNode::slotResetFilePath); connect(ui_.checkBoxBypass_, &QCheckBox::stateChanged, this, &FormOutputFileNode::slotChangedBypass); connect(ui_.pushBtnResetBypass_, &QPushButton::clicked, this, &FormOutputFileNode::slotResetBypass); connect(ui_.lineEditComment_, &QLineEdit::editingFinished, this, &FormOutputFileNode::slotEditingFinishedComment); connect(ui_.pushBtnResetComment_, &QPushButton::clicked, this, &FormOutputFileNode::slotResetComment); } //============================================================== // Корректировка цветовой схемы //============================================================== void FormOutputFileNode::correctColorScheme() { const ColorThemes theme = globalSettings()->colorTheme(); const QPixmap resetIcon = Icons::resetValue(theme); ui_.pushBtnResetFilePath_->setIcon(resetIcon); ui_.pushBtnResetBypass_->setIcon(resetIcon); ui_.pushBtnResetComment_->setIcon(resetIcon); }