QGIS API Documentation  3.21.0-Master (5b68dc587e)
qgschunknode_p.h
Go to the documentation of this file.
1 /***************************************************************************
2  qgschunknode_p.h
3  --------------------------------------
4  Date : July 2017
5  Copyright : (C) 2017 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 #ifndef QGSCHUNKNODE_P_H
17 #define QGSCHUNKNODE_P_H
18 
20 
21 //
22 // W A R N I N G
23 // -------------
24 //
25 // This file is not part of the QGIS API. It exists purely as an
26 // implementation detail. This header file may change from version to
27 // version without notice, or even be removed.
28 //
29 
30 #include "qgsaabb.h"
31 
32 #include <QTime>
33 
34 #define SIP_NO_FILE
35 
36 namespace Qt3DCore
37 {
38  class QEntity;
39 }
40 
41 struct QgsChunkListEntry;
42 class QgsChunkLoader;
43 class QgsChunkQueueJob;
44 class QgsChunkQueueJobFactory;
45 
46 
54 struct QgsChunkNodeId
55 {
57  QgsChunkNodeId( int _d = -1, int _x = -1, int _y = -1, int _z = -1 )
58  : d( _d ), x( _x ), y( _y ), z( _z ) {}
59 
60  int d, x, y, z;
61 
63  QString text() const
64  {
65  if ( z == -1 )
66  return QStringLiteral( "%1/%2/%3" ).arg( d ).arg( x ).arg( y ); // quadtree
67  else
68  return QStringLiteral( "%1/%2/%3/%4" ).arg( d ).arg( x ).arg( y ).arg( z ); // octree
69  }
70 
71  // TODO c++20 - replace with = default
72  bool operator==( const QgsChunkNodeId &other ) const
73  {
74  return d == other.d && x == other.x && y == other.y && z == other.z;
75  }
76 
77  bool operator!=( const QgsChunkNodeId &other ) const
78  {
79  return !( *this == other );
80  }
81 };
82 
98 class QgsChunkNode
99 {
100  public:
101 
103  QgsChunkNode( const QgsChunkNodeId &nodeId, const QgsAABB &bbox, float error, QgsChunkNode *parent = nullptr );
104 
105  ~QgsChunkNode();
106 
125  enum State
126  {
127  Skeleton,
128  QueuedForLoad,
129  Loading,
130  Loaded,
131  QueuedForUpdate,
132  Updating,
133  };
134 
136  QgsAABB bbox() const { return mBbox; }
138  float error() const { return mError; }
140  QgsChunkNodeId tileId() const { return mNodeId; }
142  QgsChunkNode *parent() const { return mParent; }
144  int childCount() const { return mChildCount; }
146  QgsChunkNode *const *children() const { return mChildren; }
148  State state() const { return mState; }
149 
151  QgsChunkListEntry *loaderQueueEntry() const { return mLoaderQueueEntry; }
153  QgsChunkListEntry *replacementQueueEntry() const { return mReplacementQueueEntry; }
155  QgsChunkLoader *loader() const { return mLoader; }
157  Qt3DCore::QEntity *entity() const { return mEntity; }
159  QgsChunkQueueJob *updater() const { return mUpdater; }
160 
162  bool allChildChunksResident( QTime currentTime ) const;
163 
165  void populateChildren( const QVector<QgsChunkNode *> &children );
166 
168  int level() const;
169 
171  QList<QgsChunkNode *> descendants();
172 
173  //
174  // changes of states in the state machine (see State enum)
175  //
176 
178  void setQueuedForLoad( QgsChunkListEntry *entry );
179 
181  void cancelQueuedForLoad();
182 
184  void setLoading( QgsChunkLoader *chunkLoader );
185 
187  void cancelLoading();
188 
190  void setLoaded( Qt3DCore::QEntity *mEntity );
191 
193  void unloadChunk();
194 
196  void setQueuedForUpdate( QgsChunkListEntry *entry, QgsChunkQueueJobFactory *updateJobFactory );
197 
199  void cancelQueuedForUpdate();
200 
202  void setUpdating();
203 
205  void cancelUpdating();
206 
208  void setUpdated();
209 
211  void setExactBbox( const QgsAABB &box );
212 
214  void setHasData( bool hasData ) { mHasData = hasData; }
216  bool hasData() const { return mHasData; }
217 
218  private:
219  QgsAABB mBbox;
220  float mError;
221 
222  QgsChunkNodeId mNodeId;
223 
224  QgsChunkNode *mParent;
225  QgsChunkNode *mChildren[8];
226  int mChildCount = -1;
227 
228  State mState;
229 
230  QgsChunkListEntry *mLoaderQueueEntry;
231  QgsChunkListEntry *mReplacementQueueEntry;
232 
233  QgsChunkLoader *mLoader;
234  Qt3DCore::QEntity *mEntity;
235 
236  QgsChunkQueueJobFactory *mUpdaterFactory;
237  QgsChunkQueueJob *mUpdater;
238 
239  QTime mEntityCreatedTime;
240  bool mHasData = true;
241 };
242 
244 
245 #endif // CHUNKNODE_H
3
Definition: qgsaabb.h:34
bool operator==(const QgsFeatureIterator &fi1, const QgsFeatureIterator &fi2)
bool operator!=(const QgsFeatureIterator &fi1, const QgsFeatureIterator &fi2)