]> sigrok.org Git - pulseview.git/blob - pv/metadata_obj.hpp
TabularDecView: Remove unnecessary stuff
[pulseview.git] / pv / metadata_obj.hpp
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_METADATA_OBJ_HPP
21 #define PULSEVIEW_PV_METADATA_OBJ_HPP
22
23 #include <deque>
24 #include <vector>
25
26 #include <QObject>
27 #include <QSettings>
28 #include <QString>
29 #include <QVariant>
30
31 using std::deque;
32 using std::vector;
33
34 namespace pv {
35
36
37 // When adding an entry here, don't forget to update MetadataObjectNames as well
38 enum MetadataObjectType {
39         MetadataObjMainViewRange,
40         MetadataObjSelection,
41         MetadataObjTimeMarker,
42         MetadataObjectTypeCount  // Indicates how many metadata object types there are, must always be last
43 };
44
45 // When adding an entry here, don't forget to update MetadataValueNames as well
46 enum MetadataValueType {
47         MetadataValueStartSample,  // int64_t / qlonglong
48         MetadataValueEndSample,    // int64_t / qlonglong
49         MetadataValueText,
50         MetadataValueTypeCount  // Indicates how many metadata value types there are, must always be last
51 };
52
53 extern const char* MetadataObjectNames[MetadataObjectTypeCount];
54 extern const char* MetadataValueNames[MetadataValueTypeCount];
55
56
57 class MetadataObjManager;
58 class MetadataObject;
59
60
61 class MetadataObjObserverInterface
62 {
63 public:
64         virtual void on_metadata_object_created(MetadataObject* obj);
65         virtual void on_metadata_object_deleted(MetadataObject* obj);
66         virtual void on_metadata_object_changed(MetadataObject* obj,
67                 MetadataValueType value_type);
68 };
69
70
71 class MetadataObject
72 {
73 public:
74         MetadataObject(MetadataObjManager* obj_manager, uint32_t obj_id, MetadataObjectType obj_type);
75         virtual ~MetadataObject() = default;
76
77         virtual uint32_t id() const;
78         virtual MetadataObjectType type() const;
79
80         virtual void set_value(MetadataValueType value_type, const QVariant& value);
81         virtual QVariant value(MetadataValueType value_type) const;
82 private:
83         MetadataObjManager* obj_manager_;
84         uint32_t id_;
85         MetadataObjectType type_;
86         vector<QVariant> values_;
87 };
88
89
90 class MetadataObjManager : public QObject
91 {
92         Q_OBJECT
93
94 public:
95         MetadataObject* create_object(MetadataObjectType obj_type);
96         void delete_object(uint32_t obj_id);
97         MetadataObject* find_object_by_type(MetadataObjectType obj_type);
98         MetadataObject* object(uint32_t obj_id);
99
100         void add_observer(MetadataObjObserverInterface *cb);
101         void remove_observer(MetadataObjObserverInterface *cb);
102
103         void save_objects(QSettings &settings) const;
104         void restore_objects(QSettings &settings);
105
106         void notify_observers(MetadataObject* obj, MetadataValueType changed_value);
107
108 private:
109         vector<MetadataObjObserverInterface*> callbacks_;
110         deque<MetadataObject> objects_;
111 };
112
113
114 } // namespace pv
115
116 #endif // PULSEVIEW_PV_METADATA_OBJ_HPP