Qt Designer Examples: Fix code around constructors.
authorFriedemann Kleint <Friedemann.Kleint@theqtcompany.com>
Fri, 10 Apr 2015 09:42:18 +0000 (11:42 +0200)
committerFriedemann Kleint <Friedemann.Kleint@theqtcompany.com>
Fri, 10 Apr 2015 10:34:06 +0000 (10:34 +0000)
Make constructors explicit, use constructor initialization for member
variables, remove unused variables.

Change-Id: I84273400d66ef061376bd0ec4948ab1a0fd45f30
Reviewed-by: Jarek Kobus <jaroslaw.kobus@theqtcompany.com>
20 files changed:
examples/designer/containerextension/multipagewidget.cpp
examples/designer/containerextension/multipagewidget.h
examples/designer/containerextension/multipagewidgetcontainerextension.cpp
examples/designer/containerextension/multipagewidgetcontainerextension.h
examples/designer/containerextension/multipagewidgetextensionfactory.h
examples/designer/containerextension/multipagewidgetplugin.cpp
examples/designer/containerextension/multipagewidgetplugin.h
examples/designer/customwidgetplugin/analogclock.h
examples/designer/customwidgetplugin/customwidgetplugin.cpp
examples/designer/customwidgetplugin/customwidgetplugin.h
examples/designer/taskmenuextension/tictactoe.cpp
examples/designer/taskmenuextension/tictactoe.h
examples/designer/taskmenuextension/tictactoedialog.cpp
examples/designer/taskmenuextension/tictactoeplugin.cpp
examples/designer/taskmenuextension/tictactoetaskmenu.cpp
examples/designer/taskmenuextension/tictactoetaskmenu.h
examples/designer/worldtimeclockplugin/worldtimeclock.cpp
examples/designer/worldtimeclockplugin/worldtimeclock.h
examples/designer/worldtimeclockplugin/worldtimeclockplugin.cpp
examples/designer/worldtimeclockplugin/worldtimeclockplugin.h

index 767397a..4d9e647 100644 (file)
 
 MultiPageWidget::MultiPageWidget(QWidget *parent)
     : QWidget(parent)
+    , stackWidget(new QStackedWidget)
+    , comboBox(new QComboBox)
 {
     typedef void (QComboBox::*ComboBoxActivatedIntSignal)(int);
 
-    comboBox = new QComboBox();
     comboBox->setObjectName("__qt__passive_comboBox");
-    stackWidget = new QStackedWidget();
 
     connect(comboBox, static_cast<ComboBoxActivatedIntSignal>(&QComboBox::activated),
             this, &MultiPageWidget::setCurrentIndex);
 
-    layout = new QVBoxLayout();
+    QVBoxLayout *layout = new QVBoxLayout(this);
     layout->addWidget(comboBox);
     layout->addWidget(stackWidget);
-    setLayout(layout);
 }
 
 QSize MultiPageWidget::sizeHint() const
index 8501115..4b726d7 100644 (file)
@@ -46,7 +46,6 @@
 QT_BEGIN_NAMESPACE
 class QComboBox;
 class QStackedWidget;
-class QVBoxLayout;
 QT_END_NAMESPACE
 
 //! [0]
@@ -57,7 +56,7 @@ class MultiPageWidget : public QWidget
     Q_PROPERTY(QString pageTitle READ pageTitle WRITE setPageTitle STORED false)
 
 public:
-    MultiPageWidget(QWidget *parent = 0);
+    explicit MultiPageWidget(QWidget *parent = 0);
 
     QSize sizeHint() const Q_DECL_OVERRIDE;
 
@@ -83,7 +82,6 @@ signals:
 private:
     QStackedWidget *stackWidget;
     QComboBox *comboBox;
-    QVBoxLayout *layout;
 };
 //! [0]
 
index 29efd45..b06b018 100644 (file)
@@ -44,9 +44,9 @@
 //! [0]
 MultiPageWidgetContainerExtension::MultiPageWidgetContainerExtension(MultiPageWidget *widget,
                                                                      QObject *parent)
-    :QObject(parent)
+    : QObject(parent)
+    , myWidget(widget)
 {
-    myWidget = widget;
 }
 //! [0]
 
index 1dcc88c..f7cd8f1 100644 (file)
@@ -56,7 +56,7 @@ class MultiPageWidgetContainerExtension: public QObject,
     Q_INTERFACES(QDesignerContainerExtension)
 
 public:
