WIP
This commit is contained in:
parent
562b77ea0a
commit
9e2b0f6c3c
|
@ -2,6 +2,7 @@
|
||||||
|
|
||||||
#include <QMenu>
|
#include <QMenu>
|
||||||
#include <QGraphicsSceneContextMenuEvent>
|
#include <QGraphicsSceneContextMenuEvent>
|
||||||
|
#include <QGraphicsScene>
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
|
|
||||||
#include "dialogmanager.h"
|
#include "dialogmanager.h"
|
||||||
|
@ -34,10 +35,27 @@ ComponentWrapper *ComponentWrapper::ofBus(domain::BusInstance *instance) {
|
||||||
component->redraw();
|
component->redraw();
|
||||||
return component;
|
return component;
|
||||||
}
|
}
|
||||||
void ComponentWrapper::redraw() {
|
void ComponentWrapper::clear() {
|
||||||
|
for(auto item: childItems()) {
|
||||||
|
this->removeFromGroup(item);
|
||||||
|
item->scene()->removeItem(item);
|
||||||
|
delete item;
|
||||||
|
}
|
||||||
if(componentInstance) {
|
if(componentInstance) {
|
||||||
|
componentItem->clear();
|
||||||
|
for(auto pinItem: pinItems) {
|
||||||
|
pinItem->clear();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void ComponentWrapper::redraw() {
|
||||||
|
|
||||||
|
if(componentInstance) {
|
||||||
|
addToGroup(componentItem);
|
||||||
componentItem->redraw();
|
componentItem->redraw();
|
||||||
for(auto pinItem: pinItems) {
|
for(auto pinItem: pinItems) {
|
||||||
|
addToGroup(pinItem);
|
||||||
pinItem->redraw();
|
pinItem->redraw();
|
||||||
}
|
}
|
||||||
this->addToGroup(new QGraphicsSimpleTextItem(QString::fromStdString(componentInstance->name)));
|
this->addToGroup(new QGraphicsSimpleTextItem(QString::fromStdString(componentInstance->name)));
|
||||||
|
@ -60,17 +78,33 @@ ComponentItem::ComponentItem(domain::ComponentInstance *instance, QGraphicsItem
|
||||||
void ComponentItem::redraw() {
|
void ComponentItem::redraw() {
|
||||||
componentInstance->component.getDisplay().render(this);
|
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) {
|
void ComponentItem::contextMenuEvent(QGraphicsSceneContextMenuEvent *event) {
|
||||||
QMenu menu;
|
QMenu menu;
|
||||||
auto componentInstance = this->componentInstance;
|
auto instance = this->componentInstance;
|
||||||
menu.addAction("Izmjeni ime", [componentInstance](){DialogManager::updateName(componentInstance);});
|
menu.addAction("Izmjeni ime", [instance, this](){
|
||||||
|
DialogManager::updateName(instance);
|
||||||
|
auto *wrapper = static_cast<ComponentWrapper*>(this->parentItem());
|
||||||
|
wrapper->clear();
|
||||||
|
wrapper->redraw();
|
||||||
|
});
|
||||||
menu.addSeparator();
|
menu.addSeparator();
|
||||||
for(auto attr: componentInstance->attributes) {
|
for(auto attr: componentInstance->attributes) {
|
||||||
bool enabled = attr->attribute.getPopup().has_value();
|
bool enabled = attr->attribute.getPopup().has_value();
|
||||||
|
|
||||||
auto action = menu.addAction(QString::fromStdString("Izmjeni " + attr->name),
|
auto action = menu.addAction(QString::fromStdString("Izmjeni " + attr->name),
|
||||||
[attr](){DialogManager::updateAttribute(attr);});
|
[attr, this]() {
|
||||||
|
DialogManager::updateAttribute(attr);
|
||||||
|
|
||||||
|
this->redraw();
|
||||||
|
});
|
||||||
action->setEnabled(enabled);
|
action->setEnabled(enabled);
|
||||||
}
|
}
|
||||||
menu.exec(event->screenPos());
|
menu.exec(event->screenPos());
|
||||||
|
@ -84,4 +118,12 @@ PinItem::PinItem(domain::Pin pin, QGraphicsItem *parent): pin(pin) {
|
||||||
void PinItem::redraw() {
|
void PinItem::redraw() {
|
||||||
pin.getDisplay().render(this);
|
pin.getDisplay().render(this);
|
||||||
}
|
}
|
||||||
|
void PinItem::clear() {
|
||||||
|
for(auto item: childItems()) {
|
||||||
|
this->removeFromGroup(item);
|
||||||
|
item->scene()->removeItem(item);
|
||||||
|
delete item;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
} // namespace display
|
} // namespace display
|
||||||
|
|
|
@ -13,6 +13,7 @@ class ComponentItem: public QGraphicsItemGroup
|
||||||
public:
|
public:
|
||||||
ComponentItem(domain::ComponentInstance *instance, QGraphicsItem *parent);
|
ComponentItem(domain::ComponentInstance *instance, QGraphicsItem *parent);
|
||||||
void redraw();
|
void redraw();
|
||||||
|
void clear();
|
||||||
private:
|
private:
|
||||||
domain::ComponentInstance *componentInstance;
|
domain::ComponentInstance *componentInstance;
|
||||||
|
|
||||||
|
@ -25,6 +26,7 @@ class PinItem: public QGraphicsItemGroup
|
||||||
public:
|
public:
|
||||||
PinItem(domain::Pin pin, QGraphicsItem *parent);
|
PinItem(domain::Pin pin, QGraphicsItem *parent);
|
||||||
void redraw();
|
void redraw();
|
||||||
|
void clear();
|
||||||
private:
|
private:
|
||||||
domain::Pin pin;
|
domain::Pin pin;
|
||||||
};
|
};
|
||||||
|
@ -40,6 +42,23 @@ public:
|
||||||
this->setHandlesChildEvents(false);
|
this->setHandlesChildEvents(false);
|
||||||
}
|
}
|
||||||
void redraw();
|
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:
|
private:
|
||||||
domain::ComponentInstance *componentInstance = nullptr;
|
domain::ComponentInstance *componentInstance = nullptr;
|
||||||
|
|
|
@ -1,23 +1,45 @@
|
||||||
//
|
|
||||||
// Created by bbr on 18. 04. 2022..
|
|
||||||
//
|
|
||||||
|
|
||||||
#ifndef NAME_DIALOG_H
|
#ifndef NAME_DIALOG_H
|
||||||
#define NAME_DIALOG_H
|
#define NAME_DIALOG_H
|
||||||
|
|
||||||
#include <QDialog>
|
#include <QDialog>
|
||||||
|
#include <QLabel>
|
||||||
|
#include <QVBoxLayout>
|
||||||
|
#include <QLineEdit>
|
||||||
|
#include <QPushButton>
|
||||||
|
|
||||||
#include <comdel/domain/instance.h>
|
#include <comdel/domain/instance.h>
|
||||||
|
|
||||||
namespace display {
|
namespace display {
|
||||||
|
|
||||||
class NameDialog: public QDialog {
|
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