]>
Commit | Line | Data |
---|---|---|
f2739bae 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_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> | |
8997f62a | 29 | #include <QVariant> |
f2739bae SA |
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, | |
1c521100 SA |
42 | // --- Types below will not be saved/restored --- |
43 | MetadataObjMousePos, | |
8997f62a | 44 | MetadataObjectTypeCount // Indicates how many metadata object types there are, must always be last |
f2739bae SA |
45 | }; |
46 | ||
47 | // When adding an entry here, don't forget to update MetadataValueNames as well | |
48 | enum MetadataValueType { | |
8997f62a SA |
49 | MetadataValueStartSample, // int64_t / qlonglong |
50 | MetadataValueEndSample, // int64_t / qlonglong | |
51 | MetadataValueText, | |
52 | MetadataValueTypeCount // Indicates how many metadata value types there are, must always be last | |
f2739bae SA |
53 | }; |
54 | ||
8997f62a SA |
55 | extern const char* MetadataObjectNames[MetadataObjectTypeCount]; |
56 | extern const char* MetadataValueNames[MetadataValueTypeCount]; | |
f2739bae SA |
57 | |
58 | ||
59 | class MetadataObjManager; | |
8997f62a | 60 | class MetadataObject; |
f2739bae SA |
61 | |
62 | ||
63 | class MetadataObjObserverInterface | |
64 | { | |
65 | public: | |
8997f62a SA |
66 | virtual void on_metadata_object_created(MetadataObject* obj); |
67 | virtual void on_metadata_object_deleted(MetadataObject* obj); | |
68 | virtual void on_metadata_object_changed(MetadataObject* obj, | |
69 | MetadataValueType value_type); | |
f2739bae SA |
70 | }; |
71 | ||
72 | ||
73 | class MetadataObject | |
74 | { | |
75 | public: | |
76 | MetadataObject(MetadataObjManager* obj_manager, uint32_t obj_id, MetadataObjectType obj_type); | |
77 | virtual ~MetadataObject() = default; | |
78 | ||
79 | virtual uint32_t id() const; | |
80 | virtual MetadataObjectType type() const; | |
81 | ||
8997f62a | 82 | virtual void set_value(MetadataValueType value_type, const QVariant& value); |
f2739bae SA |
83 | virtual QVariant value(MetadataValueType value_type) const; |
84 | private: | |
85 | MetadataObjManager* obj_manager_; | |
86 | uint32_t id_; | |
87 | MetadataObjectType type_; | |
88 | vector<QVariant> values_; | |
89 | }; | |
90 | ||
91 | ||
92 | class MetadataObjManager : public QObject | |
93 | { | |
94 | Q_OBJECT | |
95 | ||
96 | public: | |
97 | MetadataObject* create_object(MetadataObjectType obj_type); | |
98 | void delete_object(uint32_t obj_id); | |
99 | MetadataObject* find_object_by_type(MetadataObjectType obj_type); | |
100 | MetadataObject* object(uint32_t obj_id); | |
101 | ||
102 | void add_observer(MetadataObjObserverInterface *cb); | |
103 | void remove_observer(MetadataObjObserverInterface *cb); | |
104 | ||
105 | void save_objects(QSettings &settings) const; | |
106 | void restore_objects(QSettings &settings); | |
107 | ||
108 | void notify_observers(MetadataObject* obj, MetadataValueType changed_value); | |
109 | ||
110 | private: | |
111 | vector<MetadataObjObserverInterface*> callbacks_; | |
112 | deque<MetadataObject> objects_; | |
113 | }; | |
114 | ||
115 | ||
116 | } // namespace pv | |
117 | ||
118 | #endif // PULSEVIEW_PV_METADATA_OBJ_HPP |