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