Pokered Save Editor 2
Pokemon Red & Blue save file editor - Qt 6 C++/QML
Toggle main menu visibility
Loading...
Searching...
No Matches
creditdbentry.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
21
22
#include <QJsonDocument>
23
#include <QJsonArray>
24
#include <QJsonObject>
25
#include <QJsonValueRef>
26
#include <
pse-common/utility.h
>
27
28
#include "
creditdbentry.h
"
29
#include "
../creditsdb.h
"
30
31
CreditDBEntry::CreditDBEntry
() {
32
qmlRegister
();
33
}
34
35
CreditDBEntry::CreditDBEntry
(QJsonValue& data)
36
{
37
qmlRegister
();
38
39
name
= data[
"name"
].toString(
""
);
40
url
= data[
"url"
].toString(
""
);
41
note
= data[
"note"
].toString(
""
);
42
license
= data[
"license"
].toString(
""
);
43
mandated
= data[
"mandated"
].toString(
""
);
44
}
45
46
CreditDBEntry::CreditDBEntry
(QString
section
)
47
{
48
qmlRegister
();
49
50
this->section =
section
;
51
}
52
53
QString
CreditDBEntry::getMandated
()
const
54
{
55
return
mandated
;
56
}
57
58
void
CreditDBEntry::qmlProtect
(
const
QQmlEngine*
const
engine)
const
59
{
60
Utility::qmlProtectUtil
(
this
, engine);
61
}
62
63
QString
CreditDBEntry::getLicense
()
const
64
{
65
return
license
;
66
}
67
68
QString
CreditDBEntry::getNote
()
const
69
{
70
return
note
;
71
}
72
73
QString
CreditDBEntry::getUrl
()
const
74
{
75
return
url
;
76
}
77
78
QString
CreditDBEntry::getName
()
const
79
{
80
return
name
;
81
}
82
83
QString
CreditDBEntry::getSection
()
const
84
{
85
return
section
;
86
}
87
88
void
CreditDBEntry::process
(QJsonObject& data)
89
{
90
// Data-driven: walk the ordered "sections" array. Each section contributes a
91
// section-header entry (section name, no other fields) followed by its
92
// entries. Section ORDER is whatever the JSON lists -- adding/reordering a
93
// section, or adding a credit, is now a pure credits.json edit (no C++ change).
94
// The store stays flat (header sentinel + entries) so the DB-entry pattern and
95
// every DB-layer consumer/test is unchanged; CreditsModel regroups it for the view.
96
for
(QJsonValue sectionVal : data[
"sections"
].toArray())
97
{
98
QJsonObject
section
= sectionVal.toObject();
99
100
CreditsDB::inst
()->store.append(
new
CreditDBEntry
(
section
[
"section"
].toString(
""
)));
101
102
for
(QJsonValue entry :
section
[
"entries"
].toArray())
103
CreditsDB::inst
()->store.append(
new
CreditDBEntry
(entry));
104
}
105
}
106
107
void
CreditDBEntry::qmlRegister
()
const
108
{
109
static
bool
registered =
false
;
110
if
(registered)
111
return
;
112
113
qmlRegisterUncreatableType<CreditDBEntry>(
"PSE.DB.CreditDBEntry"
, 1, 0,
"CreditDBEntry"
,
"Can't instantiate in QML"
);
114
registered =
true
;
115
}
CreditsDB::inst
static CreditsDB * inst()
< Number of credit entries.
Definition
creditsdb.cpp:33
Utility::qmlProtectUtil
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
creditdbentry.h
creditsdb.h
CreditDBEntry::process
static void process(QJsonObject &data)
Parse JSON and append entries to CreditsDB's store.
Definition
creditdbentry.cpp:88
CreditDBEntry::getName
QString getName() const
Definition
creditdbentry.cpp:78
CreditDBEntry::url
QString url
Backing field (read via getUrl()).
Definition
creditdbentry.h:72
CreditDBEntry::getUrl
QString getUrl() const
Definition
creditdbentry.cpp:73
CreditDBEntry::name
QString name
Backing field (read via getName()).
Definition
creditdbentry.h:71
CreditDBEntry::license
QString license
Backing field (read via getLicense()).
Definition
creditdbentry.h:74
CreditDBEntry::note
QString note
Backing field (read via getNote()).
Definition
creditdbentry.h:73
CreditDBEntry::getNote
QString getNote() const
Definition
creditdbentry.cpp:68
CreditDBEntry::qmlRegister
void qmlRegister() const
Register this entry type with QML.
Definition
creditdbentry.cpp:107
CreditDBEntry::mandated
QString mandated
Backing field (read via getMandated()).
Definition
creditdbentry.h:75
CreditDBEntry::section
QString section
Backing field (read via getSection()).
Definition
creditdbentry.h:70
CreditDBEntry::getMandated
QString getMandated() const
Definition
creditdbentry.cpp:53
CreditDBEntry::CreditDBEntry
CreditDBEntry()
Empty entry (protected – built by the DB).
Definition
creditdbentry.cpp:31
CreditDBEntry::qmlProtect
void qmlProtect(const QQmlEngine *const engine) const
Pin to C++ ownership (anti-GC).
Definition
creditdbentry.cpp:58
CreditDBEntry::getSection
QString getSection() const
< Credits section heading.
Definition
creditdbentry.cpp:83
CreditDBEntry::getLicense
QString getLicense() const
Definition
creditdbentry.cpp:63
utility.h
projects
db
src
pse-db
entries
creditdbentry.cpp
Generated by
1.17.0