summaryrefslogtreecommitdiffstats
path: root/examples
diff options
context:
space:
mode:
Diffstat (limited to 'examples')
-rw-r--r--examples/corelib/serialization/convert/cborconverter.cpp13
-rw-r--r--examples/network/bearermonitor/bearermonitor.cpp6
-rw-r--r--examples/network/dnslookup/dnslookup.cpp24
-rw-r--r--examples/network/http/httpwindow.cpp2
-rw-r--r--examples/network/loopback/dialog.cpp6
-rw-r--r--examples/network/network-chat/client.cpp7
-rw-r--r--examples/network/network-chat/peermanager.cpp12
-rw-r--r--examples/network/network-chat/peermanager.h2
-rw-r--r--examples/network/torrent/addtorrentdialog.cpp3
-rw-r--r--examples/network/torrent/filemanager.cpp7
-rw-r--r--examples/network/torrent/mainwindow.cpp6
-rw-r--r--examples/network/torrent/metainfo.cpp8
-rw-r--r--examples/network/torrent/ratecontroller.cpp4
-rw-r--r--examples/network/torrent/torrentclient.cpp42
-rw-r--r--examples/network/torrent/torrentserver.cpp2
-rw-r--r--examples/sql/querymodel/customsqlmodel.cpp2
-rw-r--r--examples/widgets/animation/easing/window.cpp15
-rw-r--r--examples/widgets/animation/moveblocks/main.cpp4
-rw-r--r--examples/widgets/animation/states/main.cpp6
-rw-r--r--examples/widgets/animation/stickman/lifecycle.cpp16
-rw-r--r--examples/widgets/animation/stickman/stickman.cpp2
-rw-r--r--examples/widgets/animation/sub-attaq/animationmanager.cpp4
-rw-r--r--examples/widgets/animation/sub-attaq/boat.cpp10
-rw-r--r--examples/widgets/animation/sub-attaq/bomb.cpp10
-rw-r--r--examples/widgets/animation/sub-attaq/graphicsscene.cpp18
-rw-r--r--examples/widgets/animation/sub-attaq/qanimationstate.cpp6
-rw-r--r--examples/widgets/animation/sub-attaq/states.cpp12
-rw-r--r--examples/widgets/animation/sub-attaq/submarine.cpp12
-rw-r--r--examples/widgets/animation/sub-attaq/submarine_p.h3
-rw-r--r--examples/widgets/animation/sub-attaq/torpedo.cpp10
-rw-r--r--examples/widgets/doc/dropsite.qdoc8
-rw-r--r--examples/widgets/doc/src/addressbook.qdoc11
-rw-r--r--examples/widgets/doc/src/fetchmore.qdoc2
-rw-r--r--examples/widgets/doc/src/stardelegate.qdoc14
-rw-r--r--examples/widgets/draganddrop/dropsite/dropsitewindow.cpp3
-rw-r--r--examples/widgets/effects/fademessage/fademessage.cpp2
-rw-r--r--examples/widgets/graphicsview/boxes/scene.cpp42
-rw-r--r--examples/widgets/graphicsview/chip/view.cpp32
-rw-r--r--examples/widgets/graphicsview/collidingmice/main.cpp2
-rw-r--r--examples/widgets/graphicsview/diagramscene/diagramscene.cpp8
-rw-r--r--examples/widgets/graphicsview/diagramscene/mainwindow.cpp64
-rw-r--r--examples/widgets/graphicsview/embeddeddialogs/customproxy.cpp8
-rw-r--r--examples/widgets/itemviews/addressbook/adddialog.cpp38
-rw-r--r--examples/widgets/itemviews/addressbook/adddialog.h14
-rw-r--r--examples/widgets/itemviews/addressbook/addresswidget.cpp69
-rw-r--r--examples/widgets/itemviews/addressbook/addresswidget.h5
-rw-r--r--examples/widgets/itemviews/addressbook/mainwindow.cpp18
-rw-r--r--examples/widgets/itemviews/addressbook/mainwindow.h6
-rw-r--r--examples/widgets/itemviews/addressbook/newaddresstab.cpp21
-rw-r--r--examples/widgets/itemviews/addressbook/newaddresstab.h10
-rw-r--r--examples/widgets/itemviews/addressbook/tablemodel.cpp52
-rw-r--r--examples/widgets/itemviews/addressbook/tablemodel.h10
-rw-r--r--examples/widgets/itemviews/coloreditorfactory/colorlisteditor.cpp10
-rw-r--r--examples/widgets/itemviews/coloreditorfactory/colorlisteditor.h4
-rw-r--r--examples/widgets/itemviews/coloreditorfactory/window.cpp17
-rw-r--r--examples/widgets/itemviews/customsortfiltermodel/filterwidget.cpp5
-rw-r--r--examples/widgets/itemviews/customsortfiltermodel/filterwidget.h2
-rw-r--r--examples/widgets/itemviews/customsortfiltermodel/mysortfilterproxymodel.cpp6
-rw-r--r--examples/widgets/itemviews/customsortfiltermodel/window.cpp13
-rw-r--r--examples/widgets/itemviews/fetchmore/filelistmodel.cpp25
-rw-r--r--examples/widgets/itemviews/fetchmore/filelistmodel.h3
-rw-r--r--examples/widgets/itemviews/fetchmore/window.cpp4
-rw-r--r--examples/widgets/itemviews/fetchmore/window.h2
-rw-r--r--examples/widgets/itemviews/interview/model.cpp3
-rw-r--r--examples/widgets/itemviews/interview/model.h4
-rw-r--r--examples/widgets/itemviews/pixelator/mainwindow.cpp2
-rw-r--r--examples/widgets/itemviews/pixelator/pixeldelegate.cpp14
-rw-r--r--examples/widgets/itemviews/pixelator/pixeldelegate.h6
-rw-r--r--examples/widgets/itemviews/puzzle/piecesmodel.cpp9
-rw-r--r--examples/widgets/itemviews/puzzle/piecesmodel.h10
-rw-r--r--examples/widgets/itemviews/simpledommodel/domitem.cpp30
-rw-r--r--examples/widgets/itemviews/simpledommodel/domitem.h6
-rw-r--r--examples/widgets/itemviews/simpledommodel/dommodel.cpp40
-rw-r--r--examples/widgets/itemviews/simpledommodel/dommodel.h2
-rw-r--r--examples/widgets/itemviews/simpledommodel/mainwindow.cpp9
-rw-r--r--examples/widgets/itemviews/simpledommodel/mainwindow.h2
-rw-r--r--examples/widgets/itemviews/simplewidgetmapper/window.h2
-rw-r--r--examples/widgets/itemviews/spinboxdelegate/delegate.cpp7
-rw-r--r--examples/widgets/itemviews/spinboxdelegate/delegate.h6
-rw-r--r--examples/widgets/itemviews/spreadsheet/main.cpp3
-rw-r--r--examples/widgets/itemviews/spreadsheet/printview.cpp5
-rw-r--r--examples/widgets/itemviews/spreadsheet/spreadsheet.cpp56
-rw-r--r--examples/widgets/itemviews/spreadsheet/spreadsheet.h4
-rw-r--r--examples/widgets/itemviews/spreadsheet/spreadsheetdelegate.cpp12
-rw-r--r--examples/widgets/itemviews/spreadsheet/spreadsheetdelegate.h4
-rw-r--r--examples/widgets/itemviews/spreadsheet/spreadsheetitem.cpp35
-rw-r--r--examples/widgets/itemviews/spreadsheet/spreadsheetitem.h7
-rw-r--r--examples/widgets/itemviews/stardelegate/main.cpp5
-rw-r--r--examples/widgets/itemviews/stardelegate/stardelegate.cpp8
-rw-r--r--examples/widgets/itemviews/stardelegate/stardelegate.h3
-rw-r--r--examples/widgets/itemviews/stardelegate/stareditor.cpp20
-rw-r--r--examples/widgets/itemviews/stardelegate/stareditor.h5
-rw-r--r--examples/widgets/itemviews/stardelegate/starrating.cpp27
-rw-r--r--examples/widgets/itemviews/stardelegate/starrating.h8
-rw-r--r--examples/widgets/itemviews/storageview/main.cpp7
-rw-r--r--examples/widgets/itemviews/storageview/storagemodel.cpp8
-rw-r--r--examples/widgets/itemviews/storageview/storagemodel.h2
-rw-r--r--examples/widgets/layouts/basiclayouts/dialog.cpp6
-rw-r--r--examples/widgets/mainwindows/application/mainwindow.cpp8
-rw-r--r--examples/widgets/mainwindows/dockwidgets/mainwindow.cpp4
-rw-r--r--examples/widgets/mainwindows/mdi/mdichild.cpp8
-rw-r--r--examples/widgets/mainwindows/sdi/mainwindow.cpp8
-rw-r--r--examples/widgets/painting/basicdrawing/window.cpp32
-rw-r--r--examples/widgets/painting/composition/composition.cpp62
-rw-r--r--examples/widgets/painting/concentriccircles/window.cpp4
-rw-r--r--examples/widgets/painting/deform/pathdeform.cpp43
-rw-r--r--examples/widgets/painting/fontsampler/mainwindow.cpp15
-rw-r--r--examples/widgets/painting/gradients/gradients.cpp2
-rw-r--r--examples/widgets/painting/imagecomposition/imagecomposer.cpp9
-rw-r--r--examples/widgets/painting/painterpaths/window.cpp42
-rw-r--r--examples/widgets/painting/pathstroke/pathstroke.cpp56
-rw-r--r--examples/widgets/painting/shared/hoverpoints.cpp4
-rw-r--r--examples/widgets/painting/transformations/window.cpp7
-rw-r--r--examples/widgets/richtext/calendar/mainwindow.cpp10
-rw-r--r--examples/widgets/richtext/orderform/mainwindow.cpp2
-rw-r--r--examples/widgets/richtext/syntaxhighlighter/mainwindow.cpp13
-rw-r--r--examples/widgets/statemachine/factorial/main.cpp4
-rw-r--r--examples/widgets/statemachine/rogue/window.cpp3
-rw-r--r--examples/widgets/statemachine/trafficlight/main.cpp16
-rw-r--r--examples/widgets/statemachine/twowaybutton/main.cpp4
-rw-r--r--examples/widgets/tools/codecs/mainwindow.cpp14
-rw-r--r--examples/widgets/tools/codecs/previewform.cpp2
-rw-r--r--examples/widgets/tools/completer/mainwindow.cpp24
-rw-r--r--examples/widgets/tools/customcompleter/mainwindow.cpp10
-rw-r--r--examples/widgets/tools/customcompleter/textedit.cpp4
-rw-r--r--examples/widgets/tools/echoplugin/echowindow/echowindow.cpp3
-rw-r--r--examples/widgets/tools/i18n/languagechooser.cpp8
-rw-r--r--examples/widgets/tools/regexp/regexpdialog.cpp18
-rw-r--r--examples/widgets/tools/settingseditor/settingstree.cpp6
-rw-r--r--examples/widgets/tools/treemodelcompleter/mainwindow.cpp30
-rw-r--r--examples/widgets/tools/undo/mainwindow.cpp50
-rw-r--r--examples/widgets/tools/undoframework/mainwindow.cpp22
-rw-r--r--examples/widgets/touch/dials/main.cpp4
-rw-r--r--examples/widgets/touch/fingerpaint/mainwindow.cpp22
-rw-r--r--examples/widgets/touch/fingerpaint/scribblearea.cpp6
-rw-r--r--examples/widgets/touch/pinchzoom/mouse.cpp2
-rw-r--r--examples/widgets/tutorials/addressbook/part2/addressbook.cpp9
-rw-r--r--examples/widgets/tutorials/addressbook/part3/addressbook.cpp16
-rw-r--r--examples/widgets/tutorials/addressbook/part4/addressbook.cpp21
-rw-r--r--examples/widgets/tutorials/addressbook/part5/addressbook.cpp24
-rw-r--r--examples/widgets/tutorials/addressbook/part5/finddialog.cpp6
-rw-r--r--examples/widgets/tutorials/addressbook/part6/addressbook.cpp30
-rw-r--r--examples/widgets/tutorials/addressbook/part6/finddialog.cpp6
-rw-r--r--examples/widgets/tutorials/addressbook/part7/addressbook.cpp33
-rw-r--r--examples/widgets/tutorials/addressbook/part7/finddialog.cpp6
-rw-r--r--examples/widgets/tutorials/gettingStarted/gsQt/part2/main.cpp3
-rw-r--r--examples/widgets/tutorials/gettingStarted/gsQt/part3/main.cpp3
-rw-r--r--examples/widgets/tutorials/gettingStarted/gsQt/part4/main.cpp10
-rw-r--r--examples/widgets/tutorials/gettingStarted/gsQt/part5/main.cpp10
-rw-r--r--examples/widgets/tutorials/widgets/nestedlayouts/main.cpp35
-rw-r--r--examples/widgets/widgets/calendarwidget/window.cpp3
-rw-r--r--examples/widgets/widgets/calendarwidget/window.h2
-rw-r--r--examples/widgets/widgets/charactermap/mainwindow.cpp3
-rw-r--r--examples/widgets/widgets/charactermap/mainwindow.h2
-rw-r--r--examples/widgets/widgets/icons/mainwindow.cpp3
-rw-r--r--examples/widgets/widgets/icons/mainwindow.h2
-rw-r--r--examples/widgets/widgets/imageviewer/imageviewer.cpp7
-rw-r--r--examples/widgets/widgets/imageviewer/imageviewer.h2
-rw-r--r--examples/widgets/widgets/lineedits/window.cpp3
-rw-r--r--examples/widgets/widgets/lineedits/window.h2
-rw-r--r--examples/widgets/widgets/mousebuttons/buttontester.h5
-rw-r--r--examples/widgets/widgets/scribble/mainwindow.cpp4
-rw-r--r--examples/widgets/widgets/scribble/mainwindow.h2
-rw-r--r--examples/widgets/widgets/sliders/window.cpp3
-rw-r--r--examples/widgets/widgets/sliders/window.h2
-rw-r--r--examples/widgets/widgets/spinboxes/window.cpp3
-rw-r--r--examples/widgets/widgets/spinboxes/window.h2
-rw-r--r--examples/widgets/widgets/stylesheet/mainwindow.cpp3
-rw-r--r--examples/widgets/widgets/stylesheet/mainwindow.h2
-rw-r--r--examples/widgets/widgets/tetrix/tetrixwindow.cpp3
-rw-r--r--examples/widgets/widgets/tetrix/tetrixwindow.h2
-rw-r--r--examples/widgets/widgets/tooltips/sortingbox.cpp3
-rw-r--r--examples/widgets/widgets/tooltips/sortingbox.h2
-rw-r--r--examples/widgets/widgets/validators/main.cpp85
-rw-r--r--examples/widgets/widgets/validators/validators.pro4
-rw-r--r--examples/widgets/widgets/validators/validatorwidget.cpp122
-rw-r--r--examples/widgets/widgets/validators/validatorwidget.h64
-rw-r--r--examples/widgets/widgets/windowflags/controllerwindow.cpp3
-rw-r--r--examples/widgets/widgets/windowflags/controllerwindow.h2
179 files changed, 1236 insertions, 1083 deletions
diff --git a/examples/corelib/serialization/convert/cborconverter.cpp b/examples/corelib/serialization/convert/cborconverter.cpp
index 41724c935e..f906c81062 100644
--- a/examples/corelib/serialization/convert/cborconverter.cpp
+++ b/examples/corelib/serialization/convert/cborconverter.cpp
@@ -84,19 +84,6 @@ static const char diagnosticHelp[] =
QT_BEGIN_NAMESPACE
-QDataStream &operator<<(QDataStream &ds, QCborSimpleType st)
-{
- return ds << quint8(st);
-}
-
-QDataStream &operator>>(QDataStream &ds, QCborSimpleType &st)
-{
- quint8 v;
- ds >> v;
- st = QCborSimpleType(v);
- return ds;
-}
-
QDataStream &operator<<(QDataStream &ds, QCborTag tag)
{
return ds << quint64(tag);
diff --git a/examples/network/bearermonitor/bearermonitor.cpp b/examples/network/bearermonitor/bearermonitor.cpp
index f9b899b06b..1a54f5ec8a 100644
--- a/examples/network/bearermonitor/bearermonitor.cpp
+++ b/examples/network/bearermonitor/bearermonitor.cpp
@@ -142,7 +142,8 @@ void BearerMonitor::configurationAdded(const QNetworkConfiguration &config, QTre
treeWidget->addTopLevelItem(item);
if (config.type() == QNetworkConfiguration::ServiceNetwork) {
- foreach (const QNetworkConfiguration &child, config.children())
+ const QList<QNetworkConfiguration> children = config.children();
+ for (const QNetworkConfiguration &child : children)
configurationAdded(child, item);
}
}
@@ -181,7 +182,8 @@ void BearerMonitor::configurationChanged(const QNetworkConfiguration &config)
void BearerMonitor::updateSnapConfiguration(QTreeWidgetItem *parent, const QNetworkConfiguration &snap)
{
QMap<QString, QTreeWidgetItem *> itemMap;
- foreach (QTreeWidgetItem *item, parent->takeChildren())
+ const QList<QTreeWidgetItem *> children = parent->takeChildren();
+ for (QTreeWidgetItem *item : children)
itemMap.insert(item->data(0, Qt::UserRole).toString(), item);
QList<QNetworkConfiguration> allConfigurations = snap.children();
diff --git a/examples/network/dnslookup/dnslookup.cpp b/examples/network/dnslookup/dnslookup.cpp
index 63819b170c..a2d927d43d 100644
--- a/examples/network/dnslookup/dnslookup.cpp
+++ b/examples/network/dnslookup/dnslookup.cpp
@@ -172,35 +172,43 @@ void DnsManager::showResults()
printf("Error: %i (%s)\n", dns->error(), qPrintable(dns->errorString()));
// CNAME records
- foreach (const QDnsDomainNameRecord &record, dns->canonicalNameRecords())
+ const QList<QDnsDomainNameRecord> cnameRecords = dns->canonicalNameRecords();
+ for (const QDnsDomainNameRecord &record : cnameRecords)
printf("%s\t%i\tIN\tCNAME\t%s\n", qPrintable(record.name()), record.timeToLive(), qPrintable(record.value()));
// A and AAAA records
- foreach (const QDnsHostAddressRecord &record, dns->hostAddressRecords()) {
+ const QList<QDnsHostAddressRecord> aRecords = dns->hostAddressRecords();
+ for (const QDnsHostAddressRecord &record : aRecords) {
const char *type = (record.value().protocol() == QAbstractSocket::IPv6Protocol) ? "AAAA" : "A";
printf("%s\t%i\tIN\t%s\t%s\n", qPrintable(record.name()), record.timeToLive(), type, qPrintable(record.value().toString()));
}
// MX records
- foreach (const QDnsMailExchangeRecord &record, dns->mailExchangeRecords())
+ const QList<QDnsMailExchangeRecord> mxRecords = dns->mailExchangeRecords();
+ for (const QDnsMailExchangeRecord &record : mxRecords)
printf("%s\t%i\tIN\tMX\t%u %s\n", qPrintable(record.name()), record.timeToLive(), record.preference(), qPrintable(record.exchange()));
// NS records
- foreach (const QDnsDomainNameRecord &record, dns->nameServerRecords())
+ const QList<QDnsDomainNameRecord> nsRecords = dns->nameServerRecords();
+ for (const QDnsDomainNameRecord &record : nsRecords)
printf("%s\t%i\tIN\tNS\t%s\n", qPrintable(record.name()), record.timeToLive(), qPrintable(record.value()));
// PTR records
- foreach (const QDnsDomainNameRecord &record, dns->pointerRecords())
+ const QList<QDnsDomainNameRecord> ptrRecords = dns->pointerRecords();
+ for (const QDnsDomainNameRecord &record : ptrRecords)
printf("%s\t%i\tIN\tPTR\t%s\n", qPrintable(record.name()), record.timeToLive(), qPrintable(record.value()));
// SRV records
- foreach (const QDnsServiceRecord &record, dns->serviceRecords())
+ const QList<QDnsServiceRecord> srvRecords = dns->serviceRecords();
+ for (const QDnsServiceRecord &record : srvRecords)
printf("%s\t%i\tIN\tSRV\t%u %u %u %s\n", qPrintable(record.name()), record.timeToLive(), record.priority(), record.weight(), record.port(), qPrintable(record.target()));
// TXT records
- foreach (const QDnsTextRecord &record, dns->textRecords()) {
+ const QList<QDnsTextRecord> txtRecords = dns->textRecords();
+ for (const QDnsTextRecord &record : txtRecords) {
QStringList values;
- foreach (const QByteArray &ba, record.values())
+ const QList<QByteArray> dnsRecords = record.values();
+ for (const QByteArray &ba : dnsRecords)
values << "\"" + QString::fromLatin1(ba) + "\"";
printf("%s\t%i\tIN\tTXT\t%s\n", qPrintable(record.name()), record.timeToLive(), qPrintable(values.join(' ')));
}
diff --git a/examples/network/http/httpwindow.cpp b/examples/network/http/httpwindow.cpp
index ec90b8f7fe..39ffb3cc87 100644
--- a/examples/network/http/httpwindow.cpp
+++ b/examples/network/http/httpwindow.cpp
@@ -319,7 +319,7 @@ void HttpWindow::slotAuthenticationRequired(QNetworkReply *, QAuthenticator *aut
void HttpWindow::sslErrors(QNetworkReply *, const QList<QSslError> &errors)
{
QString errorString;
- foreach (const QSslError &error, errors) {
+ for (const QSslError &error : errors) {
if (!errorString.isEmpty())
errorString += '\n';
errorString += error.errorString();
diff --git a/examples/network/loopback/dialog.cpp b/examples/network/loopback/dialog.cpp
index b4e6b0fd5e..d87f024031 100644
--- a/examples/network/loopback/dialog.cpp
+++ b/examples/network/loopback/dialog.cpp
@@ -99,7 +99,7 @@ void Dialog::start()
startButton->setEnabled(false);
#ifndef QT_NO_CURSOR
- QApplication::setOverrideCursor(Qt::WaitCursor);
+ QGuiApplication::setOverrideCursor(Qt::WaitCursor);
#endif
bytesWritten = 0;
@@ -162,7 +162,7 @@ void Dialog::updateServerProgress()
tcpServerConnection->close();
startButton->setEnabled(true);
#ifndef QT_NO_CURSOR
- QApplication::restoreOverrideCursor();
+ QGuiApplication::restoreOverrideCursor();
#endif
}
}
@@ -198,6 +198,6 @@ void Dialog::displayError(QAbstractSocket::SocketError socketError)
serverStatusLabel->setText(tr("Server ready"));
startButton->setEnabled(true);
#ifndef QT_NO_CURSOR
- QApplication::restoreOverrideCursor();
+ QGuiApplication::restoreOverrideCursor();
#endif
}
diff --git a/examples/network/network-chat/client.cpp b/examples/network/network-chat/client.cpp
index 97c2c44b6b..b76ef18238 100644
--- a/examples/network/network-chat/client.cpp
+++ b/examples/network/network-chat/client.cpp
@@ -71,8 +71,7 @@ void Client::sendMessage(const QString &message)
if (message.isEmpty())
return;
- QList<Connection *> connections = peers.values();
- foreach (Connection *connection, connections)
+ for (Connection *connection : qAsConst(peers))
connection->sendMessage(message);
}
@@ -90,8 +89,8 @@ bool Client::hasConnection(const QHostAddress &senderIp, int senderPort) const
if (!peers.contains(senderIp))
return false;
- QList<Connection *> connections = peers.values(senderIp);
- foreach (Connection *connection, connections) {
+ const QList<Connection *> connections = peers.values(senderIp);
+ for (const Connection *connection : connections) {
if (connection->peerPort() == senderPort)
return true;
}
diff --git a/examples/network/network-chat/peermanager.cpp b/examples/network/network-chat/peermanager.cpp
index 38fa2e8e50..5c48edb1b9 100644
--- a/examples/network/network-chat/peermanager.cpp
+++ b/examples/network/network-chat/peermanager.cpp
@@ -104,9 +104,9 @@ void PeerManager::startBroadcasting()
broadcastTimer.start();
}
-bool PeerManager::isLocalHostAddress(const QHostAddress &address)
+bool PeerManager::isLocalHostAddress(const QHostAddress &address) const
{
- foreach (QHostAddress localAddress, ipAddresses) {
+ for (const QHostAddress &localAddress : ipAddresses) {
if (address.isEqual(localAddress))
return true;
}
@@ -125,7 +125,7 @@ void PeerManager::sendBroadcastDatagram()
}
bool validBroadcastAddresses = true;
- foreach (QHostAddress address, broadcastAddresses) {
+ for (const QHostAddress &address : qAsConst(broadcastAddresses)) {
if (broadcastSocket.writeDatagram(datagram, address,
broadcastPort) == -1)
validBroadcastAddresses = false;
@@ -182,8 +182,10 @@ void PeerManager::updateAddresses()
{
broadcastAddresses.clear();
ipAddresses.clear();
- foreach (QNetworkInterface interface, QNetworkInterface::allInterfaces()) {
- foreach (QNetworkAddressEntry entry, interface.addressEntries()) {
+ const QList<QNetworkInterface> interfaces = QNetworkInterface::allInterfaces();
+ for (const QNetworkInterface &interface : interfaces) {
+ const QList<QNetworkAddressEntry> entries = interface.addressEntries();
+ for (const QNetworkAddressEntry &entry : entries) {
QHostAddress broadcastAddress = entry.broadcast();
if (broadcastAddress != QHostAddress::Null && entry.ip() != QHostAddress::LocalHost) {
broadcastAddresses << broadcastAddress;
diff --git a/examples/network/network-chat/peermanager.h b/examples/network/network-chat/peermanager.h
index b79028235b..6105c83115 100644
--- a/examples/network/network-chat/peermanager.h
+++ b/examples/network/network-chat/peermanager.h
@@ -70,7 +70,7 @@ public:
void setServerPort(int port);
QString userName() const;
void startBroadcasting();
- bool isLocalHostAddress(const QHostAddress &address);
+ bool isLocalHostAddress(const QHostAddress &address) const;
signals:
void newConnection(Connection *connection);
diff --git a/examples/network/torrent/addtorrentdialog.cpp b/examples/network/torrent/addtorrentdialog.cpp
index 0d197ec5fa..c87110ac4a 100644
--- a/examples/network/torrent/addtorrentdialog.cpp
+++ b/examples/network/torrent/addtorrentdialog.cpp
@@ -148,7 +148,8 @@ void AddTorrentDialog::setTorrent(const QString &torrentFile)
ui.torrentContents->setHtml(metaInfo.singleFile().name);
} else {
QString html;
- foreach (MetaInfoMultiFile file, metaInfo.multiFiles()) {
+ const QList<MetaInfoMultiFile> multiFiles = metaInfo.multiFiles();
+ for (const MetaInfoMultiFile &file : multiFiles) {
QString name = metaInfo.name();
if (!name.isEmpty()) {
html += name;
diff --git a/examples/network/torrent/filemanager.cpp b/examples/network/torrent/filemanager.cpp
index d05408cebc..69345442c7 100644
--- a/examples/network/torrent/filemanager.cpp
+++ b/examples/network/torrent/filemanager.cpp
@@ -77,7 +77,7 @@ FileManager::~FileManager()
cond.wakeOne();
wait();
- foreach (QFile *file, files) {
+ for (QFile *file : qAsConst(files)) {
file->close();
delete file;
}
@@ -285,7 +285,8 @@ bool FileManager::generateFiles()
return false;
}
- foreach (const MetaInfoMultiFile &entry, metaInfo.multiFiles()) {
+ const QList<MetaInfoMultiFile> multiFiles = metaInfo.multiFiles();
+ for (const MetaInfoMultiFile &entry : multiFiles) {
QString filePath = QFileInfo(prefix + entry.path).path();
if (!QFile::exists(filePath)) {
if (!dir.mkpath(filePath)) {
@@ -437,7 +438,7 @@ void FileManager::verifyFileContents()
}
// Verify all pending pieces
- foreach (int index, newPendingVerificationRequests)
+ for (int index : qAsConst(newPendingVerificationRequests))
emit pieceVerified(index, verifySinglePiece(index));
}
diff --git a/examples/network/torrent/mainwindow.cpp b/examples/network/torrent/mainwindow.cpp
index 660472c05c..39b166101d 100644
--- a/examples/network/torrent/mainwindow.cpp
+++ b/examples/network/torrent/mainwindow.cpp
@@ -239,7 +239,7 @@ int MainWindow::rowOfClient(TorrentClient *client) const
// Return the row that displays this client's status, or -1 if the
// client is not known.
int row = 0;
- foreach (Job job, jobs) {
+ for (const Job &job : jobs) {
if (job.client == client)
return row;
++row;
@@ -358,7 +358,7 @@ bool MainWindow::addTorrent(const QString &fileName, const QString &destinationF
const QByteArray &resumeState)
{
// Check if the torrent is already being downloaded.
- foreach (Job job, jobs) {
+ for (const Job &job : qAsConst(jobs)) {
if (job.torrentFileName == fileName && job.destinationDirectory == destinationFolder) {
QMessageBox::warning(this, tr("Already downloading"),
tr("The torrent file %1 is "
@@ -684,7 +684,7 @@ void MainWindow::closeEvent(QCloseEvent *)
// them to signal that they have stopped.
jobsToStop = 0;
jobsStopped = 0;
- foreach (Job job, jobs) {
+ for (const Job &job : qAsConst(jobs)) {
++jobsToStop;
TorrentClient *client = job.client;
client->disconnect();
diff --git a/examples/network/torrent/metainfo.cpp b/examples/network/torrent/metainfo.cpp
index 565533e2f9..29b34b12a0 100644
--- a/examples/network/torrent/metainfo.cpp
+++ b/examples/network/torrent/metainfo.cpp
@@ -101,10 +101,10 @@ bool MetaInfo::parse(const QByteArray &data)
QList<QVariant> files = info.value("files").toList();
for (int i = 0; i < files.size(); ++i) {
- QMap<QByteArray, QVariant> file = qvariant_cast<Dictionary>(files.at(i));
- QList<QVariant> pathElements = file.value("path").toList();
+ const QMap<QByteArray, QVariant> file = qvariant_cast<Dictionary>(files.at(i));
+ const QList<QVariant> pathElements = file.value("path").toList();
QByteArray path;
- foreach (QVariant p, pathElements) {
+ for (const QVariant &p : pathElements) {
if (!path.isEmpty())
path += '/';
path += p.toByteArray();
@@ -221,7 +221,7 @@ qint64 MetaInfo::totalSize() const
return singleFile().length;
qint64 size = 0;
- foreach (MetaInfoMultiFile file, multiFiles())
+ for (const MetaInfoMultiFile &file : metaInfoMultiFiles)
size += file.length;
return size;
}
diff --git a/examples/network/torrent/ratecontroller.cpp b/examples/network/torrent/ratecontroller.cpp
index cec05c7455..47b49dba30 100644
--- a/examples/network/torrent/ratecontroller.cpp
+++ b/examples/network/torrent/ratecontroller.cpp
@@ -78,7 +78,7 @@ void RateController::removeSocket(PeerWireClient *socket)
void RateController::setDownloadLimit(int bytesPerSecond)
{
downLimit = bytesPerSecond;
- foreach (PeerWireClient *socket, sockets)
+ for (PeerWireClient *socket : qAsConst(sockets))
socket->setReadBufferSize(downLimit * 4);
}
@@ -108,7 +108,7 @@ void RateController::transfer()
}
QSet<PeerWireClient *> pendingSockets;
- foreach (PeerWireClient *client, sockets) {
+ for (PeerWireClient *client : qAsConst(sockets)) {
if (client->canTransferMore())
pendingSockets << client;
}
diff --git a/examples/network/torrent/torrentclient.cpp b/examples/network/torrent/torrentclient.cpp
index 95232646ab..d01a5f3d9e 100644
--- a/examples/network/torrent/torrentclient.cpp
+++ b/examples/network/torrent/torrentclient.cpp
@@ -383,7 +383,7 @@ qint64 TorrentClient::uploadedBytes() const
int TorrentClient::connectedPeerCount() const
{
int tmp = 0;
- foreach (PeerWireClient *client, d->connections) {
+ for (PeerWireClient *client : d->connections) {
if (client->state() == QAbstractSocket::ConnectedState)
++tmp;
}
@@ -393,7 +393,7 @@ int TorrentClient::connectedPeerCount() const
int TorrentClient::seedCount() const
{
int tmp = 0;
- foreach (PeerWireClient *client, d->connections) {
+ for (PeerWireClient *client : d->connections) {
if (client->availablePieces().count(true) == d->pieceCount)
++tmp;
}
@@ -464,7 +464,7 @@ void TorrentClient::stop()
}
// Abort all existing connections
- foreach (PeerWireClient *client, d->connections) {
+ for (PeerWireClient *client : qAsConst(d->connections)) {
RateController::instance()->removeSocket(client);
ConnectionManager::instance()->removeConnection(client);
client->abort();
@@ -487,7 +487,7 @@ void TorrentClient::setPaused(bool paused)
// connections to 0. Keep the list of peers, so we can quickly
// resume later.
d->setState(Paused);
- foreach (PeerWireClient *client, d->connections)
+ for (PeerWireClient *client : qAsConst(d->connections))
client->abort();
d->connections.clear();
TorrentServer::instance()->removeClient(this);
@@ -622,7 +622,7 @@ void TorrentClient::pieceVerified(int pieceIndex, bool ok)
}
// Update the peer list so we know who's still interesting.
- foreach (TorrentPeer *peer, d->peers) {
+ for (TorrentPeer *peer : qAsConst(d->peers)) {
if (!peer->interesting)
continue;
bool interesting = false;
@@ -642,7 +642,7 @@ void TorrentClient::pieceVerified(int pieceIndex, bool ok)
d->incompletePieces.clearBit(pieceIndex);
// Notify connected peers.
- foreach (PeerWireClient *client, d->connections) {
+ for (PeerWireClient *client : qAsConst(d->connections)) {
if (client->state() == QAbstractSocket::ConnectedState
&& !client->availablePieces().testBit(pieceIndex)) {
client->sendPieceNotification(pieceIndex);
@@ -720,9 +720,9 @@ QList<TorrentPeer *> TorrentClient::weighedFreePeers() const
qint64 now = QDateTime::currentSecsSinceEpoch();
QList<TorrentPeer *> freePeers;
QMap<QString, int> connectionsPerPeer;
- foreach (TorrentPeer *peer, d->peers) {
+ for (TorrentPeer *peer : d->peers) {
bool busy = false;
- foreach (PeerWireClient *client, d->connections) {
+ for (PeerWireClient *client : d->connections) {
if (client->state() == PeerWireClient::ConnectedState
&& client->peerAddress() == peer->address
&& client->peerPort() == peer->port) {
@@ -742,7 +742,7 @@ QList<TorrentPeer *> TorrentClient::weighedFreePeers() const
// Assign points based on connection speed and pieces available.
QList<QPair<int, TorrentPeer *> > points;
- foreach (TorrentPeer *peer, freePeers) {
+ for (TorrentPeer *peer : qAsConst(freePeers)) {
int tmp = 0;
if (peer->interesting) {
tmp += peer->numCompletedPieces;
@@ -765,7 +765,7 @@ QList<TorrentPeer *> TorrentClient::weighedFreePeers() const
QMultiMap<int, TorrentPeer *> pointMap;
int lowestScore = 0;
int lastIndex = 0;
- foreach (PointPair point, points) {
+ for (const PointPair &point : qAsConst(points)) {
if (point.first > lowestScore) {
lowestScore = point.first;
++lastIndex;
@@ -816,7 +816,7 @@ void TorrentClient::setupOutgoingConnection()
PeerWireClient *client = qobject_cast<PeerWireClient *>(sender());
// Update connection statistics.
- foreach (TorrentPeer *peer, d->peers) {
+ for (TorrentPeer *peer : qAsConst(d->peers)) {
if (peer->port == client->peerPort() && peer->address == client->peerAddress()) {
peer->connectTime = peer->lastVisited - peer->connectStart;
break;
@@ -1085,7 +1085,7 @@ void TorrentClient::scheduleUploads()
// no use in unchoking them.
QList<PeerWireClient *> allClients = d->connections;
QMultiMap<int, PeerWireClient *> transferSpeeds;
- foreach (PeerWireClient *client, allClients) {
+ for (PeerWireClient *client : qAsConst(allClients)) {
if (client->state() == QAbstractSocket::ConnectedState
&& client->availablePieces().count(true) != d->pieceCount) {
if (d->state == Seeding) {
@@ -1143,7 +1143,7 @@ void TorrentClient::scheduleDownloads()
// Check what each client is doing, and assign payloads to those
// who are either idle or done.
- foreach (PeerWireClient *client, d->connections)
+ for (PeerWireClient *client : qAsConst(d->connections))
schedulePieceForClient(client);
}
@@ -1222,7 +1222,7 @@ void TorrentClient::schedulePieceForClient(PeerWireClient *client)
incompletePiecesAvailableToClient &= client->availablePieces();
// Remove all pieces that this client has already requested.
- foreach (int i, currentPieces)
+ for (int i : qAsConst(currentPieces))
incompletePiecesAvailableToClient.clearBit(i);
// Only continue if more pieces can be scheduled. If no pieces
@@ -1258,7 +1258,7 @@ void TorrentClient::schedulePieceForClient(PeerWireClient *client)
memset(occurrences, 0, d->pieceCount * sizeof(int));
// Count how many of each piece are available.
- foreach (PeerWireClient *peer, d->connections) {
+ for (PeerWireClient *peer : qAsConst(d->connections)) {
QBitArray peerPieces = peer->availablePieces();
int peerPiecesSize = peerPieces.size();
for (int i = 0; i < peerPiecesSize; ++i) {
@@ -1356,7 +1356,7 @@ void TorrentClient::requestMore(PeerWireClient *client)
// Starting with the first piece that we're waiting for, request
// blocks until the quota is filled up.
- foreach (TorrentPiece *piece, piecesInProgress) {
+ for (TorrentPiece *piece : qAsConst(piecesInProgress)) {
numBlocksInProgress += requestBlocks(client, piece, maxInProgress - numBlocksInProgress);
if (numBlocksInProgress == maxInProgress)
break;
@@ -1450,8 +1450,8 @@ void TorrentClient::peerUnchoked()
void TorrentClient::addToPeerList(const QList<TorrentPeer> &peerList)
{
// Add peers we don't already know of to our list of peers.
- QList<QHostAddress> addresses = QNetworkInterface::allAddresses();
- foreach (TorrentPeer peer, peerList) {
+ const QList<QHostAddress> addresses = QNetworkInterface::allAddresses();
+ for (const TorrentPeer &peer : peerList) {
if (addresses.contains(peer.address)
&& peer.port == TorrentServer::instance()->serverPort()) {
// Skip our own server.
@@ -1459,7 +1459,7 @@ void TorrentClient::addToPeerList(const QList<TorrentPeer> &peerList)
}
bool known = false;
- foreach (TorrentPeer *knownPeer, d->peers) {
+ for (const TorrentPeer *knownPeer : qAsConst(d->peers)) {
if (knownPeer->port == peer.port
&& knownPeer->address == peer.address) {
known = true;
@@ -1486,8 +1486,8 @@ void TorrentClient::addToPeerList(const QList<TorrentPeer> &peerList)
if (d->peers.size() > maxPeers) {
// Find what peers are currently connected & active
QSet<TorrentPeer *> activePeers;
- foreach (TorrentPeer *peer, d->peers) {
- foreach (PeerWireClient *client, d->connections) {
+ for (TorrentPeer *peer : qAsConst(d->peers)) {
+ for (const PeerWireClient *client : qAsConst(d->connections)) {
if (client->peer() == peer && (client->downloadSpeed() + client->uploadSpeed()) > 1024)
activePeers << peer;
}
diff --git a/examples/network/torrent/torrentserver.cpp b/examples/network/torrent/torrentserver.cpp
index da98529fe0..c68f33249c 100644
--- a/examples/network/torrent/torrentserver.cpp
+++ b/examples/network/torrent/torrentserver.cpp
@@ -102,7 +102,7 @@ void TorrentServer::removeClient()
void TorrentServer::processInfoHash(const QByteArray &infoHash)
{
PeerWireClient *peer = qobject_cast<PeerWireClient *>(sender());
- foreach (TorrentClient *client, clients) {
+ for (TorrentClient *client : qAsConst(clients)) {
if (client->state() >= TorrentClient::Searching && client->infoHash() == infoHash) {
peer->disconnect(peer, 0, this, 0);
client->setupIncomingConnection(peer);
diff --git a/examples/sql/querymodel/customsqlmodel.cpp b/examples/sql/querymodel/customsqlmodel.cpp
index 21bedee727..7be0a65882 100644
--- a/examples/sql/querymodel/customsqlmodel.cpp
+++ b/examples/sql/querymodel/customsqlmodel.cpp
@@ -67,7 +67,7 @@ QVariant CustomSqlModel::data(const QModelIndex &index, int role) const
else if (index.column() == 2)
return value.toString().toUpper();
}
- if (role == Qt::TextColorRole && index.column() == 1)
+ if (role == Qt::ForegroundRole && index.column() == 1)
return QVariant::fromValue(QColor(Qt::blue));
return value;
}
diff --git a/examples/widgets/animation/easing/window.cpp b/examples/widgets/animation/easing/window.cpp
index 8c03e0534d..aa12147388 100644
--- a/examples/widgets/animation/easing/window.cpp
+++ b/examples/widgets/animation/easing/window.cpp
@@ -66,11 +66,16 @@ Window::Window(QWidget *parent)
m_ui.amplitudeSpinBox->setValue(dummy.amplitude());
m_ui.overshootSpinBox->setValue(dummy.overshoot());
- connect(m_ui.easingCurvePicker, SIGNAL(currentRowChanged(int)), this, SLOT(curveChanged(int)));
- connect(buttonGroup, SIGNAL(buttonClicked(int)), this, SLOT(pathChanged(int)));
- connect(m_ui.periodSpinBox, SIGNAL(valueChanged(double)), this, SLOT(periodChanged(double)));
- connect(m_ui.amplitudeSpinBox, SIGNAL(valueChanged(double)), this, SLOT(amplitudeChanged(double)));
- connect(m_ui.overshootSpinBox, SIGNAL(valueChanged(double)), this, SLOT(overshootChanged(double)));
+ connect(m_ui.easingCurvePicker, &QListWidget::currentRowChanged,
+ this, &Window::curveChanged);
+ connect(buttonGroup, QOverload<int>::of(&QButtonGroup::buttonClicked),
+ this, &Window::pathChanged);
+ connect(m_ui.periodSpinBox, QOverload<double>::of(&QDoubleSpinBox::valueChanged),
+ this, &Window::periodChanged);
+ connect(m_ui.amplitudeSpinBox, QOverload<double>::of(&QDoubleSpinBox::valueChanged),
+ this, &Window::amplitudeChanged);
+ connect(m_ui.overshootSpinBox, QOverload<double>::of(&QDoubleSpinBox::valueChanged),
+ this, &Window::overshootChanged);
createCurveIcons();
QPixmap pix(QLatin1String(":/images/qt-logo.png"));
diff --git a/examples/widgets/animation/moveblocks/main.cpp b/examples/widgets/animation/moveblocks/main.cpp
index 6d17696108..e59b17cbf9 100644
--- a/examples/widgets/animation/moveblocks/main.cpp
+++ b/examples/widgets/animation/moveblocks/main.cpp
@@ -214,7 +214,7 @@ int main(int argc, char **argv)
QTimer timer;
timer.setInterval(1250);
timer.setSingleShot(true);
- QObject::connect(group, SIGNAL(entered()), &timer, SLOT(start()));
+ QObject::connect(group, &QState::entered, &timer, QOverload<>::of(&QTimer::start));
//![2]
//![3]
@@ -302,7 +302,7 @@ int main(int argc, char **argv)
//![7]
StateSwitcher *stateSwitcher = new StateSwitcher(&machine);
stateSwitcher->setObjectName("stateSwitcher");
- group->addTransition(&timer, SIGNAL(timeout()), stateSwitcher);
+ group->addTransition(&timer, &QTimer::timeout, stateSwitcher);
stateSwitcher->addState(state1, &animationGroup);
stateSwitcher->addState(state2, &animationGroup);
//![7]
diff --git a/examples/widgets/animation/states/main.cpp b/examples/widgets/animation/states/main.cpp
index 14d193c301..0f61b7457a 100644
--- a/examples/widgets/animation/states/main.cpp
+++ b/examples/widgets/animation/states/main.cpp
@@ -214,7 +214,7 @@ int main(int argc, char *argv[])
state3->assignProperty(p5, "opacity", qreal(1));
state3->assignProperty(p6, "opacity", qreal(1));
- QAbstractTransition *t1 = state1->addTransition(button, SIGNAL(clicked()), state2);
+ QAbstractTransition *t1 = state1->addTransition(button, &QAbstractButton::clicked, state2);
QSequentialAnimationGroup *animation1SubGroup = new QSequentialAnimationGroup;
animation1SubGroup->addPause(250);
animation1SubGroup->addAnimation(new QPropertyAnimation(box, "geometry"));
@@ -239,7 +239,7 @@ int main(int argc, char *argv[])
t1->addAnimation(new QPropertyAnimation(p5, "opacity"));
t1->addAnimation(new QPropertyAnimation(p6, "opacity"));
- QAbstractTransition *t2 = state2->addTransition(button, SIGNAL(clicked()), state3);
+ QAbstractTransition *t2 = state2->addTransition(button, &QAbstractButton::clicked, state3);
t2->addAnimation(new QPropertyAnimation(box, "geometry"));
t2->addAnimation(new QPropertyAnimation(widget, "geometry"));
t2->addAnimation(new QPropertyAnimation(p1, "pos"));
@@ -261,7 +261,7 @@ int main(int argc, char *argv[])
t2->addAnimation(new QPropertyAnimation(p5, "opacity"));
t2->addAnimation(new QPropertyAnimation(p6, "opacity"));
- QAbstractTransition *t3 = state3->addTransition(button, SIGNAL(clicked()), state1);
+ QAbstractTransition *t3 = state3->addTransition(button, &QAbstractButton::clicked, state1);
t3->addAnimation(new QPropertyAnimation(box, "geometry"));
t3->addAnimation(new QPropertyAnimation(widget, "geometry"));
t3->addAnimation(new QPropertyAnimation(p1, "pos"));
diff --git a/examples/widgets/animation/stickman/lifecycle.cpp b/examples/widgets/animation/stickman/lifecycle.cpp
index dbe9a299b4..5d4c406b2e 100644
--- a/examples/widgets/animation/stickman/lifecycle.cpp
+++ b/examples/widgets/animation/stickman/lifecycle.cpp
@@ -61,11 +61,11 @@ class KeyPressTransition: public QSignalTransition
{
public:
KeyPressTransition(GraphicsView *receiver, Qt::Key key)
- : QSignalTransition(receiver, SIGNAL(keyPressed(int))), m_key(key)
+ : QSignalTransition(receiver, &GraphicsView::keyPressed), m_key(key)
{
}
KeyPressTransition(GraphicsView *receiver, Qt::Key key, QAbstractState *target)
- : QSignalTransition(receiver, SIGNAL(keyPressed(int))), m_key(key)
+ : QSignalTransition(receiver, &GraphicsView::keyPressed), m_key(key)
{
setTargetState(target);
}
@@ -132,8 +132,10 @@ LifeCycle::LifeCycle(StickMan *stickMan, GraphicsView *keyReceiver)
QTimer *timer = new QTimer(lightningBlink);
timer->setSingleShot(true);
timer->setInterval(100);
- QObject::connect(lightningBlink, SIGNAL(entered()), timer, SLOT(start()));
- QObject::connect(lightningBlink, SIGNAL(exited()), timer, SLOT(stop()));
+ QObject::connect(lightningBlink, &QAbstractState::entered,
+ timer, QOverload<>::of(&QTimer::start));
+ QObject::connect(lightningBlink, &QAbstractState::exited,
+ timer, &QTimer::stop);
//! [5]
m_dead = new QState(m_machine);
@@ -151,7 +153,7 @@ LifeCycle::LifeCycle(StickMan *stickMan, GraphicsView *keyReceiver)
// Lightning strikes at random
m_alive->addTransition(new LightningStrikesTransition(lightningBlink));
//! [0]
- lightningBlink->addTransition(timer, SIGNAL(timeout()), m_dead);
+ lightningBlink->addTransition(timer, &QTimer::timeout, m_dead);
//! [0]
m_machine->setInitialState(m_alive);
@@ -206,14 +208,14 @@ QState *LifeCycle::makeState(QState *parentState, const QString &animationFileNa
topLevel->setInitialState(frameState);
else
//! [2]
- previousState->addTransition(previousState, SIGNAL(propertiesAssigned()), frameState);
+ previousState->addTransition(previousState, &QState::propertiesAssigned, frameState);
//! [2]
previousState = frameState;
}
// Loop
- previousState->addTransition(previousState, SIGNAL(propertiesAssigned()), topLevel->initialState());
+ previousState->addTransition(previousState, &QState::propertiesAssigned, topLevel->initialState());
return topLevel;
diff --git a/examples/widgets/animation/stickman/stickman.cpp b/examples/widgets/animation/stickman/stickman.cpp
index b7a2d87ada..8b183d87d5 100644
--- a/examples/widgets/animation/stickman/stickman.cpp
+++ b/examples/widgets/animation/stickman/stickman.cpp
@@ -126,7 +126,7 @@ StickMan::StickMan()
// Set up start position of limbs
for (int i=0; i<NodeCount; ++i) {
m_nodes[i] = new Node(QPointF(Coords[i * 2], Coords[i * 2 + 1]), this);
- connect(m_nodes[i], SIGNAL(positionChanged()), this, SLOT(childPositionChanged()));
+ connect(m_nodes[i], &Node::positionChanged, this, &StickMan::childPositionChanged);
}
for (int i=0; i<BoneCount; ++i) {
diff --git a/examples/widgets/animation/sub-attaq/animationmanager.cpp b/examples/widgets/animation/sub-attaq/animationmanager.cpp
index b6e399967f..62dac7852a 100644
--- a/examples/widgets/animation/sub-attaq/animationmanager.cpp
+++ b/examples/widgets/animation/sub-attaq/animationmanager.cpp
@@ -71,7 +71,7 @@ AnimationManager *AnimationManager::self()
void AnimationManager::registerAnimation(QAbstractAnimation *anim)
{
- QObject::connect(anim, SIGNAL(destroyed(QObject*)), this, SLOT(unregisterAnimation_helper(QObject*)));
+ QObject::connect(anim, &QObject::destroyed, this, &AnimationManager::unregisterAnimation_helper);
animations.append(anim);
}
@@ -82,7 +82,7 @@ void AnimationManager::unregisterAnimation_helper(QObject *obj)
void AnimationManager::unregisterAnimation(QAbstractAnimation *anim)
{
- QObject::disconnect(anim, SIGNAL(destroyed(QObject*)), this, SLOT(unregisterAnimation_helper(QObject*)));
+ QObject::disconnect(anim, &QObject::destroyed, this, &AnimationManager::unregisterAnimation_helper);
animations.removeAll(anim);
}
diff --git a/examples/widgets/animation/sub-attaq/boat.cpp b/examples/widgets/animation/sub-attaq/boat.cpp
index 145d373e99..9f4feba2ec 100644
--- a/examples/widgets/animation/sub-attaq/boat.cpp
+++ b/examples/widgets/animation/sub-attaq/boat.cpp
@@ -148,8 +148,8 @@ Boat::Boat() : PixmapItem(QString("boat"), GraphicsScene::Big),
stopState->addTransition(leftMoveStop);
//The animation is finished, it means we reached the border of the screen, the boat is stopped so we move to the stop state
- moveStateLeft->addTransition(movementAnimation, SIGNAL(finished()), stopState);
- moveStateRight->addTransition(movementAnimation, SIGNAL(finished()), stopState);
+ moveStateLeft->addTransition(movementAnimation, &QAbstractAnimation::finished, stopState);
+ moveStateRight->addTransition(movementAnimation, &QAbstractAnimation::finished, stopState);
//We set up the keys for dropping bombs
KeyLaunchTransition *upFireLeft = new KeyLaunchTransition(this, QEvent::KeyPress, Qt::Key_Up);
@@ -187,13 +187,13 @@ Boat::Boat() : PixmapItem(QString("boat"), GraphicsScene::Big),
destroyedState->setAnimation(destroyAnimation);
//Play a nice animation when the boat is destroyed
- moving->addTransition(this, SIGNAL(boatDestroyed()), destroyedState);
+ moving->addTransition(this, &Boat::boatDestroyed, destroyedState);
//Transition to final state when the destroyed animation is finished
- destroyedState->addTransition(destroyedState, SIGNAL(animationFinished()), final);
+ destroyedState->addTransition(destroyedState, &QAnimationState::animationFinished, final);
//The machine has finished to be executed, then the boat is dead
- connect(machine,SIGNAL(finished()), this, SIGNAL(boatExecutionFinished()));
+ connect(machine,&QState::finished, this, &Boat::boatExecutionFinished);
}
diff --git a/examples/widgets/animation/sub-attaq/bomb.cpp b/examples/widgets/animation/sub-attaq/bomb.cpp
index a80d2d46c5..76e4575293 100644
--- a/examples/widgets/animation/sub-attaq/bomb.cpp
+++ b/examples/widgets/animation/sub-attaq/bomb.cpp
@@ -83,8 +83,8 @@ void Bomb::launch(Bomb::Direction direction)
anim->setEndValue(QPointF(x() + delta*2,scene()->height()));
anim->setDuration(y()/2*60);
launchAnimation->addAnimation(anim);
- connect(anim,SIGNAL(valueChanged(QVariant)),this,SLOT(onAnimationLaunchValueChanged(QVariant)));
- connect(this, SIGNAL(bombExploded()), launchAnimation, SLOT(stop()));
+ connect(anim,&QVariantAnimation::valueChanged,this,&Bomb::onAnimationLaunchValueChanged);
+ connect(this, &Bomb::bombExploded, launchAnimation, &QAbstractAnimation::stop);
//We setup the state machine of the bomb
QStateMachine *machine = new QStateMachine(this);
@@ -98,13 +98,13 @@ void Bomb::launch(Bomb::Direction direction)
machine->setInitialState(launched);
//### Add a nice animation when the bomb is destroyed
- launched->addTransition(this, SIGNAL(bombExploded()),final);
+ launched->addTransition(this, &Bomb::bombExploded,final);
//If the animation is finished, then we move to the final state
- launched->addTransition(launched, SIGNAL(animationFinished()), final);
+ launched->addTransition(launched, &QAnimationState::animationFinished, final);
//The machine has finished to be executed, then the boat is dead
- connect(machine,SIGNAL(finished()),this, SIGNAL(bombExecutionFinished()));
+ connect(machine,&QState::finished,this, &Bomb::bombExecutionFinished);
machine->start();
diff --git a/examples/widgets/animation/sub-attaq/graphicsscene.cpp b/examples/widgets/animation/sub-attaq/graphicsscene.cpp
index e0913f99f6..3205cdc54d 100644
--- a/examples/widgets/animation/sub-attaq/graphicsscene.cpp
+++ b/examples/widgets/animation/sub-attaq/graphicsscene.cpp
@@ -191,15 +191,15 @@ void GraphicsScene::setupScene(QAction *newAction, QAction *quitAction)
lettersFadingState->setAnimation(lettersGroupFading);
//if new game then we fade out the welcome screen and start playing
- lettersMovingState->addTransition(newAction, SIGNAL(triggered()), lettersFadingState);
- lettersFadingState->addTransition(lettersFadingState, SIGNAL(animationFinished()), gameState);
+ lettersMovingState->addTransition(newAction, &QAction::triggered, lettersFadingState);
+ lettersFadingState->addTransition(lettersFadingState, &QAnimationState::animationFinished, gameState);
//New Game is triggered then player start playing
- gameState->addTransition(newAction, SIGNAL(triggered()), gameState);
+ gameState->addTransition(newAction, &QAction::triggered, gameState);
//Wanna quit, then connect to CTRL+Q
- gameState->addTransition(quitAction, SIGNAL(triggered()), final);
- lettersMovingState->addTransition(quitAction, SIGNAL(triggered()), final);
+ gameState->addTransition(quitAction, &QAction::triggered, final);
+ lettersMovingState->addTransition(quitAction, &QAction::triggered, final);
//Welcome screen is the initial state
machine->setInitialState(lettersMovingState);
@@ -207,27 +207,27 @@ void GraphicsScene::setupScene(QAction *newAction, QAction *quitAction)
machine->start();
//We reach the final state, then we quit
- connect(machine, SIGNAL(finished()), qApp, SLOT(quit()));
+ connect(machine, &QStateMachine::finished, qApp, &QApplication::quit);
}
void GraphicsScene::addItem(Bomb *bomb)
{
bombs.insert(bomb);
- connect(bomb,SIGNAL(bombExecutionFinished()),this, SLOT(onBombExecutionFinished()));
+ connect(bomb,&Bomb::bombExecutionFinished,this, &GraphicsScene::onBombExecutionFinished);
QGraphicsScene::addItem(bomb);
}
void GraphicsScene::addItem(Torpedo *torpedo)
{
torpedos.insert(torpedo);
- connect(torpedo,SIGNAL(torpedoExecutionFinished()),this, SLOT(onTorpedoExecutionFinished()));
+ connect(torpedo,&Torpedo::torpedoExecutionFinished,this, &GraphicsScene::onTorpedoExecutionFinished);
QGraphicsScene::addItem(torpedo);
}
void GraphicsScene::addItem(SubMarine *submarine)
{
submarines.insert(submarine);
- connect(submarine,SIGNAL(subMarineExecutionFinished()),this, SLOT(onSubMarineExecutionFinished()));
+ connect(submarine,&SubMarine::subMarineExecutionFinished,this, &GraphicsScene::onSubMarineExecutionFinished);
QGraphicsScene::addItem(submarine);
}
diff --git a/examples/widgets/animation/sub-attaq/qanimationstate.cpp b/examples/widgets/animation/sub-attaq/qanimationstate.cpp
index ae24af6da3..fc0da7cea2 100644
--- a/examples/widgets/animation/sub-attaq/qanimationstate.cpp
+++ b/examples/widgets/animation/sub-attaq/qanimationstate.cpp
@@ -73,7 +73,7 @@ QAnimationState *s = new QAnimationState(machine->rootState());
QPropertyAnimation *animation = new QPropertyAnimation(obj, "pos");
s->setAnimation(animation);
QState *s2 = new QState(machine->rootState());
-s->addTransition(s, SIGNAL(animationFinished()), s2);
+s->addTransition(s, &QAnimationState::animationFinished, s2);
machine.start();
\endcode
@@ -107,13 +107,13 @@ void QAnimationState::setAnimation(QAbstractAnimation *animation)
//Disconnect from the previous animation if exist
if(m_animation)
- disconnect(m_animation, SIGNAL(finished()), this, SIGNAL(animationFinished()));
+ disconnect(m_animation, &QAbstractAnimation::finished, this, &QAnimationState::animationFinished);
m_animation = animation;
if (m_animation) {
//connect the new animation
- connect(m_animation, SIGNAL(finished()), this, SIGNAL(animationFinished()));
+ connect(m_animation, &QAbstractAnimation::finished, this, &QAnimationState::animationFinished);
}
}
diff --git a/examples/widgets/animation/sub-attaq/states.cpp b/examples/widgets/animation/sub-attaq/states.cpp
index e19704db7b..8a3a97a20f 100644
--- a/examples/widgets/animation/sub-attaq/states.cpp
+++ b/examples/widgets/animation/sub-attaq/states.cpp
@@ -124,7 +124,7 @@ void PlayState::onEntry(QEvent *)
WinState *winState = new WinState(scene, this, machine);
//The boat has been destroyed then the game is finished
- levelState->addTransition(scene->boat, SIGNAL(boatExecutionFinished()),lostState);
+ levelState->addTransition(scene->boat, &Boat::boatExecutionFinished,lostState);
//This transition check if we won or not
WinTransition *winTransition = new WinTransition(scene, this, winState);
@@ -157,7 +157,7 @@ void PlayState::onEntry(QEvent *)
winState->addTransition(spaceTransition);
//We lost we should reach the final state
- lostState->addTransition(lostState, SIGNAL(finished()), final);
+ lostState->addTransition(lostState, &QState::finished, final);
machine->start();
}
@@ -291,8 +291,8 @@ UpdateScoreState::UpdateScoreState(QState *parent) : QState(parent)
/** Win transition */
UpdateScoreTransition::UpdateScoreTransition(GraphicsScene *scene, PlayState *game, QAbstractState *target)
- : QSignalTransition(scene,SIGNAL(subMarineDestroyed(int))),
- game(game), scene(scene)
+ : QSignalTransition(scene, &GraphicsScene::subMarineDestroyed),
+ game(game), scene(scene)
{
setTargetState(target);
}
@@ -309,8 +309,8 @@ bool UpdateScoreTransition::eventTest(QEvent *event)
/** Win transition */
WinTransition::WinTransition(GraphicsScene *scene, PlayState *game, QAbstractState *target)
- : QSignalTransition(scene,SIGNAL(allSubMarineDestroyed(int))),
- game(game), scene(scene)
+ : QSignalTransition(scene, &GraphicsScene::allSubMarineDestroyed),
+ game(game), scene(scene)
{
setTargetState(target);
}
diff --git a/examples/widgets/animation/sub-attaq/submarine.cpp b/examples/widgets/animation/sub-attaq/submarine.cpp
index a451185ce0..775e75ceed 100644
--- a/examples/widgets/animation/sub-attaq/submarine.cpp
+++ b/examples/widgets/animation/sub-attaq/submarine.cpp
@@ -106,7 +106,7 @@ SubMarine::SubMarine(int type, const QString &name, int points) : PixmapItem(QSt
//This is the initial state of the moving root state
moving->setInitialState(movement);
- movement->addTransition(this, SIGNAL(subMarineStateChanged()), moving);
+ movement->addTransition(this, &SubMarine::subMarineStateChanged, moving);
//This is the initial state of the machine
machine->setInitialState(moving);
@@ -115,23 +115,23 @@ SubMarine::SubMarine(int type, const QString &name, int points) : PixmapItem(QSt
QFinalState *final = new QFinalState(machine);
//If the moving animation is finished we move to the return state
- movement->addTransition(movement, SIGNAL(animationFinished()), rotation);
+ movement->addTransition(movement, &QAnimationState::animationFinished, rotation);
//If the return animation is finished we move to the moving state
- rotation->addTransition(rotation, SIGNAL(animationFinished()), movement);
+ rotation->addTransition(rotation, &QAnimationState::animationFinished, movement);
//This state play the destroyed animation
QAnimationState *destroyedState = new QAnimationState(machine);
destroyedState->setAnimation(setupDestroyAnimation(this));
//Play a nice animation when the submarine is destroyed
- moving->addTransition(this, SIGNAL(subMarineDestroyed()), destroyedState);
+ moving->addTransition(this, &SubMarine::subMarineDestroyed, destroyedState);
//Transition to final state when the destroyed animation is finished
- destroyedState->addTransition(destroyedState, SIGNAL(animationFinished()), final);
+ destroyedState->addTransition(destroyedState, &QAnimationState::animationFinished, final);
//The machine has finished to be executed, then the submarine is dead
- connect(machine,SIGNAL(finished()),this, SIGNAL(subMarineExecutionFinished()));
+ connect(machine,&QState::finished,this, &SubMarine::subMarineExecutionFinished);
machine->start();
}
diff --git a/examples/widgets/animation/sub-attaq/submarine_p.h b/examples/widgets/animation/sub-attaq/submarine_p.h
index 698b4b494f..1c2cb7ceac 100644
--- a/examples/widgets/animation/sub-attaq/submarine_p.h
+++ b/examples/widgets/animation/sub-attaq/submarine_p.h
@@ -80,7 +80,8 @@ public:
explicit MovementState(SubMarine *submarine, QState *parent = 0) : QAnimationState(parent)
{
movementAnimation = new QPropertyAnimation(submarine, "pos");
- connect(movementAnimation,SIGNAL(valueChanged(const QVariant &)),this,SLOT(onAnimationMovementValueChanged(const QVariant &)));
+ connect(movementAnimation, &QPropertyAnimation::valueChanged,
+ this, &MovementState::onAnimationMovementValueChanged);
setAnimation(movementAnimation);
AnimationManager::self()->registerAnimation(movementAnimation);
this->submarine = submarine;
diff --git a/examples/widgets/animation/sub-attaq/torpedo.cpp b/examples/widgets/animation/sub-attaq/torpedo.cpp
index 2e9d970326..5f8ef2f2b8 100644
--- a/examples/widgets/animation/sub-attaq/torpedo.cpp
+++ b/examples/widgets/animation/sub-attaq/torpedo.cpp
@@ -73,8 +73,8 @@ void Torpedo::launch()
launchAnimation->setEndValue(QPointF(x(),qobject_cast<GraphicsScene *>(scene())->sealLevel() - 15));
launchAnimation->setEasingCurve(QEasingCurve::InQuad);
launchAnimation->setDuration(y()/currentSpeed*10);
- connect(launchAnimation,SIGNAL(valueChanged(QVariant)),this,SLOT(onAnimationLaunchValueChanged(QVariant)));
- connect(this,SIGNAL(torpedoExploded()), launchAnimation, SLOT(stop()));
+ connect(launchAnimation,&QVariantAnimation::valueChanged,this,&Torpedo::onAnimationLaunchValueChanged);
+ connect(this,&Torpedo::torpedoExploded, launchAnimation, &QAbstractAnimation::stop);
//We setup the state machine of the torpedo
QStateMachine *machine = new QStateMachine(this);
@@ -89,13 +89,13 @@ void Torpedo::launch()
machine->setInitialState(launched);
//### Add a nice animation when the torpedo is destroyed
- launched->addTransition(this, SIGNAL(torpedoExploded()),final);
+ launched->addTransition(this, &Torpedo::torpedoExploded,final);
//If the animation is finished, then we move to the final state
- launched->addTransition(launched, SIGNAL(animationFinished()), final);
+ launched->addTransition(launched, &QAnimationState::animationFinished, final);
//The machine has finished to be executed, then the boat is dead
- connect(machine,SIGNAL(finished()),this, SIGNAL(torpedoExecutionFinished()));
+ connect(machine,&QState::finished,this, &Torpedo::torpedoExecutionFinished);
machine->start();
}
diff --git a/examples/widgets/doc/dropsite.qdoc b/examples/widgets/doc/dropsite.qdoc
index 32bcfe8916..af8766a308 100644
--- a/examples/widgets/doc/dropsite.qdoc
+++ b/examples/widgets/doc/dropsite.qdoc
@@ -202,13 +202,7 @@
\snippet draganddrop/dropsite/dropsitewindow.cpp updateFormatsTable() part1
Once we are sure that \c mimeData is valid, we iterate through its
- supported formats using the \l{The foreach Keyword}{foreach keyword}.
- This keyword has the following format:
-
- \include code/doc_src_examples_dropsite.qdoc 0
-
- In our example, \c format is the \a variable and the \a container is a
- QStringList, obtained from \c mimeData->formats().
+ supported formats.
\note The \l{QMimeData::formats()}{formats()} function returns a
QStringList object, containing all the formats supported by the
diff --git a/examples/widgets/doc/src/addressbook.qdoc b/examples/widgets/doc/src/addressbook.qdoc
index 1fa0bfa9d4..e5e7fe5c2c 100644
--- a/examples/widgets/doc/src/addressbook.qdoc
+++ b/examples/widgets/doc/src/addressbook.qdoc
@@ -90,8 +90,8 @@
\snippet itemviews/addressbook/tablemodel.h 0
Two constructors are used, a default constructor which uses
- \c TableModel's own \c {QList<Contact>} and one that takes
- \c {QList<Contact>} as an argument, for convenience.
+ \c TableModel's own \c {QVector<Contact>} and one that takes
+ \c {QVector<Contact>} as an argument, for convenience.
\section1 TableModel Class Implementation
@@ -108,9 +108,6 @@
\c columnCount()'s value is always 2 because we only need space
for the \b Name and \b Address columns.
- \note The \c Q_UNUSED() macro prevents the compiler from
- generating warnings regarding unused parameters.
-
\snippet itemviews/addressbook/tablemodel.cpp 1
The \c data() function returns either a \b Name or
@@ -164,7 +161,7 @@
them here so that we can reuse the model in other programs.
The last function in \c {TableModel}, \c getContacts() returns the
- QList<Contact> object that holds all the contacts in the address
+ QVector<Contact> object that holds all the contacts in the address
book. We use this function later to obtain the list of contacts to
check for existing entries, write the contacts to a file and read
them back. Further explanation is given with \c AddressWidget.
@@ -233,7 +230,7 @@
\image addressbook-signals.png Signals and Slots Connections
- We provide 2 \c addEntry() functions: 1 which is intended to be
+ We provide two \c addEntry() functions: One which is intended to be
used to accept user input, and the other which performs the actual
task of adding new entries to the address book. We divide the
responsibility of adding entries into two parts to allow
diff --git a/examples/widgets/doc/src/fetchmore.qdoc b/examples/widgets/doc/src/fetchmore.qdoc
index df0cf3b8ec..a27efaf071 100644
--- a/examples/widgets/doc/src/fetchmore.qdoc
+++ b/examples/widgets/doc/src/fetchmore.qdoc
@@ -29,7 +29,7 @@
\example itemviews/fetchmore
\title Fetch More Example
\ingroup examples-itemviews
- \brief The Fetch More example shows how two add items to an item view
+ \brief The Fetch More example shows how to add items to an item view
model on demand.
\image fetchmore-example.png
diff --git a/examples/widgets/doc/src/stardelegate.qdoc b/examples/widgets/doc/src/stardelegate.qdoc
index 44d17662ca..0b91723a51 100644
--- a/examples/widgets/doc/src/stardelegate.qdoc
+++ b/examples/widgets/doc/src/stardelegate.qdoc
@@ -42,11 +42,11 @@
editing takes place.
Delegates are subclasses of QAbstractItemDelegate. Qt provides
- QItemDelegate, which inherits QAbstractItemDelegate and handles
+ QStyledItemDelegate, which inherits QAbstractItemDelegate and handles
the most common data types (notably \c int and QString). If we
need to support custom data types, or want to customize the
rendering or the editing for existing data types, we can subclass
- QAbstractItemDelegate or QItemDelegate. See \l{Delegate Classes}
+ QAbstractItemDelegate or QStyledItemDelegate. See \l{Delegate Classes}
for more information about delegates, and \l{Model/View
Programming} if you need a high-level introduction to Qt's
model/view architecture (including delegates).
@@ -62,9 +62,9 @@
expressed as stars, such as "2 out of 5 stars" or "5 out of
6 stars".
- \li \c StarDelegate inherits QItemDelegate and provides support
+ \li \c StarDelegate inherits QStyledItemDelegate and provides support
for \c StarRating (in addition to the data types already
- handled by QItemDelegate).
+ handled by QStyledItemDelegate).
\li \c StarEditor inherits QWidget and is used by \c StarDelegate
to let the user edit a star rating using the mouse.
@@ -80,12 +80,12 @@
\snippet itemviews/stardelegate/stardelegate.h 0
All public functions are reimplemented virtual functions from
- QItemDelegate to provide custom rendering and editing.
+ QStyledItemDelegate to provide custom rendering and editing.
\section1 StarDelegate Class Implementation
The \l{QAbstractItemDelegate::}{paint()} function is
- reimplemented from QItemDelegate and is called whenever the view
+ reimplemented from QStyledItemDelegate and is called whenever the view
needs to repaint an item:
\snippet itemviews/stardelegate/stardelegate.cpp 0
@@ -93,7 +93,7 @@
The function is invoked once for each item, represented by a
QModelIndex object from the model. If the data stored in the item
is a \c StarRating, we paint it ourselves; otherwise, we let
- QItemDelegate paint it for us. This ensures that the \c
+ QStyledItemDelegate paint it for us. This ensures that the \c
StarDelegate can handle the most common data types.
If the item is a \c StarRating, we draw the background if the
diff --git a/examples/widgets/draganddrop/dropsite/dropsitewindow.cpp b/examples/widgets/draganddrop/dropsite/dropsitewindow.cpp
index 28a42ee614..2dae83bb22 100644
--- a/examples/widgets/draganddrop/dropsite/dropsitewindow.cpp
+++ b/examples/widgets/draganddrop/dropsite/dropsitewindow.cpp
@@ -113,7 +113,8 @@ void DropSiteWindow::updateFormatsTable(const QMimeData *mimeData)
//! [updateFormatsTable() part1]
//! [updateFormatsTable() part2]
- for (const QString &format : mimeData->formats()) {
+ const QStringList formats = mimeData->formats();
+ for (const QString &format : formats) {
QTableWidgetItem *formatItem = new QTableWidgetItem(format);
formatItem->setFlags(Qt::ItemIsEnabled);
formatItem->setTextAlignment(Qt::AlignTop | Qt::AlignLeft);
diff --git a/examples/widgets/effects/fademessage/fademessage.cpp b/examples/widgets/effects/fademessage/fademessage.cpp
index 9943147bb7..4c3a70bb4f 100644
--- a/examples/widgets/effects/fademessage/fademessage.cpp
+++ b/examples/widgets/effects/fademessage/fademessage.cpp
@@ -131,7 +131,7 @@ void FadeMessage::setupScene()
QPushButton *press = new QPushButton;
press->setText(tr("Press me"));
- connect(press, SIGNAL(clicked()), SLOT(togglePopup()));
+ connect(press, &QAbstractButton::clicked, this, &FadeMessage::togglePopup);
m_scene.addWidget(press);
press->move(300, 500);
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<int>::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<int>::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<int>::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<QAbstractButton *>::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<const QString &>::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<int>::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<const QString &>::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
diff --git a/examples/widgets/itemviews/addressbook/adddialog.cpp b/examples/widgets/itemviews/addressbook/adddialog.cpp
index 1ce2d3110a..bf87307253 100644
--- a/examples/widgets/itemviews/addressbook/adddialog.cpp
+++ b/examples/widgets/itemviews/addressbook/adddialog.cpp
@@ -54,17 +54,16 @@
//! [0]
AddDialog::AddDialog(QWidget *parent)
- : QDialog(parent)
+ : QDialog(parent),
+ nameText(new QLineEdit),
+ addressText(new QTextEdit)
{
- nameLabel = new QLabel("Name");
- addressLabel = new QLabel("Address");
- okButton = new QPushButton("OK");
- cancelButton = new QPushButton("Cancel");
+ auto nameLabel = new QLabel(tr("Name"));
+ auto addressLabel = new QLabel(tr("Address"));
+ auto okButton = new QPushButton(tr("OK"));
+ auto cancelButton = new QPushButton(tr("Cancel"));
- nameText = new QLineEdit;
- addressText = new QTextEdit;
-
- QGridLayout *gLayout = new QGridLayout;
+ auto gLayout = new QGridLayout;
gLayout->setColumnStretch(1, 2);
gLayout->addWidget(nameLabel, 0, 0);
gLayout->addWidget(nameText, 0, 1);
@@ -72,13 +71,13 @@ AddDialog::AddDialog(QWidget *parent)
gLayout->addWidget(addressLabel, 1, 0, Qt::AlignLeft|Qt::AlignTop);
gLayout->addWidget(addressText, 1, 1, Qt::AlignLeft);
- QHBoxLayout *buttonLayout = new QHBoxLayout;
+ auto buttonLayout = new QHBoxLayout;
buttonLayout->addWidget(okButton);
buttonLayout->addWidget(cancelButton);
gLayout->addLayout(buttonLayout, 2, 1, Qt::AlignRight);
- QVBoxLayout *mainLayout = new QVBoxLayout;
+ auto mainLayout = new QVBoxLayout;
mainLayout->addLayout(gLayout);
setLayout(mainLayout);
@@ -87,4 +86,21 @@ AddDialog::AddDialog(QWidget *parent)
setWindowTitle(tr("Add a Contact"));
}
+
+QString AddDialog::name() const
+{
+ return nameText->text();
+}
+
+QString AddDialog::address() const
+{
+ return addressText->toPlainText();
+}
+
+void AddDialog::editAddress(const QString &name, const QString &address)
+{
+ nameText->setReadOnly(true);
+ nameText->setText(name);
+ addressText->setPlainText(address);
+}
//! [0]
diff --git a/examples/widgets/itemviews/addressbook/adddialog.h b/examples/widgets/itemviews/addressbook/adddialog.h
index 16fa7bc650..2867034122 100644
--- a/examples/widgets/itemviews/addressbook/adddialog.h
+++ b/examples/widgets/itemviews/addressbook/adddialog.h
@@ -66,15 +66,15 @@ class AddDialog : public QDialog
Q_OBJECT
public:
- AddDialog(QWidget *parent = 0);
- QLineEdit *nameText;
- QTextEdit *addressText;
+ AddDialog(QWidget *parent = nullptr);
+
+ QString name() const;
+ QString address() const;
+ void editAddress(const QString &name, const QString &address);
private:
- QLabel *nameLabel;
- QLabel *addressLabel;
- QPushButton *okButton;
- QPushButton *cancelButton;
+ QLineEdit *nameText;
+ QTextEdit *addressText;
};
//! [0]
diff --git a/examples/widgets/itemviews/addressbook/addresswidget.cpp b/examples/widgets/itemviews/addressbook/addresswidget.cpp
index 143f6266dd..b1b65174ee 100644
--- a/examples/widgets/itemviews/addressbook/addresswidget.cpp
+++ b/examples/widgets/itemviews/addressbook/addresswidget.cpp
@@ -48,21 +48,21 @@
**
****************************************************************************/
-#include "adddialog.h"
#include "addresswidget.h"
+#include "adddialog.h"
#include <QtWidgets>
//! [0]
AddressWidget::AddressWidget(QWidget *parent)
- : QTabWidget(parent)
+ : QTabWidget(parent),
+ table(new TableModel(this)),
+ newAddressTab(new NewAddressTab(this))
{
- table = new TableModel(this);
- newAddressTab = new NewAddressTab(this);
connect(newAddressTab, &NewAddressTab::sendDetails,
this, &AddressWidget::addEntry);
- addTab(newAddressTab, "Address Book");
+ addTab(newAddressTab, tr("Address Book"));
setupTabs();
}
@@ -73,17 +73,13 @@ void AddressWidget::showAddEntryDialog()
{
AddDialog aDialog;
- if (aDialog.exec()) {
- QString name = aDialog.nameText->text();
- QString address = aDialog.addressText->toPlainText();
-
- addEntry(name, address);
- }
+ if (aDialog.exec())
+ addEntry(aDialog.name(), aDialog.address());
}
//! [2]
//! [3]
-void AddressWidget::addEntry(QString name, QString address)
+void AddressWidget::addEntry(const QString &name, const QString &address)
{
if (!table->getContacts().contains({ name, address })) {
table->insertRows(0, 1, QModelIndex());
@@ -107,12 +103,12 @@ void AddressWidget::editEntry()
QSortFilterProxyModel *proxy = static_cast<QSortFilterProxyModel*>(temp->model());
QItemSelectionModel *selectionModel = temp->selectionModel();
- QModelIndexList indexes = selectionModel->selectedRows();
+ const QModelIndexList indexes = selectionModel->selectedRows();
QString name;
QString address;
int row = -1;
- foreach (QModelIndex index, indexes) {
+ for (const QModelIndex &index : indexes) {
row = proxy->mapToSource(index).row();
QModelIndex nameIndex = table->index(row, 0, QModelIndex());
QVariant varName = table->data(nameIndex, Qt::DisplayRole);
@@ -127,15 +123,12 @@ void AddressWidget::editEntry()
//! [4b]
AddDialog aDialog;
aDialog.setWindowTitle(tr("Edit a Contact"));
-
- aDialog.nameText->setReadOnly(true);
- aDialog.nameText->setText(name);
- aDialog.addressText->setText(address);
+ aDialog.editAddress(name, address);
if (aDialog.exec()) {
- QString newAddress = aDialog.addressText->toPlainText();
+ const QString newAddress = aDialog.address();
if (newAddress != address) {
- QModelIndex index = table->index(row, 1, QModelIndex());
+ const QModelIndex index = table->index(row, 1, QModelIndex());
table->setData(index, newAddress, Qt::EditRole);
}
}
@@ -149,52 +142,46 @@ void AddressWidget::removeEntry()
QSortFilterProxyModel *proxy = static_cast<QSortFilterProxyModel*>(temp->model());
QItemSelectionModel *selectionModel = temp->selectionModel();
- QModelIndexList indexes = selectionModel->selectedRows();
+ const QModelIndexList indexes = selectionModel->selectedRows();
- foreach (QModelIndex index, indexes) {
+ for (QModelIndex index : indexes) {
int row = proxy->mapToSource(index).row();
table->removeRows(row, 1, QModelIndex());
}
- if (table->rowCount(QModelIndex()) == 0) {
- insertTab(0, newAddressTab, "Address Book");
- }
+ if (table->rowCount(QModelIndex()) == 0)
+ insertTab(0, newAddressTab, tr("Address Book"));
}
//! [5]
//! [1]
void AddressWidget::setupTabs()
{
- QStringList groups;
- groups << "ABC" << "DEF" << "GHI" << "JKL" << "MNO" << "PQR" << "STU" << "VW" << "XYZ";
+ const auto groups = { "ABC", "DEF", "GHI", "JKL", "MNO", "PQR", "STU", "VW", "XYZ" };
- for (int i = 0; i < groups.size(); ++i) {
- QString str = groups.at(i);
- QString regExp = QString("^[%1].*").arg(str);
+ for (const QString &str : groups) {
+ const auto regExp = QRegularExpression(QString("^[%1].*").arg(str),
+ QRegularExpression::CaseInsensitiveOption);
- proxyModel = new QSortFilterProxyModel(this);
+ auto proxyModel = new QSortFilterProxyModel(this);
proxyModel->setSourceModel(table);
- proxyModel->setFilterRegExp(QRegExp(regExp, Qt::CaseInsensitive));
+ proxyModel->setFilterRegularExpression(regExp);
proxyModel->setFilterKeyColumn(0);
QTableView *tableView = new QTableView;
tableView->setModel(proxyModel);
-
tableView->setSelectionBehavior(QAbstractItemView::SelectRows);
tableView->horizontalHeader()->setStretchLastSection(true);
tableView->verticalHeader()->hide();
tableView->setEditTriggers(QAbstractItemView::NoEditTriggers);
tableView->setSelectionMode(QAbstractItemView::SingleSelection);
-
tableView->setSortingEnabled(true);
- connect(tableView->selectionModel(),
- &QItemSelectionModel::selectionChanged,
- this, &AddressWidget::selectionChanged);
+ connect(tableView->selectionModel(), &QItemSelectionModel::selectionChanged,
+ this, &AddressWidget::selectionChanged);
- connect(this, &QTabWidget::currentChanged, this, [this](int tabIndex) {
- auto *tableView = qobject_cast<QTableView *>(widget(tabIndex));
- if (tableView)
+ connect(this, &QTabWidget::currentChanged, this, [this, tableView](int tabIndex) {
+ if (widget(tabIndex) == tableView)
emit selectionChanged(tableView->selectionModel()->selection());
});
@@ -214,7 +201,7 @@ void AddressWidget::readFromFile(const QString &fileName)
return;
}
- QList<Contact> contacts;
+ QVector<Contact> contacts;
QDataStream in(&file);
in >> contacts;
diff --git a/examples/widgets/itemviews/addressbook/addresswidget.h b/examples/widgets/itemviews/addressbook/addresswidget.h
index de5a2da766..111ea98328 100644
--- a/examples/widgets/itemviews/addressbook/addresswidget.h
+++ b/examples/widgets/itemviews/addressbook/addresswidget.h
@@ -68,13 +68,13 @@ class AddressWidget : public QTabWidget
Q_OBJECT
public:
- AddressWidget(QWidget *parent = 0);
+ AddressWidget(QWidget *parent = nullptr);
void readFromFile(const QString &fileName);
void writeToFile(const QString &fileName);
public slots:
void showAddEntryDialog();
- void addEntry(QString name, QString address);
+ void addEntry(const QString &name, const QString &address);
void editEntry();
void removeEntry();
@@ -86,7 +86,6 @@ private:
TableModel *table;
NewAddressTab *newAddressTab;
- QSortFilterProxyModel *proxyModel;
};
//! [0]
diff --git a/examples/widgets/itemviews/addressbook/mainwindow.cpp b/examples/widgets/itemviews/addressbook/mainwindow.cpp
index 6d8b15b032..42966de375 100644
--- a/examples/widgets/itemviews/addressbook/mainwindow.cpp
+++ b/examples/widgets/itemviews/addressbook/mainwindow.cpp
@@ -56,8 +56,9 @@
//! [0]
MainWindow::MainWindow()
+ : QMainWindow(),
+ addressWidget(new AddressWidget)
{
- addressWidget = new AddressWidget;
setCentralWidget(addressWidget);
createMenus();
setWindowTitle(tr("Address Book"));
@@ -67,28 +68,29 @@ MainWindow::MainWindow()
//! [1a]
void MainWindow::createMenus()
{
- fileMenu = menuBar()->addMenu(tr("&File"));
+ QMenu *fileMenu = menuBar()->addMenu(tr("&File"));
- openAct = new QAction(tr("&Open..."), this);
+ QAction *openAct = new QAction(tr("&Open..."), this);
fileMenu->addAction(openAct);
connect(openAct, &QAction::triggered, this, &MainWindow::openFile);
//! [1a]
- saveAct = new QAction(tr("&Save As..."), this);
+ QAction *saveAct = new QAction(tr("&Save As..."), this);
fileMenu->addAction(saveAct);
connect(saveAct, &QAction::triggered, this, &MainWindow::saveFile);
fileMenu->addSeparator();
- exitAct = new QAction(tr("E&xit"), this);
+ QAction *exitAct = new QAction(tr("E&xit"), this);
fileMenu->addAction(exitAct);
connect(exitAct, &QAction::triggered, this, &QWidget::close);
- toolMenu = menuBar()->addMenu(tr("&Tools"));
+ QMenu *toolMenu = menuBar()->addMenu(tr("&Tools"));
- addAct = new QAction(tr("&Add Entry..."), this);
+ QAction *addAct = new QAction(tr("&Add Entry..."), this);
toolMenu->addAction(addAct);
- connect(addAct, &QAction::triggered, addressWidget, &AddressWidget::showAddEntryDialog);
+ connect(addAct, &QAction::triggered,
+ addressWidget, &AddressWidget::showAddEntryDialog);
//! [1b]
editAct = new QAction(tr("&Edit Entry..."), this);
diff --git a/examples/widgets/itemviews/addressbook/mainwindow.h b/examples/widgets/itemviews/addressbook/mainwindow.h
index 3d323e5799..fca5934e68 100644
--- a/examples/widgets/itemviews/addressbook/mainwindow.h
+++ b/examples/widgets/itemviews/addressbook/mainwindow.h
@@ -72,12 +72,6 @@ private:
void createMenus();
AddressWidget *addressWidget;
- QMenu *fileMenu;
- QMenu *toolMenu;
- QAction *openAct;
- QAction *saveAct;
- QAction *exitAct;
- QAction *addAct;
QAction *editAct;
QAction *removeAct;
};
diff --git a/examples/widgets/itemviews/addressbook/newaddresstab.cpp b/examples/widgets/itemviews/addressbook/newaddresstab.cpp
index f0a7369796..ef725d723f 100644
--- a/examples/widgets/itemviews/addressbook/newaddresstab.cpp
+++ b/examples/widgets/itemviews/addressbook/newaddresstab.cpp
@@ -48,24 +48,23 @@
**
****************************************************************************/
-#include "adddialog.h"
#include "newaddresstab.h"
+#include "adddialog.h"
#include <QtWidgets>
//! [0]
NewAddressTab::NewAddressTab(QWidget *parent)
+ : QWidget(parent)
{
- Q_UNUSED(parent);
+ auto descriptionLabel = new QLabel(tr("There are currently no contacts in your address book. "
+ "\nClick Add to add new contacts."));
- descriptionLabel = new QLabel(tr("There are currently no contacts in your address book. "
- "\nClick Add to add new contacts."));
-
- addButton = new QPushButton(tr("Add"));
+ auto addButton = new QPushButton(tr("Add"));
connect(addButton, &QAbstractButton::clicked, this, &NewAddressTab::addEntry);
- mainLayout = new QVBoxLayout;
+ auto mainLayout = new QVBoxLayout;
mainLayout->addWidget(descriptionLabel);
mainLayout->addWidget(addButton, 0, Qt::AlignCenter);
@@ -78,11 +77,7 @@ void NewAddressTab::addEntry()
{
AddDialog aDialog;
- if (aDialog.exec()) {
- QString name = aDialog.nameText->text();
- QString address = aDialog.addressText->toPlainText();
-
- emit sendDetails(name, address);
- }
+ if (aDialog.exec())
+ emit sendDetails(aDialog.name(), aDialog.address());
}
//! [1]
diff --git a/examples/widgets/itemviews/addressbook/newaddresstab.h b/examples/widgets/itemviews/addressbook/newaddresstab.h
index 05c7a8dada..6a147e3c7c 100644
--- a/examples/widgets/itemviews/addressbook/newaddresstab.h
+++ b/examples/widgets/itemviews/addressbook/newaddresstab.h
@@ -65,19 +65,13 @@ class NewAddressTab : public QWidget
Q_OBJECT
public:
- NewAddressTab(QWidget *parent = 0);
+ NewAddressTab(QWidget *parent = nullptr);
public slots:
void addEntry();
signals:
- void sendDetails(QString name, QString address);
-
-private:
- QLabel *descriptionLabel;
- QPushButton *addButton;
- QVBoxLayout *mainLayout;
-
+ void sendDetails(const QString &name, const QString &address);
};
//! [0]
diff --git a/examples/widgets/itemviews/addressbook/tablemodel.cpp b/examples/widgets/itemviews/addressbook/tablemodel.cpp
index b3704f857e..ddf79a3fa3 100644
--- a/examples/widgets/itemviews/addressbook/tablemodel.cpp
+++ b/examples/widgets/itemviews/addressbook/tablemodel.cpp
@@ -56,9 +56,9 @@ TableModel::TableModel(QObject *parent)
{
}
-TableModel::TableModel(QList<Contact> contacts, QObject *parent)
- : QAbstractTableModel(parent)
- , contacts(contacts)
+TableModel::TableModel(const QVector<Contact> &contacts, QObject *parent)
+ : QAbstractTableModel(parent),
+ contacts(contacts)
{
}
//! [0]
@@ -66,14 +66,12 @@ TableModel::TableModel(QList<Contact> contacts, QObject *parent)
//! [1]
int TableModel::rowCount(const QModelIndex &parent) const
{
- Q_UNUSED(parent);
- return contacts.size();
+ return parent.isValid() ? 0 : contacts.size();
}
int TableModel::columnCount(const QModelIndex &parent) const
{
- Q_UNUSED(parent);
- return 2;
+ return parent.isValid() ? 0 : 2;
}
//! [1]
@@ -89,10 +87,14 @@ QVariant TableModel::data(const QModelIndex &index, int role) const
if (role == Qt::DisplayRole) {
const auto &contact = contacts.at(index.row());
- if (index.column() == 0)
- return contact.name;
- else if (index.column() == 1)
- return contact.address;
+ switch (index.column()) {
+ case 0:
+ return contact.name;
+ case 1:
+ return contact.address;
+ default:
+ break;
+ }
}
return QVariant();
}
@@ -108,12 +110,10 @@ QVariant TableModel::headerData(int section, Qt::Orientation orientation, int ro
switch (section) {
case 0:
return tr("Name");
-
case 1:
return tr("Address");
-
default:
- return QVariant();
+ break;
}
}
return QVariant();
@@ -152,19 +152,21 @@ bool TableModel::removeRows(int position, int rows, const QModelIndex &index)
bool TableModel::setData(const QModelIndex &index, const QVariant &value, int role)
{
if (index.isValid() && role == Qt::EditRole) {
- int row = index.row();
-
+ const int row = index.row();
auto contact = contacts.value(row);
- if (index.column() == 0)
- contact.name = value.toString();
- else if (index.column() == 1)
- contact.address = value.toString();
- else
- return false;
-
+ switch (index.column()) {
+ case 0:
+ contact.name = value.toString();
+ break;
+ case 1:
+ contact.address = value.toString();
+ break;
+ default:
+ return false;
+ }
contacts.replace(row, contact);
- emit dataChanged(index, index, {role});
+ emit dataChanged(index, index, {Qt::DisplayRole, Qt::EditRole});
return true;
}
@@ -184,7 +186,7 @@ Qt::ItemFlags TableModel::flags(const QModelIndex &index) const
//! [7]
//! [8]
-QList<Contact> TableModel::getContacts() const
+const QVector<Contact> &TableModel::getContacts() const
{
return contacts;
}
diff --git a/examples/widgets/itemviews/addressbook/tablemodel.h b/examples/widgets/itemviews/addressbook/tablemodel.h
index 1004a35d31..e4025fc734 100644
--- a/examples/widgets/itemviews/addressbook/tablemodel.h
+++ b/examples/widgets/itemviews/addressbook/tablemodel.h
@@ -52,7 +52,7 @@
#define TABLEMODEL_H
#include <QAbstractTableModel>
-#include <QList>
+#include <QVector>
//! [0]
@@ -82,8 +82,8 @@ class TableModel : public QAbstractTableModel
Q_OBJECT
public:
- TableModel(QObject *parent = 0);
- TableModel(QList<Contact> contacts, QObject *parent = 0);
+ TableModel(QObject *parent = nullptr);
+ TableModel(const QVector<Contact> &contacts, QObject *parent = nullptr);
int rowCount(const QModelIndex &parent) const override;
int columnCount(const QModelIndex &parent) const override;
@@ -93,10 +93,10 @@ public:
bool setData(const QModelIndex &index, const QVariant &value, int role = Qt::EditRole) override;
bool insertRows(int position, int rows, const QModelIndex &index = QModelIndex()) override;
bool removeRows(int position, int rows, const QModelIndex &index = QModelIndex()) override;
- QList<Contact> getContacts() const;
+ const QVector<Contact> &getContacts() const;
private:
- QList<Contact> contacts;
+ QVector<Contact> contacts;
};
//! [0]
diff --git a/examples/widgets/itemviews/coloreditorfactory/colorlisteditor.cpp b/examples/widgets/itemviews/coloreditorfactory/colorlisteditor.cpp
index 75d809a44f..0b65c53477 100644
--- a/examples/widgets/itemviews/coloreditorfactory/colorlisteditor.cpp
+++ b/examples/widgets/itemviews/coloreditorfactory/colorlisteditor.cpp
@@ -48,10 +48,10 @@
**
****************************************************************************/
-#include <QtWidgets>
-
#include "colorlisteditor.h"
+#include <QtWidgets>
+
ColorListEditor::ColorListEditor(QWidget *widget) : QComboBox(widget)
{
populateList();
@@ -65,16 +65,16 @@ QColor ColorListEditor::color() const
//! [0]
//! [1]
-void ColorListEditor::setColor(QColor color)
+void ColorListEditor::setColor(const QColor &color)
{
- setCurrentIndex(findData(color, int(Qt::DecorationRole)));
+ setCurrentIndex(findData(color, Qt::DecorationRole));
}
//! [1]
//! [2]
void ColorListEditor::populateList()
{
- QStringList colorNames = QColor::colorNames();
+ const QStringList colorNames = QColor::colorNames();
for (int i = 0; i < colorNames.size(); ++i) {
QColor color(colorNames[i]);
diff --git a/examples/widgets/itemviews/coloreditorfactory/colorlisteditor.h b/examples/widgets/itemviews/coloreditorfactory/colorlisteditor.h
index f284c07c89..f9d736d298 100644
--- a/examples/widgets/itemviews/coloreditorfactory/colorlisteditor.h
+++ b/examples/widgets/itemviews/coloreditorfactory/colorlisteditor.h
@@ -65,11 +65,11 @@ class ColorListEditor : public QComboBox
Q_PROPERTY(QColor color READ color WRITE setColor USER true)
public:
- ColorListEditor(QWidget *widget = 0);
+ ColorListEditor(QWidget *widget = nullptr);
public:
QColor color() const;
- void setColor(QColor c);
+ void setColor(const QColor &color);
private:
void populateList();
diff --git a/examples/widgets/itemviews/coloreditorfactory/window.cpp b/examples/widgets/itemviews/coloreditorfactory/window.cpp
index f7ce821d31..e4a9379d8f 100644
--- a/examples/widgets/itemviews/coloreditorfactory/window.cpp
+++ b/examples/widgets/itemviews/coloreditorfactory/window.cpp
@@ -48,11 +48,11 @@
**
****************************************************************************/
-#include <QtWidgets>
-
#include "window.h"
#include "colorlisteditor.h"
+#include <QtWidgets>
+
//! [0]
Window::Window()
{
@@ -71,19 +71,18 @@ Window::Window()
void Window::createGUI()
{
- QList<QPair<QString, QColor> > list;
- list << QPair<QString, QColor>(tr("Alice"), QColor("aliceblue")) <<
- QPair<QString, QColor>(tr("Neptun"), QColor("aquamarine")) <<
- QPair<QString, QColor>(tr("Ferdinand"), QColor("springgreen"));
+ const QVector<QPair<QString, QColor> > list =
+ {{ tr("Alice"), QColor("aliceblue") },
+ { tr("Neptun"), QColor("aquamarine") },
+ { tr("Ferdinand"), QColor("springgreen") }};
QTableWidget *table = new QTableWidget(3, 2);
- table->setHorizontalHeaderLabels(QStringList() << tr("Name")
- << tr("Hair Color"));
+ table->setHorizontalHeaderLabels({ tr("Name"), tr("Hair Color") });
table->verticalHeader()->setVisible(false);
table->resize(150, 50);
for (int i = 0; i < 3; ++i) {
- QPair<QString, QColor> pair = list.at(i);
+ const QPair<QString, QColor> &pair = list.at(i);
QTableWidgetItem *nameItem = new QTableWidgetItem(pair.first);
QTableWidgetItem *colorItem = new QTableWidgetItem;
diff --git a/examples/widgets/itemviews/customsortfiltermodel/filterwidget.cpp b/examples/widgets/itemviews/customsortfiltermodel/filterwidget.cpp
index 74d88caae6..302042a6b3 100644
--- a/examples/widgets/itemviews/customsortfiltermodel/filterwidget.cpp
+++ b/examples/widgets/itemviews/customsortfiltermodel/filterwidget.cpp
@@ -52,13 +52,11 @@
#include <QIcon>
#include <QPixmap>
-#include <QImage>
#include <QMenu>
#include <QAction>
#include <QActionGroup>
#include <QToolButton>
#include <QWidgetAction>
-#include <QDebug>
FilterWidget::FilterWidget(QWidget *parent)
: QLineEdit(parent)
@@ -127,7 +125,8 @@ QRegExp::PatternSyntax FilterWidget::patternSyntax() const
void FilterWidget::setPatternSyntax(QRegExp::PatternSyntax s)
{
- foreach (QAction *a, m_patternGroup->actions()) {
+ const QList<QAction*> actions = m_patternGroup->actions();
+ for (QAction *a : actions) {
if (patternSyntaxFromAction(a) == s) {
a->setChecked(true);
break;
diff --git a/examples/widgets/itemviews/customsortfiltermodel/filterwidget.h b/examples/widgets/itemviews/customsortfiltermodel/filterwidget.h
index ea12954e52..70214b862e 100644
--- a/examples/widgets/itemviews/customsortfiltermodel/filterwidget.h
+++ b/examples/widgets/itemviews/customsortfiltermodel/filterwidget.h
@@ -67,7 +67,7 @@ class FilterWidget : public QLineEdit
Q_PROPERTY(Qt::CaseSensitivity caseSensitivity READ caseSensitivity WRITE setCaseSensitivity)
Q_PROPERTY(QRegExp::PatternSyntax patternSyntax READ patternSyntax WRITE setPatternSyntax)
public:
- explicit FilterWidget(QWidget *parent = 0);
+ explicit FilterWidget(QWidget *parent = nullptr);
Qt::CaseSensitivity caseSensitivity() const;
void setCaseSensitivity(Qt::CaseSensitivity);
diff --git a/examples/widgets/itemviews/customsortfiltermodel/mysortfilterproxymodel.cpp b/examples/widgets/itemviews/customsortfiltermodel/mysortfilterproxymodel.cpp
index 35426657d9..4753d04d9b 100644
--- a/examples/widgets/itemviews/customsortfiltermodel/mysortfilterproxymodel.cpp
+++ b/examples/widgets/itemviews/customsortfiltermodel/mysortfilterproxymodel.cpp
@@ -48,10 +48,10 @@
**
****************************************************************************/
-#include <QtWidgets>
-
#include "mysortfilterproxymodel.h"
+#include <QtWidgets>
+
//! [0]
MySortFilterProxyModel::MySortFilterProxyModel(QObject *parent)
: QSortFilterProxyModel(parent)
@@ -77,7 +77,7 @@ void MySortFilterProxyModel::setFilterMaximumDate(const QDate &date)
//! [3]
bool MySortFilterProxyModel::filterAcceptsRow(int sourceRow,
- const QModelIndex &sourceParent) const
+ const QModelIndex &sourceParent) const
{
QModelIndex index0 = sourceModel()->index(sourceRow, 0, sourceParent);
QModelIndex index1 = sourceModel()->index(sourceRow, 1, sourceParent);
diff --git a/examples/widgets/itemviews/customsortfiltermodel/window.cpp b/examples/widgets/itemviews/customsortfiltermodel/window.cpp
index bfd2350da0..3356c971ad 100644
--- a/examples/widgets/itemviews/customsortfiltermodel/window.cpp
+++ b/examples/widgets/itemviews/customsortfiltermodel/window.cpp
@@ -48,12 +48,12 @@
**
****************************************************************************/
-#include <QtWidgets>
-
-#include "mysortfilterproxymodel.h"
#include "window.h"
+#include "mysortfilterproxymodel.h"
#include "filterwidget.h"
+#include <QtWidgets>
+
//! [0]
Window::Window()
{
@@ -75,7 +75,7 @@ Window::Window()
//! [3]
filterWidget = new FilterWidget;
- filterWidget->setText("Grace|Sports");
+ filterWidget->setText(tr("Grace|Sports"));
connect(filterWidget, &FilterWidget::filterChanged, this, &Window::textFilterChanged);
filterPatternLabel = new QLabel(tr("&Filter pattern:"));
@@ -137,6 +137,11 @@ void Window::setSourceModel(QAbstractItemModel *model)
{
proxyModel->setSourceModel(model);
sourceView->setModel(model);
+
+ for (int i = 0; i < proxyModel->columnCount(); ++i)
+ proxyView->resizeColumnToContents(i);
+ for (int i = 0; i < model->columnCount(); ++i)
+ sourceView->resizeColumnToContents(i);
}
//! [7]
diff --git a/examples/widgets/itemviews/fetchmore/filelistmodel.cpp b/examples/widgets/itemviews/fetchmore/filelistmodel.cpp
index 086d45eca3..3ee80617c0 100644
--- a/examples/widgets/itemviews/fetchmore/filelistmodel.cpp
+++ b/examples/widgets/itemviews/fetchmore/filelistmodel.cpp
@@ -50,20 +50,18 @@
#include "filelistmodel.h"
-#include <QApplication>
-#include <QBrush>
+#include <QGuiApplication>
#include <QDir>
#include <QPalette>
FileListModel::FileListModel(QObject *parent)
- : QAbstractListModel(parent)
-{
-}
+ : QAbstractListModel(parent), fileCount(0)
+{}
//![4]
-int FileListModel::rowCount(const QModelIndex & /* parent */) const
+int FileListModel::rowCount(const QModelIndex &parent) const
{
- return fileCount;
+ return parent.isValid() ? 0 : fileCount;
}
QVariant FileListModel::data(const QModelIndex &index, int role) const
@@ -88,25 +86,26 @@ QVariant FileListModel::data(const QModelIndex &index, int role) const
//![4]
//![1]
-bool FileListModel::canFetchMore(const QModelIndex & /* index */) const
+bool FileListModel::canFetchMore(const QModelIndex &parent) const
{
- if (fileCount < fileList.size())
- return true;
- else
+ if (parent.isValid())
return false;
+ return (fileCount < fileList.size());
}
//![1]
//![2]
-void FileListModel::fetchMore(const QModelIndex & /* index */)
+void FileListModel::fetchMore(const QModelIndex &parent)
{
+ if (parent.isValid())
+ return;
int remainder = fileList.size() - fileCount;
int itemsToFetch = qMin(100, remainder);
if (itemsToFetch <= 0)
return;
- beginInsertRows(QModelIndex(), fileCount, fileCount+itemsToFetch-1);
+ beginInsertRows(QModelIndex(), fileCount, fileCount + itemsToFetch - 1);
fileCount += itemsToFetch;
diff --git a/examples/widgets/itemviews/fetchmore/filelistmodel.h b/examples/widgets/itemviews/fetchmore/filelistmodel.h
index 9251eaf959..35cf6f7b46 100644
--- a/examples/widgets/itemviews/fetchmore/filelistmodel.h
+++ b/examples/widgets/itemviews/fetchmore/filelistmodel.h
@@ -52,7 +52,6 @@
#define FILELISTMODEL_H
#include <QAbstractListModel>
-#include <QList>
#include <QStringList>
//![0]
@@ -61,7 +60,7 @@ class FileListModel : public QAbstractListModel
Q_OBJECT
public:
- FileListModel(QObject *parent = 0);
+ FileListModel(QObject *parent = nullptr);
int rowCount(const QModelIndex &parent = QModelIndex()) const override;
QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const override;
diff --git a/examples/widgets/itemviews/fetchmore/window.cpp b/examples/widgets/itemviews/fetchmore/window.cpp
index 886f76d6ab..d71ac7059d 100644
--- a/examples/widgets/itemviews/fetchmore/window.cpp
+++ b/examples/widgets/itemviews/fetchmore/window.cpp
@@ -48,8 +48,8 @@
**
****************************************************************************/
-#include "filelistmodel.h"
#include "window.h"
+#include "filelistmodel.h"
#include <QtWidgets>
@@ -66,7 +66,7 @@ Window::Window(QWidget *parent)
QListView *view = new QListView;
view->setModel(model);
- logViewer = new QTextBrowser;
+ logViewer = new QTextBrowser(this);
logViewer->setSizePolicy(QSizePolicy(QSizePolicy::Preferred, QSizePolicy::Preferred));
connect(lineEdit, &QLineEdit::textChanged,
diff --git a/examples/widgets/itemviews/fetchmore/window.h b/examples/widgets/itemviews/fetchmore/window.h
index f234683785..61bcb94bde 100644
--- a/examples/widgets/itemviews/fetchmore/window.h
+++ b/examples/widgets/itemviews/fetchmore/window.h
@@ -62,7 +62,7 @@ class Window : public QWidget
Q_OBJECT
public:
- Window(QWidget *parent = 0);
+ Window(QWidget *parent = nullptr);
public slots:
void updateLog(int number);
diff --git a/examples/widgets/itemviews/interview/model.cpp b/examples/widgets/itemviews/interview/model.cpp
index a8f3a6f31e..feaf8bb98c 100644
--- a/examples/widgets/itemviews/interview/model.cpp
+++ b/examples/widgets/itemviews/interview/model.cpp
@@ -50,14 +50,13 @@
#include "model.h"
-#include <QIcon>
#include <QPixmap>
Model::Model(int rows, int columns, QObject *parent)
: QAbstractItemModel(parent),
services(QPixmap(":/images/services.png")),
rc(rows), cc(columns),
- tree(new QVector<Node>(rows, Node(0)))
+ tree(new QVector<Node>(rows, Node()))
{
}
diff --git a/examples/widgets/itemviews/interview/model.h b/examples/widgets/itemviews/interview/model.h
index 969cf693b2..132f1d01aa 100644
--- a/examples/widgets/itemviews/interview/model.h
+++ b/examples/widgets/itemviews/interview/model.h
@@ -61,7 +61,7 @@ class Model : public QAbstractItemModel
Q_OBJECT
public:
- Model(int rows, int columns, QObject *parent = 0);
+ Model(int rows, int columns, QObject *parent = nullptr);
~Model();
QModelIndex index(int row, int column, const QModelIndex &parent) const override;
@@ -80,7 +80,7 @@ private:
struct Node
{
- Node(Node *parent = 0) : parent(parent), children(0) {}
+ Node(Node *parent = nullptr) : parent(parent), children(nullptr) {}
~Node() { delete children; }
Node *parent;
QVector<Node> *children;
diff --git a/examples/widgets/itemviews/pixelator/mainwindow.cpp b/examples/widgets/itemviews/pixelator/mainwindow.cpp
index 63617f0169..f6b67e4dba 100644
--- a/examples/widgets/itemviews/pixelator/mainwindow.cpp
+++ b/examples/widgets/itemviews/pixelator/mainwindow.cpp
@@ -48,8 +48,8 @@
**
****************************************************************************/
-#include "imagemodel.h"
#include "mainwindow.h"
+#include "imagemodel.h"
#include "pixeldelegate.h"
#include <QtWidgets>
diff --git a/examples/widgets/itemviews/pixelator/pixeldelegate.cpp b/examples/widgets/itemviews/pixelator/pixeldelegate.cpp
index ecf44c1224..dc8736c836 100644
--- a/examples/widgets/itemviews/pixelator/pixeldelegate.cpp
+++ b/examples/widgets/itemviews/pixelator/pixeldelegate.cpp
@@ -54,10 +54,8 @@
//! [0]
PixelDelegate::PixelDelegate(QObject *parent)
- : QAbstractItemDelegate(parent)
-{
- pixelSize = 12;
-}
+ : QAbstractItemDelegate(parent), pixelSize(12)
+{}
//! [0]
//! [1]
@@ -70,11 +68,11 @@ void PixelDelegate::paint(QPainter *painter, const QStyleOptionViewItem &option,
//! [1]
//! [3]
- int size = qMin(option.rect.width(), option.rect.height());
+ const int size = qMin(option.rect.width(), option.rect.height());
//! [3] //! [4]
- int brightness = index.model()->data(index, Qt::DisplayRole).toInt();
- double radius = (size / 2.0) - (brightness / 255.0 * size / 2.0);
- if (radius == 0.0)
+ const int brightness = index.model()->data(index, Qt::DisplayRole).toInt();
+ const double radius = (size / 2.0) - (brightness / 255.0 * size / 2.0);
+ if (qFuzzyIsNull(radius))
return;
//! [4]
diff --git a/examples/widgets/itemviews/pixelator/pixeldelegate.h b/examples/widgets/itemviews/pixelator/pixeldelegate.h
index d968d9e8d2..9f52221a28 100644
--- a/examples/widgets/itemviews/pixelator/pixeldelegate.h
+++ b/examples/widgets/itemviews/pixelator/pixeldelegate.h
@@ -61,7 +61,7 @@ class QObject;
class QPainter;
QT_END_NAMESPACE
-static const int ItemSize = 256;
+static constexpr int ItemSize = 256;
//! [0]
class PixelDelegate : public QAbstractItemDelegate
@@ -69,13 +69,13 @@ class PixelDelegate : public QAbstractItemDelegate
Q_OBJECT
public:
- PixelDelegate(QObject *parent = 0);
+ PixelDelegate(QObject *parent = nullptr);
void paint(QPainter *painter, const QStyleOptionViewItem &option,
const QModelIndex &index) const override;
QSize sizeHint(const QStyleOptionViewItem &option,
- const QModelIndex &index ) const override;
+ const QModelIndex &index) const override;
public slots:
void setPixelSize(int size);
diff --git a/examples/widgets/itemviews/puzzle/piecesmodel.cpp b/examples/widgets/itemviews/puzzle/piecesmodel.cpp
index 28b46836f4..a9c53ed2cd 100644
--- a/examples/widgets/itemviews/puzzle/piecesmodel.cpp
+++ b/examples/widgets/itemviews/puzzle/piecesmodel.cpp
@@ -134,7 +134,7 @@ QMimeData *PiecesModel::mimeData(const QModelIndexList &indexes) const
QDataStream stream(&encodedData, QIODevice::WriteOnly);
- foreach (QModelIndex index, indexes) {
+ for (const QModelIndex &index : indexes) {
if (index.isValid()) {
QPixmap pixmap = qvariant_cast<QPixmap>(data(index, Qt::UserRole));
QPoint location = data(index, Qt::UserRole+1).toPoint();
@@ -190,10 +190,7 @@ bool PiecesModel::dropMimeData(const QMimeData *data, Qt::DropAction action,
int PiecesModel::rowCount(const QModelIndex &parent) const
{
- if (parent.isValid())
- return 0;
- else
- return pixmaps.size();
+ return parent.isValid() ? 0 : pixmaps.size();
}
Qt::DropActions PiecesModel::supportedDropActions() const
@@ -201,7 +198,7 @@ Qt::DropActions PiecesModel::supportedDropActions() const
return Qt::CopyAction | Qt::MoveAction;
}
-void PiecesModel::addPieces(const QPixmap& pixmap)
+void PiecesModel::addPieces(const QPixmap &pixmap)
{
if (!pixmaps.isEmpty()) {
beginRemoveRows(QModelIndex(), 0, pixmaps.size() - 1);
diff --git a/examples/widgets/itemviews/puzzle/piecesmodel.h b/examples/widgets/itemviews/puzzle/piecesmodel.h
index bd979f4c7e..2a96603707 100644
--- a/examples/widgets/itemviews/puzzle/piecesmodel.h
+++ b/examples/widgets/itemviews/puzzle/piecesmodel.h
@@ -52,10 +52,10 @@
#define PIECESLIST_H
#include <QAbstractListModel>
-#include <QList>
#include <QPixmap>
#include <QPoint>
#include <QStringList>
+#include <QVector>
QT_BEGIN_NAMESPACE
class QMimeData;
@@ -66,7 +66,7 @@ class PiecesModel : public QAbstractListModel
Q_OBJECT
public:
- explicit PiecesModel(int pieceSize, QObject *parent = 0);
+ explicit PiecesModel(int pieceSize, QObject *parent = nullptr);
QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const override;
Qt::ItemFlags flags(const QModelIndex &index) const override;
@@ -80,11 +80,11 @@ public:
Qt::DropActions supportedDropActions() const override;
void addPiece(const QPixmap &pixmap, const QPoint &location);
- void addPieces(const QPixmap& pixmap);
+ void addPieces(const QPixmap &pixmap);
private:
- QList<QPoint> locations;
- QList<QPixmap> pixmaps;
+ QVector<QPoint> locations;
+ QVector<QPixmap> pixmaps;
int m_PieceSize;
};
diff --git a/examples/widgets/itemviews/simpledommodel/domitem.cpp b/examples/widgets/itemviews/simpledommodel/domitem.cpp
index c8b35b2e0a..a2dc9530f0 100644
--- a/examples/widgets/itemviews/simpledommodel/domitem.cpp
+++ b/examples/widgets/itemviews/simpledommodel/domitem.cpp
@@ -53,23 +53,20 @@
#include <QtXml>
//! [0]
-DomItem::DomItem(QDomNode &node, int row, DomItem *parent)
-{
- domNode = node;
+DomItem::DomItem(const QDomNode &node, int row, DomItem *parent)
+ : domNode(node),
//! [0]
- // Record the item's location within its parent.
+ // Record the item's location within its parent.
//! [1]
- rowNumber = row;
- parentItem = parent;
-}
+ parentItem(parent),
+ rowNumber(row)
+{}
//! [1]
//! [2]
DomItem::~DomItem()
{
- QHash<int,DomItem*>::iterator it;
- for (it = childItems.begin(); it != childItems.end(); ++it)
- delete it.value();
+ qDeleteAll(childItems);
}
//! [2]
@@ -90,21 +87,22 @@ DomItem *DomItem::parent()
//! [5]
DomItem *DomItem::child(int i)
{
- if (childItems.contains(i))
- return childItems[i];
+ DomItem *childItem = childItems.value(i);
+ if (childItem)
+ return childItem;
+ // if child does not yet exist, create it
if (i >= 0 && i < domNode.childNodes().count()) {
QDomNode childNode = domNode.childNodes().item(i);
- DomItem *childItem = new DomItem(childNode, i, this);
+ childItem = new DomItem(childNode, i, this);
childItems[i] = childItem;
- return childItem;
}
- return 0;
+ return childItem;
}
//! [5]
//! [6]
-int DomItem::row()
+int DomItem::row() const
{
return rowNumber;
}
diff --git a/examples/widgets/itemviews/simpledommodel/domitem.h b/examples/widgets/itemviews/simpledommodel/domitem.h
index b5db16009c..4a74db5139 100644
--- a/examples/widgets/itemviews/simpledommodel/domitem.h
+++ b/examples/widgets/itemviews/simpledommodel/domitem.h
@@ -58,16 +58,16 @@
class DomItem
{
public:
- DomItem(QDomNode &node, int row, DomItem *parent = 0);
+ DomItem(const QDomNode &node, int row, DomItem *parent = nullptr);
~DomItem();
DomItem *child(int i);
DomItem *parent();
QDomNode node() const;
- int row();
+ int row() const;
private:
QDomNode domNode;
- QHash<int,DomItem*> childItems;
+ QHash<int, DomItem *> childItems;
DomItem *parentItem;
int rowNumber;
};
diff --git a/examples/widgets/itemviews/simpledommodel/dommodel.cpp b/examples/widgets/itemviews/simpledommodel/dommodel.cpp
index f9ba0b5801..8e15252ebb 100644
--- a/examples/widgets/itemviews/simpledommodel/dommodel.cpp
+++ b/examples/widgets/itemviews/simpledommodel/dommodel.cpp
@@ -48,16 +48,17 @@
**
****************************************************************************/
-#include "domitem.h"
#include "dommodel.h"
+#include "domitem.h"
#include <QtXml>
//! [0]
-DomModel::DomModel(QDomDocument document, QObject *parent)
- : QAbstractItemModel(parent), domDocument(document)
+DomModel::DomModel(const QDomDocument &document, QObject *parent)
+ : QAbstractItemModel(parent),
+ domDocument(document),
+ rootItem(new DomItem(domDocument, 0))
{
- rootItem = new DomItem(domDocument, 0);
}
//! [0]
@@ -69,8 +70,9 @@ DomModel::~DomModel()
//! [1]
//! [2]
-int DomModel::columnCount(const QModelIndex &/*parent*/) const
+int DomModel::columnCount(const QModelIndex &parent) const
{
+ Q_UNUSED(parent);
return 3;
}
//! [2]
@@ -84,28 +86,31 @@ QVariant DomModel::data(const QModelIndex &index, int role) const
if (role != Qt::DisplayRole)
return QVariant();
- DomItem *item = static_cast<DomItem*>(index.internalPointer());
+ const DomItem *item = static_cast<DomItem*>(index.internalPointer());
- QDomNode node = item->node();
+ const QDomNode node = item->node();
//! [3] //! [4]
- QStringList attributes;
- QDomNamedNodeMap attributeMap = node.attributes();
switch (index.column()) {
case 0:
return node.nodeName();
case 1:
+ {
+ const QDomNamedNodeMap attributeMap = node.attributes();
+ QStringList attributes;
for (int i = 0; i < attributeMap.count(); ++i) {
QDomNode attribute = attributeMap.item(i);
attributes << attribute.nodeName() + "=\""
- +attribute.nodeValue() + '"';
+ + attribute.nodeValue() + '"';
}
return attributes.join(' ');
+ }
case 2:
- return node.nodeValue().split("\n").join(' ');
+ return node.nodeValue().split('\n').join(' ');
default:
- return QVariant();
+ break;
}
+ return QVariant();
}
//! [4]
@@ -113,7 +118,7 @@ QVariant DomModel::data(const QModelIndex &index, int role) const
Qt::ItemFlags DomModel::flags(const QModelIndex &index) const
{
if (!index.isValid())
- return 0;
+ return Qt::NoItemFlags;
return QAbstractItemModel::flags(index);
}
@@ -132,17 +137,15 @@ QVariant DomModel::headerData(int section, Qt::Orientation orientation,
case 2:
return tr("Value");
default:
- return QVariant();
+ break;
}
}
-
return QVariant();
}
//! [6]
//! [7]
-QModelIndex DomModel::index(int row, int column, const QModelIndex &parent)
- const
+QModelIndex DomModel::index(int row, int column, const QModelIndex &parent) const
{
if (!hasIndex(row, column, parent))
return QModelIndex();
@@ -159,8 +162,7 @@ QModelIndex DomModel::index(int row, int column, const QModelIndex &parent)
DomItem *childItem = parentItem->child(row);
if (childItem)
return createIndex(row, column, childItem);
- else
- return QModelIndex();
+ return QModelIndex();
}
//! [8]
diff --git a/examples/widgets/itemviews/simpledommodel/dommodel.h b/examples/widgets/itemviews/simpledommodel/dommodel.h
index 411f58295c..a91bb33cf9 100644
--- a/examples/widgets/itemviews/simpledommodel/dommodel.h
+++ b/examples/widgets/itemviews/simpledommodel/dommodel.h
@@ -63,7 +63,7 @@ class DomModel : public QAbstractItemModel
Q_OBJECT
public:
- explicit DomModel(QDomDocument document, QObject *parent = 0);
+ explicit DomModel(const QDomDocument &document, QObject *parent = nullptr);
~DomModel();
QVariant data(const QModelIndex &index, int role) const override;
diff --git a/examples/widgets/itemviews/simpledommodel/mainwindow.cpp b/examples/widgets/itemviews/simpledommodel/mainwindow.cpp
index 7d43d0fc02..86543b07a6 100644
--- a/examples/widgets/itemviews/simpledommodel/mainwindow.cpp
+++ b/examples/widgets/itemviews/simpledommodel/mainwindow.cpp
@@ -48,22 +48,23 @@
**
****************************************************************************/
-#include "dommodel.h"
#include "mainwindow.h"
+#include "dommodel.h"
#include <QDomDocument>
#include <QTreeView>
#include <QMenuBar>
#include <QFileDialog>
-MainWindow::MainWindow() : QMainWindow(), model(0)
+MainWindow::MainWindow(QWidget *parent)
+ : QMainWindow(parent),
+ model(new DomModel(QDomDocument(), this)),
+ view(new QTreeView(this))
{
fileMenu = menuBar()->addMenu(tr("&File"));
fileMenu->addAction(tr("&Open..."), this, &MainWindow::openFile, QKeySequence::Open);
fileMenu->addAction(tr("E&xit"), this, &QWidget::close, QKeySequence::Quit);
- model = new DomModel(QDomDocument(), this);
- view = new QTreeView(this);
view->setModel(model);
setCentralWidget(view);
diff --git a/examples/widgets/itemviews/simpledommodel/mainwindow.h b/examples/widgets/itemviews/simpledommodel/mainwindow.h
index 938a1c54c1..b3f8d77f35 100644
--- a/examples/widgets/itemviews/simpledommodel/mainwindow.h
+++ b/examples/widgets/itemviews/simpledommodel/mainwindow.h
@@ -65,7 +65,7 @@ class MainWindow : public QMainWindow
Q_OBJECT
public:
- MainWindow();
+ MainWindow(QWidget *parent = nullptr);
public slots:
void openFile();
diff --git a/examples/widgets/itemviews/simplewidgetmapper/window.h b/examples/widgets/itemviews/simplewidgetmapper/window.h
index baa087f8ae..d04b528e16 100644
--- a/examples/widgets/itemviews/simplewidgetmapper/window.h
+++ b/examples/widgets/itemviews/simplewidgetmapper/window.h
@@ -69,7 +69,7 @@ class Window : public QWidget
Q_OBJECT
public:
- Window(QWidget *parent = 0);
+ Window(QWidget *parent = nullptr);
private slots:
void updateButtons(int row);
diff --git a/examples/widgets/itemviews/spinboxdelegate/delegate.cpp b/examples/widgets/itemviews/spinboxdelegate/delegate.cpp
index e7e03688c3..f0fe524a60 100644
--- a/examples/widgets/itemviews/spinboxdelegate/delegate.cpp
+++ b/examples/widgets/itemviews/spinboxdelegate/delegate.cpp
@@ -68,8 +68,8 @@ SpinBoxDelegate::SpinBoxDelegate(QObject *parent)
//! [1]
QWidget *SpinBoxDelegate::createEditor(QWidget *parent,
- const QStyleOptionViewItem &/* option */,
- const QModelIndex &/* index */) const
+ const QStyleOptionViewItem &/* option */,
+ const QModelIndex &/* index */) const
{
QSpinBox *editor = new QSpinBox(parent);
editor->setFrame(false);
@@ -105,7 +105,8 @@ void SpinBoxDelegate::setModelData(QWidget *editor, QAbstractItemModel *model,
//! [4]
void SpinBoxDelegate::updateEditorGeometry(QWidget *editor,
- const QStyleOptionViewItem &option, const QModelIndex &/* index */) const
+ const QStyleOptionViewItem &option,
+ const QModelIndex &/* index */) const
{
editor->setGeometry(option.rect);
}
diff --git a/examples/widgets/itemviews/spinboxdelegate/delegate.h b/examples/widgets/itemviews/spinboxdelegate/delegate.h
index 47ef1555f7..5dbdda9cd0 100644
--- a/examples/widgets/itemviews/spinboxdelegate/delegate.h
+++ b/examples/widgets/itemviews/spinboxdelegate/delegate.h
@@ -59,7 +59,7 @@ class SpinBoxDelegate : public QStyledItemDelegate
Q_OBJECT
public:
- SpinBoxDelegate(QObject *parent = 0);
+ SpinBoxDelegate(QObject *parent = nullptr);
QWidget *createEditor(QWidget *parent, const QStyleOptionViewItem &option,
const QModelIndex &index) const override;
@@ -68,8 +68,8 @@ public:
void setModelData(QWidget *editor, QAbstractItemModel *model,
const QModelIndex &index) const override;
- void updateEditorGeometry(QWidget *editor,
- const QStyleOptionViewItem &option, const QModelIndex &index) const override;
+ void updateEditorGeometry(QWidget *editor, const QStyleOptionViewItem &option,
+ const QModelIndex &index) const override;
};
//! [0]
diff --git a/examples/widgets/itemviews/spreadsheet/main.cpp b/examples/widgets/itemviews/spreadsheet/main.cpp
index 769edbdf03..548dc8d604 100644
--- a/examples/widgets/itemviews/spreadsheet/main.cpp
+++ b/examples/widgets/itemviews/spreadsheet/main.cpp
@@ -53,7 +53,8 @@
#include <QApplication>
#include <QLayout>
-int main(int argc, char** argv) {
+int main(int argc, char **argv)
+{
Q_INIT_RESOURCE(spreadsheet);
QApplication app(argc, argv);
SpreadSheet sheet(10, 6);
diff --git a/examples/widgets/itemviews/spreadsheet/printview.cpp b/examples/widgets/itemviews/spreadsheet/printview.cpp
index 31424e9070..7db1a6bad9 100644
--- a/examples/widgets/itemviews/spreadsheet/printview.cpp
+++ b/examples/widgets/itemviews/spreadsheet/printview.cpp
@@ -48,12 +48,11 @@
**
****************************************************************************/
+#include "printview.h"
+
#ifndef QT_NO_PRINTER
#include <QPrinter>
#endif
-#include <QStyleOptionViewItem>
-
-#include "printview.h"
PrintView::PrintView()
{
diff --git a/examples/widgets/itemviews/spreadsheet/spreadsheet.cpp b/examples/widgets/itemviews/spreadsheet/spreadsheet.cpp
index 621f655b02..421b4a240c 100644
--- a/examples/widgets/itemviews/spreadsheet/spreadsheet.cpp
+++ b/examples/widgets/itemviews/spreadsheet/spreadsheet.cpp
@@ -48,36 +48,30 @@
**
****************************************************************************/
-#include <QtWidgets>
-#if defined(QT_PRINTSUPPORT_LIB)
-#include <QtPrintSupport/qtprintsupportglobal.h>
-#if QT_CONFIG(printdialog)
-#include <QPrinter>
-#include <QPrintDialog>
-#endif
-#if QT_CONFIG(printpreviewdialog)
-#include <QPrintPreviewDialog>
-#endif
-#endif
-
#include "spreadsheet.h"
#include "spreadsheetdelegate.h"
#include "spreadsheetitem.h"
#include "printview.h"
+#include <QtWidgets>
+#if defined(QT_PRINTSUPPORT_LIB)
+#include <QtPrintSupport>
+#endif
+
SpreadSheet::SpreadSheet(int rows, int cols, QWidget *parent)
- : QMainWindow(parent)
+ : QMainWindow(parent),
+ toolBar(new QToolBar(this)),
+ cellLabel(new QLabel(toolBar)),
+ table(new QTableWidget(rows, cols, this)),
+ formulaInput(new QLineEdit(this))
{
- addToolBar(toolBar = new QToolBar());
- formulaInput = new QLineEdit();
+ addToolBar(toolBar);
- cellLabel = new QLabel(toolBar);
cellLabel->setMinimumSize(80, 0);
toolBar->addWidget(cellLabel);
toolBar->addWidget(formulaInput);
- table = new QTableWidget(rows, cols, this);
table->setSizeAdjustPolicy(QTableWidget::AdjustToContents);
for (int c = 0; c < cols; ++c) {
QString character(QChar('A' + c));
@@ -88,7 +82,7 @@ SpreadSheet::SpreadSheet(int rows, int cols, QWidget *parent)
table->setItemDelegate(new SpreadSheetDelegate());
createActions();
- updateColor(0);
+ updateColor(nullptr);
setupMenuBar();
setupContents();
setupContextMenu();
@@ -103,7 +97,8 @@ SpreadSheet::SpreadSheet(int rows, int cols, QWidget *parent)
this, &SpreadSheet::updateLineEdit);
connect(table, &QTableWidget::itemChanged,
this, &SpreadSheet::updateStatus);
- connect(formulaInput, &QLineEdit::returnPressed, this, &SpreadSheet::returnPressed);
+ connect(formulaInput, &QLineEdit::returnPressed,
+ this, &SpreadSheet::returnPressed);
connect(table, &QTableWidget::itemChanged,
this, &SpreadSheet::updateLineEdit);
@@ -245,11 +240,11 @@ void SpreadSheet::selectColor()
if (!col.isValid())
return;
- QList<QTableWidgetItem*> selected = table->selectedItems();
- if (selected.count() == 0)
+ const QList<QTableWidgetItem *> selected = table->selectedItems();
+ if (selected.isEmpty())
return;
- foreach (QTableWidgetItem *i, selected) {
+ for (QTableWidgetItem *i : selected) {
if (i)
i->setBackgroundColor(col);
}
@@ -259,8 +254,8 @@ void SpreadSheet::selectColor()
void SpreadSheet::selectFont()
{
- QList<QTableWidgetItem*> selected = table->selectedItems();
- if (selected.count() == 0)
+ const QList<QTableWidgetItem *> selected = table->selectedItems();
+ if (selected.isEmpty())
return;
bool ok = false;
@@ -268,7 +263,7 @@ void SpreadSheet::selectFont()
if (!ok)
return;
- foreach (QTableWidgetItem *i, selected) {
+ for (QTableWidgetItem *i : selected) {
if (i)
i->setFont(fnt);
}
@@ -397,7 +392,7 @@ void SpreadSheet::actionSum()
int col_last = 0;
int col_cur = 0;
- QList<QTableWidgetItem*> selected = table->selectedItems();
+ const QList<QTableWidgetItem *> selected = table->selectedItems();
if (!selected.isEmpty()) {
QTableWidgetItem *first = selected.first();
@@ -408,7 +403,7 @@ void SpreadSheet::actionSum()
col_last = table->column(last);
}
- QTableWidgetItem *current = table->currentItem();
+ const QTableWidgetItem *current = table->currentItem();
if (current) {
row_cur = table->row(current);
@@ -435,7 +430,7 @@ void SpreadSheet::actionMath_helper(const QString &title, const QString &op)
QString cell2 = "C2";
QString out = "C3";
- QTableWidgetItem *current = table->currentItem();
+ const QTableWidgetItem *current = table->currentItem();
if (current)
out = encode_pos(table->currentRow(), table->currentColumn());
@@ -468,8 +463,9 @@ void SpreadSheet::actionDivide()
void SpreadSheet::clear()
{
- foreach (QTableWidgetItem *i, table->selectedItems())
- i->setText("");
+ const QList<QTableWidgetItem *> selectedItems = table->selectedItems();
+ for (QTableWidgetItem *i : selectedItems)
+ i->setText(QString());
}
void SpreadSheet::setupContextMenu()
diff --git a/examples/widgets/itemviews/spreadsheet/spreadsheet.h b/examples/widgets/itemviews/spreadsheet/spreadsheet.h
index a90d1d8c20..b36a377156 100644
--- a/examples/widgets/itemviews/spreadsheet/spreadsheet.h
+++ b/examples/widgets/itemviews/spreadsheet/spreadsheet.h
@@ -65,10 +65,8 @@ QT_END_NAMESPACE
class SpreadSheet : public QMainWindow
{
Q_OBJECT
-
public:
-
- SpreadSheet(int rows, int cols, QWidget *parent = 0);
+ SpreadSheet(int rows, int cols, QWidget *parent = nullptr);
public slots:
void updateStatus(QTableWidgetItem *item);
diff --git a/examples/widgets/itemviews/spreadsheet/spreadsheetdelegate.cpp b/examples/widgets/itemviews/spreadsheet/spreadsheetdelegate.cpp
index aaf8902af5..eadd5fadb8 100644
--- a/examples/widgets/itemviews/spreadsheet/spreadsheetdelegate.cpp
+++ b/examples/widgets/itemviews/spreadsheet/spreadsheetdelegate.cpp
@@ -53,11 +53,12 @@
#include <QtWidgets>
SpreadSheetDelegate::SpreadSheetDelegate(QObject *parent)
- : QItemDelegate(parent) {}
+ : QItemDelegate(parent)
+{}
QWidget *SpreadSheetDelegate::createEditor(QWidget *parent,
- const QStyleOptionViewItem &,
- const QModelIndex &index) const
+ const QStyleOptionViewItem &,
+ const QModelIndex &index) const
{
if (index.column() == 1) {
QDateTimeEdit *editor = new QDateTimeEdit(parent);
@@ -92,7 +93,7 @@ void SpreadSheetDelegate::commitAndCloseEditor()
}
void SpreadSheetDelegate::setEditorData(QWidget *editor,
- const QModelIndex &index) const
+ const QModelIndex &index) const
{
QLineEdit *edit = qobject_cast<QLineEdit*>(editor);
if (edit) {
@@ -109,7 +110,8 @@ void SpreadSheetDelegate::setEditorData(QWidget *editor,
}
void SpreadSheetDelegate::setModelData(QWidget *editor,
- QAbstractItemModel *model, const QModelIndex &index) const
+ QAbstractItemModel *model,
+ const QModelIndex &index) const
{
QLineEdit *edit = qobject_cast<QLineEdit *>(editor);
if (edit) {
diff --git a/examples/widgets/itemviews/spreadsheet/spreadsheetdelegate.h b/examples/widgets/itemviews/spreadsheet/spreadsheetdelegate.h
index 333467720f..c89459cadf 100644
--- a/examples/widgets/itemviews/spreadsheet/spreadsheetdelegate.h
+++ b/examples/widgets/itemviews/spreadsheet/spreadsheetdelegate.h
@@ -51,8 +51,6 @@
#ifndef SPREADSHEETDELEGATE_H
#define SPREADSHEETDELEGATE_H
-#include "spreadsheet.h"
-
#include <QItemDelegate>
class SpreadSheetDelegate : public QItemDelegate
@@ -60,7 +58,7 @@ class SpreadSheetDelegate : public QItemDelegate
Q_OBJECT
public:
- SpreadSheetDelegate(QObject *parent = 0);
+ SpreadSheetDelegate(QObject *parent = nullptr);
QWidget *createEditor(QWidget *parent, const QStyleOptionViewItem &,
const QModelIndex &index) const override;
void setEditorData(QWidget *editor, const QModelIndex &index) const override;
diff --git a/examples/widgets/itemviews/spreadsheet/spreadsheetitem.cpp b/examples/widgets/itemviews/spreadsheet/spreadsheetitem.cpp
index 4c18fa8251..62d3a6fdcd 100644
--- a/examples/widgets/itemviews/spreadsheet/spreadsheetitem.cpp
+++ b/examples/widgets/itemviews/spreadsheet/spreadsheetitem.cpp
@@ -50,19 +50,9 @@
#include "spreadsheetitem.h"
-SpreadSheetItem::SpreadSheetItem()
- : QTableWidgetItem(), isResolving(false)
-{
-}
-
-SpreadSheetItem::SpreadSheetItem(const QString &text)
- : QTableWidgetItem(text), isResolving(false)
-{
-}
-
QTableWidgetItem *SpreadSheetItem::clone() const
{
- SpreadSheetItem *item = new SpreadSheetItem();
+ SpreadSheetItem *item = new SpreadSheetItem;
*item = *this;
return item;
}
@@ -75,21 +65,20 @@ QVariant SpreadSheetItem::data(int role) const
if (role == Qt::DisplayRole)
return display();
- QString t = display().toString();
- bool isNumber = false;
- int number = t.toInt(&isNumber);
+ const QString t = display().toString();
- if (role == Qt::TextColorRole) {
- if (!isNumber)
- return QVariant::fromValue(QColor(Qt::black));
- else if (number < 0)
- return QVariant::fromValue(QColor(Qt::red));
- return QVariant::fromValue(QColor(Qt::blue));
+ if (role == Qt::ForegroundRole) {
+ bool isNumber = false;
+ const int number = t.toInt(&isNumber);
+ QColor color = Qt::black;
+ if (isNumber)
+ color = (number < 0) ? Qt::red : Qt::blue;
+ return QVariant::fromValue(color);
}
- if (role == Qt::TextAlignmentRole)
- if (!t.isEmpty() && (t.at(0).isNumber() || t.at(0) == '-'))
- return (int)(Qt::AlignRight | Qt::AlignVCenter);
+ if (role == Qt::TextAlignmentRole)
+ if (!t.isEmpty() && (t.at(0).isNumber() || t.at(0) == '-'))
+ return int(Qt::AlignRight | Qt::AlignVCenter);
return QTableWidgetItem::data(role);
}
diff --git a/examples/widgets/itemviews/spreadsheet/spreadsheetitem.h b/examples/widgets/itemviews/spreadsheet/spreadsheetitem.h
index 46460df527..159f4a7eea 100644
--- a/examples/widgets/itemviews/spreadsheet/spreadsheetitem.h
+++ b/examples/widgets/itemviews/spreadsheet/spreadsheetitem.h
@@ -58,8 +58,7 @@
class SpreadSheetItem : public QTableWidgetItem
{
public:
- SpreadSheetItem();
- SpreadSheetItem(const QString &text);
+ using QTableWidgetItem::QTableWidgetItem;
QTableWidgetItem *clone() const override;
@@ -74,10 +73,10 @@ public:
static QVariant computeFormula(const QString &formula,
const QTableWidget *widget,
- const QTableWidgetItem *self = 0);
+ const QTableWidgetItem *self = nullptr);
private:
- mutable bool isResolving;
+ mutable bool isResolving = false;
};
#endif // SPREADSHEETITEM_H
diff --git a/examples/widgets/itemviews/stardelegate/main.cpp b/examples/widgets/itemviews/stardelegate/main.cpp
index 51ca30c73a..452976bba0 100644
--- a/examples/widgets/itemviews/stardelegate/main.cpp
+++ b/examples/widgets/itemviews/stardelegate/main.cpp
@@ -101,10 +101,7 @@ int main(int argc, char *argv[])
tableWidget.setEditTriggers(QAbstractItemView::DoubleClicked
| QAbstractItemView::SelectedClicked);
tableWidget.setSelectionBehavior(QAbstractItemView::SelectRows);
-
- QStringList headerLabels;
- headerLabels << "Title" << "Genre" << "Artist" << "Rating";
- tableWidget.setHorizontalHeaderLabels(headerLabels);
+ tableWidget.setHorizontalHeaderLabels({"Title", "Genre", "Artist", "Rating"});
populateTableWidget(&tableWidget);
diff --git a/examples/widgets/itemviews/stardelegate/stardelegate.cpp b/examples/widgets/itemviews/stardelegate/stardelegate.cpp
index da5902a160..41ae5a920f 100644
--- a/examples/widgets/itemviews/stardelegate/stardelegate.cpp
+++ b/examples/widgets/itemviews/stardelegate/stardelegate.cpp
@@ -65,7 +65,7 @@ void StarDelegate::paint(QPainter *painter, const QStyleOptionViewItem &option,
painter->fillRect(option.rect, option.palette.highlight());
starRating.paint(painter, option.rect, option.palette,
- StarRating::ReadOnly);
+ StarRating::EditMode::ReadOnly);
} else {
QStyledItemDelegate::paint(painter, option, index);
}
@@ -79,9 +79,8 @@ QSize StarDelegate::sizeHint(const QStyleOptionViewItem &option,
if (index.data().canConvert<StarRating>()) {
StarRating starRating = qvariant_cast<StarRating>(index.data());
return starRating.sizeHint();
- } else {
- return QStyledItemDelegate::sizeHint(option, index);
}
+ return QStyledItemDelegate::sizeHint(option, index);
}
//! [1]
@@ -96,9 +95,8 @@ QWidget *StarDelegate::createEditor(QWidget *parent,
connect(editor, &StarEditor::editingFinished,
this, &StarDelegate::commitAndCloseEditor);
return editor;
- } else {
- return QStyledItemDelegate::createEditor(parent, option, index);
}
+ return QStyledItemDelegate::createEditor(parent, option, index);
}
//! [2]
diff --git a/examples/widgets/itemviews/stardelegate/stardelegate.h b/examples/widgets/itemviews/stardelegate/stardelegate.h
index ffc65fbedd..1fc31f8ee8 100644
--- a/examples/widgets/itemviews/stardelegate/stardelegate.h
+++ b/examples/widgets/itemviews/stardelegate/stardelegate.h
@@ -57,9 +57,8 @@
class StarDelegate : public QStyledItemDelegate
{
Q_OBJECT
-
public:
- StarDelegate(QWidget *parent = 0) : QStyledItemDelegate(parent) {}
+ using QStyledItemDelegate::QStyledItemDelegate;
void paint(QPainter *painter, const QStyleOptionViewItem &option,
const QModelIndex &index) const override;
diff --git a/examples/widgets/itemviews/stardelegate/stareditor.cpp b/examples/widgets/itemviews/stardelegate/stareditor.cpp
index 19a4b54d9e..43706eeae0 100644
--- a/examples/widgets/itemviews/stardelegate/stareditor.cpp
+++ b/examples/widgets/itemviews/stardelegate/stareditor.cpp
@@ -48,11 +48,11 @@
**
****************************************************************************/
-#include <QtWidgets>
-
#include "stareditor.h"
#include "starrating.h"
+#include <QtWidgets>
+
//! [0]
StarEditor::StarEditor(QWidget *parent)
: QWidget(parent)
@@ -71,35 +71,37 @@ QSize StarEditor::sizeHint() const
void StarEditor::paintEvent(QPaintEvent *)
{
QPainter painter(this);
- myStarRating.paint(&painter, rect(), this->palette(),
- StarRating::Editable);
+ myStarRating.paint(&painter, rect(), palette(),
+ StarRating::EditMode::Editable);
}
//! [1]
//! [2]
void StarEditor::mouseMoveEvent(QMouseEvent *event)
{
- int star = starAtPosition(event->x());
+ const int star = starAtPosition(event->x());
if (star != myStarRating.starCount() && star != -1) {
myStarRating.setStarCount(star);
update();
}
+ QWidget::mouseMoveEvent(event);
}
//! [2]
//! [3]
-void StarEditor::mouseReleaseEvent(QMouseEvent * /* event */)
+void StarEditor::mouseReleaseEvent(QMouseEvent *event)
{
emit editingFinished();
+ QWidget::mouseReleaseEvent(event);
}
//! [3]
//! [4]
-int StarEditor::starAtPosition(int x)
+int StarEditor::starAtPosition(int x) const
{
- int star = (x / (myStarRating.sizeHint().width()
- / myStarRating.maxStarCount())) + 1;
+ const int star = (x / (myStarRating.sizeHint().width()
+ / myStarRating.maxStarCount())) + 1;
if (star <= 0 || star > myStarRating.maxStarCount())
return -1;
diff --git a/examples/widgets/itemviews/stardelegate/stareditor.h b/examples/widgets/itemviews/stardelegate/stareditor.h
index 4a4c3a4954..8b1bf2efed 100644
--- a/examples/widgets/itemviews/stardelegate/stareditor.h
+++ b/examples/widgets/itemviews/stardelegate/stareditor.h
@@ -59,9 +59,8 @@
class StarEditor : public QWidget
{
Q_OBJECT
-
public:
- StarEditor(QWidget *parent = 0);
+ StarEditor(QWidget *parent = nullptr);
QSize sizeHint() const override;
void setStarRating(const StarRating &starRating) {
@@ -78,7 +77,7 @@ protected:
void mouseReleaseEvent(QMouseEvent *event) override;
private:
- int starAtPosition(int x);
+ int starAtPosition(int x) const;
StarRating myStarRating;
};
diff --git a/examples/widgets/itemviews/stardelegate/starrating.cpp b/examples/widgets/itemviews/stardelegate/starrating.cpp
index 845e474de9..15e14965e3 100644
--- a/examples/widgets/itemviews/stardelegate/starrating.cpp
+++ b/examples/widgets/itemviews/stardelegate/starrating.cpp
@@ -48,19 +48,18 @@
**
****************************************************************************/
+#include "starrating.h"
+
#include <QtWidgets>
#include <cmath>
-#include "starrating.h"
-
-const int PaintingScaleFactor = 20;
+constexpr int PaintingScaleFactor = 20;
//! [0]
StarRating::StarRating(int starCount, int maxStarCount)
+ : myStarCount(starCount),
+ myMaxStarCount(maxStarCount)
{
- myStarCount = starCount;
- myMaxStarCount = maxStarCount;
-
starPolygon << QPointF(1.0, 0.5);
for (int i = 1; i < 5; ++i)
starPolygon << QPointF(0.5 + 0.5 * std::cos(0.8 * i * 3.14),
@@ -87,23 +86,19 @@ void StarRating::paint(QPainter *painter, const QRect &rect,
painter->setRenderHint(QPainter::Antialiasing, true);
painter->setPen(Qt::NoPen);
+ painter->setBrush(mode == EditMode::Editable ?
+ palette.highlight() :
+ palette.foreground());
- if (mode == Editable) {
- painter->setBrush(palette.highlight());
- } else {
- painter->setBrush(palette.foreground());
- }
-
- int yOffset = (rect.height() - PaintingScaleFactor) / 2;
+ const int yOffset = (rect.height() - PaintingScaleFactor) / 2;
painter->translate(rect.x(), rect.y() + yOffset);
painter->scale(PaintingScaleFactor, PaintingScaleFactor);
for (int i = 0; i < myMaxStarCount; ++i) {
- if (i < myStarCount) {
+ if (i < myStarCount)
painter->drawPolygon(starPolygon, Qt::WindingFill);
- } else if (mode == Editable) {
+ else if (mode == EditMode::Editable)
painter->drawPolygon(diamondPolygon, Qt::WindingFill);
- }
painter->translate(1.0, 0.0);
}
diff --git a/examples/widgets/itemviews/stardelegate/starrating.h b/examples/widgets/itemviews/stardelegate/starrating.h
index fa77311914..fc3028db58 100644
--- a/examples/widgets/itemviews/stardelegate/starrating.h
+++ b/examples/widgets/itemviews/stardelegate/starrating.h
@@ -51,15 +51,15 @@
#ifndef STARRATING_H
#define STARRATING_H
-#include <QMetaType>
-#include <QPointF>
-#include <QVector>
+#include <QPainter>
+#include <QPolygonF>
+#include <QSize>
//! [0]
class StarRating
{
public:
- enum EditMode { Editable, ReadOnly };
+ enum class EditMode { Editable, ReadOnly };
explicit StarRating(int starCount = 1, int maxStarCount = 5);
diff --git a/examples/widgets/itemviews/storageview/main.cpp b/examples/widgets/itemviews/storageview/main.cpp
index f349e58fad..8f23a4820a 100644
--- a/examples/widgets/itemviews/storageview/main.cpp
+++ b/examples/widgets/itemviews/storageview/main.cpp
@@ -49,10 +49,9 @@
**
****************************************************************************/
-#include <QtWidgets/QApplication>
-#include <QtWidgets/QHeaderView>
-#include <QtWidgets/QShortcut>
-#include <QtWidgets/QTreeView>
+#include <QApplication>
+#include <QShortcut>
+#include <QTreeView>
#include "storagemodel.h"
diff --git a/examples/widgets/itemviews/storageview/storagemodel.cpp b/examples/widgets/itemviews/storageview/storagemodel.cpp
index 063f126d86..b98fc8445c 100644
--- a/examples/widgets/itemviews/storageview/storagemodel.cpp
+++ b/examples/widgets/itemviews/storageview/storagemodel.cpp
@@ -53,14 +53,6 @@
#include <QDir>
#include <QLocale>
-#include <qmath.h>
-#include <algorithm>
-#include <cmath>
-
-StorageModel::StorageModel(QObject *parent) :
- QAbstractTableModel(parent)
-{
-}
void StorageModel::refresh()
{
diff --git a/examples/widgets/itemviews/storageview/storagemodel.h b/examples/widgets/itemviews/storageview/storagemodel.h
index 787b2f04de..597218c220 100644
--- a/examples/widgets/itemviews/storageview/storagemodel.h
+++ b/examples/widgets/itemviews/storageview/storagemodel.h
@@ -74,7 +74,7 @@ public:
ColumnCount
};
- explicit StorageModel(QObject *parent = nullptr);
+ using QAbstractTableModel::QAbstractTableModel;
int columnCount(const QModelIndex &parent) const override;
int rowCount(const QModelIndex &parent) const override;
diff --git a/examples/widgets/layouts/basiclayouts/dialog.cpp b/examples/widgets/layouts/basiclayouts/dialog.cpp
index 7acbc50eb7..8376820545 100644
--- a/examples/widgets/layouts/basiclayouts/dialog.cpp
+++ b/examples/widgets/layouts/basiclayouts/dialog.cpp
@@ -69,8 +69,8 @@ Dialog::Dialog()
buttonBox = new QDialogButtonBox(QDialogButtonBox::Ok
| QDialogButtonBox::Cancel);
- connect(buttonBox, SIGNAL(accepted()), this, SLOT(accept()));
- connect(buttonBox, SIGNAL(rejected()), this, SLOT(reject()));
+ connect(buttonBox, &QDialogButtonBox::accepted, this, &QDialog::accept);
+ connect(buttonBox, &QDialogButtonBox::rejected, this, &QDialog::reject);
//! [1]
//! [2]
@@ -99,7 +99,7 @@ void Dialog::createMenu()
exitAction = fileMenu->addAction(tr("E&xit"));
menuBar->addMenu(fileMenu);
- connect(exitAction, SIGNAL(triggered()), this, SLOT(accept()));
+ connect(exitAction, &QAction::triggered, this, &QDialog::accept);
}
//! [6]
diff --git a/examples/widgets/mainwindows/application/mainwindow.cpp b/examples/widgets/mainwindows/application/mainwindow.cpp
index dc93fe4eb2..4b639ead18 100644
--- a/examples/widgets/mainwindows/application/mainwindow.cpp
+++ b/examples/widgets/mainwindows/application/mainwindow.cpp
@@ -337,11 +337,11 @@ void MainWindow::loadFile(const QString &fileName)
QTextStream in(&file);
#ifndef QT_NO_CURSOR
- QApplication::setOverrideCursor(Qt::WaitCursor);
+ QGuiApplication::setOverrideCursor(Qt::WaitCursor);
#endif
textEdit->setPlainText(in.readAll());
#ifndef QT_NO_CURSOR
- QApplication::restoreOverrideCursor();
+ QGuiApplication::restoreOverrideCursor();
#endif
setCurrentFile(fileName);
@@ -364,11 +364,11 @@ bool MainWindow::saveFile(const QString &fileName)
QTextStream out(&file);
#ifndef QT_NO_CURSOR
- QApplication::setOverrideCursor(Qt::WaitCursor);
+ QGuiApplication::setOverrideCursor(Qt::WaitCursor);
#endif
out << textEdit->toPlainText();
#ifndef QT_NO_CURSOR
- QApplication::restoreOverrideCursor();
+ QGuiApplication::restoreOverrideCursor();
#endif
setCurrentFile(fileName);
diff --git a/examples/widgets/mainwindows/dockwidgets/mainwindow.cpp b/examples/widgets/mainwindows/dockwidgets/mainwindow.cpp
index 47a6e78265..a62765cdab 100644
--- a/examples/widgets/mainwindows/dockwidgets/mainwindow.cpp
+++ b/examples/widgets/mainwindows/dockwidgets/mainwindow.cpp
@@ -161,9 +161,9 @@ void MainWindow::save()
}
QTextStream out(&file);
- QApplication::setOverrideCursor(Qt::WaitCursor);
+ QGuiApplication::setOverrideCursor(Qt::WaitCursor);
out << textEdit->toHtml();
- QApplication::restoreOverrideCursor();
+ QGuiApplication::restoreOverrideCursor();
statusBar()->showMessage(tr("Saved '%1'").arg(fileName), 2000);
}
diff --git a/examples/widgets/mainwindows/mdi/mdichild.cpp b/examples/widgets/mainwindows/mdi/mdichild.cpp
index 006c84574a..16f2040de0 100644
--- a/examples/widgets/mainwindows/mdi/mdichild.cpp
+++ b/examples/widgets/mainwindows/mdi/mdichild.cpp
@@ -82,9 +82,9 @@ bool MdiChild::loadFile(const QString &fileName)
}
QTextStream in(&file);
- QApplication::setOverrideCursor(Qt::WaitCursor);
+ QGuiApplication::setOverrideCursor(Qt::WaitCursor);
setPlainText(in.readAll());
- QApplication::restoreOverrideCursor();
+ QGuiApplication::restoreOverrideCursor();
setCurrentFile(fileName);
@@ -124,9 +124,9 @@ bool MdiChild::saveFile(const QString &fileName)
}
QTextStream out(&file);
- QApplication::setOverrideCursor(Qt::WaitCursor);
+ QGuiApplication::setOverrideCursor(Qt::WaitCursor);
out << toPlainText();
- QApplication::restoreOverrideCursor();
+ QGuiApplication::restoreOverrideCursor();
setCurrentFile(fileName);
return true;
diff --git a/examples/widgets/mainwindows/sdi/mainwindow.cpp b/examples/widgets/mainwindows/sdi/mainwindow.cpp
index 301c85c144..d44f7c918d 100644
--- a/examples/widgets/mainwindows/sdi/mainwindow.cpp
+++ b/examples/widgets/mainwindows/sdi/mainwindow.cpp
@@ -338,9 +338,9 @@ void MainWindow::loadFile(const QString &fileName)
}
QTextStream in(&file);
- QApplication::setOverrideCursor(Qt::WaitCursor);
+ QGuiApplication::setOverrideCursor(Qt::WaitCursor);
textEdit->setPlainText(in.readAll());
- QApplication::restoreOverrideCursor();
+ QGuiApplication::restoreOverrideCursor();
setCurrentFile(fileName);
statusBar()->showMessage(tr("File loaded"), 2000);
@@ -434,9 +434,9 @@ bool MainWindow::saveFile(const QString &fileName)
}
QTextStream out(&file);
- QApplication::setOverrideCursor(Qt::WaitCursor);
+ QGuiApplication::setOverrideCursor(Qt::WaitCursor);
out << textEdit->toPlainText();
- QApplication::restoreOverrideCursor();
+ QGuiApplication::restoreOverrideCursor();
setCurrentFile(fileName);
statusBar()->showMessage(tr("File saved"), 2000);
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<int>::of(&QComboBox::activated),
+ this, &Window::shapeChanged);
+ connect(penWidthSpinBox, QOverload<int>::of(&QSpinBox::valueChanged),
+ this, &Window::penChanged);
+ connect(penStyleComboBox, QOverload<int>::of(&QComboBox::activated),
+ this, &Window::penChanged);
+ connect(penCapComboBox, QOverload<int>::of(&QComboBox::activated),
+ this, &Window::penChanged);
+ connect(penJoinComboBox, QOverload<int>::of(&QComboBox::activated),
+ this, &Window::penChanged);
+ connect(brushStyleComboBox, QOverload<int>::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<int>::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<RenderArea*>::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<int>::of(&QComboBox::activated),
+ this, &Window::fillRuleChanged);
+ connect(fillColor1ComboBox, QOverload<int>::of(&QComboBox::activated),
+ this, &Window::fillGradientChanged);
+ connect(fillColor2ComboBox, QOverload<int>::of(&QComboBox::activated),
+ this, &Window::fillGradientChanged);
+ connect(penColorComboBox, QOverload<int>::of(&QComboBox::activated),
+ this, &Window::penColorChanged);
+
+ for (RenderArea *area : qAsConst(renderAreas)) {
+ connect(penWidthSpinBox, QOverload<int>::of(&QSpinBox::valueChanged),
+ area, &RenderArea::setPenWidth);
+ connect(rotationAngleSpinBox, QOverload<int>::of(&QSpinBox::valueChanged),
+ area, &RenderArea::setRotationAngle);
}
//! [16] //! [17]
QGridLayout *topLayout = new QGridLayout;
- int i=0;
- for(QList<RenderArea*>::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<RenderArea*>::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<QColor>(currentItemData(fillColor1ComboBox));
QColor color2 = qvariant_cast<QColor>(currentItemData(fillColor2ComboBox));
- for (QList<RenderArea*>::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<QColor>(currentItemData(penColorComboBox));
- for (QList<RenderArea*>::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<int>::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<int>::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<int>::of(&QComboBox::activated),
+ this, &MainWindow::setMonth);
+ connect(yearEdit, &QDateTimeEdit::dateChanged,
+ this, &MainWindow::setYear);
+ connect(fontSizeSpinBox, QOverload<int>::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);
}
diff --git a/examples/widgets/statemachine/factorial/main.cpp b/examples/widgets/statemachine/factorial/main.cpp
index f100aa0110..2d25822828 100644
--- a/examples/widgets/statemachine/factorial/main.cpp
+++ b/examples/widgets/statemachine/factorial/main.cpp
@@ -100,7 +100,7 @@ class FactorialLoopTransition : public QSignalTransition
{
public:
FactorialLoopTransition(Factorial *fact)
- : QSignalTransition(fact, SIGNAL(xChanged(int))), m_fact(fact)
+ : QSignalTransition(fact, &Factorial::xChanged), m_fact(fact)
{}
bool eventTest(QEvent *e) override
@@ -130,7 +130,7 @@ class FactorialDoneTransition : public QSignalTransition
{
public:
FactorialDoneTransition(Factorial *fact)
- : QSignalTransition(fact, SIGNAL(xChanged(int))), m_fact(fact)
+ : QSignalTransition(fact, &Factorial::xChanged), m_fact(fact)
{}
bool eventTest(QEvent *e) override
diff --git a/examples/widgets/statemachine/rogue/window.cpp b/examples/widgets/statemachine/rogue/window.cpp
index 059fbf1003..f91a6e522e 100644
--- a/examples/widgets/statemachine/rogue/window.cpp
+++ b/examples/widgets/statemachine/rogue/window.cpp
@@ -217,7 +217,8 @@ void Window::buildMachine()
//![5]
machine->setInitialState(inputState);
- connect(machine, SIGNAL(finished()), qApp, SLOT(quit()));
+ connect(machine, &QStateMachine::finished,
+ qApp, &QApplication::quit);
machine->start();
}
diff --git a/examples/widgets/statemachine/trafficlight/main.cpp b/examples/widgets/statemachine/trafficlight/main.cpp
index 21df91d8b0..b348d4f65d 100644
--- a/examples/widgets/statemachine/trafficlight/main.cpp
+++ b/examples/widgets/statemachine/trafficlight/main.cpp
@@ -132,11 +132,11 @@ QState *createLightState(LightWidget *light, int duration, QState *parent = 0)
timer->setInterval(duration);
timer->setSingleShot(true);
QState *timing = new QState(lightState);
- QObject::connect(timing, SIGNAL(entered()), light, SLOT(turnOn()));
- QObject::connect(timing, SIGNAL(entered()), timer, SLOT(start()));
- QObject::connect(timing, SIGNAL(exited()), light, SLOT(turnOff()));
+ QObject::connect(timing, &QAbstractState::entered, light, &LightWidget::turnOn);
+ QObject::connect(timing, &QAbstractState::entered, timer, QOverload<>::of(&QTimer::start));
+ QObject::connect(timing, &QAbstractState::exited, light, &LightWidget::turnOff);
QFinalState *done = new QFinalState(lightState);
- timing->addTransition(timer, SIGNAL(timeout()), done);
+ timing->addTransition(timer, &QTimer::timeout, done);
lightState->setInitialState(timing);
return lightState;
}
@@ -159,14 +159,14 @@ public:
redGoingYellow->setObjectName("redGoingYellow");
QState *yellowGoingGreen = createLightState(widget->yellowLight(), 1000);
yellowGoingGreen->setObjectName("yellowGoingGreen");
- redGoingYellow->addTransition(redGoingYellow, SIGNAL(finished()), yellowGoingGreen);
+ redGoingYellow->addTransition(redGoingYellow, &QState::finished, yellowGoingGreen);
QState *greenGoingYellow = createLightState(widget->greenLight(), 3000);
greenGoingYellow->setObjectName("greenGoingYellow");
- yellowGoingGreen->addTransition(yellowGoingGreen, SIGNAL(finished()), greenGoingYellow);
+ yellowGoingGreen->addTransition(yellowGoingGreen, &QState::finished, greenGoingYellow);
QState *yellowGoingRed = createLightState(widget->yellowLight(), 1000);
yellowGoingRed->setObjectName("yellowGoingRed");
- greenGoingYellow->addTransition(greenGoingYellow, SIGNAL(finished()), yellowGoingRed);
- yellowGoingRed->addTransition(yellowGoingRed, SIGNAL(finished()), redGoingYellow);
+ greenGoingYellow->addTransition(greenGoingYellow, &QState::finished, yellowGoingRed);
+ yellowGoingRed->addTransition(yellowGoingRed, &QState::finished, redGoingYellow);
machine->addState(redGoingYellow);
machine->addState(yellowGoingGreen);
diff --git a/examples/widgets/statemachine/twowaybutton/main.cpp b/examples/widgets/statemachine/twowaybutton/main.cpp
index 5c778aba70..3d4fef3bbe 100644
--- a/examples/widgets/statemachine/twowaybutton/main.cpp
+++ b/examples/widgets/statemachine/twowaybutton/main.cpp
@@ -69,8 +69,8 @@ int main(int argc, char **argv)
//! [1]
//! [2]
- off->addTransition(&button, SIGNAL(clicked()), on);
- on->addTransition(&button, SIGNAL(clicked()), off);
+ off->addTransition(&button, &QAbstractButton::clicked, on);
+ on->addTransition(&button, &QAbstractButton::clicked, off);
//! [2]
//! [3]
diff --git a/examples/widgets/tools/codecs/mainwindow.cpp b/examples/widgets/tools/codecs/mainwindow.cpp
index 229c2ccfd4..53db9fe61f 100644
--- a/examples/widgets/tools/codecs/mainwindow.cpp
+++ b/examples/widgets/tools/codecs/mainwindow.cpp
@@ -127,11 +127,10 @@ void MainWindow::about()
void MainWindow::aboutToShowSaveAsMenu()
{
- QString currentText = textEdit->toPlainText();
-
- foreach (QAction *action, saveAsActs) {
- QByteArray codecName = action->data().toByteArray();
- QTextCodec *codec = QTextCodec::codecForName(codecName);
+ const QString currentText = textEdit->toPlainText();
+ for (QAction *action : qAsConst(saveAsActs)) {
+ const QByteArray codecName = action->data().toByteArray();
+ const QTextCodec *codec = QTextCodec::codecForName(codecName);
action->setVisible(codec && codec->canEncode(currentText));
}
}
@@ -142,7 +141,8 @@ void MainWindow::findCodecs()
QRegularExpression iso8859RegExp("^ISO[- ]8859-([0-9]+).*$");
QRegularExpressionMatch match;
- foreach (int mib, QTextCodec::availableMibs()) {
+ const QList<int> mibs = QTextCodec::availableMibs();
+ for (int mib : mibs) {
QTextCodec *codec = QTextCodec::codecForMib(mib);
QString sortKey = codec->name().toUpper();
@@ -177,7 +177,7 @@ void MainWindow::createMenus()
QMenu *saveAsMenu = fileMenu->addMenu(tr("&Save As"));
connect(saveAsMenu, &QMenu::aboutToShow,
this, &MainWindow::aboutToShowSaveAsMenu);
- foreach (const QTextCodec *codec, codecs) {
+ for (const QTextCodec *codec : qAsConst(codecs)) {
const QByteArray name = codec->name();
QAction *action = saveAsMenu->addAction(tr("%1...").arg(QLatin1String(name)));
action->setData(QVariant(name));
diff --git a/examples/widgets/tools/codecs/previewform.cpp b/examples/widgets/tools/codecs/previewform.cpp
index d19b9c0833..206b5757cd 100644
--- a/examples/widgets/tools/codecs/previewform.cpp
+++ b/examples/widgets/tools/codecs/previewform.cpp
@@ -182,7 +182,7 @@ PreviewForm::PreviewForm(QWidget *parent)
void PreviewForm::setCodecList(const QList<QTextCodec *> &list)
{
encodingComboBox->clear();
- foreach (const QTextCodec *codec, list) {
+ for (const QTextCodec *codec : list) {
encodingComboBox->addItem(QLatin1String(codec->name()),
QVariant(codec->mibEnum()));
}
diff --git a/examples/widgets/tools/completer/mainwindow.cpp b/examples/widgets/tools/completer/mainwindow.cpp
index d63d523548..114ff0fd7c 100644
--- a/examples/widgets/tools/completer/mainwindow.cpp
+++ b/examples/widgets/tools/completer/mainwindow.cpp
@@ -102,10 +102,14 @@ MainWindow::MainWindow(QWidget *parent)
contentsLabel = new QLabel;
contentsLabel->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed);
- connect(modelCombo, SIGNAL(activated(int)), this, SLOT(changeModel()));
- connect(modeCombo, SIGNAL(activated(int)), this, SLOT(changeMode(int)));
- connect(caseCombo, SIGNAL(activated(int)), this, SLOT(changeCase(int)));
- connect(maxVisibleSpinBox, SIGNAL(valueChanged(int)), this, SLOT(changeMaxVisible(int)));
+ connect(modelCombo, QOverload<int>::of(&QComboBox::activated),
+ this, &MainWindow::changeModel);
+ connect(modeCombo, QOverload<int>::of(&QComboBox::activated),
+ this, &MainWindow::changeMode);
+ connect(caseCombo, QOverload<int>::of(&QComboBox::activated),
+ this, &MainWindow::changeCase);
+ connect(maxVisibleSpinBox, QOverload<int>::of(&QSpinBox::valueChanged),
+ this, &MainWindow::changeMaxVisible);
//! [2]
//! [3]
@@ -136,9 +140,9 @@ void MainWindow::createMenu()
QAction *aboutAct = new QAction(tr("About"), this);
QAction *aboutQtAct = new QAction(tr("About Qt"), this);
- connect(exitAction, SIGNAL(triggered()), qApp, SLOT(quit()));
- connect(aboutAct, SIGNAL(triggered()), this, SLOT(about()));
- connect(aboutQtAct, SIGNAL(triggered()), qApp, SLOT(aboutQt()));
+ connect(exitAction, &QAction::triggered, qApp, &QApplication::quit);
+ connect(aboutAct, &QAction::triggered, this, &MainWindow::about);
+ connect(aboutQtAct, &QAction::triggered, qApp, &QApplication::aboutQt);
QMenu* fileMenu = menuBar()->addMenu(tr("File"));
fileMenu->addAction(exitAction);
@@ -159,7 +163,7 @@ QAbstractItemModel *MainWindow::modelFromFile(const QString& fileName)
//! [6]
#ifndef QT_NO_CURSOR
- QApplication::setOverrideCursor(QCursor(Qt::WaitCursor));
+ QGuiApplication::setOverrideCursor(QCursor(Qt::WaitCursor));
#endif
QStringList words;
@@ -170,7 +174,7 @@ QAbstractItemModel *MainWindow::modelFromFile(const QString& fileName)
}
#ifndef QT_NO_CURSOR
- QApplication::restoreOverrideCursor();
+ QGuiApplication::restoreOverrideCursor();
#endif
//! [6]
@@ -271,7 +275,7 @@ void MainWindow::changeModel()
changeCase(caseCombo->currentIndex());
completer->setWrapAround(wrapCheckBox->isChecked());
lineEdit->setCompleter(completer);
- connect(wrapCheckBox, SIGNAL(clicked(bool)), completer, SLOT(setWrapAround(bool)));
+ connect(wrapCheckBox, &QAbstractButton::clicked, completer, &QCompleter::setWrapAround);
}
//! [14]
diff --git a/examples/widgets/tools/customcompleter/mainwindow.cpp b/examples/widgets/tools/customcompleter/mainwindow.cpp
index 26948d0c8e..39f5f39617 100644
--- a/examples/widgets/tools/customcompleter/mainwindow.cpp
+++ b/examples/widgets/tools/customcompleter/mainwindow.cpp
@@ -79,9 +79,9 @@ void MainWindow::createMenu()
QAction *aboutAct = new QAction(tr("About"), this);
QAction *aboutQtAct = new QAction(tr("About Qt"), this);
- connect(exitAction, SIGNAL(triggered()), qApp, SLOT(quit()));
- connect(aboutAct, SIGNAL(triggered()), this, SLOT(about()));
- connect(aboutQtAct, SIGNAL(triggered()), qApp, SLOT(aboutQt()));
+ connect(exitAction, &QAction::triggered, qApp, &QApplication::quit);
+ connect(aboutAct, &QAction::triggered, this, &MainWindow::about);
+ connect(aboutQtAct, &QAction::triggered, qApp, &QApplication::aboutQt);
QMenu* fileMenu = menuBar()->addMenu(tr("File"));
fileMenu->addAction(exitAction);
@@ -100,7 +100,7 @@ QAbstractItemModel *MainWindow::modelFromFile(const QString& fileName)
return new QStringListModel(completer);
#ifndef QT_NO_CURSOR
- QApplication::setOverrideCursor(QCursor(Qt::WaitCursor));
+ QGuiApplication::setOverrideCursor(QCursor(Qt::WaitCursor));
#endif
QStringList words;
@@ -111,7 +111,7 @@ QAbstractItemModel *MainWindow::modelFromFile(const QString& fileName)
}
#ifndef QT_NO_CURSOR
- QApplication::restoreOverrideCursor();
+ QGuiApplication::restoreOverrideCursor();
#endif
return new QStringListModel(words, completer);
}
diff --git a/examples/widgets/tools/customcompleter/textedit.cpp b/examples/widgets/tools/customcompleter/textedit.cpp
index 5512e72843..d42f7b38bb 100644
--- a/examples/widgets/tools/customcompleter/textedit.cpp
+++ b/examples/widgets/tools/customcompleter/textedit.cpp
@@ -88,8 +88,8 @@ void TextEdit::setCompleter(QCompleter *completer)
c->setWidget(this);
c->setCompletionMode(QCompleter::PopupCompletion);
c->setCaseSensitivity(Qt::CaseInsensitive);
- QObject::connect(c, SIGNAL(activated(QString)),
- this, SLOT(insertCompletion(QString)));
+ QObject::connect(c, QOverload<const QString &>::of(&QCompleter::activated),
+ this, &TextEdit::insertCompletion);
}
//! [2]
diff --git a/examples/widgets/tools/echoplugin/echowindow/echowindow.cpp b/examples/widgets/tools/echoplugin/echowindow/echowindow.cpp
index 64b59d506e..6886a4cd88 100644
--- a/examples/widgets/tools/echoplugin/echowindow/echowindow.cpp
+++ b/examples/widgets/tools/echoplugin/echowindow/echowindow.cpp
@@ -113,7 +113,8 @@ bool EchoWindow::loadPlugin()
}
#endif
pluginsDir.cd("plugins");
- foreach (QString fileName, pluginsDir.entryList(QDir::Files)) {
+ const QStringList entries = pluginsDir.entryList(QDir::Files);
+ for (const QString &fileName : entries) {
QPluginLoader pluginLoader(pluginsDir.absoluteFilePath(fileName));
QObject *plugin = pluginLoader.instance();
if (plugin) {
diff --git a/examples/widgets/tools/i18n/languagechooser.cpp b/examples/widgets/tools/i18n/languagechooser.cpp
index 58cf9d4047..f07d0ddee3 100644
--- a/examples/widgets/tools/i18n/languagechooser.cpp
+++ b/examples/widgets/tools/i18n/languagechooser.cpp
@@ -148,14 +148,14 @@ void LanguageChooser::checkBoxToggled()
void LanguageChooser::showAll()
{
- foreach (QCheckBox *checkBox, qmFileForCheckBoxMap.keys())
- checkBox->setChecked(true);
+ for (auto it = qmFileForCheckBoxMap.keyBegin(); it != qmFileForCheckBoxMap.keyEnd(); ++it)
+ (*it)->setChecked(true);
}
void LanguageChooser::hideAll()
{
- foreach (QCheckBox *checkBox, qmFileForCheckBoxMap.keys())
- checkBox->setChecked(false);
+ for (auto it = qmFileForCheckBoxMap.keyBegin(); it != qmFileForCheckBoxMap.keyEnd(); ++it)
+ (*it)->setChecked(false);
}
QStringList LanguageChooser::findQmFiles()
diff --git a/examples/widgets/tools/regexp/regexpdialog.cpp b/examples/widgets/tools/regexp/regexpdialog.cpp
index 7b3fee5794..bf61d09974 100644
--- a/examples/widgets/tools/regexp/regexpdialog.cpp
+++ b/examples/widgets/tools/regexp/regexpdialog.cpp
@@ -135,15 +135,15 @@ RegExpDialog::RegExpDialog(QWidget *parent)
}
setLayout(mainLayout);
- connect(patternComboBox, SIGNAL(editTextChanged(QString)),
- this, SLOT(refresh()));
- connect(textComboBox, SIGNAL(editTextChanged(QString)),
- this, SLOT(refresh()));
- connect(caseSensitiveCheckBox, SIGNAL(toggled(bool)),
- this, SLOT(refresh()));
- connect(minimalCheckBox, SIGNAL(toggled(bool)), this, SLOT(refresh()));
- connect(syntaxComboBox, SIGNAL(currentIndexChanged(int)),
- this, SLOT(refresh()));
+ connect(patternComboBox, &QComboBox::editTextChanged,
+ this, &RegExpDialog::refresh);
+ connect(textComboBox, &QComboBox::editTextChanged,
+ this, &RegExpDialog::refresh);
+ connect(caseSensitiveCheckBox, &QAbstractButton::toggled,
+ this, &RegExpDialog::refresh);
+ connect(minimalCheckBox, &QAbstractButton::toggled, this, &RegExpDialog::refresh);
+ connect(syntaxComboBox, QOverload<int>::of(&QComboBox::currentIndexChanged),
+ this, &RegExpDialog::refresh);
patternComboBox->addItem(tr("[A-Za-z_]+([A-Za-z_0-9]*)"));
textComboBox->addItem(tr("(10 + delta4) * 32"));
diff --git a/examples/widgets/tools/settingseditor/settingstree.cpp b/examples/widgets/tools/settingseditor/settingstree.cpp
index 4ca843784e..8585792787 100644
--- a/examples/widgets/tools/settingseditor/settingstree.cpp
+++ b/examples/widgets/tools/settingseditor/settingstree.cpp
@@ -170,7 +170,8 @@ void SettingsTree::updateChildItems(QTreeWidgetItem *parent)
{
int dividerIndex = 0;
- foreach (QString group, settings->childGroups()) {
+ const QStringList childGroups = settings->childGroups();
+ for (const QString &group : childGroups) {
QTreeWidgetItem *child;
int childIndex = findChild(parent, group, dividerIndex);
if (childIndex != -1) {
@@ -190,7 +191,8 @@ void SettingsTree::updateChildItems(QTreeWidgetItem *parent)
settings->endGroup();
}
- foreach (const QString &key, settings->childKeys()) {
+ const QStringList childKeys = settings->childKeys();
+ for (const QString &key : childKeys) {
QTreeWidgetItem *child;
int childIndex = findChild(parent, key, 0);
diff --git a/examples/widgets/tools/treemodelcompleter/mainwindow.cpp b/examples/widgets/tools/treemodelcompleter/mainwindow.cpp
index a8b51c7aa0..dec3cb0496 100644
--- a/examples/widgets/tools/treemodelcompleter/mainwindow.cpp
+++ b/examples/widgets/tools/treemodelcompleter/mainwindow.cpp
@@ -61,8 +61,8 @@ MainWindow::MainWindow(QWidget *parent)
completer = new TreeModelCompleter(this);
completer->setModel(modelFromFile(":/resources/treemodel.txt"));
completer->setSeparator(QLatin1String("."));
- QObject::connect(completer, SIGNAL(highlighted(QModelIndex)),
- this, SLOT(highlight(QModelIndex)));
+ QObject::connect(completer, QOverload<const QModelIndex &>::of(&TreeModelCompleter::highlighted),
+ this, &MainWindow::highlight);
QWidget *centralWidget = new QWidget;
@@ -91,18 +91,18 @@ MainWindow::MainWindow(QWidget *parent)
QLineEdit *separatorLineEdit = new QLineEdit;
separatorLineEdit->setText(completer->separator());
- connect(separatorLineEdit, SIGNAL(textChanged(QString)),
- completer, SLOT(setSeparator(QString)));
+ connect(separatorLineEdit, &QLineEdit::textChanged,
+ completer, &TreeModelCompleter::setSeparator);
QCheckBox *wrapCheckBox = new QCheckBox;
wrapCheckBox->setText(tr("Wrap around completions"));
wrapCheckBox->setChecked(completer->wrapAround());
- connect(wrapCheckBox, SIGNAL(clicked(bool)), completer, SLOT(setWrapAround(bool)));
+ connect(wrapCheckBox, &QAbstractButton::clicked, completer, &QCompleter::setWrapAround);
contentsLabel = new QLabel;
contentsLabel->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed);
- connect(separatorLineEdit, SIGNAL(textChanged(QString)),
- this, SLOT(updateContentsLabel(QString)));
+ connect(separatorLineEdit, &QLineEdit::textChanged,
+ this, &MainWindow::updateContentsLabel);
treeView = new QTreeView;
treeView->setModel(completer->model());
@@ -111,8 +111,10 @@ MainWindow::MainWindow(QWidget *parent)
//! [1]
//! [2]
- connect(modeCombo, SIGNAL(activated(int)), this, SLOT(changeMode(int)));
- connect(caseCombo, SIGNAL(activated(int)), this, SLOT(changeCase(int)));
+ connect(modeCombo, QOverload<int>::of(&QComboBox::activated),
+ this, &MainWindow::changeMode);
+ connect(caseCombo, QOverload<int>::of(&QComboBox::activated),
+ this, &MainWindow::changeMode);
lineEdit = new QLineEdit;
lineEdit->setCompleter(completer);
@@ -145,9 +147,9 @@ void MainWindow::createMenu()
QAction *aboutAct = new QAction(tr("About"), this);
QAction *aboutQtAct = new QAction(tr("About Qt"), this);
- connect(exitAction, SIGNAL(triggered()), qApp, SLOT(quit()));
- connect(aboutAct, SIGNAL(triggered()), this, SLOT(about()));
- connect(aboutQtAct, SIGNAL(triggered()), qApp, SLOT(aboutQt()));
+ connect(exitAction, &QAction::triggered, qApp, &QApplication::quit);
+ connect(aboutAct, &QAction::triggered, this, &MainWindow::about);
+ connect(aboutQtAct, &QAction::triggered, qApp, &QApplication::aboutQt);
QMenu* fileMenu = menuBar()->addMenu(tr("File"));
fileMenu->addAction(exitAction);
@@ -180,7 +182,7 @@ QAbstractItemModel *MainWindow::modelFromFile(const QString& fileName)
return new QStringListModel(completer);
#ifndef QT_NO_CURSOR
- QApplication::setOverrideCursor(QCursor(Qt::WaitCursor));
+ QGuiApplication::setOverrideCursor(QCursor(Qt::WaitCursor));
#endif
QStringList words;
@@ -218,7 +220,7 @@ QAbstractItemModel *MainWindow::modelFromFile(const QString& fileName)
}
#ifndef QT_NO_CURSOR
- QApplication::restoreOverrideCursor();
+ QGuiApplication::restoreOverrideCursor();
#endif
return model;
diff --git a/examples/widgets/tools/undo/mainwindow.cpp b/examples/widgets/tools/undo/mainwindow.cpp
index 5976163f3f..118d604742 100644
--- a/examples/widgets/tools/undo/mainwindow.cpp
+++ b/examples/widgets/tools/undo/mainwindow.cpp
@@ -68,25 +68,25 @@ MainWindow::MainWindow(QWidget *parent)
documentTabs->removeTab(0);
delete w;
- connect(actionOpen, SIGNAL(triggered()), this, SLOT(openDocument()));
- connect(actionClose, SIGNAL(triggered()), this, SLOT(closeDocument()));
- connect(actionNew, SIGNAL(triggered()), this, SLOT(newDocument()));
- connect(actionSave, SIGNAL(triggered()), this, SLOT(saveDocument()));
- connect(actionExit, SIGNAL(triggered()), this, SLOT(close()));
- connect(actionRed, SIGNAL(triggered()), this, SLOT(setShapeColor()));
- connect(actionGreen, SIGNAL(triggered()), this, SLOT(setShapeColor()));
- connect(actionBlue, SIGNAL(triggered()), this, SLOT(setShapeColor()));
- connect(actionAddCircle, SIGNAL(triggered()), this, SLOT(addShape()));
- connect(actionAddRectangle, SIGNAL(triggered()), this, SLOT(addShape()));
- connect(actionAddTriangle, SIGNAL(triggered()), this, SLOT(addShape()));
- connect(actionRemoveShape, SIGNAL(triggered()), this, SLOT(removeShape()));
- connect(actionAddRobot, SIGNAL(triggered()), this, SLOT(addRobot()));
- connect(actionAddSnowman, SIGNAL(triggered()), this, SLOT(addSnowman()));
- connect(actionAbout, SIGNAL(triggered()), this, SLOT(about()));
- connect(actionAboutQt, SIGNAL(triggered()), this, SLOT(aboutQt()));
-
- connect(undoLimit, SIGNAL(valueChanged(int)), this, SLOT(updateActions()));
- connect(documentTabs, SIGNAL(currentChanged(int)), this, SLOT(updateActions()));
+ connect(actionOpen, &QAction::triggered, this, &MainWindow::openDocument);
+ connect(actionClose, &QAction::triggered, this, &MainWindow::closeDocument);
+ connect(actionNew, &QAction::triggered, this, &MainWindow::newDocument);
+ connect(actionSave, &QAction::triggered, this, &MainWindow::saveDocument);
+ connect(actionExit, &QAction::triggered, this, &QWidget::close);
+ connect(actionRed, &QAction::triggered, this, &MainWindow::setShapeColor);
+ connect(actionGreen, &QAction::triggered, this, &MainWindow::setShapeColor);
+ connect(actionBlue, &QAction::triggered, this, &MainWindow::setShapeColor);
+ connect(actionAddCircle, &QAction::triggered, this, &MainWindow::addShape);
+ connect(actionAddRectangle, &QAction::triggered, this, &MainWindow::addShape);
+ connect(actionAddTriangle, &QAction::triggered, this, &MainWindow::addShape);
+ connect(actionRemoveShape, &QAction::triggered, this, &MainWindow::removeShape);
+ connect(actionAddRobot, &QAction::triggered, this, &MainWindow::addRobot);
+ connect(actionAddSnowman, &QAction::triggered, this, &MainWindow::addSnowman);
+ connect(actionAbout, &QAction::triggered, this, &MainWindow::about);
+ connect(actionAboutQt, &QAction::triggered, this, &MainWindow::aboutQt);
+
+ connect(undoLimit, QOverload<int>::of(&QSpinBox::valueChanged), this, &MainWindow::updateActions);
+ connect(documentTabs, &QTabWidget::currentChanged, this, &MainWindow::updateActions);
actionOpen->setShortcut(QString("Ctrl+O"));
actionClose->setShortcut(QString("Ctrl+W"));
@@ -226,9 +226,9 @@ void MainWindow::addDocument(Document *doc)
return;
m_undoGroup->addStack(doc->undoStack());
documentTabs->addTab(doc, fixedWindowTitle(doc));
- connect(doc, SIGNAL(currentShapeChanged(QString)), this, SLOT(updateActions()));
- connect(doc->undoStack(), SIGNAL(indexChanged(int)), this, SLOT(updateActions()));
- connect(doc->undoStack(), SIGNAL(cleanChanged(bool)), this, SLOT(updateActions()));
+ connect(doc, &Document::currentShapeChanged, this, &MainWindow::updateActions);
+ connect(doc->undoStack(), &QUndoStack::indexChanged, this, &MainWindow::updateActions);
+ connect(doc->undoStack(), &QUndoStack::cleanChanged, this, &MainWindow::updateActions);
setCurrentDocument(doc);
}
@@ -251,9 +251,9 @@ void MainWindow::removeDocument(Document *doc)
documentTabs->removeTab(index);
m_undoGroup->removeStack(doc->undoStack());
- disconnect(doc, SIGNAL(currentShapeChanged(QString)), this, SLOT(updateActions()));
- disconnect(doc->undoStack(), SIGNAL(indexChanged(int)), this, SLOT(updateActions()));
- disconnect(doc->undoStack(), SIGNAL(cleanChanged(bool)), this, SLOT(updateActions()));
+ disconnect(doc, &Document::currentShapeChanged, this, &MainWindow::updateActions);
+ disconnect(doc->undoStack(), &QUndoStack::indexChanged, this, &MainWindow::updateActions);
+ disconnect(doc->undoStack(), &QUndoStack::cleanChanged, this, &MainWindow::updateActions);
if (documentTabs->count() == 0) {
newDocument();
diff --git a/examples/widgets/tools/undoframework/mainwindow.cpp b/examples/widgets/tools/undoframework/mainwindow.cpp
index b2f5405b73..e95d50d164 100644
--- a/examples/widgets/tools/undoframework/mainwindow.cpp
+++ b/examples/widgets/tools/undoframework/mainwindow.cpp
@@ -70,8 +70,8 @@ MainWindow::MainWindow()
diagramScene->setBackgroundBrush(pixmapBrush);
diagramScene->setSceneRect(QRect(0, 0, 500, 500));
- connect(diagramScene, SIGNAL(itemMoved(DiagramItem*,QPointF)),
- this, SLOT(itemMoved(DiagramItem*,QPointF)));
+ connect(diagramScene, &DiagramScene::itemMoved,
+ this, &MainWindow::itemMoved);
setWindowTitle("Undo Framework");
QGraphicsView *view = new QGraphicsView(diagramScene);
@@ -95,18 +95,18 @@ void MainWindow::createActions()
{
deleteAction = new QAction(tr("&Delete Item"), this);
deleteAction->setShortcut(tr("Del"));
- connect(deleteAction, SIGNAL(triggered()), this, SLOT(deleteItem()));
+ connect(deleteAction, &QAction::triggered, this, &MainWindow::deleteItem);
//! [2] //! [3]
//! [3] //! [4]
addBoxAction = new QAction(tr("Add &Box"), this);
//! [4]
addBoxAction->setShortcut(tr("Ctrl+O"));
- connect(addBoxAction, SIGNAL(triggered()), this, SLOT(addBox()));
+ connect(addBoxAction, &QAction::triggered, this, &MainWindow::addBox);
addTriangleAction = new QAction(tr("Add &Triangle"), this);
addTriangleAction->setShortcut(tr("Ctrl+T"));
- connect(addTriangleAction, SIGNAL(triggered()), this, SLOT(addTriangle()));
+ connect(addTriangleAction, &QAction::triggered, this, &MainWindow::addTriangle);
//! [5]
undoAction = undoStack->createUndoAction(this, tr("&Undo"));
@@ -118,13 +118,13 @@ void MainWindow::createActions()
exitAction = new QAction(tr("E&xit"), this);
exitAction->setShortcuts(QKeySequence::Quit);
- connect(exitAction, SIGNAL(triggered()), this, SLOT(close()));
+ connect(exitAction, &QAction::triggered, this, &QWidget::close);
aboutAction = new QAction(tr("&About"), this);
QList<QKeySequence> aboutShortcuts;
aboutShortcuts << tr("Ctrl+A") << tr("Ctrl+B");
aboutAction->setShortcuts(aboutShortcuts);
- connect(aboutAction, SIGNAL(triggered()), this, SLOT(about()));
+ connect(aboutAction, &QAction::triggered, this, &MainWindow::about);
}
//! [6]
@@ -140,10 +140,10 @@ void MainWindow::createMenus()
editMenu->addAction(redoAction);
editMenu->addSeparator();
editMenu->addAction(deleteAction);
- connect(editMenu, SIGNAL(aboutToShow()),
- this, SLOT(itemMenuAboutToShow()));
- connect(editMenu, SIGNAL(aboutToHide()),
- this, SLOT(itemMenuAboutToHide()));
+ connect(editMenu, &QMenu::aboutToShow,
+ this, &MainWindow::itemMenuAboutToShow);
+ connect(editMenu, &QMenu::aboutToHide,
+ this, &MainWindow::itemMenuAboutToHide);
//! [7]
itemMenu = menuBar()->addMenu(tr("&Item"));
diff --git a/examples/widgets/touch/dials/main.cpp b/examples/widgets/touch/dials/main.cpp
index 071f485de3..059dfdc716 100644
--- a/examples/widgets/touch/dials/main.cpp
+++ b/examples/widgets/touch/dials/main.cpp
@@ -60,8 +60,8 @@ int main(int argc, char **argv)
QWidget window;
Ui::Dials dialsUi;
dialsUi.setupUi(&window);
- QList<QAbstractSlider *> sliders = window.findChildren<QAbstractSlider *>();
- foreach (QAbstractSlider *slider, sliders)
+ const QList<QAbstractSlider *> sliders = window.findChildren<QAbstractSlider *>();
+ for (QAbstractSlider *slider : sliders)
slider->setAttribute(Qt::WA_AcceptTouchEvents);
window.showMaximized();
return app.exec();
diff --git a/examples/widgets/touch/fingerpaint/mainwindow.cpp b/examples/widgets/touch/fingerpaint/mainwindow.cpp
index 0e45eea240..2f7ec38d1a 100644
--- a/examples/widgets/touch/fingerpaint/mainwindow.cpp
+++ b/examples/widgets/touch/fingerpaint/mainwindow.cpp
@@ -127,34 +127,35 @@ void MainWindow::createActions()
{
openAct = new QAction(tr("&Open..."), this);
openAct->setShortcut(tr("Ctrl+O"));
- connect(openAct, SIGNAL(triggered()), this, SLOT(open()));
+ connect(openAct, &QAction::triggered, this, &MainWindow::open);
- foreach (QByteArray format, QImageWriter::supportedImageFormats()) {
+ const QList<QByteArray> imageFormats = QImageWriter::supportedImageFormats();
+ for (const QByteArray &format : imageFormats) {
QString text = tr("%1...").arg(QString(format).toUpper());
QAction *action = new QAction(text, this);
action->setData(format);
- connect(action, SIGNAL(triggered()), this, SLOT(save()));
+ connect(action, &QAction::triggered, this, &MainWindow::save);
saveAsActs.append(action);
}
printAct = new QAction(tr("&Print..."), this);
- connect(printAct, SIGNAL(triggered()), scribbleArea, SLOT(print()));
+ connect(printAct, &QAction::triggered, scribbleArea, &ScribbleArea::print);
exitAct = new QAction(tr("E&xit"), this);
exitAct->setShortcut(tr("Ctrl+Q"));
- connect(exitAct, SIGNAL(triggered()), this, SLOT(close()));
+ connect(exitAct, &QAction::triggered, this, &QWidget::close);
clearScreenAct = new QAction(tr("&Clear Screen"), this);
clearScreenAct->setShortcut(tr("Ctrl+L"));
- connect(clearScreenAct, SIGNAL(triggered()),
- scribbleArea, SLOT(clearImage()));
+ connect(clearScreenAct, &QAction::triggered,
+ scribbleArea, &ScribbleArea::clearImage);
aboutAct = new QAction(tr("&About"), this);
- connect(aboutAct, SIGNAL(triggered()), this, SLOT(about()));
+ connect(aboutAct, &QAction::triggered, this, &MainWindow::about);
aboutQtAct = new QAction(tr("About &Qt"), this);
- connect(aboutQtAct, SIGNAL(triggered()), qApp, SLOT(aboutQt()));
+ connect(aboutQtAct, &QAction::triggered, qApp, &QApplication::aboutQt);
}
//! [14]
@@ -163,8 +164,7 @@ void MainWindow::createMenus()
//! [15] //! [16]
{
saveAsMenu = new QMenu(tr("&Save As"), this);
- foreach (QAction *action, saveAsActs)
- saveAsMenu->addAction(action);
+ saveAsMenu->addActions(saveAsActs);
fileMenu = new QMenu(tr("&File"), this);
fileMenu->addAction(openAct);
diff --git a/examples/widgets/touch/fingerpaint/scribblearea.cpp b/examples/widgets/touch/fingerpaint/scribblearea.cpp
index aa4e60c934..0b0c4476d9 100644
--- a/examples/widgets/touch/fingerpaint/scribblearea.cpp
+++ b/examples/widgets/touch/fingerpaint/scribblearea.cpp
@@ -195,9 +195,9 @@ bool ScribbleArea::event(QEvent *event)
case QEvent::TouchUpdate:
case QEvent::TouchEnd:
{
- QTouchEvent *touch = static_cast<QTouchEvent *>(event);
- QList<QTouchEvent::TouchPoint> touchPoints = static_cast<QTouchEvent *>(event)->touchPoints();
- foreach (const QTouchEvent::TouchPoint &touchPoint, touchPoints) {
+ const QTouchEvent *touch = static_cast<QTouchEvent *>(event);
+ const QList<QTouchEvent::TouchPoint> touchPoints = static_cast<QTouchEvent *>(event)->touchPoints();
+ for (const QTouchEvent::TouchPoint &touchPoint : touchPoints) {
switch (touchPoint.state()) {
case Qt::TouchPointStationary:
case Qt::TouchPointReleased:
diff --git a/examples/widgets/touch/pinchzoom/mouse.cpp b/examples/widgets/touch/pinchzoom/mouse.cpp
index 1e6814be13..1dfd7d749c 100644
--- a/examples/widgets/touch/pinchzoom/mouse.cpp
+++ b/examples/widgets/touch/pinchzoom/mouse.cpp
@@ -163,7 +163,7 @@ void Mouse::timerEvent(QTimerEvent *)
<< mapToScene(0, 0)
<< mapToScene(-30, -50)
<< mapToScene(30, -50));
- foreach (QGraphicsItem *item, dangerMice) {
+ for (QGraphicsItem *item : dangerMice) {
if (item == this)
continue;
diff --git a/examples/widgets/tutorials/addressbook/part2/addressbook.cpp b/examples/widgets/tutorials/addressbook/part2/addressbook.cpp
index 34fa5d2060..d5ee394abd 100644
--- a/examples/widgets/tutorials/addressbook/part2/addressbook.cpp
+++ b/examples/widgets/tutorials/addressbook/part2/addressbook.cpp
@@ -74,9 +74,12 @@ AddressBook::AddressBook(QWidget *parent)
cancelButton->hide();
//! [pushbutton declaration]
//! [connecting signals and slots]
- connect(addButton, SIGNAL(clicked()), this, SLOT(addContact()));
- connect(submitButton, SIGNAL(clicked()), this, SLOT(submitContact()));
- connect(cancelButton, SIGNAL(clicked()), this, SLOT(cancel()));
+ connect(addButton, &QPushButton::clicked,
+ this, &AddressBook::addContact);
+ connect(submitButton, &QPushButton::clicked,
+ this, &AddressBook::submitContact);
+ connect(cancelButton, &QPushButton::clicked,
+ this, &AddressBook::cancel);
//! [connecting signals and slots]
//! [vertical layout]
QVBoxLayout *buttonLayout1 = new QVBoxLayout;
diff --git a/examples/widgets/tutorials/addressbook/part3/addressbook.cpp b/examples/widgets/tutorials/addressbook/part3/addressbook.cpp
index caef83970a..b6d48f7a0d 100644
--- a/examples/widgets/tutorials/addressbook/part3/addressbook.cpp
+++ b/examples/widgets/tutorials/addressbook/part3/addressbook.cpp
@@ -74,13 +74,17 @@ AddressBook::AddressBook(QWidget *parent)
previousButton = new QPushButton(tr("&Previous"));
previousButton->setEnabled(false);
//! [navigation pushbuttons]
-
- connect(addButton, SIGNAL(clicked()), this, SLOT(addContact()));
- connect(submitButton, SIGNAL(clicked()), this, SLOT(submitContact()));
- connect(cancelButton, SIGNAL(clicked()), this, SLOT(cancel()));
+ connect(addButton, &QPushButton::clicked,
+ this, &AddressBook::addContact);
+ connect(submitButton, &QPushButton::clicked,
+ this, &AddressBook::submitContact);
+ connect(cancelButton, &QPushButton::clicked,
+ this, &AddressBook::cancel);
//! [connecting navigation signals]
- connect(nextButton, SIGNAL(clicked()), this, SLOT(next()));
- connect(previousButton, SIGNAL(clicked()), this, SLOT(previous()));
+ connect(nextButton, &QPushButton::clicked,
+ this, &AddressBook::next);
+ connect(previousButton, &QPushButton::clicked,
+ this, &AddressBook::previous);
//! [connecting navigation signals]
QVBoxLayout *buttonLayout1 = new QVBoxLayout;
diff --git a/examples/widgets/tutorials/addressbook/part4/addressbook.cpp b/examples/widgets/tutorials/addressbook/part4/addressbook.cpp
index 92f0776727..77ce216c07 100644
--- a/examples/widgets/tutorials/addressbook/part4/addressbook.cpp
+++ b/examples/widgets/tutorials/addressbook/part4/addressbook.cpp
@@ -79,15 +79,22 @@ AddressBook::AddressBook(QWidget *parent)
previousButton = new QPushButton(tr("&Previous"));
previousButton->setEnabled(false);
- connect(addButton, SIGNAL(clicked()), this, SLOT(addContact()));
- connect(submitButton, SIGNAL(clicked()), this, SLOT(submitContact()));
+ connect(addButton, &QPushButton::clicked,
+ this, &AddressBook::addContact);
+ connect(submitButton, &QPushButton::clicked,
+ this, &AddressBook::submitContact);
//! [connecting edit and remove]
- connect(editButton, SIGNAL(clicked()), this, SLOT(editContact()));
- connect(removeButton, SIGNAL(clicked()), this, SLOT(removeContact()));
+ connect(editButton, &QPushButton::clicked,
+ this, &AddressBook::editContact);
+ connect(removeButton, &QPushButton::clicked,
+ this, &AddressBook::removeContact);
//! [connecting edit and remove]
- connect(cancelButton, SIGNAL(clicked()), this, SLOT(cancel()));
- connect(nextButton, SIGNAL(clicked()), this, SLOT(next()));
- connect(previousButton, SIGNAL(clicked()), this, SLOT(previous()));
+ connect(cancelButton, &QPushButton::clicked,
+ this, &AddressBook::cancel);
+ connect(nextButton, &QPushButton::clicked,
+ this, &AddressBook::next);
+ connect(previousButton, &QPushButton::clicked,
+ this, &AddressBook::previous);
QVBoxLayout *buttonLayout1 = new QVBoxLayout;
buttonLayout1->addWidget(addButton);
diff --git a/examples/widgets/tutorials/addressbook/part5/addressbook.cpp b/examples/widgets/tutorials/addressbook/part5/addressbook.cpp
index 6e09ec287d..5505a0e35c 100644
--- a/examples/widgets/tutorials/addressbook/part5/addressbook.cpp
+++ b/examples/widgets/tutorials/addressbook/part5/addressbook.cpp
@@ -86,16 +86,24 @@ AddressBook::AddressBook(QWidget *parent)
dialog = new FindDialog(this);
//! [instantiating FindDialog]
- connect(addButton, SIGNAL(clicked()), this, SLOT(addContact()));
- connect(submitButton, SIGNAL(clicked()), this, SLOT(submitContact()));
- connect(editButton, SIGNAL(clicked()), this, SLOT(editContact()));
- connect(cancelButton, SIGNAL(clicked()), this, SLOT(cancel()));
- connect(removeButton, SIGNAL(clicked()), this, SLOT(removeContact()));
+ connect(addButton, &QPushButton::clicked,
+ this, &AddressBook::addContact);
+ connect(submitButton, &QPushButton::clicked,
+ this, &AddressBook::submitContact);
+ connect(editButton, &QPushButton::clicked,
+ this, &AddressBook::editContact);
+ connect(removeButton, &QPushButton::clicked,
+ this, &AddressBook::removeContact);
+ connect(cancelButton, &QPushButton::clicked,
+ this, &AddressBook::cancel);
//! [signals and slots for find]
- connect(findButton, SIGNAL(clicked()), this, SLOT(findContact()));
+ connect(findButton, &QPushButton::clicked,
+ this, &AddressBook::findContact);
//! [signals and slots for find]
- connect(nextButton, SIGNAL(clicked()), this, SLOT(next()));
- connect(previousButton, SIGNAL(clicked()), this, SLOT(previous()));
+ connect(nextButton, &QPushButton::clicked,
+ this, &AddressBook::next);
+ connect(previousButton, &QPushButton::clicked,
+ this, &AddressBook::previous);
QVBoxLayout *buttonLayout1 = new QVBoxLayout;
buttonLayout1->addWidget(addButton);
diff --git a/examples/widgets/tutorials/addressbook/part5/finddialog.cpp b/examples/widgets/tutorials/addressbook/part5/finddialog.cpp
index b0d9a5e6e3..615b39d42f 100644
--- a/examples/widgets/tutorials/addressbook/part5/finddialog.cpp
+++ b/examples/widgets/tutorials/addressbook/part5/finddialog.cpp
@@ -68,8 +68,10 @@ FindDialog::FindDialog(QWidget *parent)
setLayout(layout);
setWindowTitle(tr("Find a Contact"));
- connect(findButton, SIGNAL(clicked()), this, SLOT(findClicked()));
- connect(findButton, SIGNAL(clicked()), this, SLOT(accept()));
+ connect(findButton, &QPushButton::clicked,
+ this, &FindDialog::findClicked);
+ connect(findButton, &QPushButton::clicked,
+ this, &FindDialog::accept);
}
//! [constructor]
//! [findClicked() function]
diff --git a/examples/widgets/tutorials/addressbook/part6/addressbook.cpp b/examples/widgets/tutorials/addressbook/part6/addressbook.cpp
index b2e361a45e..8e740cfffc 100644
--- a/examples/widgets/tutorials/addressbook/part6/addressbook.cpp
+++ b/examples/widgets/tutorials/addressbook/part6/addressbook.cpp
@@ -92,16 +92,26 @@ AddressBook::AddressBook(QWidget *parent)
dialog = new FindDialog(this);
- connect(addButton, SIGNAL(clicked()), this, SLOT(addContact()));
- connect(submitButton, SIGNAL(clicked()), this, SLOT(submitContact()));
- connect(editButton, SIGNAL(clicked()), this, SLOT(editContact()));
- connect(cancelButton, SIGNAL(clicked()), this, SLOT(cancel()));
- connect(removeButton, SIGNAL(clicked()), this, SLOT(removeContact()));
- connect(findButton, SIGNAL(clicked()), this, SLOT(findContact()));
- connect(nextButton, SIGNAL(clicked()), this, SLOT(next()));
- connect(previousButton, SIGNAL(clicked()), this, SLOT(previous()));
- connect(loadButton, SIGNAL(clicked()), this, SLOT(loadFromFile()));
- connect(saveButton, SIGNAL(clicked()), this, SLOT(saveToFile()));
+ connect(addButton, &QPushButton::clicked,
+ this, &AddressBook::addContact);
+ connect(submitButton, &QPushButton::clicked,
+ this, &AddressBook::submitContact);
+ connect(editButton, &QPushButton::clicked,
+ this, &AddressBook::editContact);
+ connect(removeButton, &QPushButton::clicked,
+ this, &AddressBook::removeContact);
+ connect(cancelButton, &QPushButton::clicked,
+ this, &AddressBook::cancel);
+ connect(findButton, &QPushButton::clicked,
+ this, &AddressBook::findContact);
+ connect(nextButton, &QPushButton::clicked,
+ this, &AddressBook::next);
+ connect(previousButton, &QPushButton::clicked,
+ this, &AddressBook::previous);
+ connect(loadButton, &QPushButton::clicked,
+ this, &AddressBook::loadFromFile);
+ connect(saveButton, &QPushButton::clicked,
+ this, &AddressBook::saveToFile);
QVBoxLayout *buttonLayout1 = new QVBoxLayout;
buttonLayout1->addWidget(addButton);
diff --git a/examples/widgets/tutorials/addressbook/part6/finddialog.cpp b/examples/widgets/tutorials/addressbook/part6/finddialog.cpp
index 6a1e6b116f..c25cccd552 100644
--- a/examples/widgets/tutorials/addressbook/part6/finddialog.cpp
+++ b/examples/widgets/tutorials/addressbook/part6/finddialog.cpp
@@ -67,8 +67,10 @@ FindDialog::FindDialog(QWidget *parent)
setLayout(layout);
setWindowTitle(tr("Find a Contact"));
- connect(findButton, SIGNAL(clicked()), this, SLOT(findClicked()));
- connect(findButton, SIGNAL(clicked()), this, SLOT(accept()));
+ connect(findButton, &QPushButton::clicked,
+ this, &FindDialog::findClicked);
+ connect(findButton, &QPushButton::clicked,
+ this, &FindDialog::accept);
}
void FindDialog::findClicked()
diff --git a/examples/widgets/tutorials/addressbook/part7/addressbook.cpp b/examples/widgets/tutorials/addressbook/part7/addressbook.cpp
index e946c873e3..717d0882af 100644
--- a/examples/widgets/tutorials/addressbook/part7/addressbook.cpp
+++ b/examples/widgets/tutorials/addressbook/part7/addressbook.cpp
@@ -92,17 +92,28 @@ AddressBook::AddressBook(QWidget *parent)
dialog = new FindDialog(this);
- connect(addButton, SIGNAL(clicked()), this, SLOT(addContact()));
- connect(submitButton, SIGNAL(clicked()), this, SLOT(submitContact()));
- connect(editButton, SIGNAL(clicked()), this, SLOT(editContact()));
- connect(cancelButton, SIGNAL(clicked()), this, SLOT(cancel()));
- connect(removeButton, SIGNAL(clicked()), this, SLOT(removeContact()));
- connect(findButton, SIGNAL(clicked()), this, SLOT(findContact()));
- connect(nextButton, SIGNAL(clicked()), this, SLOT(next()));
- connect(previousButton, SIGNAL(clicked()), this, SLOT(previous()));
- connect(loadButton, SIGNAL(clicked()), this, SLOT(loadFromFile()));
- connect(saveButton, SIGNAL(clicked()), this, SLOT(saveToFile()));
- connect(exportButton, SIGNAL(clicked()), this, SLOT(exportAsVCard()));
+ connect(addButton, &QPushButton::clicked,
+ this, &AddressBook::addContact);
+ connect(submitButton, &QPushButton::clicked,
+ this, &AddressBook::submitContact);
+ connect(editButton, &QPushButton::clicked,
+ this, &AddressBook::editContact);
+ connect(removeButton, &QPushButton::clicked,
+ this, &AddressBook::removeContact);
+ connect(cancelButton, &QPushButton::clicked,
+ this, &AddressBook::cancel);
+ connect(findButton, &QPushButton::clicked,
+ this, &AddressBook::findContact);
+ connect(nextButton, &QPushButton::clicked,
+ this, &AddressBook::next);
+ connect(previousButton, &QPushButton::clicked,
+ this, &AddressBook::previous);
+ connect(loadButton, &QPushButton::clicked,
+ this, &AddressBook::loadFromFile);
+ connect(saveButton, &QPushButton::clicked,
+ this, &AddressBook::saveToFile);
+ connect(exportButton, &QPushButton::clicked,
+ this, &AddressBook::exportAsVCard);
QVBoxLayout *buttonLayout1 = new QVBoxLayout;
buttonLayout1->addWidget(addButton);
diff --git a/examples/widgets/tutorials/addressbook/part7/finddialog.cpp b/examples/widgets/tutorials/addressbook/part7/finddialog.cpp
index 6a1e6b116f..c25cccd552 100644
--- a/examples/widgets/tutorials/addressbook/part7/finddialog.cpp
+++ b/examples/widgets/tutorials/addressbook/part7/finddialog.cpp
@@ -67,8 +67,10 @@ FindDialog::FindDialog(QWidget *parent)
setLayout(layout);
setWindowTitle(tr("Find a Contact"));
- connect(findButton, SIGNAL(clicked()), this, SLOT(findClicked()));
- connect(findButton, SIGNAL(clicked()), this, SLOT(accept()));
+ connect(findButton, &QPushButton::clicked,
+ this, &FindDialog::findClicked);
+ connect(findButton, &QPushButton::clicked,
+ this, &FindDialog::accept);
}
void FindDialog::findClicked()
diff --git a/examples/widgets/tutorials/gettingStarted/gsQt/part2/main.cpp b/examples/widgets/tutorials/gettingStarted/gsQt/part2/main.cpp
index 90f5f1a6b3..8bf83859a0 100644
--- a/examples/widgets/tutorials/gettingStarted/gsQt/part2/main.cpp
+++ b/examples/widgets/tutorials/gettingStarted/gsQt/part2/main.cpp
@@ -57,7 +57,8 @@ int main(int argc, char *argv[])
QTextEdit *textEdit = new QTextEdit;
QPushButton *quitButton = new QPushButton("&Quit");
- QObject::connect(quitButton, SIGNAL(clicked()), qApp, SLOT(quit()));
+ QObject::connect(quitButton, &QPushButton::clicked,
+ qApp, &QApplication::quit);
QVBoxLayout *layout = new QVBoxLayout;
layout->addWidget(textEdit);
diff --git a/examples/widgets/tutorials/gettingStarted/gsQt/part3/main.cpp b/examples/widgets/tutorials/gettingStarted/gsQt/part3/main.cpp
index 0a60c1cf16..d4b43eb034 100644
--- a/examples/widgets/tutorials/gettingStarted/gsQt/part3/main.cpp
+++ b/examples/widgets/tutorials/gettingStarted/gsQt/part3/main.cpp
@@ -71,7 +71,8 @@ Notepad::Notepad()
textEdit = new QTextEdit;
quitButton = new QPushButton(tr("Quit"));
- connect(quitButton, SIGNAL(clicked()), this, SLOT(quit()));
+ connect(quitButton, &QPushButton::clicked,
+ this, &Notepad::quit);
QVBoxLayout *layout = new QVBoxLayout;
layout->addWidget(textEdit);
diff --git a/examples/widgets/tutorials/gettingStarted/gsQt/part4/main.cpp b/examples/widgets/tutorials/gettingStarted/gsQt/part4/main.cpp
index 6d9e96a3d4..8c5fbc70ca 100644
--- a/examples/widgets/tutorials/gettingStarted/gsQt/part4/main.cpp
+++ b/examples/widgets/tutorials/gettingStarted/gsQt/part4/main.cpp
@@ -73,14 +73,16 @@ private:
Notepad::Notepad()
{
-
loadAction = new QAction(tr("&Load"), this);
saveAction = new QAction(tr("&Save"), this);
exitAction = new QAction(tr("E&xit"), this);
- connect(loadAction, SIGNAL(triggered()), this, SLOT(load()));
- connect(saveAction, SIGNAL(triggered()), this, SLOT(save()));
- connect(exitAction, SIGNAL(triggered()), qApp, SLOT(quit()));
+ connect(loadAction, &QAction::triggered,
+ this, &Notepad::load);
+ connect(saveAction, &QAction::triggered,
+ this, &Notepad::save);
+ connect(exitAction, &QAction::triggered,
+ qApp, &QApplication::quit);
fileMenu = menuBar()->addMenu(tr("&File"));
fileMenu->addAction(loadAction);
diff --git a/examples/widgets/tutorials/gettingStarted/gsQt/part5/main.cpp b/examples/widgets/tutorials/gettingStarted/gsQt/part5/main.cpp
index b2b4a73874..cc3e1a261c 100644
--- a/examples/widgets/tutorials/gettingStarted/gsQt/part5/main.cpp
+++ b/examples/widgets/tutorials/gettingStarted/gsQt/part5/main.cpp
@@ -73,14 +73,16 @@ private:
Notepad::Notepad()
{
-
openAction = new QAction(tr("&Load"), this);
saveAction = new QAction(tr("&Save"), this);
exitAction = new QAction(tr("E&xit"), this);
- connect(openAction, SIGNAL(triggered()), this, SLOT(open()));
- connect(saveAction, SIGNAL(triggered()), this, SLOT(save()));
- connect(exitAction, SIGNAL(triggered()), qApp, SLOT(quit()));
+ connect(openAction, &QAction::triggered,
+ this, &Notepad::open);
+ connect(saveAction, &QAction::triggered,
+ this, &Notepad::save);
+ connect(exitAction, &QAction::triggered,
+ qApp, &QApplication::quit);
fileMenu = menuBar()->addMenu(tr("&File"));
fileMenu->addAction(openAction);
diff --git a/examples/widgets/tutorials/widgets/nestedlayouts/main.cpp b/examples/widgets/tutorials/widgets/nestedlayouts/main.cpp
index 9acc74b469..8880dbe3d0 100644
--- a/examples/widgets/tutorials/widgets/nestedlayouts/main.cpp
+++ b/examples/widgets/tutorials/widgets/nestedlayouts/main.cpp
@@ -76,25 +76,26 @@ int main(int argc, char *argv[])
//! [set up the model]
QStandardItemModel model;
- model.setHorizontalHeaderLabels(
- QStringList() << QApplication::translate("nestedlayouts", "Name")
- << QApplication::translate("nestedlayouts", "Office"));
+ model.setHorizontalHeaderLabels({ QApplication::translate("nestedlayouts", "Name"),
+ QApplication::translate("nestedlayouts", "Office") });
- QList<QStringList> rows = QList<QStringList>()
- << (QStringList() << "Verne Nilsen" << "123")
- << (QStringList() << "Carlos Tang" << "77")
- << (QStringList() << "Bronwyn Hawcroft" << "119")
- << (QStringList() << "Alessandro Hanssen" << "32")
- << (QStringList() << "Andrew John Bakken" << "54")
- << (QStringList() << "Vanessa Weatherley" << "85")
- << (QStringList() << "Rebecca Dickens" << "17")
- << (QStringList() << "David Bradley" << "42")
- << (QStringList() << "Knut Walters" << "25")
- << (QStringList() << "Andrea Jones" << "34");
+ const QStringList rows[] = {
+ QStringList{ QStringLiteral("Verne Nilsen"), QStringLiteral("123") },
+ QStringList{ QStringLiteral("Carlos Tang"), QStringLiteral("77") },
+ QStringList{ QStringLiteral("Bronwyn Hawcroft"), QStringLiteral("119") },
+ QStringList{ QStringLiteral("Alessandro Hanssen"), QStringLiteral("32") },
+ QStringList{ QStringLiteral("Andrew John Bakken"), QStringLiteral("54") },
+ QStringList{ QStringLiteral("Vanessa Weatherley"), QStringLiteral("85") },
+ QStringList{ QStringLiteral("Rebecca Dickens"), QStringLiteral("17") },
+ QStringList{ QStringLiteral("David Bradley"), QStringLiteral("42") },
+ QStringList{ QStringLiteral("Knut Walters"), QStringLiteral("25") },
+ QStringList{ QStringLiteral("Andrea Jones"), QStringLiteral("34") }
+ };
- foreach (QStringList row, rows) {
- QList<QStandardItem *> items;
- foreach (QString text, row)
+ QList<QStandardItem *> items;
+ for (const QStringList &row : rows) {
+ items.clear();
+ for (const QString &text : row)
items.append(new QStandardItem(text));
model.appendRow(items);
}
diff --git a/examples/widgets/widgets/calendarwidget/window.cpp b/examples/widgets/widgets/calendarwidget/window.cpp
index c3a0e1e3f7..a1c1746786 100644
--- a/examples/widgets/widgets/calendarwidget/window.cpp
+++ b/examples/widgets/widgets/calendarwidget/window.cpp
@@ -53,7 +53,8 @@
#include "window.h"
//! [0]
-Window::Window()
+Window::Window(QWidget *parent)
+ : QWidget(parent)
{
createPreviewGroupBox();
createGeneralOptionsGroupBox();
diff --git a/examples/widgets/widgets/calendarwidget/window.h b/examples/widgets/widgets/calendarwidget/window.h
index fa01fc4db6..83ea494fc2 100644
--- a/examples/widgets/widgets/calendarwidget/window.h
+++ b/examples/widgets/widgets/calendarwidget/window.h
@@ -70,7 +70,7 @@ class Window : public QWidget
Q_OBJECT
public:
- Window();
+ Window(QWidget *parent = nullptr);
private slots:
void localeChanged(int index);
diff --git a/examples/widgets/widgets/charactermap/mainwindow.cpp b/examples/widgets/widgets/charactermap/mainwindow.cpp
index d3ac55483c..76bd8f7799 100644
--- a/examples/widgets/widgets/charactermap/mainwindow.cpp
+++ b/examples/widgets/widgets/charactermap/mainwindow.cpp
@@ -57,7 +57,8 @@
Q_DECLARE_METATYPE(QFontComboBox::FontFilter)
-MainWindow::MainWindow()
+MainWindow::MainWindow(QWidget *parent)
+ : QMainWindow(parent)
{
QMenu *fileMenu = menuBar()->addMenu(tr("File"));
fileMenu->addAction(tr("Quit"), this, &QWidget::close);
diff --git a/examples/widgets/widgets/charactermap/mainwindow.h b/examples/widgets/widgets/charactermap/mainwindow.h
index eac16b35fa..79fe9f9cc8 100644
--- a/examples/widgets/widgets/charactermap/mainwindow.h
+++ b/examples/widgets/widgets/charactermap/mainwindow.h
@@ -70,7 +70,7 @@ class MainWindow : public QMainWindow
Q_OBJECT
public:
- MainWindow();
+ MainWindow(QWidget *parent = nullptr);
public slots:
void filterChanged(int);
diff --git a/examples/widgets/widgets/icons/mainwindow.cpp b/examples/widgets/widgets/icons/mainwindow.cpp
index f704b8306f..904245494c 100644
--- a/examples/widgets/widgets/icons/mainwindow.cpp
+++ b/examples/widgets/widgets/icons/mainwindow.cpp
@@ -60,7 +60,8 @@ enum { OtherSize = QStyle::PM_CustomBase };
//! [40]
//! [0]
-MainWindow::MainWindow()
+MainWindow::MainWindow(QWidget *parent)
+ : QMainWindow(parent)
{
QWidget *centralWidget = new QWidget(this);
setCentralWidget(centralWidget);
diff --git a/examples/widgets/widgets/icons/mainwindow.h b/examples/widgets/widgets/icons/mainwindow.h
index e3888e5fb1..1949bd235c 100644
--- a/examples/widgets/widgets/icons/mainwindow.h
+++ b/examples/widgets/widgets/icons/mainwindow.h
@@ -74,7 +74,7 @@ class MainWindow : public QMainWindow
Q_OBJECT
public:
- MainWindow();
+ MainWindow(QWidget *parent = nullptr);
void loadImages(const QStringList &fileNames);
diff --git a/examples/widgets/widgets/imageviewer/imageviewer.cpp b/examples/widgets/widgets/imageviewer/imageviewer.cpp
index 327abf7e43..b1346d9ccb 100644
--- a/examples/widgets/widgets/imageviewer/imageviewer.cpp
+++ b/examples/widgets/widgets/imageviewer/imageviewer.cpp
@@ -59,10 +59,9 @@
#include "imageviewer.h"
//! [0]
-ImageViewer::ImageViewer()
- : imageLabel(new QLabel)
- , scrollArea(new QScrollArea)
- , scaleFactor(1)
+ImageViewer::ImageViewer(QWidget *parent)
+ : QMainWindow(parent), imageLabel(new QLabel),
+ scrollArea(new QScrollArea), scaleFactor(1)
{
imageLabel->setBackgroundRole(QPalette::Base);
imageLabel->setSizePolicy(QSizePolicy::Ignored, QSizePolicy::Ignored);
diff --git a/examples/widgets/widgets/imageviewer/imageviewer.h b/examples/widgets/widgets/imageviewer/imageviewer.h
index f4a62cafe9..7e53105b33 100644
--- a/examples/widgets/widgets/imageviewer/imageviewer.h
+++ b/examples/widgets/widgets/imageviewer/imageviewer.h
@@ -71,7 +71,7 @@ class ImageViewer : public QMainWindow
Q_OBJECT
public:
- ImageViewer();
+ ImageViewer(QWidget *parent = nullptr);
bool loadFile(const QString &);
private slots:
diff --git a/examples/widgets/widgets/lineedits/window.cpp b/examples/widgets/widgets/lineedits/window.cpp
index ffb1edc5ce..47324589b7 100644
--- a/examples/widgets/widgets/lineedits/window.cpp
+++ b/examples/widgets/widgets/lineedits/window.cpp
@@ -53,7 +53,8 @@
#include "window.h"
//! [0]
-Window::Window()
+Window::Window(QWidget *parent)
+ : QWidget(parent)
{
QGroupBox *echoGroup = new QGroupBox(tr("Echo"));
diff --git a/examples/widgets/widgets/lineedits/window.h b/examples/widgets/widgets/lineedits/window.h
index 2070b3b84c..3231588f4f 100644
--- a/examples/widgets/widgets/lineedits/window.h
+++ b/examples/widgets/widgets/lineedits/window.h
@@ -64,7 +64,7 @@ class Window : public QWidget
Q_OBJECT
public:
- Window();
+ Window(QWidget *parent = nullptr);
public slots:
void echoChanged(int);
diff --git a/examples/widgets/widgets/mousebuttons/buttontester.h b/examples/widgets/widgets/mousebuttons/buttontester.h
index d99dcceb18..231733bd44 100644
--- a/examples/widgets/widgets/mousebuttons/buttontester.h
+++ b/examples/widgets/widgets/mousebuttons/buttontester.h
@@ -59,13 +59,14 @@
class ButtonTester : public QTextEdit
{
Q_OBJECT
-
+public:
+ using QTextEdit::QTextEdit;
protected:
void mousePressEvent(QMouseEvent *event) override;
void mouseReleaseEvent(QMouseEvent *event) override;
void mouseDoubleClickEvent(QMouseEvent *event) override;
#if QT_CONFIG(wheelevent)
- void wheelEvent(QWheelEvent * event) override;
+ void wheelEvent(QWheelEvent *event) override;
#endif
int buttonByNumber(const Qt::MouseButton button);
QString enumNameFromValue(const Qt::MouseButton button);
diff --git a/examples/widgets/widgets/scribble/mainwindow.cpp b/examples/widgets/widgets/scribble/mainwindow.cpp
index d54e5ce0f9..b8d01d505c 100644
--- a/examples/widgets/widgets/scribble/mainwindow.cpp
+++ b/examples/widgets/widgets/scribble/mainwindow.cpp
@@ -54,9 +54,9 @@
#include "scribblearea.h"
//! [0]
-MainWindow::MainWindow()
+MainWindow::MainWindow(QWidget *parent)
+ : QMainWindow(parent), scribbleArea(new ScribbleArea(this))
{
- scribbleArea = new ScribbleArea;
setCentralWidget(scribbleArea);
createActions();
diff --git a/examples/widgets/widgets/scribble/mainwindow.h b/examples/widgets/widgets/scribble/mainwindow.h
index 9e0ddaff71..e57ff065ac 100644
--- a/examples/widgets/widgets/scribble/mainwindow.h
+++ b/examples/widgets/widgets/scribble/mainwindow.h
@@ -62,7 +62,7 @@ class MainWindow : public QMainWindow
Q_OBJECT
public:
- MainWindow();
+ MainWindow(QWidget *parent = nullptr);
protected:
void closeEvent(QCloseEvent *event) override;
diff --git a/examples/widgets/widgets/sliders/window.cpp b/examples/widgets/widgets/sliders/window.cpp
index 16b60dde49..16467e71be 100644
--- a/examples/widgets/widgets/sliders/window.cpp
+++ b/examples/widgets/widgets/sliders/window.cpp
@@ -54,7 +54,8 @@
#include "window.h"
//! [0]
-Window::Window()
+Window::Window(QWidget *parent)
+ : QWidget(parent)
{
horizontalSliders = new SlidersGroup(Qt::Horizontal, tr("Horizontal"));
verticalSliders = new SlidersGroup(Qt::Vertical, tr("Vertical"));
diff --git a/examples/widgets/widgets/sliders/window.h b/examples/widgets/widgets/sliders/window.h
index 9c4c14fa37..4894781ac2 100644
--- a/examples/widgets/widgets/sliders/window.h
+++ b/examples/widgets/widgets/sliders/window.h
@@ -69,7 +69,7 @@ class Window : public QWidget
Q_OBJECT
public:
- Window();
+ Window(QWidget *parent = nullptr);
private:
void createControls(const QString &title);
diff --git a/examples/widgets/widgets/spinboxes/window.cpp b/examples/widgets/widgets/spinboxes/window.cpp
index 54604e35aa..eb660faace 100644
--- a/examples/widgets/widgets/spinboxes/window.cpp
+++ b/examples/widgets/widgets/spinboxes/window.cpp
@@ -53,7 +53,8 @@
#include "window.h"
//! [0]
-Window::Window()
+Window::Window(QWidget *parent)
+ : QWidget(parent)
{
createSpinBoxes();
createDateTimeEdits();
diff --git a/examples/widgets/widgets/spinboxes/window.h b/examples/widgets/widgets/spinboxes/window.h
index 97e9ac1083..138773a5aa 100644
--- a/examples/widgets/widgets/spinboxes/window.h
+++ b/examples/widgets/widgets/spinboxes/window.h
@@ -67,7 +67,7 @@ class Window : public QWidget
Q_OBJECT
public:
- Window();
+ Window(QWidget *parent = nullptr);
public slots:
void changePrecision(int decimals);
diff --git a/examples/widgets/widgets/stylesheet/mainwindow.cpp b/examples/widgets/widgets/stylesheet/mainwindow.cpp
index 9acd90658a..eb4b3a2424 100644
--- a/examples/widgets/widgets/stylesheet/mainwindow.cpp
+++ b/examples/widgets/widgets/stylesheet/mainwindow.cpp
@@ -53,7 +53,8 @@
#include "mainwindow.h"
#include "stylesheeteditor.h"
-MainWindow::MainWindow()
+MainWindow::MainWindow(QWidget *parent)
+ : QMainWindow(parent)
{
ui.setupUi(this);
diff --git a/examples/widgets/widgets/stylesheet/mainwindow.h b/examples/widgets/widgets/stylesheet/mainwindow.h
index 46d3ecbb93..8af4c01da0 100644
--- a/examples/widgets/widgets/stylesheet/mainwindow.h
+++ b/examples/widgets/widgets/stylesheet/mainwindow.h
@@ -62,7 +62,7 @@ class MainWindow : public QMainWindow
Q_OBJECT
public:
- MainWindow();
+ MainWindow(QWidget *parent = nullptr);
private slots:
void on_editStyleAction_triggered();
diff --git a/examples/widgets/widgets/tetrix/tetrixwindow.cpp b/examples/widgets/widgets/tetrix/tetrixwindow.cpp
index 7e951aceb8..970a38c1dc 100644
--- a/examples/widgets/widgets/tetrix/tetrixwindow.cpp
+++ b/examples/widgets/widgets/tetrix/tetrixwindow.cpp
@@ -54,7 +54,8 @@
#include "tetrixwindow.h"
//! [0]
-TetrixWindow::TetrixWindow()
+TetrixWindow::TetrixWindow(QWidget *parent)
+ : QWidget(parent)
{
board = new TetrixBoard;
//! [0]
diff --git a/examples/widgets/widgets/tetrix/tetrixwindow.h b/examples/widgets/widgets/tetrix/tetrixwindow.h
index a21cef2ecf..02226ffe1c 100644
--- a/examples/widgets/widgets/tetrix/tetrixwindow.h
+++ b/examples/widgets/widgets/tetrix/tetrixwindow.h
@@ -67,7 +67,7 @@ class TetrixWindow : public QWidget
Q_OBJECT
public:
- TetrixWindow();
+ TetrixWindow(QWidget *parent = nullptr);
private:
QLabel *createLabel(const QString &text);
diff --git a/examples/widgets/widgets/tooltips/sortingbox.cpp b/examples/widgets/widgets/tooltips/sortingbox.cpp
index 4769a30c64..766815e8e9 100644
--- a/examples/widgets/widgets/tooltips/sortingbox.cpp
+++ b/examples/widgets/widgets/tooltips/sortingbox.cpp
@@ -55,7 +55,8 @@
#include "sortingbox.h"
//! [0]
-SortingBox::SortingBox()
+SortingBox::SortingBox(QWidget *parent)
+ : QWidget(parent)
{
//! [0] //! [1]
setMouseTracking(true);
diff --git a/examples/widgets/widgets/tooltips/sortingbox.h b/examples/widgets/widgets/tooltips/sortingbox.h
index 2ac27614a5..12bdeff1f6 100644
--- a/examples/widgets/widgets/tooltips/sortingbox.h
+++ b/examples/widgets/widgets/tooltips/sortingbox.h
@@ -67,7 +67,7 @@ class SortingBox : public QWidget
Q_OBJECT
public:
- SortingBox();
+ SortingBox(QWidget *parent = nullptr);
protected:
bool event(QEvent *event) override;
diff --git a/examples/widgets/widgets/validators/main.cpp b/examples/widgets/widgets/validators/main.cpp
index d8ba2943d0..1fbf12410d 100644
--- a/examples/widgets/widgets/validators/main.cpp
+++ b/examples/widgets/widgets/validators/main.cpp
@@ -48,88 +48,9 @@
**
****************************************************************************/
-#include <qdebug.h>
-#include <QApplication>
-#include <QLineEdit>
-#include <QValidator>
-
-#include "ui_validators.h"
-
-class ValidatorWidget : public QWidget, public Ui::ValidatorsForm
-{
- Q_OBJECT
-public:
- ValidatorWidget(QWidget *parent = 0);
-
-private slots:
- void updateValidator();
- void updateDoubleValidator();
- void _setLocale(const QLocale &l) { setLocale(l); updateValidator(); updateDoubleValidator(); }
-
-private:
- QIntValidator *validator;
- QDoubleValidator *doubleValidator;
-};
-
-ValidatorWidget::ValidatorWidget(QWidget *parent)
- : QWidget(parent)
-{
- setupUi(this);
-
- connect(localeSelector, SIGNAL(localeSelected(QLocale)), this, SLOT(_setLocale(QLocale)));
-
- connect(minVal, SIGNAL(editingFinished()), this, SLOT(updateValidator()));
- connect(maxVal, SIGNAL(editingFinished()), this, SLOT(updateValidator()));
- connect(editor, SIGNAL(editingFinished()), ledWidget, SLOT(flash()));
-
- connect(doubleMaxVal, SIGNAL(editingFinished()), this, SLOT(updateDoubleValidator()));
- connect(doubleMinVal, SIGNAL(editingFinished()), this, SLOT(updateDoubleValidator()));
- connect(doubleDecimals, SIGNAL(valueChanged(int)), this, SLOT(updateDoubleValidator()));
- connect(doubleFormat, SIGNAL(activated(int)), this, SLOT(updateDoubleValidator()));
- connect(doubleEditor, SIGNAL(editingFinished()), doubleLedWidget, SLOT(flash()));
+#include "validatorwidget.h"
- validator = 0;
- doubleValidator = 0;
- updateValidator();
- updateDoubleValidator();
-};
-
-void ValidatorWidget::updateValidator()
-{
- QIntValidator *v = new QIntValidator(minVal->value(), maxVal->value(), this);
- v->setLocale(locale());
- editor->setValidator(v);
- delete validator;
- validator = v;
-
- QString s = editor->text();
- int i = 0;
- if (validator->validate(s, i) == QValidator::Invalid) {
- editor->clear();
- } else {
- editor->setText(s);
- }
-}
-
-void ValidatorWidget::updateDoubleValidator()
-{
- QDoubleValidator *v
- = new QDoubleValidator(doubleMinVal->value(), doubleMaxVal->value(),
- doubleDecimals->value(), this);
- v->setNotation(static_cast<QDoubleValidator::Notation>(doubleFormat->currentIndex()));
- v->setLocale(locale());
- doubleEditor->setValidator(v);
- delete doubleValidator;
- doubleValidator = v;
-
- QString s = doubleEditor->text();
- int i = 0;
- if (doubleValidator->validate(s, i) == QValidator::Invalid) {
- doubleEditor->clear();
- } else {
- doubleEditor->setText(s);
- }
-}
+#include <QApplication>
int main(int argc, char **argv)
{
@@ -142,5 +63,3 @@ int main(int argc, char **argv)
return app.exec();
}
-
-#include "main.moc"
diff --git a/examples/widgets/widgets/validators/validators.pro b/examples/widgets/widgets/validators/validators.pro
index ab1eb7809b..029cf95aca 100644
--- a/examples/widgets/widgets/validators/validators.pro
+++ b/examples/widgets/widgets/validators/validators.pro
@@ -4,8 +4,8 @@ requires(qtConfig(combobox))
FORMS += validators.ui
RESOURCES += validators.qrc
-SOURCES += main.cpp ledwidget.cpp localeselector.cpp
-HEADERS += ledwidget.h localeselector.h
+SOURCES += main.cpp ledwidget.cpp localeselector.cpp validatorwidget.cpp
+HEADERS += ledwidget.h localeselector.h validatorwidget.h
# install
target.path = $$[QT_INSTALL_EXAMPLES]/widgets/widgets/validators
diff --git a/examples/widgets/widgets/validators/validatorwidget.cpp b/examples/widgets/widgets/validators/validatorwidget.cpp
new file mode 100644
index 0000000000..fa0a55aa52
--- /dev/null
+++ b/examples/widgets/widgets/validators/validatorwidget.cpp
@@ -0,0 +1,122 @@
+/****************************************************************************
+**
+** Copyright (C) 2018 The Qt Company Ltd.
+** Contact: https://www.qt.io/licensing/
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** Commercial License Usage
+** Licensees holding valid commercial Qt licenses may use this file in
+** accordance with the commercial license agreement provided with the
+** Software or, alternatively, in accordance with the terms contained in
+** a written agreement between you and The Qt Company. For licensing terms
+** and conditions see https://www.qt.io/terms-conditions. For further
+** information use the contact form at https://www.qt.io/contact-us.
+**
+** BSD License Usage
+** Alternatively, you may use this file under the terms of the BSD license
+** as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of The Qt Company Ltd nor the names of its
+** contributors may be used to endorse or promote products derived
+** from this software without specific prior written permission.
+**
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include "validatorwidget.h"
+
+#include <QtWidgets>
+
+ValidatorWidget::ValidatorWidget(QWidget *parent)
+ : QWidget(parent)
+{
+ setupUi(this);
+
+ connect(localeSelector, &LocaleSelector::localeSelected,
+ this, &ValidatorWidget::setLocale);
+ connect(localeSelector, &LocaleSelector::localeSelected,
+ this, &ValidatorWidget::updateValidator);
+ connect(localeSelector, &LocaleSelector::localeSelected,
+ this, &ValidatorWidget::updateDoubleValidator);
+
+ connect(minVal, &QSpinBox::editingFinished,
+ this, &ValidatorWidget::updateValidator);
+ connect(maxVal, &QSpinBox::editingFinished,
+ this, &ValidatorWidget::updateValidator);
+ connect(editor, &QLineEdit::editingFinished,
+ ledWidget, &LEDWidget::flash);
+
+ connect(doubleMaxVal, &QDoubleSpinBox::editingFinished,
+ this, &ValidatorWidget::updateDoubleValidator);
+ connect(doubleMinVal, &QDoubleSpinBox::editingFinished,
+ this, &ValidatorWidget::updateDoubleValidator);
+ connect(doubleDecimals, QOverload<int>::of(&QSpinBox::valueChanged),
+ this, &ValidatorWidget::updateDoubleValidator);
+ connect(doubleFormat, QOverload<int>::of(&QComboBox::activated),
+ this, &ValidatorWidget::updateDoubleValidator);
+ connect(doubleEditor, &QLineEdit::editingFinished,
+ doubleLedWidget, &LEDWidget::flash);
+
+ updateValidator();
+ updateDoubleValidator();
+}
+
+void ValidatorWidget::updateValidator()
+{
+ QIntValidator *v = new QIntValidator(minVal->value(), maxVal->value(), this);
+ v->setLocale(locale());
+ delete editor->validator();
+ editor->setValidator(v);
+
+ QString s = editor->text();
+ int i = 0;
+ if (v->validate(s, i) == QValidator::Invalid) {
+ editor->clear();
+ } else {
+ editor->setText(s);
+ }
+}
+
+void ValidatorWidget::updateDoubleValidator()
+{
+ QDoubleValidator *v
+ = new QDoubleValidator(doubleMinVal->value(), doubleMaxVal->value(),
+ doubleDecimals->value(), this);
+ v->setNotation(static_cast<QDoubleValidator::Notation>(doubleFormat->currentIndex()));
+ v->setLocale(locale());
+ delete doubleEditor->validator();
+ doubleEditor->setValidator(v);
+
+ QString s = doubleEditor->text();
+ int i = 0;
+ if (v->validate(s, i) == QValidator::Invalid) {
+ doubleEditor->clear();
+ } else {
+ doubleEditor->setText(s);
+ }
+}
diff --git a/examples/widgets/widgets/validators/validatorwidget.h b/examples/widgets/widgets/validators/validatorwidget.h
new file mode 100644
index 0000000000..bcc4a9b91e
--- /dev/null
+++ b/examples/widgets/widgets/validators/validatorwidget.h
@@ -0,0 +1,64 @@
+/****************************************************************************
+**
+** Copyright (C) 2018 The Qt Company Ltd.
+** Contact: https://www.qt.io/licensing/
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** Commercial License Usage
+** Licensees holding valid commercial Qt licenses may use this file in
+** accordance with the commercial license agreement provided with the
+** Software or, alternatively, in accordance with the terms contained in
+** a written agreement between you and The Qt Company. For licensing terms
+** and conditions see https://www.qt.io/terms-conditions. For further
+** information use the contact form at https://www.qt.io/contact-us.
+**
+** BSD License Usage
+** Alternatively, you may use this file under the terms of the BSD license
+** as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of The Qt Company Ltd nor the names of its
+** contributors may be used to endorse or promote products derived
+** from this software without specific prior written permission.
+**
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <QWidget>
+
+#include "ui_validators.h"
+
+class ValidatorWidget : public QWidget, public Ui::ValidatorsForm
+{
+ Q_OBJECT
+public:
+ ValidatorWidget(QWidget *parent = nullptr);
+
+private slots:
+ void updateValidator();
+ void updateDoubleValidator();
+};
diff --git a/examples/widgets/widgets/windowflags/controllerwindow.cpp b/examples/widgets/widgets/windowflags/controllerwindow.cpp
index 78323810ed..c19f23c513 100644
--- a/examples/widgets/widgets/windowflags/controllerwindow.cpp
+++ b/examples/widgets/widgets/windowflags/controllerwindow.cpp
@@ -53,7 +53,8 @@
#include "controllerwindow.h"
//! [0]
-ControllerWindow::ControllerWindow()
+ControllerWindow::ControllerWindow(QWidget *parent)
+ : QWidget(parent)
{
previewWindow = new PreviewWindow(this);
diff --git a/examples/widgets/widgets/windowflags/controllerwindow.h b/examples/widgets/widgets/windowflags/controllerwindow.h
index cfb88ed20f..43ec67e27f 100644
--- a/examples/widgets/widgets/windowflags/controllerwindow.h
+++ b/examples/widgets/widgets/windowflags/controllerwindow.h
@@ -69,7 +69,7 @@ class ControllerWindow : public QWidget
Q_OBJECT
public:
- ControllerWindow();
+ ControllerWindow(QWidget *parent = nullptr);
private slots:
void updatePreview();