library is showing items and searching is working again

This commit is contained in:
Chris Cochrun 2024-09-13 14:01:06 -05:00
parent b61e05a423
commit f197099346
4 changed files with 106 additions and 43 deletions

View file

@ -34,8 +34,8 @@ Item {
Layout.alignment: Qt.AlignTop Layout.alignment: Qt.AlignTop
Layout.fillWidth: true Layout.fillWidth: true
Layout.preferredHeight: parent.height - 280 Layout.preferredHeight: parent.height - 280
proxyModel: songProxyModel proxyModel: songModel
innerModel: songProxyModel.songModel innerModel: songModel
libraryType: "song" libraryType: "song"
headerLabel: "Songs" headerLabel: "Songs"
itemIcon: "folder-music-symbolic" itemIcon: "folder-music-symbolic"
@ -53,7 +53,10 @@ Item {
songProxyModel.deleteSongs(rows) songProxyModel.deleteSongs(rows)
}) })
Component.onCompleted: selectedLibrary = "song"; Component.onCompleted: {
selectedLibrary = "song";
console.log("PRINTER SONGS: " + songModel.count);
}
} }
Presenter.LibraryItem { Presenter.LibraryItem {
@ -61,8 +64,8 @@ Item {
Layout.alignment: Qt.AlignTop Layout.alignment: Qt.AlignTop
Layout.fillWidth: true Layout.fillWidth: true
Layout.preferredHeight: parent.height - 280 Layout.preferredHeight: parent.height - 280
proxyModel: videoProxyModel proxyModel: videoModel
innerModel: videoProxyModel.videoModel innerModel: videoModel
libraryType: "video" libraryType: "video"
headerLabel: "Videos" headerLabel: "Videos"
itemIcon: "folder-videos-symbolic" itemIcon: "folder-videos-symbolic"
@ -87,8 +90,8 @@ Item {
Layout.alignment: Qt.AlignTop Layout.alignment: Qt.AlignTop
Layout.fillWidth: true Layout.fillWidth: true
Layout.preferredHeight: parent.height - 280 Layout.preferredHeight: parent.height - 280
proxyModel: imageProxyModel proxyModel: imageModel
innerModel: imageProxyModel.imageModel innerModel: imageModel
libraryType: "image" libraryType: "image"
headerLabel: "Images" headerLabel: "Images"
itemIcon: "folder-pictures-symbolic" itemIcon: "folder-pictures-symbolic"
@ -108,8 +111,8 @@ Item {
Layout.alignment: Qt.AlignTop Layout.alignment: Qt.AlignTop
Layout.fillWidth: true Layout.fillWidth: true
Layout.preferredHeight: parent.height - 280 Layout.preferredHeight: parent.height - 280
proxyModel: presProxyModel proxyModel: presentationModel
innerModel: presProxyModel.presentationModel innerModel: presentationModel
libraryType: "presentation" libraryType: "presentation"
headerLabel: "Presentations" headerLabel: "Presentations"
itemIcon: "x-office-presentation-symbolic" itemIcon: "x-office-presentation-symbolic"

View file

@ -155,7 +155,9 @@ ColumnLayout {
id: searchField id: searchField
height: parent.height height: parent.height
width: parent.width - 40 width: parent.width - 40
onAccepted: proxyModel.setFilterRegularExpression(searchField.text) onAccepted: {
innerModel.search(text);
}
background: Presenter.TextBackground { background: Presenter.TextBackground {
control: searchField control: searchField
} }
@ -177,11 +179,11 @@ ColumnLayout {
Layout.fillWidth: true Layout.fillWidth: true
Layout.alignment: Qt.AlignTop Layout.alignment: Qt.AlignTop
id: libraryList id: libraryList
model: proxyModel model: innerModel
clip: true clip: true
ItemSelectionModel { ItemSelectionModel {
id: selectionModel id: selectionModel
model: proxyModel model: innerModel
onSelectionChanged: { onSelectionChanged: {
/* showPassiveNotification("deslected: " + deselected); */ /* showPassiveNotification("deslected: " + deselected); */
/* showPassiveNotification("selected: " + selected); */ /* showPassiveNotification("selected: " + selected); */
@ -222,18 +224,30 @@ ColumnLayout {
Item { Item {
implicitWidth: ListView.view.width implicitWidth: ListView.view.width
height: selectedLibrary == libraryType ? 50 : 0 height: selectedLibrary == libraryType ? 50 : 0
property bool rightMenu: false
property bool selected: selectionModel.hasSelection && selectionModel.currentIndex == innerModel.index(index, 0)
property bool fileValidation: {
if (filePath)
fileHelper.validate(filePath)
else
false
}
Rectangle {
id: itemBackground
color: Kirigami.Theme.backgroundColor
anchors.fill: parent
Binding on color {
when: dragHandler.containsMouse || selected
value: Kirigami.Theme.highlightColor
}
}
Controls.ItemDelegate { Controls.ItemDelegate {
id: listItem id: listItem
property bool rightMenu: false
property bool selected: selectionModel.isSelected(proxyModel.idx(index))
property bool fileValidation: {
if (filePath)
fileHelper.validate(filePath)
else
false
}
implicitWidth: libraryList.width implicitWidth: libraryList.width
height: selectedLibrary == libraryType ? 50 : 0 height: selectedLibrary == libraryType ? 50 : 0
text: title text: title
@ -251,17 +265,6 @@ ColumnLayout {
icon.width: Kirigami.Units.gridUnit icon.width: Kirigami.Units.gridUnit
icon.height: Kirigami.Units.gridUnit icon.height: Kirigami.Units.gridUnit
/* supportsMouseEvents: false */ /* supportsMouseEvents: false */
/* background: Rectangle { */
/* color: Kirigami.Theme.backgroundColor */
/* fill: parent */
/* } */
/* Binding on backgroundColor { */
/* when: dragHandler.containsMouse || */
/* (selectionModel.hasSelection && */
/* selectionModel.isSelected(proxyModel.idx(index))) */
/* value: Kirigami.Theme.highlightColor */
/* } */
/* textColor: { */ /* textColor: { */
/* if (selectedLibrary == "song") */ /* if (selectedLibrary == "song") */
/* Kirigami.Theme.textColor; */ /* Kirigami.Theme.textColor; */
@ -348,7 +351,7 @@ ColumnLayout {
onClicked: { onClicked: {
if (mouse.button === Qt.RightButton) { if (mouse.button === Qt.RightButton) {
if(selectionModel.selectedIndexes.length <= 1) if(selectionModel.selectedIndexes.length <= 1)
selectionModel.select(proxyModel.idx(index), selectionModel.select(innerModel.index(index),
ItemSelectionModel.ClearAndSelect); ItemSelectionModel.ClearAndSelect);
rightClickMenu.popup() rightClickMenu.popup()
} }
@ -356,19 +359,19 @@ ColumnLayout {
(mouse.modifiers === Qt.ShiftModifier)) { (mouse.modifiers === Qt.ShiftModifier)) {
if (libraryList.currentIndex < index) { if (libraryList.currentIndex < index) {
for (let i = libraryList.currentIndex; i <= index; i++) { for (let i = libraryList.currentIndex; i <= index; i++) {
selectionModel.select(proxyModel.idx(i), selectionModel.select(innerModel.index(i),
ItemSelectionModel.Select); ItemSelectionModel.Select);
} }
} }
else { else {
for (let i = index; i <= libraryList.currentIndex; i++) { for (let i = index; i <= libraryList.currentIndex; i++) {
selectionModel.select(proxyModel.idx(i), selectionModel.select(innerModel.index(i),
ItemSelectionModel.Select); ItemSelectionModel.Select);
} }
} }
console.log(selectionModel.selectedIndexes); console.log(selectionModel.selectedIndexes);
} else { } else {
selectionModel.select(proxyModel.idx(index), selectionModel.select(innerModel.index(index),
ItemSelectionModel.ClearAndSelect); ItemSelectionModel.ClearAndSelect);
libraryList.currentIndex = index; libraryList.currentIndex = index;
} }
@ -420,13 +423,13 @@ ColumnLayout {
if (row > currentRow) { if (row > currentRow) {
for (var i = currentRow; i <= row; i++) { for (var i = currentRow; i <= row; i++) {
let idx = proxyModel.idx(i); let idx = innerModel.idx(i);
selectionModel.select(idx, ItemSelectionModel.Select); selectionModel.select(idx, ItemSelectionModel.Select);
} }
} }
else { else {
for (var i = row; i <= currentRow; i++) { for (var i = row; i <= currentRow; i++) {
let idx = proxyModel.idx(i); let idx = innerModel.idx(i);
selectionModel.select(idx, ItemSelectionModel.Select); selectionModel.select(idx, ItemSelectionModel.Select);
} }
} }

View file

@ -179,10 +179,22 @@ Controls.Page {
/* ImageProxyModel { id: imageProxyModel } */ /* ImageProxyModel { id: imageProxyModel } */
/* PresentationProxyModel { id: presProxyModel } */ /* PresentationProxyModel { id: presProxyModel } */
/* VideoProxyModel { id: videoProxyModel } */ /* VideoProxyModel { id: videoProxyModel } */
SongModel { id: songModel } SongModel {
VideoModel { id: videoModel } id: songModel
PresentationModel { id: presentationModel } Component.onCompleted: setup();
ImageModel { id: imageModel } }
VideoModel {
id: videoModel
Component.onCompleted: setup();
}
PresentationModel {
id: presentationModel
Component.onCompleted: setup();
}
ImageModel {
id: imageModel
Component.onCompleted: setup();
}
ServiceThing { id: serviceThing } ServiceThing { id: serviceThing }
FileHelper { id: fileHelper } FileHelper { id: fileHelper }
/* SlideHelper { id: slideHelper } */ /* SlideHelper { id: slideHelper } */

View file

@ -160,6 +160,8 @@ pub mod song_model {
index: i32, index: i32,
updated_audio: QString, updated_audio: QString,
) -> bool; ) -> bool;
#[qinvokable]
fn search(self: Pin<&mut SongModel>, search_term: QString);
} }
impl cxx_qt::Threading for SongModel {} impl cxx_qt::Threading for SongModel {}
@ -249,7 +251,8 @@ use diesel::sqlite::SqliteConnection;
use diesel::{delete, insert_into, prelude::*, update}; use diesel::{delete, insert_into, prelude::*, update};
use std::collections::HashMap; use std::collections::HashMap;
use std::pin::Pin; use std::pin::Pin;
use tracing::{debug, error}; use std::slice::Iter;
use tracing::{debug, debug_span, error, info, instrument};
use self::song_model::{ use self::song_model::{
QHash_i32_QByteArray, QMap_QString_QVariant, QVector_i32, QHash_i32_QByteArray, QMap_QString_QVariant, QVector_i32,
@ -290,6 +293,7 @@ pub struct SongModelRust {
count: i32, count: i32,
highest_id: i32, highest_id: i32,
songs: Vec<Song>, songs: Vec<Song>,
inner_songs: Vec<Song>,
} }
impl song_model::SongModel { impl song_model::SongModel {
@ -351,6 +355,7 @@ impl song_model::SongModel {
println!("--------------------------------------"); println!("--------------------------------------");
println!("{:?}", self.as_mut().songs); println!("{:?}", self.as_mut().songs);
println!("--------------------------------------"); println!("--------------------------------------");
self.as_mut().rust_mut().inner_songs = self.songs.clone();
} }
pub fn remove_item(mut self: Pin<&mut Self>, index: i32) -> bool { pub fn remove_item(mut self: Pin<&mut Self>, index: i32) -> bool {
@ -1053,6 +1058,25 @@ impl song_model::SongModel {
QStringList::from(&lyric_list) QStringList::from(&lyric_list)
} }
fn search(mut self: Pin<&mut Self>, search_term: QString) {
let search_term = search_term.to_string().to_lowercase();
debug!(search_term);
let searched_songs: Vec<Song> = self
.inner_songs
.iter()
.filter(|song| {
song.title.to_lowercase().contains(&search_term)
})
.cloned()
.collect();
debug!(search = ?&searched_songs);
unsafe {
self.as_mut().begin_reset_model();
self.as_mut().rust_mut().songs = searched_songs;
self.as_mut().end_reset_model();
}
}
fn get_role(&self, role: SongRoles) -> i32 { fn get_role(&self, role: SongRoles) -> i32 {
match role { match role {
SongRoles::Id => 0, SongRoles::Id => 0,
@ -1179,3 +1203,24 @@ impl song_model::SongModel {
cnt cnt
} }
} }
impl song_model::SongRoles {
fn iter() -> Iter<'static, SongRoles> {
static SONGROLES: [SongRoles; 13] = [
SongRoles::Id,
SongRoles::Title,
SongRoles::Lyrics,
SongRoles::Author,
SongRoles::Ccli,
SongRoles::Audio,
SongRoles::VerseOrder,
SongRoles::Background,
SongRoles::BackgroundType,
SongRoles::HorizontalTextAlignment,
SongRoles::VerticalTextAlignment,
SongRoles::Font,
SongRoles::FontSize,
];
SONGROLES.iter()
}
}