QGIS API Documentation 4.1.0-Master (60fea48833c)
Loading...
Searching...
No Matches
qgsraycastresult.cpp
Go to the documentation of this file.
1/***************************************************************************
2 qgsraycastresult.cpp
3 ---------------------
4 begin : September 2025
5 copyright : (C) 2025 by Stefanos Natsis
6 email : uclaros 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#include "qgsraycastresult.h"
17
18#include "qgsmaplayer.h"
19
22
24{
25 return mLayerResults.isEmpty() && mTerrainResults.isEmpty();
26}
27
29{
30 return !mLayerResults.isEmpty();
31}
32
33QList<QgsMapLayer *> QgsRayCastResult::layers() const
34{
35 QList<QgsMapLayer *> layerList { mLayerResults.keyBegin(), mLayerResults.keyEnd() };
36
37 // Remove any deleted layers, or python won't be happy
38 layerList.erase( std::remove_if( layerList.begin(), layerList.end(), [this]( QgsMapLayer *l ) { return mLayerPointers[l].isNull(); } ), layerList.end() );
39
40 return layerList;
41}
42
43QList<QgsRayCastHit> QgsRayCastResult::layerHits( QgsMapLayer *layer ) const
44{
45 return mLayerResults.value( layer );
46}
47
49{
50 return !mTerrainResults.isEmpty();
51}
52
53QList<QgsRayCastHit> QgsRayCastResult::terrainHits() const
54{
55 return mTerrainResults;
56}
57
58QList<QgsRayCastHit> QgsRayCastResult::allHits() const
59{
60 QList<QgsRayCastHit> result { mTerrainResults.constBegin(), mTerrainResults.constEnd() };
61
62 for ( auto it = mLayerResults.constBegin(); it != mLayerResults.constEnd(); ++it )
63 {
64 result.append( { it->constBegin(), it->constEnd() } );
65 }
66
67 return result;
68}
69
70void QgsRayCastResult::addLayerHits( QgsMapLayer *layer, const QList<QgsRayCastHit> &hits )
71{
72 mLayerResults[layer].append( hits );
73 if ( !mLayerPointers.contains( layer ) )
74 {
75 mLayerPointers[layer] = layer;
76 }
77}
78
79void QgsRayCastResult::addTerrainHits( const QList<QgsRayCastHit> &hits )
80{
81 mTerrainResults.append( hits );
82}
Base class for all map layer types.
Definition qgsmaplayer.h:83
QList< QgsRayCastHit > terrainHits() const
Returns all terrain intersection hits.
QList< QgsRayCastHit > layerHits(QgsMapLayer *layer) const
Returns all hits from entities of the specific layer.
bool hasTerrainHits() const
Returns true is the ray intersected the terrain.
bool hasLayerHits() const
Returns true is ray hit at least one entity from a layer.
QList< QgsMapLayer * > layers() const
Returns pointers to the map layers of entities that were intersected by the ray.
QList< QgsRayCastHit > allHits() const
Returns all the hits from both layer and terrain intersections.
void addLayerHits(QgsMapLayer *layer, const QList< QgsRayCastHit > &hits)
Adds all hits from layer to the result.
void addTerrainHits(const QList< QgsRayCastHit > &hits)
Adds all terrain hits to the result.
bool isEmpty() const
Returns true is ray did not intersect any layer or terrain entity.