swift
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 
8 using namespace swift::misc;
9 
10 namespace 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()) { return inContainer; }
21  CCountryList outContainer;
22  bool end = false;
23  for (const CCountry &country : inContainer)
24  {
25  if (!m_isoCode.isEmpty())
26  {
27  if (country.getIsoCode() != m_isoCode) { continue; }
28  end = true; // there should be only one designator
29  }
30 
31  if (!this->m_name.isEmpty())
32  {
33  if (!this->stringMatchesFilterExpression(country.getName(), this->m_name)) { continue; }
34  }
35 
36  outContainer.push_back(country);
37  if (end) { break; }
38  }
39  return outContainer;
40  }
41 } // namespace swift::gui::models
virtual 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
Standard string search supporting wildcard at begin and end: "*xyz", "abc*".
Definition: modelfilter.cpp:31
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:305
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:338