QGIS API Documentation  3.8.0-Zanzibar (11aff65)
qgsfeature3dhandler_p.cpp
Go to the documentation of this file.
1 /***************************************************************************
2  qgsfeature3dhandler_p.cpp
3  --------------------------------------
4  Date : January 2019
5  Copyright : (C) 2019 by Martin Dobias
6  Email : wonder dot sk at gmail dot com
7  ***************************************************************************
8  * *
9  * This program is free software; you can redistribute it and/or modify *
10  * it under the terms of the GNU General Public License as published by *
11  * the Free Software Foundation; either version 2 of the License, or *
12  * (at your option) any later version. *
13  * *
14  ***************************************************************************/
15 
16 
17 #include "qgsfeature3dhandler_p.h"
18 
19 #include "qgsfeaturerequest.h"
20 #include "qgsvectorlayer.h"
21 
22 #include "qgs3dmapsettings.h"
23 #include "qgs3dutils.h"
24 
26 
27 
28 namespace Qgs3DSymbolImpl
29 {
30 
31  Qt3DCore::QEntity *entityFromHandler( QgsFeature3DHandler *handler, const Qgs3DMapSettings &map, QgsVectorLayer *layer )
32  {
33  Qgs3DRenderContext context( map );
34 
36  exprContext.setFields( layer->fields() );
37  context.setExpressionContext( exprContext );
38 
39  QSet<QString> attributeNames;
40  if ( !handler->prepare( context, attributeNames ) )
41  return nullptr;
42 
43  // build the feature request
45  req.setDestinationCrs( map.crs(), map.transformContext() );
46  req.setSubsetOfAttributes( attributeNames, layer->fields() );
47 
48  QgsFeature f;
49  QgsFeatureIterator fi = layer->getFeatures( req );
50  while ( fi.nextFeature( f ) )
51  {
52  context.expressionContext().setFeature( f );
53  handler->processFeature( f, context );
54  }
55 
56  Qt3DCore::QEntity *entity = new Qt3DCore::QEntity;
57  handler->finalize( entity, context );
58  return entity;
59  }
60 
61 }
62 
QgsFeatureRequest & setDestinationCrs(const QgsCoordinateReferenceSystem &crs, const QgsCoordinateTransformContext &context)
Sets the destination crs for feature&#39;s geometries.
Wrapper for iterator of features from vector data provider or vector layer.
QgsCoordinateReferenceSystem crs() const
Returns coordinate reference system used in the 3D scene.
QgsFeatureRequest & setSubsetOfAttributes(const QgsAttributeList &attrs)
Set a subset of attributes that will be fetched.
The feature class encapsulates a single feature including its id, geometry and a list of field/values...
Definition: qgsfeature.h:55
3 Definition of the world
QgsCoordinateTransformContext transformContext() const
Returns the coordinate transform context, which stores various information regarding which datum tran...
QgsFields fields() const FINAL
Returns the list of fields of this layer.
Expression contexts are used to encapsulate the parameters around which a QgsExpression should be eva...
This class wraps a request for features to a vector layer (or directly its vector data provider)...
static QgsExpressionContext globalProjectLayerExpressionContext(QgsVectorLayer *layer)
Returns expression context for use in preparation of 3D data of a layer.
Definition: qgs3dutils.cpp:481
QgsFeatureIterator getFeatures(const QgsFeatureRequest &request=QgsFeatureRequest()) const FINAL
Queries the layer for features specified in request.
bool nextFeature(QgsFeature &f)
Represents a vector layer which manages a vector based data sets.