1
#include "Command/TrackPointCommands.h"
2
#include "Map/TrackPoint.h"
3
#include "Map/MapLayer.h"
4
#include "Sync/DirtyList.h"
6
MoveTrackPointCommand::MoveTrackPointCommand()
7
: Command(0), theLayer(0), oldLayer(0), OldPos(Coord(0, 0)), NewPos(Coord(0, 0))
11
MoveTrackPointCommand::MoveTrackPointCommand(TrackPoint* aPt)
12
: Command(aPt), theLayer(0), oldLayer(0), OldPos(Coord(0, 0)), NewPos(Coord(0, 0))
14
description = MainWindow::tr("Move node %1").arg(aPt->description());
17
MoveTrackPointCommand::MoveTrackPointCommand(TrackPoint* aPt, const Coord& aPos, MapLayer* aLayer)
18
: Command(aPt), theLayer(aLayer), oldLayer(0), thePoint(aPt), OldPos(aPt->position()), NewPos(aPos)
20
description = MainWindow::tr("Move node %1").arg(aPt->description());
24
MoveTrackPointCommand::~MoveTrackPointCommand(void)
27
oldLayer->decDirtyLevel(commandDirtyLevel);
30
void MoveTrackPointCommand::undo()
33
thePoint->setPosition(OldPos);
34
if (theLayer && oldLayer && (theLayer != oldLayer)) {
35
theLayer->remove(thePoint);
36
oldLayer->add(thePoint);
37
decDirtyLevel(oldLayer);
41
void MoveTrackPointCommand::redo()
43
thePoint->setPosition(NewPos);
44
oldLayer = thePoint->layer();
45
if (theLayer && oldLayer && (theLayer != oldLayer)) {
46
oldLayer->remove(thePoint);
47
incDirtyLevel(oldLayer);
48
theLayer->add(thePoint);
53
bool MoveTrackPointCommand::buildDirtyList(DirtyList &theList)
57
if (thePoint->lastUpdated() == MapFeature::NotYetDownloaded)
58
return theList.noop(thePoint);
59
if (!thePoint->layer())
60
return theList.update(thePoint);
61
if (thePoint->isUploadable())
62
return theList.update(thePoint);
64
return theList.noop(thePoint);
67
bool MoveTrackPointCommand::toXML(QDomElement& xParent) const
71
QDomElement e = xParent.ownerDocument().createElement("MoveTrackPointCommand");
72
xParent.appendChild(e);
74
e.setAttribute("xml:id", id());
75
e.setAttribute("trackpoint", thePoint->xmlId());
76
OldPos.toXML("oldpos", e);
77
NewPos.toXML("newpos", e);
79
e.setAttribute("layer", theLayer->id());
81
e.setAttribute("oldlayer", oldLayer->id());
88
MoveTrackPointCommand * MoveTrackPointCommand::fromXML(MapDocument * d, QDomElement e)
90
MoveTrackPointCommand* a = new MoveTrackPointCommand();
91
a->setId(e.attribute("xml:id"));
92
a->OldPos = Coord::fromXML(e.firstChildElement("oldpos"));
93
a->NewPos = Coord::fromXML(e.firstChildElement("newpos"));
94
if (e.hasAttribute("layer"))
95
a->theLayer = d->getLayer(e.attribute("layer"));
98
if (e.hasAttribute("oldlayer"))
99
a->oldLayer = d->getLayer(e.attribute("oldlayer"));
102
a->thePoint = MapFeature::getTrackPointOrCreatePlaceHolder(d, a->theLayer, e.attribute("trackpoint"));
104
a->description = MainWindow::tr("Move node %1").arg(a->thePoint->description());
106
Command::fromXML(d, e, a);