schema_editor/comdel/display/name_dialog.cpp

60 lines
1.9 KiB
C++
Raw Normal View History

2022-04-19 06:16:41 +00:00
//
// Created by bbr on 18. 04. 2022..
//
#include <set>
2022-04-19 06:16:41 +00:00
#include "name_dialog.h"
2022-05-27 06:18:17 +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());
connect(edit, &QLineEdit::textChanged, this, &NameDialog::onNameUpdate);
2022-05-27 06:18:17 +00:00
layout->addWidget(edit);
this->setWindowTitle("Izmjeni ime");
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);
}
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());
connect(edit, &QLineEdit::textChanged, this, &NameDialog::onNameUpdate);
2022-05-27 06:18:17 +00:00
layout->addWidget(edit);
this->setWindowTitle("Izmjeni ime");
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);
}
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-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();
}