karbon
vinsertcmd.cc
00001 /* This file is part of the KDE project 00002 Copyright (C) 2005, Inge Wallin 00003 00004 This library is free software; you can redistribute it and/or 00005 modify it under the terms of the GNU Library General Public 00006 License as published by the Free Software Foundation; either 00007 version 2 of the License, or (at your option) any later version. 00008 00009 This library is distributed in the hope that it will be useful, 00010 but WITHOUT ANY WARRANTY; without even the implied warranty of 00011 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00012 Library General Public License for more details. 00013 00014 You should have received a copy of the GNU Library General Public License 00015 along with this library; see the file COPYING.LIB. If not, write to 00016 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, 00017 * Boston, MA 02110-1301, USA. 00018 */ 00019 00020 #include <klocale.h> 00021 00022 #include "vdocument.h" 00023 #include "vlayer.h" 00024 #include "vselection.h" 00025 #include "vinsertcmd.h" 00026 #include "vtransformcmd.h" 00027 00028 00029 VInsertCmd::VInsertCmd( VDocument *doc, const QString& name, 00030 VObjectList *objects, 00031 double offset ) 00032 : VCommand( doc, name, "14_insert" ), 00033 m_objects( *objects ), 00034 m_offset( offset ) 00035 { 00036 } 00037 00038 VInsertCmd::~VInsertCmd() 00039 { 00040 } 00041 00042 00043 void 00044 VInsertCmd::execute() 00045 { 00046 VObjectListIterator itr( m_objects ); 00047 00048 document()->selection()->clear(); 00049 for ( ; itr.current() ; ++itr ) { 00050 VObject *object = itr.current(); 00051 00052 if ( object->state() == VObject::deleted ) { 00053 object->setState( VObject::normal ); 00054 } 00055 else { 00056 document()->append( object ); 00057 00058 if ( m_offset != 0.0 ) { 00059 VTranslateCmd cmd( 0L, m_offset, -m_offset ); 00060 cmd.visit( *object ); 00061 } 00062 } 00063 00064 document()->selection()->append( object ); 00065 } 00066 00067 setSuccess( true ); 00068 } 00069 00070 00071 void 00072 VInsertCmd::unexecute() 00073 { 00074 document()->selection()->clear(); 00075 00076 VObjectListIterator itr( m_objects ); 00077 for ( ; itr.current() ; ++itr ) { 00078 itr.current()->setState( VObject::deleted ); 00079 } 00080 00081 setSuccess( false ); 00082 } 00083