From 020216b13d18bbfe0470bea22ebc6716252d333b Mon Sep 17 00:00:00 2001 From: Joshua Goins Date: Sun, 10 Dec 2023 11:11:01 -0500 Subject: [PATCH] Reload models when importing via Penumbra HTTP API --- armoury/CMakeLists.txt | 5 ++++- armoury/include/mainwindow.h | 2 ++ armoury/include/penumbraapi.h | 18 ++++++++++++++++++ armoury/include/singlegearview.h | 1 + armoury/src/mainwindow.cpp | 3 +++ armoury/src/penumbraapi.cpp | 15 +++++++++++++++ armoury/src/singlegearview.cpp | 6 ++++-- 7 files changed, 47 insertions(+), 3 deletions(-) create mode 100644 armoury/include/penumbraapi.h create mode 100644 armoury/src/penumbraapi.cpp diff --git a/armoury/CMakeLists.txt b/armoury/CMakeLists.txt index 5ac97a4..48d76fb 100644 --- a/armoury/CMakeLists.txt +++ b/armoury/CMakeLists.txt @@ -11,6 +11,7 @@ target_sources(novus-armoury include/gearlistwidget.h include/gearview.h include/mainwindow.h + include/penumbraapi.h include/settingswindow.h include/singlegearview.h @@ -22,6 +23,7 @@ target_sources(novus-armoury src/gearview.cpp src/main.cpp src/mainwindow.cpp + src/penumbraapi.cpp src/settingswindow.cpp src/singlegearview.cpp) target_include_directories(novus-armoury @@ -40,6 +42,7 @@ target_link_libraries(novus-armoury imgui Qt6::Core Qt6::Widgets - Qt6::Concurrent) + Qt6::Concurrent + Qt6::Network) install(TARGETS novus-armoury ${KF${QT_MAJOR_VERSION}_INSTALL_TARGETS_DEFAULT_ARGS}) diff --git a/armoury/include/mainwindow.h b/armoury/include/mainwindow.h index c66b247..1b8d7c1 100644 --- a/armoury/include/mainwindow.h +++ b/armoury/include/mainwindow.h @@ -14,6 +14,7 @@ struct GameData; class FileCache; +class PenumbraApi; class MainWindow : public NovusMainWindow { @@ -31,4 +32,5 @@ private: GameData &data; FileCache cache; + PenumbraApi *m_api = nullptr; }; \ No newline at end of file diff --git a/armoury/include/penumbraapi.h b/armoury/include/penumbraapi.h new file mode 100644 index 0000000..cb44d2f --- /dev/null +++ b/armoury/include/penumbraapi.h @@ -0,0 +1,18 @@ +// SPDX-FileCopyrightText: 2023 Joshua Goins +// SPDX-License-Identifier: GPL-3.0-or-later + +#pragma once + +#include + +class PenumbraApi : public QObject +{ +public: + explicit PenumbraApi(QObject *parent = nullptr); + +public Q_SLOTS: + void redrawAll(); + +private: + QNetworkAccessManager *m_mgr = nullptr; +}; \ No newline at end of file diff --git a/armoury/include/singlegearview.h b/armoury/include/singlegearview.h index dc3fec6..d83fec8 100644 --- a/armoury/include/singlegearview.h +++ b/armoury/include/singlegearview.h @@ -29,6 +29,7 @@ Q_SIGNALS: void levelOfDetailChanged(); void addToFullModelViewer(GearInfo &info); + void importedModel(); public Q_SLOTS: void clear(); diff --git a/armoury/src/mainwindow.cpp b/armoury/src/mainwindow.cpp index 8ce4dc5..e1644eb 100644 --- a/armoury/src/mainwindow.cpp +++ b/armoury/src/mainwindow.cpp @@ -18,12 +18,14 @@ #include "cmpeditor.h" #include "filecache.h" #include "gearlistwidget.h" +#include "penumbraapi.h" #include "settingswindow.h" MainWindow::MainWindow(GameData *in_data) : NovusMainWindow() , data(*in_data) , cache(FileCache{*in_data}) + , m_api(new PenumbraApi(this)) { setMinimumSize(QSize(800, 600)); setupMenubar(); @@ -45,6 +47,7 @@ MainWindow::MainWindow(GameData *in_data) connect(gearView, &SingleGearView::addToFullModelViewer, this, [this](GearInfo &info) { fullModelViewer->addGear(info); }); + connect(gearView, &SingleGearView::importedModel, m_api, &PenumbraApi::redrawAll); auto tabWidget = new QTabWidget(); tabWidget->addTab(gearView, QStringLiteral("Models")); diff --git a/armoury/src/penumbraapi.cpp b/armoury/src/penumbraapi.cpp new file mode 100644 index 0000000..bcfe7b3 --- /dev/null +++ b/armoury/src/penumbraapi.cpp @@ -0,0 +1,15 @@ +// SPDX-FileCopyrightText: 2023 Joshua Goins +// SPDX-License-Identifier: GPL-3.0-or-later + +#include "penumbraapi.h" + +PenumbraApi::PenumbraApi(QObject *parent) + : QObject(parent) + , m_mgr(new QNetworkAccessManager(this)) +{ +} + +void PenumbraApi::redrawAll() +{ + m_mgr->post(QNetworkRequest(QUrl(QStringLiteral("http://localhost:42069/api/redrawAll"))), QByteArray{}); +} diff --git a/armoury/src/singlegearview.cpp b/armoury/src/singlegearview.cpp index 8ccb16b..c9f3e7c 100644 --- a/armoury/src/singlegearview.cpp +++ b/armoury/src/singlegearview.cpp @@ -102,8 +102,9 @@ SingleGearView::SingleGearView(GameData *data, FileCache &cache, QWidget *parent tr("Import Model"), QStringLiteral("%1.glb").arg(sanitizeMdlPath(gearView->getLoadedGearPath())), tr("glTF Binary File (*.glb)")); - - importModel(fileName); + if (!fileName.isEmpty()) { + importModel(fileName); + } } }); topControlLayout->addWidget(importButton); @@ -334,6 +335,7 @@ void SingleGearView::importModel(const QString &filename) file.close(); qInfo() << "Successfully imported model!"; + Q_EMIT importedModel(); } #include "moc_singlegearview.cpp" \ No newline at end of file