From 1100a9f0b9c5f0c6056cfa4fb4d2b4584be7021d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Borna=20Rajkovi=C4=87?= Date: Thu, 19 May 2022 21:08:00 +0200 Subject: [PATCH] Added connection display --- comdel/display/component_display.cpp | 27 ++++++++++++++++++++------- comdel/display/component_display.h | 26 ++++++++++++++++++++++++++ mainwindow.cpp | 2 ++ 3 files changed, 48 insertions(+), 7 deletions(-) diff --git a/comdel/display/component_display.cpp b/comdel/display/component_display.cpp index 14e856a..f4b33c1 100644 --- a/comdel/display/component_display.cpp +++ b/comdel/display/component_display.cpp @@ -82,13 +82,26 @@ void Bus::contextMenuEvent(QGraphicsSceneContextMenuEvent *event) { auto action = menu.addAction(QString::fromStdString("Izmjeni " + attr->name), [attr]() { - if(attr->value.getType() == domain::Value::MEMORY_REFERENCE) { - auto dialog = new MemoryDialog(attr, MainWindow::getSchema()->componentInstances); - dialog->exec(); - } else { - auto dialog = new AttributeDialog(attr); - dialog->exec(); - } + auto dialog = new AttributeDialog(attr); + dialog->exec(); + }); + action->setEnabled(enabled); + } + menu.exec(event->screenPos()); + } + + void DirectConnection::contextMenuEvent(QGraphicsSceneContextMenuEvent *event) { + QMenu menu; + menu.addAction("Ukloni poveznicu", [this](){}); + menu.addSeparator(); + for(int i=0; iconnection->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); } diff --git a/comdel/display/component_display.h b/comdel/display/component_display.h index 548eec5..09b9208 100644 --- a/comdel/display/component_display.h +++ b/comdel/display/component_display.h @@ -116,6 +116,32 @@ public: }; + class DirectConnection: public QGraphicsLineItem + { + private: + domain::DirectConnectionInstance* connection; + ComponentGroup* first; + ComponentGroup* second; + BusGroup* bus; + + public: + DirectConnection(domain::DirectConnectionInstance* connection, ComponentGroup *first, ComponentGroup *second, BusGroup *bus): connection(connection), first(first), second(second), bus(bus) { + updateConnection(); + setHandlesChildEvents(false); + } + + void updateConnection() { + auto pin1 = connection->instance->component.getPin(connection->connection.getComponent().pin).getDisplayPin(); + auto pin2 = connection->secondInstance->component.getPin(connection->connection.getSecondComponent()->pin).getDisplayPin(); + + setLine(connection->instance->position.first + pin1.getConnectionX(), connection->instance->position.second + pin1.getConnectionY(), + connection->secondInstance->position.first + pin2.getConnectionX(), connection->secondInstance->position.second + pin2.getConnectionY()); + } + + void contextMenuEvent(QGraphicsSceneContextMenuEvent *event) override; + }; + + } // namespace display #endif // DISPLAY_COMPONENT_H diff --git a/mainwindow.cpp b/mainwindow.cpp index 127de2d..e3a7b80 100644 --- a/mainwindow.cpp +++ b/mainwindow.cpp @@ -193,6 +193,8 @@ void MainWindow::onValidateSchema(bool /*toggled*/) { return; } + log->clear(); + this->validationErrors.clear(); domain::ComdelValidator validator{validators};