// // Created by bbr on 18. 04. 2022.. // #include "attribute_dialog.h" #include "mainwindow.h" namespace display { void AttributeDialog::onUpdate() { auto oldValue = attributeValue->value; attributeValue->value = value; domain::ComdelValidator validator(domain::getSupportedValidators()); domain::ValidationContext context; for (auto &addressSpace: MainWindow::getLibrary()->getAddressSpaces()) { context.addressSpaces.insert(std::make_pair(addressSpace.getName(), addressSpace)); } auto validationErrors = validator.validateAttribute(attributeValue, context); if(validationErrors.empty()) { accept(); } else { bool canAccept = true; std::vector errors; std::vector warnings; for(auto& err: validationErrors) { if(err.type == domain::Action::ERROR) { errors.push_back(err); } else { warnings.push_back(err); } } if(!errors.empty()) { canAccept = false; auto errorDialog = new ErrorDialog(errors); errorDialog->exec(); } for(auto& warning: warnings) { auto warningDialog = new WarningDialog(warning); int response = warningDialog->exec(); if(response == QDialog::Rejected) { canAccept = false; } } if(canAccept) { accept(); } else { attributeValue->value = oldValue; } } } void MemoryDialog::onUpdate() { attributeValue->value = value; accept(); } }