Chris@49
|
1 /* -*- c-basic-offset: 4 indent-tabs-mode: nil -*- vi:set ts=8 sts=4 sw=4: */
|
Chris@0
|
2
|
Chris@0
|
3 /*
|
Chris@52
|
4 Sonic Visualiser
|
Chris@52
|
5 An audio file viewer and annotation editor.
|
Chris@52
|
6 Centre for Digital Music, Queen Mary, University of London.
|
Chris@202
|
7 This file copyright 2006 Chris Cannam and QMUL.
|
Chris@0
|
8
|
Chris@52
|
9 This program is free software; you can redistribute it and/or
|
Chris@52
|
10 modify it under the terms of the GNU General Public License as
|
Chris@52
|
11 published by the Free Software Foundation; either version 2 of the
|
Chris@52
|
12 License, or (at your option) any later version. See the file
|
Chris@52
|
13 COPYING included with this distribution for more information.
|
Chris@0
|
14 */
|
Chris@0
|
15
|
Chris@1331
|
16 #ifndef SV_PROPERTY_CONTAINER_H
|
Chris@1331
|
17 #define SV_PROPERTY_CONTAINER_H
|
Chris@0
|
18
|
Chris@46
|
19 #include "Command.h"
|
Chris@46
|
20
|
Chris@0
|
21 #include <QString>
|
Chris@0
|
22 #include <QObject>
|
Chris@0
|
23 #include <vector>
|
Chris@1751
|
24 #include <memory>
|
Chris@0
|
25
|
Chris@28
|
26 class PlayParameters;
|
Chris@190
|
27 class RangeMapper;
|
Chris@0
|
28
|
Chris@29
|
29 class PropertyContainer : public QObject
|
Chris@0
|
30 {
|
Chris@29
|
31 Q_OBJECT
|
Chris@29
|
32
|
Chris@0
|
33 public:
|
Chris@27
|
34 virtual ~PropertyContainer() { }
|
Chris@27
|
35
|
Chris@0
|
36 typedef QString PropertyName;
|
Chris@0
|
37 typedef std::vector<PropertyName> PropertyList;
|
Chris@0
|
38
|
Chris@0
|
39 enum PropertyType {
|
Chris@1429
|
40 ToggleProperty, // on or off
|
Chris@1429
|
41 RangeProperty, // range of integers
|
Chris@1429
|
42 ValueProperty, // range of integers given string labels
|
Chris@1429
|
43 ColourProperty, // colours, get/set as ColourDatabase indices
|
Chris@1331
|
44 ColourMapProperty, // colour maps, get/set as ColourMapper::StandardMap enum
|
Chris@116
|
45 UnitsProperty, // unit from UnitDatabase, get/set unit id
|
Chris@1429
|
46 InvalidProperty, // property not found!
|
Chris@0
|
47 };
|
Chris@0
|
48
|
Chris@0
|
49 /**
|
Chris@0
|
50 * Get a list of the names of all the supported properties on this
|
Chris@94
|
51 * container. These should be fixed (i.e. not internationalized).
|
Chris@0
|
52 */
|
Chris@0
|
53 virtual PropertyList getProperties() const;
|
Chris@0
|
54
|
Chris@0
|
55 /**
|
Chris@94
|
56 * Return the human-readable (and i18n'ised) name of a property.
|
Chris@94
|
57 */
|
Chris@94
|
58 virtual QString getPropertyLabel(const PropertyName &) const = 0;
|
Chris@94
|
59
|
Chris@94
|
60 /**
|
Chris@0
|
61 * Return the type of the given property, or InvalidProperty if
|
Chris@0
|
62 * the property is not supported on this container.
|
Chris@0
|
63 */
|
Chris@0
|
64 virtual PropertyType getPropertyType(const PropertyName &) const;
|
Chris@0
|
65
|
Chris@0
|
66 /**
|
Chris@340
|
67 * Return an icon for the property, if any.
|
Chris@340
|
68 */
|
Chris@340
|
69 virtual QString getPropertyIconName(const PropertyName &) const;
|
Chris@340
|
70
|
Chris@340
|
71 /**
|
Chris@0
|
72 * If this property has something in common with other properties
|
Chris@0
|
73 * on this container, return a name that can be used to group them
|
Chris@0
|
74 * (in order to save screen space, for example). e.g. "Window
|
Chris@0
|
75 * Type" and "Window Size" might both have a group name of "Window".
|
Chris@0
|
76 * If this property is not groupable, return the empty string.
|
Chris@0
|
77 */
|
Chris@0
|
78 virtual QString getPropertyGroupName(const PropertyName &) const;
|
Chris@0
|
79
|
Chris@0
|
80 /**
|
Chris@0
|
81 * Return the minimum and maximum values for the given property
|
Chris@0
|
82 * and its current value in this container. Min and/or max may be
|
Chris@0
|
83 * passed as NULL if their values are not required.
|
Chris@0
|
84 */
|
Chris@0
|
85 virtual int getPropertyRangeAndValue(const PropertyName &,
|
Chris@1429
|
86 int *min, int *max, int *deflt) const;
|
Chris@0
|
87
|
Chris@0
|
88 /**
|
Chris@0
|
89 * If the given property is a ValueProperty, return the display
|
Chris@0
|
90 * label to be used for the given value for that property.
|
Chris@0
|
91 */
|
Chris@0
|
92 virtual QString getPropertyValueLabel(const PropertyName &,
|
Chris@1429
|
93 int value) const;
|
Chris@0
|
94
|
Chris@190
|
95 /**
|
Chris@984
|
96 * If the given property is a ValueProperty, return the icon to be
|
Chris@984
|
97 * used for the given value for that property, if any.
|
Chris@984
|
98 */
|
Chris@984
|
99 virtual QString getPropertyValueIconName(const PropertyName &,
|
Chris@984
|
100 int value) const;
|
Chris@984
|
101
|
Chris@984
|
102 /**
|
Chris@190
|
103 * If the given property is a RangeProperty, return a new
|
Chris@190
|
104 * RangeMapper object mapping its integer range onto an underlying
|
Chris@190
|
105 * floating point value range for human-intelligible display, if
|
Chris@190
|
106 * appropriate. The RangeMapper should be allocated with new, and
|
Chris@190
|
107 * the caller takes responsibility for deleting it. Return NULL
|
Chris@190
|
108 * (as in the default implementation) if there is no such mapping.
|
Chris@190
|
109 */
|
Chris@190
|
110 virtual RangeMapper *getNewPropertyRangeMapper(const PropertyName &) const;
|
Chris@190
|
111
|
Chris@29
|
112 virtual QString getPropertyContainerName() const = 0;
|
Chris@29
|
113 virtual QString getPropertyContainerIconName() const = 0;
|
Chris@29
|
114
|
Chris@1751
|
115 /**
|
Chris@1751
|
116 * Return the play parameters for this layer, if any. The return
|
Chris@1751
|
117 * value is a shared_ptr that, if not null, can be passed to
|
Chris@1751
|
118 * e.g. PlayParameterRepository::EditCommand to change the
|
Chris@1751
|
119 * parameters.
|
Chris@1751
|
120 */
|
Chris@1751
|
121 virtual std::shared_ptr<PlayParameters> getPlayParameters() { return {}; }
|
Chris@29
|
122
|
Chris@29
|
123 signals:
|
Chris@141
|
124 void propertyChanged(PropertyContainer::PropertyName);
|
Chris@224
|
125
|
Chris@29
|
126 public slots:
|
Chris@0
|
127 /**
|
Chris@0
|
128 * Set a property. This is used for all property types. For
|
Chris@0
|
129 * boolean properties, zero is false and non-zero true; for
|
Chris@277
|
130 * colours, the integer value is an index into the colours in the
|
Chris@277
|
131 * global ColourDatabase.
|
Chris@0
|
132 */
|
Chris@0
|
133 virtual void setProperty(const PropertyName &, int value);
|
Chris@46
|
134
|
Chris@46
|
135 /**
|
Chris@387
|
136 * Obtain a command that sets the given property, which can be
|
Chris@387
|
137 * added to the command history for undo/redo. Returns NULL
|
Chris@387
|
138 * if the property is already set to the given value.
|
Chris@46
|
139 */
|
Chris@387
|
140 virtual Command *getSetPropertyCommand(const PropertyName &, int value);
|
Chris@46
|
141
|
Chris@199
|
142 /**
|
Chris@199
|
143 * Set a property using a fuzzy match. Compare nameString with
|
Chris@199
|
144 * the property labels and underlying names, and if it matches one
|
Chris@199
|
145 * (with preference given to labels), try to convert valueString
|
Chris@199
|
146 * appropriately and set it. The valueString should contain a
|
Chris@199
|
147 * value label for value properties, a mapped value for range
|
Chris@199
|
148 * properties, "on" or "off" for toggle properties, a colour or
|
Chris@199
|
149 * unit name, or the underlying integer value for the property.
|
Chris@199
|
150 *
|
Chris@199
|
151 * Note that as property and value labels may be translatable, the
|
Chris@199
|
152 * results of this function may vary by locale. It is intended
|
Chris@199
|
153 * for handling user-originated strings, _not_ persistent storage.
|
Chris@199
|
154 *
|
Chris@199
|
155 * The default implementation should work for most subclasses.
|
Chris@199
|
156 */
|
Chris@528
|
157 virtual void setPropertyFuzzy(QString nameString, QString valueString);
|
Chris@199
|
158
|
Chris@199
|
159 /**
|
Chris@387
|
160 * As above, but returning a command.
|
Chris@199
|
161 */
|
Chris@387
|
162 virtual Command *getSetPropertyCommand(QString nameString, QString valueString);
|
Chris@199
|
163
|
Chris@46
|
164 protected:
|
Chris@46
|
165
|
Chris@46
|
166 class SetPropertyCommand : public Command
|
Chris@46
|
167 {
|
Chris@46
|
168 public:
|
Chris@1429
|
169 SetPropertyCommand(PropertyContainer *pc, const PropertyName &pn, int);
|
Chris@1429
|
170 virtual ~SetPropertyCommand() { }
|
Chris@46
|
171
|
Chris@1580
|
172 void execute() override;
|
Chris@1580
|
173 void unexecute() override;
|
Chris@1580
|
174 QString getName() const override;
|
Chris@46
|
175
|
Chris@46
|
176 protected:
|
Chris@1429
|
177 PropertyContainer *m_pc;
|
Chris@1429
|
178 PropertyName m_pn;
|
Chris@1429
|
179 int m_value;
|
Chris@1429
|
180 int m_oldValue;
|
Chris@46
|
181 };
|
Chris@199
|
182
|
Chris@199
|
183 virtual bool convertPropertyStrings(QString nameString, QString valueString,
|
Chris@199
|
184 PropertyName &name, int &value);
|
Chris@0
|
185 };
|
Chris@0
|
186
|
Chris@0
|
187 #endif
|