diff options
author | Christian Ehrlicher <ch.ehrlicher@gmx.de> | 2018-11-12 21:20:34 +0100 |
---|---|---|
committer | Christian Ehrlicher <ch.ehrlicher@gmx.de> | 2018-12-04 07:00:41 +0000 |
commit | 51f6d5d8c261fb94adc9bf5754cabf8e37236af5 (patch) | |
tree | 88a374c564ffadd6b1f90e97121ab7274484bf71 /examples/widgets/itemviews/addressbook/adddialog.cpp | |
parent | 8c38b08343b226883ef368d31a085b0a620f7995 (diff) |
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 <samuel.gaist@idiap.ch>
Reviewed-by: Sze Howe Koh <szehowe.koh@gmail.com>
Reviewed-by: Paul Wicking <paul.wicking@qt.io>
Reviewed-by: Luca Beldi <v.ronin@yahoo.it>
Diffstat (limited to 'examples/widgets/itemviews/addressbook/adddialog.cpp')
-rw-r--r-- | examples/widgets/itemviews/addressbook/adddialog.cpp | 38 |
1 files changed, 27 insertions, 11 deletions
diff --git a/examples/widgets/itemviews/addressbook/adddialog.cpp b/examples/widgets/itemviews/addressbook/adddialog.cpp index 1ce2d3110a..bf87307253 100644 --- a/examples/widgets/itemviews/addressbook/adddialog.cpp +++ b/examples/widgets/itemviews/addressbook/adddialog.cpp @@ -54,17 +54,16 @@ //! [0] AddDialog::AddDialog(QWidget *parent) - : QDialog(parent) + : QDialog(parent), + nameText(new QLineEdit), + addressText(new QTextEdit) { - nameLabel = new QLabel("Name"); - addressLabel = new QLabel("Address"); - okButton = new QPushButton("OK"); - cancelButton = new QPushButton("Cancel"); + auto nameLabel = new QLabel(tr("Name")); + auto addressLabel = new QLabel(tr("Address")); + auto okButton = new QPushButton(tr("OK")); + auto cancelButton = new QPushButton(tr("Cancel")); - nameText = new QLineEdit; - addressText = new QTextEdit; - - QGridLayout *gLayout = new QGridLayout; + auto gLayout = new QGridLayout; gLayout->setColumnStretch(1, 2); gLayout->addWidget(nameLabel, 0, 0); gLayout->addWidget(nameText, 0, 1); @@ -72,13 +71,13 @@ AddDialog::AddDialog(QWidget *parent) gLayout->addWidget(addressLabel, 1, 0, Qt::AlignLeft|Qt::AlignTop); gLayout->addWidget(addressText, 1, 1, Qt::AlignLeft); - QHBoxLayout *buttonLayout = new QHBoxLayout; + auto buttonLayout = new QHBoxLayout; buttonLayout->addWidget(okButton); buttonLayout->addWidget(cancelButton); gLayout->addLayout(buttonLayout, 2, 1, Qt::AlignRight); - QVBoxLayout *mainLayout = new QVBoxLayout; + auto mainLayout = new QVBoxLayout; mainLayout->addLayout(gLayout); setLayout(mainLayout); @@ -87,4 +86,21 @@ AddDialog::AddDialog(QWidget *parent) setWindowTitle(tr("Add a Contact")); } + +QString AddDialog::name() const +{ + return nameText->text(); +} + +QString AddDialog::address() const +{ + return addressText->toPlainText(); +} + +void AddDialog::editAddress(const QString &name, const QString &address) +{ + nameText->setReadOnly(true); + nameText->setText(name); + addressText->setPlainText(address); +} //! [0] |