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@52
|
7 This file copyright 2006 Chris Cannam.
|
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@0
|
16 #ifndef _PROPERTY_CONTAINER_H_
|
Chris@0
|
17 #define _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@0
|
24
|
Chris@28
|
25 class PlayParameters;
|
Chris@190
|
26 class RangeMapper;
|
Chris@0
|
27
|
Chris@29
|
28 class PropertyContainer : public QObject
|
Chris@0
|
29 {
|
Chris@29
|
30 Q_OBJECT
|
Chris@29
|
31
|
Chris@0
|
32 public:
|
Chris@27
|
33 virtual ~PropertyContainer() { }
|
Chris@27
|
34
|
Chris@0
|
35 typedef QString PropertyName;
|
Chris@0
|
36 typedef std::vector<PropertyName> PropertyList;
|
Chris@0
|
37
|
Chris@0
|
38 enum PropertyType {
|
Chris@0
|
39 ToggleProperty, // on or off
|
Chris@0
|
40 RangeProperty, // range of integers
|
Chris@0
|
41 ValueProperty, // range of integers given string labels
|
Chris@0
|
42 ColourProperty, // colours, get/set as qRgb
|
Chris@116
|
43 UnitsProperty, // unit from UnitDatabase, get/set unit id
|
Chris@0
|
44 InvalidProperty, // property not found!
|
Chris@0
|
45 };
|
Chris@0
|
46
|
Chris@0
|
47 /**
|
Chris@0
|
48 * Get a list of the names of all the supported properties on this
|
Chris@94
|
49 * container. These should be fixed (i.e. not internationalized).
|
Chris@0
|
50 */
|
Chris@0
|
51 virtual PropertyList getProperties() const;
|
Chris@0
|
52
|
Chris@0
|
53 /**
|
Chris@94
|
54 * Return the human-readable (and i18n'ised) name of a property.
|
Chris@94
|
55 */
|
Chris@94
|
56 virtual QString getPropertyLabel(const PropertyName &) const = 0;
|
Chris@94
|
57
|
Chris@94
|
58 /**
|
Chris@0
|
59 * Return the type of the given property, or InvalidProperty if
|
Chris@0
|
60 * the property is not supported on this container.
|
Chris@0
|
61 */
|
Chris@0
|
62 virtual PropertyType getPropertyType(const PropertyName &) const;
|
Chris@0
|
63
|
Chris@0
|
64 /**
|
Chris@0
|
65 * If this property has something in common with other properties
|
Chris@0
|
66 * on this container, return a name that can be used to group them
|
Chris@0
|
67 * (in order to save screen space, for example). e.g. "Window
|
Chris@0
|
68 * Type" and "Window Size" might both have a group name of "Window".
|
Chris@0
|
69 * If this property is not groupable, return the empty string.
|
Chris@0
|
70 */
|
Chris@0
|
71 virtual QString getPropertyGroupName(const PropertyName &) const;
|
Chris@0
|
72
|
Chris@0
|
73 /**
|
Chris@0
|
74 * Return the minimum and maximum values for the given property
|
Chris@0
|
75 * and its current value in this container. Min and/or max may be
|
Chris@0
|
76 * passed as NULL if their values are not required.
|
Chris@0
|
77 */
|
Chris@0
|
78 virtual int getPropertyRangeAndValue(const PropertyName &,
|
Chris@0
|
79 int *min, int *max) const;
|
Chris@0
|
80
|
Chris@0
|
81 /**
|
Chris@0
|
82 * If the given property is a ValueProperty, return the display
|
Chris@0
|
83 * label to be used for the given value for that property.
|
Chris@0
|
84 */
|
Chris@0
|
85 virtual QString getPropertyValueLabel(const PropertyName &,
|
Chris@0
|
86 int value) const;
|
Chris@0
|
87
|
Chris@190
|
88 /**
|
Chris@190
|
89 * If the given property is a RangeProperty, return a new
|
Chris@190
|
90 * RangeMapper object mapping its integer range onto an underlying
|
Chris@190
|
91 * floating point value range for human-intelligible display, if
|
Chris@190
|
92 * appropriate. The RangeMapper should be allocated with new, and
|
Chris@190
|
93 * the caller takes responsibility for deleting it. Return NULL
|
Chris@190
|
94 * (as in the default implementation) if there is no such mapping.
|
Chris@190
|
95 */
|
Chris@190
|
96 virtual RangeMapper *getNewPropertyRangeMapper(const PropertyName &) const;
|
Chris@190
|
97
|
Chris@29
|
98 virtual QString getPropertyContainerName() const = 0;
|
Chris@29
|
99 virtual QString getPropertyContainerIconName() const = 0;
|
Chris@29
|
100
|
Chris@29
|
101 virtual PlayParameters *getPlayParameters() { return 0; }
|
Chris@29
|
102
|
Chris@29
|
103 signals:
|
Chris@141
|
104 void propertyChanged(PropertyContainer::PropertyName);
|
Chris@29
|
105
|
Chris@29
|
106 public slots:
|
Chris@0
|
107 /**
|
Chris@0
|
108 * Set a property. This is used for all property types. For
|
Chris@0
|
109 * boolean properties, zero is false and non-zero true; for
|
Chris@0
|
110 * colours, the integer value should be treated as a qRgb.
|
Chris@0
|
111 */
|
Chris@0
|
112 virtual void setProperty(const PropertyName &, int value);
|
Chris@46
|
113
|
Chris@46
|
114 /**
|
Chris@46
|
115 * Set a property using a command, supporting undo and redo.
|
Chris@136
|
116 * The default implementation should work for most subclasses.
|
Chris@46
|
117 */
|
Chris@46
|
118 virtual void setPropertyWithCommand(const PropertyName &, int value);
|
Chris@46
|
119
|
Chris@199
|
120 /**
|
Chris@199
|
121 * Set a property using a fuzzy match. Compare nameString with
|
Chris@199
|
122 * the property labels and underlying names, and if it matches one
|
Chris@199
|
123 * (with preference given to labels), try to convert valueString
|
Chris@199
|
124 * appropriately and set it. The valueString should contain a
|
Chris@199
|
125 * value label for value properties, a mapped value for range
|
Chris@199
|
126 * properties, "on" or "off" for toggle properties, a colour or
|
Chris@199
|
127 * unit name, or the underlying integer value for the property.
|
Chris@199
|
128 *
|
Chris@199
|
129 * Note that as property and value labels may be translatable, the
|
Chris@199
|
130 * results of this function may vary by locale. It is intended
|
Chris@199
|
131 * for handling user-originated strings, _not_ persistent storage.
|
Chris@199
|
132 *
|
Chris@199
|
133 * The default implementation should work for most subclasses.
|
Chris@199
|
134 */
|
Chris@199
|
135 virtual void setProperty(QString nameString, QString valueString);
|
Chris@199
|
136
|
Chris@199
|
137 /**
|
Chris@199
|
138 * As above, but using a command.
|
Chris@199
|
139 */
|
Chris@199
|
140 virtual void setPropertyWithCommand(QString nameString, QString valueString);
|
Chris@199
|
141
|
Chris@46
|
142 protected:
|
Chris@46
|
143
|
Chris@46
|
144 class SetPropertyCommand : public Command
|
Chris@46
|
145 {
|
Chris@46
|
146 public:
|
Chris@46
|
147 SetPropertyCommand(PropertyContainer *pc, const PropertyName &pn, int);
|
Chris@46
|
148 virtual ~SetPropertyCommand() { }
|
Chris@46
|
149
|
Chris@46
|
150 virtual void execute();
|
Chris@46
|
151 virtual void unexecute();
|
Chris@46
|
152 virtual QString getName() const;
|
Chris@46
|
153
|
Chris@46
|
154 protected:
|
Chris@46
|
155 PropertyContainer *m_pc;
|
Chris@46
|
156 PropertyName m_pn;
|
Chris@46
|
157 int m_value;
|
Chris@46
|
158 int m_oldValue;
|
Chris@46
|
159 };
|
Chris@199
|
160
|
Chris@199
|
161 virtual bool convertPropertyStrings(QString nameString, QString valueString,
|
Chris@199
|
162 PropertyName &name, int &value);
|
Chris@0
|
163 };
|
Chris@0
|
164
|
Chris@0
|
165 #endif
|