vdeletecmd.cpp
1/* This file is part of the KDE project
2 Copyright (C) 2001, 2002, 2003 The Karbon Developers
3
4 This library is free software; you can redistribute it and/or
5 modify it under the terms of the GNU Library General Public
6 License as published by the Free Software Foundation; either
7 version 2 of the License, or (at your option) any later version.
8
9 This library 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 GNU
12 Library General Public License for more details.
13
14 You should have received a copy of the GNU Library General Public License
15 along with this library; see the file COPYING.LIB. If not, write to
16 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
17 * Boston, MA 02110-1301, USA.
18*/
19
20#include <tdelocale.h>
21
22#include "vdeletecmd.h"
23#include "vselection.h"
24#include "vdocument.h"
25
26VDeleteCmd::VDeleteCmd( VDocument* doc )
27 : VCommand( doc, i18n( "Delete Objects" ), "edit-delete" )
28{
29 m_selection = document()->selection()->clone();
30
31 if( m_selection->objects().count() == 1 )
32 setName( i18n( "Delete Object" ) );
33}
34
35VDeleteCmd::VDeleteCmd( VDocument* doc, VObject* object )
36 : VCommand( doc, i18n( "Delete Object" ), "edit-delete" )
37{
38 m_selection = new VSelection();
39 m_selection->append( object );
40}
41
42VDeleteCmd::~VDeleteCmd()
43{
44 delete( m_selection );
45}
46
47void
49{
50 document()->selection()->clear();
51 VObjectListIterator itr( m_selection->objects() );
52 for ( ; itr.current() ; ++itr )
53 {
54 itr.current()->setState( VObject::deleted );
55 }
56
57 setSuccess( true );
58}
59
60void
62{
63 document()->selection()->clear();
64
65 VObjectListIterator itr( m_selection->objects() );
66 for ( ; itr.current() ; ++itr )
67 {
68 itr.current()->setState( VObject::selected );
69 document()->selection()->append( itr.current() );
70 }
71
72 setSuccess( false );
73}
74
The base class for all karbon commands.
Definition vcommand.h:42
VDocument * document() const
Returns the document the command works on.
Definition vcommand.h:121
virtual void unexecute()
Unexecutes the command.
virtual void execute()
Executes the command.
All non-visual, static doc info is in here.
Definition vdocument.h:53
VSelection * selection() const
Returns a pointer to the selection.
Definition vdocument.h:238
The base class for all karbon objects.
Definition vobject.h:50
@ selected
visible, active and can be manipulated by tools
Definition vobject.h:61
@ deleted
deleted, nearly dead
Definition vobject.h:58
VSelection manages a set of selected vobjects.
Definition vselection.h:62
const VObjectList & objects() const
Read only access to the selected objects.
Definition vselection.h:136
void append()
Adds all objects to the selection.
void clear()
Removes the references to all objects, not the objects themselves.
void setSuccess(bool success=true)
Set the success property.
Definition vvisitor.h:142