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"
38 #include <QtCore/QTimer>
39 #include <QtGui/QResizeEvent>
40 #include <QtGui/QPaintDevice>
45 m_displayPixmap(new QPixmap(size)),
46 m_draftPixmap(new QPixmap(size)),
47 m_backgroundColor(Qt::white),
48 m_resizePolicy(te::qt::widgets::
MapDisplay::Fixed),
49 m_timer(new QTimer(this)),
64 delete m_displayPixmap;
67 std::map<te::map::AbstractLayer*, te::qt::widgets::Canvas*>::iterator it;
68 for(it = m_layerCanvasMap.begin(); it != m_layerCanvasMap.end(); ++it)
71 m_layerCanvasMap.clear();
76 Qt::DropActions actions = e->dropAction();
77 if(actions != Qt::CopyAction)
80 const QMimeData* mime = e->mimeData();
81 QString s = mime->data(
"application/x-terralib;value=\"DraggedItems\"").constData();
91 const QMimeData* mime = e->mimeData();
92 QString s = mime->data(
"application/x-terralib;value=\"DraggedItems\"").constData();
93 unsigned long v = s.toULongLong();
94 std::vector<te::qt::widgets::AbstractTreeItem*>* draggedItems =
reinterpret_cast<std::vector<AbstractTreeItem*>*
>(v);
103 std::map<te::map::AbstractLayer*, te::qt::widgets::Canvas*>::iterator it;
104 for(it = m_layerCanvasMap.begin(); it != m_layerCanvasMap.end(); ++it)
109 m_layerCanvasMap.
clear();
115 std::list<te::map::AbstractLayerPtr> vis, visibleLayers;
118 std::list<te::map::AbstractLayerPtr>::iterator vit;
119 for(vit = vis.begin(); vit != vis.end(); ++vit)
121 if((*vit)->getType() ==
"DATASETLAYER" ||
122 (*vit)->getType() ==
"QUERYLAYER" ||
123 (*vit)->getType() ==
"RASTERLAYER")
125 visibleLayers.push_front(*vit);
129 setLayerList(visibleLayers);
136 std::list<te::map::AbstractLayerPtr>::iterator lit;
137 for(lit = visibleLayers.begin(); lit != visibleLayers.end(); ++lit)
141 int srid = (*lit)->getSRID();
157 std::map<te::map::AbstractLayer*, te::qt::widgets::Canvas*>::iterator it;
158 for(it = m_layerCanvasMap.begin(); it != m_layerCanvasMap.end(); ++it)
161 canvas->
calcAspectRatio(m_extent.m_llx, m_extent.m_lly, m_extent.m_urx, m_extent.m_ury, m_hAlign, m_vAlign);
162 canvas->
setWindow(m_extent.m_llx, m_extent.m_lly, m_extent.m_urx, m_extent.m_ury);
170 emit extentChanged();
180 m_displayPixmap->fill(m_backgroundColor);
182 QPainter painter(m_displayPixmap);
184 std::list<te::map::AbstractLayerPtr>::iterator it;
186 for(it = m_layerList.begin(); it != m_layerList.end(); ++it)
187 draw(it->get(), painter);
196 return static_cast<unsigned int>(width());
201 return static_cast<unsigned int>(height());
206 return static_cast<double>(widthMM());
211 return static_cast<double>(heightMM());
216 return m_displayPixmap;
221 return m_draftPixmap;
226 m_resizePolicy = policy;
242 draw(boost::dynamic_pointer_cast<te::map::AbstractLayer>(layer->
getChild(i)).
get(), painter);
248 layer->
draw(canvas, m_extent, m_srid);
251 QPaintDevice* device = canvas->
getDevice();
253 if(device->devType() == QInternal::Pixmap)
254 painter.drawPixmap(0, 0, *static_cast<QPixmap*>(device));
255 else if(device->devType() == QInternal::Image)
256 painter.drawImage(0, 0, *static_cast<QImage*>(device));
262 std::map<te::map::AbstractLayer*, te::qt::widgets::Canvas*>::iterator it = m_layerCanvasMap.find(layer);
263 if(it != m_layerCanvasMap.end())
268 canvas->
calcAspectRatio(m_extent.m_llx, m_extent.m_lly, m_extent.m_urx, m_extent.m_ury, m_hAlign, m_vAlign);
269 canvas->setWindow(m_extent.m_llx, m_extent.m_lly, m_extent.m_urx, m_extent.m_ury);
272 m_layerCanvasMap[layer] = canvas;
279 std::map<te::map::AbstractLayer*, te::qt::widgets::Canvas*>::iterator it;
280 for(it = m_layerCanvasMap.begin(); it != m_layerCanvasMap.end(); ++it)
281 it->second->resize(m_displayPixmap->width(), m_displayPixmap->height());
286 QPainter painter(
this);
287 painter.drawPixmap(0, 0, *m_displayPixmap);
288 painter.drawPixmap(0, 0, *m_draftPixmap);
293 QWidget::resizeEvent(e);
300 if(!m_oldSize.isValid())
301 e->oldSize().isValid() ? m_oldSize = e->oldSize() : m_oldSize = e->size();
304 m_timer->start(m_interval);
310 if(m_layerCanvasMap.empty())
317 return canvas->
getMatrix().inverted().map(p);
322 return m_backgroundColor;
327 m_backgroundColor = color;
338 delete m_displayPixmap;
339 m_displayPixmap =
new QPixmap(size());
340 m_displayPixmap->fill(m_backgroundColor);
342 delete m_draftPixmap;
343 m_draftPixmap =
new QPixmap(size());
344 m_draftPixmap->fill(Qt::transparent);
350 adjustExtent(m_oldSize, size());
358 if(!m_extent.isValid())
376 double newWidthW = (size.width() * widthW) / oldSize.width();
377 double newHeightW = (size.height() * heightW) / oldSize.height();
379 switch(m_resizePolicy)
391 e.
m_llx = center.
x - (newWidthW * 0.5);
392 e.
m_urx = center.
x + (newWidthW * 0.5);
393 e.
m_lly = center.
y - (newHeightW * 0.5);
394 e.
m_ury = center.
y + (newHeightW * 0.5);
virtual void onResizeTimeout()
virtual te::map::AbstractLayerPtr getLayer() const =0
QPaintDevice * getDevice() const
It returns the internal device used to draw geographical objects.
virtual void dragEnterEvent(QDragEnterEvent *)
virtual void setResizePolicy(const ResizePolicy &policy)
Sets the resize policy to this map display.
virtual QPixmap * getDisplayPixmap() const
It returns the map display pixmap.
QTimer * m_timer
Timer to execute redraw on resize action.
This is the base class for layers.
An object that when created shows a cursor during its scope.
A canvas is an abstraction of a drawing area.
virtual QPointF transform(const QPointF &p)
Transforms the given point, in screen coordinates, to a point in world coordinates.
virtual void setBackgroundColor(const QColor &color)
Sets the map display background color.
virtual void setExtent(te::gm::Envelope &e, bool doRefresh=true)
It sets the world visible area and refreshes the contents in the map display.
A Qt4 widget to control the display of a set of layers.
#define TE_UNKNOWN_SRS
A numeric value to represent a unknown SRS identification in TerraLib.
QMatrix getMatrix()
It returns the matrix.
ResizePolicy
Defines the resize policy for map display.
virtual te::qt::widgets::Canvas * getCanvas(te::map::AbstractLayer *layer, int type=QInternal::Pixmap)
It retrieves an associated canvas to the given layer.
double getHeightMM() const
It returns the MapDisplay current height in millimeters.
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. ...
virtual void draw(te::map::AbstractLayer *layer, QPainter &painter)
It displays the given layer.
A canvas built on top of Qt.
double m_lly
Lower left corner y-coordinate.
std::size_t getChildrenCount() const
It returns the number of children of this node.
virtual void changeData(te::map::AbstractLayerPtr, int nsrid=TE_UNKNOWN_SRS)
virtual QPixmap * getDraftPixmap() const
It returns the map display draft pixmap.
double m_ury
Upper right corner y-coordinate.
QPixmap * m_displayPixmap
This pixmap will be the result of all canvas pixmap drawing, i. e., the result of drawing all visible...
virtual void setExtent(te::gm::Envelope &e, bool doRefresh=true)
It sets the world visible area and refreshes the contents in the map display.
A canvas built on top of Qt.
virtual void setResizeInterval(int msec)
Sets the timeout interval in milliseconds to redraw on resize event.
bool isDrawing() const
Returns if the map display is drawing.
double m_urx
Upper right corner x-coordinate.
A widget to control the display of a set of layers.
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.
const TreeItemPtr & getChild(std::size_t i) const
It returns the n-th child.
Coord2D getCenter() const
It returns the rectangle's center coordinate.
void calcAspectRatio(double &llx, double &lly, double &urx, double &ury, const te::map::AlignType hAlign=te::map::Center, const te::map::AlignType vAlign=te::map::Center)
It calculates the best aspect ratio for world (or window) coordinates area (supposing a cartesian ref...
void transform(int oldsrid, int newsrid)
It will transform the coordinates of the Envelope from the old SRS to the new one.
The class that represents an item in a LayerTreeModel.
unsigned int getHeight() const
It returns the MapDisplay current height in pixels.
QPixmap * m_draftPixmap
The draft pixmap can be used to draw some feedback on map display.
virtual void resizeEvent(QResizeEvent *e)
This event handler receives widget resize events wich are passed in the event parameter.
virtual QColor getBackgroundColor()
Gets the map display background color.
unsigned int getWidth() const
It returns the MapDisplay current width in pixels.
MapDisplay()
It initializes a new MapDisplay.
double m_llx
Lower left corner x-coordinate.
virtual void refresh()
It updates the contents in the map display.
double getWidthMM() const
It returns the MapDisplay current width in millimeters.
virtual void resizeAllCanvas()
It resizes all canvas of map display.
boost::intrusive_ptr< AbstractLayer > AbstractLayerPtr
virtual void paintEvent(QPaintEvent *e)
It assembles the final image and draws the widget.
virtual Visibility getVisibility() const
It returns the layer visibility.
void clear()
It clears the canvas content and fills with the background color.
An Envelope defines a 2D rectangular region.
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).
QColor m_backgroundColor
Background color.
virtual ~MapDisplay()
Destructor.
virtual void dropEvent(QDropEvent *)
void Union(const Envelope &rhs)
It updates the envelop with coordinates of another envelope.
virtual void clear()=0
It clears the canvas content and fills with the background color.
virtual void adjustExtent(const QSize &oldSize, const QSize &size)
It adjusts the map display extent based on resize policy.
An object that when created shows a cursor during its scope.