Skip to content
Permalink
Browse files

[layouts][FEATURE] Port arrow functionality to polyline item

Instead of a separate (badly behaved) item type for arrows, instead
add the arrowhead options to the much nicer polyline item.

There's still a dedicated toolbar action for creating arrows, but
all this does is create a polyline with the arrowhead enabled
by default.
  • Loading branch information
nyalldawson committed Nov 24, 2017
1 parent f76ed22 commit 6ec96d6d8e4eaf957d2a51e2184c27b40d5c9a52
@@ -118,6 +118,10 @@ class QgsLayoutItem : QgsLayoutObject, QGraphicsRectItem, QgsLayoutUndoObjectInt
UndoScaleBarMapUnitsSegment,
UndoScaleBarLabelBarSize,
UndoScaleBarBoxContentSpace,
UndoArrowStrokeWidth,
UndoArrowHeadWidth,
UndoArrowHeadFillColor,
UndoArrowHeadStrokeColor,

UndoCustomCommand,
};
@@ -180,6 +180,15 @@ Compute an euclidian distance between 2 nodes.
Update the current scene rectangle for this item.
%End


protected slots:

virtual void updateBoundingRect();
%Docstring
Called when the bounding rect of the item should recalculated. Subclasses should update
currentRectangle in their implementations.
%End

};

