examples: Mark ctor's as explicit

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>
This commit is contained in:
Sergio Ahumada 2012-09-15 13:46:14 +02:00 committed by Qt by Nokia
parent 89b12da2ef
commit 58e2b9c01b
41 changed files with 54 additions and 54 deletions

View 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);

View 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();

View 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; }

View 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;

View 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;

View 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;

View 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();

View 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))

View 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:

View 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;

View 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();

View 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;

View 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;

View 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:

View 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 *);

View 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);

View 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;

View 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:

View 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;

View 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();

View 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);
};

View 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;

View 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

View 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,

View 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;

View 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);

View 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;

View 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;

View 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;

View 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);

View 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;

View 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;

View 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();

View 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);

View 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);

View 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);

View 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;

View 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);

View 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;
};

View 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; }

View 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]