Pokered Save Editor 2
Pokemon Red & Blue save file editor - Qt 6 C++/QML
Loading...
Searching...
No Matches
utility.h
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#pragma once
17#include <QObject>
18#include <QString>
19
20class QQmlContext;
21class QQmlEngine;
22
23#include "./common_autoport.h"
24
25class Random;
26
45class COMMON_AUTOPORT Utility : public QObject
46{
47 Q_OBJECT
48 Q_PROPERTY(Random* random READ random CONSTANT)
49
50public:
52 static Utility* inst();
53
55 Random* random();
56
65 Q_INVOKABLE const QString encodeBeforeUrl(const QString beforeStr) const;
71 Q_INVOKABLE const QString decodeAfterUrl(QString beforeStr) const;
72
73 // Generic utility for any of the databases to use
83 static void qmlProtectUtil(const QObject* const obj, const QQmlEngine* const engine);
84
85public slots:
90 void qmlProtect(const QQmlEngine* const engine) const;
95 void qmlHook(QQmlContext* const context) const;
96
97private slots:
99 void qmlRegister() const;
100
101private:
103 Utility();
104};
Project-wide source of randomness, usable from both C++ and QML.
Definition random.h:50
const QString decodeAfterUrl(QString beforeStr) const
Decode the space-separated hex produced by encodeBeforeUrl() back to text.
Definition utility.cpp:57
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
static Utility * inst()
< The shared Random instance, reachable from QML as pseCommon.random.
Definition utility.cpp:31
void qmlProtect(const QQmlEngine *const engine) const
Protect this Utility (and the Random it owns) from QML GC.
Definition utility.cpp:69
Random * random()
Accessor for the shared Random singleton (also backs the random property).
Definition utility.cpp:37
void qmlHook(QQmlContext *const context) const
Install this object into a QML context as the pseCommon property.
Definition utility.cpp:76
const QString encodeBeforeUrl(const QString beforeStr) const
Encode a string into space-separated hex of each character's code point.
Definition utility.cpp:44
Shared-library import/export macro for the common library.
#define COMMON_AUTOPORT
Expands to the correct dllexport/dllimport decoration for this library.