QGIS API Documentation  2.99.0-Master (cd0ba91)
qgsaddremoveitemcommand.h
Go to the documentation of this file.
1 /***************************************************************************
2  qgsaddremoveitemcommand.h
3  ------------------------
4  begin : 2010-11-27
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 QGSADDREMOVEITEMCOMMAND_H
19 #define QGSADDREMOVEITEMCOMMAND_H
20 
21 #include <QUndoCommand>
22 #include "qgis.h"
23 
24 #include "qgis_core.h"
25 
26 class QgsComposerItem;
27 class QgsComposition;
28 
33 class CORE_EXPORT QgsAddRemoveItemCommand: public QObject, public QUndoCommand
34 {
35  Q_OBJECT
36 
37  public:
38 
39  enum State
40  {
41  Added = 0,
42  Removed
43  };
44 
45  QgsAddRemoveItemCommand( State s, QgsComposerItem *item, QgsComposition *c, const QString &text, QUndoCommand *parent SIP_TRANSFERTHIS = 0 );
47 
48  void redo() override;
49  void undo() override;
50 
51  signals:
52  void itemAdded( QgsComposerItem *item );
53  void itemRemoved( QgsComposerItem *item );
54 
55  private:
56  QgsComposerItem *mItem = nullptr;
57  QgsComposition *mComposition = nullptr;
58  State mState;
59  bool mFirstRun; //flag to prevent execution when the command is pushed to the QUndoStack
60 
61  //changes between added / removed state
62  void switchState();
63 };
64 
65 #endif // QGSADDREMOVEITEMCOMMAND_H
#define SIP_TRANSFERTHIS
Definition: qgis_sip.h:46
A item that forms part of a map composition.
Graphics scene for map printing.
A composer command class for adding / removing composer items.