Skip to content
Permalink
Browse files

Encapsulate all mesh renderer stuff in one class + fix legend updates

  • Loading branch information
wonder-sk committed Aug 14, 2018
1 parent 545eb97 commit feddb3d3e6aee20f6007eb28c29fc4b4e7324369
@@ -129,66 +129,13 @@ Returns the provider type for this layer



QgsMeshRendererMeshSettings rendererNativeMeshSettings() const;
QgsMeshRendererSettings rendererSettings() const;
%Docstring
Returns renderer settings
%End

void setRendererNativeMeshSettings( const QgsMeshRendererMeshSettings &settings );
%Docstring
Sets new renderer settings, triggers repaint
%End

QgsMeshRendererMeshSettings rendererTriangularMeshSettings() const;
%Docstring
Returns renderer settings
%End

void setRendererTriangularMeshSettings( const QgsMeshRendererMeshSettings &settings );
%Docstring
Sets new renderer settings, triggers repaint
%End

QgsMeshRendererScalarSettings rendererScalarSettings() const;
%Docstring
Returns renderer settings
%End

void setRendererScalarSettings( const QgsMeshRendererScalarSettings &settings );
%Docstring
Sets new renderer settings, triggers repaint
%End

QgsMeshRendererVectorSettings rendererVectorSettings() const;
%Docstring
Returns renderer settings
%End

void setRendererVectorSettings( const QgsMeshRendererVectorSettings &settings );
%Docstring
Sets new renderer settings, triggers repaint
%End

void setActiveScalarDataset( QgsMeshDatasetIndex index = QgsMeshDatasetIndex() );
%Docstring
Sets active scalar dataset for rendering

Triggers repaint
%End
QgsMeshDatasetIndex activeScalarDataset() const;
%Docstring
Returns active scalar dataset
%End

void setActiveVectorDataset( QgsMeshDatasetIndex index = QgsMeshDatasetIndex() );
%Docstring
Sets active vector dataset for rendering.

If dataset is not vector based, do nothing. Triggers repaint
%End
QgsMeshDatasetIndex activeVectorDataset() const;
void setRendererSettings( const QgsMeshRendererSettings &settings );
%Docstring
Returns active vector dataset
Sets new renderer settings
%End

QgsMeshDatasetValue datasetValue( const QgsMeshDatasetIndex &index, const QgsPointXY &point ) const;
@@ -261,6 +261,82 @@ Sets ratio of the head length of the arrow (range 0-1)

};



class QgsMeshRendererSettings
{
%Docstring

Represents all mesh renderer settings

.. note::

The API is considered EXPERIMENTAL and can be changed without a notice

.. versionadded:: 3.4
%End

%TypeHeaderCode
#include "qgsmeshrenderersettings.h"
%End
public:

QgsMeshRendererMeshSettings nativeMeshSettings() const;
%Docstring
Returns renderer settings
%End
void setNativeMeshSettings( const QgsMeshRendererMeshSettings &settings );
%Docstring
Sets new renderer settings, triggers repaint
%End

QgsMeshRendererMeshSettings triangularMeshSettings() const;
%Docstring
Returns renderer settings
%End
void setTriangularMeshSettings( const QgsMeshRendererMeshSettings &settings );
%Docstring
Sets new renderer settings
%End

QgsMeshRendererScalarSettings scalarSettings() const;
%Docstring
Returns renderer settings
%End
void setScalarSettings( const QgsMeshRendererScalarSettings &settings );
%Docstring
Sets new renderer settings
%End

QgsMeshRendererVectorSettings vectorSettings() const;
%Docstring
Returns renderer settings
%End
void setVectorSettings( const QgsMeshRendererVectorSettings &settings );
%Docstring
Sets new renderer settings
%End

QgsMeshDatasetIndex activeScalarDataset() const;
%Docstring
Returns active scalar dataset
%End
void setActiveScalarDataset( QgsMeshDatasetIndex index = QgsMeshDatasetIndex() );
%Docstring
Sets active scalar dataset for rendering
%End

QgsMeshDatasetIndex activeVectorDataset() const;
%Docstring
Returns active vector dataset
%End
void setActiveVectorDataset( QgsMeshDatasetIndex index = QgsMeshDatasetIndex() );
%Docstring
Sets active vector dataset for rendering.
%End

};

