Krita Source Code Documentation
Loading...
Searching...
No Matches
LocaleHandler Class Reference

The LocaleHandler class. More...

#include <LocaleHandler.h>

+ Inheritance diagram for LocaleHandler:

Classes

struct  Private
 

Signals

void bcp47TagChanged ()
 
void favoritesModelChanged ()
 
void languageChanged ()
 
void languagesModelChanged ()
 
void scriptChanged ()
 
void searchStringChanged ()
 

Public Member Functions

QString bcp47Tag () const
 
QAbstractItemModel * favoritesModel () const
 
QString language () const
 
QAbstractItemModel * languagesModel () const
 
 LocaleHandler (QObject *parent=nullptr)
 
bool localeValid () const
 
QString script () const
 
Q_INVOKABLE QVariantList scriptModel () const
 
QString searchString () const
 
void setBcp47Tag (const QString &newBcp47Tag)
 
void setLanguage (const QString &newLanguage)
 
void setScript (const QString &newScript)
 
void setSearchString (const QString &newSearchString)
 
Q_INVOKABLE bool validBcp47Tag (const QString &tag) const
 
 ~LocaleHandler ()
 

Properties

QString bcp47Tag
 
QAbstractItemModel * favoritesModel
 
QString language
 
QAbstractItemModel * languagesModel
 
bool localeValid
 
QString script
 
QString searchString
 

Private Attributes

const QScopedPointer< Privated
 

Detailed Description

The LocaleHandler class.

This object splits up a BCP47 locale into language and script sections, and allows editing each.

It also keeps track of models for script and language.

Definition at line 21 of file LocaleHandler.h.

Constructor & Destructor Documentation

◆ LocaleHandler()

LocaleHandler::LocaleHandler ( QObject * parent = nullptr)

Definition at line 60 of file LocaleHandler.cpp.

61 : QObject(parent)
62 , d(new Private(parent))
63{
64
65}
const QScopedPointer< Private > d

◆ ~LocaleHandler()

LocaleHandler::~LocaleHandler ( )

Definition at line 67 of file LocaleHandler.cpp.

68{
69
70}

Member Function Documentation

◆ bcp47Tag()

QString LocaleHandler::bcp47Tag ( ) const

Definition at line 72 of file LocaleHandler.cpp.

73{
74 return d->locale.toString();
75}

References d.

◆ bcp47TagChanged

void LocaleHandler::bcp47TagChanged ( )
signal

◆ favoritesModel()

QAbstractItemModel * LocaleHandler::favoritesModel ( ) const

Definition at line 152 of file LocaleHandler.cpp.

153{
154 return d->favorites;
155}

References d.

◆ favoritesModelChanged

void LocaleHandler::favoritesModelChanged ( )
signal

◆ language()

QString LocaleHandler::language ( ) const

Definition at line 104 of file LocaleHandler.cpp.

105{
106 KoWritingSystemUtils::Bcp47Locale langOnly = d->locale;
107 langOnly.scriptTag.clear();
108 return langOnly.toString();
109}
The Bcp47Locale class This holds a parsed BCP47 locale. QLocale is primarily made for POSIX locale fo...

References d, KoWritingSystemUtils::Bcp47Locale::scriptTag, and KoWritingSystemUtils::Bcp47Locale::toString().

◆ languageChanged

void LocaleHandler::languageChanged ( )
signal

◆ languagesModel()

QAbstractItemModel * LocaleHandler::languagesModel ( ) const

Definition at line 147 of file LocaleHandler.cpp.

148{
149 return d->filteredLanguagesModel;
150}

References d.

◆ languagesModelChanged

void LocaleHandler::languagesModelChanged ( )
signal

◆ localeValid()

bool LocaleHandler::localeValid ( ) const

Definition at line 170 of file LocaleHandler.cpp.

171{
172 return d->locale.isValid();
173}

References d.

◆ script()

QString LocaleHandler::script ( ) const

Definition at line 90 of file LocaleHandler.cpp.

91{
92 return d->locale.scriptTag;
93}

References d.

◆ scriptChanged

void LocaleHandler::scriptChanged ( )
signal

◆ scriptModel()

QVariantList LocaleHandler::scriptModel ( ) const

Definition at line 131 of file LocaleHandler.cpp.

132{
133 QVariantList model;
134 const QString code = "code";
135 const QString name = "name";
136
137 for (int i = 0; i< int(QLocale::LastScript); i++) {
138 const QLocale::Script script = QLocale::Script(i);
139 QVariantMap map;
141 map.insert(name, QLocale::scriptToString(script));
142 model.append(map);
143 }
144 return model;
145}
static QString scriptTagForQLocaleScript(QLocale::Script script)
const char * name(StandardAction id)

