Pokered Save Editor 2
Pokemon Red & Blue save file editor - Qt 6 C++/QML
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
34
36{
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
47{
49
50 this->section = section;
51}
52
54{
55 return mandated;
56}
57
58void CreditDBEntry::qmlProtect(const QQmlEngine* const engine) const
59{
60 Utility::qmlProtectUtil(this, engine);
61}
62
64{
65 return license;
66}
67
69{
70 return note;
71}
72
73QString CreditDBEntry::getUrl() const
74{
75 return url;
76}
77
79{
80 return name;
81}
82
84{
85 return section;
86}
87
88void 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
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}
static CreditsDB * inst()
< Number of credit entries.
Definition creditsdb.cpp:33
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 void process(QJsonObject &data)
Parse JSON and append entries to CreditsDB's store.
QString getName() const
QString url
Backing field (read via getUrl()).
QString getUrl() const
QString name
Backing field (read via getName()).
QString license
Backing field (read via getLicense()).
QString note
Backing field (read via getNote()).
QString getNote() const
void qmlRegister() const
Register this entry type with QML.
QString mandated
Backing field (read via getMandated()).
QString section
Backing field (read via getSection()).
QString getMandated() const
CreditDBEntry()
Empty entry (protected – built by the DB).
void qmlProtect(const QQmlEngine *const engine) const
Pin to C++ ownership (anti-GC).
QString getSection() const
< Credits section heading.
QString getLicense() const