svcore  1.9
UnitDatabase.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.
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 _UNIT_DATABASE_H_
00017 #define _UNIT_DATABASE_H_
00018 
00019 #include <QObject>
00020 #include <QString>
00021 #include <QStringList>
00022 #include <map>
00023 
00024 // This grandly named class is just a list of the names of known scale
00025 // units for the various models, for use as the set of fixed values in
00026 // unit dropdown menus etc.  Of course, the user should be allowed to
00027 // enter their own as well.
00028 
00029 class UnitDatabase : public QObject
00030 {
00031     Q_OBJECT
00032 
00033 public:
00034     static UnitDatabase *getInstance();
00035 
00036     QStringList getKnownUnits() const;
00037     void registerUnit(QString unit);
00038 
00044     int getUnitId(QString unit, bool registerNew = true);
00045 
00046     QString getUnitById(int id);
00047 
00048 signals:
00049     void unitDatabaseChanged();
00050 
00051 protected:
00052     UnitDatabase();
00053 
00054     typedef std::map<QString, int> UnitMap;
00055     UnitMap m_units;
00056     int m_nextId;
00057 
00058     static UnitDatabase m_instance;
00059 };
00060 
00061 #endif
00062