From c70bba16e4af064516180330145ee6a3583b05ab Mon Sep 17 00:00:00 2001 From: Shaun Reed Date: Sun, 1 Feb 2026 13:07:10 -0500 Subject: [PATCH] Revert "Try to use QSortFilterProxyModel via cxx-qt." This reverts commit 325cf285fc70783a74a5dc6547de4c42feaab0d4. --- qml/ClideTreeView.qml | 11 ++-- src/gui/filesystem.rs | 134 ++++++------------------------------------ 2 files changed, 21 insertions(+), 124 deletions(-) diff --git a/qml/ClideTreeView.qml b/qml/ClideTreeView.qml index 47480c7..49ca563 100644 --- a/qml/ClideTreeView.qml +++ b/qml/ClideTreeView.qml @@ -16,23 +16,20 @@ Rectangle { signal fileClicked(string filePath) - // https://doc.qt.io/qt-6/qml-qtquick-treeview.html TreeView { id: fileSystemTreeView anchors.margins: 15 property int lastIndex: -1 - model: FileSystemSortProxyModel { - id: fs - } + model: FileSystem anchors.fill: parent boundsBehavior: Flickable.StopAtBounds boundsMovement: Flickable.StopAtBounds clip: true Component.onCompleted: { - fs.setDirectory(root.rootDirectory) + FileSystem.setDirectory(root.rootDirectory) fileSystemTreeView.expandRecursively(0, -1) } @@ -125,13 +122,13 @@ Rectangle { text: qsTr("Set as root index") onTriggered: { console.log("Setting directory: " + treeDelegate.filePath) - FileSystemSortProxyModel.setDirectory(treeDelegate.filePath) + FileSystem.setDirectory(treeDelegate.filePath) } } Action { text: qsTr("Reset root index") onTriggered: { - FileSystemSortProxyModel.setDirectory("") + FileSystem.setDirectory("") } } } diff --git a/src/gui/filesystem.rs b/src/gui/filesystem.rs index 92cbb02..ffac3bf 100644 --- a/src/gui/filesystem.rs +++ b/src/gui/filesystem.rs @@ -1,48 +1,21 @@ // SPDX-FileCopyrightText: 2026, Shaun Reed // // SPDX-License-Identifier: GNU General Public License v3.0 or later -use crate::gui::filesystem::qobject::{QAbstractItemModel}; -use cxx_qt_lib::{QModelIndex, QString}; -use dirs; -use log::warn; -use std::io::BufRead; -use std::{fs}; -use std::pin::Pin; -use syntect::easy::HighlightFile; -use syntect::highlighting::ThemeSet; -use syntect::html::{ - IncludeBackground, append_highlighted_html_for_styled_line, start_highlighted_html_snippet, -}; -use syntect::parsing::SyntaxSet; #[cxx_qt::bridge] pub mod qobject { - // Import Qt Types from C++ unsafe extern "C++" { + // Import Qt Types from C++ include!("cxx-qt-lib/qstring.h"); type QString = cxx_qt_lib::QString; - include!("cxx-qt-lib/qmodelindex.h"); type QModelIndex = cxx_qt_lib::QModelIndex; - include!(); type QFileSystemModel; - - include!(); - type QSortFilterProxyModel; - - include!(); - type QAbstractItemModel; } - // Export QML classes from Rust unsafe extern "RustQt" { - #[qobject] - #[qml_element] - #[base = QSortFilterProxyModel] - #[qproperty(*mut FileSystem, inner)] - type FileSystemSortProxyModel = super::FileSystemSortProxyModelImpl; - + // Export QML Types from Rust #[qobject] #[base = QFileSystemModel] #[qml_element] @@ -50,37 +23,7 @@ pub mod qobject { #[qproperty(QString, file_path, cxx_name = "filePath")] #[qproperty(QModelIndex, root_index, cxx_name = "rootIndex")] type FileSystem = super::FileSystemImpl; - } - // Export QSortFilterProxyModel functions from Rust - // https://doc.qt.io/qt-6/qsortfilterproxymodel.html - unsafe extern "RustQt" { - #[inherit] - #[cxx_name = "setSourceModel"] - unsafe fn set_source_model( - self: Pin<&mut FileSystemSortProxyModel>, - source: *mut QAbstractItemModel, - ); - - #[cxx_override] - #[cxx_name = "filterAcceptsRow"] - const fn filter_accepts_row( - self: &FileSystemSortProxyModel, - source_row: i32, - source_parent: &QModelIndex, - ) -> bool; - - #[qinvokable] - #[cxx_name = "setDirectory"] - fn set_directory(self: Pin<&mut FileSystemSortProxyModel>, path: &QString) -> QModelIndex; - } - - // Custom initialization logic. - impl cxx_qt::Initialize for FileSystemSortProxyModel {} - - // Export QFileSystemModel functions from Rust - // https://doc.qt.io/qt-6/qfilesystemmodel.html - unsafe extern "RustQt" { #[inherit] #[cxx_name = "setRootPath"] fn set_root_path(self: Pin<&mut FileSystem>, path: &QString) -> QModelIndex; @@ -93,67 +36,24 @@ pub mod qobject { #[qinvokable] #[cxx_name = "readFile"] fn read_file(self: &FileSystem, path: &QString) -> QString; - // - // #[qinvokable] - // #[cxx_name = "setDirectory"] - // fn set_directory(self: Pin<&mut FileSystem>, path: &QString) -> QModelIndex; + + #[qinvokable] + #[cxx_name = "setDirectory"] + fn set_directory(self: Pin<&mut FileSystem>, path: &QString) -> QModelIndex; } } -pub struct FileSystemSortProxyModelImpl { - inner: *mut qobject::FileSystem, -} - -impl Default for FileSystemSortProxyModelImpl { - fn default() -> Self { - let model = Self { - inner: std::ptr::null_mut(), - }; - model - } -} - -impl qobject::FileSystemSortProxyModel { - pub const fn filter_accepts_row(&self, _source_row: i32, _source_parent: &QModelIndex) -> bool { - false - } - - fn read_file(&self, path: &QString) -> QString { - if let Some(inner) = unsafe { self.inner().as_ref() } { - let pinned_inner = unsafe { Pin::new_unchecked(inner) }; - return pinned_inner.read_file(path) - } else { - panic!("Can't get inner()") - } - QString::default() - } - - // There will never be more than one column. - fn column_count(&self, _index: &QModelIndex) -> i32 { - 1 - } - - fn set_directory(self: Pin<&mut Self>, path: &QString) -> QModelIndex { - if let Some(inner) = unsafe { self.inner().as_mut() } { - let pinned_inner = unsafe { Pin::new_unchecked(inner) }; - return pinned_inner.set_directory(path) - } else { - panic!("Can't get inner()") - } - QModelIndex::default() - } -} - -impl cxx_qt::Initialize for qobject::FileSystemSortProxyModel { - fn initialize(self: core::pin::Pin<&mut Self>) { - let mut fs = FileSystemImpl::default(); - unsafe { - let model: *mut FileSystemImpl = std::ptr::from_mut(&mut fs); - let m: *mut QAbstractItemModel = model as *mut QAbstractItemModel; - self.set_source_model(m); - } - } -} +use cxx_qt_lib::{QModelIndex, QString}; +use dirs; +use log::warn; +use std::fs; +use std::io::BufRead; +use syntect::easy::HighlightFile; +use syntect::highlighting::ThemeSet; +use syntect::html::{ + IncludeBackground, append_highlighted_html_for_styled_line, start_highlighted_html_snippet, +}; +use syntect::parsing::SyntaxSet; // TODO: Impleent a provider for QFileSystemModel::setIconProvider for icons. pub struct FileSystemImpl {