2022-04-19 06:16:41 +00:00
|
|
|
//
|
|
|
|
// Created by bbr on 18. 04. 2022..
|
|
|
|
//
|
|
|
|
|
2022-05-30 23:05:08 +00:00
|
|
|
#include <set>
|
2022-04-19 06:16:41 +00:00
|
|
|
#include "name_dialog.h"
|
2022-05-27 06:18:17 +00:00
|
|
|
|
2022-05-30 23:05:08 +00:00
|
|
|
display::NameDialog::NameDialog(domain::ComponentInstance *instance, std::set<std::string>& names) : componentInstance(instance), usedNames(names) {
|
|
|
|
usedNames.erase(instance->name);
|
|
|
|
|
2022-05-27 06:18:17 +00:00
|
|
|
auto *layout = new QVBoxLayout(this);
|
|
|
|
layout->addWidget(new QLabel("Izmjeni ime", this));
|
|
|
|
|
|
|
|
edit = new QLineEdit(this);
|
|
|
|
edit->insert(instance->name.c_str());
|
2022-05-30 23:05:08 +00:00
|
|
|
connect(edit, &QLineEdit::textChanged, this, &NameDialog::onNameUpdate);
|
2022-05-27 06:18:17 +00:00
|
|
|
layout->addWidget(edit);
|
|
|
|
this->setWindowTitle("Izmjeni ime");
|
2022-05-30 23:05:08 +00:00
|
|
|
button = new QPushButton("Ažuriraj", this);
|
2022-05-27 06:18:17 +00:00
|
|
|
connect(button, &QPushButton::clicked, this, &NameDialog::onNameChange);
|
|
|
|
layout->addWidget(button);
|
|
|
|
this->setLayout(layout);
|
|
|
|
}
|
|
|
|
|
2022-05-30 23:05:08 +00:00
|
|
|
display::NameDialog::NameDialog(domain::BusInstance *instance, std::set<std::string>& names): busInstance(instance), usedNames(names) {
|
|
|
|
usedNames.erase(instance->name);
|
|
|
|
|
2022-05-27 06:18:17 +00:00
|
|
|
auto *layout = new QVBoxLayout(this);
|
|
|
|
layout->addWidget(new QLabel("Izmjeni ime", this));
|
|
|
|
|
|
|
|
edit = new QLineEdit(this);
|
|
|
|
edit->insert(instance->name.c_str());
|
2022-05-30 23:05:08 +00:00
|
|
|
connect(edit, &QLineEdit::textChanged, this, &NameDialog::onNameUpdate);
|
2022-05-27 06:18:17 +00:00
|
|
|
layout->addWidget(edit);
|
|
|
|
this->setWindowTitle("Izmjeni ime");
|
2022-05-30 23:05:08 +00:00
|
|
|
button = new QPushButton("Ažuriraj", this);
|
2022-05-27 06:18:17 +00:00
|
|
|
connect(button, &QPushButton::clicked, this, &NameDialog::onNameChange);
|
|
|
|
layout->addWidget(button);
|
|
|
|
this->setLayout(layout);
|
|
|
|
}
|
|
|
|
|
2022-05-30 23:05:08 +00:00
|
|
|
void display::NameDialog::onNameUpdate(const QString &text) {
|
|
|
|
if(usedNames.find(text.toStdString()) == usedNames.end()) {
|
|
|
|
button->setDisabled(false);
|
|
|
|
} else {
|
|
|
|
button->setDisabled(true);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-05-27 06:18:17 +00:00
|
|
|
void display::NameDialog::onNameChange() {
|
2022-05-30 23:05:08 +00:00
|
|
|
|
|
|
|
|
2022-05-27 06:18:17 +00:00
|
|
|
if (componentInstance != nullptr) {
|
|
|
|
componentInstance->name = this->edit->text().toStdString();
|
|
|
|
} else if (busInstance != nullptr) {
|
|
|
|
busInstance->name = this->edit->text().toStdString();
|
|
|
|
}
|
|
|
|
this->close();
|
|
|
|
}
|