QtWidgets: Introduce delegating constructors.
Reduce code duplication by chaining constructors. Change-Id: I0229556a417153063ac6d14d35765c85e6fe1fe8 Reviewed-by: Marc Mutz <marc.mutz@kdab.com>
This commit is contained in:
parent
799be4e489
commit
f40dbe0d0b
@ -1948,10 +1948,8 @@ static const Qt::WindowFlags DefaultWindowFlags =
|
||||
Constructs a color dialog with the given \a parent.
|
||||
*/
|
||||
QColorDialog::QColorDialog(QWidget *parent)
|
||||
: QDialog(*new QColorDialogPrivate, parent, DefaultWindowFlags)
|
||||
: QColorDialog(QColor(Qt::white), parent)
|
||||
{
|
||||
Q_D(QColorDialog);
|
||||
d->init(Qt::white);
|
||||
}
|
||||
|
||||
/*!
|
||||
|
@ -168,10 +168,8 @@ QFontDialog::QFontDialog(QWidget *parent)
|
||||
\a initial color.
|
||||
*/
|
||||
QFontDialog::QFontDialog(const QFont &initial, QWidget *parent)
|
||||
: QDialog(*new QFontDialogPrivate, parent, DefaultWindowFlags)
|
||||
: QFontDialog(parent)
|
||||
{
|
||||
Q_D(QFontDialog);
|
||||
d->init();
|
||||
setCurrentFont(initial);
|
||||
}
|
||||
|
||||
|
@ -279,12 +279,8 @@ void QActionPrivate::setShortcutEnabled(bool enable, QShortcutMap &map)
|
||||
group the action will be automatically inserted into the group.
|
||||
*/
|
||||
QAction::QAction(QObject* parent)
|
||||
: QObject(*(new QActionPrivate), parent)
|
||||
: QAction(*new QActionPrivate, parent)
|
||||
{
|
||||
Q_D(QAction);
|
||||
d->group = qobject_cast<QActionGroup *>(parent);
|
||||
if (d->group)
|
||||
d->group->addAction(this);
|
||||
}
|
||||
|
||||
|
||||
@ -302,13 +298,10 @@ QAction::QAction(QObject* parent)
|
||||
|
||||
*/
|
||||
QAction::QAction(const QString &text, QObject* parent)
|
||||
: QObject(*(new QActionPrivate), parent)
|
||||
: QAction(parent)
|
||||
{
|
||||
Q_D(QAction);
|
||||
d->text = text;
|
||||
d->group = qobject_cast<QActionGroup *>(parent);
|
||||
if (d->group)
|
||||
d->group->addAction(this);
|
||||
}
|
||||
|
||||
/*!
|
||||
@ -324,14 +317,10 @@ QAction::QAction(const QString &text, QObject* parent)
|
||||
setToolTip().
|
||||
*/
|
||||
QAction::QAction(const QIcon &icon, const QString &text, QObject* parent)
|
||||
: QObject(*(new QActionPrivate), parent)
|
||||
: QAction(text, parent)
|
||||
{
|
||||
Q_D(QAction);
|
||||
d->icon = icon;
|
||||
d->text = text;
|
||||
d->group = qobject_cast<QActionGroup *>(parent);
|
||||
if (d->group)
|
||||
d->group->addAction(this);
|
||||
}
|
||||
|
||||
/*!
|
||||
|
@ -456,12 +456,11 @@ QShortcut::QShortcut(QWidget *parent)
|
||||
QShortcut::QShortcut(const QKeySequence &key, QWidget *parent,
|
||||
const char *member, const char *ambiguousMember,
|
||||
Qt::ShortcutContext context)
|
||||
: QObject(*new QShortcutPrivate, parent)
|
||||
: QShortcut(parent)
|
||||
{
|
||||
QAPP_CHECK("QShortcut");
|
||||
|
||||
Q_D(QShortcut);
|
||||
Q_ASSERT(parent != 0);
|
||||
d->sc_context = context;
|
||||
d->sc_sequence = key;
|
||||
d->redoGrab(qApp->d_func()->shortcutMap);
|
||||
|
@ -131,16 +131,9 @@ QProxyStyle::QProxyStyle(QStyle *style) :
|
||||
|
||||
\sa QStyleFactory::create()
|
||||
*/
|
||||
QProxyStyle::QProxyStyle(const QString &key) :
|
||||
QCommonStyle(*new QProxyStylePrivate())
|
||||
QProxyStyle::QProxyStyle(const QString &key)
|
||||
: QProxyStyle(QStyleFactory::create(key))
|
||||
{
|
||||
Q_D(QProxyStyle);
|
||||
QStyle *style = QStyleFactory::create(key);
|
||||
if (style) {
|
||||
d->baseStyle = style;
|
||||
style->setProxy(this);
|
||||
style->setParent(this); // Take ownership
|
||||
}
|
||||
}
|
||||
|
||||
/*!
|
||||
|
@ -141,7 +141,7 @@ QSystemTrayIcon::QSystemTrayIcon(QObject *parent)
|
||||
\sa visible
|
||||
*/
|
||||
QSystemTrayIcon::QSystemTrayIcon(const QIcon &icon, QObject *parent)
|
||||
: QObject(*new QSystemTrayIconPrivate(), parent)
|
||||
: QSystemTrayIcon(parent)
|
||||
{
|
||||
setIcon(icon);
|
||||
}
|
||||
|
@ -110,10 +110,8 @@ QT_BEGIN_NAMESPACE
|
||||
*/
|
||||
|
||||
QUndoCommand::QUndoCommand(const QString &text, QUndoCommand *parent)
|
||||
: QUndoCommand(parent)
|
||||
{
|
||||
d = new QUndoCommandPrivate;
|
||||
if (parent != 0)
|
||||
parent->d->child_list.append(this);
|
||||
setText(text);
|
||||
}
|
||||
|
||||
|
@ -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);
|
||||
}
|
||||
|
||||
|
@ -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();
|
||||
}
|
||||
|
||||
/*!
|
||||
|
@ -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);
|
||||
}
|
||||
|
||||
|
@ -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);
|
||||
}
|
||||
|
||||
|
@ -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);
|
||||
}
|
||||
|
||||
|
@ -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);
|
||||
}
|
||||
|
||||
|
@ -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);
|
||||
}
|
||||
|
||||
|
@ -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();
|
||||
}
|
||||
|
||||
|
||||
|
@ -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());
|
||||
}
|
||||
|
||||
/*!
|
||||
|
@ -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);
|
||||
}
|
||||
|
||||
|
@ -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
|
||||
|
@ -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);
|
||||
}
|
||||
|
||||
|
@ -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();
|
||||
}
|
||||
|
||||
/*!
|
||||
|
@ -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();
|
||||
}
|
||||
|
||||
/*!
|
||||
|
@ -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();
|
||||
}
|
||||
|
||||
|
||||
|
@ -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);
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user