doc: Add missing override and remove redundant virtual for snippets

Change-Id: I2395fd01b93c4ea364225e0cf1a5f59908b691d0
Reviewed-by: Martin Smith <martin.smith@qt.io>
This commit is contained in:
Alexander Volkov 2016-12-08 00:23:14 +03:00
parent 9b59a2ef97
commit 242ea38375
37 changed files with 95 additions and 95 deletions

View File

@ -51,7 +51,7 @@
//! [0] //! [0]
class HelloWorldTask : public QRunnable class HelloWorldTask : public QRunnable
{ {
void run() void run() override
{ {
qDebug() << "Hello world from thread" << QThread::currentThread(); qDebug() << "Hello world from thread" << QThread::currentThread();
} }

View File

@ -52,7 +52,7 @@
class ZipEngineHandler : public QAbstractFileEngineHandler class ZipEngineHandler : public QAbstractFileEngineHandler
{ {
public: public:
QAbstractFileEngine *create(const QString &fileName) const; QAbstractFileEngine *create(const QString &fileName) const override;
}; };
QAbstractFileEngine *ZipEngineHandler::create(const QString &fileName) const QAbstractFileEngine *ZipEngineHandler::create(const QString &fileName) const
@ -105,12 +105,12 @@ public:
entries << "entry1" << "entry2" << "entry3"; entries << "entry1" << "entry2" << "entry3";
} }
bool hasNext() const bool hasNext() const override
{ {
return index < entries.size() - 1; return index < entries.size() - 1;
} }
QString next() QString next() override
{ {
if (!hasNext()) if (!hasNext())
return QString(); return QString();
@ -118,7 +118,7 @@ public:
return currentFilePath(); return currentFilePath();
} }
QString currentFileName() QString currentFileName() override
{ {
return entries.at(index); return entries.at(index);
} }

View File

@ -94,7 +94,7 @@ class SandboxProcess : public QProcess
{ {
... ...
protected: protected:
void setupChildProcess(); void setupChildProcess() override;
... ...
}; };

View File

