Skip to content

Commit ad59983

Browse files
authored
Add functionality to watch QML files for changes (#22)
Issue JuliaGraphics/QML.jl#195
1 parent ad560c0 commit ad59983

2 files changed

Lines changed: 27 additions & 5 deletions

File tree

CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ project(JlQML)
22

33
cmake_minimum_required(VERSION 3.16.0)
44

5-
set(JlQML_VERSION 0.5.4)
5+
set(JlQML_VERSION 0.6.0)
66
message(STATUS "Project version: v${JlQML_VERSION}")
77

88
set(CMAKE_MACOSX_RPATH 1)

wrap_qml.cpp

Lines changed: 26 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
#include <QFileSystemWatcher>
12
#include <QGuiApplication>
23
#include <QLibraryInfo>
34
#include <QPainter>
@@ -40,6 +41,9 @@ template<> struct SuperType<QTimer> { using type = QObject; };
4041
template<> struct SuperType<qmlwrap::JuliaPaintedItem> { using type = QQuickItem; };
4142
template<> struct SuperType<QAbstractItemModel> { using type = QObject; };
4243
template<> struct SuperType<QAbstractTableModel> { using type = QAbstractItemModel; };
44+
template<> struct SuperType<QQuickItem> { using type = QObject; };
45+
template<> struct SuperType<QWindow> { using type = QObject; };
46+
template<> struct SuperType<QQuickWindow> { using type = QWindow; };
4347
template<> struct SuperType<qmlwrap::JuliaItemModel> { using type = QAbstractTableModel; };
4448

4549
}
@@ -321,7 +325,8 @@ JLCXX_MODULE define_julia_module(jlcxx::Module& qml_module)
321325
qml_module.set_const("Metal", QSGRendererInterface::Metal);
322326
qml_module.set_const("Null", QSGRendererInterface::Null);
323327

324-
qml_module.add_type<QObject>("QObject");
328+
qml_module.add_type<QObject>("QObject")
329+
.method("deleteLater", &QObject::deleteLater);
325330
qml_module.method("connect_destroyed_signal", [] (QObject& obj, jl_function_t* jl_f)
326331
{
327332
QObject::connect(&obj, &QObject::destroyed, [jl_f](QObject* o)
@@ -395,7 +400,7 @@ JLCXX_MODULE define_julia_module(jlcxx::Module& qml_module)
395400
qml_module.add_type<QByteArrayView>("QByteArrayView");
396401

397402
qml_module.add_type<Parametric<TypeVar<1>>>("QList", julia_type("AbstractVector"))
398-
.apply<QVariantList, QList<QString>, QList<QUrl>, QList<QByteArray>, QList<int>>(qmlwrap::WrapQList());
403+
.apply<QVariantList, QList<QString>, QList<QUrl>, QList<QByteArray>, QList<int>, QList<QObject*>>(qmlwrap::WrapQList());
399404

400405
// QMap (= QVariantMap for the given type)
401406
qml_module.add_type<Parametric<TypeVar<1>,TypeVar<2>>>("QMapIterator")
@@ -450,13 +455,16 @@ JLCXX_MODULE define_julia_module(jlcxx::Module& qml_module)
450455
.method("context_object", &QQmlContext::contextObject);
451456

452457
qml_module.add_type<QQmlEngine>("QQmlEngine", julia_base_type<QObject>())
458+
.method("clearComponentCache", &QQmlEngine::clearComponentCache)
459+
.method("clearSingletons", &QQmlEngine::clearSingletons)
453460
.method("root_context", &QQmlEngine::rootContext)
454461
.method("quit", &QQmlEngine::quit);
455462

456463
qqmlcontext_wrapper.method("engine", &QQmlContext::engine);
457464

458465
qml_module.add_type<QQmlApplicationEngine>("QQmlApplicationEngine", julia_base_type<QQmlEngine>())
459466
.constructor<QString>() // Construct with path to QML
467+
.method("rootObjects", &QQmlApplicationEngine::rootObjects)
460468
.method("load_into_engine", [] (QQmlApplicationEngine* e, const QString& qmlpath)
461469
{
462470
bool success = false;
@@ -472,9 +480,11 @@ JLCXX_MODULE define_julia_module(jlcxx::Module& qml_module)
472480

473481
qml_module.method("qt_prefix_path", []() { return QLibraryInfo::location(QLibraryInfo::PrefixPath); });
474482

475-
auto qquickitem_type = qml_module.add_type<QQuickItem>("QQuickItem");
483+
auto qquickitem_type = qml_module.add_type<QQuickItem>("QQuickItem", julia_base_type<QObject>());
476484

477-
qml_module.add_type<QQuickWindow>("QQuickWindow")
485+
qml_module.add_type<QWindow>("QWindow", julia_base_type<QObject>())
486+
.method("destroy", &QWindow::destroy);
487+
qml_module.add_type<QQuickWindow>("QQuickWindow", julia_base_type<QWindow>())
478488
.method("content_item", &QQuickWindow::contentItem);
479489

480490
qquickitem_type.method("window", &QQuickItem::window);
@@ -631,4 +641,16 @@ JLCXX_MODULE define_julia_module(jlcxx::Module& qml_module)
631641
var.setValue(val);
632642
return var;
633643
});
644+
645+
qml_module.add_type<QFileSystemWatcher>("QFileSystemWatcher")
646+
.constructor<QObject*>(jlcxx::finalize_policy::no)
647+
.method("addPath", &QFileSystemWatcher::addPath);
648+
qml_module.method("connect_file_changed_signal", [] (QFileSystemWatcher& watcher, jl_function_t* jl_f)
649+
{
650+
QObject::connect(&watcher, &QFileSystemWatcher::fileChanged, [jl_f](const QString& path)
651+
{
652+
static JuliaFunction f(jl_f);
653+
f(path);
654+
});
655+
});
634656
}

0 commit comments

Comments
 (0)