27 #include "../../../common/STLUtils.h"
28 #include "../../../geometry/Coord2D.h"
29 #include "../../../geometry/Envelope.h"
30 #include "../../../maptools/AbstractLayer.h"
31 #include "../../../maptools/Utils.h"
32 #include "../../../qt/widgets/layer/explorer/AbstractTreeItem.h"
33 #include "../utils/ScopedCursor.h"
39 #include <QPaintDevice>
40 #include <QResizeEvent>
46 m_displayPixmap(new QPixmap(size)),
47 m_draftPixmap(new QPixmap(size)),
48 m_backgroundColor(Qt::white),
49 m_resizePolicy(te::qt::widgets::
MapDisplay::Fixed),
50 m_timer(new QTimer(this)),
65 delete m_displayPixmap;
68 std::map<te::map::AbstractLayer*, te::qt::widgets::Canvas*>::iterator it;
69 for(it = m_layerCanvasMap.begin(); it != m_layerCanvasMap.end(); ++it)
72 m_layerCanvasMap.clear();
77 Qt::DropActions actions = e->dropAction();
78 if(actions != Qt::CopyAction)
81 const QMimeData* mime = e->mimeData();
82 QString s = mime->data(
"application/x-terralib;value=\"DraggedItems\"").constData();
92 const QMimeData* mime = e->mimeData();
93 QString s = mime->data(
"application/x-terralib;value=\"DraggedItems\"").constData();
94 unsigned long v = s.toULongLong();
95 std::vector<te::qt::widgets::AbstractTreeItem*>* draggedItems =
reinterpret_cast<std::vector<AbstractTreeItem*>*
>(v);
104 std::map<te::map::AbstractLayer*, te::qt::widgets::Canvas*>::iterator it;
105 for(it = m_layerCanvasMap.begin(); it != m_layerCanvasMap.end(); ++it)
110 m_layerCanvasMap.
clear();
116 std::list<te::map::AbstractLayerPtr> vis, visibleLayers;
119 std::list<te::map::AbstractLayerPtr>::iterator vit;
120 for(vit = vis.begin(); vit != vis.end(); ++vit)
122 if((*vit)->getType() ==
"DATASETLAYER" ||
123 (*vit)->getType() ==
"QUERYLAYER" ||
124 (*vit)->getType() ==
"RASTERLAYER")
126 visibleLayers.push_front(*vit);
130 setLayerList(visibleLayers);
137 std::list<te::map::AbstractLayerPtr>::iterator lit;
138 for(lit = visibleLayers.begin(); lit != visibleLayers.end(); ++lit)
142 int srid = (*lit)->getSRID();
158 std::map<te::map::AbstractLayer*, te::qt::widgets::Canvas*>::iterator it;
159 for(it = m_layerCanvasMap.begin(); it != m_layerCanvasMap.end(); ++it)
162 canvas->
calcAspectRatio(m_extent.m_llx, m_extent.m_lly, m_extent.m_urx, m_extent.m_ury, m_hAlign, m_vAlign);
163 canvas->
setWindow(m_extent.m_llx, m_extent.m_lly, m_extent.m_urx, m_extent.m_ury);
171 emit extentChanged();
181 m_displayPixmap->fill(m_backgroundColor);
183 QPainter painter(m_displayPixmap);
185 std::list<te::map::AbstractLayerPtr>::iterator it;
187 for(it = m_layerList.begin(); it != m_layerList.end(); ++it)
188 draw(it->get(), painter);
197 return static_cast<unsigned int>(width());
202 return static_cast<unsigned int>(height());
207 return static_cast<double>(widthMM());
212 return static_cast<double>(heightMM());
218 emit displaySridChanged();
223 return m_displayPixmap;
228 return m_draftPixmap;
233 m_resizePolicy = policy;
249 draw(boost::dynamic_pointer_cast<te::map::AbstractLayer>(layer->
getChild(i)).
get(), painter);
255 layer->
draw(canvas, m_extent, m_srid);
258 QPaintDevice* device = canvas->
getDevice();
260 if(device->devType() == QInternal::Pixmap)
261 painter.drawPixmap(0, 0, *static_cast<QPixmap*>(device));
262 else if(device->devType() == QInternal::Image)
263 painter.drawImage(0, 0, *static_cast<QImage*>(device));
269 std::map<te::map::AbstractLayer*, te::qt::widgets::Canvas*>::iterator it = m_layerCanvasMap.find(layer);
270 if(it != m_layerCanvasMap.end())
275 canvas->
calcAspectRatio(m_extent.m_llx, m_extent.m_lly, m_extent.m_urx, m_extent.m_ury, m_hAlign, m_vAlign);
276 canvas->setWindow(m_extent.m_llx, m_extent.m_lly, m_extent.m_urx, m_extent.m_ury);
279 m_layerCanvasMap[layer] = canvas;
286 std::map<te::map::AbstractLayer*, te::qt::widgets::Canvas*>::iterator it;
287 for(it = m_layerCanvasMap.begin(); it != m_layerCanvasMap.end(); ++it)
288 it->second->resize(m_displayPixmap->width(), m_displayPixmap->height());
293 QPainter painter(
this);
294 painter.drawPixmap(0, 0, *m_displayPixmap);
296 emit displayPaintEvent(&painter);
298 painter.drawPixmap(0, 0, *m_draftPixmap);
303 QWidget::resizeEvent(e);
310 if(!m_oldSize.isValid())
311 e->oldSize().isValid() ? m_oldSize = e->oldSize() : m_oldSize = e->size();
314 m_timer->start(m_interval);
320 if(m_layerCanvasMap.empty())
327 return canvas->
getMatrix().inverted().map(p);
332 return m_backgroundColor;
337 m_backgroundColor = color;
348 delete m_displayPixmap;
349 m_displayPixmap =
new QPixmap(size());
350 m_displayPixmap->fill(m_backgroundColor);
352 delete m_draftPixmap;
353 m_draftPixmap =
new QPixmap(size());
354 m_draftPixmap->fill(Qt::transparent);
360 adjustExtent(m_oldSize, size());
368 if(!m_extent.isValid())
386 double newWidthW = (size.width() * widthW) / oldSize.width();
387 double newHeightW = (size.height() * heightW) / oldSize.height();
389 switch(m_resizePolicy)
401 e.
m_llx = center.
x - (newWidthW * 0.5);
402 e.
m_urx = center.
x + (newWidthW * 0.5);
403 e.
m_lly = center.
y - (newHeightW * 0.5);
404 e.
m_ury = center.
y + (newHeightW * 0.5);
const TreeItemPtr & getChild(std::size_t i) const
It returns the n-th child.
std::size_t getChildrenCount() const
It returns the number of children of this node.
This is the base class for layers.
double m_urx
Upper right corner x-coordinate.
virtual void clear()=0
It clears the canvas content and fills with the background color.
virtual Visibility getVisibility() const
It returns the layer visibility.
An utility struct for representing 2D coordinates.
virtual void draw(Canvas *canvas, const te::gm::Envelope &bbox, int srid)=0
It draws the layer geographic objects in the given canvas using the informed SRS. ...
void Union(const Envelope &rhs)
It updates the envelop with coordinates of another envelope.
virtual void setExtent(te::gm::Envelope &e, bool doRefresh=true)
It sets the world visible area and refreshes the contents in the map display.
Coord2D getCenter() const
It returns the rectangle's center coordinate.
MapDisplay()
It initializes a new MapDisplay.
double m_llx
Lower left corner x-coordinate.
An Envelope defines a 2D rectangular region.
#define TE_UNKNOWN_SRS
A numeric value to represent a unknown SRS identification in TerraLib.
virtual void setSRID(const int &srid, bool doRefresh=true)
It sets a new Spatial Reference System to be used by the Map Display.
double m_lly
Lower left corner y-coordinate.
A canvas is an abstraction of a drawing area.
double m_ury
Upper right corner y-coordinate.
boost::intrusive_ptr< AbstractLayer > AbstractLayerPtr
void transform(int oldsrid, int newsrid)
It will transform the coordinates of the Envelope from the old SRS to the new one.
TEMAPEXPORT void GetVisibleLayers(const std::list< te::map::AbstractLayerPtr > &layers, std::list< te::map::AbstractLayerPtr > &visibleLayers)
It gets the visible layers of the given layer list.