add sort func to sort model

This commit is contained in:
ouwou
2024-02-02 01:32:44 -05:00
parent c41ff1e4d9
commit 2be776b12f
2 changed files with 16 additions and 0 deletions

View File

@@ -84,6 +84,7 @@ ChannelListTree::ChannelListTree()
m_view.set_headers_visible(false);
m_view.set_model(m_sort_model);
m_sort_model->set_sort_column(m_columns.m_sort, Gtk::SORT_ASCENDING);
m_sort_model->set_sort_func(m_columns.m_sort, sigc::mem_fun(*this, &ChannelListTree::SortFunc));
m_model->signal_row_inserted().connect([this](const Gtk::TreeModel::Path &path, const Gtk::TreeModel::iterator &iter) {
if (m_updating_listing) return;
@@ -347,6 +348,19 @@ void ChannelListTree::SetSelectedDMs() {
}
}
int ChannelListTree::SortFunc(const Gtk::TreeModel::iterator &a, const Gtk::TreeModel::iterator &b) {
const RenderType a_type = (*a)[m_columns.m_type];
const RenderType b_type = (*b)[m_columns.m_type];
const int64_t a_sort = (*a)[m_columns.m_sort];
const int64_t b_sort = (*b)[m_columns.m_sort];
if (a_type == RenderType::DMHeader) return -1;
if (b_type == RenderType::DMHeader) return 1;
if (a_type == RenderType::TextChannel && b_type == RenderType::VoiceChannel) return -1;
if (b_type == RenderType::TextChannel && a_type == RenderType::VoiceChannel) return 1;
if (a_type == b_type) return static_cast<int>(a_sort - b_sort);
return 0;
}
void ChannelListTree::OnPanedPositionChanged() {
m_view.queue_draw();
}

View File

@@ -38,6 +38,8 @@ public:
void SetSelectedDMs();
protected:
int SortFunc(const Gtk::TreeModel::iterator &a, const Gtk::TreeModel::iterator &b);
void OnPanedPositionChanged();
void UpdateListingClassic();