swift
Loading...
Searching...
No Matches
countryfilter.cpp
1// SPDX-FileCopyrightText: Copyright (C) 2015 swift Project Community / Contributors
2// SPDX-License-Identifier: GPL-3.0-or-later OR LicenseRef-swift-pilot-client-1
3
5
6#include "misc/country.h"
7
8using namespace swift::misc;
9
10namespace swift::gui::models
11{
12 CCountryFilter::CCountryFilter(const QString &isoCode, const QString &name)
13 : m_isoCode(isoCode.trimmed().toUpper()), m_name(name.trimmed())
14 {
15 this->m_valid = !(this->m_isoCode.isEmpty() && this->m_name.isEmpty());
16 }
17
19 {
20 if (!this->isValid())
21 {
22 return inContainer;
23 }
24 CCountryList outContainer;
25 bool end = false;
26 for (const CCountry &country : inContainer)
27 {
28 if (!m_isoCode.isEmpty())
29 {
30 if (country.getIsoCode() != m_isoCode)
31 {
32 continue;
33 }
34 end = true; // there should be only one designator
35 }
36
37 if (!this->m_name.isEmpty())
38 {
39 if (!this->stringMatchesFilterExpression(country.getName(), this->m_name))
40 {
41 continue;
42 }
43 }
44
45 outContainer.push_back(country);
46 if (end)
47 {
48 break;
49 }
50 }
51 return outContainer;
52 }
53} // namespace swift::gui::models
CCountryFilter(const QString &isoCode, const QString &name)
Constructor.
swift::misc::CCountryList filter(const swift::misc::CCountryList &inContainer) const
Used container data.
bool stringMatchesFilterExpression(const QString &value, const QString &filter, Qt::CaseSensitivity cs=Qt::CaseInsensitive) const
Value object encapsulating a list of countries.
Definition countrylist.h:32
void push_back(const T &value)
Appends an element at the end of the sequence.
Definition sequence.h:308
Models to be used with views, mainly QTableView.
Free functions in swift::misc.
T::const_iterator end(const LockFreeReader< T > &reader)
Non-member begin() and end() for so LockFree containers can be used in ranged for loops.
Definition lockfree.h:264