[libcalamares] Rename classes describing Translations

- the name 'Label' was a relic of the class being UI-centered
This commit is contained in:
Adriaan de Groot 2021-07-26 11:28:11 +02:00
parent d6825c4986
commit bf9f1c95bc
9 changed files with 43 additions and 43 deletions

View File

@ -46,14 +46,14 @@ namespace CalamaresUtils
namespace Locale namespace Locale
{ {
Label::Label( QObject* parent ) Translation::Translation( QObject* parent )
: Label( QString(), LabelFormat::IfNeededWithCountry, parent ) : Translation( QString(), LabelFormat::IfNeededWithCountry, parent )
{ {
} }
Label::Label( const QString& locale, LabelFormat format, QObject* parent ) Translation::Translation( const QString& locale, LabelFormat format, QObject* parent )
: QObject( parent ) : QObject( parent )
, m_locale( Label::getLocale( locale ) ) , m_locale( getLocale( locale ) )
, m_localeId( locale.isEmpty() ? m_locale.name() : locale ) , m_localeId( locale.isEmpty() ? m_locale.name() : locale )
{ {
auto special = specialCase( locale ); auto special = specialCase( locale );
@ -80,7 +80,7 @@ Label::Label( const QString& locale, LabelFormat format, QObject* parent )
} }
QLocale QLocale
Label::getLocale( const QString& localeName ) Translation::getLocale( const QString& localeName )
{ {
if ( localeName.isEmpty() ) if ( localeName.isEmpty() )
{ {

View File

@ -34,7 +34,7 @@ namespace Locale
* - `ca@valencia` is the Catalan dialect spoken in Valencia. * - `ca@valencia` is the Catalan dialect spoken in Valencia.
* There is no Qt code for it. * There is no Qt code for it.
*/ */
class Label : public QObject class Translation : public QObject
{ {
Q_OBJECT Q_OBJECT
@ -47,7 +47,7 @@ public:
}; };
/** @brief Empty locale. This uses the system-default locale. */ /** @brief Empty locale. This uses the system-default locale. */
Label( QObject* parent = nullptr ); Translation( QObject* parent = nullptr );
/** @brief Construct from a locale name. /** @brief Construct from a locale name.
* *
@ -55,7 +55,7 @@ public:
* The @p format determines whether the country name is always present * The @p format determines whether the country name is always present
* in the label (human-readable form) or only if needed for disambiguation. * in the label (human-readable form) or only if needed for disambiguation.
*/ */
Label( const QString& localeName, Translation( const QString& localeName,
LabelFormat format = LabelFormat::IfNeededWithCountry, LabelFormat format = LabelFormat::IfNeededWithCountry,
QObject* parent = nullptr ); QObject* parent = nullptr );
@ -64,7 +64,7 @@ public:
* *
* Locales are sorted by their id, which means the ISO 2-letter code + country. * Locales are sorted by their id, which means the ISO 2-letter code + country.
*/ */
bool operator<( const Label& other ) const { return m_localeId < other.m_localeId; } bool operator<( const Translation& other ) const { return m_localeId < other.m_localeId; }
/** @brief Is this locale English? /** @brief Is this locale English?
* *
@ -96,7 +96,7 @@ public:
*/ */
static QLocale getLocale( const QString& localeName ); static QLocale getLocale( const QString& localeName );
protected: private:
QLocale m_locale; QLocale m_locale;
QString m_localeId; // the locale identifier, e.g. "en_GB" QString m_localeId; // the locale identifier, e.g. "en_GB"
QString m_label; // the native name of the locale QString m_label; // the native name of the locale

View File

@ -20,7 +20,7 @@ namespace CalamaresUtils
namespace Locale namespace Locale
{ {
LabelModel::LabelModel( const QStringList& locales, QObject* parent ) TranslationsModel::TranslationsModel( const QStringList& locales, QObject* parent )
: QAbstractListModel( parent ) : QAbstractListModel( parent )
, m_localeIds( locales ) , m_localeIds( locales )
{ {
@ -29,20 +29,20 @@ LabelModel::LabelModel( const QStringList& locales, QObject* parent )
for ( const auto& l : locales ) for ( const auto& l : locales )
{ {
m_locales.push_back( new Label( l, Label::LabelFormat::IfNeededWithCountry, this ) ); m_locales.push_back( new Translation( l, Translation::LabelFormat::IfNeededWithCountry, this ) );
} }
} }
LabelModel::~LabelModel() {} TranslationsModel::~TranslationsModel() {}
int int
LabelModel::rowCount( const QModelIndex& ) const TranslationsModel::rowCount( const QModelIndex& ) const
{ {
return m_locales.count(); return m_locales.count();
} }
QVariant QVariant
LabelModel::data( const QModelIndex& index, int role ) const TranslationsModel::data( const QModelIndex& index, int role ) const
{ {
if ( ( role != LabelRole ) && ( role != EnglishLabelRole ) ) if ( ( role != LabelRole ) && ( role != EnglishLabelRole ) )
{ {
@ -67,13 +67,13 @@ LabelModel::data( const QModelIndex& index, int role ) const
} }
QHash< int, QByteArray > QHash< int, QByteArray >
LabelModel::roleNames() const TranslationsModel::roleNames() const
{ {
return { { LabelRole, "label" }, { EnglishLabelRole, "englishLabel" } }; return { { LabelRole, "label" }, { EnglishLabelRole, "englishLabel" } };
} }
const Label& const Translation&
LabelModel::locale( int row ) const TranslationsModel::locale( int row ) const
{ {
if ( ( row < 0 ) || ( row >= m_locales.count() ) ) if ( ( row < 0 ) || ( row >= m_locales.count() ) )
{ {
@ -88,7 +88,7 @@ LabelModel::locale( int row ) const
} }
int int
LabelModel::find( std::function< bool( const Label& ) > predicate ) const TranslationsModel::find( std::function< bool( const Translation& ) > predicate ) const
{ {
for ( int row = 0; row < m_locales.count(); ++row ) for ( int row = 0; row < m_locales.count(); ++row )
{ {
@ -101,19 +101,19 @@ LabelModel::find( std::function< bool( const Label& ) > predicate ) const
} }
int int
LabelModel::find( std::function< bool( const QLocale& ) > predicate ) const TranslationsModel::find( std::function< bool( const QLocale& ) > predicate ) const
{ {
return find( [&]( const Label& l ) { return predicate( l.locale() ); } ); return find( [&]( const Translation& l ) { return predicate( l.locale() ); } );
} }
int int
LabelModel::find( const QLocale& locale ) const TranslationsModel::find( const QLocale& locale ) const
{ {
return find( [&]( const Label& l ) { return locale == l.locale(); } ); return find( [&]( const Translation& l ) { return locale == l.locale(); } );
} }
int int
LabelModel::find( const QString& countryCode ) const TranslationsModel::find( const QString& countryCode ) const
{ {
if ( countryCode.length() != 2 ) if ( countryCode.length() != 2 )
{ {
@ -121,18 +121,18 @@ LabelModel::find( const QString& countryCode ) const
} }
auto c_l = countryData( countryCode ); auto c_l = countryData( countryCode );
int r = find( [&]( const Label& l ) { return ( l.language() == c_l.second ) && ( l.country() == c_l.first ); } ); int r = find( [&]( const Translation& l ) { return ( l.language() == c_l.second ) && ( l.country() == c_l.first ); } );
if ( r >= 0 ) if ( r >= 0 )
{ {
return r; return r;
} }
return find( [&]( const Label& l ) { return l.language() == c_l.second; } ); return find( [&]( const Translation& l ) { return l.language() == c_l.second; } );
} }
LabelModel* TranslationsModel*
availableTranslations() availableTranslations()
{ {
static LabelModel* model = new LabelModel( QStringLiteral( CALAMARES_TRANSLATION_LANGUAGES ).split( ';' ) ); static TranslationsModel* model = new TranslationsModel( QStringLiteral( CALAMARES_TRANSLATION_LANGUAGES ).split( ';' ) );
return model; return model;
} }

View File

@ -24,7 +24,7 @@ namespace CalamaresUtils
namespace Locale namespace Locale
{ {
class DLLEXPORT LabelModel : public QAbstractListModel class DLLEXPORT TranslationsModel : public QAbstractListModel
{ {
Q_OBJECT Q_OBJECT
@ -35,8 +35,8 @@ public:
EnglishLabelRole = Qt::UserRole + 1 EnglishLabelRole = Qt::UserRole + 1
}; };
LabelModel( const QStringList& locales, QObject* parent = nullptr ); TranslationsModel( const QStringList& locales, QObject* parent = nullptr );
~LabelModel() override; ~TranslationsModel() override;
int rowCount( const QModelIndex& parent ) const override; int rowCount( const QModelIndex& parent ) const override;
@ -48,7 +48,7 @@ public:
* This is the backing data for the model; if @p row is out-of-range, * This is the backing data for the model; if @p row is out-of-range,
* returns a reference to en_US. * returns a reference to en_US.
*/ */
const Label& locale( int row ) const; const Translation& locale( int row ) const;
/// @brief Returns all of the locale Ids (e.g. en_US) put into this model. /// @brief Returns all of the locale Ids (e.g. en_US) put into this model.
const QStringList& localeIds() const { return m_localeIds; } const QStringList& localeIds() const { return m_localeIds; }
@ -58,14 +58,14 @@ public:
* Returns the row number of the first match, or -1 if there isn't one. * Returns the row number of the first match, or -1 if there isn't one.
*/ */
int find( std::function< bool( const QLocale& ) > predicate ) const; int find( std::function< bool( const QLocale& ) > predicate ) const;
int find( std::function< bool( const Label& ) > predicate ) const; int find( std::function< bool( const Translation& ) > predicate ) const;
/// @brief Looks for an item using the same locale, -1 if there isn't one /// @brief Looks for an item using the same locale, -1 if there isn't one
int find( const QLocale& ) const; int find( const QLocale& ) const;
/// @brief Looks for an item that best matches the 2-letter country code /// @brief Looks for an item that best matches the 2-letter country code
int find( const QString& countryCode ) const; int find( const QString& countryCode ) const;
private: private:
QVector< Label* > m_locales; QVector< Translation* > m_locales;
QStringList m_localeIds; QStringList m_localeIds;
}; };
@ -79,7 +79,7 @@ private:
* *
* NOTE: While the model is not typed const, it should be. Do not modify. * NOTE: While the model is not typed const, it should be. Do not modify.
*/ */
DLLEXPORT LabelModel* availableTranslations(); DLLEXPORT TranslationsModel* availableTranslations();
} // namespace Locale } // namespace Locale
} // namespace CalamaresUtils } // namespace CalamaresUtils
#endif #endif

View File

@ -368,9 +368,9 @@ Config::currentTimezoneName() const
static inline QString static inline QString
localeLabel( const QString& s ) localeLabel( const QString& s )
{ {
using CalamaresUtils::Locale::Label; using CalamaresUtils::Locale::Translation;
Label lang( s, Label::LabelFormat::AlwaysWithCountry ); Translation lang( s, Translation::LabelFormat::AlwaysWithCountry );
return lang.label(); return lang.label();
} }

View File

@ -84,7 +84,7 @@ Config::retranslate()
emit warningMessageChanged( m_warningMessage ); emit warningMessageChanged( m_warningMessage );
} }
CalamaresUtils::Locale::LabelModel* CalamaresUtils::Locale::TranslationsModel*
Config::languagesModel() const Config::languagesModel() const
{ {
return m_languages; return m_languages;

View File

@ -27,7 +27,7 @@ class Config : public QObject
* This is a list-model, with names and descriptions for the translations * This is a list-model, with names and descriptions for the translations
* available to Calamares. * available to Calamares.
*/ */
Q_PROPERTY( CalamaresUtils::Locale::LabelModel* languagesModel READ languagesModel CONSTANT FINAL ) Q_PROPERTY( CalamaresUtils::Locale::TranslationsModel* languagesModel READ languagesModel CONSTANT FINAL )
/** @brief The requirements (from modules) and their checked-status /** @brief The requirements (from modules) and their checked-status
* *
* The model grows rows over time as each module is checked and its * The model grows rows over time as each module is checked and its
@ -92,7 +92,7 @@ public:
QString warningMessage() const; QString warningMessage() const;
public slots: public slots:
CalamaresUtils::Locale::LabelModel* languagesModel() const; CalamaresUtils::Locale::TranslationsModel* languagesModel() const;
void retranslate(); void retranslate();
///@brief The **global** requirements model, from ModuleManager ///@brief The **global** requirements model, from ModuleManager
@ -116,7 +116,7 @@ signals:
private: private:
void initLanguages(); void initLanguages();
CalamaresUtils::Locale::LabelModel* m_languages = nullptr; CalamaresUtils::Locale::TranslationsModel* m_languages = nullptr;
std::unique_ptr< QSortFilterProxyModel > m_filtermodel; std::unique_ptr< QSortFilterProxyModel > m_filtermodel;
QString m_languageIcon; QString m_languageIcon;

View File

@ -275,5 +275,5 @@ LocaleTwoColumnDelegate::paint( QPainter* painter, const QStyleOptionViewItem& o
Qt::AlignRight | Qt::AlignVCenter, Qt::AlignRight | Qt::AlignVCenter,
option.palette, option.palette,
false, false,
index.data( CalamaresUtils::Locale::LabelModel::EnglishLabelRole ).toString() ); index.data( CalamaresUtils::Locale::TranslationsModel::EnglishLabelRole ).toString() );
} }

View File

@ -64,7 +64,7 @@ private:
Ui::WelcomePage* ui; Ui::WelcomePage* ui;
CheckerContainer* m_checkingWidget; CheckerContainer* m_checkingWidget;
CalamaresUtils::Locale::LabelModel* m_languages; CalamaresUtils::Locale::TranslationsModel* m_languages;
Config* m_conf; Config* m_conf;
}; };