Utils: Fix build with Qt6

Do not use QStringRef related API, replace with QStringView where
appropriate.

Adapt to removal of QAbstractItemView::viewOptions().

Task-number: QTCREATORBUG-24098
Change-Id: I5a7a9821984583222083733f91b46df39c21d592
Reviewed-by: hjk <hjk@qt.io>
This commit is contained in:
Eike Ziller
2020-09-07 10:08:59 +02:00
parent 3dd224c466
commit 7e8c3e91a1
10 changed files with 30 additions and 20 deletions

View File

@@ -1,6 +1,8 @@
add_qtc_library(Utils add_qtc_library(Utils
DEPENDS Qt5::Xml DEPENDS Qt5::Xml
PUBLIC_DEPENDS Qt5::Concurrent Qt5::Core Qt5::Network Qt5::Qml Qt5::Gui Qt5::Widgets PUBLIC_DEPENDS
Qt5::Concurrent Qt5::Core Qt5::Network Qt5::Qml Qt5::Gui Qt5::Widgets
Qt6Core5Compat
DEFINES DEFINES
"QTC_REL_TOOLS_PATH=\"${RELATIVE_LIBEXEC_PATH}\"" "QTC_REL_TOOLS_PATH=\"${RELATIVE_LIBEXEC_PATH}\""
SOURCES SOURCES

View File

@@ -152,7 +152,7 @@ QList<FormattedText> AnsiEscapeCodeHandler::parseText(const FormattedText &input
} }
break; break;
} }
m_pendingText += strippedText.midRef(0, escape.length()); m_pendingText += strippedText.mid(0, escape.length());
strippedText.remove(0, escape.length()); strippedText.remove(0, escape.length());
// \e[K is not supported. Just strip it. // \e[K is not supported. Just strip it.
@@ -174,7 +174,7 @@ QList<FormattedText> AnsiEscapeCodeHandler::parseText(const FormattedText &input
break; break;
strNumber.clear(); strNumber.clear();
} }
m_pendingText += strippedText.midRef(0, 1); m_pendingText += strippedText.mid(0, 1);
strippedText.remove(0, 1); strippedText.remove(0, 1);
} }
if (strippedText.isEmpty()) if (strippedText.isEmpty())

View File

@@ -78,7 +78,7 @@ static int commonOverlap(const QString &text1, const QString &text2)
const int text2Count = text2.count(); const int text2Count = text2.count();
const int maxCount = qMin(text1Count, text2Count); const int maxCount = qMin(text1Count, text2Count);
while (i < maxCount) { while (i < maxCount) {
if (text1.midRef(text1Count - maxCount + i) == text2.leftRef(maxCount - i)) if (QStringView(text1).mid(text1Count - maxCount + i) == QStringView(text2).left(maxCount - i))
return maxCount - i; return maxCount - i;
i++; i++;
} }
@@ -298,7 +298,7 @@ QList<Diff> Differ::moveWhitespaceIntoEqualities(const QList<Diff> &input)
} }
if (j > 0) { if (j > 0) {
// diff starts with j whitespaces, move them to the previous diff // diff starts with j whitespaces, move them to the previous diff
previousDiff.text.append(diff.text.leftRef(j)); previousDiff.text.append(diff.text.left(j));
diff.text = diff.text.mid(j); diff.text = diff.text.mid(j);
} }
} }

View File

