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