@ -120,7 +120,7 @@ public:
... ...
QVariant data(const QModelIndex &index, int role) QVariant data(const QModelIndex &index, int role) override
{ {
if (role != Qt::BackgroundRole) if (role != Qt::BackgroundRole)
return QSortFilterProxyModel::data(index, role); return QSortFilterProxyModel::data(index, role);

View File

@ -101,7 +101,7 @@ public:
MainWindow(); MainWindow();
protected: protected:
bool eventFilter(QObject *obj, QEvent *ev); bool eventFilter(QObject *obj, QEvent *ev) override;
private: private:
QTextEdit *textEdit; QTextEdit *textEdit;
@ -147,7 +147,7 @@ public:
MyObject(QObject *parent = 0); MyObject(QObject *parent = 0);
protected: protected:
void timerEvent(QTimerEvent *event); void timerEvent(QTimerEvent *event) override;
}; };
MyObject::MyObject(QObject *parent) MyObject::MyObject(QObject *parent)
@ -215,7 +215,7 @@ class KeyPressEater : public QObject
... ...
protected: protected:
bool eventFilter(QObject *obj, QEvent *event); bool eventFilter(QObject *obj, QEvent *event) override;
}; };
bool KeyPressEater::eventFilter(QObject *obj, QEvent *event) bool KeyPressEater::eventFilter(QObject *obj, QEvent *event)
@ -508,7 +508,7 @@ public:
MyClass(QWidget *parent = 0); MyClass(QWidget *parent = 0);
~MyClass(); ~MyClass();
bool event(QEvent* ev) bool event(QEvent* ev) override
{ {
if (ev->type() == QEvent::PolishRequest) { if (ev->type() == QEvent::PolishRequest) {
// overwrite handling of PolishRequest if any // overwrite handling of PolishRequest if any

View File

@ -53,8 +53,8 @@
class MyException : public QException class MyException : public QException
{ {
public: public:
void raise() const { throw *this; } void raise() const override { throw *this; }
MyException *clone() const { return new MyException(*this); } MyException *clone() const override { return new MyException(*this); }
}; };
//! [0] //! [0]

View File

@ -58,7 +58,7 @@ class DateFormatProxyModel : public QIdentityProxyModel
m_formatString = formatString; m_formatString = formatString;
} }
QVariant data(const QModelIndex &index, int role) const QVariant data(const QModelIndex &index, int role) const override
{ {
if (role != Qt::DisplayRole) if (role != Qt::DisplayRole)
return QIdentityProxyModel::data(index, role); return QIdentityProxyModel::data(index, role);

View File

@ -59,7 +59,7 @@ class FilterObject : public QObject
public: public:
FilterObject(QObject *parent = 0); FilterObject(QObject *parent = 0);
bool eventFilter(QObject *object, QEvent *event); bool eventFilter(QObject *object, QEvent *event) override;
void setFilteredObject(QObject *object); void setFilteredObject(QObject *object);
private: private:

View File

@ -54,7 +54,7 @@
class MyCheckBox : public QCheckBox class MyCheckBox : public QCheckBox
{ {
public: public:
void mousePressEvent(QMouseEvent *event); void mousePressEvent(QMouseEvent *event) override;
}; };
//! [0] //! [0]
@ -72,7 +72,7 @@ void MyCheckBox::mousePressEvent(QMouseEvent *event)
class MyWidget : public QWidget class MyWidget : public QWidget
{ {
public: public:
bool event(QEvent *event); bool event(QEvent *event) override;
}; };
static const int MyCustomEventType = 1099; static const int MyCustomEventType = 1099;

View File

@ -143,7 +143,7 @@ public:
void readSettings(); void readSettings();
protected: protected:
void closeEvent(QCloseEvent *event); void closeEvent(QCloseEvent *event) override;
}; };
//! [16] //! [16]

View File

@ -58,7 +58,7 @@ public:
protected: protected:
//![0] //![0]
bool eventTest(QEvent *event) bool eventTest(QEvent *event) override
{ {
if (event->type() == QEvent::Wrapped) { if (event->type() == QEvent::Wrapped) {
QEvent *wrappedEvent = static_cast<QStateMachine::WrappedEvent *>(event)->event(); QEvent *wrappedEvent = static_cast<QStateMachine::WrappedEvent *>(event)->event();
@ -71,7 +71,7 @@ protected:
} }
//![0] //![0]
void onTransition(QEvent *event) void onTransition(QEvent *event) override
{ {
} }

View File

@ -72,7 +72,7 @@ public:
: m_value(value) {} : m_value(value) {}
protected: protected:
virtual bool eventTest(QEvent *e) bool eventTest(QEvent *e) override
{ {
if (e->type() != QEvent::Type(QEvent::User+1)) // StringEvent if (e->type() != QEvent::Type(QEvent::User+1)) // StringEvent
return false; return false;
@ -80,7 +80,7 @@ protected:
return (m_value == se->value); return (m_value == se->value);
} }
virtual void onTransition(QEvent *) {} void onTransition(QEvent *) override {}
private: private:
QString m_value; QString m_value;

View File

@ -74,10 +74,10 @@ signals:
void mimeTypes(const QStringList &types); void mimeTypes(const QStringList &types);
protected: protected:
void dragEnterEvent(QDragEnterEvent *event); void dragEnterEvent(QDragEnterEvent *event) override;
void dropEvent(QDropEvent *event); void dropEvent(QDropEvent *event) override;
void mouseMoveEvent(QMouseEvent *event); void mouseMoveEvent(QMouseEvent *event) override;
void mousePressEvent(QMouseEvent *event); void mousePressEvent(QMouseEvent *event) override;
private: private:
QByteArray data; QByteArray data;

View File

@ -68,7 +68,7 @@ public:
MainWindow(QWidget *parent = 0); MainWindow(QWidget *parent = 0);
protected: protected:
void mousePressEvent(QMouseEvent *event); void mousePressEvent(QMouseEvent *event) override;
private: private:
QLabel *iconLabel; QLabel *iconLabel;

View File

@ -67,8 +67,8 @@ public:
Window(QWidget *parent = 0); Window(QWidget *parent = 0);
protected: protected:
void dragEnterEvent(QDragEnterEvent *event); void dragEnterEvent(QDragEnterEvent *event) override;
void dropEvent(QDropEvent *event); void dropEvent(QDropEvent *event) override;
private: private:
QComboBox *mimeTypeCombo; QComboBox *mimeTypeCombo;

View File

@ -67,8 +67,8 @@ public:
Window(QWidget *parent = 0); Window(QWidget *parent = 0);
protected: protected:
void dragMoveEvent(QDragMoveEvent *event); void dragMoveEvent(QDragMoveEvent *event) override;
void dropEvent(QDropEvent *event); void dropEvent(QDropEvent *event) override;
private: private:
QComboBox *mimeTypeCombo; QComboBox *mimeTypeCombo;

View File

@ -53,7 +53,7 @@
class SimpleTransformation : public QWidget class SimpleTransformation : public QWidget
{ {
void paintEvent(QPaintEvent *); void paintEvent(QPaintEvent *) override;
}; };
//! [0] //! [0]
@ -73,7 +73,7 @@ void SimpleTransformation::paintEvent(QPaintEvent *)
class CombinedTransformation : public QWidget class CombinedTransformation : public QWidget
{ {
void paintEvent(QPaintEvent *); void paintEvent(QPaintEvent *) override;
}; };
//! [1] //! [1]
@ -97,7 +97,7 @@ void CombinedTransformation::paintEvent(QPaintEvent *)
class BasicOperations : public QWidget class BasicOperations : public QWidget
{ {
void paintEvent(QPaintEvent *); void paintEvent(QPaintEvent *) override;
}; };
//! [2] //! [2]

View File

@ -61,7 +61,7 @@ public:
Window(QWidget *parent = 0); Window(QWidget *parent = 0);
protected: protected:
void paintEvent(QPaintEvent *event); void paintEvent(QPaintEvent *event) override;
private: private:
QFont font; QFont font;

View File

@ -61,7 +61,7 @@ public:
{ {
} }
bool event(QEvent *event) bool event(QEvent *event) override
{ {
if (event->type() == QEvent::FileOpen) { if (event->type() == QEvent::FileOpen) {
QFileOpenEvent *openEvent = static_cast<QFileOpenEvent *>(event); QFileOpenEvent *openEvent = static_cast<QFileOpenEvent *>(event);

View File

@ -71,8 +71,8 @@ public:
const QPixmap *pixmap() const; const QPixmap *pixmap() const;
protected: protected:
void mouseMoveEvent(QMouseEvent *event); void mouseMoveEvent(QMouseEvent *event) override;
void mousePressEvent(QMouseEvent *event); void mousePressEvent(QMouseEvent *event) override;
private: private:
void createImage(); void createImage();

View File

@ -59,8 +59,8 @@ class TextEdit : public QTextEdit
public: public:
TextEdit(QWidget *parent=0); TextEdit(QWidget *parent=0);
bool canInsertFromMimeData( const QMimeData *source ) const; bool canInsertFromMimeData( const QMimeData *source ) const override;
void insertFromMimeData( const QMimeData *source ); void insertFromMimeData( const QMimeData *source ) override;
}; };
#endif #endif

View File

@ -53,7 +53,7 @@
class SimpleTransformation : public QWidget class SimpleTransformation : public QWidget
{ {
void paintEvent(QPaintEvent *); void paintEvent(QPaintEvent *) override;
}; };
//! [0] //! [0]
@ -73,7 +73,7 @@ void SimpleTransformation::paintEvent(QPaintEvent *)
class CombinedTransformation : public QWidget class CombinedTransformation : public QWidget
{ {
void paintEvent(QPaintEvent *); void paintEvent(QPaintEvent *) override;
}; };
//! [1] //! [1]
@ -97,7 +97,7 @@ void CombinedTransformation::paintEvent(QPaintEvent *)
class BasicOperations : public QWidget class BasicOperations : public QWidget
{ {
void paintEvent(QPaintEvent *); void paintEvent(QPaintEvent *) override;
}; };
//! [2] //! [2]

View File

@ -146,7 +146,7 @@ public:
protected: protected:
void initializeGL() void initializeGL() override
{ {
// Set up the rendering context, define display lists etc.: // Set up the rendering context, define display lists etc.:
... ...
@ -155,7 +155,7 @@ protected:
... ...
} }
void resizeGL(int w, int h) void resizeGL(int w, int h) override
{ {
// setup viewport, projection etc.: // setup viewport, projection etc.:
glViewport(0, 0, (GLint)w, (GLint)h); glViewport(0, 0, (GLint)w, (GLint)h);
@ -164,7 +164,7 @@ protected:
... ...
} }
void paintGL() void paintGL() override
{ {
// draw the scene: // draw the scene:
... ...

View File

@ -273,7 +273,7 @@ void QSqlQueryModel_snippets()
class MyModel : public QSqlQueryModel class MyModel : public QSqlQueryModel
{ {
public: public:
QVariant data(const QModelIndex &item, int role) const; QVariant data(const QModelIndex &item, int role) const override;
int m_specialColumnNo; int m_specialColumnNo;
}; };
@ -526,15 +526,15 @@ public:
~XyzResult() {} ~XyzResult() {}
protected: protected:
QVariant data(int /* index */) { return QVariant(); } QVariant data(int /* index */) override { return QVariant(); }
bool isNull(int /* index */) { return false; } bool isNull(int /* index */) override { return false; }
bool reset(const QString & /* query */) { return false; } bool reset(const QString & /* query */) override { return false; }
bool fetch(int /* index */) { return false; } bool fetch(int /* index */) override { return false; }
bool fetchFirst() { return false; } bool fetchFirst() override { return false; }
bool fetchLast() { return false; } bool fetchLast() override { return false; }
int size() { return 0; } int size() override { return 0; }
int numRowsAffected() { return 0; } int numRowsAffected() override { return 0; }
QSqlRecord record() const { return QSqlRecord(); } QSqlRecord record() const override { return QSqlRecord(); }
}; };
//! [47] //! [47]
@ -545,13 +545,13 @@ public:
XyzDriver() {} XyzDriver() {}
~XyzDriver() {} ~XyzDriver() {}
bool hasFeature(DriverFeature /* feature */) const { return false; } bool hasFeature(DriverFeature /* feature */) const override { return false; }
bool open(const QString & /* db */, const QString & /* user */, bool open(const QString & /* db */, const QString & /* user */,
const QString & /* password */, const QString & /* host */, const QString & /* password */, const QString & /* host */,
int /* port */, const QString & /* options */) int /* port */, const QString & /* options */) override
{ return false; } { return false; }
void close() {} void close() {}
QSqlResult *createResult() const { return new XyzResult(this); } QSqlResult *createResult() const override { return new XyzResult(this); }
}; };
//! [48] //! [48]

View File

@ -55,7 +55,7 @@ public:
MyGLWidget(QWidget *parent) : QOpenGLWidget(parent) { } MyGLWidget(QWidget *parent) : QOpenGLWidget(parent) { }
protected: protected:
void initializeGL() void initializeGL() override
{ {
// Set up the rendering context, load shaders and other resources, etc.: // Set up the rendering context, load shaders and other resources, etc.:
QOpenGLFunctions *f = QOpenGLContext::currentContext()->functions(); QOpenGLFunctions *f = QOpenGLContext::currentContext()->functions();
@ -63,7 +63,7 @@ protected:
... ...
} }
void resizeGL(int w, int h) void resizeGL(int w, int h) override
{ {
// Update projection matrix and other size related settings: // Update projection matrix and other size related settings:
m_projection.setToIdentity(); m_projection.setToIdentity();
@ -71,7 +71,7 @@ protected:
... ...
} }
void paintGL() void paintGL() override
{ {
// Draw the scene: // Draw the scene:
QOpenGLFunctions *f = QOpenGLContext::currentContext()->functions(); QOpenGLFunctions *f = QOpenGLContext::currentContext()->functions();
@ -86,7 +86,7 @@ protected:
class MyGLWidget : public QOpenGLWidget, protected QOpenGLFunctions class MyGLWidget : public QOpenGLWidget, protected QOpenGLFunctions
{ {
... ...
void initializeGL() void initializeGL() override
{ {
initializeOpenGLFunctions(); initializeOpenGLFunctions();
glClearColor(...); glClearColor(...);
@ -108,7 +108,7 @@ widget->setFormat(format); // must be called before the widget or its parent win
//! [3] //! [3]
... ...
void paintGL() void paintGL() override
{ {
QOpenGLFunctions_3_2_Core *f = QOpenGLContext::currentContext()->versionFunctions<QOpenGLFunctions_3_2_Core>(); QOpenGLFunctions_3_2_Core *f = QOpenGLContext::currentContext()->versionFunctions<QOpenGLFunctions_3_2_Core>();
... ...

View File

@ -63,13 +63,13 @@ public:
CardLayout(int dist): QLayout(dist) {} CardLayout(int dist): QLayout(dist) {}
~CardLayout(); ~CardLayout();
void addItem(QLayoutItem *item); void addItem(QLayoutItem *item) override;
QSize sizeHint() const; QSize sizeHint() const override;
QSize minimumSize() const; QSize minimumSize() const override;
int count() const; int count() const override;
QLayoutItem *itemAt(int) const; QLayoutItem *itemAt(int) const override;
QLayoutItem *takeAt(int); QLayoutItem *takeAt(int) override;
void setGeometry(const QRect &rect); void setGeometry(const QRect &rect) override;
private: private:
QList<QLayoutItem*> list; QList<QLayoutItem*> list;

View File

@ -52,7 +52,7 @@
class SimpleItem : public QGraphicsItem class SimpleItem : public QGraphicsItem
{ {
public: public:
QRectF boundingRect() const QRectF boundingRect() const override
{ {
qreal penWidth = 1; qreal penWidth = 1;
return QRectF(-10 - penWidth / 2, -10 - penWidth / 2, return QRectF(-10 - penWidth / 2, -10 - penWidth / 2,
@ -60,7 +60,7 @@ public:
} }
void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, void paint(QPainter *painter, const QStyleOptionGraphicsItem *option,
QWidget *widget) QWidget *widget) override
{ {
painter->drawRoundedRect(-10, -10, 20, 20, 5, 5); painter->drawRoundedRect(-10, -10, 20, 20, 5, 5);
} }
@ -74,7 +74,7 @@ class CustomItem : public QGraphicsItem
public: public:
enum { Type = UserType + 1 }; enum { Type = UserType + 1 };
int type() const int type() const override
{ {
// Enable the use of qgraphicsitem_cast with this item. // Enable the use of qgraphicsitem_cast with this item.
return Type; return Type;
@ -260,7 +260,7 @@ class QGraphicsPathItem : public QAbstractGraphicsShapeItem
{ {
public: public:
enum { Type = 2 }; enum { Type = 2 };
int type() const { return Type; } int type() const override { return Type; }
... ...
}; };
//! [18] //! [18]

View File

@ -54,7 +54,7 @@ class MyProxyStyle : public QProxyStyle
public: public:
int styleHint(StyleHint hint, const QStyleOption *option = 0, int styleHint(StyleHint hint, const QStyleOption *option = 0,
const QWidget *widget = 0, QStyleHintReturn *returnData = 0) const const QWidget *widget = 0, QStyleHintReturn *returnData = 0) const override
{ {
if (hint == QStyle::SH_UnderlineShortcut) if (hint == QStyle::SH_UnderlineShortcut)
return 1; return 1;
@ -73,7 +73,7 @@ class MyProxyStyle : public QProxyStyle
{ {
public: public:
int styleHint(StyleHint hint, const QStyleOption *option = 0, int styleHint(StyleHint hint, const QStyleOption *option = 0,
const QWidget *widget = 0, QStyleHintReturn *returnData = 0) const const QWidget *widget = 0, QStyleHintReturn *returnData = 0) const override
{ {
if (hint == QStyle::SH_UnderlineShortcut) if (hint == QStyle::SH_UnderlineShortcut)
return 0; return 0;

View File

@ -54,9 +54,9 @@ class AppendText : public QUndoCommand
public: public:
AppendText(QString *doc, const QString &text) AppendText(QString *doc, const QString &text)
: m_document(doc), m_text(text) { setText("append text"); } : m_document(doc), m_text(text) { setText("append text"); }
virtual void undo() void undo() override
{ m_document->chop(m_text.length()); } { m_document->chop(m_text.length()); }
virtual void redo() void redo() override
{ m_document->append(m_text); } { m_document->append(m_text); }
private: private:
QString *m_document; QString *m_document;

View File

@ -63,7 +63,7 @@ public:
~CustomStyle() {} ~CustomStyle() {}
void drawPrimitive(PrimitiveElement element, const QStyleOption *option, void drawPrimitive(PrimitiveElement element, const QStyleOption *option,
QPainter *painter, const QWidget *widget) const; QPainter *painter, const QWidget *widget) const override;
}; };
//! [0] //! [0]

View File

@ -58,7 +58,7 @@ public:
void drawItems(QPainter *painter, int numItems, QGraphicsItem *items[], void drawItems(QPainter *painter, int numItems, QGraphicsItem *items[],
const QStyleOptionGraphicsItem options[], const QStyleOptionGraphicsItem options[],
QWidget *widget = 0); QWidget *widget = 0) override;
}; };
//! [0] //! [0]

View File

@ -57,8 +57,8 @@ public:
void setWidget(QWidget *w); void setWidget(QWidget *w);
protected: protected:
void scrollContentsBy(int dx, int dy); void scrollContentsBy(int dx, int dy) override;
void resizeEvent(QResizeEvent *event); void resizeEvent(QResizeEvent *event) override;
private: private:
void updateWidgetPosition(); void updateWidgetPosition();

View File

@ -61,15 +61,15 @@ class DragDropListModel : public QStringListModel
public: public:
DragDropListModel(const QStringList &strings, QObject *parent = 0); DragDropListModel(const QStringList &strings, QObject *parent = 0);
Qt::ItemFlags flags(const QModelIndex &index) const; Qt::ItemFlags flags(const QModelIndex &index) const override;
bool canDropMimeData(const QMimeData *data, Qt::DropAction action, bool canDropMimeData(const QMimeData *data, Qt::DropAction action,
int row, int column, const QModelIndex &parent); int row, int column, const QModelIndex &parent) override;
bool dropMimeData(const QMimeData *data, Qt::DropAction action, bool dropMimeData(const QMimeData *data, Qt::DropAction action,
int row, int column, const QModelIndex &parent); int row, int column, const QModelIndex &parent) override;
QMimeData *mimeData(const QModelIndexList &indexes) const; QMimeData *mimeData(const QModelIndexList &indexes) const override;
QStringList mimeTypes() const; QStringList mimeTypes() const override;
Qt::DropActions supportedDropActions() const; Qt::DropActions supportedDropActions() const override;
}; };
#endif #endif

View File

@ -56,7 +56,7 @@ class MyPushButton : public QPushButton
public: public:
MyPushButton(QWidget *parent = 0); MyPushButton(QWidget *parent = 0);
void paintEvent(QPaintEvent *); void paintEvent(QPaintEvent *) override;
}; };
MyPushButton::MyPushButton(QWidget *parent) MyPushButton::MyPushButton(QWidget *parent)
@ -87,7 +87,7 @@ class MyStyle : public QStyle
public: public:
void drawPrimitive(PrimitiveElement element, const QStyleOption *option, void drawPrimitive(PrimitiveElement element, const QStyleOption *option,
QPainter *painter, const QWidget *widget); QPainter *painter, const QWidget *widget) override;
}; };
//! [4] //! [4]

View File

@ -59,7 +59,7 @@ class MyStylePlugin : public QStylePlugin
public: public:
MyStylePlugin(QObject *parent = 0); MyStylePlugin(QObject *parent = 0);
QStyle *create(const QString &key); QStyle *create(const QString &key) override;
}; };
//! [0] //! [0]

View File

@ -64,7 +64,7 @@ public:
Splitter(Qt::Orientation orientation, QWidget *parent = 0); Splitter(Qt::Orientation orientation, QWidget *parent = 0);
protected: protected:
QSplitterHandle *createHandle(); QSplitterHandle *createHandle() override;
}; };
//! [0] //! [0]
@ -74,7 +74,7 @@ public:
SplitterHandle(Qt::Orientation orientation, QSplitter *parent); SplitterHandle(Qt::Orientation orientation, QSplitter *parent);
protected: protected:
void paintEvent(QPaintEvent *event); void paintEvent(QPaintEvent *event) override;
private: private:
QLinearGradient gradient; QLinearGradient gradient;

View File

@ -55,7 +55,7 @@
class MyWidget : public QWidget class MyWidget : public QWidget
{ {
protected: protected:
void paintEvent(QPaintEvent *event); void paintEvent(QPaintEvent *event) override;
void paintEvent2(QPaintEvent *event); void paintEvent2(QPaintEvent *event);
}; };