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

The GlyphPaletteProxyModel class. More...

#include <GlyphPaletteProxyModel.h>

+ Inheritance diagram for GlyphPaletteProxyModel:

Classes

struct  Private
 

Public Slots

void emitBlockLabelsChanged ()
 emitBlockLabelsChanged This called "block labels changed" and is should be used when the source KoFontGlyphModel changes, so that the unicode block filter list is updated to the new font.
 
void setBlockFilter (int filter)
 setBlockFilter set the unicode block filter.
 
void setSearchText (const QString &text)
 setSearchText
 

Signals

void blockFilterChanged ()
 
void blockLabelsChanged ()
 
void searchTextChanged ()
 

Public Member Functions

int blockFilter () const
 blockFilter
 
QVariantList blockLabels () const
 blockLabels
 
 GlyphPaletteProxyModel (QObject *parent=nullptr)
 
QString searchText () const
 searchText
 
 ~GlyphPaletteProxyModel () override
 

Protected Member Functions

bool filterAcceptsRow (int sourceRow, const QModelIndex &sourceParent) const override
 

Properties

int blockFilter
 
QVariantList blockLabels
 
QString searchText
 

Private Attributes

QScopedPointer< Privated
 

Detailed Description

The GlyphPaletteProxyModel class.

This class is a filter model for the KoFontGlyphModel, which allows it to be used as a character map, allowing filtering on blocks and strings.

Definition at line 20 of file GlyphPaletteProxyModel.h.

Constructor & Destructor Documentation

◆ GlyphPaletteProxyModel()

GlyphPaletteProxyModel::GlyphPaletteProxyModel ( QObject * parent = nullptr)

Definition at line 17 of file GlyphPaletteProxyModel.cpp.

18 : QSortFilterProxyModel(parent)
19 , d(new Private)
20{
21
22}
QScopedPointer< Private > d

◆ ~GlyphPaletteProxyModel()

GlyphPaletteProxyModel::~GlyphPaletteProxyModel ( )
override

Definition at line 24 of file GlyphPaletteProxyModel.cpp.

25{
26}

Member Function Documentation

◆ blockFilter()

int GlyphPaletteProxyModel::blockFilter ( ) const

blockFilter

Returns
current blockfilter, value is value in blockLabels.

Definition at line 28 of file GlyphPaletteProxyModel.cpp.

29{
30 return d->filterIndex;
31}

References d.

◆ blockFilterChanged

void GlyphPaletteProxyModel::blockFilterChanged ( )
signal

◆ blockLabels()

QVariantList GlyphPaletteProxyModel::blockLabels ( ) const

blockLabels

Returns
list of unicode block filter labels, with each entry representing a QVariantMap with a "name" and a "value"

Definition at line 38 of file GlyphPaletteProxyModel.cpp.

39{
40 QVariantList labels;
41
42 KoFontGlyphModel *model = qobject_cast<KoFontGlyphModel*>(sourceModel());
43 labels.append(QVariantMap({{"name", i18nc("@title", "All glyphs")}, {"value", 0}}));
44 if (model) {
45 for (int i=0; i < model->blocks().size(); i++) {
46 labels.append(QVariantMap({{"name", model->blocks().at(i).name}, {"value", i+1}}));
47 }
48 }
49 return labels;
50}
The KoFontGlyphModel class Creates a tree model of all the glyphs in a given face.
QVector< KoUnicodeBlockData > blocks() const
blocks

References KoFontGlyphModel::blocks().

◆ blockLabelsChanged

void GlyphPaletteProxyModel::blockLabelsChanged ( )
signal

◆ emitBlockLabelsChanged

void GlyphPaletteProxyModel::emitBlockLabelsChanged ( )
slot

emitBlockLabelsChanged This called "block labels changed" and is should be used when the source KoFontGlyphModel changes, so that the unicode block filter list is updated to the new font.

Definition at line 95 of file GlyphPaletteProxyModel.cpp.

96{
97 emit blockLabelsChanged();
98}

References blockLabelsChanged().

◆ filterAcceptsRow()

bool GlyphPaletteProxyModel::filterAcceptsRow ( int sourceRow,
const QModelIndex & sourceParent ) const
overrideprotected

