From c6463514b91f71562301ff041e6f4b89f304f4d0 Mon Sep 17 00:00:00 2001 From: Steru Date: Fri, 16 Aug 2024 15:47:19 +0200 Subject: Fixed iteration over QList. --- src/model/Sport.cpp | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/src/model/Sport.cpp b/src/model/Sport.cpp index 80bfe94..9dd6c69 100644 --- a/src/model/Sport.cpp +++ b/src/model/Sport.cpp @@ -131,7 +131,8 @@ void Sport::lastName(QList &competitors) { // validate competitors if (competitors.isEmpty()) return; - for (Competitor comp : competitors) { + for (int i = 0; i < competitors.size(); i++) { + Competitor comp = competitors.value(i); string fullName = comp.getName().toUtf8().constData(); // regex to identify names, written in CAPS @@ -203,7 +204,9 @@ QList Sport::getCompetitorsByCategory(QString category) { // add all competitors from one unit for (const QJsonValueRef &compRef : unit["competitors"].toArray()) { - competitors.push_back(CompetitorWithResults(compRef.toObject())); + CompetitorWithResults comp = new CompetitorWithResults(); // TODO declare comp + comp.setCompetitorWithResults(compRef.toObject()); + competitors.push_back(comp); } } @@ -273,7 +276,9 @@ QList Sport::getCompetitorsWithMedal() { // convert map to QJsonArray QList output; for (const pair &competitor : competitors) { - output.append(MedalWinner(competitor.second)); + MedalWinner comp = new MedalWinner(); // TODO declare comp + comp.setMedalWinner(competitor.second); + output.append(comp); } return output; @@ -332,8 +337,8 @@ void Sport::filterByCountry(QList &competitors, QString nocShort) { * @param filter The string, which should be contained. */ void Sport::filterCompetitors(QList &competitors, QString filter) { - for (qsizetype i = 0; i < competitors.size(); i++) { - if (competitors.value(i).getNOC().contains(filter)) { + for (int i = 0; i < competitors.size(); i++) { + if (!competitors.value(i).getNOC().contains(filter)) { competitors.remove(i); i--; } -- cgit v1.2.3