vungroupcmd.cpp
1/* This file is part of the KDE project
2 Copyright (C) 2001, The Karbon Developers
3 Copyright (C) 2002, The Karbon Developers
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 <tdelocale.h>
22
23#include "vgroup.h"
24#include "vungroupcmd.h"
25#include "vselection.h"
26#include "vdocument.h"
27#include "vlayer.h"
28
29VUnGroupCmd::VUnGroupCmd( VDocument *doc )
30 : VCommand( doc, i18n( "Ungroup Objects" ), "14_ungroup" )
31{
32 m_group = dynamic_cast<VGroup *>( document()->selection()->objects().getFirst() );
33 if( m_group )
34 m_objects = m_group->objects();
35}
36
37VUnGroupCmd::~VUnGroupCmd()
38{
39}
40
41void
42VUnGroupCmd::execute()
43{
44 if( !m_group )
45 return;
46
47 document()->selection()->clear();
48
49 VObjectListIterator itr( m_group->objects() );
50 for ( ; itr.current() ; ++itr )
51 {
52 // TODO : remove from corresponding VLayer
53 document()->selection()->append( itr.current() );
54 }
55
56 VGroup* parent;
57 if( ( parent = dynamic_cast<VGroup*>( m_group->parent() ) ) )
58 {
59 // unregister from parent:
60 parent->take( *m_group );
61
62 // inform all objects in this group about their new parent
63 VObjectListIterator itr = m_group->objects();
64
65 for ( ; itr.current() ; ++itr )
66 {
67 itr.current()->invalidateBoundingBox();
68 parent->append( itr.current() );
69 }
70
71 m_group->clear();
72 m_group->setState( VObject::deleted );
73 }
74
75 setSuccess( true );
76}
77
78void
79VUnGroupCmd::unexecute()
80{
81 if( !m_group )
82 return;
83
84 VObjectListIterator itr( m_objects );
85 for ( ; itr.current() ; ++itr )
86 {
87 // TODO : remove from corresponding VLayer
88 document()->activeLayer()->take( *itr.current() );
89 m_group->append( itr.current() );
90 }
91
92 m_group->setState( VObject::normal );
93 document()->append( m_group );
94 document()->selection()->clear();
95 document()->selection()->append( m_group );
96
97 setSuccess( false );
98}
99
The base class for all karbon commands.
Definition vcommand.h:42
All non-visual, static doc info is in here.
Definition vdocument.h:53
Base class for all sort of VObject conglomerats.
Definition vgroup.h:35
void take(const VObject &object)
Removes the reference to child object, not the object itself.
Definition vgroup.cpp:364
void append(VObject *object)
Appends a new child object.
Definition vgroup.cpp:372
const VObjectList & objects() const
Read only access to the grouped objects.
Definition vgroup.h:110
@ deleted
deleted, nearly dead
Definition vobject.h:58
@ normal
visible, not active
Definition vobject.h:54