30 #include "../../core/pattern/singleton/Context.h"
31 #include "../../core/enum/Enums.h"
32 #include "../../../geometry/Envelope.h"
34 #include "../item/ItemGroup.h"
37 #include "../../outside/PageSetupController.h"
38 #include "../../outside/PageSetupModel.h"
39 #include "../../outside/SystematicScaleController.h"
40 #include "../../outside/SystematicScaleModel.h"
44 #include "../../core/enum/EnumTemplateType.h"
46 #include "../../item/LineModel.h"
50 #include <QMouseEvent>
51 #include <QWheelEvent>
53 #include <QGraphicsRectItem>
54 #include <QGraphicsItem>
56 #include <QMessageBox>
57 #include <QFileDialog>
58 #include <QPainterPath>
62 QGraphicsView(new QGraphicsScene, widget),
63 m_visualizationArea(0),
65 m_pageSetupOutside(0),
66 m_systematicOutside(0),
67 m_selectionChange(false),
75 m_updateItemPos(false),
80 setDragMode(RubberBandDrag);
94 if(m_visualizationArea)
96 delete m_visualizationArea;
97 m_visualizationArea = 0;
100 if(m_pageSetupOutside)
102 delete m_pageSetupOutside;
103 m_pageSetupOutside = 0;
106 if(m_systematicOutside)
108 delete m_systematicOutside;
109 m_systematicOutside = 0;
114 delete m_verticalRuler;
118 if(m_horizontalRuler)
120 delete m_horizontalRuler;
121 m_horizontalRuler = 0;
127 QGraphicsView::mousePressEvent(event);
129 QPointF scenePos = mapToScene(event->pos());
136 if (m_isMoving ==
false)
138 QList<QGraphicsItem*> selectedItems = sc->selectedItems();
140 if (selectedItems.size() > 1)
142 bool isInvertedMatrix =
false;
143 foreach(QGraphicsItem* item, selectedItems)
150 isInvertedMatrix =
true;
155 if (isInvertedMatrix ==
true)
157 m_movingItemGroup = sc->createMovingItemGroup(selectedItems);
167 QPointF posPixel =
event->pos();
168 m_wait->addCoord(posPixel);
191 QGraphicsItem* it = 0;
195 it = sc->createItem(coord);
212 if (event->modifiers() & Qt::ControlModifier)
217 QGraphicsView::mouseMoveEvent(event);
224 if(!scene()->selectedItems().empty())
226 m_updateItemPos =
true;
230 m_updateItemPos =
false;
233 QPointF pt = mapToScene(event->pos());
235 emit changeSceneCoordMouse(pt);
240 emit changeContext();
246 QGraphicsView::mouseReleaseEvent(event);
253 if (m_isMoving ==
true)
255 QList<QGraphicsItem*> selectedItems = m_movingItemGroup->childItems();
258 m_movingItemGroup = 0;
261 sc->clearSelection();
263 foreach (QGraphicsItem* item, selectedItems)
265 if (item->isSelected())
267 item->setSelected(
false);
275 if(!m_selectionChange && !m_updateItemPos)
283 emit reloadProperties();
284 m_selectionChange =
false;
289 ViewportUpdateMode mode = viewportUpdateMode();
290 setViewportUpdateMode(QGraphicsView::FullViewportUpdate);
292 if(event->modifiers() & Qt::AltModifier)
294 double zoomFactor = 1.;
298 if(event->delta() > 0)
301 zoomFactor = nextFactor(currentZoom);
305 zoomFactor = previousFactor(currentZoom);
316 zoomFactor = currentZoom;
318 emit changeZoom(zoomFactor);
321 QGraphicsView::wheelEvent(event);
323 setViewportUpdateMode(mode);
330 if((keyEvent->modifiers() & Qt::ControlModifier) && (keyEvent->key() == Qt::Key_P))
339 else if((keyEvent->modifiers() & Qt::AltModifier) && (keyEvent->key() == Qt::Key_0))
343 else if((keyEvent->modifiers() == Qt::AltModifier) & (keyEvent->key() == Qt::Key_R))
347 else if((keyEvent->modifiers() == Qt::AltModifier) & (keyEvent->key() == Qt::Key_A))
351 else if((keyEvent->modifiers() == Qt::AltModifier) & (keyEvent->key() == Qt::Key_O))
355 else if((keyEvent->modifiers() == Qt::AltModifier) & (keyEvent->key() == Qt::Key_G))
359 else if((keyEvent->modifiers() == Qt::AltModifier) & (keyEvent->key() == Qt::Key_U))
363 else if(keyEvent->key() == Qt::Key_Delete)
367 else if(keyEvent->key() == Qt::Key_Escape)
372 QGraphicsView::keyPressEvent(keyEvent);
379 Scene* nscene =
dynamic_cast<Scene*
>(scene());
384 double sw = viewport()->widthMM();
385 double sh = viewport()->heightMM();
387 if(m_width == -1 || m_height == -1)
393 nscene->
init(m_width, m_height);
403 scale(zoomFactor, zoomFactor);
407 if(!m_visualizationArea)
410 m_visualizationArea->build();
413 setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
414 setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
418 connect(scene(), SIGNAL(selectionChanged()),
this, SLOT(onSelectionChanged()));
422 connect(
this, SIGNAL(changeZoom(
double)), sce, SLOT(onChangeZoomFactor(
double)));
429 QGraphicsView::resizeEvent(event);
434 outsideAreaChangeContext(change);
440 QList<QGraphicsItem*> graphicsItems = this->scene()->selectedItems();
460 group->setHandlesChildEvents(
true);
467 QList<QGraphicsItem*> graphicsItems = this->scene()->selectedItems();
469 foreach( QGraphicsItem *item, graphicsItems)
473 QGraphicsItemGroup* group =
dynamic_cast<QGraphicsItemGroup*
>(item);
489 setDragMode(RubberBandDrag);
492 setInteractive(
true);
493 setCursor(Qt::ArrowCursor);
494 setViewportUpdateMode(QGraphicsView::MinimalViewportUpdate);
498 viewport()->removeEventFilter(m_currentTool);
499 delete m_currentTool;
506 outsideAreaChangeContext(change);
511 resetDefaultConfig();
564 resetDefaultConfig();
569 m_visualizationArea->build();
647 exportItemsToImage();
661 QGraphicsView::hideEvent(event);
667 QGraphicsView::closeEvent(event);
673 QGraphicsView::showEvent(event);
679 if(!m_pageSetupOutside)
685 connect(m_pageSetupOutside, SIGNAL(changeConfig()),
this, SLOT(onChangeConfig()));
688 m_pageSetupOutside->load();
689 m_pageSetupOutside->show();
703 m_visualizationArea->changeBoxArea(boxW);
705 m_visualizationArea->build();
712 if(!m_systematicOutside)
718 connect(m_systematicOutside, SIGNAL(systematicApply(
double,SystematicScaleType)),
this, SLOT(onSystematicApply(
double,SystematicScaleType)));
721 m_systematicOutside->show();
726 if(m_pageSetupOutside)
728 m_pageSetupOutside->close();
739 m_selectionChange =
true;
744 if(event->reason() != QContextMenuEvent::Mouse)
747 QPointF pt = mapToScene(event->pos());
764 QList<QGraphicsItem*> graphicsItems = this->scene()->selectedItems();
766 m_menuBuilder->createMenu(graphicsItems);
767 m_menuBuilder->menuExec(event->globalX(),
event->globalY());
779 QRectF rtv(0, 0, width(), height());
782 QImage img(rtv.width(), rtv.height(), QImage::Format_ARGB32);
784 ptr.setRenderHint(QPainter::Antialiasing);
785 this->render(&ptr, QRect(), QRect(), Qt::IgnoreAspectRatio);
793 QIcon ico(QIcon::fromTheme(pathIcon.c_str()));
795 QPixmap pix = ico.pixmap(sz);
816 scale(zoomFactor, zoomFactor);
822 resetDefaultConfig();
825 setViewportUpdateMode(QGraphicsView::FullViewportUpdate);
827 setInteractive(
false);
828 setDragMode(QGraphicsView::ScrollHandDrag);
833 resetDefaultConfig();
836 QCursor curIn = createCursor(
"layout-paper-zoom-in");
840 setInteractive(
false);
841 viewport()->installEventFilter(m_currentTool);
846 resetDefaultConfig();
850 QCursor curOut = createCursor(
"layout-paper-zoom-out");
853 setInteractive(
false);
854 viewport()->installEventFilter(m_currentTool);
861 resetDefaultConfig();
864 setUpdatesEnabled(
false);
867 m_visibleRulers =
false;
869 m_visibleRulers =
true;
871 setUpdatesEnabled(
true);
877 resetDefaultConfig();
880 changeZoomFactor(defaultZoomFactor);
893 double scaleMatrix = transform().m11();
895 if(isExceededLimit(scaleMatrix, zoomFactor, oldZoomFactor))
898 double factor = zoomFactor;
903 mtrx.scale(factor, factor);
905 emit changeZoom(zoomFactor);
912 resetDefaultConfig();
915 setUpdatesEnabled(
false);
918 m_visibleRulers =
false;
920 m_visibleRulers =
true;
922 setUpdatesEnabled(
true);
928 if(factor < oldFactor)
931 if(currentScale < m_maxZoomLimit)
936 if(currentScale > m_minZoomLimit)
948 QGraphicsView::drawForeground(painter, rect);
951 painter->setMatrixEnabled(
false);
956 if(!m_wait->getCoords().empty())
958 QPainterPath pathZero (m_wait->getCoords()[0]);
962 for(
int i = 0; i < m_wait->getCoords().size() ; ++i)
964 path.lineTo(m_wait->getCoords()[i]);
967 painter->drawPath(path);
968 painter->setMatrixEnabled(
true);
974 double scale = transform().m11();
976 m_horizontalRuler->drawRuler(
this, painter, scale);
977 m_verticalRuler->drawRuler(
this, painter, scale);
982 bool is_export =
false;
984 QString fileName = QFileDialog::getSaveFileName(
this, tr(
"Save File"),
985 QDir::currentPath(), tr(
"JSON Files (*.json)"));
987 if(fileName.isEmpty())
992 std::string j_name = fileName.toStdString();
1004 msgBox.setIcon(QMessageBox::Information);
1005 msgBox.setText(
"Template exported successfully!");
1009 msgBox.setIcon(QMessageBox::Warning);
1010 msgBox.setText(
"Error exporting template!");
1020 QString fileName = QFileDialog::getOpenFileName(
this, tr(
"Import File"),
1021 QDir::currentPath(), tr(
"JSON Files (*.json)"));
1023 if(fileName.isEmpty())
1028 std::string j_name = fileName.toStdString();
1034 bool result = scne->
buildTemplate(m_visualizationArea, type, j_name);
1037 m_visualizationArea->build();
1051 if(scne->selectedItems().empty())
1053 msgBox.setIcon(QMessageBox::Warning);
1054 msgBox.setText(
"Select at least one component!");
1059 QFileDialog dialog(
this);
1060 dialog.setGeometry(QRect(this->width()/4, this->height()/4, this->width()/2, this->height()/2));
1061 QString dir = dialog.getExistingDirectory(
this, tr(
"Open Directory"),
1062 QDir::currentPath(), QFileDialog::ShowDirsOnly | QFileDialog::DontResolveSymlinks);
1067 std::string dirName = dir.toStdString();
1071 msgBox.setIcon(QMessageBox::Information);
1072 msgBox.setText(
"Successfully exported images!");
1080 double scaleMatrix = transform().m11();
1082 if(isExceededLimit(scaleMatrix, currentZoom, zoomFactor))
1089 scale(zoomFactor, zoomFactor);
1090 emit changeZoom(zoomFactor);
1102 emit reloadProperties();
1103 m_selectionChange =
false;
virtual EnumType * getModeObjectToImage() const
Returns value that represents object to image (MVC Component to image. Ex.: .png) mode type belonging...
virtual void config()
Initialization method that configures the View and sets the transformation matrix of the scene in the...
te::layout::EnumTypeFlags getType()
Returns enum type.
virtual void closeOutsideWindows()
Close all windows that have been instantiated by this View. Ex .: Page Settings.
virtual void hideEvent(QHideEvent *event)
Reimplemented from QGraphicsView.
double getOldZoomFactor()
Returns previous zoom factor. Ex.: 0.5 (50%)
virtual void reset()
Method that clears the scene and the stack of Undo/Redo.
virtual EnumType * getModeDrawSelectionMap() const
Returns value that represents draw selection map (MapDisplay proxy) mode type belonging to enumeratio...
virtual void redrawSelectionMap()
Redraws the Layer of the selected map.
virtual void exportItemsToImage()
Saves each item in the scene as image. Ex .: .png.
virtual void zoomArea()
Method that sets View object for the Zoom Area function.
virtual bool exportToPDF()
Class that represents a horizontal ruler with the coordinate system in mm.
virtual EnumType * getModeSendToBack() const
Returns value that represents send to back mode type belonging to enumeration.
Class to represent a template type enumeration. Ex.: json, etc.
virtual void mouseMoveEvent(QMouseEvent *event)
Reimplemented from QGraphicsView.
virtual EnumType * getModeRecompose() const
Returns value that represents recompose mode type belonging to enumeration.
virtual void createTextMapAsObject()
Vectorizes inside text of selected MapItem. (generates te::layout::TextItem objects) ...
virtual EnumType * getModeBringToFront() const
Returns value that represents bring to front mode type belonging to enumeration.
virtual EnumType * getModeExportToPDF() const
Returns value that represents export to PDF mode type belonging to enumeration.
Creates the viewing area. Ex.: creation of the sheet of paper.
virtual EnumModeType * getEnumModeType()
Returns mode type enumeration.
virtual void setCoords(std::vector< te::gm::Point * > coords)
virtual EnumType * getModeMapZoomIn() const
Returns value that represents map zoom in mode type belonging to enumeration.
virtual void onSystematicApply(double scale, SystematicScaleType type)
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).
void setZoomFactor(double zoomFactor)
Change current zoom factor. Ex.: 0.5 (50%)
virtual void alignRight()
virtual void resizeEvent(QResizeEvent *event)
Reimplemented from QGraphicsView.
virtual EnumType * getModeMapCreateTextGrid() const
Returns value that represents create text grid (vectorize) mode type belonging to enumeration...
Abstract class to represent an observer. "View" part of MVC widget. All classes representing the grap...
virtual EnumType * getModeLegendChildAsObject() const
Returns value that represents legend child as object (vectorize) mode type belonging to enumeration...
double m_urx
Upper right corner x-coordinate.
virtual void onChangeConfig()
Notifies View object that some configuration was modified in the Page Settings Window.
Utility class for manipulating items in the scene and vectorization of text and legend.
VerticalRuler * m_verticalRuler
virtual EnumType * getModeUngroup() const
Returns value that represents ungroup mode type belonging to enumeration.
Creates the viewing area. Ex.: creation of the sheet of paper.
Abstract class to represent an observer. "View" part of MVC component. All classes representing the g...
virtual void resetDefaultConfig()
An utility struct for representing 2D coordinates.
virtual EnumType * getModeExportPropsJSON() const
Returns value that represents export properties to json mode type belonging to enumeration.
virtual EnumType * getModeCoordWait() const
Returns value that represents wait coordinate mode type belonging to enumeration. ...
virtual void pan()
Method that sets View object for the Pan function.
virtual void showEvent(QShowEvent *event)
Reimplemented from QGraphicsView.
virtual void showSystematicScale()
virtual void bringToFront()
virtual EnumType * getModeSceneZoom() const
Returns value that represents scene zoom mode type belonging to enumeration.
virtual EnumType * getJsonType() const
Returns value that represents json type belonging to enumeration.
virtual void sendToBack()
virtual void selectItem(std::string name)
Select an item an item by name.
View(QWidget *widget=(QWidget *) 0)
Constructor.
virtual bool isInvertedMatrix()
Returns whether the graph component has the inverted matrix, otherwise the matrix scene...
virtual EnumType * getModeZoomOut() const
Returns value that represents zoom out mode type belonging to enumeration.
virtual void onMainMenuChangeContext(bool change)
Notifies View object that some action on the Menu has been thrown.
virtual void redraw(bool bRefresh=true)
Redraws the graphic component.
virtual void onSelectionItem(std::string name)
virtual EnumType * getModeExit() const
Returns value that represents exit mode type belonging to enumeration.
virtual EnumType * getModeAlignCenterVertical() const
Returns value that represents align center vertical mode type belonging to enumeration.
virtual bool exportPropertiesToTemplate(EnumType *type, std::string fileName)
Method that exports all the objects in the scene to a template. Ex.: JSON.
This class implements a concrete tool to geographic zoom operation using the mouse click...
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.
virtual bool buildTemplate(VisualizationArea *vzArea, EnumType *type, std::string fileName)
Method that import a template and build all objects. Ex.: JSON.
virtual EnumType * getModeNewTemplate() const
Returns value that represents new template mode type belonging to enumeration.
double m_llx
Lower left corner x-coordinate.
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 QGraphicsItem * intersectionSelectionItem(int x, int y)
Checks whether the coordinated intersects an item and returns.
double getDefaultZoomFactor()
Default zoom factor. Ex.: 0.5 (50%)
virtual EnumType * getModeUnitsMetricsChange() const
Returns value that represents units metrics change mode type belonging to enumeration.
void setItem(ItemObserver *item)
virtual bool exportProperties(EnumType *type)
Method that exports all the objects in the scene to a template. Ex.: JSON.
static Enums & 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...
An Envelope defines a 2D rectangular region.
virtual void createItemGroup()
Groups selected objects.
virtual EnumType * getModeAlignRight() const
Returns value that represents align right mode type belonging to enumeration.
virtual EnumType * getModeNone() const
Returns value that represents none mode type belonging to enumeration.
virtual void printPreview()
virtual void outsideAreaChangeContext(bool change)
Responsible method for verifying changes made in Context outside the View object and call correspondi...
Class representing the view. This view is child of QGraphicsView, part of Graphics View Framework...
ItemUtils * getItemUtils()
Returns pointer for manipulating items in the scene and vectorization of text and legend...
virtual void init(double screenWMM, double screenHMM)
Method that starts the scene and configures. Calculates the transformation matrix of the scene and ca...
HorizontalRuler * m_horizontalRuler
const Observer * getView()
Returns the "View" part of the MVC widget.
virtual void onToolbarChangeContext(bool change)
Notifies View object that some action on the toolbar has been thrown.
virtual void alignBottom()
virtual void keyPressEvent(QKeyEvent *keyEvent)
Reimplemented from QGraphicsView.
virtual void wheelEvent(QWheelEvent *event)
Reimplemented from QGraphicsView.
virtual EnumType * getModeMapPan() const
Returns value that represents map pan mode type belonging to enumeration.
EnumType * getMode()
Returns value of the enumeration of mode type.
Utility class for manipulating items in the scene and vectorization of text and legend.
Class representing the scene. This scene is child of QGraphicsScene, part of Graphics View Framework...
virtual EnumType * getModeAlignLeft() const
Returns value that represents align left mode type belonging to enumeration.
virtual EnumType * getModePan() const
Returns value that represents pan mode type belonging to enumeration.
virtual EnumType * getModeAlignBottom() const
Returns value that represents align bottom mode type belonging to enumeration.
virtual void alignCenterHorizontal()
virtual void exportItemsToImage(std::string dir)
Saves each item in the scene as image. Ex .: .png.
virtual bool importTemplate(EnumType *type)
Method that import a template and build all objects. Ex.: JSON.
virtual void zoomPercentage()
Method that applies current zoom defined in the Context.
virtual EnumType * getModeAlignCenterHorizontal() const
Returns value that represents align center horizontal mode type belonging to enumeration.
double m_lly
Lower left corner y-coordinate.
virtual void createTextGridAsObject()
Vectorizes grid text of selected MapItem. (generates te::layout::TextItem objects) ...
virtual void zoomOut()
Method that sets View object for the Zoom Out function.
virtual void mousePressEvent(QMouseEvent *event)
Reimplemented from QGraphicsView. Call method createItem() of the scene.
virtual void showPageSetup()
Method that instantiates and shows the Page Setup window.
virtual EnumType * getModeGroup() const
Returns value that represents group mode type belonging to enumeration.
virtual void resetView()
Reset to initial configuration made in the config() method.
virtual EnumType * getModeMapZoomOut() const
Returns value that represents map zoom out mode type belonging to enumeration.
virtual void recompose()
Reset to initial configuration made in the config() method. Reset to default zoom factor...
double m_ury
Upper right corner y-coordinate.
virtual QImage createImage()
Create snapshot of the View current state.
virtual void exportToPDF()
Method that sets View object for the Print function.
virtual EnumType * getModeZoomIn() const
Returns value that represents zoom in mode type belonging to enumeration.
void setWait(EnumType *wait)
virtual QCursor createCursor(std::string pathIcon)
Class that represents the value of an enumeration. An enumeration is made of "1..n" objects EnumType...
virtual EnumType * getModeMapCreateTextMap() const
Returns value that represents create text map (vectorize) mode type belonging to enumeration.
Class that represents a vertical ruler with the coordinate system in mm.
virtual ~View()
Destructor.
virtual Observable * getModel()
Returns the "Model" part of the MVC.
virtual te::gm::Envelope getSceneBox()
Method that return the scene box.
virtual QTransform sceneTransform()
Method that returns the matrix transformation scene.
virtual void closeEvent(QCloseEvent *event)
Reimplemented from QGraphicsView.
virtual EnumTemplateType * getEnumTemplateType()
Returns template type enumeration.
virtual EnumType * getModePrinter() const
Returns value that represents printer mode type belonging to enumeration.
virtual void setCurrentToolInSelectedMapItems(EnumType *mode)
Changes the active tool of te::layout::MapItem.
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...
virtual EnumType * getModeImportJSONProps() const
Returns value that represents import properties from json mode type belonging to enumeration.
virtual void drawForeground(QPainter *painter, const QRectF &rect)
Reimplemented from QGraphicsView.
virtual void mouseReleaseEvent(QMouseEvent *event)
Reimplemented from QGraphicsView.
virtual EnumType * getModeArrowCursor() const
Returns value that represents arrow mode type belonging to enumeration.
virtual bool isExceededLimit(double currentScale, double factor, double oldFactor)
double getZoomFactor()
Returns current zoom factor. Ex.: 0.5 (50%)
virtual void changeZoomFactor(double currentZoom)
Method that change rulers visibility state.
void setOldZoomFactor(double zoomFactor)
Change previous zoom factor. Ex.: 0.5 (50%)
virtual EnumType * getModeRemoveObject() const
Returns value that represents remove object (MVC component) mode type belonging to enumeration...
virtual void contextMenuEvent(QContextMenuEvent *event)
Reimplemented from QGraphicsView.
virtual void createLegendChildAsObject()
Vectorizes selected LegendItem. (generates te::layout::TextItem objects)
virtual EnumType * getModePageConfig() const
Returns value that represents page configuration mode type belonging to enumeration.
Class responsible for printing the entire content or part of the scene. As the scene is upside down...
Class that represents a horizontal ruler with the coordinate system in mm.
virtual void destroyItemGroup(QGraphicsItemGroup *group)
Method that delete object grouping, but the individual objects continue to exist. ...
virtual void onSelectionChanged()
Notifies View object that the selection of objects in the scene changed.
Class that represents a vertical ruler with the coordinate system in mm.
virtual void alignCenterVertical()
virtual EnumType * getModeAlignTop() const
Returns value that represents align top mode type belonging to enumeration.
virtual void destroyItemGroup()
Method that delete Grouping object selected, but the individual objects continue to exist...
virtual void print()
Method that sets View object for the Print function.