Files
pilotclient/src/blackmisc/countrylist.h
Lars Toenning bcc4bdd31e Add SPDX identifiers for REUSE compliance
Co-authored-by: Mat Sutcliffe <oktal3700@gmail.com>
2023-10-03 09:29:49 +02:00

75 lines
2.2 KiB
C++

// SPDX-FileCopyrightText: Copyright (C) 2015 swift Project Community / Contributors
// SPDX-License-Identifier: GPL-3.0-or-later OR LicenseRef-swift-pilot-client-1
//! \file
#ifndef BLACKMISC_COUNTRYLIST_H
#define BLACKMISC_COUNTRYLIST_H
#include "blackmisc/db/datastoreobjectlist.h"
#include "blackmisc/blackmiscexport.h"
#include "blackmisc/collection.h"
#include "blackmisc/country.h"
#include "blackmisc/sequence.h"
#include <QJsonArray>
#include <QMetaType>
#include <QString>
#include <QStringList>
#include <tuple>
BLACK_DECLARE_SEQUENCE_MIXINS(BlackMisc, CCountry, CCountryList)
namespace BlackMisc
{
//! Value object encapsulating a list of countries.
//! \remark: I do not use CCollection as I want to sort per column
class BLACKMISC_EXPORT CCountryList :
public CSequence<CCountry>,
public BlackMisc::Db::IDatastoreObjectList<CCountry, CCountryList, QString>,
public BlackMisc::Mixin::MetaType<CCountryList>
{
public:
BLACKMISC_DECLARE_USING_MIXIN_METATYPE(CCountryList)
using CSequence::CSequence;
//! Default constructor.
CCountryList();
//! Construct from a base class object.
CCountryList(const CSequence<CCountry> &other);
//! Find by ISO code
CCountry findByIsoCode(const QString &isoCode) const;
//! Find "best match" by country
CCountry findBestMatchByCountryName(const QString &candidate) const;
//! Find first by alias
CCountry findFirstByAlias(const QString &alias) const;
//! ISO/name string list
QStringList toIsoNameList(bool sorted = false) const;
//! Name/ISO string list
QStringList toNameIsoList(bool sorted = false) const;
//! Name string list
QStringList toNameList(bool sorted = false) const;
//! All ISO codes
QStringList toIsoList(bool sorted = false) const;
//! All ISO 3 codes
QStringList toIso3List(bool sorted = false) const;
//! From our database JSON format
static CCountryList fromDatabaseJson(const QJsonArray &array);
};
} // namespace
Q_DECLARE_METATYPE(BlackMisc::CCountryList)
Q_DECLARE_METATYPE(BlackMisc::CCollection<BlackMisc::CCountry>)
#endif // guard