]> sigrok.org Git - pulseview.git/blame - pv/views/tabular_decoder/view.hpp
Implement MainViewRange meta obj and tab_dec::ViewModeVisible
[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
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
88a25978 29#include "pv/globalsettings.hpp"
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
88a25978 60class AnnotationCollectionModel : public QAbstractTableModel, public GlobalSettingsInterface
24d69d27
SA
61{
62 Q_OBJECT
63
64public:
65 AnnotationCollectionModel(QObject* parent = nullptr);
66
85125b0f 67 QVariant data_from_ann(const Annotation* ann, int index) const;
24d69d27
SA
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
f54e68b0 81 void set_signal_and_segment(data::DecodeSignal* signal, uint32_t current_segment);
8997f62a 82 void set_sample_range(uint64_t start_sample, uint64_t end_sample);
86d4b8e3
SA
83 void set_hide_hidden(bool hide_hidden);
84
85 void update_annotations_without_hidden();
f54e68b0 86
88a25978
SA
87 void on_setting_changed(const QString &key, const QVariant &value) override;
88
24d69d27 89private:
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_;
88a25978 99 bool theme_is_dark_;
f54e68b0
SA
100};
101
102
103class QCustomTableView : public QTableView
104{
105 Q_OBJECT
106
107public:
108 QSize minimumSizeHint() const;
109 QSize sizeHint() const;
24d69d27
SA
110};
111
112
8997f62a 113class View : public ViewBase, public MetadataObjObserverInterface
24d69d27
SA
114{
115 Q_OBJECT
116
117public:
118 explicit View(Session &session, bool is_main_view=false, QMainWindow *parent = nullptr);
8997f62a 119 ~View();
24d69d27
SA
120
121 virtual ViewType get_type() const;
122
123 /**
124 * Resets the view to its default state after construction. It does however
125 * not reset the signal bases or any other connections with the session.
126 */
127 virtual void reset_view_state();
128
129 virtual void clear_decode_signals();
130 virtual void add_decode_signal(shared_ptr<data::DecodeSignal> signal);
131 virtual void remove_decode_signal(shared_ptr<data::DecodeSignal> signal);
132
133 virtual void save_settings(QSettings &settings) const;
134 virtual void restore_settings(QSettings &settings);
135
136private:
137 void reset_data();
138 void update_data();
139
be0f5903 140 void save_data_as_csv(unsigned int save_type) const;
24d69d27
SA
141
142private Q_SLOTS:
143 void on_selected_decoder_changed(int index);
86d4b8e3
SA
144 void on_hide_hidden_changed(bool checked);
145 void on_view_mode_changed(int index);
146
24d69d27 147 void on_signal_name_changed(const QString &name);
88a25978 148 void on_signal_color_changed(const QColor &color);
24d69d27
SA
149 void on_new_annotations();
150
02c87df7 151 void on_decoder_reset();
24d69d27
SA
152 void on_decoder_stacked(void* decoder);
153 void on_decoder_removed(void* decoder);
154
155 void on_actionSave_triggered(QAction* action = nullptr);
156
9a35b05d
SA
157 void on_table_item_clicked(const QModelIndex& index);
158 void on_table_item_double_clicked(const QModelIndex& index);
159 void on_table_header_requested(const QPoint& pos);
160 void on_table_header_toggled(bool checked);
161
8997f62a
SA
162 virtual void on_metadata_object_changed(MetadataObject* obj,
163 MetadataValueType value_type);
164
24d69d27
SA
165 virtual void perform_delayed_view_update();
166
167private:
168 QWidget* parent_;
169
f54e68b0 170 QComboBox* decoder_selector_;
86d4b8e3
SA
171 QCheckBox* hide_hidden_cb_;
172 QComboBox* view_mode_selector_;
24d69d27
SA
173
174 QToolButton* save_button_;
175 QAction* save_action_;
176
f54e68b0 177 QCustomTableView* table_view_;
24d69d27
SA
178
179 AnnotationCollectionModel* model_;
180
f54e68b0
SA
181 data::DecodeSignal* signal_;
182 const data::decode::Decoder* decoder_;
24d69d27
SA
183};
184
185} // namespace tabular_decoder
186} // namespace views
187} // namespace pv
188
189#endif // PULSEVIEW_PV_VIEWS_TABULARDECODER_VIEW_HPP