30 #include "../../core/pattern/mvc/ItemObserver.h"
31 #include "../../core/pattern/mvc/Observable.h"
32 #include "../../core/pattern/singleton/Context.h"
33 #include "../../core/enum/Enums.h"
35 #include "../item/ItemGroup.h"
38 #include "../../core/AbstractBuildGraphicsItem.h"
39 #include "../../core/template/TemplateEditor.h"
40 #include "../../core/template/AbstractTemplate.h"
41 #include "../../core/property/Properties.h"
43 #include "../../../qt/widgets/Utils.h"
44 #include "../../core/Utils.h"
45 #include "../../../common/STLUtils.h"
46 #include "../item/MapItem.h"
53 #include <QUndoCommand>
55 #include <QGraphicsItem>
57 #include <QStyleOptionGraphicsItem>
59 #include <QGraphicsTextItem>
62 QGraphicsScene(object),
75 QGraphicsScene(object),
86 m_moveWatches.clear();
94 foreach( QGraphicsItem *item, m_itemStackWithoutScene )
96 if(item->scene() !=
this)
123 QGraphicsItem* qitem = ((QGraphicsItem*)item);
135 if(item->scene() ==
this)
142 total = this->items().count();
154 QTransform transfItem = item->transform();
156 if(transfItem != m_matrix.inverted())
158 QTransform transf = m_matrix.inverted();
159 item->setTransform(transf);
163 item->setZValue(total);
164 QGraphicsObject* qObj =
dynamic_cast<QGraphicsObject*
>(item);
167 qObj->installEventFilter(
this);
172 removeItemStackWithoutScene(item);
174 emit addItemFinalized();
179 calculateSceneMeasures(screenWMM, screenHMM);
198 double llx = m_box.m_llx;
199 double lly = m_box.m_lly;
200 double urx = m_box.m_urx;
201 double ury = m_box.m_ury;
205 double factor = (dpiX / 25.4);
208 m_matrix = QTransform().scale(factor, -factor).translate(-llx, -ury);
210 setSceneRect(QRectF(QPointF(llx, lly), QPointF(urx, ury)));
230 double minX = std::min(ppSizeWMM, wMM);
231 double maxX = std::max(ppSizeWMM, wMM);
233 paddingX = (maxX - minX) / 2;
235 x2 = maxX - paddingX;
238 double minY = std::min(ppSizeHMM, hMM);
239 double maxY = std::max(ppSizeHMM, hMM);
241 paddingY = (maxY - minY) / 2;
243 y2 = maxY - paddingY;
258 std::vector<std::string> names;
260 QList<QGraphicsItem*> graphicsItems = selectedItems();
261 foreach( QGraphicsItem *item, graphicsItems)
281 emit deleteFinalized(names);
286 std::vector<std::string> names;
288 QList<QGraphicsItem*> graphicsItems = selectedItems();
290 if(graphicsItems.empty())
293 foreach( QGraphicsItem *item, graphicsItems)
307 addUndoStack(command);
310 emit deleteFinalized(names);
315 m_undoStack->push(command);
320 m_undoStackLimit = limit;
325 return m_undoStackLimit;
336 QGraphicsItemGroup* p = QGraphicsScene::createItemGroup(items);
356 QGraphicsItem* parent = group->parentItem();
357 group->setParentItem(p->parentItem());
358 foreach (QGraphicsItem *item, p->childItems())
365 group->setParentItem(parent);
367 QUndoCommand* command =
new AddCommand(group);
368 addUndoStack(command);
377 group->setHandlesChildEvents(
false);
378 QGraphicsScene::destroyItemGroup(group);
389 QGraphicsItem* item = 0;
397 foreach(QGraphicsItem* i, items)
402 movingItem->setHandlesChildEvents(
true);
410 QGraphicsItem* item = 0;
431 addUndoStack(command);
443 calculateWindow(widthMM, heightMM);
445 double w = m_box.getWidth();
446 double h = m_box.getHeight();
448 calculateWindow(w,h);
450 calculateMatrixViewScene();
465 bool is_export =
false;
467 if(fileName.compare(
"") == 0)
472 std::vector<te::layout::Properties*> props = getItemsProperties();
491 std::vector<te::layout::Properties*> props;
493 if(fileName.compare(
"") == 0)
512 std::vector<te::layout::Properties*> props;
514 QList<QGraphicsItem*> graphicsItems = items();
515 foreach( QGraphicsItem *item, graphicsItems)
539 if(m_undoStack->count() > 0)
540 m_undoStack->clear();
553 std::vector<te::layout::Properties*> props = importTemplateToProperties(type, fileName);
560 std::vector<te::layout::Properties*>::iterator it;
565 for(it = props.begin() ; it != props.end() ; ++it)
580 QList<QGraphicsItem*> selected = selectedItems();
581 foreach(QGraphicsItem *item, selected)
602 QList<QGraphicsItem*> selected = selectedItems();
603 foreach(QGraphicsItem *item, selected)
631 img->save(dirName.c_str());
644 if(event->type() == QEvent::GraphicsSceneMousePress)
646 QGraphicsItem* item =
dynamic_cast<QGraphicsItem*
>(watched);
649 QList<QGraphicsItem*> its = selectedItems();
650 m_moveWatches.clear();
653 QPointF pt = item->scenePos();
654 m_moveWatches[item] = pt;
656 foreach(QGraphicsItem *item, its)
658 QPointF pt = item->scenePos();
659 m_moveWatches[item] = pt;
664 if(event->type() == QEvent::GraphicsSceneMouseMove)
666 QGraphicsItem* item =
dynamic_cast<QGraphicsItem*
>(watched);
669 bool resultFound =
false;
670 std::map<QGraphicsItem*, QPointF>::iterator it;
671 for(it = m_moveWatches.begin() ; it != m_moveWatches.end() ; ++it)
673 if(it->first == item)
681 m_moveWatches.clear();
682 QPointF pt = item->scenePos();
683 m_moveWatches[item] = pt;
686 m_moveWatched =
true;
690 if(event->type() == QEvent::GraphicsSceneMouseRelease)
692 QGraphicsItem* item =
dynamic_cast<QGraphicsItem*
>(watched);
697 QUndoCommand* command =
new MoveCommand(m_moveWatches);
698 addUndoStack(command);
699 m_moveWatched =
false;
704 return QGraphicsScene::eventFilter(watched, event);
709 QList<QGraphicsItem*> allItems = items();
710 foreach(QGraphicsItem *item, allItems)
724 item->setSelected(
true);
728 item->setSelected(
false);
739 item->setSelected(
true);
745 foreach(std::string name, names)
747 this->selectItem(name);
753 foreach(QGraphicsItem* item, items)
755 this->selectItem(item);
761 QList<QGraphicsItem*> allItems = items();
762 foreach(QGraphicsItem *item, allItems)
780 QList<QGraphicsItem*> allItems = selectedItems();
781 foreach(QGraphicsItem *item, allItems)
796 QList<QGraphicsItem*> allItems = items();
797 foreach(QGraphicsItem *item, allItems)
817 if(item->scene() ==
this)
822 if(m_itemStackWithoutScene.contains(item))
827 m_itemStackWithoutScene.push_back(item);
839 return m_itemStackWithoutScene.removeOne(item);
QUndoStack * m_undoStack
Undo/Redo stack.
Class to represent a graphic object (MVC component) and widget object (MVC widget) type enumeration...
virtual void reset()
Method that clears the scene and the stack of Undo/Redo.
virtual void redrawSelectionMap()
Redraws the Layer of the selected map.
Class responsible for paper setting. Size, orientation, custom size, etc.
virtual ~Scene()
Destructor.
virtual te::color::RGBAColor ** getRGBAColorImage(int &w, int &h)=0
Returns a image of the graphic component. Reimplement this function in a ItemObserver subclass to pro...
Creates the viewing area. Ex.: creation of the sheet of paper.
virtual EnumModeType * getEnumModeType()
Returns mode type enumeration.
Class that represents the grouping of objects of type QGraphicsItem, MVC components. Its coordinate system is the same of scene (millimeters). He is also the son of ItemObserver and ObjectItem, so it can become observer of a model (Observable).
QColor m_backgroundColor
background color that is applied to each observer(QGraphicsView) of the scene.
Undo/Redo for add one components.
Class applying the alignment of one or more objects. Ex .: send to back, bring to front...
Class representing the scene. This scene is child of QGraphicsScene, part of Graphics View Framework...
Creates the viewing area. Ex.: creation of the sheet of paper.
The Properties class represents a persistent set of properties. The Properties can be saved to a file...
Abstract class to represent an observer. "View" part of MVC component. All classes representing the g...
An utility struct for representing 2D coordinates.
virtual void deleteItems()
Method that deletes all selected items in the scene.
virtual te::layout::AbstractTemplate * getTemplate()
QGraphicsItem * createItem(te::layout::EnumType *mode, const te::gm::Coord2D &coordinate, bool draw=true)
Method to create a graphic object from the properties.
virtual EnumObjectType * getEnumObjectType()
Returns graphic object (MVC component) and widget object (MVC widget) type enumeration.
virtual void selectItem(std::string name)
Select an item an item by name.
virtual bool isInvertedMatrix()
Returns whether the graph component has the inverted matrix, otherwise the matrix scene...
virtual void redraw(bool bRefresh=true)
Redraws the graphic component.
virtual bool isPrintable()
Returns whether the graphic component is printable.
virtual void onChangeZoomFactor(double currentFactor)
It is called immediately when the zoom factor is changed in the Context.
virtual bool exportPropertiesToTemplate(EnumType *type, std::string fileName)
Method that exports all the objects in the scene to a template. Ex.: JSON.
virtual void selectItems(std::vector< std::string > names)
Select items by name.
virtual AlignItems * getAlignItems()
Method that returns the object responsible for aligning objects in the scene.
Class responsible for creating or building graphics objects. All objects are children of QGraphicsIte...
virtual EnumType * getModeCreateItemGroup() const
Returns value that represents create item group mode type belonging to enumeration.
void Free(std::vector< T * > *v)
This function can be applied to a pointer to a vector of pointers.
virtual bool buildTemplate(VisualizationArea *vzArea, EnumType *type, std::string fileName)
Method that import a template and build all objects. Ex.: JSON.
virtual void changeZoomFactor(double currentZoomFactor)
It is called immediately by the Scene when the zoom factor is changed in the Context.
Scene(QObject *object=(QObject *) 0)
Constructor.
virtual PrintScene * getPrintScene()
Method that returns the object responsible for printing the scene.
virtual QGraphicsItemGroup * createItemGroup(const QList< QGraphicsItem * > &items)
Groups objects and creates a QGraphicsItemGroup object. A command Undo/Redo of type AddCommand is cre...
virtual bool exportTemplate(std::vector< te::layout::Properties * > properties)=0
virtual void calculateMatrixViewScene()
Method that calculates the transformation matrix of the scene. This matrix will be set in each QGraph...
static Context & getInstance()
It returns a reference to the singleton instance.
Class to represent a mode type enumeration. Ex.: select, pan, create text, etc. The type of mode is u...
virtual QUndoStack * getUndoStack()
Method that return stack of Undo/Redo.
An Envelope defines a 2D rectangular region.
virtual bool isCanChangeGraphicOrder()
Returns whether the graphic component to be or not send to back or bring to front.
Undo/Redo for moving components.
virtual EnumType * getModeNone() const
Returns value that represents none mode type belonging to enumeration.
Utils * getUtils()
Returns pointer with functions to manipulate the canvas and conversion between projections.
virtual void redrawItems()
virtual void refresh(bool pos=true)
Updated model state.
virtual void init(double screenWMM, double screenHMM)
Method that starts the scene and configures. Calculates the transformation matrix of the scene and ca...
QGraphicsItem * rebuildItem(te::layout::Properties *props, bool draw=true)
Method to build a graphics object from the properties.
virtual bool addItemStackWithoutScene(QGraphicsItem *item)
virtual void changeBoxArea(te::gm::Envelope boxArea)
Undo/Redo for delete one or more components.
virtual te::layout::Properties * getProperties() const =0
Returns the model state as properties. Reimplement this function in a Observable subclass to provide ...
Calls the factory to create a template of the specified type and keep. Responsible for delete the cre...
EnumType * getMode()
Returns value of the enumeration of mode type.
AbstractBuildGraphicsItem * getAbstractBuildGraphicsItem()
Returns pointer for build graphics MVC components.
virtual std::vector< te::layout::Properties * > importTemplateToProperties(EnumType *type, std::string fileName)
Method that imports a template and turns it into properties. Ex.: JSON.
virtual void calculateSceneMeasures(double widthMM, double heightMM)
Method that resets the scene and calculates again.
virtual void addToGroup(QGraphicsItem *item)
Undo/Redo for delete one or more components.
virtual EnumType * getMovingItemGroup() const
Returns value that represents moving item group (MVC Component) type belonging to enumeration...
virtual void calculateWindow(double wMM, double hMM)
Method that calculates the ratio of the size of the scene with the paper size. This calculation is ne...
virtual void exportItemsToImage(std::string dir)
Saves each item in the scene as image. Ex .: .png.
virtual bool eventFilter(QObject *watched, QEvent *event)
Reimplemented from QGraphicsScene.
Abstract class that represents a Template.
virtual QGraphicsItem * createItem(const te::gm::Coord2D &coord)
Method that create a graphic object and place it in the scene. A name and a position is added...
virtual void setUndoStackLimit(int limit)
Method that limits the size of the stack of Undo/Redo.
virtual bool removeItemStackWithoutScene(QGraphicsItem *item)
virtual void getPaperSize(double &w, double &h)
Returns paper size. Height and Width.
Undo/Redo for moving components.
Class that represents the value of an enumeration. An enumeration is made of "1..n" objects EnumType...
A helper class for 32-bit RGBA (Red-Green-Blue-Alpha channel) color.
virtual Observable * getModel()
Returns the "Model" part of the MVC.
Class responsible for printing the entire content or part of the scene. As the scene is upside down...
virtual void addUndoStack(QUndoCommand *command)
Method that insert command Undo/Redo of type AddCommand in the Undo/Redo stack.
virtual QTransform sceneTransform()
Method that returns the matrix transformation scene.
virtual std::vector< te::layout::Properties * > importTemplate()=0
Undo/Redo for add one components.
virtual te::layout::MovingItemGroup * createMovingItemGroup(const QList< QGraphicsItem * > &items)
void setMode(EnumType *mode)
Change value of the enumeration of mode type. Ex.: select, pan, create text, etc. The type of mode is...
virtual void updateSelectedItemsPositions()
virtual void removeSelectedItems()
Method that removes all selected items in the scene and creates a Command to Undo/Redo of type Delete...
PaperConfig * getPaperConfig() const
Returns paper setting.
Abstract class for build graphics MVC components.
virtual std::string getName()=0
Method that returns the name of the MVC component. Reimplement this function in a Observable subclass...
virtual void insertItem(ItemObserver *item)
Method that inserts a graphic object in the scene. Inverts the matrix of the object if necessary...
Utility class with functions to manipulate the canvas and conversion between projections.
Class responsible for creating or building graphics objects. All objects are children of QGraphicsIte...
virtual int getUndoStackLimit()
Method that returns the size limit of the stack Undo/Redo.
virtual void destroyItemGroup(QGraphicsItemGroup *group)
Method that delete object grouping, but the individual objects continue to exist. ...
virtual std::vector< te::layout::Properties * > getItemsProperties()
Method that returns a list of the properties of all the graphic objects in the scene.
This class is a proxy MapDisplay. This makes it possible to add a MapDisplay as item of a scene...