Skip to content

Commit 2942c7e

Browse files
authored
Merge pull request #239 from Ghabry/json
Add Glaze JSON bindings for QML interop with lcf data
2 parents 01633e4 + d5a4065 commit 2942c7e

39 files changed

Lines changed: 1777 additions & 20 deletions

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,9 @@ Makefile*
3232
/.flatpak-builder
3333
/local-repo
3434

35+
# appimage
36+
AppDir/
37+
3538
# liblcf
3639
lib/liblcf
3740

CMakeLists.txt

Lines changed: 37 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ if(EDITOR_FIND_ROOT_PATH_APPEND)
1616
list(APPEND CMAKE_FIND_ROOT_PATH "${CMAKE_PREFIX_PATH}")
1717
endif()
1818

19-
# C++17 is required
19+
# C++23 is required
2020
set(CMAKE_CXX_STANDARD 23)
2121
set(CMAKE_CXX_STANDARD_REQUIRED ON)
2222
set(CMAKE_CXX_EXTENSIONS OFF)
@@ -323,21 +323,48 @@ set(EDITOR_SOURCES
323323
)
324324

325325
set(EDITOR_QML_UI
326+
src/ui/common/CheckBox.qml
327+
src/ui/common/SpinBox.qml
328+
src/ui/common/TextField.qml
326329
src/ui/MainWindow.qml
330+
src/ui/database/DatabaseWindow.qml
331+
src/ui/database/ActorPage.qml
332+
src/ui/database/DatabaseEntryListPage.qml
333+
src/ui/database/DatabaseEntryPage.qml
334+
src/ui/database/DatabasePage.qml
335+
src/ui/database/ItemPage.qml
336+
src/ui/database/SkillPage.qml
337+
src/ui/database/VocabularyPage.qml
327338
)
328339

329340
set(EDITOR_QML_INTERFACE
330-
src/qmlbinding/empty.h
341+
src/qmlbinding/json_internals/json_t_database.cpp
342+
src/qmlbinding/json_internals/json_t_impl.h
343+
src/qmlbinding/json_internals/json_t_map.cpp
344+
src/qmlbinding/json_internals/json_t_treemap.cpp
345+
src/qmlbinding/json.h
346+
src/qmlbinding/json_list_view.cpp
347+
src/qmlbinding/json_list_view.h
348+
src/qmlbinding/json_t.h
349+
src/qmlbinding/json_view.cpp
350+
src/qmlbinding/json_view.h
351+
src/qmlbinding/lcf_glaze.h
352+
src/qmlbinding/project_data_gadget.cpp
353+
src/qmlbinding/project_data_gadget.h
331354
)
332355

333356
# Dependencies
334357
set(QT_NO_PRIVATE_MODULE_WARNING ON)
335-
find_package(Qt6 ${REQUIRED_QT_VERSION} CONFIG REQUIRED COMPONENTS Widgets Core Multimedia Gui GuiPrivate Svg QuickControls2)
358+
find_package(Qt6 ${REQUIRED_QT_VERSION} CONFIG REQUIRED COMPONENTS
359+
Widgets Core Multimedia Gui Svg
360+
GuiPrivate QuickPrivate QuickControls2 WidgetsPrivate)
336361
find_package(Qt6LinguistTools CONFIG QUIET)
337362
find_package(ZLIB REQUIRED)
338363
find_package(glaze REQUIRED)
339364
find_package(KF6 ${KF_DEP_VERSION} REQUIRED COMPONENTS Kirigami)
340365
find_package(QQC2BreezeStyle REQUIRED)
366+
find_package(KDBindings QUIET) # only required by the static build
367+
find_package(KDDockWidgets-qt6 REQUIRED)
341368

