Merge branch 'model-q'
- Make models of some things previously held as lists, as prep-work for QML modules.
This commit is contained in:
commit
c7780db07a
@ -24,23 +24,16 @@ namespace CalamaresUtils
|
|||||||
namespace Locale
|
namespace Locale
|
||||||
{
|
{
|
||||||
|
|
||||||
Label::Label()
|
Label::Label( QObject* parent )
|
||||||
: m_locale( QLocale() )
|
: Label( QString(), LabelFormat::IfNeededWithCountry, parent )
|
||||||
{
|
{
|
||||||
m_localeId = m_locale.name();
|
|
||||||
|
|
||||||
setLabels( QString(), LabelFormat::IfNeededWithCountry );
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Label::Label( const QString& locale, LabelFormat format )
|
Label::Label( const QString& locale, LabelFormat format, QObject* parent )
|
||||||
: m_locale( Label::getLocale( locale ) )
|
: QObject( parent )
|
||||||
, m_localeId( locale )
|
, m_locale( Label::getLocale( locale ) )
|
||||||
{
|
, m_localeId( locale.isEmpty() ? m_locale.name() : locale )
|
||||||
setLabels( locale, format );
|
|
||||||
}
|
|
||||||
|
|
||||||
void
|
|
||||||
Label::setLabels( const QString& locale, LabelFormat format )
|
|
||||||
{
|
{
|
||||||
//: language[name] (country[name])
|
//: language[name] (country[name])
|
||||||
QString longFormat = QObject::tr( "%1 (%2)" );
|
QString longFormat = QObject::tr( "%1 (%2)" );
|
||||||
@ -69,6 +62,10 @@ Label::setLabels( const QString& locale, LabelFormat format )
|
|||||||
QLocale
|
QLocale
|
||||||
Label::getLocale( const QString& localeName )
|
Label::getLocale( const QString& localeName )
|
||||||
{
|
{
|
||||||
|
if ( localeName.isEmpty() )
|
||||||
|
{
|
||||||
|
return QLocale();
|
||||||
|
}
|
||||||
if ( localeName.contains( "@latin" ) )
|
if ( localeName.contains( "@latin" ) )
|
||||||
{
|
{
|
||||||
QLocale loc( localeName ); // Ignores @latin
|
QLocale loc( localeName ); // Ignores @latin
|
||||||
|
@ -21,6 +21,7 @@
|
|||||||
#define LOCALE_LABEL_H
|
#define LOCALE_LABEL_H
|
||||||
|
|
||||||
#include <QLocale>
|
#include <QLocale>
|
||||||
|
#include <QObject>
|
||||||
#include <QString>
|
#include <QString>
|
||||||
|
|
||||||
namespace CalamaresUtils
|
namespace CalamaresUtils
|
||||||
@ -35,8 +36,14 @@ namespace Locale
|
|||||||
* translation system) into QLocales, and also into consistent
|
* translation system) into QLocales, and also into consistent
|
||||||
* human-readable text labels.
|
* human-readable text labels.
|
||||||
*/
|
*/
|
||||||
class Label
|
class Label : public QObject
|
||||||
{
|
{
|
||||||
|
Q_OBJECT
|
||||||
|
|
||||||
|
Q_PROPERTY( QString label READ label CONSTANT FINAL )
|
||||||
|
Q_PROPERTY( QString englishLabel READ englishLabel CONSTANT FINAL )
|
||||||
|
Q_PROPERTY( QString localeId MEMBER m_localeId CONSTANT FINAL )
|
||||||
|
|
||||||
public:
|
public:
|
||||||
/** @brief Formatting option for label -- add (country) to label. */
|
/** @brief Formatting option for label -- add (country) to label. */
|
||||||
enum class LabelFormat
|
enum class LabelFormat
|
||||||
@ -46,7 +53,7 @@ public:
|
|||||||
};
|
};
|
||||||
|
|
||||||
/** @brief Empty locale. This uses the system-default locale. */
|
/** @brief Empty locale. This uses the system-default locale. */
|
||||||
Label();
|
Label( QObject* parent = nullptr );
|
||||||
|
|
||||||
/** @brief Construct from a locale name.
|
/** @brief Construct from a locale name.
|
||||||
*
|
*
|
||||||
@ -54,7 +61,9 @@ 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, LabelFormat format = LabelFormat::IfNeededWithCountry );
|
Label( const QString& localeName,
|
||||||
|
LabelFormat format = LabelFormat::IfNeededWithCountry,
|
||||||
|
QObject* parent = nullptr );
|
||||||
|
|
||||||
/** @brief Define a sorting order.
|
/** @brief Define a sorting order.
|
||||||
*
|
*
|
||||||
@ -94,8 +103,6 @@ public:
|
|||||||
static QLocale getLocale( const QString& localeName );
|
static QLocale getLocale( const QString& localeName );
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
void setLabels( const QString& name, LabelFormat format );
|
|
||||||
|
|
||||||
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
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
/* === This file is part of Calamares - <https://github.com/calamares> ===
|
/* === This file is part of Calamares - <https://github.com/calamares> ===
|
||||||
*
|
*
|
||||||
* Copyright 2019, Adriaan de Groot <groot@kde.org>
|
* Copyright 2019-2020 Adriaan de Groot <groot@kde.org>
|
||||||
|
* Copyright 2019, Camilo Higuita <milo.h@aol.com>
|
||||||
*
|
*
|
||||||
* Calamares is free software: you can redistribute it and/or modify
|
* Calamares is free software: you can redistribute it and/or modify
|
||||||
* it under the terms of the GNU General Public License as published by
|
* it under the terms of the GNU General Public License as published by
|
||||||
@ -36,7 +37,7 @@ LabelModel::LabelModel( const QStringList& locales, QObject* parent )
|
|||||||
|
|
||||||
for ( const auto& l : locales )
|
for ( const auto& l : locales )
|
||||||
{
|
{
|
||||||
m_locales.push_back( Label( l ) );
|
m_locales.push_back( new Label( l, Label::LabelFormat::IfNeededWithCountry, this ) );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -65,27 +66,33 @@ LabelModel::data( const QModelIndex& index, int role ) const
|
|||||||
switch ( role )
|
switch ( role )
|
||||||
{
|
{
|
||||||
case LabelRole:
|
case LabelRole:
|
||||||
return locale.label();
|
return locale->label();
|
||||||
case EnglishLabelRole:
|
case EnglishLabelRole:
|
||||||
return locale.englishLabel();
|
return locale->englishLabel();
|
||||||
default:
|
default:
|
||||||
return QVariant();
|
return QVariant();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
QHash< int, QByteArray >
|
||||||
|
LabelModel::roleNames() const
|
||||||
|
{
|
||||||
|
return { { LabelRole, "label" }, { EnglishLabelRole, "englishLabel" } };
|
||||||
|
}
|
||||||
|
|
||||||
const Label&
|
const Label&
|
||||||
LabelModel::locale( int row ) const
|
LabelModel::locale( int row ) const
|
||||||
{
|
{
|
||||||
if ( ( row < 0 ) || ( row >= m_locales.count() ) )
|
if ( ( row < 0 ) || ( row >= m_locales.count() ) )
|
||||||
{
|
{
|
||||||
for ( const auto& l : m_locales )
|
for ( const auto& l : m_locales )
|
||||||
if ( l.isEnglish() )
|
if ( l->isEnglish() )
|
||||||
{
|
{
|
||||||
return l;
|
return *l;
|
||||||
}
|
}
|
||||||
return m_locales[ 0 ];
|
return *m_locales[ 0 ];
|
||||||
}
|
}
|
||||||
return m_locales[ row ];
|
return *m_locales[ row ];
|
||||||
}
|
}
|
||||||
|
|
||||||
int
|
int
|
||||||
@ -93,7 +100,7 @@ LabelModel::find( std::function< bool( const Label& ) > predicate ) const
|
|||||||
{
|
{
|
||||||
for ( int row = 0; row < m_locales.count(); ++row )
|
for ( int row = 0; row < m_locales.count(); ++row )
|
||||||
{
|
{
|
||||||
if ( predicate( m_locales[ row ] ) )
|
if ( predicate( *m_locales[ row ] ) )
|
||||||
{
|
{
|
||||||
return row;
|
return row;
|
||||||
}
|
}
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
/* === This file is part of Calamares - <https://github.com/calamares> ===
|
/* === This file is part of Calamares - <https://github.com/calamares> ===
|
||||||
*
|
*
|
||||||
* Copyright 2019, Adriaan de Groot <groot@kde.org>
|
* Copyright 2019-2020, Adriaan de Groot <groot@kde.org>
|
||||||
|
* Copyright 2019, Camilo Higuita <milo.h@aol.com>
|
||||||
*
|
*
|
||||||
* Calamares is free software: you can redistribute it and/or modify
|
* Calamares is free software: you can redistribute it and/or modify
|
||||||
* it under the terms of the GNU General Public License as published by
|
* it under the terms of the GNU General Public License as published by
|
||||||
@ -33,6 +34,8 @@ namespace Locale
|
|||||||
|
|
||||||
class DLLEXPORT LabelModel : public QAbstractListModel
|
class DLLEXPORT LabelModel : public QAbstractListModel
|
||||||
{
|
{
|
||||||
|
Q_OBJECT
|
||||||
|
|
||||||
public:
|
public:
|
||||||
enum
|
enum
|
||||||
{
|
{
|
||||||
@ -46,6 +49,7 @@ public:
|
|||||||
int rowCount( const QModelIndex& parent ) const override;
|
int rowCount( const QModelIndex& parent ) const override;
|
||||||
|
|
||||||
QVariant data( const QModelIndex& index, int role ) const override;
|
QVariant data( const QModelIndex& index, int role ) const override;
|
||||||
|
QHash< int, QByteArray > roleNames() const override;
|
||||||
|
|
||||||
/** @brief Gets locale information for entry #n
|
/** @brief Gets locale information for entry #n
|
||||||
*
|
*
|
||||||
@ -69,7 +73,7 @@ public:
|
|||||||
int find( const QString& countryCode ) const;
|
int find( const QString& countryCode ) const;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
QVector< Label > m_locales;
|
QVector< Label* > m_locales;
|
||||||
QStringList m_localeIds;
|
QStringList m_localeIds;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -3,6 +3,7 @@
|
|||||||
* Copyright 2014-2015, Teo Mrnjavac <teo@kde.org>
|
* Copyright 2014-2015, Teo Mrnjavac <teo@kde.org>
|
||||||
* Copyright 2017-2019, Adriaan de Groot <groot@kde.org>
|
* Copyright 2017-2019, Adriaan de Groot <groot@kde.org>
|
||||||
* Copyright 2018, Raul Rodrigo Segura (raurodse)
|
* Copyright 2018, Raul Rodrigo Segura (raurodse)
|
||||||
|
* Copyright 2019, Camilo Higuita <milo.h@aol.com>
|
||||||
*
|
*
|
||||||
* Calamares is free software: you can redistribute it and/or modify
|
* Calamares is free software: you can redistribute it and/or modify
|
||||||
* it under the terms of the GNU General Public License as published by
|
* it under the terms of the GNU General Public License as published by
|
||||||
@ -74,7 +75,8 @@ const QStringList Branding::s_imageEntryStrings =
|
|||||||
{
|
{
|
||||||
"productLogo",
|
"productLogo",
|
||||||
"productIcon",
|
"productIcon",
|
||||||
"productWelcome"
|
"productWelcome",
|
||||||
|
"productWallpaper"
|
||||||
};
|
};
|
||||||
|
|
||||||
const QStringList Branding::s_styleEntryStrings =
|
const QStringList Branding::s_styleEntryStrings =
|
||||||
|
@ -3,6 +3,7 @@
|
|||||||
* Copyright 2014-2015, Teo Mrnjavac <teo@kde.org>
|
* Copyright 2014-2015, Teo Mrnjavac <teo@kde.org>
|
||||||
* Copyright 2017-2018, Adriaan de Groot <groot@kde.org>
|
* Copyright 2017-2018, Adriaan de Groot <groot@kde.org>
|
||||||
* Copyright 2018, Raul Rodrigo Segura (raurodse)
|
* Copyright 2018, Raul Rodrigo Segura (raurodse)
|
||||||
|
* Copyright 2019, Camilo Higuita <milo.h@aol.com>
|
||||||
*
|
*
|
||||||
* Calamares is free software: you can redistribute it and/or modify
|
* Calamares is free software: you can redistribute it and/or modify
|
||||||
* it under the terms of the GNU General Public License as published by
|
* it under the terms of the GNU General Public License as published by
|
||||||
@ -48,7 +49,7 @@ public:
|
|||||||
* e.g. *Branding::ProductName to get the string value for
|
* e.g. *Branding::ProductName to get the string value for
|
||||||
* the product name.
|
* the product name.
|
||||||
*/
|
*/
|
||||||
enum StringEntry : short
|
enum StringEntry
|
||||||
{
|
{
|
||||||
ProductName,
|
ProductName,
|
||||||
Version,
|
Version,
|
||||||
@ -62,13 +63,16 @@ public:
|
|||||||
KnownIssuesUrl,
|
KnownIssuesUrl,
|
||||||
ReleaseNotesUrl
|
ReleaseNotesUrl
|
||||||
};
|
};
|
||||||
|
Q_ENUM( StringEntry )
|
||||||
|
|
||||||
enum ImageEntry : short
|
enum ImageEntry : short
|
||||||
{
|
{
|
||||||
ProductLogo,
|
ProductLogo,
|
||||||
ProductIcon,
|
ProductIcon,
|
||||||
ProductWelcome
|
ProductWelcome,
|
||||||
|
ProductWallpaper
|
||||||
};
|
};
|
||||||
|
Q_ENUM( ImageEntry )
|
||||||
|
|
||||||
enum StyleEntry : short
|
enum StyleEntry : short
|
||||||
{
|
{
|
||||||
@ -77,6 +81,7 @@ public:
|
|||||||
SidebarTextSelect,
|
SidebarTextSelect,
|
||||||
SidebarTextHighlight
|
SidebarTextHighlight
|
||||||
};
|
};
|
||||||
|
Q_ENUM( StyleEntry )
|
||||||
|
|
||||||
/** @brief Setting for how much the main window may expand. */
|
/** @brief Setting for how much the main window may expand. */
|
||||||
enum class WindowExpansion
|
enum class WindowExpansion
|
||||||
@ -85,6 +90,7 @@ public:
|
|||||||
Fullscreen,
|
Fullscreen,
|
||||||
Fixed
|
Fixed
|
||||||
};
|
};
|
||||||
|
Q_ENUM( WindowExpansion )
|
||||||
/** @brief Setting for the main window size.
|
/** @brief Setting for the main window size.
|
||||||
*
|
*
|
||||||
* The units are pixels (Pixies) or something-based-on-fontsize (Fonties), which
|
* The units are pixels (Pixies) or something-based-on-fontsize (Fonties), which
|
||||||
@ -96,6 +102,7 @@ public:
|
|||||||
Pixies,
|
Pixies,
|
||||||
Fonties
|
Fonties
|
||||||
};
|
};
|
||||||
|
Q_ENUM( WindowDimensionUnit )
|
||||||
class WindowDimension : public NamedSuffix< WindowDimensionUnit, WindowDimensionUnit::None >
|
class WindowDimension : public NamedSuffix< WindowDimensionUnit, WindowDimensionUnit::None >
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
|
Loading…
Reference in New Issue
Block a user