41 lines
1.1 KiB
C++
41 lines
1.1 KiB
C++
#include <set>
|
|
#include "name_dialog.h"
|
|
#include "message_source.h"
|
|
|
|
namespace display {
|
|
|
|
NameDialog::NameDialog(std::string currentName, std::set<std::string> &names)
|
|
: GenericDialog("msg_dialog_name_update"), currentName(currentName), usedNames(names) {
|
|
|
|
usedNames.erase(currentName);
|
|
|
|
auto *contentLayout = new QVBoxLayout();
|
|
contentLayout->addWidget(new QLabel(QMESSAGE("msg_dialog_name_update"), 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;
|
|
}
|
|
|
|
}
|