chore: fixed android build
This commit is contained in:
parent
a1ca994c8b
commit
c128ba981c
11 changed files with 28 additions and 22 deletions
84
client/ui/models/api/apiCountryModel.cpp
Normal file
84
client/ui/models/api/apiCountryModel.cpp
Normal file
|
|
@ -0,0 +1,84 @@
|
|||
#include "apiCountryModel.h"
|
||||
|
||||
#include <QJsonObject>
|
||||
|
||||
#include "logger.h"
|
||||
|
||||
namespace
|
||||
{
|
||||
Logger logger("ApiCountryModel");
|
||||
|
||||
namespace configKey
|
||||
{
|
||||
constexpr char serverCountryCode[] = "server_country_code";
|
||||
constexpr char serverCountryName[] = "server_country_name";
|
||||
}
|
||||
}
|
||||
|
||||
ApiCountryModel::ApiCountryModel(QObject *parent) : QAbstractListModel(parent)
|
||||
{
|
||||
}
|
||||
|
||||
int ApiCountryModel::rowCount(const QModelIndex &parent) const
|
||||
{
|
||||
Q_UNUSED(parent)
|
||||
return m_countries.size();
|
||||
}
|
||||
|
||||
QVariant ApiCountryModel::data(const QModelIndex &index, int role) const
|
||||
{
|
||||
if (!index.isValid() || index.row() < 0 || index.row() >= static_cast<int>(rowCount()))
|
||||
return QVariant();
|
||||
|
||||
QJsonObject countryInfo = m_countries.at(index.row()).toObject();
|
||||
|
||||
switch (role) {
|
||||
case CountryCodeRole: {
|
||||
return countryInfo.value(configKey::serverCountryCode).toString();
|
||||
}
|
||||
case CountryNameRole: {
|
||||
return countryInfo.value(configKey::serverCountryName).toString();
|
||||
}
|
||||
case CountryImageCodeRole: {
|
||||
return countryInfo.value(configKey::serverCountryCode).toString().toUpper();
|
||||
}
|
||||
}
|
||||
|
||||
return QVariant();
|
||||
}
|
||||
|
||||
void ApiCountryModel::updateModel(const QJsonArray &countries, const QString ¤tCountryCode)
|
||||
{
|
||||
beginResetModel();
|
||||
|
||||
m_countries = countries;
|
||||
for (int i = 0; i < m_countries.size(); i++) {
|
||||
if (m_countries.at(i).toObject().value(configKey::serverCountryCode).toString() == currentCountryCode) {
|
||||
m_currentIndex = i;
|
||||
emit currentIndexChanged(m_currentIndex);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
endResetModel();
|
||||
}
|
||||
|
||||
int ApiCountryModel::getCurrentIndex()
|
||||
{
|
||||
return m_currentIndex;
|
||||
}
|
||||
|
||||
void ApiCountryModel::setCurrentIndex(const int i)
|
||||
{
|
||||
m_currentIndex = i;
|
||||
emit currentIndexChanged(m_currentIndex);
|
||||
}
|
||||
|
||||
QHash<int, QByteArray> ApiCountryModel::roleNames() const
|
||||
{
|
||||
QHash<int, QByteArray> roles;
|
||||
roles[CountryNameRole] = "countryName";
|
||||
roles[CountryCodeRole] = "countryCode";
|
||||
roles[CountryImageCodeRole] = "countryImageCode";
|
||||
return roles;
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue