initial ability to update properties of video_model.rs

I've made it possible to update the properties of the videos. I'll
need to make sure title, start and end times, and paths all work as
well. Let's make videos really good and then move on to images and
presentations.
This commit is contained in:
Chris Cochrun 2023-04-17 11:22:07 -05:00
parent 2311af3b46
commit b037f1a91c
6 changed files with 138 additions and 31 deletions

View file

@ -361,3 +361,34 @@ void VideoProxyModel::deleteVideos(const QVector<int> &rows) {
model->removeItem(rows.at(i));
}
}
bool VideoProxyModel::updateLoop(int row, bool value) {
auto model = qobject_cast<VideoModel *>(sourceModel());
qDebug() << "THIS:" << row;
bool ret = model->updateLoop(row, value);
return ret;
}
bool VideoProxyModel::updateStartTime(int row, float value) {
auto model = qobject_cast<VideoModel *>(sourceModel());
bool ret = model->updateStartTime(row, value);
return ret;
}
bool VideoProxyModel::updateEndTime(int row, float value) {
auto model = qobject_cast<VideoModel *>(sourceModel());
bool ret = model->updateEndTime(row, value);
return ret;
}
bool VideoProxyModel::updateTitle(int row, QString value) {
auto model = qobject_cast<VideoModel *>(sourceModel());
bool ret = model->updateTitle(row, value);
return ret;
}
bool VideoProxyModel::updatePath(int row, QString value) {
auto model = qobject_cast<VideoModel *>(sourceModel());
bool ret = model->updatePath(row, value);
return ret;
}

View file

@ -82,6 +82,11 @@ public slots:
Q_INVOKABLE QVariantMap getVideo(const int &row);
Q_INVOKABLE void deleteVideo(const int &row);
Q_INVOKABLE void deleteVideos(const QVector<int> &row);
Q_INVOKABLE bool updateLoop(int row, bool value);
Q_INVOKABLE bool updateTitle(int row, QString value);
Q_INVOKABLE bool updatePath(int row, QString value);
Q_INVOKABLE bool updateStartTime(int row, float value);
Q_INVOKABLE bool updateEndTime(int row, float value);
private:
VideoModel *m_videoModel;

View file

