Updated component and bus generation logic + bugfixes
This commit is contained in:
1 parent
86b8861533
commit
f93a2afa63
14 files changed
+208
-68
No files matched your search
@@ -7,13 +7,19 @@
|
||||
#include <QMenu>
|
||||
#include <QLine>
|
||||
#include <QGraphicsSceneContextMenuEvent>
|
||||
#include <set>
|
||||
|
||||
namespace display {
|
||||
|
||||
void Component::contextMenuEvent(QGraphicsSceneContextMenuEvent *event) {
|
||||
QMenu menu;
|
||||
menu.addAction("Izmjeni ime", [this]() {
|
||||
auto dialog = new NameDialog(this->instance.get());
|
||||
std::set<std::string> names;
|
||||
for(const auto &component: Application::instance()->getSchema()->componentInstances) {
|
||||
names.insert(component->name);
|
||||
}
|
||||
|
||||
auto dialog = new NameDialog(this->instance.get(), names);
|
||||
dialog->exec();
|
||||
});
|
||||
menu.addSeparator();
|
||||
@@ -93,7 +99,12 @@ namespace display {
|
||||
void Bus::contextMenuEvent(QGraphicsSceneContextMenuEvent *event) {
|
||||
QMenu menu;
|
||||
menu.addAction("Izmjeni ime", [this]() {
|
||||
auto dialog = new NameDialog(this->busInstance.get());
|
||||
std::set<std::string> names;
|
||||
for(const auto &component: Application::instance()->getSchema()->busInstances) {
|
||||
names.insert(component->name);
|
||||
}
|
||||
|
||||
auto dialog = new NameDialog(this->busInstance.get(), names);
|
||||
dialog->exec();
|
||||
});
|
||||
menu.exec(event->screenPos());
|
||||
@@ -110,7 +121,7 @@ namespace display {
|
||||
QVariant BusGroup::itemChange(QGraphicsItem::GraphicsItemChange change, const QVariant &value) {
|
||||
if (change == ItemPositionChange && scene()) {
|
||||
// value is the new position.
|
||||
QPointF newPos = value.toPointF();
|
||||
QPoint newPos = value.toPointF().toPoint();
|
||||
busInstance->position.first = newPos.x();
|
||||
busInstance->position.second = newPos.y();
|
||||
|
||||
@@ -136,7 +147,7 @@ namespace display {
|
||||
QVariant ComponentGroup::itemChange(QGraphicsItem::GraphicsItemChange change, const QVariant &value) {
|
||||
if (change == ItemPositionChange && scene()) {
|
||||
// value is the new position.
|
||||
QPointF newPos = value.toPointF();
|
||||
QPoint newPos = value.toPointF().toPoint();
|
||||
componentInstance->position.first = newPos.x();
|
||||
componentInstance->position.second = newPos.y();
|
||||
|
||||
|
||||
@@ -2,37 +2,54 @@
|
||||
// Created by bbr on 18. 04. 2022..
|
||||
//
|
||||
|
||||
#include <set>
|
||||
#include "name_dialog.h"
|
||||
|
||||
display::NameDialog::NameDialog(domain::ComponentInstance *instance) : componentInstance(instance) {
|
||||
display::NameDialog::NameDialog(domain::ComponentInstance *instance, std::set<std::string>& names) : componentInstance(instance), usedNames(names) {
|
||||
usedNames.erase(instance->name);
|
||||
|
||||
auto *layout = new QVBoxLayout(this);
|
||||
layout->addWidget(new QLabel("Izmjeni ime", this));
|
||||
|
||||
edit = new QLineEdit(this);
|
||||
edit->insert(instance->name.c_str());
|
||||
connect(edit, &QLineEdit::textChanged, this, &NameDialog::onNameUpdate);
|
||||
layout->addWidget(edit);
|
||||
this->setWindowTitle("Izmjeni ime");
|
||||
auto *button = new QPushButton("Ažuriraj", this);
|
||||
button = new QPushButton("Ažuriraj", this);
|
||||
connect(button, &QPushButton::clicked, this, &NameDialog::onNameChange);
|
||||
layout->addWidget(button);
|
||||
this->setLayout(layout);
|
||||
}
|
||||
|
||||
display::NameDialog::NameDialog(domain::BusInstance *instance): busInstance(instance) {
|
||||
display::NameDialog::NameDialog(domain::BusInstance *instance, std::set<std::string>& names): busInstance(instance), usedNames(names) {
|
||||
usedNames.erase(instance->name);
|
||||
|
||||
auto *layout = new QVBoxLayout(this);
|
||||
layout->addWidget(new QLabel("Izmjeni ime", this));
|
||||
|
||||
edit = new QLineEdit(this);
|
||||
edit->insert(instance->name.c_str());
|
||||
connect(edit, &QLineEdit::textChanged, this, &NameDialog::onNameUpdate);
|
||||
layout->addWidget(edit);
|
||||
this->setWindowTitle("Izmjeni ime");
|
||||
auto *button = new QPushButton("Ažuriraj", this);
|
||||
button = new QPushButton("Ažuriraj", this);
|
||||
connect(button, &QPushButton::clicked, this, &NameDialog::onNameChange);
|
||||
layout->addWidget(button);
|
||||
this->setLayout(layout);
|
||||
}
|
||||
|
||||
void display::NameDialog::onNameUpdate(const QString &text) {
|
||||
if(usedNames.find(text.toStdString()) == usedNames.end()) {
|
||||
button->setDisabled(false);
|
||||
} else {
|
||||
button->setDisabled(true);
|
||||
}
|
||||
}
|
||||
|
||||
void display::NameDialog::onNameChange() {
|
||||
|
||||
|
||||
if (componentInstance != nullptr) {
|
||||
componentInstance->name = this->edit->text().toStdString();
|
||||
} else if (busInstance != nullptr) {
|
||||
|
||||
@@ -7,24 +7,28 @@
|
||||
#include <QLineEdit>
|
||||
#include <QPushButton>
|
||||
|
||||
#include <set>
|
||||
|
||||
#include <comdel/domain/instance.h>
|
||||
|
||||
namespace display {
|
||||
|
||||
class NameDialog : public QDialog {
|
||||
|
||||
std::set<std::string> usedNames;
|
||||
QLineEdit *edit = nullptr;
|
||||
domain::ComponentInstance *componentInstance = nullptr;
|
||||
domain::BusInstance *busInstance = nullptr;
|
||||
QPushButton *button;
|
||||
|
||||
public:
|
||||
|
||||
NameDialog(domain::ComponentInstance *instance);
|
||||
NameDialog(domain::ComponentInstance *instance, std::set<std::string>& names);
|
||||
|
||||
NameDialog(domain::BusInstance *instance);
|
||||
NameDialog(domain::BusInstance *instance, std::set<std::string>& names);
|
||||
|
||||
public slots:
|
||||
|
||||
void onNameUpdate(const QString& text);
|
||||
void onNameChange();
|
||||
};
|
||||
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
#include "component_display.h"
|
||||
#include "schema_display.h"
|
||||
#include "application.h"
|
||||
#include "attribute_dialog.h"
|
||||
|
||||
#include <QDrag>
|
||||
#include <QDragEnterEvent>
|
||||
@@ -86,15 +88,30 @@ namespace display {
|
||||
|
||||
auto attributes = std::vector<domain::InstanceAttribute>();
|
||||
for (auto attr: component.getAttributes()) {
|
||||
attributes.emplace_back(attr.getName(), attr.getDefault(), attr);
|
||||
domain::InstanceAttribute attribute(attr.getName(), attr.getDefault(), attr);
|
||||
if(attr.getPopup().has_value() && attr.getPopup()->getType() == domain::Popup::AUTOMATIC) {
|
||||
if(attr.getDefault().isType(domain::Value::MEMORY_REFERENCE)) {
|
||||
auto dialog = new MemoryDialog(&attribute, schema->componentInstances);
|
||||
if(dialog->exec() == QDialog::Rejected) {
|
||||
// if any dialog isn't set, whole creation is rejected
|
||||
event->ignore();
|
||||
return;
|
||||
}
|
||||
} else {
|
||||
auto dialog = new AttributeDialog(&attribute);
|
||||
if(dialog->exec() == QDialog::Rejected) {
|
||||
// if any dialog isn't set, whole creation is rejected
|
||||
event->ignore();
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
attributes.push_back(attribute);
|
||||
}
|
||||
|
||||
auto currentPos = this->mapToScene(event->pos());
|
||||
auto currentPos = this->mapToScene(event->pos()).toPoint();
|
||||
|
||||
auto instance = std::make_shared<domain::ComponentInstance>(component.getInstanceName(), attributes,
|
||||
std::make_pair(currentPos.x(), currentPos.y()),
|
||||
component);
|
||||
schema->componentInstances.push_back(instance);
|
||||
auto instance = Application::instance()->addComponent(component, attributes, currentPos.x(), currentPos.y());
|
||||
|
||||
auto group = new display::ComponentGroup(instance);
|
||||
scene.addItem(group);
|
||||
@@ -111,11 +128,9 @@ namespace display {
|
||||
if (event->mimeData()->hasFormat("comdel/bus")) {
|
||||
auto bus = library->getBus(event->mimeData()->data("comdel/bus").toStdString());
|
||||
|
||||
auto currentPos = this->mapToScene(event->pos());
|
||||
auto currentPos = this->mapToScene(event->pos()).toPoint();
|
||||
|
||||
auto instance = std::make_shared<domain::BusInstance>(bus.getName(),
|
||||
std::make_pair(currentPos.x(), currentPos.y()), bus);
|
||||
schema->busInstances.push_back(instance);
|
||||
auto instance = Application::instance()->addBus(bus, currentPos.x(), currentPos.y());
|
||||
|
||||
auto group = new display::BusGroup(instance);
|
||||
scene.addItem(group);
|
||||
|
||||
Reference in new issue
Block a user