diff options
author | Mateusz Piekos <mateuszpiekos@gmail.com> | 2012-07-31 08:31:54 (GMT) |
---|---|---|
committer | Mateusz Piekos <mateuszpiekos@gmail.com> | 2012-07-31 08:31:54 (GMT) |
commit | 4321da432e3332e868abf07678f15d305fec2a4b (patch) | |
tree | 72cc36c121448dce907a4ccbc679bc3cad3c07f4 /Swiften/Whiteboard | |
parent | 5fafa602d859657d6616acdbb63dfcd501aed9a0 (diff) | |
download | swift-contrib-4321da432e3332e868abf07678f15d305fec2a4b.zip swift-contrib-4321da432e3332e868abf07678f15d305fec2a4b.tar.bz2 |
Upgraded update operation with ability to move elements
Diffstat (limited to 'Swiften/Whiteboard')
-rw-r--r-- | Swiften/Whiteboard/Operations/WhiteboardUpdateOperation.h | 9 | ||||
-rw-r--r-- | Swiften/Whiteboard/WhiteboardTransformer.cpp | 36 |
2 files changed, 41 insertions, 4 deletions
diff --git a/Swiften/Whiteboard/Operations/WhiteboardUpdateOperation.h b/Swiften/Whiteboard/Operations/WhiteboardUpdateOperation.h index 7c4b088..1b79043 100644 --- a/Swiften/Whiteboard/Operations/WhiteboardUpdateOperation.h +++ b/Swiften/Whiteboard/Operations/WhiteboardUpdateOperation.h @@ -26,7 +26,16 @@ namespace Swift { element_ = element; } + int getNewPos() const { + return newPos_; + } + + void setNewPos(int newPos) { + newPos_ = newPos; + } + private: WhiteboardElement::ref element_; + int newPos_; }; } diff --git a/Swiften/Whiteboard/WhiteboardTransformer.cpp b/Swiften/Whiteboard/WhiteboardTransformer.cpp index c9dbbbd..88ab7d5 100644 --- a/Swiften/Whiteboard/WhiteboardTransformer.cpp +++ b/Swiften/Whiteboard/WhiteboardTransformer.cpp @@ -61,6 +61,24 @@ namespace Swift { result.second = boost::make_shared<WhiteboardUpdateOperation>(*clientOp); result.second->setParentID(serverOp->getID()); } + + if (clientOp->getPos() < serverOp->getPos() && clientOp->getNewPos() > serverOp->getPos()) { + result.first->setPos(result.first->getPos()-1); + if (clientOp->getNewPos() >= serverOp->getNewPos()) { + result.first->setNewPos(result.first->getNewPos()-1); + } + } else if (clientOp->getNewPos() >= serverOp->getNewPos()) { + result.first->setNewPos(result.first->getNewPos()-1); + } + + if (serverOp->getPos() < clientOp->getPos() && serverOp->getNewPos() > clientOp->getPos()) { + result.second->setPos(result.second->getPos()-1); + if (serverOp->getNewPos() >= clientOp->getNewPos()) { + result.second->setNewPos(result.second->getNewPos()-1); + } + } else if (serverOp->getNewPos() >= clientOp->getNewPos()) { + result.second->setNewPos(result.second->getNewPos()-1); + } return result; } @@ -144,7 +162,8 @@ namespace Swift { std::pair<WhiteboardDeleteOperation::ref, WhiteboardOperation::ref> result; result.first = boost::make_shared<WhiteboardDeleteOperation>(*serverOp); result.first->setParentID(clientOp->getID()); - result.second = boost::make_shared<WhiteboardUpdateOperation>(*clientOp); + WhiteboardUpdateOperation::ref updateOp = boost::make_shared<WhiteboardUpdateOperation>(*clientOp); + result.second = updateOp; result.second->setParentID(serverOp->getID()); if (clientOp->getPos() == serverOp->getPos()) { WhiteboardDeleteOperation::ref deleteOp = boost::make_shared<WhiteboardDeleteOperation>(); @@ -153,16 +172,21 @@ namespace Swift { result.second->setID(clientOp->getID()); result.second->setParentID(serverOp->getID()); deleteOp->setElementID(serverOp->getElementID()); + } else if (clientOp->getPos() > serverOp->getPos() && clientOp->getNewPos() <= serverOp->getPos()) { + result.second->setPos(result.second->getPos()-1); + } else if (clientOp->getPos() < serverOp->getPos() && clientOp->getNewPos() >= serverOp->getPos()) { + updateOp->setNewPos(updateOp->getNewPos()-1); } else if (clientOp->getPos() > serverOp->getPos()) { result.second->setPos(result.second->getPos()-1); + updateOp->setNewPos(updateOp->getNewPos()-1); } return result; -//TODO: situation with the same pos } std::pair<WhiteboardOperation::ref, WhiteboardOperation::ref> WhiteboardTransformer::transform(WhiteboardDeleteOperation::ref clientOp, WhiteboardUpdateOperation::ref serverOp) { std::pair<WhiteboardOperation::ref, WhiteboardDeleteOperation::ref> result; - result.first = boost::make_shared<WhiteboardUpdateOperation>(*serverOp); + WhiteboardUpdateOperation::ref updateOp = boost::make_shared<WhiteboardUpdateOperation>(*serverOp); + result.first = updateOp; result.first->setParentID(clientOp->getID()); result.second = boost::make_shared<WhiteboardDeleteOperation>(*clientOp); result.second->setParentID(serverOp->getID()); @@ -173,10 +197,14 @@ namespace Swift { result.first->setID(serverOp->getID()); result.first->setParentID(clientOp->getID()); deleteOp->setElementID(clientOp->getElementID()); + } else if (clientOp->getPos() < serverOp->getPos() && clientOp->getPos() >= serverOp->getNewPos()) { + result.first->setPos(result.first->getPos()-1); + } else if (clientOp->getPos() > serverOp->getPos() && clientOp->getPos() <= serverOp->getNewPos()) { + updateOp->setNewPos(updateOp->getNewPos()-1); } else if (clientOp->getPos() < serverOp->getPos()) { result.first->setPos(result.first->getPos()-1); + updateOp->setNewPos(updateOp->getNewPos()-1); } return result; -//TODO: situation with the same pos } } |