Definition at line 100 of file GlyphPaletteProxyModel.cpp.

101{
102 if (sourceParent.isValid()) return true;
103 const QModelIndex idx = sourceModel()->index(sourceRow, 0, sourceParent);
104 const QString main = sourceModel()->data(idx).toString();
105 if (main.isEmpty()) return false;
106 const uint firstChar = main.toUcs4().first();
107
108 if (!d->searchText.isEmpty()) {
109 const QString decomposition = QChar::decomposition(firstChar);
110 const uint searchFirst = d->searchText.toUcs4().first();
111 return searchFirst == firstChar
112 || (!decomposition.isEmpty() && searchFirst == decomposition.toUcs4().first());
113 }
114 if (d->filterIndex == 0) return true;
115
116 return d->block.match(firstChar);
117}
unsigned int uint
int main(int argc, char **argv)
Definition main.cpp:26

References d, and main().

◆ searchText()

QString GlyphPaletteProxyModel::searchText ( ) const

searchText

Returns
current search text. This is a single unicode codepoint.

Definition at line 33 of file GlyphPaletteProxyModel.cpp.

34{
35 return d->searchText;
36}

References d.

◆ searchTextChanged

void GlyphPaletteProxyModel::searchTextChanged ( )
signal

◆ setBlockFilter

void GlyphPaletteProxyModel::setBlockFilter ( int filter)
slot

setBlockFilter set the unicode block filter.

Parameters
filter– value from blockLabels();

Definition at line 71 of file GlyphPaletteProxyModel.cpp.

72{
73 if (d->filterIndex == filter) {
74 return;
75 }
76 if (filter == 0) {
77 d->filterIndex = 0;
79 emit blockFilterChanged();
80 invalidateFilter();
81 } else {
82 KoFontGlyphModel *model = qobject_cast<KoFontGlyphModel*>(sourceModel());
83 if (model) {
84 int actualFilter = filter - 1;
85 if (actualFilter < model->blocks().size()) {
86 d->filterIndex = filter;
87 d->block = model->blocks().at(actualFilter);
88 emit blockFilterChanged();
89 invalidateFilter();
90 }
91 }
92 }
93}
int size(const Forest< T > &forest)
Definition KisForest.h:1232
static KoUnicodeBlockData noBlock()

References blockFilterChanged(), KoFontGlyphModel::blocks(), d, and KoUnicodeBlockDataFactory::noBlock().

◆ setSearchText

void GlyphPaletteProxyModel::setSearchText ( const QString & text)
slot

setSearchText

Parameters
text– if the text starts with "U+", the consecutive characters are interpreted as a hex value. Otherwise, the first codepoint of text is searched upon.

Definition at line 52 of file GlyphPaletteProxyModel.cpp.

53{
54 QString adjustedText = text;
55 if (text.startsWith("U+")) {
56 bool ok = false;
57 const uint code = text.mid(2).toUInt(&ok, 16);
58 if (ok) {
59 adjustedText = QString::fromUcs4(&code, 1);
60 }
61 }
62 if (!d->searchText.isEmpty() && !adjustedText.isEmpty() && d->searchText.toUcs4().first() == adjustedText.toUcs4().first()) {
63 return;
64 } else {
65 d->searchText = adjustedText.isEmpty()? adjustedText: QString::fromUcs4(&adjustedText.toUcs4().first(), 1);
66 emit searchTextChanged();
67 invalidateFilter();
68 }
69}

References d, and searchTextChanged().

Member Data Documentation

◆ d

QScopedPointer<Private> GlyphPaletteProxyModel::d
private

Definition at line 80 of file GlyphPaletteProxyModel.h.

Property Documentation

◆ blockFilter

int GlyphPaletteProxyModel::blockFilter
readwrite

Definition at line 25 of file GlyphPaletteProxyModel.h.

◆ blockLabels

QVariantList GlyphPaletteProxyModel::blockLabels
read

Definition at line 24 of file GlyphPaletteProxyModel.h.

◆ searchText

QString GlyphPaletteProxyModel::searchText
read

Definition at line 26 of file GlyphPaletteProxyModel.h.


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