-    MultiPageWidgetContainerExtension(MultiPageWidget *widget, QObject *parent);
+    explicit MultiPageWidgetContainerExtension(MultiPageWidget *widget, QObject *parent);
 
     void addWidget(QWidget *widget) Q_DECL_OVERRIDE;
     int count() const Q_DECL_OVERRIDE;
index 2ece4e1..ace3bcd 100644 (file)
@@ -53,7 +53,7 @@ class MultiPageWidgetExtensionFactory: public QExtensionFactory
     Q_OBJECT
 
 public:
-    MultiPageWidgetExtensionFactory(QExtensionManager *parent = 0);
+    explicit MultiPageWidgetExtensionFactory(QExtensionManager *parent = 0);
 
 protected:
     QObject *createExtension(QObject *object, const QString &iid, QObject *parent) const Q_DECL_OVERRIDE;
index 950f2ed..4e858a6 100644 (file)
@@ -54,9 +54,9 @@
 
 //! [0]
 MultiPageWidgetPlugin::MultiPageWidgetPlugin(QObject *parent)
-    :QObject(parent)
+    : QObject(parent)
+    , initialized(false)
 {
-    initialized = false;
 }
 
 QString MultiPageWidgetPlugin::name() const
index 2099819..34a1836 100644 (file)
@@ -57,7 +57,7 @@ class MultiPageWidgetPlugin: public QObject, public QDesignerCustomWidgetInterfa
 //! [1]
     Q_INTERFACES(QDesignerCustomWidgetInterface)
 public:
-    MultiPageWidgetPlugin(QObject *parent = 0);
+    explicit MultiPageWidgetPlugin(QObject *parent = 0);
 
     QString name() const Q_DECL_OVERRIDE;
     QString group() const Q_DECL_OVERRIDE;
index fd4056c..1ea6d9e 100644 (file)
@@ -49,7 +49,7 @@ class QDESIGNER_WIDGET_EXPORT AnalogClock : public QWidget
     Q_OBJECT
 
 public:
-    AnalogClock(QWidget *parent = 0);
+    explicit AnalogClock(QWidget *parent = 0);
 
 protected:
     void paintEvent(QPaintEvent *event) Q_DECL_OVERRIDE;
index eeb0a84..67b9c28 100644 (file)
@@ -46,8 +46,8 @@
 //! [0]
 AnalogClockPlugin::AnalogClockPlugin(QObject *parent)
     : QObject(parent)
+    , initialized(false)
 {
-    initialized = false;
 }
 //! [0]
 
index d1a09ed..a503747 100644 (file)
@@ -50,7 +50,7 @@ class AnalogClockPlugin : public QObject, public QDesignerCustomWidgetInterface
     Q_PLUGIN_METADATA(IID "org.qt-project.Qt.QDesignerCustomWidgetInterface" FILE "analogclock.json")
     Q_INTERFACES(QDesignerCustomWidgetInterface)
 public:
-    AnalogClockPlugin(QObject *parent = 0);
+    explicit AnalogClockPlugin(QObject *parent = 0);
 
     bool isContainer() const Q_DECL_OVERRIDE;
     bool isInitialized() const Q_DECL_OVERRIDE;
index b79beee..c46acb0 100644 (file)
@@ -45,6 +45,7 @@
 
 TicTacToe::TicTacToe(QWidget *parent)
     : QWidget(parent)
+    , turnNumber(0)
 {
 }
 
index 14a6b6a..d31e8e4 100644 (file)
@@ -55,7 +55,7 @@ class TicTacToe : public QWidget
     Q_PROPERTY(QString state READ state WRITE setState)
 
 public:
-    TicTacToe(QWidget *parent = 0);
+    explicit TicTacToe(QWidget *parent = 0);
 
     QSize minimumSizeHint() const Q_DECL_OVERRIDE;
     QSize sizeHint() const Q_DECL_OVERRIDE;
index e6d1d41..6c6e2f3 100644 (file)
 //! [0]
 TicTacToeDialog::TicTacToeDialog(TicTacToe *tic, QWidget *parent)
     : QDialog(parent)
