QGIS API Documentation 3.99.0-Master (26c88405ac0)
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
23
25{
26 return mLayerResults.isEmpty() && mTerrainResults.isEmpty();
27}
28
30{
31 return !mLayerResults.isEmpty();
32}
33
34QList<QgsMapLayer *> QgsRayCastResult::layers() const
35{
36 QList<QgsMapLayer *> layerList { mLayerResults.keyBegin(), mLayerResults.keyEnd() };
37
38 // Remove any deleted layers, or python won't be happy
39 layerList.erase(
40 std::remove_if(
41 layerList.begin(),
42 layerList.end(),
43 [this]( QgsMapLayer *l ) { return mLayerPointers[l].isNull(); }
44 ),
45 layerList.end()
46 );
47
48 return layerList;
49}
50
51QList<QgsRayCastHit> QgsRayCastResult::layerHits( QgsMapLayer *layer ) const
52{
53 return mLayerResults.value( layer );
54}
55
57{
58 return !mTerrainResults.isEmpty();
59}
60
61QList<QgsRayCastHit> QgsRayCastResult::terrainHits() const
62{
63 return mTerrainResults;
64}
65
66QList<QgsRayCastHit> QgsRayCastResult::allHits() const
67{
68 QList<QgsRayCastHit> result { mTerrainResults.constBegin(), mTerrainResults.constEnd() };
69
70 for ( auto it = mLayerResults.constBegin(); it != mLayerResults.constEnd(); ++it )
71 {
72 result.append( { it->constBegin(), it->constEnd() } );
73 }
74
75 return result;
76}
77
78void QgsRayCastResult::addLayerHits( QgsMapLayer *layer, const QList<QgsRayCastHit> &hits )
79{
80 mLayerResults[layer].append( hits );
81 if ( !mLayerPointers.contains( layer ) )
82 {
83 mLayerPointers[layer] = layer;
84 }
85}
86
87void QgsRayCastResult::addTerrainHits( const QList<QgsRayCastHit> &hits )
88{
89 mTerrainResults.append( hits );
90}
Base class for all map layer types.
Definition qgsmaplayer.h:80
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.