-
Notifications
You must be signed in to change notification settings - Fork 77
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
WIP: extern "C++Qt" block support and widgets example
- Loading branch information
1 parent
0d74bbd
commit d33623c
Showing
20 changed files
with
695 additions
and
170 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
// SPDX-FileCopyrightText: 2023 Klarälvdalens Datakonsult AB, a KDAB Group company <[email protected]> | ||
// SPDX-FileContributor: Andrew Hayzen <[email protected]> | ||
// | ||
// SPDX-License-Identifier: MIT OR Apache-2.0 | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
// SPDX-FileCopyrightText: 2023 Klarälvdalens Datakonsult AB, a KDAB Group company <[email protected]> | ||
// SPDX-FileContributor: Andrew Hayzen <[email protected]> | ||
// | ||
// SPDX-License-Identifier: MIT OR Apache-2.0 | ||
|
||
use std::collections::BTreeMap; | ||
|
||
use crate::{ | ||
generator::{ | ||
naming::CombinedIdent, | ||
rust::{ | ||
fragment::RustFragmentPair, qobject::GeneratedRustQObject, | ||
signals::generate_rust_signal, | ||
}, | ||
}, | ||
parser::cxxqtdata::ParsedExternCxxBlocks, | ||
}; | ||
use quote::{format_ident, quote}; | ||
use syn::{Ident, Item, Path, Result}; | ||
|
||
#[derive(Default)] | ||
pub struct GeneratedExternCxxQt { | ||
/// Module for the CXX bridge | ||
pub cxx_mod_contents: Vec<Item>, | ||
/// Items for the CXX-Qt module | ||
pub cxx_qt_mod_contents: Vec<Item>, | ||
} | ||
|
||
impl From<GeneratedRustQObject> for GeneratedExternCxxQt { | ||
fn from(value: GeneratedRustQObject) -> Self { | ||
Self { | ||
cxx_mod_contents: value.cxx_mod_contents, | ||
cxx_qt_mod_contents: value.cxx_qt_mod_contents, | ||
} | ||
} | ||
} | ||
|
||
impl GeneratedExternCxxQt { | ||
pub fn append(&mut self, other: &mut Self) { | ||
self.cxx_mod_contents.append(&mut other.cxx_mod_contents); | ||
self.cxx_qt_mod_contents | ||
.append(&mut other.cxx_qt_mod_contents); | ||
} | ||
|
||
pub fn from( | ||
extern_cxx_block: &ParsedExternCxxBlocks, | ||
qualified_mappings: &BTreeMap<Ident, Path>, | ||
) -> Result<Self> { | ||
let mut generated = GeneratedExternCxxQt::default(); | ||
|
||
// Add the pass through blocks | ||
let attrs = &extern_cxx_block.attrs; | ||
let unsafety = &extern_cxx_block.unsafety; | ||
let items = &extern_cxx_block.passthrough_items; | ||
let fragment = RustFragmentPair { | ||
cxx_bridge: vec![quote! { | ||
#(#attrs)* | ||
#unsafety extern "C++" { | ||
#(#items)* | ||
} | ||
}], | ||
implementation: vec![], | ||
}; | ||
generated | ||
.cxx_mod_contents | ||
.append(&mut fragment.cxx_bridge_as_items()?); | ||
|
||
// Build the signals | ||
for signal in &extern_cxx_block.signals { | ||
let custom_connect_ident_rust = CombinedIdent { | ||
cpp: format_ident!("{}_{}", signal.qobject_ident, signal.ident.cpp), | ||
rust: format_ident!("{}_{}", signal.qobject_ident, signal.ident.rust), | ||
}; | ||
generated.append( | ||
&mut generate_rust_signal( | ||
signal, | ||
&signal.qobject_ident, | ||
qualified_mappings, | ||
Some(custom_connect_ident_rust), | ||
)? | ||
.into(), | ||
); | ||
} | ||
|
||
Ok(generated) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.