Merge "Merge remote-tracking branch 'origin/7.0'"

This commit is contained in:
The Qt Project
2022-04-22 08:30:05 +00:00
23 changed files with 341 additions and 492 deletions

View File

@@ -3973,10 +3973,18 @@ void ExtraHighlightingResultsCollector::collectFromNode(const AstNode &node)
QString detail = node.detail().value_or(QString());
const bool isCallToNew = node.kind() == "CXXNew";
const bool isCallToDelete = node.kind() == "CXXDelete";
if (!isCallToNew && !isCallToDelete
&& (!detail.startsWith(operatorPrefix) || detail == operatorPrefix)) {
const auto isProperOperator = [&] {
if (isCallToNew || isCallToDelete)
return true;
if (!detail.startsWith(operatorPrefix))
return false;
if (detail == operatorPrefix)
return false;
const QChar nextChar = detail.at(operatorPrefix.length());
return !nextChar.isLetterOrNumber() && nextChar != '_';
};
if (!isProperOperator())
return;
}
if (!isCallToNew && !isCallToDelete)
detail.remove(0, operatorPrefix.length());

View File

@@ -1329,6 +1329,14 @@ void ClangdTestHighlighting::test_data()
<< QList<int>{C_FIELD} << 0;
QTest::newRow("pass inherited member by value") << 1038 << 21 << 1038 << 26
<< QList<int>{C_FIELD} << 0;
QTest::newRow("fake operator member declaration") << 1045 << 9 << 1045 << 23
<< QList<int>{C_FIELD, C_DECLARATION} << 0;
QTest::newRow("fake operator method declaration") << 1046 << 10 << 1046 << 24
<< QList<int>{C_FUNCTION, C_DECLARATION} << 0;
QTest::newRow("fake operator member access") << 1049 << 8 << 1049 << 22
<< QList<int>{C_FIELD} << 0;
QTest::newRow("fake operator method call") << 1050 << 8 << 1050 << 22
<< QList<int>{C_FUNCTION} << 0;
}
void ClangdTestHighlighting::test()

View File

@@ -1040,3 +1040,12 @@ template<typename T> class Derived2 : public BaseWithMember2
return false;
}
};
struct StructWithMisleadingMemberNames {
int operatormember;
void operatorMethod();
};
void useStrangeStruct(StructWithMisleadingMemberNames *s) {
s->operatormember = 5;
s->operatorMethod();
}

View File

@@ -5302,7 +5302,17 @@ void TextEditorWidgetPrivate::clearVisibleFoldedBlock()
void TextEditorWidget::mouseMoveEvent(QMouseEvent *e)
{
d->requestUpdateLink(e);
d->m_linkPressed = false;
bool onLink = false;
if (d->m_linkPressed && d->m_currentLink.hasValidTarget()) {
const int eventCursorPosition = cursorForPosition(e->pos()).position();
if (eventCursorPosition < d->m_currentLink.linkTextStart
|| eventCursorPosition > d->m_currentLink.linkTextEnd) {
d->m_linkPressed = false;
} else {
onLink = true;
}
}
static Utils::optional<MultiTextCursor> startMouseMoveCursor;
if (e->buttons() == Qt::LeftButton && e->modifiers() & Qt::AltModifier) {
@@ -5363,7 +5373,8 @@ void TextEditorWidget::mouseMoveEvent(QMouseEvent *e)
d->m_mouseOnFoldedMarker = false;
viewport()->setCursor(Qt::IBeamCursor);
}
} else {
} else if (!onLink || e->buttons() != Qt::LeftButton
|| e->modifiers() != Qt::ControlModifier) {
QPlainTextEdit::mouseMoveEvent(e);
}
}

View File

@@ -3,6 +3,10 @@ add_qtc_plugin(UpdateInfo
PLUGIN_DEPENDS Core
PLUGIN_JSON_IN UPDATEINFO_EXPERIMENTAL_STR=true
SOURCES
settingspage.cpp settingspage.h settingspage.ui
updateinfoplugin.cpp updateinfoplugin.h
settingspage.cpp
settingspage.h
settingspage.ui
updateinfoplugin.cpp
updateinfoplugin.h
updateinfotools.h
)

View File

@@ -12,10 +12,11 @@ QtcPlugin {
pluginJsonReplacements: ({"UPDATEINFO_EXPERIMENTAL_STR": (enable ? "false": "true")})
files: [
"updateinfoplugin.cpp",
"updateinfoplugin.h",
"settingspage.cpp",
"settingspage.h",
"settingspage.ui",
"updateinfoplugin.cpp",
"updateinfoplugin.h",
"updateinfotools.h",
]
}

View File

