From f40dbe0d0b54ce83d2168e82905cf4f75059a841 Mon Sep 17 00:00:00 2001 From: Friedemann Kleint Date: Fri, 29 Apr 2016 15:12:22 +0200 Subject: QtWidgets: Introduce delegating constructors. Reduce code duplication by chaining constructors. Change-Id: I0229556a417153063ac6d14d35765c85e6fe1fe8 Reviewed-by: Marc Mutz --- src/widgets/widgets/qcheckbox.cpp | 4 +--- src/widgets/widgets/qcommandlinkbutton.cpp | 9 ++------- src/widgets/widgets/qdialogbuttonbox.cpp | 10 +++------- src/widgets/widgets/qdockwidget.cpp | 4 +--- src/widgets/widgets/qgroupbox.cpp | 4 +--- src/widgets/widgets/qkeysequenceedit.cpp | 12 ++++-------- src/widgets/widgets/qlabel.cpp | 4 +--- src/widgets/widgets/qlcdnumber.cpp | 5 +---- src/widgets/widgets/qlineedit.cpp | 4 +--- src/widgets/widgets/qmenu.cpp | 3 +-- src/widgets/widgets/qpushbutton.cpp | 8 ++------ src/widgets/widgets/qradiobutton.cpp | 4 +--- src/widgets/widgets/qscrollbar.cpp | 4 +--- src/widgets/widgets/qslider.cpp | 4 +--- src/widgets/widgets/qsplitter.cpp | 5 +---- src/widgets/widgets/qtoolbar.cpp | 4 +--- 16 files changed, 23 insertions(+), 65 deletions(-) (limited to 'src/widgets/widgets') diff --git a/src/widgets/widgets/qcheckbox.cpp b/src/widgets/widgets/qcheckbox.cpp index 19369d6cb1..d4ba17b08e 100644 --- a/src/widgets/widgets/qcheckbox.cpp +++ b/src/widgets/widgets/qcheckbox.cpp @@ -204,10 +204,8 @@ QCheckBox::QCheckBox(QWidget *parent) */ QCheckBox::QCheckBox(const QString &text, QWidget *parent) - : QAbstractButton (*new QCheckBoxPrivate, parent) + : QCheckBox(parent) { - Q_D(QCheckBox); - d->init(); setText(text); } diff --git a/src/widgets/widgets/qcommandlinkbutton.cpp b/src/widgets/widgets/qcommandlinkbutton.cpp index 2ec8b1c41a..b6ec2a8d31 100644 --- a/src/widgets/widgets/qcommandlinkbutton.cpp +++ b/src/widgets/widgets/qcommandlinkbutton.cpp @@ -281,23 +281,18 @@ QCommandLinkButton::QCommandLinkButton(QWidget *parent) */ QCommandLinkButton::QCommandLinkButton(const QString &text, QWidget *parent) - : QPushButton(*new QCommandLinkButtonPrivate, parent) + : QCommandLinkButton(parent) { - Q_D(QCommandLinkButton); setText(text); - d->init(); } /*! Constructs a command link with a \a text, a \a description, and a \a parent. */ QCommandLinkButton::QCommandLinkButton(const QString &text, const QString &description, QWidget *parent) - : QPushButton(*new QCommandLinkButtonPrivate, parent) + : QCommandLinkButton(text, parent) { - Q_D(QCommandLinkButton); - setText(text); setDescription(description); - d->init(); } /*! diff --git a/src/widgets/widgets/qdialogbuttonbox.cpp b/src/widgets/widgets/qdialogbuttonbox.cpp index 2b68c308ec..0d369eb28c 100644 --- a/src/widgets/widgets/qdialogbuttonbox.cpp +++ b/src/widgets/widgets/qdialogbuttonbox.cpp @@ -462,9 +462,8 @@ void QDialogButtonBoxPrivate::retranslateStrings() \sa orientation, addButton() */ QDialogButtonBox::QDialogButtonBox(QWidget *parent) - : QWidget(*new QDialogButtonBoxPrivate(Qt::Horizontal), parent, 0) + : QDialogButtonBox(Qt::Horizontal, parent) { - d_func()->initLayout(); } /*! @@ -487,10 +486,8 @@ QDialogButtonBox::QDialogButtonBox(Qt::Orientation orientation, QWidget *parent) \sa orientation, addButton() */ QDialogButtonBox::QDialogButtonBox(StandardButtons buttons, QWidget *parent) - : QWidget(*new QDialogButtonBoxPrivate(Qt::Horizontal), parent, 0) + : QDialogButtonBox(buttons, Qt::Horizontal, parent) { - d_func()->initLayout(); - d_func()->createStandardButtons(buttons); } /*! @@ -501,9 +498,8 @@ QDialogButtonBox::QDialogButtonBox(StandardButtons buttons, QWidget *parent) */ QDialogButtonBox::QDialogButtonBox(StandardButtons buttons, Qt::Orientation orientation, QWidget *parent) - : QWidget(*new QDialogButtonBoxPrivate(orientation), parent, 0) + : QDialogButtonBox(orientation, parent) { - d_func()->initLayout(); d_func()->createStandardButtons(buttons); } diff --git a/src/widgets/widgets/qdockwidget.cpp b/src/widgets/widgets/qdockwidget.cpp index 3ddf5d4dc6..2358568efe 100644 --- a/src/widgets/widgets/qdockwidget.cpp +++ b/src/widgets/widgets/qdockwidget.cpp @@ -1224,10 +1224,8 @@ QDockWidget::QDockWidget(QWidget *parent, Qt::WindowFlags flags) \sa setWindowTitle() */ QDockWidget::QDockWidget(const QString &title, QWidget *parent, Qt::WindowFlags flags) - : QWidget(*new QDockWidgetPrivate, parent, flags) + : QDockWidget(parent, flags) { - Q_D(QDockWidget); - d->init(); setWindowTitle(title); } diff --git a/src/widgets/widgets/qgroupbox.cpp b/src/widgets/widgets/qgroupbox.cpp index 5bdd6f20e6..a9b32ae065 100644 --- a/src/widgets/widgets/qgroupbox.cpp +++ b/src/widgets/widgets/qgroupbox.cpp @@ -194,10 +194,8 @@ QGroupBox::QGroupBox(QWidget *parent) */ QGroupBox::QGroupBox(const QString &title, QWidget *parent) - : QWidget(*new QGroupBoxPrivate, parent, 0) + : QGroupBox(parent) { - Q_D(QGroupBox); - d->init(); setTitle(title); } diff --git a/src/widgets/widgets/qkeysequenceedit.cpp b/src/widgets/widgets/qkeysequenceedit.cpp index f8a3be366e..2fbc42330d 100644 --- a/src/widgets/widgets/qkeysequenceedit.cpp +++ b/src/widgets/widgets/qkeysequenceedit.cpp @@ -138,21 +138,17 @@ void QKeySequenceEditPrivate::finishEditing() /*! Constructs a QKeySequenceEdit widget with the given \a parent. */ -QKeySequenceEdit::QKeySequenceEdit(QWidget *parent) : - QWidget(*new QKeySequenceEditPrivate, parent, 0) +QKeySequenceEdit::QKeySequenceEdit(QWidget *parent) + : QKeySequenceEdit(*new QKeySequenceEditPrivate, parent, 0) { - Q_D(QKeySequenceEdit); - d->init(); } /*! Constructs a QKeySequenceEdit widget with the given \a keySequence and \a parent. */ -QKeySequenceEdit::QKeySequenceEdit(const QKeySequence &keySequence, QWidget *parent) : - QWidget(*new QKeySequenceEditPrivate, parent, 0) +QKeySequenceEdit::QKeySequenceEdit(const QKeySequence &keySequence, QWidget *parent) + : QKeySequenceEdit(parent) { - Q_D(QKeySequenceEdit); - d->init(); setKeySequence(keySequence); } diff --git a/src/widgets/widgets/qlabel.cpp b/src/widgets/widgets/qlabel.cpp index 5db1013fd2..76713d9880 100644 --- a/src/widgets/widgets/qlabel.cpp +++ b/src/widgets/widgets/qlabel.cpp @@ -233,10 +233,8 @@ QLabel::QLabel(QWidget *parent, Qt::WindowFlags f) \sa setText(), setAlignment(), setFrameStyle(), setIndent() */ QLabel::QLabel(const QString &text, QWidget *parent, Qt::WindowFlags f) - : QFrame(*new QLabelPrivate(), parent, f) + : QLabel(parent, f) { - Q_D(QLabel); - d->init(); setText(text); } diff --git a/src/widgets/widgets/qlcdnumber.cpp b/src/widgets/widgets/qlcdnumber.cpp index 543a7aee11..2703e5d8a3 100644 --- a/src/widgets/widgets/qlcdnumber.cpp +++ b/src/widgets/widgets/qlcdnumber.cpp @@ -338,11 +338,8 @@ static const char *getSegments(char ch) // gets list of segments f */ QLCDNumber::QLCDNumber(QWidget *parent) - : QFrame(*new QLCDNumberPrivate, parent) + : QLCDNumber(5, parent) { - Q_D(QLCDNumber); - d->ndigits = 5; - d->init(); } diff --git a/src/widgets/widgets/qlineedit.cpp b/src/widgets/widgets/qlineedit.cpp index e93ed11930..9e489fad14 100644 --- a/src/widgets/widgets/qlineedit.cpp +++ b/src/widgets/widgets/qlineedit.cpp @@ -260,10 +260,8 @@ void QLineEdit::initStyleOption(QStyleOptionFrame *option) const \sa setText(), setMaxLength() */ QLineEdit::QLineEdit(QWidget* parent) - : QWidget(*new QLineEditPrivate, parent,0) + : QLineEdit(QString(), parent) { - Q_D(QLineEdit); - d->init(QString()); } /*! diff --git a/src/widgets/widgets/qmenu.cpp b/src/widgets/widgets/qmenu.cpp index 8df083f75e..c03c96333a 100644 --- a/src/widgets/widgets/qmenu.cpp +++ b/src/widgets/widgets/qmenu.cpp @@ -1481,10 +1481,9 @@ QMenu::QMenu(QWidget *parent) \sa title */ QMenu::QMenu(const QString &title, QWidget *parent) - : QWidget(*new QMenuPrivate, parent, Qt::Popup) + : QMenu(parent) { Q_D(QMenu); - d->init(); d->menuAction->setText(title); } diff --git a/src/widgets/widgets/qpushbutton.cpp b/src/widgets/widgets/qpushbutton.cpp index a3bb06c063..5608a4aff9 100644 --- a/src/widgets/widgets/qpushbutton.cpp +++ b/src/widgets/widgets/qpushbutton.cpp @@ -254,11 +254,9 @@ QPushButton::QPushButton(QWidget *parent) */ QPushButton::QPushButton(const QString &text, QWidget *parent) - : QAbstractButton(*new QPushButtonPrivate, parent) + : QPushButton(parent) { - Q_D(QPushButton); setText(text); - d->init(); } @@ -270,12 +268,10 @@ QPushButton::QPushButton(const QString &text, QWidget *parent) */ QPushButton::QPushButton(const QIcon& icon, const QString &text, QWidget *parent) - : QAbstractButton(*new QPushButtonPrivate, parent) + : QPushButton(*new QPushButtonPrivate, parent) { - Q_D(QPushButton); setText(text); setIcon(icon); - d->init(); } /*! \internal diff --git a/src/widgets/widgets/qradiobutton.cpp b/src/widgets/widgets/qradiobutton.cpp index 55a584078a..284c5f56cf 100644 --- a/src/widgets/widgets/qradiobutton.cpp +++ b/src/widgets/widgets/qradiobutton.cpp @@ -155,10 +155,8 @@ QRadioButton::~QRadioButton() */ QRadioButton::QRadioButton(const QString &text, QWidget *parent) - : QAbstractButton(*new QRadioButtonPrivate, parent) + : QRadioButton(parent) { - Q_D(QRadioButton); - d->init(); setText(text); } diff --git a/src/widgets/widgets/qscrollbar.cpp b/src/widgets/widgets/qscrollbar.cpp index 0490aa7bc8..79bfedb8c4 100644 --- a/src/widgets/widgets/qscrollbar.cpp +++ b/src/widgets/widgets/qscrollbar.cpp @@ -348,10 +348,8 @@ void QScrollBar::initStyleOption(QStyleOptionSlider *option) const initial \l {QAbstractSlider::value} {value} of 0. */ QScrollBar::QScrollBar(QWidget *parent) - : QAbstractSlider(*new QScrollBarPrivate, parent) + : QScrollBar(Qt::Vertical, parent) { - d_func()->orientation = Qt::Vertical; - d_func()->init(); } /*! diff --git a/src/widgets/widgets/qslider.cpp b/src/widgets/widgets/qslider.cpp index 7b675fccbd..744a43253a 100644 --- a/src/widgets/widgets/qslider.cpp +++ b/src/widgets/widgets/qslider.cpp @@ -284,10 +284,8 @@ QStyle::SubControl QSliderPrivate::newHoverControl(const QPoint &pos) Constructs a vertical slider with the given \a parent. */ QSlider::QSlider(QWidget *parent) - : QAbstractSlider(*new QSliderPrivate, parent) + : QSlider(Qt::Vertical, parent) { - d_func()->orientation = Qt::Vertical; - d_func()->init(); } /*! diff --git a/src/widgets/widgets/qsplitter.cpp b/src/widgets/widgets/qsplitter.cpp index e3ca6b0a79..3f1fa2d015 100644 --- a/src/widgets/widgets/qsplitter.cpp +++ b/src/widgets/widgets/qsplitter.cpp @@ -941,11 +941,8 @@ QSplitterLayoutStruct *QSplitterPrivate::insertWidget(int index, QWidget *w) \sa setOrientation() */ QSplitter::QSplitter(QWidget *parent) - : QFrame(*new QSplitterPrivate, parent) + : QSplitter(Qt::Horizontal, parent) { - Q_D(QSplitter); - d->orient = Qt::Horizontal; - d->init(); } diff --git a/src/widgets/widgets/qtoolbar.cpp b/src/widgets/widgets/qtoolbar.cpp index 2e67276047..b93cefd867 100644 --- a/src/widgets/widgets/qtoolbar.cpp +++ b/src/widgets/widgets/qtoolbar.cpp @@ -520,10 +520,8 @@ QToolBar::QToolBar(QWidget *parent) \sa setWindowTitle() */ QToolBar::QToolBar(const QString &title, QWidget *parent) - : QWidget(*new QToolBarPrivate, parent, 0) + : QToolBar(parent) { - Q_D(QToolBar); - d->init(); setWindowTitle(title); } -- cgit v1.2.3