60 lines
1.9 KiB
C++
60 lines
1.9 KiB
C++
//
|
|
// Created by bbr on 18. 04. 2022..
|
|
//
|
|
|
|
#include <set>
|
|
#include "name_dialog.h"
|
|
|
|
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");
|
|
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, 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");
|
|
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) {
|
|
busInstance->name = this->edit->text().toStdString();
|
|
}
|
|
this->close();
|
|
}
|