References script, and KoWritingSystemUtils::scriptTagForQLocaleScript().

◆ searchString()

QString LocaleHandler::searchString ( ) const

Definition at line 157 of file LocaleHandler.cpp.

158{
159 return d->filteredLanguagesModel->filterRegularExpression().pattern();
160}

References d.

◆ searchStringChanged

void LocaleHandler::searchStringChanged ( )
signal

◆ setBcp47Tag()

void LocaleHandler::setBcp47Tag ( const QString & newBcp47Tag)

Definition at line 77 of file LocaleHandler.cpp.

78{
79 if (d->locale.toString() == newBcp47Tag)
80 return;
81 d->locale = KoWritingSystemUtils::parseBcp47Locale(newBcp47Tag);
82
83
84 d->favorites->addCode(language());
85 emit bcp47TagChanged();
86 emit languageChanged();
87 emit scriptChanged();
88}
static Bcp47Locale parseBcp47Locale(const QString &locale)
void languageChanged()
void bcp47TagChanged()
void scriptChanged()

References bcp47TagChanged(), d, language, languageChanged(), KoWritingSystemUtils::parseBcp47Locale(), and scriptChanged().

◆ setLanguage()

void LocaleHandler::setLanguage ( const QString & newLanguage)

Definition at line 111 of file LocaleHandler.cpp.

112{
113 KoWritingSystemUtils::Bcp47Locale langOnly = d->locale;
114 langOnly.scriptTag.clear();
115 if (langOnly.toString() == newLanguage)
116 return;
117
118 langOnly = KoWritingSystemUtils::parseBcp47Locale(newLanguage);
119 langOnly.scriptTag.clear();
120 if (!langOnly.isValid()) return;
121
122 d->favorites->addCode(langOnly.toString());
123
124 langOnly.scriptTag = d->locale.scriptTag;
125 d->locale = langOnly;
126
127 emit languageChanged();
128 emit bcp47TagChanged();
129}

References bcp47TagChanged(), d, KoWritingSystemUtils::Bcp47Locale::isValid(), languageChanged(), KoWritingSystemUtils::parseBcp47Locale(), KoWritingSystemUtils::Bcp47Locale::scriptTag, and KoWritingSystemUtils::Bcp47Locale::toString().

◆ setScript()

void LocaleHandler::setScript ( const QString & newScript)

Definition at line 95 of file LocaleHandler.cpp.

96{
97 if (d->locale.scriptTag == newScript)
98 return;
99 d->locale.scriptTag = newScript;
100 emit scriptChanged();
101 emit bcp47TagChanged();
102}

References bcp47TagChanged(), d, and scriptChanged().

◆ setSearchString()

void LocaleHandler::setSearchString ( const QString & newSearchString)

Definition at line 162 of file LocaleHandler.cpp.

163{
164 if (d->filteredLanguagesModel->filterRegularExpression().pattern() == newSearchString)
165 return;
166 d->filteredLanguagesModel->setFilterRegularExpression(newSearchString);
167 emit searchStringChanged();
168}
void searchStringChanged()

References d, and searchStringChanged().

◆ validBcp47Tag()

bool LocaleHandler::validBcp47Tag ( const QString & tag) const

Member Data Documentation

◆ d

const QScopedPointer<Private> LocaleHandler::d
private

Definition at line 78 of file LocaleHandler.h.

Property Documentation

◆ bcp47Tag

QString LocaleHandler::bcp47Tag
readwrite

Definition at line 25 of file LocaleHandler.h.

◆ favoritesModel

QAbstractItemModel * LocaleHandler::favoritesModel
read

Definition at line 31 of file LocaleHandler.h.

◆ language

QString LocaleHandler::language
readwrite

Definition at line 27 of file LocaleHandler.h.

◆ languagesModel

QAbstractItemModel * LocaleHandler::languagesModel
read

Definition at line 29 of file LocaleHandler.h.

◆ localeValid

bool LocaleHandler::localeValid
read

Definition at line 33 of file LocaleHandler.h.

◆ script

QString LocaleHandler::script
readwrite

Definition at line 26 of file LocaleHandler.h.

◆ searchString

QString LocaleHandler::searchString
readwrite

Definition at line 30 of file LocaleHandler.h.


The documentation for this class was generated from the following files: