From 780e2fb1a241de5c98104cae89cccbef94c072fb Mon Sep 17 00:00:00 2001 From: Collin Kidder Date: Tue, 11 Apr 2023 21:15:34 -0400 Subject: [PATCH] Several changes suggested in draft pull requests from llange. Fix some ambiguous places, fix warnings, fix errors when trying to compile with QT6 --- connections/connectionwindow.cpp | 8 ++-- connections/socketcand.cpp | 2 +- dbc/dbchandler.cpp | 8 ++-- dbc/dbcloadsavewindow.cpp | 12 ++--- framefileio.cpp | 75 +++++++++++++++++--------------- scriptcontainer.cpp | 6 +-- 6 files changed, 59 insertions(+), 52 deletions(-) diff --git a/connections/connectionwindow.cpp b/connections/connectionwindow.cpp index 84bd514..e748e31 100644 --- a/connections/connectionwindow.cpp +++ b/connections/connectionwindow.cpp @@ -109,16 +109,16 @@ void ConnectionWindow::readPendingDatagrams() while(!CANBeaconXml.atEnd() && !CANBeaconXml.hasError()) { CANBeaconXml.readNext(); - if(CANBeaconXml.name() == "CANBeacon" && !CANBeaconXml.isEndElement()) + if(CANBeaconXml.name() == QString("CANBeacon") && !CANBeaconXml.isEndElement()) KayakHost.append(CANBeaconXml.attributes().value("name")); - if(CANBeaconXml.name() == "URL") + if(CANBeaconXml.name() == QString("URL")) KayakHost.append(" (" + CANBeaconXml.readElementText() + ')'); //Kayak can theoretically send multiple busses over one ports //TODO: implement this case in socketcand.cpp - if(CANBeaconXml.name() == "Bus" && !CANBeaconXml.isEndElement()) - KayakBus.append(CANBeaconXml.attributes().value("name") + ","); + if(CANBeaconXml.name() == QString("Bus") && !CANBeaconXml.isEndElement()) + KayakBus.append(CANBeaconXml.attributes().value("name").toUtf8() + ","); } KayakHost = KayakBus.left(KayakBus.length() - 1) + "@" + KayakHost; diff --git a/connections/socketcand.cpp b/connections/socketcand.cpp index e7eb5ef..1467d01 100644 --- a/connections/socketcand.cpp +++ b/connections/socketcand.cpp @@ -266,7 +266,7 @@ QString SocketCANd::decodeFrames(QString data, int busNum) QString framePart = data.mid(firstIndex); //remove starting beginning of payload if not < frame > const QString frameStrConst = framePart.left(framePart.indexOf(">")+1); QString frameStr = frameStrConst; - QStringList frameParsed = (frameStr.remove(QRegExp("^<")).remove(QRegExp(">$"))).simplified().split(' '); + QStringList frameParsed = (frameStr.remove(QRegularExpression("^<")).remove(QRegularExpression(">$"))).simplified().split(' '); if(frameParsed.length() < 3) { diff --git a/dbc/dbchandler.cpp b/dbc/dbchandler.cpp index 3da3214..5807e8b 100644 --- a/dbc/dbchandler.cpp +++ b/dbc/dbchandler.cpp @@ -2249,14 +2249,14 @@ DBCHandler::DBCHandler() qDebug() << "Previously loaded DBC file count: " << filecount; for (int i=0; isetAssocBus(bus); - MatchingCriteria_t matchingCriteria = (MatchingCriteria_t)settings.value("DBC/MatchingCriteria_" + QString(i),0).toInt(); + MatchingCriteria_t matchingCriteria = (MatchingCriteria_t)settings.value("DBC/MatchingCriteria_" + QString::number(i),0).toInt(); DBC_ATTRIBUTE attr; @@ -2270,7 +2270,7 @@ DBCHandler::DBCHandler() file->dbc_attributes.append(attr); file->messageHandler->setMatchingCriteria(matchingCriteria); - bool filterLabeling = settings.value("DBC/FilterLabeling_" + QString(i),0).toBool(); + bool filterLabeling = settings.value("DBC/FilterLabeling_" + QString::number(i),0).toBool(); attr.attrType = ATTR_TYPE_MESSAGE; attr.defaultValue = filterLabeling; attr.enumVals.clear(); diff --git a/dbc/dbcloadsavewindow.cpp b/dbc/dbcloadsavewindow.cpp index 7136379..d44b62a 100644 --- a/dbc/dbcloadsavewindow.cpp +++ b/dbc/dbcloadsavewindow.cpp @@ -108,10 +108,10 @@ void DBCLoadSaveWindow::updateSettings() qDebug() << "Save DBC settings #" << i << " File: " << file->getFullFilename() << "Bus: " << file->getAssocBus() << "MC: " << file->messageHandler->getMatchingCriteria() << "Filter Labeling: " << (file->messageHandler->filterLabeling() ? "enabled" : "disabled"); - settings.setValue("DBC/Filename_" + QString(i), file->getFullFilename()); - settings.setValue("DBC/AssocBus_" + QString(i), file->getAssocBus()); - settings.setValue("DBC/MatchingCriteria_" + QString(i), file->messageHandler->getMatchingCriteria()); - settings.setValue("DBC/FilterLabeling_" + QString(i), file->messageHandler->filterLabeling()); + settings.setValue("DBC/Filename_" + QString::number(i), file->getFullFilename()); + settings.setValue("DBC/AssocBus_" + QString::number(i), file->getAssocBus()); + settings.setValue("DBC/MatchingCriteria_" + QString::number(i), file->messageHandler->getMatchingCriteria()); + settings.setValue("DBC/FilterLabeling_" + QString::number(i), file->messageHandler->filterLabeling()); } } emit updatedDBCSettings(); @@ -200,7 +200,7 @@ void DBCLoadSaveWindow::loadFile() DBC_ATTRIBUTE *attr = file->findAttributeByName("matchingcriteria"); QComboBox * mc_item = addMatchingCriteriaCombobox(idx); - if (attr && attr->defaultValue > 0) + if (attr && attr->defaultValue.toInt() > 0) { mc_item->setCurrentIndex(attr->defaultValue.toInt()); } @@ -208,7 +208,7 @@ void DBCLoadSaveWindow::loadFile() attr = file->findAttributeByName("filterlabeling"); QTableWidgetItem *item = new QTableWidgetItem(""); ui->tableFiles->setItem(idx, 3, item); - if (attr && attr->defaultValue > 0) + if (attr && attr->defaultValue.toInt() > 0) { item->setCheckState(Qt::Checked); } diff --git a/framefileio.cpp b/framefileio.cpp index c5822ba..ff62cd9 100644 --- a/framefileio.cpp +++ b/framefileio.cpp @@ -867,7 +867,7 @@ bool FrameFileIO::loadCARBUSAnalyzerFile(QString filename, QVector* fr line = txt.readLine().simplified(); if (line.length() > 2) { - QList tokens = line.split(QRegExp("\\s+")); + QList tokens = line.split(QRegularExpression("\\s+")); if (tokens.length() > 3) { QString time = tokens[0].replace(",", ""); @@ -3507,9 +3507,9 @@ bool FrameFileIO::isCanDumpFile(QString filename) QFile *inFile = new QFile(filename); QByteArray line; QList tokens; - QRegExp timeExp("^\\((\\S+)\\)$"); - QRegExp IdValExp("^(\\S+)#(\\S+)$"); - QRegExp valExp("(\\S{2})"); + QRegularExpression timeExp(QRegularExpression::anchoredPattern("^\\((\\S+)\\)$")); //anchored pattern causes exact match + QRegularExpression IdValExp(QRegularExpression::anchoredPattern("^(\\S+)#(\\S+)$")); + QRegularExpression valExp("(\\S{2})"); int lineCounter = 0; int pos = 0; bool isMatch = true; @@ -3534,11 +3534,13 @@ bool FrameFileIO::isCanDumpFile(QString filename) tokens = line.simplified().split(' '); if(tokens.count() < 3) isMatch = false; - /* timestamp */ - ret = timeExp.exactMatch(tokens[0]); - if(!ret) isMatch = false; + /* timestamp */ + QRegularExpressionMatch timeExpMatched = timeExp.match(tokens[0]); + if(!timeExpMatched.hasMatch()) { + isMatch = false; + } - /*uint64_t timestamp = (uint64_t)*/(timeExp.cap(1).toDouble(&ret) /** (double)1000000.0*/); + /*uint64_t timestamp = (uint64_t)*/(timeExpMatched.captured(1).toDouble(&ret) /** (double)1000000.0*/); if(!ret) isMatch = false; if (line.contains('[')) //the expanded format @@ -3568,17 +3570,19 @@ bool FrameFileIO::isCanDumpFile(QString filename) isMatch = false; continue; } - ret = IdValExp.exactMatch(tokens[2]); - if(!ret) + + + QRegularExpressionMatch IdValExpMatched = IdValExp.match(tokens[2]); + if(!IdValExpMatched.hasMatch()) { isMatch = false; continue; } /* ID */ - /*int ID = */IdValExp.cap(1).toInt(&ret, 16); + /*int ID = */IdValExpMatched.captured(1).toInt(&ret, 16); - QString val= IdValExp.cap(2); + QString val= IdValExpMatched.captured(2); pos = 0; int len = 0; @@ -3592,22 +3596,23 @@ bool FrameFileIO::isCanDumpFile(QString filename) } else { /* val byte per byte */ int lng = 0; - while ((pos = valExp.indexIn(val, pos)) != -1) - { + QRegularExpressionMatch valExpMatch; + QRegularExpressionMatchIterator i = valExp.globalMatch(val); + while (i.hasNext()) { + valExpMatch = i.next(); lng++; if (lng > 8) { isMatch = false; break; } - /*int data = */valExp.cap(1).toInt(&ret, 16); + /*int data = */valExpMatch.captured(1).toInt(&ret, 16); if(!ret) { isMatch = false; break; } - pos += valExp.matchedLength(); } } } @@ -3634,11 +3639,10 @@ bool FrameFileIO::loadCanDumpFile(QString filename, QVector* frames) CANFrame thisFrame; QByteArray line; QList tokens; - QRegExp timeExp("^\\((\\S+)\\)$"); - QRegExp IdValExp("^(\\S+)#(\\S+)$"); - QRegExp valExp("(\\S{2})"); + QRegularExpression timeExp(QRegularExpression::anchoredPattern("^\\((\\S+)\\)$")); //anchored pattern causes exact match + QRegularExpression IdValExp(QRegularExpression::anchoredPattern("^(\\S+)#(\\S+)$")); + QRegularExpression valExp("(\\S{2})"); int lineCounter = 0; - int pos = 0; bool ret; if (!inFile->open(QIODevice::ReadOnly | QIODevice::Text)) @@ -3664,8 +3668,8 @@ bool FrameFileIO::loadCanDumpFile(QString filename, QVector* frames) if(tokens.count()<3) continue; /* timestamp */ - ret = timeExp.exactMatch(tokens[0]); - if(!ret) continue; + QRegularExpressionMatch timeExpMatched = timeExp.match(tokens[0]); + if(!timeExpMatched.hasMatch()) continue; //Sort out the bus std::string busString = tokens[1].toStdString(); @@ -3686,7 +3690,7 @@ bool FrameFileIO::loadCanDumpFile(QString filename, QVector* frames) thisFrame.bus = busNum; - thisFrame.setTimeStamp(QCanBusFrame::TimeStamp(0, (uint64_t)(timeExp.cap(1).toDouble(&ret) * (double)1000000.0))); + thisFrame.setTimeStamp(QCanBusFrame::TimeStamp(0, (uint64_t)(timeExpMatched.captured(1).toDouble(&ret) * (double)1000000.0))); if(!ret) continue; if (line.contains('[')) //the expanded format (second one from the above list) @@ -3709,24 +3713,26 @@ bool FrameFileIO::loadCanDumpFile(QString filename, QVector* frames) { /* ID & value */ //qDebug() << tokens[2]; - ret = IdValExp.exactMatch(tokens[2]); - if(!ret) + QRegularExpressionMatch IdValExpMatched = IdValExp.match(tokens[2]); + if(!IdValExpMatched.hasMatch()) { qDebug() << "ID regex didn't match!"; continue; } /* ID */ - thisFrame.setFrameId(static_cast(IdValExp.cap(1).toInt(&ret, 16))); - if (IdValExp.cap(1).length() > 3) { + thisFrame.setFrameId(static_cast(IdValExpMatched.captured(1).toInt(&ret, 16))); + if (IdValExpMatched.captured(1).length() > 3) + { thisFrame.setExtendedFrameFormat(true); - } else { + } + else + { thisFrame.setExtendedFrameFormat(false); } - QString val= IdValExp.cap(2); + QString val = IdValExpMatched.captured(2); - pos = 0; QByteArray bytes; if (val.startsWith("R") && val.at(1).isDigit()) { thisFrame.payload().resize( val.at(1).toLatin1() - '0' ); @@ -3734,12 +3740,13 @@ bool FrameFileIO::loadCanDumpFile(QString filename, QVector* frames) } else { thisFrame.setFrameType(QCanBusFrame::DataFrame); /* val byte per byte */ - while ((pos = valExp.indexIn(val, pos)) != -1) + QRegularExpressionMatch valExpMatch; + QRegularExpressionMatchIterator i = valExp.globalMatch(val); + while (i.hasNext()) { - bytes.append((char)valExp.cap(1).toInt(&ret, 16)); + valExpMatch = i.next(); + bytes.append((char)valExpMatch.captured(1).toInt(&ret, 16)); if(!ret) continue; - - pos += valExp.matchedLength(); } } thisFrame.setPayload(bytes); diff --git a/scriptcontainer.cpp b/scriptcontainer.cpp index 5cb63da..8720235 100644 --- a/scriptcontainer.cpp +++ b/scriptcontainer.cpp @@ -263,7 +263,7 @@ void CANScriptHelper::gotTargettedFrame(const CANFrame &frame) if (filters[i].checkFilter(frame.frameId(), frame.bus)) { QJSValueList args; - args << frame.bus << frame.frameId() << frame.payload().length(); + args << frame.bus << frame.frameId() << static_cast(frame.payload().length()); QJSValue dataBytes = scriptEngine->newArray(dataLen); for (int j = 0; j < dataLen; j++) dataBytes.setProperty(j, QJSValue(data[j])); @@ -341,7 +341,7 @@ void ISOTPScriptHelper::newISOMessage(ISOTP_MESSAGE msg) //qDebug() << "Got frame in script interface"; QJSValueList args; - args << msg.bus << msg.frameId() << msg.payload().length(); + args << msg.bus << msg.frameId() << static_cast(msg.payload().length()); QJSValue dataBytes = scriptEngine->newArray(static_cast(msg.payload().length())); for (int j = 0; j < msg.payload().length(); j++) dataBytes.setProperty(static_cast(j), QJSValue((unsigned char)msg.payload()[j])); @@ -420,7 +420,7 @@ void UDSScriptHelper::newUDSMessage(UDS_MESSAGE msg) qDebug() << "Got frame in script interface"; QJSValueList args; - args << msg.bus << msg.frameId() << msg.service << msg.subFunc << msg.payload().length(); + args << msg.bus << msg.frameId() << msg.service << msg.subFunc << static_cast(msg.payload().length()); QJSValue dataBytes = scriptEngine->newArray(static_cast(msg.payload().length())); for (int j = 0; j < msg.payload().length(); j++) dataBytes.setProperty(static_cast(j), QJSValue((unsigned char)msg.payload()[j]));