]>
Commit | Line | Data |
---|---|---|
97378470 SA |
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> | |
c2b80ad9 | 26 | #include <QLabel> |
a6fab024 | 27 | #include <QSortFilterProxyModel> |
97378470 SA |
28 | #include <QSplitter> |
29 | #include <QTreeView> | |
30 | ||
31 | #include "pv/subwindows/subwindowbase.hpp" | |
32 | ||
33 | using std::shared_ptr; | |
34 | ||
35 | namespace pv { | |
36 | namespace subwindows { | |
37 | namespace decoder_selector { | |
38 | ||
39 | class DecoderCollectionItem | |
40 | { | |
41 | public: | |
42 | DecoderCollectionItem(const vector<QVariant>& data, | |
43 | shared_ptr<DecoderCollectionItem> parent = nullptr); | |
44 | ||
45 | void appendSubItem(shared_ptr<DecoderCollectionItem> item); | |
46 | ||
47 | shared_ptr<DecoderCollectionItem> subItem(int row) const; | |
48 | shared_ptr<DecoderCollectionItem> parent() const; | |
49 | shared_ptr<DecoderCollectionItem> findSubItem(const QVariant& value, int column); | |
50 | ||
51 | int subItemCount() const; | |
52 | int columnCount() const; | |
53 | int row() const; | |
54 | QVariant data(int column) const; | |
55 | ||
56 | private: | |
57 | vector< shared_ptr<DecoderCollectionItem> > subItems_; | |
58 | vector<QVariant> data_; | |
59 | shared_ptr<DecoderCollectionItem> parent_; | |
60 | }; | |
61 | ||
62 | ||
63 | class DecoderCollectionModel : public QAbstractItemModel | |
64 | { | |
65 | Q_OBJECT | |
66 | ||
67 | public: | |
c409988b | 68 | DecoderCollectionModel(QObject* parent = nullptr); |
97378470 SA |
69 | |
70 | QVariant data(const QModelIndex& index, int role) const override; | |
71 | Qt::ItemFlags flags(const QModelIndex& index) const override; | |
72 | ||
73 | QVariant headerData(int section, Qt::Orientation orientation, | |
74 | int role = Qt::DisplayRole) const override; | |
75 | QModelIndex index(int row, int column, | |
76 | const QModelIndex& parent_idx = QModelIndex()) const override; | |
77 | ||
78 | QModelIndex parent(const QModelIndex& index) const override; | |
79 | ||
80 | int rowCount(const QModelIndex& parent_idx = QModelIndex()) const override; | |
81 | int columnCount(const QModelIndex& parent_idx = QModelIndex()) const override; | |
82 | ||
83 | private: | |
84 | shared_ptr<DecoderCollectionItem> root_; | |
85 | }; | |
86 | ||
87 | ||
b229a1b7 SA |
88 | class QCustomSortFilterProxyModel : public QSortFilterProxyModel |
89 | { | |
90 | protected: | |
91 | bool filterAcceptsRow(int source_row, const QModelIndex& source_parent) const; | |
92 | }; | |
93 | ||
e10848e8 SA |
94 | class QCustomTreeView : public QTreeView |
95 | { | |
96 | Q_OBJECT | |
97 | ||
98 | public: | |
99 | void currentChanged(const QModelIndex& current, const QModelIndex& previous); | |
100 | ||
101 | Q_SIGNALS: | |
102 | void currentChanged(const QModelIndex& current); | |
103 | }; | |
104 | ||
97378470 SA |
105 | class SubWindow : public SubWindowBase |
106 | { | |
107 | Q_OBJECT | |
108 | ||
109 | public: | |
110 | explicit SubWindow(Session &session, QWidget *parent = nullptr); | |
111 | ||
112 | bool has_toolbar() const; | |
113 | QToolBar* create_toolbar(QWidget *parent) const; | |
114 | ||
c52493c9 SA |
115 | int minimum_width() const; |
116 | ||
97378470 SA |
117 | /** |
118 | * Returns a list of input types that a given protocol decoder requires | |
119 | * ("logic", "uart", etc.) | |
120 | */ | |
8f7c2dce | 121 | vector<const char*> get_decoder_inputs(const srd_decoder* d) const; |
97378470 SA |
122 | |
123 | /** | |
124 | * Returns a list of protocol decoder IDs which provide a given output | |
125 | * ("uart", "spi", etc.) | |
126 | */ | |
8f7c2dce | 127 | vector<const srd_decoder*> get_decoders_providing(const char* output) const; |
97378470 SA |
128 | |
129 | Q_SIGNALS: | |
130 | void new_decoders_selected(vector<const srd_decoder*> decoders); | |
131 | ||
132 | public Q_SLOTS: | |
e10848e8 SA |
133 | void on_item_changed(const QModelIndex& index); |
134 | void on_item_activated(const QModelIndex& index); | |
97378470 | 135 | |
b229a1b7 | 136 | void on_filter_changed(const QString& text); |
66ab3d70 | 137 | void on_filter_return_pressed(); |
b229a1b7 | 138 | |
97378470 SA |
139 | private: |
140 | QSplitter* splitter_; | |
e10848e8 | 141 | QCustomTreeView* tree_view_; |
c2b80ad9 SA |
142 | QWidget* info_box_; |
143 | QLabel* info_label_header_; | |
144 | QLabel* info_label_body_; | |
145 | QLabel* info_label_footer_; | |
97378470 | 146 | DecoderCollectionModel* model_; |
b229a1b7 | 147 | QCustomSortFilterProxyModel* sort_filter_model_; |
97378470 SA |
148 | }; |
149 | ||
c409988b | 150 | } // namespace decoder_selector |
97378470 SA |
151 | } // namespace subwindows |
152 | } // namespace pv | |
153 | ||
154 | #endif // PULSEVIEW_PV_SUBWINDOWS_DECODERSELECTOR_SUBWINDOW_HPP | |
155 |