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