2 #include "namedialog.h"
4 NameDialog::NameDialog(QWidget *parent, EmuFrontObject *efObj)
5 : EmuFrontDialog(parent), efObject(efObj)
7 nameLabel = new QLabel(tr("&Name: "));
8 nameEdit = new QLineEdit;
9 nameLabel->setBuddy(nameEdit);
10 buttonBox = new QDialogButtonBox(QDialogButtonBox::Ok | QDialogButtonBox::Abort, Qt::Horizontal);
13 setWindowTitle(tr("Set names"));
16 NameDialog::~NameDialog()
20 /* deleting parenteed QT-objects in heap is not needed here
21 * because when deleting a parent widget
22 * the child widgets will be also deleted
26 void NameDialog::connectSignals()
28 connect(nameEdit, SIGNAL(textChanged(const QString &)), this, SLOT(enableSaveButton(const QString &)));
29 connect(buttonBox, SIGNAL(accepted()), this, SLOT(acceptChanges()));
30 connect(buttonBox, SIGNAL(rejected()), this, SLOT(close()));
33 void NameDialog::layout()
35 QHBoxLayout *topLayout = new QHBoxLayout;
36 topLayout->addWidget(nameLabel);
37 topLayout->addWidget(nameEdit);
39 QHBoxLayout *bottomLayout = new QHBoxLayout;
40 bottomLayout->addWidget(buttonBox);
42 QVBoxLayout *mainLayout = new QVBoxLayout;
43 mainLayout->addLayout(topLayout);
44 mainLayout->addLayout(bottomLayout);
45 setLayout(mainLayout);
48 void NameDialog::acceptChanges()
50 if (nameEdit->text() == 0 || nameEdit->text().trimmed().isEmpty())
52 QMessageBox::warning(this, tr("Invalid input"), tr("Empty string is not accepted as name!"));
56 QString name = nameEdit->text().simplified();
58 emit dataObjectUpdated();
59 efObject = 0; // TODO we should also se efObject to null when user clicks abort
63 void NameDialog::enableSaveButton(const QString &text)
65 //saveButton->setEnabled(!text.isEmpty());
68 void NameDialog::setDataObject(EmuFrontObject *ob)
70 // delete efObject; -> we should not delete the previously referenced data object here, it may be still used in the parent widget
71 // the parent widget will take of destruction
72 // we'll just refresh the name dialog pointer to a new object