ZoomInMapDisplayWidget.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 terralib/qt/widgets/canvas/ZoomInMapDisplayWidget.h
22 
23  \brief This file has the ZoomInMapDisplayWidget class.
24 */
25 
26 // TerraLib
27 #include "../../../common/STLUtils.h"
28 #include "../../../geometry/Coord2D.h"
29 #include "../../../geometry/Envelope.h"
30 #include "../../../geometry/Point.h"
31 #include "../../../maptools/MarkRendererManager.h"
32 #include "../../../maptools/Utils.h"
33 #include "../../../se/Fill.h"
34 #include "../../../se/Mark.h"
35 #include "../../../se/Stroke.h"
36 #include "../../../se/Utils.h"
37 #include "../../widgets/tools/AbstractTool.h"
38 #include "../../widgets/tools/Pan.h"
39 #include "../canvas/Canvas.h"
40 #include "../canvas/MultiThreadMapDisplay.h"
41 #include "ZoomInMapDisplayWidget.h"
42 
43 // Qt
44 #include <QGridLayout>
45 
46 #define PATTERN_SIZE 14
47 
49  : QWidget(parent, f), m_parentMapDisplay(mapParent), m_itsMe(false), m_isEnabled(true)
50 {
51 
52 //build form
53  QGridLayout* displayLayout = new QGridLayout(this);
54 
55  m_mapDisplay = new te::qt::widgets::MultiThreadMapDisplay(parent->size(), this);
57 
58  displayLayout->addWidget(m_mapDisplay, 0,0);
59 
60  m_sliderZoomFactor = new QSlider(Qt::Horizontal, this);
61  m_sliderZoomFactor->setRange(1, 100);
62  m_sliderZoomFactor->setValue(50);
63  m_sliderZoomFactor->setInvertedAppearance(true);
64 
65  displayLayout->addWidget(m_sliderZoomFactor, 1,0);
66 
67  displayLayout->setContentsMargins(0,0,0,0);
68 
69 //define mark
70  te::se::Stroke* strokeSel = te::se::CreateStroke("#000000", "1");
71  te::se::Fill* fillSel = te::se::CreateFill("#000000", "1.0");
72  m_mark = te::se::CreateMark("cross", strokeSel, fillSel);
73 
75 
76 // Zoom In Display pan tool
77  te::qt::widgets::Pan* zoomInPan = new te::qt::widgets::Pan(m_mapDisplay, Qt::OpenHandCursor, Qt::ClosedHandCursor, m_mapDisplay);
78  m_mapDisplay->installEventFilter(zoomInPan);
79 
80 // signals & slots
81  connect(m_mapDisplay, SIGNAL(extentChanged()), this, SLOT(onMapDisplayExtentChanged()));
82  connect(m_parentMapDisplay, SIGNAL(extentChanged()), this, SLOT(onParentMapDisplayExtentChanged()));
83  connect(m_sliderZoomFactor, SIGNAL(sliderReleased()), this, SLOT(onZoomFactorChanged()));
84 }
85 
87 {
89  delete m_mark;
90 }
91 
92 void te::qt::widgets::ZoomInMapDisplayWidget::setList(std::list<te::map::AbstractLayerPtr>& layerList, int srid)
93 {
95 
97 
98  m_mapDisplay->setMouseTracking(true);
99  m_mapDisplay->setLayerList(layerList);
100  m_mapDisplay->setSRID(srid, false);
101 
102  //m_itsMe = true;
103  m_mapDisplay->setExtent(ext, false);
104  //m_itsMe = false;
105 }
106 
108 {
109  return m_mapDisplay->getExtent();
110 }
111 
113 {
114  if(!m_isEnabled)
115  return;
116 
117  m_mapDisplay->getDraftPixmap()->fill(Qt::transparent);
118  const te::gm::Envelope& mapExt = m_mapDisplay->getExtent();
120  canvasInstance.setWindow(mapExt.m_llx, mapExt.m_lly, mapExt.m_urx, mapExt.m_ury);
121 
122  canvasInstance.setPointColor(te::color::RGBAColor(0,0,0, TE_TRANSPARENT)); //GAMBI
123  canvasInstance.setPointPattern(m_rgbaMark, PATTERN_SIZE, PATTERN_SIZE);
124 
125  te::gm::Point point(x, y);
126  canvasInstance.draw(&point);
127 
128  m_mapDisplay->repaint();
129 }
130 
132 {
133  m_isEnabled = status;
134 
136 }
137 
139 {
140  if(!m_isEnabled)
141  return;
142 
143  if(m_itsMe)
144  return;
145 
147 
148  double w = m_parentMapDisplay->getExtent().getWidth() * 0.5;
149  double h = m_parentMapDisplay->getExtent().getHeight() * 0.5;
150 
151  te::gm::Envelope auxExt;
152 
153  auxExt.m_llx = center.x - w;
154  auxExt.m_lly = center.y - h;
155  auxExt.m_urx = center.x + w;
156  auxExt.m_ury = center.y + h;
157 
158  m_itsMe = true;
159  m_parentMapDisplay->setExtent(auxExt);
160  m_itsMe = false;
161 }
162 
164 {
165  if(!m_isEnabled)
166  return;
167 
168  if(m_itsMe)
169  return;
170 
172 
174 
175  if(!ext.isValid())
176  return;
177 
178  m_itsMe = true;
179  m_mapDisplay->setExtent(ext, true);
180  m_itsMe = false;
181 }
182 
184 {
186 
188 
189  m_itsMe = true;
190  m_mapDisplay->setExtent(ext, true);
191  m_itsMe = false;
192 }
193 
195 {
196  double value = (double)m_sliderZoomFactor->value() / 100.;
197  double hScale = (double)m_mapDisplay->getHeight() / (double)m_parentMapDisplay->getHeight();
198  double wScale = (double)m_mapDisplay->getWidth() / (double)m_parentMapDisplay->getWidth();
199  double scale = (hScale + wScale) / 2.;
200 
201  te::gm::Coord2D center = e.getCenter();
202 
203  // Bulding the zoom extent based on zoom factor value and the given point
204  double w = e.getWidth() * scale * value;
205  double h = e.getHeight() * scale * value;
206 
207  te::gm::Envelope ext(center.x - w, center.y - h, center.x + w, center.y + h);
208 
209  return ext;
210 }
This file has the ZoomInMapDisplayWidget class.
unsigned int getWidth() const
It returns the MapDisplay current width in pixels.
double y
y-coordinate.
Definition: Coord2D.h:114
double x
x-coordinate.
Definition: Coord2D.h:113
te::gm::Envelope calculateExtent(te::gm::Envelope &e)
double m_urx
Upper right corner x-coordinate.
double getWidth() const
It returns the envelope width.
A widget to control the display of a set of layers.
An utility struct for representing 2D coordinates.
Definition: Coord2D.h:40
te::qt::widgets::MapDisplay * m_mapDisplay
Coord2D getCenter() const
It returns the rectangle&#39;s center coordinate.
virtual void setLayerList(const std::list< te::map::AbstractLayerPtr > &layers)
It sets the layer list to be showed in the Map Display.
void Free(std::vector< T * > *v)
This function can be applied to a pointer to a vector of pointers.
Definition: STLUtils.h:131
void setWindow(const double &llx, const double &lly, const double &urx, const double &ury)
It sets the world (or window) coordinates area (supposing a cartesian reference system).
This class implements a concrete tool to geographic pan operation.
Definition: Pan.h:49
te::se::Mark * m_mark
Represents the mark of a cursor point.
double m_llx
Lower left corner x-coordinate.
virtual void setResizePolicy(const ResizePolicy &policy)
Sets the resize policy to this map display.
static MarkRendererManager & getInstance()
It returns a reference to the singleton instance.
A point with x and y coordinate values.
Definition: Point.h:50
An Envelope defines a 2D rectangular region.
virtual const te::gm::Envelope & getExtent() const
It returns the world extent showned by the MapDisplay.
A Fill specifies the pattern for filling an area geometry.
Definition: Fill.h:59
TESEEXPORT Mark * CreateMark(const std::string &wellKnownName, Stroke *stroke, Fill *fill)
Creates a mark.
double m_lly
Lower left corner y-coordinate.
TESEEXPORT Stroke * CreateStroke(const std::string &color, const std::string &width)
Creates a stroke.
void setList(std::list< te::map::AbstractLayerPtr > &layerList, int srid)
This method is used to set the selected layer for mixture model operation.
unsigned int getHeight() const
It returns the MapDisplay current height in pixels.
te::qt::widgets::MapDisplay * m_parentMapDisplay
te::color::RGBAColor ** m_rgbaMark
Represents the pattern of cursor point.
virtual QPixmap * getDraftPixmap() const
It returns the map display draft pixmap.
double m_ury
Upper right corner y-coordinate.
A Stroke specifies the appearance of a linear geometry.
Definition: Stroke.h:67
A helper class for 32-bit RGBA (Red-Green-Blue-Alpha channel) color.
Definition: RGBAColor.h:57
#define PATTERN_SIZE
virtual void setSRID(const int &srid, bool doRefresh=true)
It sets a new Spatial Reference System to be used by the Map Display.
#define TE_TRANSPARENT
For an RGBA color this is the value of the alpha-channel for totally transparent. ...
virtual void setExtent(te::gm::Envelope &e, bool doRefresh=true)
It sets the world visible area and refreshes the contents in the map display.
double getHeight() const
It returns the envelope height.
bool isValid() const
It tells if the rectangle is valid or not.
A multi thread Qt4 widget to control the display of a set of layers.
ZoomInMapDisplayWidget(te::qt::widgets::MapDisplay *mapParent, QWidget *parent=0, Qt::WindowFlags f=0)
TESEEXPORT Fill * CreateFill(const std::string &color, const std::string &opacity)
Creates a fill.