diff --git a/src/cpp/main.cpp b/src/cpp/main.cpp index 73aa555..c38c145 100644 --- a/src/cpp/main.cpp +++ b/src/cpp/main.cpp @@ -10,7 +10,6 @@ #include #include "rootwrapper.hpp" -#include "shell.hpp" int main(int argc, char** argv) { const auto app = QGuiApplication(argc, argv); @@ -41,8 +40,6 @@ int main(int argc, char** argv) { return -1; } - CONFIG_PATH = configPath; - LayerShellQt::Shell::useLayerShell(); // Base window transparency appears to be additive. // Use a fully transparent window with a colored rect. diff --git a/src/cpp/shell.cpp b/src/cpp/shell.cpp index 120f3a5..f74e43c 100644 --- a/src/cpp/shell.cpp +++ b/src/cpp/shell.cpp @@ -1,22 +1,13 @@ #include "shell.hpp" -#include -#include #include #include -#include -#include #include #include #include -#include #include "rootwrapper.hpp" -QString CONFIG_PATH; // NOLINT - -QtShell::QtShell(): QObject(nullptr), path(CONFIG_PATH), dir(QFileInfo(this->path).dir()) {} - void QtShell::reload() { auto* rootobj = QQmlEngine::contextForObject(this)->engine()->parent(); auto* root = qobject_cast(rootobj); @@ -29,14 +20,8 @@ void QtShell::reload() { root->reloadGraph(); } -void QtShell::componentComplete() { - for (auto* component: this->mComponents) { - component->prepare(this->dir); - } -} - -QQmlListProperty QtShell::components() { - return QQmlListProperty( +QQmlListProperty QtShell::components() { + return QQmlListProperty( this, nullptr, &QtShell::appendComponent, @@ -48,56 +33,7 @@ QQmlListProperty QtShell::components() { ); } -void QtShell::appendComponent(QQmlListProperty* list, ShellComponent* component) { - auto* shell = qobject_cast(list->object); - - if (shell != nullptr) shell->mComponents.append(component); -} - -void ShellComponent::setSource(QString source) { - if (this->mComponent != nullptr) { - qWarning() << "cannot define ShellComponent.source while defining a component"; - return; - } - - this->mSource = std::move(source); -} - -void ShellComponent::setComponent(QQmlComponent* component) { - if (this->mSource != nullptr) { - qWarning() << "cannot define a component for ShellComponent while source is set"; - return; - } - - this->mComponent = component; -} - -void ShellComponent::prepare(const QDir& basePath) { - if (this->mComponent == nullptr) { - if (this->mSource == nullptr) { - qWarning() << "neither source or a component was set for ShellComponent on prepare"; - return; - } - - auto path = basePath.filePath(this->mSource); - qDebug() << "preparing ShellComponent from" << path; - - auto* context = QQmlEngine::contextForObject(this); - if (context == nullptr) { - qWarning() << "ShellComponent was created without an associated QQmlEngine, cannot prepare"; - return; - } - - auto* engine = context->engine(); - - this->mComponent = new QQmlComponent(engine, path, this); - - if (this->mComponent == nullptr) { - qWarning() << "could not load ShellComponent source" << path; - return; - } - } - - qDebug() << "Sending ready for ShellComponent"; - emit this->ready(); +void QtShell::appendComponent(QQmlListProperty* list, QObject* component) { + auto* shell = static_cast(list->object); // NOLINT + component->setParent(shell); } diff --git a/src/cpp/shell.hpp b/src/cpp/shell.hpp index 205ab9f..299a369 100644 --- a/src/cpp/shell.hpp +++ b/src/cpp/shell.hpp @@ -1,62 +1,26 @@ #pragma once -#include +#include #include #include -#include #include -#include #include -#include +#include -extern QString CONFIG_PATH; // NOLINT - -class ShellComponent; - -class QtShell: public QObject, public QQmlParserStatus { +class QtShell: public QObject { Q_OBJECT; - Q_INTERFACES(QQmlParserStatus); - Q_PROPERTY(QQmlListProperty components READ components FINAL); + Q_PROPERTY(QQmlListProperty components READ components FINAL); Q_CLASSINFO("DefaultProperty", "components"); QML_ELEMENT; public: - explicit QtShell(); + explicit QtShell(QObject* parent = nullptr): QObject(parent) {} - void classBegin() override {} - void componentComplete() override; - - QQmlListProperty components(); + QQmlListProperty components(); public slots: void reload(); private: - static void appendComponent(QQmlListProperty* list, ShellComponent* component); - - QList mComponents; - QString path; - QDir dir; -}; - -class ShellComponent: public QObject { - Q_OBJECT; - Q_PROPERTY(QString source WRITE setSource); - Q_PROPERTY(QQmlComponent* component MEMBER mComponent WRITE setComponent); - Q_CLASSINFO("DefaultProperty", "component"); - QML_ELEMENT; - -public: - explicit ShellComponent(QObject* parent = nullptr): QObject(parent) {} - - void setSource(QString source); - void setComponent(QQmlComponent* component); - void prepare(const QDir& basePath); - -signals: - void ready(); - -private: - QString mSource; - QQmlComponent* mComponent = nullptr; + static void appendComponent(QQmlListProperty* list, QObject* component); };