svcore  1.9
PropertyContainer.h
Go to the documentation of this file.
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 ColourDatabase indices
43  UnitsProperty, // unit from UnitDatabase, get/set unit id
44  InvalidProperty, // property not found!
45  };
46 
51  virtual PropertyList getProperties() const;
52 
56  virtual QString getPropertyLabel(const PropertyName &) const = 0;
57 
62  virtual PropertyType getPropertyType(const PropertyName &) const;
63 
67  virtual QString getPropertyIconName(const PropertyName &) const;
68 
76  virtual QString getPropertyGroupName(const PropertyName &) const;
77 
83  virtual int getPropertyRangeAndValue(const PropertyName &,
84  int *min, int *max, int *deflt) const;
85 
90  virtual QString getPropertyValueLabel(const PropertyName &,
91  int value) const;
92 
101  virtual RangeMapper *getNewPropertyRangeMapper(const PropertyName &) const;
102 
103  virtual QString getPropertyContainerName() const = 0;
104  virtual QString getPropertyContainerIconName() const = 0;
105 
106  virtual PlayParameters *getPlayParameters() { return 0; }
107 
108 signals:
110 
111 public slots:
118  virtual void setProperty(const PropertyName &, int value);
119 
125  virtual Command *getSetPropertyCommand(const PropertyName &, int value);
126 
142  virtual void setPropertyFuzzy(QString nameString, QString valueString);
143 
147  virtual Command *getSetPropertyCommand(QString nameString, QString valueString);
148 
149 protected:
150 
152  {
153  public:
155  virtual ~SetPropertyCommand() { }
156 
157  virtual void execute();
158  virtual void unexecute();
159  virtual QString getName() const;
160 
161  protected:
164  int m_value;
166  };
167 
168  virtual bool convertPropertyStrings(QString nameString, QString valueString,
169  PropertyName &name, int &value);
170 };
171 
172 #endif
void propertyChanged(PropertyContainer::PropertyName)
virtual PropertyType getPropertyType(const PropertyName &) const
Return the type of the given property, or InvalidProperty if the property is not supported on this co...
virtual bool convertPropertyStrings(QString nameString, QString valueString, PropertyName &name, int &value)
virtual RangeMapper * getNewPropertyRangeMapper(const PropertyName &) const
If the given property is a RangeProperty, return a new RangeMapper object mapping its integer range o...
virtual QString getPropertyValueLabel(const PropertyName &, int value) const
If the given property is a ValueProperty, return the display label to be used for the given value for...
virtual QString getPropertyContainerName() const =0
virtual PropertyList getProperties() const
Get a list of the names of all the supported properties on this container.
virtual void setPropertyFuzzy(QString nameString, QString valueString)
Set a property using a fuzzy match.
virtual QString getPropertyLabel(const PropertyName &) const =0
Return the human-readable (and i18n'ised) name of a property.
virtual QString getPropertyGroupName(const PropertyName &) const
If this property has something in common with other properties on this container, return a name that ...
virtual Command * getSetPropertyCommand(const PropertyName &, int value)
Obtain a command that sets the given property, which can be added to the command history for undo/red...
virtual QString getPropertyIconName(const PropertyName &) const
Return an icon for the property, if any.
SetPropertyCommand(PropertyContainer *pc, const PropertyName &pn, int)
virtual int getPropertyRangeAndValue(const PropertyName &, int *min, int *max, int *deflt) const
Return the minimum and maximum values for the given property and its current value in this container.
virtual ~PropertyContainer()
virtual void setProperty(const PropertyName &, int value)
Set a property.
virtual PlayParameters * getPlayParameters()
std::vector< PropertyName > PropertyList
virtual QString getPropertyContainerIconName() const =0