]> sigrok.org Git - pulseview.git/blob - pv/views/tabular_decoder/view.hpp
Add tabular decoder view
[pulseview.git] / pv / views / tabular_decoder / view.hpp
1 /*
2  * This file is part of the PulseView project.
3  *
4  * Copyright (C) 2020 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_VIEWS_TABULARDECODER_VIEW_HPP
21 #define PULSEVIEW_PV_VIEWS_TABULARDECODER_VIEW_HPP
22
23 #include <QAction>
24 #include <QComboBox>
25 #include <QTableView>
26 #include <QToolButton>
27
28 #include "pv/views/viewbase.hpp"
29 #include "pv/data/decodesignal.hpp"
30
31 namespace pv {
32 class Session;
33
34 namespace views {
35
36 namespace tabular_decoder {
37
38 class AnnotationCollectionItem
39 {
40 public:
41         AnnotationCollectionItem(const vector<QVariant>& data,
42                 shared_ptr<AnnotationCollectionItem> parent = nullptr);
43
44         void appendSubItem(shared_ptr<AnnotationCollectionItem> item);
45
46         shared_ptr<AnnotationCollectionItem> subItem(int row) const;
47         shared_ptr<AnnotationCollectionItem> parent() const;
48         shared_ptr<AnnotationCollectionItem> 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<AnnotationCollectionItem> > subItems_;
57         vector<QVariant> data_;
58         shared_ptr<AnnotationCollectionItem> parent_;
59 };
60
61
62 class AnnotationCollectionModel : public QAbstractItemModel
63 {
64         Q_OBJECT
65
66 public:
67         AnnotationCollectionModel(QObject* parent = nullptr);
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<AnnotationCollectionItem> root_;
84 };
85
86
87 class View : public ViewBase
88 {
89         Q_OBJECT
90
91 public:
92         explicit View(Session &session, bool is_main_view=false, QMainWindow *parent = nullptr);
93
94         virtual ViewType get_type() const;
95
96         /**
97          * Resets the view to its default state after construction. It does however
98          * not reset the signal bases or any other connections with the session.
99          */
100         virtual void reset_view_state();
101
102         virtual void clear_decode_signals();
103         virtual void add_decode_signal(shared_ptr<data::DecodeSignal> signal);
104         virtual void remove_decode_signal(shared_ptr<data::DecodeSignal> signal);
105
106         virtual void save_settings(QSettings &settings) const;
107         virtual void restore_settings(QSettings &settings);
108
109 private:
110         void reset_data();
111         void update_data();
112
113         void save_data() const;
114
115 private Q_SLOTS:
116         void on_selected_decoder_changed(int index);
117         void on_signal_name_changed(const QString &name);
118         void on_new_annotations();
119
120         void on_decoder_stacked(void* decoder);
121         void on_decoder_removed(void* decoder);
122
123         void on_actionSave_triggered(QAction* action = nullptr);
124
125         virtual void perform_delayed_view_update();
126
127 private:
128         QWidget* parent_;
129
130         QComboBox *decoder_selector_;
131
132         QToolButton* save_button_;
133         QAction* save_action_;
134
135         QTableView* table_view_;
136
137         AnnotationCollectionModel* model_;
138
139         data::DecodeSignal *signal_;
140         const data::decode::Decoder *decoder_;
141 };
142
143 } // namespace tabular_decoder
144 } // namespace views
145 } // namespace pv
146
147 #endif // PULSEVIEW_PV_VIEWS_TABULARDECODER_VIEW_HPP