summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAlexander Volkov <a.volkov@rusbitech.ru>2016-12-20 21:37:37 +0300
committerAlexander Volkov <a.volkov@rusbitech.ru>2016-12-22 14:54:55 +0000
commitfb7bfbf18d91d0bd0f1c88ee6043e3dfa7ae9b9e (patch)
tree4afb53415fdd372095f3e9abcb7e9f332d01be40
parent63e7ff97e960987080e6bda668ba960650dca87f (diff)
examples: Use QOverload to select overloaded signals and slots
We can use QOverload since Qt 5.7 (it depends on Q_COMPILER_VARIADIC_TEMPLATES which is required since Qt 5.7). Use it in the examples to show the best practice. qOverload currently can't be used because it requires c++14. Change-Id: I94a3c0db9d551fe169fa3d19c07ec0b329d5946c Reviewed-by: Friedemann Kleint <Friedemann.Kleint@qt.io> Reviewed-by: Olivier Goffart (Woboq GmbH) <ogoffart@woboq.com>
-rw-r--r--examples/network/fortuneclient/client.cpp3
-rw-r--r--examples/opengl/paintedwindow/paintedwindow.cpp4
-rw-r--r--examples/opengl/qopenglwidget/mainwindow.cpp11
-rw-r--r--examples/opengl/qopenglwindow/main.cpp6
-rw-r--r--examples/widgets/desktop/screenshot/screenshot.cpp3
-rw-r--r--examples/widgets/desktop/systray/window.cpp3
-rw-r--r--examples/widgets/itemviews/basicsortfiltermodel/window.cpp6
-rw-r--r--examples/widgets/itemviews/pixelator/mainwindow.cpp5
-rw-r--r--examples/widgets/richtext/textedit/textedit.cpp8
-rw-r--r--examples/widgets/tools/codecs/previewform.cpp3
-rw-r--r--examples/widgets/tools/regularexpression/regularexpressiondialog.cpp4
-rw-r--r--examples/widgets/tools/settingseditor/locationdialog.cpp7
-rw-r--r--examples/widgets/widgets/charactermap/mainwindow.cpp8
-rw-r--r--examples/widgets/widgets/icons/imagedelegate.cpp3
-rw-r--r--examples/widgets/widgets/icons/mainwindow.cpp6
15 files changed, 28 insertions, 52 deletions
diff --git a/examples/network/fortuneclient/client.cpp b/examples/network/fortuneclient/client.cpp
index 205959936d..c0043e246f 100644
--- a/examples/network/fortuneclient/client.cpp
+++ b/examples/network/fortuneclient/client.cpp
@@ -122,8 +122,7 @@ Client::Client(QWidget *parent)
//! [2] //! [3]
connect(tcpSocket, &QIODevice::readyRead, this, &Client::readFortune);
//! [2] //! [4]
- typedef void (QAbstractSocket::*QAbstractSocketErrorSignal)(QAbstractSocket::SocketError);
- connect(tcpSocket, static_cast<QAbstractSocketErrorSignal>(&QAbstractSocket::error),
+ connect(tcpSocket, QOverload<QAbstractSocket::SocketError>::of(&QAbstractSocket::error),
//! [3]
this, &Client::displayError);
//! [4]
diff --git a/examples/opengl/paintedwindow/paintedwindow.cpp b/examples/opengl/paintedwindow/paintedwindow.cpp
index 6e031e5cb7..799431a765 100644
--- a/examples/opengl/paintedwindow/paintedwindow.cpp
+++ b/examples/opengl/paintedwindow/paintedwindow.cpp
@@ -95,9 +95,7 @@ PaintedWindow::PaintedWindow()
connect(screen(), &QScreen::orientationChanged, this, &PaintedWindow::orientationChanged);
connect(m_animation, &QAbstractAnimation::finished, this, &PaintedWindow::rotationDone);
- typedef void (PaintedWindow::*PaintedWindowVoidSlot)();
- connect(this, &PaintedWindow::rotationChanged,
- this, static_cast<PaintedWindowVoidSlot>(&PaintedWindow::paint));
+ connect(this, &PaintedWindow::rotationChanged, this, QOverload<>::of(&PaintedWindow::paint));
}
void PaintedWindow::exposeEvent(QExposeEvent *)
diff --git a/examples/opengl/qopenglwidget/mainwindow.cpp b/examples/opengl/qopenglwidget/mainwindow.cpp
index f602c9995b..1bb2aa2bf0 100644
--- a/examples/opengl/qopenglwidget/mainwindow.cpp
+++ b/examples/opengl/qopenglwidget/mainwindow.cpp
@@ -61,8 +61,6 @@
#include "glwidget.h"
-typedef void (QWidget::*QWidgetVoidSlot)();
-
MainWindow::MainWindow()
: m_nextX(1), m_nextY(1)
{
@@ -131,14 +129,11 @@ MainWindow::MainWindow()
QMenu *helpMenu = menuBar()->addMenu("&Help");
helpMenu->addAction("About Qt", qApp, &QApplication::aboutQt);
- connect(m_timer, &QTimer::timeout,
- glwidget, static_cast<QWidgetVoidSlot>(&QWidget::update));
+ connect(m_timer, &QTimer::timeout, glwidget, QOverload<>::of(&QWidget::update));
connect(slider, &QAbstractSlider::valueChanged, glwidget, &GLWidget::setScaling);
connect(transparent, &QCheckBox::toggled, glwidget, &GLWidget::setTransparent);
-
- typedef void (QSpinBox::*QSpinBoxIntSignal)(int);
- connect(updateInterval, static_cast<QSpinBoxIntSignal>(&QSpinBox::valueChanged),
+ connect(updateInterval, QOverload<int>::of(&QSpinBox::valueChanged),
this, &MainWindow::updateIntervalChanged);
connect(timerBased, &QCheckBox::toggled, this, &MainWindow::timerUsageChanged);
connect(timerBased, &QCheckBox::toggled, updateInterval, &QWidget::setEnabled);
@@ -162,7 +157,7 @@ void MainWindow::addNew()
return;
GLWidget *w = new GLWidget(this, false, qRgb(qrand() % 256, qrand() % 256, qrand() % 256));
m_glWidgets << w;
- connect(m_timer, &QTimer::timeout, w, static_cast<QWidgetVoidSlot>(&QWidget::update));
+ connect(m_timer, &QTimer::timeout, w, QOverload<>::of(&QWidget::update));
m_layout->addWidget(w, m_nextY, m_nextX, 1, 1);
if (m_nextX == 3) {
m_nextX = 1;
diff --git a/examples/opengl/qopenglwindow/main.cpp b/examples/opengl/qopenglwindow/main.cpp
index 4287d42d24..4f008b45a6 100644
--- a/examples/opengl/qopenglwindow/main.cpp
+++ b/examples/opengl/qopenglwindow/main.cpp
@@ -173,8 +173,6 @@ void OpenGLWindow::keyPressEvent(QKeyEvent *e)
void OpenGLWindow::setAnimating(bool enabled)
{
- typedef void (QPaintDeviceWindow::*QPaintDeviceWindowVoidSlot)();
-
if (enabled) {
// Animate continuously, throttled by the blocking swapBuffers() call the
// QOpenGLWindow internally executes after each paint. Once that is done
@@ -182,11 +180,11 @@ void OpenGLWindow::setAnimating(bool enabled)
// obviously assumes that the swap interval (see
// QSurfaceFormat::setSwapInterval()) is non-zero.
connect(this, &QOpenGLWindow::frameSwapped,
- this, static_cast<QPaintDeviceWindowVoidSlot>(&QPaintDeviceWindow::update));
+ this, QOverload<>::of(&QPaintDeviceWindow::update));
update();
} else {
disconnect(this, &QOpenGLWindow::frameSwapped,
- this, static_cast<QPaintDeviceWindowVoidSlot>(&QPaintDeviceWindow::update));
+ this, QOverload<>::of(&QPaintDeviceWindow::update));
}
}
diff --git a/examples/widgets/desktop/screenshot/screenshot.cpp b/examples/widgets/desktop/screenshot/screenshot.cpp
index 6438eb27cc..80f26ae282 100644
--- a/examples/widgets/desktop/screenshot/screenshot.cpp
+++ b/examples/widgets/desktop/screenshot/screenshot.cpp
@@ -70,8 +70,7 @@ Screenshot::Screenshot()
delaySpinBox->setSuffix(tr(" s"));
delaySpinBox->setMaximum(60);
- typedef void (QSpinBox::*QSpinBoxIntSignal)(int);
- connect(delaySpinBox, static_cast<QSpinBoxIntSignal>(&QSpinBox::valueChanged),
+ connect(delaySpinBox, QOverload<int>::of(&QSpinBox::valueChanged),
this, &Screenshot::updateCheckBox);
hideThisWindowCheckBox = new QCheckBox(tr("Hide This Window"), optionsGroupBox);
diff --git a/examples/widgets/desktop/systray/window.cpp b/examples/widgets/desktop/systray/window.cpp
index 518f03d4b5..5e98996ff3 100644
--- a/examples/widgets/desktop/systray/window.cpp
+++ b/examples/widgets/desktop/systray/window.cpp
@@ -80,8 +80,7 @@ Window::Window()
connect(showMessageButton, &QAbstractButton::clicked, this, &Window::showMessage);
connect(showIconCheckBox, &QAbstractButton::toggled, trayIcon, &QSystemTrayIcon::setVisible);
- typedef void (QComboBox::*QComboIntSignal)(int);
- connect(iconComboBox, static_cast<QComboIntSignal>(&QComboBox::currentIndexChanged),
+ connect(iconComboBox, QOverload<int>::of(&QComboBox::currentIndexChanged),
this, &Window::setIcon);
connect(trayIcon, &QSystemTrayIcon::messageClicked, this, &Window::messageClicked);
connect(trayIcon, &QSystemTrayIcon::activated, this, &Window::iconActivated);
diff --git a/examples/widgets/itemviews/basicsortfiltermodel/window.cpp b/examples/widgets/itemviews/basicsortfiltermodel/window.cpp
index a8a8875f6b..b45ee47ee2 100644
--- a/examples/widgets/itemviews/basicsortfiltermodel/window.cpp
+++ b/examples/widgets/itemviews/basicsortfiltermodel/window.cpp
@@ -89,11 +89,9 @@ Window::Window()
connect(filterPatternLineEdit, &QLineEdit::textChanged,
this, &Window::filterRegExpChanged);
-
- typedef void (QComboBox::*QComboIntSignal)(int);
- connect(filterSyntaxComboBox, static_cast<QComboIntSignal>(&QComboBox::currentIndexChanged),
+ connect(filterSyntaxComboBox, QOverload<int>::of(&QComboBox::currentIndexChanged),
this, &Window::filterRegExpChanged);
- connect(filterColumnComboBox, static_cast<QComboIntSignal>(&QComboBox::currentIndexChanged),
+ connect(filterColumnComboBox, QOverload<int>::of(&QComboBox::currentIndexChanged),
this, &Window::filterColumnChanged);
connect(filterCaseSensitivityCheckBox, &QAbstractButton::toggled,
this, &Window::filterRegExpChanged);
diff --git a/examples/widgets/itemviews/pixelator/mainwindow.cpp b/examples/widgets/itemviews/pixelator/mainwindow.cpp
index a5a704a864..2a5b572344 100644
--- a/examples/widgets/itemviews/pixelator/mainwindow.cpp
+++ b/examples/widgets/itemviews/pixelator/mainwindow.cpp
@@ -113,10 +113,9 @@ MainWindow::MainWindow()
connect(quitAction, &QAction::triggered, qApp, &QCoreApplication::quit);
connect(aboutAction, &QAction::triggered, this, &MainWindow::showAboutBox);
//! [4]
- typedef void (QSpinBox::*QSpinBoxIntSignal)(int);
- connect(pixelSizeSpinBox, static_cast<QSpinBoxIntSignal>(&QSpinBox::valueChanged),
+ connect(pixelSizeSpinBox, QOverload<int>::of(&QSpinBox::valueChanged),
delegate, &PixelDelegate::setPixelSize);
- connect(pixelSizeSpinBox, static_cast<QSpinBoxIntSignal>(&QSpinBox::valueChanged),
+ connect(pixelSizeSpinBox, QOverload<int>::of(&QSpinBox::valueChanged),
this, &MainWindow::updateView);
//! [4]
diff --git a/examples/widgets/richtext/textedit/textedit.cpp b/examples/widgets/richtext/textedit/textedit.cpp
index dec0b0bd35..140ae478ff 100644
--- a/examples/widgets/richtext/textedit/textedit.cpp
+++ b/examples/widgets/richtext/textedit/textedit.cpp
@@ -342,13 +342,11 @@ void TextEdit::setupTextActions()
comboStyle->addItem("Ordered List (Roman lower)");
comboStyle->addItem("Ordered List (Roman upper)");
- typedef void (QComboBox::*QComboIntSignal)(int);
- connect(comboStyle, static_cast<QComboIntSignal>(&QComboBox::activated), this, &TextEdit::textStyle);
+ connect(comboStyle, QOverload<int>::of(&QComboBox::activated), this, &TextEdit::textStyle);
- typedef void (QComboBox::*QComboStringSignal)(const QString &);
comboFont = new QFontComboBox(tb);
tb->addWidget(comboFont);
- connect(comboFont, static_cast<QComboStringSignal>(&QComboBox::activated), this, &TextEdit::textFamily);
+ connect(comboFont, QOverload<const QString &>::of(&QComboBox::activated), this, &TextEdit::textFamily);
comboSize = new QComboBox(tb);
comboSize->setObjectName("comboSize");
@@ -360,7 +358,7 @@ void TextEdit::setupTextActions()
comboSize->addItem(QString::number(size));
comboSize->setCurrentIndex(standardSizes.indexOf(QApplication::font().pointSize()));
- connect(comboSize, static_cast<QComboStringSignal>(&QComboBox::activated), this, &TextEdit::textSize);
+ connect(comboSize, QOverload<const QString &>::of(&QComboBox::activated), this, &TextEdit::textSize);
}
bool TextEdit::load(const QString &f)
diff --git a/examples/widgets/tools/codecs/previewform.cpp b/examples/widgets/tools/codecs/previewform.cpp
index e5ca13f011..d19b9c0833 100644
--- a/examples/widgets/tools/codecs/previewform.cpp
+++ b/examples/widgets/tools/codecs/previewform.cpp
@@ -159,8 +159,7 @@ PreviewForm::PreviewForm(QWidget *parent)
new QDialogButtonBox(QDialogButtonBox::Ok | QDialogButtonBox::Cancel);
okButton = buttonBox->button(QDialogButtonBox::Ok);
- typedef void(QComboBox::*ComboBoxIntSignal)(int);
- connect(encodingComboBox, static_cast<ComboBoxIntSignal>(&QComboBox::activated),
+ connect(encodingComboBox, QOverload<int>::of(&QComboBox::activated),
this, &PreviewForm::updateTextEdit);
connect(buttonBox, &QDialogButtonBox::accepted, this, &QDialog::accept);
connect(buttonBox, &QDialogButtonBox::rejected, this, &QDialog::reject);
diff --git a/examples/widgets/tools/regularexpression/regularexpressiondialog.cpp b/examples/widgets/tools/regularexpression/regularexpressiondialog.cpp
index f13240d06f..7a67c763d8 100644
--- a/examples/widgets/tools/regularexpression/regularexpressiondialog.cpp
+++ b/examples/widgets/tools/regularexpression/regularexpressiondialog.cpp
@@ -94,10 +94,10 @@ RegularExpressionDialog::RegularExpressionDialog(QWidget *parent)
connect(optimizeOnFirstUsageOptionCheckBox, &QCheckBox::toggled, this, &RegularExpressionDialog::refresh);
connect(dontAutomaticallyOptimizeOptionCheckBox, &QCheckBox::toggled, this, &RegularExpressionDialog::refresh);
- connect(offsetSpinBox, static_cast<void (QSpinBox::*)(int)>(&QSpinBox::valueChanged),
+ connect(offsetSpinBox, QOverload<int>::of(&QSpinBox::valueChanged),
this, &RegularExpressionDialog::refresh);
- connect(matchTypeComboBox, static_cast<void (QComboBox::*)(int)>(&QComboBox::currentIndexChanged),
+ connect(matchTypeComboBox, QOverload<int>::of(&QComboBox::currentIndexChanged),
this, &RegularExpressionDialog::refresh);
connect(anchoredMatchOptionCheckBox, &QCheckBox::toggled, this, &RegularExpressionDialog::refresh);
diff --git a/examples/widgets/tools/settingseditor/locationdialog.cpp b/examples/widgets/tools/settingseditor/locationdialog.cpp
index 4aa1e6073f..5b6e2652bb 100644
--- a/examples/widgets/tools/settingseditor/locationdialog.cpp
+++ b/examples/widgets/tools/settingseditor/locationdialog.cpp
@@ -106,10 +106,9 @@ LocationDialog::LocationDialog(QWidget *parent)
buttonBox = new QDialogButtonBox(QDialogButtonBox::Ok | QDialogButtonBox::Cancel);
- typedef void (QComboBox::*QComboIntSignal)(int);
- connect(formatComboBox, static_cast<QComboIntSignal>(&QComboBox::activated),
+ connect(formatComboBox, QOverload<int>::of(&QComboBox::activated),
this, &LocationDialog::updateLocationsTable);
- connect(scopeComboBox, static_cast<QComboIntSignal>(&QComboBox::activated),
+ connect(scopeComboBox, QOverload<int>::of(&QComboBox::activated),
this, &LocationDialog::updateLocationsTable);
connect(organizationComboBox->lineEdit(),
&QLineEdit::editingFinished,
@@ -117,7 +116,7 @@ LocationDialog::LocationDialog(QWidget *parent)
connect(applicationComboBox->lineEdit(),
&QLineEdit::editingFinished,
this, &LocationDialog::updateLocationsTable);
- connect(applicationComboBox, static_cast<QComboIntSignal>(&QComboBox::activated),
+ connect(applicationComboBox, QOverload<int>::of(&QComboBox::activated),
this, &LocationDialog::updateLocationsTable);
connect(buttonBox, &QDialogButtonBox::accepted, this, &QDialog::accept);
connect(buttonBox, &QDialogButtonBox::rejected, this, &QDialog::reject);
diff --git a/examples/widgets/widgets/charactermap/mainwindow.cpp b/examples/widgets/widgets/charactermap/mainwindow.cpp
index 8b406ba1ca..5f17128a2f 100644
--- a/examples/widgets/widgets/charactermap/mainwindow.cpp
+++ b/examples/widgets/widgets/charactermap/mainwindow.cpp
@@ -74,8 +74,7 @@ MainWindow::MainWindow()
filterCombo->addItem(tr("Monospaced"), QVariant::fromValue(QFontComboBox::MonospacedFonts));
filterCombo->addItem(tr("Proportional"), QVariant::fromValue(QFontComboBox::ProportionalFonts));
filterCombo->setCurrentIndex(0);
- typedef void (QComboBox::*QComboBoxIntSignal)(int);
- connect(filterCombo, static_cast<QComboBoxIntSignal>(&QComboBox::currentIndexChanged),
+ connect(filterCombo, QOverload<int>::of(&QComboBox::currentIndexChanged),
this, &MainWindow::filterChanged);
QLabel *fontLabel = new QLabel(tr("Font:"));
@@ -114,10 +113,9 @@ MainWindow::MainWindow()
this, &MainWindow::findSizes);
connect(fontCombo, &QFontComboBox::currentFontChanged,
characterWidget, &CharacterWidget::updateFont);
- typedef void (QComboBox::*QComboBoxStringSignal)(const QString &);
- connect(sizeCombo, static_cast<QComboBoxStringSignal>(&QComboBox::currentIndexChanged),
+ connect(sizeCombo, QOverload<const QString &>::of(&QComboBox::currentIndexChanged),
characterWidget, &CharacterWidget::updateSize);
- connect(styleCombo, static_cast<QComboBoxStringSignal>(&QComboBox::currentIndexChanged),
+ connect(styleCombo, QOverload<const QString &>::of(&QComboBox::currentIndexChanged),
characterWidget, &CharacterWidget::updateStyle);
//! [4] //! [5]
connect(characterWidget, &CharacterWidget::characterSelected,
diff --git a/examples/widgets/widgets/icons/imagedelegate.cpp b/examples/widgets/widgets/icons/imagedelegate.cpp
index 980013daee..3c873f1e24 100644
--- a/examples/widgets/widgets/icons/imagedelegate.cpp
+++ b/examples/widgets/widgets/icons/imagedelegate.cpp
@@ -71,8 +71,7 @@ QWidget *ImageDelegate::createEditor(QWidget *parent,
else if (index.column() == 2)
comboBox->addItems(IconPreviewArea::iconStateNames());
- typedef void (QComboBox::*QComboBoxIntSignal)(int);
- connect(comboBox, static_cast<QComboBoxIntSignal>(&QComboBox::activated),
+ connect(comboBox, QOverload<int>::of(&QComboBox::activated),
this, &ImageDelegate::emitCommitData);
return comboBox;
diff --git a/examples/widgets/widgets/icons/mainwindow.cpp b/examples/widgets/widgets/icons/mainwindow.cpp
index 5f3882de94..f704b8306f 100644
--- a/examples/widgets/widgets/icons/mainwindow.cpp
+++ b/examples/widgets/widgets/icons/mainwindow.cpp
@@ -362,8 +362,7 @@ QWidget *MainWindow::createIconSizeGroupBox()
sizeButtonGroup = new QButtonGroup(this);
sizeButtonGroup->setExclusive(true);
- typedef void (QButtonGroup::*QButtonGroupIntBoolSignal)(int, bool);
- connect(sizeButtonGroup, static_cast<QButtonGroupIntBoolSignal>(&QButtonGroup::buttonToggled),
+ connect(sizeButtonGroup, QOverload<int, bool>::of(&QButtonGroup::buttonToggled),
this, &MainWindow::changeSize);
QRadioButton *smallRadioButton = new QRadioButton;
@@ -391,8 +390,7 @@ QWidget *MainWindow::createIconSizeGroupBox()
//! [26]
//! [27]
- typedef void (QSpinBox::*QSpinBoxIntSignal)(int);
- connect(otherSpinBox, static_cast<QSpinBoxIntSignal>(&QSpinBox::valueChanged),
+ connect(otherSpinBox, QOverload<int>::of(&QSpinBox::valueChanged),
this, &MainWindow::triggerChangeSize);
QHBoxLayout *otherSizeLayout = new QHBoxLayout;