Cleanup QtCore examples
Cleanup QtCore examples: - use new signal/slot syntax - use 0 instead nullptr - remove unneeded includes - use initializer lists - replace foreach with range-based-for loop Change-Id: I5581f485fa0e9ccf3f4ce6f643908832bc6959bb Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
This commit is contained in:
parent
7910dd0a54
commit
4715ca7bc5
@ -53,14 +53,12 @@
|
||||
|
||||
#include <QDialog>
|
||||
#include <QDataStream>
|
||||
|
||||
#include <qlocalsocket.h>
|
||||
#include <QLocalSocket>
|
||||
|
||||
QT_BEGIN_NAMESPACE
|
||||
class QLabel;
|
||||
class QLineEdit;
|
||||
class QPushButton;
|
||||
class QLocalSocket;
|
||||
QT_END_NAMESPACE
|
||||
|
||||
class Client : public QDialog
|
||||
|
@ -49,9 +49,6 @@
|
||||
****************************************************************************/
|
||||
|
||||
#include <QApplication>
|
||||
#include <QtCore>
|
||||
|
||||
#include <stdlib.h>
|
||||
|
||||
#include "server.h"
|
||||
|
||||
|
@ -48,15 +48,11 @@
|
||||
**
|
||||
****************************************************************************/
|
||||
|
||||
#include "server.h"
|
||||
|
||||
#include <QtWidgets>
|
||||
#include <QtNetwork>
|
||||
|
||||
#include <stdlib.h>
|
||||
|
||||
#include "server.h"
|
||||
#include <qlocalserver.h>
|
||||
#include <qlocalsocket.h>
|
||||
|
||||
Server::Server(QWidget *parent)
|
||||
: QDialog(parent)
|
||||
{
|
||||
|
@ -51,7 +51,6 @@
|
||||
#include "dialog.h"
|
||||
#include <QFileDialog>
|
||||
#include <QBuffer>
|
||||
#include <QtCore/QDebug>
|
||||
|
||||
/*!
|
||||
\class Dialog
|
||||
@ -81,10 +80,10 @@ Dialog::Dialog(QWidget *parent)
|
||||
: QDialog(parent), sharedMemory("QSharedMemoryExample")
|
||||
{
|
||||
ui.setupUi(this);
|
||||
connect(ui.loadFromFileButton, SIGNAL(clicked()), SLOT(loadFromFile()));
|
||||
connect(ui.loadFromSharedMemoryButton,
|
||||
SIGNAL(clicked()),
|
||||
SLOT(loadFromMemory()));
|
||||
connect(ui.loadFromFileButton, &QPushButton::clicked,
|
||||
this, &Dialog::loadFromFile);
|
||||
connect(ui.loadFromSharedMemoryButton, &QPushButton::clicked,
|
||||
this, &Dialog::loadFromMemory);
|
||||
setWindowTitle(tr("SharedMemory Example"));
|
||||
}
|
||||
//! [0]
|
||||
|
@ -51,8 +51,8 @@
|
||||
#ifndef DIALOG_H
|
||||
#define DIALOG_H
|
||||
|
||||
#include <qdialog.h>
|
||||
#include <qsharedmemory.h>
|
||||
#include <QDialog>
|
||||
#include <QSharedMemory>
|
||||
#include "ui_dialog.h"
|
||||
|
||||
//! [0]
|
||||
@ -61,7 +61,7 @@ class Dialog : public QDialog
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
Dialog(QWidget *parent = 0);
|
||||
Dialog(QWidget *parent = nullptr);
|
||||
|
||||
public slots:
|
||||
void loadFromFile();
|
||||
|
@ -55,9 +55,6 @@
|
||||
|
||||
#include <QCommandLineParser>
|
||||
#include <QCommandLineOption>
|
||||
#include <QDebug>
|
||||
#include <QMimeDatabase>
|
||||
#include <QMimeType>
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
|
@ -50,9 +50,8 @@
|
||||
|
||||
#include "mimetypemodel.h"
|
||||
|
||||
#include <QIcon>
|
||||
|
||||
#include <QDebug>
|
||||
#include <QIcon>
|
||||
#include <QMimeDatabase>
|
||||
#include <QTextStream>
|
||||
#include <QVariant>
|
||||
|
@ -56,7 +56,6 @@
|
||||
#include <QCborArray>
|
||||
#include <QCborValue>
|
||||
#include <QDataStream>
|
||||
#include <QDebug>
|
||||
#include <QFloat16>
|
||||
#include <QFile>
|
||||
#include <QMetaType>
|
||||
|
@ -185,7 +185,7 @@ void Game::write(QJsonObject &json) const
|
||||
json["player"] = playerObject;
|
||||
|
||||
QJsonArray levelArray;
|
||||
for (const Level level : mLevels) {
|
||||
for (const Level &level : mLevels) {
|
||||
QJsonObject levelObject;
|
||||
level.write(levelObject);
|
||||
levelArray.append(levelObject);
|
||||
|
@ -97,7 +97,7 @@ void Level::write(QJsonObject &json) const
|
||||
{
|
||||
json["name"] = mName;
|
||||
QJsonArray npcArray;
|
||||
for (const Character npc : mNpcs) {
|
||||
for (const Character &npc : mNpcs) {
|
||||
QJsonObject npcObject;
|
||||
npc.write(npcObject);
|
||||
npcArray.append(npcObject);
|
||||
|
@ -48,14 +48,13 @@
|
||||
**
|
||||
****************************************************************************/
|
||||
|
||||
#include "mandelbrotwidget.h"
|
||||
|
||||
#include <QPainter>
|
||||
#include <QKeyEvent>
|
||||
|
||||
#include <math.h>
|
||||
|
||||
#include "mandelbrotwidget.h"
|
||||
|
||||
|
||||
//! [0]
|
||||
const double DefaultCenterX = -0.637011f;
|
||||
const double DefaultCenterY = -0.0395159f;
|
||||
@ -75,7 +74,8 @@ MandelbrotWidget::MandelbrotWidget(QWidget *parent)
|
||||
pixmapScale = DefaultScale;
|
||||
curScale = DefaultScale;
|
||||
|
||||
connect(&thread, SIGNAL(renderedImage(QImage,double)), this, SLOT(updatePixmap(QImage,double)));
|
||||
connect(&thread, &RenderThread::renderedImage,
|
||||
this, &MandelbrotWidget::updatePixmap);
|
||||
|
||||
setWindowTitle(tr("Mandelbrot"));
|
||||
#ifndef QT_NO_CURSOR
|
||||
|
@ -62,7 +62,7 @@ class MandelbrotWidget : public QWidget
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
MandelbrotWidget(QWidget *parent = 0);
|
||||
MandelbrotWidget(QWidget *parent = nullptr);
|
||||
|
||||
protected:
|
||||
void paintEvent(QPaintEvent *event) override;
|
||||
|
@ -50,7 +50,7 @@
|
||||
|
||||
#include "renderthread.h"
|
||||
|
||||
#include <QtWidgets>
|
||||
#include <QImage>
|
||||
#include <cmath>
|
||||
|
||||
//! [0]
|
||||
|
@ -66,7 +66,7 @@ class RenderThread : public QThread
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
RenderThread(QObject *parent = 0);
|
||||
RenderThread(QObject *parent = nullptr);
|
||||
~RenderThread();
|
||||
|
||||
void render(double centerX, double centerY, double scaleFactor, QSize resultSize);
|
||||
|
@ -48,8 +48,6 @@
|
||||
**
|
||||
****************************************************************************/
|
||||
|
||||
#include <QColor>
|
||||
#include <QRect>
|
||||
#include "block.h"
|
||||
|
||||
Block::Block()
|
||||
@ -57,9 +55,8 @@ Block::Block()
|
||||
}
|
||||
|
||||
Block::Block(const Block &other)
|
||||
: m_rect(other.m_rect), m_color(other.m_color)
|
||||
{
|
||||
m_rect = other.m_rect;
|
||||
m_color = other.m_color;
|
||||
}
|
||||
|
||||
Block::~Block()
|
||||
@ -67,9 +64,8 @@ Block::~Block()
|
||||
}
|
||||
|
||||
Block::Block(const QRect &rect, const QColor &color)
|
||||
: m_rect(rect), m_color(color)
|
||||
{
|
||||
m_rect = rect;
|
||||
m_color = color;
|
||||
}
|
||||
|
||||
QColor Block::color() const
|
||||
|
@ -52,7 +52,6 @@
|
||||
#define BLOCK_H
|
||||
|
||||
#include <QColor>
|
||||
#include <QDebug>
|
||||
#include <QMetaType>
|
||||
#include <QRect>
|
||||
|
||||
|
@ -62,7 +62,7 @@ class RenderThread : public QThread
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
RenderThread(QObject *parent = 0);
|
||||
RenderThread(QObject *parent = nullptr);
|
||||
~RenderThread();
|
||||
|
||||
void processImage(const QImage &image);
|
||||
|
@ -48,30 +48,34 @@
|
||||
**
|
||||
****************************************************************************/
|
||||
|
||||
#include <QtWidgets>
|
||||
#include "window.h"
|
||||
#include <QtWidgets>
|
||||
|
||||
//! [Window constructor start]
|
||||
Window::Window()
|
||||
Window::Window(QWidget *parent)
|
||||
: QWidget(parent), thread(new RenderThread(this))
|
||||
{
|
||||
thread = new RenderThread();
|
||||
//! [Window constructor start] //! [set up widgets and connections]
|
||||
|
||||
label = new QLabel();
|
||||
label = new QLabel(this);
|
||||
label->setAlignment(Qt::AlignCenter);
|
||||
|
||||
loadButton = new QPushButton(tr("&Load image..."));
|
||||
resetButton = new QPushButton(tr("&Stop"));
|
||||
loadButton = new QPushButton(tr("&Load image..."), this);
|
||||
resetButton = new QPushButton(tr("&Stop"), this);
|
||||
resetButton->setEnabled(false);
|
||||
|
||||
connect(loadButton, SIGNAL(clicked()), this, SLOT(loadImage()));
|
||||
connect(resetButton, SIGNAL(clicked()), thread, SLOT(stopProcess()));
|
||||
connect(thread, SIGNAL(finished()), this, SLOT(resetUi()));
|
||||
connect(loadButton, &QPushButton::clicked,
|
||||
this, QOverload<>::of(&Window::loadImage));
|
||||
connect(resetButton, &QPushButton::clicked,
|
||||
thread, &RenderThread::stopProcess);
|
||||
connect(thread, &RenderThread::finished,
|
||||
this, &Window::resetUi);
|
||||
//! [set up widgets and connections] //! [connecting signal with custom type]
|
||||
connect(thread, SIGNAL(sendBlock(Block)), this, SLOT(addBlock(Block)));
|
||||
connect(thread, &RenderThread::sendBlock,
|
||||
this, &Window::addBlock);
|
||||
//! [connecting signal with custom type]
|
||||
|
||||
QHBoxLayout *buttonLayout = new QHBoxLayout();
|
||||
QHBoxLayout *buttonLayout = new QHBoxLayout;
|
||||
buttonLayout->addStretch();
|
||||
buttonLayout->addWidget(loadButton);
|
||||
buttonLayout->addWidget(resetButton);
|
||||
|
@ -65,7 +65,7 @@ class Window : public QWidget
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
Window();
|
||||
Window(QWidget *parent = nullptr);
|
||||
void loadImage(const QImage &image);
|
||||
|
||||
public slots:
|
||||
|
@ -49,7 +49,6 @@
|
||||
****************************************************************************/
|
||||
#include "randomlistmodel.h"
|
||||
#include <QRandomGenerator>
|
||||
#include <stdlib.h>
|
||||
|
||||
static const int bufferSize(500);
|
||||
static const int lookAhead(100);
|
||||
|
@ -59,7 +59,7 @@ class RandomListModel : public QAbstractListModel
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
RandomListModel(QObject *parent = 0);
|
||||
RandomListModel(QObject *parent = nullptr);
|
||||
~RandomListModel();
|
||||
|
||||
int rowCount(const QModelIndex & = QModelIndex()) const override;
|
||||
|
@ -49,6 +49,7 @@
|
||||
****************************************************************************/
|
||||
|
||||
#include <QCoreApplication>
|
||||
#include <QDebug>
|
||||
#include <QVariant>
|
||||
#include "message.h"
|
||||
|
||||
|
@ -50,15 +50,16 @@
|
||||
|
||||
#include "message.h"
|
||||
|
||||
#include <QDebug>
|
||||
|
||||
//! [Message class implementation]
|
||||
Message::Message()
|
||||
{
|
||||
}
|
||||
|
||||
Message::Message(const Message &other)
|
||||
: m_body(other.m_body), m_headers(other.m_headers)
|
||||
{
|
||||
m_body = other.m_body;
|
||||
m_headers = other.m_headers;
|
||||
}
|
||||
|
||||
Message::~Message()
|
||||
@ -67,9 +68,8 @@ Message::~Message()
|
||||
//! [Message class implementation]
|
||||
|
||||
Message::Message(const QString &body, const QStringList &headers)
|
||||
: m_body(body), m_headers(headers)
|
||||
{
|
||||
m_body = body;
|
||||
m_headers = headers;
|
||||
}
|
||||
|
||||
//! [custom type streaming operator]
|
||||
|
@ -51,7 +51,6 @@
|
||||
#ifndef MESSAGE_H
|
||||
#define MESSAGE_H
|
||||
|
||||
#include <QDebug>
|
||||
#include <QMetaType>
|
||||
#include <QStringList>
|
||||
|
||||
|
@ -57,19 +57,20 @@ int main(int argc, char *argv[])
|
||||
{
|
||||
QApplication app(argc, argv);
|
||||
|
||||
Window window1;
|
||||
QStringList headers;
|
||||
headers << "Subject: Hello World"
|
||||
<< "From: address@example.com";
|
||||
QString body = "This is a test.\r\n";
|
||||
Message message(body, headers);
|
||||
|
||||
Window window1;
|
||||
window1.setMessage(message);
|
||||
|
||||
Window window2;
|
||||
QObject::connect(&window1, SIGNAL(messageSent(Message)),
|
||||
&window2, SLOT(setMessage(Message)));
|
||||
QObject::connect(&window2, SIGNAL(messageSent(Message)),
|
||||
&window1, SLOT(setMessage(Message)));
|
||||
QObject::connect(&window1, &Window::messageSent,
|
||||
&window2, &Window::setMessage);
|
||||
QObject::connect(&window2, &Window::messageSent,
|
||||
&window1, &Window::setMessage);
|
||||
window1.show();
|
||||
window2.show();
|
||||
return app.exec();
|
||||
|
@ -55,9 +55,8 @@ Message::Message()
|
||||
}
|
||||
|
||||
Message::Message(const Message &other)
|
||||
: m_body(other.m_body), m_headers(other.m_headers)
|
||||
{
|
||||
m_body = other.m_body;
|
||||
m_headers = other.m_headers;
|
||||
}
|
||||
|
||||
Message::~Message()
|
||||
@ -65,9 +64,8 @@ Message::~Message()
|
||||
}
|
||||
|
||||
Message::Message(const QString &body, const QStringList &headers)
|
||||
: m_body(body), m_headers(headers)
|
||||
{
|
||||
m_body = body;
|
||||
m_headers = headers;
|
||||
}
|
||||
|
||||
QString Message::body() const
|
||||
|
@ -51,7 +51,6 @@
|
||||
#ifndef MESSAGE_H
|
||||
#define MESSAGE_H
|
||||
|
||||
#include <QDebug>
|
||||
#include <QMetaType>
|
||||
#include <QStringList>
|
||||
|
||||
|
@ -52,14 +52,15 @@
|
||||
#include "window.h"
|
||||
|
||||
//! [Window constructor]
|
||||
Window::Window()
|
||||
Window::Window(QWidget *parent)
|
||||
: QWidget(parent), editor(new QTextEdit(this))
|
||||
{
|
||||
editor = new QTextEdit();
|
||||
QPushButton *sendButton = new QPushButton(tr("&Send message"));
|
||||
|
||||
connect(sendButton, SIGNAL(clicked()), this, SLOT(sendMessage()));
|
||||
connect(sendButton, &QPushButton::clicked,
|
||||
this, &Window::sendMessage);
|
||||
|
||||
QHBoxLayout *buttonLayout = new QHBoxLayout();
|
||||
QHBoxLayout *buttonLayout = new QHBoxLayout;
|
||||
buttonLayout->addStretch();
|
||||
buttonLayout->addWidget(sendButton);
|
||||
buttonLayout->addStretch();
|
||||
|
@ -62,7 +62,7 @@ class Window : public QWidget
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
Window();
|
||||
Window(QWidget *parent = nullptr);
|
||||
|
||||
signals:
|
||||
void messageSent(const Message &message);
|
||||
|
Loading…
Reference in New Issue
Block a user