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
virtual QHash<int, QByteArray> roleNames() const
virtual int rowCount(const QModelIndex &parent = QModelIndex()) const
virtual void sort(int column, Qt::SortOrder order = Qt::AscendingOrder)

Signals

void addItem(LocaleItem *item)
void ready()

Static Public Members

void generateModel(LocaleModel *model)
const QMetaObject staticMetaObject
bool variantLessThan(const LocaleItem *v1, const LocaleItem *v2)
  • 9 static public members inherited from QObject

Additional Inherited Members

Detailed Description

The LocaleModel class provides a model for the available locales.

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.

ConstantValueDescription
LocaleModel::LanguageQt::UserRole + 1The language of the country.
LocaleModel::Country258The name of the country.
LocaleModel::Code259The 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.

[virtual] LocaleModel::~LocaleModel()

Deletes the locale model.

[signal] void LocaleModel::addItem(LocaleItem *item)

This signal is emitted when the locale item item is added to the locale model.

[virtual] QVariant LocaleModel::data(const QModelIndex &index, int role = Qt::DisplayRole) const

Reimplemented from QAbstractItemModel::data().

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.

[signal] void LocaleModel::ready()

This signal is emitted when the locale model has been reset.

[virtual] QHash<int, QByteArray> LocaleModel::roleNames() const

Reimplemented from QAbstractItemModel::roleNames().

Returns an array of user roles.

See also Roles.

[virtual] int LocaleModel::rowCount(const QModelIndex &parent = QModelIndex()) const

Reimplemented from QAbstractItemModel::rowCount().

Returns the number of rows in the locale model that has parent.

[virtual] void LocaleModel::sort(int column, Qt::SortOrder order = Qt::AscendingOrder)

Reimplemented from QAbstractItemModel::sort().

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 ##?

© 2019 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.