QGIS API Documentation 3.37.0-Master (fdefdf9c27f)
qgstiledsceneindex.cpp
Go to the documentation of this file.
1/***************************************************************************
2 qgstiledsceneindex.cpp
3 --------------------
4 begin : June 2023
5 copyright : (C) 2023 by Nyall Dawson
6 email : nyall dot dawson at gmail dot com
7 ***************************************************************************/
8
9/***************************************************************************
10 * *
11 * This program is free software; you can redistribute it and/or modify *
12 * it under the terms of the GNU General Public License as published by *
13 * the Free Software Foundation; either version 2 of the License, or *
14 * (at your option) any later version. *
15 * *
16 ***************************************************************************/
17
18#include "qgstiledsceneindex.h"
19#include "qgsfeedback.h"
20#include "qgstiledscenetile.h"
21
22//
23// QgsAbstractTiledSceneIndex
24//
25
27{
28 mContentCache.setMaxCost( 10000 );
29}
30
32
33QByteArray QgsAbstractTiledSceneIndex::retrieveContent( const QString &uri, QgsFeedback *feedback )
34{
35 QMutexLocker locker( &mCacheMutex );
36 if ( QByteArray *cachedData = mContentCache.object( uri ) )
37 {
38 return *cachedData;
39 }
40 locker.unlock();
41
42 const QByteArray res = fetchContent( uri, feedback );
43 if ( feedback && feedback->isCanceled() )
44 return QByteArray();
45
46 locker.relock();
47 mContentCache.insert( uri, new QByteArray( res ) );
48 return res;
49}
50
51//
52// QgsTiledSceneIndex
53//
54
56 : mIndex( index )
57{
58
59}
60
62
64 : mIndex( other.mIndex )
65{
66
67}
68
70{
71 if ( this == &other )
72 return *this;
73
74 mIndex = other.mIndex;
75 return *this;
76}
77
79{
80 return static_cast< bool >( mIndex.get() );
81}
82
84{
85 if ( !mIndex )
86 return QgsTiledSceneTile();
87
88 return mIndex->rootTile();
89}
90
92{
93 if ( !mIndex )
94 return QgsTiledSceneTile();
95
96 return mIndex->getTile( id );
97}
98
99long long QgsTiledSceneIndex::parentTileId( long long id ) const
100{
101 if ( !mIndex )
102 return -1;
103
104 return mIndex->parentTileId( id );
105}
106
107QVector< long long > QgsTiledSceneIndex::childTileIds( long long id ) const
108{
109 if ( !mIndex )
110 return {};
111
112 return mIndex->childTileIds( id );
113}
114
115QVector< long long > QgsTiledSceneIndex::getTiles( const QgsTiledSceneRequest &request )
116{
117 if ( !mIndex )
118 return {};
119
120 return mIndex->getTiles( request );
121}
122
124{
125 if ( !mIndex )
127
128 return mIndex->childAvailability( id );
129}
130
131bool QgsTiledSceneIndex::fetchHierarchy( long long id, QgsFeedback *feedback )
132{
133 if ( !mIndex )
134 return {};
135
136 return mIndex->fetchHierarchy( id, feedback );
137}
138
139QByteArray QgsTiledSceneIndex::retrieveContent( const QString &uri, QgsFeedback *feedback )
140{
141 if ( !mIndex )
142 return QByteArray();
143
144 return mIndex->retrieveContent( uri, feedback );
145}
146
TileChildrenAvailability
Possible availability states for a tile's children.
Definition: qgis.h:4588
@ NoChildren
Tile is known to have no children.
An abstract base class for tiled scene data provider indices.
virtual ~QgsAbstractTiledSceneIndex()
QByteArray retrieveContent(const QString &uri, QgsFeedback *feedback=nullptr)
Retrieves index content for the specified uri.
virtual QByteArray fetchContent(const QString &uri, QgsFeedback *feedback=nullptr)=0
Fetches index content for the specified uri.
Base class for feedback objects to be used for cancellation of something running in a worker thread.
Definition: qgsfeedback.h:44
bool isCanceled() const
Tells whether the operation has been canceled already.
Definition: qgsfeedback.h:53
An index for tiled scene data providers.
Qgis::TileChildrenAvailability childAvailability(long long id) const
Returns the availability for a tile's children.
QgsTiledSceneTile rootTile() const
Returns the root tile for the index.
QByteArray retrieveContent(const QString &uri, QgsFeedback *feedback=nullptr)
Retrieves index content for the specified uri.
bool fetchHierarchy(long long id, QgsFeedback *feedback=nullptr)
Populates the tile with the given id by fetching any sub datasets attached to the tile.
QVector< long long > childTileIds(long long id) const
Returns a list of the tile IDs of any children for the tile with matching id.
QgsTiledSceneIndex(QgsAbstractTiledSceneIndex *index=nullptr)
Constructor for QgsTiledSceneIndex.
QgsTiledSceneTile getTile(long long id)
Returns the tile with matching id, or an invalid tile if the matching tile is not available.
QgsTiledSceneIndex & operator=(const QgsTiledSceneIndex &other)
QVector< long long > getTiles(const QgsTiledSceneRequest &request)
Returns the list of tile IDs which match the given request.
long long parentTileId(long long id) const
Returns the tile ID of the parent tile of the tile with matching id, or -1 if the tile has no parent.
bool isValid() const
Returns true if the index is valid.
Tiled scene data request.
Represents an individual tile from a tiled scene data source.