Commit eccc840c authored by Simon Hausmann's avatar Simon Hausmann
Browse files

Small cleanups

* Instantiate the FindDialog on demand only.
* When submitting a contact and there was an error, return early to
avoid adding the incomplete contact.
* In the FindDialog's findClicked slot call accept() or reject() on the
dialog, to propagate the acceptance to the caller in
AddressBook::findContact.
* Renamed FindDialog::getFindText to FindDialog::findText()

Reviewed-by: Kavindra
parent 5cdeac54
......@@ -15,10 +15,6 @@ AddressBook::AddressBook(QWidget *parent)
ui->editButton->setEnabled(false);
ui->removeButton->setEnabled(false);
//! [setup FindDialog]
dialog = new FindDialog;
//! [private members]
connect(ui->addButton, SIGNAL(clicked()), this,
SLOT(addContact()));
connect(ui->submitButton, SIGNAL(clicked()), this,
......@@ -65,6 +61,8 @@ void AddressBook::submitContact()
if (name == "" || address == "") {
QMessageBox::information(this, tr("Empty Field"),
tr("Please enter a name and address."));
updateInterface(NavigationMode);
return;
}
if (currentMode == AddingMode) {
......@@ -224,10 +222,10 @@ void AddressBook::updateInterface(Mode mode)
//! [findContact]
void AddressBook::findContact()
{
dialog->show();
FindDialog dialog;
if (dialog->exec() == QDialog::Accepted) {
QString contactName = dialog->getFindText();
if (dialog.exec() == QDialog::Accepted) {
QString contactName = dialog.findText();
if (contacts.contains(contactName)) {
ui->nameLine->setText(contactName);
......
......@@ -42,9 +42,6 @@ private:
QString oldName;
QString oldAddress;
Mode currentMode;
//! [dialog]
FindDialog *dialog;
//! [dialog]
};
#endif // ADDRESSBOOK_H
......@@ -8,7 +8,6 @@ FindDialog::FindDialog(QWidget *parent) :
m_ui(new Ui::FindDialog)
{
m_ui->setupUi(this);
findText = "";
connect(m_ui->findButton, SIGNAL(clicked()), this, SLOT(findClicked()));
......@@ -29,18 +28,16 @@ void FindDialog::findClicked()
if (text.isEmpty()) {
QMessageBox::information(this, tr("Empty Field"),
tr("Please enter a name."));
return;
reject();
} else {
findText = text;
m_ui->lineEdit->clear();
hide();
accept();
}
}
//! [findClicked]
//! [getFindText]
QString FindDialog::getFindText()
//! [findText]
QString FindDialog::findText()
{
return findText;
return m_ui->lineEdit->text();
}
//! [getFindText]
//! [findText]
......@@ -14,9 +14,9 @@ class FindDialog : public QDialog {
public:
FindDialog(QWidget *parent = 0);
~FindDialog();
//! [getFindText]
QString getFindText();
//! [getFindText]
//! [findText]
QString findText();
//! [findText]
//! [findClicked]
public slots:
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment