From cf27d9e8a5e14ebe083f4b0fa2204d0646e7ed5e Mon Sep 17 00:00:00 2001 From: Christian Ehrlicher Date: Fri, 7 Dec 2018 14:17:02 +0100 Subject: Cleanup Widgets examples - new signal/slot syntax MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Cleanup the Widget examples - use the new signal/slot syntax where possible - painting and richtext subdirectory Change-Id: If0e365ab1cabf9184076595494cfca151406fddf Reviewed-by: Luca Beldi Reviewed-by: Topi Reiniƶ --- examples/widgets/painting/basicdrawing/window.cpp | 32 +++++------ .../widgets/painting/composition/composition.cpp | 62 +++++++++++----------- .../widgets/painting/concentriccircles/window.cpp | 4 +- examples/widgets/painting/deform/pathdeform.cpp | 43 ++++++++------- .../widgets/painting/fontsampler/mainwindow.cpp | 15 +++--- examples/widgets/painting/gradients/gradients.cpp | 2 +- .../painting/imagecomposition/imagecomposer.cpp | 9 ++-- examples/widgets/painting/painterpaths/window.cpp | 42 +++++++++------ .../widgets/painting/pathstroke/pathstroke.cpp | 56 +++++++++---------- examples/widgets/painting/shared/hoverpoints.cpp | 4 +- .../widgets/painting/transformations/window.cpp | 7 +-- examples/widgets/richtext/calendar/mainwindow.cpp | 10 ++-- examples/widgets/richtext/orderform/mainwindow.cpp | 2 +- .../richtext/syntaxhighlighter/mainwindow.cpp | 13 +++-- 14 files changed, 161 insertions(+), 140 deletions(-) diff --git a/examples/widgets/painting/basicdrawing/window.cpp b/examples/widgets/painting/basicdrawing/window.cpp index c80237e914..65f6971d13 100644 --- a/examples/widgets/painting/basicdrawing/window.cpp +++ b/examples/widgets/painting/basicdrawing/window.cpp @@ -157,22 +157,22 @@ Window::Window() //! [7] //! [8] - connect(shapeComboBox, SIGNAL(activated(int)), - this, SLOT(shapeChanged())); - connect(penWidthSpinBox, SIGNAL(valueChanged(int)), - this, SLOT(penChanged())); - connect(penStyleComboBox, SIGNAL(activated(int)), - this, SLOT(penChanged())); - connect(penCapComboBox, SIGNAL(activated(int)), - this, SLOT(penChanged())); - connect(penJoinComboBox, SIGNAL(activated(int)), - this, SLOT(penChanged())); - connect(brushStyleComboBox, SIGNAL(activated(int)), - this, SLOT(brushChanged())); - connect(antialiasingCheckBox, SIGNAL(toggled(bool)), - renderArea, SLOT(setAntialiased(bool))); - connect(transformationsCheckBox, SIGNAL(toggled(bool)), - renderArea, SLOT(setTransformed(bool))); + connect(shapeComboBox, QOverload::of(&QComboBox::activated), + this, &Window::shapeChanged); + connect(penWidthSpinBox, QOverload::of(&QSpinBox::valueChanged), + this, &Window::penChanged); + connect(penStyleComboBox, QOverload::of(&QComboBox::activated), + this, &Window::penChanged); + connect(penCapComboBox, QOverload::of(&QComboBox::activated), + this, &Window::penChanged); + connect(penJoinComboBox, QOverload::of(&QComboBox::activated), + this, &Window::penChanged); + connect(brushStyleComboBox, QOverload::of(&QComboBox::activated), + this, &Window::brushChanged); + connect(antialiasingCheckBox, &QAbstractButton::toggled, + renderArea, &RenderArea::setAntialiased); + connect(transformationsCheckBox, &QAbstractButton::toggled, + renderArea, &RenderArea::setTransformed); //! [8] //! [9] diff --git a/examples/widgets/painting/composition/composition.cpp b/examples/widgets/painting/composition/composition.cpp index e0abc5875c..96088cca4a 100644 --- a/examples/widgets/painting/composition/composition.cpp +++ b/examples/widgets/painting/composition/composition.cpp @@ -76,68 +76,68 @@ CompositionWidget::CompositionWidget(QWidget *parent) modesGroup->setTitle(tr("Mode")); rbClear = new QRadioButton(tr("Clear"), modesGroup); - connect(rbClear, SIGNAL(clicked()), view, SLOT(setClearMode())); + connect(rbClear, &QAbstractButton::clicked, view, &CompositionRenderer::setClearMode); rbSource = new QRadioButton(tr("Source"), modesGroup); - connect(rbSource, SIGNAL(clicked()), view, SLOT(setSourceMode())); + connect(rbSource, &QAbstractButton::clicked, view, &CompositionRenderer::setSourceMode); rbDest = new QRadioButton(tr("Destination"), modesGroup); - connect(rbDest, SIGNAL(clicked()), view, SLOT(setDestMode())); + connect(rbDest, &QAbstractButton::clicked, view, &CompositionRenderer::setDestMode); rbSourceOver = new QRadioButton(tr("Source Over"), modesGroup); - connect(rbSourceOver, SIGNAL(clicked()), view, SLOT(setSourceOverMode())); + connect(rbSourceOver, &QAbstractButton::clicked, view, &CompositionRenderer::setSourceOverMode); rbDestOver = new QRadioButton(tr("Destination Over"), modesGroup); - connect(rbDestOver, SIGNAL(clicked()), view, SLOT(setDestOverMode())); + connect(rbDestOver, &QAbstractButton::clicked, view, &CompositionRenderer::setDestOverMode); rbSourceIn = new QRadioButton(tr("Source In"), modesGroup); - connect(rbSourceIn, SIGNAL(clicked()), view, SLOT(setSourceInMode())); + connect(rbSourceIn, &QAbstractButton::clicked, view, &CompositionRenderer::setSourceInMode); rbDestIn = new QRadioButton(tr("Dest In"), modesGroup); - connect(rbDestIn, SIGNAL(clicked()), view, SLOT(setDestInMode())); + connect(rbDestIn, &QAbstractButton::clicked, view, &CompositionRenderer::setDestInMode); rbSourceOut = new QRadioButton(tr("Source Out"), modesGroup); - connect(rbSourceOut, SIGNAL(clicked()), view, SLOT(setSourceOutMode())); + connect(rbSourceOut, &QAbstractButton::clicked, view, &CompositionRenderer::setSourceOutMode); rbDestOut = new QRadioButton(tr("Dest Out"), modesGroup); - connect(rbDestOut, SIGNAL(clicked()), view, SLOT(setDestOutMode())); + connect(rbDestOut, &QAbstractButton::clicked, view, &CompositionRenderer::setDestOutMode); rbSourceAtop = new QRadioButton(tr("Source Atop"), modesGroup); - connect(rbSourceAtop, SIGNAL(clicked()), view, SLOT(setSourceAtopMode())); + connect(rbSourceAtop, &QAbstractButton::clicked, view, &CompositionRenderer::setSourceAtopMode); rbDestAtop = new QRadioButton(tr("Dest Atop"), modesGroup); - connect(rbDestAtop, SIGNAL(clicked()), view, SLOT(setDestAtopMode())); + connect(rbDestAtop, &QAbstractButton::clicked, view, &CompositionRenderer::setDestAtopMode); rbXor = new QRadioButton(tr("Xor"), modesGroup); - connect(rbXor, SIGNAL(clicked()), view, SLOT(setXorMode())); + connect(rbXor, &QAbstractButton::clicked, view, &CompositionRenderer::setXorMode); rbPlus = new QRadioButton(tr("Plus"), modesGroup); - connect(rbPlus, SIGNAL(clicked()), view, SLOT(setPlusMode())); + connect(rbPlus, &QAbstractButton::clicked, view, &CompositionRenderer::setPlusMode); rbMultiply = new QRadioButton(tr("Multiply"), modesGroup); - connect(rbMultiply, SIGNAL(clicked()), view, SLOT(setMultiplyMode())); + connect(rbMultiply, &QAbstractButton::clicked, view, &CompositionRenderer::setMultiplyMode); rbScreen = new QRadioButton(tr("Screen"), modesGroup); - connect(rbScreen, SIGNAL(clicked()), view, SLOT(setScreenMode())); + connect(rbScreen, &QAbstractButton::clicked, view, &CompositionRenderer::setScreenMode); rbOverlay = new QRadioButton(tr("Overlay"), modesGroup); - connect(rbOverlay, SIGNAL(clicked()), view, SLOT(setOverlayMode())); + connect(rbOverlay, &QAbstractButton::clicked, view, &CompositionRenderer::setOverlayMode); rbDarken = new QRadioButton(tr("Darken"), modesGroup); - connect(rbDarken, SIGNAL(clicked()), view, SLOT(setDarkenMode())); + connect(rbDarken, &QAbstractButton::clicked, view, &CompositionRenderer::setDarkenMode); rbLighten = new QRadioButton(tr("Lighten"), modesGroup); - connect(rbLighten, SIGNAL(clicked()), view, SLOT(setLightenMode())); + connect(rbLighten, &QAbstractButton::clicked, view, &CompositionRenderer::setLightenMode); rbColorDodge = new QRadioButton(tr("Color Dodge"), modesGroup); - connect(rbColorDodge, SIGNAL(clicked()), view, SLOT(setColorDodgeMode())); + connect(rbColorDodge, &QAbstractButton::clicked, view, &CompositionRenderer::setColorDodgeMode); rbColorBurn = new QRadioButton(tr("Color Burn"), modesGroup); - connect(rbColorBurn, SIGNAL(clicked()), view, SLOT(setColorBurnMode())); + connect(rbColorBurn, &QAbstractButton::clicked, view, &CompositionRenderer::setColorBurnMode); rbHardLight = new QRadioButton(tr("Hard Light"), modesGroup); - connect(rbHardLight, SIGNAL(clicked()), view, SLOT(setHardLightMode())); + connect(rbHardLight, &QAbstractButton::clicked, view, &CompositionRenderer::setHardLightMode); rbSoftLight = new QRadioButton(tr("Soft Light"), modesGroup); - connect(rbSoftLight, SIGNAL(clicked()), view, SLOT(setSoftLightMode())); + connect(rbSoftLight, &QAbstractButton::clicked, view, &CompositionRenderer::setSoftLightMode); rbDifference = new QRadioButton(tr("Difference"), modesGroup); - connect(rbDifference, SIGNAL(clicked()), view, SLOT(setDifferenceMode())); + connect(rbDifference, &QAbstractButton::clicked, view, &CompositionRenderer::setDifferenceMode); rbExclusion = new QRadioButton(tr("Exclusion"), modesGroup); - connect(rbExclusion, SIGNAL(clicked()), view, SLOT(setExclusionMode())); + connect(rbExclusion, &QAbstractButton::clicked, view, &CompositionRenderer::setExclusionMode); QGroupBox *circleColorGroup = new QGroupBox(mainGroup); circleColorGroup->setTitle(tr("Circle color")); QSlider *circleColorSlider = new QSlider(Qt::Horizontal, circleColorGroup); circleColorSlider->setRange(0, 359); circleColorSlider->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Fixed); - connect(circleColorSlider, SIGNAL(valueChanged(int)), view, SLOT(setCircleColor(int))); + connect(circleColorSlider, &QAbstractSlider::valueChanged, view, &CompositionRenderer::setCircleColor); QGroupBox *circleAlphaGroup = new QGroupBox(mainGroup); circleAlphaGroup->setTitle(tr("Circle alpha")); QSlider *circleAlphaSlider = new QSlider(Qt::Horizontal, circleAlphaGroup); circleAlphaSlider->setRange(0, 255); circleAlphaSlider->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Fixed); - connect(circleAlphaSlider, SIGNAL(valueChanged(int)), view, SLOT(setCircleAlpha(int))); + connect(circleAlphaSlider, &QAbstractSlider::valueChanged, view, &CompositionRenderer::setCircleAlpha); QPushButton *showSourceButton = new QPushButton(mainGroup); showSourceButton->setText(tr("Show Source")); @@ -209,13 +209,13 @@ CompositionWidget::CompositionWidget(QWidget *parent) view->loadDescription(":res/composition/composition.html"); view->loadSourceFile(":res/composition/composition.cpp"); - connect(whatsThisButton, SIGNAL(clicked(bool)), view, SLOT(setDescriptionEnabled(bool))); - connect(view, SIGNAL(descriptionEnabledChanged(bool)), whatsThisButton, SLOT(setChecked(bool))); - connect(showSourceButton, SIGNAL(clicked()), view, SLOT(showSource())); + connect(whatsThisButton, &QAbstractButton::clicked, view, &ArthurFrame::setDescriptionEnabled); + connect(view, &ArthurFrame::descriptionEnabledChanged, whatsThisButton, &QAbstractButton::setChecked); + connect(showSourceButton, &QAbstractButton::clicked, view, &ArthurFrame::showSource); #if QT_CONFIG(opengl) - connect(enableOpenGLButton, SIGNAL(clicked(bool)), view, SLOT(enableOpenGL(bool))); + connect(enableOpenGLButton, &QAbstractButton::clicked, view, &ArthurFrame::enableOpenGL); #endif - connect(animateButton, SIGNAL(toggled(bool)), view, SLOT(setAnimationEnabled(bool))); + connect(animateButton, &QAbstractButton::toggled, view, &CompositionRenderer::setAnimationEnabled); circleColorSlider->setValue(270); circleAlphaSlider->setValue(200); diff --git a/examples/widgets/painting/concentriccircles/window.cpp b/examples/widgets/painting/concentriccircles/window.cpp index 0f65dc2285..45258e0bc4 100644 --- a/examples/widgets/painting/concentriccircles/window.cpp +++ b/examples/widgets/painting/concentriccircles/window.cpp @@ -77,8 +77,8 @@ Window::Window() circleWidgets[i][j]->setAntialiased(j != 0); circleWidgets[i][j]->setFloatBased(i != 0); - connect(timer, SIGNAL(timeout()), - circleWidgets[i][j], SLOT(nextAnimationFrame())); + connect(timer, &QTimer::timeout, + circleWidgets[i][j], &CircleWidget::nextAnimationFrame); layout->addWidget(circleWidgets[i][j], i + 1, j + 1); } diff --git a/examples/widgets/painting/deform/pathdeform.cpp b/examples/widgets/painting/deform/pathdeform.cpp index 7c3fe45277..3b80c40e9b 100644 --- a/examples/widgets/painting/deform/pathdeform.cpp +++ b/examples/widgets/painting/deform/pathdeform.cpp @@ -152,19 +152,19 @@ void PathDeformControls::layoutForDesktop() mainLayout->addWidget(mainGroup); mainLayout->setMargin(0); - connect(radiusSlider, SIGNAL(valueChanged(int)), m_renderer, SLOT(setRadius(int))); - connect(deformSlider, SIGNAL(valueChanged(int)), m_renderer, SLOT(setIntensity(int))); - connect(fontSizeSlider, SIGNAL(valueChanged(int)), m_renderer, SLOT(setFontSize(int))); - connect(animateButton, SIGNAL(clicked(bool)), m_renderer, SLOT(setAnimated(bool))); + connect(radiusSlider, &QAbstractSlider::valueChanged, m_renderer, &PathDeformRenderer::setRadius); + connect(deformSlider, &QAbstractSlider::valueChanged, m_renderer, &PathDeformRenderer::setIntensity); + connect(fontSizeSlider, &QAbstractSlider::valueChanged, m_renderer, &PathDeformRenderer::setFontSize); + connect(animateButton, &QAbstractButton::clicked, m_renderer, &PathDeformRenderer::setAnimated); #if QT_CONFIG(opengl) - connect(enableOpenGLButton, SIGNAL(clicked(bool)), m_renderer, SLOT(enableOpenGL(bool))); + connect(enableOpenGLButton, &QAbstractButton::clicked, m_renderer, &ArthurFrame::enableOpenGL); #endif - connect(textInput, SIGNAL(textChanged(QString)), m_renderer, SLOT(setText(QString))); - connect(m_renderer, SIGNAL(descriptionEnabledChanged(bool)), - whatsThisButton, SLOT(setChecked(bool))); - connect(whatsThisButton, SIGNAL(clicked(bool)), m_renderer, SLOT(setDescriptionEnabled(bool))); - connect(showSourceButton, SIGNAL(clicked()), m_renderer, SLOT(showSource())); + connect(textInput, &QLineEdit::textChanged, m_renderer, &PathDeformRenderer::setText); + connect(m_renderer, &ArthurFrame::descriptionEnabledChanged, + whatsThisButton, &QAbstractButton::setChecked); + connect(whatsThisButton, &QAbstractButton::clicked, m_renderer, &ArthurFrame::setDescriptionEnabled); + connect(showSourceButton, &QAbstractButton::clicked, m_renderer, &ArthurFrame::showSource); animateButton->animateClick(); deformSlider->setValue(80); @@ -229,14 +229,14 @@ void PathDeformControls::layoutForSmallScreen() mainLayout->addWidget(okButton); mainLayout->addWidget(quitButton); - connect(quitButton, SIGNAL(clicked()), this, SIGNAL(quitPressed())); - connect(okButton, SIGNAL(clicked()), this, SIGNAL(okPressed())); - connect(radiusSlider, SIGNAL(valueChanged(int)), m_renderer, SLOT(setRadius(int))); - connect(deformSlider, SIGNAL(valueChanged(int)), m_renderer, SLOT(setIntensity(int))); - connect(fontSizeSlider, SIGNAL(valueChanged(int)), m_renderer, SLOT(setFontSize(int))); - connect(animateButton, SIGNAL(clicked(bool)), m_renderer, SLOT(setAnimated(bool))); + connect(quitButton, &QAbstractButton::clicked, this, &PathDeformControls::quitPressed); + connect(okButton, &QAbstractButton::clicked, this, &PathDeformControls::okPressed); + connect(radiusSlider, &QAbstractSlider::valueChanged, m_renderer, &PathDeformRenderer::setRadius); + connect(deformSlider, &QAbstractSlider::valueChanged, m_renderer, &PathDeformRenderer::setIntensity); + connect(fontSizeSlider, &QAbstractSlider::valueChanged, m_renderer, &PathDeformRenderer::setFontSize); + connect(animateButton, &QAbstractButton::clicked, m_renderer, &PathDeformRenderer::setAnimated); #if QT_CONFIG(opengl) - connect(enableOpenGLButton, SIGNAL(clicked(bool)), m_renderer, SLOT(enableOpenGL(bool))); + connect(enableOpenGLButton, &QAbstractButton::clicked, m_renderer, &ArthurFrame::enableOpenGL); #endif @@ -272,9 +272,12 @@ PathDeformWidget::PathDeformWidget(QWidget *parent, bool smallScreen) m_renderer->loadDescription(":res/deform/pathdeform.html"); m_renderer->setDescriptionEnabled(false); - connect(m_renderer, SIGNAL(clicked()), this, SLOT(showControls())); - connect(m_controls, SIGNAL(okPressed()), this, SLOT(hideControls())); - connect(m_controls, SIGNAL(quitPressed()), QCoreApplication::instance(), SLOT(quit())); + connect(m_renderer, &PathDeformRenderer::clicked, + this, &PathDeformWidget::showControls); + connect(m_controls, &PathDeformControls::okPressed, + this, &PathDeformWidget::hideControls); + connect(m_controls, &PathDeformControls::quitPressed, + qApp, &QCoreApplication::quit); } diff --git a/examples/widgets/painting/fontsampler/mainwindow.cpp b/examples/widgets/painting/fontsampler/mainwindow.cpp index bd15438df9..6344806f29 100644 --- a/examples/widgets/painting/fontsampler/mainwindow.cpp +++ b/examples/widgets/painting/fontsampler/mainwindow.cpp @@ -71,11 +71,12 @@ MainWindow::MainWindow(QWidget *parent) markedCount = 0; setupFontTree(); - connect(quitAction, SIGNAL(triggered()), qApp, SLOT(quit())); - connect(fontTree, SIGNAL(currentItemChanged(QTreeWidgetItem*,QTreeWidgetItem*)), - this, SLOT(showFont(QTreeWidgetItem*))); - connect(fontTree, SIGNAL(itemChanged(QTreeWidgetItem*,int)), - this, SLOT(updateStyles(QTreeWidgetItem*,int))); + connect(quitAction, &QAction::triggered, + qApp, &QApplication::quit); + connect(fontTree, &QTreeWidget::currentItemChanged, + this, &MainWindow::showFont); + connect(fontTree, &QTreeWidget::itemChanged, + this, &MainWindow::updateStyles); fontTree->setItemSelected(fontTree->topLevelItem(0), true); showFont(fontTree->topLevelItem(0)); @@ -285,8 +286,8 @@ void MainWindow::on_printPreviewAction_triggered() QPrinter printer(QPrinter::HighResolution); QPrintPreviewDialog preview(&printer, this); - connect(&preview, SIGNAL(paintRequested(QPrinter*)), - this, SLOT(printDocument(QPrinter*))); + connect(&preview, &QPrintPreviewDialog::paintRequested, + this, &MainWindow::printDocument); preview.exec(); #endif } diff --git a/examples/widgets/painting/gradients/gradients.cpp b/examples/widgets/painting/gradients/gradients.cpp index 004f6710cd..fd6eaeb0d9 100644 --- a/examples/widgets/painting/gradients/gradients.cpp +++ b/examples/widgets/painting/gradients/gradients.cpp @@ -421,7 +421,7 @@ GradientWidget::GradientWidget(QWidget *parent) m_renderer->loadSourceFile(":res/gradients/gradients.cpp"); m_renderer->loadDescription(":res/gradients/gradients.html"); - QTimer::singleShot(50, this, SLOT(setDefault1())); + QTimer::singleShot(50, this, &GradientWidget::setDefault1); } void GradientWidget::setDefault(int config) diff --git a/examples/widgets/painting/imagecomposition/imagecomposer.cpp b/examples/widgets/painting/imagecomposition/imagecomposer.cpp index d53017b955..ffdc8f433c 100644 --- a/examples/widgets/painting/imagecomposition/imagecomposer.cpp +++ b/examples/widgets/painting/imagecomposition/imagecomposer.cpp @@ -100,9 +100,12 @@ ImageComposer::ImageComposer() //! [2] //! [3] - connect(sourceButton, SIGNAL(clicked()), this, SLOT(chooseSource())); - connect(operatorComboBox, SIGNAL(activated(int)), this, SLOT(recalculateResult())); - connect(destinationButton, SIGNAL(clicked()), this, SLOT(chooseDestination())); + connect(sourceButton, &QAbstractButton::clicked, + this, &ImageComposer::chooseSource); + connect(operatorComboBox, QOverload::of(&QComboBox::activated), + this, &ImageComposer::recalculateResult); + connect(destinationButton, &QAbstractButton::clicked, + this, &ImageComposer::chooseDestination); //! [3] //! [4] diff --git a/examples/widgets/painting/painterpaths/window.cpp b/examples/widgets/painting/painterpaths/window.cpp index a987937b39..95e312623e 100644 --- a/examples/widgets/painting/painterpaths/window.cpp +++ b/examples/widgets/painting/painterpaths/window.cpp @@ -194,22 +194,30 @@ Window::Window() //! [12] //! [16] - connect(fillRuleComboBox, SIGNAL(activated(int)), this, SLOT(fillRuleChanged())); - connect(fillColor1ComboBox, SIGNAL(activated(int)), this, SLOT(fillGradientChanged())); - connect(fillColor2ComboBox, SIGNAL(activated(int)), this, SLOT(fillGradientChanged())); - connect(penColorComboBox, SIGNAL(activated(int)), this, SLOT(penColorChanged())); - - for(QList::iterator it = renderAreas.begin(); it != renderAreas.end(); it++) { - connect(penWidthSpinBox, SIGNAL(valueChanged(int)), *it, SLOT(setPenWidth(int))); - connect(rotationAngleSpinBox, SIGNAL(valueChanged(int)), *it, SLOT(setRotationAngle(int))); + connect(fillRuleComboBox, QOverload::of(&QComboBox::activated), + this, &Window::fillRuleChanged); + connect(fillColor1ComboBox, QOverload::of(&QComboBox::activated), + this, &Window::fillGradientChanged); + connect(fillColor2ComboBox, QOverload::of(&QComboBox::activated), + this, &Window::fillGradientChanged); + connect(penColorComboBox, QOverload::of(&QComboBox::activated), + this, &Window::penColorChanged); + + for (RenderArea *area : qAsConst(renderAreas)) { + connect(penWidthSpinBox, QOverload::of(&QSpinBox::valueChanged), + area, &RenderArea::setPenWidth); + connect(rotationAngleSpinBox, QOverload::of(&QSpinBox::valueChanged), + area, &RenderArea::setRotationAngle); } //! [16] //! [17] QGridLayout *topLayout = new QGridLayout; - int i=0; - for(QList::iterator it = renderAreas.begin(); it != renderAreas.end(); it++, i++) - topLayout->addWidget(*it, i / 3, i % 3); + int i = 0; + for (RenderArea *area : qAsConst(renderAreas)) { + topLayout->addWidget(area, i / 3, i % 3); + ++i; + } QGridLayout *mainLayout = new QGridLayout; mainLayout->addLayout(topLayout, 0, 0, 1, 4); @@ -243,8 +251,8 @@ void Window::fillRuleChanged() { Qt::FillRule rule = (Qt::FillRule)currentItemData(fillRuleComboBox).toInt(); - for (QList::iterator it = renderAreas.begin(); it != renderAreas.end(); ++it) - (*it)->setFillRule(rule); + for (RenderArea *area : qAsConst(renderAreas)) + area->setFillRule(rule); } //! [19] @@ -254,8 +262,8 @@ void Window::fillGradientChanged() QColor color1 = qvariant_cast(currentItemData(fillColor1ComboBox)); QColor color2 = qvariant_cast(currentItemData(fillColor2ComboBox)); - for (QList::iterator it = renderAreas.begin(); it != renderAreas.end(); ++it) - (*it)->setFillGradient(color1, color2); + for (RenderArea *area : qAsConst(renderAreas)) + area->setFillGradient(color1, color2); } //! [20] @@ -264,8 +272,8 @@ void Window::penColorChanged() { QColor color = qvariant_cast(currentItemData(penColorComboBox)); - for (QList::iterator it = renderAreas.begin(); it != renderAreas.end(); ++it) - (*it)->setPenColor(color); + for (RenderArea *area : qAsConst(renderAreas)) + area->setPenColor(color); } //! [21] diff --git a/examples/widgets/painting/pathstroke/pathstroke.cpp b/examples/widgets/painting/pathstroke/pathstroke.cpp index b04998afac..acb946496f 100644 --- a/examples/widgets/painting/pathstroke/pathstroke.cpp +++ b/examples/widgets/painting/pathstroke/pathstroke.cpp @@ -164,24 +164,24 @@ void PathStrokeControls::createCommonControls(QWidget* parent) // Connections - connect(flatCap, SIGNAL(clicked()), m_renderer, SLOT(setFlatCap())); - connect(squareCap, SIGNAL(clicked()), m_renderer, SLOT(setSquareCap())); - connect(roundCap, SIGNAL(clicked()), m_renderer, SLOT(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, SIGNAL(clicked()), m_renderer, SLOT(setBevelJoin())); - connect(miterJoin, SIGNAL(clicked()), m_renderer, SLOT(setMiterJoin())); - connect(svgMiterJoin, SIGNAL(clicked()), m_renderer, SLOT(setSvgMiterJoin())); - connect(roundJoin, SIGNAL(clicked()), m_renderer, SLOT(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, SIGNAL(clicked()), m_renderer, SLOT(setCurveMode())); - connect(lineMode, SIGNAL(clicked()), m_renderer, SLOT(setLineMode())); + connect(curveMode, &QAbstractButton::clicked, m_renderer, &PathStrokeRenderer::setCurveMode); + connect(lineMode, &QAbstractButton::clicked, m_renderer, &PathStrokeRenderer::setLineMode); - connect(solidLine, SIGNAL(clicked()), m_renderer, SLOT(setSolidLine())); - connect(dashLine, SIGNAL(clicked()), m_renderer, SLOT(setDashLine())); - connect(dotLine, SIGNAL(clicked()), m_renderer, SLOT(setDotLine())); - connect(dashDotLine, SIGNAL(clicked()), m_renderer, SLOT(setDashDotLine())); - connect(dashDotDotLine, SIGNAL(clicked()), m_renderer, SLOT(setDashDotDotLine())); - connect(customDashLine, SIGNAL(clicked()), m_renderer, SLOT(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,17 +247,17 @@ void PathStrokeControls::layoutForDesktop() // Set up connections - connect(animated, SIGNAL(toggled(bool)), m_renderer, SLOT(setAnimation(bool))); + connect(animated, &QAbstractButton::toggled, m_renderer, &PathStrokeRenderer::setAnimation); - connect(penWidth, SIGNAL(valueChanged(int)), m_renderer, SLOT(setPenWidth(int))); + connect(penWidth, &QAbstractSlider::valueChanged, m_renderer, &PathStrokeRenderer::setPenWidth); - connect(showSourceButton, SIGNAL(clicked()), m_renderer, SLOT(showSource())); + connect(showSourceButton, &QAbstractButton::clicked, m_renderer, &ArthurFrame::showSource); #if QT_CONFIG(opengl) - connect(enableOpenGLButton, SIGNAL(clicked(bool)), m_renderer, SLOT(enableOpenGL(bool))); + connect(enableOpenGLButton, &QAbstractButton::clicked, m_renderer, &ArthurFrame::enableOpenGL); #endif - connect(whatsThisButton, SIGNAL(clicked(bool)), m_renderer, SLOT(setDescriptionEnabled(bool))); - connect(m_renderer, SIGNAL(descriptionEnabledChanged(bool)), - whatsThisButton, SLOT(setChecked(bool))); + connect(whatsThisButton, &QAbstractButton::clicked, m_renderer, &ArthurFrame::setDescriptionEnabled); + connect(m_renderer, &ArthurFrame::descriptionEnabledChanged, + whatsThisButton, &QAbstractButton::setChecked); // Set the defaults @@ -327,12 +327,12 @@ void PathStrokeControls::layoutForSmallScreens() mainLayout->addWidget(okBtn, 2, 2, Qt::AlignHCenter | Qt::AlignTop); #if QT_CONFIG(opengl) - connect(enableOpenGLButton, SIGNAL(clicked(bool)), m_renderer, SLOT(enableOpenGL(bool))); + connect(enableOpenGLButton, &QAbstractButton::clicked, m_renderer, &ArthurFrame::enableOpenGL); #endif - connect(penWidth, SIGNAL(valueChanged(int)), m_renderer, SLOT(setPenWidth(int))); - connect(quitBtn, SIGNAL(clicked()), this, SLOT(emitQuitSignal())); - connect(okBtn, SIGNAL(clicked()), this, SLOT(emitOkSignal())); + connect(penWidth, &QAbstractSlider::valueChanged, m_renderer, &PathStrokeRenderer::setPenWidth); + connect(quitBtn, &QAbstractButton::clicked, this, &PathStrokeControls::emitQuitSignal); + connect(okBtn, &QAbstractButton::clicked, this, &PathStrokeControls::emitOkSignal); m_renderer->setAnimation(true); penWidth->setValue(50); @@ -368,8 +368,8 @@ PathStrokeWidget::PathStrokeWidget(bool smallScreen) m_renderer->loadSourceFile(":res/pathstroke/pathstroke.cpp"); m_renderer->loadDescription(":res/pathstroke/pathstroke.html"); - connect(m_renderer, SIGNAL(clicked()), this, SLOT(showControls())); - connect(m_controls, SIGNAL(okPressed()), this, SLOT(hideControls())); + connect(m_renderer, &PathStrokeRenderer::clicked, this, &PathStrokeWidget::showControls); + connect(m_controls, &PathStrokeControls::okPressed, this, &PathStrokeWidget::hideControls); connect(m_controls, SIGNAL(quitPressed()), QApplication::instance(), SLOT(quit())); } diff --git a/examples/widgets/painting/shared/hoverpoints.cpp b/examples/widgets/painting/shared/hoverpoints.cpp index 7cd8cc0b29..a16bda4835 100644 --- a/examples/widgets/painting/shared/hoverpoints.cpp +++ b/examples/widgets/painting/shared/hoverpoints.cpp @@ -73,8 +73,8 @@ HoverPoints::HoverPoints(QWidget *widget, PointShape shape) m_editable = true; m_enabled = true; - connect(this, SIGNAL(pointsChanged(QPolygonF)), - m_widget, SLOT(update())); + connect(this, &HoverPoints::pointsChanged, + m_widget, QOverload<>::of(&QWidget::update)); } diff --git a/examples/widgets/painting/transformations/window.cpp b/examples/widgets/painting/transformations/window.cpp index d8babb2e00..8261c4e12e 100644 --- a/examples/widgets/painting/transformations/window.cpp +++ b/examples/widgets/painting/transformations/window.cpp @@ -79,8 +79,8 @@ Window::Window() operationComboBoxes[i]->addItem(tr("Scale to 75%")); operationComboBoxes[i]->addItem(tr("Translate by (50, 50)")); - connect(operationComboBoxes[i], SIGNAL(activated(int)), - this, SLOT(operationChanged())); + connect(operationComboBoxes[i], QOverload::of(&QComboBox::activated), + this, &Window::operationChanged); layout->addWidget(transformedRenderAreas[i], 0, i + 1); layout->addWidget(operationComboBoxes[i], 1, i + 1); @@ -159,7 +159,8 @@ void Window::setupShapes() shapes.append(text); shapes.append(truck); - connect(shapeComboBox, SIGNAL(activated(int)), this, SLOT(shapeSelected(int))); + connect(shapeComboBox, QOverload::of(&QComboBox::activated), + this, &Window::shapeSelected); } //! [7] diff --git a/examples/widgets/richtext/calendar/mainwindow.cpp b/examples/widgets/richtext/calendar/mainwindow.cpp index 38dc0e2849..3ddb1cf7ad 100644 --- a/examples/widgets/richtext/calendar/mainwindow.cpp +++ b/examples/widgets/richtext/calendar/mainwindow.cpp @@ -86,10 +86,12 @@ MainWindow::MainWindow() //! [2] //! [3] - connect(monthCombo, SIGNAL(activated(int)), this, SLOT(setMonth(int))); - connect(yearEdit, SIGNAL(dateChanged(QDate)), this, SLOT(setYear(QDate))); - connect(fontSizeSpinBox, SIGNAL(valueChanged(int)), - this, SLOT(setFontSize(int))); + connect(monthCombo, QOverload::of(&QComboBox::activated), + this, &MainWindow::setMonth); + connect(yearEdit, &QDateTimeEdit::dateChanged, + this, &MainWindow::setYear); + connect(fontSizeSpinBox, QOverload::of(&QSpinBox::valueChanged), + this, &MainWindow::setFontSize); //! [3] fontSizeSpinBox->setValue(10); diff --git a/examples/widgets/richtext/orderform/mainwindow.cpp b/examples/widgets/richtext/orderform/mainwindow.cpp index b207ee4dbc..291c37edf6 100644 --- a/examples/widgets/richtext/orderform/mainwindow.cpp +++ b/examples/widgets/richtext/orderform/mainwindow.cpp @@ -66,7 +66,7 @@ MainWindow::MainWindow() QMenu *fileMenu = new QMenu(tr("&File"), this); QAction *newAction = fileMenu->addAction(tr("&New...")); newAction->setShortcuts(QKeySequence::New); - printAction = fileMenu->addAction(tr("&Print..."), this, SLOT(printFile())); + printAction = fileMenu->addAction(tr("&Print..."), this, &MainWindow::printFile); printAction->setShortcuts(QKeySequence::Print); printAction->setEnabled(false); QAction *quitAction = fileMenu->addAction(tr("E&xit")); diff --git a/examples/widgets/richtext/syntaxhighlighter/mainwindow.cpp b/examples/widgets/richtext/syntaxhighlighter/mainwindow.cpp index dd58f1f45b..2dba0ba73e 100644 --- a/examples/widgets/richtext/syntaxhighlighter/mainwindow.cpp +++ b/examples/widgets/richtext/syntaxhighlighter/mainwindow.cpp @@ -117,9 +117,12 @@ void MainWindow::setupFileMenu() QMenu *fileMenu = new QMenu(tr("&File"), this); menuBar()->addMenu(fileMenu); - fileMenu->addAction(tr("&New"), this, SLOT(newFile()), QKeySequence::New); - fileMenu->addAction(tr("&Open..."), this, SLOT(openFile()), QKeySequence::Open); - fileMenu->addAction(tr("E&xit"), qApp, SLOT(quit()), QKeySequence::Quit); + fileMenu->addAction(tr("&New"), this, + &MainWindow::newFile, QKeySequence::New); + fileMenu->addAction(tr("&Open..."), + this, [this](){ openFile(); }, QKeySequence::Open); + fileMenu->addAction(tr("E&xit"), qApp, + &QApplication::quit, QKeySequence::Quit); } void MainWindow::setupHelpMenu() @@ -127,6 +130,6 @@ void MainWindow::setupHelpMenu() QMenu *helpMenu = new QMenu(tr("&Help"), this); menuBar()->addMenu(helpMenu); - helpMenu->addAction(tr("&About"), this, SLOT(about())); - helpMenu->addAction(tr("About &Qt"), qApp, SLOT(aboutQt())); + helpMenu->addAction(tr("&About"), this, &MainWindow::about); + helpMenu->addAction(tr("About &Qt"), qApp, &QApplication::aboutQt); } -- cgit v1.2.3