OGS
SetNameDialog.cpp
Go to the documentation of this file.
1// SPDX-FileCopyrightText: Copyright (c) OpenGeoSys Community (opengeosys.org)
2// SPDX-License-Identifier: BSD-3-Clause
3
4#include "SetNameDialog.h"
5
6#include <QDialogButtonBox>
7#include <QLabel>
8#include <QLineEdit>
9#include <QVBoxLayout>
10
11SetNameDialog::SetNameDialog(const std::string& geo_object_type, std::size_t id,
12 const std::string& old_name = "", QDialog* parent)
13 : QDialog(parent)
14{
15 QString const& label =
16 QString::fromStdString(geo_object_type) + "#" + QString::number(id);
17 setupDialog(label, old_name);
18 show();
19}
20
22{
23 delete _buttonBox;
24 delete _layout;
25 delete _new_name;
26 delete _txt_label;
27}
28
29void SetNameDialog::setupDialog(const QString& label,
30 const std::string& old_name)
31{
32 _layout = new QVBoxLayout(this);
33 QString dialog_text("Please enter a name for " + label);
34 _txt_label = new QLabel(dialog_text, this);
35 _new_name = new QLineEdit(QString::fromStdString(old_name));
36
37 setWindowTitle("Set name...");
38 _layout->addWidget(_txt_label);
39 _layout->addWidget(_new_name);
41 new QDialogButtonBox(QDialogButtonBox::Ok | QDialogButtonBox::Cancel);
42 connect(_buttonBox, SIGNAL(accepted()), this, SLOT(accept()));
43 connect(_buttonBox, SIGNAL(rejected()), this, SLOT(reject()));
44 _layout->addWidget(_buttonBox);
45
46 setLayout(_layout);
47}
48
50{
51 return _new_name->text().toStdString();
52}
53
55{
56 this->done(QDialog::Accepted);
57}
58
60{
61 this->done(QDialog::Rejected);
62}
void setupDialog(const QString &label, const std::string &old_name)
Constructs a dialog window.
QDialogButtonBox * _buttonBox
QLineEdit * _new_name
std::string getNewName()
QLabel * _txt_label
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