Added message source and arm example
This commit is contained in:
1 parent
eaa115d115
commit
d2fc849cc2
38 files changed
+2261
-174
No files matched your search
@@ -5,6 +5,7 @@
|
||||
#include "application.h"
|
||||
#include "comdel/display/dialog/single_automatic_dialog.h"
|
||||
#include "comdel/display/dialog/memory_dialog.h"
|
||||
#include "message_source.h"
|
||||
|
||||
#include <QMenu>
|
||||
#include <QLine>
|
||||
@@ -25,7 +26,7 @@ namespace display {
|
||||
|
||||
void Component::contextMenuEvent(QGraphicsSceneContextMenuEvent *event) {
|
||||
QMenu menu;
|
||||
menu.addAction("Izmjeni ime", [this]() {
|
||||
menu.addAction(QMESSAGE("msg_dialog_name_update"), [this]() {
|
||||
std::set<std::string> names;
|
||||
for(const auto &component: Application::instance()->getSchema()->componentInstances) {
|
||||
names.insert(component->name);
|
||||
@@ -45,22 +46,29 @@ namespace display {
|
||||
bool enabled = attr->attribute.getPopup().has_value();
|
||||
|
||||
if(attr->value.getType() == domain::Value::MEMORY_REFERENCE) {
|
||||
menu.addAction("Izmjeni memoriju", [attr]() {
|
||||
auto dialog = new MemoryDialog("Izmjeni memoriju", "Izmjeni", attr,
|
||||
menu.addAction(QMESSAGE("msg_dialog_memory_update"), [attr]() {
|
||||
auto dialog = new MemoryDialog(MESSAGE("msg_dialog_memory_update"),
|
||||
MESSAGE("msg_dialog_actions_update"),
|
||||
attr,
|
||||
Application::instance()->getSchema()->componentInstances);
|
||||
dialog->exec();
|
||||
});
|
||||
} else {
|
||||
auto action = menu.addAction(QString::fromStdString("Izmjeni '" + attr->attribute.getDisplayName() + "'"),
|
||||
[attr]() {
|
||||
auto dialog = new AttributeDialog("Izmjeni " + attr->attribute.getDisplayName(), "Izmjeni", attr);
|
||||
dialog->exec();
|
||||
});
|
||||
std::map<std::string, std::string> params = {{"attribute", attr->attribute.getDisplayName()}};
|
||||
auto action = menu.addAction(QMESSAGE_PARAM("msg_dialog_attribute_update", params),
|
||||
[attr]() {
|
||||
std::map<std::string, std::string> params = {{"attribute", attr->attribute.getDisplayName()}};
|
||||
auto dialog = new AttributeDialog(MESSAGE_PARAM("msg_dialog_attribute_update", params),
|
||||
"msg_dialog_actions_update",
|
||||
attr);
|
||||
dialog->exec();
|
||||
});
|
||||
action->setEnabled(enabled);
|
||||
}
|
||||
}
|
||||
menu.addSeparator();
|
||||
menu.addAction(QString::fromStdString("Ukloni " + this->instance->name), [this]() {
|
||||
std::map<std::string, std::string> params = {{"name", instance->name}};
|
||||
menu.addAction(QMESSAGE_PARAM("msg_dialog_actions_remove_named", params), [this]() {
|
||||
Application::instance()->removeComponent(this->instance->name);
|
||||
auto view = dynamic_cast<Schema *>(this->scene()->views()[0]);
|
||||
view->refreshContent();
|
||||
@@ -75,19 +83,28 @@ namespace display {
|
||||
auto pinConnections = Application::instance()->getSchema()->getConnections(componentInstance->name, pin.getName());
|
||||
|
||||
if(isSingleAutomatic(pinConnections)) {
|
||||
auto *update = menu.addMenu("Izmjeni");
|
||||
auto *remove = menu.addMenu("Ukloni");
|
||||
auto *update = menu.addMenu(QMESSAGE("msg_pin_update"));
|
||||
auto *remove = menu.addMenu(QMESSAGE("msg_pin_remove"));
|
||||
for (auto pinConnection: pinConnections) {
|
||||
// this always must be true as only directConnections can be connected multiple times
|
||||
if (auto directConnection = dynamic_cast<domain::DirectConnectionInstance *>(pinConnection)) {
|
||||
if (directConnection->bus->bus.getType() == domain::Bus::SINGLE_AUTOMATIC) {
|
||||
auto connectionName = directConnection->attributes[0].value.stringify() + "-" +
|
||||
directConnection->attributes[1].value.stringify();
|
||||
update->addAction(QString::fromStdString("Izmjeni " + connectionName), [directConnection]() {
|
||||
auto dialog = new SingleAutomaticDialog("Izmjeni sabirnicu", "Izmjeni", directConnection->attributes);
|
||||
auto params = MessageSource::instance()->map(
|
||||
{{"wire1", directConnection->attributes[0].value},
|
||||
{"wire2", directConnection->attributes[1].value}}
|
||||
);
|
||||
update->addAction(QMESSAGE_PARAM("msg_sa_pin_update_title", params),
|
||||
[directConnection]() {
|
||||
auto params = MessageSource::instance()->map(
|
||||
{{"wire1", directConnection->attributes[0].value},
|
||||
{"wire2", directConnection->attributes[1].value}}
|
||||
);
|
||||
auto dialog = new SingleAutomaticDialog(MESSAGE_PARAM("msg_sa_pin_update_title", params),
|
||||
MESSAGE("msg_pin_update_action"),
|
||||
directConnection->attributes);
|
||||
dialog->exec();
|
||||
});
|
||||
remove->addAction(QString::fromStdString("Ukloni " + connectionName),
|
||||
remove->addAction(QMESSAGE_PARAM("msg_sa_pin_remove_title", params),
|
||||
[this, directConnection]() {
|
||||
Application::instance()->removeConnection(directConnection);
|
||||
auto view = dynamic_cast<Schema *>(this->scene()->views()[0]);
|
||||
@@ -109,12 +126,15 @@ namespace display {
|
||||
}
|
||||
for (int i = 0; i < pinConnection->attributes.size(); i++) {
|
||||
auto *attr = &pinConnection->attributes[i];
|
||||
menu.addAction(QString::fromStdString("Izmjeni '" + attr->attribute.getDisplayName() + "'"),[attr]() {
|
||||
auto dialog = new AttributeDialog("Izmjeni '" + attr->attribute.getDisplayName() + "'", "Izmjeni", attr);
|
||||
dialog->exec();
|
||||
std::map<std::string, std::string> params = {{"name", attr->attribute.getDisplayName()}};
|
||||
menu.addAction(QMESSAGE_PARAM("msg_dialog_actions_update_named", params),
|
||||
[attr]() {
|
||||
std::map<std::string, std::string> params = {{"name", attr->attribute.getDisplayName()}};
|
||||
auto dialog = new AttributeDialog(MESSAGE_PARAM("msg_dialog_actions_update_named", params), "msg_pin_update_action", attr);
|
||||
dialog->exec();
|
||||
});
|
||||
}
|
||||
menu.addAction("Ukloni poveznicu", [this, pinConnection]() {
|
||||
menu.addAction(QMESSAGE("msg_pin_remove_action"), [this, pinConnection]() {
|
||||
Application::instance()->removeConnection(pinConnection);
|
||||
auto view = dynamic_cast<Schema *>(this->scene()->views()[0]);
|
||||
view->refreshContent();
|
||||
@@ -186,7 +206,7 @@ namespace display {
|
||||
|
||||
void Bus::contextMenuEvent(QGraphicsSceneContextMenuEvent *event) {
|
||||
QMenu menu;
|
||||
menu.addAction("Izmjeni ime", [this]() {
|
||||
menu.addAction(QMESSAGE("msg_dialog_name_update"), [this]() {
|
||||
std::set<std::string> names;
|
||||
for(const auto &component: Application::instance()->getSchema()->busInstances) {
|
||||
names.insert(component->name);
|
||||
@@ -201,7 +221,9 @@ namespace display {
|
||||
setToolTip(QString::fromStdString(busInstance->name + "::" + busInstance->bus.getDisplayName()));
|
||||
});
|
||||
menu.addSeparator();
|
||||
menu.addAction(QString::fromStdString("Ukloni " + this->busInstance->name), [this]() {
|
||||
|
||||
std::map<std::string, std::string> params = {{"name", busInstance->name}};
|
||||
menu.addAction(QMESSAGE_PARAM("msg_dialog_actions_remove_named", params), [this]() {
|
||||
Application::instance()->removeBus(this->busInstance->name);
|
||||
auto view = dynamic_cast<Schema *>(this->scene()->views()[0]);
|
||||
view->refreshContent();
|
||||
@@ -306,10 +328,19 @@ namespace display {
|
||||
}
|
||||
|
||||
void DirectConnection::updateConnection() {
|
||||
auto pin1 = connection->instance->component.getPin(
|
||||
connection->connection.getComponent().pin).getDisplayPin();
|
||||
auto pin2 = connection->secondInstance->component.getPin(
|
||||
connection->connection.getSecondComponent()->pin).getDisplayPin();
|
||||
domain::ui::Pin pin1, pin2;
|
||||
if(connection->connection.getComponent().component == connection->instance->component.getName()) {
|
||||
pin1 = connection->instance->component.getPin(
|
||||
connection->connection.getComponent().pin).getDisplayPin();
|
||||
pin2 = connection->secondInstance->component.getPin(
|
||||
connection->connection.getSecondComponent()->pin).getDisplayPin();
|
||||
|
||||
} else {
|
||||
pin1 = connection->instance->component.getPin(
|
||||
connection->connection.getSecondComponent()->pin).getDisplayPin();
|
||||
pin2 = connection->secondInstance->component.getPin(
|
||||
connection->connection.getComponent().pin).getDisplayPin();
|
||||
}
|
||||
|
||||
setLine(connection->instance->position.first + pin1.getConnectionX(),
|
||||
connection->instance->position.second + pin1.getConnectionY(),
|
||||
|
||||
@@ -4,6 +4,7 @@
|
||||
#include "application.h"
|
||||
#include "error_dialog.h"
|
||||
#include "warning_dialog.h"
|
||||
#include "message_source.h"
|
||||
|
||||
namespace display {
|
||||
|
||||
@@ -140,11 +141,11 @@ namespace display {
|
||||
auto *radioLayout = new QHBoxLayout(group);
|
||||
group->setLayout(radioLayout);
|
||||
|
||||
auto isTrue = new QRadioButton("da", group);
|
||||
auto isTrue = new QRadioButton(QMESSAGE("msg_boolean_true"), group);
|
||||
connect(isTrue, &QRadioButton::clicked, [this]() {
|
||||
this->value = domain::Value::fromBool(true);
|
||||
});
|
||||
auto isFalse = new QRadioButton("ne", group);
|
||||
auto isFalse = new QRadioButton(QMESSAGE("msg_boolean_false"), group);
|
||||
connect(isFalse, &QRadioButton::clicked, [this]() {
|
||||
this->value = domain::Value::fromBool(false);
|
||||
});
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
namespace display {
|
||||
|
||||
ErrorDialog::ErrorDialog(std::vector<domain::ValidationError> errors)
|
||||
: GenericDialog("Greške", "") {
|
||||
: GenericDialog("msg_dialog_error_title", std::nullopt, "msg_dialog_error_close") {
|
||||
|
||||
auto contentLayout = new QVBoxLayout();
|
||||
content->setLayout(contentLayout);
|
||||
@@ -17,7 +17,7 @@ namespace display {
|
||||
}
|
||||
|
||||
ErrorDialog::ErrorDialog(std::ostringstream& errorStream)
|
||||
: GenericDialog("Greške", "") {
|
||||
: GenericDialog("msg_dialog_error_title", std::nullopt, "msg_dialog_error_close") {
|
||||
|
||||
auto contentLayout = new QVBoxLayout();
|
||||
content->setLayout(contentLayout);
|
||||
|
||||
@@ -1,9 +1,11 @@
|
||||
#include <QVBoxLayout>
|
||||
#include "generic_dialog.h"
|
||||
|
||||
display::GenericDialog::GenericDialog(std::string title, std::string action) {
|
||||
#include "message_source.h"
|
||||
|
||||
display::GenericDialog::GenericDialog(std::string title, std::optional<std::string> action, std::string cancel) {
|
||||
setAttribute(Qt::WA_DeleteOnClose);
|
||||
setWindowTitle(QString::fromStdString(title));
|
||||
setWindowTitle(QMESSAGE(title));
|
||||
|
||||
setLayout(new QVBoxLayout());
|
||||
content = new QWidget(this);
|
||||
@@ -14,12 +16,16 @@ display::GenericDialog::GenericDialog(std::string title, std::string action) {
|
||||
layout()->addWidget(actionWidget);
|
||||
|
||||
// if action isn't defined only close button is offered
|
||||
if(!action.empty()) {
|
||||
okButton = new QPushButton(QString::fromStdString(action), this);
|
||||
connect(okButton, &QPushButton::clicked, this, [this](){if(this->onUpdate()) this->accept();});
|
||||
if(action.has_value()) {
|
||||
okButton = new QPushButton(QMESSAGE(*action), this);
|
||||
connect(okButton, &QPushButton::clicked, this, [this](){
|
||||
if(this->onUpdate()) {
|
||||
this->accept();
|
||||
}
|
||||
});
|
||||
actionBar->addWidget(okButton);
|
||||
}
|
||||
cancelButton = new QPushButton("Odustani", this);
|
||||
cancelButton = new QPushButton(QMESSAGE(cancel), this);
|
||||
connect(cancelButton, &QPushButton::clicked, [this]() { reject(); });
|
||||
actionBar->addWidget(cancelButton);
|
||||
}
|
||||
|
||||
@@ -5,12 +5,16 @@
|
||||
#include <QWidget>
|
||||
#include <QPushButton>
|
||||
|
||||
#include <optional>
|
||||
|
||||
namespace display {
|
||||
|
||||
class GenericDialog: public QDialog {
|
||||
public:
|
||||
|
||||
GenericDialog(std::string title, std::string action = "Ažuriraj");
|
||||
explicit GenericDialog(std::string title,
|
||||
std::optional<std::string> action = "msg_dialog_actions_update",
|
||||
std::string cancel = "msg_dialog_actions_cancel");
|
||||
|
||||
protected:
|
||||
void setOkButtonDisabled(bool disabled);
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
#include <QVBoxLayout>
|
||||
#include <QLabel>
|
||||
#include "memory_dialog.h"
|
||||
#include "message_source.h"
|
||||
|
||||
namespace display {
|
||||
|
||||
@@ -35,7 +36,7 @@ namespace display {
|
||||
for (const auto& entry: memoryInstances) {
|
||||
combo->addItem(QString::fromStdString(entry));
|
||||
}
|
||||
combo->addItem("null");
|
||||
combo->addItem(QMESSAGE("msg_dialog_memory_default"));
|
||||
|
||||
connect(combo, QOverload<int>::of(&QComboBox::currentIndexChanged), [this](int index) {
|
||||
if(index == memoryInstances.size()) {
|
||||
|
||||
@@ -1,15 +1,16 @@
|
||||
#include <set>
|
||||
#include "name_dialog.h"
|
||||
#include "message_source.h"
|
||||
|
||||
namespace display {
|
||||
|
||||
NameDialog::NameDialog(std::string currentName, std::set<std::string> &names)
|
||||
: GenericDialog("Izmjeni ime", "Izmjeni"), currentName(currentName), usedNames(names) {
|
||||
: GenericDialog("msg_dialog_name_update"), currentName(currentName), usedNames(names) {
|
||||
|
||||
usedNames.erase(currentName);
|
||||
|
||||
auto *contentLayout = new QVBoxLayout();
|
||||
contentLayout->addWidget(new QLabel("Izmjeni ime", this));
|
||||
contentLayout->addWidget(new QLabel(QMESSAGE("msg_dialog_name_update"), this));
|
||||
|
||||
edit = new QLineEdit(this);
|
||||
edit->insert(currentName.c_str());
|
||||
|
||||
@@ -2,14 +2,16 @@
|
||||
#include <QLabel>
|
||||
#include <QPushButton>
|
||||
#include "success_dialog.h"
|
||||
#include "message_source.h"
|
||||
|
||||
namespace display {
|
||||
|
||||
SuccessDialog::SuccessDialog(std::string message, std::string action) {
|
||||
SuccessDialog::SuccessDialog(std::string message) {
|
||||
setLayout(new QVBoxLayout());
|
||||
setWindowTitle(QMESSAGE("msg_dialog_success_title"));
|
||||
layout()->addWidget(new QLabel(QString::fromStdString(message)));
|
||||
|
||||
auto button = new QPushButton(QString::fromStdString(action));
|
||||
auto button = new QPushButton(QMESSAGE("msg_dialog_actions_ok"));
|
||||
connect(button, &QPushButton::clicked, [this]() {accept();});
|
||||
layout()->addWidget(button);
|
||||
}
|
||||
|
||||
@@ -11,7 +11,7 @@ namespace display {
|
||||
|
||||
class SuccessDialog: public QDialog {
|
||||
public:
|
||||
explicit SuccessDialog(std::string message, std::string action = "Ok");
|
||||
explicit SuccessDialog(std::string message);
|
||||
};
|
||||
|
||||
} // display
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
namespace display {
|
||||
|
||||
WarningDialog::WarningDialog(domain::ValidationError error)
|
||||
: GenericDialog("Upozorenje", "U redu") {
|
||||
: GenericDialog("msg_dialog_warning_title", "msg_dialog_actions_ok") {
|
||||
|
||||
auto contentLayout = new QVBoxLayout();
|
||||
content->setLayout(contentLayout);
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
#include "library_display.h"
|
||||
#include "message_source.h"
|
||||
|
||||
#include <QLabel>
|
||||
#include <QListWidget>
|
||||
@@ -15,16 +16,23 @@ namespace display {
|
||||
busList = new LibraryList(this);
|
||||
|
||||
layout->setContentsMargins(4, 4, 4, 4);
|
||||
layout->addWidget(new QLabel("Komponente:"));
|
||||
|
||||
componentsLabel = new QLabel(QMESSAGE("msg_sidebar_components"));
|
||||
busLabel = new QLabel(QMESSAGE("msg_sidebar_busses"));
|
||||
|
||||
layout->addWidget(componentsLabel);
|
||||
layout->addWidget(componentList, 1);
|
||||
layout->addSpacing(8);
|
||||
layout->addWidget(new QLabel("Sabirnice:"));
|
||||
layout->addWidget(busLabel);
|
||||
layout->addWidget(busList, 1);
|
||||
}
|
||||
|
||||
void Library::refreshContent() {
|
||||
library = Application::instance()->getLibrary();
|
||||
|
||||
componentsLabel->setText(QMESSAGE("msg_sidebar_components"));
|
||||
busLabel->setText(QMESSAGE("msg_sidebar_busses"));
|
||||
|
||||
componentList->clear();
|
||||
busList->clear();
|
||||
|
||||
|
||||
@@ -5,6 +5,7 @@
|
||||
#include <QWidget>
|
||||
|
||||
#include <comdel/domain/library.h>
|
||||
#include <QLabel>
|
||||
#include "library_list.h"
|
||||
|
||||
namespace display {
|
||||
@@ -21,6 +22,8 @@ namespace display {
|
||||
LibraryList *componentList;
|
||||
LibraryList *busList;
|
||||
|
||||
QLabel *componentsLabel;
|
||||
QLabel *busLabel;
|
||||
};
|
||||
|
||||
} // namespace display
|
||||
|
||||
@@ -8,6 +8,8 @@
|
||||
#include <QDrag>
|
||||
#include <QDragEnterEvent>
|
||||
#include <QMimeData>
|
||||
#include "message_source.h"
|
||||
|
||||
|
||||
namespace display {
|
||||
|
||||
@@ -183,7 +185,7 @@ namespace display {
|
||||
|
||||
if (rect.contains(endPoint)) {
|
||||
auto name = components[pinInstance.component]->getComponentInstance()->component.getName();
|
||||
auto con = library->getConnection({instance->component.getName(), connection.pin.value().getName()},
|
||||
auto con = library->getConnection({instance->component.getName(), context.pin->getPin().getName()},
|
||||
{name, pinInstance.pin});
|
||||
if (con.has_value()) {
|
||||
auto busInstance = Application::instance()->addBus(library->getBus(con->getBus()), 0, 0);
|
||||
@@ -199,12 +201,22 @@ namespace display {
|
||||
return;
|
||||
}
|
||||
|
||||
auto conInstance = std::make_shared<domain::DirectConnectionInstance>(instance,
|
||||
components[pinInstance.component]->getComponentInstance().get(),
|
||||
attributes, busInstance.get(),
|
||||
*con);
|
||||
std::shared_ptr<domain::DirectConnectionInstance> conInstance = nullptr;
|
||||
if(con->getComponent() == domain::ConnectionComponent{instance->component.getName(), context.pin->getPin().getName()}) {
|
||||
conInstance = std::make_shared<domain::DirectConnectionInstance>(instance,
|
||||
components[pinInstance.component]->getComponentInstance().get(),
|
||||
attributes, busInstance.get(),
|
||||
*con);
|
||||
} else {
|
||||
conInstance = std::make_shared<domain::DirectConnectionInstance>(components[pinInstance.component]->getComponentInstance().get(),
|
||||
instance,
|
||||
attributes, busInstance.get(),
|
||||
*con);
|
||||
}
|
||||
|
||||
schema->connections.push_back(conInstance);
|
||||
|
||||
|
||||
if (conInstance != nullptr) {
|
||||
auto c = new display::DirectConnection(conInstance.get(),
|
||||
components[conInstance->instance->name],
|
||||
@@ -276,13 +288,14 @@ namespace display {
|
||||
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("Postavi memoriju", "Postavi", &attribute, schema->componentInstances);
|
||||
auto dialog = new MemoryDialog("msg_dialog_memory_set", "msg_dialog_actions_set", &attribute, schema->componentInstances);
|
||||
if(dialog->exec() == QDialog::Rejected) {
|
||||
// if any dialog isn't set, whole creation is rejected
|
||||
return {};
|
||||
}
|
||||
} else {
|
||||
auto dialog = new AttributeDialog("Postavi " + attribute.attribute.getDisplayName(), "Postavi", &attribute);
|
||||
std::map<std::string, std::string> params = {{"attribute", attribute.attribute.getDisplayName()}};
|
||||
auto dialog = new AttributeDialog(MESSAGE_PARAM("msg_dialog_attribute_set", params), "msg_dialog_actions_set", &attribute);
|
||||
if(dialog->exec() == QDialog::Rejected) {
|
||||
// if any dialog isn't set, whole creation is rejected
|
||||
return {};
|
||||
@@ -301,7 +314,7 @@ namespace display {
|
||||
instanceAttributes.emplace_back(attr.getName(), attr.getDefault(), attr);
|
||||
}
|
||||
|
||||
auto dialog = new display::SingleAutomaticDialog("Postavi sabirnicu", "Postavi", instanceAttributes);
|
||||
auto dialog = new display::SingleAutomaticDialog("msg_dialog_sa_pin_set", "msg_dialog_actions_set", instanceAttributes);
|
||||
if(dialog->exec() == QDialog::Rejected) {
|
||||
// if dialog is rejected, whole creation is rejected
|
||||
return {};
|
||||
|
||||
Reference in new issue
Block a user