fixing name clobbering in qobjects.

Apparently qobjects need unique names or else they will name clobber.
This commit is contained in:
Chris Cochrun 2024-06-26 09:12:11 -05:00
parent f9e2d2c6dd
commit da1c4f84b5
14 changed files with 57 additions and 60 deletions

View file

@ -59,9 +59,9 @@
#include "cxx-qt-gen/song_model.cxxqt.h" #include "cxx-qt-gen/song_model.cxxqt.h"
#include "cxx-qt-gen/video_model.cxxqt.h" #include "cxx-qt-gen/video_model.cxxqt.h"
#include "cxx-qt-gen/image_model.cxxqt.h" #include "cxx-qt-gen/image_model.cxxqt.h"
#include "cxx-qt-gen/utilities.cxxqt.h" #include "cxx-qt-gen/utils.cxxqt.h"
#include "cxx-qt-gen/song_editor.cxxqt.h" #include "cxx-qt-gen/song_editor.cxxqt.h"
#include "cxx-qt-gen/obs_model.cxxqt.h" #include "cxx-qt-gen/obs.cxxqt.h"
static QWindow *windowFromEngine(QQmlApplicationEngine *engine) static QWindow *windowFromEngine(QQmlApplicationEngine *engine)
{ {

View file

@ -1,7 +1,7 @@
// The purpose of this file is to provide validation // The purpose of this file is to provide validation
// of whether or not a file exists // of whether or not a file exists
#[cxx_qt::bridge] #[cxx_qt::bridge]
mod qobject { mod file_helper {
unsafe extern "C++" { unsafe extern "C++" {
include!("cxx-qt-lib/qstring.h"); include!("cxx-qt-lib/qstring.h");
type QString = cxx_qt_lib::QString; type QString = cxx_qt_lib::QString;
@ -56,7 +56,7 @@ impl Default for FileHelperRust {
} }
} }
impl qobject::FileHelper { impl file_helper::FileHelper {
pub fn load(self: Pin<&mut Self>, file: QUrl) -> Vec<String> { pub fn load(self: Pin<&mut Self>, file: QUrl) -> Vec<String> {
println!("{file}"); println!("{file}");
vec!["hi".to_string()] vec!["hi".to_string()]

View file

@ -1,5 +1,5 @@
#[cxx_qt::bridge] #[cxx_qt::bridge]
mod qobject { mod image_model {
unsafe extern "C++" { unsafe extern "C++" {
include!(< QAbstractListModel >); include!(< QAbstractListModel >);
include!("cxx-qt-lib/qhash.h"); include!("cxx-qt-lib/qhash.h");
@ -155,14 +155,14 @@ mod qobject {
} }
use crate::schema::images::dsl::*; use crate::schema::images::dsl::*;
use cxx_qt::{CxxQtType}; use cxx_qt::CxxQtType;
use cxx_qt_lib::{QModelIndex, QString, QUrl, QVariant}; use cxx_qt_lib::{QModelIndex, QString, QUrl, QVariant};
use diesel::sqlite::SqliteConnection; use diesel::sqlite::SqliteConnection;
use diesel::{delete, insert_into, prelude::*, update}; use diesel::{delete, insert_into, prelude::*, update};
use std::path::PathBuf; use std::path::PathBuf;
use std::pin::Pin; use std::pin::Pin;
use self::qobject::{ use self::image_model::{
ImageRoles, QHash_i32_QByteArray, QMap_QString_QVariant, ImageRoles, QHash_i32_QByteArray, QMap_QString_QVariant,
QVector_i32, QVector_i32,
}; };
@ -182,7 +182,7 @@ pub struct ImageModelRust {
images: Vec<Image>, images: Vec<Image>,
} }
impl qobject::ImageModel { impl image_model::ImageModel {
pub fn clear(mut self: Pin<&mut Self>) { pub fn clear(mut self: Pin<&mut Self>) {
unsafe { unsafe {
self.as_mut().begin_reset_model(); self.as_mut().begin_reset_model();
@ -450,7 +450,7 @@ impl qobject::ImageModel {
} }
// QAbstractListModel implementation // QAbstractListModel implementation
impl qobject::ImageModel { impl image_model::ImageModel {
fn data(&self, index: &QModelIndex, role: i32) -> QVariant { fn data(&self, index: &QModelIndex, role: i32) -> QVariant {
let role = ImageRoles { repr: role }; let role = ImageRoles { repr: role };
if let Some(image) = self.images.get(index.row() as usize) { if let Some(image) = self.images.get(index.row() as usize) {

View file

@ -8,7 +8,7 @@ use obws::Client;
use std::{error::Error, pin::Pin}; use std::{error::Error, pin::Pin};
use tracing::{debug, error}; use tracing::{debug, error};
use crate::obs::qobject::QList_QString; use crate::obs::obs::QList_QString;
#[derive(Default)] #[derive(Default)]
pub struct Obs { pub struct Obs {
@ -117,7 +117,7 @@ fn make_client() -> Client {
} }
#[cxx_qt::bridge] #[cxx_qt::bridge]
mod qobject { mod obs {
unsafe extern "C++" { unsafe extern "C++" {
include!("cxx-qt-lib/qstring.h"); include!("cxx-qt-lib/qstring.h");
type QString = cxx_qt_lib::QString; type QString = cxx_qt_lib::QString;
@ -154,7 +154,7 @@ pub struct ObsModelRust {
current_program_scene: QString, current_program_scene: QString,
} }
impl qobject::ObsModel { impl obs::ObsModel {
pub fn update_scenes(mut self: Pin<&mut Self>) -> QStringList { pub fn update_scenes(mut self: Pin<&mut Self>) -> QStringList {
debug!("updating scenes"); debug!("updating scenes");
let mut scenes_list = QList_QString::default(); let mut scenes_list = QList_QString::default();

View file

@ -1,5 +1,5 @@
#[cxx_qt::bridge] #[cxx_qt::bridge]
mod qobject { mod presentation_model {
unsafe extern "C++" { unsafe extern "C++" {
include!(< QAbstractListModel >); include!(< QAbstractListModel >);
include!("cxx-qt-lib/qhash.h"); include!("cxx-qt-lib/qhash.h");
@ -175,7 +175,7 @@ mod qobject {
} }
} }
use crate::presentation_model::qobject::QMap_QString_QVariant; use crate::presentation_model::presentation_model::QMap_QString_QVariant;
use crate::reveal_js; use crate::reveal_js;
use crate::schema::presentations::dsl::*; use crate::schema::presentations::dsl::*;
use cxx_qt::CxxQtType; use cxx_qt::CxxQtType;
@ -187,7 +187,9 @@ use std::path::PathBuf;
use std::pin::Pin; use std::pin::Pin;
use tracing::debug; use tracing::debug;
use self::qobject::{PresRoles, QHash_i32_QByteArray, QVector_i32}; use self::presentation_model::{
PresRoles, QHash_i32_QByteArray, QVector_i32,
};
#[derive(Default, Clone, Debug)] #[derive(Default, Clone, Debug)]
pub struct Presentation { pub struct Presentation {
@ -205,7 +207,7 @@ pub struct PresentationModelRust {
presentations: Vec<Presentation>, presentations: Vec<Presentation>,
} }
impl qobject::PresentationModel { impl presentation_model::PresentationModel {
pub fn clear(mut self: Pin<&mut Self>) { pub fn clear(mut self: Pin<&mut Self>) {
unsafe { unsafe {
self.as_mut().begin_reset_model(); self.as_mut().begin_reset_model();
@ -579,7 +581,7 @@ impl qobject::PresentationModel {
} }
// QAbstractListModel implementation // QAbstractListModel implementation
impl qobject::PresentationModel { impl presentation_model::PresentationModel {
fn data(&self, index: &QModelIndex, role: i32) -> QVariant { fn data(&self, index: &QModelIndex, role: i32) -> QVariant {
let role = PresRoles { repr: role }; let role = PresRoles { repr: role };
if let Some(presentation) = if let Some(presentation) =
@ -636,7 +638,6 @@ impl qobject::PresentationModel {
} }
pub fn row_count(&self, _parent: &QModelIndex) -> i32 { pub fn row_count(&self, _parent: &QModelIndex) -> i32 {
// println!("row count is {cnt}"); // println!("row count is {cnt}");
self.presentations.len() as i32 self.presentations.len() as i32
} }

View file

@ -1,5 +1,5 @@
#[cxx_qt::bridge] #[cxx_qt::bridge]
mod qobject { mod service_item_model {
unsafe extern "C++" { unsafe extern "C++" {
include!(< QAbstractListModel >); include!(< QAbstractListModel >);
include!("cxx-qt-lib/qhash.h"); include!("cxx-qt-lib/qhash.h");
@ -291,7 +291,7 @@ mod qobject {
} }
use crate::obs::Obs; use crate::obs::Obs;
use crate::service_item_model::qobject::QList_QString; use crate::service_item_model::service_item_model::QList_QString;
use cxx_qt::{CxxQtType, Threading}; use cxx_qt::{CxxQtType, Threading};
use cxx_qt_lib::{ use cxx_qt_lib::{
QByteArray, QModelIndex, QString, QStringList, QUrl, QVariant, QByteArray, QModelIndex, QString, QStringList, QUrl, QVariant,
@ -306,12 +306,12 @@ use std::{fs, println};
use tar::{Archive, Builder}; use tar::{Archive, Builder};
use tracing::{debug, error}; use tracing::{debug, error};
use zstd::{Decoder, Encoder}; use zstd::{Decoder, Encoder};
use self::qobject::{ use self::service_item_model::{
QHash_i32_QByteArray, QMap_QString_QVariant, QVector_i32, QHash_i32_QByteArray, QMap_QString_QVariant, QVector_i32,
ServiceRoles, ServiceRoles,
}; };
use super::service_item_model::qobject::ServiceItemModel; use super::service_item_model::service_item_model::ServiceItemModel;
#[derive(Clone, Debug)] #[derive(Clone, Debug)]
pub struct ServiceItem { pub struct ServiceItem {
@ -395,7 +395,7 @@ impl Default for ServiceItemModelRust {
} }
} }
impl qobject::ServiceItemModel { impl service_item_model::ServiceItemModel {
pub fn setup(self: Pin<&mut Self>) { pub fn setup(self: Pin<&mut Self>) {
todo!() todo!()
} }
@ -1380,7 +1380,7 @@ impl qobject::ServiceItemModel {
} }
// QAbstractListModel implementation // QAbstractListModel implementation
impl qobject::ServiceItemModel { impl service_item_model::ServiceItemModel {
fn data(&self, index: &QModelIndex, role: i32) -> QVariant { fn data(&self, index: &QModelIndex, role: i32) -> QVariant {
let role = ServiceRoles { repr: role }; let role = ServiceRoles { repr: role };
if let Some(service_item) = if let Some(service_item) =

View file

@ -1,5 +1,5 @@
#[cxx_qt::bridge] #[cxx_qt::bridge]
mod qobject { mod settings {
unsafe extern "C++" { unsafe extern "C++" {
include!("cxx-qt-lib/qstring.h"); include!("cxx-qt-lib/qstring.h");
type QString = cxx_qt_lib::QString; type QString = cxx_qt_lib::QString;
@ -30,7 +30,7 @@ use configparser::ini::Ini;
use cxx_qt::CxxQtType; use cxx_qt::CxxQtType;
use cxx_qt_lib::{QString, QUrl}; use cxx_qt_lib::{QString, QUrl};
use dirs; use dirs;
use std::{pin::Pin}; use std::pin::Pin;
// In order for settings to save to the ini file, // In order for settings to save to the ini file,
// I'll need to create my own setting functions I think. // I'll need to create my own setting functions I think.
@ -60,7 +60,7 @@ impl Default for SettingsRust {
} }
} }
impl qobject::Settings { impl settings::Settings {
pub fn setup(mut self: Pin<&mut Self>) { pub fn setup(mut self: Pin<&mut Self>) {
let home = dirs::config_dir(); let home = dirs::config_dir();
println!("{:?}", home); println!("{:?}", home);

View file

@ -1,5 +1,5 @@
#[cxx_qt::bridge] #[cxx_qt::bridge]
mod qobject { mod slide_model {
unsafe extern "C++" { unsafe extern "C++" {
include!(< QAbstractListModel >); include!(< QAbstractListModel >);
include!("cxx-qt-lib/qhash.h"); include!("cxx-qt-lib/qhash.h");
@ -213,7 +213,7 @@ mod qobject {
use crate::ffmpeg; use crate::ffmpeg;
use crate::obs::Obs; use crate::obs::Obs;
use crate::slide_model::qobject::QList_QString; use crate::slide_model::slide_model::QList_QString;
use cxx_qt::{CxxQtType, Threading}; use cxx_qt::{CxxQtType, Threading};
use cxx_qt_lib::{ use cxx_qt_lib::{
CaseSensitivity, QByteArray, QModelIndex, QString, QStringList, CaseSensitivity, QByteArray, QModelIndex, QString, QStringList,
@ -223,7 +223,7 @@ use std::thread;
use std::{path::PathBuf, pin::Pin}; use std::{path::PathBuf, pin::Pin};
use tracing::{debug, error}; use tracing::{debug, error};
use self::qobject::{ use self::slide_model::{
QHash_i32_QByteArray, QMap_QString_QVariant, QVector_i32, QHash_i32_QByteArray, QMap_QString_QVariant, QVector_i32,
SlideRoles, SlideRoles,
}; };
@ -308,7 +308,7 @@ impl Default for SlideModelRust {
} }
} }
impl qobject::SlideModel { impl slide_model::SlideModel {
pub fn add_video_thumbnail( pub fn add_video_thumbnail(
mut self: Pin<&mut Self>, mut self: Pin<&mut Self>,
index: i32, index: i32,
@ -1270,7 +1270,7 @@ impl qobject::SlideModel {
} }
// QAbstractListModel implementation // QAbstractListModel implementation
impl qobject::SlideModel { impl slide_model::SlideModel {
pub fn data(&self, index: &QModelIndex, role: i32) -> QVariant { pub fn data(&self, index: &QModelIndex, role: i32) -> QVariant {
let role = SlideRoles { repr: role }; let role = SlideRoles { repr: role };
if let Some(slide) = self.slides.get(index.row() as usize) { if let Some(slide) = self.slides.get(index.row() as usize) {

View file

@ -1,5 +1,5 @@
#[cxx_qt::bridge] #[cxx_qt::bridge]
mod qobject { mod slide_object {
unsafe extern "C++" { unsafe extern "C++" {
include!("cxx-qt-lib/qstring.h"); include!("cxx-qt-lib/qstring.h");
type QString = cxx_qt_lib::QString; type QString = cxx_qt_lib::QString;
@ -90,7 +90,7 @@ use cxx_qt::CxxQtType;
use cxx_qt_lib::{CaseSensitivity, QString, QVariant}; use cxx_qt_lib::{CaseSensitivity, QString, QVariant};
use tracing::debug; use tracing::debug;
use self::qobject::QMap_QString_QVariant; use self::slide_object::QMap_QString_QVariant;
#[derive(Clone, Debug)] #[derive(Clone, Debug)]
pub struct SlideObjectRust { pub struct SlideObjectRust {
@ -139,7 +139,7 @@ impl Default for SlideObjectRust {
} }
} }
impl qobject::SlideObject { impl slide_object::SlideObject {
pub fn change_slide( pub fn change_slide(
mut self: Pin<&mut Self>, mut self: Pin<&mut Self>,
item: QMap_QString_QVariant, item: QMap_QString_QVariant,
@ -149,7 +149,8 @@ impl qobject::SlideObject {
let icount_variant = item let icount_variant = item
.get(&QString::from("imageCount")) .get(&QString::from("imageCount"))
.unwrap_or(QVariant::from(&1)); .unwrap_or(QVariant::from(&1));
let _count = icount_variant.value::<i32>().unwrap_or_default(); let _count =
icount_variant.value::<i32>().unwrap_or_default();
let slindex = item let slindex = item
.get(&QString::from("slideIndex")) .get(&QString::from("slideIndex"))

View file

@ -1,5 +1,5 @@
#[cxx_qt::bridge] #[cxx_qt::bridge]
pub mod qobject { pub mod song_editor {
unsafe extern "C++" { unsafe extern "C++" {
include!("cxx-qt-lib/qmap.h"); include!("cxx-qt-lib/qmap.h");
type QMap_QString_QVariant = type QMap_QString_QVariant =
@ -49,7 +49,7 @@ pub mod qobject {
// use crate::songs::song_model::qobject::SongModel; // use crate::songs::song_model::qobject::SongModel;
use cxx_qt_lib::QString; use cxx_qt_lib::QString;
use std::{path::PathBuf, pin::Pin}; use std::{path::PathBuf, pin::Pin};
use tracing::{debug}; use tracing::debug;
#[derive(Clone, Debug)] #[derive(Clone, Debug)]
pub struct SongEditorRust { pub struct SongEditorRust {
@ -94,7 +94,7 @@ impl Default for SongEditorRust {
} }
} }
impl qobject::SongEditor { impl song_editor::SongEditor {
fn idk(self: Pin<&mut Self>) { fn idk(self: Pin<&mut Self>) {
// if let Some(model) = unsafe { self.song_model().as_mut() } { // if let Some(model) = unsafe { self.song_model().as_mut() } {
// let pinned_model = unsafe { Pin::new_unchecked(model) }; // let pinned_model = unsafe { Pin::new_unchecked(model) };

View file

@ -1,5 +1,5 @@
#[cxx_qt::bridge] #[cxx_qt::bridge]
pub mod qobject { pub mod song_model {
unsafe extern "C++" { unsafe extern "C++" {
include!(< QAbstractListModel >); include!(< QAbstractListModel >);
include!("cxx-qt-lib/qhash.h"); include!("cxx-qt-lib/qhash.h");
@ -240,7 +240,7 @@ pub mod qobject {
use crate::models::*; use crate::models::*;
use crate::schema::songs::dsl::*; use crate::schema::songs::dsl::*;
use crate::songs::song_editor::qobject::QList_QString; use crate::songs::song_editor::song_editor::QList_QString;
use cxx_qt::CxxQtType; use cxx_qt::CxxQtType;
use cxx_qt_lib::{ use cxx_qt_lib::{
QByteArray, QModelIndex, QString, QStringList, QVariant, QByteArray, QModelIndex, QString, QStringList, QVariant,
@ -251,7 +251,7 @@ use std::collections::HashMap;
use std::pin::Pin; use std::pin::Pin;
use tracing::{debug, error}; use tracing::{debug, error};
use self::qobject::{ use self::song_model::{
QHash_i32_QByteArray, QMap_QString_QVariant, QVector_i32, QHash_i32_QByteArray, QMap_QString_QVariant, QVector_i32,
SongRoles, SongRoles,
}; };
@ -292,7 +292,7 @@ pub struct SongModelRust {
songs: Vec<Song>, songs: Vec<Song>,
} }
impl qobject::SongModel { impl song_model::SongModel {
pub fn clear(mut self: Pin<&mut Self>) { pub fn clear(mut self: Pin<&mut Self>) {
unsafe { unsafe {
self.as_mut().begin_reset_model(); self.as_mut().begin_reset_model();
@ -1074,7 +1074,7 @@ impl qobject::SongModel {
} }
// QAbstractListModel implementation // QAbstractListModel implementation
impl qobject::SongModel { impl song_model::SongModel {
fn data(&self, index: &QModelIndex, role: i32) -> QVariant { fn data(&self, index: &QModelIndex, role: i32) -> QVariant {
let role = SongRoles { repr: role }; let role = SongRoles { repr: role };
if let Some(song) = self.songs.get(index.row() as usize) { if let Some(song) = self.songs.get(index.row() as usize) {

View file

@ -1,18 +1,14 @@
use std::pin::Pin; use std::pin::Pin;
use tokio::runtime::Runtime; use tokio::runtime::Runtime;
use tracing::{debug, info}; use tracing::{debug, info};
use tracing_subscriber::{ use tracing_subscriber::EnvFilter;
EnvFilter,
};
use self::qobject::{QString, QUrl}; use self::utils::{QString, QUrl};
mod db { mod db {
use diesel::{Connection, SqliteConnection}; use diesel::{Connection, SqliteConnection};
use dirs::data_local_dir; use dirs::data_local_dir;
pub enum Model { pub enum Model {
Songs, Songs,
@ -51,7 +47,7 @@ mod db {
} }
#[cxx_qt::bridge] #[cxx_qt::bridge]
mod qobject { mod utils {
unsafe extern "C++" { unsafe extern "C++" {
include!("cxx-qt-lib/qstring.h"); include!("cxx-qt-lib/qstring.h");
type QString = cxx_qt_lib::QString; type QString = cxx_qt_lib::QString;
@ -91,7 +87,7 @@ impl Default for UtilsRust {
} }
} }
impl qobject::Utils { impl utils::Utils {
pub fn setup(self: Pin<&mut Self>) { pub fn setup(self: Pin<&mut Self>) {
crate::utils::setup(); crate::utils::setup();
} }

View file

@ -1,5 +1,5 @@
#[cxx_qt::bridge] #[cxx_qt::bridge]
mod qobject { mod video_model {
unsafe extern "C++" { unsafe extern "C++" {
include!(< QAbstractListModel >); include!(< QAbstractListModel >);
include!("cxx-qt-lib/qhash.h"); include!("cxx-qt-lib/qhash.h");
@ -176,16 +176,15 @@ mod qobject {
} }
} }
use crate::schema::videos::dsl::*; use crate::schema::videos::dsl::*;
use cxx_qt::CxxQtType; use cxx_qt::CxxQtType;
use cxx_qt_lib::{QByteArray, QModelIndex, QString, QUrl, QVariant}; use cxx_qt_lib::{QByteArray, QModelIndex, QString, QUrl, QVariant};
use diesel::sqlite::SqliteConnection; use diesel::sqlite::SqliteConnection;
use diesel::{delete, insert_into, prelude::*, update}; use diesel::{delete, insert_into, prelude::*, update};
use std::path::{PathBuf}; use std::path::PathBuf;
use std::pin::Pin; use std::pin::Pin;
use self::qobject::{ use self::video_model::{
QHash_i32_QByteArray, QMap_QString_QVariant, QVector_i32, QHash_i32_QByteArray, QMap_QString_QVariant, QVector_i32,
VideoRoles, VideoRoles,
}; };
@ -207,7 +206,7 @@ pub struct VideoModelRust {
videos: Vec<self::Video>, videos: Vec<self::Video>,
} }
impl qobject::VideoModel { impl video_model::VideoModel {
pub fn clear(mut self: Pin<&mut Self>) { pub fn clear(mut self: Pin<&mut Self>) {
unsafe { unsafe {
self.as_mut().begin_reset_model(); self.as_mut().begin_reset_model();
@ -609,7 +608,7 @@ impl qobject::VideoModel {
} }
// QAbstractListModel implementation // QAbstractListModel implementation
impl qobject::VideoModel { impl video_model::VideoModel {
fn data(&self, index: &QModelIndex, role: i32) -> QVariant { fn data(&self, index: &QModelIndex, role: i32) -> QVariant {
let role = VideoRoles { repr: role }; let role = VideoRoles { repr: role };
if let Some(video) = self.videos.get(index.row() as usize) { if let Some(video) = self.videos.get(index.row() as usize) {

View file

@ -1,5 +1,5 @@
#[cxx_qt::bridge] #[cxx_qt::bridge]
mod qobject { mod ytdl {
unsafe extern "C++" { unsafe extern "C++" {
include!("cxx-qt-lib/qurl.h"); include!("cxx-qt-lib/qurl.h");
type QUrl = cxx_qt_lib::QUrl; type QUrl = cxx_qt_lib::QUrl;
@ -40,7 +40,7 @@ pub struct YtdlRust {
file: QUrl, file: QUrl,
} }
impl qobject::Ytdl { impl ytdl::Ytdl {
pub fn get_video(mut self: Pin<&mut Self>, url: QUrl) -> bool { pub fn get_video(mut self: Pin<&mut Self>, url: QUrl) -> bool {
if !url.is_valid() { if !url.is_valid() {
false false