From 8cf812231405e011b422a1505d9a219618fe5cee Mon Sep 17 00:00:00 2001 From: Christian Ehrlicher Date: Fri, 7 Dec 2018 14:15:36 +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 - animation, effects and graphicsview subdirectory Change-Id: I6cbaea6e628eb06f8e0ca6a0b795030a66b83878 Reviewed-by: Luca Beldi Reviewed-by: Topi Reiniƶ --- examples/widgets/graphicsview/boxes/scene.cpp | 42 +++++++------- examples/widgets/graphicsview/chip/view.cpp | 32 +++++------ .../widgets/graphicsview/collidingmice/main.cpp | 2 +- .../graphicsview/diagramscene/diagramscene.cpp | 8 +-- .../graphicsview/diagramscene/mainwindow.cpp | 64 +++++++++++----------- .../graphicsview/embeddeddialogs/customproxy.cpp | 8 +-- 6 files changed, 79 insertions(+), 77 deletions(-) (limited to 'examples/widgets/graphicsview') diff --git a/examples/widgets/graphicsview/boxes/scene.cpp b/examples/widgets/graphicsview/boxes/scene.cpp index 1637c1f781..3c65206c02 100644 --- a/examples/widgets/graphicsview/boxes/scene.cpp +++ b/examples/widgets/graphicsview/boxes/scene.cpp @@ -111,7 +111,7 @@ ColorEdit::ColorEdit(QRgb initialColor, int id) m_button->setFrameStyle(QFrame::StyledPanel | QFrame::Sunken); layout->addWidget(m_button); - connect(m_lineEdit, SIGNAL(editingFinished()), this, SLOT(editDone())); + connect(m_lineEdit, &QLineEdit::editingFinished, this, &ColorEdit::editDone); } void ColorEdit::editDone() @@ -166,7 +166,7 @@ FloatEdit::FloatEdit(float initialValue, int id) m_lineEdit = new QLineEdit(QString::number(m_value)); layout->addWidget(m_lineEdit); - connect(m_lineEdit, SIGNAL(editingFinished()), this, SLOT(editDone())); + connect(m_lineEdit, &QLineEdit::editingFinished, this, &FloatEdit::editDone); } void FloatEdit::editDone() @@ -252,7 +252,7 @@ void TwoSidedGraphicsWidget::animateFlip() .translate(-r.width() / 2, -r.height() / 2)); if ((m_current == 0 && m_angle > 0) || (m_current == 1 && m_angle < 180)) - QTimer::singleShot(25, this, SLOT(animateFlip())); + QTimer::singleShot(25, this, &TwoSidedGraphicsWidget::animateFlip); } QVariant GraphicsWidget::itemChange(GraphicsItemChange change, const QVariant &value) @@ -307,7 +307,7 @@ RenderOptionsDialog::RenderOptionsDialog() check->setCheckState(Qt::Unchecked); // Dynamic cube maps are only enabled when multi-texturing and render to texture are available. check->setEnabled(glActiveTexture && glGenFramebuffersEXT); - connect(check, SIGNAL(stateChanged(int)), this, SIGNAL(dynamicCubemapToggled(int))); + connect(check, &QCheckBox::stateChanged, this, &RenderOptionsDialog::dynamicCubemapToggled); layout->addWidget(check, 0, 0, 1, 2); ++row; @@ -356,7 +356,7 @@ RenderOptionsDialog::RenderOptionsDialog() ColorEdit *colorEdit = new ColorEdit(it->toUInt(&ok, 16), m_parameterNames.size() - 1); m_parameterEdits << colorEdit; layout->addWidget(colorEdit); - connect(colorEdit, SIGNAL(colorChanged(QRgb,int)), this, SLOT(setColorParameter(QRgb,int))); + connect(colorEdit, &ColorEdit::colorChanged, this, &RenderOptionsDialog::setColorParameter); ++row; } else if (type == "float") { layout->addWidget(new QLabel(m_parameterNames.back())); @@ -364,7 +364,7 @@ RenderOptionsDialog::RenderOptionsDialog() FloatEdit *floatEdit = new FloatEdit(it->toFloat(&ok), m_parameterNames.size() - 1); m_parameterEdits << floatEdit; layout->addWidget(floatEdit); - connect(floatEdit, SIGNAL(valueChanged(float,int)), this, SLOT(setFloatParameter(float,int))); + connect(floatEdit, &FloatEdit::valueChanged, this, &RenderOptionsDialog::setFloatParameter); ++row; } } @@ -375,13 +375,15 @@ RenderOptionsDialog::RenderOptionsDialog() layout->addWidget(new QLabel(tr("Texture:"))); m_textureCombo = new QComboBox; - connect(m_textureCombo, SIGNAL(currentIndexChanged(int)), this, SIGNAL(textureChanged(int))); + connect(m_textureCombo, QOverload::of(&QComboBox::currentIndexChanged), + this, &RenderOptionsDialog::textureChanged); layout->addWidget(m_textureCombo); ++row; layout->addWidget(new QLabel(tr("Shader:"))); m_shaderCombo = new QComboBox; - connect(m_shaderCombo, SIGNAL(currentIndexChanged(int)), this, SIGNAL(shaderChanged(int))); + connect(m_shaderCombo, QOverload::of(&QComboBox::currentIndexChanged), + this, &RenderOptionsDialog::shaderChanged); layout->addWidget(m_shaderCombo); ++row; @@ -439,15 +441,15 @@ ItemDialog::ItemDialog() button = new QPushButton(tr("Add Qt box")); layout->addWidget(button); - connect(button, SIGNAL(clicked()), this, SLOT(triggerNewQtBox())); + connect(button, &QAbstractButton::clicked, this, &ItemDialog::triggerNewQtBox); button = new QPushButton(tr("Add circle")); layout->addWidget(button); - connect(button, SIGNAL(clicked()), this, SLOT(triggerNewCircleItem())); + connect(button, &QAbstractButton::clicked, this, &ItemDialog::triggerNewCircleItem); button = new QPushButton(tr("Add square")); layout->addWidget(button); - connect(button, SIGNAL(clicked()), this, SLOT(triggerNewSquareItem())); + connect(button, &QAbstractButton::clicked, this, &ItemDialog::triggerNewSquareItem); layout->addStretch(1); } @@ -506,21 +508,21 @@ Scene::Scene(int width, int height, int maxTextureSize) m_renderOptions->move(20, 120); m_renderOptions->resize(m_renderOptions->sizeHint()); - connect(m_renderOptions, SIGNAL(dynamicCubemapToggled(int)), this, SLOT(toggleDynamicCubemap(int))); - connect(m_renderOptions, SIGNAL(colorParameterChanged(QString,QRgb)), this, SLOT(setColorParameter(QString,QRgb))); - connect(m_renderOptions, SIGNAL(floatParameterChanged(QString,float)), this, SLOT(setFloatParameter(QString,float))); - connect(m_renderOptions, SIGNAL(textureChanged(int)), this, SLOT(setTexture(int))); - connect(m_renderOptions, SIGNAL(shaderChanged(int)), this, SLOT(setShader(int))); + connect(m_renderOptions, &RenderOptionsDialog::dynamicCubemapToggled, this, &Scene::toggleDynamicCubemap); + connect(m_renderOptions, &RenderOptionsDialog::colorParameterChanged, this, &Scene::setColorParameter); + connect(m_renderOptions, &RenderOptionsDialog::floatParameterChanged, this, &Scene::setFloatParameter); + connect(m_renderOptions, &RenderOptionsDialog::textureChanged, this, &Scene::setTexture); + connect(m_renderOptions, &RenderOptionsDialog::shaderChanged, this, &Scene::setShader); m_itemDialog = new ItemDialog; - connect(m_itemDialog, SIGNAL(newItemTriggered(ItemDialog::ItemType)), this, SLOT(newItem(ItemDialog::ItemType))); + connect(m_itemDialog, &ItemDialog::newItemTriggered, this, &Scene::newItem); TwoSidedGraphicsWidget *twoSided = new TwoSidedGraphicsWidget(this); twoSided->setWidget(0, m_renderOptions); twoSided->setWidget(1, m_itemDialog); - connect(m_renderOptions, SIGNAL(doubleClicked()), twoSided, SLOT(flip())); - connect(m_itemDialog, SIGNAL(doubleClicked()), twoSided, SLOT(flip())); + connect(m_renderOptions, &RenderOptionsDialog::doubleClicked, twoSided, &TwoSidedGraphicsWidget::flip); + connect(m_itemDialog, &ItemDialog::doubleClicked, twoSided, &TwoSidedGraphicsWidget::flip); addItem(new QtBox(64, width - 64, height - 64)); addItem(new QtBox(64, width - 64, 64)); @@ -531,7 +533,7 @@ Scene::Scene(int width, int height, int maxTextureSize) m_timer = new QTimer(this); m_timer->setInterval(20); - connect(m_timer, SIGNAL(timeout()), this, SLOT(update())); + connect(m_timer, &QTimer::timeout, this, [this](){ update(); }); m_timer->start(); m_time.start(); diff --git a/examples/widgets/graphicsview/chip/view.cpp b/examples/widgets/graphicsview/chip/view.cpp index 491f1a54cf..9676c13ff7 100644 --- a/examples/widgets/graphicsview/chip/view.cpp +++ b/examples/widgets/graphicsview/chip/view.cpp @@ -190,22 +190,22 @@ View::View(const QString &name, QWidget *parent) topLayout->addWidget(resetButton, 2, 1); setLayout(topLayout); - connect(resetButton, SIGNAL(clicked()), this, SLOT(resetView())); - connect(zoomSlider, SIGNAL(valueChanged(int)), this, SLOT(setupMatrix())); - connect(rotateSlider, SIGNAL(valueChanged(int)), this, SLOT(setupMatrix())); - connect(graphicsView->verticalScrollBar(), SIGNAL(valueChanged(int)), - this, SLOT(setResetButtonEnabled())); - connect(graphicsView->horizontalScrollBar(), SIGNAL(valueChanged(int)), - this, SLOT(setResetButtonEnabled())); - connect(selectModeButton, SIGNAL(toggled(bool)), this, SLOT(togglePointerMode())); - connect(dragModeButton, SIGNAL(toggled(bool)), this, SLOT(togglePointerMode())); - connect(antialiasButton, SIGNAL(toggled(bool)), this, SLOT(toggleAntialiasing())); - connect(openGlButton, SIGNAL(toggled(bool)), this, SLOT(toggleOpenGL())); - connect(rotateLeftIcon, SIGNAL(clicked()), this, SLOT(rotateLeft())); - connect(rotateRightIcon, SIGNAL(clicked()), this, SLOT(rotateRight())); - connect(zoomInIcon, SIGNAL(clicked()), this, SLOT(zoomIn())); - connect(zoomOutIcon, SIGNAL(clicked()), this, SLOT(zoomOut())); - connect(printButton, SIGNAL(clicked()), this, SLOT(print())); + connect(resetButton, &QAbstractButton::clicked, this, &View::resetView); + connect(zoomSlider, &QAbstractSlider::valueChanged, this, &View::setupMatrix); + connect(rotateSlider, &QAbstractSlider::valueChanged, this, &View::setupMatrix); + connect(graphicsView->verticalScrollBar(), &QAbstractSlider::valueChanged, + this, &View::setResetButtonEnabled); + connect(graphicsView->horizontalScrollBar(), &QAbstractSlider::valueChanged, + this, &View::setResetButtonEnabled); + connect(selectModeButton, &QAbstractButton::toggled, this, &View::togglePointerMode); + connect(dragModeButton, &QAbstractButton::toggled, this, &View::togglePointerMode); + connect(antialiasButton, &QAbstractButton::toggled, this, &View::toggleAntialiasing); + connect(openGlButton, &QAbstractButton::toggled, this, &View::toggleOpenGL); + connect(rotateLeftIcon, &QAbstractButton::clicked, this, &View::rotateLeft); + connect(rotateRightIcon, &QAbstractButton::clicked, this, &View::rotateRight); + connect(zoomInIcon, &QAbstractButton::clicked, this, &View::zoomIn); + connect(zoomOutIcon, &QAbstractButton::clicked, this, &View::zoomOut); + connect(printButton, &QAbstractButton::clicked, this, &View::print); setupMatrix(); } diff --git a/examples/widgets/graphicsview/collidingmice/main.cpp b/examples/widgets/graphicsview/collidingmice/main.cpp index 91aee70b86..dfb20815b9 100644 --- a/examples/widgets/graphicsview/collidingmice/main.cpp +++ b/examples/widgets/graphicsview/collidingmice/main.cpp @@ -92,7 +92,7 @@ int main(int argc, char **argv) view.show(); QTimer timer; - QObject::connect(&timer, SIGNAL(timeout()), &scene, SLOT(advance())); + QObject::connect(&timer, &QTimer::timeout, &scene, &QGraphicsScene::advance); timer.start(1000 / 33); return app.exec(); diff --git a/examples/widgets/graphicsview/diagramscene/diagramscene.cpp b/examples/widgets/graphicsview/diagramscene/diagramscene.cpp index bbbc512b55..51d855cc75 100644 --- a/examples/widgets/graphicsview/diagramscene/diagramscene.cpp +++ b/examples/widgets/graphicsview/diagramscene/diagramscene.cpp @@ -169,10 +169,10 @@ void DiagramScene::mousePressEvent(QGraphicsSceneMouseEvent *mouseEvent) textItem->setFont(myFont); textItem->setTextInteractionFlags(Qt::TextEditorInteraction); textItem->setZValue(1000.0); - connect(textItem, SIGNAL(lostFocus(DiagramTextItem*)), - this, SLOT(editorLostFocus(DiagramTextItem*))); - connect(textItem, SIGNAL(selectedChange(QGraphicsItem*)), - this, SIGNAL(itemSelected(QGraphicsItem*))); + connect(textItem, &DiagramTextItem::lostFocus, + this, &DiagramScene::editorLostFocus); + connect(textItem, &DiagramTextItem::selectedChange, + this, &DiagramScene::itemSelected); addItem(textItem); textItem->setDefaultTextColor(myTextColor); textItem->setPos(mouseEvent->scenePos()); diff --git a/examples/widgets/graphicsview/diagramscene/mainwindow.cpp b/examples/widgets/graphicsview/diagramscene/mainwindow.cpp index 36353674ea..875c41b284 100644 --- a/examples/widgets/graphicsview/diagramscene/mainwindow.cpp +++ b/examples/widgets/graphicsview/diagramscene/mainwindow.cpp @@ -67,12 +67,12 @@ MainWindow::MainWindow() scene = new DiagramScene(itemMenu, this); scene->setSceneRect(QRectF(0, 0, 5000, 5000)); - connect(scene, SIGNAL(itemInserted(DiagramItem*)), - this, SLOT(itemInserted(DiagramItem*))); - connect(scene, SIGNAL(textInserted(QGraphicsTextItem*)), - this, SLOT(textInserted(QGraphicsTextItem*))); - connect(scene, SIGNAL(itemSelected(QGraphicsItem*)), - this, SLOT(itemSelected(QGraphicsItem*))); + connect(scene, &DiagramScene::itemInserted, + this, &MainWindow::itemInserted); + connect(scene, &DiagramScene::textInserted, + this, &MainWindow::textInserted); + connect(scene, &DiagramScene::itemSelected, + this, &MainWindow::itemSelected); createToolbars(); QHBoxLayout *layout = new QHBoxLayout; @@ -332,8 +332,8 @@ void MainWindow::createToolBox() { buttonGroup = new QButtonGroup(this); buttonGroup->setExclusive(false); - connect(buttonGroup, SIGNAL(buttonClicked(int)), - this, SLOT(buttonGroupClicked(int))); + connect(buttonGroup, QOverload::of(&QButtonGroup::buttonClicked), + this, &MainWindow::buttonGroupClicked); QGridLayout *layout = new QGridLayout; layout->addWidget(createCellWidget(tr("Conditional"), DiagramItem::Conditional), 0, 0); layout->addWidget(createCellWidget(tr("Process"), DiagramItem::Step),0, 1); @@ -359,8 +359,8 @@ void MainWindow::createToolBox() itemWidget->setLayout(layout); backgroundButtonGroup = new QButtonGroup(this); - connect(backgroundButtonGroup, SIGNAL(buttonClicked(QAbstractButton*)), - this, SLOT(backgroundButtonGroupClicked(QAbstractButton*))); + connect(backgroundButtonGroup, QOverload::of(&QButtonGroup::buttonClicked), + this, &MainWindow::backgroundButtonGroupClicked); QGridLayout *backgroundLayout = new QGridLayout; backgroundLayout->addWidget(createBackgroundCellWidget(tr("Blue Grid"), @@ -395,44 +395,44 @@ void MainWindow::createActions() tr("Bring to &Front"), this); toFrontAction->setShortcut(tr("Ctrl+F")); toFrontAction->setStatusTip(tr("Bring item to front")); - connect(toFrontAction, SIGNAL(triggered()), this, SLOT(bringToFront())); + connect(toFrontAction, &QAction::triggered, this, &MainWindow::bringToFront); //! [23] sendBackAction = new QAction(QIcon(":/images/sendtoback.png"), tr("Send to &Back"), this); sendBackAction->setShortcut(tr("Ctrl+T")); sendBackAction->setStatusTip(tr("Send item to back")); - connect(sendBackAction, SIGNAL(triggered()), this, SLOT(sendToBack())); + connect(sendBackAction, &QAction::triggered, this, &MainWindow::sendToBack); deleteAction = new QAction(QIcon(":/images/delete.png"), tr("&Delete"), this); deleteAction->setShortcut(tr("Delete")); deleteAction->setStatusTip(tr("Delete item from diagram")); - connect(deleteAction, SIGNAL(triggered()), this, SLOT(deleteItem())); + connect(deleteAction, &QAction::triggered, this, &MainWindow::deleteItem); exitAction = new QAction(tr("E&xit"), this); exitAction->setShortcuts(QKeySequence::Quit); exitAction->setStatusTip(tr("Quit Scenediagram example")); - connect(exitAction, SIGNAL(triggered()), this, SLOT(close())); + connect(exitAction, &QAction::triggered, this, &QWidget::close); boldAction = new QAction(tr("Bold"), this); boldAction->setCheckable(true); QPixmap pixmap(":/images/bold.png"); boldAction->setIcon(QIcon(pixmap)); boldAction->setShortcut(tr("Ctrl+B")); - connect(boldAction, SIGNAL(triggered()), this, SLOT(handleFontChange())); + connect(boldAction, &QAction::triggered, this, &MainWindow::handleFontChange); italicAction = new QAction(QIcon(":/images/italic.png"), tr("Italic"), this); italicAction->setCheckable(true); italicAction->setShortcut(tr("Ctrl+I")); - connect(italicAction, SIGNAL(triggered()), this, SLOT(handleFontChange())); + connect(italicAction, &QAction::triggered, this, &MainWindow::handleFontChange); underlineAction = new QAction(QIcon(":/images/underline.png"), tr("Underline"), this); underlineAction->setCheckable(true); underlineAction->setShortcut(tr("Ctrl+U")); - connect(underlineAction, SIGNAL(triggered()), this, SLOT(handleFontChange())); + connect(underlineAction, &QAction::triggered, this, &MainWindow::handleFontChange); aboutAction = new QAction(tr("A&bout"), this); aboutAction->setShortcut(tr("F1")); - connect(aboutAction, SIGNAL(triggered()), this, SLOT(about())); + connect(aboutAction, &QAction::triggered, this, &MainWindow::about); } //! [24] @@ -462,8 +462,8 @@ void MainWindow::createToolbars() editToolBar->addAction(sendBackAction); fontCombo = new QFontComboBox(); - connect(fontCombo, SIGNAL(currentFontChanged(QFont)), - this, SLOT(currentFontChanged(QFont))); + connect(fontCombo, &QFontComboBox::currentFontChanged, + this, &MainWindow::currentFontChanged); fontSizeCombo = new QComboBox; fontSizeCombo->setEditable(true); @@ -471,8 +471,8 @@ void MainWindow::createToolbars() fontSizeCombo->addItem(QString().setNum(i)); QIntValidator *validator = new QIntValidator(2, 64, this); fontSizeCombo->setValidator(validator); - connect(fontSizeCombo, SIGNAL(currentIndexChanged(QString)), - this, SLOT(fontSizeChanged(QString))); + connect(fontSizeCombo, QOverload::of(&QComboBox::currentIndexChanged), + this, &MainWindow::fontSizeChanged); fontColorToolButton = new QToolButton; fontColorToolButton->setPopupMode(QToolButton::MenuButtonPopup); @@ -480,8 +480,8 @@ void MainWindow::createToolbars() textAction = fontColorToolButton->menu()->defaultAction(); fontColorToolButton->setIcon(createColorToolButtonIcon(":/images/textpointer.png", Qt::black)); fontColorToolButton->setAutoFillBackground(true); - connect(fontColorToolButton, SIGNAL(clicked()), - this, SLOT(textButtonTriggered())); + connect(fontColorToolButton, &QAbstractButton::clicked, + this, &MainWindow::textButtonTriggered); //! [26] fillColorToolButton = new QToolButton; @@ -490,8 +490,8 @@ void MainWindow::createToolbars() fillAction = fillColorToolButton->menu()->defaultAction(); fillColorToolButton->setIcon(createColorToolButtonIcon( ":/images/floodfill.png", Qt::white)); - connect(fillColorToolButton, SIGNAL(clicked()), - this, SLOT(fillButtonTriggered())); + connect(fillColorToolButton, &QAbstractButton::clicked, + this, &MainWindow::fillButtonTriggered); //! [26] lineColorToolButton = new QToolButton; @@ -500,8 +500,8 @@ void MainWindow::createToolbars() lineAction = lineColorToolButton->menu()->defaultAction(); lineColorToolButton->setIcon(createColorToolButtonIcon( ":/images/linecolor.png", Qt::black)); - connect(lineColorToolButton, SIGNAL(clicked()), - this, SLOT(lineButtonTriggered())); + connect(lineColorToolButton, &QAbstractButton::clicked, + this, &MainWindow::lineButtonTriggered); textToolBar = addToolBar(tr("Font")); textToolBar->addWidget(fontCombo); @@ -526,16 +526,16 @@ void MainWindow::createToolbars() pointerTypeGroup = new QButtonGroup(this); pointerTypeGroup->addButton(pointerButton, int(DiagramScene::MoveItem)); pointerTypeGroup->addButton(linePointerButton, int(DiagramScene::InsertLine)); - connect(pointerTypeGroup, SIGNAL(buttonClicked(int)), - this, SLOT(pointerGroupClicked(int))); + connect(pointerTypeGroup, QOverload::of(&QButtonGroup::buttonClicked), + this, &MainWindow::pointerGroupClicked); sceneScaleCombo = new QComboBox; QStringList scales; scales << tr("50%") << tr("75%") << tr("100%") << tr("125%") << tr("150%"); sceneScaleCombo->addItems(scales); sceneScaleCombo->setCurrentIndex(2); - connect(sceneScaleCombo, SIGNAL(currentIndexChanged(QString)), - this, SLOT(sceneScaleChanged(QString))); + connect(sceneScaleCombo, QOverload::of(&QComboBox::currentIndexChanged), + this, &MainWindow::sceneScaleChanged); pointerToolbar = addToolBar(tr("Pointer type")); pointerToolbar->addWidget(pointerButton); diff --git a/examples/widgets/graphicsview/embeddeddialogs/customproxy.cpp b/examples/widgets/graphicsview/embeddeddialogs/customproxy.cpp index 158c31d9c1..c181a03e85 100644 --- a/examples/widgets/graphicsview/embeddeddialogs/customproxy.cpp +++ b/examples/widgets/graphicsview/embeddeddialogs/customproxy.cpp @@ -58,10 +58,10 @@ CustomProxy::CustomProxy(QGraphicsItem *parent, Qt::WindowFlags wFlags) : QGraphicsProxyWidget(parent, wFlags), popupShown(false), currentPopup(0) { timeLine = new QTimeLine(250, this); - connect(timeLine, SIGNAL(valueChanged(qreal)), - this, SLOT(updateStep(qreal))); - connect(timeLine, SIGNAL(stateChanged(QTimeLine::State)), - this, SLOT(stateChanged(QTimeLine::State))); + connect(timeLine, &QTimeLine::valueChanged, + this, &CustomProxy::updateStep); + connect(timeLine, &QTimeLine::stateChanged, + this, &CustomProxy::stateChanged); } QRectF CustomProxy::boundingRect() const -- cgit v1.2.3