~ubuntu-branches/ubuntu/precise/koffice/precise

« back to all changes in this revision

Viewing changes to plugins/treeshape/TreeShapeMoveCommand.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Alessandro Ghersi
  • Date: 2010-10-27 17:52:57 UTC
  • mfrom: (0.12.1 upstream)
  • Revision ID: james.westby@ubuntu.com-20101027175257-s04zqqk5bs8ckm9o
Tags: 1:2.2.83-0ubuntu1
* Merge with Debian git remaining changes:
 - Add build-deps on librcps-dev, opengtl-dev, libqtgtl-dev, freetds-dev,
   create-resources, libspnav-dev
 - Remove needless build-dep on libwv2-dev
 - koffice-libs recommends create-resources
 - krita recommends pstoedit
 - Keep our patches
* New upstream release 2.3 beta 3
  - Remove debian/patches fixed by upstream
  - Update install files

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* This file is part of the KDE project
 
2
 
 
3
   Copyright (c) 2010 Cyril Oblikov <munknex@gmail.com>
 
4
 
 
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.
 
9
 
 
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.
 
14
 
 
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.
 
19
*/
 
20
 
 
21
#include "TreeShapeMoveCommand.h"
 
22
#include "TreeShape.h"
 
23
#include "KoShapeContainer.h"
 
24
 
 
25
#include <klocale.h>
 
26
 
 
27
TreeShapeMoveCommand::TreeShapeMoveCommand(const QList<KoShape*> &shapes,
 
28
                                           TreeShape *newParent,
 
29
                                           KoShape *nextShape,
 
30
                                           QPointF diff,
 
31
                                           QUndoCommand *parent)
 
32
        : QUndoCommand(parent),
 
33
        m_newParent(newParent),
 
34
        m_nextShape(nextShape),
 
35
        m_diff(diff)
 
36
{
 
37
    foreach(KoShape *shape, shapes) {
 
38
        TreeShape *tree = dynamic_cast<TreeShape*>(shape);
 
39
        TreeShape *par = dynamic_cast<TreeShape*>(shape->parent());
 
40
        m_trees.append(tree);
 
41
        m_oldNextShapes.append(tree->nextShape());
 
42
        m_parents.append(par);
 
43
        m_connectors.append(par ? par->connector(shape) : 0);
 
44
    }
 
45
    setText(i18n("Attach tree"));
 
46
}
 
47
 
 
48
TreeShapeMoveCommand::~TreeShapeMoveCommand()
 
49
{
 
50
}
 
51
 
 
52
void TreeShapeMoveCommand::redo()
 
53
{
 
54
    QUndoCommand::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);
 
59
        tree->setParent(0);
 
60
        if (m_newParent) {
 
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]);
 
64
        } else {
 
65
            tree->setPosition(tree->position()+m_diff);
 
66
        }
 
67
    }
 
68
}
 
69
 
 
70
void TreeShapeMoveCommand::undo()
 
71
{
 
72
    QUndoCommand::undo();
 
73
    for (int i = 0; i < m_trees.count(); i++) {
 
74
        TreeShape *tree = m_trees[i];
 
75
        tree->setNextShape(m_oldNextShapes[i]);
 
76
        tree->setParent(0);
 
77
        if (m_parents[i]) {
 
78
            m_parents[i]->addChild(tree, m_connectors[i]);
 
79
        } else {
 
80
            tree->setPosition(tree->position()-m_diff);
 
81
        }
 
82
    }
 
83
}
 
 
b'\\ No newline at end of file'