1 /*
2 * Copyright (C) 2018 Damir Porobic <damir.porobic@gmx.com>
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU Lesser General Public License as published by
6 * the Free Software Foundation; either version 3 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 Lesser General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 51 Franklin Street, Fifth Floor,
17 * Boston, MA 02110-1301, USA.
18 */
19
20 #include "PasteCommand.h"
21
22 namespace kImageAnnotator {
23
PasteCommand(const QHash<kImageAnnotator::AbstractAnnotationItem *,QPointF> & itemsWithOffset,const QPointF & position,AnnotationItemFactory * itemFactory,kImageAnnotator::AnnotationArea * annotationArea)24 PasteCommand::PasteCommand(const QHash<kImageAnnotator::AbstractAnnotationItem *, QPointF> &itemsWithOffset,
25 const QPointF &position,
26 AnnotationItemFactory *itemFactory,
27 kImageAnnotator::AnnotationArea *annotationArea)
28 {
29 Q_ASSERT(annotationArea != nullptr);
30 Q_ASSERT(itemFactory != nullptr);
31
32 mAnnotationArea = annotationArea;
33 mItemFactory = itemFactory;
34 for (auto item : itemsWithOffset.keys()) {
35 auto pastedItem = itemFactory->clone(item);
36 pastedItem->setPosition(position + itemsWithOffset[item]);
37 mPastedItems.append(pastedItem);
38 }
39 }
40
~PasteCommand()41 PasteCommand::~PasteCommand()
42 {
43 // Deleting with the annotation area
44 }
45
undo()46 void PasteCommand::undo()
47 {
48 for (auto item : mPastedItems) {
49 mAnnotationArea->removeAnnotationItem(item);
50 item->hide();
51 }
52 }
53
redo()54 void PasteCommand::redo()
55 {
56 for (auto item : mPastedItems) {
57 mAnnotationArea->addAnnotationItem(item);
58 item->show();
59 }
60 }
61
62 } // namespace kImageAnnotator
63