156 lines
5.4 KiB
C++
Executable File
156 lines
5.4 KiB
C++
Executable File
|
|
/**
|
|
**
|
|
** @RDE_HEADER@
|
|
** Implementation of base class for rubberband handles
|
|
** $Id$
|
|
** $HeadURL$
|
|
** $Author$
|
|
**
|
|
** -----------------------------------------------------------------------------------------------
|
|
**
|
|
** Hardware-Environment: Intel-PC
|
|
** Software-Environment: Windows 7, Qt 5.4. ArcGIS 10.2.5
|
|
**
|
|
** Language ........: C++ 11
|
|
**
|
|
** -----------------------------------------------------------------------------------------------
|
|
**
|
|
** Author ...........: Jörg Turla, SPD G, Tel. 3132
|
|
**
|
|
** -----------------------------------------------------------------------------------------------
|
|
**
|
|
** Notes .........:
|
|
**
|
|
** 27.03.2015, JT : First edition for use with Qt5
|
|
**
|
|
** -----------------------------------------------------------------------------------------------
|
|
*/
|
|
|
|
#include "rubberband_drawable.h"
|
|
|
|
|
|
// ESRI
|
|
#include <arcgis/Map.h>
|
|
|
|
|
|
|
|
namespace SituationMap { namespace RB
|
|
{
|
|
|
|
Esri::ArcGISRuntime::Point convert(const QPointF &point, const Esri::ArcGISRuntime::SpatialReference& spatialReference)
|
|
{
|
|
return Esri::ArcGISRuntime::Point(point.x(), point.y(), spatialReference);
|
|
} // convert
|
|
|
|
|
|
RubberbandDrawable::RubberbandDrawable( QGraphicsView * view )
|
|
: _scene((view) ? view->scene() : nullptr)
|
|
, _mapView()
|
|
, _isVisible(true)
|
|
, _lineWidth(1)
|
|
, _zBufferValue((unsigned int) ZBufferPlane::Drawables)
|
|
, _logger(getLogger("RubberbandDrawable"))
|
|
|
|
{
|
|
doConnecting();
|
|
} /* RubberbandDrawable::RubberbandDrawable */
|
|
|
|
RubberbandDrawable::RubberbandDrawable( Esri::ArcGISRuntime::MapGraphicsView * mapView )
|
|
: _scene(mapView->scene())
|
|
, _mapView(mapView)
|
|
, _isVisible(true)
|
|
, _lineWidth(1)
|
|
, _zBufferValue((unsigned int) ZBufferPlane::Drawables)
|
|
, _logger(getLogger("RubberbandDrawable"))
|
|
|
|
{
|
|
doConnecting();
|
|
} /* RubberbandDrawable::RubberbandDrawable */
|
|
|
|
RubberbandDrawable::RubberbandDrawable( Esri::ArcGISRuntime::MapGraphicsView * mapView, QGraphicsScene * scene)
|
|
: _scene(scene)
|
|
, _mapView(mapView)
|
|
, _isVisible(true)
|
|
, _lineWidth(1)
|
|
, _zBufferValue((unsigned int) ZBufferPlane::Drawables)
|
|
, _logger(getLogger("RubberbandDrawable"))
|
|
|
|
{
|
|
doConnecting();
|
|
} /* RubberbandDrawable::RubberbandDrawable */
|
|
|
|
|
|
#ifdef ADJUST_COORDINATES_EVERY_PAINT_EVENT
|
|
bool RubberbandDrawable::eventFilter( QObject*, QEvent * e )
|
|
{
|
|
if (e)
|
|
{
|
|
if (e->type() == QEvent::Paint)
|
|
{
|
|
/* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
|
* Sometimes the signals extentChanges and rectChanged of Esri Map Widget are not emitted. In this case
|
|
* the position update of handles and drawabled fails and they are drawn at wrong positions on map. As
|
|
* workaround updates coordinates at every paint event.
|
|
* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */
|
|
DEBUG_LOG(_logger) << LOGFUNCTION << " paint event";
|
|
onDo_adjustCoordinates();
|
|
}
|
|
}
|
|
return false;
|
|
} /* RubberbandDrawable::eventFilter */
|
|
#endif
|
|
|
|
void RubberbandDrawable::doConnecting()
|
|
{
|
|
if (nullptr == _mapView) return;
|
|
|
|
#ifdef ADJUST_COORDINATES_EVERY_PAINT_EVENT
|
|
_view -> installEventFilter( this );
|
|
#endif
|
|
|
|
/* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
|
* It is really important to specify the connnection type as following. Because the onDo_adjustCoordinates
|
|
* should be call as soon as possible to get smooth changes of map. The connection type is DirectConnnection here.
|
|
* The rectChanged signal is some times emitted, when the calculation of screen coordinates to map coordinates
|
|
* and vice versa has not been updated to the new map window size. In this case all calculations provides wrong
|
|
* results. Using the connection type QueuedConnection defers the call of onDo_adjustWindow.
|
|
* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */
|
|
// Check Quartz
|
|
connect( _mapView.data(), &Esri::ArcGISRuntime::MapGraphicsView::viewpointChanged,
|
|
this, &RubberbandDrawable::onDo_adjustCoordinates, Qt::ConnectionType::DirectConnection );
|
|
connect( _mapView.data(), &Esri::ArcGISRuntime::MapGraphicsView::rectChanged ,
|
|
this, &RubberbandDrawable::onDo_adjustWindow , Qt::ConnectionType::QueuedConnection );
|
|
|
|
} /* RubberbandDrawable::doConnecting */
|
|
|
|
|
|
void RubberbandDrawable::onDo_adjustCoordinates()
|
|
{
|
|
adjustCoordinates();
|
|
forceUpdateViewWidget();
|
|
} /* RubberbandDrawable::onDo_adjustCoordinates */
|
|
|
|
|
|
void RubberbandDrawable::onDo_adjustWindow( const QRectF &r )
|
|
{
|
|
adjustWindow(r);
|
|
forceUpdateViewWidget();
|
|
} /* RubberbandDrawable::onDo_adjustWindow */
|
|
|
|
|
|
void RubberbandDrawable::makeLineStyle( bool dottedLine, QPen & lineStyle )
|
|
{
|
|
lineStyle.setColor( _drawColor );
|
|
lineStyle.setWidth( int(_lineWidth) );
|
|
|
|
if (dottedLine) lineStyle.setStyle( Qt::DashDotLine );
|
|
else lineStyle.setStyle( Qt::SolidLine );
|
|
} /* DrawablePainterPathItem::makeLineStyle */
|
|
|
|
|
|
RubberbandDrawable::~RubberbandDrawable() { if (_mapView) _mapView->removeEventFilter(this); }
|
|
|
|
|
|
} } /* namespace SituationMap::RB */
|