QGIS API Documentation  2.18.21-Las Palmas (9fba24a)
qgscomposeritemcommand.h
Go to the documentation of this file.
1 /***************************************************************************
2  qgscomposeritemcommand.h
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 #ifndef QGSCOMPOSERITEMCOMMAND_H
19 #define QGSCOMPOSERITEMCOMMAND_H
20 
21 #include <QUndoCommand>
22 #include <QDomDocument>
23 
24 class QgsComposerItem;
26 
30 class CORE_EXPORT QgsComposerItemCommand: public QUndoCommand
31 {
32  public:
33  QgsComposerItemCommand( QgsComposerItem* item, const QString& text, QUndoCommand* parent = nullptr );
34  virtual ~QgsComposerItemCommand();
35 
37  void undo() override;
39  void redo() override;
40 
42  void savePreviousState();
44  void saveAfterState();
45 
46  QDomDocument previousState() const { return mPreviousState.cloneNode().toDocument(); }
47  QDomDocument afterState() const { return mAfterState.cloneNode().toDocument(); }
48 
50  bool containsChange() const;
51 
55  QgsComposerItem *item() const;
56 
57  protected:
64 
69 
71  bool mFirstRun;
72 
73  void saveState( QDomDocument& stateDoc ) const;
74  void restoreState( QDomDocument& stateDoc ) const;
75 };
76 
82 {
83  public:
84  enum Context
85  {
86  Unknown = 0,
87  //composer label
90  //composer map
93  //composer legend
110  //composer picture
113  // composer scalebar
123  // composer table
127  //composer shape
130  //composer arrow
133  //item
138  ItemZoomContent
139  };
140 
141  QgsComposerMergeCommand( Context c, QgsComposerItem* item, const QString& text );
143 
144  bool mergeWith( const QUndoCommand * command ) override;
145  int id() const override { return static_cast< int >( mContext ); }
146 
147  private:
148  Context mContext;
149 };
150 
151 #endif // QGSCOMPOSERITEMCOMMAND_H
QDomDocument afterState() const
A item that forms part of a map composition.
A composer command that merges together with other commands having the same context (=id)...
virtual bool mergeWith(const QUndoCommand *command)
QDomDocument previousState() const
Abstract base class for composer items with the ability to distribute the content to several frames (...
virtual void redo()
bool mFirstRun
Flag to prevent the first redo() if the command is pushed to the undo stack.
virtual void undo()
Undo command to undo/redo all composer item related changes.
QDomDocument mAfterState
XML containing the state after executing the command.
QDomNode cloneNode(bool deep) const
QgsComposerItem * mItem
Target item of the command.
QgsComposerMultiFrame * mMultiFrame
Parameters for frame items.
QDomDocument toDocument() const
QDomDocument mPreviousState
XML that saves the state before executing the command.