comparison base/UnitDatabase.cpp @ 116:a08718723b20

* Add units repository, and unit property on time-value and note layers.
author Chris Cannam
date Thu, 11 May 2006 15:02:14 +0000
parents
children 1d789d688f59
comparison
equal deleted inserted replaced
115:90ade4fa63be 116:a08718723b20
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 #include "UnitDatabase.h"
17
18 UnitDatabase
19 UnitDatabase::m_instance;
20
21 UnitDatabase *
22 UnitDatabase::getInstance()
23 {
24 return &m_instance;
25 }
26
27 UnitDatabase::UnitDatabase() :
28 m_nextId(0)
29 {
30 }
31
32 QStringList
33 UnitDatabase::getKnownUnits() const
34 {
35 QStringList list;
36 for (UnitMap::const_iterator i = m_units.begin(); i != m_units.end(); ++i) {
37 list.push_back(i->first);
38 }
39 return list;
40 }
41
42 void
43 UnitDatabase::registerUnit(QString unit)
44 {
45 if (m_units.find(unit) == m_units.end()) {
46 m_units[unit] = m_nextId++;
47 }
48 emit unitDatabaseChanged();
49 }
50
51 int
52 UnitDatabase::getUnitId(QString unit)
53 {
54 if (m_units.find(unit) == m_units.end()) {
55 registerUnit(unit);
56 }
57 return m_units[unit];
58 }
59
60 QString
61 UnitDatabase::getUnitById(int id)
62 {
63 for (UnitMap::const_iterator i = m_units.begin(); i != m_units.end(); ++i) {
64 if (i->second == id) return i->first;
65 }
66 return "";
67 }
68