Quantum GIS API Documentation
1.7.4
|
00001 /*************************************************************************** 00002 qgscomposeritemcommand.cpp 00003 -------------------------- 00004 begin : 2010-11-18 00005 copyright : (C) 2010 by Marco Hugentobler 00006 email : marco dot hugentobler at sourcepole dot ch 00007 ***************************************************************************/ 00008 00009 /*************************************************************************** 00010 * * 00011 * This program is free software; you can redistribute it and/or modify * 00012 * it under the terms of the GNU General Public License as published by * 00013 * the Free Software Foundation; either version 2 of the License, or * 00014 * (at your option) any later version. * 00015 * * 00016 ***************************************************************************/ 00017 00018 #include "qgscomposeritemcommand.h" 00019 #include "qgscomposeritem.h" 00020 00021 QgsComposerItemCommand::QgsComposerItemCommand( QgsComposerItem* item, const QString& text, QUndoCommand* parent ): 00022 QUndoCommand( text, parent ), mItem( item ), mFirstRun( true ) 00023 { 00024 } 00025 00026 QgsComposerItemCommand::~QgsComposerItemCommand() 00027 { 00028 } 00029 00030 void QgsComposerItemCommand::undo() 00031 { 00032 restoreState( mPreviousState ); 00033 } 00034 00035 void QgsComposerItemCommand::redo() 00036 { 00037 if ( mFirstRun ) 00038 { 00039 mFirstRun = false; 00040 return; 00041 } 00042 restoreState( mAfterState ); 00043 } 00044 00045 bool QgsComposerItemCommand::containsChange() const 00046 { 00047 return !( mPreviousState.isNull() || mAfterState.isNull() || mPreviousState.toString() == mAfterState.toString() ); 00048 } 00049 00050 void QgsComposerItemCommand::savePreviousState() 00051 { 00052 saveState( mPreviousState ); 00053 } 00054 00055 void QgsComposerItemCommand::saveAfterState() 00056 { 00057 saveState( mAfterState ); 00058 } 00059 00060 void QgsComposerItemCommand::saveState( QDomDocument& stateDoc ) const 00061 { 00062 if ( mItem ) 00063 { 00064 stateDoc.clear(); 00065 QDomElement documentElement = stateDoc.createElement( "ComposerItemState" ); 00066 mItem->writeXML( documentElement, stateDoc ); 00067 stateDoc.appendChild( documentElement ); 00068 } 00069 } 00070 00071 void QgsComposerItemCommand::restoreState( QDomDocument& stateDoc ) const 00072 { 00073 if ( mItem ) 00074 { 00075 mItem->readXML( stateDoc.documentElement().firstChild().toElement(), stateDoc ); 00076 mItem->repaint(); 00077 } 00078 } 00079 00080 QgsComposerMergeCommand::QgsComposerMergeCommand( Context c, QgsComposerItem* item, const QString& text ): QgsComposerItemCommand( item, text ), mContext( c ) 00081 { 00082 } 00083 00084 QgsComposerMergeCommand::~QgsComposerMergeCommand() 00085 { 00086 } 00087 00088 bool QgsComposerMergeCommand::mergeWith( const QUndoCommand * command ) 00089 { 00090 const QgsComposerItemCommand* c = dynamic_cast<const QgsComposerItemCommand*>( command ); 00091 if ( !c ) 00092 { 00093 return false; 00094 } 00095 mAfterState = c->afterState(); 00096 return true; 00097 } 00098