Mercurial > hg > svcore
annotate base/UnitDatabase.cpp @ 182:f75f8a1cd7b1
* Some dull work to continue unifying the fft model and editable dense 3d model
interfaces
author | Chris Cannam |
---|---|
date | Mon, 09 Oct 2006 10:49:46 +0000 |
parents | a08718723b20 |
children | 1d789d688f59 |
rev | line source |
---|---|
Chris@116 | 1 /* -*- c-basic-offset: 4 indent-tabs-mode: nil -*- vi:set ts=8 sts=4 sw=4: */ |
Chris@116 | 2 |
Chris@116 | 3 /* |
Chris@116 | 4 Sonic Visualiser |
Chris@116 | 5 An audio file viewer and annotation editor. |
Chris@116 | 6 Centre for Digital Music, Queen Mary, University of London. |
Chris@116 | 7 This file copyright 2006 Chris Cannam. |
Chris@116 | 8 |
Chris@116 | 9 This program is free software; you can redistribute it and/or |
Chris@116 | 10 modify it under the terms of the GNU General Public License as |
Chris@116 | 11 published by the Free Software Foundation; either version 2 of the |
Chris@116 | 12 License, or (at your option) any later version. See the file |
Chris@116 | 13 COPYING included with this distribution for more information. |
Chris@116 | 14 */ |
Chris@116 | 15 |
Chris@116 | 16 #include "UnitDatabase.h" |
Chris@116 | 17 |
Chris@116 | 18 UnitDatabase |
Chris@116 | 19 UnitDatabase::m_instance; |
Chris@116 | 20 |
Chris@116 | 21 UnitDatabase * |
Chris@116 | 22 UnitDatabase::getInstance() |
Chris@116 | 23 { |
Chris@116 | 24 return &m_instance; |
Chris@116 | 25 } |
Chris@116 | 26 |
Chris@116 | 27 UnitDatabase::UnitDatabase() : |
Chris@116 | 28 m_nextId(0) |
Chris@116 | 29 { |
Chris@116 | 30 } |
Chris@116 | 31 |
Chris@116 | 32 QStringList |
Chris@116 | 33 UnitDatabase::getKnownUnits() const |
Chris@116 | 34 { |
Chris@116 | 35 QStringList list; |
Chris@116 | 36 for (UnitMap::const_iterator i = m_units.begin(); i != m_units.end(); ++i) { |
Chris@116 | 37 list.push_back(i->first); |
Chris@116 | 38 } |
Chris@116 | 39 return list; |
Chris@116 | 40 } |
Chris@116 | 41 |
Chris@116 | 42 void |
Chris@116 | 43 UnitDatabase::registerUnit(QString unit) |
Chris@116 | 44 { |
Chris@116 | 45 if (m_units.find(unit) == m_units.end()) { |
Chris@116 | 46 m_units[unit] = m_nextId++; |
Chris@116 | 47 } |
Chris@116 | 48 emit unitDatabaseChanged(); |
Chris@116 | 49 } |
Chris@116 | 50 |
Chris@116 | 51 int |
Chris@116 | 52 UnitDatabase::getUnitId(QString unit) |
Chris@116 | 53 { |
Chris@116 | 54 if (m_units.find(unit) == m_units.end()) { |
Chris@116 | 55 registerUnit(unit); |
Chris@116 | 56 } |
Chris@116 | 57 return m_units[unit]; |
Chris@116 | 58 } |
Chris@116 | 59 |
Chris@116 | 60 QString |
Chris@116 | 61 UnitDatabase::getUnitById(int id) |
Chris@116 | 62 { |
Chris@116 | 63 for (UnitMap::const_iterator i = m_units.begin(); i != m_units.end(); ++i) { |
Chris@116 | 64 if (i->second == id) return i->first; |
Chris@116 | 65 } |
Chris@116 | 66 return ""; |
Chris@116 | 67 } |
Chris@116 | 68 |