56 if ( !symbol || ( symbol->
type() !=
"line"_L1 && symbol->
type() ==
"point"_L1 && symbol->
type() ==
"polygon"_L1 ) )
58 QgsDebugError( u
"A vector symbol is expected by the Qgs3DSymbolUtils::vectorSymbolPreviewIcon function"_s );
63 QPixmap pixmap( size * devicePixelRatio );
64 pixmap.setDevicePixelRatio( devicePixelRatio );
65 pixmap.fill( Qt::transparent );
67 QPainter painter( &pixmap );
68 painter.setRenderHint( QPainter::Antialiasing );
69 painter.setPen( Qt::NoPen );
72 painter.setBrush( QBrush( baseColor ) );
74 if ( symbol->
type() ==
"line"_L1 )
79 const int lineHeight = std::min(
static_cast<int>( lineSymbol->
width() ), size.height() - 2 * padding );
80 const int y = ( size.height() - lineHeight ) / 2;
81 painter.drawRect( padding, y, size.width() - 2 * padding, lineHeight );
83 else if ( symbol->
type() ==
"point"_L1 )
87 switch ( pointSymbol->
shape() )
92 float bottomRadius = pointSymbol->
shapeProperty( u
"bottomRadius"_s ).toFloat();
93 float topRadius = 2 * pointSymbol->
shapeProperty( u
"topRadius"_s ).toFloat();
94 float length = pointSymbol->
shapeProperty( u
"length"_s ).toFloat();
96 const float maxRadius =
static_cast<float>( size.width() ) / 2.0f -
static_cast<float>( padding );
97 const float maxLength =
static_cast<float>( size.height() ) - 2.0f *
static_cast<float>( padding );
99 bottomRadius = std::min( bottomRadius, maxRadius );
100 topRadius = std::min( topRadius, maxRadius );
101 length = std::min( length, maxLength );
103 const float centerX =
static_cast<float>( size.width() ) / 2.0f;
104 const float availableHeight =
static_cast<float>( size.height() - 2 * padding );
105 const float topY =
static_cast<float>( padding ) + ( availableHeight - length ) / 2.0f;
106 const float bottomY = topY + length;
109 const QPointF topLeft( centerX - topRadius, topY );
110 const QPointF topRight( centerX + topRadius, topY );
111 const QPointF bottomLeft( centerX - bottomRadius, bottomY );
112 const QPointF bottomRight( centerX + bottomRadius, bottomY );
114 path.moveTo( topLeft );
115 path.lineTo( bottomLeft );
116 path.lineTo( bottomRight );
117 path.lineTo( topRight );
119 painter.fillPath( path, painter.brush() );
126 const int pointSize =
static_cast<int>( pointSymbol->
shapeProperty( u
"size"_s ).toFloat() );
127 const int rectSize = std::min( std::min( pointSize, size.height() ), size.width() ) - 2 * padding;
128 const int rectX = ( size.width() - rectSize ) / 2;
129 const int rectY = ( size.height() - rectSize ) / 2;
130 painter.drawRect( rectX, rectY, rectSize, rectSize );
136 float radius = pointSymbol->
shapeProperty( u
"radius"_s ).toFloat();
137 float length = pointSymbol->
shapeProperty( u
"length"_s ).toFloat();
138 float centerX =
static_cast<float>( size.width() ) / 2.0f;
140 float maxRadius =
static_cast<float>( size.width() ) / 2.0f -
static_cast<float>( padding );
141 float maxLength =
static_cast<float>( size.height() - 2 * padding );
142 radius = std::min( radius, maxRadius );
143 length = std::min( length, maxLength );
145 float availableHeight =
static_cast<float>( size.height() - 2 * padding );
146 float topY =
static_cast<float>( padding ) + ( availableHeight - length ) / 2.0f;
147 float bottomY = topY + length;
150 QPointF topLeft( centerX - radius, topY );
151 QPointF topRight( centerX + radius, topY );
152 QPointF bottomLeft( centerX - radius, bottomY );
153 QPointF bottomRight( centerX + radius, bottomY );
155 path.moveTo( topLeft );
156 path.lineTo( bottomLeft );
157 path.lineTo( bottomRight );
158 path.lineTo( topRight );
161 painter.fillPath( path, painter.brush() );
162 painter.drawPath( path );
168 const float pointSize = 2 * pointSymbol->
shapeProperty( u
"radius"_s ).toFloat();
169 const int diameter = std::min( std::min(
static_cast<int>( pointSize ), size.width() ), size.height() ) - 2 * padding;
170 const int x = ( size.width() - diameter ) / 2;
171 const int y = ( size.height() - diameter ) / 2;
172 painter.drawEllipse( x, y, diameter, diameter );
178 float radius = pointSymbol->
shapeProperty( u
"radius"_s ).toFloat();
179 float minorRadius = pointSymbol->
shapeProperty( u
"minorRadius"_s ).toFloat();
181 float maxRadius = std::min(
static_cast<float>( size.width() ),
static_cast<float>( size.height() ) ) / 2.0f -
static_cast<float>( padding );
182 radius = std::min( radius, maxRadius );
183 minorRadius = std::min( minorRadius, radius );
186 const float centerX =
static_cast<float>( size.width() ) / 2.0f;
187 const float centerY =
static_cast<float>( size.height() ) / 2.0f;
188 painter.drawEllipse( QPointF( centerX, centerY ), radius, radius );
192 painter.setCompositionMode( QPainter::CompositionMode_Clear );
193 painter.drawEllipse( QPointF( centerX, centerY ), minorRadius, minorRadius );
202 const int shapeSize = 10;
203 const int rectSize = std::min( std::min( shapeSize, size.height() ), size.width() ) - 2 * padding;
204 const int rectX = ( size.width() - rectSize ) / 2;
205 const int rectY = ( size.height() - rectSize ) / 2;
206 painter.drawRect( rectX, rectY, rectSize, rectSize );
211 else if ( symbol->
type() ==
"polygon"_L1 )
219 painter.drawRect( padding, padding, size.width() - 2 * padding, size.height() - 2 * padding );
223 return QIcon( pixmap );