QGIS API Documentation  3.18.1-Zürich (202f1bf7e5)
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  bool operator==( const QgsChunkNodeId &other ) const
72  {
73  return d == other.d && x == other.x && y == other.y && z == other.z;
74  }
75 
76  bool operator!=( const QgsChunkNodeId &other ) const
77  {
78  return !( *this == other );
79  }
80 };
81 
97 class QgsChunkNode
98 {
99  public:
100 
102  QgsChunkNode( const QgsChunkNodeId &nodeId, const QgsAABB &bbox, float error, QgsChunkNode *parent = nullptr );
103 
104  ~QgsChunkNode();
105 
124  enum State
125  {
126  Skeleton,
127  QueuedForLoad,
128  Loading,
129  Loaded,
130  QueuedForUpdate,
131  Updating,
132  };
133 
135  QgsAABB bbox() const { return mBbox; }
137  float error() const { return mError; }
139  QgsChunkNodeId tileId() const { return mNodeId; }
141  QgsChunkNode *parent() const { return mParent; }
143  int childCount() const { return mChildCount; }
145  QgsChunkNode *const *children() const { return mChildren; }
147  State state() const { return mState; }
148 
150  QgsChunkListEntry *loaderQueueEntry() const { return mLoaderQueueEntry; }
152  QgsChunkListEntry *replacementQueueEntry() const { return mReplacementQueueEntry; }
154  QgsChunkLoader *loader() const { return mLoader; }
156  Qt3DCore::QEntity *entity() const { return mEntity; }
158  QgsChunkQueueJob *updater() const { return mUpdater; }
159 
161  bool allChildChunksResident( QTime currentTime ) const;
162 
164  void populateChildren( const QVector<QgsChunkNode *> &children );
165 
167  int level() const;
168 
170  QList<QgsChunkNode *> descendants();
171 
172  //
173  // changes of states in the state machine (see State enum)
174  //
175 
177  void setQueuedForLoad( QgsChunkListEntry *entry );
178 
180  void cancelQueuedForLoad();
181 
183  void setLoading( QgsChunkLoader *chunkLoader );
184 
186  void cancelLoading();
187 
189  void setLoaded( Qt3DCore::QEntity *mEntity );
190 
192  void unloadChunk();
193 
195  void setQueuedForUpdate( QgsChunkListEntry *entry, QgsChunkQueueJobFactory *updateJobFactory );
196 
198  void cancelQueuedForUpdate();
199 
201  void setUpdating();
202 
204  void cancelUpdating();
205 
207  void setUpdated();
208 
210  void setExactBbox( const QgsAABB &box );
211 
213  void setHasData( bool hasData ) { mHasData = hasData; }
215  bool hasData() const { return mHasData; }
216 
217  private:
218  QgsAABB mBbox;
219  float mError;
220 
221  QgsChunkNodeId mNodeId;
222 
223  QgsChunkNode *mParent;
224  QgsChunkNode *mChildren[8];
225  int mChildCount = -1;
226 
227  State mState;
228 
229  QgsChunkListEntry *mLoaderQueueEntry;
230  QgsChunkListEntry *mReplacementQueueEntry;
231 
232  QgsChunkLoader *mLoader;
233  Qt3DCore::QEntity *mEntity;
234 
235  QgsChunkQueueJobFactory *mUpdaterFactory;
236  QgsChunkQueueJob *mUpdater;
237 
238  QTime mEntityCreatedTime;
239  bool mHasData = true;
240 };
241 
243 
244 #endif // CHUNKNODE_H
3
Definition: qgsaabb.h:34
bool operator==(const QgsFeatureIterator &fi1, const QgsFeatureIterator &fi2)
bool operator!=(const QgsFeatureIterator &fi1, const QgsFeatureIterator &fi2)