examples: Mark ctor's as explicit
authorSergio Ahumada <sergio.ahumada@nokia.com>
Sat, 15 Sep 2012 11:46:14 +0000 (13:46 +0200)
committerQt by Nokia <qt-info@nokia.com>
Mon, 17 Sep 2012 20:14:25 +0000 (22:14 +0200)
Make C++ class constructors that can be used with only one
required argument 'explicit' to minimize wrong use of the class.

Change-Id: Ida9f9c2f0c8608c35b0137b2512a6747afd69515
Reviewed-by: Mitch Curtis <mitch.curtis@nokia.com>
Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
41 files changed:
examples/network/torrent/peerwireclient.h
examples/network/torrent/trackerclient.h
examples/opengl/hellowindow/hellowindow.h
examples/opengl/pbuffers/cube.h
examples/opengl/shared/qtlogo.h
examples/opengl/textures/glwidget.h
examples/sql/cachedtable/tableeditor.h
examples/sql/sqlbrowser/browser.h
examples/tools/treemodelcompleter/treemodelcompleter.h
examples/tools/undo/document.h
examples/tools/undoframework/commands.h
examples/tools/undoframework/diagramitem.h
examples/widgets/animation/stickman/node.h
examples/widgets/animation/sub-attaq/boat_p.h
examples/widgets/animation/sub-attaq/states.h
examples/widgets/animation/sub-attaq/submarine_p.h
examples/widgets/dialogs/tabdialog/tabdialog.h
examples/widgets/draganddrop/puzzle/pieceslist.h
examples/widgets/draganddrop/puzzle/puzzlewidget.h
examples/widgets/graphicsview/boxes/glbuffers.h
examples/widgets/graphicsview/boxes/roundedbox.h
examples/widgets/graphicsview/chip/view.h
examples/widgets/graphicsview/diagramscene/diagramscene.h
examples/widgets/graphicsview/embeddeddialogs/customproxy.h
examples/widgets/graphicsview/padnavigator/flippablepad.h
examples/widgets/itemviews/editabletreemodel/treeitem.h
examples/widgets/itemviews/puzzle/piecesmodel.h
examples/widgets/itemviews/puzzle/puzzlewidget.h
examples/widgets/itemviews/simpledommodel/dommodel.h
examples/widgets/itemviews/simpletreemodel/treeitem.h
examples/widgets/itemviews/simpletreemodel/treemodel.h
examples/widgets/itemviews/stardelegate/starrating.h
examples/widgets/layouts/borderlayout/borderlayout.h
examples/widgets/layouts/flowlayout/flowlayout.h
examples/widgets/mainwindows/mainwindow/colorswatch.h
examples/widgets/painting/deform/pathdeform.h
examples/widgets/painting/painterpaths/renderarea.h
examples/widgets/painting/pathstroke/pathstroke.h
examples/widgets/widgets/calculator/button.h
examples/widgets/widgets/elidedlabel/elidedlabel.h
examples/widgets/widgets/wiggly/dialog.h

index 2a6e965..f8a598a 100644 (file)
@@ -82,7 +82,7 @@ public:
     };
     Q_DECLARE_FLAGS(PeerWireState, PeerWireStateFlag)
 
-    PeerWireClient(const QByteArray &peerId, QObject *parent = 0);
+    explicit PeerWireClient(const QByteArray &peerId, QObject *parent = 0);
     void initialize(const QByteArray &infoHash, int pieceCount);
 
     void setPeer(TorrentPeer *peer);
index 0bd4e17..494428b 100644 (file)
@@ -59,7 +59,7 @@ class TrackerClient : public QObject
     Q_OBJECT
 
 public:
-    TrackerClient(TorrentClient *downloader, QObject *parent = 0);
+    explicit TrackerClient(TorrentClient *downloader, QObject *parent = 0);
 
     void start(const MetaInfo &info);
     void stop();
