40 lines
1.0 KiB
C++
40 lines
1.0 KiB
C++
|
#include <set>
|
||
|
#include "name_dialog.h"
|
||
|
|
||
|
namespace display {
|
||
|
|
||
|
NameDialog::NameDialog(std::string currentName, std::set<std::string> &names)
|
||
|
: GenericDialog("Izmjeni ime", "Izmjeni"), currentName(currentName), usedNames(names) {
|
||
|
|
||
|
usedNames.erase(currentName);
|
||
|
|
||
|
auto *contentLayout = new QVBoxLayout();
|
||
|
contentLayout->addWidget(new QLabel("Izmjeni ime", this));
|
||
|
|
||
|
edit = new QLineEdit(this);
|
||
|
edit->insert(currentName.c_str());
|
||
|
connect(edit, &QLineEdit::textChanged, this, &NameDialog::onNameUpdate);
|
||
|
contentLayout->addWidget(edit);
|
||
|
|
||
|
content->setLayout(contentLayout);
|
||
|
}
|
||
|
|
||
|
void NameDialog::onNameUpdate(const QString &text) {
|
||
|
if(usedNames.find(text.toStdString()) == usedNames.end()) {
|
||
|
setOkButtonDisabled(false);
|
||
|
} else {
|
||
|
setOkButtonDisabled(true);
|
||
|
}
|
||
|
}
|
||
|
|
||
|
std::string NameDialog::getName() {
|
||
|
return currentName;
|
||
|
}
|
||
|
|
||
|
bool NameDialog::onUpdate() {
|
||
|
currentName = edit->text().toStdString();
|
||
|
return true;
|
||
|
}
|
||
|
|
||
|
}
|