File indexing completed on 2025-02-02 05:02:27

0001 /*
0002     SPDX-FileCopyrightText: 2022 Volker Krause <vkrause@kde.org>
0003     SPDX-License-Identifier: LGPL-2.0-or-later
0004 */
0005 
0006 #ifndef COUNTRYSUBDIVISIONMODEL_H
0007 #define COUNTRYSUBDIVISIONMODEL_H
0008 
0009 #include <KCountry>
0010 #include <KCountrySubdivision>
0011 
0012 #include <QAbstractListModel>
0013 
0014 /** Country subdivision model, for a given country. */
0015 class CountrySubdivisionModel : public QAbstractListModel
0016 {
0017     Q_OBJECT
0018     Q_PROPERTY(KCountry country READ country WRITE setCountry NOTIFY countryChanged)
0019 
0020 public:
0021     enum {
0022         CodeRole = Qt::UserRole,
0023         SubdivisionRole,
0024     };
0025 
0026     explicit CountrySubdivisionModel(QObject *parent = nullptr);
0027     ~CountrySubdivisionModel();
0028 
0029     KCountry country() const;
0030     void setCountry(const KCountry &country);
0031 
0032     int rowCount(const QModelIndex &parent) const override;
0033     QVariant data(const QModelIndex &index, int role) const override;
0034     QHash<int, QByteArray> roleNames() const override;
0035 
0036     Q_INVOKABLE int rowForNameOrCode(const QString &input) const;
0037 
0038 Q_SIGNALS:
0039     void countryChanged();
0040 
0041 private:
0042     KCountry m_country;
0043     QList<KCountrySubdivision> m_subdivs;
0044 };
0045 
0046 #endif // COUNTRYSUBDIVISIONMODEL_H