diff --git a/comdel/display/attribute_dialog.cpp b/comdel/display/attribute_dialog.cpp index 60ce931..372e822 100644 --- a/comdel/display/attribute_dialog.cpp +++ b/comdel/display/attribute_dialog.cpp @@ -9,59 +9,8 @@ namespace display { - void AttributeDialog::onUpdate() { - auto oldValue = attributeValue->value; - - attributeValue->value = value; - domain::ComdelValidator validator(domain::getSupportedValidators()); - - domain::ValidationContext context; - - for (auto &addressSpace: Application::instance()->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; - } - } - - } - AttributeDialog::AttributeDialog(domain::InstanceAttribute *attribute, bool updating) { - setAttribute(Qt::WA_DeleteOnClose); attributeValue = attribute; @@ -142,10 +91,68 @@ namespace display { layout->addWidget(group); } - auto button = new QPushButton(updating ? "Ažuriraj" : "Postavi"); - connect(button, &QPushButton::clicked, this, &AttributeDialog::onUpdate); - layout->addWidget(button); + auto buttonLayout = new QHBoxLayout(this); + + auto okButton = new QPushButton(updating ? "Ažuriraj" : "Postavi", this); + auto cancelButton = new QPushButton("Odustani", this); + + connect(okButton, &QPushButton::clicked, this, &AttributeDialog::onUpdate); + connect(cancelButton, &QPushButton::clicked, [this]() { reject(); }); + + buttonLayout->addWidget(okButton); + buttonLayout->addWidget(cancelButton); + + layout->addLayout(buttonLayout); + } + + void AttributeDialog::onUpdate() { + auto oldValue = attributeValue->value; + + attributeValue->value = value; + domain::ComdelValidator validator(domain::getSupportedValidators()); + + domain::ValidationContext context; + + for (auto &addressSpace: Application::instance()->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 AttributeDialog::onTextChanged(const QString &string) { @@ -165,12 +172,6 @@ namespace display { value = attributeValue->attribute.getPopup()->getEnumeration()[index].getValue(); } - - void MemoryDialog::onUpdate() { - attributeValue->value = value; - accept(); - } - MemoryDialog::MemoryDialog(domain::InstanceAttribute *attribute, std::vector> instances, bool updating) { memoryInstances = std::vector(); @@ -216,10 +217,23 @@ namespace display { } } - auto button = new QPushButton(updating ? "Ažuriraj" : "Postavi"); - connect(button, &QPushButton::clicked, this, &MemoryDialog::onUpdate); + auto buttonLayout = new QHBoxLayout(this); - layout->addWidget(button); + auto okButton = new QPushButton(updating ? "Ažuriraj" : "Postavi"); + auto cancelButton = new QPushButton("Odustani", this); + + connect(okButton, &QPushButton::clicked, this, &MemoryDialog::onUpdate); + connect(cancelButton, &QPushButton::clicked, [this]() { reject(); }); + + buttonLayout->addWidget(okButton); + buttonLayout->addWidget(cancelButton); + + layout->addLayout(buttonLayout); + } + + void MemoryDialog::onUpdate() { + attributeValue->value = value; + accept(); } void MemoryDialog::onMemoryChanged(int index) { @@ -264,6 +278,6 @@ namespace display { buttonLayout->addWidget(okButton); buttonLayout->addWidget(cancelButton); - layout->addItem(buttonLayout); + layout->addLayout(buttonLayout); } } \ No newline at end of file diff --git a/comdel/display/component_display.cpp b/comdel/display/component_display.cpp index 2ef59b0..33b7cc5 100644 --- a/comdel/display/component_display.cpp +++ b/comdel/display/component_display.cpp @@ -272,24 +272,6 @@ namespace display { setPos(instance->position.first, instance->position.second); } - void BusConnection::contextMenuEvent(QGraphicsSceneContextMenuEvent *event) { - QMenu menu; - menu.addAction("Ukloni poveznicu", [this]() {}); - menu.addSeparator(); - for (int i = 0; i < this->connection->attributes.size(); i++) { - auto *attr = &this->connection->attributes[i]; - bool enabled = attr->attribute.getPopup().has_value(); - - auto action = menu.addAction(QString::fromStdString("Izmjeni " + attr->name), - [attr]() { - auto dialog = new AttributeDialog(attr); - dialog->exec(); - }); - action->setEnabled(enabled); - } - menu.exec(event->screenPos()); - } - BusConnection::BusConnection(domain::BusConnectionInstance *connection, ComponentGroup *component, BusGroup *bus): connection( connection), component(component), bus(bus) { updateConnection(); @@ -314,36 +296,6 @@ namespace display { connection->end.second = connection->bus->position.second + busPosition.height() / 2; } - - void DirectConnection::contextMenuEvent(QGraphicsSceneContextMenuEvent *event) { - QMenu menu; - menu.addAction("Ukloni poveznicu", [this]() {}); - menu.addSeparator(); - - if(connection->bus->bus.getType() == domain::Bus::SINGLE_AUTOMATIC) { - auto &attributes = this->connection->attributes; - menu.addAction(QString::fromStdString("Izmjeni poveznicu"), - [&attributes]() { - auto dialog = new display::SingleAutomaticDialog(attributes); - dialog->exec(); - }); - } else { - for (int i = 0; i < this->connection->attributes.size(); i++) { - auto *attr = &this->connection->attributes[i]; - bool enabled = attr->attribute.getPopup().has_value(); - - auto action = menu.addAction(QString::fromStdString("Izmjeni " + attr->name), - [attr]() { - auto dialog = new AttributeDialog(attr); - dialog->exec(); - }); - action->setEnabled(enabled); - } - } - - menu.exec(event->screenPos()); - } - DirectConnection::DirectConnection(domain::DirectConnectionInstance *connection, ComponentGroup *first, ComponentGroup *second): connection(connection), first(first), second(second) { updateConnection(); diff --git a/comdel/display/component_display.h b/comdel/display/component_display.h index fb92aed..d72d7aa 100644 --- a/comdel/display/component_display.h +++ b/comdel/display/component_display.h @@ -95,8 +95,6 @@ namespace display { BusConnection(domain::BusConnectionInstance *connection, ComponentGroup *component, BusGroup *bus); void updateConnection(); - - void contextMenuEvent(QGraphicsSceneContextMenuEvent *event) override; }; @@ -110,8 +108,6 @@ namespace display { DirectConnection(domain::DirectConnectionInstance *connection, ComponentGroup *first, ComponentGroup *second); void updateConnection(); - - void contextMenuEvent(QGraphicsSceneContextMenuEvent *event) override; }; diff --git a/comdel/display/name_dialog.cpp b/comdel/display/name_dialog.cpp index 87c3ed7..45837ca 100644 --- a/comdel/display/name_dialog.cpp +++ b/comdel/display/name_dialog.cpp @@ -16,10 +16,20 @@ display::NameDialog::NameDialog(std::string currentName, std::set & connect(edit, &QLineEdit::textChanged, this, &NameDialog::onNameUpdate); layout->addWidget(edit); setWindowTitle("Izmjeni ime"); - button = new QPushButton("Ažuriraj", this); - connect(button, &QPushButton::clicked, this, &NameDialog::onNameChange); - layout->addWidget(button); setLayout(layout); + + auto buttonLayout = new QHBoxLayout(this); + + auto okButton = new QPushButton("Ažuriraj"); + auto cancelButton = new QPushButton("Odustani", this); + + connect(okButton, &QPushButton::clicked, this, &NameDialog::onNameChange); + connect(cancelButton, &QPushButton::clicked, [this]() { reject(); }); + + buttonLayout->addWidget(okButton); + buttonLayout->addWidget(cancelButton); + + layout->addLayout(buttonLayout); } void display::NameDialog::onNameUpdate(const QString &text) { diff --git a/comdel/display/single_automatic_dialog.cpp b/comdel/display/single_automatic_dialog.cpp index f478bf2..fb1667c 100644 --- a/comdel/display/single_automatic_dialog.cpp +++ b/comdel/display/single_automatic_dialog.cpp @@ -29,9 +29,18 @@ namespace display { setupValues(firstLayout, values[0], &SingleAutomaticDialog::onFirstEnumerationChanged); setupValues(secondLayout, values[1], &SingleAutomaticDialog::onSecondEnumerationChanged); - auto button = new QPushButton(updating ? "Ažuriraj" : "Postavi"); - connect(button, &QPushButton::clicked, this, &SingleAutomaticDialog::onUpdate); - parentLayout->addWidget(button); + auto buttonLayout = new QHBoxLayout(this); + + auto okButton = new QPushButton("U redu", this); + auto cancelButton = new QPushButton("Odustani", this); + + connect(okButton, &QPushButton::clicked, [this]() { accept(); }); + connect(cancelButton, &QPushButton::clicked, [this]() { reject(); }); + + buttonLayout->addWidget(okButton); + buttonLayout->addWidget(cancelButton); + + parentLayout->addLayout(buttonLayout); } void SingleAutomaticDialog::setupValues(QVBoxLayout *layout, domain::InstanceAttribute &attribute, void (display::SingleAutomaticDialog::* handler)(int)) { diff --git a/comdel/domain/comdel_validator.cpp b/comdel/domain/comdel_validator.cpp index c64188c..fb8b567 100644 --- a/comdel/domain/comdel_validator.cpp +++ b/comdel/domain/comdel_validator.cpp @@ -37,12 +37,12 @@ namespace domain { if (count < comp.getCount().first) { auto message = populateMessage( - "Not enough instances of component '{componentName}' required at least {min}, found {count}", + "Nedovoljno instanci komponente '{componentName}' potrebno barem {min}, pronađeno {count}", context); errors.emplace_back(Action::ERROR, message); } else if (count > comp.getCount().second) { auto message = populateMessage( - "To many instances of component '{componentName}' allow at most {max}, found {count}", context); + "Previše insanci komponente '{componentName}' dozvoljeno najviše {max}, pronađeno {count}", context); errors.emplace_back(Action::ERROR, message); } } @@ -64,11 +64,11 @@ namespace domain { if (count < bus.getCount().first) { auto message = populateMessage( - "Not enough instances of bus '{busName}' required at least {min}, found {count}", context); + "Nedovoljno instanci sabirnice '{busName}' potrebna barem jedna {min}, pronađeno {count}", context); errors.emplace_back(Action::ERROR, message); } else if (count > bus.getCount().second) { auto message = populateMessage( - "To many instances of bus '{busName}' allow at most {max}, found {count}", context); + "Previše instanci sabirnice '{busName}' dozvoljeno najviše {max}, pronašeno {count}", context); errors.emplace_back(Action::ERROR, message); } } @@ -193,7 +193,7 @@ namespace domain { if(names.find(component->name) != names.end()) { context.attributes["componentName"] = Value::fromString(component->name); auto message = populateMessage( - "There are multiple component instances named '{componentName}'", context); + "Pronađeno više instanci sa imenom '{componentName}'", context); errors.emplace_back(Action::ERROR, message); } names.insert(component->name); @@ -234,11 +234,11 @@ namespace domain { auto directConnection = dynamic_cast(conn.get()); if (directConnection != nullptr) { if (directConnection->instance->name == component->name && - busConnection->connection.getComponent().pin == pin.getName()) { + directConnection->connection.getComponent().pin == pin.getName()) { return true; } if (directConnection->secondInstance->name == component->name && - busConnection->connection.getSecondComponent()->pin == pin.getName()) { + directConnection->connection.getSecondComponent()->pin == pin.getName()) { return true; } }