All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
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 {
88  te::common::Free(m_rgbaMark, PATTERN_SIZE);
89  delete m_mark;
90 }
91 
92 void te::qt::widgets::ZoomInMapDisplayWidget::setList(std::list<te::map::AbstractLayerPtr>& layerList, int srid)
93 {
94  te::gm::Envelope e = m_parentMapDisplay->getExtent();
95 
96  te::gm::Envelope ext = calculateExtent(e);
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(QColor(0, 0, 0, 0));
118  const te::gm::Envelope& mapExt = m_mapDisplay->getExtent();
119  te::qt::widgets::Canvas canvasInstance(m_mapDisplay->getDraftPixmap());
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 
135  onParentMapDisplayExtentChanged();
136 }
137 
139 {
140  if(!m_isEnabled)
141  return;
142 
143  if(m_itsMe)
144  return;
145 
146  te::gm::Coord2D center = m_mapDisplay->getExtent().getCenter();
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 
171  te::gm::Envelope e = m_parentMapDisplay->getExtent();
172 
173  te::gm::Envelope ext = calculateExtent(e);
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 {
185  te::gm::Envelope e = m_parentMapDisplay->getExtent();
186 
187  te::gm::Envelope ext = calculateExtent(e);
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.
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.
Definition: Envelope.h:346
double getWidth() const
It returns the envelope width.
Definition: Envelope.h:443
A widget to control the display of a set of layers.
Definition: MapDisplay.h:66
An utility struct for representing 2D coordinates.
Definition: Coord2D.h:40
te::qt::widgets::MapDisplay * m_mapDisplay
Coord2D getCenter() const
It returns the rectangle's center coordinate.
Definition: Envelope.cpp:51
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).
Definition: Canvas.cpp:147
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.
Definition: Envelope.h:344
virtual void setResizePolicy(const ResizePolicy &policy)
Sets the resize policy to this map display.
Definition: MapDisplay.cpp:227
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.
Definition: Envelope.h:51
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.
Definition: Utils.cpp:130
double m_lly
Lower left corner y-coordinate.
Definition: Envelope.h:345
TESEEXPORT Stroke * CreateStroke(const std::string &color, const std::string &width)
Creates a stroke.
Definition: Utils.cpp:54
A canvas built on top of Qt.
Definition: Canvas.h:54
void setList(std::list< te::map::AbstractLayerPtr > &layerList, int srid)
This method is used to set the selected layer for mixture model operation.
te::qt::widgets::MapDisplay * m_parentMapDisplay
te::color::RGBAColor ** m_rgbaMark
Represents the pattern of cursor point.
double m_ury
Upper right corner y-coordinate.
Definition: Envelope.h:347
#define TE_TRANSPARENT
For an RGBA color this is the value of the alpha-channel for totally transparent. ...
Definition: Config.h:46
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
double getHeight() const
It returns the envelope height.
Definition: Envelope.h:448
bool isValid() const
It tells if the rectangle is valid or not.
Definition: Envelope.h:438
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.
Definition: Utils.cpp:109