]> sigrok.org Git - pulseview.git/blob - pv/subwindows/decoder_selector/subwindow.hpp
1b75a6c7d3bc30fd59eed491c3ff59b1bf1f40c7
[pulseview.git] / pv / subwindows / decoder_selector / subwindow.hpp
1 /*
2  * This file is part of the PulseView project.
3  *
4  * Copyright (C) 2018 Soeren Apel <soeren@apelpie.net>
5  *
6  * This program is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation; either version 2 of the License, or
9  * (at your option) any later version.
10  *
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with this program; if not, see <http://www.gnu.org/licenses/>.
18  */
19
20 #ifndef PULSEVIEW_PV_SUBWINDOWS_DECODERSELECTOR_SUBWINDOW_HPP
21 #define PULSEVIEW_PV_SUBWINDOWS_DECODERSELECTOR_SUBWINDOW_HPP
22
23 #include <vector>
24
25 #include <QAbstractItemModel>
26 #include <QSplitter>
27 #include <QTreeView>
28
29 #include "pv/subwindows/subwindowbase.hpp"
30
31 using std::shared_ptr;
32
33 namespace pv {
34 namespace subwindows {
35 namespace decoder_selector {
36
37 class DecoderCollectionItem
38 {
39 public:
40         DecoderCollectionItem(const vector<QVariant>& data,
41                 shared_ptr<DecoderCollectionItem> parent = nullptr);
42
43         void appendSubItem(shared_ptr<DecoderCollectionItem> item);
44
45         shared_ptr<DecoderCollectionItem> subItem(int row) const;
46         shared_ptr<DecoderCollectionItem> parent() const;
47         shared_ptr<DecoderCollectionItem> findSubItem(const QVariant& value, int column);
48
49         int subItemCount() const;
50         int columnCount() const;
51         int row() const;
52         QVariant data(int column) const;
53
54 private:
55         vector< shared_ptr<DecoderCollectionItem> > subItems_;
56         vector<QVariant> data_;
57         shared_ptr<DecoderCollectionItem> parent_;
58 };
59
60
61 class DecoderCollectionModel : public QAbstractItemModel
62 {
63         Q_OBJECT
64
65 public:
66         DecoderCollectionModel(QObject* parent = 0);
67
68         QVariant data(const QModelIndex& index, int role) const override;
69         Qt::ItemFlags flags(const QModelIndex& index) const override;
70
71         QVariant headerData(int section, Qt::Orientation orientation,
72                 int role = Qt::DisplayRole) const override;
73         QModelIndex index(int row, int column,
74                 const QModelIndex& parent_idx = QModelIndex()) const override;
75
76         QModelIndex parent(const QModelIndex& index) const override;
77
78         int rowCount(const QModelIndex& parent_idx = QModelIndex()) const override;
79         int columnCount(const QModelIndex& parent_idx = QModelIndex()) const override;
80
81 private:
82         shared_ptr<DecoderCollectionItem> root_;
83 };
84
85
86 class SubWindow : public SubWindowBase
87 {
88         Q_OBJECT
89
90 public:
91         explicit SubWindow(Session &session, QWidget *parent = nullptr);
92
93         bool has_toolbar() const;
94         QToolBar* create_toolbar(QWidget *parent) const;
95
96         const srd_decoder* get_srd_decoder_from_id(QString id) const;
97
98         /**
99          * Returns a list of input types that a given protocol decoder requires
100          * ("logic", "uart", etc.)
101          */
102         vector<const char*> decoder_inputs(const srd_decoder* d) const;
103
104         /**
105          * Returns a list of protocol decoder IDs which provide a given output
106          * ("uart", "spi", etc.)
107          */
108         vector<const srd_decoder*> decoders_providing(const char* output) const;
109
110 Q_SIGNALS:
111         void new_decoders_selected(vector<const srd_decoder*> decoders);
112
113 public Q_SLOTS:
114         void on_item_double_clicked(const QModelIndex& index);
115
116 private:
117         QSplitter* splitter_;
118         QTreeView* tree_view_;
119         DecoderCollectionModel* model_;
120 };
121
122 } // decoder_selector
123 } // namespace subwindows
124 } // namespace pv
125
126 #endif // PULSEVIEW_PV_SUBWINDOWS_DECODERSELECTOR_SUBWINDOW_HPP
127