2 * This file is part of the PulseView project.
4 * Copyright (C) 2020 Soeren Apel <soeren@apelpie.net>
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.
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.
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/>.
20 #ifndef PULSEVIEW_PV_VIEWS_TABULAR_DECODER_VIEW_HPP
21 #define PULSEVIEW_PV_VIEWS_TABULAR_DECODER_VIEW_HPP
26 #include <QSortFilterProxyModel>
28 #include <QToolButton>
30 #include "pv/metadata_obj.hpp"
31 #include "pv/views/viewbase.hpp"
32 #include "pv/data/decodesignal.hpp"
39 namespace tabular_decoder {
41 // When adding an entry here, don't forget to update SaveTypeNames as well
45 SaveTypeCount // Indicates how many save types there are, must always be last
48 // When adding an entry here, don't forget to update ViewModeNames as well
53 ViewModeCount // Indicates how many view mode types there are, must always be last
56 extern const char* SaveTypeNames[SaveTypeCount];
57 extern const char* ViewModeNames[ViewModeCount];
60 class AnnotationCollectionModel : public QAbstractTableModel
65 AnnotationCollectionModel(QObject* parent = nullptr);
67 int get_hierarchy_level(const Annotation* ann) const;
68 QVariant data_from_ann(const Annotation* ann, int index) const;
69 QVariant data(const QModelIndex& index, int role) const override;
70 Qt::ItemFlags flags(const QModelIndex& index) const override;
72 uint8_t first_hidden_column() const;
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;
78 QModelIndex parent(const QModelIndex& index) const override;
80 int rowCount(const QModelIndex& parent_idx = QModelIndex()) const override;
81 int columnCount(const QModelIndex& parent_idx = QModelIndex()) const override;
83 void set_signal_and_segment(data::DecodeSignal* signal, uint32_t current_segment);
84 void set_hide_hidden(bool hide_hidden);
86 void update_annotations_without_hidden();
87 QModelIndex update_highlighted_rows(QModelIndex first, QModelIndex last,
91 void on_annotation_visibility_changed();
94 vector<QVariant> header_data_;
95 const deque<const Annotation*>* all_annotations_;
96 deque<const Annotation*> all_annotations_without_hidden_;
97 const deque<const Annotation*>* dataset_;
98 data::DecodeSignal* signal_;
99 uint8_t first_hidden_column_;
100 uint32_t prev_segment_;
101 uint64_t prev_last_row_;
102 int64_t highlight_sample_num_;
103 bool had_highlight_before_;
108 class CustomFilterProxyModel : public QSortFilterProxyModel
113 CustomFilterProxyModel(QObject* parent = 0);
115 void set_sample_range(uint64_t start_sample, uint64_t end_sample);
118 bool filterAcceptsRow(int sourceRow, const QModelIndex &sourceParent) const override;
121 uint64_t range_start_sample_, range_end_sample_;
125 class CustomTableView : public QTableView
130 QSize minimumSizeHint() const;
131 QSize sizeHint() const;
135 class View : public ViewBase, public MetadataObjObserverInterface
140 explicit View(Session &session, bool is_main_view=false, QMainWindow *parent = nullptr);
143 virtual ViewType get_type() const;
146 * Resets the view to its default state after construction. It does however
147 * not reset the signal bases or any other connections with the session.
149 virtual void reset_view_state();
151 virtual void clear_decode_signals();
152 virtual void add_decode_signal(shared_ptr<data::DecodeSignal> signal);
153 virtual void remove_decode_signal(shared_ptr<data::DecodeSignal> signal);
155 virtual void save_settings(QSettings &settings) const;
156 virtual void restore_settings(QSettings &settings);
162 void save_data_as_csv(unsigned int save_type) const;
165 void on_selected_decoder_changed(int index);
166 void on_hide_hidden_changed(bool checked);
167 void on_view_mode_changed(int index);
169 void on_signal_name_changed(const QString &name);
170 void on_signal_color_changed(const QColor &color);
171 void on_new_annotations();
173 void on_decoder_reset();
174 void on_decoder_stacked(void* decoder);
175 void on_decoder_removed(void* decoder);
177 void on_actionSave_triggered(QAction* action = nullptr);
179 void on_table_item_clicked(const QModelIndex& index);
180 void on_table_item_double_clicked(const QModelIndex& index);
181 void on_table_header_requested(const QPoint& pos);
182 void on_table_header_toggled(bool checked);
184 virtual void on_metadata_object_changed(MetadataObject* obj,
185 MetadataValueType value_type);
187 virtual void perform_delayed_view_update();
192 QComboBox* decoder_selector_;
193 QCheckBox* hide_hidden_cb_;
194 QComboBox* view_mode_selector_;
196 QToolButton* save_button_;
197 QAction* save_action_;
199 CustomTableView* table_view_;
200 AnnotationCollectionModel* model_;
201 CustomFilterProxyModel* filter_proxy_model_;
203 data::DecodeSignal* signal_;
204 const data::decode::Decoder* decoder_;
207 } // namespace tabular_decoder
211 #endif // PULSEVIEW_PV_VIEWS_TABULAR_DECODER_VIEW_HPP