1
#include "RelationCommands.h"
3
#include "Map/Relation.h"
4
#include "Map/MapFeature.h"
5
#include "Map/MapLayer.h"
6
#include "Sync/DirtyList.h"
8
RelationAddFeatureCommand::RelationAddFeatureCommand(Relation* R)
9
: Command(R), theLayer(0), oldLayer(0), theRelation(R), Role(""), theMapFeature(0), Position(0)
13
RelationAddFeatureCommand::RelationAddFeatureCommand(Relation* R, const QString& aRole, MapFeature* W, MapLayer* aLayer)
14
: Command(R), theLayer(aLayer), oldLayer(0), theRelation(R), Role(aRole), theMapFeature(W), Position(theRelation->size())
19
RelationAddFeatureCommand::RelationAddFeatureCommand(Relation* R, const QString& aRole, MapFeature* W, unsigned int aPos, MapLayer* aLayer)
20
: Command(R), theLayer(aLayer), oldLayer(0), theRelation(R), Role(aRole), theMapFeature(W), Position(aPos)
25
RelationAddFeatureCommand::~RelationAddFeatureCommand(void)
28
oldLayer->decDirtyLevel(commandDirtyLevel);
31
void RelationAddFeatureCommand::undo()
34
theRelation->remove(Position);
35
if (theLayer && oldLayer && (theLayer != oldLayer)) {
36
theLayer->remove(theRelation);
37
oldLayer->add(theRelation);
38
decDirtyLevel(oldLayer);
42
void RelationAddFeatureCommand::redo()
44
theRelation->add(Role, theMapFeature, Position);
45
oldLayer = theRelation->layer();
46
if (theLayer && oldLayer && (theLayer != oldLayer)) {
47
oldLayer->remove(theRelation);
48
incDirtyLevel(oldLayer);
49
theLayer->add(theRelation);
54
bool RelationAddFeatureCommand::buildDirtyList(DirtyList& theList)
58
if (theRelation->lastUpdated() == MapFeature::NotYetDownloaded)
59
return theList.noop(theRelation);
60
if (!theRelation->layer())
61
return theList.update(theRelation);
62
if (theRelation->layer()->isUploadable())
63
return theList.update(theRelation);
65
return theList.noop(theRelation);
68
bool RelationAddFeatureCommand::toXML(QDomElement& xParent) const
72
QDomElement e = xParent.ownerDocument().createElement("RelationAddFeatureCommand");
73
xParent.appendChild(e);
75
e.setAttribute("xml:id", id());
76
e.setAttribute("relation", theRelation->xmlId());
77
e.setAttribute("role", Role);
78
e.setAttribute("feature", theMapFeature->xmlId());
79
e.setAttribute("pos", QString::number(Position));
81
e.setAttribute("layer", theLayer->id());
83
e.setAttribute("oldlayer", oldLayer->id());
90
RelationAddFeatureCommand * RelationAddFeatureCommand::fromXML(MapDocument * d, QDomElement e)
92
RelationAddFeatureCommand* a = new RelationAddFeatureCommand();
93
a->setId(e.attribute("xml:id"));
94
if (e.hasAttribute("layer"))
95
a->theLayer = d->getLayer(e.attribute("layer"));
97
a->theLayer = d->getDirtyOrOriginLayer();
98
if (e.hasAttribute("oldlayer"))
99
a->oldLayer = d->getLayer(e.attribute("oldlayer"));
102
a->theRelation = MapFeature::getRelationOrCreatePlaceHolder(d, a->theLayer, e.attribute("relation"));
104
if (e.attribute("featureclass") == "TrackPoint") {
105
F = (MapFeature*) MapFeature::getTrackPointOrCreatePlaceHolder(d, a->theLayer, e.attribute("trackpoint"));
107
if (e.attribute("featureclass") == "Road") {
108
F = (MapFeature*) MapFeature::getWayOrCreatePlaceHolder(d, a->theLayer, e.attribute("road"));
110
if (e.attribute("featureclass") == "Relation") {
111
F = (MapFeature*) MapFeature::getRelationOrCreatePlaceHolder(d, a->theLayer, e.attribute("road"));
113
if (!(F = d->getFeature(e.attribute("feature"), false)))
116
a->Role = e.attribute("role");
117
a->theMapFeature = F;
118
a->Position = e.attribute("pos").toUInt();
120
Command::fromXML(d, e, a);
125
/* ROADREMOVEMapFeatureCOMMAND */
127
RelationRemoveFeatureCommand::RelationRemoveFeatureCommand(Relation* R)
128
: Command(R), theLayer(0), oldLayer(0), Idx(0), theRelation(R), theMapFeature(0)
132
RelationRemoveFeatureCommand::RelationRemoveFeatureCommand(Relation* R, MapFeature* W, MapLayer* aLayer)
133
: Command(R), theLayer(aLayer), oldLayer(0), Idx(R->find(W)), theRelation(R), theMapFeature(W)
135
Role = R->getRole(Idx);
139
RelationRemoveFeatureCommand::RelationRemoveFeatureCommand(Relation* R, unsigned int anIdx, MapLayer* aLayer)
140
: Command(R), theLayer(aLayer), oldLayer(0), Idx(anIdx), theRelation(R), Role(R->getRole(anIdx)), theMapFeature(R->get(anIdx))
145
RelationRemoveFeatureCommand::~RelationRemoveFeatureCommand(void)
147
oldLayer->decDirtyLevel(commandDirtyLevel);
151
void RelationRemoveFeatureCommand::undo()
154
theRelation->add(Role,theMapFeature,Idx);
155
if (theLayer && oldLayer && (theLayer != oldLayer)) {
156
theLayer->remove(theRelation);
157
oldLayer->add(theRelation);
158
decDirtyLevel(oldLayer);
162
void RelationRemoveFeatureCommand::redo()
164
theRelation->remove(Idx);
165
oldLayer = theRelation->layer();
166
if (theLayer && oldLayer && (theLayer != oldLayer)) {
167
oldLayer->remove(theRelation);
168
incDirtyLevel(oldLayer);
169
theLayer->add(theRelation);
174
bool RelationRemoveFeatureCommand::buildDirtyList(DirtyList& theList)
178
if (theRelation->lastUpdated() == MapFeature::NotYetDownloaded)
179
return theList.noop(theRelation);
180
if (!theRelation->layer())
181
return theList.update(theRelation);
182
if (theRelation->layer()->isUploadable())
183
return theList.update(theRelation);
185
return theList.noop(theRelation);
188
bool RelationRemoveFeatureCommand::toXML(QDomElement& xParent) const
192
QDomElement e = xParent.ownerDocument().createElement("RelationRemoveFeatureCommand");
193
xParent.appendChild(e);
195
e.setAttribute("xml:id", id());
196
e.setAttribute("relation", theRelation->xmlId());
197
e.setAttribute("feature", theMapFeature->xmlId());
198
e.setAttribute("featureclass", theMapFeature->getClass());
199
e.setAttribute("index", QString::number(Idx));
200
e.setAttribute("role", Role);
202
e.setAttribute("layer", theLayer->id());
204
e.setAttribute("oldlayer", oldLayer->id());
211
RelationRemoveFeatureCommand * RelationRemoveFeatureCommand::fromXML(MapDocument * d, QDomElement e)
213
RelationRemoveFeatureCommand* a = new RelationRemoveFeatureCommand();
215
a->setId(e.attribute("xml:id"));
216
if (e.hasAttribute("layer"))
217
a->theLayer = d->getLayer(e.attribute("layer"));
219
a->theLayer = d->getDirtyOrOriginLayer();
220
if (e.hasAttribute("oldlayer"))
221
a->oldLayer = d->getLayer(e.attribute("oldlayer"));
224
a->theRelation = MapFeature::getRelationOrCreatePlaceHolder(d, a->theLayer, e.attribute("relation"));
225
MapFeature* F = NULL;
226
if (e.attribute("featureclass") == "TrackPoint") {
227
F = (MapFeature*) MapFeature::getTrackPointOrCreatePlaceHolder(d, a->theLayer, e.attribute("feature"));
229
if (e.attribute("featureclass") == "Road") {
230
F = (MapFeature*) MapFeature::getWayOrCreatePlaceHolder(d, a->theLayer, e.attribute("feature"));
232
if (e.attribute("featureclass") == "Relation") {
233
F = (MapFeature*) MapFeature::getRelationOrCreatePlaceHolder(d, a->theLayer, e.attribute("feature"));
235
a->theMapFeature = F;
236
a->Idx = e.attribute("index").toInt();
237
a->Role = e.attribute("role");
239
Command::fromXML(d, e, a);