Skip to content

Span inspector #1296

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 20 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 25 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ members = [

"tests/basic_cxx_only/rust",
"tests/basic_cxx_qt/rust",
"tests/qt_types_standalone/rust",
"tests/qt_types_standalone/rust", "examples/span-inspector",
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Move this line up to the other examples.

]
resolver = "2"

Expand Down
29 changes: 29 additions & 0 deletions examples/span-inspector/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
# SPDX-FileCopyrightText: 2022 Klarälvdalens Datakonsult AB, a KDAB Group company <[email protected]>
# SPDX-FileContributor: Leon Matthes <[email protected]>
# SPDX-FileContributor: Quentin Weber <[email protected]>
#
# SPDX-License-Identifier: MIT OR Apache-2.0

[package]
name = "span-inspector"
edition.workspace = true
license.workspace = true
repository.workspace = true
version.workspace = true
rust-version.workspace = true

[dependencies]
cxx.workspace = true
cxx-qt.workspace = true
cxx-qt-lib = { workspace = true, features = ["full"] }
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please take a look at which features of cxx-qt-lib you really need, as compiling cxx-qt-lib fully can take a lot of time.

cxx-qt-macro = { workspace = true }
cxx-qt-gen = { workspace = true }
proc-macro2.workspace = true
prettyplease = { version = "0.2", features = ["verbatim"] }
syn.workspace=true

[build-dependencies]
cxx-qt-build = { workspace = true, features = [ "link_qt_object_files" ] }

[lints]
workspace = true
25 changes: 25 additions & 0 deletions examples/span-inspector/build.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
// SPDX-FileCopyrightText: 2025 Klarälvdalens Datakonsult AB, a KDAB Group company <[email protected]>
// SPDX-FileContributor: Leon Matthes <[email protected]>
//
// SPDX-License-Identifier: MIT OR Apache-2.0

use cxx_qt_build::{CxxQtBuilder, QmlModule};

fn main() {
let qml_module: QmlModule<'static, &str, &str> = QmlModule {
uri: "com.kdab.cxx_qt.demo",
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
uri: "com.kdab.cxx_qt.demo",
uri: "com.kdab.cxx_qt.span_inspector",

I copied this from our demos, but this could actually use a useful name (remember to update the according QML import).

rust_files: &["src/inspector.rs"],
qml_files: &["qml/main.qml"],
..Default::default()
};
CxxQtBuilder::new()
// Link Qt's Network library
// - Qt Core is always linked
// - Qt Gui is linked by enabling the qt_gui Cargo feature of cxx-qt-lib.
// - Qt Qml is linked by enabling the qt_qml Cargo feature of cxx-qt-lib.
// - Qt Qml requires linking Qt Network on macOS
.qt_module("Network")
.qt_module("Quick")
.qml_module(qml_module)
.build();
}
63 changes: 63 additions & 0 deletions examples/span-inspector/qml/main.qml
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
// SPDX-FileCopyrightText: 2025 Klarälvdalens Datakonsult AB, a KDAB Group company <[email protected]>
// SPDX-FileContributor: Leon Matthes <[email protected]>
//
// SPDX-License-Identifier: MIT OR Apache-2.0

import QtQuick
import QtQuick.Controls
import QtQuick.Window
import QtQuick.Layouts

import com.kdab.cxx_qt.demo 1.0

ApplicationWindow {
id: appWindow
color: palette.window
property color textColor: color.lightness < 128 * "black" , "white"
height: 480
title: qsTr("Span Inspector")
visible: true
width: 640

SpanInspector {
id: inspector
}

SplitView {
anchors.fill: parent
Item {
SplitView.preferredWidth: parent.width / 2
TextArea {
SplitView.preferredWidth: parent.width / 2
wrapMode: TextArea.Wrap
id: inputEdit
anchors.fill: parent
clip: true
color: appWindow.textColor
Component.onCompleted: {
inspector.input = textDocument
inspector.rebuildOutput(cursorPosition)
}

onCursorPositionChanged: {
inspector.rebuildOutput(cursorPosition)
}

onTextChanged: {
inspector.rebuildOutput(cursorPosition)
}
}
}

ScrollView {
SplitView.preferredWidth: parent.width / 2
TextEdit {
clip: true
color: appWindow.textColor
text: "Hello World"
readOnly: true;
Component.onCompleted: inspector.output = textDocument
}
}
}
}
Loading
Loading