Skip to content

Commit 8a5294e

Browse files
committed
ImportExport: Avoid duplicate warnings
In addition to 'addWarning()' 'addWarningOnce()' only adds a warning to the list of warnings if the warning is not yet in the list.
1 parent 2da0885 commit 8a5294e

File tree

2 files changed

+17
-2
lines changed

2 files changed

+17
-2
lines changed

src/fileformats/file_import_export.cpp

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/*
22
* Copyright 2012, 2013 Pete Curtis
33
* Copyright 2013, 2014 Thomas Schöps
4-
* Copyright 2013-2020 Kai Pastor
4+
* Copyright 2013-2020, 2024 Kai Pastor
55
*
66
* This file is part of OpenOrienteering.
77
*
@@ -21,6 +21,7 @@
2121

2222
#include "file_import_export.h"
2323

24+
#include <algorithm>
2425
#include <exception>
2526
#include <memory>
2627
#include <utility>
@@ -84,6 +85,13 @@ void ImportExport::setOption(const QString& name, const QVariant& value)
8485
}
8586

8687

88+
void ImportExport::addWarningOnce(const QString& str)
89+
{
90+
if (std::find(warnings_.begin(), warnings_.end(), str) == warnings_.end())
91+
warnings_.emplace_back(str);
92+
}
93+
94+
8795
// ### Importer ###
8896

8997
Importer::~Importer() = default;

src/fileformats/file_import_export.h

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/*
22
* Copyright 2012, 2013 Pete Curtis
3-
* Copyright 2018 Kai Pastor
3+
* Copyright 2018, 2024 Kai Pastor
44
*
55
* This file is part of OpenOrienteering.
66
*
@@ -112,6 +112,13 @@ class ImportExport
112112
*/
113113
void addWarning(const QString& str) { warnings_.emplace_back(str); }
114114

115+
/**
116+
* Adds a string to the current list of warnings if not yet in the list.
117+
*
118+
* The provided message should be translated.
119+
*/
120+
void addWarningOnce(const QString& str);
121+
115122
/**
116123
* Returns the current list of warnings collected by this object.
117124
*/

0 commit comments

Comments
 (0)