@ -36,7 +36,7 @@ Item {
libraryType: "song"
headerLabel: "Songs"
itemIcon: "folder-music-symbolic"
itemSubtitle: "hi"
itemSubtitle: model.author
newItemFunction: (function() {
songProxyModel.setFilterRegularExpression("");
songProxyModel.songModel.newSong();
@ -63,12 +63,7 @@ Item {
libraryType: "video"
headerLabel: "Videos"
itemIcon: "folder-videos-symbolic"
itemSubtitle: {
if (fileValidation)
model.path;
else
"file is missing"
}
itemSubtitle: model.path
newItemFunction: (function() {
videoProxyModel.setFilterRegularExpression("");
})
@ -88,12 +83,7 @@ Item {
libraryType: "image"
headerLabel: "Images"
itemIcon: "folder-pictures-symbolic"
itemSubtitle: {
if (fileValidation)
model.path;
else
"file is missing"
}
itemSubtitle: model.path
newItemFunction: (function() {
imageProxyModel.setFilterRegularExpression("");
})
@ -113,12 +103,7 @@ Item {
libraryType: "presentation"
headerLabel: "Presentations"
itemIcon: "x-office-presentation-symbolic"
itemSubtitle: {
if (fileValidation)
model.filePath;
else
"file is missing"
}
itemSubtitle: model.path
newItemFunction: (function() {
presProxyModel.setFilterRegularExpression("");
})

View file

@ -70,7 +70,7 @@ ColumnLayout {
anchors {left: libraryLabel.right
verticalCenter: libraryLabel.verticalCenter
leftMargin: 15}
text: libraryType == "song" ? innerModel.rowCount() : innerModel.count()
text: libraryType == "song" ? innerModel.rowCount() : innerModel.count(innerModel)
color: Kirigami.Theme.disabledTextColor
}

View file

@ -245,28 +245,28 @@ Item {
function updateEndTime(value) {
/* changeStartTime(value, false); */
videosqlmodel.updateEndTime(video.id, value);
videoProxyModel.updateEndTime(video.id, value);
video.endTime = value;
showPassiveNotification(video.endTime);
}
function updateStartTime(value) {
/* changeStartTime(value, false); */
videosqlmodel.updateStartTime(video.id, value);
videoProxyModel.updateStartTime(video.id, value);
video.startTime = value;
showPassiveNotification(video.startTime);
}
function updateTitle(text) {
changeTitle(text, false);
videosqlmodel.updateTitle(video.id, text);
videoProxyModel.updateTitle(video.id, text);
showPassiveNotification(video.title);
}
function updateLoop(value) {
/* changeStartTime(value, false); */
videosqlmodel.updateLoop(video.id, value);
/* video.loop = value; */
let bool = videoProxyModel.updateLoop(video.id, value);
video.loop = value;
showPassiveNotification("Loop changed to: " + video.loop);
}

View file

@ -98,9 +98,9 @@ mod video_model {
id: video.id,
title: QString::from(&video.title),
path: QString::from(&video.path),
start_time: 0.0,
end_time: 0.0,
looping: false,
start_time: video.start_time.unwrap_or(0.0),
end_time: video.end_time.unwrap_or(0.0),
looping: video.looping,
};
self.as_mut().add_video(img);
@ -239,6 +239,7 @@ mod video_model {
self.as_ref().data(&idx, *i.0),
);
}
println!("gotted-video: {:?}", video);
};
qvariantmap
}
@ -260,6 +261,8 @@ mod video_model {
let mut vector_roles = QVector_i32::default();
vector_roles.append(self.as_ref().get_role(Role::LoopingRole));
let model_index = &self.as_ref().index(index, 0, &QModelIndex::default());
println!("rust-video: {:?}", index);
println!("rust-loop: {:?}", loop_value);
let db = &mut self.as_mut().get_db();
let result = update(videos.filter(id.eq(index)))
@ -267,10 +270,69 @@ mod video_model {
.execute(db);
match result {
Ok(_i) => {
let video = self.as_mut().videos_mut().get_mut(index as usize).unwrap();
video.looping = loop_value;
for video in self.as_mut().videos_mut().iter_mut() {
if video.id == index {
video.looping = loop_value.clone();
println!("rust-video: {:?}", video.title);
}
}
self.as_mut()
.emit_data_changed(model_index, model_index, &vector_roles);
println!("rust-looping: {:?}", loop_value);
true
}
Err(_e) => false,
}
}
#[qinvokable]
pub fn update_end_time(
mut self: Pin<&mut Self>,
index: i32,
updated_end_time: f32,
) -> bool {
let mut vector_roles = QVector_i32::default();
vector_roles.append(self.as_ref().get_role(Role::EndTimeRole));
let model_index = &self.as_ref().index(index, 0, &QModelIndex::default());
let db = &mut self.as_mut().get_db();
let result = update(videos.filter(id.eq(index)))
.set(end_time.eq(updated_end_time))
.execute(db);
match result {
Ok(_i) => {
let video = self.as_mut().videos_mut().get_mut(index as usize).unwrap();
video.end_time = updated_end_time.clone();
self.as_mut()
.emit_data_changed(model_index, model_index, &vector_roles);
println!("rust-end-time: {:?}", updated_end_time);
true
}
Err(_e) => false,
}
}
#[qinvokable]
pub fn update_start_time(
mut self: Pin<&mut Self>,
index: i32,
updated_start_time: f32,
) -> bool {
let mut vector_roles = QVector_i32::default();
vector_roles.append(self.as_ref().get_role(Role::StartTimeRole));
let model_index = &self.as_ref().index(index, 0, &QModelIndex::default());
let db = &mut self.as_mut().get_db();
let result = update(videos.filter(id.eq(index)))
.set(start_time.eq(updated_start_time))
.execute(db);
match result {
Ok(_i) => {
let video = self.as_mut().videos_mut().get_mut(index as usize).unwrap();
video.start_time = updated_start_time.clone();
self.as_mut()
.emit_data_changed(model_index, model_index, &vector_roles);
println!("rust-start-time: {:?}", updated_start_time);
true
}
Err(_e) => false,
@ -290,9 +352,33 @@ mod video_model {
match result {
Ok(_i) => {
let video = self.as_mut().videos_mut().get_mut(index as usize).unwrap();
video.title = updated_title;
video.title = updated_title.clone();
self.as_mut()
.emit_data_changed(model_index, model_index, &vector_roles);
println!("rust-title: {:?}", updated_title);
true
}
Err(_e) => false,
}
}
#[qinvokable]
pub fn update_path(mut self: Pin<&mut Self>, index: i32, updated_path: QString) -> bool {
let mut vector_roles = QVector_i32::default();
vector_roles.append(self.as_ref().get_role(Role::PathRole));
let model_index = &self.as_ref().index(index, 0, &QModelIndex::default());
let db = &mut self.as_mut().get_db();
let result = update(videos.filter(id.eq(index)))
.set(path.eq(updated_path.to_string()))
.execute(db);
match result {
Ok(_i) => {
let video = self.as_mut().videos_mut().get_mut(index as usize).unwrap();
video.path = updated_path.clone();
self.as_mut()
.emit_data_changed(model_index, model_index, &vector_roles);
println!("rust-path: {:?}", updated_path);
true
}
Err(_e) => false,