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