mirror of
https://github.com/swift-project/pilotclient.git
synced 2026-04-06 10:15:38 +08:00
refactor: Fix cppcoreguidelines-init-variables warnings
This commit is contained in:
@@ -376,7 +376,7 @@ namespace swift::misc::aviation
|
||||
if (m_combinedType.length() < 2) { return -1; }
|
||||
const QString c(m_combinedType.mid(1, 1));
|
||||
if (c == "-") { return -1; }
|
||||
bool ok;
|
||||
bool ok {};
|
||||
int ec = c.toInt(&ok);
|
||||
if (ok && ec >= 0 && ec < 10) { return ec; }
|
||||
return -1;
|
||||
|
||||
@@ -234,7 +234,7 @@ namespace swift::misc::aviation
|
||||
return false;
|
||||
}
|
||||
|
||||
bool ok;
|
||||
bool ok {};
|
||||
if (v.startsWith("F", Qt::CaseInsensitive))
|
||||
{
|
||||
this->setUnit(CLengthUnit::ft());
|
||||
|
||||
@@ -286,7 +286,7 @@ namespace swift::misc::aviation
|
||||
int CCallsign::getFlightNumberInt() const
|
||||
{
|
||||
if (this->isAtcCallsign()) { return -1; }
|
||||
bool ok;
|
||||
bool ok {};
|
||||
const int fn = this->getFlightNumber().toInt(&ok);
|
||||
return ok ? fn : -1;
|
||||
}
|
||||
|
||||
@@ -204,7 +204,7 @@ namespace swift::misc::aviation
|
||||
//! Incremental update or add object
|
||||
int incrementalUpdateOrAdd(const OBJ &objectBeforeChanges, const CPropertyIndexVariantMap &changedValues)
|
||||
{
|
||||
int c;
|
||||
int c {};
|
||||
const CCallsign cs = objectBeforeChanges.getCallsign();
|
||||
if (this->containsCallsign(cs))
|
||||
{
|
||||
|
||||
@@ -212,7 +212,7 @@ namespace swift::misc::aviation
|
||||
comFreq.parseFromString(input, sep);
|
||||
if (comFreq.isNull())
|
||||
{
|
||||
bool ok;
|
||||
bool ok {};
|
||||
const double f = CPqString::parseNumber(input, ok, sep);
|
||||
if (ok) { comFreq = CFrequency(f, f > 999 ? CFrequencyUnit::kHz() : CFrequencyUnit::MHz()); }
|
||||
else { comFreq = CFrequency::null(); }
|
||||
|
||||
@@ -444,7 +444,7 @@ namespace swift::misc::aviation
|
||||
const QDomNodeList generalList = doc.elementsByTagName("general");
|
||||
if (!generalList.isEmpty())
|
||||
{
|
||||
bool ok;
|
||||
bool ok {};
|
||||
const QDomNode general = generalList.at(0);
|
||||
QString route = general.firstChildElement("route").text();
|
||||
fp.setRoute(route.remove("DCT").simplified().trimmed());
|
||||
@@ -470,7 +470,7 @@ namespace swift::misc::aviation
|
||||
const QDomNodeList timeList = doc.elementsByTagName("times");
|
||||
if (!timeList.isEmpty())
|
||||
{
|
||||
bool ok;
|
||||
bool ok {};
|
||||
const QDomNode times = timeList.at(0);
|
||||
const QString enroute = times.firstChildElement("est_time_enroute").text();
|
||||
const int enrouteSecs = enroute.toInt(&ok);
|
||||
|
||||
@@ -54,7 +54,10 @@ namespace swift::misc::aviation
|
||||
bool CSelcal::isValidCode(const QString &code)
|
||||
{
|
||||
if (code.length() != 4) return false;
|
||||
int p1, p2, p3, p4;
|
||||
int p1 {};
|
||||
int p2 {};
|
||||
int p3 {};
|
||||
int p4 {};
|
||||
QString codeUpper = code.toUpper();
|
||||
if ((p1 = CSelcal::validCharacters().indexOf(codeUpper.at(0))) < 0) return false;
|
||||
if ((p2 = CSelcal::validCharacters().indexOf(codeUpper.at(1))) < 0) return false;
|
||||
|
||||
@@ -120,7 +120,7 @@ namespace swift::misc::aviation
|
||||
{
|
||||
if (CTransponder::isValidTransponderCode(transponderCode))
|
||||
{
|
||||
bool ok;
|
||||
bool ok {};
|
||||
this->setTransponderCode(transponderCode.toInt(&ok));
|
||||
}
|
||||
else { Q_ASSERT_X(false, "CTransponder::setTransponderCode", "illegal transponder value"); }
|
||||
@@ -129,7 +129,7 @@ namespace swift::misc::aviation
|
||||
bool CTransponder::isValidTransponderCode(const QString &transponderCode)
|
||||
{
|
||||
if (transponderCode.isEmpty() || transponderCode.length() > 4) return false;
|
||||
bool number;
|
||||
bool number {};
|
||||
int tc = transponderCode.toInt(&number);
|
||||
if (!number) return false;
|
||||
if (tc < 0 || tc > 7777) return false;
|
||||
|
||||
@@ -41,7 +41,7 @@ namespace swift::misc::db
|
||||
|
||||
void IDatastoreObjectWithIntegerKey::setDbKey(const QString &key)
|
||||
{
|
||||
bool ok;
|
||||
bool ok {};
|
||||
const int k = key.toInt(&ok);
|
||||
m_dbKey = ok ? k : -1;
|
||||
}
|
||||
@@ -65,7 +65,7 @@ namespace swift::misc::db
|
||||
int IDatastoreObjectWithIntegerKey::stringToDbKey(const QString &candidate)
|
||||
{
|
||||
if (candidate.isEmpty()) { return invalidDbKey(); }
|
||||
bool ok;
|
||||
bool ok {};
|
||||
int k = candidate.toInt(&ok);
|
||||
return ok ? k : invalidDbKey();
|
||||
}
|
||||
|
||||
@@ -40,7 +40,7 @@ QDBusArgument &operator<<(QDBusArgument &arg, const E &value)
|
||||
template <class E, std::enable_if_t<std::is_enum_v<E>, int> = 0>
|
||||
const QDBusArgument &operator>>(const QDBusArgument &arg, E &value)
|
||||
{
|
||||
int temp;
|
||||
int temp {};
|
||||
arg.beginStructure();
|
||||
arg >> temp;
|
||||
arg.endStructure();
|
||||
|
||||
@@ -139,7 +139,7 @@ namespace swift::misc
|
||||
else if (part.contains("port=", Qt::CaseInsensitive))
|
||||
{
|
||||
const QString p = part.mid(part.lastIndexOf("=") + 1).trimmed();
|
||||
bool ok;
|
||||
bool ok {};
|
||||
port = p.toInt(&ok);
|
||||
if (!ok) { port = -1; }
|
||||
}
|
||||
@@ -158,7 +158,7 @@ namespace swift::misc
|
||||
|
||||
bool CDBusServer::dBusAddressToHostAndPort(const QString &dbusAddress, QString &o_host, QString &o_port)
|
||||
{
|
||||
int port;
|
||||
int port {};
|
||||
const bool s = dBusAddressToHostAndPort(dbusAddress, o_host, port);
|
||||
o_port = QString::number(port);
|
||||
return s;
|
||||
|
||||
@@ -75,7 +75,7 @@ namespace swift::misc::geo
|
||||
}
|
||||
|
||||
// number only -> parsed as degrees
|
||||
bool isDouble;
|
||||
bool isDouble {};
|
||||
const double valueDegrees = wgs.toDouble(&isDouble);
|
||||
if (isDouble)
|
||||
{
|
||||
@@ -93,7 +93,7 @@ namespace swift::misc::geo
|
||||
while (i.hasNext() && c < 3)
|
||||
{
|
||||
const QRegularExpressionMatch match = i.next();
|
||||
bool ok;
|
||||
bool ok {};
|
||||
if (match.hasMatch())
|
||||
{
|
||||
const QString cap = match.captured(0);
|
||||
|
||||
@@ -206,7 +206,7 @@ namespace swift::misc
|
||||
if (isFallThroughEnabled(handlers))
|
||||
{
|
||||
Q_ASSERT_X(m_oldHandler, Q_FUNC_INFO, "Handler must be installed");
|
||||
QtMsgType type;
|
||||
QtMsgType type {};
|
||||
QString category;
|
||||
QString message;
|
||||
statusMessage.toQtLogTriple(&type, &category, &message);
|
||||
|
||||
@@ -363,7 +363,7 @@ namespace swift::misc
|
||||
|
||||
void CLogPattern::unmarshallFromDbus(const QDBusArgument &argument)
|
||||
{
|
||||
quint8 severities;
|
||||
quint8 severities {};
|
||||
QStringList strings;
|
||||
argument >> severities >> m_strategy >> strings;
|
||||
m_strings = QSet<QString>(strings.begin(), strings.end());
|
||||
@@ -385,7 +385,7 @@ namespace swift::misc
|
||||
|
||||
void CLogPattern::unmarshalFromDataStream(QDataStream &stream)
|
||||
{
|
||||
quint8 severities;
|
||||
quint8 severities {};
|
||||
QStringList strings;
|
||||
stream >> severities >> m_strategy >> strings;
|
||||
m_strings = QSet<QString>(strings.begin(), strings.end());
|
||||
|
||||
@@ -18,8 +18,8 @@ namespace swift::misc::math
|
||||
double CMathUtils::round(double value, int digits)
|
||||
{
|
||||
// gosh, is there no Qt method for this??? It's year 2013
|
||||
double fractpart, intpart;
|
||||
fractpart = modf(value, &intpart);
|
||||
double intpart {};
|
||||
double fractpart = modf(value, &intpart);
|
||||
if (epsilonZeroLimits(fractpart)) { return value; } // do not mess any "integers" to the worse
|
||||
const double m = pow(10.0, digits);
|
||||
const qint64 ri = qRound64(value * m); // do not loose any range here
|
||||
@@ -30,8 +30,8 @@ namespace swift::misc::math
|
||||
double CMathUtils::roundEpsilon(double value, double epsilon)
|
||||
{
|
||||
if (epsilonZeroLimits(epsilon)) { return value; } // avoid division by 0
|
||||
double fractpart, intpart;
|
||||
fractpart = modf(value, &intpart);
|
||||
double intpart {};
|
||||
double fractpart = modf(value, &intpart);
|
||||
if (epsilonZeroLimits(fractpart)) { return value; } // do not mess any "integers" to the worse
|
||||
const double roundValue = value / epsilon;
|
||||
const qint64 ri = qRound64(roundValue);
|
||||
@@ -98,7 +98,7 @@ namespace swift::misc::math
|
||||
|
||||
QString CMathUtils::fractionalPartAsString(double value, int width)
|
||||
{
|
||||
double intpart;
|
||||
double intpart {};
|
||||
const double fractpart = modf(value, &intpart);
|
||||
const int prec = width >= 0 ? width + 1 : 10;
|
||||
const QString f = QString::number(fractpart, 'f', prec); // avoid scientific notation
|
||||
|
||||
@@ -57,7 +57,7 @@ namespace swift::misc::math
|
||||
//! Fractional part of value
|
||||
static inline double fract(double value)
|
||||
{
|
||||
double unused;
|
||||
double unused {};
|
||||
return modf(value, &unused);
|
||||
}
|
||||
|
||||
|
||||
@@ -135,7 +135,7 @@ namespace swift::misc::network
|
||||
|
||||
bool CNetworkUtils::isValidPort(const QString &port)
|
||||
{
|
||||
bool success;
|
||||
bool success {};
|
||||
int p = port.toInt(&success);
|
||||
if (!success) return false;
|
||||
return (p >= 1 && p <= 65535);
|
||||
|
||||
@@ -80,7 +80,7 @@ namespace swift::misc::network
|
||||
bool CUrlLogList::markAsReceived(const QNetworkReply *nwReply, bool success)
|
||||
{
|
||||
Q_ASSERT_X(nwReply, Q_FUNC_INFO, "missing reply");
|
||||
bool ok;
|
||||
bool ok {};
|
||||
const int id = nwReply->property(CUrlLog::propertyNameId()).toInt(&ok);
|
||||
return (ok && id >= 0) ? this->markAsReceived(id, success) : false;
|
||||
}
|
||||
|
||||
@@ -43,7 +43,7 @@ namespace swift::misc::physical_quantities
|
||||
unit = unit.trimmed(); // trim after replace, not before
|
||||
|
||||
if (unit.isEmpty() || number.isEmpty()) { return v; }
|
||||
bool success;
|
||||
bool success {};
|
||||
const double numberD = parseNumber(number, success, mode);
|
||||
if (!success) { return v; }
|
||||
|
||||
|
||||
@@ -69,7 +69,7 @@ namespace swift::misc::physical_quantities
|
||||
const QString hStr = hhmm.left(2);
|
||||
const QString mStr = hhmm.right(2);
|
||||
|
||||
bool ok;
|
||||
bool ok {};
|
||||
const int h = hStr.toInt(&ok);
|
||||
if (!ok || h < 0 || h > 23) { return false; }
|
||||
|
||||
|
||||
@@ -58,7 +58,7 @@ namespace swift::misc
|
||||
for (const auto &index : QStringView { indexes }.split(';'))
|
||||
{
|
||||
if (index.isEmpty()) { continue; }
|
||||
bool ok;
|
||||
bool ok {};
|
||||
int i = index.toInt(&ok);
|
||||
Q_ASSERT(ok);
|
||||
Q_ASSERT(i >= static_cast<int>(CPropertyIndexRef::GlobalIndexCValueObject));
|
||||
|
||||
@@ -310,7 +310,7 @@ namespace swift::misc::simulation
|
||||
|
||||
int ISimulationEnvironmentProvider::cleanUpElevations(const ICoordinateGeodetic &referenceCoordinate, int maxNumber)
|
||||
{
|
||||
int currentMax;
|
||||
int currentMax {};
|
||||
CCoordinateGeodeticList coordinates(this->getAllElevationCoordinates(currentMax));
|
||||
if (maxNumber < 0) { maxNumber = currentMax; }
|
||||
const int size = coordinates.size();
|
||||
@@ -390,8 +390,8 @@ namespace swift::misc::simulation
|
||||
const int m = foundMissed.second;
|
||||
const double hitRatioPercent = 100.0 * static_cast<double>(f) / static_cast<double>(f + m);
|
||||
|
||||
int elvGnd;
|
||||
int elv;
|
||||
int elvGnd {};
|
||||
int elv {};
|
||||
{
|
||||
QReadLocker l(&m_lockElvCoordinates);
|
||||
elvGnd = m_elvCoordinatesGnd.sizeInt();
|
||||
|
||||
@@ -239,7 +239,7 @@ namespace swift::misc
|
||||
static bool canHandleIndex(CPropertyIndexRef index);
|
||||
|
||||
//! Constructor
|
||||
ITimestampWithOffsetBased() : ITimestampBased() {}
|
||||
ITimestampWithOffsetBased() = default;
|
||||
|
||||
//! Constructor
|
||||
ITimestampWithOffsetBased(qint64 msSincePoch) : ITimestampBased(msSincePoch) {}
|
||||
|
||||
@@ -543,7 +543,7 @@ namespace swift::misc
|
||||
else if (QMetaType(localUserType).flags() & QMetaType::IsEnumeration)
|
||||
{
|
||||
arg.beginStructure();
|
||||
int i;
|
||||
int i {};
|
||||
arg >> i;
|
||||
arg.endStructure();
|
||||
|
||||
|
||||
@@ -224,6 +224,7 @@ namespace swift::misc
|
||||
template <typename F>
|
||||
static CWorker *fromTask(QObject *owner, const QString &name, F &&task)
|
||||
{
|
||||
// NOLINTNEXTLINE(cppcoreguidelines-init-variables)
|
||||
int typeId = qMetaTypeId<std::decay_t<decltype(std::forward<F>(task)())>>();
|
||||
return fromTaskImpl(owner, name, typeId, [task = std::forward<F>(task)]() mutable {
|
||||
if constexpr (std::is_void_v<decltype(task())>)
|
||||
|
||||
Reference in New Issue
Block a user