Cleanup QtWidgets examples

Cleanup QtWidgets examples:
 - use nullptr (clang-tidy)
 - use member-initialization
 - adjust the style
 - fix includes

Change-Id: Ic5448606aacc525ea60b615a69227017aa2b821a
Reviewed-by: Paul Wicking <paul.wicking@qt.io>
This commit is contained in:
Christian Ehrlicher 2019-09-06 23:24:56 +02:00
parent 65fcd8524d
commit 4af00753fa
56 changed files with 213 additions and 192 deletions

View File

@ -118,9 +118,9 @@ void ClassWizard::accept()
block += "public:\n";
if (field("qobjectCtor").toBool()) {
block += " " + className + "(QObject *parent = 0);\n";
block += " " + className + "(QObject *parent = nullptr);\n";
} else if (field("qwidgetCtor").toBool()) {
block += " " + className + "(QWidget *parent = 0);\n";
block += " " + className + "(QWidget *parent = nullptr);\n";
} else if (field("defaultCtor").toBool()) {
block += " " + className + "();\n";
if (field("copyCtor").toBool()) {

View File

@ -67,7 +67,7 @@ class ClassWizard : public QWizard
Q_OBJECT
public:
ClassWizard(QWidget *parent = 0);
ClassWizard(QWidget *parent = nullptr);
void accept() override;
};
@ -79,7 +79,7 @@ class IntroPage : public QWizardPage
Q_OBJECT
public:
IntroPage(QWidget *parent = 0);
IntroPage(QWidget *parent = nullptr);
private:
QLabel *label;
@ -92,7 +92,7 @@ class ClassInfoPage : public QWizardPage
Q_OBJECT
public:
ClassInfoPage(QWidget *parent = 0);
ClassInfoPage(QWidget *parent = nullptr);
private:
QLabel *classNameLabel;
@ -114,7 +114,7 @@ class CodeStylePage : public QWizardPage
Q_OBJECT
public:
CodeStylePage(QWidget *parent = 0);
CodeStylePage(QWidget *parent = nullptr);
protected:
void initializePage() override;
@ -135,7 +135,7 @@ class OutputFilesPage : public QWizardPage
Q_OBJECT
public:
OutputFilesPage(QWidget *parent = 0);
OutputFilesPage(QWidget *parent = nullptr);
protected:
void initializePage() override;
@ -154,7 +154,7 @@ class ConclusionPage : public QWizardPage
Q_OBJECT
public:
ConclusionPage(QWidget *parent = 0);
ConclusionPage(QWidget *parent = nullptr);
protected:
void initializePage() override;

View File

@ -68,7 +68,7 @@ class FindDialog : public QDialog
Q_OBJECT
public:
FindDialog(QWidget *parent = 0);
FindDialog(QWidget *parent = nullptr);
private:
QLabel *label;

View File

@ -68,7 +68,7 @@ class Window : public QWidget
Q_OBJECT
public:
Window(QWidget *parent = 0);
Window(QWidget *parent = nullptr);
private slots:
void browse();

View File

@ -72,7 +72,7 @@ public:
Page_Conclusion };
//! [2]
LicenseWizard(QWidget *parent = 0);
LicenseWizard(QWidget *parent = nullptr);
private slots:
void showHelp();
@ -86,7 +86,7 @@ class IntroPage : public QWizardPage
Q_OBJECT
public:
IntroPage(QWidget *parent = 0);
IntroPage(QWidget *parent = nullptr);
int nextId() const override;
@ -103,7 +103,7 @@ class EvaluatePage : public QWizardPage
Q_OBJECT
public:
EvaluatePage(QWidget *parent = 0);
EvaluatePage(QWidget *parent = nullptr);
int nextId() const override;
@ -120,7 +120,7 @@ class RegisterPage : public QWizardPage
Q_OBJECT
public:
RegisterPage(QWidget *parent = 0);
RegisterPage(QWidget *parent = nullptr);
int nextId() const override;
@ -136,7 +136,7 @@ class DetailsPage : public QWizardPage
Q_OBJECT
public:
DetailsPage(QWidget *parent = 0);
DetailsPage(QWidget *parent = nullptr);
int nextId() const override;
@ -155,7 +155,7 @@ class ConclusionPage : public QWizardPage
Q_OBJECT
public:
ConclusionPage(QWidget *parent = 0);
ConclusionPage(QWidget *parent = nullptr);
void initializePage() override;
int nextId() const override;

View File

@ -66,7 +66,7 @@ class Dialog : public QWidget
Q_OBJECT
public:
Dialog(QWidget *parent = 0);
Dialog(QWidget *parent = nullptr);
private slots:
void setInteger();

View File

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

View File

@ -63,7 +63,7 @@ class BlurPicker: public QGraphicsView
Q_PROPERTY(qreal index READ index WRITE setIndex)
public:
BlurPicker(QWidget *parent = 0);
BlurPicker(QWidget *parent = nullptr);
qreal index() const;
void setIndex(qreal);

View File

@ -62,7 +62,7 @@ class FadeMessage: public QGraphicsView
Q_OBJECT
public:
FadeMessage(QWidget *parent = 0);
FadeMessage(QWidget *parent = nullptr);
private:
void setupScene();

