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
26 #include <QToolButton>
28 #include "pv/views/viewbase.hpp"
29 #include "pv/data/decodesignal.hpp"
36 namespace tabular_decoder {
38 class AnnotationCollectionItem
41 AnnotationCollectionItem(const vector<QVariant>& data,
42 shared_ptr<AnnotationCollectionItem> parent = nullptr);
44 void appendSubItem(shared_ptr<AnnotationCollectionItem> item);
46 shared_ptr<AnnotationCollectionItem> subItem(int row) const;
47 shared_ptr<AnnotationCollectionItem> parent() const;
48 shared_ptr<AnnotationCollectionItem> findSubItem(const QVariant& value, int column);
50 int subItemCount() const;
51 int columnCount() const;
53 QVariant data(int column) const;
56 vector< shared_ptr<AnnotationCollectionItem> > subItems_;
57 vector<QVariant> data_;
58 shared_ptr<AnnotationCollectionItem> parent_;
62 class AnnotationCollectionModel : public QAbstractItemModel
67 AnnotationCollectionModel(QObject* parent = nullptr);
69 QVariant data(const QModelIndex& index, int role) const override;
70 Qt::ItemFlags flags(const QModelIndex& index) const override;
72 QVariant headerData(int section, Qt::Orientation orientation,
73 int role = Qt::DisplayRole) const override;
74 QModelIndex index(int row, int column,
75 const QModelIndex& parent_idx = QModelIndex()) const override;
77 QModelIndex parent(const QModelIndex& index) const override;
79 int rowCount(const QModelIndex& parent_idx = QModelIndex()) const override;
80 int columnCount(const QModelIndex& parent_idx = QModelIndex()) const override;
83 shared_ptr<AnnotationCollectionItem> root_;
87 class View : public ViewBase
92 explicit View(Session &session, bool is_main_view=false, QMainWindow *parent = nullptr);
94 virtual ViewType get_type() const;
97 * Resets the view to its default state after construction. It does however
98 * not reset the signal bases or any other connections with the session.
100 virtual void reset_view_state();
102 virtual void clear_decode_signals();
103 virtual void add_decode_signal(shared_ptr<data::DecodeSignal> signal);
104 virtual void remove_decode_signal(shared_ptr<data::DecodeSignal> signal);
106 virtual void save_settings(QSettings &settings) const;
107 virtual void restore_settings(QSettings &settings);
113 void save_data() const;
116 void on_selected_decoder_changed(int index);
117 void on_signal_name_changed(const QString &name);
118 void on_new_annotations();
120 void on_decoder_stacked(void* decoder);
121 void on_decoder_removed(void* decoder);
123 void on_actionSave_triggered(QAction* action = nullptr);
125 virtual void perform_delayed_view_update();
130 QComboBox *decoder_selector_;
132 QToolButton* save_button_;
133 QAction* save_action_;
135 QTableView* table_view_;
137 AnnotationCollectionModel* model_;
139 data::DecodeSignal *signal_;
140 const data::decode::Decoder *decoder_;
143 } // namespace tabular_decoder
147 #endif // PULSEVIEW_PV_VIEWS_TABULARDECODER_VIEW_HPP