Quantum GIS API Documentation  1.7.5-Wroclaw
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
qgscomposeritemcommand.cpp
Go to the documentation of this file.
1 /***************************************************************************
2  qgscomposeritemcommand.cpp
3  --------------------------
4  begin : 2010-11-18
5  copyright : (C) 2010 by Marco Hugentobler
6  email : marco dot hugentobler at sourcepole dot ch
7 ***************************************************************************/
8 
9 /***************************************************************************
10  * *
11  * This program is free software; you can redistribute it and/or modify *
12  * it under the terms of the GNU General Public License as published by *
13  * the Free Software Foundation; either version 2 of the License, or *
14  * (at your option) any later version. *
15  * *
16  ***************************************************************************/
17 
18 #include "qgscomposeritemcommand.h"
19 #include "qgscomposeritem.h"
20 
21 QgsComposerItemCommand::QgsComposerItemCommand( QgsComposerItem* item, const QString& text, QUndoCommand* parent ):
22  QUndoCommand( text, parent ), mItem( item ), mFirstRun( true )
23 {
24 }
25 
27 {
28 }
29 
31 {
33 }
34 
36 {
37  if ( mFirstRun )
38  {
39  mFirstRun = false;
40  return;
41  }
43 }
44 
46 {
47  return !( mPreviousState.isNull() || mAfterState.isNull() || mPreviousState.toString() == mAfterState.toString() );
48 }
49 
51 {
53 }
54 
56 {
58 }
59 
60 void QgsComposerItemCommand::saveState( QDomDocument& stateDoc ) const
61 {
62  if ( mItem )
63  {
64  stateDoc.clear();
65  QDomElement documentElement = stateDoc.createElement( "ComposerItemState" );
66  mItem->writeXML( documentElement, stateDoc );
67  stateDoc.appendChild( documentElement );
68  }
69 }
70 
71 void QgsComposerItemCommand::restoreState( QDomDocument& stateDoc ) const
72 {
73  if ( mItem )
74  {
75  mItem->readXML( stateDoc.documentElement().firstChild().toElement(), stateDoc );
76  mItem->repaint();
77  }
78 }
79 
80 QgsComposerMergeCommand::QgsComposerMergeCommand( Context c, QgsComposerItem* item, const QString& text ): QgsComposerItemCommand( item, text ), mContext( c )
81 {
82 }
83 
85 {
86 }
87 
88 bool QgsComposerMergeCommand::mergeWith( const QUndoCommand * command )
89 {
90  const QgsComposerItemCommand* c = dynamic_cast<const QgsComposerItemCommand*>( command );
91  if ( !c )
92  {
93  return false;
94  }
95  mAfterState = c->afterState();
96  return true;
97 }
98