diff options
Diffstat (limited to 'src/widgets/widgets/qtextbrowser.cpp')
-rw-r--r-- | src/widgets/widgets/qtextbrowser.cpp | 53 |
1 files changed, 31 insertions, 22 deletions
diff --git a/src/widgets/widgets/qtextbrowser.cpp b/src/widgets/widgets/qtextbrowser.cpp index 2bab2efc61..2c01ed2b26 100644 --- a/src/widgets/widgets/qtextbrowser.cpp +++ b/src/widgets/widgets/qtextbrowser.cpp @@ -46,6 +46,11 @@ public: , lastKeypadScrollValue(-1) #endif {} + ~QTextBrowserPrivate() + { + for (const QMetaObject::Connection &connection : connections) + QObject::disconnect(connection); + } void init(); @@ -64,13 +69,13 @@ public: HistoryEntry history(int i) const { if (i <= 0) - if (-i < stack.count()) - return stack[stack.count()+i-1]; + if (-i < stack.size()) + return stack[stack.size()+i-1]; else return HistoryEntry(); else - if (i <= forwardStack.count()) - return forwardStack[forwardStack.count()-i]; + if (i <= forwardStack.size()) + return forwardStack[forwardStack.size()-i]; else return HistoryEntry(); } @@ -103,14 +108,14 @@ public: QString findFile(const QUrl &name) const; - inline void _q_documentModified() + inline void documentModified() { textOrSourceChanged = true; forceLoadOnSourceChange = !currentURL.path().isEmpty(); } - void _q_activateAnchor(const QString &href); - void _q_highlightLink(const QString &href); + void activateAnchor(const QString &href); + void highlightLink(const QString &href); void setSource(const QUrl &url, QTextDocument::ResourceType type); @@ -129,6 +134,7 @@ public: Q_Q(QTextBrowser); emit q->highlighted(url); } + std::array<QMetaObject::Connection, 3> connections; }; Q_DECLARE_TYPEINFO(QTextBrowserPrivate::HistoryEntry, Q_RELOCATABLE_TYPE); @@ -154,7 +160,7 @@ QString QTextBrowserPrivate::findFile(const QUrl &name) const if (QFileInfo(fileName).isAbsolute()) return fileName; - for (QString path : qAsConst(searchPaths)) { + for (QString path : std::as_const(searchPaths)) { if (!path.endsWith(u'/')) path.append(u'/'); path.append(fileName); @@ -190,7 +196,7 @@ QUrl QTextBrowserPrivate::resolveUrl(const QUrl &url) const return url; } -void QTextBrowserPrivate::_q_activateAnchor(const QString &href) +void QTextBrowserPrivate::activateAnchor(const QString &href) { if (href.isEmpty()) return; @@ -231,7 +237,7 @@ void QTextBrowserPrivate::_q_activateAnchor(const QString &href) q->setSource(url); } -void QTextBrowserPrivate::_q_highlightLink(const QString &anchor) +void QTextBrowserPrivate::highlightLink(const QString &anchor) { if (anchor.isEmpty()) { #ifndef QT_NO_CURSOR @@ -670,11 +676,14 @@ void QTextBrowserPrivate::init() q->setAttribute(Qt::WA_InputMethodEnabled, shouldEnableInputMethod(q)); q->setUndoRedoEnabled(false); viewport->setMouseTracking(true); - QObject::connect(q->document(), SIGNAL(contentsChanged()), q, SLOT(_q_documentModified())); - QObject::connect(control, SIGNAL(linkActivated(QString)), - q, SLOT(_q_activateAnchor(QString))); - QObject::connect(control, SIGNAL(linkHovered(QString)), - q, SLOT(_q_highlightLink(QString))); + connections = { + QObjectPrivate::connect(q->document(), &QTextDocument::contentsChanged, + this, &QTextBrowserPrivate::documentModified), + QObjectPrivate::connect(control, &QWidgetTextControl::linkActivated, + this, &QTextBrowserPrivate::activateAnchor), + QObjectPrivate::connect(control, &QWidgetTextControl::linkHovered, + this, &QTextBrowserPrivate::highlightLink), + }; } /*! @@ -828,11 +837,11 @@ void QTextBrowser::doSetSource(const QUrl &url, QTextDocument::ResourceType type entry.vpos = 0; d->stack.push(entry); - emit backwardAvailable(d->stack.count() > 1); + emit backwardAvailable(d->stack.size() > 1); if (!d->forwardStack.isEmpty() && d->forwardStack.top().url == url) { d->forwardStack.pop(); - emit forwardAvailable(d->forwardStack.count() > 0); + emit forwardAvailable(d->forwardStack.size() > 0); } else { d->forwardStack.clear(); emit forwardAvailable(false); @@ -906,14 +915,14 @@ void QTextBrowser::doSetSource(const QUrl &url, QTextDocument::ResourceType type void QTextBrowser::backward() { Q_D(QTextBrowser); - if (d->stack.count() <= 1) + if (d->stack.size() <= 1) return; // Update the history entry d->forwardStack.push(d->createHistoryEntry()); d->stack.pop(); // throw away the old version of the current entry d->restoreHistoryEntry(d->stack.top()); // previous entry - emit backwardAvailable(d->stack.count() > 1); + emit backwardAvailable(d->stack.size() > 1); emit forwardAvailable(true); emit historyChanged(); } @@ -1156,7 +1165,7 @@ QVariant QTextBrowser::loadResource(int /*type*/, const QUrl &name) bool QTextBrowser::isBackwardAvailable() const { Q_D(const QTextBrowser); - return d->stack.count() > 1; + return d->stack.size() > 1; } /*! @@ -1243,7 +1252,7 @@ QString QTextBrowser::historyTitle(int i) const int QTextBrowser::forwardHistoryCount() const { Q_D(const QTextBrowser); - return d->forwardStack.count(); + return d->forwardStack.size(); } /*! @@ -1254,7 +1263,7 @@ int QTextBrowser::forwardHistoryCount() const int QTextBrowser::backwardHistoryCount() const { Q_D(const QTextBrowser); - return d->stack.count()-1; + return d->stack.size()-1; } /*! |