Replies: 2 comments 1 reply
-
|
I believe the row_data is supposed to be of the type You can make one for example with |
Beta Was this translation helpful? Give feedback.
-
|
The The definition and conversion is bizarre and far from straightforward. Anyway, in my project, the following snippet works. // callback: add multiple documents
ui->on_file_add([&] {
#ifdef _WIN32
const char SLASH[] = "\\";
#else
const char SLASH[] = "/";
#endif
auto results =
open_file("Add Documents", ".", {"All Files", "*"}, opt::multiselect).result();
if (!results.empty()) {
vector<SharedString> oldfnames;
// in-out property <[[StandardListViewItem]]> dt_files:[]; <==>
// StandardTableView.rows
auto dt_files = ui->get_dt_files();
typedef shared_ptr<Model<StandardListViewItem>> ModelRcLVI;
vector<ModelRcLVI> table; // new table
for (int i = 0; i < dt_files->row_count(); i++) {
auto row = *dt_files->row_data(i);
// push old rows in original StandardTableView to new table
if (row->row_data(0)->text == "🔒") {
table.push_back(*dt_files->row_data(i));
SharedString fname =
row->row_data(2)->text + SLASH + row->row_data(1)->text;
oldfnames.push_back(fname);
}
}
// add selected files to StandardTableView
for (auto fnm : results) {
#ifdef _WIN32
std::replace(fnm.begin(), fnm.end(), '/', '\\');
#endif
std::cout << fnm << std::endl;
auto it =
std::find(oldfnames.begin(), oldfnames.end(), SharedString(fnm));
if (it != oldfnames.end()) {
continue;
}
size_t pos = fnm.find_last_of(SLASH);
// row data: fileStatus, fileName, filePath
vector<StandardListViewItem> row1 = {
StandardListViewItem("🔒"),
StandardListViewItem(SharedString(fnm.substr(pos + 1, fnm.size()))),
StandardListViewItem(SharedString(fnm.substr(0, pos))),
};
auto row1_model = make_shared<VectorModel<StandardListViewItem>>(row1);
table.push_back(row1_model);
}
auto table_model = make_shared<VectorModel<ModelRcLVI>>(table);
ui->set_dt_files(table_model); // set new table
}
}); in-out property <[[StandardListViewItem]]> dt_files:[];
callback file-add();
Menu {
title: @tr("File");
MenuItem {
title: @tr("Add Documents");
activated => {
file-add();
}
}
}
StandardTableView {
columns: [
{ title: "♨", width:60px },
{ title: "name" },
{ title: "location" },
];
rows: dt_files;
} |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
I'm trying to populate data into the StandardTableView component and relating to disccusion #5298, it is advised to use
VecModel::pushto add new row to model. Is there a way to achieve that in C++?MainWindow.slint code:
Cpp code:
To push new entry into the row model for StandardTableView component, how can I create the right structure type for 'row_data' in C++?
Thanks!
Beta Was this translation helpful? Give feedback.
All reactions