From: Soeren Apel Date: Sun, 10 Mar 2019 10:39:32 +0000 (+0100) Subject: DecoderSelector: Use proxy model to permit sorting X-Git-Url: https://sigrok.org/gitaction?a=commitdiff_plain;h=a6fab02455b3d9910fe1bcc51ab644f224ee52e1;p=pulseview.git DecoderSelector: Use proxy model to permit sorting --- diff --git a/pv/subwindows/decoder_selector/subwindow.cpp b/pv/subwindows/decoder_selector/subwindow.cpp index f669146d..375e749e 100644 --- a/pv/subwindows/decoder_selector/subwindow.cpp +++ b/pv/subwindows/decoder_selector/subwindow.cpp @@ -52,7 +52,8 @@ SubWindow::SubWindow(Session& session, QWidget* parent) : info_label_header_(new QLabel()), info_label_body_(new QLabel()), info_label_footer_(new QLabel()), - model_(new DecoderCollectionModel()) + model_(new DecoderCollectionModel()), + sort_filter_model_(new QSortFilterProxyModel()) { QVBoxLayout* root_layout = new QVBoxLayout(this); root_layout->setContentsMargins(0, 0, 0, 0); @@ -62,8 +63,12 @@ SubWindow::SubWindow(Session& session, QWidget* parent) : splitter_->addWidget(tree_view_); splitter_->addWidget(info_box_); - tree_view_->setModel(model_); + sort_filter_model_->setSourceModel(model_); + + tree_view_->setModel(sort_filter_model_); tree_view_->setRootIsDecorated(true); + tree_view_->setSortingEnabled(true); + tree_view_->sortByColumn(0, Qt::AscendingOrder); // Hide the columns that hold the detailed item information tree_view_->hideColumn(2); // ID diff --git a/pv/subwindows/decoder_selector/subwindow.hpp b/pv/subwindows/decoder_selector/subwindow.hpp index 4434f0a6..dba6f6de 100644 --- a/pv/subwindows/decoder_selector/subwindow.hpp +++ b/pv/subwindows/decoder_selector/subwindow.hpp @@ -24,6 +24,7 @@ #include #include +#include #include #include @@ -134,6 +135,7 @@ private: QLabel* info_label_body_; QLabel* info_label_footer_; DecoderCollectionModel* model_; + QSortFilterProxyModel* sort_filter_model_; }; } // decoder_selector