30 #include "../../core/pattern/singleton/Context.h"
31 #include "../../core/AbstractScene.h"
32 #include "../../core/pattern/mvc/ItemModelObservable.h"
33 #include "../../core/pattern/mvc/ItemObserver.h"
34 #include "../../core/pattern/mvc/ItemController.h"
35 #include "../../../color/RGBAColor.h"
36 #include "../../../qt/widgets/Utils.h"
37 #include "../../../geometry/Envelope.h"
38 #include "../../../common/STLUtils.h"
39 #include "../../../qt/widgets/canvas/Canvas.h"
40 #include "../../../dataaccess/utils/Utils.h"
41 #include "../../../dataaccess/dataset/ObjectIdSet.h"
42 #include "../../../qt/widgets/canvas/MultiThreadMapDisplay.h"
43 #include "../../../common/TreeItem.h"
44 #include "../../../srs/Converter.h"
45 #include "../../../maptools/Utils.h"
46 #include "../../item/MapController.h"
47 #include "../../../qt/widgets/tools/Pan.h"
48 #include "../../../qt/widgets/tools/ZoomArea.h"
49 #include "../../../qt/widgets/tools/ZoomClick.h"
50 #include "../core/ItemUtils.h"
51 #include "../../item/MapModel.h"
52 #include "../../../common/StringUtils.h"
53 #include "../../core/enum/Enums.h"
54 #include "../core/Scene.h"
55 #include "../../core/pattern/proxy/AbstractProxyProject.h"
64 #include <QMessageBox>
69 #include <QVBoxLayout>
73 #include <QApplication>
74 #include <QGraphicsSceneMouseEvent>
75 #include <QStyleOptionGraphicsItem>
84 ParentItem<QGraphicsProxyWidget>(controller, o),
86 m_grabbedByWidget(false),
94 m_nameClass = std::string(this->metaObject()->className());
111 m_mapDisplay->setSynchronous(
true);
112 m_mapDisplay->setAcceptDrops(
true);
113 m_mapDisplay->setBackgroundColor(Qt::gray);
114 m_mapDisplay->setResizeInterval(0);
115 m_mapDisplay->setMouseTracking(
true);
117 connect(m_mapDisplay,SIGNAL(drawLayersFinished(
const QMap<QString, QString>&)),
123 setWidget(m_mapDisplay);
129 m_mapDisplay->show();
136 setHandlesChildEvents(
true);
144 m_mapDisplay->removeEventFilter(m_zoomWheel);
161 boundRect = boundingRect();
174 double w = mapBox.
getWidth() * zoomFactor;
175 double h = mapBox.
getHeight() * zoomFactor;
181 if(w != m_mapDisplay->getWidth()
182 || h != m_mapDisplay->getHeight())
184 QPointF pt = scenePos();
185 m_mapDisplay->setGeometry(pt.x(), pt.y(), w, h);
190 qcolor.setRed(clr.
getRed());
194 m_mapDisplay->setBackgroundColor(qcolor);
195 m_mapDisplay->refresh();
197 calculateFrameMargin();
211 pixmap = QPixmap::fromImage(*img);
224 double resX = widget.width() / item.width();
225 double resY = widget.height() / item.height();
228 matrix.scale(resX, -resY);
229 matrix.translate(-item.bottomLeft().x(), -item.bottomLeft().y());
231 QPointF remappedPoint = matrix.map(point);
232 return remappedPoint;
244 drawBackground( painter );
251 if (option->state & QStyle::State_Selected)
253 drawSelection(painter);
259 if(!m_mapDisplay || !painter)
263 boundRect = boundingRect();
265 if( m_pixmap.isNull() || m_changeLayer)
267 m_changeLayer =
false;
269 m_pixmap = QPixmap(m_mapDisplay->width(), m_mapDisplay->height());
270 m_pixmap.fill(Qt::transparent);
272 QPainter localPainter(&m_pixmap);
273 m_mapDisplay->render(&localPainter);
276 QImage image = m_pixmap.toImage();
277 image = image.mirrored();
279 m_pixmap = QPixmap::fromImage(image);
283 painter->setClipRect(boundRect);
284 painter->drawPixmap(boundRect, m_pixmap, m_pixmap.rect());
291 event->setDropAction(Qt::CopyAction);
293 getMimeData(event->mimeData());
298 std::list<te::map::AbstractLayerPtr> layerList;
299 layerList.push_back(al);
303 m_mapDisplay->setLayerList(layerList);
304 m_mapDisplay->setSRID(al->getSRID(),
false);
305 m_mapDisplay->setExtent(e,
true);
311 Qt::DropActions actions =
event->dropAction();
312 if(actions != Qt::CopyAction)
315 const QMimeData* mime =
event->mimeData();
316 QString s = mime->data(
"application/x-terralib;value=\"DraggedItems\"").constData();
320 event->acceptProposedAction();
352 box = m_model->getBox();
355 QPointF posF = scenePos();
357 qreal valuex = posF.x() - x;
358 qreal valuey = posF.y() - y;
361 coordinate.
x = valuex;
362 coordinate.
y = valuey;
380 QRectF rect = boundingRect();
381 QPointF point =
event->pos();
384 QMouseEvent mouseEvent(QEvent::MouseMove, remappedPoint.toPoint(),
385 event->button(),
event->buttons(),
event->modifiers());
386 QApplication::sendEvent(m_mapDisplay, &mouseEvent);
387 event->setAccepted(mouseEvent.isAccepted());
406 QRectF rect = boundingRect();
407 QPointF point =
event->pos();
410 QMouseEvent mouseEvent(QEvent::MouseButtonPress, remappedPoint.toPoint(),
411 event->button(),
event->buttons(),
event->modifiers());
412 QApplication::sendEvent(m_mapDisplay, &mouseEvent);
413 event->setAccepted(mouseEvent.isAccepted());
432 QRectF rect = boundingRect();
433 QPointF point =
event->pos();
436 QMouseEvent mouseEvent(QEvent::MouseButtonRelease, remappedPoint.toPoint(),
437 event->button(),
event->buttons(),
event->modifiers());
438 QApplication::sendEvent(m_mapDisplay, &mouseEvent);
439 event->setAccepted(mouseEvent.isAccepted());
448 QString s = mime->data(
"application/x-terralib;value=\"DraggedItems\"").constData();
449 unsigned long v = s.toULongLong();
450 std::vector<te::qt::widgets::AbstractTreeItem*>* draggedItems =
reinterpret_cast<std::vector<te::qt::widgets::AbstractTreeItem*>*
>(v);
452 if(draggedItems->empty())
455 m_treeItem = draggedItems->operator[](0);
460 std::list<te::map::AbstractLayerPtr> visibleLayers;
463 return visibleLayers;
468 return visibleLayers;
470 std::list<te::map::AbstractLayerPtr> vis;
473 std::list<te::map::AbstractLayerPtr>::iterator vit;
474 for(vit = vis.begin(); vit != vis.end(); ++vit)
476 if((*vit)->getType() ==
"DATASETLAYER" ||
477 (*vit)->getType() ==
"QUERYLAYER" ||
478 (*vit)->getType() ==
"RASTERLAYER")
480 visibleLayers.push_front(*vit);
484 return visibleLayers;
494 layer = m_treeItem->getLayer();
521 m_changeLayer =
true;
530 m_mapDisplay->installEventFilter(m_tool);
537 m_mapDisplay->removeEventFilter(m_tool);
559 std::string icon_path_zoom_area =
"layout-map-zoom-in";
560 QCursor zoomAreaCursor(QIcon::fromTheme(icon_path_zoom_area.c_str()).pixmap(QSize(10,10)));
562 setCurrentTool(zoomArea);
567 std::string icon_path_zoom_out =
"layout-map-zoom-out";
568 QCursor zoomOutCursor(QIcon::fromTheme(icon_path_zoom_out.c_str()).pixmap(QSize(10,10)));
570 setCurrentTool(zoomOut);
578 QImage img = m_pixmap.toImage();
579 img = img.mirrored();
595 QColor color(0, 0, 255, 0);
597 QImage generator(m_pixmap.width(), m_pixmap.height(), QImage::Format_ARGB32);
598 generator.fill(color);
601 painter.begin(&generator);
603 QPoint pt(m_wMargin, m_hMargin);
604 widget()->render(&painter, pt);
606 if(!m_pixmap.isNull())
608 QRectF rectF(0, 0, m_pixmap.width(), m_pixmap.height());
610 painter.drawPixmap(rectF, m_pixmap, rectF);
612 generator.mirrored();
639 QRegion srcRegion( 0, 0, this->widget()->width(), this->widget()->height());
641 QColor color(255, 255, 255, 0);
642 QPixmap img(this->widget()->width(), this->widget()->height());
643 img.fill(Qt::transparent);
647 this->widget()->render(&ptr, pt, srcRegion);
673 if(name.compare(
"") == 0)
681 m_mapDisplay->changeData(layer);
696 QSize currentSize = m_mapDisplay->size();
697 QSize newSize = m_mapSize * currentZoomFactor;
698 if(currentSize != newSize)
700 QPointF pt = scenePos();
702 m_mapDisplay->setGeometry(pt.x(), pt.y(), newSize.width(), newSize.height());
703 m_changeLayer =
true;
715 prepareGeometryChange();
720 env.
m_urx = env.m_llx + m_rect.width();
721 env.m_ury = env.m_lly + m_rect.height();
722 m_controller->setBox(env);
virtual void updateObserver(ContextItem context)
Reimplemented from ItemObserver.
Abstract class to represent an observable. "Model" part of MVC component.
virtual ~MapItem()
Destructor.
virtual void getMimeData(const QMimeData *mime)
Class responsible for maintaining the drawing context of a MVC component. It is always used by the "M...
virtual bool isLoadedLayer()
virtual std::string getNameLayer()
virtual double getDisplacementX()
virtual te::color::RGBAColor ** getRGBAColorImage(int &w, int &h)
Reimplemented from ItemObserver.
virtual void mouseReleaseEvent(QGraphicsSceneMouseEvent *event)
Reimplemented from QGraphicsItem.
void onDrawLayersFinished(const QMap< QString, QString > &errors)
te::layout::Observable * m_model
"Model" part of MVC component.
int getRed() const
It returns the red component color value (a value from 0 to 255).
te::qt::widgets::ZoomWheel * m_zoomWheel
virtual void dragEnterEvent(QGraphicsSceneDragDropEvent *event)
Reimplemented from QGraphicsProxyWidget.
virtual EnumModeType * getEnumModeType()
Returns mode type enumeration.
virtual EnumType * getModeMapZoomIn() const
Returns value that represents map zoom in mode type belonging to enumeration.
virtual void mouseMoveEvent(QGraphicsSceneMouseEvent *event)
Reimplemented from QGraphicsProxyWidget.
virtual QImage generateImage()
virtual void mouseMoveEvent(QGraphicsSceneMouseEvent *event)
Reimplemented from QGraphicsItem.
virtual void generateMapPixmap()
virtual te::gm::Envelope getBox()=0
Returns the bounding rectangle of the component in scene coordinates(millimeters). Starting point is llx, lly. Reimplement this function in a Observable subclass to provide the model's getBox implementation.
QPointF remapPointToViewport(const QPointF &point, const QRectF &item, const QRectF &widget)
virtual void changeZoomFactor(double currentZoomFactor)
It is called immediately by the Scene when the zoom factor is changed in the Context.
int getBlue() const
It returns the blue component color value (a value from 0 to 255).
double m_urx
Upper right corner x-coordinate.
int getGreen() const
It returns the green component color value (a value from 0 to 255).
double getWidth() const
It returns the envelope width.
virtual bool isCurrentMapTools()
Indicates whether there is a tool active for object te::layout::MapItem.
The Properties class represents a persistent set of properties. The Properties can be saved to a file...
An utility struct for representing 2D coordinates.
void setPixmap(const QPixmap &pixmap)
Abstract class to represent a controller. "Controller" part of MVC component. All classes representin...
virtual void mousePressEvent(QGraphicsSceneMouseEvent *event)
Reimplemented from QGraphicsItem.
virtual void dragLeaveEvent(QGraphicsSceneDragDropEvent *event)
Reimplemented from QGraphicsProxyWidget.
virtual te::color::RGBAColor ** getPixmap()
Returns pixmap generated after drawing.
virtual void updateProperties(te::layout::Properties *properties)
Reimplemented from Observable.
virtual void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget=0)
Reimplemented from QGraphicsProxyWidget.
void Free(std::vector< T * > *v)
This function can be applied to a pointer to a vector of pointers.
static Context & 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...
An Envelope defines a 2D rectangular region.
virtual Utils * getUtils()
AbstractProxyProject * getProxyProject()
Returns proxy to provide a surrogate or placeholder for te::qt::af::Project to control access to it...
virtual void updateProperties(te::layout::Properties *properties)
Reimplemented from ItemObserver.
virtual void recalculateBoundingRect()
The default implementation does nothing.
void setCurrentTool(te::qt::widgets::AbstractTool *tool)
Utils * getUtils()
Returns pointer with functions to manipulate the canvas and conversion between projections.
virtual void dropEvent(QGraphicsSceneDragDropEvent *event)
Reimplemented from QGraphicsProxyWidget.
int getAlpha() const
It returns the alpha component color value (a value from 0 to 255).
ItemUtils * getItemUtils()
Returns pointer for manipulating items in the scene and vectorization of text and legend...
std::string m_nameClass
Class name.
QSize m_mapSize
The size of the map display in a zoom of 100%. This size is in pixels and is calculated based on the ...
virtual EnumType * getModeMapPan() const
Returns value that represents map pan mode type belonging to enumeration.
virtual te::gm::Envelope viewportBox(te::gm::Envelope box)
Converts the box world (mm) to screen coordinates (pixel).
std::list< te::map::AbstractLayerPtr > getVisibleLayers()
Utility class for manipulating items in the scene and vectorization of text and legend.
virtual te::gm::Coord2D getPosition()
Reimplemented from ItemObserver.
Class that represents a "Model" part of Map MVC component. Its coordinate system is the same of scene...
virtual te::gm::Envelope getMapBox()
Abstract class to provide a surrogate or placeholder for te::qt::af::Project to control access to it...
virtual te::color::RGBAColor getMapBackgroundColor()
Class that represents a "Controller" part of Map MVC component. Its coordinate system is the same of ...
virtual EnumType * getModeMapZoomOut() const
Returns value that represents map zoom out mode type belonging to enumeration.
virtual void changeCurrentTool(EnumType *mode)
Class that represents the value of an enumeration. An enumeration is made of "1..n" objects EnumType...
virtual double getDisplacementY()
A helper class for 32-bit RGBA (Red-Green-Blue-Alpha channel) color.
virtual te::map::AbstractLayerPtr contains(std::string name)=0
Checks whether the layer is in the project.
void setMode(EnumType *mode)
Change value of the enumeration of mode type. Ex.: select, pan, create text, etc. The type of mode is...
virtual te::gm::Envelope getBox()
Reimplemented from Observable.
te::map::AbstractLayerPtr getLayer()
virtual void mouseReleaseEvent(QGraphicsSceneMouseEvent *event)
Reimplemented from QGraphicsProxyWidget.
double getZoomFactor()
Returns current zoom factor. Ex.: 0.5 (50%)
virtual void calculateFrameMargin()
virtual void dragMoveEvent(QGraphicsSceneDragDropEvent *event)
Reimplemented from QGraphicsProxyWidget.
virtual void drawMap(QPainter *painter)
Utility class with functions to manipulate the canvas and conversion between projections.
virtual bool refreshLayer(te::map::AbstractLayerPtr layer)
virtual QRectF boundingRect() const
Reimplemented from ParentItem.
boost::intrusive_ptr< AbstractLayer > AbstractLayerPtr
Abstract class that represents a graphic item. Its coordinate system is the same of scene (millimeter...
double getHeight() const
It returns the envelope height.
bool isValid() const
It tells if the rectangle is valid or not.
MapItem(ItemController *controller, Observable *o)
Constructor.
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.
te::qt::widgets::MultiThreadMapDisplay * m_mapDisplay
virtual void mousePressEvent(QGraphicsSceneMouseEvent *event)
Reimplemented from QGraphicsProxyWidget.