From 51f6d5d8c261fb94adc9bf5754cabf8e37236af5 Mon Sep 17 00:00:00 2001 From: Christian Ehrlicher Date: Mon, 12 Nov 2018 21:20:34 +0100 Subject: Cleanup Addressbook example Cleanup the Addressbook example: - use nullptr - use for instead foreach - don't use public members but setters/getters - use QVector instead QList - make user-visible translatable Change-Id: Ie7bdad8a2799c8fa6f634659b51c3064cc8a04ce Reviewed-by: Samuel Gaist Reviewed-by: Sze Howe Koh Reviewed-by: Paul Wicking Reviewed-by: Luca Beldi --- .../widgets/itemviews/addressbook/newaddresstab.cpp | 21 ++++++++------------- 1 file changed, 8 insertions(+), 13 deletions(-) (limited to 'examples/widgets/itemviews/addressbook/newaddresstab.cpp') diff --git a/examples/widgets/itemviews/addressbook/newaddresstab.cpp b/examples/widgets/itemviews/addressbook/newaddresstab.cpp index f0a7369796..ef725d723f 100644 --- a/examples/widgets/itemviews/addressbook/newaddresstab.cpp +++ b/examples/widgets/itemviews/addressbook/newaddresstab.cpp @@ -48,24 +48,23 @@ ** ****************************************************************************/ -#include "adddialog.h" #include "newaddresstab.h" +#include "adddialog.h" #include //! [0] NewAddressTab::NewAddressTab(QWidget *parent) + : QWidget(parent) { - Q_UNUSED(parent); + auto descriptionLabel = new QLabel(tr("There are currently no contacts in your address book. " + "\nClick Add to add new contacts.")); - descriptionLabel = new QLabel(tr("There are currently no contacts in your address book. " - "\nClick Add to add new contacts.")); - - addButton = new QPushButton(tr("Add")); + auto addButton = new QPushButton(tr("Add")); connect(addButton, &QAbstractButton::clicked, this, &NewAddressTab::addEntry); - mainLayout = new QVBoxLayout; + auto mainLayout = new QVBoxLayout; mainLayout->addWidget(descriptionLabel); mainLayout->addWidget(addButton, 0, Qt::AlignCenter); @@ -78,11 +77,7 @@ void NewAddressTab::addEntry() { AddDialog aDialog; - if (aDialog.exec()) { - QString name = aDialog.nameText->text(); - QString address = aDialog.addressText->toPlainText(); - - emit sendDetails(name, address); - } + if (aDialog.exec()) + emit sendDetails(aDialog.name(), aDialog.address()); } //! [1] -- cgit v1.2.3