]> sigrok.org Git - pulseview.git/blob - pv/subwindows/decoder_selector/subwindow.hpp
baeedd36dad343a7247a8bdf53be2b2643c49916
[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 <QLabel>
27 #include <QSplitter>
28 #include <QTreeView>
29
30 #include "pv/subwindows/subwindowbase.hpp"
31
32 using std::shared_ptr;
33
34 namespace pv {
35 namespace subwindows {
36 namespace decoder_selector {
37
38 class DecoderCollectionItem
39 {
40 public:
41         DecoderCollectionItem(const vector<QVariant>& data,
42                 shared_ptr<DecoderCollectionItem> parent = nullptr);
43
44         void appendSubItem(shared_ptr<DecoderCollectionItem> item);
45
46         shared_ptr<DecoderCollectionItem> subItem(int row) const;
47         shared_ptr<DecoderCollectionItem> parent() const;
48         shared_ptr<DecoderCollectionItem> findSubItem(const QVariant& value, int column);
49
50         int subItemCount() const;
51         int columnCount() const;
52         int row() const;
53         QVariant data(int column) const;
54
55 private:
56         vector< shared_ptr<DecoderCollectionItem> > subItems_;
57         vector<QVariant> data_;
58         shared_ptr<DecoderCollectionItem> parent_;
59 };
60
61
62 class DecoderCollectionModel : public QAbstractItemModel
63 {
64         Q_OBJECT
65
66 public:
67         DecoderCollectionModel(QObject* parent = 0);
68
69         QVariant data(const QModelIndex& index, int role) const override;
70         Qt::ItemFlags flags(const QModelIndex& index) const override;
71
72         QVariant headerData(int section, Qt::Orientation orientation,
73                 int role = Qt::DisplayRole) const override;
74         QModelIndex index(int row, int column,
75                 const QModelIndex& parent_idx = QModelIndex()) const override;
76
77         QModelIndex parent(const QModelIndex& index) const override;
78
79         int rowCount(const QModelIndex& parent_idx = QModelIndex()) const override;
80         int columnCount(const QModelIndex& parent_idx = QModelIndex()) const override;
81
82 private:
83         shared_ptr<DecoderCollectionItem> root_;
84 };
85
86
87 class SubWindow : public SubWindowBase
88 {
89         Q_OBJECT
90
91 public:
92         explicit SubWindow(Session &session, QWidget *parent = nullptr);
93
94         bool has_toolbar() const;
95         QToolBar* create_toolbar(QWidget *parent) const;
96
97         const srd_decoder* get_srd_decoder_from_id(QString id) const;
98
99         /**
100          * Returns a list of input types that a given protocol decoder requires
101          * ("logic", "uart", etc.)
102          */
103         vector<const char*> decoder_inputs(const srd_decoder* d) const;
104
105         /**
106          * Returns a list of protocol decoder IDs which provide a given output
107          * ("uart", "spi", etc.)
108          */
109         vector<const srd_decoder*> decoders_providing(const char* output) const;
110
111 Q_SIGNALS:
112         void new_decoders_selected(vector<const srd_decoder*> decoders);
113
114 public Q_SLOTS:
115         void on_item_clicked(const QModelIndex& index);
116         void on_item_double_clicked(const QModelIndex& index);
117
118 private:
119         QSplitter* splitter_;
120         QTreeView* tree_view_;
121         QWidget* info_box_;
122         QLabel* info_label_header_;
123         QLabel* info_label_body_;
124         QLabel* info_label_footer_;
125         DecoderCollectionModel* model_;
126 };
127
128 } // decoder_selector
129 } // namespace subwindows
130 } // namespace pv
131
132 #endif // PULSEVIEW_PV_SUBWINDOWS_DECODERSELECTOR_SUBWINDOW_HPP
133