@@ -192,10 +192,10 @@ bool FileInProjectFinder::findFileOrDirectory(const QString &originalPath, FileH
return false; return false;
} }
const auto segments = originalPath.splitRef('/', Qt::SkipEmptyParts); const auto segments = originalPath.split('/', Qt::SkipEmptyParts);
const PathMappingNode *node = &m_pathMapRoot; const PathMappingNode *node = &m_pathMapRoot;
for (const auto &segment : segments) { for (const auto &segment : segments) {
auto it = node->children.find(segment.toString()); auto it = node->children.find(segment);
if (it == node->children.end()) { if (it == node->children.end()) {
node = nullptr; node = nullptr;
break; break;

View File

@@ -123,7 +123,7 @@ bool MimeGlobPattern::matchFileName(const QString &inputFilename) const
if (starCount == 1 && m_pattern.at(pattern_len - 1) == QLatin1Char('*')) { if (starCount == 1 && m_pattern.at(pattern_len - 1) == QLatin1Char('*')) {
if (len + 1 < pattern_len) return false; if (len + 1 < pattern_len) return false;
if (m_pattern.at(0) == QLatin1Char('*')) if (m_pattern.at(0) == QLatin1Char('*'))
return filename.indexOf(m_pattern.midRef(1, pattern_len - 2)) != -1; return filename.indexOf(QStringView(m_pattern).mid(1, pattern_len - 2)) != -1;
const QChar *c1 = m_pattern.unicode(); const QChar *c1 = m_pattern.unicode();
const QChar *c2 = filename.unicode(); const QChar *c2 = filename.unicode();

View File

@@ -107,7 +107,8 @@ static const char matchMaskAttributeC[] = "mask";
Overwrite to process the sequence of parsed data Overwrite to process the sequence of parsed data
*/ */
MimeTypeParserBase::ParseState MimeTypeParserBase::nextState(ParseState currentState, const QStringRef &startElement) MimeTypeParserBase::ParseState MimeTypeParserBase::nextState(ParseState currentState,
const QStringView &startElement)
{ {
switch (currentState) { switch (currentState) {
case ParseBeginning: case ParseBeginning:
@@ -320,7 +321,7 @@ bool MimeTypeParserBase::parse(const QByteArray &content, const QString &fileNam
// continue switch QXmlStreamReader::Token... // continue switch QXmlStreamReader::Token...
case QXmlStreamReader::EndElement: // Finished element case QXmlStreamReader::EndElement: // Finished element
{ {
const QStringRef elementName = reader.name(); const QStringView elementName = reader.name();
if (elementName == QLatin1String(mimeTypeTagC)) { if (elementName == QLatin1String(mimeTypeTagC)) {
if (!ignoreCurrentMimeType) { if (!ignoreCurrentMimeType) {
if (!process(MimeType(data), errorMessage)) if (!process(MimeType(data), errorMessage))

View File

@@ -91,7 +91,7 @@ private:
ParseError ParseError
}; };
static ParseState nextState(ParseState currentState, const QStringRef &startElement); static ParseState nextState(ParseState currentState, const QStringView &startElement);
}; };

View File

@@ -67,8 +67,15 @@ void NavigationTreeView::scrollTo(const QModelIndex &index, QAbstractItemView::S
QRect itemRect = visualRect(index); QRect itemRect = visualRect(index);
QAbstractItemDelegate *delegate = itemDelegate(index); QAbstractItemDelegate *delegate = itemDelegate(index);
if (delegate) if (delegate) {
itemRect.setWidth(delegate->sizeHint(viewOptions(), index).width()); #if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
const QStyleOptionViewItem option = viewOptions();
#else
QStyleOptionViewItem option;
initViewItemOption(&option);
#endif
itemRect.setWidth(delegate->sizeHint(option, index).width());
}
if (itemRect.x() - indentation() < 0) { if (itemRect.x() - indentation() < 0) {
// scroll so left edge minus one indent of item is visible // scroll so left edge minus one indent of item is visible

View File

@@ -188,13 +188,13 @@ private:
enum Element { QtCreatorElement, DataElement, VariableElement, enum Element { QtCreatorElement, DataElement, VariableElement,
SimpleValueElement, ListValueElement, MapValueElement, UnknownElement }; SimpleValueElement, ListValueElement, MapValueElement, UnknownElement };
Element element(const QStringRef &r) const; Element element(const QStringView &r) const;
static inline bool isValueElement(Element e) static inline bool isValueElement(Element e)
{ return e == SimpleValueElement || e == ListValueElement || e == MapValueElement; } { return e == SimpleValueElement || e == ListValueElement || e == MapValueElement; }
QVariant readSimpleValue(QXmlStreamReader &r, const QXmlStreamAttributes &attributes) const; QVariant readSimpleValue(QXmlStreamReader &r, const QXmlStreamAttributes &attributes) const;
bool handleStartElement(QXmlStreamReader &r); bool handleStartElement(QXmlStreamReader &r);
bool handleEndElement(const QStringRef &name); bool handleEndElement(const QStringView &name);
static QString formatWarning(const QXmlStreamReader &r, const QString &message); static QString formatWarning(const QXmlStreamReader &r, const QString &message);
@@ -233,7 +233,7 @@ QVariantMap ParseContext::parse(QFile &file)
bool ParseContext::handleStartElement(QXmlStreamReader &r) bool ParseContext::handleStartElement(QXmlStreamReader &r)
{ {
const QStringRef name = r.name(); const QStringView name = r.name();
const Element e = element(name); const Element e = element(name);
if (e == VariableElement) { if (e == VariableElement) {
m_currentVariableName = r.readElementText(); m_currentVariableName = r.readElementText();
@@ -268,7 +268,7 @@ bool ParseContext::handleStartElement(QXmlStreamReader &r)
return false; return false;
} }
bool ParseContext::handleEndElement(const QStringRef &name) bool ParseContext::handleEndElement(const QStringView &name)
{ {
const Element e = element(name); const Element e = element(name);
if (ParseContext::isValueElement(e)) { if (ParseContext::isValueElement(e)) {
@@ -297,7 +297,7 @@ QString ParseContext::formatWarning(const QXmlStreamReader &r, const QString &me
return result; return result;
} }
ParseContext::Element ParseContext::element(const QStringRef &r) const ParseContext::Element ParseContext::element(const QStringView &r) const
{ {
if (r == valueElement) if (r == valueElement)
return SimpleValueElement; return SimpleValueElement;
@@ -317,7 +317,7 @@ ParseContext::Element ParseContext::element(const QStringRef &r) const
QVariant ParseContext::readSimpleValue(QXmlStreamReader &r, const QXmlStreamAttributes &attributes) const QVariant ParseContext::readSimpleValue(QXmlStreamReader &r, const QXmlStreamAttributes &attributes) const
{ {
// Simple value // Simple value
const QStringRef type = attributes.value(typeAttribute); const QStringView type = attributes.value(typeAttribute);
const QString text = r.readElementText(); const QString text = r.readElementText();
if (type == QLatin1String("QChar")) { // Workaround: QTBUG-12345 if (type == QLatin1String("QChar")) { // Workaround: QTBUG-12345
QTC_ASSERT(text.size() == 1, return QVariant()); QTC_ASSERT(text.size() == 1, return QVariant());

View File

@@ -352,7 +352,7 @@ static QStringList splitArgsUnix(const QString &args, bool abortOnMeta,
goto quoteerr; goto quoteerr;
c = args.unicode()[pos++]; c = args.unicode()[pos++];
} while (c != QLatin1Char('\'')); } while (c != QLatin1Char('\''));
cret += args.midRef(spos, pos - spos - 1); cret += args.mid(spos, pos - spos - 1);
hadWord = true; hadWord = true;
} else if (c == QLatin1Char('"')) { } else if (c == QLatin1Char('"')) {
for (;;) { for (;;) {