mirror of
https://github.com/qgis/QGIS.git
synced 2025-04-14 00:07:35 -04:00
Read/write mesh styling from/to project files
This commit is contained in:
parent
9fc2e3e148
commit
358d12946b
@ -53,6 +53,15 @@ Returns color used for rendering
|
|||||||
void setColor( const QColor &color );
|
void setColor( const QColor &color );
|
||||||
%Docstring
|
%Docstring
|
||||||
Sets color used for rendering of the mesh
|
Sets color used for rendering of the mesh
|
||||||
|
%End
|
||||||
|
|
||||||
|
QDomElement writeXml( QDomDocument &doc ) const;
|
||||||
|
%Docstring
|
||||||
|
Writes configuration to a new DOM element
|
||||||
|
%End
|
||||||
|
void readXml( const QDomElement &elem );
|
||||||
|
%Docstring
|
||||||
|
Reads configuration from the given DOM element
|
||||||
%End
|
%End
|
||||||
|
|
||||||
};
|
};
|
||||||
@ -81,6 +90,15 @@ Returns color ramp shader function
|
|||||||
void setColorRampShader( const QgsColorRampShader &shader );
|
void setColorRampShader( const QgsColorRampShader &shader );
|
||||||
%Docstring
|
%Docstring
|
||||||
Sets color ramp shader function
|
Sets color ramp shader function
|
||||||
|
%End
|
||||||
|
|
||||||
|
QDomElement writeXml( QDomDocument &doc ) const;
|
||||||
|
%Docstring
|
||||||
|
Writes configuration to a new DOM element
|
||||||
|
%End
|
||||||
|
void readXml( const QDomElement &elem );
|
||||||
|
%Docstring
|
||||||
|
Reads configuration from the given DOM element
|
||||||
%End
|
%End
|
||||||
|
|
||||||
};
|
};
|
||||||
@ -242,6 +260,15 @@ Returns ratio of the head length of the arrow (range 0-1)
|
|||||||
void setArrowHeadLengthRatio( double arrowHeadLengthRatio );
|
void setArrowHeadLengthRatio( double arrowHeadLengthRatio );
|
||||||
%Docstring
|
%Docstring
|
||||||
Sets ratio of the head length of the arrow (range 0-1)
|
Sets ratio of the head length of the arrow (range 0-1)
|
||||||
|
%End
|
||||||
|
|
||||||
|
QDomElement writeXml( QDomDocument &doc ) const;
|
||||||
|
%Docstring
|
||||||
|
Writes configuration to a new DOM element
|
||||||
|
%End
|
||||||
|
void readXml( const QDomElement &elem );
|
||||||
|
%Docstring
|
||||||
|
Reads configuration from the given DOM element
|
||||||
%End
|
%End
|
||||||
|
|
||||||
};
|
};
|
||||||
@ -318,6 +345,15 @@ Returns active vector dataset
|
|||||||
void setActiveVectorDataset( QgsMeshDatasetIndex index = QgsMeshDatasetIndex() );
|
void setActiveVectorDataset( QgsMeshDatasetIndex index = QgsMeshDatasetIndex() );
|
||||||
%Docstring
|
%Docstring
|
||||||
Sets active vector dataset for rendering.
|
Sets active vector dataset for rendering.
|
||||||
|
%End
|
||||||
|
|
||||||
|
QDomElement writeXml( QDomDocument &doc ) const;
|
||||||
|
%Docstring
|
||||||
|
Writes configuration to a new DOM element
|
||||||
|
%End
|
||||||
|
void readXml( const QDomElement &elem );
|
||||||
|
%Docstring
|
||||||
|
Reads configuration from the given DOM element
|
||||||
%End
|
%End
|
||||||
|
|
||||||
};
|
};
|
||||||
|
@ -82,7 +82,7 @@ Returns the custom colormap.
|
|||||||
Returns the color ramp type.
|
Returns the color ramp type.
|
||||||
%End
|
%End
|
||||||
|
|
||||||
QString colorRampTypeAsQString();
|
QString colorRampTypeAsQString() const;
|
||||||
%Docstring
|
%Docstring
|
||||||
Returns the color ramp type as a string.
|
Returns the color ramp type as a string.
|
||||||
%End
|
%End
|
||||||
@ -160,6 +160,20 @@ Generates and new RGB value based on original RGB value
|
|||||||
virtual void legendSymbologyItems( QList< QPair< QString, QColor > > &symbolItems /Out/ ) const;
|
virtual void legendSymbologyItems( QList< QPair< QString, QColor > > &symbolItems /Out/ ) const;
|
||||||
|
|
||||||
|
|
||||||
|
QDomElement writeXml( QDomDocument &doc ) const;
|
||||||
|
%Docstring
|
||||||
|
Writes configuration to a new DOM element
|
||||||
|
|
||||||
|
.. versionadded:: 3.4
|
||||||
|
%End
|
||||||
|
|
||||||
|
void readXml( const QDomElement &elem );
|
||||||
|
%Docstring
|
||||||
|
Reads configuration from the given DOM element
|
||||||
|
|
||||||
|
.. versionadded:: 3.4
|
||||||
|
%End
|
||||||
|
|
||||||
void setClassificationMode( ClassificationMode classificationMode );
|
void setClassificationMode( ClassificationMode classificationMode );
|
||||||
%Docstring
|
%Docstring
|
||||||
Sets classification mode
|
Sets classification mode
|
||||||
|
@ -164,11 +164,13 @@ void QgsMeshRendererActiveDatasetWidget::syncToLayer()
|
|||||||
if ( mMeshLayer )
|
if ( mMeshLayer )
|
||||||
{
|
{
|
||||||
const QgsMeshRendererSettings rendererSettings = mMeshLayer->rendererSettings();
|
const QgsMeshRendererSettings rendererSettings = mMeshLayer->rendererSettings();
|
||||||
|
mActiveDatasetGroup = mDatasetGroupTreeView->activeGroup();
|
||||||
mActiveScalarDataset = rendererSettings.activeScalarDataset();
|
mActiveScalarDataset = rendererSettings.activeScalarDataset();
|
||||||
mActiveVectorDataset = rendererSettings.activeVectorDataset();
|
mActiveVectorDataset = rendererSettings.activeVectorDataset();
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
mActiveDatasetGroup = -1;
|
||||||
mActiveScalarDataset = QgsMeshDatasetIndex();
|
mActiveScalarDataset = QgsMeshDatasetIndex();
|
||||||
mActiveVectorDataset = QgsMeshDatasetIndex();
|
mActiveVectorDataset = QgsMeshDatasetIndex();
|
||||||
}
|
}
|
||||||
|
@ -26,6 +26,8 @@ QgsMeshRendererVectorSettingsWidget::QgsMeshRendererVectorSettingsWidget( QWidge
|
|||||||
{
|
{
|
||||||
setupUi( this );
|
setupUi( this );
|
||||||
|
|
||||||
|
mShaftLengthComboBox->setCurrentIndex( -1 );
|
||||||
|
|
||||||
connect( mColorWidget, &QgsColorButton::colorChanged, this, &QgsMeshRendererVectorSettingsWidget::widgetChanged );
|
connect( mColorWidget, &QgsColorButton::colorChanged, this, &QgsMeshRendererVectorSettingsWidget::widgetChanged );
|
||||||
connect( mLineWidthSpinBox, qgis::overload<double>::of( &QgsDoubleSpinBox::valueChanged ),
|
connect( mLineWidthSpinBox, qgis::overload<double>::of( &QgsDoubleSpinBox::valueChanged ),
|
||||||
this, &QgsMeshRendererVectorSettingsWidget::widgetChanged );
|
this, &QgsMeshRendererVectorSettingsWidget::widgetChanged );
|
||||||
|
@ -221,18 +221,26 @@ QgsMapLayerRenderer *QgsMeshLayer::createMapRenderer( QgsRenderContext &renderer
|
|||||||
|
|
||||||
bool QgsMeshLayer::readSymbology( const QDomNode &node, QString &errorMessage, QgsReadWriteContext &context )
|
bool QgsMeshLayer::readSymbology( const QDomNode &node, QString &errorMessage, QgsReadWriteContext &context )
|
||||||
{
|
{
|
||||||
Q_UNUSED( node );
|
|
||||||
Q_UNUSED( errorMessage );
|
Q_UNUSED( errorMessage );
|
||||||
Q_UNUSED( context );
|
Q_UNUSED( context );
|
||||||
|
|
||||||
|
QDomElement elem = node.toElement();
|
||||||
|
QDomElement elemRendererSettings = elem.firstChildElement( "mesh-renderer-settings" );
|
||||||
|
if ( !elemRendererSettings.isNull() )
|
||||||
|
mRendererSettings.readXml( elemRendererSettings );
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool QgsMeshLayer::writeSymbology( QDomNode &node, QDomDocument &doc, QString &errorMessage, const QgsReadWriteContext &context ) const
|
bool QgsMeshLayer::writeSymbology( QDomNode &node, QDomDocument &doc, QString &errorMessage, const QgsReadWriteContext &context ) const
|
||||||
{
|
{
|
||||||
Q_UNUSED( node );
|
|
||||||
Q_UNUSED( doc );
|
|
||||||
Q_UNUSED( errorMessage );
|
Q_UNUSED( errorMessage );
|
||||||
Q_UNUSED( context );
|
Q_UNUSED( context );
|
||||||
|
|
||||||
|
QDomElement elem = node.toElement();
|
||||||
|
QDomElement elemRendererSettings = mRendererSettings.writeXml( doc );
|
||||||
|
elem.appendChild( elemRendererSettings );
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -258,8 +266,6 @@ QString QgsMeshLayer::encodedSource( const QString &source, const QgsReadWriteCo
|
|||||||
|
|
||||||
bool QgsMeshLayer::readXml( const QDomNode &layer_node, QgsReadWriteContext &context )
|
bool QgsMeshLayer::readXml( const QDomNode &layer_node, QgsReadWriteContext &context )
|
||||||
{
|
{
|
||||||
Q_UNUSED( context );
|
|
||||||
|
|
||||||
QgsDebugMsgLevel( QStringLiteral( "Datasource in QgsMeshLayer::readXml: %1" ).arg( mDataSource.toLocal8Bit().data() ), 3 );
|
QgsDebugMsgLevel( QStringLiteral( "Datasource in QgsMeshLayer::readXml: %1" ).arg( mDataSource.toLocal8Bit().data() ), 3 );
|
||||||
|
|
||||||
//process provider key
|
//process provider key
|
||||||
@ -296,6 +302,9 @@ bool QgsMeshLayer::readXml( const QDomNode &layer_node, QgsReadWriteContext &con
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
QString errorMsg;
|
||||||
|
readSymbology( layer_node, errorMsg, context );
|
||||||
|
|
||||||
return mValid; // should be true if read successfully
|
return mValid; // should be true if read successfully
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -17,6 +17,9 @@
|
|||||||
|
|
||||||
#include "qgsmeshrenderersettings.h"
|
#include "qgsmeshrenderersettings.h"
|
||||||
|
|
||||||
|
#include "qgssymbollayerutils.h"
|
||||||
|
|
||||||
|
|
||||||
bool QgsMeshRendererMeshSettings::isEnabled() const
|
bool QgsMeshRendererMeshSettings::isEnabled() const
|
||||||
{
|
{
|
||||||
return mEnabled;
|
return mEnabled;
|
||||||
@ -47,11 +50,27 @@ void QgsMeshRendererMeshSettings::setColor( const QColor &color )
|
|||||||
mColor = color;
|
mColor = color;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
QDomElement QgsMeshRendererMeshSettings::writeXml( QDomDocument &doc ) const
|
||||||
|
{
|
||||||
|
QDomElement elem = doc.createElement( "mesh-settings" );
|
||||||
|
elem.setAttribute( "enabled", mEnabled ? "1" : "0" );
|
||||||
|
elem.setAttribute( "line-width", mLineWidth );
|
||||||
|
elem.setAttribute( "color", QgsSymbolLayerUtils::encodeColor( mColor ) );
|
||||||
|
return elem;
|
||||||
|
}
|
||||||
|
|
||||||
|
void QgsMeshRendererMeshSettings::readXml( const QDomElement &elem )
|
||||||
|
{
|
||||||
|
mEnabled = elem.attribute( "enabled" ).toInt();
|
||||||
|
mLineWidth = elem.attribute( "line-width" ).toDouble();
|
||||||
|
mColor = QgsSymbolLayerUtils::decodeColor( elem.attribute( "color" ) );
|
||||||
|
}
|
||||||
|
|
||||||
|
// ---------------------------------------------------------------------
|
||||||
|
|
||||||
QgsColorRampShader QgsMeshRendererScalarSettings::colorRampShader() const
|
QgsColorRampShader QgsMeshRendererScalarSettings::colorRampShader() const
|
||||||
{
|
{
|
||||||
return mColorRampShader;
|
return mColorRampShader;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void QgsMeshRendererScalarSettings::setColorRampShader( const QgsColorRampShader &shader )
|
void QgsMeshRendererScalarSettings::setColorRampShader( const QgsColorRampShader &shader )
|
||||||
@ -59,6 +78,22 @@ void QgsMeshRendererScalarSettings::setColorRampShader( const QgsColorRampShader
|
|||||||
mColorRampShader = shader;
|
mColorRampShader = shader;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
QDomElement QgsMeshRendererScalarSettings::writeXml( QDomDocument &doc ) const
|
||||||
|
{
|
||||||
|
QDomElement elem = doc.createElement( "scalar-settings" );
|
||||||
|
QDomElement elemShader = mColorRampShader.writeXml( doc );
|
||||||
|
elem.appendChild( elemShader );
|
||||||
|
return elem;
|
||||||
|
}
|
||||||
|
|
||||||
|
void QgsMeshRendererScalarSettings::readXml( const QDomElement &elem )
|
||||||
|
{
|
||||||
|
QDomElement elemShader = elem.firstChildElement( QStringLiteral( "colorrampshader" ) );
|
||||||
|
mColorRampShader.readXml( elemShader );
|
||||||
|
}
|
||||||
|
|
||||||
|
// ---------------------------------------------------------------------
|
||||||
|
|
||||||
double QgsMeshRendererVectorSettings::lineWidth() const
|
double QgsMeshRendererVectorSettings::lineWidth() const
|
||||||
{
|
{
|
||||||
return mLineWidth;
|
return mLineWidth;
|
||||||
@ -168,3 +203,153 @@ void QgsMeshRendererVectorSettings::setArrowHeadLengthRatio( double vectorHeadLe
|
|||||||
{
|
{
|
||||||
mArrowHeadLengthRatio = vectorHeadLengthRatio;
|
mArrowHeadLengthRatio = vectorHeadLengthRatio;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
QDomElement QgsMeshRendererVectorSettings::writeXml( QDomDocument &doc ) const
|
||||||
|
{
|
||||||
|
QDomElement elem = doc.createElement( "vector-settings" );
|
||||||
|
elem.setAttribute( "line-width", mLineWidth );
|
||||||
|
elem.setAttribute( "color", QgsSymbolLayerUtils::encodeColor( mColor ) );
|
||||||
|
elem.setAttribute( "filter-min", mFilterMin );
|
||||||
|
elem.setAttribute( "filter-max", mFilterMax );
|
||||||
|
elem.setAttribute( "arrow-head-width-ratio", mArrowHeadWidthRatio );
|
||||||
|
elem.setAttribute( "arrow-head-length-ratio", mArrowHeadLengthRatio );
|
||||||
|
|
||||||
|
QDomElement elemShaft = doc.createElement( "shaft-length" );
|
||||||
|
QString methodTxt;
|
||||||
|
switch ( mShaftLengthMethod )
|
||||||
|
{
|
||||||
|
case MinMax:
|
||||||
|
methodTxt = "minmax";
|
||||||
|
elemShaft.setAttribute( "min", mMinShaftLength );
|
||||||
|
elemShaft.setAttribute( "max", mMaxShaftLength );
|
||||||
|
break;
|
||||||
|
case Scaled:
|
||||||
|
methodTxt = "scaled";
|
||||||
|
elemShaft.setAttribute( "scale-factor", mScaleFactor );
|
||||||
|
break;
|
||||||
|
case Fixed:
|
||||||
|
methodTxt = "fixed";
|
||||||
|
elemShaft.setAttribute( "fixed-length", mFixedShaftLength );
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
elemShaft.setAttribute( "method", methodTxt );
|
||||||
|
elem.appendChild( elemShaft );
|
||||||
|
return elem;
|
||||||
|
}
|
||||||
|
|
||||||
|
void QgsMeshRendererVectorSettings::readXml( const QDomElement &elem )
|
||||||
|
{
|
||||||
|
mLineWidth = elem.attribute( "line-width" ).toDouble();
|
||||||
|
mColor = QgsSymbolLayerUtils::decodeColor( elem.attribute( "color" ) );
|
||||||
|
mFilterMin = elem.attribute( "filter-min" ).toDouble();
|
||||||
|
mFilterMax = elem.attribute( "filter-max" ).toDouble();
|
||||||
|
mArrowHeadWidthRatio = elem.attribute( "arrow-head-width-ratio" ).toDouble();
|
||||||
|
mArrowHeadLengthRatio = elem.attribute( "arrow-head-length-ratio" ).toDouble();
|
||||||
|
|
||||||
|
QDomElement elemShaft = elem.firstChildElement( "shaft-length" );
|
||||||
|
QString methodTxt = elemShaft.attribute( "method" );
|
||||||
|
if ( methodTxt == "minmax" )
|
||||||
|
{
|
||||||
|
mShaftLengthMethod = MinMax;
|
||||||
|
mMinShaftLength = elemShaft.attribute( "min" ).toDouble();
|
||||||
|
mMaxShaftLength = elemShaft.attribute( "max" ).toDouble();
|
||||||
|
}
|
||||||
|
else if ( methodTxt == "scaled" )
|
||||||
|
{
|
||||||
|
mShaftLengthMethod = Scaled;
|
||||||
|
mScaleFactor = elemShaft.attribute( "scale-factor" ).toDouble();
|
||||||
|
}
|
||||||
|
else // fixed
|
||||||
|
{
|
||||||
|
mShaftLengthMethod = Fixed;
|
||||||
|
mFixedShaftLength = elemShaft.attribute( "fixed-length" ).toDouble();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// ---------------------------------------------------------------------
|
||||||
|
|
||||||
|
QDomElement QgsMeshRendererSettings::writeXml( QDomDocument &doc ) const
|
||||||
|
{
|
||||||
|
QDomElement elem = doc.createElement( "mesh-renderer-settings" );
|
||||||
|
|
||||||
|
QDomElement elemActiveDataset = doc.createElement( "active-dataset" );
|
||||||
|
if ( mActiveScalarDataset.isValid() )
|
||||||
|
elemActiveDataset.setAttribute( "scalar", QString( "%1,%2" ).arg( mActiveScalarDataset.group() ).arg( mActiveScalarDataset.dataset() ) );
|
||||||
|
if ( mActiveVectorDataset.isValid() )
|
||||||
|
elemActiveDataset.setAttribute( "vector", QString( "%1,%2" ).arg( mActiveVectorDataset.group() ).arg( mActiveVectorDataset.dataset() ) );
|
||||||
|
elem.appendChild( elemActiveDataset );
|
||||||
|
|
||||||
|
for ( int groupIndex : mRendererScalarSettings.keys() )
|
||||||
|
{
|
||||||
|
const QgsMeshRendererScalarSettings &scalarSettings = mRendererScalarSettings[groupIndex];
|
||||||
|
QDomElement elemScalar = scalarSettings.writeXml( doc );
|
||||||
|
elemScalar.setAttribute( "group", groupIndex );
|
||||||
|
elem.appendChild( elemScalar );
|
||||||
|
}
|
||||||
|
|
||||||
|
for ( int groupIndex : mRendererVectorSettings.keys() )
|
||||||
|
{
|
||||||
|
const QgsMeshRendererVectorSettings &vectorSettings = mRendererVectorSettings[groupIndex];
|
||||||
|
QDomElement elemVector = vectorSettings.writeXml( doc );
|
||||||
|
elemVector.setAttribute( "group", groupIndex );
|
||||||
|
elem.appendChild( elemVector );
|
||||||
|
}
|
||||||
|
|
||||||
|
QDomElement elemNativeMesh = mRendererNativeMeshSettings.writeXml( doc );
|
||||||
|
elemNativeMesh.setTagName( "mesh-settings-native" );
|
||||||
|
elem.appendChild( elemNativeMesh );
|
||||||
|
|
||||||
|
QDomElement elemTriangularMesh = mRendererTriangularMeshSettings.writeXml( doc );
|
||||||
|
elemTriangularMesh.setTagName( "mesh-settings-triangular" );
|
||||||
|
elem.appendChild( elemTriangularMesh );
|
||||||
|
|
||||||
|
return elem;
|
||||||
|
}
|
||||||
|
|
||||||
|
void QgsMeshRendererSettings::readXml( const QDomElement &elem )
|
||||||
|
{
|
||||||
|
mRendererScalarSettings.clear();
|
||||||
|
mRendererVectorSettings.clear();
|
||||||
|
|
||||||
|
QDomElement elemActiveDataset = elem.firstChildElement( "active-dataset" );
|
||||||
|
if ( elemActiveDataset.hasAttribute( "scalar" ) )
|
||||||
|
{
|
||||||
|
QStringList lst = elemActiveDataset.attribute( "scalar" ).split( QChar( ',' ) );
|
||||||
|
if ( lst.count() == 2 )
|
||||||
|
mActiveScalarDataset = QgsMeshDatasetIndex( lst[0].toInt(), lst[1].toInt() );
|
||||||
|
}
|
||||||
|
if ( elemActiveDataset.hasAttribute( "vector" ) )
|
||||||
|
{
|
||||||
|
QStringList lst = elemActiveDataset.attribute( "vector" ).split( QChar( ',' ) );
|
||||||
|
if ( lst.count() == 2 )
|
||||||
|
mActiveVectorDataset = QgsMeshDatasetIndex( lst[0].toInt(), lst[1].toInt() );
|
||||||
|
}
|
||||||
|
|
||||||
|
QDomElement elemScalar = elem.firstChildElement( "scalar-settings" );
|
||||||
|
while ( !elemScalar.isNull() )
|
||||||
|
{
|
||||||
|
int groupIndex = elemScalar.attribute( "group" ).toInt();
|
||||||
|
QgsMeshRendererScalarSettings scalarSettings;
|
||||||
|
scalarSettings.readXml( elemScalar );
|
||||||
|
mRendererScalarSettings.insert( groupIndex, scalarSettings );
|
||||||
|
|
||||||
|
elemScalar = elemScalar.nextSiblingElement( "scalar-settings" );
|
||||||
|
}
|
||||||
|
|
||||||
|
QDomElement elemVector = elem.firstChildElement( "vector-settings" );
|
||||||
|
while ( !elemVector.isNull() )
|
||||||
|
{
|
||||||
|
int groupIndex = elemVector.attribute( "group" ).toInt();
|
||||||
|
QgsMeshRendererVectorSettings vectorSettings;
|
||||||
|
vectorSettings.readXml( elemVector );
|
||||||
|
mRendererVectorSettings.insert( groupIndex, vectorSettings );
|
||||||
|
|
||||||
|
elemVector = elemVector.nextSiblingElement( "vector-settings" );
|
||||||
|
}
|
||||||
|
|
||||||
|
QDomElement elemNativeMesh = elem.firstChildElement( "mesh-settings-native" );
|
||||||
|
mRendererNativeMeshSettings.readXml( elemNativeMesh );
|
||||||
|
|
||||||
|
QDomElement elemTriangularMesh = elem.firstChildElement( "mesh-settings-triangular" );
|
||||||
|
mRendererTriangularMeshSettings.readXml( elemTriangularMesh );
|
||||||
|
}
|
||||||
|
@ -53,6 +53,11 @@ class CORE_EXPORT QgsMeshRendererMeshSettings
|
|||||||
//! Sets color used for rendering of the mesh
|
//! Sets color used for rendering of the mesh
|
||||||
void setColor( const QColor &color );
|
void setColor( const QColor &color );
|
||||||
|
|
||||||
|
//! Writes configuration to a new DOM element
|
||||||
|
QDomElement writeXml( QDomDocument &doc ) const;
|
||||||
|
//! Reads configuration from the given DOM element
|
||||||
|
void readXml( const QDomElement &elem );
|
||||||
|
|
||||||
private:
|
private:
|
||||||
bool mEnabled = false;
|
bool mEnabled = false;
|
||||||
double mLineWidth = DEFAULT_LINE_WIDTH;
|
double mLineWidth = DEFAULT_LINE_WIDTH;
|
||||||
@ -76,6 +81,11 @@ class CORE_EXPORT QgsMeshRendererScalarSettings
|
|||||||
//! Sets color ramp shader function
|
//! Sets color ramp shader function
|
||||||
void setColorRampShader( const QgsColorRampShader &shader );
|
void setColorRampShader( const QgsColorRampShader &shader );
|
||||||
|
|
||||||
|
//! Writes configuration to a new DOM element
|
||||||
|
QDomElement writeXml( QDomDocument &doc ) const;
|
||||||
|
//! Reads configuration from the given DOM element
|
||||||
|
void readXml( const QDomElement &elem );
|
||||||
|
|
||||||
private:
|
private:
|
||||||
QgsColorRampShader mColorRampShader;
|
QgsColorRampShader mColorRampShader;
|
||||||
};
|
};
|
||||||
@ -222,6 +232,11 @@ class CORE_EXPORT QgsMeshRendererVectorSettings
|
|||||||
//! Sets ratio of the head length of the arrow (range 0-1)
|
//! Sets ratio of the head length of the arrow (range 0-1)
|
||||||
void setArrowHeadLengthRatio( double arrowHeadLengthRatio );
|
void setArrowHeadLengthRatio( double arrowHeadLengthRatio );
|
||||||
|
|
||||||
|
//! Writes configuration to a new DOM element
|
||||||
|
QDomElement writeXml( QDomDocument &doc ) const;
|
||||||
|
//! Reads configuration from the given DOM element
|
||||||
|
void readXml( const QDomElement &elem );
|
||||||
|
|
||||||
private:
|
private:
|
||||||
double mLineWidth = DEFAULT_LINE_WIDTH; //in milimeters
|
double mLineWidth = DEFAULT_LINE_WIDTH; //in milimeters
|
||||||
QColor mColor = Qt::black;
|
QColor mColor = Qt::black;
|
||||||
@ -282,6 +297,11 @@ class CORE_EXPORT QgsMeshRendererSettings
|
|||||||
//! Sets active vector dataset for rendering.
|
//! Sets active vector dataset for rendering.
|
||||||
void setActiveVectorDataset( QgsMeshDatasetIndex index = QgsMeshDatasetIndex() ) { mActiveVectorDataset = index; }
|
void setActiveVectorDataset( QgsMeshDatasetIndex index = QgsMeshDatasetIndex() ) { mActiveVectorDataset = index; }
|
||||||
|
|
||||||
|
//! Writes configuration to a new DOM element
|
||||||
|
QDomElement writeXml( QDomDocument &doc ) const;
|
||||||
|
//! Reads configuration from the given DOM element
|
||||||
|
void readXml( const QDomElement &elem );
|
||||||
|
|
||||||
private:
|
private:
|
||||||
QgsMeshRendererMeshSettings mRendererNativeMeshSettings;
|
QgsMeshRendererMeshSettings mRendererNativeMeshSettings;
|
||||||
QgsMeshRendererMeshSettings mRendererTriangularMeshSettings;
|
QgsMeshRendererMeshSettings mRendererTriangularMeshSettings;
|
||||||
|
@ -28,6 +28,7 @@ originally part of the larger QgsRasterLayer class
|
|||||||
#include "qgscolorrampshader.h"
|
#include "qgscolorrampshader.h"
|
||||||
#include "qgsrasterinterface.h"
|
#include "qgsrasterinterface.h"
|
||||||
#include "qgsrasterminmaxorigin.h"
|
#include "qgsrasterminmaxorigin.h"
|
||||||
|
#include "qgssymbollayerutils.h"
|
||||||
|
|
||||||
#include <cmath>
|
#include <cmath>
|
||||||
QgsColorRampShader::QgsColorRampShader( double minimumValue, double maximumValue, QgsColorRamp *colorRamp, Type type, ClassificationMode classificationMode )
|
QgsColorRampShader::QgsColorRampShader( double minimumValue, double maximumValue, QgsColorRamp *colorRamp, Type type, ClassificationMode classificationMode )
|
||||||
@ -73,7 +74,7 @@ QgsColorRampShader &QgsColorRampShader::operator=( const QgsColorRampShader &oth
|
|||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
QString QgsColorRampShader::colorRampTypeAsQString()
|
QString QgsColorRampShader::colorRampTypeAsQString() const
|
||||||
{
|
{
|
||||||
switch ( mColorRampType )
|
switch ( mColorRampType )
|
||||||
{
|
{
|
||||||
@ -491,3 +492,66 @@ void QgsColorRampShader::legendSymbologyItems( QList< QPair< QString, QColor > >
|
|||||||
symbolItems.push_back( qMakePair( colorRampIt->label, colorRampIt->color ) );
|
symbolItems.push_back( qMakePair( colorRampIt->label, colorRampIt->color ) );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
QDomElement QgsColorRampShader::writeXml( QDomDocument &doc ) const
|
||||||
|
{
|
||||||
|
QDomElement colorRampShaderElem = doc.createElement( QStringLiteral( "colorrampshader" ) );
|
||||||
|
colorRampShaderElem.setAttribute( QStringLiteral( "colorRampType" ), colorRampTypeAsQString() );
|
||||||
|
colorRampShaderElem.setAttribute( QStringLiteral( "classificationMode" ), classificationMode() );
|
||||||
|
colorRampShaderElem.setAttribute( QStringLiteral( "clip" ), clip() );
|
||||||
|
|
||||||
|
// save source color ramp
|
||||||
|
if ( sourceColorRamp() )
|
||||||
|
{
|
||||||
|
QDomElement colorRampElem = QgsSymbolLayerUtils::saveColorRamp( QStringLiteral( "[source]" ), sourceColorRamp(), doc );
|
||||||
|
colorRampShaderElem.appendChild( colorRampElem );
|
||||||
|
}
|
||||||
|
|
||||||
|
//items
|
||||||
|
QList<QgsColorRampShader::ColorRampItem> itemList = colorRampItemList();
|
||||||
|
QList<QgsColorRampShader::ColorRampItem>::const_iterator itemIt = itemList.constBegin();
|
||||||
|
for ( ; itemIt != itemList.constEnd(); ++itemIt )
|
||||||
|
{
|
||||||
|
QDomElement itemElem = doc.createElement( QStringLiteral( "item" ) );
|
||||||
|
itemElem.setAttribute( QStringLiteral( "label" ), itemIt->label );
|
||||||
|
itemElem.setAttribute( QStringLiteral( "value" ), QgsRasterBlock::printValue( itemIt->value ) );
|
||||||
|
itemElem.setAttribute( QStringLiteral( "color" ), itemIt->color.name() );
|
||||||
|
itemElem.setAttribute( QStringLiteral( "alpha" ), itemIt->color.alpha() );
|
||||||
|
colorRampShaderElem.appendChild( itemElem );
|
||||||
|
}
|
||||||
|
return colorRampShaderElem;
|
||||||
|
}
|
||||||
|
|
||||||
|
void QgsColorRampShader::readXml( const QDomElement &colorRampShaderElem )
|
||||||
|
{
|
||||||
|
// try to load color ramp (optional)
|
||||||
|
QDomElement sourceColorRampElem = colorRampShaderElem.firstChildElement( QStringLiteral( "colorramp" ) );
|
||||||
|
if ( !sourceColorRampElem.isNull() && sourceColorRampElem.attribute( QStringLiteral( "name" ) ) == QLatin1String( "[source]" ) )
|
||||||
|
{
|
||||||
|
setSourceColorRamp( QgsSymbolLayerUtils::loadColorRamp( sourceColorRampElem ) );
|
||||||
|
}
|
||||||
|
|
||||||
|
setColorRampType( colorRampShaderElem.attribute( QStringLiteral( "colorRampType" ), QStringLiteral( "INTERPOLATED" ) ) );
|
||||||
|
setClassificationMode( static_cast< QgsColorRampShader::ClassificationMode >( colorRampShaderElem.attribute( QStringLiteral( "classificationMode" ), QStringLiteral( "1" ) ).toInt() ) );
|
||||||
|
setClip( colorRampShaderElem.attribute( QStringLiteral( "clip" ), QStringLiteral( "0" ) ) == QLatin1String( "1" ) );
|
||||||
|
|
||||||
|
QList<QgsColorRampShader::ColorRampItem> itemList;
|
||||||
|
QDomElement itemElem;
|
||||||
|
QString itemLabel;
|
||||||
|
double itemValue;
|
||||||
|
QColor itemColor;
|
||||||
|
|
||||||
|
QDomNodeList itemNodeList = colorRampShaderElem.elementsByTagName( QStringLiteral( "item" ) );
|
||||||
|
itemList.reserve( itemNodeList.size() );
|
||||||
|
for ( int i = 0; i < itemNodeList.size(); ++i )
|
||||||
|
{
|
||||||
|
itemElem = itemNodeList.at( i ).toElement();
|
||||||
|
itemValue = itemElem.attribute( QStringLiteral( "value" ) ).toDouble();
|
||||||
|
itemLabel = itemElem.attribute( QStringLiteral( "label" ) );
|
||||||
|
itemColor.setNamedColor( itemElem.attribute( QStringLiteral( "color" ) ) );
|
||||||
|
itemColor.setAlpha( itemElem.attribute( QStringLiteral( "alpha" ), QStringLiteral( "255" ) ).toInt() );
|
||||||
|
|
||||||
|
itemList.push_back( QgsColorRampShader::ColorRampItem( itemValue, itemColor, itemLabel ) );
|
||||||
|
}
|
||||||
|
setColorRampItemList( itemList );
|
||||||
|
}
|
||||||
|
@ -108,7 +108,7 @@ class CORE_EXPORT QgsColorRampShader : public QgsRasterShaderFunction
|
|||||||
Type colorRampType() const { return mColorRampType; }
|
Type colorRampType() const { return mColorRampType; }
|
||||||
|
|
||||||
//! Returns the color ramp type as a string.
|
//! Returns the color ramp type as a string.
|
||||||
QString colorRampTypeAsQString();
|
QString colorRampTypeAsQString() const;
|
||||||
|
|
||||||
//! Sets a custom colormap
|
//! Sets a custom colormap
|
||||||
void setColorRampItemList( const QList<QgsColorRampShader::ColorRampItem> &list ); //TODO: sort on set
|
void setColorRampItemList( const QList<QgsColorRampShader::ColorRampItem> &list ); //TODO: sort on set
|
||||||
@ -167,6 +167,18 @@ class CORE_EXPORT QgsColorRampShader : public QgsRasterShaderFunction
|
|||||||
|
|
||||||
void legendSymbologyItems( QList< QPair< QString, QColor > > &symbolItems SIP_OUT ) const override;
|
void legendSymbologyItems( QList< QPair< QString, QColor > > &symbolItems SIP_OUT ) const override;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Writes configuration to a new DOM element
|
||||||
|
* \since QGIS 3.4
|
||||||
|
*/
|
||||||
|
QDomElement writeXml( QDomDocument &doc ) const;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Reads configuration from the given DOM element
|
||||||
|
* \since QGIS 3.4
|
||||||
|
*/
|
||||||
|
void readXml( const QDomElement &elem );
|
||||||
|
|
||||||
//! Sets classification mode
|
//! Sets classification mode
|
||||||
void setClassificationMode( ClassificationMode classificationMode ) { mClassificationMode = classificationMode; }
|
void setClassificationMode( ClassificationMode classificationMode ) { mClassificationMode = classificationMode; }
|
||||||
|
|
||||||
|
@ -99,31 +99,7 @@ void QgsRasterShader::writeXml( QDomDocument &doc, QDomElement &parent ) const
|
|||||||
QgsColorRampShader *colorRampShader = dynamic_cast<QgsColorRampShader *>( mRasterShaderFunction.get() );
|
QgsColorRampShader *colorRampShader = dynamic_cast<QgsColorRampShader *>( mRasterShaderFunction.get() );
|
||||||
if ( colorRampShader )
|
if ( colorRampShader )
|
||||||
{
|
{
|
||||||
QDomElement colorRampShaderElem = doc.createElement( QStringLiteral( "colorrampshader" ) );
|
rasterShaderElem.appendChild( colorRampShader->writeXml( doc ) );
|
||||||
colorRampShaderElem.setAttribute( QStringLiteral( "colorRampType" ), colorRampShader->colorRampTypeAsQString() );
|
|
||||||
colorRampShaderElem.setAttribute( QStringLiteral( "classificationMode" ), colorRampShader->classificationMode() );
|
|
||||||
colorRampShaderElem.setAttribute( QStringLiteral( "clip" ), colorRampShader->clip() );
|
|
||||||
|
|
||||||
// save source color ramp
|
|
||||||
if ( colorRampShader->sourceColorRamp() )
|
|
||||||
{
|
|
||||||
QDomElement colorRampElem = QgsSymbolLayerUtils::saveColorRamp( QStringLiteral( "[source]" ), colorRampShader->sourceColorRamp(), doc );
|
|
||||||
colorRampShaderElem.appendChild( colorRampElem );
|
|
||||||
}
|
|
||||||
|
|
||||||
//items
|
|
||||||
QList<QgsColorRampShader::ColorRampItem> itemList = colorRampShader->colorRampItemList();
|
|
||||||
QList<QgsColorRampShader::ColorRampItem>::const_iterator itemIt = itemList.constBegin();
|
|
||||||
for ( ; itemIt != itemList.constEnd(); ++itemIt )
|
|
||||||
{
|
|
||||||
QDomElement itemElem = doc.createElement( QStringLiteral( "item" ) );
|
|
||||||
itemElem.setAttribute( QStringLiteral( "label" ), itemIt->label );
|
|
||||||
itemElem.setAttribute( QStringLiteral( "value" ), QgsRasterBlock::printValue( itemIt->value ) );
|
|
||||||
itemElem.setAttribute( QStringLiteral( "color" ), itemIt->color.name() );
|
|
||||||
itemElem.setAttribute( QStringLiteral( "alpha" ), itemIt->color.alpha() );
|
|
||||||
colorRampShaderElem.appendChild( itemElem );
|
|
||||||
}
|
|
||||||
rasterShaderElem.appendChild( colorRampShaderElem );
|
|
||||||
}
|
}
|
||||||
parent.appendChild( rasterShaderElem );
|
parent.appendChild( rasterShaderElem );
|
||||||
}
|
}
|
||||||
@ -135,37 +111,7 @@ void QgsRasterShader::readXml( const QDomElement &elem )
|
|||||||
if ( !colorRampShaderElem.isNull() )
|
if ( !colorRampShaderElem.isNull() )
|
||||||
{
|
{
|
||||||
QgsColorRampShader *colorRampShader = new QgsColorRampShader();
|
QgsColorRampShader *colorRampShader = new QgsColorRampShader();
|
||||||
|
colorRampShader->readXml( colorRampShaderElem );
|
||||||
// try to load color ramp (optional)
|
|
||||||
QDomElement sourceColorRampElem = colorRampShaderElem.firstChildElement( QStringLiteral( "colorramp" ) );
|
|
||||||
if ( !sourceColorRampElem.isNull() && sourceColorRampElem.attribute( QStringLiteral( "name" ) ) == QLatin1String( "[source]" ) )
|
|
||||||
{
|
|
||||||
colorRampShader->setSourceColorRamp( QgsSymbolLayerUtils::loadColorRamp( sourceColorRampElem ) );
|
|
||||||
}
|
|
||||||
|
|
||||||
colorRampShader->setColorRampType( colorRampShaderElem.attribute( QStringLiteral( "colorRampType" ), QStringLiteral( "INTERPOLATED" ) ) );
|
|
||||||
colorRampShader->setClassificationMode( static_cast< QgsColorRampShader::ClassificationMode >( colorRampShaderElem.attribute( QStringLiteral( "classificationMode" ), QStringLiteral( "1" ) ).toInt() ) );
|
|
||||||
colorRampShader->setClip( colorRampShaderElem.attribute( QStringLiteral( "clip" ), QStringLiteral( "0" ) ) == QLatin1String( "1" ) );
|
|
||||||
|
|
||||||
QList<QgsColorRampShader::ColorRampItem> itemList;
|
|
||||||
QDomElement itemElem;
|
|
||||||
QString itemLabel;
|
|
||||||
double itemValue;
|
|
||||||
QColor itemColor;
|
|
||||||
|
|
||||||
QDomNodeList itemNodeList = colorRampShaderElem.elementsByTagName( QStringLiteral( "item" ) );
|
|
||||||
itemList.reserve( itemNodeList.size() );
|
|
||||||
for ( int i = 0; i < itemNodeList.size(); ++i )
|
|
||||||
{
|
|
||||||
itemElem = itemNodeList.at( i ).toElement();
|
|
||||||
itemValue = itemElem.attribute( QStringLiteral( "value" ) ).toDouble();
|
|
||||||
itemLabel = itemElem.attribute( QStringLiteral( "label" ) );
|
|
||||||
itemColor.setNamedColor( itemElem.attribute( QStringLiteral( "color" ) ) );
|
|
||||||
itemColor.setAlpha( itemElem.attribute( QStringLiteral( "alpha" ), QStringLiteral( "255" ) ).toInt() );
|
|
||||||
|
|
||||||
itemList.push_back( QgsColorRampShader::ColorRampItem( itemValue, itemColor, itemLabel ) );
|
|
||||||
}
|
|
||||||
colorRampShader->setColorRampItemList( itemList );
|
|
||||||
setRasterShaderFunction( colorRampShader );
|
setRasterShaderFunction( colorRampShader );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user