Skip to content
Permalink
Browse files

Make scalar/vector rendering settings per dataset group

Until now there was just one scalar and vector configuration
for a mesh layer. It is however most useful to have different
rendering settings for each dataset group (quantity).
  • Loading branch information
wonder-sk committed Aug 14, 2018
1 parent feddb3d commit 9fc2e3e14895eaf33ecc8721231b54a5cf790e3b
@@ -392,6 +392,12 @@ Ctor
Returns the extent of the layer

:return: QgsRectangle containing the extent of the layer
%End

signals:
void datasetGroupsAdded( int count );
%Docstring
Emitted when some new dataset groups have been added
%End
};

@@ -83,12 +83,6 @@ Returns color ramp shader function
Sets color ramp shader function
%End

bool isEnabled() const;
%Docstring
Returns whether color ramp has any items assigned
%End

void setEnabled( bool enabled );
};

class QgsMeshRendererVectorSettings
@@ -109,15 +103,6 @@ Represents a mesh renderer settings for vector datasets
%End
public:

bool isEnabled() const;
%Docstring
Returns whether rendering of vectors is enabled
%End
void setEnabled( bool enabled );
%Docstring
Sets whether rendering of vectors is enabled
%End

enum ArrowScalingMethod
{

@@ -299,20 +284,20 @@ Returns renderer settings
Sets new renderer settings
%End

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

QgsMeshRendererVectorSettings vectorSettings() const;
QgsMeshRendererVectorSettings vectorSettings( int groupIndex ) const;
%Docstring
Returns renderer settings
%End
void setVectorSettings( const QgsMeshRendererVectorSettings &settings );
void setVectorSettings( int groupIndex, const QgsMeshRendererVectorSettings &settings );
%Docstring
Sets new renderer settings
%End
@@ -283,11 +283,6 @@ int QgsMeshDatasetGroupTreeView::setActiveGroupFromActiveDataset()
{
group = activeDataset.group();
}
else if ( !mGroups.empty() )
{
// not found, select first item
group = 0;
}

if ( mActiveGroup != group )
{
@@ -67,6 +67,8 @@ void QgsMeshRendererActiveDatasetWidget::onActiveGroupChanged()

mDatasetSlider->setValue( val );
onActiveDatasetChanged( val );
mActiveDatasetGroup = mDatasetGroupTreeView->activeGroup();
emit activeDatasetGroupChanged( mActiveDatasetGroup );
}

void QgsMeshRendererActiveDatasetWidget::onActiveDatasetChanged( int value )
@@ -46,6 +46,12 @@ class APP_EXPORT QgsMeshRendererActiveDatasetWidget : public QWidget, private Ui
//! Associates mesh layer with the widget
void setLayer( QgsMeshLayer *layer );

//! Returns index of the active scalar dataset group
int activeScalarDatasetGroup() const { return mActiveDatasetGroup; }

//! Returns index of the active vector dataset group
int activeVectorDatasetGroup() const { return mActiveDatasetGroup; }

//! Gets index of the selected/active scalar dataset
QgsMeshDatasetIndex activeScalarDataset() const;

@@ -63,6 +69,9 @@ class APP_EXPORT QgsMeshRendererActiveDatasetWidget : public QWidget, private Ui
//! Emitted when active vector dataset changed
void activeVectorDatasetChanged( QgsMeshDatasetIndex index );

//! Emitted when the current group gets changed
void activeDatasetGroupChanged( int groupIndex );

//! Emitted when any settings related to rendering changed
void widgetChanged();

@@ -76,6 +85,7 @@ class APP_EXPORT QgsMeshRendererActiveDatasetWidget : public QWidget, private Ui
void setSliderRange();

QgsMeshLayer *mMeshLayer = nullptr; // not owned
int mActiveDatasetGroup = -1;
QgsMeshDatasetIndex mActiveScalarDataset;
QgsMeshDatasetIndex mActiveVectorDataset;
};
@@ -17,6 +17,7 @@

#include "qgis.h"
#include "qgsmeshlayer.h"
#include "qgsmeshlayerutils.h"
#include "qgsmessagelog.h"


@@ -52,14 +53,15 @@ void QgsMeshRendererScalarSettingsWidget::syncToLayer( )
if ( !mMeshLayer )
return;