/************************************************************************
@@ -21,6 +21,13 @@ class QgsLayoutItemPolyline: QgsLayoutNodesItem
%End
public:

enum MarkerMode
{
NoMarker,
ArrowHead,
SvgMarker,
};

QgsLayoutItemPolyline( QgsLayout *layout );
%Docstring
Constructor for QgsLayoutItemPolyline for the specified ``layout``.
@@ -61,6 +68,124 @@ class QgsLayoutItemPolyline: QgsLayoutNodesItem
.. seealso:: symbol()
%End

MarkerMode startMarker() const;
%Docstring
Returns the start marker mode, which controls what marker is drawn at the start of the line.
.. seealso:: setStartMarker()
.. seealso:: endMarker()
:rtype: MarkerMode
%End

void setStartMarker( MarkerMode mode );
%Docstring
Sets the start marker ``mode``, which controls what marker is drawn at the start of the line.
.. seealso:: startMarker()
.. seealso:: setEndMarker()
%End

MarkerMode endMarker() const;
%Docstring
Returns the end marker mode, which controls what marker is drawn at the end of the line.
.. seealso:: setEndMarker()
.. seealso:: startMarker()
:rtype: MarkerMode
%End

void setEndMarker( MarkerMode mode );
%Docstring
Sets the end marker ``mode``, which controls what marker is drawn at the end of the line.
.. seealso:: endMarker()
.. seealso:: setStartMarker()
%End

void setArrowHeadWidth( double width );
%Docstring
Sets the ``width`` of line arrow heads in mm.
.. seealso:: arrowHeadWidth()
%End

double arrowHeadWidth() const;
%Docstring
Returns the width of line arrow heads in mm.
.. seealso:: setArrowHeadWidth()
:rtype: float
%End

void setStartSvgMarkerPath( const QString &path );
%Docstring
Sets the ``path`` to a SVG marker to draw at the start of the line.
.. seealso:: startSvgMarkerPath()
.. seealso:: setEndSvgMarkerPath()
%End

QString startSvgMarkerPath() const;
%Docstring
Returns the path the an SVG marker drawn at the start of the line.
.. seealso:: setStartSvgMarkerPath()
.. seealso:: endSvgMarkerPath
:rtype: str
%End

void setEndSvgMarkerPath( const QString &path );
%Docstring
Sets the ``path`` to a SVG marker to draw at the end of the line.
.. seealso:: endSvgMarkerPath()
.. seealso:: setStartSvgMarkerPath()
%End

QString endSvgMarkerPath() const;
%Docstring
Returns the path the an SVG marker drawn at the end of the line.
.. seealso:: setEndSvgMarkerPath()
.. seealso:: startSvgMarkerPath
:rtype: str
%End

QColor arrowHeadStrokeColor() const;
%Docstring
Returns the color used to draw the stroke around the the arrow head.
.. seealso:: arrowHeadFillColor()
.. seealso:: setArrowHeadStrokeColor()
:rtype: QColor
%End

void setArrowHeadStrokeColor( const QColor &color );
%Docstring
Sets the ``color`` used to draw the stroke around the arrow head.
.. seealso:: setArrowHeadFillColor()
.. seealso:: arrowHeadStrokeColor()
%End

QColor arrowHeadFillColor() const;
%Docstring
Returns the color used to fill the arrow head.
.. seealso:: arrowHeadStrokeColor()
.. seealso:: setArrowHeadFillColor()
:rtype: QColor
%End

void setArrowHeadFillColor( const QColor &color );
%Docstring
Sets the ``color`` used to fill the arrow head.
.. seealso:: arrowHeadFillColor()
.. seealso:: setArrowHeadStrokeColor()
%End

void setArrowHeadStrokeWidth( double width );
%Docstring
Sets the pen ``width`` in millimeters for the stroke of the arrow head
.. seealso:: arrowHeadStrokeWidth()
.. seealso:: setArrowHeadStrokeColor()
%End

double arrowHeadStrokeWidth() const;
%Docstring
Returns the pen width in millimeters for the stroke of the arrow head.
.. seealso:: setArrowHeadStrokeWidth()
.. seealso:: arrowHeadStrokeColor()
:rtype: float
%End

protected:

virtual bool _addNode( const int indexPoint, QPointF newPoint, const double radius );
@@ -73,6 +198,15 @@ class QgsLayoutItemPolyline: QgsLayoutNodesItem

virtual void _writeXmlStyle( QDomDocument &doc, QDomElement &elmt, const QgsReadWriteContext &context ) const;

virtual bool writePropertiesToElement( QDomElement &element, QDomDocument &document, const QgsReadWriteContext &context ) const;

virtual bool readPropertiesFromElement( const QDomElement &element, const QDomDocument &document, const QgsReadWriteContext &context );


protected slots:

virtual void updateBoundingRect();


};

@@ -227,6 +227,28 @@ void QgsLayoutAppUtils::registerGuiForKnownItemTypes()
return shape.release();
} ) );

// arrow
std::unique_ptr< QgsLayoutItemGuiMetadata > arrowMetadata = qgis::make_unique< QgsLayoutItemGuiMetadata>(
QgsLayoutItemRegistry::LayoutPolyline, QObject::tr( "Arrow" ), QgsApplication::getThemeIcon( QStringLiteral( "/mActionAddArrow.svg" ) ),
[ = ]( QgsLayoutItem * item )->QgsLayoutItemBaseWidget *
{
return new QgsLayoutPolylineWidget( qobject_cast< QgsLayoutItemPolyline * >( item ) );
}, createRubberBand, QString(), true );
arrowMetadata->setItemCreationFunction( []( QgsLayout * layout )->QgsLayoutItem *
{
std::unique_ptr< QgsLayoutItemPolyline > arrow = qgis::make_unique< QgsLayoutItemPolyline >( layout );
arrow->setEndMarker( QgsLayoutItemPolyline::ArrowHead );
return arrow.release();
} );
arrowMetadata->setNodeRubberBandCreationFunction( []( QgsLayoutView * )->QGraphicsPathItem*
{
std::unique_ptr< QGraphicsPathItem > band = qgis::make_unique< QGraphicsPathItem >();
band->setPen( QPen( QBrush( QColor( 227, 22, 22, 200 ) ), 0 ) );
band->setZValue( QgsLayout::ZViewTool );
return band.release();
} );
registry->addLayoutItemGuiMetadata( arrowMetadata.release() );


// node items

0 comments on commit 6ec96d6

Please sign in to comment.
You can’t perform that action at this time.