Updated name dialog

This commit is contained in:
Borna Rajković 2022-05-15 17:00:20 +02:00
parent 23764776f1
commit 65020c2b7f
7 changed files with 43 additions and 236 deletions

View File

@ -38,5 +38,5 @@ add_executable(SchemeEditor
comdel/parser/comdellexer.cpp comdel/parser/comdellexer.cpp
main.cpp main.cpp
mainwindow.ui 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) target_link_libraries(SchemeEditor Qt5::Core Qt5::Gui Qt5::Widgets)

View File

@ -11,7 +11,10 @@ namespace display {
void Component::contextMenuEvent(QGraphicsSceneContextMenuEvent *event) { void Component::contextMenuEvent(QGraphicsSceneContextMenuEvent *event) {
QMenu menu; QMenu menu;
menu.addAction("Izmjeni ime", [this](){}); menu.addAction("Izmjeni ime", [this](){
auto dialog = new NameDialog(this->instance.get());
dialog->exec();
});
menu.addSeparator(); menu.addSeparator();
for(int i=0; i<this->instance->attributes.size(); i++) { for(int i=0; i<this->instance->attributes.size(); i++) {
auto* attr = &this->instance->attributes[i]; auto* attr = &this->instance->attributes[i];
@ -30,126 +33,11 @@ void Component::contextMenuEvent(QGraphicsSceneContextMenuEvent *event) {
void Bus::contextMenuEvent(QGraphicsSceneContextMenuEvent *event) { void Bus::contextMenuEvent(QGraphicsSceneContextMenuEvent *event) {
QMenu menu; QMenu menu;
menu.addAction("Izmjeni ime", [this](){}); menu.addAction("Izmjeni ime", [this](){
auto dialog = new NameDialog(this->busInstance.get());
dialog->exec();
});
menu.exec(event->screenPos()); 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.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 } // namespace display

View File

@ -8,69 +8,6 @@
namespace display { 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 class Pin: public QGraphicsItemGroup
{ {
private: private:
@ -94,8 +31,9 @@ public:
class Bus: public QGraphicsItemGroup class Bus: public QGraphicsItemGroup
{ {
std::shared_ptr<domain::BusInstance> busInstance;
public: public:
Bus(const std::shared_ptr<domain::BusInstance>& instance) { Bus(const std::shared_ptr<domain::BusInstance>& instance): busInstance(instance) {
instance->bus.getDisplay()->render(this); instance->bus.getDisplay()->render(this);
} }
void contextMenuEvent(QGraphicsSceneContextMenuEvent *event) override; void contextMenuEvent(QGraphicsSceneContextMenuEvent *event) override;

View File

@ -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();
}
}

View File

@ -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

View File

@ -13,12 +13,27 @@ namespace display {
class NameDialog: public QDialog { class NameDialog: public QDialog {
QLineEdit *edit; QLineEdit *edit = nullptr;
domain::ComponentInstance *instance; domain::ComponentInstance *componentInstance = nullptr;
domain::BusInstance *busInstance = nullptr;
public: 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); auto *layout = new QVBoxLayout(this);
layout->addWidget(new QLabel("Izmjeni ime", this)); layout->addWidget(new QLabel("Izmjeni ime", this));
@ -34,7 +49,11 @@ public:
public slots: public slots:
void onNameChange() { 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(); this->close();
} }
}; };

View File

@ -1,19 +1,20 @@
@source "frisc_library.csl" @source "frisc_library.csl"
@schema { @schema {
@instance proc FRISC { @instance procesor2 FRISC {
@position (0, 0) @position (0, 0)
} }
@instance mem Memorija { @instance memorija2 Memorija {
@position (0, 250) @position (0, 250)
@attribute brzina 25 @attribute sinkroniziran false
@attribute kapacitet 2048 @attribute brzina 1
@attribute kapacitet 1024
@attribute size 8 @attribute size 8
@attribute pocetnaAdresa 0 @attribute pocetnaAdresa 1023
} }
@instance bus glavnaSabirnica { @instance bus2 glavnaSabirnica {
@position (0, 200) @position (0, 200)
@size 100 @size 100
} }
@ -23,11 +24,11 @@
@size 0 @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 dmaPoveznica "READY"
@attribute mmaPoveznica "PIO_DATA" @attribute mmaPoveznica "PIO_DATA"
} }