#include "PersonDialog.h" #include "Person.h" #include #include #include #include #include #include #include #include PersonDialog::PersonDialog( QWidget *parent ) : QDialog( parent ), m_firstName( new QLineEdit() ), m_lastName( new QLineEdit() ), m_age( new QSpinBox() ), m_gender( new QComboBox() ), m_buttons( new QDialogButtonBox( QDialogButtonBox::Save | QDialogButtonBox::Cancel ) ) { m_age->setRange( 0, 150 ); m_gender->addItem( "Male", QVariant::fromValue( Gender::MALE ) ); m_gender->addItem( "Female", QVariant::fromValue( Gender::FEMALE ) ); connect( m_buttons->button( QDialogButtonBox::Save ), &QPushButton::clicked, this, &QDialog::accept ); connect( m_buttons->button( QDialogButtonBox::Cancel ), &QPushButton::clicked, this, &QDialog::reject ); QVBoxLayout *vLayout = new QVBoxLayout( this ); QFormLayout *fLayout = new QFormLayout(); fLayout->addRow( "First Name:", m_firstName ); fLayout->addRow( "Last Name:", m_lastName ); fLayout->addRow( "Age:", m_age ); fLayout->addRow( "Gender:", m_gender ); vLayout->addLayout( fLayout ); QHBoxLayout *hLayout = new QHBoxLayout(); hLayout->addStretch(); hLayout->addWidget( m_buttons ); vLayout->addLayout( hLayout ); setWindowTitle( "Person" ); } void PersonDialog::done( int result ) { QDialog::done( result ); if ( result == Accepted ) emit personSelected( person() ); } Person PersonDialog::person() const { return Person( m_firstName->text(), m_lastName->text(), m_age->value(), m_gender->currentData().value() ); }