OGS
SetNameDialog.cpp
Go to the documentation of this file.
1
15#include "SetNameDialog.h"
16
17#include <QDialogButtonBox>
18#include <QLabel>
19#include <QLineEdit>
20#include <QVBoxLayout>
21
22SetNameDialog::SetNameDialog(const std::string& geo_object_type, std::size_t id,
23 const std::string& old_name = "", QDialog* parent)
24 : QDialog(parent)
25{
26 QString const& label =
27 QString::fromStdString(geo_object_type) + "#" + QString::number(id);
28 setupDialog(label, old_name);
29 show();
30}
31
33{
34 delete _buttonBox;
35 delete _layout;
36 delete _new_name;
37 delete _txt_label;
38}
39
40void SetNameDialog::setupDialog(const QString& label,
41 const std::string& old_name)
42{
43 _layout = new QVBoxLayout(this);
44 QString dialog_text("Please enter a name for " + label);
45 _txt_label = new QLabel(dialog_text, this);
46 _new_name = new QLineEdit(QString::fromStdString(old_name));
47
48 setWindowTitle("Set name...");
49 _layout->addWidget(_txt_label);
50 _layout->addWidget(_new_name);
52 new QDialogButtonBox(QDialogButtonBox::Ok | QDialogButtonBox::Cancel);
53 connect(_buttonBox, SIGNAL(accepted()), this, SLOT(accept()));
54 connect(_buttonBox, SIGNAL(rejected()), this, SLOT(reject()));
55 _layout->addWidget(_buttonBox);
56
57 setLayout(_layout);
58}
59
61{
62 return _new_name->text().toStdString();
63}
64
66{
67 this->done(QDialog::Accepted);
68}
69
71{
72 this->done(QDialog::Rejected);
73}
Definition of the SetNameDialog class.
void setupDialog(const QString &label, const std::string &old_name)
Constructs a dialog window.
QDialogButtonBox * _buttonBox
Definition: SetNameDialog.h:47
QLineEdit * _new_name
Definition: SetNameDialog.h:45
std::string getNewName()
QLabel * _txt_label
Definition: SetNameDialog.h:44
void reject() override
Instructions if the Cancel-Button has been pressed.
~SetNameDialog() override
void accept() override
Instructions if the OK-Button has been pressed.
SetNameDialog(const std::string &geo_object_type, std::size_t id, const std::string &old_name, QDialog *parent=nullptr)
Constructor.
QVBoxLayout * _layout
Definition: SetNameDialog.h:46