]> sigrok.org Git - pulseview.git/blob - pv/views/tabular_decoder/view.hpp
TabularDecView: Increase robustness
[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 AnnotationCollectionModel : public QAbstractTableModel
39 {
40         Q_OBJECT
41
42 public:
43         AnnotationCollectionModel(QObject* parent = nullptr);
44
45         QVariant data(const QModelIndex& index, int role) const override;
46         Qt::ItemFlags flags(const QModelIndex& index) const override;
47
48         QVariant headerData(int section, Qt::Orientation orientation,
49                 int role = Qt::DisplayRole) const override;
50         QModelIndex index(int row, int column,
51                 const QModelIndex& parent_idx = QModelIndex()) const override;
52
53         QModelIndex parent(const QModelIndex& index) const override;
54
55         int rowCount(const QModelIndex& parent_idx = QModelIndex()) const override;
56         int columnCount(const QModelIndex& parent_idx = QModelIndex()) const override;
57
58         void set_signal_and_segment(data::DecodeSignal* signal, uint32_t current_segment);
59
60 private:
61         vector<QVariant> header_data_;
62         const deque<const Annotation*>* all_annotations_;
63         uint32_t prev_segment_;
64         uint64_t prev_last_row_;
65 };
66
67
68 class QCustomTableView : public QTableView
69 {
70         Q_OBJECT
71
72 public:
73         QSize minimumSizeHint() const;
74         QSize sizeHint() const;
75 };
76
77
78 class View : public ViewBase
79 {
80         Q_OBJECT
81
82 public:
83         explicit View(Session &session, bool is_main_view=false, QMainWindow *parent = nullptr);
84
85         virtual ViewType get_type() const;
86
87         /**
88          * Resets the view to its default state after construction. It does however
89          * not reset the signal bases or any other connections with the session.
90          */
91         virtual void reset_view_state();
92
93         virtual void clear_decode_signals();
94         virtual void add_decode_signal(shared_ptr<data::DecodeSignal> signal);
95         virtual void remove_decode_signal(shared_ptr<data::DecodeSignal> signal);
96
97         virtual void save_settings(QSettings &settings) const;
98         virtual void restore_settings(QSettings &settings);
99
100 private:
101         void reset_data();
102         void update_data();
103
104         void save_data() const;
105
106 private Q_SLOTS:
107         void on_selected_decoder_changed(int index);
108         void on_signal_name_changed(const QString &name);
109         void on_new_annotations();
110
111         void on_decoder_reset();
112         void on_decoder_stacked(void* decoder);
113         void on_decoder_removed(void* decoder);
114
115         void on_actionSave_triggered(QAction* action = nullptr);
116
117         virtual void perform_delayed_view_update();
118
119 private:
120         QWidget* parent_;
121
122         QComboBox* decoder_selector_;
123
124         QToolButton* save_button_;
125         QAction* save_action_;
126
127         QCustomTableView* table_view_;
128
129         AnnotationCollectionModel* model_;
130
131         data::DecodeSignal* signal_;
132         const data::decode::Decoder* decoder_;
133         bool updating_data_;
134 };
135
136 } // namespace tabular_decoder
137 } // namespace views
138 } // namespace pv
139
140 #endif // PULSEVIEW_PV_VIEWS_TABULARDECODER_VIEW_HPP