From 0b65f3ca378810d3b33345b99bf084124acf3e5f Mon Sep 17 00:00:00 2001 From: Pierre Rossi Date: Thu, 11 Jun 2015 14:06:13 +0200 Subject: Last minute API review cleanup The getters in QWebEngineDownloadItem were not const. The script collection in QWebEngineProfile was passed by reference, which is not idiomatic of Qt. Change-Id: I9b4218b407288b91a726a711bd2a7e1c1167d99a Reviewed-by: Andras Becsi --- .../browser/browserapplication.cpp | 6 ++--- .../api/qwebenginedownloaditem.cpp | 28 +++++++++++----------- src/webenginewidgets/api/qwebenginedownloaditem.h | 14 +++++------ src/webenginewidgets/api/qwebengineprofile.cpp | 10 ++++---- src/webenginewidgets/api/qwebengineprofile.h | 2 +- src/webenginewidgets/api/qwebengineprofile_p.h | 3 ++- .../api/qwebenginescriptcollection.h | 1 + 7 files changed, 33 insertions(+), 31 deletions(-) diff --git a/examples/webenginewidgets/browser/browserapplication.cpp b/examples/webenginewidgets/browser/browserapplication.cpp index 8961bf7fb..ca28b2d0b 100644 --- a/examples/webenginewidgets/browser/browserapplication.cpp +++ b/examples/webenginewidgets/browser/browserapplication.cpp @@ -83,11 +83,11 @@ static void setUserStyleSheet(QWebEngineProfile *profile, const QString &styleSh Q_ASSERT(profile); QString scriptName(QStringLiteral("userStyleSheet")); QWebEngineScript script; - QList styleSheets = profile->scripts().findScripts(scriptName); + QList styleSheets = profile->scripts()->findScripts(scriptName); if (!styleSheets.isEmpty()) script = styleSheets.first(); Q_FOREACH (const QWebEngineScript &s, styleSheets) - profile->scripts().remove(s); + profile->scripts()->remove(s); if (script.isNull()) { script.setName(scriptName); @@ -106,7 +106,7 @@ static void setUserStyleSheet(QWebEngineProfile *profile, const QString &styleSh "css.innerText = \"%1\";"\ "})()").arg(styleSheet); script.setSourceCode(source); - profile->scripts().insert(script); + profile->scripts()->insert(script); // run the script on the already loaded views // this has to be deferred as it could mess with the storage initialization on startup if (mainWindow) diff --git a/src/webenginewidgets/api/qwebenginedownloaditem.cpp b/src/webenginewidgets/api/qwebenginedownloaditem.cpp index 703570587..7df044e66 100644 --- a/src/webenginewidgets/api/qwebenginedownloaditem.cpp +++ b/src/webenginewidgets/api/qwebenginedownloaditem.cpp @@ -156,9 +156,9 @@ void QWebEngineDownloadItem::cancel() Returns the download item's id. */ -quint32 QWebEngineDownloadItem::id() +quint32 QWebEngineDownloadItem::id() const { - Q_D(QWebEngineDownloadItem); + Q_D(const QWebEngineDownloadItem); return d->downloadId; } @@ -205,9 +205,9 @@ quint32 QWebEngineDownloadItem::id() \sa QWebEngineDownloadItem::DownloadState */ -QWebEngineDownloadItem::DownloadState QWebEngineDownloadItem::state() +QWebEngineDownloadItem::DownloadState QWebEngineDownloadItem::state() const { - Q_D(QWebEngineDownloadItem); + Q_D(const QWebEngineDownloadItem); return d->downloadState; } @@ -217,9 +217,9 @@ QWebEngineDownloadItem::DownloadState QWebEngineDownloadItem::state() -1 means the size is unknown. */ -qint64 QWebEngineDownloadItem::totalBytes() +qint64 QWebEngineDownloadItem::totalBytes() const { - Q_D(QWebEngineDownloadItem); + Q_D(const QWebEngineDownloadItem); return d->totalBytes; } @@ -229,9 +229,9 @@ qint64 QWebEngineDownloadItem::totalBytes() -1 means the size is unknown. */ -qint64 QWebEngineDownloadItem::receivedBytes() +qint64 QWebEngineDownloadItem::receivedBytes() const { - Q_D(QWebEngineDownloadItem); + Q_D(const QWebEngineDownloadItem); return d->receivedBytes; } @@ -239,9 +239,9 @@ qint64 QWebEngineDownloadItem::receivedBytes() Returns the download's origin url. */ -QUrl QWebEngineDownloadItem::url() +QUrl QWebEngineDownloadItem::url() const { - Q_D(QWebEngineDownloadItem); + Q_D(const QWebEngineDownloadItem); return d->downloadUrl; } @@ -252,9 +252,9 @@ QUrl QWebEngineDownloadItem::url() and file name is deduced not to overwrite already existing files. */ -QString QWebEngineDownloadItem::path() +QString QWebEngineDownloadItem::path() const { - Q_D(QWebEngineDownloadItem); + Q_D(const QWebEngineDownloadItem); return d->downloadPath; } @@ -282,9 +282,9 @@ void QWebEngineDownloadItem::setPath(QString path) \sa finished(), state(), */ -bool QWebEngineDownloadItem::isFinished() +bool QWebEngineDownloadItem::isFinished() const { - Q_D(QWebEngineDownloadItem); + Q_D(const QWebEngineDownloadItem); return d->downloadFinished; } diff --git a/src/webenginewidgets/api/qwebenginedownloaditem.h b/src/webenginewidgets/api/qwebenginedownloaditem.h index ee3ab221d..d362131f2 100644 --- a/src/webenginewidgets/api/qwebenginedownloaditem.h +++ b/src/webenginewidgets/api/qwebenginedownloaditem.h @@ -61,14 +61,14 @@ public: }; Q_ENUMS(DownloadState) - quint32 id(); - DownloadState state(); - qint64 totalBytes(); - qint64 receivedBytes(); - QUrl url(); - QString path(); + quint32 id() const; + DownloadState state() const; + qint64 totalBytes() const; + qint64 receivedBytes() const; + QUrl url() const; + QString path() const; void setPath(QString path); - bool isFinished(); + bool isFinished() const; public Q_SLOTS: void accept(); diff --git a/src/webenginewidgets/api/qwebengineprofile.cpp b/src/webenginewidgets/api/qwebengineprofile.cpp index adccfca2a..2e5f685fd 100644 --- a/src/webenginewidgets/api/qwebengineprofile.cpp +++ b/src/webenginewidgets/api/qwebengineprofile.cpp @@ -103,8 +103,8 @@ using QtWebEngineCore::BrowserContextAdapter; */ QWebEngineProfilePrivate::QWebEngineProfilePrivate(BrowserContextAdapter* browserContext) - : scriptCollection(new QWebEngineScriptCollectionPrivate(browserContext->userScriptController())) - , m_settings(new QWebEngineSettings()) + : m_settings(new QWebEngineSettings()) + , m_scriptCollection(new QWebEngineScriptCollection(new QWebEngineScriptCollectionPrivate(browserContext->userScriptController()))) , m_browserContextRef(browserContext) { m_browserContextRef->addClient(this); @@ -438,10 +438,10 @@ bool QWebEngineProfile::visitedLinksContainsUrl(const QUrl &url) const Returns the script collection used by this profile. \sa QWebEngineScriptCollection */ -QWebEngineScriptCollection &QWebEngineProfile::scripts() +QWebEngineScriptCollection *QWebEngineProfile::scripts() const { - Q_D(QWebEngineProfile); - return d->scriptCollection; + Q_D(const QWebEngineProfile); + return d->m_scriptCollection.data(); } /*! diff --git a/src/webenginewidgets/api/qwebengineprofile.h b/src/webenginewidgets/api/qwebengineprofile.h index d65db24ab..4308fe75d 100644 --- a/src/webenginewidgets/api/qwebengineprofile.h +++ b/src/webenginewidgets/api/qwebengineprofile.h @@ -98,7 +98,7 @@ public: bool visitedLinksContainsUrl(const QUrl &url) const; QWebEngineSettings *settings() const; - QWebEngineScriptCollection &scripts(); + QWebEngineScriptCollection *scripts() const; static QWebEngineProfile *defaultProfile(); diff --git a/src/webenginewidgets/api/qwebengineprofile_p.h b/src/webenginewidgets/api/qwebengineprofile_p.h index b0bfc88b9..55941580d 100644 --- a/src/webenginewidgets/api/qwebengineprofile_p.h +++ b/src/webenginewidgets/api/qwebengineprofile_p.h @@ -43,6 +43,7 @@ #include "qwebenginescriptcollection.h" #include #include +#include namespace QtWebEngineCore { class BrowserContextAdapter; @@ -72,10 +73,10 @@ public: void removeUrlSchemeHandler(QWebEngineUrlSchemeHandler *); void clearUrlSchemeHandlers(); - QWebEngineScriptCollection scriptCollection; private: QWebEngineProfile *q_ptr; QWebEngineSettings *m_settings; + QScopedPointer m_scriptCollection; QExplicitlySharedDataPointer m_browserContextRef; QMap > m_ongoingDownloads; QMap > m_urlSchemeHandlers; diff --git a/src/webenginewidgets/api/qwebenginescriptcollection.h b/src/webenginewidgets/api/qwebenginescriptcollection.h index 5ef9c55c7..fe3ce2861 100644 --- a/src/webenginewidgets/api/qwebenginescriptcollection.h +++ b/src/webenginewidgets/api/qwebenginescriptcollection.h @@ -67,6 +67,7 @@ public: QList toList() const; private: + Q_DISABLE_COPY(QWebEngineScriptCollection) friend class QWebEnginePagePrivate; friend class QWebEngineProfilePrivate; QWebEngineScriptCollection(QWebEngineScriptCollectionPrivate *); -- cgit v1.2.3