Skip to content

Commit

Permalink
Movie initialization of Makie support into separate JlCxx module
Browse files Browse the repository at this point in the history
  • Loading branch information
steffenhaug authored and barche committed Sep 8, 2024
1 parent bece833 commit db93458
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 11 deletions.
15 changes: 10 additions & 5 deletions makie_viewport.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

#include <QOpenGLContext>
#include <QQuickWindow>
#include <julia.h>

namespace qmlwrap
{
Expand Down Expand Up @@ -32,13 +33,17 @@ class MakieRenderFunction : public RenderFunction

jl_module_t* get_makie_support_module()
{
jl_value_t* mod = jl_get_global(MakieViewport::m_qml_mod, jl_symbol("MakieSupport"));
if(mod == nullptr || !jl_is_module(mod))
// MakieViewport::m_qml_mod is set when initializing the Julia module `QtMakie`,
// corresponding to `JLCXX_MODULE define_julia_module_makie` in `wrap_qml.cpp`.
jl_module_t* mod = MakieViewport::m_qml_mod;

// If `mod` is not initialized, you have not loaded the Julia module.
if(mod == nullptr)
{
throw std::runtime_error("Makie is not loaded, did you forget \"Using Makie\" in your Julia file?");
throw std::runtime_error("Makie Support not initialized. Have you loaded QtMakie?");
}
return (jl_module_t*)mod;

return mod;
}

/// Takes care of loading the MakieSupport Julia module
Expand Down
17 changes: 11 additions & 6 deletions wrap_qml.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -247,7 +247,7 @@ struct WrapQtIterator
using WrappedT = typename TypeWrapperT::type;
using KeyT = typename WrappedT::key_type;
using ValueT = typename WrappedT::value_type;

wrapped.method("iteratornext", [] (WrappedT it) -> WrappedT { ++(it.value); return it; });
wrapped.method("iteratorkey", [] (WrappedT it) -> KeyT { validate_iterator(it); return it.value.key();} );
wrapped.method("iteratorvalue", [] (WrappedT it) -> ValueT& { validate_iterator(it); return it.value.value(); } );
Expand Down Expand Up @@ -282,6 +282,12 @@ struct WrapQtAssociativeContainer

}

JLCXX_MODULE define_julia_module_makie(jlcxx::Module& qml_module)
{
using namespace jlcxx;
qmlwrap::MakieViewport::m_qml_mod = qml_module.julia_module();
}

JLCXX_MODULE define_julia_module(jlcxx::Module& qml_module)
{
using namespace jlcxx;
Expand All @@ -290,8 +296,7 @@ JLCXX_MODULE define_julia_module(jlcxx::Module& qml_module)
qmlwrap::JuliaFunction::m_qml_mod = qml_module.julia_module();
qmlwrap::ApplicationManager::m_qml_mod = qml_module.julia_module();
qmlwrap::JuliaItemModel::m_qml_mod = qml_module.julia_module();
qmlwrap::MakieViewport::m_qml_mod = qml_module.julia_module();


// Enums
qml_module.add_bits<Qt::Orientation>("Orientation", jlcxx::julia_type("CppEnum"));
qml_module.set_const("Horizontal", Qt::Horizontal);
Expand Down Expand Up @@ -390,7 +395,7 @@ JLCXX_MODULE define_julia_module(jlcxx::Module& qml_module)
.constructor<QString>()
.method("toString", [] (const QUrl& url) { return url.toString(); });
qml_module.method("QUrlFromLocalFile", QUrl::fromLocalFile);

auto qvar_type = qml_module.add_type<QVariant>("QVariant");
qvar_type.method("toString", &QVariant::toString);

Expand All @@ -413,7 +418,7 @@ JLCXX_MODULE define_julia_module(jlcxx::Module& qml_module)
.apply<qmlwrap::QHashIteratorWrapper<int, QByteArray>>(qmlwrap::WrapQtIterator());
qml_module.add_type<Parametric<TypeVar<1>,TypeVar<2>>>("QHash", julia_type("AbstractDict"))
.apply<QHash<int, QByteArray>>(qmlwrap::WrapQtAssociativeContainer<qmlwrap::QHashIteratorWrapper>());

qml_module.add_type<QQmlPropertyMap>("QQmlPropertyMap", julia_base_type<QObject>())
.constructor<QObject *>(jlcxx::finalize_policy::no)
.method("clear", &QQmlPropertyMap::clear)
Expand All @@ -439,7 +444,7 @@ JLCXX_MODULE define_julia_module(jlcxx::Module& qml_module)
jlcxx::stl::apply_stl<QVariant>(qml_module);

qml_module.method("make_qvariant_map", [] ()
{
{
QVariantMap m;
m[QString("test")] = QVariant::fromValue(5);
return QVariant::fromValue(m);
Expand Down

0 comments on commit db93458

Please sign in to comment.