karbon

vinsertcmd.cpp
1/* This file is part of the KDE project
2 Copyright (C) 2005, Inge Wallin
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 "vdocument.h"
23#include "vlayer.h"
24#include "vselection.h"
25#include "vinsertcmd.h"
26#include "vtransformcmd.h"
27
28
29VInsertCmd::VInsertCmd( VDocument *doc, const TQString& name,
30 VObjectList *objects,
31 double offset )
32 : VCommand( doc, name, "14_insert" ),
33 m_objects( *objects ),
34 m_offset( offset )
35{
36}
37
38VInsertCmd::~VInsertCmd()
39{
40}
41
42
43void
45{
46 VObjectListIterator itr( m_objects );
47
48 document()->selection()->clear();
49 for ( ; itr.current() ; ++itr ) {
50 VObject *object = itr.current();
51
52 if ( object->state() == VObject::deleted ) {
53 object->setState( VObject::normal );
54 }
55 else {
56 document()->append( object );
57
58 if ( m_offset != 0.0 ) {
59 VTranslateCmd cmd( 0L, m_offset, -m_offset );
60 cmd.visit( *object );
61 }
62 }
63
64 document()->selection()->append( object );
65 }
66
67 setSuccess( true );
68}
69
70
71void
73{
74 document()->selection()->clear();
75
76 VObjectListIterator itr( m_objects );
77 for ( ; itr.current() ; ++itr ) {
78 itr.current()->setState( VObject::deleted );
79 }
80
81 setSuccess( false );
82}
83
The base class for all karbon commands.
Definition vcommand.h:42
virtual void unexecute()
Unexecutes the command.
Definition vcommand.h:75
VDocument * document() const
Returns the document the command works on.
Definition vcommand.h:121
virtual void execute()=0
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
void append(VObject *object)
Appends a new object to the active layer.
@ deleted
deleted, nearly dead
Definition vobject.h:58
@ normal
visible, not active
Definition vobject.h:54
VState state() const
Get the state the object is in.
Definition vobject.h:154
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