Skip to content
Permalink
Browse files

use smart pointer internally and remove unnecessary code

  • Loading branch information
PeterPetrik committed Apr 20, 2018
1 parent 1efdbc5 commit c42af60dfef74b9acc28a1152094ab1cbb69b87c
@@ -70,6 +70,7 @@ IF(WITH_APIDOC)
${CMAKE_SOURCE_DIR}/src/core/layout
${CMAKE_SOURCE_DIR}/src/core/locator
${CMAKE_SOURCE_DIR}/src/core/metadata
${CMAKE_SOURCE_DIR}/src/core/mesh
${CMAKE_SOURCE_DIR}/src/core/pal
${CMAKE_SOURCE_DIR}/src/core/processing
${CMAKE_SOURCE_DIR}/src/core/providers
@@ -10,6 +10,7 @@




class QgsMeshLayer : QgsMapLayer
{
%Docstring
@@ -38,7 +38,7 @@ QgsMeshLayer::QgsMeshLayer( const QString &meshLayerPath,

QgsSymbolLayerList l1;
l1 << new QgsSimpleFillSymbolLayer( Qt::white, Qt::NoBrush, Qt::black, Qt::SolidLine, 1.0 );
mNativeMeshSymbol = new QgsFillSymbol( l1 );
mNativeMeshSymbol.reset( new QgsFillSymbol( l1 ) );


toggleTriangularMeshRendering( false );
@@ -49,16 +49,8 @@ QgsMeshLayer::QgsMeshLayer( const QString &meshLayerPath,

QgsMeshLayer::~QgsMeshLayer()
{
clearMeshes();

if ( mDataProvider )
delete mDataProvider;

if ( mNativeMeshSymbol )
delete mNativeMeshSymbol;

if ( mTriangularMeshSymbol )
delete mTriangularMeshSymbol;
}

QgsMeshDataProvider *QgsMeshLayer::dataProvider()
@@ -95,31 +87,41 @@ QString QgsMeshLayer::providerType() const
return mProviderKey;
}

QgsMesh *QgsMeshLayer::nativeMesh() SIP_SKIP {return mNativeMesh;}
QgsMesh *QgsMeshLayer::nativeMesh() SIP_SKIP
{
return mNativeMesh.get();
}

QgsTriangularMesh *QgsMeshLayer::triangularMesh() SIP_SKIP {return mTriangularMesh;}

QgsSymbol *QgsMeshLayer::nativeMeshSymbol() {return mNativeMeshSymbol;}
QgsTriangularMesh *QgsMeshLayer::triangularMesh() SIP_SKIP
{
return mTriangularMesh.get();
}

QgsSymbol *QgsMeshLayer::triangularMeshSymbol() {return mTriangularMeshSymbol;}
QgsSymbol *QgsMeshLayer::nativeMeshSymbol()
{
return mNativeMeshSymbol.get();
}

QgsSymbol *QgsMeshLayer::triangularMeshSymbol()
{
return mTriangularMeshSymbol.get();
}

void QgsMeshLayer::toggleTriangularMeshRendering( bool toggle )
{
if ( toggle && mTriangularMeshSymbol )
return;

if ( mTriangularMeshSymbol )
delete mTriangularMeshSymbol;

if ( toggle )
{
QgsSymbolLayerList l2;
l2 << new QgsSimpleFillSymbolLayer( Qt::white, Qt::NoBrush, Qt::red, Qt::SolidLine, 0.26 );
mTriangularMeshSymbol = new QgsFillSymbol( l2 );
mTriangularMeshSymbol.reset( new QgsFillSymbol( l2 ) );
}
else
{
mTriangularMeshSymbol = nullptr;
mTriangularMeshSymbol.reset();
}
triggerRepaint();
}
@@ -128,7 +130,7 @@ void QgsMeshLayer::fillNativeMesh()
{
Q_ASSERT( !mNativeMesh );

mNativeMesh = new QgsMesh();
mNativeMesh.reset( new QgsMesh() );

if ( !( dataProvider() && dataProvider()->isValid() ) )
return;
@@ -150,13 +152,14 @@ QgsMapLayerRenderer *QgsMeshLayer::createMapRenderer( QgsRenderContext &renderer
{
if ( !mNativeMesh )
{
// lazy loading of mesh data
fillNativeMesh();
}

if ( !mTriangularMesh )
mTriangularMesh = new QgsTriangularMesh();
mTriangularMesh.reset( new QgsTriangularMesh() );

triangularMesh()->update( mNativeMesh, &rendererContext );
mTriangularMesh->update( mNativeMesh.get(), &rendererContext );
return new QgsMeshLayerRenderer( this, rendererContext );
}

@@ -177,26 +180,13 @@ bool QgsMeshLayer::writeSymbology( QDomNode &node, QDomDocument &doc, QString &e
return true;
}

void QgsMeshLayer::clearMeshes()
{
if ( mTriangularMesh )
delete mTriangularMesh;

if ( mNativeMesh )
delete mNativeMesh;

}

bool QgsMeshLayer::setDataProvider( QString const &provider )
{
clearMeshes();
Q_ASSERT( !mDataProvider ); //called from ctor

mProviderKey = provider;
QString dataSource = mDataSource;

if ( mDataProvider )
delete mDataProvider;

mDataProvider = qobject_cast<QgsMeshDataProvider *>( QgsProviderRegistry::instance()->createProvider( provider, dataSource ) );
if ( !mDataProvider )
{
@@ -18,6 +18,8 @@
#ifndef QGSMESHLAYER_H
#define QGSMESHLAYER_H

#include <memory>

#include "qgis_core.h"
#include "qgsmaplayer.h"
#include "qgsrendercontext.h"
@@ -152,28 +154,26 @@ class CORE_EXPORT QgsMeshLayer : public QgsMapLayer
#endif

private:
//! Clear native and triangular mesh
void clearMeshes();
void fillNativeMesh();

private:
//! Pointer to native mesh structure, used as cache for rendering
QgsMesh *mNativeMesh = nullptr;

//! Pointer to derived mesh structure
QgsTriangularMesh *mTriangularMesh = nullptr;

//! Pointer to data provider derived from the abastract base class QgsMeshDataProvider
QgsMeshDataProvider *mDataProvider = nullptr;

//! Data provider key
QString mProviderKey;

//! Pointer to native mesh structure, used as cache for rendering
std::unique_ptr<QgsMesh> mNativeMesh;

//! Pointer to derived mesh structure
std::unique_ptr<QgsTriangularMesh> mTriangularMesh;

//! rendering native mesh
QgsSymbol *mNativeMeshSymbol = nullptr;
std::unique_ptr<QgsSymbol> mNativeMeshSymbol;

//! rendering triangular mesh
QgsSymbol *mTriangularMeshSymbol = nullptr;
std::unique_ptr<QgsSymbol> mTriangularMeshSymbol;
};

#endif //QGSMESHLAYER_H
@@ -40,27 +40,15 @@ QgsMeshLayerRenderer::QgsMeshLayerRenderer( QgsMeshLayer *layer, QgsRenderContex
// make copies for symbols
if ( layer->nativeMeshSymbol() )
{
mNativeMeshSymbol = layer->nativeMeshSymbol()->clone();
mNativeMeshSymbol.reset( layer->nativeMeshSymbol()->clone() );
}

if ( layer->triangularMeshSymbol() )
{
mTriangularMeshSymbol = layer->triangularMeshSymbol()->clone();
mTriangularMeshSymbol.reset( layer->triangularMeshSymbol()->clone() );
}
}


QgsMeshLayerRenderer::~QgsMeshLayerRenderer()
{
if ( mNativeMeshSymbol )
delete mNativeMeshSymbol;

if ( mTriangularMeshSymbol )
delete mTriangularMeshSymbol;
}



bool QgsMeshLayerRenderer::render()
{
renderMesh( mNativeMeshSymbol, mNativeMesh.faces ); // native mesh
@@ -69,7 +57,7 @@ bool QgsMeshLayerRenderer::render()
return true;
}

void QgsMeshLayerRenderer::renderMesh( QgsSymbol *symbol, const QVector<QgsMeshFace> &faces )
void QgsMeshLayerRenderer::renderMesh( const std::unique_ptr<QgsSymbol> &symbol, const QVector<QgsMeshFace> &faces )
{
if ( !symbol )
return;
@@ -23,6 +23,8 @@ class QgsSymbol;

#define SIP_NO_FILE

#include <memory>

#include "qgis.h"

#include "qgsmaplayerrenderer.h"
@@ -42,11 +44,11 @@ class QgsMeshLayerRenderer : public QgsMapLayerRenderer
//! Ctor
QgsMeshLayerRenderer( QgsMeshLayer *layer, QgsRenderContext &context );

~QgsMeshLayerRenderer() override;
~QgsMeshLayerRenderer() override = default;
bool render() override;

private:
void renderMesh( QgsSymbol *symbol, const QVector<QgsMeshFace> &faces );
void renderMesh( const std::unique_ptr<QgsSymbol> &symbol, const QVector<QgsMeshFace> &faces );


protected:
@@ -57,15 +59,13 @@ class QgsMeshLayerRenderer : public QgsMapLayerRenderer
QgsTriangularMesh mTriangularMesh;

// copy from mesh layer
QgsSymbol *mNativeMeshSymbol = nullptr;
std::unique_ptr<QgsSymbol> mNativeMeshSymbol = nullptr;

// copy from mesh layer
QgsSymbol *mTriangularMeshSymbol = nullptr;
std::unique_ptr<QgsSymbol> mTriangularMeshSymbol = nullptr;

// rendering context
QgsRenderContext &mContext;


};


@@ -19,14 +19,6 @@
#include "qgsrendercontext.h"
#include "qgscoordinatetransform.h"

QgsTriangularMesh::QgsTriangularMesh( )
{
}

QgsTriangularMesh::~QgsTriangularMesh()
{
}

void QgsTriangularMesh::update( QgsMesh *nativeMesh, QgsRenderContext *context )
{
Q_ASSERT( nativeMesh );
@@ -41,7 +33,7 @@ void QgsTriangularMesh::update( QgsMesh *nativeMesh, QgsRenderContext *context )
mTriangularMesh.vertices.resize( nativeMesh->vertices.size() );
for ( int i = 0; i < nativeMesh->vertices.size(); ++i )
{
QgsMeshVertex vertex = nativeMesh->vertices[i];
const QgsMeshVertex &vertex = nativeMesh->vertices.at( i );
if ( transform.isValid() )
{
QgsPointXY mapPoint = transform.transform( QgsPointXY( vertex.x(), vertex.y() ) );
@@ -59,7 +51,7 @@ void QgsTriangularMesh::update( QgsMesh *nativeMesh, QgsRenderContext *context )
// CREATE TRIANGULAR MESH
for ( int i = 0; i < nativeMesh->faces.size(); ++i )
{
QgsMeshFace face = nativeMesh->faces[i] ;
const QgsMeshFace &face = nativeMesh->faces.at( i ) ;
if ( face.size() == 3 )
{
// triangle
@@ -45,9 +45,9 @@ class CORE_EXPORT QgsTriangularMesh
{
public:
//! Ctor
QgsTriangularMesh();
QgsTriangularMesh() = default;
//! Dtor
~QgsTriangularMesh();
~QgsTriangularMesh() = default;

/**
* Construct triangular mesh from layer's native mesh and context

0 comments on commit c42af60

Please sign in to comment.
You can’t perform that action at this time.