View File

@ -50,26 +50,23 @@
#include "imagewidget.h"
#include <QtWidgets>
#include <QDir>
#include <QImageReader>
#include <QGestureEvent>
#include <QPainter>
Q_LOGGING_CATEGORY(lcExample, "qt.examples.imagegestures")
//! [constructor]
ImageWidget::ImageWidget(QWidget *parent)
: QWidget(parent),
position(0),
horizontalOffset(0),
verticalOffset(0),
rotationAngle(0),
scaleFactor(1),
currentStepScaleFactor(1)
: QWidget(parent), position(0), horizontalOffset(0), verticalOffset(0)
, rotationAngle(0), scaleFactor(1), currentStepScaleFactor(1)
{
setMinimumSize(QSize(100,100));
setMinimumSize(QSize(100, 100));
}
//! [constructor]
void ImageWidget::grabGestures(const QList<Qt::GestureType> &gestures)
void ImageWidget::grabGestures(const QVector<Qt::GestureType> &gestures)
{
//! [enable gestures]
for (Qt::GestureType gesture : gestures)
@ -96,11 +93,11 @@ void ImageWidget::paintEvent(QPaintEvent*)
const qreal wh = height();
const qreal ww = width();
p.translate(ww/2, wh/2);
p.translate(ww / 2, wh / 2);
p.translate(horizontalOffset, verticalOffset);
p.rotate(rotationAngle);
p.scale(currentStepScaleFactor * scaleFactor, currentStepScaleFactor * scaleFactor);
p.translate(-iw/2, -ih/2);
p.translate(-iw / 2, -ih / 2);
p.drawImage(0, 0, currentImage);
}
//! [paint method]
@ -198,8 +195,7 @@ void ImageWidget::openDirectory(const QString &path)
{
this->path = path;
QDir dir(path);
QStringList nameFilters;
nameFilters << "*.jpg" << "*.png";
const QStringList nameFilters{"*.jpg", "*.png"};
files = dir.entryList(nameFilters, QDir::Files|QDir::Readable, QDir::Name);
position = 0;
@ -207,7 +203,7 @@ void ImageWidget::openDirectory(const QString &path)
update();
}
QImage ImageWidget::loadImage(const QString &fileName)
QImage ImageWidget::loadImage(const QString &fileName) const
{
QImageReader reader(fileName);
reader.setAutoTransform(true);

View File

@ -51,9 +51,9 @@
#ifndef IMAGEWIDGET_H
#define IMAGEWIDGET_H
#include <QWidget>
#include <QImage>
#include <QtWidgets>
#include <QLoggingCategory>
#include <QWidget>
QT_BEGIN_NAMESPACE
class QGestureEvent;
@ -70,9 +70,9 @@ class ImageWidget : public QWidget
Q_OBJECT
public:
ImageWidget(QWidget *parent = 0);
ImageWidget(QWidget *parent = nullptr);
void openDirectory(const QString &path);
void grabGestures(const QList<Qt::GestureType> &gestures);
void grabGestures(const QVector<Qt::GestureType> &gestures);
protected:
bool event(QEvent *event) override;
@ -87,7 +87,7 @@ private:
void swipeTriggered(QSwipeGesture*);
//! [class definition begin]
QImage loadImage(const QString &fileName);
QImage loadImage(const QString &fileName) const;
void loadImage();
void goNextImage();
void goPrevImage();

View File

@ -102,7 +102,7 @@ int main(int argc, char *argv[])
return -1;
}
QList<Qt::GestureType> gestures;
QVector<Qt::GestureType> gestures;
if (!commandLineParser.isSet(disablePanOption))
gestures << Qt::PanGesture;
if (!commandLineParser.isSet(disablePinchOption))

View File

@ -72,7 +72,7 @@ void MainWidget::openDirectory(const QString &path)
imageWidget->openDirectory(path);
}
void MainWidget::grabGestures(const QList<Qt::GestureType> &gestures)
void MainWidget::grabGestures(const QVector<Qt::GestureType> &gestures)
{
imageWidget->grabGestures(gestures);
}

View File

@ -60,8 +60,8 @@ class MainWidget : public QMainWindow
Q_OBJECT
public:
MainWidget(QWidget *parent = 0);
void grabGestures(const QList<Qt::GestureType> &gestures);
MainWidget(QWidget *parent = nullptr);
void grabGestures(const QVector<Qt::GestureType> &gestures);
public slots:
void openDirectory(const QString &path);

View File

@ -69,8 +69,9 @@ static qreal normalizeAngle(qreal angle)
}
//! [0]
Mouse::Mouse()
: color(QRandomGenerator::global()->bounded(256), QRandomGenerator::global()->bounded(256), QRandomGenerator::global()->bounded(256))
Mouse::Mouse() : color(QRandomGenerator::global()->bounded(256),
QRandomGenerator::global()->bounded(256),
QRandomGenerator::global()->bounded(256))
{
setRotation(QRandomGenerator::global()->bounded(360 * 16));
}

View File

