Fixed arch build

Signed-off-by: Trial97 <alexandru.tripon97@gmail.com>
This commit is contained in:
Trial97 2023-10-14 09:40:56 +03:00
parent 7015b8f7b2
commit 023b3e3c39
No known key found for this signature in database
GPG Key ID: 55EF5DA53DB36318
2 changed files with 22 additions and 18 deletions

View File

@ -206,7 +206,7 @@ void TranslationsModel::indexReceived()
reloadLocalFiles();
auto language = d->m_system_locale;
if (!findLanguage(language)) {
if (!findLanguageAsOptional(language).has_value()) {
language = d->m_system_language;
}
selectLanguage(language);
@ -417,14 +417,17 @@ int TranslationsModel::columnCount([[maybe_unused]] const QModelIndex& parent) c
return 2;
}
Language* TranslationsModel::findLanguage(const QString& key)
QVector<Language>::Iterator TranslationsModel::findLanguage(const QString& key)
{
auto found = std::find_if(d->m_languages.begin(), d->m_languages.end(), [&](Language& lang) { return lang.key == key; });
if (found == d->m_languages.end()) {
return nullptr;
} else {
return found;
}
return std::find_if(d->m_languages.begin(), d->m_languages.end(), [&](Language& lang) { return lang.key == key; });
}
std::optional<Language> TranslationsModel::findLanguageAsOptional(const QString& key)
{
auto found = findLanguage(key);
if (found != d->m_languages.end())
return *found;
return {};
}
void TranslationsModel::setUseSystemLocale(bool useSystemLocale)
@ -436,13 +439,13 @@ void TranslationsModel::setUseSystemLocale(bool useSystemLocale)
bool TranslationsModel::selectLanguage(QString key)
{
QString& langCode = key;
auto langPtr = findLanguage(key);
auto langPtr = findLanguageAsOptional(key);
if (langCode.isEmpty()) {
d->no_language_set = true;
}
if (!langPtr) {
if (!langPtr.has_value()) {
qWarning() << "Selected invalid language" << key << ", defaulting to" << defaultLangCode;
langCode = defaultLangCode;
} else {
@ -527,9 +530,8 @@ bool TranslationsModel::selectLanguage(QString key)
QModelIndex TranslationsModel::selectedIndex()
{
auto found = findLanguage(d->m_selectedLanguage);
if (found) {
// QVector iterator freely converts to pointer to contained type
return index(found - d->m_languages.begin(), 0, QModelIndex());
if (found != d->m_languages.end()) {
return index(std::distance(d->m_languages.begin(), found), 0, QModelIndex());
}
return QModelIndex();
}
@ -562,8 +564,8 @@ void TranslationsModel::updateLanguage(QString key)
qWarning() << "Cannot update builtin language" << key;
return;
}
auto found = findLanguage(key);
if (!found) {
auto found = findLanguageAsOptional(key);
if (!found.has_value()) {
qWarning() << "Cannot update invalid language" << key;
return;
}
@ -578,8 +580,8 @@ void TranslationsModel::downloadTranslation(QString key)
d->m_nextDownload = key;
return;
}
auto lang = findLanguage(key);
if (!lang) {
auto lang = findLanguageAsOptional(key);
if (!lang.has_value()) {
qWarning() << "Will not download an unknown translation" << key;
return;
}

View File

@ -17,6 +17,7 @@
#include <QAbstractListModel>
#include <memory>
#include <optional>
struct Language;
@ -40,7 +41,8 @@ class TranslationsModel : public QAbstractListModel {
void setUseSystemLocale(bool useSystemLocale);
private:
Language* findLanguage(const QString& key);
QVector<Language>::Iterator findLanguage(const QString& key);
std::optional<Language> findLanguageAsOptional(const QString& key);
void reloadLocalFiles();
void downloadTranslation(QString key);
void downloadNext();