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