X-Git-Url: https://sigrok.org/gitweb/?a=blobdiff_plain;f=pv%2Fviews%2Ftabular_decoder%2Fview.hpp;fp=pv%2Fviews%2Ftabular_decoder%2Fview.hpp;h=83a4549161bed2d391312aa8db669317ef9be264;hb=24d69d27584c7adec70bc0d6db764a3db04fce3c;hp=0000000000000000000000000000000000000000;hpb=7d5a9c3e79cbfc7640365894c79ef5b6caaa1631;p=pulseview.git diff --git a/pv/views/tabular_decoder/view.hpp b/pv/views/tabular_decoder/view.hpp new file mode 100644 index 00000000..83a45491 --- /dev/null +++ b/pv/views/tabular_decoder/view.hpp @@ -0,0 +1,147 @@ +/* + * This file is part of the PulseView project. + * + * Copyright (C) 2020 Soeren Apel + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, see . + */ + +#ifndef PULSEVIEW_PV_VIEWS_TABULARDECODER_VIEW_HPP +#define PULSEVIEW_PV_VIEWS_TABULARDECODER_VIEW_HPP + +#include +#include +#include +#include + +#include "pv/views/viewbase.hpp" +#include "pv/data/decodesignal.hpp" + +namespace pv { +class Session; + +namespace views { + +namespace tabular_decoder { + +class AnnotationCollectionItem +{ +public: + AnnotationCollectionItem(const vector& data, + shared_ptr parent = nullptr); + + void appendSubItem(shared_ptr item); + + shared_ptr subItem(int row) const; + shared_ptr parent() const; + shared_ptr findSubItem(const QVariant& value, int column); + + int subItemCount() const; + int columnCount() const; + int row() const; + QVariant data(int column) const; + +private: + vector< shared_ptr > subItems_; + vector data_; + shared_ptr parent_; +}; + + +class AnnotationCollectionModel : public QAbstractItemModel +{ + Q_OBJECT + +public: + AnnotationCollectionModel(QObject* parent = nullptr); + + QVariant data(const QModelIndex& index, int role) const override; + Qt::ItemFlags flags(const QModelIndex& index) const override; + + QVariant headerData(int section, Qt::Orientation orientation, + int role = Qt::DisplayRole) const override; + QModelIndex index(int row, int column, + const QModelIndex& parent_idx = QModelIndex()) const override; + + QModelIndex parent(const QModelIndex& index) const override; + + int rowCount(const QModelIndex& parent_idx = QModelIndex()) const override; + int columnCount(const QModelIndex& parent_idx = QModelIndex()) const override; + +private: + shared_ptr root_; +}; + + +class View : public ViewBase +{ + Q_OBJECT + +public: + explicit View(Session &session, bool is_main_view=false, QMainWindow *parent = nullptr); + + virtual ViewType get_type() const; + + /** + * Resets the view to its default state after construction. It does however + * not reset the signal bases or any other connections with the session. + */ + virtual void reset_view_state(); + + virtual void clear_decode_signals(); + virtual void add_decode_signal(shared_ptr signal); + virtual void remove_decode_signal(shared_ptr signal); + + virtual void save_settings(QSettings &settings) const; + virtual void restore_settings(QSettings &settings); + +private: + void reset_data(); + void update_data(); + + void save_data() const; + +private Q_SLOTS: + void on_selected_decoder_changed(int index); + void on_signal_name_changed(const QString &name); + void on_new_annotations(); + + void on_decoder_stacked(void* decoder); + void on_decoder_removed(void* decoder); + + void on_actionSave_triggered(QAction* action = nullptr); + + virtual void perform_delayed_view_update(); + +private: + QWidget* parent_; + + QComboBox *decoder_selector_; + + QToolButton* save_button_; + QAction* save_action_; + + QTableView* table_view_; + + AnnotationCollectionModel* model_; + + data::DecodeSignal *signal_; + const data::decode::Decoder *decoder_; +}; + +} // namespace tabular_decoder +} // namespace views +} // namespace pv + +#endif // PULSEVIEW_PV_VIEWS_TABULARDECODER_VIEW_HPP