Files
qt5-legatus-legacy/Lts/Viewer/SituationMap/Rubberbands/drawable_smooth_path.cpp
T
2026-08-13 18:33:10 +02:00

128 lines
3.8 KiB
C++
Executable File

/**
**
** @RDE_HEADER@
** Implementation of line drawables
** $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 .........:
**
** 06.08.2015, JT : First edition for use with Qt5
**
** -----------------------------------------------------------------------------------------------
*/
#include "drawable_smooth_path.h"
#include <QPainterPath>
#include <QGraphicsPathItem>
#include <MathUtils/curve.h>
#include <MathUtils/path_rasterer.h>
namespace SituationMap { namespace RB
{
DrawableSmoothPath::DrawableSmoothPath(Esri::ArcGISRuntime::MapGraphicsView * map)
: DrawablePainterPath(map)
, _smoothLine( new SituationMap::MathUtils::SmoothLine() )
{
_pathRasterer = _smoothLine->createPathRaster();
} /* DrawableSmoothPath::DrawableLine */
DrawableSmoothPath::DrawableSmoothPath(Esri::ArcGISRuntime::MapGraphicsView * map, QGraphicsScene * scene)
: DrawablePainterPath(map, scene)
, _smoothLine( new SituationMap::MathUtils::SmoothLine() )
{
_pathRasterer = _smoothLine->createPathRaster();
} /* DrawableSmoothLine::DrawableLine */
DrawableSmoothPath::~DrawableSmoothPath()
{
delete _pathRasterer;
delete _smoothLine;
_pathRasterer = nullptr;
_smoothLine = nullptr;
} /* DrawableSmoothPath::~DrawableSmoothPath */
void DrawableSmoothPath::setPath( const QVector<RubberbandDrawable::RubberbandCoordinate> & vertexVector )
{
_pathCoordinates = vertexVector;
updateGraphic();
} /* DrawableSmoothPath::setPath */
void DrawableSmoothPath::updateGraphic()
{
if (_pathCoordinates.size() > 2)
{
makeLineStyle( _dottedPath, _lineStyle );
_painterPathItem -> setPen( _lineStyle );
_painterPathItem -> setVisible( _isVisible );
if (_closedLine)
{
const QColor &fillColor = transparentFillColor();
_painterPathItem -> setBrush( (fillColor.alpha() > 0) ? QBrush(fillColor) : QBrush() );
}
else _painterPathItem -> setBrush( QBrush() );
QVector<QPointF> vertexVector;
vertexVector.reserve( _pathCoordinates.size() );
for (auto vertex : qAsConst(_pathCoordinates))
{
vertex.mapToScene(_mapView);
vertexVector.append( vertex._sceneCoordinate );
}
_smoothLine -> vertexVector( vertexVector, _closedLine );
_pathRasterer -> epsilon( 2 );
_pathRasterer -> maxVertexCount( 1000 );
_pathRasterer -> rasterize( _smoothLine->minimumCurveParameter(), _smoothLine->maximumCurveParameter(), vertexVector );
QPainterPath path;
if (vertexVector.size() > 1)
{
QVector<QPointF>::const_iterator vit = vertexVector.constBegin();
path.moveTo( *vit );
for (++vit; vit != vertexVector.end(); ++vit)
{
path.lineTo( *vit );
}
if (_closedLine) path.lineTo( QPointF(path.elementAt(0)) );
}
_painterPathItem->setPath(path);
}
else _painterPathItem ->setVisible(false);
} /* DrawableSmoothPath::updateGraphic */
void DrawableSmoothPath::adjustCoordinates() { updateGraphic(); }
void DrawableSmoothPath::adjustWindow( const QRectF& ) { updateGraphic(); }
} } /* namespace SituationMap::RB */