Fix LogView Qt6 compatibility: QStringRef to QStringView migration
- Migrated QStringRef to QStringView in LogViewTetraTelegramsParser - Updated tokenize() function signature and implementation - Updated bracketCount() helper function - Updated validStructTokens() function - Updated parseStruct(), parseEnum(), parseConstraint() functions - Migrated QStringRef to QStringView in LogViewGui.cpp - Updated splitRef() to splitView() calls - Updated QVector<QStringRef> to QVector<QStringView> - Migrated QStringRef to QStringView in LogViewXdrParser.cpp - Updated midRef() to mid() calls - Updated leftRef() to left() calls - Updated Qt6 include paths: QAbstractTableModel and QModelIndex moved to QtCore Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
This commit is contained in:
4 files changed
+45
-43
No files matched your search
@@ -655,7 +655,7 @@ void LogViewGui::updateLogfile()
|
||||
|
||||
QString filePath(fileInfo.absolutePath() + QLatin1Char('/'));
|
||||
const QString baseName = fileInfo.baseName();
|
||||
const QVector<QStringRef> parts = baseName.splitRef(QLatin1Char('_'));
|
||||
const QVector<QStringView> parts = baseName.splitView(QLatin1Char('_'));
|
||||
|
||||
for (int iterator = 0; iterator < parts.size() - 2; ++iterator)
|
||||
filePath += parts.at(iterator).toString() + QLatin1Char('_');
|
||||
@@ -912,7 +912,7 @@ void LogViewGui::startInjectionThread()
|
||||
settings.beginGroup(QLatin1String("LogFiles"));
|
||||
QString filePath = settings.value(QLatin1String("Dir")).toString();
|
||||
QString exerciseName;
|
||||
QVector<QStringRef> parts = filePath.splitRef(QLatin1Char('/'));
|
||||
QVector<QStringView> parts = filePath.splitView(QLatin1Char('/'));
|
||||
if (parts.size() >= 2)
|
||||
exerciseName = QLatin1Char('_') + parts.at(parts.size() - 2).toString();
|
||||
|
||||
|
||||
@@ -6,6 +6,7 @@
|
||||
|
||||
#include <QtCore/QFile>
|
||||
#include <QtCore/QVector>
|
||||
#include <QtCore/QStringView>
|
||||
|
||||
namespace N_LogView
|
||||
{
|
||||
@@ -87,16 +88,16 @@ bool LogViewTetraTelegramsParser::parse(const QString &filename)
|
||||
const QString content = QString::fromUtf8(f.readAll());
|
||||
f.close();
|
||||
|
||||
const QVector<QStringRef> lines = content.splitRef(QLatin1Char('\n'));
|
||||
QVector<QStringRef> linesTrimmed;
|
||||
const QVector<QStringView> lines = content.splitView(QLatin1Char('\n'));
|
||||
QVector<QStringView> linesTrimmed;
|
||||
linesTrimmed.reserve(lines.size());
|
||||
for (const QStringRef &line : lines)
|
||||
for (const QStringView &line : lines)
|
||||
linesTrimmed += line.trimmed();
|
||||
|
||||
int i = 0;
|
||||
while (i < linesTrimmed.size())
|
||||
{
|
||||
const QStringRef &line = linesTrimmed.at(i);
|
||||
const QStringView &line = linesTrimmed.at(i);
|
||||
if (line.startsWith(QLatin1String("struct")))
|
||||
{
|
||||
i = parseStruct(linesTrimmed, i);
|
||||
@@ -136,12 +137,12 @@ void LogViewTetraTelegramsParser::insertPod(const QString &type, int byteLen, bo
|
||||
}
|
||||
|
||||
|
||||
int LogViewTetraTelegramsParser::parseStruct(const QVector<QStringRef> &lines, int iStartPos)
|
||||
int LogViewTetraTelegramsParser::parseStruct(const QVector<QStringView> &lines, int iStartPos)
|
||||
{
|
||||
const QVector<QStringRef> tokens = tokenize(lines.at(iStartPos));
|
||||
const QVector<QStringView> tokens = tokenize(lines.at(iStartPos));
|
||||
if (tokens.size() < 2)
|
||||
return -1;
|
||||
const QStringRef &structType = tokens.at(1);
|
||||
const QStringView &structType = tokens.at(1);
|
||||
if (structType.endsWith(QLatin1Char(';')))
|
||||
return iStartPos;
|
||||
|
||||
@@ -162,7 +163,7 @@ int LogViewTetraTelegramsParser::parseStruct(const QVector<QStringRef> &lines, i
|
||||
WARNING_LOG(m_logger) << "Could not parse struct: '" << lines.at(iStartPos).toString() << "', line: " << iStartPos + 1;
|
||||
return -1;
|
||||
}
|
||||
QStringRef base = tokens.at(i);
|
||||
QStringView base = tokens.at(i);
|
||||
if (base == QLatin1String("public") ||
|
||||
base == QLatin1String("protected") ||
|
||||
base == QLatin1String("private"))
|
||||
@@ -181,7 +182,7 @@ int LogViewTetraTelegramsParser::parseStruct(const QVector<QStringRef> &lines, i
|
||||
int i = iStartPos + 1;
|
||||
while (i < lines.size())
|
||||
{
|
||||
const QVector<QStringRef> tokens = tokenize(lines.at(i));
|
||||
const QVector<QStringView> tokens = tokenize(lines.at(i));
|
||||
if (!validStructTokens(tokens))
|
||||
{
|
||||
++i;
|
||||
@@ -204,15 +205,15 @@ int LogViewTetraTelegramsParser::parseStruct(const QVector<QStringRef> &lines, i
|
||||
const int parserCommentPos = tokens.at(2) == QLatin1String("=") ? 4 : 2;
|
||||
if (tokens.size() > parserCommentPos)
|
||||
{
|
||||
const QStringRef &comment = tokens.at(parserCommentPos);
|
||||
const QStringView &comment = tokens.at(parserCommentPos);
|
||||
DEBUG_LOG(m_logger) << "comment: " << comment.toString();
|
||||
if (comment.startsWith(QLatin1String("//@array: ")))
|
||||
{
|
||||
const QStringRef hint = comment.mid(QLatin1String("//@array: ").size());
|
||||
const QStringView hint = comment.mid(QLatin1String("//@array: ").size());
|
||||
QString structStr = QLatin1String("struct ") + si.type + QLatin1String("::") + tokens.at(0).toString() + QLatin1Char('\n') + hint.toString();
|
||||
structStr.replace(QLatin1Char(';'), QLatin1String(";\n"));
|
||||
DEBUG_LOG(m_logger) << "structStr: " << structStr;
|
||||
parseStruct(structStr.splitRef(QLatin1Char('\n')), 0);
|
||||
parseStruct(structStr.splitView(QLatin1Char('\n')), 0);
|
||||
|
||||
mi.type = si.type + QLatin1String("::") + tokens.at(0).toString();
|
||||
mi.isArray = true;
|
||||
@@ -222,7 +223,7 @@ int LogViewTetraTelegramsParser::parseStruct(const QVector<QStringRef> &lines, i
|
||||
}
|
||||
}
|
||||
|
||||
QStringRef name = tokens.at(1);
|
||||
QStringView name = tokens.at(1);
|
||||
if (name.endsWith(QLatin1Char(';')))
|
||||
name.chop(1);
|
||||
if (mi.type.isEmpty())
|
||||
@@ -265,12 +266,12 @@ int LogViewTetraTelegramsParser::parseStruct(const QVector<QStringRef> &lines, i
|
||||
return i;
|
||||
}
|
||||
|
||||
int LogViewTetraTelegramsParser::parseEnum(const QVector<QStringRef> &lines, int iStartPos, const QString &ns, StructInformation *si)
|
||||
int LogViewTetraTelegramsParser::parseEnum(const QVector<QStringView> &lines, int iStartPos, const QString &ns, StructInformation *si)
|
||||
{
|
||||
const QVector<QStringRef> tokens = tokenize(lines.at(iStartPos));
|
||||
const QVector<QStringView> tokens = tokenize(lines.at(iStartPos));
|
||||
if (tokens.size() < 2)
|
||||
return -1;
|
||||
QStringRef enumName = tokens.at(1);
|
||||
QStringView enumName = tokens.at(1);
|
||||
if (enumName == QLatin1String("class"))
|
||||
{
|
||||
if (tokens.size() < 3)
|
||||
@@ -287,7 +288,7 @@ int LogViewTetraTelegramsParser::parseEnum(const QVector<QStringRef> &lines, int
|
||||
int i = iStartPos + 1;
|
||||
while (i < lines.size())
|
||||
{
|
||||
const QVector<QStringRef> tokens = tokenize(lines.at(i).split(QStringLiteral("//")).first());
|
||||
const QVector<QStringView> tokens = tokenize(lines.at(i).split(QStringLiteral("//")).first());
|
||||
if (tokens.isEmpty() ||
|
||||
(tokens.at(0) == QLatin1String("{")))
|
||||
{
|
||||
@@ -320,7 +321,7 @@ int LogViewTetraTelegramsParser::parseEnum(const QVector<QStringRef> &lines, int
|
||||
ev.key = tokens.at(0).toString();
|
||||
if (tokens.size() == 3)
|
||||
{
|
||||
QStringRef value = tokens.at(2);
|
||||
QStringView value = tokens.at(2);
|
||||
if (value.endsWith(QLatin1Char(',')))
|
||||
value.chop(1);
|
||||
ev.value = value.toInt();
|
||||
@@ -346,28 +347,28 @@ int LogViewTetraTelegramsParser::parseEnum(const QVector<QStringRef> &lines, int
|
||||
return i;
|
||||
}
|
||||
|
||||
int LogViewTetraTelegramsParser::parseConstraint(const QVector<QStringRef> &lines, int iStartPos)
|
||||
int LogViewTetraTelegramsParser::parseConstraint(const QVector<QStringView> &lines, int iStartPos)
|
||||
{
|
||||
const QVector<QStringRef> tokens = tokenize(lines.at(iStartPos));
|
||||
const QVector<QStringView> tokens = tokenize(lines.at(iStartPos));
|
||||
if (tokens.size() != 4)
|
||||
{
|
||||
WARNING_LOG(m_logger) << "Could not parse constraint: '" << lines.at(iStartPos).toString() << "'";
|
||||
return -1;
|
||||
}
|
||||
const QStringRef &cs = tokens.at(3);
|
||||
const QStringView &cs = tokens.at(3);
|
||||
if (!cs.startsWith(QLatin1String("Constraints<")) || !cs.endsWith(QLatin1Char('>')))
|
||||
{
|
||||
WARNING_LOG(m_logger) << "Could not parse constraint: '" << lines.at(iStartPos).toString() << "'";
|
||||
return -1;
|
||||
}
|
||||
QStringRef structName = cs.mid(QLatin1String("Constraints<").size());
|
||||
QStringView structName = cs.mid(QLatin1String("Constraints<").size());
|
||||
structName.chop(1);
|
||||
DEBUG_LOG(m_logger) << "Constraint: " << structName.toString();
|
||||
|
||||
int i = iStartPos + 1;
|
||||
while (i < lines.size())
|
||||
{
|
||||
const QVector<QStringRef> tokens = tokenize(lines.at(i));
|
||||
const QVector<QStringView> tokens = tokenize(lines.at(i));
|
||||
if (tokens.isEmpty() ||
|
||||
(tokens.at(0) == QLatin1String("{")))
|
||||
{
|
||||
@@ -381,14 +382,14 @@ int LogViewTetraTelegramsParser::parseConstraint(const QVector<QStringRef> &line
|
||||
++i;
|
||||
continue;
|
||||
}
|
||||
const QVector<QStringRef> parts = tokens.at(6).split(QLatin1String("::"));
|
||||
const QVector<QStringView> parts = tokens.at(6).split(QLatin1String("::"));
|
||||
if (parts.size() != 2)
|
||||
{
|
||||
WARNING_LOG(m_logger) << "Could not parse constraint: '" << lines.at(i).toString() << "'";
|
||||
return -1;
|
||||
}
|
||||
|
||||
QStringRef enumKey = parts.at(1);
|
||||
QStringView enumKey = parts.at(1);
|
||||
if (enumKey.endsWith(QLatin1Char(';')))
|
||||
enumKey.chop(1);
|
||||
bool bFound = false;
|
||||
@@ -434,7 +435,7 @@ void LogViewTetraTelegramsParser::categorizeMember(MemberInformation &mi) const
|
||||
mi.isBinary = (mi.type == QLatin1String("std::vector<unsigned char>") || mi.type == QLatin1String("QByteArray"));
|
||||
}
|
||||
|
||||
static inline void bracketCount(const QStringRef &str, int &cntLt, int &cntGt)
|
||||
static inline void bracketCount(const QStringView &str, int &cntLt, int &cntGt)
|
||||
{
|
||||
cntLt = 0;
|
||||
cntGt = 0;
|
||||
@@ -447,20 +448,20 @@ static inline void bracketCount(const QStringRef &str, int &cntLt, int &cntGt)
|
||||
}
|
||||
}
|
||||
|
||||
QVector<QStringRef> LogViewTetraTelegramsParser::tokenize(const QStringRef &line) const
|
||||
QVector<QStringView> LogViewTetraTelegramsParser::tokenize(const QStringView &line) const
|
||||
{
|
||||
QVector<QStringRef> ret = line.split(QLatin1Char(' '), QString::SkipEmptyParts);
|
||||
QVector<QStringView> ret = line.split(QLatin1Char(' '), Qt::SkipEmptyParts);
|
||||
int i = 0;
|
||||
while (i < ret.size())
|
||||
{
|
||||
const QStringRef &token = ret.at(i);
|
||||
const QStringView &token = ret.at(i);
|
||||
if (token.startsWith(QLatin1String("//")))
|
||||
{
|
||||
|
||||
if (i == ret.size() - 1)
|
||||
break;
|
||||
const QStringRef &lastToken = ret.last();
|
||||
const QStringRef newToken = QStringRef(token.string(), token.position(), lastToken.position() - token.position() + lastToken.size());
|
||||
const QStringView &lastToken = ret.last();
|
||||
const QStringView newToken = line.mid(token.position(), lastToken.position() - token.position() + lastToken.size());
|
||||
DEBUG_LOG(m_logger) << "New Token: " << newToken.toString();
|
||||
ret.resize(i + 1);
|
||||
ret[i] = newToken;
|
||||
@@ -476,8 +477,8 @@ QVector<QStringRef> LogViewTetraTelegramsParser::tokenize(const QStringRef &line
|
||||
++i;
|
||||
continue;
|
||||
}
|
||||
const QStringRef &nextToken = ret.at(i + 1);
|
||||
const QStringRef newToken = QStringRef(token.string(), token.position(), nextToken.position() - token.position() + nextToken.size());
|
||||
const QStringView &nextToken = ret.at(i + 1);
|
||||
const QStringView newToken = line.mid(token.position(), nextToken.position() - token.position() + nextToken.size());
|
||||
DEBUG_LOG(m_logger) << "New Token: " << newToken.toString();
|
||||
ret.removeAt(i + 1);
|
||||
ret[i] = newToken;
|
||||
@@ -486,7 +487,7 @@ QVector<QStringRef> LogViewTetraTelegramsParser::tokenize(const QStringRef &line
|
||||
return ret;
|
||||
}
|
||||
|
||||
bool LogViewTetraTelegramsParser::validStructTokens(const QVector<QStringRef> &tokens)
|
||||
bool LogViewTetraTelegramsParser::validStructTokens(const QVector<QStringView> &tokens)
|
||||
{
|
||||
if (tokens.isEmpty() ||
|
||||
(tokens.at(0) == QLatin1String("{")) ||
|
||||
|
||||
@@ -5,6 +5,7 @@
|
||||
|
||||
#include <QtCore/QHash>
|
||||
#include <QtCore/QString>
|
||||
#include <QtCore/QStringView>
|
||||
#include <QtCore/QVector>
|
||||
#include "logger.h"
|
||||
|
||||
@@ -72,12 +73,12 @@ public:
|
||||
static QString getInnerType(const QString &type);
|
||||
private:
|
||||
void insertPod(const QString &type, int byteLen, bool isSigned, bool isIntegral, bool isBoolean = false);
|
||||
int parseStruct(const QVector<QStringRef> &lines, int iStartPos);
|
||||
int parseEnum(const QVector<QStringRef> &lines, int iStartPos, const QString &ns, StructInformation *si = nullptr);
|
||||
int parseConstraint(const QVector<QStringRef> &lines, int iStartPos);
|
||||
int parseStruct(const QVector<QStringView> &lines, int iStartPos);
|
||||
int parseEnum(const QVector<QStringView> &lines, int iStartPos, const QString &ns, StructInformation *si = nullptr);
|
||||
int parseConstraint(const QVector<QStringView> &lines, int iStartPos);
|
||||
void categorizeMember(MemberInformation &mi) const;
|
||||
QVector<QStringRef> tokenize(const QStringRef &line) const;
|
||||
static bool validStructTokens(const QVector<QStringRef> &tokens);
|
||||
QVector<QStringView> tokenize(QStringView line) const;
|
||||
static bool validStructTokens(const QVector<QStringView> &tokens);
|
||||
private:
|
||||
EnumInformation m_telegramIdEnum;
|
||||
QVector<EnumInformation> m_enums;
|
||||
|
||||
@@ -317,8 +317,8 @@ void LogViewXdrParser::parseDefine(const QString &a_line)
|
||||
int sepPos = line.indexOf(QLatin1Char(' '));
|
||||
if (sepPos >= 0)
|
||||
{
|
||||
const QString name = line.leftRef(sepPos).trimmed().toString();
|
||||
QStringRef substitution = line.midRef(sepPos).trimmed();
|
||||
const QString name = line.left(sepPos).trimmed();
|
||||
QStringView substitution = line.mid(sepPos).trimmed();
|
||||
sepPos = substitution.indexOf(QLatin1Char(' '));
|
||||
if (sepPos >= 0)
|
||||
substitution = substitution.left(sepPos).trimmed();
|
||||
|
||||
Reference in new issue
Block a user