qtbridge_interfaces/lib.rs
1// Copyright (C) 2025 The Qt Company Ltd.
2// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only
3
4//! # Qt Interfaces (Internal Documentation)
5//!
6//! This crate provides proxies for various Qt (C++) interfaces using Cxx.
7//! Proxies serve as the bridge between Rust and C++ implementations of Qt
8//! interfaces, allowing Rust types to implement behavior expected by C++
9//! code and to access C++ functionality from Rust.
10//!
11//! ## The proxy
12//!
13//! Each Qt interface has a corresponding **proxy** in Rust. This proxy has
14//! to implement the [`QRustProxy`] trait and interacts mostly with the [`QObjectHolder`]
15//! trait, that is automatically implemented for all user types by qt_gen.
16//!
17//! The demands on proxies are baked into the [`QRustProxy`] trait. For example, there
18//! is the demand to provide a Qt static meta object, usually from the "base" this proxy
19//! is derived from. Further, the proxy has to provide a marker trait called `AdapterType`
20//! that is at a minimum used to store a reference to the user object as
21//! `Rc<RefCell<dyn AdapterType>>`. Otherwise the proxy is mostly free in its design.
22//!
23//! All proxies provided in this module follow a similar architecture. The proxy works
24//! together with a set of traits. The QObject proxy is very different since it is the
25//! proxy that is used if only QMetaObject functionality needs to be provided but no
26//! interface implementation.
27//!
28//! ## Traits
29//!
30//! 1. **User-implemented functionality**: Rust implementations of Qt virtual functions.
31//! 2. **Rust access to C++ functionality**: Rust wrappers around C++ methods of the interface.
32//! 3. **Internal type erasure and proxy plumbing**: Allows dynamic behavior when types
33//! are not fully known at compile time.
34//!
35//! These proxies rely on the following Rust traits to define functionality and structure,
36//! shown on the example of `QListModel`.
37//!
38//! ### 1. `QListModel`
39//! * **Responsibility**: Must be implemented by the user.
40//! * **Purpose**: Functions in this trait are called from C++ via the proxy, providing Rust
41//! implementations of Qt virtual functions. Some modifications can be done in the functions
42//! to shape the API and to erase Qt types (e.g. QVariant and QModelIndex).
43//! * **Associated Types**: Defines types (e.g., `Item`) that are part of the interface contract.
44//! * **Notes**: Users implement function as expected from the Qt API. Default implementation
45//! can exist for non-pure virtual functions.
46//!
47//! ### 2. `QListModelBase`
48//! * **Responsibility**: Default / blank implementation for all `QListModel`.
49//! * **Purpose**: Provides access to C++ functions from Rust and other convenience functions
50//! that should not be overridden. Serves as a bridge between user logic and C++ functionality.
51//! Functions that should not be overridden by the user are implemented here.
52//! * **Notes**: This trait forms the core Rust interface to call C++ functions for types implementing
53//! `QListModel`.
54//!
55//! ### 3. `QListModelAdapter` (Internal Only)
56//! * **Responsibility**: Default / blank implementation for all `QListModel`.
57//! * **Purpose**: Provides a type-erased interface for internal machinery. Traits with associated
58//! types (like `QListModel::Item`) cannot be used as `dyn` traits in Rust. `QListModelAdapter`
59//! erases unknown types while exposing the necessary interface internally.
60//! * **Notes**: Never meant for user implementation or usage. Facilitates dynamic behavior and
61//! internal bridging without exposing associated types to user code.
62
63pub mod qobject;
64
65pub mod qlist_model;
66pub use qlist_model::{QListModel, QListModelBase};
67
68pub mod qtable_model;
69pub use qtable_model::{QTableModel, QTableModelBase};
70
71pub mod object_access;
72pub use object_access::rust_object_access::RustObjAccess;
73
74mod generated;
75pub use generated::*;