@ -71,7 +71,7 @@ int main(int argc, char* argv[])
model->setHorizontalHeaderLabels(list);
int row = 0;
QStandardItem *newItem = 0;
QStandardItem *newItem = nullptr;
while (!stream.atEnd()) {
line = stream.readLine();
if (!line.startsWith('#') && line.contains(',')) {

View File

@ -132,7 +132,7 @@ bool Model::hasChildren(const QModelIndex &parent) const
Qt::ItemFlags Model::flags(const QModelIndex &index) const
{
if (!index.isValid())
return 0;
return {};
return Qt::ItemIsDragEnabled|QAbstractItemModel::flags(index);
}
@ -146,7 +146,7 @@ Model::Node *Model::node(int row, Node *parent) const
Model::Node *Model::parent(Node *child) const
{
return child ? child->parent : 0;
return child ? child->parent : nullptr;
}
int Model::row(Node *node) const

View File

@ -48,7 +48,8 @@
**
****************************************************************************/
#include <QtWidgets>
#include <QApplication>
#include <QTableWidget>
#include "stardelegate.h"
#include "stareditor.h"
@ -57,7 +58,7 @@
//! [0]
void populateTableWidget(QTableWidget *tableWidget)
{
static const struct {
static constexpr struct {
const char *title;
const char *genre;
const char *artist;
@ -70,12 +71,12 @@ void populateTableWidget(QTableWidget *tableWidget)
{ "Sex Bomb", "Pop", "Tom Jones", 3 },
{ "Barbie Girl", "Pop", "Aqua", 5 },
//! [2]
{ 0, 0, 0, 0 }
{ nullptr, nullptr, nullptr, 0 }
//! [2] //! [3]
};
//! [3] //! [4]
for (int row = 0; staticData[row].title != 0; ++row) {
for (int row = 0; staticData[row].title != nullptr; ++row) {
QTableWidgetItem *item0 = new QTableWidgetItem(staticData[row].title);
QTableWidgetItem *item1 = new QTableWidgetItem(staticData[row].genre);
QTableWidgetItem *item2 = new QTableWidgetItem(staticData[row].artist);

View File

@ -262,7 +262,7 @@ PathDeformWidget::PathDeformWidget(QWidget *parent, bool smallScreen)
QHBoxLayout *mainLayout = new QHBoxLayout(this);
mainLayout->addWidget(m_renderer);
m_controls = new PathDeformControls(0, m_renderer, smallScreen);
m_controls = new PathDeformControls(nullptr, m_renderer, smallScreen);
m_controls->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Minimum);
if (!smallScreen)

View File

@ -70,7 +70,7 @@ class MainWindow : public QMainWindow, private Ui::MainWindowBase
Q_OBJECT
public:
MainWindow(QWidget *parent = 0);
MainWindow(QWidget *parent = nullptr);
public slots:
void on_clearAction_triggered();

View File

@ -102,9 +102,9 @@ uint ShadeWidget::colorAt(int x)
generateShade();
QPolygonF pts = m_hoverPoints->points();
for (int i=1; i < pts.size(); ++i) {
if (pts.at(i-1).x() <= x && pts.at(i).x() >= x) {
QLineF l(pts.at(i-1), pts.at(i));
for (int i = 1; i < pts.size(); ++i) {
if (pts.at(i - 1).x() <= x && pts.at(i).x() >= x) {
QLineF l(pts.at(i - 1), pts.at(i));
l.setLength(l.length() * ((x - l.x1()) / l.dx()));
return m_shade.pixel(qRound(qMin(l.x2(), (qreal(m_shade.width() - 1)))),
qRound(qMin(l.y2(), qreal(m_shade.height() - 1))));
@ -118,9 +118,9 @@ void ShadeWidget::setGradientStops(const QGradientStops &stops)
if (m_shade_type == ARGBShade) {
m_alpha_gradient = QLinearGradient(0, 0, width(), 0);
for (int i=0; i<stops.size(); ++i) {
QColor c = stops.at(i).second;
m_alpha_gradient.setColorAt(stops.at(i).first, QColor(c.red(), c.green(), c.blue()));
for (const auto &stop : stops) {
QColor c = stop.second;
m_alpha_gradient.setColorAt(stop.first, QColor(c.red(), c.green(), c.blue()));
}
m_shade = QImage();
@ -223,13 +223,13 @@ void GradientEditor::pointsUpdated()
std::sort(points.begin(), points.end(), x_less_than);
for (int i = 0; i < points.size(); ++i) {
qreal x = int(points.at(i).x());
if (i + 1 < points.size() && x == points.at(i + 1).x())
const int x = int(points.at(i).x());
if (i + 1 < points.size() && x == int(points.at(i + 1).x()))
continue;
QColor color((0x00ff0000 & m_red_shade->colorAt(int(x))) >> 16,
(0x0000ff00 & m_green_shade->colorAt(int(x))) >> 8,
(0x000000ff & m_blue_shade->colorAt(int(x))),
(0xff000000 & m_alpha_shade->colorAt(int(x))) >> 24);
QColor color((0x00ff0000 & m_red_shade->colorAt(x)) >> 16,
(0x0000ff00 & m_green_shade->colorAt(x)) >> 8,
(0x000000ff & m_blue_shade->colorAt(x)),
(0xff000000 & m_alpha_shade->colorAt(x)) >> 24);
if (x / w > 1)
return;
@ -568,8 +568,8 @@ void GradientRenderer::paint(QPainter *p)
g = QConicalGradient(pts.at(0), angle);
}
for (int i = 0; i < m_stops.size(); ++i)
g.setColorAt(m_stops.at(i).first, m_stops.at(i).second);
for (const auto &stop : qAsConst(m_stops))
g.setColorAt(stop.first, stop.second);
g.setSpread(m_spread);

View File

@ -157,7 +157,7 @@ class GradientWidget : public QWidget
Q_OBJECT
public:
GradientWidget(QWidget *parent);
GradientWidget(QWidget *parent = nullptr);
public slots:
void setDefault1() { setDefault(1); }

View File

@ -58,8 +58,8 @@ int main(int argc, char *argv[])
QApplication app(argc, argv);
GradientWidget gradientWidget(0);
QStyle *arthurStyle = new ArthurStyle();
GradientWidget gradientWidget;
QStyle *arthurStyle = new ArthurStyle;
gradientWidget.setStyle(arthurStyle);
const QList<QWidget *> widgets = gradientWidget.findChildren<QWidget *>();
for (QWidget *w : widgets) {

View File

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

View File

@ -48,11 +48,9 @@
**
****************************************************************************/
#include "pathstroke.h"
#include "arthurstyle.h"
#include "arthurwidgets.h"
#include "pathstroke.h"
#include <stdio.h>
extern void draw_round_rect(QPainter *p, const QRect &bounds, int radius);
@ -164,24 +162,39 @@ void PathStrokeControls::createCommonControls(QWidget* parent)
// Connections
connect(flatCap, &QAbstractButton::clicked, m_renderer, &PathStrokeRenderer::setFlatCap);
connect(squareCap, &QAbstractButton::clicked, m_renderer, &PathStrokeRenderer::setSquareCap);
connect(roundCap, &QAbstractButton::clicked, m_renderer, &PathStrokeRenderer::setRoundCap);
connect(flatCap, &QAbstractButton::clicked,
m_renderer, &PathStrokeRenderer::setFlatCap);
connect(squareCap, &QAbstractButton::clicked,
m_renderer, &PathStrokeRenderer::setSquareCap);
connect(roundCap, &QAbstractButton::clicked,
m_renderer, &PathStrokeRenderer::setRoundCap);
connect(bevelJoin, &QAbstractButton::clicked, m_renderer, &PathStrokeRenderer::setBevelJoin);
connect(miterJoin, &QAbstractButton::clicked, m_renderer, &PathStrokeRenderer::setMiterJoin);
connect(svgMiterJoin, &QAbstractButton::clicked, m_renderer, &PathStrokeRenderer::setSvgMiterJoin);
connect(roundJoin, &QAbstractButton::clicked, m_renderer, &PathStrokeRenderer::setRoundJoin);
connect(bevelJoin, &QAbstractButton::clicked,
m_renderer, &PathStrokeRenderer::setBevelJoin);
connect(miterJoin, &QAbstractButton::clicked,
m_renderer, &PathStrokeRenderer::setMiterJoin);
connect(svgMiterJoin, &QAbstractButton::clicked,
m_renderer, &PathStrokeRenderer::setSvgMiterJoin);
connect(roundJoin, &QAbstractButton::clicked,
m_renderer, &PathStrokeRenderer::setRoundJoin);
connect(curveMode, &QAbstractButton::clicked, m_renderer, &PathStrokeRenderer::setCurveMode);
connect(lineMode, &QAbstractButton::clicked, m_renderer, &PathStrokeRenderer::setLineMode);
connect(curveMode, &QAbstractButton::clicked,
m_renderer, &PathStrokeRenderer::setCurveMode);
connect(lineMode, &QAbstractButton::clicked,
m_renderer, &PathStrokeRenderer::setLineMode);
connect(solidLine, &QAbstractButton::clicked, m_renderer, &PathStrokeRenderer::setSolidLine);
connect(dashLine, &QAbstractButton::clicked, m_renderer, &PathStrokeRenderer::setDashLine);
connect(dotLine, &QAbstractButton::clicked, m_renderer, &PathStrokeRenderer::setDotLine);
connect(dashDotLine, &QAbstractButton::clicked, m_renderer, &PathStrokeRenderer::setDashDotLine);
connect(dashDotDotLine, &QAbstractButton::clicked, m_renderer, &PathStrokeRenderer::setDashDotDotLine);
connect(customDashLine, &QAbstractButton::clicked, m_renderer, &PathStrokeRenderer::setCustomDashLine);
connect(solidLine, &QAbstractButton::clicked,
m_renderer, &PathStrokeRenderer::setSolidLine);
connect(dashLine, &QAbstractButton::clicked,
m_renderer, &PathStrokeRenderer::setDashLine);
connect(dotLine, &QAbstractButton::clicked,
m_renderer, &PathStrokeRenderer::setDotLine);
connect(dashDotLine, &QAbstractButton::clicked,
m_renderer, &PathStrokeRenderer::setDashDotLine);
connect(dashDotDotLine, &QAbstractButton::clicked,
m_renderer, &PathStrokeRenderer::setDashDotDotLine);
connect(customDashLine, &QAbstractButton::clicked,
m_renderer, &PathStrokeRenderer::setCustomDashLine);
// Set the defaults:
flatCap->setChecked(true);
@ -247,15 +260,20 @@ void PathStrokeControls::layoutForDesktop()
// Set up connections
connect(animated, &QAbstractButton::toggled, m_renderer, &PathStrokeRenderer::setAnimation);
connect(animated, &QAbstractButton::toggled,
m_renderer, &PathStrokeRenderer::setAnimation);
connect(penWidth, &QAbstractSlider::valueChanged, m_renderer, &PathStrokeRenderer::setPenWidth);
connect(penWidth, &QAbstractSlider::valueChanged,
m_renderer, &PathStrokeRenderer::setPenWidth);
connect(showSourceButton, &QAbstractButton::clicked, m_renderer, &ArthurFrame::showSource);
connect(showSourceButton, &QAbstractButton::clicked,
m_renderer, &ArthurFrame::showSource);
#if QT_CONFIG(opengl)
connect(enableOpenGLButton, &QAbstractButton::clicked, m_renderer, &ArthurFrame::enableOpenGL);
connect(enableOpenGLButton, &QAbstractButton::clicked,
m_renderer, &ArthurFrame::enableOpenGL);
#endif
connect(whatsThisButton, &QAbstractButton::clicked, m_renderer, &ArthurFrame::setDescriptionEnabled);
connect(whatsThisButton, &QAbstractButton::clicked,
m_renderer, &ArthurFrame::setDescriptionEnabled);
connect(m_renderer, &ArthurFrame::descriptionEnabledChanged,
whatsThisButton, &QAbstractButton::setChecked);
@ -296,11 +314,11 @@ void PathStrokeControls::layoutForSmallScreens()
#endif
// Layouts:
QHBoxLayout *penWidthLayout = new QHBoxLayout(0);
QHBoxLayout *penWidthLayout = new QHBoxLayout;
penWidthLayout->addWidget(penWidthLabel, 0, Qt::AlignRight);
penWidthLayout->addWidget(penWidth);
QVBoxLayout *leftLayout = new QVBoxLayout(0);
QVBoxLayout *leftLayout = new QVBoxLayout;
leftLayout->addWidget(m_capGroup);
leftLayout->addWidget(m_joinGroup);
#if QT_CONFIG(opengl)
@ -308,7 +326,7 @@ void PathStrokeControls::layoutForSmallScreens()
#endif
leftLayout->addLayout(penWidthLayout);
QVBoxLayout *rightLayout = new QVBoxLayout(0);
QVBoxLayout *rightLayout = new QVBoxLayout;
rightLayout->addWidget(m_styleGroup);
rightLayout->addWidget(m_pathModeGroup);
@ -356,7 +374,7 @@ PathStrokeWidget::PathStrokeWidget(bool smallScreen)
// Widget construction and property setting
m_renderer = new PathStrokeRenderer(this, smallScreen);
m_controls = new PathStrokeControls(0, m_renderer, smallScreen);
m_controls = new PathStrokeControls(nullptr, m_renderer, smallScreen);
// Layouting
QHBoxLayout *viewLayout = new QHBoxLayout(this);
@ -383,10 +401,10 @@ void PathStrokeWidget::hideControls()
m_controls->hide();
}
void PathStrokeWidget::setStyle( QStyle * style )
void PathStrokeWidget::setStyle(QStyle *style)
{
QWidget::setStyle(style);
if (m_controls != 0)
if (m_controls != nullptr)
{
m_controls->setStyle(style);
@ -516,7 +534,7 @@ void PathStrokeRenderer::updatePoints()
qreal bottom = height() - pad;
Q_ASSERT(m_points.size() == m_vectors.size());
for (int i=0; i<m_points.size(); ++i) {
for (int i = 0; i < m_points.size(); ++i) {
QPointF pos = m_points.at(i);
QPointF vec = m_vectors.at(i);
pos += vec;
@ -540,7 +558,7 @@ void PathStrokeRenderer::mousePressEvent(QMouseEvent *e)
setDescriptionEnabled(false);
m_activePoint = -1;
qreal distance = -1;
for (int i=0; i<m_points.size(); ++i) {
for (int i = 0; i < m_points.size(); ++i) {
qreal d = QLineF(e->pos(), m_points.at(i)).length();
if ((distance < 0 && d < 8 * m_pointSize) || d < distance) {
distance = d;
@ -673,7 +691,6 @@ bool PathStrokeRenderer::event(QEvent *e)
m_fingerPointMapping.clear();
setAnimation(m_wasAnimated);
return true;
break;
default:
break;
}

View File

@ -169,7 +169,7 @@ class PathStrokeWidget : public QWidget
public:
PathStrokeWidget(bool smallScreen);
void setStyle ( QStyle * style );
void setStyle(QStyle *style);
private:
PathStrokeRenderer *m_renderer;

View File

@ -63,7 +63,7 @@ public:
void drawHoverRect(QPainter *painter, const QRect &rect) const;
void drawPrimitive(PrimitiveElement element, const QStyleOption *option,
QPainter *painter, const QWidget *widget = 0) const override;
QPainter *painter, const QWidget *widget = nullptr) const override;
void drawControl(ControlElement element, const QStyleOption *option,
QPainter *painter, const QWidget *widget) const override;
void drawComplexControl(ComplexControl control, const QStyleOptionComplex *option,

View File

@ -136,7 +136,7 @@ void ArthurFrame::createGlWindow()
void ArthurFrame::paintEvent(QPaintEvent *e)
{
static QImage *static_image = 0;
static QImage *static_image = nullptr;
QPainter painter;
@ -376,7 +376,7 @@ void ArthurFrame::showSource()
const QString html = QStringLiteral("<html><pre>") + contents + QStringLiteral("</pre></html>");
QTextBrowser *sourceViewer = new QTextBrowser(0);
QTextBrowser *sourceViewer = new QTextBrowser;
sourceViewer->setWindowTitle(tr("Source: %1").arg(m_sourceFileName.midRef(5)));
sourceViewer->setParent(this, Qt::Dialog);
sourceViewer->setAttribute(Qt::WA_DeleteOnClose);

View File

@ -53,7 +53,7 @@
#include <QOffscreenSurface>
#include <QOpenGLFunctions>
QFboPaintDevice::QFboPaintDevice(const QSize& size, bool flipped, bool clearOnInit,
QFboPaintDevice::QFboPaintDevice(const QSize &size, bool flipped, bool clearOnInit,
QOpenGLFramebufferObject::Attachment attachment)
: QOpenGLPaintDevice(size)
{
@ -97,8 +97,8 @@ GLuint QFboPaintDevice::takeTexture()
QImage QFboPaintDevice::toImage() const
{
QOpenGLContext* currentContext = QOpenGLContext::currentContext();
QSurface* currentSurface = currentContext ? currentContext->surface() : 0;
QOpenGLContext *currentContext = QOpenGLContext::currentContext();
QSurface *currentSurface = currentContext ? currentContext->surface() : nullptr;
context()->makeCurrent(m_surface);

View File

@ -60,7 +60,7 @@
class QFboPaintDevice : public QOpenGLPaintDevice {
public:
QFboPaintDevice(const QSize&, bool flipped = false, bool clearOnInit = true,
QFboPaintDevice(const QSize &size, bool flipped = false, bool clearOnInit = true,
QOpenGLFramebufferObject::Attachment = QOpenGLFramebufferObject::CombinedDepthStencil);
~QFboPaintDevice();
@ -83,7 +83,7 @@ public:
private:
QOpenGLFramebufferObject *m_framebufferObject;
QSurface* m_surface;
QSurface *m_surface;
};
#endif // QT_NO_OPENGL

View File

@ -262,8 +262,8 @@ bool HoverPoints::eventFilter(QObject *object, QEvent *event)
case QEvent::Paint:
{
QWidget *that_widget = m_widget;
m_widget = 0;
QApplication::sendEvent(object, event);
m_widget = nullptr;
QCoreApplication::sendEvent(object, event);
m_widget = that_widget;
paintPoints();
return true;

View File

@ -70,7 +70,7 @@ class RenderArea : public QWidget
Q_OBJECT
public:
RenderArea(QWidget *parent = 0);
RenderArea(QWidget *parent = nullptr);
void setOperations(const QList<Operation> &operations);
void setShape(const QPainterPath &shape);

View File

@ -64,7 +64,7 @@ class RectObject : public QGraphicsObject
public:
RectObject(const QString &text, qreal x, qreal y, qreal width, qreal height, QBrush brush, QGraphicsItem *parent = 0)
RectObject(const QString &text, qreal x, qreal y, qreal width, qreal height, QBrush brush, QGraphicsItem *parent = nullptr)
: QGraphicsObject(parent)
, m_text(text)
, m_rect(x, y, width, height)

View File

@ -48,13 +48,18 @@
**
****************************************************************************/
#include <QtWidgets>
#include <QApplication>
#include <QEventTransition>
#include <QPushButton>
#include <QStateMachine>
#include <QVBoxLayout>
#include <QWidget>
//! [0]
class Window : public QWidget
{
public:
Window(QWidget *parent = 0)
Window(QWidget *parent = nullptr)
: QWidget(parent)
{
QPushButton *button = new QPushButton(this);

View File

@ -57,10 +57,7 @@ class Factorial : public QObject
Q_PROPERTY(int x READ x WRITE setX)
Q_PROPERTY(int fac READ fac WRITE setFac)
public:
Factorial(QObject *parent = 0)
: QObject(parent), m_x(-1), m_fac(1)
{
}
using QObject::QObject;
int x() const
{
@ -89,8 +86,8 @@ Q_SIGNALS:
void xChanged(int value);
private:
int m_x;
int m_fac;
int m_x = -1;
int m_fac = 1;
};
//! [0]

View File

@ -48,7 +48,13 @@
**
****************************************************************************/
#include <QtWidgets>
#include <QApplication>
#include <QFinalState>
#include <QPainter>
#include <QStateMachine>
#include <QTimer>
#include <QVBoxLayout>
#include <QWidget>
//! [0]
class LightWidget : public QWidget
@ -56,7 +62,7 @@ class LightWidget : public QWidget
Q_OBJECT
Q_PROPERTY(bool on READ isOn WRITE setOn)
public:
LightWidget(const QColor &color, QWidget *parent = 0)
LightWidget(const QColor &color, QWidget *parent = nullptr)
: QWidget(parent), m_color(color), m_on(false) {}
bool isOn() const
@ -94,7 +100,7 @@ private:
class TrafficLightWidget : public QWidget
{
public:
TrafficLightWidget(QWidget *parent = 0)
TrafficLightWidget(QWidget *parent = nullptr)
: QWidget(parent)
{
QVBoxLayout *vbox = new QVBoxLayout(this);
@ -125,7 +131,7 @@ private:
//! [1]
//! [2]
QState *createLightState(LightWidget *light, int duration, QState *parent = 0)
QState *createLightState(LightWidget *light, int duration, QState *parent = nullptr)
{
QState *lightState = new QState(parent);
QTimer *timer = new QTimer(lightState);

View File

@ -62,7 +62,7 @@ class ScribbleArea : public QWidget
Q_OBJECT
public:
ScribbleArea(QWidget *parent = 0);
ScribbleArea(QWidget *parent = nullptr);
bool openImage(const QString &fileName);
bool saveImage(const QString &fileName, const char *fileFormat);

View File

@ -54,7 +54,7 @@
#include <QTouchEvent>
GraphicsView::GraphicsView(QGraphicsScene *scene, QWidget *parent)
: QGraphicsView(scene, parent), totalScaleFactor(1)
: QGraphicsView(scene, parent)
{
viewport()->setAttribute(Qt::WA_AcceptTouchEvents);
setDragMode(ScrollHandDrag);
@ -83,8 +83,8 @@ bool GraphicsView::viewportEvent(QEvent *event)
totalScaleFactor *= currentScaleFactor;
currentScaleFactor = 1;
}
setTransform(QTransform().scale(totalScaleFactor * currentScaleFactor,
totalScaleFactor * currentScaleFactor));
setTransform(QTransform::fromScale(totalScaleFactor * currentScaleFactor,
totalScaleFactor * currentScaleFactor));
}
return true;
}

View File

@ -56,10 +56,10 @@ class GraphicsView : public QGraphicsView
Q_OBJECT
public:
GraphicsView(QGraphicsScene *scene = 0, QWidget *parent = 0);
GraphicsView(QGraphicsScene *scene = nullptr, QWidget *parent = nullptr);
bool viewportEvent(QEvent *event) override;
private:
qreal totalScaleFactor;
qreal totalScaleFactor = 1;
};

View File

@ -51,11 +51,10 @@
#include "graphicsview.h"
#include "mouse.h"
#include <QtWidgets>
#include <QApplication>
#include <cmath>
#include <math.h>
static const int MouseCount = 7;
static constexpr int MouseCount = 7;
//! [0]
int main(int argc, char **argv)

View File

@ -56,8 +56,8 @@
#include <QStyleOption>
#include <qmath.h>
const qreal Pi = M_PI;
const qreal TwoPi = 2 * M_PI;
constexpr qreal Pi = M_PI;
constexpr qreal TwoPi = 2 * M_PI;
static qreal normalizeAngle(qreal angle)
{
@ -69,9 +69,9 @@ static qreal normalizeAngle(qreal angle)
}
//! [0]
Mouse::Mouse()
: angle(0), speed(0), mouseEyeDirection(0),
color(QRandomGenerator::global()->bounded(256), QRandomGenerator::global()->bounded(256), QRandomGenerator::global()->bounded(256))
Mouse::Mouse() : color(QRandomGenerator::global()->bounded(256),
QRandomGenerator::global()->bounded(256),
QRandomGenerator::global()->bounded(256))
{
setTransform(QTransform().rotate(QRandomGenerator::global()->bounded(360 * 16)), true);
startTimer(1000 / 33);

View File

@ -70,9 +70,9 @@ protected:
void timerEvent(QTimerEvent *event) override;
private:
qreal angle;
qreal speed;
qreal mouseEyeDirection;
qreal angle = 0;
qreal speed = 0;
qreal mouseEyeDirection = 0;
QColor color;
};
//! [0]

View File

@ -65,7 +65,7 @@ class AddressBook : public QWidget
Q_OBJECT
public:
AddressBook(QWidget *parent = 0);
AddressBook(QWidget *parent = nullptr);
private:
QLineEdit *nameLine;

View File

@ -66,7 +66,7 @@ class AddressBook : public QWidget
Q_OBJECT
public:
AddressBook(QWidget *parent = 0);
AddressBook(QWidget *parent = nullptr);
//! [slots]
public slots:

View File

@ -66,7 +66,7 @@ class AddressBook : public QWidget
Q_OBJECT
public:
AddressBook(QWidget *parent = 0);
AddressBook(QWidget *parent = nullptr);
public slots:
void addContact();

View File

@ -66,7 +66,7 @@ class AddressBook : public QWidget
Q_OBJECT
public:
AddressBook(QWidget *parent = 0);
AddressBook(QWidget *parent = nullptr);
//! [Mode enum]
enum Mode { NavigationMode, AddingMode, EditingMode };
//! [Mode enum]

View File

@ -69,7 +69,7 @@ class AddressBook : public QWidget
Q_OBJECT
public:
AddressBook(QWidget *parent = 0);
AddressBook(QWidget *parent = nullptr);
enum Mode { NavigationMode, AddingMode, EditingMode };
public slots:

View File

@ -63,7 +63,7 @@ class FindDialog : public QDialog
Q_OBJECT
public:
FindDialog(QWidget *parent = 0);
FindDialog(QWidget *parent = nullptr);
QString getFindText();
public slots:

View File

@ -68,7 +68,7 @@ class AddressBook : public QWidget
Q_OBJECT
public:
AddressBook(QWidget *parent = 0);
AddressBook(QWidget *parent = nullptr);
enum Mode { NavigationMode, AddingMode, EditingMode };
public slots:

View File

@ -63,7 +63,7 @@ class FindDialog : public QDialog
Q_OBJECT
public:
FindDialog(QWidget *parent = 0);
FindDialog(QWidget *parent = nullptr);
QString getFindText();
public slots:

View File

@ -68,7 +68,7 @@ class AddressBook : public QWidget
Q_OBJECT
public:
AddressBook(QWidget *parent = 0);
AddressBook(QWidget *parent = nullptr);
enum Mode { NavigationMode, AddingMode, EditingMode };
public slots:

View File

@ -63,7 +63,7 @@ class FindDialog : public QDialog
Q_OBJECT
public:
FindDialog(QWidget *parent = 0);
FindDialog(QWidget *parent = nullptr);
QString getFindText();
public slots:

View File

@ -56,7 +56,7 @@ int main(int argc, char *argv[])
{
QApplication a(argc, argv);
QTableView tableView;
MyModel myModel(0);
MyModel myModel;
tableView.setModel(&myModel);
tableView.show();
return a.exec();

View File

@ -69,7 +69,7 @@ private:
private slots:
void selectionChangedSlot(const QItemSelection &newSelection, const QItemSelection &oldSelection);
public:
MainWindow(QWidget *parent = 0);
MainWindow(QWidget *parent = nullptr);
};
#endif // MAINWINDOW_H

View File

@ -72,7 +72,7 @@ class Notepad : public QMainWindow
//! [4]
public:
explicit Notepad(QWidget *parent = 0);
explicit Notepad(QWidget *parent = nullptr);
//! [4]
//! [5]
~Notepad();

View File

@ -50,16 +50,14 @@
#include "openglwindow.h"
#include <QPainter>
#include <QMouseEvent>
#include <QKeyEvent>
#include <QFocusEvent>
#include <QApplication>
#include <QWidget>
#include <QFocusEvent>
#include <QHBoxLayout>
#include <QKeyEvent>
#include <QLineEdit>
#include <QMouseEvent>
#include <QPainter>
#include <QWidget>
// Making use of the class from the opengl example in gui.
@ -67,13 +65,10 @@ class Window : public OpenGLWindow
{
Q_OBJECT
public:
Window()
: m_mouseDown(false)
, m_focus(false)
{
}
using OpenGLWindow::OpenGLWindow;
void render(QPainter *p) override {
void render(QPainter *p) override
{
QLinearGradient g(0, 0, 0, height());
g.setColorAt(0, QColor("lightsteelblue"));
g.setColorAt(1, Qt::black);
@ -93,15 +88,15 @@ public:
p->restore();
}
if (m_focus) {
if (m_focus)
p->drawText(20, height() - 20, QLatin1String("Window has focus!"));
}
p->setRenderHint(QPainter::Antialiasing);
p->drawPolyline(m_polygon);
}
void mousePressEvent(QMouseEvent *e) override {
void mousePressEvent(QMouseEvent *e) override
{
if (!m_mouseDown) {
m_mouseDown = true;
m_polygon.clear();
@ -110,14 +105,16 @@ public:
}
}
void mouseMoveEvent(QMouseEvent *e) override {
void mouseMoveEvent(QMouseEvent *e) override
{
if (m_mouseDown) {
m_polygon.append(e->pos());
renderLater();
}
}
void mouseReleaseEvent(QMouseEvent *e) override {
void mouseReleaseEvent(QMouseEvent *e) override
{
if (m_mouseDown) {
m_mouseDown = false;
m_polygon.append(e->pos());
@ -125,33 +122,35 @@ public:
}
}
void focusInEvent(QFocusEvent *) override {
void focusInEvent(QFocusEvent *) override
{
m_focus = true;
renderLater();
}
void focusOutEvent(QFocusEvent *) override {
void focusOutEvent(QFocusEvent *) override
{
m_focus = false;
m_polygon.clear();
renderLater();
}
void keyPressEvent(QKeyEvent *e) override {
void keyPressEvent(QKeyEvent *e) override
{
m_key = e->text();
renderLater();
}
void keyReleaseEvent(QKeyEvent *) override {
void keyReleaseEvent(QKeyEvent *) override
{
m_key = QString();
renderLater();
}
private:
QPolygon m_polygon;
bool m_mouseDown;
bool m_focus;
QString m_key;
bool m_mouseDown = false;
bool m_focus = false;
};
@ -162,7 +161,7 @@ int main(int argc, char *argv[])
QWidget *widget = new QWidget;
QHBoxLayout *layout = new QHBoxLayout(widget);
Window *window = new Window();
Window *window = new Window;
QWidget *container = QWidget::createWindowContainer(window);
container->setMinimumSize(300, 300);