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_TABULARDECODER_VIEW_HPP
21 #define PULSEVIEW_PV_VIEWS_TABULARDECODER_VIEW_HPP
27 #include <QToolButton>
29 #include "pv/globalsettings.hpp"
30 #include "pv/views/viewbase.hpp"
31 #include "pv/data/decodesignal.hpp"
38 namespace tabular_decoder {
40 // When adding an entry here, don't forget to update SaveTypeNames as well
44 SaveTypeCount // Indicates how many save types there are, must always be last
47 // When adding an entry here, don't forget to update ViewModeNames as well
52 ViewModeCount // Indicates how many save types there are, must always be last
55 extern const char* SaveTypeNames[SaveTypeCount];
56 extern const char* ViewModeNames[ViewModeCount];
59 class AnnotationCollectionModel : public QAbstractTableModel, public GlobalSettingsInterface
64 AnnotationCollectionModel(QObject* parent = nullptr);
66 QVariant data_from_ann(const Annotation* ann, int index) const;
67 QVariant data(const QModelIndex& index, int role) const override;
68 Qt::ItemFlags flags(const QModelIndex& index) const override;
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;
75 QModelIndex parent(const QModelIndex& index) const override;
77 int rowCount(const QModelIndex& parent_idx = QModelIndex()) const override;
78 int columnCount(const QModelIndex& parent_idx = QModelIndex()) const override;
80 void set_signal_and_segment(data::DecodeSignal* signal, uint32_t current_segment);
81 void set_hide_hidden(bool hide_hidden);
83 void update_annotations_without_hidden();
85 void on_setting_changed(const QString &key, const QVariant &value) override;
88 vector<QVariant> header_data_;
89 const deque<const Annotation*>* all_annotations_;
90 deque<const Annotation*> all_annotations_without_hidden_;
91 const deque<const Annotation*>* dataset_;
92 data::DecodeSignal* signal_;
93 uint32_t prev_segment_;
94 uint64_t prev_last_row_;
100 class QCustomTableView : public QTableView
105 QSize minimumSizeHint() const;
106 QSize sizeHint() const;
110 class View : public ViewBase
115 explicit View(Session &session, bool is_main_view=false, QMainWindow *parent = nullptr);
117 virtual ViewType get_type() const;
120 * Resets the view to its default state after construction. It does however
121 * not reset the signal bases or any other connections with the session.
123 virtual void reset_view_state();
125 virtual void clear_decode_signals();
126 virtual void add_decode_signal(shared_ptr<data::DecodeSignal> signal);
127 virtual void remove_decode_signal(shared_ptr<data::DecodeSignal> signal);
129 virtual void save_settings(QSettings &settings) const;
130 virtual void restore_settings(QSettings &settings);
136 void save_data_as_csv(unsigned int save_type) const;
139 void on_selected_decoder_changed(int index);
140 void on_hide_hidden_changed(bool checked);
141 void on_view_mode_changed(int index);
143 void on_signal_name_changed(const QString &name);
144 void on_signal_color_changed(const QColor &color);
145 void on_new_annotations();
147 void on_decoder_reset();
148 void on_decoder_stacked(void* decoder);
149 void on_decoder_removed(void* decoder);
151 void on_actionSave_triggered(QAction* action = nullptr);
153 void on_table_item_clicked(const QModelIndex& index);
154 void on_table_item_double_clicked(const QModelIndex& index);
155 void on_table_header_requested(const QPoint& pos);
156 void on_table_header_toggled(bool checked);
158 virtual void perform_delayed_view_update();
163 QComboBox* decoder_selector_;
164 QCheckBox* hide_hidden_cb_;
165 QComboBox* view_mode_selector_;
167 QToolButton* save_button_;
168 QAction* save_action_;
170 QCustomTableView* table_view_;
172 AnnotationCollectionModel* model_;
174 data::DecodeSignal* signal_;
175 const data::decode::Decoder* decoder_;
178 } // namespace tabular_decoder
182 #endif // PULSEVIEW_PV_VIEWS_TABULARDECODER_VIEW_HPP