schema_editor/comdel/display/name_dialog.cpp

51 lines
1.4 KiB
C++
Raw Permalink 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(std::string currentName, std::set<std::string> &names): currentName(currentName) {
usedNames.erase(currentName);
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(currentName.c_str());
connect(edit, &QLineEdit::textChanged, this, &NameDialog::onNameUpdate);
2022-05-27 06:18:17 +00:00
layout->addWidget(edit);
setWindowTitle("Izmjeni ime");
setLayout(layout);
2022-06-12 09:51:57 +00:00
auto buttonLayout = new QHBoxLayout(this);
button = new QPushButton("Ažuriraj");
2022-06-12 09:51:57 +00:00
auto cancelButton = new QPushButton("Odustani", this);
connect(button, &QPushButton::clicked, this, &NameDialog::onNameChange);
2022-06-12 09:51:57 +00:00
connect(cancelButton, &QPushButton::clicked, [this]() { reject(); });
buttonLayout->addWidget(button);
2022-06-12 09:51:57 +00:00
buttonLayout->addWidget(cancelButton);
layout->addLayout(buttonLayout);
2022-05-27 06:18:17 +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() {
currentName = edit->text().toStdString();
close();
}
std::string display::NameDialog::getName() {
return currentName;
2022-05-27 06:18:17 +00:00
}