QGIS API Documentation  2.99.0-Master (0cba29c)
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 
32 class CORE_EXPORT QgsAddRemoveItemCommand: public QObject, public QUndoCommand
33 {
34  Q_OBJECT
35 
36  public:
37 
38  enum State
39  {
40  Added = 0,
41  Removed
42  };
43 
44  QgsAddRemoveItemCommand( State s, QgsComposerItem *item, QgsComposition *c, const QString &text, QUndoCommand *parent SIP_TRANSFERTHIS = 0 );
46 
47  void redo() override;
48  void undo() override;
49 
50  signals:
51  void itemAdded( QgsComposerItem *item );
52  void itemRemoved( QgsComposerItem *item );
53 
54  private:
55  QgsComposerItem *mItem = nullptr;
56  QgsComposition *mComposition = nullptr;
57  State mState;
58  bool mFirstRun; //flag to prevent execution when the command is pushed to the QUndoStack
59 
60  //changes between added / removed state
61  void switchState();
62 };
63 
64 #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.