[libcalamaresui] Give LocaleLabel a default constructor

- Needed for use in containers
 - While here refactor building the english label
main
Adriaan de Groot 6 years ago
parent 94765d40cd
commit bd0af4bb77

@ -262,9 +262,23 @@ clearLayout( QLayout* layout )
}
}
LocaleLabel::LocaleLabel()
: m_locale( QLocale() )
{
m_localeId = m_locale.name();
setLabels( QString(), LabelFormat::IfNeededWithCountry );
}
LocaleLabel::LocaleLabel( const QString& locale, LabelFormat format )
: m_locale( LocaleLabel::getLocale( locale ) )
, m_localeId( locale )
{
setLabels( locale, format );
}
void
LocaleLabel::setLabels( const QString& locale, LabelFormat format )
{
//: language[name] (country[name])
QString longFormat = QObject::tr( "%1 (%2)" );
@ -274,7 +288,7 @@ LocaleLabel::LocaleLabel( const QString& locale, LabelFormat format )
QString countryName;
if ( languageName.isEmpty() )
languageName = QString( QLatin1Literal( "* %1 (%2)" ) ).arg( locale, englishName );
languageName = QString( "* %1 (%2)" ).arg( locale, englishName );
bool needsCountryName = ( format == LabelFormat::AlwaysWithCountry ) ||
(locale.contains( '_' ) && QLocale::countriesForLanguage( m_locale.language() ).count() > 1 );

@ -140,6 +140,9 @@ public:
/** @brief Formatting option for label -- add (country) to label. */
enum class LabelFormat { AlwaysWithCountry, IfNeededWithCountry } ;
/** @brief Empty locale. This uses the system-default locale. */
LocaleLabel();
/** @brief Construct from a locale name.
*
* The @p localeName should be one that Qt recognizes, e.g. en_US or ar_EY.
@ -192,6 +195,8 @@ public:
static QLocale getLocale( const QString& localeName );
protected:
void setLabels( const QString& name, LabelFormat format );
QLocale m_locale;
QString m_localeId; // the locale identifier, e.g. "en_GB"
QString m_label; // the native name of the locale

Loading…
Cancel
Save