WIP
This commit is contained in:
parent
562b77ea0a
commit
9e2b0f6c3c
|
@ -2,6 +2,7 @@
|
|||
|
||||
#include <QMenu>
|
||||
#include <QGraphicsSceneContextMenuEvent>
|
||||
#include <QGraphicsScene>
|
||||
#include <iostream>
|
||||
|
||||
#include "dialogmanager.h"
|
||||
|
@ -34,10 +35,27 @@ ComponentWrapper *ComponentWrapper::ofBus(domain::BusInstance *instance) {
|
|||
component->redraw();
|
||||
return component;
|
||||
}
|
||||
void ComponentWrapper::redraw() {
|
||||
void ComponentWrapper::clear() {
|
||||
for(auto item: childItems()) {
|
||||
this->removeFromGroup(item);
|
||||
item->scene()->removeItem(item);
|
||||
delete item;
|
||||
}
|
||||
if(componentInstance) {
|
||||
componentItem->clear();
|
||||
for(auto pinItem: pinItems) {
|
||||
pinItem->clear();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void ComponentWrapper::redraw() {
|
||||
|
||||
if(componentInstance) {
|
||||
addToGroup(componentItem);
|
||||
componentItem->redraw();
|
||||
for(auto pinItem: pinItems) {
|
||||
addToGroup(pinItem);
|
||||
pinItem->redraw();
|
||||
}
|
||||
this->addToGroup(new QGraphicsSimpleTextItem(QString::fromStdString(componentInstance->name)));
|
||||
|
@ -60,17 +78,33 @@ ComponentItem::ComponentItem(domain::ComponentInstance *instance, QGraphicsItem
|
|||
void ComponentItem::redraw() {
|
||||
componentInstance->component.getDisplay().render(this);
|
||||
}
|
||||
void ComponentItem::clear() {
|
||||
for(auto item: childItems()) {
|
||||
this->removeFromGroup(item);
|
||||
item->scene()->removeItem(item);
|
||||
delete item;
|
||||
}
|
||||
}
|
||||
|
||||
void ComponentItem::contextMenuEvent(QGraphicsSceneContextMenuEvent *event) {
|
||||
QMenu menu;
|
||||
auto componentInstance = this->componentInstance;
|
||||
menu.addAction("Izmjeni ime", [componentInstance](){DialogManager::updateName(componentInstance);});
|
||||
auto instance = this->componentInstance;
|
||||
menu.addAction("Izmjeni ime", [instance, this](){
|
||||
DialogManager::updateName(instance);
|
||||
auto *wrapper = static_cast<ComponentWrapper*>(this->parentItem());
|
||||
wrapper->clear();
|
||||
wrapper->redraw();
|
||||
});
|
||||
menu.addSeparator();
|
||||
for(auto attr: componentInstance->attributes) {
|
||||
bool enabled = attr->attribute.getPopup().has_value();
|
||||
|
||||
auto action = menu.addAction(QString::fromStdString("Izmjeni " + attr->name),
|
||||
[attr](){DialogManager::updateAttribute(attr);});
|
||||
[attr, this]() {
|
||||
DialogManager::updateAttribute(attr);
|
||||
|
||||
this->redraw();
|
||||
});
|
||||
action->setEnabled(enabled);
|
||||
}
|
||||
menu.exec(event->screenPos());
|
||||
|
@ -84,4 +118,12 @@ PinItem::PinItem(domain::Pin pin, QGraphicsItem *parent): pin(pin) {
|
|||
void PinItem::redraw() {
|
||||
pin.getDisplay().render(this);
|
||||
}
|
||||
void PinItem::clear() {
|
||||
for(auto item: childItems()) {
|
||||
this->removeFromGroup(item);
|
||||
item->scene()->removeItem(item);
|
||||
delete item;
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace display
|
||||
|
|
|
@ -13,6 +13,7 @@ class ComponentItem: public QGraphicsItemGroup
|
|||
public:
|
||||
ComponentItem(domain::ComponentInstance *instance, QGraphicsItem *parent);
|
||||
void redraw();
|
||||
void clear();
|
||||
private:
|
||||
domain::ComponentInstance *componentInstance;
|
||||
|
||||
|
@ -25,6 +26,7 @@ class PinItem: public QGraphicsItemGroup
|
|||
public:
|
||||
PinItem(domain::Pin pin, QGraphicsItem *parent);
|
||||
void redraw();
|
||||
void clear();
|
||||
private:
|
||||
domain::Pin pin;
|
||||
};
|
||||
|
@ -40,6 +42,23 @@ public:
|
|||
this->setHandlesChildEvents(false);
|
||||
}
|
||||
void redraw();
|
||||
void clear();
|
||||
|
||||
|
||||
QVariant itemChange( GraphicsItemChange change, const QVariant &value ) override
|
||||
{
|
||||
auto response = QGraphicsItem::itemChange(change, value);
|
||||
if (change == ItemPositionChange){
|
||||
if(componentInstance != nullptr) {
|
||||
componentInstance->position.first = (int)scenePos().x();
|
||||
componentInstance->position.second = (int)scenePos().y();
|
||||
} else if(busInstance != nullptr) {
|
||||
busInstance->position.first = (int)scenePos().x();
|
||||
busInstance->position.second = (int)scenePos().y();
|
||||
}
|
||||
}
|
||||
return response;
|
||||
}
|
||||
|
||||
private:
|
||||
domain::ComponentInstance *componentInstance = nullptr;
|
||||
|
|
|
@ -1,23 +1,45 @@
|
|||
//
|
||||
// Created by bbr on 18. 04. 2022..
|
||||
//
|
||||
|
||||
#ifndef NAME_DIALOG_H
|
||||
#define NAME_DIALOG_H
|
||||
|
||||
#include <QDialog>
|
||||
#include <QLabel>
|
||||
#include <QVBoxLayout>
|
||||
#include <QLineEdit>
|
||||
#include <QPushButton>
|
||||
|
||||
#include <comdel/domain/instance.h>
|
||||
|
||||
namespace display {
|
||||
|
||||
class NameDialog: public QDialog {
|
||||
public:
|
||||
NameDialog(domain::ComponentInstance *instance) {
|
||||
|
||||
QLineEdit *edit;
|
||||
domain::ComponentInstance *instance;
|
||||
|
||||
public:
|
||||
|
||||
NameDialog(domain::ComponentInstance *instance): instance(instance) {
|
||||
auto *layout = new QVBoxLayout(this);
|
||||
layout->addWidget(new QLabel("Izmjeni ime", this));
|
||||
|
||||
edit = new QLineEdit(this);
|
||||
edit->insert(instance->name.c_str());
|
||||
layout->addWidget(edit);
|
||||
this->setWindowTitle("Izmjeni ime");
|
||||
auto *button = new QPushButton("Ažuriraj", this);
|
||||
connect(button, &QPushButton::clicked, this, &NameDialog::onNameChange);
|
||||
layout->addWidget(button);
|
||||
this->setLayout(layout);
|
||||
}
|
||||
|
||||
public slots:
|
||||
void onNameChange() {
|
||||
instance->name = this->edit->text().toStdString();
|
||||
this->close();
|
||||
}
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
|
||||
#endif //sNAME_DIALOG_H
|
||||
#endif //NAME_DIALOG_H
|
||||
|
|
Loading…
Reference in New Issue