Pokered Save Editor 2
Pokemon Red & Blue save file editor - Qt 6 C++/QML
Loading...
Searching...
No Matches
Utility Class Reference

Grab-bag of shared helpers, and the QML entry point for the common layer. More...

#include <utility.h>

Inheritance diagram for Utility:
Collaboration diagram for Utility:

Public Member Functions

Randomrandom ()
 Accessor for the shared Random singleton (also backs the random property).
const QString encodeBeforeUrl (const QString beforeStr) const
 Encode a string into space-separated hex of each character's code point.
const QString decodeAfterUrl (QString beforeStr) const
 Decode the space-separated hex produced by encodeBeforeUrl() back to text.
void qmlProtect (const QQmlEngine *const engine) const
 Protect this Utility (and the Random it owns) from QML GC.
void qmlHook (QQmlContext *const context) const
 Install this object into a QML context as the pseCommon property.

Static Public Member Functions

static Utilityinst ()
 < The shared Random instance, reachable from QML as pseCommon.random.
static void qmlProtectUtil (const QObject *const obj, const QQmlEngine *const engine)
 Pin obj to C++ ownership so the QML engine never garbage-collects it.

Detailed Description

Grab-bag of shared helpers, and the QML entry point for the common layer.

Utility is a QObject singleton exposed to QML under the context name pseCommon. Through it, QML reaches the shared Random instance (pseCommon.random) and a couple of string helpers used by the name editors.

It also hosts qmlProtectUtil() - the one-liner every database and save object in the project calls to keep its C++ QObjects from being garbage-collected by the QML engine. Centralising that here means there is exactly one place that knows the GC-ownership incantation.

Singleton
Private constructor; obtain via inst(). Registered with QML as an uncreatable type. Constructing it also brings up Random.
See also
Random, qmlProtectUtil()

Definition at line 45 of file utility.h.

Member Function Documentation

◆ decodeAfterUrl()

const QString Utility::decodeAfterUrl ( QString beforeStr) const

Decode the space-separated hex produced by encodeBeforeUrl() back to text.

Parameters
beforeStrThe encoded hex string (spaces are stripped before decoding).
Returns
The original text.

Definition at line 57 of file utility.cpp.

Referenced by FontPreviewInstance::getInputStr(), and FontPreviewInstance::setup().

◆ encodeBeforeUrl()

const QString Utility::encodeBeforeUrl ( const QString beforeStr) const

Encode a string into space-separated hex of each character's code point.

Used to pass arbitrary name text safely through a URL/route fragment.

Parameters
beforeStrThe text to encode.
Returns
e.g. "41 42" for "AB".
See also
decodeAfterUrl(), the exact inverse.

Definition at line 44 of file utility.cpp.

◆ inst()

Utility * Utility::inst ( )
static

< The shared Random instance, reachable from QML as pseCommon.random.

Returns the process-wide Utility singleton, constructing it on first call.

Definition at line 31 of file utility.cpp.

Referenced by FontPreviewInstance::getInputStr(), and FontPreviewInstance::setup().

◆ qmlHook()

void Utility::qmlHook ( QQmlContext *const context) const

Install this object into a QML context as the pseCommon property.

Parameters
contextThe QML context to inject into.

Definition at line 76 of file utility.cpp.

◆ qmlProtect()

void Utility::qmlProtect ( const QQmlEngine *const engine) const

Protect this Utility (and the Random it owns) from QML GC.

Parameters
engineThe active QML engine.

Definition at line 69 of file utility.cpp.

References Random::inst(), Random::qmlProtect(), and qmlProtectUtil().

◆ qmlProtectUtil()

void Utility::qmlProtectUtil ( const QObject *const obj,
const QQmlEngine *const engine )
static

Pin obj to C++ ownership so the QML engine never garbage-collects it.

The shared building block behind every qmlProtect() in the project. Static so any class can call it without a Utility instance.

Parameters
objThe C++ QObject to protect (kept alive on the C++ side).
engineThe QML engine that would otherwise claim ownership.
Note
Internally casts away constness because Qt's ownership setter is non-const.

Definition at line 63 of file utility.cpp.

Referenced by AbstractHiddenItemDB::qmlProtect(), AbstractRandomString::qmlProtect(), CreditDBEntry::qmlProtect(), CreditsDB::qmlProtect(), DB::qmlProtect(), EventDBEntry::qmlProtect(), EventPokemonDB::qmlProtect(), EventPokemonDBEntry::qmlProtect(), EventsDB::qmlProtect(), Examples::qmlProtect(), FlyDB::qmlProtect(), FlyDBEntry::qmlProtect(), FontDBEntry::qmlProtect(), FontsDB::qmlProtect(), FontSearch::qmlProtect(), GameCornerDB::qmlProtect(), GameCornerDBEntry::qmlProtect(), GameData::qmlProtect(), HiddenItemDBEntry::qmlProtect(), ItemDBEntry::qmlProtect(), ItemsDB::qmlProtect(), MapDBEntry::qmlProtect(), MapDBEntryConnect::qmlProtect(), MapDBEntrySign::qmlProtect(), MapDBEntrySprite::qmlProtect(), MapDBEntryWarpIn::qmlProtect(), MapDBEntryWarpOut::qmlProtect(), MapDBEntryWildMon::qmlProtect(), MapsDB::qmlProtect(), MapSearch::qmlProtect(), MissableDBEntry::qmlProtect(), MissablesDB::qmlProtect(), MovesDB::qmlProtect(), MusicDB::qmlProtect(), Names::qmlProtect(), PokemonDB::qmlProtect(), Random::qmlProtect(), ScriptsDB::qmlProtect(), SpritesDB::qmlProtect(), SpriteSetDB::qmlProtect(), StarterPokemonDB::qmlProtect(), TilesetDB::qmlProtect(), TmHmsDB::qmlProtect(), TradesDB::qmlProtect(), TrainersDB::qmlProtect(), TypesDB::qmlProtect(), and qmlProtect().

◆ random()

Random * Utility::random ( )

Accessor for the shared Random singleton (also backs the random property).

Definition at line 37 of file utility.cpp.

References Random::inst().


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