391 lines
13 KiB
C++
Executable File
391 lines
13 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_point_handle.h"
|
|
|
|
#include <MathUtils/math_const.h>
|
|
|
|
#include <arcgis/MapGraphicsView.h>
|
|
|
|
#include <QtWidgets/QGraphicsScene>
|
|
#include <QtWidgets/QGraphicsEllipseItem>
|
|
|
|
namespace SituationMap { namespace RB
|
|
{
|
|
|
|
RubberbandPointHandle::RubberbandPointHandle( Esri::ArcGISRuntime::MapGraphicsView * mapView
|
|
, QGraphicsScene * scene
|
|
, const QPointF & scenePosition )
|
|
: RubberbandHandle(mapView,scene)
|
|
, _pointSymbol(nullptr)
|
|
, _coordinate( mapView, scenePosition )
|
|
, _sceneOffset(0,0)
|
|
, _iconPixmap(nullptr)
|
|
, _boundingRect(nullptr)
|
|
{
|
|
zBufferPlane( ZBufferPlane::PointHandle );
|
|
buildHandle( scenePosition );
|
|
} /* RubberbandPointHandle::RubberbandPointHandle */
|
|
|
|
|
|
RubberbandPointHandle::RubberbandPointHandle( Esri::ArcGISRuntime::MapGraphicsView * mapView
|
|
, QGraphicsScene * scene
|
|
, const Esri::ArcGISRuntime::Point & mapCoordinate )
|
|
: RubberbandHandle(mapView,scene)
|
|
, _pointSymbol(nullptr)
|
|
, _coordinate( mapView, mapCoordinate )
|
|
, _sceneOffset(0,0)
|
|
, _iconPixmap(nullptr)
|
|
, _boundingRect(nullptr)
|
|
{
|
|
zBufferPlane( ZBufferPlane::PointHandle );
|
|
buildHandle( _coordinate._sceneCoordinate );
|
|
} /* RubberbandPointHandle::RubberbandPointHandle */
|
|
|
|
|
|
RubberbandPointHandle::RubberbandPointHandle( Esri::ArcGISRuntime::MapGraphicsView * mapView
|
|
, QGraphicsScene * scene
|
|
, const QPointF & scenePosition
|
|
, const QPixmap & icon )
|
|
: RubberbandHandle(mapView,scene)
|
|
, _pointSymbol(nullptr)
|
|
, _coordinate( mapView, scenePosition )
|
|
, _sceneOffset(0,0)
|
|
, _iconPixmap( new QPixmap(icon) )
|
|
, _boundingRect(nullptr)
|
|
{
|
|
zBufferPlane( ZBufferPlane::PointHandle );
|
|
buildHandle( scenePosition );
|
|
} /* RubberbandPointHandle::RubberbandPointHandle */
|
|
|
|
|
|
RubberbandPointHandle::RubberbandPointHandle( Esri::ArcGISRuntime::MapGraphicsView * mapView
|
|
, QGraphicsScene * scene
|
|
, const Esri::ArcGISRuntime::Point & mapCoordinate
|
|
, const QPixmap & icon )
|
|
: RubberbandHandle(mapView,scene)
|
|
, _pointSymbol(nullptr)
|
|
, _coordinate( mapView, mapCoordinate )
|
|
, _sceneOffset(0,0)
|
|
, _iconPixmap( new QPixmap(icon) )
|
|
, _boundingRect(nullptr)
|
|
{
|
|
zBufferPlane( ZBufferPlane::PointHandle );
|
|
buildHandle( _coordinate._sceneCoordinate );
|
|
} /* RubberbandPointHandle::RubberbandPointHandle */
|
|
|
|
|
|
void RubberbandPointHandle::setIcon( const QPixmap & icon )
|
|
{
|
|
if (_iconPixmap == nullptr)
|
|
{
|
|
_iconPixmap = new QPixmap(icon);
|
|
if (_pointSymbol)
|
|
{
|
|
_scene->removeItem(_pointSymbol);
|
|
delete _pointSymbol;
|
|
_pointSymbol = nullptr;
|
|
}
|
|
buildHandle( _coordinate._sceneCoordinate );
|
|
return;
|
|
}
|
|
|
|
*_iconPixmap = icon;
|
|
|
|
QGraphicsPixmapItem * iconItem = static_cast<QGraphicsPixmapItem*>( _pointSymbol);
|
|
if (iconItem)
|
|
{
|
|
iconItem->setPixmap( *_iconPixmap );
|
|
QRectF bbox = iconItem->boundingRect();
|
|
bbox.moveCenter( _coordinate._sceneCoordinate );
|
|
if (_boundingRect) _boundingRect->setRect(bbox);
|
|
}
|
|
else buildHandle( _coordinate._sceneCoordinate );
|
|
} /* RubberbandPointHandle::setIcon */
|
|
|
|
|
|
void RubberbandPointHandle::buildHandle( const QPointF & scenePosition )
|
|
{
|
|
if (_scene != nullptr)
|
|
{
|
|
if (_iconPixmap != nullptr)
|
|
{
|
|
if (_iconPixmap->isNull())
|
|
{
|
|
delete _iconPixmap;
|
|
_iconPixmap = nullptr;
|
|
}
|
|
}
|
|
|
|
if (_iconPixmap == nullptr)
|
|
{
|
|
QGraphicsEllipseItem * kuller = new QGraphicsEllipseItem();
|
|
|
|
_pointSymbol = kuller;
|
|
|
|
if (_pointSymbol != nullptr)
|
|
{
|
|
_scene -> addItem( _pointSymbol );
|
|
|
|
kuller -> setPos( scenePosition+_sceneOffset );
|
|
kuller -> setRect( -qreal(_pickingRatio), -qreal(_pickingRatio), qreal(2*_pickingRatio), qreal(2*_pickingRatio) );
|
|
kuller -> setZValue( _zBufferValue );
|
|
|
|
kuller -> setCacheMode(QGraphicsItem::CacheMode::NoCache, QSize(_pickingRatio*2,_pickingRatio*2) );
|
|
kuller -> setFlags( QGraphicsItem::ItemIgnoresTransformations );
|
|
kuller -> setVisible( _isVisible );
|
|
}
|
|
}
|
|
else
|
|
{
|
|
QGraphicsPixmapItem * icon = new QGraphicsPixmapItem(*_iconPixmap);
|
|
|
|
_pointSymbol = icon;
|
|
|
|
if (_pointSymbol != nullptr)
|
|
{
|
|
_scene -> addItem( _pointSymbol );
|
|
|
|
qreal xOff = -(_iconPixmap->width() * 0.5);
|
|
qreal yOff = -(_iconPixmap->height() * 0.5);
|
|
|
|
icon -> setPos( scenePosition+_sceneOffset );
|
|
icon -> setZValue( _zBufferValue );
|
|
icon -> setFlags( QGraphicsItem::ItemIgnoresTransformations );
|
|
icon -> setVisible( _isVisible );
|
|
icon -> setOffset( xOff, yOff );
|
|
icon -> setShapeMode( QGraphicsPixmapItem::BoundingRectShape );
|
|
|
|
QRectF bbox = icon->boundingRect();
|
|
bbox.moveCenter( scenePosition );
|
|
|
|
_boundingRect = new QGraphicsRectItem( bbox );
|
|
_boundingRect -> setZValue(_zBufferValue-1);
|
|
_boundingRect -> setVisible( _isVisible );
|
|
|
|
_scene -> addItem( _boundingRect );
|
|
|
|
}
|
|
}
|
|
}
|
|
} /* RubberbandPointHandle::buildHandle */
|
|
|
|
|
|
RubberbandPointHandle::~RubberbandPointHandle()
|
|
{
|
|
delete _iconPixmap;
|
|
if (_scene)
|
|
{
|
|
|
|
if (nullptr != _boundingRect)
|
|
{
|
|
_scene->removeItem(_boundingRect);
|
|
delete _boundingRect;
|
|
}
|
|
|
|
if (nullptr != _pointSymbol)
|
|
{
|
|
_scene->removeItem(_pointSymbol);
|
|
delete _pointSymbol;
|
|
}
|
|
}
|
|
|
|
_pointSymbol = nullptr;
|
|
_iconPixmap = nullptr;
|
|
_boundingRect = nullptr;
|
|
|
|
} /* RubberbandHandle::~Rubberbandhandle */
|
|
|
|
|
|
QPointF RubberbandPointHandle::getRotatedSceneOffset() const
|
|
{
|
|
auto rotate = [](const QPointF & p, qreal sinA, qreal cosA) -> QPointF { return QPointF(p.x()*cosA+p.y()*sinA,p.y()*cosA-p.x()*sinA); };
|
|
|
|
qreal mapRotatePhi = _mapView->mapRotation() * MathConst::pi / 180.0;
|
|
|
|
qreal sinMap = sin(mapRotatePhi);
|
|
qreal cosMap = cos(mapRotatePhi);
|
|
|
|
return rotate( _sceneOffset, sinMap, cosMap );
|
|
} /* RubberbandPointHandle::getRotatedSceneOffset */
|
|
|
|
|
|
void RubberbandPointHandle::adjustCoordinates()
|
|
{
|
|
const QPointF & rotatedSceneOffset = getRotatedSceneOffset();
|
|
|
|
if (_iconPixmap == nullptr)
|
|
{
|
|
static_cast<QGraphicsEllipseItem*>(_pointSymbol)->setPos(_coordinate.mapToScene(_mapView)+rotatedSceneOffset);
|
|
}
|
|
else
|
|
{
|
|
QGraphicsPixmapItem * icon = static_cast<QGraphicsPixmapItem*>( _pointSymbol);
|
|
|
|
const QPointF & scenePosition = _coordinate.mapToScene(_mapView);
|
|
icon -> setPos( scenePosition+rotatedSceneOffset );
|
|
|
|
QRectF bbox = icon->boundingRect();
|
|
bbox.moveCenter( scenePosition+rotatedSceneOffset );
|
|
_boundingRect->setRect(bbox);
|
|
}
|
|
|
|
DEBUG_LOG(_logger) << LOGFUNCTION << " map-coordinate = " << QString::number(_coordinate._mapCoordinate.x(),'f',15)
|
|
<< " ; " << QString::number(_coordinate._mapCoordinate.y(),'f',15)
|
|
<< " scene-coordinate = " << _coordinate._sceneCoordinate.x() << " ; " << _coordinate._sceneCoordinate.y();
|
|
emit adjusted();
|
|
} /* RubberbandPointHandle::onDo_adjustCoordinates */
|
|
|
|
|
|
void RubberbandPointHandle::adjustWindow( const QRectF& )
|
|
{
|
|
onDo_adjustCoordinates();
|
|
} /* RubberbandPointHandle::onDo_adjustWindow */
|
|
|
|
|
|
void RubberbandPointHandle::updateGraphic()
|
|
{
|
|
if (_pointSymbol)
|
|
{
|
|
if (_pointSymbol != nullptr)
|
|
{
|
|
if (_iconPixmap == nullptr)
|
|
{
|
|
QGraphicsEllipseItem * kuller = static_cast<QGraphicsEllipseItem*>( _pointSymbol);
|
|
|
|
kuller -> setPen( QPen(_drawColor) );
|
|
|
|
QRadialGradient gradient(0, 0, _pickingRatio, 0, 0);
|
|
QColor gradientColor = (_isSelected) ? _selectionColor : _fillColor;
|
|
|
|
gradient.setColorAt( 0, gradientColor);
|
|
gradient.setColorAt( 1, QColor(gradientColor.red(), gradientColor.green(), gradientColor.blue(), 0) );
|
|
kuller -> setBrush( QBrush(gradient) );
|
|
kuller -> setVisible( _isVisible );
|
|
}
|
|
else
|
|
{
|
|
QGraphicsPixmapItem * icon = static_cast<QGraphicsPixmapItem*>( _pointSymbol);
|
|
|
|
_boundingRect -> setPen( QPen(_drawColor) );
|
|
const QColor &backColor = (_isSelected) ? _selectionColor : _fillColor;
|
|
_boundingRect -> setBrush( QBrush(backColor) );
|
|
_boundingRect -> setVisible( _isVisible );
|
|
icon -> setVisible( _isVisible );
|
|
}
|
|
}
|
|
}
|
|
} /* RubberbandPointHandle::updateGraphic */
|
|
|
|
|
|
void RubberbandPointHandle::updateCoordinate(const QPointF & scenePosition)
|
|
{
|
|
const QPointF & rotatedSceneOffset = getRotatedSceneOffset();
|
|
|
|
_coordinate.updateSceneCoordinate( _mapView, scenePosition );
|
|
|
|
if (_pointSymbol != nullptr)
|
|
{
|
|
if (_iconPixmap == nullptr)
|
|
{
|
|
QGraphicsEllipseItem * kuller = static_cast<QGraphicsEllipseItem*>( _pointSymbol);
|
|
kuller -> setPos( scenePosition+rotatedSceneOffset );
|
|
}
|
|
else
|
|
{
|
|
QGraphicsPixmapItem * icon = static_cast<QGraphicsPixmapItem*>( _pointSymbol);
|
|
icon -> setPos( scenePosition+rotatedSceneOffset );
|
|
|
|
QRectF bbox = icon->boundingRect();
|
|
bbox.moveCenter( scenePosition+rotatedSceneOffset );
|
|
|
|
_boundingRect->setRect(bbox);
|
|
}
|
|
}
|
|
} /* RubberbandPointHandle::updateCoordinate */
|
|
|
|
|
|
void RubberbandPointHandle::updateCoordinate()
|
|
{
|
|
const QPointF & rotatedSceneOffset = getRotatedSceneOffset();
|
|
|
|
if (_pointSymbol != nullptr)
|
|
{
|
|
if (_iconPixmap == nullptr)
|
|
{
|
|
QGraphicsEllipseItem * kuller = static_cast<QGraphicsEllipseItem*>( _pointSymbol);
|
|
kuller -> setPos( _coordinate._sceneCoordinate+rotatedSceneOffset );
|
|
}
|
|
else
|
|
{
|
|
QGraphicsPixmapItem * icon = static_cast<QGraphicsPixmapItem*>( _pointSymbol);
|
|
icon -> setPos( _coordinate._sceneCoordinate+rotatedSceneOffset );
|
|
|
|
QRectF bbox = icon->boundingRect();
|
|
|
|
bbox.moveCenter( _coordinate._sceneCoordinate+rotatedSceneOffset );
|
|
_boundingRect->setRect(bbox);
|
|
}
|
|
}
|
|
} /* RubberbandPointHandle::updateCoordinate */
|
|
|
|
|
|
void RubberbandPointHandle::moveCoordinate(const QPointF & sceneDelta)
|
|
{
|
|
_coordinate.updateSceneCoordinate( _mapView, _coordinate._sceneCoordinate+sceneDelta );
|
|
updateCoordinate();
|
|
} /* RubberbandPointHandle::moveCoordinate */
|
|
|
|
|
|
void RubberbandPointHandle::setCoordinate(const RubberbandHandle::RubberbandCoordinate & p)
|
|
{
|
|
_coordinate = p;
|
|
updateCoordinate();
|
|
} /* RubberbandPointHandle::setCoordinate */
|
|
|
|
|
|
RubberbandHandle::RubberbandCoordinate RubberbandPointHandle::getCoordinate() const { return _coordinate; }
|
|
|
|
QPointF RubberbandPointHandle::getPixelCoordinate() const
|
|
{
|
|
return _coordinate._sceneCoordinate;
|
|
}
|
|
|
|
|
|
bool RubberbandPointHandle::isPositionInside( const QPointF & scenePosition ) const
|
|
{
|
|
if (_pointSymbol)
|
|
{
|
|
return _pointSymbol->contains( _coordinate._sceneCoordinate+getRotatedSceneOffset() - scenePosition );
|
|
}
|
|
return false;
|
|
} /* RubberbandPointHandle::isPositionInside */
|
|
|
|
} } /* namespace SituationMap::RB */
|