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) 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 initialize(const QByteArray &infoHash, int pieceCount);
void setPeer(TorrentPeer *peer); void setPeer(TorrentPeer *peer);

View File

@ -59,7 +59,7 @@ class TrackerClient : public QObject
Q_OBJECT Q_OBJECT
public: public:
TrackerClient(TorrentClient *downloader, QObject *parent = 0); explicit TrackerClient(TorrentClient *downloader, QObject *parent = 0);
void start(const MetaInfo &info); void start(const MetaInfo &info);
void stop(); void stop();

View File

@ -55,7 +55,7 @@ class Renderer : public QObject
{ {
Q_OBJECT Q_OBJECT
public: 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; } QSurfaceFormat format() const { return m_format; }

View File

@ -95,7 +95,7 @@ class TileBuilder
{ {
public: public:
enum { bl, br, tr, tl }; 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; Tile *newTile(const QVector3D &loc = QVector3D()) const;
void setColor(QColor c) { color = c; } void setColor(QColor c) { color = c; }
protected: protected:
@ -140,7 +140,7 @@ private:
class CubeBuilder : public TileBuilder class CubeBuilder : public TileBuilder
{ {
public: 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; Cube *newCube(const QVector3D &loc = QVector3D()) const;
private: private:
mutable int ix; mutable int ix;

View File

@ -51,7 +51,7 @@ struct Geometry;
class QtLogo : public QObject class QtLogo : public QObject
{ {
public: public:
QtLogo(QObject *parent, int d = 64, qreal s = 1.0); explicit QtLogo(QObject *parent, int d = 64, qreal s = 1.0);
~QtLogo(); ~QtLogo();
void setColor(QColor c); void setColor(QColor c);
void draw() const; void draw() const;

View File

@ -51,7 +51,7 @@ class GLWidget : public QGLWidget
Q_OBJECT Q_OBJECT
public: public:
GLWidget(QWidget *parent = 0, QGLWidget *shareWidget = 0); explicit GLWidget(QWidget *parent = 0, QGLWidget *shareWidget = 0);
~GLWidget(); ~GLWidget();
QSize minimumSizeHint() const; QSize minimumSizeHint() const;

View File

@ -55,7 +55,7 @@ class TableEditor : public QWidget
Q_OBJECT Q_OBJECT
public: public:
TableEditor(const QString &tableName, QWidget *parent = 0); explicit TableEditor(const QString &tableName, QWidget *parent = 0);
private slots: private slots:
void submit(); void submit();

View File

@ -107,7 +107,7 @@ class CustomModel: public QSqlTableModel
{ {
Q_OBJECT Q_OBJECT
public: 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 QVariant data(const QModelIndex &idx, int role) const
{ {
if (role == Qt::BackgroundRole && isDirty(idx)) if (role == Qt::BackgroundRole && isDirty(idx))

View File

@ -50,8 +50,8 @@ class TreeModelCompleter : public QCompleter
Q_PROPERTY(QString separator READ separator WRITE setSeparator) Q_PROPERTY(QString separator READ separator WRITE setSeparator)
public: public:
TreeModelCompleter(QObject *parent = 0); explicit TreeModelCompleter(QObject *parent = 0);
TreeModelCompleter(QAbstractItemModel *model, QObject *parent = 0); explicit TreeModelCompleter(QAbstractItemModel *model, QObject *parent = 0);
QString separator() const; QString separator() const;
public slots: public slots:

View File

@ -52,7 +52,7 @@ class Shape
public: public:
enum Type { Rectangle, Circle, Triangle }; 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; Type type() const;
QString name() const; QString name() const;

View File

@ -70,7 +70,7 @@ private:
class DeleteCommand : public QUndoCommand class DeleteCommand : public QUndoCommand
{ {
public: public:
DeleteCommand(QGraphicsScene *graphicsScene, QUndoCommand *parent = 0); explicit DeleteCommand(QGraphicsScene *graphicsScene, QUndoCommand *parent = 0);
void undo(); void undo();
void redo(); void redo();

View File

@ -56,7 +56,7 @@ public:
enum { Type = UserType + 1 }; enum { Type = UserType + 1 };
enum DiagramType { Box, Triangle }; enum DiagramType { Box, Triangle };
DiagramItem(DiagramType diagramType, QGraphicsItem *item = 0); explicit DiagramItem(DiagramType diagramType, QGraphicsItem *item = 0);
DiagramType diagramType() const { DiagramType diagramType() const {
return polygon() == boxPolygon ? Box : Triangle; return polygon() == boxPolygon ? Box : Triangle;

View File

@ -47,7 +47,7 @@ class Node: public QGraphicsObject
{ {
Q_OBJECT Q_OBJECT
public: public:
Node(const QPointF &pos, QGraphicsItem *parent = 0); explicit Node(const QPointF &pos, QGraphicsItem *parent = 0);
~Node(); ~Node();
QRectF boundingRect() const; QRectF boundingRect() const;

View File

@ -139,7 +139,7 @@ private:
class MoveStateRight : public QState class MoveStateRight : public QState
{ {
public: public:
MoveStateRight(Boat *boat,QState *parent = 0) : QState(parent), boat(boat) explicit MoveStateRight(Boat *boat,QState *parent = 0) : QState(parent), boat(boat)
{ {
} }
protected: protected:
@ -156,7 +156,7 @@ private:
class MoveStateLeft : public QState class MoveStateLeft : public QState
{ {
public: public:
MoveStateLeft(Boat *boat,QState *parent = 0) : QState(parent), boat(boat) explicit MoveStateLeft(Boat *boat,QState *parent = 0) : QState(parent), boat(boat)
{ {
} }
protected: protected:
@ -173,7 +173,7 @@ private:
class StopState : public QState class StopState : public QState
{ {
public: public:
StopState(Boat *boat,QState *parent = 0) : QState(parent), boat(boat) explicit StopState(Boat *boat,QState *parent = 0) : QState(parent), boat(boat)
{ {
} }
protected: protected:
@ -191,7 +191,7 @@ private:
class LaunchStateRight : public QState class LaunchStateRight : public QState
{ {
public: public:
LaunchStateRight(Boat *boat,QState *parent = 0) : QState(parent), boat(boat) explicit LaunchStateRight(Boat *boat,QState *parent = 0) : QState(parent), boat(boat)
{ {
} }
protected: protected:
@ -212,7 +212,7 @@ private:
class LaunchStateLeft : public QState class LaunchStateLeft : public QState
{ {
public: public:
LaunchStateLeft(Boat *boat,QState *parent = 0) : QState(parent), boat(boat) explicit LaunchStateLeft(Boat *boat,QState *parent = 0) : QState(parent), boat(boat)
{ {
} }
protected: protected:

View File

@ -59,7 +59,7 @@ QT_END_NAMESPACE
class PlayState : public QState class PlayState : public QState
{ {
public: public:
PlayState(GraphicsScene *scene, QState *parent = 0); explicit PlayState(GraphicsScene *scene, QState *parent = 0);
~PlayState(); ~PlayState();
protected: protected:
@ -96,7 +96,7 @@ private :
class PauseState : public QState class PauseState : public QState
{ {
public: public:
PauseState(GraphicsScene *scene, QState *parent = 0); explicit PauseState(GraphicsScene *scene, QState *parent = 0);
protected: protected:
void onEntry(QEvent *); void onEntry(QEvent *);

View File

@ -67,7 +67,7 @@ class MovementState : public QAnimationState
{ {
Q_OBJECT Q_OBJECT
public: public:
MovementState(SubMarine *submarine, QState *parent = 0) : QAnimationState(parent) explicit MovementState(SubMarine *submarine, QState *parent = 0) : QAnimationState(parent)
{ {
movementAnimation = new QPropertyAnimation(submarine, "pos"); movementAnimation = new QPropertyAnimation(submarine, "pos");
connect(movementAnimation,SIGNAL(valueChanged(const QVariant &)),this,SLOT(onAnimationMovementValueChanged(const QVariant &))); connect(movementAnimation,SIGNAL(valueChanged(const QVariant &)),this,SLOT(onAnimationMovementValueChanged(const QVariant &)));
@ -106,7 +106,7 @@ private:
class ReturnState : public QAnimationState class ReturnState : public QAnimationState
{ {
public: 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 = new QPropertyAnimation(submarine->rotation(), "angle");
returnAnimation->setDuration(500); returnAnimation->setDuration(500);

View File

@ -55,7 +55,7 @@ class GeneralTab : public QWidget
Q_OBJECT Q_OBJECT
public: public:
GeneralTab(const QFileInfo &fileInfo, QWidget *parent = 0); explicit GeneralTab(const QFileInfo &fileInfo, QWidget *parent = 0);
}; };
//! [0] //! [0]
@ -66,7 +66,7 @@ class PermissionsTab : public QWidget
Q_OBJECT Q_OBJECT
public: public:
PermissionsTab(const QFileInfo &fileInfo, QWidget *parent = 0); explicit PermissionsTab(const QFileInfo &fileInfo, QWidget *parent = 0);
}; };
//! [1] //! [1]
@ -77,7 +77,7 @@ class ApplicationsTab : public QWidget
Q_OBJECT Q_OBJECT
public: public:
ApplicationsTab(const QFileInfo &fileInfo, QWidget *parent = 0); explicit ApplicationsTab(const QFileInfo &fileInfo, QWidget *parent = 0);
}; };
//! [2] //! [2]
@ -88,7 +88,7 @@ class TabDialog : public QDialog
Q_OBJECT Q_OBJECT
public: public:
TabDialog(const QString &fileName, QWidget *parent = 0); explicit TabDialog(const QString &fileName, QWidget *parent = 0);
private: private:
QTabWidget *tabWidget; QTabWidget *tabWidget;

View File

@ -48,7 +48,7 @@ class PiecesList : public QListWidget
Q_OBJECT Q_OBJECT
public: public:
PiecesList(int pieceSize, QWidget *parent = 0); explicit PiecesList(int pieceSize, QWidget *parent = 0);
void addPiece(QPixmap pixmap, QPoint location); void addPiece(QPixmap pixmap, QPoint location);
protected: protected:

View File

@ -57,7 +57,7 @@ class PuzzleWidget : public QWidget
Q_OBJECT Q_OBJECT
public: public:
PuzzleWidget(int imageSize, QWidget *parent = 0); explicit PuzzleWidget(int imageSize, QWidget *parent = 0);
void clear(); void clear();
int pieceSize() const; int pieceSize() const;

View File

@ -99,7 +99,7 @@ class GLTexture2D : public GLTexture
{ {
public: public:
GLTexture2D(int width, int height); 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); void load(int width, int height, QRgb *data);
virtual void bind(); virtual void bind();
virtual void unbind(); virtual void unbind();
@ -120,7 +120,7 @@ class GLTextureCube : public GLTexture
{ {
public: public:
GLTextureCube(int size); 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); void load(int size, int face, QRgb *data);
virtual void bind(); virtual void bind();
virtual void unbind(); virtual void unbind();

View File

@ -65,7 +65,7 @@ class GLRoundedBox : public GLTriangleMesh<P3T2N3Vertex, unsigned short>
{ {
public: public:
// 0 < r < 0.5, 0 <= n <= 125 // 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 Q_OBJECT
public: public:
View(const QString &name, QWidget *parent = 0); explicit View(const QString &name, QWidget *parent = 0);
QGraphicsView *view() const; QGraphicsView *view() const;

View File

@ -63,7 +63,7 @@ class DiagramScene : public QGraphicsScene
public: public:
enum Mode { InsertItem, InsertLine, InsertText, MoveItem }; enum Mode { InsertItem, InsertLine, InsertText, MoveItem };
DiagramScene(QMenu *itemMenu, QObject *parent = 0); explicit DiagramScene(QMenu *itemMenu, QObject *parent = 0);
QFont font() const QFont font() const
{ return myFont; } { return myFont; }
QColor textColor() const QColor textColor() const

View File

@ -49,7 +49,7 @@ class CustomProxy : public QGraphicsProxyWidget
{ {
Q_OBJECT Q_OBJECT
public: public:
CustomProxy(QGraphicsItem *parent = 0, Qt::WindowFlags wFlags = 0); explicit CustomProxy(QGraphicsItem *parent = 0, Qt::WindowFlags wFlags = 0);
QRectF boundingRect() const; QRectF boundingRect() const;
void paintWindowFrame(QPainter *painter, const QStyleOptionGraphicsItem *option, void paintWindowFrame(QPainter *painter, const QStyleOptionGraphicsItem *option,

View File

@ -51,7 +51,7 @@
class FlippablePad : public RoundRectItem class FlippablePad : public RoundRectItem
{ {
public: public:
FlippablePad(const QSize &size, QGraphicsItem *parent = 0); explicit FlippablePad(const QSize &size, QGraphicsItem *parent = 0);
RoundRectItem *iconAt(int column, int row) const; RoundRectItem *iconAt(int column, int row) const;

View File

@ -49,7 +49,7 @@
class TreeItem class TreeItem
{ {
public: public:
TreeItem(const QVector<QVariant> &data, TreeItem *parent = 0); explicit TreeItem(const QVector<QVariant> &data, TreeItem *parent = 0);
~TreeItem(); ~TreeItem();
TreeItem *child(int number); TreeItem *child(int number);

View File

@ -56,7 +56,7 @@ class PiecesModel : public QAbstractListModel
Q_OBJECT Q_OBJECT
public: public:
PiecesModel(int pieceSize, QObject *parent = 0); explicit PiecesModel(int pieceSize, QObject *parent = 0);
QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const; QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const;
Qt::ItemFlags flags(const QModelIndex &index) const; Qt::ItemFlags flags(const QModelIndex &index) const;

View File

@ -57,7 +57,7 @@ class PuzzleWidget : public QWidget
Q_OBJECT Q_OBJECT
public: public:
PuzzleWidget(int imageSize, QWidget *parent = 0); explicit PuzzleWidget(int imageSize, QWidget *parent = 0);
void clear(); void clear();
int pieceSize() const; int pieceSize() const;

View File

@ -54,7 +54,7 @@ class DomModel : public QAbstractItemModel
Q_OBJECT Q_OBJECT
public: public:
DomModel(QDomDocument document, QObject *parent = 0); explicit DomModel(QDomDocument document, QObject *parent = 0);
~DomModel(); ~DomModel();
QVariant data(const QModelIndex &index, int role) const; QVariant data(const QModelIndex &index, int role) const;

View File

@ -48,7 +48,7 @@
class TreeItem class TreeItem
{ {
public: public:
TreeItem(const QList<QVariant> &data, TreeItem *parent = 0); explicit TreeItem(const QList<QVariant> &data, TreeItem *parent = 0);
~TreeItem(); ~TreeItem();
void appendChild(TreeItem *child); void appendChild(TreeItem *child);

View File

@ -53,7 +53,7 @@ class TreeModel : public QAbstractItemModel
Q_OBJECT Q_OBJECT
public: public:
TreeModel(const QString &data, QObject *parent = 0); explicit TreeModel(const QString &data, QObject *parent = 0);
~TreeModel(); ~TreeModel();
QVariant data(const QModelIndex &index, int role) const; QVariant data(const QModelIndex &index, int role) const;

View File

@ -51,7 +51,7 @@ class StarRating
public: public:
enum EditMode { Editable, ReadOnly }; 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, void paint(QPainter *painter, const QRect &rect,
const QPalette &palette, EditMode mode) const; const QPalette &palette, EditMode mode) const;

View File

@ -50,7 +50,7 @@ class BorderLayout : public QLayout
public: public:
enum Position { West, North, South, East, Center }; 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(int spacing = -1);
~BorderLayout(); ~BorderLayout();

View File

@ -48,8 +48,8 @@
class FlowLayout : public QLayout class FlowLayout : public QLayout
{ {
public: public:
FlowLayout(QWidget *parent, int margin = -1, int hSpacing = -1, int vSpacing = -1); explicit FlowLayout(QWidget *parent, int margin = -1, int hSpacing = -1, int vSpacing = -1);
FlowLayout(int margin = -1, int hSpacing = -1, int vSpacing = -1); explicit FlowLayout(int margin = -1, int hSpacing = -1, int vSpacing = -1);
~FlowLayout(); ~FlowLayout();
void addItem(QLayoutItem *item); void addItem(QLayoutItem *item);

View File

@ -79,7 +79,7 @@ class ColorSwatch : public QDockWidget
QAction *windowModifiedAction; QAction *windowModifiedAction;
public: 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; QMenu *menu;
void setCustomSizeHint(const QSize &size); void setCustomSizeHint(const QSize &size);

View File

@ -58,7 +58,7 @@ class PathDeformRenderer : public ArthurFrame
Q_PROPERTY(QString text READ text WRITE setText) Q_PROPERTY(QString text READ text WRITE setText)
public: public:
PathDeformRenderer(QWidget *widget, bool smallScreen = false); explicit PathDeformRenderer(QWidget *widget, bool smallScreen = false);
void paint(QPainter *painter); void paint(QPainter *painter);

View File

@ -50,7 +50,7 @@ class RenderArea : public QWidget
Q_OBJECT Q_OBJECT
public: public:
RenderArea(const QPainterPath &path, QWidget *parent = 0); explicit RenderArea(const QPainterPath &path, QWidget *parent = 0);
QSize minimumSizeHint() const; QSize minimumSizeHint() const;
QSize sizeHint() const; QSize sizeHint() const;

View File

@ -53,7 +53,7 @@ class PathStrokeRenderer : public ArthurFrame
public: public:
enum PathMode { CurveMode, LineMode }; enum PathMode { CurveMode, LineMode };
PathStrokeRenderer(QWidget *parent, bool smallScreen = false); explicit PathStrokeRenderer(QWidget *parent, bool smallScreen = false);
void paint(QPainter *); void paint(QPainter *);
void mousePressEvent(QMouseEvent *e); void mousePressEvent(QMouseEvent *e);

View File

@ -49,7 +49,7 @@ class Button : public QToolButton
Q_OBJECT Q_OBJECT
public: public:
Button(const QString &text, QWidget *parent = 0); explicit Button(const QString &text, QWidget *parent = 0);
QSize sizeHint() const; QSize sizeHint() const;
}; };

View File

@ -55,7 +55,7 @@ class ElidedLabel : public QFrame
Q_PROPERTY(bool isElided READ isElided) Q_PROPERTY(bool isElided READ isElided)
public: public:
ElidedLabel(const QString &text, QWidget *parent = 0); explicit ElidedLabel(const QString &text, QWidget *parent = 0);
void setText(const QString &text); void setText(const QString &text);
const QString & text() const { return content; } const QString & text() const { return content; }

View File

@ -49,7 +49,7 @@ class Dialog : public QDialog
Q_OBJECT Q_OBJECT
public: public:
Dialog(QWidget *parent = 0, bool smallScreen = false); explicit Dialog(QWidget *parent = 0, bool smallScreen = false);
}; };
//! [0] //! [0]