schema_editor/comdel/display/name_dialog.h

65 lines
1.8 KiB
C
Raw Normal View History

2022-04-19 06:16:41 +00:00
#ifndef NAME_DIALOG_H
#define NAME_DIALOG_H
#include <QDialog>
2022-04-20 19:50:39 +00:00
#include <QLabel>
#include <QVBoxLayout>
#include <QLineEdit>
#include <QPushButton>
2022-04-19 06:16:41 +00:00
#include <comdel/domain/instance.h>
namespace display {
class NameDialog: public QDialog {
2022-04-20 19:50:39 +00:00
2022-05-15 15:00:20 +00:00
QLineEdit *edit = nullptr;
domain::ComponentInstance *componentInstance = nullptr;
domain::BusInstance *busInstance = nullptr;
2022-04-20 19:50:39 +00:00
2022-04-19 06:16:41 +00:00
public:
2022-05-15 15:00:20 +00:00
NameDialog(domain::ComponentInstance *instance): componentInstance(instance) {
auto *layout = new QVBoxLayout(this);
layout->addWidget(new QLabel("Izmjeni ime", this));
edit = new QLineEdit(this);
edit->insert(instance->name.c_str());
layout->addWidget(edit);
this->setWindowTitle("Izmjeni ime");
auto *button = new QPushButton("Ažuriraj", this);
connect(button, &QPushButton::clicked, this, &NameDialog::onNameChange);
layout->addWidget(button);
this->setLayout(layout);
}
NameDialog(domain::BusInstance *instance): busInstance(instance) {
2022-04-20 19:50:39 +00:00
auto *layout = new QVBoxLayout(this);
layout->addWidget(new QLabel("Izmjeni ime", this));
edit = new QLineEdit(this);
edit->insert(instance->name.c_str());
layout->addWidget(edit);
this->setWindowTitle("Izmjeni ime");
auto *button = new QPushButton("Ažuriraj", this);
connect(button, &QPushButton::clicked, this, &NameDialog::onNameChange);
layout->addWidget(button);
this->setLayout(layout);
}
public slots:
void onNameChange() {
2022-05-15 15:00:20 +00:00
if(componentInstance != nullptr) {
componentInstance->name = this->edit->text().toStdString();
} else if(busInstance != nullptr) {
busInstance->name = this->edit->text().toStdString();
}
2022-04-20 19:50:39 +00:00
this->close();
2022-04-19 06:16:41 +00:00
}
};
}
2022-04-20 19:50:39 +00:00
#endif //NAME_DIALOG_H