98 lines
3.7 KiB
C++
98 lines
3.7 KiB
C++
#include "component_display.h"
|
|
#include "attribute_dialog.h"
|
|
#include "name_dialog.h"
|
|
#include "mainwindow.h"
|
|
|
|
#include <QMenu>
|
|
#include <QGraphicsSceneContextMenuEvent>
|
|
#include <iostream>
|
|
|
|
namespace display {
|
|
|
|
void Component::contextMenuEvent(QGraphicsSceneContextMenuEvent *event) {
|
|
QMenu menu;
|
|
menu.addAction("Izmjeni ime", [this](){
|
|
auto dialog = new NameDialog(this->instance.get());
|
|
dialog->exec();
|
|
});
|
|
menu.addSeparator();
|
|
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]() {
|
|
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());
|
|
}
|
|
|
|
|
|
void Bus::contextMenuEvent(QGraphicsSceneContextMenuEvent *event) {
|
|
QMenu menu;
|
|
menu.addAction("Izmjeni ime", [this](){
|
|
auto dialog = new NameDialog(this->busInstance.get());
|
|
dialog->exec();
|
|
});
|
|
menu.exec(event->screenPos());
|
|
}
|
|
|
|
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();
|
|
|
|
auto view = dynamic_cast<Schema*>(scene()->views()[0]);
|
|
view->updateConnections();
|
|
}
|
|
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();
|
|
|
|
auto view = dynamic_cast<Schema*>(scene()->views()[0]);
|
|
view->updateConnections();
|
|
}
|
|
return QGraphicsItem::itemChange(change, value);
|
|
}
|
|
|
|
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());
|
|
}
|
|
} // namespace display
|