Problem with sorting ColumnView
- From: Jackson Campolattaro <jackcamp vt edu>
- To: gtkmm-list gnome org
- Subject: Problem with sorting ColumnView
- Date: Tue, 23 Aug 2022 13:32:24 +0200
Hello,
I'm trying to use the Gtk ColumnView to show a custom ListModel in sorted order. I noticed that when I set a simple sorter for a column and then sort by that column, the order isn't changed. The UI allows me to switch between ascending and descending, but doing so doesn't reverse the list.
I've created a simplified example, which is supposed to show the file paths in the current directory in alphabetical order, but doesn't:
#include <gtkmm.h>
#include <giomm.h>
class MyWindow : public Gtk::Window {
private:
Glib::RefPtr<Gio::ListStore<Gio::File>> _listModel;
Glib::RefPtr<Gtk::SingleSelection> _selectionModel;
Gtk::ColumnView _columnView;
public:
MyWindow() {
_listModel = Gio::ListStore<Gio::File>::create();
_selectionModel = Gtk::SingleSelection::create(_listModel);
_columnView.set_model(_selectionModel);
auto files = Gio::File::create_for_path(".")->enumerate_children();
Glib::RefPtr<Gio::FileInfo> fileInfo;
while ((fileInfo = files->next_file())) {
_listModel->append(Gio::File::create_for_path(fileInfo->get_name()));
}
auto _factory = Gtk::SignalListItemFactory::create();
_factory->signal_setup().connect([](auto listItem) {
listItem->set_child(*Gtk::make_managed<Gtk::Label>("Placeholder!"));
});
_factory->signal_bind().connect([](auto listItem) {
auto data = ""> auto label = dynamic_cast<Gtk::Label *>(listItem->get_child());
if (data && label) {
label->set_text(data->get_path());
label->set_xalign(0);
}
});
auto column = Gtk::ColumnViewColumn::create("File Paths", _factory);
_columnView.append_column(column);
column->set_sorter(Gtk::StringSorter::create(
Gtk::ClosureExpression<Glib::ustring>::create([](auto item) {
auto data = ""> return data->get_path();
})
));
_columnView.sort_by_column(column, Gtk::SortType::ASCENDING);
set_child(_columnView);
};
};
int main(int argc, char *argv[]) {
auto app = Gtk::Application::create("org.gtkmm.examples.base");
return app->make_window_and_run<MyWindow>(argc, argv);
}
Perhaps this is a bug, but before I report it I wanted to make sure I'm not doing something wrong.
Thanks,
Jackson
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]