1
/* This file is part of the KDE project
3
Copyright (c) 2010 Cyril Oblikov <munknex@gmail.com>
5
This library is free software; you can redistribute it and/or
6
modify it under the terms of the GNU Library General Public
7
License as published by the Free Software Foundation; either
8
version 2 of the License, or (at your option) any later version.
10
This library is distributed in the hope that it will be useful,
11
but WITHOUT ANY WARRANTY; without even the implied warranty of
12
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13
Library General Public License for more details.
15
You should have received a copy of the GNU Library General Public License
16
along with this library; see the file COPYING.LIB. If not, write to
17
the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
18
* Boston, MA 02110-1301, USA.
21
#include "TreeShapeMoveCommand.h"
22
#include "TreeShape.h"
23
#include "KoShapeContainer.h"
27
TreeShapeMoveCommand::TreeShapeMoveCommand(const QList<KoShape*> &shapes,
32
: QUndoCommand(parent),
33
m_newParent(newParent),
34
m_nextShape(nextShape),
37
foreach(KoShape *shape, shapes) {
38
TreeShape *tree = dynamic_cast<TreeShape*>(shape);
39
TreeShape *par = dynamic_cast<TreeShape*>(shape->parent());
41
m_oldNextShapes.append(tree->nextShape());
42
m_parents.append(par);
43
m_connectors.append(par ? par->connector(shape) : 0);
45
setText(i18n("Attach tree"));
48
TreeShapeMoveCommand::~TreeShapeMoveCommand()
52
void TreeShapeMoveCommand::redo()
55
Q_ASSERT(!m_trees.isEmpty());
56
for (int i = 0; i < m_trees.count(); i++) {
57
TreeShape *tree = m_trees[i];
58
tree->setNextShape(m_nextShape);
61
// TODO: if tree was without parent we should create a connector
62
// for it. Otherwise it will cause a crash.
63
m_newParent->addChild(tree, m_connectors[i]);
65
tree->setPosition(tree->position()+m_diff);
70
void TreeShapeMoveCommand::undo()
73
for (int i = 0; i < m_trees.count(); i++) {
74
TreeShape *tree = m_trees[i];
75
tree->setNextShape(m_oldNextShapes[i]);
78
m_parents[i]->addChild(tree, m_connectors[i]);
80
tree->setPosition(tree->position()-m_diff);
b'\\ No newline at end of file'