]> sigrok.org Git - pulseview.git/blame - pv/subwindows/decoder_selector/subwindow.hpp
DecodeSelector: Use custom treeview to hook into selection changes
[pulseview.git] / pv / subwindows / decoder_selector / subwindow.hpp
CommitLineData
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>
97378470
SA
27#include <QSplitter>
28#include <QTreeView>
29
30#include "pv/subwindows/subwindowbase.hpp"
31
32using std::shared_ptr;
33
34namespace pv {
35namespace subwindows {
36namespace decoder_selector {
37
38class DecoderCollectionItem
39{
40public:
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
55private:
56 vector< shared_ptr<DecoderCollectionItem> > subItems_;
57 vector<QVariant> data_;
58 shared_ptr<DecoderCollectionItem> parent_;
59};
60
61
62class DecoderCollectionModel : public QAbstractItemModel
63{
64 Q_OBJECT
65
66public:
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
82private:
83 shared_ptr<DecoderCollectionItem> root_;
84};
85
86
e10848e8
SA
87class QCustomTreeView : public QTreeView
88{
89 Q_OBJECT
90
91public:
92 void currentChanged(const QModelIndex& current, const QModelIndex& previous);
93
94Q_SIGNALS:
95 void currentChanged(const QModelIndex& current);
96};
97
97378470
SA
98class SubWindow : public SubWindowBase
99{
100 Q_OBJECT
101
102public:
103 explicit SubWindow(Session &session, QWidget *parent = nullptr);
104
105 bool has_toolbar() const;
106 QToolBar* create_toolbar(QWidget *parent) const;
107
108 const srd_decoder* get_srd_decoder_from_id(QString id) const;
109
110 /**
111 * Returns a list of input types that a given protocol decoder requires
112 * ("logic", "uart", etc.)
113 */
114 vector<const char*> decoder_inputs(const srd_decoder* d) const;
115
116 /**
117 * Returns a list of protocol decoder IDs which provide a given output
118 * ("uart", "spi", etc.)
119 */
120 vector<const srd_decoder*> decoders_providing(const char* output) const;
121
122Q_SIGNALS:
123 void new_decoders_selected(vector<const srd_decoder*> decoders);
124
125public Q_SLOTS:
e10848e8
SA
126 void on_item_changed(const QModelIndex& index);
127 void on_item_activated(const QModelIndex& index);
97378470
SA
128
129private:
130 QSplitter* splitter_;
e10848e8 131 QCustomTreeView* tree_view_;
c2b80ad9
SA
132 QWidget* info_box_;
133 QLabel* info_label_header_;
134 QLabel* info_label_body_;
135 QLabel* info_label_footer_;
97378470
SA
136 DecoderCollectionModel* model_;
137};
138
139} // decoder_selector
140} // namespace subwindows
141} // namespace pv
142
143#endif // PULSEVIEW_PV_SUBWINDOWS_DECODERSELECTOR_SUBWINDOW_HPP
144