schema_editor/comdel/display/dialog/name_dialog.cpp

41 lines
1.1 KiB
C++
Raw Permalink Normal View History

2022-06-13 22:53:46 +00:00
#include <set>
#include "name_dialog.h"
2022-06-19 18:10:44 +00:00
#include "message_source.h"
2022-06-13 22:53:46 +00:00
namespace display {
NameDialog::NameDialog(std::string currentName, std::set<std::string> &names)
2022-06-19 18:10:44 +00:00
: GenericDialog("msg_dialog_name_update"), currentName(currentName), usedNames(names) {
2022-06-13 22:53:46 +00:00
usedNames.erase(currentName);
auto *contentLayout = new QVBoxLayout();
2022-06-19 18:10:44 +00:00
contentLayout->addWidget(new QLabel(QMESSAGE("msg_dialog_name_update"), this));
2022-06-13 22:53:46 +00:00
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;
}
}