]> sigrok.org Git - pulseview.git/commitdiff
DecoderSelector: Use proxy model to permit sorting
authorSoeren Apel <redacted>
Sun, 10 Mar 2019 10:39:32 +0000 (11:39 +0100)
committerSoeren Apel <redacted>
Tue, 12 Mar 2019 07:57:31 +0000 (08:57 +0100)
pv/subwindows/decoder_selector/subwindow.cpp
pv/subwindows/decoder_selector/subwindow.hpp

index f669146d56eab408c4a33548340cabf23fdc900d..375e749e789b9860af5988f07422a42c404d5ea9 100644 (file)
@@ -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
index 4434f0a610bcd2030e867acc598b5417eb3184c4..dba6f6deed8f72515d58bcd15df5fa0175e2f836 100644 (file)
@@ -24,6 +24,7 @@
 
 #include <QAbstractItemModel>
 #include <QLabel>
+#include <QSortFilterProxyModel>
 #include <QSplitter>
 #include <QTreeView>
 
@@ -134,6 +135,7 @@ private:
        QLabel* info_label_body_;
        QLabel* info_label_footer_;
        DecoderCollectionModel* model_;
+       QSortFilterProxyModel* sort_filter_model_;
 };
 
 } // decoder_selector