+    , editor(new TicTacToe)
+    , ticTacToe(tic)
+    , buttonBox(new QDialogButtonBox(QDialogButtonBox::Ok
+                                     | QDialogButtonBox::Cancel
+                                     | QDialogButtonBox::Reset))
 {
-    ticTacToe = tic;
-    editor = new TicTacToe;
     editor->setState(ticTacToe->state());
 
-    buttonBox = new QDialogButtonBox(QDialogButtonBox::Ok
-                                     | QDialogButtonBox::Cancel
-                                     | QDialogButtonBox::Reset);
-
     connect(buttonBox->button(QDialogButtonBox::Reset), &QAbstractButton::clicked,
             this, &TicTacToeDialog::resetState);
     connect(buttonBox, &QDialogButtonBox::accepted, this, &TicTacToeDialog::saveState);
index 2c953f6..770a44a 100644 (file)
@@ -49,8 +49,8 @@
 //! [0]
 TicTacToePlugin::TicTacToePlugin(QObject *parent)
     : QObject(parent)
+    , initialized(false)
 {
-    initialized = false;
 }
 
 QString TicTacToePlugin::name() const
index 961d5a1..e71d96c 100644 (file)
 //! [0]
 TicTacToeTaskMenu::TicTacToeTaskMenu(TicTacToe *tic, QObject *parent)
     : QObject(parent)
+    , editStateAction(new QAction(tr("Edit State..."), this))
+    , ticTacToe(tic)
 {
-    ticTacToe = tic;
-
-    editStateAction = new QAction(tr("Edit State..."), this);
     connect(editStateAction, &QAction::triggered, this, &TicTacToeTaskMenu::editState);
 }
 //! [0]
index 0f41cf8..3757789 100644 (file)
@@ -57,7 +57,7 @@ class TicTacToeTaskMenu : public QObject, public QDesignerTaskMenuExtension
     Q_INTERFACES(QDesignerTaskMenuExtension)
 
 public:
-    TicTacToeTaskMenu(TicTacToe *tic, QObject *parent);
+    explicit TicTacToeTaskMenu(TicTacToe *tic, QObject *parent);
 
     QAction *preferredEditAction() const Q_DECL_OVERRIDE;
     QList<QAction *> taskActions() const Q_DECL_OVERRIDE;
@@ -77,7 +77,7 @@ class TicTacToeTaskMenuFactory : public QExtensionFactory
     Q_OBJECT
 
 public:
-    TicTacToeTaskMenuFactory(QExtensionManager *parent = 0);
+    explicit TicTacToeTaskMenuFactory(QExtensionManager *parent = 0);
 
 protected:
     QObject *createExtension(QObject *object, const QString &iid, QObject *parent) const Q_DECL_OVERRIDE;
index 1a4d8fc..776eec7 100644 (file)
 
 WorldTimeClock::WorldTimeClock(QWidget *parent)
     : QWidget(parent)
+    , timeZoneOffset(0)
+
 {
     typedef void (QWidget::*WidgetUpdateSlot)();
 
-    timeZoneOffset = 0;
-
     QTimer *timer = new QTimer(this);
     connect(timer, &QTimer::timeout, this, static_cast<WidgetUpdateSlot>(&QWidget::update));
     timer->start(1000);
index 497c51b..e0220a8 100644 (file)
@@ -52,7 +52,7 @@ class QDESIGNER_WIDGET_EXPORT WorldTimeClock : public QWidget
 //! [0]
 
 public:
-    WorldTimeClock(QWidget *parent = 0);
+    explicit WorldTimeClock(QWidget *parent = 0);
 
 public slots:
     void setTimeZone(int hourOffset);
index 6c879fd..416c828 100644 (file)
@@ -45,8 +45,8 @@
 
 WorldTimeClockPlugin::WorldTimeClockPlugin(QObject *parent)
     : QObject(parent)
+    , initialized(false)
 {
-    initialized = false;
 }
 
 void WorldTimeClockPlugin::initialize(QDesignerFormEditorInterface * /* core */)
index a4bb242..7ed81ba 100644 (file)
@@ -54,7 +54,7 @@ class WorldTimeClockPlugin : public QObject,
     Q_INTERFACES(QDesignerCustomWidgetInterface)
 
 public:
-    WorldTimeClockPlugin(QObject *parent = 0);
+    explicit WorldTimeClockPlugin(QObject *parent = 0);
 
     bool isContainer() const Q_DECL_OVERRIDE;
     bool isInitialized() const Q_DECL_OVERRIDE;