Skip to content

Commit

Permalink
adjust to use the new QgsPointCloudIndex class
Browse files Browse the repository at this point in the history
  • Loading branch information
uclaros committed Jan 7, 2025
1 parent d8a2f42 commit 2be85ec
Show file tree
Hide file tree
Showing 13 changed files with 179 additions and 88 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -269,6 +269,13 @@ Returns all attributes that are stored in the file



bool updateNodeData( const QHash<QgsPointCloudNodeId, QByteArray> &data );
%Docstring
Tries to update the data for the specified nodes.

:return: ``True`` on success, otherwise ``False``
%End

QgsRectangle extent() const;
%Docstring
Returns extent of the data
Expand Down Expand Up @@ -346,6 +353,18 @@ Returns extra metadata that's not accessible through the other methods
in an implementation-specific dynamic structure.

.. seealso:: :py:func:`QgsAbstractPointCloudIndex.extraMetadata`
%End

bool commitChanges();
%Docstring
Tries to store pending changes to the data provider.

:return: ``True`` on success, otherwise ``False``
%End

bool isModified() const;
%Docstring
Returns ``True`` if there are uncommitted changes, ``False`` otherwise
%End

};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -274,6 +274,14 @@ Stops a current editing operation and discards any uncommitted edits.
%End


QgsPointCloudIndex index() const;
%Docstring
Returns the point cloud index associated with the layer.
If the layer is editable, its :py:class:`QgsPointCloudEditingIndex` is returned,
otherwise the index is fetched from the data provider.

.. versionadded:: 3.42
%End


signals:
Expand Down
19 changes: 19 additions & 0 deletions python/core/auto_generated/pointcloud/qgspointcloudindex.sip.in
Original file line number Diff line number Diff line change
Expand Up @@ -269,6 +269,13 @@ Returns all attributes that are stored in the file



bool updateNodeData( const QHash<QgsPointCloudNodeId, QByteArray> &data );
%Docstring
Tries to update the data for the specified nodes.

:return: ``True`` on success, otherwise ``False``
%End

QgsRectangle extent() const;
%Docstring
Returns extent of the data
Expand Down Expand Up @@ -346,6 +353,18 @@ Returns extra metadata that's not accessible through the other methods
in an implementation-specific dynamic structure.

.. seealso:: :py:func:`QgsAbstractPointCloudIndex.extraMetadata`
%End

bool commitChanges();
%Docstring
Tries to store pending changes to the data provider.

:return: ``True`` on success, otherwise ``False``
%End

bool isModified() const;
%Docstring
Returns ``True`` if there are uncommitted changes, ``False`` otherwise
%End

};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -274,6 +274,14 @@ Stops a current editing operation and discards any uncommitted edits.
%End


QgsPointCloudIndex index() const;
%Docstring
Returns the point cloud index associated with the layer.
If the layer is editable, its :py:class:`QgsPointCloudEditingIndex` is returned,
otherwise the index is fetched from the data provider.

.. versionadded:: 3.42
%End


signals:
Expand Down
48 changes: 24 additions & 24 deletions src/core/pointcloud/qgspointcloudeditingindex.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,26 +20,26 @@


QgsPointCloudEditingIndex::QgsPointCloudEditingIndex( QgsPointCloudLayer *layer )
: mIndex( layer ? layer->index() : nullptr )
: mIndex( layer ? layer->index() : QgsPointCloudIndex() )
{
if ( !layer ||
!layer->dataProvider() ||
!layer->dataProvider()->hasValidIndex() ||
!( layer->dataProvider()->capabilities() & QgsPointCloudDataProvider::Capability::ChangeAttributeValues ) )
return;

mAttributes = mIndex->attributes();
mScale = mIndex->scale();
mOffset = mIndex->offset();
mExtent = mIndex->extent();
mZMin = mIndex->zMin();
mZMax = mIndex->zMax();
mRootBounds = mIndex->rootNodeBounds();
mSpan = mIndex->span();
mAttributes = mIndex.attributes();
mScale = mIndex.scale();
mOffset = mIndex.offset();
mExtent = mIndex.extent();
mZMin = mIndex.zMin();
mZMax = mIndex.zMax();
mRootBounds = mIndex.rootNodeBounds();
mSpan = mIndex.span();
mIsValid = true;
}

std::unique_ptr<QgsPointCloudIndex> QgsPointCloudEditingIndex::clone() const
std::unique_ptr<QgsAbstractPointCloudIndex> QgsPointCloudEditingIndex::clone() const
{
return nullptr;
}
Expand All @@ -51,59 +51,59 @@ void QgsPointCloudEditingIndex::load( const QString & )

