CppTools: Fix QStringRef and QSharedPointer related issues with Qt6

Task-number: QTCREATORBUG-24098
Change-Id: I97347ac3fb397fea8eee655e3cc4ee252c511885
Reviewed-by: hjk <hjk@qt.io>
This commit is contained in:
Eike Ziller
2020-09-15 15:27:32 +02:00
parent 432247357e
commit 242579099a
10 changed files with 26 additions and 16 deletions

View File

@@ -528,7 +528,7 @@ void CodeFormatter::recalculateStateAfter(const QTextBlock &block)
}
}
QStringRef tokenText = currentTokenText();
QStringView tokenText = currentTokenText();
if (tokenText == QLatin1String("ifdef")
|| tokenText == QLatin1String("if")
|| tokenText == QLatin1String("ifndef")) {
@@ -854,7 +854,7 @@ bool CodeFormatter::tryDeclaration()
return true;
case T_IDENTIFIER:
if (m_tokenIndex == 0) {
const QStringRef tokenText = currentTokenText();
const QStringView tokenText = currentTokenText();
if (tokenText.startsWith(QLatin1String("Q_"))
|| tokenText.startsWith(QLatin1String("QT_"))
|| tokenText.startsWith(QLatin1String("QML_"))
@@ -1009,9 +1009,11 @@ int CodeFormatter::column(int index) const
return col;
}
QStringRef CodeFormatter::currentTokenText() const
QStringView CodeFormatter::currentTokenText() const
{
return m_currentLine.midRef(m_currentToken.utf16charsBegin(), m_currentToken.utf16chars());
if (m_currentToken.utf16charsEnd() > m_currentLine.size())
return QStringView(m_currentLine).mid(m_currentToken.utf16charsBegin());
return QStringView(m_currentLine).mid(m_currentToken.utf16charsBegin(), m_currentToken.utf16chars());
}
void CodeFormatter::turnInto(int newState)

View File

@@ -216,7 +216,7 @@ private:
void saveCurrentState(const QTextBlock &block);
void restoreCurrentState(const QTextBlock &block);
QStringRef currentTokenText() const;
QStringView currentTokenText() const;
int tokenizeBlock(const QTextBlock &block, bool *endedJoined = nullptr);

View File

@@ -880,9 +880,12 @@ bool InternalCppCompletionAssistProcessor::accepts() const
&& tokens.at(1).kind() == T_IDENTIFIER) {
const QString &line = tc.block().text();
const Token &idToken = tokens.at(1);
const QStringRef &identifier =
line.midRef(idToken.utf16charsBegin(),
idToken.utf16charsEnd() - idToken.utf16charsBegin());
const QStringView &identifier = idToken.utf16charsEnd() > line.size()
? QStringView(line).mid(
idToken.utf16charsBegin())
: QStringView(line)
.mid(idToken.utf16charsBegin(),
idToken.utf16chars());
if (identifier == QLatin1String("include")
|| identifier == QLatin1String("include_next")
|| (m_interface->languageFeatures().objCEnabled && identifier == QLatin1String("import"))) {

View File

@@ -101,7 +101,7 @@ QList<Core::LocatorFilterEntry> CppLocatorFilter::matchesFor(
// Highlight the matched characters, therefore it may be necessary
// to update the match if the displayName is different from matchString
if (matchString.midRef(matchOffset) != filterEntry.displayName) {
if (QStringView(matchString).mid(matchOffset) != filterEntry.displayName) {
match = shortRegexp.match(filterEntry.displayName);
matchOffset = 0;
}

View File

@@ -132,7 +132,7 @@ QVariant SymbolItem::data(int /*column*/, int role) const
bool OverviewModel::hasDocument() const
{
return _cppDocument;
return !_cppDocument.isNull();
}
int OverviewModel::globalSymbolCount() const

View File

@@ -55,7 +55,7 @@ CppTools::ProjectPart::Ptr projectPartForFile(const QString &filePath)
bool isProjectPartValid(const CppTools::ProjectPart::Ptr projectPart)
{
if (projectPart)
return CppTools::CppModelManager::instance()->projectPartForId(projectPart->id());
return !CppTools::CppModelManager::instance()->projectPartForId(projectPart->id()).isNull();
return false;
}