forked from mapmapteam/mapmap
-
Notifications
You must be signed in to change notification settings - Fork 0
/
MappingManager.h
108 lines (82 loc) · 3.16 KB
/
MappingManager.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
/*
* MappingManager.h
*
* (c) 2013 Sofian Audry -- info(@)sofianaudry(.)com
* (c) 2013 Alexandre Quessy -- alexandre(@)quessy(.)net
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef MAPPINGMANAGER_H_
#define MAPPINGMANAGER_H_
#include <QVector>
#include <QMap>
#include "Paint.h"
#include "Mapping.h"
/**
* This is a container class for all the paints and mappings ie. the main model object that allows
* CRUD over paints and mappings.
*/
class MappingManager
{
public:
/// Constructor.
MappingManager();
private:
// Model elements.
/// Container for all paints.
QVector<Paint::ptr> paintVector;
/// Maps from uids to paints.
QMap<uid, Paint::ptr> paintMap;
/// Container for all mappings (ordered from bottom layer to top layer).
QVector<Mapping::ptr> mappingVector;
/// Maps from uids to mappings.
QMap<uid, Mapping::ptr> mappingMap;
public:
/// Returns the list of mappings associated with given paint.
QMap<uid, Mapping::ptr> getPaintMappings(const Paint::ptr paint) const;
/// Returns the list of mappings associated with given paint uid.
QMap<uid, Mapping::ptr> getPaintMappingsById(uid paintId) const;
/// Adds a paint and returns its uid.
uid addPaint(Paint::ptr paint);
/// Returns the uid of a paint.
uid getPaintId(Paint::ptr paint) const { return paintMap.key(paint); }
/// Removes a paint of given uid.
bool removePaint(uid paintId);
/// DEPRECATED.
bool replacePaintMappings(Paint::ptr oldpaint, Paint::ptr newpaint);
/// Returns the number of paints.
int nPaints() const { return paintVector.size(); }
/// Returns the i-th paint in the vector. Good for iterating over all paints.
Paint::ptr getPaint(int i) { return paintVector[i]; }
/// Returns paint with given uid.
Paint::ptr getPaintById(uid id) { return paintMap[id]; }
/// Adds a mapping and returns its uid.
uid addMapping(Mapping::ptr mapping);
/// Removes a mapping of given uid.
bool removeMapping(uid mappingId);
/// Returns the number of mappings.
int nMappings() const { return mappingVector.size(); }
/**
* Returns the i-th mapping in the vector. Good for iterating over all mappings. Vector is
* ordered from bottom to top layer.
*/
Mapping::ptr getMapping(int i) { return mappingVector[i]; }
/// Returns mapping with given uid.
Mapping::ptr getMappingById(uid id) { return mappingMap[id]; }
/// Reorders the mappings according to given list of uids. QVector needs to
void reorderMappings(QVector<uid> mappingIds);
QVector<Mapping::ptr> getVisibleMappings() const;
void clearAll();
};
#endif /* MAPPINGMANAGER_H_ */