]> sigrok.org Git - pulseview.git/blame - pv/views/tabular_decoder/view.hpp
DecodeSignal: Sort annotations by start sample and length
[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>
24#include <QComboBox>
25#include <QTableView>
26#include <QToolButton>
27
88a25978 28#include "pv/globalsettings.hpp"
24d69d27
SA
29#include "pv/views/viewbase.hpp"
30#include "pv/data/decodesignal.hpp"
31
32namespace pv {
33class Session;
34
35namespace views {
36
37namespace tabular_decoder {
38
88a25978 39class AnnotationCollectionModel : public QAbstractTableModel, public GlobalSettingsInterface
24d69d27
SA
40{
41 Q_OBJECT
42
43public:
44 AnnotationCollectionModel(QObject* parent = nullptr);
45
46 QVariant data(const QModelIndex& index, int role) const override;
47 Qt::ItemFlags flags(const QModelIndex& index) const override;
48
49 QVariant headerData(int section, Qt::Orientation orientation,
50 int role = Qt::DisplayRole) const override;
51 QModelIndex index(int row, int column,
52 const QModelIndex& parent_idx = QModelIndex()) const override;
53
54 QModelIndex parent(const QModelIndex& index) const override;
55
56 int rowCount(const QModelIndex& parent_idx = QModelIndex()) const override;
57 int columnCount(const QModelIndex& parent_idx = QModelIndex()) const override;
58
f54e68b0
SA
59 void set_signal_and_segment(data::DecodeSignal* signal, uint32_t current_segment);
60
88a25978
SA
61 void on_setting_changed(const QString &key, const QVariant &value) override;
62
24d69d27 63private:
f54e68b0
SA
64 vector<QVariant> header_data_;
65 const deque<const Annotation*>* all_annotations_;
66 uint32_t prev_segment_;
67 uint64_t prev_last_row_;
88a25978 68 bool theme_is_dark_;
f54e68b0
SA
69};
70
71
72class QCustomTableView : public QTableView
73{
74 Q_OBJECT
75
76public:
77 QSize minimumSizeHint() const;
78 QSize sizeHint() const;
24d69d27
SA
79};
80
81
82class View : public ViewBase
83{
84 Q_OBJECT
85
86public:
87 explicit View(Session &session, bool is_main_view=false, QMainWindow *parent = nullptr);
88
89 virtual ViewType get_type() const;
90
91 /**
92 * Resets the view to its default state after construction. It does however
93 * not reset the signal bases or any other connections with the session.
94 */
95 virtual void reset_view_state();
96
97 virtual void clear_decode_signals();
98 virtual void add_decode_signal(shared_ptr<data::DecodeSignal> signal);
99 virtual void remove_decode_signal(shared_ptr<data::DecodeSignal> signal);
100
101 virtual void save_settings(QSettings &settings) const;
102 virtual void restore_settings(QSettings &settings);
103
104private:
105 void reset_data();
106 void update_data();
107
108 void save_data() const;
109
110private Q_SLOTS:
111 void on_selected_decoder_changed(int index);
112 void on_signal_name_changed(const QString &name);
88a25978 113 void on_signal_color_changed(const QColor &color);
24d69d27
SA
114 void on_new_annotations();
115
02c87df7 116 void on_decoder_reset();
24d69d27
SA
117 void on_decoder_stacked(void* decoder);
118 void on_decoder_removed(void* decoder);
119
120 void on_actionSave_triggered(QAction* action = nullptr);
121
122 virtual void perform_delayed_view_update();
123
124private:
125 QWidget* parent_;
126
f54e68b0 127 QComboBox* decoder_selector_;
24d69d27
SA
128
129 QToolButton* save_button_;
130 QAction* save_action_;
131
f54e68b0 132 QCustomTableView* table_view_;
24d69d27
SA
133
134 AnnotationCollectionModel* model_;
135
f54e68b0
SA
136 data::DecodeSignal* signal_;
137 const data::decode::Decoder* decoder_;
138 bool updating_data_;
24d69d27
SA
139};
140
141} // namespace tabular_decoder
142} // namespace views
143} // namespace pv
144
145#endif // PULSEVIEW_PV_VIEWS_TABULARDECODER_VIEW_HPP