QGIS API Documentation  3.12.1-BucureČ™ti (121cc00ff0)
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 namespace Qt3DCore
35 {
36  class QEntity;
37 }
38 
39 struct QgsChunkListEntry;
40 class QgsChunkLoader;
41 class QgsChunkQueueJob;
42 class QgsChunkQueueJobFactory;
43 
44 
46 struct QgsChunkNodeId
47 {
49  QgsChunkNodeId( int _x = -1, int _y = -1, int _z = -1 )
50  : x( _x ), y( _y ), z( _z ) {}
51 
52  int x, y, z;
53 
55  QString text() const { return QStringLiteral( "%1/%2/%3" ).arg( z ).arg( x ).arg( y ); }
56 };
57 
72 class QgsChunkNode
73 {
74  public:
76  QgsChunkNode( int tileX, int tileY, int tileZ, const QgsAABB &bbox, float error, QgsChunkNode *parent = nullptr );
77 
78  ~QgsChunkNode();
79 
98  enum State
99  {
100  Skeleton,
101  QueuedForLoad,
102  Loading,
103  Loaded,
104  QueuedForUpdate,
105  Updating,
106  };
107 
109  QgsAABB bbox() const { return mBbox; }
111  float error() const { return mError; }
113  int tileX() const { return mTileX; }
115  int tileY() const { return mTileY; }
117  int tileZ() const { return mTileZ; }
119  QgsChunkNodeId tileId() const { return QgsChunkNodeId( mTileX, mTileY, mTileZ ); }
121  QgsChunkNode *parent() const { return mParent; }
123  QgsChunkNode *const *children() const { return mChildren; }
125  State state() const { return mState; }
126 
128  QgsChunkListEntry *loaderQueueEntry() const { return mLoaderQueueEntry; }
130  QgsChunkListEntry *replacementQueueEntry() const { return mReplacementQueueEntry; }
132  QgsChunkLoader *loader() const { return mLoader; }
134  Qt3DCore::QEntity *entity() const { return mEntity; }
136  QgsChunkQueueJob *updater() const { return mUpdater; }
137 
139  bool allChildChunksResident( QTime currentTime ) const;
140 
142  void ensureAllChildrenExist();
143 
145  int level() const;
146 
148  QList<QgsChunkNode *> descendants();
149 
150  //
151  // changes of states in the state machine (see State enum)
152  //
153 
155  void setQueuedForLoad( QgsChunkListEntry *entry );
156 
158  void cancelQueuedForLoad();
159 
161  void setLoading( QgsChunkLoader *chunkLoader );
162 
164  void cancelLoading();
165 
167  void setLoaded( Qt3DCore::QEntity *mEntity );
168 
170  void unloadChunk();
171 
173  void setQueuedForUpdate( QgsChunkListEntry *entry, QgsChunkQueueJobFactory *updateJobFactory );
174 
176  void cancelQueuedForUpdate();
177 
179  void setUpdating();
180 
182  void cancelUpdating();
183 
185  void setUpdated();
186 
188  void setExactBbox( const QgsAABB &box );
189 
191  void setHasData( bool hasData ) { mHasData = hasData; }
193  bool hasData() const { return mHasData; }
194 
195  private:
196  QgsAABB mBbox;
197  float mError;
198 
199  int mTileX, mTileY, mTileZ;
200 
201  QgsChunkNode *mParent;
202  QgsChunkNode *mChildren[4];
203 
204  State mState;
205 
206  QgsChunkListEntry *mLoaderQueueEntry;
207  QgsChunkListEntry *mReplacementQueueEntry;
208 
209  QgsChunkLoader *mLoader;
210  Qt3DCore::QEntity *mEntity;
211 
212  QgsChunkQueueJobFactory *mUpdaterFactory;
213  QgsChunkQueueJob *mUpdater;
214 
215  QTime mEntityCreatedTime;
216  bool mHasData = true;
217 };
218 
220 
221 #endif // CHUNKNODE_H
3 Axis-aligned bounding box - in world coords.
Definition: qgsaabb.h:30