File indexing completed on 2024-12-22 04:31:17

0001 #include "citiesmodel.h"
0002 
0003 #include <MauiKit3/ImageTools/cities.h>
0004 #include <MauiKit3/ImageTools/city.h>
0005 
0006 CitiesModel::CitiesModel(QObject *parent) : MauiList(parent)
0007 {
0008 
0009 }
0010 
0011 const QStringList &CitiesModel::cities() const
0012 {
0013     return m_cities;
0014 }
0015 
0016 void CitiesModel::setCities(const QStringList &newCities)
0017 {
0018     if (m_cities == newCities)
0019         return;
0020     m_cities = newCities;
0021     Q_EMIT citiesChanged();
0022 }
0023 
0024 
0025 void CitiesModel::componentComplete()
0026 {
0027     connect(this, &CitiesModel::citiesChanged, this, &CitiesModel::setList);
0028     setList ();
0029 }
0030 
0031 const FMH::MODEL_LIST &CitiesModel::items() const
0032 {
0033     return m_list;
0034 }
0035 
0036 void CitiesModel::setList()
0037 {
0038     Q_EMIT this->preListChanged();
0039     this->m_list.clear();
0040     auto cities = Cities::getInstance();
0041     for (const auto &cityId : (m_cities)) {
0042         City city = cities->city(cityId);
0043 
0044         if(!city.isValid())
0045             continue;
0046 
0047         this->m_list << FMH::MODEL( {
0048                                         {FMH::MODEL_KEY::COUNTRY, city.country()},
0049                                         {FMH::MODEL_KEY::ID, city.id()},
0050                                         {FMH::MODEL_KEY::NAME, city.name()}
0051                                     });
0052     }
0053     Q_EMIT this->postListChanged();
0054 }