Skip to content
Switch branches/tags
Go to file
Cannot retrieve contributors at this time
use qmetaobject::scenegraph::SGNode;
use qmetaobject::{qrc, QQuickItem};
use qttypes::{QColor, QRectF};
use cpp::cpp;
qrc! {
pub init_resources,
"scenegraph/graph" {
"src" as "qml" {
// Ideally, everything should be possible to do in plain rust.
// However, there is quite some API to expose.
cpp! {{
#include <QtQuick/QQuickItem>
#include "src/gridnode.cpp"
#include "src/linenode.cpp"
#include "src/noisynode.cpp"
pub enum NoisyNode {}
pub fn create_noisy_node(s: &mut SGNode<NoisyNode>, ctx: &dyn QQuickItem) {
let item_ptr = ctx.get_cpp_object();
cpp!(unsafe [s as "NoisyNode**", item_ptr as "QQuickItem*"] {
if (!*s && item_ptr) {
*s = new NoisyNode(item_ptr->window());
pub fn noisy_node_set_rect(s: &mut SGNode<NoisyNode>, rect: QRectF) {
cpp!(unsafe [s as "NoisyNode**", rect as "QRectF"] {
if (*s) {
pub enum GridNode {}
pub fn update_grid_node(s: &mut SGNode<GridNode>, rect: QRectF) {
cpp!(unsafe [s as "GridNode**", rect as "QRectF"] {
if (!*s) *s = new GridNode;
pub enum LineNode {}
pub fn create_line_node(s: &mut SGNode<LineNode>, size: f32, spread: f32, color: QColor) {
cpp!(unsafe [s as "LineNode**", size as "float", spread as "float", color as "QColor"] {
if (!*s) *s = new LineNode(size, spread, color);
pub fn update_line_node(s: &mut SGNode<LineNode>, rect: QRectF, samples: &[f64]) {
let samples_ptr = samples.as_ptr();
let samples_len = samples.len();
cpp!(unsafe [s as "LineNode**", rect as "QRectF", samples_ptr as "double*",
samples_len as "std::size_t"] {
if (!*s) return;
QList<qreal> samples;
std::copy(samples_ptr, samples_ptr + samples_len, std::back_inserter(samples));
(*s)->updateGeometry(rect, samples);