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());
292 Qt::DropActions actions =
event->dropAction();
293 if(actions != Qt::CopyAction)
296 getMimeData(event->mimeData());
301 std::list<te::map::AbstractLayerPtr> layerList;
302 layerList.push_back(al);
306 m_mapDisplay->setLayerList(layerList);
307 m_mapDisplay->setSRID(al->getSRID(),
false);
308 m_mapDisplay->setExtent(e,
true);
314 Qt::DropActions actions =
event->dropAction();
315 if(actions != Qt::CopyAction)
318 const QMimeData* mime =
event->mimeData();
319 QString s = mime->data(
"application/x-terralib;value=\"DraggedItems\"").constData();
323 event->acceptProposedAction();
355 box = m_model->getBox();
358 QPointF posF = scenePos();
360 qreal valuex = posF.x() - x;
361 qreal valuey = posF.y() - y;
364 coordinate.
x = valuex;
365 coordinate.
y = valuey;
383 QRectF rect = boundingRect();
384 QPointF point =
event->pos();
387 QMouseEvent mouseEvent(QEvent::MouseMove, remappedPoint.toPoint(),
388 event->button(),
event->buttons(),
event->modifiers());
389 QApplication::sendEvent(m_mapDisplay, &mouseEvent);
390 event->setAccepted(mouseEvent.isAccepted());
409 QRectF rect = boundingRect();
410 QPointF point =
event->pos();
413 QMouseEvent mouseEvent(QEvent::MouseButtonPress, remappedPoint.toPoint(),
414 event->button(),
event->buttons(),
event->modifiers());
415 QApplication::sendEvent(m_mapDisplay, &mouseEvent);
416 event->setAccepted(mouseEvent.isAccepted());
435 QRectF rect = boundingRect();
436 QPointF point =
event->pos();
439 QMouseEvent mouseEvent(QEvent::MouseButtonRelease, remappedPoint.toPoint(),
440 event->button(),
event->buttons(),
event->modifiers());
441 QApplication::sendEvent(m_mapDisplay, &mouseEvent);
442 event->setAccepted(mouseEvent.isAccepted());
451 QString s = mime->data(
"application/x-terralib;value=\"DraggedItems\"").constData();
452 unsigned long v = s.toULongLong();
453 std::vector<te::qt::widgets::AbstractTreeItem*>* draggedItems =
reinterpret_cast<std::vector<te::qt::widgets::AbstractTreeItem*>*
>(v);
455 if(draggedItems->empty())
458 m_treeItem = draggedItems->operator[](0);
463 std::list<te::map::AbstractLayerPtr> visibleLayers;
466 return visibleLayers;
471 return visibleLayers;
473 std::list<te::map::AbstractLayerPtr> vis;
476 std::list<te::map::AbstractLayerPtr>::iterator vit;
477 for(vit = vis.begin(); vit != vis.end(); ++vit)
479 if((*vit)->getType() ==
"DATASETLAYER" ||
480 (*vit)->getType() ==
"QUERYLAYER" ||
481 (*vit)->getType() ==
"RASTERLAYER")
483 visibleLayers.push_front(*vit);
487 return visibleLayers;
497 layer = m_treeItem->getLayer();
524 m_changeLayer =
true;
533 m_mapDisplay->installEventFilter(m_tool);
540 m_mapDisplay->removeEventFilter(m_tool);
562 std::string icon_path_zoom_area =
"layout-map-zoom-in";
563 QCursor zoomAreaCursor(QIcon::fromTheme(icon_path_zoom_area.c_str()).pixmap(QSize(10,10)));
565 setCurrentTool(zoomArea);
570 std::string icon_path_zoom_out =
"layout-map-zoom-out";
571 QCursor zoomOutCursor(QIcon::fromTheme(icon_path_zoom_out.c_str()).pixmap(QSize(10,10)));
573 setCurrentTool(zoomOut);
581 QImage img = m_pixmap.toImage();
582 img = img.mirrored();
598 QColor color(0, 0, 255, 0);
600 QImage generator(m_pixmap.width(), m_pixmap.height(), QImage::Format_ARGB32);
601 generator.fill(color);
604 painter.begin(&generator);
606 QPoint pt(m_wMargin, m_hMargin);
607 widget()->render(&painter, pt);
609 if(!m_pixmap.isNull())
611 QRectF rectF(0, 0, m_pixmap.width(), m_pixmap.height());
613 painter.drawPixmap(rectF, m_pixmap, rectF);
615 generator.mirrored();
642 QRegion srcRegion( 0, 0, this->widget()->width(), this->widget()->height());
644 QColor color(255, 255, 255, 0);
645 QPixmap img(this->widget()->width(), this->widget()->height());
646 img.fill(Qt::transparent);
650 this->widget()->render(&ptr, pt, srcRegion);
676 if(name.compare(
"") == 0)
684 m_mapDisplay->changeData(layer);
699 QSize currentSize = m_mapDisplay->size();
700 QSize newSize = m_mapSize * currentZoomFactor;
701 if(currentSize != newSize)
703 QPointF pt = scenePos();
705 m_mapDisplay->setGeometry(pt.x(), pt.y(), newSize.width(), newSize.height());
706 m_changeLayer =
true;
718 prepareGeometryChange();
723 env.
m_urx = env.m_llx + m_rect.width();
724 env.m_ury = env.m_lly + m_rect.height();
725 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.