21 #include <Qt3DRender/QMaterial>
22 #include <Qt3DRender/QParameter>
23 #include <Qt3DRender/QTexture>
94 elem.setAttribute( QStringLiteral(
"point-size" ),
mPointSize );
95 elem.setAttribute( QStringLiteral(
"render-as-triangles" ),
mRenderAsTriangles ? 1 : 0 );
106 mPointSize = elem.attribute( QStringLiteral(
"point-size" ), QStringLiteral(
"3.0" ) ).toFloat();
107 mRenderAsTriangles = elem.attribute( QStringLiteral(
"render-as-triangles" ), QStringLiteral(
"0" ) ).toInt() == 1;
108 mHorizontalTriangleFilter = elem.attribute( QStringLiteral(
"horizontal-triangle-filter" ), QStringLiteral(
"0" ) ).toInt() == 1;
109 mHorizontalFilterThreshold = elem.attribute( QStringLiteral(
"horizontal-filter-threshold" ), QStringLiteral(
"10.0" ) ).toFloat();
110 mVerticalTriangleFilter = elem.attribute( QStringLiteral(
"vertical-triangle-filter" ), QStringLiteral(
"0" ) ).toInt() == 1;
111 mVerticalFilterThreshold = elem.attribute( QStringLiteral(
"vertical-filter-threshold" ), QStringLiteral(
"10.0" ) ).toFloat();
136 return QStringLiteral(
"single-color" );
142 result->mSingleColor = mSingleColor;
166 mSingleColor = color;
172 mat->addParameter( renderingStyle );
173 Qt3DRender::QParameter *pointSizeParameter =
new Qt3DRender::QParameter(
"u_pointSize", QVariant::fromValue(
mPointSize ) );
174 mat->addParameter( pointSizeParameter );
175 Qt3DRender::QParameter *singleColorParameter =
new Qt3DRender::QParameter(
"u_singleColor", QVector3D( mSingleColor.redF(), mSingleColor.greenF(), mSingleColor.blueF() ) );
176 mat->addParameter( singleColorParameter );
190 result->mRenderingParameter = mRenderingParameter;
191 result->mColorRampShader = mColorRampShader;
192 result->mColorRampShaderMin = mColorRampShaderMin;
193 result->mColorRampShaderMax = mColorRampShaderMax;
200 return QStringLiteral(
"color-ramp" );
208 elem.setAttribute( QStringLiteral(
"rendering-parameter" ), mRenderingParameter );
209 elem.setAttribute( QStringLiteral(
"color-ramp-shader-min" ), mColorRampShaderMin );
210 elem.setAttribute( QStringLiteral(
"color-ramp-shader-max" ), mColorRampShaderMax );
211 QDomDocument doc = elem.ownerDocument();
212 const QDomElement elemColorRampShader = mColorRampShader.
writeXml( doc );
213 elem.appendChild( elemColorRampShader );
221 mRenderingParameter = elem.attribute(
"rendering-parameter", QString() );
222 mColorRampShaderMin = elem.attribute( QStringLiteral(
"color-ramp-shader-min" ), QStringLiteral(
"0.0" ) ).toDouble();
223 mColorRampShaderMax = elem.attribute( QStringLiteral(
"color-ramp-shader-max" ), QStringLiteral(
"1.0" ) ).toDouble();
224 mColorRampShader.
readXml( elem );
229 return mRenderingParameter;
234 mRenderingParameter = parameter;
239 return mColorRampShader;
249 mColorRampShaderMin = min;
250 mColorRampShaderMax = max;
256 mat->addParameter( renderingStyle );
257 Qt3DRender::QParameter *pointSizeParameter =
new Qt3DRender::QParameter(
"u_pointSize", QVariant::fromValue(
mPointSize ) );
258 mat->addParameter( pointSizeParameter );
260 Qt3DRender::QTexture1D *colorRampTexture =
nullptr;
263 colorRampTexture =
new Qt3DRender::QTexture1D( mat );
264 colorRampTexture->addTextureImage(
new QgsColorRampTexture( mColorRampShader, 1 ) );
265 colorRampTexture->setMinificationFilter( Qt3DRender::QTexture1D::Linear );
266 colorRampTexture->setMagnificationFilter( Qt3DRender::QTexture1D::Linear );
270 Qt3DRender::QParameter *colorRampTextureParameter =
new Qt3DRender::QParameter(
"u_colorRampTexture", colorRampTexture );
271 mat->addParameter( colorRampTextureParameter );
272 Qt3DRender::QParameter *colorRampCountParameter =
new Qt3DRender::QParameter(
"u_colorRampCount", mColorRampShader.
colorRampItemList().count() );
273 mat->addParameter( colorRampCountParameter );
275 Qt3DRender::QParameter *colorRampTypeParameter =
new Qt3DRender::QParameter(
"u_colorRampType", colorRampType );
276 mat->addParameter( colorRampTypeParameter );
289 return QStringLiteral(
"rgb" );
295 result->mRedAttribute = mRedAttribute;
296 result->mGreenAttribute = mGreenAttribute;
297 result->mBlueAttribute = mBlueAttribute;
299 if ( mRedContrastEnhancement )
303 if ( mGreenContrastEnhancement )
307 if ( mBlueContrastEnhancement )
321 elem.setAttribute( QStringLiteral(
"red" ), mRedAttribute );
322 elem.setAttribute( QStringLiteral(
"green" ), mGreenAttribute );
323 elem.setAttribute( QStringLiteral(
"blue" ), mBlueAttribute );
325 QDomDocument doc = elem.ownerDocument();
328 if ( mRedContrastEnhancement )
330 QDomElement redContrastElem = doc.createElement( QStringLiteral(
"redContrastEnhancement" ) );
331 mRedContrastEnhancement->writeXml( doc, redContrastElem );
332 elem.appendChild( redContrastElem );
334 if ( mGreenContrastEnhancement )
336 QDomElement greenContrastElem = doc.createElement( QStringLiteral(
"greenContrastEnhancement" ) );
337 mGreenContrastEnhancement->writeXml( doc, greenContrastElem );
338 elem.appendChild( greenContrastElem );
340 if ( mBlueContrastEnhancement )
342 QDomElement blueContrastElem = doc.createElement( QStringLiteral(
"blueContrastEnhancement" ) );
343 mBlueContrastEnhancement->writeXml( doc, blueContrastElem );
344 elem.appendChild( blueContrastElem );
354 setRedAttribute( elem.attribute( QStringLiteral(
"red" ), QStringLiteral(
"Red" ) ) );
355 setGreenAttribute( elem.attribute( QStringLiteral(
"green" ), QStringLiteral(
"Green" ) ) );
356 setBlueAttribute( elem.attribute( QStringLiteral(
"blue" ), QStringLiteral(
"Blue" ) ) );
360 const QDomElement redContrastElem = elem.firstChildElement( QStringLiteral(
"redContrastEnhancement" ) );
361 if ( !redContrastElem.isNull() )
369 const QDomElement greenContrastElem = elem.firstChildElement( QStringLiteral(
"greenContrastEnhancement" ) );
370 if ( !greenContrastElem.isNull() )
378 const QDomElement blueContrastElem = elem.firstChildElement( QStringLiteral(
"blueContrastEnhancement" ) );
379 if ( !blueContrastElem.isNull() )
390 mat->addParameter( renderingStyle );
391 Qt3DRender::QParameter *pointSizeParameter =
new Qt3DRender::QParameter(
"u_pointSize", QVariant::fromValue(
mPointSize ) );
392 mat->addParameter( pointSizeParameter );
398 return mRedAttribute;
408 return mGreenAttribute;
418 return mBlueAttribute;
428 return mRedContrastEnhancement.get();
433 mRedContrastEnhancement.reset( enhancement );
438 return mGreenContrastEnhancement.get();
443 mGreenContrastEnhancement.reset( enhancement );
448 return mBlueContrastEnhancement.get();
453 mBlueContrastEnhancement.reset( enhancement );
468 result->mRenderingParameter = mRenderingParameter;
469 result->mCategoriesList = mCategoriesList;
476 return QStringLiteral(
"classification" );
482 QDomDocument doc = elem.ownerDocument();
486 elem.setAttribute( QStringLiteral(
"rendering-parameter" ), mRenderingParameter );
489 QDomElement catsElem = doc.createElement( QStringLiteral(
"categories" ) );
492 QDomElement catElem = doc.createElement( QStringLiteral(
"category" ) );
493 catElem.setAttribute( QStringLiteral(
"value" ), QString::number( category.value() ) );
494 catElem.setAttribute( QStringLiteral(
"label" ), category.label() );
496 catElem.setAttribute( QStringLiteral(
"render" ), category.renderState() ?
"true" :
"false" );
497 catsElem.appendChild( catElem );
499 elem.appendChild( catsElem );
507 mRenderingParameter = elem.attribute(
"rendering-parameter", QString() );
509 const QDomElement catsElem = elem.firstChildElement( QStringLiteral(
"categories" ) );
510 if ( !catsElem.isNull() )
512 mCategoriesList.clear();
513 QDomElement catElem = catsElem.firstChildElement();
514 while ( !catElem.isNull() )
516 if ( catElem.tagName() == QLatin1String(
"category" ) )
518 const int value = catElem.attribute( QStringLiteral(
"value" ) ).toInt();
519 const QString label = catElem.attribute( QStringLiteral(
"label" ) );
520 const bool render = catElem.attribute( QStringLiteral(
"render" ) ) != QLatin1String(
"false" );
524 catElem = catElem.nextSiblingElement();
531 return mRenderingParameter;
541 mCategoriesList = categories;
549 if ( !category.renderState() )
550 filteredOut.push_back( category );
560 QList<QgsColorRampShader::ColorRampItem> colorRampItemList;
563 const QColor color = category.color();
565 colorRampItemList.push_back( item );
568 return colorRampShader;
576 mat->addParameter( renderingStyle );
577 Qt3DRender::QParameter *pointSizeParameter =
new Qt3DRender::QParameter(
"u_pointSize", QVariant::fromValue(
mPointSize ) );
578 mat->addParameter( pointSizeParameter );
580 Qt3DRender::QTexture1D *colorRampTexture =
nullptr;
583 colorRampTexture =
new Qt3DRender::QTexture1D( mat );
584 colorRampTexture->addTextureImage(
new QgsColorRampTexture( mColorRampShader, 1 ) );
585 colorRampTexture->setMinificationFilter( Qt3DRender::QTexture1D::Linear );
586 colorRampTexture->setMagnificationFilter( Qt3DRender::QTexture1D::Linear );
590 Qt3DRender::QParameter *colorRampTextureParameter =
new Qt3DRender::QParameter(
"u_colorRampTexture", colorRampTexture );
591 mat->addParameter( colorRampTextureParameter );
592 Qt3DRender::QParameter *colorRampCountParameter =
new Qt3DRender::QParameter(
"u_colorRampCount", mColorRampShader.
colorRampItemList().count() );
593 mat->addParameter( colorRampCountParameter );
595 Qt3DRender::QParameter *colorRampTypeParameter =
new Qt3DRender::QParameter(
"u_colorRampType", colorRampType );
596 mat->addParameter( colorRampTypeParameter );