2 * This file is part of the PulseView project.
4 * Copyright (C) 2018 Soeren Apel <soeren@apelpie.net>
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.
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.
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/>.
20 #ifndef PULSEVIEW_PV_SUBWINDOWS_DECODERSELECTOR_SUBWINDOW_HPP
21 #define PULSEVIEW_PV_SUBWINDOWS_DECODERSELECTOR_SUBWINDOW_HPP
25 #include <QAbstractItemModel>
30 #include "pv/subwindows/subwindowbase.hpp"
32 using std::shared_ptr;
35 namespace subwindows {
36 namespace decoder_selector {
38 class DecoderCollectionItem
41 DecoderCollectionItem(const vector<QVariant>& data,
42 shared_ptr<DecoderCollectionItem> parent = nullptr);
44 void appendSubItem(shared_ptr<DecoderCollectionItem> item);
46 shared_ptr<DecoderCollectionItem> subItem(int row) const;
47 shared_ptr<DecoderCollectionItem> parent() const;
48 shared_ptr<DecoderCollectionItem> findSubItem(const QVariant& value, int column);
50 int subItemCount() const;
51 int columnCount() const;
53 QVariant data(int column) const;
56 vector< shared_ptr<DecoderCollectionItem> > subItems_;
57 vector<QVariant> data_;
58 shared_ptr<DecoderCollectionItem> parent_;
62 class DecoderCollectionModel : public QAbstractItemModel
67 DecoderCollectionModel(QObject* parent = 0);
69 QVariant data(const QModelIndex& index, int role) const override;
70 Qt::ItemFlags flags(const QModelIndex& index) const override;
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;
77 QModelIndex parent(const QModelIndex& index) const override;
79 int rowCount(const QModelIndex& parent_idx = QModelIndex()) const override;
80 int columnCount(const QModelIndex& parent_idx = QModelIndex()) const override;
83 shared_ptr<DecoderCollectionItem> root_;
87 class QCustomTreeView : public QTreeView
92 void currentChanged(const QModelIndex& current, const QModelIndex& previous);
95 void currentChanged(const QModelIndex& current);
98 class SubWindow : public SubWindowBase
103 explicit SubWindow(Session &session, QWidget *parent = nullptr);
105 bool has_toolbar() const;
106 QToolBar* create_toolbar(QWidget *parent) const;
108 const srd_decoder* get_srd_decoder_from_id(QString id) const;
111 * Returns a list of input types that a given protocol decoder requires
112 * ("logic", "uart", etc.)
114 vector<const char*> decoder_inputs(const srd_decoder* d) const;
117 * Returns a list of protocol decoder IDs which provide a given output
118 * ("uart", "spi", etc.)
120 vector<const srd_decoder*> decoders_providing(const char* output) const;
123 void new_decoders_selected(vector<const srd_decoder*> decoders);
126 void on_item_changed(const QModelIndex& index);
127 void on_item_activated(const QModelIndex& index);
130 QSplitter* splitter_;
131 QCustomTreeView* tree_view_;
133 QLabel* info_label_header_;
134 QLabel* info_label_body_;
135 QLabel* info_label_footer_;
136 DecoderCollectionModel* model_;
139 } // decoder_selector
140 } // namespace subwindows
143 #endif // PULSEVIEW_PV_SUBWINDOWS_DECODERSELECTOR_SUBWINDOW_HPP