Skip to content

Commit

Permalink
qml_features: enable deny(missing_docs)
Browse files Browse the repository at this point in the history
This ensures we don't regress with any missing docs for
generated public items, related to #517
  • Loading branch information
ahayzen-kdab authored and Be-ing committed May 17, 2023
1 parent 2f999cc commit 90d621b
Show file tree
Hide file tree
Showing 15 changed files with 202 additions and 31 deletions.
8 changes: 7 additions & 1 deletion examples/cargo_without_cmake/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,14 @@
//
// SPDX-License-Identifier: MIT OR Apache-2.0

//! This example provides demostrations of building a Cargo only CXX-Qt application
// Use this crate to test that missing_docs works with our generated code for a Cargo only build
#![deny(missing_docs)]

/// A module for our Rust defined QObject
// ANCHOR: book_cargo_imports
mod cxxqt_object;
pub mod cxxqt_object;

use cxx_qt_lib::{QGuiApplication, QQmlApplicationEngine, QUrl};
// ANCHOR_END: book_cargo_imports
Expand Down
23 changes: 21 additions & 2 deletions examples/qml_features/rust/src/containers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,25 +3,38 @@
//
// SPDX-License-Identifier: MIT OR Apache-2.0

//! This example shows how container types can be used
/// A CXX-Qt bridge which shows container types can be used
#[cxx_qt::bridge(cxx_file_stem = "rust_containers")]
mod ffi {
pub mod ffi {
unsafe extern "C++" {
include!("cxx-qt-lib/qhash.h");
/// QHash<QString, QVariant> from cxx_qt_lib
type QHash_QString_QVariant = cxx_qt_lib::QHash<cxx_qt_lib::QHashPair_QString_QVariant>;
include!("cxx-qt-lib/qlist.h");
/// QList<i32> from cxx_qt_lib
type QList_i32 = cxx_qt_lib::QList<i32>;
include!("cxx-qt-lib/qmap.h");
/// QMap<QString, QVariant> from cxx_qt_lib
type QMap_QString_QVariant = cxx_qt_lib::QMap<cxx_qt_lib::QMapPair_QString_QVariant>;
include!("cxx-qt-lib/qset.h");
/// QSet<i32> from cxx_qt_lib
type QSet_i32 = cxx_qt_lib::QSet<i32>;
include!("cxx-qt-lib/qstring.h");
/// QString from cxx_qt_lib
type QString = cxx_qt_lib::QString;
include!("cxx-qt-lib/qvariant.h");
/// QVariant from cxx_qt_lib
type QVariant = cxx_qt_lib::QVariant;
include!("cxx-qt-lib/qvector.h");
/// QVector<i32> from cxx_qt_lib
type QVector_i32 = cxx_qt_lib::QVector<i32>;
}

/// A QObject which stores container types internally
///
/// Then it has Q_PROPERTYs which expose a string of the container to be show in QML
#[cxx_qt::qobject(qml_uri = "com.kdab.cxx_qt.demo", qml_version = "1.0")]
#[derive(Default)]
pub struct RustContainers {
Expand All @@ -44,6 +57,7 @@ mod ffi {
}

impl qobject::RustContainers {
/// Reset all the container types
#[qinvokable]
pub fn reset(mut self: Pin<&mut Self>) {
self.as_mut().set_hash(QHash_QString_QVariant::default());
Expand All @@ -55,42 +69,47 @@ mod ffi {
self.update_strings();
}

/// Append the given number to the vector container
#[qinvokable]
pub fn append_vector(mut self: Pin<&mut Self>, value: i32) {
self.as_mut().vector_mut().append(value);

self.update_strings();
}

/// Append the given number to the list container
#[qinvokable]
pub fn append_list(mut self: Pin<&mut Self>, value: i32) {
self.as_mut().list_mut().append(value);

self.update_strings();
}

/// Insert the given number into the set container
#[qinvokable]
pub fn insert_set(mut self: Pin<&mut Self>, value: i32) {
self.as_mut().set_mut().insert(value);

self.update_strings();
}

/// Insert the given string and variant to the hash container
#[qinvokable]
pub fn insert_hash(mut self: Pin<&mut Self>, key: QString, value: QVariant) {
self.as_mut().hash_mut().insert(key, value);

self.update_strings();
}

/// Insert the given string and variant to the map container
#[qinvokable]
pub fn insert_map(mut self: Pin<&mut Self>, key: QString, value: QVariant) {
self.as_mut().map_mut().insert(key, value);

self.update_strings();
}

pub fn update_strings(mut self: Pin<&mut Self>) {
fn update_strings(mut self: Pin<&mut Self>) {
let hash_items = self
.as_ref()
.hash()
Expand Down
25 changes: 24 additions & 1 deletion examples/qml_features/rust/src/custom_base_class.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,27 +3,35 @@
//
// SPDX-License-Identifier: MIT OR Apache-2.0

//! This example shows how a custom base class and inheritance can be used
/// A CXX-Qt bridge which shows a custom base class and inheritance can be used
// ANCHOR: book_macro_code
#[cxx_qt::bridge(cxx_file_stem = "custom_base_class")]
mod ffi {
pub mod ffi {
// ANCHOR: book_base_include
unsafe extern "C++" {
include!(< QAbstractListModel >);
// ANCHOR_END: book_base_include

include!("cxx-qt-lib/qhash.h");
/// QHash<i32, QByteArray> from cxx_qt_lib
type QHash_i32_QByteArray = cxx_qt_lib::QHash<cxx_qt_lib::QHashPair_i32_QByteArray>;

include!("cxx-qt-lib/qvariant.h");
/// QVariant from cxx_qt_lib
type QVariant = cxx_qt_lib::QVariant;

include!("cxx-qt-lib/qmodelindex.h");
/// QModelIndex from cxx_qt_lib
type QModelIndex = cxx_qt_lib::QModelIndex;

include!("cxx-qt-lib/qvector.h");
/// QVector<i32> from cxx_qt_lib
type QVector_i32 = cxx_qt_lib::QVector<i32>;
}

/// A struct which will derive from a QAbstractListModel
// ANCHOR: book_inherit_qalm
// ANCHOR: book_qobject_base
#[cxx_qt::qobject(
Expand All @@ -39,24 +47,31 @@ mod ffi {
}
// ANCHOR_END: book_inherit_qalm

/// The signals for our QAbstractListModel struct
// ANCHOR: book_qsignals_inherit
#[cxx_qt::qsignals(CustomBaseClass)]
pub enum Signals<'a> {
/// Inherit the DataChanged signal from the QAbstractListModel base class
#[inherit]
DataChanged {
/// Top left affected index
top_left: &'a QModelIndex,
/// Bottom right affected index
bottom_right: &'a QModelIndex,
/// Roles that have been modified
roles: &'a QVector_i32,
},
}
// ANCHOR_END: book_qsignals_inherit

impl qobject::CustomBaseClass {
/// Add a new row to the QAbstractListModel on the current thread
#[qinvokable]
pub fn add(self: Pin<&mut Self>) {
self.add_cpp_context();
}

/// On a background thread add a given number of rows to the QAbstractListModel
#[qinvokable]
pub fn add_on_thread(self: Pin<&mut Self>, mut counter: i32) {
let qt_thread = self.qt_thread();
Expand Down Expand Up @@ -92,6 +107,7 @@ mod ffi {
}
}

/// Clear the rows in the QAbstractListModel
// ANCHOR: book_inherit_clear
#[qinvokable]
pub fn clear(mut self: Pin<&mut Self>) {
Expand All @@ -104,6 +120,7 @@ mod ffi {
}
// ANCHOR_END: book_inherit_clear

/// Multiply the number in the row with the given index by the given factor
#[qinvokable]
pub fn multiply(mut self: Pin<&mut Self>, index: i32, factor: f64) {
if let Some((_, value)) = self.as_mut().vector_mut().get_mut(index as usize) {
Expand All @@ -121,6 +138,7 @@ mod ffi {
}
}

/// Remove the row with the given index
#[qinvokable]
pub fn remove(mut self: Pin<&mut Self>, index: i32) {
if index < 0 || (index as usize) >= self.vector().len() {
Expand Down Expand Up @@ -178,7 +196,9 @@ mod ffi {

// QAbstractListModel implementation
impl qobject::CustomBaseClass {
/// i32 representing the id role
pub const ID_ROLE: i32 = 0;
/// i32 representing the value role
pub const VALUE_ROLE: i32 = 1;

// ANCHOR: book_inherit_data
Expand All @@ -196,6 +216,7 @@ mod ffi {
}
// ANCHOR_END: book_inherit_data

/// Return whether the base class can fetch more
// ANCHOR: book_inherit_can_fetch_more
// Example of overriding a C++ virtual method and calling the base class implementation.
#[qinvokable(cxx_override)]
Expand All @@ -204,6 +225,7 @@ mod ffi {
}
// ANCHOR_END: book_inherit_can_fetch_more

/// Return the role names for the QAbstractListModel
#[qinvokable(cxx_override)]
pub fn role_names(&self) -> QHash_i32_QByteArray {
let mut roles = QHash_i32_QByteArray::default();
Expand All @@ -212,6 +234,7 @@ mod ffi {
roles
}

/// Return the row count for the QAbstractListModel
#[qinvokable(cxx_override)]
pub fn row_count(&self, _parent: &QModelIndex) -> i32 {
self.rust().vector.len() as i32
Expand Down
5 changes: 5 additions & 0 deletions examples/qml_features/rust/src/invokables.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,19 @@
//
// SPDX-License-Identifier: MIT OR Apache-2.0

//! This example shows how a Q_INVOKABLE can be used
/// A CXX-Qt bridge which shows how a Q_INVOKABLE can be used
// ANCHOR: book_macro_code
#[cxx_qt::bridge(cxx_file_stem = "rust_invokables")]
pub mod ffi {
unsafe extern "C++" {
include!("cxx-qt-lib/qcolor.h");
/// QColor from cxx_qt_lib
type QColor = cxx_qt_lib::QColor;
}

/// A QObject which has Q_INVOKABLEs
#[cxx_qt::qobject(qml_uri = "com.kdab.cxx_qt.demo", qml_version = "1.0")]
pub struct RustInvokables {
red: f32,
Expand Down
30 changes: 18 additions & 12 deletions examples/qml_features/rust/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,21 @@
//
// SPDX-License-Identifier: MIT OR Apache-2.0

mod containers;
mod custom_base_class;
mod invokables;
mod multiple_qobjects;
mod nested_qobjects;
mod properties;
mod serialisation;
mod signals;
mod singleton;
mod threading;
mod types;
mod uncreatable;
// Use this crate to test that missing_docs works with our generated code
#![deny(missing_docs)]

//! This example provides demostrations of most of the features of CXX-Qt
//! split into separate modules
pub mod containers;
pub mod custom_base_class;
pub mod invokables;
pub mod multiple_qobjects;
pub mod nested_qobjects;
pub mod properties;
pub mod serialisation;
pub mod signals;
pub mod singleton;
pub mod threading;
pub mod types;
pub mod uncreatable;
17 changes: 16 additions & 1 deletion examples/qml_features/rust/src/multiple_qobjects.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,21 @@
//
// SPDX-License-Identifier: MIT OR Apache-2.0

//! This example shows how multiple QObjects can be defined in one module
/// A CXX-Qt bridge which shows multiple QObjects can be defined in one module
#[cxx_qt::bridge(cxx_file_stem = "multiple_qobjects")]
mod ffi {
pub mod ffi {
unsafe extern "C++" {
include!("cxx-qt-lib/qcolor.h");
/// QColor from cxx_qt_lib
type QColor = cxx_qt_lib::QColor;
include!("cxx-qt-lib/qurl.h");
/// QUrl from cxx_qt_lib
type QUrl = cxx_qt_lib::QUrl;
}

/// The first QObject
#[cxx_qt::qobject(qml_uri = "com.kdab.cxx_qt.demo", qml_version = "1.0")]
pub struct FirstObject {
#[qproperty]
Expand All @@ -29,13 +35,17 @@ mod ffi {
}
}

/// Signals for the first QObject
#[cxx_qt::qsignals(FirstObject)]
pub enum FirstSignals {
/// Accepted Q_SIGNAL
Accepted,
/// Rejected Q_SIGNAL
Rejected,
}

impl qobject::FirstObject {
/// A Q_INVOKABLE on the first QObject which increments a counter
#[qinvokable]
pub fn increment(mut self: Pin<&mut Self>) {
let new_value = self.as_ref().counter() + 1;
Expand All @@ -51,6 +61,7 @@ mod ffi {
}
}

/// The second QObject
#[cxx_qt::qobject(qml_uri = "com.kdab.cxx_qt.demo", qml_version = "1.0")]
pub struct SecondObject {
#[qproperty]
Expand All @@ -68,13 +79,17 @@ mod ffi {
}
}

/// Signals for the second QObject
#[cxx_qt::qsignals(SecondObject)]
pub enum SecondSignals {
/// Accepted Q_SIGNAL
Accepted,
/// Rejected Q_SIGNAL
Rejected,
}

impl qobject::SecondObject {
/// A Q_INVOKABLE on the second QObject which increments a counter
#[qinvokable]
pub fn increment(mut self: Pin<&mut Self>) {
let new_value = self.as_ref().counter() + 1;
Expand Down
Loading

0 comments on commit 90d621b

Please sign in to comment.