Skip to content

Commit 9d0b83a

Browse files
committed
[composer] Allow removing svg markers for arrows (fix #11220)
Previous behaviour was that if the start or end marker was cleared than the old marker was drawn. This made it impossible to remove an svg marker from the start or end of the line after one had been assigned. Also fix a Qt warning caused by trying to draw markers if the marker size is set to 0.
1 parent 6c0155a commit 9d0b83a

File tree

1 file changed

+22
-14
lines changed

1 file changed

+22
-14
lines changed

src/core/composer/qgscomposerarrow.cpp

Lines changed: 22 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -242,6 +242,12 @@ void QgsComposerArrow::drawSVGMarker( QPainter* p, MarkerType type, const QStrin
242242
imageWidth *= qMin( viewScaleFactor, 10.0 );
243243
imageHeight *= qMin( viewScaleFactor, 10.0 );
244244
}
245+
if ( imageWidth <= 0 || imageHeight <= 0 )
246+
{
247+
//bad image size
248+
return;
249+
}
250+
245251
QImage markerImage( imageWidth, imageHeight, QImage::Format_ARGB32 );
246252
QColor markerBG( 255, 255, 255, 0 ); //transparent white background
247253
markerImage.fill( markerBG.rgba() );
@@ -317,32 +323,34 @@ void QgsComposerArrow::drawSVGMarker( QPainter* p, MarkerType type, const QStrin
317323
void QgsComposerArrow::setStartMarker( const QString& svgPath )
318324
{
319325
QSvgRenderer r;
326+
mStartMarkerFile = svgPath;
320327
if ( svgPath.isEmpty() || !r.load( svgPath ) )
321328
{
322-
return;
323-
// mStartArrowHeadHeight = 0;
329+
mStartArrowHeadHeight = 0;
330+
}
331+
else
332+
{
333+
//calculate mArrowHeadHeight from svg file and mArrowHeadWidth
334+
QRect viewBox = r.viewBox();
335+
mStartArrowHeadHeight = mArrowHeadWidth / viewBox.width() * viewBox.height();
324336
}
325-
mStartMarkerFile = svgPath;
326-
327-
//calculate mArrowHeadHeight from svg file and mArrowHeadWidth
328-
QRect viewBox = r.viewBox();
329-
mStartArrowHeadHeight = mArrowHeadWidth / viewBox.width() * viewBox.height();
330337
adaptItemSceneRect();
331338
}
332339

333340
void QgsComposerArrow::setEndMarker( const QString& svgPath )
334341
{
335342
QSvgRenderer r;
343+
mEndMarkerFile = svgPath;
336344
if ( svgPath.isEmpty() || !r.load( svgPath ) )
337345
{
338-
return;
339-
// mStopArrowHeadHeight = 0;
346+
mStopArrowHeadHeight = 0;
347+
}
348+
else
349+
{
350+
//calculate mArrowHeadHeight from svg file and mArrowHeadWidth
351+
QRect viewBox = r.viewBox();
352+
mStopArrowHeadHeight = mArrowHeadWidth / viewBox.width() * viewBox.height();
340353
}
341-
mEndMarkerFile = svgPath;
342-
343-
//calculate mArrowHeadHeight from svg file and mArrowHeadWidth
344-
QRect viewBox = r.viewBox();
345-
mStopArrowHeadHeight = mArrowHeadWidth / viewBox.width() * viewBox.height();
346354
adaptItemSceneRect();
347355
}
348356

0 commit comments

Comments
 (0)