mirror of
https://github.com/slint-ui/slint.git
synced 2025-11-19 19:45:06 +00:00
implement update and delete for crud example
This commit is contained in:
parent
2417869aa4
commit
858c327a8f
2 changed files with 47 additions and 8 deletions
|
|
@ -7,9 +7,12 @@ MainWindow := Window {
|
||||||
|
|
||||||
GridBox {
|
GridBox {
|
||||||
Text { text: "Filter prefix:"; }
|
Text { text: "Filter prefix:"; }
|
||||||
LineEdit {}
|
LineEdit {
|
||||||
|
text <=> root.prefix;
|
||||||
|
edited => { root.prefexEdited() }
|
||||||
|
}
|
||||||
|
|
||||||
StandardListView {
|
list := StandardListView {
|
||||||
row: 1;
|
row: 1;
|
||||||
rowspan: 3;
|
rowspan: 3;
|
||||||
colspan: 2;
|
colspan: 2;
|
||||||
|
|
@ -30,19 +33,26 @@ MainWindow := Window {
|
||||||
}
|
}
|
||||||
Button {
|
Button {
|
||||||
text: "Update";
|
text: "Update";
|
||||||
|
enabled: list.current-item != -1;
|
||||||
clicked => { root.updateClicked() }
|
clicked => { root.updateClicked() }
|
||||||
}
|
}
|
||||||
Button {
|
Button {
|
||||||
text: "Delete";
|
text: "Delete";
|
||||||
|
enabled: list.current-item != -1;
|
||||||
clicked => { root.deleteClicked() }
|
clicked => { root.deleteClicked() }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
property <[StandardListViewItem]> names-list;
|
property <[StandardListViewItem]> names-list;
|
||||||
|
property <int> current-item: list.current-item;
|
||||||
|
|
||||||
property <string> name;
|
property <string> name;
|
||||||
property <string> surname;
|
property <string> surname;
|
||||||
|
|
||||||
|
property <string> prefix;
|
||||||
|
|
||||||
|
callback prefexEdited();
|
||||||
callback createClicked();
|
callback createClicked();
|
||||||
callback updateClicked();
|
callback updateClicked();
|
||||||
callback deleteClicked();
|
callback deleteClicked();
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,6 @@
|
||||||
// Copyright © SixtyFPS GmbH <info@slint-ui.com>
|
// Copyright © SixtyFPS GmbH <info@slint-ui.com>
|
||||||
// SPDX-License-Identifier: GPL-3.0-only OR LicenseRef-Slint-commercial
|
// SPDX-License-Identifier: GPL-3.0-only OR LicenseRef-Slint-commercial
|
||||||
|
use slint::Model;
|
||||||
use std::rc::Rc;
|
use std::rc::Rc;
|
||||||
|
|
||||||
slint::slint!(import { MainWindow } from "crud.slint";);
|
slint::slint!(import { MainWindow } from "crud.slint";);
|
||||||
|
|
@ -14,11 +15,39 @@ pub fn main() {
|
||||||
]));
|
]));
|
||||||
main_window.set_names_list(model.clone().into());
|
main_window.set_names_list(model.clone().into());
|
||||||
|
|
||||||
let main_window_weak = main_window.as_weak();
|
{
|
||||||
main_window.on_createClicked(move || {
|
let main_window_weak = main_window.as_weak();
|
||||||
let main_window = main_window_weak.unwrap();
|
let model = model.clone();
|
||||||
let new_entry = main_window.get_surname() + ", " + main_window.get_name().as_str();
|
main_window.on_createClicked(move || {
|
||||||
model.push(new_entry.into());
|
let main_window = main_window_weak.unwrap();
|
||||||
});
|
let new_entry = main_window.get_surname() + ", " + main_window.get_name().as_str();
|
||||||
|
|
||||||
|
model.push(new_entry.into());
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
{
|
||||||
|
let main_window_weak = main_window.as_weak();
|
||||||
|
let model = model.clone();
|
||||||
|
main_window.on_updateClicked(move || {
|
||||||
|
let main_window = main_window_weak.unwrap();
|
||||||
|
let index = main_window.get_current_item() as usize;
|
||||||
|
let entry = main_window.get_surname() + ", " + main_window.get_name().as_str();
|
||||||
|
|
||||||
|
model.set_row_data(index, entry.into());
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
{
|
||||||
|
let main_window_weak = main_window.as_weak();
|
||||||
|
let model = model.clone();
|
||||||
|
main_window.on_deleteClicked(move || {
|
||||||
|
let main_window = main_window_weak.unwrap();
|
||||||
|
let index = main_window.get_current_item() as usize;
|
||||||
|
|
||||||
|
model.remove(index);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
main_window.run();
|
main_window.run();
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue