All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
DeleteCommand.cpp
Go to the documentation of this file.
1 /* Copyright (C) 2008 National Institute For Space Research (INPE) - Brazil.
2 
3  This file is part of the TerraLib - a Framework for building GIS enabled applications.
4 
5  TerraLib is free software: you can redistribute it and/or modify
6  it under the terms of the GNU Lesser General Public License as published by
7  the Free Software Foundation, either version 3 of the License,
8  or (at your option) any later version.
9 
10  TerraLib is distributed in the hope that it will be useful,
11  but WITHOUT ANY WARRANTY; without even the implied warranty of
12  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  GNU Lesser General Public License for more details.
14 
15  You should have received a copy of the GNU Lesser General Public License
16  along with TerraLib. See COPYING. If not, write to
17  TerraLib Team at <terralib-team@terralib.org>.
18  */
19 
20 /*!
21  \file DeleteCommand.cpp
22 
23  \brief
24 
25  \ingroup layout
26 */
27 
28 // TerraLib
29 #include "DeleteCommand.h"
30 #include "../../../../core/pattern/mvc/ItemObserver.h"
31 #include "../../../../core/enum/EnumType.h"
32 #include "../../../../core/pattern/mvc/Observable.h"
33 #include "../../Scene.h"
34 
35 // Qt
36 #include <QGraphicsScene>
37 #include <QGraphicsItem>
38 
39 te::layout::DeleteCommand::DeleteCommand( QGraphicsScene* scene, QUndoCommand *parent /*= 0*/ ) :
40  QUndoCommand(parent),
41  m_scene(scene)
42 {
43  m_items = m_scene->selectedItems();
44 
45  foreach( QGraphicsItem *item, m_items )
46  {
47  item->setSelected(false);
48  }
49 
50  int size = m_items.size();
51 
52  setText(QObject::tr("Delete %1")
53  .arg(createCommandString(size)));
54 }
55 
57 {
58 
59 }
60 
62 {
63  Scene* scene = dynamic_cast<Scene*>(m_scene);
64 
65  if(!scene)
66  return;
67 
68  foreach( QGraphicsItem *item, m_items )
69  {
70  item->setSelected(false);
71 
72  if(item->scene() != m_scene)
73  {
74  scene->insertItem(item);
75  scene->removeItemStackWithoutScene(item);
76  }
77  }
78 
79  m_scene->update();
80 }
81 
83 {
84  Scene* scene = dynamic_cast<Scene*>(m_scene);
85 
86  if(!scene)
87  return;
88 
89  foreach( QGraphicsItem *item, m_items )
90  {
91  if(item->scene() == m_scene)
92  {
93  m_scene->removeItem(item);
94  scene->addItemStackWithoutScene(item);
95  }
96  }
97 }
98 
100 {
101  return QObject::tr("%1")
102  .arg(totalItems);
103 }
104 
105 
106 
virtual ~DeleteCommand()
Destructor.
virtual void undo()
Reimplemented from QUndoCommand.
QGraphicsScene * m_scene
Definition: DeleteCommand.h:82
virtual void redo()
Reimplemented from QUndoCommand.
virtual QString createCommandString(int totalItems)
virtual bool addItemStackWithoutScene(QGraphicsItem *item)
Definition: Scene.cpp:810
Undo/Redo for delete one or more components.
Class representing the scene. This scene is child of QGraphicsScene, part of Graphics View Framework...
Definition: Scene.h:80
DeleteCommand(QGraphicsScene *scene, QUndoCommand *parent=0)
Constructor.
virtual bool removeItemStackWithoutScene(QGraphicsItem *item)
Definition: Scene.cpp:832
virtual void insertItem(ItemObserver *item)
Method that inserts a graphic object in the scene. Inverts the matrix of the object if necessary...
Definition: Scene.cpp:116
QList< QGraphicsItem * > m_items
Definition: DeleteCommand.h:83