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