karbon
vreplacingcmd.cc00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021 #include "vreplacingcmd.h"
00022 #include "vselection.h"
00023 #include "vdocument.h"
00024
00025 VReplacingCmd::VReplacingCmd( VDocument* doc, const QString& name )
00026 : VCommand( doc, name )
00027 {
00028
00029 m_oldObjects = doc ? document()->selection()->clone() : 0L;
00030 m_newObjects = 0L;
00031 }
00032
00033 VReplacingCmd::~VReplacingCmd()
00034 {
00035 delete( m_oldObjects );
00036 delete( m_newObjects );
00037 }
00038
00039 void
00040 VReplacingCmd::execute()
00041 {
00042
00043
00044 bool successful = false;
00045
00046
00047
00048 if( !m_newObjects )
00049 {
00050 m_newObjects = new VSelection();
00051
00052
00053 VObject* newObject;
00054
00055 VObjectListIterator itr( m_oldObjects->objects() );
00056 VObjectList rejects;
00057
00058 for( ; itr.current(); ++itr )
00059 {
00060
00061 newObject = itr.current()->clone();
00062
00063
00064 if( visit( *newObject ) )
00065 {
00066 successful = true;
00067
00068
00069 itr.current()->parent()->insertInfrontOf(
00070 newObject, itr.current() );
00071
00072
00073 m_newObjects->append( newObject );
00074 }
00075
00076 else
00077 {
00078 rejects.append( itr.current() );
00079
00080 delete( newObject );
00081 }
00082 }
00083 VObjectListIterator jtr( rejects );
00084 for( ; jtr.current(); ++jtr )
00085 {
00086
00087 m_oldObjects->take( *jtr.current() );
00088 }
00089 }
00090
00091
00092 if( m_newObjects->objects().count() == 0 )
00093 return;
00094
00095
00096 VObjectListIterator itr( m_oldObjects->objects() );
00097
00098
00099 for( ; itr.current(); ++itr )
00100 {
00101 document()->selection()->take( *itr.current() );
00102 itr.current()->setState( VObject::deleted );
00103 }
00104
00105
00106 for( itr = m_newObjects->objects(); itr.current(); ++itr )
00107 {
00108 itr.current()->setState( VObject::normal );
00109 document()->selection()->append( itr.current() );
00110 }
00111
00112
00113
00114 setSuccess( successful );
00115 }
00116
00117 void
00118 VReplacingCmd::unexecute()
00119 {
00120
00121 if( m_newObjects->objects().count() == 0 )
00122 return;
00123
00124
00125 VObjectListIterator itr( m_oldObjects->objects() );
00126
00127
00128 for( ; itr.current(); ++itr )
00129 {
00130 itr.current()->setState( VObject::normal );
00131 document()->selection()->append( itr.current() );
00132 }
00133
00134
00135 for( itr = m_newObjects->objects(); itr.current(); ++itr )
00136 {
00137 document()->selection()->take( *itr.current() );
00138 itr.current()->setState( VObject::deleted );
00139 }
00140
00141
00142
00143 setSuccess( false );
00144 }
00145
|