Merge pull request #1709 from Trial97/arch_build
Fix compatibility with Qt 6.6
This commit is contained in:
commit
05d7cc31bf
@ -206,7 +206,7 @@ void TranslationsModel::indexReceived()
|
|||||||
reloadLocalFiles();
|
reloadLocalFiles();
|
||||||
|
|
||||||
auto language = d->m_system_locale;
|
auto language = d->m_system_locale;
|
||||||
if (!findLanguage(language)) {
|
if (!findLanguageAsOptional(language).has_value()) {
|
||||||
language = d->m_system_language;
|
language = d->m_system_language;
|
||||||
}
|
}
|
||||||
selectLanguage(language);
|
selectLanguage(language);
|
||||||
@ -417,14 +417,17 @@ int TranslationsModel::columnCount([[maybe_unused]] const QModelIndex& parent) c
|
|||||||
return 2;
|
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; });
|
return 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 {
|
std::optional<Language> TranslationsModel::findLanguageAsOptional(const QString& key)
|
||||||
return found;
|
{
|
||||||
}
|
auto found = findLanguage(key);
|
||||||
|
if (found != d->m_languages.end())
|
||||||
|
return *found;
|
||||||
|
return {};
|
||||||
}
|
}
|
||||||
|
|
||||||
void TranslationsModel::setUseSystemLocale(bool useSystemLocale)
|
void TranslationsModel::setUseSystemLocale(bool useSystemLocale)
|
||||||
@ -436,13 +439,13 @@ void TranslationsModel::setUseSystemLocale(bool useSystemLocale)
|
|||||||
bool TranslationsModel::selectLanguage(QString key)
|
bool TranslationsModel::selectLanguage(QString key)
|
||||||
{
|
{
|
||||||
QString& langCode = key;
|
QString& langCode = key;
|
||||||
auto langPtr = findLanguage(key);
|
auto langPtr = findLanguageAsOptional(key);
|
||||||
|
|
||||||
if (langCode.isEmpty()) {
|
if (langCode.isEmpty()) {
|
||||||
d->no_language_set = true;
|
d->no_language_set = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!langPtr) {
|
if (!langPtr.has_value()) {
|
||||||
qWarning() << "Selected invalid language" << key << ", defaulting to" << defaultLangCode;
|
qWarning() << "Selected invalid language" << key << ", defaulting to" << defaultLangCode;
|
||||||
langCode = defaultLangCode;
|
langCode = defaultLangCode;
|
||||||
} else {
|
} else {
|
||||||
@ -527,9 +530,8 @@ bool TranslationsModel::selectLanguage(QString key)
|
|||||||
QModelIndex TranslationsModel::selectedIndex()
|
QModelIndex TranslationsModel::selectedIndex()
|
||||||
{
|
{
|
||||||
auto found = findLanguage(d->m_selectedLanguage);
|
auto found = findLanguage(d->m_selectedLanguage);
|
||||||
if (found) {
|
if (found != d->m_languages.end()) {
|
||||||
// QVector iterator freely converts to pointer to contained type
|
return index(std::distance(d->m_languages.begin(), found), 0, QModelIndex());
|
||||||
return index(found - d->m_languages.begin(), 0, QModelIndex());
|
|
||||||
}
|
}
|
||||||
return QModelIndex();
|
return QModelIndex();
|
||||||
}
|
}
|
||||||
@ -562,8 +564,8 @@ void TranslationsModel::updateLanguage(QString key)
|
|||||||
qWarning() << "Cannot update builtin language" << key;
|
qWarning() << "Cannot update builtin language" << key;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
auto found = findLanguage(key);
|
auto found = findLanguageAsOptional(key);
|
||||||
if (!found) {
|
if (!found.has_value()) {
|
||||||
qWarning() << "Cannot update invalid language" << key;
|
qWarning() << "Cannot update invalid language" << key;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -578,8 +580,8 @@ void TranslationsModel::downloadTranslation(QString key)
|
|||||||
d->m_nextDownload = key;
|
d->m_nextDownload = key;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
auto lang = findLanguage(key);
|
auto lang = findLanguageAsOptional(key);
|
||||||
if (!lang) {
|
if (!lang.has_value()) {
|
||||||
qWarning() << "Will not download an unknown translation" << key;
|
qWarning() << "Will not download an unknown translation" << key;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -17,6 +17,7 @@
|
|||||||
|
|
||||||
#include <QAbstractListModel>
|
#include <QAbstractListModel>
|
||||||
#include <memory>
|
#include <memory>
|
||||||
|
#include <optional>
|
||||||
|
|
||||||
struct Language;
|
struct Language;
|
||||||
|
|
||||||
@ -40,7 +41,8 @@ class TranslationsModel : public QAbstractListModel {
|
|||||||
void setUseSystemLocale(bool useSystemLocale);
|
void setUseSystemLocale(bool useSystemLocale);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
Language* findLanguage(const QString& key);
|
QVector<Language>::Iterator findLanguage(const QString& key);
|
||||||
|
std::optional<Language> findLanguageAsOptional(const QString& key);
|
||||||
void reloadLocalFiles();
|
void reloadLocalFiles();
|
||||||
void downloadTranslation(QString key);
|
void downloadTranslation(QString key);
|
||||||
void downloadNext();
|
void downloadNext();
|
||||||
|
Loading…
Reference in New Issue
Block a user