bool QgsPointCloudEditingIndex::isValid() const
{
return mIsValid && mIndex->isValid();
return mIsValid && mIndex.isValid();
}

QgsPointCloudIndex::AccessType QgsPointCloudEditingIndex::accessType() const
Qgis::PointCloudAccessType QgsPointCloudEditingIndex::accessType() const
{
return mIndex->accessType();
return mIndex.accessType();
}

QgsCoordinateReferenceSystem QgsPointCloudEditingIndex::crs() const
{
return mIndex->crs();
return mIndex.crs();
}

qint64 QgsPointCloudEditingIndex::pointCount() const
{
return mIndex->pointCount();
return mIndex.pointCount();
}

QVariantMap QgsPointCloudEditingIndex::originalMetadata() const
{
return mIndex->originalMetadata();
return mIndex.originalMetadata();
}

bool QgsPointCloudEditingIndex::hasNode( const QgsPointCloudNodeId &n ) const
{
return mIndex->hasNode( n );
return mIndex.hasNode( n );
}

QgsPointCloudNode QgsPointCloudEditingIndex::getNode( const QgsPointCloudNodeId &id ) const
{
return mIndex->getNode( id );
return mIndex.getNode( id );
}

std::unique_ptr< QgsPointCloudBlock > QgsPointCloudEditingIndex::nodeData( const QgsPointCloudNodeId &n, const QgsPointCloudRequest &request )
{
if ( mEditedNodeData.contains( n ) )
{
const QByteArray data = mEditedNodeData.value( n );
int nPoints = data.size() / mIndex->attributes().pointRecordSize();
int nPoints = data.size() / mIndex.attributes().pointRecordSize();

const QByteArray requestedData = QgsPointCloudLayerEditUtils::dataForAttributes( mIndex->attributes(), data, request );
const QByteArray requestedData = QgsPointCloudLayerEditUtils::dataForAttributes( mIndex.attributes(), data, request );

std::unique_ptr<QgsPointCloudBlock> block = std::make_unique< QgsPointCloudBlock >(
nPoints,
request.attributes(),
requestedData,
mIndex->scale(),
mIndex->offset() );
mIndex.scale(),
mIndex.offset() );
return block;
}
else
{
return mIndex->nodeData( n, request );
return mIndex.nodeData( n, request );
}
}

Expand All @@ -118,7 +118,7 @@ bool QgsPointCloudEditingIndex::commitChanges()
if ( !isModified() )
return true;

if ( !mIndex->updateNodeData( mEditedNodeData ) )
if ( !mIndex.updateNodeData( mEditedNodeData ) )
return false;

mEditedNodeData.clear();
Expand Down
10 changes: 5 additions & 5 deletions src/core/pointcloud/qgspointcloudeditingindex.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,16 +33,16 @@ class QgsPointCloudLayer;
*
* \since QGIS 3.42
*/
class CORE_EXPORT QgsPointCloudEditingIndex : public QgsPointCloudIndex
class CORE_EXPORT QgsPointCloudEditingIndex : public QgsAbstractPointCloudIndex
{
public:
//! Ctor
explicit QgsPointCloudEditingIndex( QgsPointCloudLayer *layer );

std::unique_ptr<QgsPointCloudIndex> clone() const override;
std::unique_ptr<QgsAbstractPointCloudIndex> clone() const override;
void load( const QString &fileName ) override;
bool isValid() const override;
AccessType accessType() const override;
Qgis::PointCloudAccessType accessType() const override;
QgsCoordinateReferenceSystem crs() const override;
qint64 pointCount() const override;
QVariantMap originalMetadata() const override;
Expand All @@ -56,7 +56,7 @@ class CORE_EXPORT QgsPointCloudEditingIndex : public QgsPointCloudIndex
bool updateNodeData( const QHash<QgsPointCloudNodeId, QByteArray> &data ) override;

/**
* Try to store pending changes to the data provider.
* Tries to store pending changes to the data provider.
* \return TRUE on success, otherwise FALSE
*/
bool commitChanges();
Expand All @@ -66,7 +66,7 @@ class CORE_EXPORT QgsPointCloudEditingIndex : public QgsPointCloudIndex


private:
QgsPointCloudIndex *mIndex = nullptr;
QgsPointCloudIndex mIndex;
bool mIsValid = false;
QHash<QgsPointCloudNodeId, QByteArray> mEditedNodeData;
};
Expand Down
24 changes: 24 additions & 0 deletions src/core/pointcloud/qgspointcloudindex.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
#include "qgstiledownloadmanager.h"
#include "qgspointcloudstatistics.h"
#include "qgslogger.h"
#include "qgspointcloudeditingindex.h"

