QGIS API Documentation  2.2.0-Valmiera
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties 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 #include "qgsproject.h"
21 
22 QgsComposerItemCommand::QgsComposerItemCommand( QgsComposerItem* item, const QString& text, QUndoCommand* parent ):
23  QUndoCommand( text, parent ), mItem( item ), mFirstRun( true )
24 {
25 }
26 
28 {
29 }
30 
32 {
34 }
35 
37 {
38  if ( mFirstRun )
39  {
40  mFirstRun = false;
41  return;
42  }
44 }
45 
47 {
48  return !( mPreviousState.isNull() || mAfterState.isNull() || mPreviousState.toString() == mAfterState.toString() );
49 }
50 
52 {
54 }
55 
57 {
59 }
60 
61 void QgsComposerItemCommand::saveState( QDomDocument& stateDoc ) const
62 {
63  if ( mItem )
64  {
65  stateDoc.clear();
66  QDomElement documentElement = stateDoc.createElement( "ComposerItemState" );
67  mItem->writeXML( documentElement, stateDoc );
68  stateDoc.appendChild( documentElement );
69  }
70 }
71 
72 void QgsComposerItemCommand::restoreState( QDomDocument& stateDoc ) const
73 {
74  if ( mItem )
75  {
76  mItem->readXML( stateDoc.documentElement().firstChild().toElement(), stateDoc );
77  mItem->repaint();
78  QgsProject::instance()->dirty( true );
79  }
80 }
81 
82 QgsComposerMergeCommand::QgsComposerMergeCommand( Context c, QgsComposerItem* item, const QString& text ): QgsComposerItemCommand( item, text ), mContext( c )
83 {
84 }
85 
87 {
88 }
89 
90 bool QgsComposerMergeCommand::mergeWith( const QUndoCommand * command )
91 {
92  const QgsComposerItemCommand* c = dynamic_cast<const QgsComposerItemCommand*>( command );
93  if ( !c || mItem != c->item() )
94  {
95  return false;
96  }
97  mAfterState = c->afterState();
98  return true;
99 }
100