index 0a88a0d..ea59b3f 100644 (file)
@@ -55,7 +55,7 @@ class Renderer : public QObject
 {
     Q_OBJECT
 public:
-    Renderer(const QSurfaceFormat &format, Renderer *share = 0, QScreen *screen = 0);
+    explicit Renderer(const QSurfaceFormat &format, Renderer *share = 0, QScreen *screen = 0);
 
     QSurfaceFormat format() const { return m_format; }
 
index ad56e43..81e8263 100644 (file)
@@ -95,7 +95,7 @@ class TileBuilder
 {
 public:
     enum { bl, br, tr, tl };
-    TileBuilder(Geometry *, qreal depth = 0.0f, qreal size = 1.0f);
+    explicit TileBuilder(Geometry *, qreal depth = 0.0f, qreal size = 1.0f);
     Tile *newTile(const QVector3D &loc = QVector3D()) const;
     void setColor(QColor c) { color = c; }
 protected:
@@ -140,7 +140,7 @@ private:
 class CubeBuilder : public TileBuilder
 {
 public:
-    CubeBuilder(Geometry *, qreal depth = 0.0f, qreal size = 1.0f);
+    explicit CubeBuilder(Geometry *, qreal depth = 0.0f, qreal size = 1.0f);
     Cube *newCube(const QVector3D &loc = QVector3D()) const;
 private:
     mutable int ix;
index d55fb08..3f60818 100644 (file)
@@ -51,7 +51,7 @@ struct Geometry;
 class QtLogo : public QObject
 {
 public:
-    QtLogo(QObject *parent, int d = 64, qreal s = 1.0);
+    explicit QtLogo(QObject *parent, int d = 64, qreal s = 1.0);
     ~QtLogo();
     void setColor(QColor c);
     void draw() const;
index be120e0..9dccd33 100644 (file)
@@ -51,7 +51,7 @@ class GLWidget : public QGLWidget
     Q_OBJECT
 
 public:
-    GLWidget(QWidget *parent = 0, QGLWidget *shareWidget = 0);
+    explicit GLWidget(QWidget *parent = 0, QGLWidget *shareWidget = 0);
     ~GLWidget();
 
     QSize minimumSizeHint() const;
index b7d728a..c39f4b3 100644 (file)
@@ -55,7 +55,7 @@ class TableEditor : public QWidget
     Q_OBJECT
 
 public:
-    TableEditor(const QString &tableName, QWidget *parent = 0);
+    explicit TableEditor(const QString &tableName, QWidget *parent = 0);
 
 private slots:
     void submit();
index e9f4534..be15ba0 100644 (file)
@@ -107,7 +107,7 @@ class CustomModel: public QSqlTableModel
 {
     Q_OBJECT
 public:
-    CustomModel(QObject *parent = 0, QSqlDatabase db = QSqlDatabase()):QSqlTableModel(parent, db) {}
+    explicit CustomModel(QObject *parent = 0, QSqlDatabase db = QSqlDatabase()):QSqlTableModel(parent, db) {}
     QVariant data(const QModelIndex &idx, int role) const
     {
         if (role == Qt::BackgroundRole && isDirty(idx))
index 953be62..a7234a4 100644 (file)
@@ -50,8 +50,8 @@ class TreeModelCompleter : public QCompleter
     Q_PROPERTY(QString separator READ separator WRITE setSeparator)
 
 public:
-    TreeModelCompleter(QObject *parent = 0);
-    TreeModelCompleter(QAbstractItemModel *model, QObject *parent = 0);
+    explicit TreeModelCompleter(QObject *parent = 0);
+    explicit TreeModelCompleter(QAbstractItemModel *model, QObject *parent = 0);
 
     QString separator() const;
 public slots:
index 713094c..4ffbe47 100644 (file)
@@ -52,7 +52,7 @@ class Shape
 public:
     enum Type { Rectangle, Circle, Triangle };
 
-    Shape(Type type = Rectangle, const QColor &color = Qt::red, const QRect &rect = QRect());
+    explicit Shape(Type type = Rectangle, const QColor &color = Qt::red, const QRect &rect = QRect());
 
     Type type() const;
     QString name() const;
index 70667e9..72f61b1 100644 (file)
@@ -70,7 +70,7 @@ private:
 class DeleteCommand : public QUndoCommand
 {
 public:
-    DeleteCommand(QGraphicsScene *graphicsScene, QUndoCommand *parent = 0);
+    explicit DeleteCommand(QGraphicsScene *graphicsScene, QUndoCommand *parent = 0);
 
     void undo();
     void redo();
index 849ef21..91ed55b 100644 (file)
@@ -56,7 +56,7 @@ public:
     enum { Type = UserType + 1 };
     enum DiagramType { Box, Triangle };
 
-    DiagramItem(DiagramType diagramType, QGraphicsItem *item = 0);
+    explicit DiagramItem(DiagramType diagramType, QGraphicsItem *item = 0);
 
     DiagramType diagramType() const {
         return polygon() == boxPolygon ? Box : Triangle;
index ae6e2a3..ca04d78 100644 (file)
@@ -47,7 +47,7 @@ class Node: public QGraphicsObject
 {
     Q_OBJECT
 public:
-    Node(const QPointF &pos, QGraphicsItem *parent = 0);
+    explicit Node(const QPointF &pos, QGraphicsItem *parent = 0);
     ~Node();
 
     QRectF boundingRect() const;
index 38be985..03f7df2 100644 (file)
@@ -139,7 +139,7 @@ private:
 class MoveStateRight : public QState
 {
 public:
-    MoveStateRight(Boat *boat,QState *parent = 0) : QState(parent), boat(boat)
+    explicit MoveStateRight(Boat *boat,QState *parent = 0) : QState(parent), boat(boat)
     {
     }
 protected:
@@ -156,7 +156,7 @@ private:
 class MoveStateLeft : public QState
 {
 public:
-    MoveStateLeft(Boat *boat,QState *parent = 0) : QState(parent), boat(boat)
+    explicit MoveStateLeft(Boat *boat,QState *parent = 0) : QState(parent), boat(boat)
     {
     }
 protected:
@@ -173,7 +173,7 @@ private:
 class StopState : public QState
 {
 public:
-    StopState(Boat *boat,QState *parent = 0) : QState(parent), boat(boat)
+    explicit StopState(Boat *boat,QState *parent = 0) : QState(parent), boat(boat)
     {
     }
 protected:
@@ -191,7 +191,7 @@ private:
 class LaunchStateRight : public QState
 {
 public:
-    LaunchStateRight(Boat *boat,QState *parent = 0) : QState(parent), boat(boat)
+    explicit LaunchStateRight(Boat *boat,QState *parent = 0) : QState(parent), boat(boat)
     {
     }
 protected:
@@ -212,7 +212,7 @@ private:
 class LaunchStateLeft : public QState
 {
 public:
-    LaunchStateLeft(Boat *boat,QState *parent = 0) : QState(parent), boat(boat)
+    explicit LaunchStateLeft(Boat *boat,QState *parent = 0) : QState(parent), boat(boat)
     {
     }
 protected:
index e433703..98799dd 100644 (file)
@@ -59,7 +59,7 @@ QT_END_NAMESPACE
 class PlayState : public QState
 {
 public:
-    PlayState(GraphicsScene *scene, QState *parent = 0);
+    explicit PlayState(GraphicsScene *scene, QState *parent = 0);
     ~PlayState();
 
  protected:
@@ -96,7 +96,7 @@ private :
 class PauseState : public QState
 {
 public:
-    PauseState(GraphicsScene *scene, QState *parent = 0);
+    explicit PauseState(GraphicsScene *scene, QState *parent = 0);
 
 protected:
     void onEntry(QEvent *);
index f24487a..c9b9829 100644 (file)
@@ -67,7 +67,7 @@ class MovementState : public QAnimationState
 {
 Q_OBJECT
 public:
-    MovementState(SubMarine *submarine, QState *parent = 0) : QAnimationState(parent)
+    explicit MovementState(SubMarine *submarine, QState *parent = 0) : QAnimationState(parent)
     {
         movementAnimation = new QPropertyAnimation(submarine, "pos");
         connect(movementAnimation,SIGNAL(valueChanged(const QVariant &)),this,SLOT(onAnimationMovementValueChanged(const QVariant &)));
@@ -106,7 +106,7 @@ private:
 class ReturnState : public QAnimationState
 {
 public:
-    ReturnState(SubMarine *submarine, QState *parent = 0) : QAnimationState(parent)
+    explicit ReturnState(SubMarine *submarine, QState *parent = 0) : QAnimationState(parent)
     {
         returnAnimation = new QPropertyAnimation(submarine->rotation(), "angle");
         returnAnimation->setDuration(500);
index c2b46f0..c0d74c1 100644 (file)
@@ -55,7 +55,7 @@ class GeneralTab : public QWidget
     Q_OBJECT
 
 public:
-    GeneralTab(const QFileInfo &fileInfo, QWidget *parent = 0);
+    explicit GeneralTab(const QFileInfo &fileInfo, QWidget *parent = 0);
 };
 //! [0]
 
@@ -66,7 +66,7 @@ class PermissionsTab : public QWidget
     Q_OBJECT
 
 public:
-    PermissionsTab(const QFileInfo &fileInfo, QWidget *parent = 0);
+    explicit PermissionsTab(const QFileInfo &fileInfo, QWidget *parent = 0);
 };
 //! [1]
 
@@ -77,7 +77,7 @@ class ApplicationsTab : public QWidget
     Q_OBJECT
 
 public:
-    ApplicationsTab(const QFileInfo &fileInfo, QWidget *parent = 0);
+    explicit ApplicationsTab(const QFileInfo &fileInfo, QWidget *parent = 0);
 };
 //! [2]
 
@@ -88,7 +88,7 @@ class TabDialog : public QDialog
     Q_OBJECT
 
 public:
-    TabDialog(const QString &fileName, QWidget *parent = 0);
+    explicit TabDialog(const QString &fileName, QWidget *parent = 0);
 
 private:
     QTabWidget *tabWidget;
index 3c6b042..16091f5 100644 (file)
@@ -48,7 +48,7 @@ class PiecesList : public QListWidget
     Q_OBJECT
 
 public:
-    PiecesList(int pieceSize, QWidget *parent = 0);
+    explicit PiecesList(int pieceSize, QWidget *parent = 0);
     void addPiece(QPixmap pixmap, QPoint location);
 
 protected:
index 1c0fc77..98056ec 100644 (file)
@@ -57,7 +57,7 @@ class PuzzleWidget : public QWidget
     Q_OBJECT
 
 public:
-    PuzzleWidget(int imageSize, QWidget *parent = 0);
+    explicit PuzzleWidget(int imageSize, QWidget *parent = 0);
     void clear();
 
     int pieceSize() const;
index 2b91915..b3b1777 100644 (file)
@@ -99,7 +99,7 @@ class GLTexture2D : public GLTexture
 {
 public:
     GLTexture2D(int width, int height);
-    GLTexture2D(const QString& fileName, int width = 0, int height = 0);
+    explicit GLTexture2D(const QString& fileName, int width = 0, int height = 0);
     void load(int width, int height, QRgb *data);
     virtual void bind();
     virtual void unbind();
@@ -120,7 +120,7 @@ class GLTextureCube : public GLTexture
 {
 public:
     GLTextureCube(int size);
-    GLTextureCube(const QStringList& fileNames, int size = 0);
+    explicit GLTextureCube(const QStringList& fileNames, int size = 0);
     void load(int size, int face, QRgb *data);
     virtual void bind();
     virtual void unbind();
index 3edfb69..0ab6766 100644 (file)
@@ -65,7 +65,7 @@ class GLRoundedBox : public GLTriangleMesh<P3T2N3Vertex, unsigned short>
 {
 public:
     // 0 < r < 0.5, 0 <= n <= 125
-    GLRoundedBox(float r = 0.25f, float scale = 1.0f, int n = 10);
+    explicit GLRoundedBox(float r = 0.25f, float scale = 1.0f, int n = 10);
 };
 
 
index 7753eff..c688506 100644 (file)
@@ -68,7 +68,7 @@ class View : public QFrame
 {
     Q_OBJECT
 public:
-    View(const QString &name, QWidget *parent = 0);
+    explicit View(const QString &name, QWidget *parent = 0);
 
     QGraphicsView *view() const;
 
index 9f65eba..53a34b0 100644 (file)
@@ -63,7 +63,7 @@ class DiagramScene : public QGraphicsScene
 public:
     enum Mode { InsertItem, InsertLine, InsertText, MoveItem };
 
-    DiagramScene(QMenu *itemMenu, QObject *parent = 0);
+    explicit DiagramScene(QMenu *itemMenu, QObject *parent = 0);
     QFont font() const
         { return myFont; }
     QColor textColor() const
index c85bbac..12de414 100644 (file)
@@ -49,7 +49,7 @@ class CustomProxy : public QGraphicsProxyWidget
 {
     Q_OBJECT
 public:
-    CustomProxy(QGraphicsItem *parent = 0, Qt::WindowFlags wFlags = 0);
+    explicit CustomProxy(QGraphicsItem *parent = 0, Qt::WindowFlags wFlags = 0);
 
     QRectF boundingRect() const;
     void paintWindowFrame(QPainter *painter, const QStyleOptionGraphicsItem *option,
index e0d1fe2..ce49ef1 100644 (file)
@@ -51,7 +51,7 @@
 class FlippablePad : public RoundRectItem
 {
 public:
-    FlippablePad(const QSize &size, QGraphicsItem *parent = 0);
+    explicit FlippablePad(const QSize &size, QGraphicsItem *parent = 0);
 
     RoundRectItem *iconAt(int column, int row) const;
 
index 8426514..a0f8ed0 100644 (file)
@@ -49,7 +49,7 @@
 class TreeItem
 {
 public:
-    TreeItem(const QVector<QVariant> &data, TreeItem *parent = 0);
+    explicit TreeItem(const QVector<QVariant> &data, TreeItem *parent = 0);
     ~TreeItem();
 
     TreeItem *child(int number);
index e8fa45a..f306c51 100644 (file)
@@ -56,7 +56,7 @@ class PiecesModel : public QAbstractListModel
     Q_OBJECT
 
 public:
-    PiecesModel(int pieceSize, QObject *parent = 0);
+    explicit PiecesModel(int pieceSize, QObject *parent = 0);
 
     QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const;
     Qt::ItemFlags flags(const QModelIndex &index) const;
index 1c0fc77..98056ec 100644 (file)
@@ -57,7 +57,7 @@ class PuzzleWidget : public QWidget
     Q_OBJECT
 
 public:
-    PuzzleWidget(int imageSize, QWidget *parent = 0);
+    explicit PuzzleWidget(int imageSize, QWidget *parent = 0);
     void clear();
 
     int pieceSize() const;
index 386f976..bef3ba7 100644 (file)
@@ -54,7 +54,7 @@ class DomModel : public QAbstractItemModel
     Q_OBJECT
 
 public:
-    DomModel(QDomDocument document, QObject *parent = 0);
+    explicit DomModel(QDomDocument document, QObject *parent = 0);
     ~DomModel();
 
     QVariant data(const QModelIndex &index, int role) const;
index b2a7a83..03da562 100644 (file)
@@ -48,7 +48,7 @@
 class TreeItem
 {
 public:
-    TreeItem(const QList<QVariant> &data, TreeItem *parent = 0);
+    explicit TreeItem(const QList<QVariant> &data, TreeItem *parent = 0);
     ~TreeItem();
 
     void appendChild(TreeItem *child);
index 9cf870c..edddf48 100644 (file)
@@ -53,7 +53,7 @@ class TreeModel : public QAbstractItemModel
     Q_OBJECT
 
 public:
-    TreeModel(const QString &data, QObject *parent = 0);
+    explicit TreeModel(const QString &data, QObject *parent = 0);
     ~TreeModel();
 
     QVariant data(const QModelIndex &index, int role) const;
index 04fae25..54de319 100644 (file)
@@ -51,7 +51,7 @@ class StarRating
 public:
     enum EditMode { Editable, ReadOnly };
 
-    StarRating(int starCount = 1, int maxStarCount = 5);
+    explicit StarRating(int starCount = 1, int maxStarCount = 5);
 
     void paint(QPainter *painter, const QRect &rect,
                const QPalette &palette, EditMode mode) const;
index 937517d..91f927b 100644 (file)
@@ -50,7 +50,7 @@ class BorderLayout : public QLayout
 public:
     enum Position { West, North, South, East, Center };
 
-    BorderLayout(QWidget *parent, int margin = 0, int spacing = -1);
+    explicit BorderLayout(QWidget *parent, int margin = 0, int spacing = -1);
     BorderLayout(int spacing = -1);
     ~BorderLayout();
 
index 2a27f93..2b98f00 100644 (file)
@@ -48,8 +48,8 @@
 class FlowLayout : public QLayout
 {
 public:
-    FlowLayout(QWidget *parent, int margin = -1, int hSpacing = -1, int vSpacing = -1);
-    FlowLayout(int margin = -1, int hSpacing = -1, int vSpacing = -1);
+    explicit FlowLayout(QWidget *parent, int margin = -1, int hSpacing = -1, int vSpacing = -1);
+    explicit FlowLayout(int margin = -1, int hSpacing = -1, int vSpacing = -1);
     ~FlowLayout();
 
     void addItem(QLayoutItem *item);
index 794a69c..95facc5 100644 (file)
@@ -79,7 +79,7 @@ class ColorSwatch : public QDockWidget
     QAction *windowModifiedAction;
 
 public:
-    ColorSwatch(const QString &colorName, QWidget *parent = 0, Qt::WindowFlags flags = 0);
+    explicit ColorSwatch(const QString &colorName, QWidget *parent = 0, Qt::WindowFlags flags = 0);
 
     QMenu *menu;
     void setCustomSizeHint(const QSize &size);
index 6f0d647..07f615d 100644 (file)
@@ -58,7 +58,7 @@ class PathDeformRenderer : public ArthurFrame
     Q_PROPERTY(QString text READ text WRITE setText)
 
 public:
-    PathDeformRenderer(QWidget *widget, bool smallScreen = false);
+    explicit PathDeformRenderer(QWidget *widget, bool smallScreen = false);
 
     void paint(QPainter *painter);
 
index 5c310fd..ec6c4ea 100644 (file)
@@ -50,7 +50,7 @@ class RenderArea : public QWidget
     Q_OBJECT
 
 public:
-    RenderArea(const QPainterPath &path, QWidget *parent = 0);
+    explicit RenderArea(const QPainterPath &path, QWidget *parent = 0);
 
     QSize minimumSizeHint() const;
     QSize sizeHint() const;
index 743a757..5e2a1ea 100644 (file)
@@ -53,7 +53,7 @@ class PathStrokeRenderer : public ArthurFrame
 public:
     enum PathMode { CurveMode, LineMode };
 
-    PathStrokeRenderer(QWidget *parent, bool smallScreen = false);
+    explicit PathStrokeRenderer(QWidget *parent, bool smallScreen = false);
 
     void paint(QPainter *);
     void mousePressEvent(QMouseEvent *e);
index 50874ea..d84d7e9 100644 (file)
@@ -49,7 +49,7 @@ class Button : public QToolButton
     Q_OBJECT
 
 public:
-    Button(const QString &text, QWidget *parent = 0);
+    explicit Button(const QString &text, QWidget *parent = 0);
 
     QSize sizeHint() const;
 };
index 2c19589..118c8c2 100644 (file)
@@ -55,7 +55,7 @@ class ElidedLabel : public QFrame
     Q_PROPERTY(bool isElided READ isElided)
 
 public:
-    ElidedLabel(const QString &text, QWidget *parent = 0);
+    explicit ElidedLabel(const QString &text, QWidget *parent = 0);
 
     void setText(const QString &text);
     const QString & text() const { return content; }
index 84167d9..e6117f8 100644 (file)
@@ -49,7 +49,7 @@ class Dialog : public QDialog
     Q_OBJECT
 
 public:
-    Dialog(QWidget *parent = 0, bool smallScreen = false);
+    explicit Dialog(QWidget *parent = 0, bool smallScreen = false);
 };
 //! [0]