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