karbon
vlayercmd.cc
00001 /* This file is part of the KDE project 00002 Copyright (C) 2001, The Karbon Developers 00003 Copyright (C) 2002, The Karbon Developers 00004 00005 This library is free software; you can redistribute it and/or 00006 modify it under the terms of the GNU Library General Public 00007 License as published by the Free Software Foundation; either 00008 version 2 of the License, or (at your option) any later version. 00009 00010 This library is distributed in the hope that it will be useful, 00011 but WITHOUT ANY WARRANTY; without even the implied warranty of 00012 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00013 Library General Public License for more details. 00014 00015 You should have received a copy of the GNU Library General Public License 00016 along with this library; see the file COPYING.LIB. If not, write to 00017 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, 00018 * Boston, MA 02110-1301, USA. 00019 */ 00020 00021 #include "vlayer.h" 00022 #include "vlayercmd.h" 00023 #include "vdocument.h" 00024 00025 VLayerCmd::VLayerCmd( VDocument* doc, const QString& name, VLayer* layer, VLayerCmdType order ) 00026 : VCommand( doc, name, "14_layers" ), m_layer( layer ), m_cmdType( order ) 00027 { 00028 if( order == addLayer ) 00029 { 00030 layer->setState( VObject::deleted ); 00031 document()->insertLayer( layer ); 00032 } 00033 00034 m_oldState = layer->state(); 00035 } 00036 00037 void 00038 VLayerCmd::execute() 00039 { 00040 switch( m_cmdType ) 00041 { 00042 case addLayer: 00043 m_layer->setState( VObject::normal ); 00044 break; 00045 00046 case deleteLayer: 00047 m_layer->setState( VObject::deleted ); 00048 break; 00049 00050 case raiseLayer: 00051 document()->raiseLayer( m_layer ); 00052 break; 00053 00054 case lowerLayer: 00055 document()->lowerLayer( m_layer ); 00056 break; 00057 } 00058 00059 setSuccess( true ); 00060 } 00061 00062 void 00063 VLayerCmd::unexecute() 00064 { 00065 switch ( m_cmdType ) 00066 { 00067 case addLayer: 00068 m_layer->setState( VObject::deleted ); 00069 break; 00070 00071 case deleteLayer: 00072 m_layer->setState( m_oldState ); 00073 break; 00074 00075 case raiseLayer: 00076 document()->lowerLayer( m_layer ); 00077 break; 00078 00079 case lowerLayer: 00080 document()->raiseLayer( m_layer ); 00081 break; 00082 } 00083 00084 setSuccess( false ); 00085 } 00086