Updated name dialog
This commit is contained in:
parent
23764776f1
commit
65020c2b7f
|
@ -38,5 +38,5 @@ add_executable(SchemeEditor
|
|||
comdel/parser/comdellexer.cpp
|
||||
main.cpp
|
||||
mainwindow.ui
|
||||
comdel/domain/comdelvalidator.cpp comdel/domain/comdelvalidator.h comdel/display/dialogmanager.cpp comdel/display/dialogmanager.h comdel/display/attribute_dialog.cpp comdel/display/attribute_dialog.h comdel/display/name_dialog.cpp comdel/display/name_dialog.h comdel/domain/comdel_generator.cpp comdel/domain/comdel_generator.h)
|
||||
comdel/domain/comdelvalidator.cpp comdel/domain/comdelvalidator.h comdel/display/attribute_dialog.cpp comdel/display/attribute_dialog.h comdel/display/name_dialog.cpp comdel/display/name_dialog.h comdel/domain/comdel_generator.cpp comdel/domain/comdel_generator.h)
|
||||
target_link_libraries(SchemeEditor Qt5::Core Qt5::Gui Qt5::Widgets)
|
||||
|
|
|
@ -11,7 +11,10 @@ namespace display {
|
|||
|
||||
void Component::contextMenuEvent(QGraphicsSceneContextMenuEvent *event) {
|
||||
QMenu menu;
|
||||
menu.addAction("Izmjeni ime", [this](){});
|
||||
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];
|
||||
|
@ -30,126 +33,11 @@ void Component::contextMenuEvent(QGraphicsSceneContextMenuEvent *event) {
|
|||
|
||||
void Bus::contextMenuEvent(QGraphicsSceneContextMenuEvent *event) {
|
||||
QMenu menu;
|
||||
menu.addAction("Izmjeni ime", [this](){});
|
||||
menu.exec(event->screenPos());
|
||||
}
|
||||
|
||||
/*
|
||||
ComponentWrapper *ComponentWrapper::ofWire(domain::WireInstance *wire) {
|
||||
auto component = new ComponentWrapper();
|
||||
component->wireInstance = wire;
|
||||
component->redraw();
|
||||
return component;
|
||||
}
|
||||
ComponentWrapper *ComponentWrapper::ofComponent(domain::ComponentInstance *instance) {
|
||||
auto component = new ComponentWrapper();
|
||||
component->componentInstance = instance;
|
||||
component->setFlag(QGraphicsItem::ItemIsMovable, true);
|
||||
component->componentItem = new ComponentItem(instance, component);
|
||||
|
||||
for(auto& pin: instance->component.getPins()) {
|
||||
component->pinItems.push_back(new PinItem(pin, component));
|
||||
}
|
||||
|
||||
component->redraw();
|
||||
return component;
|
||||
}
|
||||
ComponentWrapper *ComponentWrapper::ofBus(domain::BusInstance *instance) {
|
||||
auto component = new ComponentWrapper();
|
||||
component->busInstance = instance;
|
||||
component->setFlag(QGraphicsItem::ItemIsMovable, true);
|
||||
component->redraw();
|
||||
return component;
|
||||
}
|
||||
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)));
|
||||
}
|
||||
if(busInstance && busInstance->bus.getDisplay()) {
|
||||
busInstance->bus.getDisplay()->render(this);
|
||||
this->addToGroup(new QGraphicsSimpleTextItem(QString::fromStdString(busInstance->name)));
|
||||
}
|
||||
if(wireInstance) {
|
||||
wireInstance->display.render(this);
|
||||
this->addToGroup(new QGraphicsSimpleTextItem(QString::fromStdString(wireInstance->name)));
|
||||
}
|
||||
}
|
||||
|
||||
ComponentItem::ComponentItem(domain::ComponentInstance *instance, QGraphicsItem *parent): componentInstance(instance) {
|
||||
setParentItem(parent);
|
||||
redraw();
|
||||
setToolTip(QString::fromStdString(this->componentInstance->component.getTooltip()));
|
||||
}
|
||||
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 instance = this->componentInstance;
|
||||
menu.addAction("Izmjeni ime", [instance, this](){
|
||||
DialogManager::updateName(instance);
|
||||
auto *wrapper = static_cast<ComponentWrapper*>(this->parentItem());
|
||||
wrapper->clear();
|
||||
wrapper->redraw();
|
||||
menu.addAction("Izmjeni ime", [this](){
|
||||
auto dialog = new NameDialog(this->busInstance.get());
|
||||
dialog->exec();
|
||||
});
|
||||
menu.addSeparator();
|
||||
for(auto attr: componentInstance->attributes) {
|
||||
bool enabled = attr.attribute.getPopup().has_value();
|
||||
|
||||
auto action = menu.addAction(QString::fromStdString("Izmjeni " + attr.name),
|
||||
[&attr, this]() {
|
||||
DialogManager::updateAttribute(&attr);
|
||||
|
||||
this->redraw();
|
||||
});
|
||||
action->setEnabled(enabled);
|
||||
}
|
||||
menu.exec(event->screenPos());
|
||||
}
|
||||
|
||||
PinItem::PinItem(domain::Pin pin, QGraphicsItem *parent): pin(pin) {
|
||||
setParentItem(parent);
|
||||
redraw();
|
||||
setToolTip(QString::fromStdString(pin.getTooltip()));
|
||||
}
|
||||
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
|
||||
|
|
|
@ -8,69 +8,6 @@
|
|||
|
||||
namespace display {
|
||||
|
||||
/*
|
||||
class ComponentItem: public QGraphicsItemGroup
|
||||
{
|
||||
public:
|
||||
ComponentItem(domain::ComponentInstance *instance, QGraphicsItem *parent);
|
||||
void redraw();
|
||||
void clear();
|
||||
private:
|
||||
domain::ComponentInstance *componentInstance;
|
||||
|
||||
public:
|
||||
void contextMenuEvent(QGraphicsSceneContextMenuEvent *event) override;
|
||||
};
|
||||
|
||||
class PinItem: public QGraphicsItemGroup
|
||||
{
|
||||
public:
|
||||
PinItem(domain::Pin pin, QGraphicsItem *parent);
|
||||
void redraw();
|
||||
void clear();
|
||||
private:
|
||||
domain::Pin pin;
|
||||
};
|
||||
|
||||
class ComponentWrapper: public QGraphicsItemGroup
|
||||
{
|
||||
public:
|
||||
static ComponentWrapper *ofComponent(domain::ComponentInstance *instance);
|
||||
static ComponentWrapper *ofBus(domain::BusInstance *instance);
|
||||
static ComponentWrapper *ofWire(domain::WireInstance *wire);
|
||||
|
||||
ComponentWrapper() {
|
||||
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;
|
||||
domain::BusInstance *busInstance = nullptr;
|
||||
domain::WireInstance *wireInstance = nullptr;
|
||||
|
||||
ComponentItem *componentItem;
|
||||
std::vector<PinItem*> pinItems;
|
||||
};
|
||||
*/
|
||||
|
||||
class Pin: public QGraphicsItemGroup
|
||||
{
|
||||
private:
|
||||
|
@ -94,8 +31,9 @@ public:
|
|||
|
||||
class Bus: public QGraphicsItemGroup
|
||||
{
|
||||
std::shared_ptr<domain::BusInstance> busInstance;
|
||||
public:
|
||||
Bus(const std::shared_ptr<domain::BusInstance>& instance) {
|
||||
Bus(const std::shared_ptr<domain::BusInstance>& instance): busInstance(instance) {
|
||||
instance->bus.getDisplay()->render(this);
|
||||
}
|
||||
void contextMenuEvent(QGraphicsSceneContextMenuEvent *event) override;
|
||||
|
|
|
@ -1,21 +0,0 @@
|
|||
//
|
||||
// Created by bbr on 18. 04. 2022..
|
||||
//
|
||||
|
||||
#include "dialogmanager.h"
|
||||
#include "attribute_dialog.h"
|
||||
#include "name_dialog.h"
|
||||
|
||||
namespace display {
|
||||
|
||||
void DialogManager::updateAttribute(domain::InstanceAttribute *attribute) {
|
||||
auto dialog = new AttributeDialog(attribute);
|
||||
dialog->exec();
|
||||
}
|
||||
|
||||
void DialogManager::updateName(domain::ComponentInstance *instance) {
|
||||
auto dialog = new NameDialog(instance);
|
||||
dialog->exec();
|
||||
}
|
||||
|
||||
}
|
|
@ -1,18 +0,0 @@
|
|||
#ifndef DIALOG_MANAGER_H
|
||||
#define DIALOG_MANAGER_H
|
||||
|
||||
#include <comdel/domain/instanceattribute.h>
|
||||
#include <comdel/domain/instance.h>
|
||||
|
||||
namespace display {
|
||||
|
||||
class DialogManager {
|
||||
public:
|
||||
static void updateAttribute(domain::InstanceAttribute *attribute);
|
||||
|
||||
static void updateName(domain::ComponentInstance *instance);
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
#endif //DIALOG_MANAGER_H
|
|
@ -13,12 +13,27 @@ namespace display {
|
|||
|
||||
class NameDialog: public QDialog {
|
||||
|
||||
QLineEdit *edit;
|
||||
domain::ComponentInstance *instance;
|
||||
QLineEdit *edit = nullptr;
|
||||
domain::ComponentInstance *componentInstance = nullptr;
|
||||
domain::BusInstance *busInstance = nullptr;
|
||||
|
||||
public:
|
||||
|
||||
NameDialog(domain::ComponentInstance *instance): instance(instance) {
|
||||
NameDialog(domain::ComponentInstance *instance): componentInstance(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);
|
||||
}
|
||||
|
||||
NameDialog(domain::BusInstance *instance): busInstance(instance) {
|
||||
auto *layout = new QVBoxLayout(this);
|
||||
layout->addWidget(new QLabel("Izmjeni ime", this));
|
||||
|
||||
|
@ -34,7 +49,11 @@ public:
|
|||
|
||||
public slots:
|
||||
void onNameChange() {
|
||||
instance->name = this->edit->text().toStdString();
|
||||
if(componentInstance != nullptr) {
|
||||
componentInstance->name = this->edit->text().toStdString();
|
||||
} else if(busInstance != nullptr) {
|
||||
busInstance->name = this->edit->text().toStdString();
|
||||
}
|
||||
this->close();
|
||||
}
|
||||
};
|
||||
|
|
|
@ -1,19 +1,20 @@
|
|||
@source "frisc_library.csl"
|
||||
|
||||
@schema {
|
||||
@instance proc FRISC {
|
||||
@instance procesor2 FRISC {
|
||||
@position (0, 0)
|
||||
}
|
||||
|
||||
@instance mem Memorija {
|
||||
@instance memorija2 Memorija {
|
||||
@position (0, 250)
|
||||
@attribute brzina 25
|
||||
@attribute kapacitet 2048
|
||||
@attribute sinkroniziran false
|
||||
@attribute brzina 1
|
||||
@attribute kapacitet 1024
|
||||
@attribute size 8
|
||||
@attribute pocetnaAdresa 0
|
||||
@attribute pocetnaAdresa 1023
|
||||
}
|
||||
|
||||
@instance bus glavnaSabirnica {
|
||||
@instance bus2 glavnaSabirnica {
|
||||
@position (0, 200)
|
||||
@size 100
|
||||
}
|
||||
|
@ -23,11 +24,11 @@
|
|||
@size 0
|
||||
}
|
||||
|
||||
@connection (proc.glavniPin, bus) {
|
||||
@connection (procesor2.glavniPin, bus2) {
|
||||
}
|
||||
@connection (mem.glavniPin, bus) {
|
||||
@connection (memorija2.glavniPin, bus2) {
|
||||
}
|
||||
@connection (proc.glavniPin, testBus, mem.glavniPin) {
|
||||
@connection (procesor2.glavniPin, testBus, memorija2.glavniPin) {
|
||||
@attribute dmaPoveznica "READY"
|
||||
@attribute mmaPoveznica "PIO_DATA"
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue