Pokered Save Editor 2
Pokemon Red & Blue save file editor - Qt 6 C++/QML
Loading...
Searching...
No Matches
fontsearch.cpp
Go to the documentation of this file.
1/*
2 * Copyright 2020 Twilight
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15*/
16
22
23#include <QQmlEngine>
24#include <pse-common/utility.h>
25
26#include "fontsearch.h"
27#include "../fontsdb.h"
29#include "../fontsdb.h"
30
32{
33 qmlRegister();
34 startOver();
35}
36
38{
39 results.clear();
40
41 // Copy elements over to begin search
42 for(auto entry : FontsDB::inst()->getStore())
43 {
44 results.append(entry);
45 }
46
47 fontCountChanged();
48
49 return this;
50}
51
53{
54 results.clear();
55 fontCountChanged();
56
57 return this;
58}
59
60FontSearch* FontSearch::keepAnyOf(bool normal, bool control, bool picture,
61 bool singleChar, bool multiChar, bool variable)
62{
63 // Rebuild from the full store, keeping any entry that matches at least one
64 // enabled trait. This gives the keyboard's filters OR/union semantics ("show
65 // Normal AND Control" = show both), and naturally yields an empty list when
66 // nothing is enabled.
67 results.clear();
68
69 for(auto entry : FontsDB::inst()->getStore())
70 {
71 if((normal && entry->normal) ||
72 (control && entry->control) ||
73 (picture && entry->picture) ||
74 (singleChar && entry->singleChar) ||
75 (multiChar && entry->multiChar) ||
76 (variable && entry->variable))
77 results.append(entry);
78 }
79
80 fontCountChanged();
81
82 return this;
83}
84
86{
87 for(auto entry : QVector<FontDBEntry*>(results))
88 if(!entry->shorthand)
89 results.removeOne(entry);
90
91 fontCountChanged();
92
93 return this;
94}
95
97{
98 for(auto entry : QVector<FontDBEntry*>(results))
99 if(entry->shorthand)
100 results.removeOne(entry);
101
102 fontCountChanged();
103
104 return this;
105}
106
108{
109 for(auto entry : QVector<FontDBEntry*>(results))
110 if(!entry->normal)
111 results.removeOne(entry);
112
113 fontCountChanged();
114
115 return this;
116}
117
119{
120 for(auto entry : QVector<FontDBEntry*>(results))
121 if(entry->normal)
122 results.removeOne(entry);
123
124 fontCountChanged();
125
126 return this;
127}
128
130{
131 for(auto entry : QVector<FontDBEntry*>(results))
132 if(!entry->control)
133 results.removeOne(entry);
134
135 fontCountChanged();
136
137 return this;
138}
139
141{
142 for(auto entry : QVector<FontDBEntry*>(results))
143 if(entry->control)
144 results.removeOne(entry);
145
146 fontCountChanged();
147
148 return this;
149}
150
152{
153 for(auto entry : QVector<FontDBEntry*>(results))
154 if(!entry->picture)
155 results.removeOne(entry);
156
157 fontCountChanged();
158
159 return this;
160}
161
163{
164 for(auto entry : QVector<FontDBEntry*>(results))
165 if(entry->picture)
166 results.removeOne(entry);
167
168 fontCountChanged();
169
170 return this;
171}
172
174{
175 for(auto entry : QVector<FontDBEntry*>(results))
176 if(!entry->singleChar)
177 results.removeOne(entry);
178
179 fontCountChanged();
180
181 return this;
182}
183
185{
186 for(auto entry : QVector<FontDBEntry*>(results))
187 if(entry->singleChar)
188 results.removeOne(entry);
189
190 fontCountChanged();
191
192 return this;
193}
194
196{
197 for(auto entry : QVector<FontDBEntry*>(results))
198 if(!entry->multiChar)
199 results.removeOne(entry);
200
201 fontCountChanged();
202
203 return this;
204}
205
207{
208 for(auto entry : QVector<FontDBEntry*>(results))
209 if(entry->multiChar)
210 results.removeOne(entry);
211
212 fontCountChanged();
213
214 return this;
215}
216
218{
219 for(auto entry : QVector<FontDBEntry*>(results))
220 if(!entry->variable)
221 results.removeOne(entry);
222
223 fontCountChanged();
224
225 return this;
226}
227
229{
230 for(auto entry : QVector<FontDBEntry*>(results))
231 if(entry->variable)
232 results.removeOne(entry);
233
234 fontCountChanged();
235
236 return this;
237}
238
239const QVector<FontDBEntry*> FontSearch::getFonts() const
240{
241 return results;
242}
243
245{
246 return results.size();
247}
248
249const FontDBEntry* FontSearch::fontAt(const int ind) const
250{
251 return results.at(ind);
252}
253
254void FontSearch::qmlProtect(const QQmlEngine* const engine) const
255{
256 Utility::qmlProtectUtil(this, engine);
257}
258
259void FontSearch::qmlRegister() const
260{
261 static bool registered = false;
262 if(registered)
263 return;
264
265 qmlRegisterUncreatableType<FontSearch>("PSE.DB.FontSearch", 1, 0, "FontSearch", "Can't instantiate in QML");
266 registered = true;
267}
268
FontSearch * andVariable()
Keep only variable glyphs.
FontSearch * notNormal()
Drop normal glyphs.
FontSearch * notSingleChar()
Drop single-char glyphs.
FontSearch * andPicture()
Keep only picture glyphs.
FontSearch * notShorthand()
Drop shorthand glyphs. Returns this.
FontSearch * andControl()
Keep only control glyphs.
int getFontCount() const
Result count (backs fontCount).
FontSearch * startOver()
Reset to all glyphs. Returns this.
FontSearch * keepAnyOf(bool normal, bool control, bool picture, bool singleChar, bool multiChar, bool variable)
OR-union filter (see note). Returns this.
FontSearch * andNormal()
Keep only normal glyphs.
FontSearch * andMultiChar()
Keep only multi-char glyphs.
const FontDBEntry * fontAt(const int ind) const
Result ind (for QML).
const QVector< FontDBEntry * > getFonts() const
The current result set.
FontSearch * notMultiChar()
Drop multi-char glyphs.
FontSearch * notPicture()
Drop picture glyphs.
FontSearch()
Start with all glyphs in the result set.
FontSearch * clear()
Empty the result set. Returns this.
FontSearch * andShorthand()
Keep only shorthand glyphs. Returns this.
FontSearch * andSingleChar()
Keep only single-char glyphs.
FontSearch * notVariable()
Drop variable glyphs.
FontSearch * notControl()
Drop control glyphs.
void qmlProtect(const QQmlEngine *const engine) const
Pin to C++ ownership.
static FontsDB * inst()
< Number of font glyphs.
Definition fontsdb.cpp:367
static void qmlProtectUtil(const QObject *const obj, const QQmlEngine *const engine)
Pin obj to C++ ownership so the QML engine never garbage-collects it.
Definition utility.cpp:63
One in-game font character: its code, output text, and classification flags.
Definition fontdbentry.h:43