svcore  1.9
PropertyContainer.h
Go to the documentation of this file.
00001 /* -*- c-basic-offset: 4 indent-tabs-mode: nil -*-  vi:set ts=8 sts=4 sw=4: */
00002 
00003 /*
00004     Sonic Visualiser
00005     An audio file viewer and annotation editor.
00006     Centre for Digital Music, Queen Mary, University of London.
00007     This file copyright 2006 Chris Cannam and QMUL.
00008     
00009     This program is free software; you can redistribute it and/or
00010     modify it under the terms of the GNU General Public License as
00011     published by the Free Software Foundation; either version 2 of the
00012     License, or (at your option) any later version.  See the file
00013     COPYING included with this distribution for more information.
00014 */
00015 
00016 #ifndef _PROPERTY_CONTAINER_H_
00017 #define _PROPERTY_CONTAINER_H_
00018 
00019 #include "Command.h"
00020 
00021 #include <QString>
00022 #include <QObject>
00023 #include <vector>
00024 
00025 class PlayParameters;
00026 class RangeMapper;
00027 
00028 class PropertyContainer : public QObject
00029 {
00030     Q_OBJECT
00031 
00032 public:
00033     virtual ~PropertyContainer() { }
00034 
00035     typedef QString PropertyName;
00036     typedef std::vector<PropertyName> PropertyList;
00037     
00038     enum PropertyType {
00039         ToggleProperty, // on or off
00040         RangeProperty, // range of integers
00041         ValueProperty, // range of integers given string labels
00042         ColourProperty, // colours, get/set as ColourDatabase indices
00043         UnitsProperty, // unit from UnitDatabase, get/set unit id
00044         InvalidProperty, // property not found!
00045     };
00046 
00051     virtual PropertyList getProperties() const;
00052 
00056     virtual QString getPropertyLabel(const PropertyName &) const = 0;
00057 
00062     virtual PropertyType getPropertyType(const PropertyName &) const;
00063 
00067     virtual QString getPropertyIconName(const PropertyName &) const;
00068 
00076     virtual QString getPropertyGroupName(const PropertyName &) const;
00077 
00083     virtual int getPropertyRangeAndValue(const PropertyName &,
00084                                          int *min, int *max, int *deflt) const;
00085 
00090     virtual QString getPropertyValueLabel(const PropertyName &,
00091                                           int value) const;
00092 
00101     virtual RangeMapper *getNewPropertyRangeMapper(const PropertyName &) const;
00102 
00103     virtual QString getPropertyContainerName() const = 0;
00104     virtual QString getPropertyContainerIconName() const = 0;
00105 
00106     virtual PlayParameters *getPlayParameters() { return 0; }
00107 
00108 signals:
00109     void propertyChanged(PropertyContainer::PropertyName);
00110 
00111 public slots:
00118     virtual void setProperty(const PropertyName &, int value);
00119 
00125     virtual Command *getSetPropertyCommand(const PropertyName &, int value);
00126 
00142     virtual void setPropertyFuzzy(QString nameString, QString valueString);
00143 
00147     virtual Command *getSetPropertyCommand(QString nameString, QString valueString);
00148 
00149 protected:
00150 
00151     class SetPropertyCommand : public Command
00152     {
00153     public:
00154         SetPropertyCommand(PropertyContainer *pc, const PropertyName &pn, int);
00155         virtual ~SetPropertyCommand() { }
00156 
00157         virtual void execute();
00158         virtual void unexecute();
00159         virtual QString getName() const;
00160 
00161     protected:
00162         PropertyContainer *m_pc;
00163         PropertyName m_pn;
00164         int m_value;
00165         int m_oldValue;
00166     };
00167 
00168     virtual bool convertPropertyStrings(QString nameString, QString valueString,
00169                                         PropertyName &name, int &value);
00170 };
00171 
00172 #endif