const QgsMeshRendererScalarSettings settings = mMeshLayer->rendererSettings().scalarSettings();
if ( settings.isEnabled() )
{
const QgsColorRampShader shader = settings.colorRampShader();
whileBlocking( mScalarMinLineEdit )->setText( QString::number( shader.minimumValue() ) );
whileBlocking( mScalarMaxLineEdit )->setText( QString::number( shader.maximumValue() ) );
whileBlocking( mScalarColorRampShaderWidget )->setFromShader( shader );
}
if ( mActiveDatasetGroup < 0 )
return;

const QgsMeshRendererSettings rendererSettings = mMeshLayer->rendererSettings();
const QgsMeshRendererScalarSettings settings = rendererSettings.scalarSettings( mActiveDatasetGroup );
const QgsColorRampShader shader = settings.colorRampShader();
whileBlocking( mScalarMinLineEdit )->setText( QString::number( shader.minimumValue() ) );
whileBlocking( mScalarMaxLineEdit )->setText( QString::number( shader.maximumValue() ) );
whileBlocking( mScalarColorRampShaderWidget )->setFromShader( shader );
}

double QgsMeshRendererScalarSettingsWidget::lineEditValue( const QLineEdit *lineEdit ) const
@@ -89,54 +91,8 @@ void QgsMeshRendererScalarSettingsWidget::minMaxEdited()
void QgsMeshRendererScalarSettingsWidget::recalculateMinMaxButtonClicked()
{
double min, max;
calcMinMax( mActiveDataset, min, max );
QgsMeshLayerUtils::calculateMinMaxForDatasetGroup( min, max, mMeshLayer->dataProvider(), mActiveDatasetGroup );
whileBlocking( mScalarMinLineEdit )->setText( QString::number( min ) );
whileBlocking( mScalarMaxLineEdit )->setText( QString::number( max ) );
mScalarColorRampShaderWidget->setMinimumMaximumAndClassify( min, max );
}

void QgsMeshRendererScalarSettingsWidget::setActiveDataset( QgsMeshDatasetIndex activeDataset )
{
mActiveDataset = activeDataset;
}

void QgsMeshRendererScalarSettingsWidget::calcMinMax( QgsMeshDatasetIndex datasetIndex, double &min, double &max ) const
{
if ( !mMeshLayer )
return;

if ( !mMeshLayer->dataProvider() )
return;

const QgsMeshDatasetGroupMetadata metadata = mMeshLayer->dataProvider()->datasetGroupMetadata( datasetIndex );
bool scalarDataOnVertices = metadata.dataType() == QgsMeshDatasetGroupMetadata::DataOnVertices;
int count;
if ( scalarDataOnVertices )
count = mMeshLayer->dataProvider()->vertexCount();
else
count = mMeshLayer->dataProvider()->faceCount();

bool myFirstIterationFlag = true;
for ( int i = 0; i < count; ++i )
{
double myValue = mMeshLayer->dataProvider()->datasetValue( datasetIndex, i ).scalar();
if ( std::isnan( myValue ) ) continue; // NULL
if ( myFirstIterationFlag )
{
myFirstIterationFlag = false;
min = myValue;
max = myValue;
}
else
{
if ( myValue < min )
{
min = myValue;
}
if ( myValue > max )
{
max = myValue;
}
}
}
}
@@ -45,6 +45,9 @@ class APP_EXPORT QgsMeshRendererScalarSettingsWidget : public QWidget, private U
//! Associates mesh layer with the widget
void setLayer( QgsMeshLayer *layer );

//! Associates a dataset group with the widget (should be set before syncToLayer())
void setActiveDatasetGroup( int groupIndex ) { mActiveDatasetGroup = groupIndex; }

//! Returns scalar settings
QgsMeshRendererScalarSettings settings() const;

@@ -55,21 +58,16 @@ class APP_EXPORT QgsMeshRendererScalarSettingsWidget : public QWidget, private U
//! Mesh rendering settings changed
void widgetChanged();

public slots:
//! Set active scalar dataset to be used
void setActiveDataset( QgsMeshDatasetIndex activeDataset );

private slots:
void minMaxChanged();
void minMaxEdited();
void recalculateMinMaxButtonClicked();

private:
double lineEditValue( const QLineEdit *lineEdit ) const;
void calcMinMax( QgsMeshDatasetIndex datasetIndex, double &min, double &max ) const;