/************************************************************************
* This file has been generated automatically from *
* *
@@ -272,9 +272,10 @@ int QgsMeshDatasetGroupTreeView::setActiveGroupFromActiveDataset()
QgsMeshDatasetIndex activeDataset;
if ( mMeshLayer )
{
activeDataset = mMeshLayer->activeScalarDataset();
const QgsMeshRendererSettings rendererSettings = mMeshLayer->rendererSettings();
activeDataset = rendererSettings.activeScalarDataset();
if ( !activeDataset.isValid() )
activeDataset = mMeshLayer->activeVectorDataset();
activeDataset = rendererSettings.activeVectorDataset();
}

// find group that contains active dataset
@@ -161,8 +161,9 @@ void QgsMeshRendererActiveDatasetWidget::syncToLayer()

if ( mMeshLayer )
{
mActiveScalarDataset = mMeshLayer->activeScalarDataset();
mActiveVectorDataset = mMeshLayer->activeVectorDataset();
const QgsMeshRendererSettings rendererSettings = mMeshLayer->rendererSettings();
mActiveScalarDataset = rendererSettings.activeScalarDataset();
mActiveVectorDataset = rendererSettings.activeVectorDataset();
}
else
{
@@ -57,11 +57,13 @@ void QgsMeshRendererMeshSettingsWidget::syncToLayer( )
if ( !mMeshLayer )
return;

const QgsMeshRendererSettings rendererSettings = mMeshLayer->rendererSettings();

QgsMeshRendererMeshSettings settings;
if ( mIsTriangularMesh )
settings = mMeshLayer->rendererTriangularMeshSettings();
settings = rendererSettings.triangularMeshSettings();
else
settings = mMeshLayer->rendererNativeMeshSettings();
settings = rendererSettings.nativeMeshSettings();

mColorWidget->setColor( settings.color() );
mLineWidthSpinBox->setValue( settings.lineWidth() );
@@ -52,9 +52,10 @@ void QgsMeshRendererScalarSettingsWidget::syncToLayer( )
if ( !mMeshLayer )
return;

if ( mMeshLayer->rendererScalarSettings().isEnabled() )
const QgsMeshRendererScalarSettings settings = mMeshLayer->rendererSettings().scalarSettings();
if ( settings.isEnabled() )
{
const QgsColorRampShader shader = mMeshLayer->rendererScalarSettings().colorRampShader();
const QgsColorRampShader shader = settings.colorRampShader();
whileBlocking( mScalarMinLineEdit )->setText( QString::number( shader.minimumValue() ) );
whileBlocking( mScalarMaxLineEdit )->setText( QString::number( shader.maximumValue() ) );
whileBlocking( mScalarColorRampShaderWidget )->setFromShader( shader );
@@ -103,7 +103,7 @@ void QgsMeshRendererVectorSettingsWidget::syncToLayer( )
if ( !mMeshLayer )
return;

QgsMeshRendererVectorSettings settings = mMeshLayer->rendererVectorSettings();
QgsMeshRendererVectorSettings settings = mMeshLayer->rendererSettings().vectorSettings();

// basic
mColorWidget->setColor( settings.color() );
@@ -74,27 +74,30 @@ void QgsRendererMeshPropertiesWidget::apply()
bool meshRenderingIsEnabled = mNativeMeshGroup->isChecked();
QgsMeshRendererMeshSettings meshSettings = mNativeMeshSettingsWidget->settings();
meshSettings.setEnabled( meshRenderingIsEnabled );
whileBlocking( mMeshLayer )->setRendererNativeMeshSettings( meshSettings );

// TRIANGULAR MESH
bool triangularMeshRenderingIsEnabled = mTriangularMeshGroup->isChecked();
QgsMeshRendererMeshSettings triangularMeshSettings = mTriangularMeshSettingsWidget->settings();
triangularMeshSettings.setEnabled( triangularMeshRenderingIsEnabled );
whileBlocking( mMeshLayer )->setRendererTriangularMeshSettings( triangularMeshSettings );

// SCALAR
const QgsMeshDatasetIndex activeScalarDatasetIndex = mMeshRendererActiveDatasetWidget->activeScalarDataset();
whileBlocking( mMeshLayer )->setActiveScalarDataset( activeScalarDatasetIndex );
QgsMeshRendererScalarSettings scalarSettings = mMeshRendererScalarSettingsWidget->settings();
scalarSettings.setEnabled( mContoursGroupBox->isChecked() );
whileBlocking( mMeshLayer )->setRendererScalarSettings( scalarSettings );

// VECTOR
const QgsMeshDatasetIndex activeVectorDatasetIndex = mMeshRendererActiveDatasetWidget->activeVectorDataset();
whileBlocking( mMeshLayer )->setActiveVectorDataset( activeVectorDatasetIndex );
QgsMeshRendererVectorSettings vectorSettings = mMeshRendererVectorSettingsWidget->settings();
vectorSettings.setEnabled( mVectorsGroupBox->isChecked() );
whileBlocking( mMeshLayer )->setRendererVectorSettings( vectorSettings );

QgsMeshRendererSettings settings;
settings.setNativeMeshSettings( meshSettings );
settings.setTriangularMeshSettings( triangularMeshSettings );
settings.setScalarSettings( scalarSettings );
settings.setVectorSettings( vectorSettings );
settings.setActiveScalarDataset( activeScalarDatasetIndex );
settings.setActiveVectorDataset( activeVectorDatasetIndex );
mMeshLayer->setRendererSettings( settings );

mMeshLayer->triggerRepaint();
}
@@ -110,8 +113,8 @@ void QgsRendererMeshPropertiesWidget::syncToLayer()
mTriangularMeshSettingsWidget->syncToLayer();
mMeshRendererVectorSettingsWidget->syncToLayer();

mContoursGroupBox->setChecked( mMeshLayer->rendererScalarSettings().isEnabled() );
mVectorsGroupBox->setChecked( mMeshLayer->rendererVectorSettings().isEnabled() );
mContoursGroupBox->setChecked( mMeshLayer->rendererSettings().scalarSettings().isEnabled() );
mVectorsGroupBox->setChecked( mMeshLayer->rendererSettings().vectorSettings().isEnabled() );

enableVectorRenderingTab( mMeshRendererActiveDatasetWidget->activeVectorDataset() );
}
@@ -45,7 +45,9 @@ QgsMeshLayer::QgsMeshLayer( const QString &meshLayerPath,
setLegend( QgsMapLayerLegend::defaultMeshLegend( this ) );

// show at least the mesh by default so we render something
mRendererNativeMeshSettings.setEnabled( true );
QgsMeshRendererMeshSettings meshSettings;
meshSettings.setEnabled( true );
mRendererSettings.setNativeMeshSettings( meshSettings );

} // QgsMeshLayer ctor

@@ -101,97 +103,18 @@ QgsTriangularMesh *QgsMeshLayer::triangularMesh() SIP_SKIP
return mTriangularMesh.get();
}


QgsMeshRendererMeshSettings QgsMeshLayer::rendererNativeMeshSettings() const
{
return mRendererNativeMeshSettings;
}

void QgsMeshLayer::setRendererNativeMeshSettings( const QgsMeshRendererMeshSettings &settings )
{
mRendererNativeMeshSettings = settings;
emit rendererChanged();
triggerRepaint();
}

QgsMeshRendererMeshSettings QgsMeshLayer::rendererTriangularMeshSettings() const
{
return mRendererTriangularMeshSettings;
}

void QgsMeshLayer::setRendererTriangularMeshSettings( const QgsMeshRendererMeshSettings &settings )
{
mRendererTriangularMeshSettings = settings;
emit rendererChanged();
triggerRepaint();
}

QgsMeshRendererScalarSettings QgsMeshLayer::rendererScalarSettings() const
{
return mRendererScalarSettings;
}

void QgsMeshLayer::setRendererScalarSettings( const QgsMeshRendererScalarSettings &settings )
{
mRendererScalarSettings = settings;
emit rendererChanged();
triggerRepaint();
}


QgsMeshRendererVectorSettings QgsMeshLayer::rendererVectorSettings() const
QgsMeshRendererSettings QgsMeshLayer::rendererSettings() const
{
return mRendererVectorSettings;
return mRendererSettings;
}

void QgsMeshLayer::setRendererVectorSettings( const QgsMeshRendererVectorSettings &settings )
void QgsMeshLayer::setRendererSettings( const QgsMeshRendererSettings &settings )
{
mRendererVectorSettings = settings;
mRendererSettings = settings;
emit rendererChanged();
triggerRepaint();
}


void QgsMeshLayer::setActiveScalarDataset( QgsMeshDatasetIndex index )
{
if ( index == mActiveScalarDataset )
return;

if ( index.isValid() )
mActiveScalarDataset = index;
else
mActiveScalarDataset = QgsMeshDatasetIndex();

emit rendererChanged();
triggerRepaint();

emit activeScalarDatasetChanged( mActiveScalarDataset );
}

void QgsMeshLayer::setActiveVectorDataset( QgsMeshDatasetIndex index )
{
if ( index == mActiveVectorDataset )
return;

if ( !index.isValid() )
{
mActiveVectorDataset = QgsMeshDatasetIndex();
}
else
{
const QgsMeshDatasetGroupMetadata metadata = dataProvider()->datasetGroupMetadata( index );
if ( metadata.isVector() )
mActiveVectorDataset = index;
else
mActiveVectorDataset = QgsMeshDatasetIndex();
}

emit rendererChanged();
triggerRepaint();

emit activeVectorDatasetChanged( mActiveVectorDataset );
}

QgsMeshDatasetValue QgsMeshLayer::datasetValue( const QgsMeshDatasetIndex &index, const QgsPointXY &point ) const
{
QgsMeshDatasetValue value;

0 comments on commit feddb3d

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