From 578c96f0bbe281f710248f0015ec133fa0083b48 Mon Sep 17 00:00:00 2001 From: Friedemann Kleint Date: Mon, 23 Apr 2018 10:55:33 +0200 Subject: Polish the manual touch test Introduce C++11, nullptr, for, port to Qt 5 connection syntax. Change-Id: I2d233ccd68bad533af8d4674d91236b2c049e997 Reviewed-by: Andy Shaw --- tests/manual/touch/main.cpp | 30 ++++++++++++++++-------------- 1 file changed, 16 insertions(+), 14 deletions(-) (limited to 'tests/manual/touch') diff --git a/tests/manual/touch/main.cpp b/tests/manual/touch/main.cpp index d3c6079c7d..9f2dcb3842 100644 --- a/tests/manual/touch/main.cpp +++ b/tests/manual/touch/main.cpp @@ -47,8 +47,8 @@ #include #include -bool optIgnoreTouch = false; -QVector optGestures; +static bool optIgnoreTouch = false; +static QVector optGestures; static inline void drawEllipse(const QPointF ¢er, qreal hDiameter, qreal vDiameter, const QColor &color, QPainter &painter) { @@ -275,10 +275,10 @@ class TouchTestWidget : public QWidget { Q_OBJECT Q_PROPERTY(bool drawPoints READ drawPoints WRITE setDrawPoints) public: - explicit TouchTestWidget(QWidget *parent = 0) : QWidget(parent), m_drawPoints(true) + explicit TouchTestWidget(QWidget *parent = nullptr) : QWidget(parent), m_drawPoints(true) { setAttribute(Qt::WA_AcceptTouchEvents); - foreach (Qt::GestureType t, optGestures) + for (Qt::GestureType t : optGestures) grabGesture(t); } @@ -337,10 +337,11 @@ bool TouchTestWidget::event(QEvent *event) case QEvent::TouchBegin: case QEvent::TouchUpdate: if (m_drawPoints) { - foreach (const QTouchEvent::TouchPoint &p, static_cast(event)->touchPoints()) + for (const QTouchEvent::TouchPoint &p : static_cast(event)->touchPoints()) m_points.append(Point(p.pos(), TouchPoint, Qt::MouseEventNotSynthesized, p.ellipseDiameters())); update(); } + Q_FALLTHROUGH(); case QEvent::TouchEnd: if (optIgnoreTouch) event->ignore(); @@ -358,7 +359,8 @@ bool TouchTestWidget::event(QEvent *event) void TouchTestWidget::handleGestureEvent(QGestureEvent *gestureEvent) { - foreach (QGesture *gesture, gestureEvent->gestures()) { + const auto gestures = gestureEvent->gestures(); + for (QGesture *gesture : gestures) { if (optGestures.contains(gesture->gestureType())) { switch (gesture->state()) { case Qt::NoGesture: @@ -389,7 +391,7 @@ void TouchTestWidget::paintEvent(QPaintEvent *) const QRectF geom = QRectF(QPointF(0, 0), QSizeF(size())); painter.fillRect(geom, Qt::white); painter.drawRect(QRectF(geom.topLeft(), geom.bottomRight() - QPointF(1, 1))); - foreach (const Point &point, m_points) { + for (const Point &point : qAsConst(m_points)) { if (geom.contains(point.pos)) { if (point.type == MouseRelease) drawEllipse(point.pos, point.horizontalDiameter, point.verticalDiameter, point.color(), painter); @@ -397,7 +399,7 @@ void TouchTestWidget::paintEvent(QPaintEvent *) fillEllipse(point.pos, point.horizontalDiameter, point.verticalDiameter, point.color(), painter); } } - foreach (const GesturePtr &gp, m_gestures) + for (const GesturePtr &gp : qAsConst(m_gestures)) gp->draw(geom, painter); } @@ -429,24 +431,24 @@ MainWindow::MainWindow() QMenu *fileMenu = menuBar()->addMenu("File"); QAction *dumpDeviceAction = fileMenu->addAction(QStringLiteral("Dump devices")); dumpDeviceAction->setShortcut(QKeySequence(Qt::CTRL + Qt::Key_D)); - connect(dumpDeviceAction, SIGNAL(triggered()), this, SLOT(dumpTouchDevices())); + connect(dumpDeviceAction, &QAction::triggered, this, &MainWindow::dumpTouchDevices); toolBar->addAction(dumpDeviceAction); QAction *clearLogAction = fileMenu->addAction(QStringLiteral("Clear Log")); clearLogAction->setShortcut(QKeySequence(Qt::CTRL + Qt::Key_L)); - connect(clearLogAction, SIGNAL(triggered()), m_logTextEdit, SLOT(clear())); + connect(clearLogAction, &QAction::triggered, m_logTextEdit, &QPlainTextEdit::clear); toolBar->addAction(clearLogAction); QAction *toggleDrawPointAction = fileMenu->addAction(QStringLiteral("Draw Points")); toggleDrawPointAction->setCheckable(true); toggleDrawPointAction->setChecked(m_touchWidget->drawPoints()); - connect(toggleDrawPointAction, SIGNAL(toggled(bool)), m_touchWidget, SLOT(setDrawPoints(bool))); + connect(toggleDrawPointAction, &QAction::toggled, m_touchWidget, &TouchTestWidget::setDrawPoints); toolBar->addAction(toggleDrawPointAction); QAction *clearPointAction = fileMenu->addAction(QStringLiteral("Clear Points")); clearPointAction->setShortcut(QKeySequence(Qt::CTRL + Qt::Key_P)); - connect(clearPointAction, SIGNAL(triggered()), m_touchWidget, SLOT(clearPoints())); + connect(clearPointAction, &QAction::triggered, m_touchWidget, &TouchTestWidget::clearPoints); toolBar->addAction(clearPointAction); QAction *quitAction = fileMenu->addAction(QStringLiteral("Quit")); quitAction->setShortcut(QKeySequence(Qt::CTRL + Qt::Key_Q)); - connect(quitAction, SIGNAL(triggered()), this, SLOT(close())); + connect(quitAction, &QAction::triggered, qApp, &QCoreApplication::quit); toolBar->addAction(quitAction); QSplitter *mainSplitter = new QSplitter(Qt::Vertical, this); @@ -541,7 +543,7 @@ int main(int argc, char *argv[]) : static_cast(w.touchWidget()); EventFilter *filter = new EventFilter(eventTypes, filterTarget); filterTarget->installEventFilter(filter); - QObject::connect(filter, SIGNAL(eventReceived(QString)), &w, SLOT(appendToLog(QString))); + QObject::connect(filter, &EventFilter::eventReceived, &w, &MainWindow::appendToLog); return a.exec(); } -- cgit v1.2.3