QgsPointCloudNodeId::QgsPointCloudNodeId():
mD( -1 ),
Expand Down Expand Up @@ -425,6 +426,12 @@ QgsPointCloudBlockRequest *QgsPointCloudIndex::asyncNodeData( const QgsPointClou
return mIndex->asyncNodeData( n, request );
}

bool QgsPointCloudIndex::updateNodeData( const QHash<QgsPointCloudNodeId, QByteArray> &data )
{
Q_ASSERT( mIndex );
return mIndex->updateNodeData( data );
}

QgsRectangle QgsPointCloudIndex::extent() const
{
Q_ASSERT( mIndex );
Expand Down Expand Up @@ -497,3 +504,20 @@ QVariantMap QgsPointCloudIndex::extraMetadata() const
return mIndex->extraMetadata();
}

bool QgsPointCloudIndex::commitChanges()
{
Q_ASSERT( mIndex );
if ( QgsPointCloudEditingIndex *index = dynamic_cast<QgsPointCloudEditingIndex *>( mIndex.get() ) )
return index->commitChanges();

return false;
}

bool QgsPointCloudIndex::isModified() const
{
if ( QgsPointCloudEditingIndex *index = dynamic_cast<QgsPointCloudEditingIndex *>( mIndex.get() ) )
return index->isModified();

return false;
}

37 changes: 28 additions & 9 deletions src/core/pointcloud/qgspointcloudindex.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
#include <QList>
#include <QMutex>
#include <QCache>
#include <QByteArray>

#include "qgis_core.h"
#include "qgspointcloudstatistics.h"
Expand Down Expand Up @@ -273,15 +274,6 @@ class CORE_EXPORT QgsAbstractPointCloudIndex
//! Returns object for a given node
virtual QgsPointCloudNode getNode( const QgsPointCloudNodeId &id ) const;

/**
* Tries to update the data for the specified nodes.
* Subclasses that support editing should override this to handle storing the data.
* Default implementation does nothing, returns false.
* \returns TRUE on success, otherwise FALSE
* \since QGIS 3.42
*/
virtual bool updateNodeData( const QHash<QgsPointCloudNodeId, QByteArray> &data );

//! Returns all attributes that are stored in the file
QgsPointCloudAttributeCollection attributes() const;

Expand All @@ -307,6 +299,15 @@ class CORE_EXPORT QgsAbstractPointCloudIndex
*/
virtual QgsPointCloudBlockRequest *asyncNodeData( const QgsPointCloudNodeId &n, const QgsPointCloudRequest &request ) = 0;

/**
* Tries to update the data for the specified nodes.
* Subclasses that support editing should override this to handle storing the data.
* Default implementation does nothing, returns false.
* \returns TRUE on success, otherwise FALSE
* \since QGIS 3.42
*/
virtual bool updateNodeData( const QHash<QgsPointCloudNodeId, QByteArray> &data );

//! Returns extent of the data
QgsRectangle extent() const { return mExtent; }

Expand Down Expand Up @@ -542,6 +543,13 @@ class CORE_EXPORT QgsPointCloudIndex SIP_NODEFAULTCTORS
*/
QgsPointCloudBlockRequest *asyncNodeData( const QgsPointCloudNodeId &n, const QgsPointCloudRequest &request ) SIP_SKIP;

/**
* Tries to update the data for the specified nodes.
*
* \returns TRUE on success, otherwise FALSE
*/
bool updateNodeData( const QHash<QgsPointCloudNodeId, QByteArray> &data );

/**
* Returns extent of the data
*
Expand Down Expand Up @@ -633,8 +641,19 @@ class CORE_EXPORT QgsPointCloudIndex SIP_NODEFAULTCTORS
*/
QVariantMap extraMetadata() const;

/**
* Tries to store pending changes to the data provider.
* \return TRUE on success, otherwise FALSE
*/
bool commitChanges();

//! Returns TRUE if there are uncommitted changes, FALSE otherwise
bool isModified() const;

private:
std::shared_ptr<QgsAbstractPointCloudIndex> mIndex;

friend class TestQgsPointCloudEditing;
};


Expand Down
Loading

0 comments on commit 2be85ec

Please sign in to comment.