]> sigrok.org Git - pulseview.git/blame - pv/views/tabular_decoder/view.hpp
TabularDecView: Some fixes and refactorings
[pulseview.git] / pv / views / tabular_decoder / view.hpp
CommitLineData
24d69d27
SA
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
8845be3c
UH
20#ifndef PULSEVIEW_PV_VIEWS_TABULAR_DECODER_VIEW_HPP
21#define PULSEVIEW_PV_VIEWS_TABULAR_DECODER_VIEW_HPP
24d69d27
SA
22
23#include <QAction>
86d4b8e3 24#include <QCheckBox>
24d69d27 25#include <QComboBox>
6f43db70 26#include <QSortFilterProxyModel>
24d69d27
SA
27#include <QTableView>
28#include <QToolButton>
29
8997f62a 30#include "pv/metadata_obj.hpp"
24d69d27
SA
31#include "pv/views/viewbase.hpp"
32#include "pv/data/decodesignal.hpp"
33
34namespace pv {
35class Session;
36
37namespace views {
38
39namespace tabular_decoder {
40
be0f5903
SA
41// When adding an entry here, don't forget to update SaveTypeNames as well
42enum SaveType {
43 SaveTypeCSVEscaped,
44 SaveTypeCSVQuoted,
45 SaveTypeCount // Indicates how many save types there are, must always be last
46};
47
86d4b8e3
SA
48// When adding an entry here, don't forget to update ViewModeNames as well
49enum ViewModeType {
50 ViewModeAll,
51 ViewModeLatest,
8997f62a 52 ViewModeVisible,
f2739bae 53 ViewModeCount // Indicates how many view mode types there are, must always be last
86d4b8e3
SA
54};
55
be0f5903 56extern const char* SaveTypeNames[SaveTypeCount];
86d4b8e3 57extern const char* ViewModeNames[ViewModeCount];
be0f5903
SA
58
59
8e168b23 60class AnnotationCollectionModel : public QAbstractTableModel
24d69d27
SA
61{
62 Q_OBJECT
63
64public:
65 AnnotationCollectionModel(QObject* parent = nullptr);
66
1c521100 67 int get_hierarchy_level(const Annotation* ann) const;
85125b0f 68 QVariant data_from_ann(const Annotation* ann, int index) const;
24d69d27
SA
69 QVariant data(const QModelIndex& index, int role) const override;
70 Qt::ItemFlags flags(const QModelIndex& index) const override;
71
6f43db70 72 uint8_t first_hidden_column() const;
24d69d27
SA
73 QVariant headerData(int section, Qt::Orientation orientation,
74 int role = Qt::DisplayRole) const override;
75 QModelIndex index(int row, int column,
76 const QModelIndex& parent_idx = QModelIndex()) const override;
77
78 QModelIndex parent(const QModelIndex& index) const override;
79
80 int rowCount(const QModelIndex& parent_idx = QModelIndex()) const override;
81 int columnCount(const QModelIndex& parent_idx = QModelIndex()) const override;
82
f54e68b0 83 void set_signal_and_segment(data::DecodeSignal* signal, uint32_t current_segment);
86d4b8e3
SA
84 void set_hide_hidden(bool hide_hidden);
85
86 void update_annotations_without_hidden();
6f43db70 87 QModelIndex update_highlighted_rows(QModelIndex first, QModelIndex last,
1c521100 88 int64_t sample_num);
f54e68b0 89
02078aa1
SA
90private Q_SLOTS:
91 void on_annotation_visibility_changed();
92
24d69d27 93private:
f54e68b0
SA
94 vector<QVariant> header_data_;
95 const deque<const Annotation*>* all_annotations_;
86d4b8e3
SA
96 deque<const Annotation*> all_annotations_without_hidden_;
97 const deque<const Annotation*>* dataset_;
d656b010 98 data::DecodeSignal* signal_;
6f43db70 99 uint8_t first_hidden_column_;
f54e68b0
SA
100 uint32_t prev_segment_;
101 uint64_t prev_last_row_;
1c521100
SA
102 int64_t highlight_sample_num_;
103 bool had_highlight_before_;
86d4b8e3 104 bool hide_hidden_;
f54e68b0
SA
105};
106
107
6f43db70
SA
108class CustomFilterProxyModel : public QSortFilterProxyModel
109{
110 Q_OBJECT
111
112public:
113 CustomFilterProxyModel(QObject* parent = 0);
114
115 void set_sample_range(uint64_t start_sample, uint64_t end_sample);
116
939d25cb
SA
117 void enable_range_filtering(bool value);
118
6f43db70
SA
119protected:
120 bool filterAcceptsRow(int sourceRow, const QModelIndex &sourceParent) const override;
121
122private:
123 uint64_t range_start_sample_, range_end_sample_;
939d25cb 124 bool range_filtering_enabled_;
6f43db70
SA
125};
126
127
128class CustomTableView : public QTableView
f54e68b0
SA
129{
130 Q_OBJECT
131
132public:
133 QSize minimumSizeHint() const;
134 QSize sizeHint() const;
24d69d27
SA
135};
136
137
8997f62a 138class View : public ViewBase, public MetadataObjObserverInterface
24d69d27
SA
139{
140 Q_OBJECT
141
142public:
143 explicit View(Session &session, bool is_main_view=false, QMainWindow *parent = nullptr);
8997f62a 144 ~View();
24d69d27
SA
145
146 virtual ViewType get_type() const;
147
148 /**
149 * Resets the view to its default state after construction. It does however
150 * not reset the signal bases or any other connections with the session.
151 */
152 virtual void reset_view_state();
153
154 virtual void clear_decode_signals();
155 virtual void add_decode_signal(shared_ptr<data::DecodeSignal> signal);
156 virtual void remove_decode_signal(shared_ptr<data::DecodeSignal> signal);
157
158 virtual void save_settings(QSettings &settings) const;
159 virtual void restore_settings(QSettings &settings);
160
161private:
162 void reset_data();
163 void update_data();
164
be0f5903 165 void save_data_as_csv(unsigned int save_type) const;
24d69d27
SA
166
167private Q_SLOTS:
168 void on_selected_decoder_changed(int index);
86d4b8e3
SA
169 void on_hide_hidden_changed(bool checked);
170 void on_view_mode_changed(int index);
171
24d69d27 172 void on_signal_name_changed(const QString &name);
88a25978 173 void on_signal_color_changed(const QColor &color);
24d69d27
SA
174 void on_new_annotations();
175
02c87df7 176 void on_decoder_reset();
24d69d27
SA
177 void on_decoder_stacked(void* decoder);
178 void on_decoder_removed(void* decoder);
179
180 void on_actionSave_triggered(QAction* action = nullptr);
181
9a35b05d
SA
182 void on_table_item_clicked(const QModelIndex& index);
183 void on_table_item_double_clicked(const QModelIndex& index);
184 void on_table_header_requested(const QPoint& pos);
185 void on_table_header_toggled(bool checked);
186
8997f62a
SA
187 virtual void on_metadata_object_changed(MetadataObject* obj,
188 MetadataValueType value_type);
189
24d69d27
SA
190 virtual void perform_delayed_view_update();
191
192private:
193 QWidget* parent_;
194
f54e68b0 195 QComboBox* decoder_selector_;
86d4b8e3
SA
196 QCheckBox* hide_hidden_cb_;
197 QComboBox* view_mode_selector_;
24d69d27
SA
198
199 QToolButton* save_button_;
200 QAction* save_action_;
201
6f43db70 202 CustomTableView* table_view_;
24d69d27 203 AnnotationCollectionModel* model_;
6f43db70 204 CustomFilterProxyModel* filter_proxy_model_;
24d69d27 205
f54e68b0
SA
206 data::DecodeSignal* signal_;
207 const data::decode::Decoder* decoder_;
24d69d27
SA
208};
209
210} // namespace tabular_decoder
211} // namespace views
212} // namespace pv
213
8845be3c 214#endif // PULSEVIEW_PV_VIEWS_TABULAR_DECODER_VIEW_HPP