1 | /* |
2 | Copyright 2010 Stefan Majewsky <majewsky@gmx.net> |
3 | |
4 | This program is free software; you can redistribute it and/or modify |
5 | it under the terms of the GNU General Public License as published by |
6 | the Free Software Foundation; either version 2 of the License, or |
7 | (at your option) any later version. |
8 | |
9 | This program is distributed in the hope that it will be useful, |
10 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
12 | GNU General Public License for more details. |
13 | |
14 | You should have received a copy of the GNU General Public License |
15 | along with this program; if not, write to the Free Software |
16 | Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA |
17 | */ |
18 | |
19 | #include "itemfactory.h" |
20 | |
21 | QList<Kolf::ItemMetadata> Kolf::ItemFactory::knownTypes() const |
22 | { |
23 | QList<Kolf::ItemMetadata> result; |
24 | QList<Entry>::const_iterator it1 = m_entries.begin(), it2 = m_entries.end(); |
25 | for (; it1 != it2; ++it1) |
26 | result << it1->first; |
27 | return result; |
28 | } |
29 | |
30 | QGraphicsItem* Kolf::ItemFactory::createInstance(const QString& identifier, QGraphicsItem* parent, b2World* world) const |
31 | { |
32 | QList<Entry>::const_iterator it1 = m_entries.begin(), it2 = m_entries.end(); |
33 | for (; it1 != it2; ++it1) |
34 | if (it1->first.identifier == identifier) |
35 | return (it1->second)(parent, world); |
36 | return 0; |
37 | } |
38 | |
39 | void Kolf::ItemFactory::registerType(const Kolf::ItemMetadata& metadata, ItemCreator creator) |
40 | { |
41 | m_entries << Entry(metadata, creator); |
42 | } |
43 | |