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 SV_PROPERTY_CONTAINER_H
17 #define SV_PROPERTY_CONTAINER_H
18 
19 #include "Command.h"
20 
21 #include <QString>
22 #include <QObject>
23 #include <vector>
24 #include <memory>
25 
26 class PlayParameters;
27 class RangeMapper;
28 
29 class PropertyContainer : public QObject
30 {
31  Q_OBJECT
32 
33 public:
34  virtual ~PropertyContainer() { }
35 
36  typedef QString PropertyName;
37  typedef std::vector<PropertyName> PropertyList;
38 
39  enum PropertyType {
40  ToggleProperty, // on or off
41  RangeProperty, // range of integers
42  ValueProperty, // range of integers given string labels
43  ColourProperty, // colours, get/set as ColourDatabase indices
44  ColourMapProperty, // colour maps, get/set as ColourMapper::StandardMap enum
45  UnitsProperty, // unit from UnitDatabase, get/set unit id
46  InvalidProperty, // property not found!
47  };
48 
53  virtual PropertyList getProperties() const;
54 
58  virtual QString getPropertyLabel(const PropertyName &) const = 0;
59 
64  virtual PropertyType getPropertyType(const PropertyName &) const;
65 
69  virtual QString getPropertyIconName(const PropertyName &) const;
70 
78  virtual QString getPropertyGroupName(const PropertyName &) const;
79 
85  virtual int getPropertyRangeAndValue(const PropertyName &,
86  int *min, int *max, int *deflt) const;
87 
92  virtual QString getPropertyValueLabel(const PropertyName &,
93  int value) const;
94 
99  virtual QString getPropertyValueIconName(const PropertyName &,
100  int value) const;
101 
110  virtual RangeMapper *getNewPropertyRangeMapper(const PropertyName &) const;
111 
112  virtual QString getPropertyContainerName() const = 0;
113  virtual QString getPropertyContainerIconName() const = 0;
114 
121  virtual std::shared_ptr<PlayParameters> getPlayParameters() { return {}; }
122 
123 signals:
125 
126 public slots:
133  virtual void setProperty(const PropertyName &, int value);
134 
140  virtual Command *getSetPropertyCommand(const PropertyName &, int value);
141 
157  virtual void setPropertyFuzzy(QString nameString, QString valueString);
158 
162  virtual Command *getSetPropertyCommand(QString nameString, QString valueString);
163 
164 protected:
165 
167  {
168  public:
169  SetPropertyCommand(PropertyContainer *pc, const PropertyName &pn, int);
170  virtual ~SetPropertyCommand() { }
171 
172  void execute() override;
173  void unexecute() override;
174  QString getName() const override;
175 
176  protected:
178  PropertyName m_pn;
179  int m_value;
181  };
182 
183  virtual bool convertPropertyStrings(QString nameString, QString valueString,
184  PropertyName &name, int &value);
185 };
186 
187 #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 QString getPropertyGroupName(const PropertyName &) const
If this property has something in common with other properties on this container, return a name that ...
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 bool convertPropertyStrings(QString nameString, QString valueString, PropertyName &name, int &value)
virtual QString getPropertyValueIconName(const PropertyName &, int value) const
If the given property is a ValueProperty, return the icon to be used for the given value for that pro...
virtual RangeMapper * getNewPropertyRangeMapper(const PropertyName &) const
If the given property is a RangeProperty, return a new RangeMapper object mapping its integer range o...
virtual PropertyList getProperties() const
Get a list of the names of all the supported properties on this container.
virtual QString getPropertyContainerName() const =0
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&#39;ised) name of a property.
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 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...
SetPropertyCommand(PropertyContainer *pc, const PropertyName &pn, int)
virtual ~PropertyContainer()
virtual void setProperty(const PropertyName &, int value)
Set a property.
virtual std::shared_ptr< PlayParameters > getPlayParameters()
Return the play parameters for this layer, if any.
std::vector< PropertyName > PropertyList
virtual QString getPropertyIconName(const PropertyName &) const
Return an icon for the property, if any.
virtual QString getPropertyContainerIconName() const =0