Skip to content

Commit

Permalink
Fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
nyalldawson committed Apr 10, 2020
1 parent c4049c6 commit 3e7ebdc
Show file tree
Hide file tree
Showing 9 changed files with 14 additions and 6 deletions.
7 changes: 4 additions & 3 deletions src/core/layertree/qgslegendpatchshape.cpp
Expand Up @@ -178,15 +178,16 @@ QList<QList<QPolygonF> > QgsLegendPatchShape::defaultPatch( QgsSymbol::SymbolTyp
switch ( type )
{
case QgsSymbol::Marker:
return QList< QList< QPolygonF > >() << ( QList< QPolygonF >() << ( QPolygonF() << QPointF( size.width() / 2, size.height() / 2 ) ) );
return QList< QList< QPolygonF > >() << ( QList< QPolygonF >() << ( QPolygonF() << QPointF( static_cast< int >( size.width() ) / 2,
static_cast< int >( size.height() ) / 2 ) ) );

case QgsSymbol::Line:
// we're adding 0.5 to get rid of blurred preview:
// drawing antialiased lines of width 1 at (x,0)-(x,100) creates 2px line
return QList< QList<QPolygonF> >() << ( QList< QPolygonF >() << ( QPolygonF() << QPointF( 0, int( size.height() / 2 ) + 0.5 ) << QPointF( size.width(), int( size.height() / 2 ) + 0.5 ) ) );
return QList< QList<QPolygonF> >() << ( QList< QPolygonF >() << ( QPolygonF() << QPointF( 0, static_cast< int >( size.height() ) / 2 + 0.5 ) << QPointF( size.width(), static_cast< int >( size.height() ) / 2 + 0.5 ) ) );

case QgsSymbol::Fill:
return QList< QList<QPolygonF> >() << ( QList< QPolygonF> () << ( QRectF( QPointF( 0, 0 ), QPointF( size.width(), size.height() ) ) ) );
return QList< QList<QPolygonF> >() << ( QList< QPolygonF> () << ( QRectF( QPointF( 0, 0 ), QPointF( static_cast< int >( size.width() ), static_cast< int >( size.height() ) ) ) ) );

case QgsSymbol::Hybrid:
return QList< QList<QPolygonF> >();
Expand Down
13 changes: 10 additions & 3 deletions tests/src/python/test_qgslegendpatchshape.py
Expand Up @@ -27,7 +27,8 @@
QgsLineSymbol,
QgsMarkerSymbol,
QgsRenderChecker,
QgsReadWriteContext
QgsReadWriteContext,
QgsRenderContext
)
from qgis.PyQt.QtXml import QDomDocument, QDomElement

Expand Down Expand Up @@ -86,7 +87,9 @@ def testDefault(self):
self.assertEqual(QgsLegendPatchShape.defaultPatch(QgsSymbol.Hybrid, QSizeF(10, 10)), [])

# markers
self.assertEqual(self.polys_to_list(QgsLegendPatchShape.defaultPatch(QgsSymbol.Marker, QSizeF(1, 1))), [[[[0.5, 0.5]]]])
self.assertEqual(self.polys_to_list(QgsLegendPatchShape.defaultPatch(QgsSymbol.Marker, QSizeF(1, 1))), [[[[0.0, 0.0]]]])
self.assertEqual(self.polys_to_list(QgsLegendPatchShape.defaultPatch(QgsSymbol.Marker, QSizeF(2, 2))),
[[[[1.0, 1.0]]]])
self.assertEqual(self.polys_to_list(QgsLegendPatchShape.defaultPatch(QgsSymbol.Marker, QSizeF(10, 2))), [[[[5.0, 1.0]]]])

# lines
Expand Down Expand Up @@ -228,9 +231,13 @@ def testReadWriteXml(self):

def renderPatch(self, patch):
image = QImage(200, 200, QImage.Format_RGB32)

painter = QPainter()
painter.begin(image)

context = QgsRenderContext.fromQPainter(painter)
context.setPainter(painter)
context.setScaleFactor(96 / 25.4) # 96 DPI

try:
image.fill(QColor(0, 0, 0))

Expand Down
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 3e7ebdc

Please sign in to comment.