2022-04-07 22:21:23 +00:00
|
|
|
#include "component_display.h"
|
2022-05-15 14:13:29 +00:00
|
|
|
#include "attribute_dialog.h"
|
|
|
|
#include "name_dialog.h"
|
2022-05-15 21:55:03 +00:00
|
|
|
#include "mainwindow.h"
|
2022-04-07 22:21:23 +00:00
|
|
|
|
2022-04-10 15:24:15 +00:00
|
|
|
#include <QMenu>
|
|
|
|
#include <QGraphicsSceneContextMenuEvent>
|
|
|
|
#include <iostream>
|
|
|
|
|
2022-04-07 22:21:23 +00:00
|
|
|
namespace display {
|
|
|
|
|
2022-05-08 22:51:47 +00:00
|
|
|
void Component::contextMenuEvent(QGraphicsSceneContextMenuEvent *event) {
|
|
|
|
QMenu menu;
|
2022-05-15 15:00:20 +00:00
|
|
|
menu.addAction("Izmjeni ime", [this](){
|
|
|
|
auto dialog = new NameDialog(this->instance.get());
|
|
|
|
dialog->exec();
|
|
|
|
});
|
2022-05-08 22:51:47 +00:00
|
|
|
menu.addSeparator();
|
2022-05-15 14:13:29 +00:00
|
|
|
for(int i=0; i<this->instance->attributes.size(); i++) {
|
|
|
|
auto* attr = &this->instance->attributes[i];
|
|
|
|
bool enabled = attr->attribute.getPopup().has_value();
|
|
|
|
|
|
|
|
auto action = menu.addAction(QString::fromStdString("Izmjeni " + attr->name),
|
|
|
|
[attr]() {
|
2022-05-15 21:55:03 +00:00
|
|
|
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();
|
|
|
|
}
|
2022-05-15 14:13:29 +00:00
|
|
|
});
|
2022-05-08 22:51:47 +00:00
|
|
|
action->setEnabled(enabled);
|
|
|
|
}
|
|
|
|
menu.exec(event->screenPos());
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void Bus::contextMenuEvent(QGraphicsSceneContextMenuEvent *event) {
|
|
|
|
QMenu menu;
|
2022-05-15 15:00:20 +00:00
|
|
|
menu.addAction("Izmjeni ime", [this](){
|
|
|
|
auto dialog = new NameDialog(this->busInstance.get());
|
|
|
|
dialog->exec();
|
2022-04-20 19:50:39 +00:00
|
|
|
});
|
2022-04-10 15:24:15 +00:00
|
|
|
menu.exec(event->screenPos());
|
|
|
|
}
|
|
|
|
|
2022-05-17 19:31:32 +00:00
|
|
|
QVariant BusGroup::itemChange(QGraphicsItem::GraphicsItemChange change, const QVariant &value) {
|
|
|
|
if (change == ItemPositionChange && scene()) {
|
|
|
|
// value is the new position.
|
|
|
|
QPointF newPos = value.toPointF();
|
|
|
|
busInstance->position.first = newPos.x();
|
|
|
|
busInstance->position.second = newPos.y();
|
2022-05-17 22:14:33 +00:00
|
|
|
|
|
|
|
auto view = dynamic_cast<Schema*>(scene()->views()[0]);
|
|
|
|
view->updateConnections();
|
2022-05-17 19:31:32 +00:00
|
|
|
}
|
|
|
|
return QGraphicsItem::itemChange(change, value);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
QVariant ComponentGroup::itemChange(QGraphicsItem::GraphicsItemChange change, const QVariant &value) {
|
|
|
|
if (change == ItemPositionChange && scene()) {
|
|
|
|
// value is the new position.
|
|
|
|
QPointF newPos = value.toPointF();
|
|
|
|
componentInstance->position.first = newPos.x();
|
|
|
|
componentInstance->position.second = newPos.y();
|
2022-05-17 22:14:33 +00:00
|
|
|
|
|
|
|
auto view = dynamic_cast<Schema*>(scene()->views()[0]);
|
|
|
|
view->updateConnections();
|
2022-05-17 19:31:32 +00:00
|
|
|
}
|
|
|
|
return QGraphicsItem::itemChange(change, value);
|
|
|
|
}
|
2022-05-17 22:14:33 +00:00
|
|
|
|
|
|
|
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]() {
|
|
|
|
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();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
action->setEnabled(enabled);
|
|
|
|
}
|
|
|
|
menu.exec(event->screenPos());
|
|
|
|
}
|
2022-04-07 22:21:23 +00:00
|
|
|
} // namespace display
|