summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorVolker Hilsheimer <volker.hilsheimer@qt.io>2021-02-25 14:19:34 +0100
committerQt CI Bot <qt_ci_bot@qt-project.org>2021-03-02 13:58:43 +0000
commitf28088873e955f599e585c7dc732ffc93bebe782 (patch)
treeec97fc66d919bae7bf8589f6f23c1844535b53cb /src
parent9d80deb92f066dba6c2bfce98f5cc83304026c2b (diff)
parente718818745e6db8df09ea55c4071e116f00851c9 (diff)
Merge "QLabel: simplify createStandardContextMenu"
Diffstat (limited to 'src')
-rw-r--r--src/corelib/text/qstring.cpp13
-rw-r--r--src/widgets/widgets/qlabel.cpp13
2 files changed, 12 insertions, 14 deletions
diff --git a/src/corelib/text/qstring.cpp b/src/corelib/text/qstring.cpp
index a6f3cd2b5d..390c10e1fc 100644
--- a/src/corelib/text/qstring.cpp
+++ b/src/corelib/text/qstring.cpp
@@ -6342,9 +6342,9 @@ namespace QUnicodeTables {
\endlist
In copy-convert mode, the local variable \c{s} is detached from the input
- \a str. In the in-place convert mode, \a str is in moved-from state (which
- this function requires to be a valid, empty string) and \c{s} contains the
- only copy of the string, without reallocation (thus, \a it is still valid).
+ \a str. In the in-place convert mode, \a str is in moved-from state and
+ \c{s} contains the only copy of the string, without reallocation (thus,
+ \a it is still valid).
There is one pathological case left: when the in-place conversion needs to
reallocate memory to grow the buffer. In that case, we need to adjust the \a
@@ -6355,7 +6355,7 @@ Q_NEVER_INLINE
static QString detachAndConvertCase(T &str, QStringIterator it, QUnicodeTables::Case which)
{
Q_ASSERT(!str.isEmpty());
- QString s = std::move(str); // will copy if T is const QString
+ QString s = std::move(str); // will copy if T is const QString
QChar *pp = s.begin() + it.index(); // will detach if necessary
do {
@@ -6374,9 +6374,8 @@ static QString detachAndConvertCase(T &str, QStringIterator it, QUnicodeTables::
s.replace(outpos, 1, reinterpret_cast<const QChar *>(folded.data()), folded.size());
pp = const_cast<QChar *>(s.constBegin()) + outpos + folded.size();
- // do we need to adjust the input iterator too?
- // if it is pointing to s's data, str is empty
- if (str.isEmpty())
+ // Adjust the input iterator if we are performing an in-place conversion
+ if constexpr (!std::is_const<T>::value)
it = QStringIterator(s.constBegin(), inpos + folded.size(), s.constEnd());
}
} else {
diff --git a/src/widgets/widgets/qlabel.cpp b/src/widgets/widgets/qlabel.cpp
index 2d7b7f79b1..189a7488d3 100644
--- a/src/widgets/widgets/qlabel.cpp
+++ b/src/widgets/widgets/qlabel.cpp
@@ -1694,14 +1694,13 @@ QPoint QLabelPrivate::layoutPoint(const QPoint& p) const
#ifndef QT_NO_CONTEXTMENU
QMenu *QLabelPrivate::createStandardContextMenu(const QPoint &pos)
{
- QString linkToCopy;
- QPoint p;
- if (control && effectiveTextFormat != Qt::PlainText) {
- p = layoutPoint(pos);
- linkToCopy = control->document()->documentLayout()->anchorAt(p);
- }
+ if (!control || effectiveTextFormat == Qt::PlainText)
+ return nullptr;
+
+ const QPoint p = layoutPoint(pos);
+ QString linkToCopy = control->document()->documentLayout()->anchorAt(p);
- if (linkToCopy.isEmpty() && !control)
+ if (linkToCopy.isEmpty())
return nullptr;
return control->createStandardContextMenu(p, q_func());