All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
View.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 View.cpp
22 
23  \brief
24 
25  \ingroup layout
26 */
27 
28 // TerraLib
29 #include "View.h"
30 #include "../../core/pattern/singleton/Context.h"
31 #include "../../core/enum/Enums.h"
32 #include "../../../geometry/Envelope.h"
33 #include "VisualizationArea.h"
34 #include "../item/ItemGroup.h"
35 #include "tools/ViewZoomClick.h"
36 #include "tools/ViewZoomArea.h"
37 #include "../../outside/PageSetupController.h"
38 #include "../../outside/PageSetupModel.h"
39 #include "../../outside/SystematicScaleController.h"
40 #include "../../outside/SystematicScaleModel.h"
41 #include "HorizontalRuler.h"
42 #include "VerticalRuler.h"
43 #include "PrintScene.h"
44 #include "../../core/enum/EnumTemplateType.h"
45 #include "ItemUtils.h"
46 #include "../../item/LineModel.h"
47 #include "WaitView.h"
48 
49 // Qt
50 #include <QMouseEvent>
51 #include <QWheelEvent>
52 #include <QKeyEvent>
53 #include <QGraphicsRectItem>
54 #include <QGraphicsItem>
55 #include <QDebug>
56 #include <QMessageBox>
57 #include <QFileDialog>
58 #include <QPainterPath>
59 #include <QEvent>
60 
61 te::layout::View::View( QWidget* widget) :
62  QGraphicsView(new QGraphicsScene, widget),
63  m_visualizationArea(0),
64  m_currentTool(0),
65  m_pageSetupOutside(0),
66  m_systematicOutside(0),
67  m_selectionChange(false),
68  m_menuBuilder(0),
69  m_maxZoomLimit(29.),
70  m_minZoomLimit(0.9),
71  m_width(-1),
72  m_height(-1),
73  m_isMoving(false),
74  m_movingItemGroup(0),
75  m_updateItemPos(false),
76  m_oldMode(0),
77  m_wait(0),
78  m_flag(false)
79 {
80  setDragMode(RubberBandDrag);
81 
84  m_wait = new WaitView(this);
85 
86  if(Enums::getInstance().getEnumModeType())
87  {
88  m_oldMode = Enums::getInstance().getEnumModeType()->getModeNone();
89  }
90 }
91 
93 {
94  if(m_visualizationArea)
95  {
96  delete m_visualizationArea;
97  m_visualizationArea = 0;
98  }
99 
100  if(m_pageSetupOutside)
101  {
102  delete m_pageSetupOutside;
103  m_pageSetupOutside = 0;
104  }
105 
106  if(m_systematicOutside)
107  {
108  delete m_systematicOutside;
109  m_systematicOutside = 0;
110  }
111 
112  if(m_verticalRuler)
113  {
114  delete m_verticalRuler;
115  m_verticalRuler = 0;
116  }
117 
118  if(m_horizontalRuler)
119  {
120  delete m_horizontalRuler;
121  m_horizontalRuler = 0;
122  }
123 }
124 
125 void te::layout::View::mousePressEvent( QMouseEvent * event )
126 {
127  QGraphicsView::mousePressEvent(event);
128 
129  QPointF scenePos = mapToScene(event->pos());
130  te::gm::Coord2D coord(scenePos.x(), scenePos.y());
131 
132  Scene* sc = dynamic_cast<Scene*>(scene());
133  if(!sc)
134  return;
135 
136  if (m_isMoving == false)
137  {
138  QList<QGraphicsItem*> selectedItems = sc->selectedItems();
139 
140  if (selectedItems.size() > 1)
141  {
142  bool isInvertedMatrix = false;
143  foreach(QGraphicsItem* item, selectedItems)
144  {
145  ItemObserver* observer = dynamic_cast<ItemObserver*> (item);
146  if (observer)
147  {
148  if (observer->isInvertedMatrix() == true)
149  {
150  isInvertedMatrix = true;
151  }
152  }
153  }
154 
155  if (isInvertedMatrix == true)
156  {
157  m_movingItemGroup = sc->createMovingItemGroup(selectedItems);
158  m_isMoving = true;
159  }
160  }
161  }
162 
164 
165  if(m_flag && Context::getInstance().getWait() == mode->getModeCoordWait())
166  {
167  QPointF posPixel = event->pos();
168  m_wait->addCoord(posPixel);
169  }
170  else
171  {
172  if(Context::getInstance().getWait() == mode->getModeCoordWait())
173  {
175 
176  if (oItem)
177  {
178  LineModel* lm = dynamic_cast<LineModel*>(oItem->getModel());
179  lm->setCoords(m_wait->getCoordsW());
180  m_wait->clear();
183  m_flag = false;
184  }
185  }
186  }
187 
188  if(Context::getInstance().getMode() == mode->getModeNone())
189  return;
190 
191  QGraphicsItem* it = 0;
192 
194  {
195  it = sc->createItem(coord);
196  }
197 
198  if(Context::getInstance().getWait() == mode->getModeCoordWait())
199  {
200  ItemObserver* iob = dynamic_cast<ItemObserver*>(it);
201 
202  if (!iob)
203  return;
204 
206  m_flag = true;
207  }
208 }
209 
210 void te::layout::View::mouseMoveEvent( QMouseEvent * event )
211 {
212  if (event->modifiers() & Qt::ControlModifier)
213  {
214  return;
215  }
216 
217  QGraphicsView::mouseMoveEvent(event);
218 
219  Scene* sc = dynamic_cast<Scene*>(scene());
220 
221  if(!sc)
222  return;
223 
224  if(!scene()->selectedItems().empty())
225  {
226  m_updateItemPos = true;
227  }
228  else
229  {
230  m_updateItemPos = false;
231  }
232 
233  QPointF pt = mapToScene(event->pos());
234 
235  emit changeSceneCoordMouse(pt);
236 
237  if(m_oldMode != Context::getInstance().getMode())
238  {
239  m_oldMode = Context::getInstance().getMode();
240  emit changeContext();
241  }
242 }
243 
244 void te::layout::View::mouseReleaseEvent( QMouseEvent * event )
245 {
246  QGraphicsView::mouseReleaseEvent(event);
247 
248  Scene* sc = dynamic_cast<Scene*>(scene());
249 
250  if(!sc)
251  return;
252 
253  if (m_isMoving == true)
254  {
255  QList<QGraphicsItem*> selectedItems = m_movingItemGroup->childItems();
256 
257  sc->destroyItemGroup(m_movingItemGroup);
258  m_movingItemGroup = 0;
259  m_isMoving = false;
260 
261  sc->clearSelection();
262 
263  foreach (QGraphicsItem* item, selectedItems)
264  {
265  if (item->isSelected())
266  {
267  item->setSelected(false);
268  }
269  }
270 
271  sc->selectItems(selectedItems);
272  }
273 
274  /* The Properties only load when selection change and mouse release */
275  if(!m_selectionChange && !m_updateItemPos)
276  return;
277 
278  if(m_updateItemPos)
279  {
281  }
282 
283  emit reloadProperties();
284  m_selectionChange = false;
285 }
286 
287 void te::layout::View::wheelEvent( QWheelEvent *event )
288 {
289  ViewportUpdateMode mode = viewportUpdateMode();
290  setViewportUpdateMode(QGraphicsView::FullViewportUpdate);
291 
292  if(event->modifiers() & Qt::AltModifier)
293  {
294  double zoomFactor = 1.;
295  double currentZoom = Context::getInstance().getZoomFactor();
296 
297  // Zoom in / Zoom Out
298  if(event->delta() > 0)
299  {
300  //Zooming In
301  zoomFactor = nextFactor(currentZoom);
302  }
303  else
304  {
305  zoomFactor = previousFactor(currentZoom);
306  }
307 
308  if(zoomFactor > 0)
309  {
310  Context::getInstance().setOldZoomFactor(currentZoom);
311  Context::getInstance().setZoomFactor(zoomFactor);
312  zoomPercentage();
313  }
314  else
315  {
316  zoomFactor = currentZoom;
317  }
318  emit changeZoom(zoomFactor);
319  }
320 
321  QGraphicsView::wheelEvent(event);
322 
323  setViewportUpdateMode(mode);
324 }
325 
326 void te::layout::View::keyPressEvent( QKeyEvent* keyEvent )
327 {
328  Scene* scne = dynamic_cast<Scene*>(scene());
329 
330  if((keyEvent->modifiers() & Qt::ControlModifier) && (keyEvent->key() == Qt::Key_P))
331  {
334 
335  print();
336 
338  }
339  else if((keyEvent->modifiers() & Qt::AltModifier) && (keyEvent->key() == Qt::Key_0))
340  {
341  pan();
342  }
343  else if((keyEvent->modifiers() == Qt::AltModifier) & (keyEvent->key() == Qt::Key_R))
344  {
345  recompose();
346  }
347  else if((keyEvent->modifiers() == Qt::AltModifier) & (keyEvent->key() == Qt::Key_A))
348  {
349  zoomArea();
350  }
351  else if((keyEvent->modifiers() == Qt::AltModifier) & (keyEvent->key() == Qt::Key_O))
352  {
353  zoomOut();
354  }
355  else if((keyEvent->modifiers() == Qt::AltModifier) & (keyEvent->key() == Qt::Key_G))
356  {
357  createItemGroup();
358  }
359  else if((keyEvent->modifiers() == Qt::AltModifier) & (keyEvent->key() == Qt::Key_U))
360  {
361  destroyItemGroup();
362  }
363  else if(keyEvent->key() == Qt::Key_Delete)
364  {
365  scne->removeSelectedItems();
366  }
367  else if(keyEvent->key() == Qt::Key_Escape)
368  {
369  m_flag = false;
370  }
371 
372  QGraphicsView::keyPressEvent(keyEvent);
373 }
374 
376 {
377  //Calculate matrix and centralizes the scene
378 
379  Scene* nscene = dynamic_cast<Scene*>(scene());
380 
381  if(!nscene)
382  return;
383 
384  double sw = viewport()->widthMM();
385  double sh = viewport()->heightMM();
386 
387  if(m_width == -1 || m_height == -1)
388  {
389  m_width = sw;
390  m_height = sh;
391  }
392 
393  nscene->init(m_width, m_height);
394 
395  QTransform mtrx = nscene->sceneTransform();
396 
397  setTransform(mtrx);
398 
399  te::gm::Envelope box = nscene->getSceneBox();
400  centerOn(QPointF(box.m_llx, box.m_ury));
401 
402  double zoomFactor = Context::getInstance().getDefaultZoomFactor();
403  scale(zoomFactor, zoomFactor); //Initial zoom out
404 
405  //----------------------------------------------------------------------------------------------
406 
407  if(!m_visualizationArea)
408  {
409  m_visualizationArea = new VisualizationArea(box);
410  m_visualizationArea->build();
411  }
412 
413  setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
414  setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
415 
416  if(scene())
417  {
418  connect(scene(), SIGNAL(selectionChanged()), this, SLOT(onSelectionChanged()));
419  Scene* sce = dynamic_cast<Scene*>(scene());
420  if(sce)
421  {
422  connect(this, SIGNAL(changeZoom(double)), sce, SLOT(onChangeZoomFactor(double)));
423  }
424  }
425 }
426 
427 void te::layout::View::resizeEvent(QResizeEvent * event)
428 {
429  QGraphicsView::resizeEvent(event);
430 }
431 
433 {
434  outsideAreaChangeContext(change);
435 }
436 
438 {
439  Scene* sc = dynamic_cast<Scene*>(scene());
440  QList<QGraphicsItem*> graphicsItems = this->scene()->selectedItems();
441 
442  if(sc)
443  {
444  QGraphicsItemGroup* group = sc->createItemGroup(graphicsItems);
445 
446  if(!group)
447  return;
448 
449  ItemGroup* layoutGroup = dynamic_cast<ItemGroup*>(group);
450 
451  if(!layoutGroup)
452  return;
453 
454  layoutGroup->redraw();
455 
456  /*If "enabled=true", QGraphicsItemGroup will handle all the events. For example,
457  the event of mouse click on the child item won't be handled by child item.
458  If "enabled=false", QGraphicsItem Group will not block the child item's event
459  and let child item handle it own event.*/
460  group->setHandlesChildEvents(true);
461  }
462 }
463 
465 {
466  Scene* sc = dynamic_cast<Scene*>(scene());
467  QList<QGraphicsItem*> graphicsItems = this->scene()->selectedItems();
468 
469  foreach( QGraphicsItem *item, graphicsItems)
470  {
471  if (item)
472  {
473  QGraphicsItemGroup* group = dynamic_cast<QGraphicsItemGroup*>(item);
474  if(group)
475  {
476  if(sc)
477  {
478  sc->destroyItemGroup(group);
479  }
480  }
481  }
482  }
483 }
484 
486 {
487  //Use ScrollHand Drag Mode to enable Panning
488  //You do need the enable scroll bars for that to work.
489  setDragMode(RubberBandDrag);
490 
491  //Whole view not interactive while in ScrollHandDrag Mode
492  setInteractive(true);
493  setCursor(Qt::ArrowCursor);
494  setViewportUpdateMode(QGraphicsView::MinimalViewportUpdate);
495 
496  if(m_currentTool)
497  {
498  viewport()->removeEventFilter(m_currentTool);
499  delete m_currentTool;
500  m_currentTool = 0;
501  }
502 }
503 
505 {
506  outsideAreaChangeContext(change);
507 }
508 
510 {
511  resetDefaultConfig();
512 
513  Scene* sc = dynamic_cast<Scene*>(scene());
514 
515  if(!sc)
516  return;
517 
521 
522  if(mode == enumMode->getModeUnitsMetricsChange())
523  {
524 
525  }
526  else if(mode == enumMode->getModePan())
527  {
528  pan();
529  }
530  else if(mode == enumMode->getModeGroup())
531  {
532  createItemGroup();
533  }
534  else if(mode == enumMode->getModeUngroup())
535  {
536  destroyItemGroup();
537  }
538  else if(mode == enumMode->getModePrinter())
539  {
540  print();
541  }
542  else if(mode == enumMode->getModeSceneZoom())
543  {
544  zoomPercentage();
545  }
546  else if(mode == enumMode->getModeZoomIn())
547  {
548  zoomArea();
549  }
550  else if(mode == enumMode->getModeZoomOut())
551  {
552  zoomOut();
553  }
554  else if(mode == enumMode->getModeRecompose())
555  {
556  recompose();
557  }
558  else if(mode == enumMode->getModePageConfig())
559  {
560  showPageSetup();
561  }
562  else if(mode == enumMode->getModeArrowCursor())
563  {
564  resetDefaultConfig();
565  }
566  else if(mode == enumMode->getModeNewTemplate())
567  {
568  sc->reset();
569  m_visualizationArea->build();
570  }
571  else if(mode == enumMode->getModeExportPropsJSON())
572  {
574  exportProperties(enumTemplate->getJsonType());
575  }
576  else if(mode == enumMode->getModeImportJSONProps())
577  {
579  importTemplate(enumTemplate->getJsonType());
580  }
581  else if(mode == enumMode->getModeMapPan())
582  {
583  iUtils->setCurrentToolInSelectedMapItems(enumMode->getModeMapPan());
584  }
585  else if(mode == enumMode->getModeMapZoomIn())
586  {
588  }
589  else if(mode == enumMode->getModeMapZoomOut())
590  {
592  }
593  else if(mode == enumMode->getModeBringToFront())
594  {
595  sc->getAlignItems()->bringToFront();
596  }
597  else if(mode == enumMode->getModeSendToBack())
598  {
599  sc->getAlignItems()->sendToBack();
600  }
601  else if(mode == enumMode->getModeMapCreateTextGrid())
602  {
603  iUtils->createTextGridAsObject();
604  }
605  else if(mode == enumMode->getModeMapCreateTextMap())
606  {
607  iUtils->createTextMapAsObject();
608  }
609  else if(mode == enumMode->getModeAlignLeft())
610  {
611  sc->getAlignItems()->alignLeft();
612  }
613  else if(mode == enumMode->getModeAlignRight())
614  {
615  sc->getAlignItems()->alignRight();
616  }
617  else if(mode == enumMode->getModeAlignTop())
618  {
619  sc->getAlignItems()->alignTop();
620  }
621  else if(mode == enumMode->getModeAlignBottom())
622  {
623  sc->getAlignItems()->alignBottom();
624  }
625  else if(mode == enumMode->getModeAlignCenterHorizontal())
626  {
628  }
629  else if(mode == enumMode->getModeAlignCenterVertical())
630  {
632  }
633  else if(mode == enumMode->getModeRemoveObject())
634  {
635  sc->removeSelectedItems();
636  }
637  else if(mode == enumMode->getModeDrawSelectionMap())
638  {
639  sc->redrawSelectionMap();
640  }
641  else if(mode == enumMode->getModeLegendChildAsObject())
642  {
643  iUtils->createLegendChildAsObject();
644  }
645  else if(mode == enumMode->getModeObjectToImage())
646  {
647  exportItemsToImage();
648  }
649  else if(mode == enumMode->getModeExit())
650  {
651  close();
652  }
653  else if(mode == enumMode->getModeExportToPDF())
654  {
655  exportToPDF();
656  }
657 }
658 
659 void te::layout::View::hideEvent( QHideEvent * event )
660 {
661  QGraphicsView::hideEvent(event);
662  emit hideView();
663 }
664 
665 void te::layout::View::closeEvent( QCloseEvent * event )
666 {
667  QGraphicsView::closeEvent(event);
668  emit closeView();
669 }
670 
671 void te::layout::View::showEvent( QShowEvent * event )
672 {
673  QGraphicsView::showEvent(event);
674  emit showView();
675 }
676 
678 {
679  if(!m_pageSetupOutside)
680  {
681  PageSetupModel* model = new PageSetupModel;
682  PageSetupController* controller = new PageSetupController(model);
683  OutsideObserver* obsever = (OutsideObserver*)(controller->getView());
684  m_pageSetupOutside = dynamic_cast<PageSetupOutside*>(obsever);
685  connect(m_pageSetupOutside, SIGNAL(changeConfig()), this, SLOT(onChangeConfig()));
686  }
687 
688  m_pageSetupOutside->load();
689  m_pageSetupOutside->show();
690 }
691 
693 {
694  Scene* sc = dynamic_cast<Scene*>(scene());
695  if(!sc)
696  return;
697 
698  sc->reset();
699 
700  config();
701 
702  te::gm::Envelope boxW = sc->getSceneBox();
703  m_visualizationArea->changeBoxArea(boxW);
704 
705  m_visualizationArea->build();
706 
707  recompose();
708 }
709 
711 {
712  if(!m_systematicOutside)
713  {
715  SystematicScaleController* controller = new SystematicScaleController(model);
716  OutsideObserver* obsever = (OutsideObserver*)(controller->getView());
717  m_systematicOutside = dynamic_cast<SystematicScaleOutside*>(obsever);
718  connect(m_systematicOutside, SIGNAL(systematicApply(double,SystematicScaleType)), this, SLOT(onSystematicApply(double,SystematicScaleType)));
719  }
720 
721  m_systematicOutside->show();
722 }
723 
725 {
726  if(m_pageSetupOutside)
727  {
728  m_pageSetupOutside->close();
729  }
730 }
731 
732 void te::layout::View::onSystematicApply(double scale, SystematicScaleType type)
733 {
734 
735 }
736 
738 {
739  m_selectionChange = true;
740 }
741 
742 void te::layout::View::contextMenuEvent( QContextMenuEvent * event )
743 {
744  if(event->reason() != QContextMenuEvent::Mouse)
745  return;
746 
747  QPointF pt = mapToScene(event->pos());
748 
750  if(!iUtils)
751  {
752  return;
753  }
754 
755  QGraphicsItem* hasItem = iUtils->intersectionSelectionItem(pt.x(), pt.y());
756  if(!hasItem)
757  return;
758 
759  if(!m_menuBuilder)
760  {
761  m_menuBuilder = new MenuBuilder(this);
762  }
763 
764  QList<QGraphicsItem*> graphicsItems = this->scene()->selectedItems();
765 
766  m_menuBuilder->createMenu(graphicsItems);
767  m_menuBuilder->menuExec(event->globalX(), event->globalY());
768 }
769 
771 {
772  QImage ig;
773  Scene* sc = dynamic_cast<Scene*>(scene());
774  if(!sc)
775  return ig;
776 
777  te::gm::Envelope env = sc->getSceneBox();
778 
779  QRectF rtv(0, 0, width(), height());
780  QRectF rts(env.m_llx, env.m_lly, env.m_urx, env.m_ury);
781 
782  QImage img(rtv.width(), rtv.height(), QImage::Format_ARGB32);
783  QPainter ptr(&img);
784  ptr.setRenderHint(QPainter::Antialiasing);
785  this->render(&ptr, QRect(), QRect(), Qt::IgnoreAspectRatio);
786 
787  return img;
788 }
789 
790 QCursor te::layout::View::createCursor( std::string pathIcon )
791 {
792  QSize sz;
793  QIcon ico(QIcon::fromTheme(pathIcon.c_str()));
794  ico.actualSize(sz);
795  QPixmap pix = ico.pixmap(sz);
796  QCursor cur(pix);
797 
798  return cur;
799 }
800 
802 {
803  Scene* scne = dynamic_cast<Scene*>(scene());
804 
805  if(!scne)
806  return;
807 
808  QTransform mtrx = scne->sceneTransform();
809  setTransform(mtrx);
810 
811  te::gm::Envelope box = scne->getSceneBox();
812  QPointF pt(box.m_llx, box.m_ury);
813  centerOn(pt);
814 
815  double zoomFactor = Context::getInstance().getDefaultZoomFactor();
816  scale(zoomFactor, zoomFactor); //Initial zoom out
817 }
818 
820 {
821  //Use ScrollHand Drag Mode to enable Panning
822  resetDefaultConfig();
823 
824  //The entire viewport is redrawn to avoid traces
825  setViewportUpdateMode(QGraphicsView::FullViewportUpdate);
826 
827  setInteractive(false);
828  setDragMode(QGraphicsView::ScrollHandDrag); // Pan Mode
829 }
830 
832 {
833  resetDefaultConfig();
834 
835  // Active ZoomArea Tool
836  QCursor curIn = createCursor("layout-paper-zoom-in");
837 
838  m_currentTool = new ViewZoomArea(this, curIn);
839 
840  setInteractive(false);
841  viewport()->installEventFilter(m_currentTool);
842 }
843 
845 {
846  resetDefaultConfig();
847 
848  // #Active ZoomClick (Out) Tool
849 
850  QCursor curOut = createCursor("layout-paper-zoom-out");
851  m_currentTool = new ViewZoomClick(this, curOut);
852 
853  setInteractive(false);
854  viewport()->installEventFilter(m_currentTool);
855 }
856 
858 {
859  Scene* scne = dynamic_cast<Scene*>(scene());
860 
861  resetDefaultConfig();
862 
863  // No update Widget while print is running
864  setUpdatesEnabled(false);
865 
866  // Rulers aren't print
867  m_visibleRulers = false;
868  scne->getPrintScene()->printPreview();
869  m_visibleRulers = true;
870 
871  setUpdatesEnabled(true);
872 }
873 
875 {
876  resetView();
877  resetDefaultConfig();
878 
879  double defaultZoomFactor = Context::getInstance().getDefaultZoomFactor();
880  changeZoomFactor(defaultZoomFactor);
881 }
882 
884 {
885  Scene* scne = dynamic_cast<Scene*>(scene());
886  if(!scne)
887  return;
888 
889  QTransform mtrx = scne->sceneTransform();
890 
891  double zoomFactor = Context::getInstance().getZoomFactor();
892  double oldZoomFactor = Context::getInstance().getOldZoomFactor();
893  double scaleMatrix = transform().m11();
894 
895  if(isExceededLimit(scaleMatrix, zoomFactor, oldZoomFactor))
896  return;
897 
898  double factor = zoomFactor;
899 
900  if(factor <= 0)
901  factor = 1.;
902 
903  mtrx.scale(factor, factor);
904  setTransform(mtrx);
905  emit changeZoom(zoomFactor);
906 }
907 
909 {
910  Scene* scne = dynamic_cast<Scene*>(scene());
911 
912  resetDefaultConfig();
913 
914  // No update Widget while print is running
915  setUpdatesEnabled(false);
916 
917  // Rulers aren't print
918  m_visibleRulers = false;
919  scne->getPrintScene()->exportToPDF();
920  m_visibleRulers = true;
921 
922  setUpdatesEnabled(true);
923 }
924 
925 bool te::layout::View::isExceededLimit(double currentScale, double factor, double oldFactor)
926 {
927  // Zoom in / Zoom Out
928  if(factor < oldFactor)
929  {
930  //Zooming In
931  if(currentScale < m_maxZoomLimit)
932  return false;
933  }
934  else
935  {
936  if(currentScale > m_minZoomLimit)
937  return false;
938  }
939 
940  return true;
941 }
942 
943 void te::layout::View::drawForeground( QPainter * painter, const QRectF & rect )
944 {
945  if ( !painter )
946  return;
947 
948  QGraphicsView::drawForeground(painter, rect);
949 
950  painter->save();
951  painter->setMatrixEnabled(false);
952  painter->setPen(Qt::SolidLine);
953 
954  QPainterPath path;
955 
956  if(!m_wait->getCoords().empty())
957  {
958  QPainterPath pathZero (m_wait->getCoords()[0]);
959  path = pathZero;
960  }
961 
962  for(int i = 0; i < m_wait->getCoords().size() ; ++i)
963  {
964  path.lineTo(m_wait->getCoords()[i]);
965  }
966 
967  painter->drawPath(path);
968  painter->setMatrixEnabled(true);
969  painter->restore();
970 
971  if(!m_visibleRulers)
972  return;
973 
974  double scale = transform().m11();
975 
976  m_horizontalRuler->drawRuler(this, painter, scale);
977  m_verticalRuler->drawRuler(this, painter, scale);
978 }
979 
981 {
982  bool is_export = false;
983 
984  QString fileName = QFileDialog::getSaveFileName(this, tr("Save File"),
985  QDir::currentPath(), tr("JSON Files (*.json)"));
986 
987  if(fileName.isEmpty())
988  {
989  return is_export;
990  }
991 
992  std::string j_name = fileName.toStdString();
993 
994  Scene* scne = dynamic_cast<Scene*>(scene());
995  if(!scne)
996  return false;
997 
998  is_export = scne->exportPropertiesToTemplate(type, j_name);
999 
1000  QMessageBox msgBox;
1001 
1002  if(is_export)
1003  {
1004  msgBox.setIcon(QMessageBox::Information);
1005  msgBox.setText("Template exported successfully!");
1006  }
1007  else
1008  {
1009  msgBox.setIcon(QMessageBox::Warning);
1010  msgBox.setText("Error exporting template!");
1011  }
1012 
1013  msgBox.exec();
1014 
1015  return is_export;
1016 }
1017 
1019 {
1020  QString fileName = QFileDialog::getOpenFileName(this, tr("Import File"),
1021  QDir::currentPath(), tr("JSON Files (*.json)"));
1022 
1023  if(fileName.isEmpty())
1024  {
1025  return false;
1026  }
1027 
1028  std::string j_name = fileName.toStdString();
1029 
1030  Scene* scne = dynamic_cast<Scene*>(scene());
1031  if(!scne)
1032  return false;
1033 
1034  bool result = scne->buildTemplate(m_visualizationArea, type, j_name);
1035  if(result)
1036  {
1037  m_visualizationArea->build();
1038  }
1039 
1040  return result;
1041 }
1042 
1044 {
1045  Scene* scne = dynamic_cast<Scene*>(scene());
1046  if(!scne)
1047  return;
1048 
1049  QMessageBox msgBox;
1050 
1051  if(scne->selectedItems().empty())
1052  {
1053  msgBox.setIcon(QMessageBox::Warning);
1054  msgBox.setText("Select at least one component!");
1055  msgBox.exec();
1056  return;
1057  }
1058 
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);
1063 
1064  if(dir.isEmpty())
1065  return;
1066 
1067  std::string dirName = dir.toStdString();
1068 
1069  scne->exportItemsToImage(dirName);
1070 
1071  msgBox.setIcon(QMessageBox::Information);
1072  msgBox.setText("Successfully exported images!");
1073  msgBox.exec();
1074 }
1075 
1076 void te::layout::View::changeZoomFactor( double currentZoom )
1077 {
1078  double zoomFactor = Context::getInstance().getZoomFactor();
1079 
1080  double scaleMatrix = transform().m11();
1081 
1082  if(isExceededLimit(scaleMatrix, currentZoom, zoomFactor))
1083  return;
1084 
1085  if(currentZoom > 0)
1086  {
1087  Context::getInstance().setOldZoomFactor(zoomFactor);
1088  Context::getInstance().setZoomFactor(currentZoom);
1089  scale(zoomFactor, zoomFactor);
1090  emit changeZoom(zoomFactor);
1091  }
1092 }
1093 
1094 void te::layout::View::onSelectionItem( std::string name )
1095 {
1096  Scene* scne = dynamic_cast<Scene*>(scene());
1097  if(!scne)
1098  return;
1099 
1100  scne->selectItem(name);
1101 
1102  emit reloadProperties();
1103  m_selectionChange = false;
1104 }
virtual EnumType * getModeObjectToImage() const
Returns value that represents object to image (MVC Component to image. Ex.: .png) mode type belonging...
Class responsible for creating the menu, right mouse button, and dynamically add menu options...
Definition: MenuBuilder.h:57
virtual void config()
Initialization method that configures the View and sets the transformation matrix of the scene in the...
Definition: View.cpp:375
te::layout::EnumTypeFlags getType()
Returns enum type.
Definition: EnumType.cpp:79
virtual void closeOutsideWindows()
Close all windows that have been instantiated by this View. Ex .: Page Settings.
Definition: View.cpp:724
virtual void hideEvent(QHideEvent *event)
Reimplemented from QGraphicsView.
Definition: View.cpp:659
double getOldZoomFactor()
Returns previous zoom factor. Ex.: 0.5 (50%)
Definition: Context.cpp:238
virtual void reset()
Method that clears the scene and the stack of Undo/Redo.
Definition: Scene.cpp:534
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.
Definition: Scene.cpp:578
virtual void exportItemsToImage()
Saves each item in the scene as image. Ex .: .png.
Definition: View.cpp:1043
virtual void zoomArea()
Method that sets View object for the Zoom Area function.
Definition: View.cpp:831
virtual bool exportToPDF()
Definition: PrintScene.cpp:205
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.
Definition: View.cpp:210
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) ...
Definition: ItemUtils.cpp:284
virtual EnumType * getModeBringToFront() const
Returns value that represents bring to front mode type belonging to enumeration.
EnumType * m_oldMode
Definition: View.h:359
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.
Definition: Enums.cpp:92
virtual void setCoords(std::vector< te::gm::Point * > coords)
Definition: LineModel.cpp:77
virtual EnumType * getModeMapZoomIn() const
Returns value that represents map zoom in mode type belonging to enumeration.
virtual void onSystematicApply(double scale, SystematicScaleType type)
Definition: View.cpp:732
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).
Definition: ItemGroup.h:63
void setZoomFactor(double zoomFactor)
Change current zoom factor. Ex.: 0.5 (50%)
Definition: Context.cpp:108
virtual void alignRight()
Definition: AlignItems.cpp:155
virtual void resizeEvent(QResizeEvent *event)
Reimplemented from QGraphicsView.
Definition: View.cpp:427
virtual EnumType * getModeMapCreateTextGrid() const
Returns value that represents create text grid (vectorize) mode type belonging to enumeration...
WaitView * m_wait
Definition: View.h:360
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.
Definition: Envelope.h:346
virtual void onChangeConfig()
Notifies View object that some configuration was modified in the Page Settings Window.
Definition: View.cpp:692
Utility class for manipulating items in the scene and vectorization of text and legend.
VerticalRuler * m_verticalRuler
Definition: View.h:351
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...
Definition: ItemObserver.h:52
virtual void resetDefaultConfig()
Definition: View.cpp:485
An utility struct for representing 2D coordinates.
Definition: Coord2D.h:40
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.
Definition: View.cpp:819
virtual void showEvent(QShowEvent *event)
Reimplemented from QGraphicsView.
Definition: View.cpp:671
virtual void showSystematicScale()
Definition: View.cpp:710
virtual void bringToFront()
Definition: AlignItems.cpp:51
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()
Definition: AlignItems.cpp:85
virtual void selectItem(std::string name)
Select an item an item by name.
Definition: Scene.cpp:707
View(QWidget *widget=(QWidget *) 0)
Constructor.
Definition: View.cpp:61
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.
Definition: View.cpp:504
virtual void redraw(bool bRefresh=true)
Redraws the graphic component.
virtual void onSelectionItem(std::string name)
Definition: View.cpp:1094
virtual EnumType * getModeExit() const
Returns value that represents exit mode type belonging to enumeration.
ItemObserver * getItem()
Definition: Context.cpp:288
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.
Definition: Scene.cpp:463
This class implements a concrete tool to geographic zoom operation using the mouse click...
Definition: ViewZoomClick.h:46
virtual void selectItems(std::vector< std::string > names)
Select items by name.
Definition: Scene.cpp:743
virtual AlignItems * getAlignItems()
Method that returns the object responsible for aligning objects in the scene.
Definition: Scene.cpp:458
virtual bool buildTemplate(VisualizationArea *vzArea, EnumType *type, std::string fileName)
Method that import a template and build all objects. Ex.: JSON.
Definition: Scene.cpp:545
virtual EnumType * getModeNewTemplate() const
Returns value that represents new template mode type belonging to enumeration.
double m_llx
Lower left corner x-coordinate.
Definition: Envelope.h:344
virtual PrintScene * getPrintScene()
Method that returns the object responsible for printing the scene.
Definition: Scene.cpp:453
virtual QGraphicsItemGroup * createItemGroup(const QList< QGraphicsItem * > &items)
Groups objects and creates a QGraphicsItemGroup object. A command Undo/Redo of type AddCommand is cre...
Definition: Scene.cpp:333
virtual QGraphicsItem * intersectionSelectionItem(int x, int y)
Checks whether the coordinated intersects an item and returns.
Definition: ItemUtils.cpp:472
EnumCreate
Definition: AbstractType.h:134
double getDefaultZoomFactor()
Default zoom factor. Ex.: 0.5 (50%)
Definition: Context.cpp:228
virtual EnumType * getModeUnitsMetricsChange() const
Returns value that represents units metrics change mode type belonging to enumeration.
void setItem(ItemObserver *item)
Definition: Context.cpp:293
virtual bool exportProperties(EnumType *type)
Method that exports all the objects in the scene to a template. Ex.: JSON.
Definition: View.cpp:980
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...
Definition: EnumModeType.h:50
An Envelope defines a 2D rectangular region.
Definition: Envelope.h:51
virtual void createItemGroup()
Groups selected objects.
Definition: View.cpp:437
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()
Definition: PrintScene.cpp:61
virtual void outsideAreaChangeContext(bool change)
Responsible method for verifying changes made in Context outside the View object and call correspondi...
Definition: View.cpp:509
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...
Definition: Context.cpp:273
virtual void init(double screenWMM, double screenHMM)
Method that starts the scene and configures. Calculates the transformation matrix of the scene and ca...
Definition: Scene.cpp:177
HorizontalRuler * m_horizontalRuler
Definition: View.h:350
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.
Definition: View.cpp:432
virtual void alignBottom()
Definition: AlignItems.cpp:234
virtual void keyPressEvent(QKeyEvent *keyEvent)
Reimplemented from QGraphicsView.
Definition: View.cpp:326
virtual void wheelEvent(QWheelEvent *event)
Reimplemented from QGraphicsView.
Definition: View.cpp:287
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.
Definition: Context.cpp:75
Utility class for manipulating items in the scene and vectorization of text and legend.
Definition: ItemUtils.h:62
Class representing the scene. This scene is child of QGraphicsScene, part of Graphics View Framework...
Definition: Scene.h:80
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()
Definition: AlignItems.cpp:270
virtual void exportItemsToImage(std::string dir)
Saves each item in the scene as image. Ex .: .png.
Definition: Scene.cpp:598
virtual bool importTemplate(EnumType *type)
Method that import a template and build all objects. Ex.: JSON.
Definition: View.cpp:1018
virtual void zoomPercentage()
Method that applies current zoom defined in the Context.
Definition: View.cpp:883
virtual EnumType * getModeAlignCenterHorizontal() const
Returns value that represents align center horizontal mode type belonging to enumeration.
double m_lly
Lower left corner y-coordinate.
Definition: Envelope.h:345
virtual void createTextGridAsObject()
Vectorizes grid text of selected MapItem. (generates te::layout::TextItem objects) ...
Definition: ItemUtils.cpp:279
virtual void zoomOut()
Method that sets View object for the Zoom Out function.
Definition: View.cpp:844
virtual void mousePressEvent(QMouseEvent *event)
Reimplemented from QGraphicsView. Call method createItem() of the scene.
Definition: View.cpp:125
virtual void showPageSetup()
Method that instantiates and shows the Page Setup window.
Definition: View.cpp:677
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.
Definition: View.cpp:801
virtual EnumType * getModeMapZoomOut() const
Returns value that represents map zoom out mode type belonging to enumeration.
virtual void alignTop()
Definition: AlignItems.cpp:195
virtual void recompose()
Reset to initial configuration made in the config() method. Reset to default zoom factor...
Definition: View.cpp:874
double m_ury
Upper right corner y-coordinate.
Definition: Envelope.h:347
virtual QImage createImage()
Create snapshot of the View current state.
Definition: View.cpp:770
virtual void exportToPDF()
Method that sets View object for the Print function.
Definition: View.cpp:908
virtual EnumType * getModeZoomIn() const
Returns value that represents zoom in mode type belonging to enumeration.
void setWait(EnumType *wait)
Definition: Context.cpp:283
virtual QCursor createCursor(std::string pathIcon)
Definition: View.cpp:790
Class that represents the value of an enumeration. An enumeration is made of "1..n" objects EnumType...
Definition: EnumType.h:48
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.
Definition: VerticalRuler.h:44
virtual ~View()
Destructor.
Definition: View.cpp:92
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.
Definition: Scene.cpp:251
virtual void closeEvent(QCloseEvent *event)
Reimplemented from QGraphicsView.
Definition: View.cpp:665
virtual EnumTemplateType * getEnumTemplateType()
Returns template type enumeration.
Definition: Enums.cpp:102
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.
Definition: ItemUtils.cpp:248
virtual void alignLeft()
Definition: AlignItems.cpp:119
void setMode(EnumType *mode)
Change value of the enumeration of mode type. Ex.: select, pan, create text, etc. The type of mode is...
Definition: Context.cpp:93
virtual void updateSelectedItemsPositions()
Definition: Scene.cpp:778
virtual void removeSelectedItems()
Method that removes all selected items in the scene and creates a Command to Undo/Redo of type Delete...
Definition: Scene.cpp:284
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.
Definition: View.cpp:943
virtual void mouseReleaseEvent(QMouseEvent *event)
Reimplemented from QGraphicsView.
Definition: View.cpp:244
virtual EnumType * getModeArrowCursor() const
Returns value that represents arrow mode type belonging to enumeration.
virtual bool isExceededLimit(double currentScale, double factor, double oldFactor)
Definition: View.cpp:925
double getZoomFactor()
Returns current zoom factor. Ex.: 0.5 (50%)
Definition: Context.cpp:103
virtual void changeZoomFactor(double currentZoom)
Method that change rulers visibility state.
Definition: View.cpp:1076
void setOldZoomFactor(double zoomFactor)
Change previous zoom factor. Ex.: 0.5 (50%)
Definition: Context.cpp:243
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.
Definition: View.cpp:742
virtual void createLegendChildAsObject()
Vectorizes selected LegendItem. (generates te::layout::TextItem objects)
Definition: ItemUtils.cpp:303
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. ...
Definition: Scene.cpp:375
virtual void onSelectionChanged()
Notifies View object that the selection of objects in the scene changed.
Definition: View.cpp:737
Class that represents a vertical ruler with the coordinate system in mm.
virtual void alignCenterVertical()
Definition: AlignItems.cpp:310
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...
Definition: View.cpp:464
virtual void print()
Method that sets View object for the Print function.
Definition: View.cpp:857