LocaleModel Class
The LocaleModel class provides a model for the available locales. More...
Header: | #include <LocaleModel> |
qmake: | QT += localesettings |
Inherits: | QAbstractListModel |
Public Types
enum | Roles { Language, Country, Code } |
Public Functions
LocaleModel(QObject *parent = Q_NULLPTR) | |
virtual | ~LocaleModel() |
QModelIndex | indexForCountry(const QString &country) const |
Reimplemented Public Functions
virtual QVariant | data(const QModelIndex &index, int role = Qt::DisplayRole) const override |
virtual QHash<int, QByteArray> | roleNames() const override |
virtual int | rowCount(const QModelIndex &parent = QModelIndex()) const override |
virtual void | sort(int column, Qt::SortOrder order = Qt::AscendingOrder) override |
Signals
Static Public Members
void | generateModel(LocaleModel *model) |
bool | variantLessThan(const LocaleItem *v1, const LocaleItem *v2) |
Detailed Description
Each item in the model has a set of data elements associated with it, each with its own role. The roles are used by the view to indicate to the model which type of data it needs. Custom models should return data in these types.
The data in a locale model can be filtered according to the country code, name, or language.
See also LocaleItem and LocaleFilterModel.
Member Type Documentation
enum LocaleModel::Roles
This enum holds the role of the locale item.
For user roles, it is up to the developer to decide which types to use and ensure that components use the correct types when accessing and setting data.
Constant | Value | Description |
---|---|---|
LocaleModel::Language | Qt::UserRole + 1 | The language of the country. |
LocaleModel::Country | 258 | The name of the country. |
LocaleModel::Code | 259 | The locale code string in the format language_country. |
See also Qt::UserRole.
Member Function Documentation
LocaleModel::LocaleModel(QObject *parent = Q_NULLPTR)
Creates a locale model with the parent parent.
[signal]
void LocaleModel::addItem(LocaleItem *item)
This signal is emitted when the locale item item is added to the locale model.
[signal]
void LocaleModel::ready()
This signal is emitted when the locale model has been reset.
[virtual]
LocaleModel::~LocaleModel()
Deletes the locale model.
[override virtual]
QVariant LocaleModel::data(const QModelIndex &index, int role = Qt::DisplayRole) const
Reimplements: QAbstractItemModel::data(const QModelIndex &index, int role) const.
Returns the locale item at index in the locale model for role.
This item can be assigned to LocaleManager::locale(), when the user selects a locale from a list.
See also LocaleItem and Roles.
[static]
void LocaleModel::generateModel(LocaleModel *model)
Creates the locale model model.
QModelIndex LocaleModel::indexForCountry(const QString &country) const
Returns the index for the country country in the locale model.
The index is used by item views, delegates, and selection models to locate an item in the model.
[override virtual]
QHash<int, QByteArray> LocaleModel::roleNames() const
Reimplements: QAbstractItemModel::roleNames() const.
Returns an array of user roles.
See also Roles.
[override virtual]
int LocaleModel::rowCount(const QModelIndex &parent = QModelIndex()) const
Reimplements: QAbstractItemModel::rowCount(const QModelIndex &parent) const.
Returns the number of rows in the locale model that has parent.
[override virtual]
void LocaleModel::sort(int column, Qt::SortOrder order = Qt::AscendingOrder)
Reimplements: QAbstractItemModel::sort(int column, Qt::SortOrder order).
Sets the sorting order of the column items in the locale model to order.
The sort order can be either ascending or descending.
[static]
bool LocaleModel::variantLessThan(const LocaleItem *v1, const LocaleItem *v2)
Returns whether the locale item has more than one languages specified.
If the language variant of the locale item if v1 is less than v2 ##?
© 2023 The Qt Company Ltd. Documentation contributions included herein are the copyrights of their respective owners. The documentation provided herein is licensed under the terms of the GNU Free Documentation License version 1.3 as published by the Free Software Foundation. Qt and respective logos are trademarks of The Qt Company Ltd. in Finland and/or other countries worldwide. All other trademarks are property of their respective owners.