Adding popups (WIP)

This commit is contained in:
Borna Rajkovic 2022-04-19 08:16:41 +02:00
parent 93e643503e
commit 562b77ea0a
9 changed files with 163 additions and 3 deletions

View File

@ -39,5 +39,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/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) target_link_libraries(SchemeEditor Qt5::Core Qt5::Gui Qt5::Widgets)

View File

@ -38,6 +38,9 @@ SOURCES += \
comdel/parser/sourceerror.cpp \ comdel/parser/sourceerror.cpp \
comdel/parser/token.cpp \ comdel/parser/token.cpp \
comdel/parser/tokenstype.cpp \ comdel/parser/tokenstype.cpp \
comdel/display/dialogmanager.cpp \
comdel/display/attribute_dialog.cpp \
comdel/display/name_dialog.cpp \
main.cpp \ main.cpp \
mainwindow.cpp mainwindow.cpp
@ -74,6 +77,9 @@ HEADERS += \
comdel/parser/sourceerror.h \ comdel/parser/sourceerror.h \
comdel/parser/token.h \ comdel/parser/token.h \
comdel/parser/tokenstype.h \ comdel/parser/tokenstype.h \
comdel/display/dialogmanager.h \
comdel/display/attribute_dialog.h \
comdel/display/name_dialog.h \
mainwindow.h mainwindow.h
FORMS += \ FORMS += \

View File

@ -0,0 +1,5 @@
//
// Created by bbr on 18. 04. 2022..
//
#include "attribute_dialog.h"

View File

@ -0,0 +1,75 @@
#ifndef ATTRIBUTE_DIALOG_H
#define ATTRIBUTE_DIALOG_H
#include <QIntValidator>
#include <QGroupBox>
#include <QRadioButton>
#include <QDialog>
#include <QLineEdit>
#include <QLabel>
#include <QVBoxLayout>
#include <comdel/domain/instanceattribute.h>
#include <comdel/domain/value.h>
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

View File

@ -4,6 +4,8 @@
#include <QGraphicsSceneContextMenuEvent> #include <QGraphicsSceneContextMenuEvent>
#include <iostream> #include <iostream>
#include "dialogmanager.h"
namespace display { namespace display {
ComponentWrapper *ComponentWrapper::ofWire(domain::WireInstance *wire) { ComponentWrapper *ComponentWrapper::ofWire(domain::WireInstance *wire) {
@ -61,10 +63,15 @@ void ComponentItem::redraw() {
void ComponentItem::contextMenuEvent(QGraphicsSceneContextMenuEvent *event) { void ComponentItem::contextMenuEvent(QGraphicsSceneContextMenuEvent *event) {
QMenu menu; QMenu menu;
menu.addAction("Izmjeni ime"); auto componentInstance = this->componentInstance;
menu.addAction("Izmjeni ime", [componentInstance](){DialogManager::updateName(componentInstance);});
menu.addSeparator(); menu.addSeparator();
for(auto attr: componentInstance->attributes) { 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()); menu.exec(event->screenPos());
} }

View File

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

View File

@ -0,0 +1,18 @@
#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

@ -0,0 +1,5 @@
//
// Created by bbr on 18. 04. 2022..
//
#include "name_dialog.h"

View File

@ -0,0 +1,23 @@
//
// Created by bbr on 18. 04. 2022..
//
#ifndef NAME_DIALOG_H
#define NAME_DIALOG_H
#include <QDialog>
#include <comdel/domain/instance.h>
namespace display {
class NameDialog: public QDialog {
public:
NameDialog(domain::ComponentInstance *instance) {
}
};
}
#endif //sNAME_DIALOG_H