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 64 of file LocaleHandler.cpp.

65 : QObject(parent)
66 , d(new Private(parent))
67{
68
69}
const QScopedPointer< Private > d

◆ ~LocaleHandler()

LocaleHandler::~LocaleHandler ( )

Definition at line 71 of file LocaleHandler.cpp.

72{
73
74}

Member Function Documentation

◆ bcp47Tag()

QString LocaleHandler::bcp47Tag ( ) const

Definition at line 76 of file LocaleHandler.cpp.

77{
78 return d->locale.toString();
79}

References d.

◆ bcp47TagChanged

void LocaleHandler::bcp47TagChanged ( )
signal

◆ favoritesModel()

QAbstractItemModel * LocaleHandler::favoritesModel ( ) const

Definition at line 156 of file LocaleHandler.cpp.

157{
158 return d->favorites;
159}

References d.

◆ favoritesModelChanged

void LocaleHandler::favoritesModelChanged ( )
signal

◆ language()

QString LocaleHandler::language ( ) const

Definition at line 108 of file LocaleHandler.cpp.

109{
110 KoWritingSystemUtils::Bcp47Locale langOnly = d->locale;
111 langOnly.scriptTag.clear();
112 return langOnly.toString();
113}
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 151 of file LocaleHandler.cpp.

152{
153 return d->filteredLanguagesModel;
154}

References d.

◆ languagesModelChanged

void LocaleHandler::languagesModelChanged ( )
signal

◆ localeValid()

bool LocaleHandler::localeValid ( ) const

Definition at line 174 of file LocaleHandler.cpp.

175{
176 return d->locale.isValid();
177}

References d.

◆ script()

QString LocaleHandler::script ( ) const

Definition at line 94 of file LocaleHandler.cpp.

95{
96 return d->locale.scriptTag;
97}

References d.

◆ scriptChanged

void LocaleHandler::scriptChanged ( )
signal

◆ scriptModel()

QVariantList LocaleHandler::scriptModel ( ) const

Definition at line 135 of file LocaleHandler.cpp.

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

References script, and KoWritingSystemUtils::scriptTagForQLocaleScript().

◆ searchString()

QString LocaleHandler::searchString ( ) const

Definition at line 161 of file LocaleHandler.cpp.

162{
163 return d->filteredLanguagesModel->filterRegularExpression().pattern();
164}

References d.

◆ searchStringChanged

void LocaleHandler::searchStringChanged ( )
signal

◆ setBcp47Tag()

void LocaleHandler::setBcp47Tag ( const QString & newBcp47Tag)

Definition at line 81 of file LocaleHandler.cpp.

82{
83 if (d->locale.toString() == newBcp47Tag)
84 return;
85 d->locale = KoWritingSystemUtils::parseBcp47Locale(newBcp47Tag);
86
87
88 d->favorites->addCode(language());
89 emit bcp47TagChanged();
90 emit languageChanged();
91 emit scriptChanged();
92}
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 115 of file LocaleHandler.cpp.

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

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 99 of file LocaleHandler.cpp.

100{
101 if (d->locale.scriptTag == newScript)
102 return;
103 d->locale.scriptTag = newScript;
104 emit scriptChanged();
105 emit bcp47TagChanged();
106}

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

◆ setSearchString()

void LocaleHandler::setSearchString ( const QString & newSearchString)

Definition at line 166 of file LocaleHandler.cpp.

167{
168 if (d->filteredLanguagesModel->filterRegularExpression().pattern() == newSearchString)
169 return;
170 d->filteredLanguagesModel->setFilterRegularExpression(newSearchString);
171 emit searchStringChanged();
172}
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: