summaryrefslogtreecommitdiff
path: root/examples
diff options
context:
space:
mode:
authorFriedemann Kleint <Friedemann.Kleint@qt.io>2023-04-05 09:27:08 +0200
committerFriedemann Kleint <Friedemann.Kleint@qt.io>2023-04-05 09:50:49 +0200
commit88ef502099d535823156c31e77251dd2a723ad1c (patch)
treed38c1de13e54564277716c8f04add7ba5777f87c /examples
parent356f65b87c508c44bf31bc3134eaebfd6f39c6ec (diff)
downloadqtwebengine-88ef502099d535823156c31e77251dd2a723ad1c.tar.gz
Simple browser example: Fix up the code
- Remove duplicated unused helper questionForFeature() - Replace lambdas by slots where possible - Fix clang warning about using multiple arguments to QString::arg() - Remove dead code in WebView::contextMenuEvent() which checks on inspectElement == actions.cend(), but is within an "if" checking the same condition. Pick-to: 6.5 Change-Id: Ie85a3811f4f5a8c3fa9550d4eb2ca5bf79e39084 Reviewed-by: Michal Klocek <michal.klocek@qt.io>
Diffstat (limited to 'examples')
-rw-r--r--examples/webenginewidgets/simplebrowser/browserwindow.cpp5
-rw-r--r--examples/webenginewidgets/simplebrowser/webpage.cpp23
-rw-r--r--examples/webenginewidgets/simplebrowser/webview.cpp12
3 files changed, 6 insertions, 34 deletions
diff --git a/examples/webenginewidgets/simplebrowser/browserwindow.cpp b/examples/webenginewidgets/simplebrowser/browserwindow.cpp
index 7a72b4a6f..7f30d2e92 100644
--- a/examples/webenginewidgets/simplebrowser/browserwindow.cpp
+++ b/examples/webenginewidgets/simplebrowser/browserwindow.cpp
@@ -355,9 +355,8 @@ QToolBar *BrowserWindow::createToolBar()
downloadsAction->setIcon(QIcon(u":go-bottom.png"_s));
downloadsAction->setToolTip(tr("Show downloads"));
navigationBar->addAction(downloadsAction);
- connect(downloadsAction, &QAction::triggered, [this]() {
- m_browser->downloadManagerWidget().show();
- });
+ connect(downloadsAction, &QAction::triggered,
+ &m_browser->downloadManagerWidget(), &QWidget::show);
return navigationBar;
}
diff --git a/examples/webenginewidgets/simplebrowser/webpage.cpp b/examples/webenginewidgets/simplebrowser/webpage.cpp
index 66de5d6d9..699e3d2ed 100644
--- a/examples/webenginewidgets/simplebrowser/webpage.cpp
+++ b/examples/webenginewidgets/simplebrowser/webpage.cpp
@@ -22,29 +22,6 @@ void WebPage::handleCertificateError(QWebEngineCertificateError error)
[this, error]() mutable { emit createCertificateErrorDialog(error); });
}
-inline QString questionForFeature(QWebEnginePage::Feature feature)
-{
- switch (feature) {
- case QWebEnginePage::Geolocation:
- return WebPage::tr("Allow %1 to access your location information?");
- case QWebEnginePage::MediaAudioCapture:
- return WebPage::tr("Allow %1 to access your microphone?");
- case QWebEnginePage::MediaVideoCapture:
- return WebPage::tr("Allow %1 to access your webcam?");
- case QWebEnginePage::MediaAudioVideoCapture:
- return WebPage::tr("Allow %1 to access your microphone and webcam?");
- case QWebEnginePage::MouseLock:
- return WebPage::tr("Allow %1 to lock your mouse cursor?");
- case QWebEnginePage::DesktopVideoCapture:
- return WebPage::tr("Allow %1 to capture video of your desktop?");
- case QWebEnginePage::DesktopAudioVideoCapture:
- return WebPage::tr("Allow %1 to capture audio and video of your desktop?");
- case QWebEnginePage::Notifications:
- return WebPage::tr("Allow %1 to show notification on your desktop?");
- }
- return QString();
-}
-
void WebPage::handleSelectClientCertificate(QWebEngineClientCertificateSelection selection)
{
// Just select one.
diff --git a/examples/webenginewidgets/simplebrowser/webview.cpp b/examples/webenginewidgets/simplebrowser/webview.cpp
index dd6dbb149..e024f9126 100644
--- a/examples/webenginewidgets/simplebrowser/webview.cpp
+++ b/examples/webenginewidgets/simplebrowser/webview.cpp
@@ -58,7 +58,7 @@ WebView::WebView(QWidget *parent)
tr("Render process exited with code: %1\n"
"Do you want to reload the page ?").arg(statusCode));
if (btn == QMessageBox::Yes)
- QTimer::singleShot(0, [this] { reload(); });
+ QTimer::singleShot(0, this, &WebView::reload);
});
}
@@ -195,12 +195,8 @@ void WebView::contextMenuEvent(QContextMenuEvent *event)
if (viewSource == actions.cend())
menu->addSeparator();
- QAction *action = new QAction(menu);
- action->setText("Open inspector in new window");
+ QAction *action = menu->addAction("Open inspector in new window");
connect(action, &QAction::triggered, [this]() { emit devToolsRequested(page()); });
-
- QAction *before(inspectElement == actions.cend() ? nullptr : *inspectElement);
- menu->insertAction(before, action);
} else {
(*inspectElement)->setText(tr("Inspect element"));
}
@@ -241,8 +237,8 @@ void WebView::handleAuthenticationRequired(const QUrl &requestUrl, QAuthenticato
passwordDialog.m_iconLabel->setPixmap(icon.pixmap(32, 32));
QString introMessage(tr("Enter username and password for \"%1\" at %2")
- .arg(auth->realm())
- .arg(requestUrl.toString().toHtmlEscaped()));
+ .arg(auth->realm(),
+ requestUrl.toString().toHtmlEscaped()));
passwordDialog.m_infoLabel->setText(introMessage);
passwordDialog.m_infoLabel->setWordWrap(true);