58 if ( !symbol || ( symbol->
type() !=
"line"_L1 && symbol->
type() ==
"point"_L1 && symbol->
type() ==
"polygon"_L1 ) )
60 QgsDebugError( u
"A vector symbol is expected by the Qgs3DSymbolUtils::vectorSymbolPreviewIcon function"_s );
65 QPixmap pixmap( size * devicePixelRatio );
66 pixmap.setDevicePixelRatio( devicePixelRatio );
67 pixmap.fill( Qt::transparent );
69 QPainter painter( &pixmap );
70 painter.setRenderHint( QPainter::Antialiasing );
71 painter.setPen( Qt::NoPen );
74 painter.setBrush( QBrush( baseColor ) );
76 if ( symbol->
type() ==
"line"_L1 )
81 const int lineHeight = std::min(
static_cast<int>( lineSymbol->
width() ), size.height() - 2 * padding );
82 const int y = ( size.height() - lineHeight ) / 2;
83 painter.drawRect( padding, y, size.width() - 2 * padding, lineHeight );
85 else if ( symbol->
type() ==
"point"_L1 )
89 switch ( pointSymbol->
shape() )
94 float bottomRadius = pointSymbol->
shapeProperty( u
"bottomRadius"_s ).toFloat();
95 float topRadius = 2 * pointSymbol->
shapeProperty( u
"topRadius"_s ).toFloat();
96 float length = pointSymbol->
shapeProperty( u
"length"_s ).toFloat();
98 const float maxRadius =
static_cast<float>( size.width() ) / 2.0f -
static_cast<float>( padding );
99 const float maxLength =
static_cast<float>( size.height() ) - 2.0f *
static_cast<float>( padding );
101 bottomRadius = std::min( bottomRadius, maxRadius );
102 topRadius = std::min( topRadius, maxRadius );
103 length = std::min( length, maxLength );
105 const float centerX =
static_cast<float>( size.width() ) / 2.0f;
106 const float availableHeight =
static_cast<float>( size.height() - 2 * padding );
107 const float topY =
static_cast<float>( padding ) + ( availableHeight - length ) / 2.0f;
108 const float bottomY = topY + length;
111 const QPointF topLeft( centerX - topRadius, topY );
112 const QPointF topRight( centerX + topRadius, topY );
113 const QPointF bottomLeft( centerX - bottomRadius, bottomY );
114 const QPointF bottomRight( centerX + bottomRadius, bottomY );
116 path.moveTo( topLeft );
117 path.lineTo( bottomLeft );
118 path.lineTo( bottomRight );
119 path.lineTo( topRight );
121 painter.fillPath( path, painter.brush() );
128 const int pointSize =
static_cast<int>( pointSymbol->
shapeProperty( u
"size"_s ).toFloat() );
129 const int rectSize = std::min( std::min( pointSize, size.height() ), size.width() ) - 2 * padding;
130 const int rectX = ( size.width() - rectSize ) / 2;
131 const int rectY = ( size.height() - rectSize ) / 2;
132 painter.drawRect( rectX, rectY, rectSize, rectSize );
138 float radius = pointSymbol->
shapeProperty( u
"radius"_s ).toFloat();
139 float length = pointSymbol->
shapeProperty( u
"length"_s ).toFloat();
140 float centerX =
static_cast<float>( size.width() ) / 2.0f;
142 float maxRadius =
static_cast<float>( size.width() ) / 2.0f -
static_cast<float>( padding );
143 float maxLength =
static_cast<float>( size.height() - 2 * padding );
144 radius = std::min( radius, maxRadius );
145 length = std::min( length, maxLength );
147 float availableHeight =
static_cast<float>( size.height() - 2 * padding );
148 float topY =
static_cast<float>( padding ) + ( availableHeight - length ) / 2.0f;
149 float bottomY = topY + length;
152 QPointF topLeft( centerX - radius, topY );
153 QPointF topRight( centerX + radius, topY );
154 QPointF bottomLeft( centerX - radius, bottomY );
155 QPointF bottomRight( centerX + radius, bottomY );
157 path.moveTo( topLeft );
158 path.lineTo( bottomLeft );
159 path.lineTo( bottomRight );
160 path.lineTo( topRight );
163 painter.fillPath( path, painter.brush() );
164 painter.drawPath( path );
170 const float pointSize = 2 * pointSymbol->
shapeProperty( u
"radius"_s ).toFloat();
171 const int diameter = std::min( std::min(
static_cast<int>( pointSize ), size.width() ), size.height() ) - 2 * padding;
172 const int x = ( size.width() - diameter ) / 2;
173 const int y = ( size.height() - diameter ) / 2;
174 painter.drawEllipse( x, y, diameter, diameter );
180 float radius = pointSymbol->
shapeProperty( u
"radius"_s ).toFloat();
181 float minorRadius = pointSymbol->
shapeProperty( u
"minorRadius"_s ).toFloat();
183 float maxRadius = std::min(
static_cast<float>( size.width() ),
static_cast<float>( size.height() ) ) / 2.0f -
static_cast<float>( padding );
184 radius = std::min( radius, maxRadius );
185 minorRadius = std::min( minorRadius, radius );
188 const float centerX =
static_cast<float>( size.width() ) / 2.0f;
189 const float centerY =
static_cast<float>( size.height() ) / 2.0f;
190 painter.drawEllipse( QPointF( centerX, centerY ), radius, radius );
194 painter.setCompositionMode( QPainter::CompositionMode_Clear );
195 painter.drawEllipse( QPointF( centerX, centerY ), minorRadius, minorRadius );
203 const int shapeSize = 10;
204 const int rectSize = std::min( std::min( shapeSize, size.height() ), size.width() ) - 2 * padding;
205 const int rectX = ( size.width() - rectSize ) / 2;
206 const int rectY = ( size.height() - rectSize ) / 2;
207 painter.drawRect( rectX, rectY, rectSize, rectSize );
212 else if ( symbol->
type() ==
"polygon"_L1 )
220 painter.drawRect( padding, padding, size.width() - 2 * padding, size.height() - 2 * padding );
224 return QIcon( pixmap );