All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
Scene.h
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 Scene.h
22 
23  \brief Class representing the scene. This scene is child of QGraphicsScene, part of Graphics View Framework.
24  The scene is not drawn, but the items that are inserted into it. She is responsible for managing items QGraphicsItem and know when and how to redrawing them.
25  The scene has a coordinate system that is, by default, the same for all items that are inserted.
26  The coordinate system of this representation is millimeters and your point 0.0 is in the bottom left(Cartesian coordinate system).
27  The default settings of the layout module are in the object Context (singleton).
28 
29  \ingroup layout
30 */
31 
32 #ifndef __TERRALIB_LAYOUT_INTERNAL_SCENE_H
33 #define __TERRALIB_LAYOUT_INTERNAL_SCENE_H
34 
35 // TerraLib
36 #include "../../core/AbstractScene.h"
37 #include "../../core/Config.h"
38 #include "PrintScene.h"
39 #include "AlignItems.h"
40 #include "../item/MovingItemGroup.h"
41 
42 // STL
43 #include <string>
44 #include <vector>
45 #include <map>
46 
47 // Qt
48 #include <QGraphicsScene>
49 #include <QTransform>
50 #include <QColor>
51 #include <QPointF>
52 #include <QRectF>
53 
54 class QUndoCommand;
55 class QUndoStack;
56 class QGraphicsItemGroup;
57 class QPainter;
58 class QWidget;
59 class QStyleOptionGraphicsItem;
60 
61 namespace te
62 {
63  namespace layout
64  {
65  class EnumType;
66  class Properties;
67  class VisualizationArea;
68 
69  /*!
70  \brief Class representing the scene. This scene is child of QGraphicsScene, part of Graphics View Framework.
71  The scene is not drawn, but the items that are inserted into it. She is responsible for managing items QGraphicsItem and know when and how to redrawing them.
72  The scene has a coordinate system that is, by default, the same for all items that are inserted.
73  The coordinate system of this representation is millimeters and your point 0.0 is in the bottom left(Cartesian coordinate system).
74  The default settings of the layout module are in the object Context (singleton).
75 
76  \ingroup layout
77 
78  \sa te::layout::AbstractScene
79  */
80  class TELAYOUTEXPORT Scene : public QGraphicsScene, public AbstractScene
81  {
82  Q_OBJECT //for slots/signals
83 
84  public:
85 
86  /*!
87  \brief Constructor
88  */
89  Scene(QObject* object = (QObject*)0);
90 
91  /*!
92  \brief Constructor. The ownership of objects passed via parameter becomes the scene.
93 
94  \param align applying the alignment of one or more objects
95  \param print printing the entire content or part of the scene
96  */
97  Scene(AlignItems* align, PrintScene* print, QObject* object = 0);
98 
99  /*!
100  \brief Destructor
101  */
102  virtual ~Scene();
103 
104  /*!
105  \brief Method that inserts a graphic object in the scene. Inverts the matrix of the object if necessary, ex.: TextItem.
106 
107  \param item graphic object
108  */
109  virtual void insertItem(ItemObserver* item);
110 
111  /*!
112  \brief Method that inserts a graphic object in the scene. Inverts the matrix of the object if necessary, ex.: TextItem.
113 
114  \param item graphic object
115  */
116  virtual void insertItem(QGraphicsItem* item);
117 
118  /*!
119  \brief Method that starts the scene and configures. Calculates the transformation matrix of the scene and calculates the ratio of the size of the scene with the paper size.
120 
121  \param screenWMM width of physical screen in millimeters
122  \param screenHMM height of physical screen in millimeters
123  */
124  virtual void init(double screenWMM, double screenHMM);
125 
126  /*!
127  \brief Method that returns the matrix transformation scene.
128 
129  \return transformation matrix
130  */
131  virtual QTransform sceneTransform();
132 
133  /*!
134  \brief Method that deletes all selected items in the scene.
135  */
136  virtual void deleteItems();
137 
138  /*!
139  \brief Method that removes all selected items in the scene and creates a Command to Undo/Redo of type DeleteCommand. The item is removed from the scene, but is not deleted.
140  */
141  virtual void removeSelectedItems();
142 
143  /*!
144  \brief Groups objects and creates a QGraphicsItemGroup object. A command Undo/Redo of type AddCommand is created.
145 
146  \param list of objects
147 
148  \return items group of objects
149  */
150  virtual QGraphicsItemGroup* createItemGroup( const QList<QGraphicsItem *> & items );
151 
152 
153  virtual te::layout::MovingItemGroup* createMovingItemGroup( const QList<QGraphicsItem*>& items);
154 
155  /*!
156  \brief Method that delete object grouping, but the individual objects continue to exist.
157 
158  \param group list of objects
159  */
160  virtual void destroyItemGroup( QGraphicsItemGroup *group );
161 
162  /*!
163  \brief Method that create a graphic object and place it in the scene. A name and a position is added. A command Undo/Redo of type AddCommand is created.
164 
165  \param coord Coordinated where the item is located. The coordinate should be the same scene coordinates system
166  */
167  virtual QGraphicsItem* createItem( const te::gm::Coord2D& coord );
168 
169  /*!
170  \brief Method that insert command Undo/Redo of type AddCommand in the Undo/Redo stack.
171 
172  \param command command
173  */
174  virtual void addUndoStack( QUndoCommand* command );
175 
176  /*!
177  \brief Method that limits the size of the stack of Undo/Redo.
178 
179  \param limit limit
180  */
181  virtual void setUndoStackLimit( int limit );
182 
183  /*!
184  \brief Method that returns the size limit of the stack Undo/Redo.
185 
186  \return limit
187  */
188  virtual int getUndoStackLimit();
189 
190  /*!
191  \brief Method that return stack of Undo/Redo.
192 
193  \return stack
194  */
195  virtual QUndoStack* getUndoStack();
196 
197  /*!
198  \brief Method that resets the scene and calculates again.
199 
200  \param widthMM width of physical screen in millimeters
201  \param heightMM height of physical screen in millimeters
202  */
203  virtual void calculateSceneMeasures(double widthMM, double heightMM);
204 
205  /*!
206  \brief Method that returns the object responsible for printing the scene.
207 
208  \return print object
209  */
210  virtual PrintScene* getPrintScene();
211 
212  /*!
213  \brief Method that returns the object responsible for aligning objects in the scene.
214 
215  \return align object
216  */
217  virtual AlignItems* getAlignItems();
218 
219  /*!
220  \brief Method that exports all the objects in the scene to a template. Ex.: JSON.
221 
222  \param type type of template. Ex .: JSON type
223  \param fileName Full path where the template is saved.
224 
225  \return true if exported, false otherwise
226  */
227  virtual bool exportPropertiesToTemplate(EnumType* type, std::string fileName);
228 
229  /*!
230  \brief Method that imports a template and turns it into properties. Ex.: JSON.
231 
232  \param type type of template. Ex .: JSON type
233  \param fileName Full path where the template is saved
234 
235  \return true list of properties, false list of empty properties
236  */
237  virtual std::vector<te::layout::Properties*> importTemplateToProperties(EnumType* type, std::string fileName);
238 
239  /*!
240  \brief Method that clears the scene and the stack of Undo/Redo.
241  */
242  virtual void reset();
243 
244  /*!
245  \brief Method that import a template and build all objects. Ex.: JSON.
246 
247  \param type type of template. Ex .: JSON type
248  \param fileName Full path where the template is saved.
249 
250  \return true if exported, false otherwise
251  */
252  virtual bool buildTemplate(VisualizationArea* vzArea, EnumType* type, std::string fileName);
253 
254  /*!
255  \brief Redraws the Layer of the selected map.
256  */
257  virtual void redrawSelectionMap();
258 
259  /*!
260  \brief Saves each item in the scene as image. Ex .: .png.
261 
262  \param dir Full path where the images will be saved
263  */
264  virtual void exportItemsToImage(std::string dir);
265 
266  /*!
267  \brief Reimplemented from QGraphicsScene
268  */
269  virtual bool eventFilter ( QObject * watched, QEvent * event );
270 
271  /*!
272  \brief Select an item an item by name.
273 
274  \param name graphic object name
275  */
276  virtual void selectItem(std::string name);
277  /*!
278  \brief Select items by name.
279 
280  \param names vector with object names
281  */
282  virtual void selectItems(std::vector<std::string> names);
283 
284  /*!
285  \brief Select items.
286 
287  \param items vector with QGraphicsItems
288  */
289  virtual void selectItems(QList<QGraphicsItem*> items);
290 
291  /*!
292  \brief Select specified item.
293 
294  \param item instance of QGraphicsItem
295  */
296  virtual void selectItem(QGraphicsItem* item);
297 
298  virtual void redrawItems();
299 
300  virtual void updateSelectedItemsPositions();
301 
302  /*
303  \brief Add to stack that stores the items that are not entered into the scene.
304  To undo/redo operations, where the item is removed from the scene,
305  a single place to store it is necessary, and if necessary, delete the items that are not entered into the scene (scene destructor).
306 
307  \param item
308  */
309 
310  virtual bool addItemStackWithoutScene(QGraphicsItem* item);
311 
312  /*
313  \brief Remove from stack that stores the items that are not entered into the scene.
314  To undo/redo operations, where the item is removed from the scene,
315  a single place to store it is necessary, and if necessary, delete the items that are not entered into the scene (scene destructor).
316 
317  \param item
318  */
319  virtual bool removeItemStackWithoutScene(QGraphicsItem* item);
320 
321  public slots:
322 
323  /*!
324  \brief It is called immediately when the zoom factor is changed in the Context.
325 
326  \param currentZoomFactor current zoom factor of the layout module
327  */
328  virtual void onChangeZoomFactor(double currentFactor);
329 
330  signals:
331 
332  /*!
333  \brief Issued after insertion of an item in the scene.
334  */
335  void addItemFinalized();
336 
337  /*!
338  \brief Issued after deleting an item in the scene.
339 
340  \param names names of items removed
341  */
342  void deleteFinalized(std::vector<std::string> names);
343 
344  protected:
345 
346  /*!
347  \brief Method that calculates the transformation matrix of the scene. This matrix will be set in each QGraphicsView class that watches this scene.
348  */
349  virtual void calculateMatrixViewScene();
350 
351  /*!
352  \brief Method that calculates the ratio of the size of the scene with the paper size. This calculation is necessary so that the paper always is centered in the scene.
353 
354  \param wMM width of physical screen in millimeters
355  \param hMM height of physical screen in millimeters
356  */
357  virtual void calculateWindow(double wMM, double hMM);
358 
359  /*!
360  \brief Method that returns a list of the properties of all the graphic objects in the scene.
361 
362  \return list of properties
363  */
364  virtual std::vector<te::layout::Properties*> getItemsProperties();
365 
366  protected:
367 
368  QTransform m_matrix; //!< transformation matrix of the scene.
369  QColor m_backgroundColor; //!< background color that is applied to each observer(QGraphicsView) of the scene.
370  QUndoStack* m_undoStack; //!< Undo/Redo stack
371  int m_undoStackLimit; //!< Undo/Redo limit size
372  AlignItems* m_align; //!< object responsible for aligning objects in the scene.
373  PrintScene* m_print; //!< object responsible for printing the scene.
375  std::map<QGraphicsItem*, QPointF> m_moveWatches;
376  QList<QGraphicsItem*> m_itemStackWithoutScene; //!< Items that are not included in any scene
377  };
378  }
379 }
380 
381 #endif
382 
383 
384 
385 
QUndoStack * m_undoStack
Undo/Redo stack.
Definition: Scene.h:370
#define TELAYOUTEXPORT
You can use this macro in order to export/import classes and functions from this module.
Definition: Config.h:99
Creates the viewing area. Ex.: creation of the sheet of paper.
QColor m_backgroundColor
background color that is applied to each observer(QGraphicsView) of the scene.
Definition: Scene.h:369
Class applying the alignment of one or more objects. Ex .: send to back, bring to front...
Definition: AlignItems.h:49
Class applying the alignment of one or more objects. Ex .: send to back, bring to front...
QTransform m_matrix
transformation matrix of the scene.
Definition: Scene.h:368
Abstract class to represent an observer. "View" part of MVC component. All classes representing the g...
Definition: ItemObserver.h:52
An utility struct for representing 2D coordinates.
Definition: Coord2D.h:40
QList< QGraphicsItem * > m_itemStackWithoutScene
Items that are not included in any scene.
Definition: Scene.h:376
int m_undoStackLimit
Undo/Redo limit size.
Definition: Scene.h:371
Class representing the scene. This scene is child of QGraphicsScene, part of Graphics View Framework...
Definition: Scene.h:80
std::map< QGraphicsItem *, QPointF > m_moveWatches
Definition: Scene.h:375
AlignItems * m_align
object responsible for aligning objects in the scene.
Definition: Scene.h:372
Abstract scene for Scene, a QGraphicsScene class, part of Graphics View Framework.
Definition: AbstractScene.h:48
PrintScene * m_print
object responsible for printing the scene.
Definition: Scene.h:373
bool m_moveWatched
Definition: Scene.h:374
Class that represents the value of an enumeration. An enumeration is made of "1..n" objects EnumType...
Definition: EnumType.h:48
Class responsible for printing the entire content or part of the scene. As the scene is upside down...
Definition: PrintScene.h:54
Class responsible for printing the entire content or part of the scene. As the scene is upside down...