schema_editor/comdel/display/component_display.cpp

50 lines
1.5 KiB
C++

#include "component_display.h"
#include "attribute_dialog.h"
#include "name_dialog.h"
#include "mainwindow.h"
#include <QMenu>
#include <QGraphicsSceneContextMenuEvent>
#include <QGraphicsScene>
#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());
}
} // namespace display