QGIS API Documentation  3.16.0-Hannover (43b64b13f3)
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 
48 struct QgsChunkNodeId
49 {
51  QgsChunkNodeId( int _x = -1, int _y = -1, int _z = -1 )
52  : x( _x ), y( _y ), z( _z ) {}
53 
54  int x, y, z;
55 
57  QString text() const { return QStringLiteral( "%1/%2/%3" ).arg( z ).arg( x ).arg( y ); }
58 };
59 
74 class QgsChunkNode
75 {
76  public:
78  QgsChunkNode( int tileX, int tileY, int tileZ, const QgsAABB &bbox, float error, QgsChunkNode *parent = nullptr );
79 
80  ~QgsChunkNode();
81 
100  enum State
101  {
102  Skeleton,
103  QueuedForLoad,
104  Loading,
105  Loaded,
106  QueuedForUpdate,
107  Updating,
108  };
109 
111  QgsAABB bbox() const { return mBbox; }
113  float error() const { return mError; }
115  int tileX() const { return mTileX; }
117  int tileY() const { return mTileY; }
119  int tileZ() const { return mTileZ; }
121  QgsChunkNodeId tileId() const { return QgsChunkNodeId( mTileX, mTileY, mTileZ ); }
123  QgsChunkNode *parent() const { return mParent; }
125  QgsChunkNode *const *children() const { return mChildren; }
127  State state() const { return mState; }
128 
130  QgsChunkListEntry *loaderQueueEntry() const { return mLoaderQueueEntry; }
132  QgsChunkListEntry *replacementQueueEntry() const { return mReplacementQueueEntry; }
134  QgsChunkLoader *loader() const { return mLoader; }
136  Qt3DCore::QEntity *entity() const { return mEntity; }
138  QgsChunkQueueJob *updater() const { return mUpdater; }
139 
141  bool allChildChunksResident( QTime currentTime ) const;
142 
144  void ensureAllChildrenExist();
145 
147  int level() const;
148 
150  QList<QgsChunkNode *> descendants();
151 
152  //
153  // changes of states in the state machine (see State enum)
154  //
155 
157  void setQueuedForLoad( QgsChunkListEntry *entry );
158 
160  void cancelQueuedForLoad();
161 
163  void setLoading( QgsChunkLoader *chunkLoader );
164 
166  void cancelLoading();
167 
169  void setLoaded( Qt3DCore::QEntity *mEntity );
170 
172  void unloadChunk();
173 
175  void setQueuedForUpdate( QgsChunkListEntry *entry, QgsChunkQueueJobFactory *updateJobFactory );
176 
178  void cancelQueuedForUpdate();
179 
181  void setUpdating();
182 
184  void cancelUpdating();
185 
187  void setUpdated();
188 
190  void setExactBbox( const QgsAABB &box );
191 
193  void setHasData( bool hasData ) { mHasData = hasData; }
195  bool hasData() const { return mHasData; }
196 
197  private:
198  QgsAABB mBbox;
199  float mError;
200 
201  int mTileX, mTileY, mTileZ;
202 
203  QgsChunkNode *mParent;
204  QgsChunkNode *mChildren[4];
205 
206  State mState;
207 
208  QgsChunkListEntry *mLoaderQueueEntry;
209  QgsChunkListEntry *mReplacementQueueEntry;
210 
211  QgsChunkLoader *mLoader;
212  Qt3DCore::QEntity *mEntity;
213 
214  QgsChunkQueueJobFactory *mUpdaterFactory;
215  QgsChunkQueueJob *mUpdater;
216 
217  QTime mEntityCreatedTime;
218  bool mHasData = true;
219 };
220 
222 
223 #endif // CHUNKNODE_H
qgsaabb.h
Qt3DCore
Definition: qgsabstract3drenderer.h:31
QgsAABB
3 Axis-aligned bounding box - in world coords.
Definition: qgsaabb.h:34