@@ -23,9 +23,11 @@
**
****************************************************************************/
#include "settingspage.h"
#include "updateinfoplugin.h"
#include "settingspage.h"
#include "updateinfotools.h"
#include <coreplugin/actionmanager/actioncontainer.h>
#include <coreplugin/actionmanager/actionmanager.h>
#include <coreplugin/coreconstants.h>
@@ -181,107 +183,6 @@ void UpdateInfoPlugin::collectCheckForUpdatesOutput(const QString &contents)
d->m_collectedOutput += contents;
}
struct Update
{
QString name;
QString version;
};
static QList<Update> availableUpdates(const QDomDocument &document)
{
if (document.isNull() || !document.firstChildElement().hasChildNodes())
return {};
QList<Update> result;
const QDomNodeList updates = document.firstChildElement().elementsByTagName("update");
for (int i = 0; i < updates.size(); ++i) {
const QDomNode node = updates.item(i);
if (node.isElement()) {
const QDomElement element = node.toElement();
if (element.hasAttribute("name"))
result.append({element.attribute("name"), element.attribute("version")});
}
}
return result;
}
struct QtPackage
{
QString displayName;
QVersionNumber version;
bool installed;
bool isPrerelease = false;
};
static QList<QtPackage> availableQtPackages(const QDomDocument &document)
{
if (document.isNull() || !document.firstChildElement().hasChildNodes())
return {};
QList<QtPackage> result;
const QDomNodeList packages = document.firstChildElement().elementsByTagName("package");
for (int i = 0; i < packages.size(); ++i) {
const QDomNode node = packages.item(i);
if (node.isElement()) {
const QDomElement element = node.toElement();
if (element.hasAttribute("displayname") && element.hasAttribute("name")
&& element.hasAttribute("version")) {
QtPackage package{element.attribute("displayname"),
QVersionNumber::fromString(element.attribute("version")),
element.hasAttribute("installedVersion")};
// Heuristic: Prerelease if the name is not "Qt x.y.z"
// (prereleases are named "Qt x.y.z-alpha" etc)
package.isPrerelease = package.displayName
!= QString("Qt %1").arg(package.version.toString());
result.append(package);
}
}
}
std::sort(result.begin(), result.end(), [](const QtPackage &p1, const QtPackage &p2) {
return p1.version > p2.version;
});
return result;
}
// Expects packages to be sorted, high version first.
static Utils::optional<QtPackage> highestInstalledQt(const QList<QtPackage> &packages)
{
const auto highestInstalledIt = std::find_if(packages.cbegin(),
packages.cend(),
[](const QtPackage &p) { return p.installed; });
if (highestInstalledIt == packages.cend()) // Qt not installed
return {};
return *highestInstalledIt;
}
// Expects packages to be sorted, high version first.
static Utils::optional<QtPackage> qtToNagAbout(const QList<QtPackage> &allPackages,
QVersionNumber *highestSeen)
{
// Filter out any Qt prereleases
const QList<QtPackage> packages = Utils::filtered(allPackages, [](const QtPackage &p) {
return !p.isPrerelease;
});
if (packages.isEmpty())
return {};
const QtPackage highest = packages.constFirst();
qCDebug(log) << "Highest available (non-prerelease) Qt:" << highest.version;
qCDebug(log) << "Highest previously seen (non-prerelease) Qt:" << *highestSeen;
// if the highestSeen version is null, we don't know if the Qt version is new, and better don't nag
const bool isNew = !highestSeen->isNull() && highest.version > *highestSeen;
if (highestSeen->isNull() || isNew)
*highestSeen = highest.version;
if (!isNew)
return {};
const Utils::optional<QtPackage> highestInstalled = highestInstalledQt(packages);
qCDebug(log) << "Highest installed Qt:"
<< qPrintable(highestInstalled ? highestInstalled->version.toString()
: QString("none"));
if (!highestInstalled) // don't nag if no Qt is installed at all
return {};
if (highestInstalled->version == highest.version)
return {};
return highest;
}
static void showUpdateInfo(const QList<Update> &updates, const std::function<void()> &startUpdater)
{
Utils::InfoBarEntry info(InstallUpdates,
@@ -334,20 +235,14 @@ void UpdateInfoPlugin::checkForUpdatesFinished()
{
setLastCheckDate(QDate::currentDate());
QDomDocument document;
// since the output can contain two toplevel items from the two separate MaintenanceTool runs,
// surround with a toplevel element
const QString xml = d->m_collectedOutput.isEmpty()
? QString()
: ("<doc>" + d->m_collectedOutput + "</doc>");
qCDebug(log) << "--- MaintenanceTool output (combined):";
qCDebug(log) << qPrintable(xml);
document.setContent(xml);
qCDebug(log) << qPrintable(d->m_collectedOutput);
std::unique_ptr<QDomDocument> document = documentForResponse(d->m_collectedOutput);
stopCheckForUpdates();
const QList<Update> updates = availableUpdates(document);
const QList<QtPackage> qtPackages = availableQtPackages(document);
const QList<Update> updates = availableUpdates(*document);
const QList<QtPackage> qtPackages = availableQtPackages(*document);
if (log().isDebugEnabled()) {
qCDebug(log) << "--- Available updates:";
for (const Update &u : updates)

View File

@@ -0,0 +1,167 @@
/****************************************************************************
**
** Copyright (C) 2022 the Qt Company Ltd.
** Contact: https://www.qt.io/licensing/
**
** This file is part of Qt Creator.
**
** 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.
**
** GNU General Public License Usage
** Alternatively, this file may be used under the terms of the GNU
** General Public License version 3 as published by the Free Software
** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
** included in the packaging of this file. Please review the following
** information to ensure the GNU General Public License requirements will
** be met: https://www.gnu.org/licenses/gpl-3.0.html.
**
****************************************************************************/
#pragma once
#include <utils/algorithm.h>
#include <utils/optional.h>
#include <QDomDocument>
#include <QList>
#include <QLoggingCategory>
#include <QRegularExpression>
#include <QVersionNumber>
#include <memory>
Q_DECLARE_LOGGING_CATEGORY(log)
std::unique_ptr<QDomDocument> documentForResponse(const QString &response)
{
// since the output can contain two toplevel items from the two separate MaintenanceTool runs,
// clean up any <?xml version="1.0"?> and surround with a toplevel element
QString responseWithoutHeader = response;
responseWithoutHeader.remove(QRegularExpression("<\\?xml.*\\?>"));
const QString xml = response.isEmpty() ? QString()
: ("<doc>" + responseWithoutHeader + "</doc>");
std::unique_ptr<QDomDocument> doc(new QDomDocument);
doc->setContent(xml);
return doc;
}
struct Update
{
QString name;
QString version;
bool operator==(const Update &other) const
{
return other.name == name && other.version == version;
};
};
QList<Update> availableUpdates(const QDomDocument &document)
{
if (document.isNull() || !document.firstChildElement().hasChildNodes())
return {};
QList<Update> result;
const QDomNodeList updates = document.firstChildElement().elementsByTagName("update");
for (int i = 0; i < updates.size(); ++i) {
const QDomNode node = updates.item(i);
if (node.isElement()) {
const QDomElement element = node.toElement();
if (element.hasAttribute("name"))
result.append({element.attribute("name"), element.attribute("version")});
}
}
return result;
}
struct QtPackage
{
QString displayName;
QVersionNumber version;
bool installed;
bool isPrerelease = false;
bool operator==(const QtPackage &other) const
{
return other.installed == installed && other.isPrerelease == isPrerelease
&& other.version == version && other.displayName == displayName;
}
};
QList<QtPackage> availableQtPackages(const QDomDocument &document)
{
if (document.isNull() || !document.firstChildElement().hasChildNodes())
return {};
QList<QtPackage> result;
const QDomNodeList packages = document.firstChildElement().elementsByTagName("package");
for (int i = 0; i < packages.size(); ++i) {
const QDomNode node = packages.item(i);
if (node.isElement()) {
const QDomElement element = node.toElement();
if (element.hasAttribute("displayname") && element.hasAttribute("name")
&& element.hasAttribute("version")) {
QtPackage package{element.attribute("displayname"),
QVersionNumber::fromString(element.attribute("version")),
element.hasAttribute("installedVersion")};
// Heuristic: Prerelease if the name is not "Qt x.y.z"
// (prereleases are named "Qt x.y.z-alpha" etc)
package.isPrerelease = package.displayName
!= QString("Qt %1").arg(package.version.toString());
result.append(package);
}
}
}
std::sort(result.begin(), result.end(), [](const QtPackage &p1, const QtPackage &p2) {
return p1.version > p2.version;
});
return result;
}
// Expects packages to be sorted, high version first.
Utils::optional<QtPackage> highestInstalledQt(const QList<QtPackage> &packages)
{
const auto highestInstalledIt = std::find_if(packages.cbegin(),
packages.cend(),
[](const QtPackage &p) { return p.installed; });
if (highestInstalledIt == packages.cend()) // Qt not installed
return {};
return *highestInstalledIt;
}
// Expects packages to be sorted, high version first.
Utils::optional<QtPackage> qtToNagAbout(const QList<QtPackage> &allPackages,
QVersionNumber *highestSeen)
{
// Filter out any Qt prereleases
const QList<QtPackage> packages = Utils::filtered(allPackages, [](const QtPackage &p) {
return !p.isPrerelease;
});
if (packages.isEmpty())
return {};
const QtPackage highest = packages.constFirst();
qCDebug(log) << "Highest available (non-prerelease) Qt:" << highest.version;
qCDebug(log) << "Highest previously seen (non-prerelease) Qt:" << *highestSeen;
// if the highestSeen version is null, we don't know if the Qt version is new, and better don't nag
const bool isNew = !highestSeen->isNull() && highest.version > *highestSeen;
if (highestSeen->isNull() || isNew)
*highestSeen = highest.version;
if (!isNew)
return {};
const Utils::optional<QtPackage> highestInstalled = highestInstalledQt(packages);
qCDebug(log) << "Highest installed Qt:"
<< qPrintable(highestInstalled ? highestInstalled->version.toString()
: QString("none"));
if (!highestInstalled) // don't nag if no Qt is installed at all
return {};
if (highestInstalled->version == highest.version)
return {};
return highest;
}
Q_DECLARE_METATYPE(Update)
Q_DECLARE_METATYPE(QtPackage)