UnitDatabase.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.
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_UNIT_DATABASE_H
17 #define SV_UNIT_DATABASE_H
18 
19 #include <QObject>
20 #include <QString>
21 #include <QStringList>
22 #include <map>
23 
24 // This grandly named class is just a list of the names of known scale
25 // units for the various models, for use as the set of fixed values in
26 // unit dropdown menus etc. Of course, the user should be allowed to
27 // enter their own as well.
28 
29 class UnitDatabase : public QObject
30 {
31  Q_OBJECT
32 
33 public:
34  static UnitDatabase *getInstance();
35 
36  QStringList getKnownUnits() const;
37  void registerUnit(QString unit);
38 
44  int getUnitId(QString unit, bool registerNew = true);
45 
46  QString getUnitById(int id);
47 
48 signals:
49  void unitDatabaseChanged();
50 
51 protected:
52  UnitDatabase();
53 
54  typedef std::map<QString, int> UnitMap;
55  UnitMap m_units;
56  int m_nextId;
57 
59 };
60 
61 #endif
62 
int getUnitId(QString unit, bool registerNew=true)
Return the reference id for a given unit name.
void registerUnit(QString unit)
static UnitDatabase * getInstance()
std::map< QString, int > UnitMap
Definition: UnitDatabase.h:54
void unitDatabaseChanged()
static UnitDatabase m_instance
Definition: UnitDatabase.h:58
QString getUnitById(int id)
QStringList getKnownUnits() const
UnitMap m_units
Definition: UnitDatabase.h:55