diff --git a/CMakeLists.txt b/CMakeLists.txt index f59b84e..25f1f0a 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -39,5 +39,5 @@ add_executable(SchemeEditor comdel/parser/comdellexer.cpp main.cpp mainwindow.ui - comdel/domain/comdelvalidator.cpp comdel/domain/comdelvalidator.h) + 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) target_link_libraries(SchemeEditor Qt5::Core Qt5::Gui Qt5::Widgets) diff --git a/SchemeEditor.pro b/SchemeEditor.pro index b6bc69c..c608e2e 100644 --- a/SchemeEditor.pro +++ b/SchemeEditor.pro @@ -38,6 +38,9 @@ SOURCES += \ comdel/parser/sourceerror.cpp \ comdel/parser/token.cpp \ comdel/parser/tokenstype.cpp \ + comdel/display/dialogmanager.cpp \ + comdel/display/attribute_dialog.cpp \ + comdel/display/name_dialog.cpp \ main.cpp \ mainwindow.cpp @@ -74,6 +77,9 @@ HEADERS += \ comdel/parser/sourceerror.h \ comdel/parser/token.h \ comdel/parser/tokenstype.h \ + comdel/display/dialogmanager.h \ + comdel/display/attribute_dialog.h \ + comdel/display/name_dialog.h \ mainwindow.h FORMS += \ diff --git a/comdel/display/attribute_dialog.cpp b/comdel/display/attribute_dialog.cpp new file mode 100644 index 0000000..1ae0aee --- /dev/null +++ b/comdel/display/attribute_dialog.cpp @@ -0,0 +1,5 @@ +// +// Created by bbr on 18. 04. 2022.. +// + +#include "attribute_dialog.h" diff --git a/comdel/display/attribute_dialog.h b/comdel/display/attribute_dialog.h new file mode 100644 index 0000000..b7b538b --- /dev/null +++ b/comdel/display/attribute_dialog.h @@ -0,0 +1,75 @@ +#ifndef ATTRIBUTE_DIALOG_H +#define ATTRIBUTE_DIALOG_H + +#include +#include +#include +#include +#include +#include +#include +#include + +#include + +namespace display { + +class AttributeDialog: public QDialog { + +public: + AttributeDialog(domain::InstanceAttribute *attribute) { + this->setWindowTitle(QString::fromStdString("Izmjeni " + attribute->attribute.getName())); + + auto layout = new QVBoxLayout(this); + this->setLayout(layout); + auto popup = *attribute->attribute.getPopup(); + + layout->addWidget(new QLabel(popup.getTitle().c_str())); + layout->addWidget(new QLabel(popup.getText().c_str())); + + auto type = attribute->attribute.getDefault().getType(); + + if(attribute->attribute.getPopup()->isEnumerated()) { + + } else if(!(type == domain::Value::ValueType::WIRE_REFERENCE || type == domain::Value::ValueType::BOOL)) { + + auto edit = new QLineEdit(this); + layout->addWidget(edit); + + switch (attribute->attribute.getDefault().getType()) { + case domain::Value::ValueType::INT: + edit->setValidator(new QIntValidator(-10000000, 10000000, edit)); + edit->insert(std::to_string(attribute->value.asInt()).c_str()); + break; + case domain::Value::ValueType::STRING: + edit->insert(attribute->value.asString().c_str()); + break; + } + + + + } else if(type == domain::Value::ValueType::BOOL) { + auto *group = new QGroupBox(this); + group->setCheckable(true); + group->setChecked(true); + + auto isTrue = new QRadioButton("true", group); + auto isFalse = new QRadioButton("false", group); + + if(attribute->value.asBool()) { + isTrue->setChecked(true); + } else { + isFalse->setChecked(true); + } + + + + layout->addWidget(group); + } + } + +}; + +} + +#endif //ATTRIBUTE_DIALOG_H diff --git a/comdel/display/component_display.cpp b/comdel/display/component_display.cpp index 2fa6483..9fc2b10 100644 --- a/comdel/display/component_display.cpp +++ b/comdel/display/component_display.cpp @@ -4,6 +4,8 @@ #include #include +#include "dialogmanager.h" + namespace display { ComponentWrapper *ComponentWrapper::ofWire(domain::WireInstance *wire) { @@ -61,10 +63,15 @@ void ComponentItem::redraw() { void ComponentItem::contextMenuEvent(QGraphicsSceneContextMenuEvent *event) { QMenu menu; - menu.addAction("Izmjeni ime"); + auto componentInstance = this->componentInstance; + menu.addAction("Izmjeni ime", [componentInstance](){DialogManager::updateName(componentInstance);}); menu.addSeparator(); for(auto attr: componentInstance->attributes) { - menu.addAction(QString::fromStdString("Izmjeni " + attr->name)); + bool enabled = attr->attribute.getPopup().has_value(); + + auto action = menu.addAction(QString::fromStdString("Izmjeni " + attr->name), + [attr](){DialogManager::updateAttribute(attr);}); + action->setEnabled(enabled); } menu.exec(event->screenPos()); } diff --git a/comdel/display/dialogmanager.cpp b/comdel/display/dialogmanager.cpp new file mode 100644 index 0000000..642a903 --- /dev/null +++ b/comdel/display/dialogmanager.cpp @@ -0,0 +1,21 @@ +// +// 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(); +} + +} \ No newline at end of file diff --git a/comdel/display/dialogmanager.h b/comdel/display/dialogmanager.h new file mode 100644 index 0000000..c4c8f69 --- /dev/null +++ b/comdel/display/dialogmanager.h @@ -0,0 +1,18 @@ +#ifndef DIALOG_MANAGER_H +#define DIALOG_MANAGER_H + +#include +#include + +namespace display { + +class DialogManager { +public: + static void updateAttribute(domain::InstanceAttribute *attribute); + + static void updateName(domain::ComponentInstance *instance); +}; + +} + +#endif //DIALOG_MANAGER_H diff --git a/comdel/display/name_dialog.cpp b/comdel/display/name_dialog.cpp new file mode 100644 index 0000000..77b646d --- /dev/null +++ b/comdel/display/name_dialog.cpp @@ -0,0 +1,5 @@ +// +// Created by bbr on 18. 04. 2022.. +// + +#include "name_dialog.h" diff --git a/comdel/display/name_dialog.h b/comdel/display/name_dialog.h new file mode 100644 index 0000000..f73ccd7 --- /dev/null +++ b/comdel/display/name_dialog.h @@ -0,0 +1,23 @@ +// +// Created by bbr on 18. 04. 2022.. +// + +#ifndef NAME_DIALOG_H +#define NAME_DIALOG_H + +#include +#include + +namespace display { + +class NameDialog: public QDialog { +public: + NameDialog(domain::ComponentInstance *instance) { + + } +}; + +} + + +#endif //sNAME_DIALOG_H