342369
qt_standard_project_setup(
343370
REQUIRES "${REQUIRED_QT_VERSION}"
@@ -383,6 +410,11 @@ else()
383410
endif()
384411
endif()
385412

413+
if (CMAKE_CXX_COMPILER_ID MATCHES "Clang$")
414+
# Fix template recursion limit hit by glaze
415+
target_compile_options(${EXE_NAME} PRIVATE "-fbracket-depth=1024")
416+
endif()
417+
386418
# Include directories
387419
target_include_directories(${EXE_NAME}
388420
PUBLIC
@@ -462,6 +494,7 @@ endif()
462494
target_link_libraries(${EXE_NAME} PRIVATE
463495
ZLIB::ZLIB
464496
glaze::glaze
497+
KDAB::kddockwidgets
465498
Qt6::Widgets
466499
Qt6::Gui
467500
Qt6::Core
@@ -486,6 +519,7 @@ if(KIRIGAMI_TYPE STREQUAL "STATIC_LIBRARY")
486519
KF6KirigamiPrivateplugin
487520
KF6KirigamiPolyfillplugin
488521
)
522+
target_compile_definitions(${EXE_NAME} PUBLIC "-DKIRIGAMI_STATIC=1")
489523
endif()
490524

491525
get_target_property(QQC2_TYPE org.kde.breeze TYPE)

CMakePresets.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -262,7 +262,7 @@
262262
"name": "macos-parent",
263263
"cacheVariables": {
264264
"EDITOR_PREFIX_PATH_APPEND": "$env{EASYRPG_BUILDSCRIPTS}/macos/qt/6.10.1/macos",
265-
"CMAKE_OSX_DEPLOYMENT_TARGET": "10.15",
265+
"CMAKE_OSX_DEPLOYMENT_TARGET": "13.3",
266266
"CMAKE_OSX_ARCHITECTURES": "arm64"
267267
},
268268
"environment": {

builds/cmake/CMakePresets.json.template

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@
3939
"displayName": "macOS",
4040
"cacheVariables": {
4141
"EDITOR_PREFIX_PATH_APPEND": "$env{EASYRPG_BUILDSCRIPTS}/macos/qt/6.10.1/macos",
42-
"CMAKE_OSX_DEPLOYMENT_TARGET": "10.15",
42+
"CMAKE_OSX_DEPLOYMENT_TARGET": "13.3",
4343
"CMAKE_OSX_ARCHITECTURES": "arm64"
4444
},
4545
"environment": {

builds/vcpkg_overlay/kddockwidgets/portfile.cmake

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ vcpkg_cmake_configure(
4545
# https://github.com/KDAB/KDDockWidgets/blob/v2.1.0/CMakeLists.txt#L301
4646
-DCMAKE_DISABLE_FIND_PACKAGE_spdlog=ON
4747
-DCMAKE_DISABLE_FIND_PACKAGE_fmt=ON
48-
-DCMAKE_REQUIRE_FIND_PACKAGE_nlohmann_json=ON
48+
-DCMAKE_DISABLE_FIND_PACKAGE_nlohmann_json=ON
4949
"-DCMAKE_PREFIX_PATH=$ENV{Qt6_Path}"
5050
)
5151

src/core.cpp

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,12 @@
2222
#include <QGraphicsView>
2323
#include <QPainter>
2424
#include <QDebug>
25+
#include <QQmlApplicationEngine>
2526
#include "ui/map/map_scene.h"
2627
#include "common/dbstring.h"
2728
#include "common/image_loader.h"
29+
#include <kddockwidgets/Config.h>
30+
#include <kddockwidgets/qtquick/Platform.h>
2831

2932
//define static member
3033
Core *Core::core_instance = nullptr;
@@ -684,6 +687,16 @@ const std::shared_ptr<Project>& Core::project() const {
684687
return m_project;
685688
}
686689

690+
QQmlApplicationEngine* Core::qmlEngine() {
691+
if (!m_qml_engine) {
692+
m_qml_engine = new QQmlApplicationEngine();
693+
KDDockWidgets::initFrontend(KDDockWidgets::FrontendType::QtQuick);
694+
KDDockWidgets::QtQuick::Platform::instance()->setQmlEngine(m_qml_engine);
695+
}
696+
697+
return m_qml_engine;
698+
}
699+
687700
void Core::beginPainting(QPixmap &dest)
688701
{
689702
m_painter.begin(&dest);

src/core.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
#include <QPixmap>
2929
#include <QPainter>
3030
#include <QListWidget>
31+
#include <QQmlApplicationEngine>
3132
#include <lcf/rpg/map.h>
3233
#include <lcf/rpg/chipset.h>
3334
#include "ui/other/run_game_dialog.h"
@@ -117,6 +118,8 @@ class Core : public QObject
117118
std::shared_ptr<Project>& project();
118119
const std::shared_ptr<Project>& project() const;
119120

121+
QQmlApplicationEngine* qmlEngine();
122+
120123
signals:
121124
void toolChanged();
122125

@@ -151,6 +154,7 @@ class Core : public QObject
151154
QMap<int, lcf::rpg::Event*> *m_currentMapEvents;
152155
RunGameDialog *m_runGameDialog;
153156
std::shared_ptr<Project> m_project;
157+
QQmlApplicationEngine* m_qml_engine = nullptr;
154158
};
155159

156160
Core& core();

src/main.cpp

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
* along with EasyRPG Editor. If not, see <http://www.gnu.org/licenses/>.
1616
*/
1717

18+
#include "core.h"
1819
#include "ui/main_window.h"
1920
#include <QApplication>
2021
#include <QSplashScreen>
@@ -41,7 +42,7 @@ int main(int argc, char *argv[]) {
4142

4243
// Kirigami only loads a custom style when using a static build
4344
// Lets wait for upstream to improve this
44-
#if defined(_WIN32) || defined(__APPLE__)
45+
#if defined(KIRIGAMI_STATIC)
4546
// Default to org.kde.breeze style (from qqc2-breeze style)
4647
if (qEnvironmentVariableIsEmpty("QT_QUICK_CONTROLS_STYLE")) {
4748
const char* fstyle = "KIRIGAMI_FORCE_STYLE";
@@ -67,18 +68,19 @@ int main(int argc, char *argv[]) {
6768

6869
s.showMessage("EasyRPG Editor");
6970
//s.show();
71+
7072
#ifdef NDEBUG
7173
// close splash after 3 seconds for release
7274
QTimer::singleShot(3000, &s, &QWidget::close);
7375
#endif
7476

7577
// setup qml engine
76-
QQmlApplicationEngine engine;
77-
engine.loadFromModule("org.easyrpg.editor", "MainWindow");
78+
auto engine = core().qmlEngine();
7879

79-
if (engine.rootObjects().isEmpty()) {
80+
/*engine->loadFromModule("org.easyrpg.editor", "MainWindow");
81+
if (engine->rootObjects().isEmpty()) {
8082
return -1;
81-
}
83+
}*/
8284

8385
// load translations
8486
s.showMessage("Loading translations...");

src/model/project.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -168,7 +168,7 @@ QString Project::findFile(const QString& dir, const QString& filename, FileFinde
168168
return FileFinder::Find(projectDir().absolutePath(), dir, filename, type);
169169
}
170170

171-
QString Project::findFileOrDefault(const QString& filename) {
171+
QString Project::findFileOrDefault(const QString& filename) const {
172172
QString found = findFile(filename);
173173
return found.isEmpty() ? FileFinder::CombinePath(projectDir().absolutePath(), filename) : found;
174174
}

src/model/project.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ class Project {
5454
* @param filename File to find
5555
* @return Found file or the passed filename when not found
5656
*/
57-
QString findFileOrDefault(const QString& filename);
57+
QString findFileOrDefault(const QString& filename) const;
5858

5959
QString findDirectory(const QString& dir) const;
6060
QString findDirectory(const QString& baseDir, const QString& dir) const;

0 commit comments

Comments
 (0)