[WIP] Add cmake module to clone subrepos; add CMakeLists for QJsonModel.

-  ⚠️  Currently not working. Experiencing a SegFault
This commit is contained in:
S David 2024-04-29 11:33:49 -04:00
parent 9f6e0743f2
commit 8c42557063
9 changed files with 68 additions and 22 deletions

3
.gitmodules vendored
View File

@ -0,0 +1,3 @@
[submodule "Apps/Editors/third-party/QJsonModel"]
path = Apps/Editors/third-party/QJsonModel
url = git@gitea.beniquez.me:sdaveb/QJsonModel.git

View File

@ -1,3 +1,4 @@
add_subdirectory(third-party)
qt_add_executable(ResourceEditor
main.cpp
@ -13,6 +14,7 @@ PRIVATE
Qt6::Core
Qt6::Widgets
Qt6::Gui
QJsonModel
)
set_target_properties(ResourceEditor

View File

@ -28,6 +28,8 @@
#include <QTextStream>
#include <QWidget>
#include "qjsonmodel.h"
#include <algorithm>
#include <functional>
#include <iostream>
@ -146,19 +148,48 @@ void MainWindow::onclick_fstree_file(const QModelIndex& index)
tr("Document was already loaded"), 1000
);
} else {
this->statusBar()->showMessage(tr("Opened New Document"), 1000);
auto text_widget = new QPlainTextEdit(this->ui->mdiArea);
auto filename = path_info.baseName();
auto suffix = path_info.suffix();
if (suffix == "json") {
auto tree_widget = new QTreeView(this->ui->mdiArea);
auto found = this->json_models.find(filename);
QFile file(path);
if (file.open(QIODevice::ReadOnly | QIODevice::Text)) {
QTextStream file_text(&file);
text_widget->setPlainText(file_text.readAll());
file.close();
if (found != this->json_models.end()) {
this->json_models[filename] =
std::make_unique<QJsonModel>(this);
}
auto& model = this->json_models[filename];
tree_widget->setModel(model.get());
QFile file(path);
if (file.open(QIODevice::ReadOnly | QIODevice::Text)) {
QTextStream file_text(&file);
model->loadJson(file_text.readAll().toUtf8());
file.close();
}
subwindow = this->ui->mdiArea->addSubWindow(tree_widget);
subwindow->setObjectName(path);
subwindow->setWindowTitle(path_info.fileName());
} else {
this->statusBar()->showMessage(
tr("Opened New Document"), 1000
);
auto text_widget = new QPlainTextEdit(this->ui->mdiArea);
QFile file(path);
if (file.open(QIODevice::ReadOnly | QIODevice::Text)) {
QTextStream file_text(&file);
text_widget->setPlainText(file_text.readAll());
file.close();
}
subwindow = this->ui->mdiArea->addSubWindow(text_widget);
subwindow->setObjectName(path);
subwindow->setWindowTitle(path_info.fileName());
}
subwindow = this->ui->mdiArea->addSubWindow(text_widget);
subwindow->setObjectName(path);
subwindow->setWindowTitle(path_info.fileName());
}
subwindow->show();

View File

@ -23,6 +23,7 @@ class QMdiSubWindow;
class QFileSystemModel;
class QModelIndex;
class QMdiSubWindow;
class QJsonModel;
namespace ResourceEditor {
class MainWindow : public QMainWindow {
@ -50,6 +51,8 @@ class MainWindow : public QMainWindow {
QString current_directory;
Ptr<Ui::MainWindow> ui;
Ptr<QFileSystemModel> filesystem_model;
std::map<QString, Ptr<QJsonModel>> json_models;
};
}

View File

@ -6,8 +6,8 @@
<rect>
<x>0</x>
<y>0</y>
<width>486</width>
<height>425</height>
<width>644</width>
<height>546</height>
</rect>
</property>
<property name="sizePolicy">
@ -108,12 +108,13 @@
</item>
</layout>
</widget>
<widget class="QStatusBar" name="statusbar"/>
<widget class="QMenuBar" name="menubar">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>486</width>
<width>644</width>
<height>24</height>
</rect>
</property>
@ -139,7 +140,6 @@
<addaction name="menuFile"/>
<addaction name="menuHelp"/>
</widget>
<widget class="QStatusBar" name="statusbar"/>
<action name="actionNew">
<property name="text">
<string>New file...</string>

11
Apps/Editors/third-party/CMakeLists.txt vendored Normal file
View File

@ -0,0 +1,11 @@
add_library(QJsonModel OBJECT ${CMAKE_CURRENT_SOURCE_DIR}/QJsonModel/qjsonmodel.cpp)
target_include_directories(QJsonModel SYSTEM BEFORE
INTERFACE ${CMAKE_CURRENT_SOURCE_DIR}/QJsonModel
)
target_link_libraries(QJsonModel
PRIVATE
Qt6::Core
Qt6::Gui
Qt6::Widgets
)

@ -0,0 +1 @@
Subproject commit 65aa28dd7f4281c8db71a8693f3014f6c695666a

View File

@ -42,14 +42,12 @@ else()
endif()
endfunction()
function(git_setup_submodules)
find_package(Git QUIET)
if(GIT_FOUND AND EXISTS "${PROJECT_SOURCE_DIR}/.git")
# Update submodules as needed
option(GIT_SUBMODULE "Check submodules during build" ON)
if(GIT_SUBMODULE)
message(STATUS "Submodule update")
message(STATUS "Git submodule update")
execute_process(COMMAND ${GIT_EXECUTABLE} submodule update --init --recursive
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
RESULT_VARIABLE GIT_SUBMOD_RESULT)
@ -58,9 +56,5 @@ function(git_setup_submodules)
endif()
endif()
endif()
if(NOT EXISTS "${PROJECT_SOURCE_DIR}/extern/repo/CMakeLists.txt")
message(FATAL_ERROR "The submodules were not downloaded! GIT_SUBMODULE was turned off or failed. Please update submodules and try again.")
endif()
endfunction()
# vim: ts=4 sts=4 sw=4 noet :

View File

@ -22,6 +22,7 @@ project(Elemental
DESCRIPTION "A simple top-down strategy game"
)
include(CPM)
git_setup_submodules()
SET(${PROJECT_NAME}_CMAKE_SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR})