Skip to content

Commit 606efd3

Browse files
committed
Strip out Makie Support stuff
1 parent 79ed285 commit 606efd3

2 files changed

Lines changed: 46 additions & 286 deletions

File tree

src/QML.jl

Lines changed: 46 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -39,12 +39,12 @@ end
3939
const QStringList = QList{QString}
4040

4141
# Make sure functions accepting a QString argument also accept a Julia string
42-
CxxWrap.argument_overloads(::Type{<:QString}) = [QString,String]
42+
CxxWrap.argument_overloads(::Type{<:QString}) = [QString, String]
4343

4444
@wrapfunctions
4545

4646
# Protect items stored in a QML context from GC
47-
global __context_gc_protection = Dict{ConstCxxPtr{QQmlContext}, Vector{Any}}()
47+
global __context_gc_protection = Dict{ConstCxxPtr{QQmlContext},Vector{Any}}()
4848

4949
# Clear GC protection list when the context is destroyed
5050
function on_context_destroyed(ctx)
@@ -89,7 +89,7 @@ Load a QML file, creating a [`QML.QQmlApplicationEngine`](@ref), and setting the
8989
function loadqml(qmlfilename; kwargs...)
9090
qml_engine = init_qmlapplicationengine()
9191
ctx = root_context(CxxRef(qml_engine))
92-
for (key,value) in kwargs
92+
for (key, value) in kwargs
9393
set_context_property(ctx, String(key), value)
9494
end
9595
try
@@ -121,7 +121,7 @@ function watchqml(qview::CxxPtr{QQuickView}, qmlfile)
121121
QML.clearComponentCache(engine)
122122
set_source(qview, QUrlFromLocalFile(path))
123123
end
124-
124+
125125
watcher = QML.QFileSystemWatcher(engine)
126126
QML.addPath(watcher, qmlfile)
127127
QML.connect_file_changed_signal(watcher, clearcache)
@@ -172,10 +172,8 @@ end
172172
function __init__()
173173
@initcxx
174174

175-
@require GLMakie="e9467ef8-e4e7-5192-8a1a-b1aee30e663a" include(joinpath(@__DIR__, "makie_support.jl"))
176-
177175
loadqmljll(jlqml_jll.Qt6Declarative_jll)
178-
@require Qt65Compat_jll="f5784262-74e5-52be-b835-f3e8a3cf8710" @eval loadqmljll(Qt65Compat_jll)
176+
@require Qt65Compat_jll = "f5784262-74e5-52be-b835-f3e8a3cf8710" @eval loadqmljll(Qt65Compat_jll)
179177

180178
global ARGV = ArgcArgv([Base.julia_cmd()[1], ARGS...])
181179
global APPLICATION = QGuiApplication(ARGV.argc, getargv(ARGV))
@@ -185,17 +183,17 @@ end
185183
QString(s::String) = fromStdWString(StdWString(s))
186184
Base.ncodeunits(s::QString)::Int = cppsize(s)
187185
Base.codeunit(s::QString) = UInt16
188-
Base.codeunit(s::QString, i::Integer) = uint16char(s, i-1)
189-
Base.isvalid(s::QString, i::Integer) = isvalidindex(s, i-1)
186+
Base.codeunit(s::QString, i::Integer) = uint16char(s, i - 1)
187+
Base.isvalid(s::QString, i::Integer) = isvalidindex(s, i - 1)
190188
function Base.iterate(s::QString, i::Integer=1)
191-
if !isvalid(s,i)
189+
if !isvalid(s, i)
192190
return nothing
193191
end
194-
(charcode, nexti) = get_iterate(s,i-1)
192+
(charcode, nexti) = get_iterate(s, i - 1)
195193
if nexti == -1
196194
return nothing
197195
end
198-
return(Char(charcode),nexti+1)
196+
return (Char(charcode), nexti + 1)
199197
end
200198
Base.convert(::Type{<:QString}, s::String) = QString(s)
201199
QString(u::QUrl) = toString(u)
@@ -210,11 +208,11 @@ const QVariantList = QList{QVariant}
210208
const QVariantMap = QMap{QString,QVariant}
211209

212210
# Conversion to the strongly-typed QVariant interface
213-
@inline QVariant(x) = QVariant(Any,x)
211+
@inline QVariant(x) = QVariant(Any, x)
214212
@inline QVariant(x::T) where {T<:Union{Number,Ref,CxxWrap.SafeCFunction,QVariantMap,Nothing}} = QVariant(T, x)
215-
@inline QVariant(x::AbstractString) = QVariant(QString,QString(x))
216-
@inline QVariant(x::QString) = QVariant(QString,x)
217-
@inline QVariant(x::QObject) = QVariant(CxxPtr{QObject},CxxPtr(x))
213+
@inline QVariant(x::AbstractString) = QVariant(QString, QString(x))
214+
@inline QVariant(x::QString) = QVariant(QString, x)
215+
@inline QVariant(x::QObject) = QVariant(CxxPtr{QObject}, CxxPtr(x))
218216
@inline QVariant(x::QVariant) = x
219217

220218
QVariant(::Type{Bool}, b::Bool) = QVariant(CxxBool, CxxBool(b))
@@ -231,9 +229,9 @@ end
231229
@inline @cxxdereference setValue(v::QVariant, x::T) where {T} = setValue(T, v, x)
232230
QVariant(::Type{Nothing}, ::Nothing) = QVariant()
233231
@cxxdereference value(::Type{Nothing}, ::QML.QVariant) = nothing
234-
@cxxdereference value(v::QVariant) = CxxWrap.dereference_argument(value(type(v),v))
232+
@cxxdereference value(v::QVariant) = CxxWrap.dereference_argument(value(type(v), v))
235233
Base.convert(::Type{QVariant}, x::T) where {T} = QVariant(x)
236-
Base.convert(::Type{T}, x::QVariant) where {T} = convert(T,value(x))
234+
Base.convert(::Type{T}, x::QVariant) where {T} = convert(T, value(x))
237235
Base.convert(::Type{Any}, x::QVariant) = x
238236
Base.convert(::Type{<:QVariant}, x::QVariant) = x
239237

@@ -242,29 +240,29 @@ Base.convert(::Type{<:QVariant}, x::QVariant) = x
242240
# QList
243241
Base.IndexStyle(::Type{<:QList}) = IndexLinear()
244242
Base.size(v::QList) = (Int(cppsize(v)),)
245-
Base.getindex(v::QList, i::Int) = cppgetindex(v,i-1)[]
246-
Base.setindex!(v::QList{T}, val, i::Int) where {T} = cppsetindex!(v, convert(T,val), i-1)
243+
Base.getindex(v::QList, i::Int) = cppgetindex(v, i - 1)[]
244+
Base.setindex!(v::QList{T}, val, i::Int) where {T} = cppsetindex!(v, convert(T, val), i - 1)
247245
function Base.push!(v::QList{T}, x) where {T}
248-
push_back(v, convert(T,x))
246+
push_back(v, convert(T, x))
249247
return v
250248
end
251249
Base.empty!(l::QList) = clear(l)
252-
Base.deleteat!(l::QList, i::Integer) = removeAt(l, i-1)
250+
Base.deleteat!(l::QList, i::Integer) = removeAt(l, i - 1)
253251

254252
# QHash
255253
Base.isempty(h::QHash) = empty(h)
256254
Base.length(h::QHash) = Int(cppsize(h))
257255
Base.haskey(h::QHash, key) = QML.contains(h, key)
258256
function Base.getindex(h::QHash{K,V}, key) where {K,V}
259-
if !haskey(h,key)
257+
if !haskey(h, key)
260258
throw(KeyError(key))
261259
end
262-
return cppgetindex(h, convert(K,key))[]
260+
return cppgetindex(h, convert(K, key))[]
263261
end
264-
Base.setindex!(h::QHash{K,V}, val, key) where {K,V} = cppsetindex!(h, convert(V,val), convert(K,key))
262+
Base.setindex!(h::QHash{K,V}, val, key) where {K,V} = cppsetindex!(h, convert(V, val), convert(K, key))
265263
Base.empty!(h::QHash) = clear(h)
266-
Base.delete!(h::QHash{K,V}, key) where {K,V} = remove(h, convert(K,key))
267-
Base.:(==)(a::QHashIterator, b::QHashIterator) = iteratorisequal(a,b)
264+
Base.delete!(h::QHash{K,V}, key) where {K,V} = remove(h, convert(K, key))
265+
Base.:(==)(a::QHashIterator, b::QHashIterator) = iteratorisequal(a, b)
268266
function _qhash_iteration_tuple(h::QHash, state::QHashIterator)
269267
if state == iteratorend(h)
270268
return nothing
@@ -281,15 +279,15 @@ Base.isempty(h::QMap) = empty(h)
281279
Base.length(h::QMap) = Int(cppsize(h))
282280
Base.haskey(h::QMap, key) = QML.contains(h, key)
283281
function Base.getindex(h::QMap{K,V}, key) where {K,V}
284-
if !haskey(h,key)
282+
if !haskey(h, key)
285283
throw(KeyError(key))
286284
end
287-
return cppgetindex(h, convert(K,key))[]
285+
return cppgetindex(h, convert(K, key))[]
288286
end
289-
Base.setindex!(h::QMap{K,V}, val, key) where {K,V} = cppsetindex!(h, convert(V,val), convert(K,key))
287+
Base.setindex!(h::QMap{K,V}, val, key) where {K,V} = cppsetindex!(h, convert(V, val), convert(K, key))
290288
Base.empty!(h::QMap) = clear(h)
291-
Base.delete!(h::QMap{K,V}, key) where {K,V} = remove(h, convert(K,key))
292-
Base.:(==)(a::QMapIterator, b::QMapIterator) = iteratorisequal(a,b)
289+
Base.delete!(h::QMap{K,V}, key) where {K,V} = remove(h, convert(K, key))
290+
Base.:(==)(a::QMapIterator, b::QMapIterator) = iteratorisequal(a, b)
293291
function _qmap_iteration_tuple(h::QMap, state::QMapIterator)
294292
if state == iteratorend(h)
295293
return nothing
@@ -309,7 +307,7 @@ function julia_call(f, argptr::Ptr{Cvoid})
309307
end
310308

311309
function get_julia_call()
312-
return @cfunction(julia_call, Ptr{Cvoid}, (Any,Ptr{Cvoid}))
310+
return @cfunction(julia_call, Ptr{Cvoid}, (Any, Ptr{Cvoid}))
313311
end
314312

315313
# QQmlPropertyMap indexing interface
@@ -322,10 +320,10 @@ function on_value_changed end
322320

323321
mutable struct JuliaPropertyMap <: AbstractDict{String,Any}
324322
propertymap::_JuliaPropertyMap
325-
dict::Dict{String, Any}
323+
dict::Dict{String,Any}
326324

327325
function JuliaPropertyMap()
328-
result = new(_JuliaPropertyMap(), Dict{String, Any}())
326+
result = new(_JuliaPropertyMap(), Dict{String,Any}())
329327
set_julia_value(result.propertymap, result)
330328
connect_value_changed(result.propertymap, result, on_value_changed)
331329
finalizer(result) do jpm
@@ -379,7 +377,7 @@ julia> mktempdir() do folder
379377
"""
380378
function JuliaPropertyMap(pairs::Pair{<:AbstractString,<:Any}...)
381379
result = JuliaPropertyMap()
382-
for (k,v) in pairs
380+
for (k, v) in pairs
383381
result[k] = v
384382
end
385383
return result
@@ -404,7 +402,7 @@ function (updater::QmlPropertyUpdater)(x)
404402
updater.propertymap[updater.key] = x
405403
end
406404

407-
setactive!(::Any,::Bool) = nothing
405+
setactive!(::Any, ::Bool) = nothing
408406
setactive!(updater::QmlPropertyUpdater, active::Bool) = (updater.active = active)
409407

410408
Base.getindex(jpm::JuliaPropertyMap, k::AbstractString) = jpm.dict[k]
@@ -413,7 +411,7 @@ Base.get(jpm::JuliaPropertyMap, k::AbstractString, def) = get(jpm.dict, k, def)
413411
function Base.delete!(jpm::JuliaPropertyMap, k::AbstractString)
414412
storedvalue = jpm.dict[k]
415413
if storedvalue isa Observable
416-
for (_,observer) in filter(x -> x[2] isa QmlPropertyUpdater, Observables.listeners(storedvalue))
414+
for (_, observer) in filter(x -> x[2] isa QmlPropertyUpdater, Observables.listeners(storedvalue))
417415
if observer.propertymap == jpm.propertymap
418416
off(storedvalue, observer)
419417
end
@@ -600,16 +598,16 @@ function Base.display(d::JuliaDisplay, x)
600598
supported_types = (MIME"image/svg+xml"(), MIME"image/png"())
601599
write_methods = (load_svg, load_png)
602600
written = false
603-
for (t,write_method) in zip(supported_types, write_methods)
604-
if showable(t,x)
601+
for (t, write_method) in zip(supported_types, write_methods)
602+
if showable(t, x)
605603
Base.show(buf, t, x)
606604
write_method(d, take!(buf))
607605
written = true
608606
break
609607
end
610608
end
611609
if !written
612-
throw(MethodError(display, (d,x)))
610+
throw(MethodError(display, (d, x)))
613611
end
614612

615613
end
@@ -626,14 +624,14 @@ include("itemmodel.jl")
626624
global _async_timer
627625

628626
function exec_async()
629-
newrepl = @async Base.run_main_repl(true,true,true,true,true)
627+
newrepl = @async Base.run_main_repl(true, true, true, true, true)
630628
while !istaskdone(newrepl)
631-
for (updater, x) in _queued_properties
632-
updater.propertymap[updater.key] = x
633-
end
634-
empty!(_queued_properties)
635-
process_events()
636-
sleep(0.015)
629+
for (updater, x) in _queued_properties
630+
updater.propertymap[updater.key] = x
631+
end
632+
empty!(_queued_properties)
633+
process_events()
634+
sleep(0.015)
637635
end
638636
QML.quit(QML.get_qmlengine())
639637
QML.quit()

0 commit comments

Comments
 (0)