QgsMeshLayer *mMeshLayer = nullptr; // not owned
QgsMeshDatasetIndex mActiveDataset;
int mActiveDatasetGroup = -1;
};

#endif // QGSMESHRENDERERSCALARSETTINGSWIDGET_H
@@ -93,17 +93,16 @@ QgsMeshRendererVectorSettings QgsMeshRendererVectorSettingsWidget::settings() co
return settings;
}

void QgsMeshRendererVectorSettingsWidget::setActiveDataset( QgsMeshDatasetIndex activeDataset )
{
mActiveDataset = activeDataset;
}

void QgsMeshRendererVectorSettingsWidget::syncToLayer( )
{
if ( !mMeshLayer )
return;

QgsMeshRendererVectorSettings settings = mMeshLayer->rendererSettings().vectorSettings();
if ( mActiveDatasetGroup < 0 )
return;

const QgsMeshRendererSettings rendererSettings = mMeshLayer->rendererSettings();
const QgsMeshRendererVectorSettings settings = rendererSettings.vectorSettings( mActiveDatasetGroup );

// basic
mColorWidget->setColor( settings.color() );
@@ -46,6 +46,9 @@ class APP_EXPORT QgsMeshRendererVectorSettingsWidget : public QWidget, private U
//! Associates mesh layer with the widget
void setLayer( QgsMeshLayer *layer );

//! Associates a dataset group with the widget (should be set before syncToLayer())
void setActiveDatasetGroup( int groupIndex ) { mActiveDatasetGroup = groupIndex; }

//! Returns vector settings
QgsMeshRendererVectorSettings settings() const;

@@ -56,10 +59,6 @@ class APP_EXPORT QgsMeshRendererVectorSettingsWidget : public QWidget, private U
//! Mesh rendering settings changed
void widgetChanged();

public slots:
//! Set active vector dataset to be used
void setActiveDataset( QgsMeshDatasetIndex activeDataset );

private:

/**
@@ -69,7 +68,7 @@ class APP_EXPORT QgsMeshRendererVectorSettingsWidget : public QWidget, private U
double filterValue( const QString &text, double errVal ) const;

QgsMeshLayer *mMeshLayer = nullptr; //not owned
QgsMeshDatasetIndex mActiveDataset;
int mActiveDatasetGroup = -1;
};

#endif // QGSMESHRENDERERVECTORSETTINGSWIDGET_H
@@ -44,12 +44,8 @@ QgsRendererMeshPropertiesWidget::QgsRendererMeshPropertiesWidget( QgsMeshLayer *
mMeshRendererVectorSettingsWidget->setLayer( mMeshLayer );
syncToLayer();

connect( mMeshRendererActiveDatasetWidget, &QgsMeshRendererActiveDatasetWidget::activeScalarDatasetChanged,
mMeshRendererScalarSettingsWidget, &QgsMeshRendererScalarSettingsWidget::setActiveDataset );
connect( mMeshRendererActiveDatasetWidget, &QgsMeshRendererActiveDatasetWidget::activeVectorDatasetChanged,
mMeshRendererVectorSettingsWidget, &QgsMeshRendererVectorSettingsWidget::setActiveDataset );
connect( mMeshRendererActiveDatasetWidget, &QgsMeshRendererActiveDatasetWidget::activeVectorDatasetChanged,
this, &QgsRendererMeshPropertiesWidget::enableVectorRenderingTab );
connect( mMeshRendererActiveDatasetWidget, &QgsMeshRendererActiveDatasetWidget::activeDatasetGroupChanged,
this, &QgsRendererMeshPropertiesWidget::onActiveDatasetGroupChanged );

connect( mNativeMeshGroup, &QGroupBox::toggled, this, &QgsPanelWidget::widgetChanged );
connect( mTriangularMeshGroup, &QGroupBox::toggled, this, &QgsPanelWidget::widgetChanged );
@@ -81,45 +77,54 @@ void QgsRendererMeshPropertiesWidget::apply()
triangularMeshSettings.setEnabled( triangularMeshRenderingIsEnabled );

// SCALAR
const QgsMeshDatasetIndex activeScalarDatasetIndex = mMeshRendererActiveDatasetWidget->activeScalarDataset();
QgsMeshRendererScalarSettings scalarSettings = mMeshRendererScalarSettingsWidget->settings();
scalarSettings.setEnabled( mContoursGroupBox->isChecked() );
QgsMeshDatasetIndex activeScalarDatasetIndex = mMeshRendererActiveDatasetWidget->activeScalarDataset();
if ( !mContoursGroupBox->isChecked() )
activeScalarDatasetIndex = QgsMeshDatasetIndex();

// VECTOR
const QgsMeshDatasetIndex activeVectorDatasetIndex = mMeshRendererActiveDatasetWidget->activeVectorDataset();
QgsMeshRendererVectorSettings vectorSettings = mMeshRendererVectorSettingsWidget->settings();
vectorSettings.setEnabled( mVectorsGroupBox->isChecked() );
QgsMeshDatasetIndex activeVectorDatasetIndex = mMeshRendererActiveDatasetWidget->activeVectorDataset();
if ( !mVectorsGroupBox->isChecked() )
activeVectorDatasetIndex = QgsMeshDatasetIndex();

QgsMeshRendererSettings settings;
QgsMeshRendererSettings settings = mMeshLayer->rendererSettings();
settings.setNativeMeshSettings( meshSettings );
settings.setTriangularMeshSettings( triangularMeshSettings );
settings.setScalarSettings( scalarSettings );
settings.setVectorSettings( vectorSettings );

settings.setActiveScalarDataset( activeScalarDatasetIndex );
if ( activeScalarDatasetIndex.isValid() )
settings.setScalarSettings( activeScalarDatasetIndex.group(), mMeshRendererScalarSettingsWidget->settings() );

settings.setActiveVectorDataset( activeVectorDatasetIndex );
mMeshLayer->setRendererSettings( settings );
if ( activeVectorDatasetIndex.isValid() )
settings.setVectorSettings( activeVectorDatasetIndex.group(), mMeshRendererVectorSettingsWidget->settings() );

mMeshLayer->setRendererSettings( settings );
mMeshLayer->triggerRepaint();
}

void QgsRendererMeshPropertiesWidget::syncToLayer()
{
mMeshRendererActiveDatasetWidget->syncToLayer();
mMeshRendererScalarSettingsWidget->setActiveDataset( mMeshRendererActiveDatasetWidget->activeScalarDataset() );
mMeshRendererVectorSettingsWidget->setActiveDataset( mMeshRendererActiveDatasetWidget->activeVectorDataset() );

mMeshRendererScalarSettingsWidget->syncToLayer();
mNativeMeshSettingsWidget->syncToLayer();
mTriangularMeshSettingsWidget->syncToLayer();
mMeshRendererVectorSettingsWidget->syncToLayer();

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

enableVectorRenderingTab( mMeshRendererActiveDatasetWidget->activeVectorDataset() );
onActiveDatasetGroupChanged();
}

void QgsRendererMeshPropertiesWidget::enableVectorRenderingTab( QgsMeshDatasetIndex vectorDatasetIndex )
void QgsRendererMeshPropertiesWidget::onActiveDatasetGroupChanged()
{
mVectorsGroupBox->setEnabled( vectorDatasetIndex.isValid() );
int scalarGroup = mMeshRendererActiveDatasetWidget->activeScalarDatasetGroup();
int vectorGroup = mMeshRendererActiveDatasetWidget->activeVectorDatasetGroup();
if ( vectorGroup >= 0 && !mMeshLayer->dataProvider()->datasetGroupMetadata( vectorGroup ).isVector() )
vectorGroup = -1;

mMeshRendererScalarSettingsWidget->setActiveDatasetGroup( scalarGroup );
mMeshRendererVectorSettingsWidget->setActiveDatasetGroup( vectorGroup );

mMeshRendererScalarSettingsWidget->syncToLayer();
mMeshRendererVectorSettingsWidget->syncToLayer();

mContoursGroupBox->setChecked( scalarGroup >= 0 );
mVectorsGroupBox->setChecked( vectorGroup >= 0 );
mVectorsGroupBox->setEnabled( vectorGroup >= 0 );
}
@@ -53,7 +53,7 @@ class APP_EXPORT QgsRendererMeshPropertiesWidget : public QgsMapLayerConfigWidge
void syncToLayer();

private slots:
void enableVectorRenderingTab( QgsMeshDatasetIndex vectorDatasetIndex );
void onActiveDatasetGroupChanged();

private:
QgsMeshLayer *mMeshLayer = nullptr; //not owned

0 comments on commit 9fc2e3e

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