QGIS API Documentation  2.99.0-Master (b95d432)
qgscomposermultiframecommand.cpp
Go to the documentation of this file.
1 /***************************************************************************
2  qgscomposermultiframecommand.cpp
3  --------------------------------
4  begin : 2012-08-02
5  copyright : (C) 2012 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 
19 #include "qgscomposermultiframe.h"
20 #include "qgscomposition.h"
21 #include "qgsproject.h"
22 
23 QgsComposerMultiFrameCommand::QgsComposerMultiFrameCommand( QgsComposerMultiFrame *multiFrame, const QString &text, QUndoCommand *parent ):
24  QUndoCommand( text, parent ), mMultiFrame( multiFrame ), mFirstRun( true )
25 {
26 }
27 
28 QgsComposerMultiFrameCommand::QgsComposerMultiFrameCommand(): QUndoCommand( QLatin1String( "" ), nullptr ), mMultiFrame( nullptr ), mFirstRun( false )
29 {
30 }
31 
33 {
35 }
36 
38 {
39  if ( checkFirstRun() )
40  {
41  return;
42  }
44 }
45 
47 {
49 }
50 
52 {
54 }
55 
56 void QgsComposerMultiFrameCommand::saveState( QDomDocument &stateDoc )
57 {
58  if ( mMultiFrame )
59  {
60  stateDoc.clear();
61  QDomElement documentElement = stateDoc.createElement( QStringLiteral( "ComposerMultiFrameState" ) );
62  mMultiFrame->writeXml( documentElement, stateDoc );
63  stateDoc.appendChild( documentElement );
64  }
65 }
66 
67 void QgsComposerMultiFrameCommand::restoreState( QDomDocument &stateDoc )
68 {
69  if ( mMultiFrame )
70  {
71  mMultiFrame->readXml( stateDoc.documentElement().firstChild().toElement(), stateDoc );
72  mMultiFrame->composition()->project()->setDirty( true );
73  }
74 }
75 
77 {
78  if ( !mFirstRun )
79  {
80  return false;
81  }
82  mFirstRun = false;
83  return true;
84 }
85 
87 {
88  return !( mPreviousState.isNull() || mAfterState.isNull() || mPreviousState.toString() == mAfterState.toString() );
89 }
90 
91 
93  : QgsComposerMultiFrameCommand( multiFrame, text )
94  , mContext( c )
95 {
96 
97 }
98 
99 bool QgsComposerMultiFrameMergeCommand::mergeWith( const QUndoCommand *command )
100 {
101  const QgsComposerMultiFrameCommand *c = dynamic_cast<const QgsComposerMultiFrameCommand *>( command );
102  if ( !c || mMultiFrame != c->multiFrame() )
103  {
104  return false;
105  }
106  mAfterState = c->afterState();
107  return true;
108 }
bool mergeWith(const QUndoCommand *command) override
void setDirty(bool b=true)
Flag the project as dirty (modified).
Definition: qgsproject.cpp:408
bool containsChange() const
Returns true if previous state and after state are valid and different.
const QgsComposerMultiFrame * multiFrame() const
void restoreState(QDomDocument &stateDoc)
void saveState(QDomDocument &stateDoc)
virtual bool readXml(const QDomElement &itemElem, const QDomDocument &doc, bool ignoreFrames=false)=0
Reads multiframe state information from a DOM element.
Abstract base class for composer items with the ability to distribute the content to several frames (...
virtual bool writeXml(QDomElement &elem, QDomDocument &doc, bool ignoreFrames=false) const =0
Stores state information about multiframe in DOM element.
QgsProject * project() const
The project associated with the composition.
QgsComposition * composition()
Returns the parent composition for the multiframe.
QgsComposerMultiFrameMergeCommand(Context c, QgsComposerMultiFrame *multiFrame, const QString &text)