25 #include <QStyleOptionGraphicsItem> 
   60   mPolygon = polygon.translated( -topLeft );
 
   63 void QgsLayoutNodesItem::init()
 
   67   setCacheMode( QGraphicsItem::NoCache );
 
   77   painter->setPen( Qt::NoPen );
 
   78   painter->setBrush( Qt::NoBrush );
 
   84   if ( mDrawNodes && 
layout()->renderContext().isPreviewRender() )
 
   91   return std::sqrt( std::pow( pt1.x() - pt2.x(), 2 ) + std::pow( pt1.y() - pt2.y(), 2 ) );
 
   98   const QPointF start = mapFromScene( pt );
 
   99   double minDistance = std::numeric_limits<double>::max();
 
  100   double maxDistance = ( checkArea ) ? radius : minDistance;
 
  104   for ( 
int i = 0; i != 
mPolygon.size(); i++ )
 
  107     const QPointF pt1 = 
mPolygon.at( i );
 
  113     const double coef = ( pt2.y() - pt1.y() ) / ( pt2.x() - pt1.x() );
 
  114     const double b = pt1.y() - coef * pt1.x();
 
  116     double distance = std::numeric_limits<double>::max();
 
  117     if ( std::isinf( coef ) )
 
  118       distance = std::fabs( pt1.x() - start.x() );
 
  121       const double coef2 = ( -1 / coef );
 
  122       const double b2 = start.y() - coef2 * start.x();
 
  125       if ( std::isinf( coef2 ) )
 
  127         distance = std::fabs( pt1.y() - start.y() );
 
  128         inter.setX( start.x() );
 
  129         inter.setY( pt1.y() );
 
  133         const double interx = ( b - b2 ) / ( coef2 - coef );
 
  134         const double intery = interx * coef2 + b2;
 
  135         inter.setX( interx );
 
  136         inter.setY( intery );
 
  143       const double length4 = length1 + length2;
 
  145       if ( std::fabs( length3 - length4 ) < std::numeric_limits<float>::epsilon() )
 
  149     if ( distance < minDistance && distance < maxDistance )
 
  151       minDistance = distance;
 
  158     rc = 
_addNode( idx, start, maxDistance );
 
  173   properties.insert( QStringLiteral( 
"name" ), QStringLiteral( 
"cross" ) );
 
  174   properties.insert( QStringLiteral( 
"color_border" ), QStringLiteral( 
"red" ) );
 
  176   std::unique_ptr<QgsMarkerSymbol> symbol;
 
  178   symbol->setSize( rectSize );
 
  179   symbol->setAngle( 45 );
 
  186   if ( mSelectedNode >= 0 && mSelectedNode < 
mPolygon.size() )
 
  187     drawSelectedNode( context );
 
  195   properties.insert( QStringLiteral( 
"name" ), QStringLiteral( 
"square" ) );
 
  196   properties.insert( QStringLiteral( 
"color" ), QStringLiteral( 
"0, 0, 0, 0" ) );
 
  197   properties.insert( QStringLiteral( 
"color_border" ), QStringLiteral( 
"blue" ) );
 
  198   properties.insert( QStringLiteral( 
"width_border" ), QStringLiteral( 
"4" ) );
 
  200   std::unique_ptr<QgsMarkerSymbol> symbol;
 
  202   symbol->setSize( rectSize );
 
  210                                         const bool searchInRadius,
 
  211                                         const double radius )
 const 
  213   const QPointF pt = mapFromScene( node );
 
  214   double nearestDistance = std::numeric_limits<double>::max();
 
  215   double maxDistance = ( searchInRadius ) ? radius : nearestDistance;
 
  223     if ( distance < nearestDistance && distance < maxDistance )
 
  225       nearestDistance = distance;
 
  238   if ( index >= 0 && index < 
mPolygon.size() )
 
  240     position = mapToScene( 
mPolygon.at( index ) );
 
  262   if ( index >= 0 && index < 
mPolygon.size() )
 
  264     QPointF nodeItem = mapFromScene( pt );
 
  265     mPolygon.replace( index, nodeItem );
 
  278   QDomElement styleSymbolElem = itemElem.firstChildElement( QStringLiteral( 
"symbol" ) );
 
  279   if ( !styleSymbolElem.isNull() )
 
  284   QDomNodeList nodesList = itemElem.elementsByTagName( QStringLiteral( 
"node" ) );
 
  285   for ( 
int i = 0; i < nodesList.size(); i++ )
 
  287     QDomElement nodeElem = nodesList.at( i ).toElement();
 
  289     newPt.setX( nodeElem.attribute( QStringLiteral( 
"x" ) ).toDouble() );
 
  290     newPt.setY( nodeElem.attribute( QStringLiteral( 
"y" ) ).toDouble() );
 
  312   trans = trans.scale( ratioX, ratioY );
 
  321   if ( index >= 0 && index < 
mPolygon.size() )
 
  323     mSelectedNode = index;
 
  333   const QRectF br = 
mPolygon.boundingRect();
 
  335   const QPointF topLeft = mapToScene( br.topLeft() );
 
  340   mPolygon.translate( -br.topLeft().x(), -br.topLeft().y() );
 
  350   prepareGeometryChange();
 
  360   QDomElement nodesElem = doc.createElement( QStringLiteral( 
"nodes" ) );
 
  363     QDomElement nodeElem = doc.createElement( QStringLiteral( 
"node" ) );
 
  364     nodeElem.setAttribute( QStringLiteral( 
"x" ), QString::number( pt.x() ) );
 
  365     nodeElem.setAttribute( QStringLiteral( 
"y" ), QString::number( pt.y() ) );
 
  366     nodesElem.appendChild( nodeElem );
 
  368   elem.appendChild( nodesElem );