Skip to content
Permalink
Browse files

remove const for QgsReadWriteContext to allow bringing up error messages

  • Loading branch information
3nids committed Feb 28, 2018
1 parent f271300 commit 47ab9b89e70820fdd375e6bfdfc6878364e2b04d
@@ -252,7 +252,7 @@ Set type of feature form pop-up suppression after feature creation (overrides ap
%End


void readXml( const QDomNode &node, const QgsReadWriteContext &context );
void readXml( const QDomNode &node, QgsReadWriteContext &context );
%Docstring
Read XML information
Deserialize on project load
@@ -29,7 +29,7 @@ files also store the layer tree info for the exported layers, including group in
%Docstring
Loads the QLR at path into QGIS. New layers are added to given project into layer tree specified by rootGroup
%End
static bool loadLayerDefinition( QDomDocument doc, QgsProject *project, QgsLayerTreeGroup *rootGroup, QString &errorMessage /Out/, const QgsReadWriteContext &context );
static bool loadLayerDefinition( QDomDocument doc, QgsProject *project, QgsLayerTreeGroup *rootGroup, QString &errorMessage /Out/, QgsReadWriteContext &context );
%Docstring
Loads the QLR from the XML document. New layers are added to given project into layer tree specified by rootGroup
%End
@@ -54,7 +54,7 @@ This is a low-level routine that does not write layer tree.
.. seealso:: :py:func:`exportLayerDefinition`
%End

static QList<QgsMapLayer *> loadLayerDefinitionLayers( QDomDocument &document, const QgsReadWriteContext &context ) /Factory/;
static QList<QgsMapLayer *> loadLayerDefinitionLayers( QDomDocument &document, QgsReadWriteContext &context ) /Factory/;
%Docstring
Creates new layers from a layer definition document.
This is a low-level routine that does not resolve layer ID conflicts, dependencies and joins
@@ -452,7 +452,7 @@ Returns true if the layer is considered a spatial layer, ie it has some form of
.. versionadded:: 2.16
%End

bool readLayerXml( const QDomElement &layerElement, const QgsReadWriteContext &context );
bool readLayerXml( const QDomElement &layerElement, QgsReadWriteContext &context );
%Docstring
Sets state from Dom document

@@ -825,7 +825,7 @@ the SLD file could not be loaded



virtual bool readSymbology( const QDomNode &node, QString &errorMessage, const QgsReadWriteContext &context ) = 0;
virtual bool readSymbology( const QDomNode &node, QString &errorMessage, QgsReadWriteContext &context ) = 0;
%Docstring
Read the symbology for the current layer from the Dom node supplied.

@@ -836,7 +836,7 @@ Read the symbology for the current layer from the Dom node supplied.
:return: true in case of success.
%End

virtual bool readStyle( const QDomNode &node, QString &errorMessage, const QgsReadWriteContext &context );
virtual bool readStyle( const QDomNode &node, QString &errorMessage, QgsReadWriteContext &context );
%Docstring
Read the style for the current layer from the Dom node supplied.

@@ -1361,7 +1361,7 @@ Set the extent
Set whether layer is valid or not - should be used in constructor.
%End

virtual bool readXml( const QDomNode &layer_node, const QgsReadWriteContext &context );
virtual bool readXml( const QDomNode &layer_node, QgsReadWriteContext &context );
%Docstring
Called by readLayerXML(), used by children to read state specific to them from
project files.
@@ -728,7 +728,7 @@ Return the provider type for this layer
virtual QString sourceName() const;


virtual bool readXml( const QDomNode &layer_node, const QgsReadWriteContext &context );
virtual bool readXml( const QDomNode &layer_node, QgsReadWriteContext &context );

%Docstring
Reads vector layer specific state from project file Dom node.
@@ -849,7 +849,7 @@ Returns the current auxiliary layer.
%End


virtual bool readSymbology( const QDomNode &layerNode, QString &errorMessage, const QgsReadWriteContext &context );
virtual bool readSymbology( const QDomNode &layerNode, QString &errorMessage, QgsReadWriteContext &context );

%Docstring
Read the symbology for the current layer from the Dom node supplied.
@@ -861,7 +861,7 @@ Read the symbology for the current layer from the Dom node supplied.
:return: true in case of success.
%End

virtual bool readStyle( const QDomNode &node, QString &errorMessage, const QgsReadWriteContext &context );
virtual bool readStyle( const QDomNode &node, QString &errorMessage, QgsReadWriteContext &context );

%Docstring
Read the style for the current layer from the Dom node supplied.
@@ -354,19 +354,19 @@ Time stamp of data source in the moment when data/metadata were loaded by provid
void showStatusMessage( const QString &message );

protected:
virtual bool readSymbology( const QDomNode &node, QString &errorMessage, const QgsReadWriteContext &context );
virtual bool readSymbology( const QDomNode &node, QString &errorMessage, QgsReadWriteContext &context );

%Docstring
Read the symbology for the current layer from the Dom node supplied
%End

virtual bool readStyle( const QDomNode &node, QString &errorMessage, const QgsReadWriteContext &context );
virtual bool readStyle( const QDomNode &node, QString &errorMessage, QgsReadWriteContext &context );

%Docstring
Read the style information for the current layer from the Dom node supplied
%End

virtual bool readXml( const QDomNode &layer_node, const QgsReadWriteContext &context );
virtual bool readXml( const QDomNode &layer_node, QgsReadWriteContext &context );

%Docstring
Reads layer specific state from project file Dom node
@@ -8928,8 +8928,10 @@ void QgisApp::duplicateVectorStyle( QgsVectorLayer *srcLayer, QgsVectorLayer *de
rootNode.setAttribute( QStringLiteral( "version" ), Qgis::QGIS_VERSION );
doc.appendChild( rootNode );
QString errorMsg;
srcLayer->writeSymbology( rootNode, doc, errorMsg, QgsReadWriteContext() );
destLayer->readSymbology( rootNode, errorMsg, QgsReadWriteContext() );
QgsReadWriteContext writeContext = QgsReadWriteContext();
srcLayer->writeSymbology( rootNode, doc, errorMsg, writeContext );
QgsReadWriteContext readContext = QgsReadWriteContext();
destLayer->readSymbology( rootNode, errorMsg, readContext );
}
}

@@ -542,14 +542,16 @@ QgsMapLayerStyleCommand::QgsMapLayerStyleCommand( QgsMapLayer *layer, const QStr
void QgsMapLayerStyleCommand::undo()
{
QString error;
mLayer->readStyle( mLastState, error, QgsReadWriteContext() );
QgsReadWriteContext context = QgsReadWriteContext();
mLayer->readStyle( mLastState, error, context );
mLayer->triggerRepaint();
}

void QgsMapLayerStyleCommand::redo()
{
QString error;
mLayer->readStyle( mXml, error, QgsReadWriteContext() );
QgsReadWriteContext context = QgsReadWriteContext();
mLayer->readStyle( mXml, error, context );
mLayer->triggerRepaint();
}

@@ -258,7 +258,7 @@ void QgsEditFormConfig::setSuppress( QgsEditFormConfig::FeatureFormSuppress s )
d->mSuppressForm = s;
}

void QgsEditFormConfig::readXml( const QDomNode &node, const QgsReadWriteContext &context )
void QgsEditFormConfig::readXml( const QDomNode &node, QgsReadWriteContext &context )
{
d.detach();

@@ -273,7 +273,7 @@ class CORE_EXPORT QgsEditFormConfig
* Read XML information
* Deserialize on project load
*/
void readXml( const QDomNode &node, const QgsReadWriteContext &context );
void readXml( const QDomNode &node, QgsReadWriteContext &context );

/**
* Write XML information
@@ -56,7 +56,7 @@ bool QgsLayerDefinition::loadLayerDefinition( const QString &path, QgsProject *p
return loadLayerDefinition( doc, project, rootGroup, errorMessage, context );
}

bool QgsLayerDefinition::loadLayerDefinition( QDomDocument doc, QgsProject *project, QgsLayerTreeGroup *rootGroup, QString &errorMessage, const QgsReadWriteContext &context )
bool QgsLayerDefinition::loadLayerDefinition( QDomDocument doc, QgsProject *project, QgsLayerTreeGroup *rootGroup, QString &errorMessage, QgsReadWriteContext &context )
{
Q_UNUSED( errorMessage );

@@ -238,7 +238,7 @@ QDomDocument QgsLayerDefinition::exportLayerDefinitionLayers( const QList<QgsMap
return doc;
}

QList<QgsMapLayer *> QgsLayerDefinition::loadLayerDefinitionLayers( QDomDocument &document, const QgsReadWriteContext &context )
QList<QgsMapLayer *> QgsLayerDefinition::loadLayerDefinitionLayers( QDomDocument &document, QgsReadWriteContext &context )
{
QList<QgsMapLayer *> layers;
QDomNodeList layernodes = document.elementsByTagName( QStringLiteral( "maplayer" ) );
@@ -45,7 +45,7 @@ class CORE_EXPORT QgsLayerDefinition
//! Loads the QLR at path into QGIS. New layers are added to given project into layer tree specified by rootGroup
static bool loadLayerDefinition( const QString &path, QgsProject *project, QgsLayerTreeGroup *rootGroup, QString &errorMessage SIP_OUT );
//! Loads the QLR from the XML document. New layers are added to given project into layer tree specified by rootGroup
static bool loadLayerDefinition( QDomDocument doc, QgsProject *project, QgsLayerTreeGroup *rootGroup, QString &errorMessage SIP_OUT, const QgsReadWriteContext &context );
static bool loadLayerDefinition( QDomDocument doc, QgsProject *project, QgsLayerTreeGroup *rootGroup, QString &errorMessage SIP_OUT, QgsReadWriteContext &context );
//! Export the selected layer tree nodes to a QLR file
static bool exportLayerDefinition( QString path, const QList<QgsLayerTreeNode *> &selectedTreeNodes, QString &errorMessage SIP_OUT );
//! Export the selected layer tree nodes to a QLR-XML document
@@ -67,7 +67,7 @@ class CORE_EXPORT QgsLayerDefinition
* This is a low-level routine that does not resolve layer ID conflicts, dependencies and joins
* \see loadLayerDefinition()
*/
static QList<QgsMapLayer *> loadLayerDefinitionLayers( QDomDocument &document, const QgsReadWriteContext &context ) SIP_FACTORY;
static QList<QgsMapLayer *> loadLayerDefinitionLayers( QDomDocument &document, QgsReadWriteContext &context ) SIP_FACTORY;

/**
* Creates new layers from a layer definition file (.QLR)
@@ -202,7 +202,7 @@ QPainter::CompositionMode QgsMapLayer::blendMode() const
}


bool QgsMapLayer::readLayerXml( const QDomElement &layerElement, const QgsReadWriteContext &context )
bool QgsMapLayer::readLayerXml( const QDomElement &layerElement, QgsReadWriteContext &context )
{
bool layerError;

@@ -559,7 +559,7 @@ bool QgsMapLayer::readLayerXml( const QDomElement &layerElement, const QgsReadWr
} // bool QgsMapLayer::readLayerXML


bool QgsMapLayer::readXml( const QDomNode &layer_node, const QgsReadWriteContext &context )
bool QgsMapLayer::readXml( const QDomNode &layer_node, QgsReadWriteContext &context )
{
Q_UNUSED( layer_node );
Q_UNUSED( context );
@@ -1310,7 +1310,8 @@ bool QgsMapLayer::importNamedStyle( QDomDocument &myDocument, QString &myErrorMe
setMinimumScale( myRoot.attribute( QStringLiteral( "minScale" ) ).toDouble() );
}

return readSymbology( myRoot, myErrorMessage, QgsReadWriteContext() ); // TODO: support relative paths in QML?
QgsReadWriteContext context = QgsReadWriteContext();
return readSymbology( myRoot, myErrorMessage, context ); // TODO: support relative paths in QML?
}

void QgsMapLayer::exportNamedMetadata( QDomDocument &doc, QString &errorMsg ) const
@@ -1791,7 +1792,7 @@ QString QgsMapLayer::loadSldStyle( const QString &uri, bool &resultFlag )
return QLatin1String( "" );
}

bool QgsMapLayer::readStyle( const QDomNode &node, QString &errorMessage, const QgsReadWriteContext &context )
bool QgsMapLayer::readStyle( const QDomNode &node, QString &errorMessage, QgsReadWriteContext &context )
{
Q_UNUSED( node );
Q_UNUSED( errorMessage );
@@ -460,7 +460,7 @@ class CORE_EXPORT QgsMapLayer : public QObject
\returns true if successful
*/
bool readLayerXml( const QDomElement &layerElement, const QgsReadWriteContext &context );
bool readLayerXml( const QDomElement &layerElement, QgsReadWriteContext &context );

/**
* Stores state in Dom node
@@ -763,7 +763,7 @@ class CORE_EXPORT QgsMapLayer : public QObject
* \param context reading context (used for transform from relative to absolute paths)
* \returns true in case of success.
*/
virtual bool readSymbology( const QDomNode &node, QString &errorMessage, const QgsReadWriteContext &context ) = 0;
virtual bool readSymbology( const QDomNode &node, QString &errorMessage, QgsReadWriteContext &context ) = 0;

/**
* Read the style for the current layer from the Dom node supplied.
@@ -774,7 +774,7 @@ class CORE_EXPORT QgsMapLayer : public QObject
* \since QGIS 2.16
* \note To be implemented in subclasses. Default implementation does nothing and returns false.
*/
virtual bool readStyle( const QDomNode &node, QString &errorMessage, const QgsReadWriteContext &context );
virtual bool readStyle( const QDomNode &node, QString &errorMessage, QgsReadWriteContext &context );

/**
* Write the symbology for the layer into the docment provided.
@@ -1180,7 +1180,7 @@ class CORE_EXPORT QgsMapLayer : public QObject
* Called by readLayerXML(), used by children to read state specific to them from
* project files.
*/
virtual bool readXml( const QDomNode &layer_node, const QgsReadWriteContext &context );
virtual bool readXml( const QDomNode &layer_node, QgsReadWriteContext &context );

/**
* Called by writeLayerXML(), used by children to write state specific to them to
@@ -724,7 +724,7 @@ bool QgsProject::_getMapLayers( const QDomDocument &doc, QList<QDomNode> &broken
return returnStatus;
}

bool QgsProject::addLayer( const QDomElement &layerElem, QList<QDomNode> &brokenNodes, const QgsReadWriteContext &context )
bool QgsProject::addLayer( const QDomElement &layerElem, QList<QDomNode> &brokenNodes, QgsReadWriteContext &context )
{
QString type = layerElem.attribute( QStringLiteral( "type" ) );
QgsDebugMsgLevel( "Layer type is " + type, 4 );
@@ -1134,7 +1134,7 @@ class CORE_EXPORT QgsProject : public QObject, public QgsExpressionContextGenera
* Creates layer and adds it to maplayer registry
* \note not available in Python bindings
*/
bool addLayer( const QDomElement &layerElem, QList<QDomNode> &brokenNodes, const QgsReadWriteContext &context ) SIP_SKIP;
bool addLayer( const QDomElement &layerElem, QList<QDomNode> &brokenNodes, QgsReadWriteContext &context ) SIP_SKIP;

//! \note not available in Python bindings
void initializeEmbeddedSubtree( const QString &projectFilePath, QgsLayerTreeGroup *group ) SIP_SKIP;
@@ -1353,7 +1353,7 @@ bool QgsVectorLayer::startEditing()
return true;
}

bool QgsVectorLayer::readXml( const QDomNode &layer_node, const QgsReadWriteContext &context )
bool QgsVectorLayer::readXml( const QDomNode &layer_node, QgsReadWriteContext &context )
{
QgsDebugMsgLevel( QStringLiteral( "Datasource in QgsVectorLayer::readXml: %1" ).arg( mDataSource.toLocal8Bit().data() ), 3 );

@@ -1686,7 +1686,7 @@ void QgsVectorLayer::resolveReferences( QgsProject *project )
}


bool QgsVectorLayer::readSymbology( const QDomNode &layerNode, QString &errorMessage, const QgsReadWriteContext &context )
bool QgsVectorLayer::readSymbology( const QDomNode &layerNode, QString &errorMessage, QgsReadWriteContext &context )
{
if ( !mExpressionFieldBuffer )
mExpressionFieldBuffer = new QgsExpressionFieldBuffer();
@@ -1876,7 +1876,7 @@ bool QgsVectorLayer::readSymbology( const QDomNode &layerNode, QString &errorMes
return true;
}

bool QgsVectorLayer::readStyle( const QDomNode &node, QString &errorMessage, const QgsReadWriteContext &context )
bool QgsVectorLayer::readStyle( const QDomNode &node, QString &errorMessage, QgsReadWriteContext &context )
{
bool result = true;
emit readCustomSymbology( node.toElement(), errorMessage );
@@ -756,7 +756,7 @@ class CORE_EXPORT QgsVectorLayer : public QgsMapLayer, public QgsExpressionConte
* Reads vector layer specific state from project file Dom node.
* \note Called by QgsMapLayer::readXml().
*/
bool readXml( const QDomNode &layer_node, const QgsReadWriteContext &context ) override;
bool readXml( const QDomNode &layer_node, QgsReadWriteContext &context ) override;

/**
* Write vector layer specific state to project file Dom node.
@@ -868,7 +868,7 @@ class CORE_EXPORT QgsVectorLayer : public QgsMapLayer, public QgsExpressionConte
* \param context reading context (used for transform from relative to absolute paths)
* \returns true in case of success.
*/
bool readSymbology( const QDomNode &layerNode, QString &errorMessage, const QgsReadWriteContext &context ) override;
bool readSymbology( const QDomNode &layerNode, QString &errorMessage, QgsReadWriteContext &context ) override;

/**
* Read the style for the current layer from the Dom node supplied.
@@ -877,7 +877,7 @@ class CORE_EXPORT QgsVectorLayer : public QgsMapLayer, public QgsExpressionConte
* \param context reading context (used for transform from relative to absolute paths)
* \returns true in case of success.
*/
bool readStyle( const QDomNode &node, QString &errorMessage, const QgsReadWriteContext &context ) override;
bool readStyle( const QDomNode &node, QString &errorMessage, QgsReadWriteContext &context ) override;

/**
* Write the symbology for the layer into the docment provided.
@@ -1305,7 +1305,7 @@ QImage QgsRasterLayer::previewAsImage( QSize size, const QColor &bgColor, QImage
* @param errorMessage reference to string that will be updated with any error messages
* @return true in case of success.
*/
bool QgsRasterLayer::readSymbology( const QDomNode &layer_node, QString &errorMessage, const QgsReadWriteContext &context )
bool QgsRasterLayer::readSymbology( const QDomNode &layer_node, QString &errorMessage, QgsReadWriteContext &context )
{
Q_UNUSED( errorMessage );
QDomElement rasterRendererElem;
@@ -1397,7 +1397,7 @@ bool QgsRasterLayer::readSymbology( const QDomNode &layer_node, QString &errorMe
return true;
}

bool QgsRasterLayer::readStyle( const QDomNode &node, QString &errorMessage, const QgsReadWriteContext &context )
bool QgsRasterLayer::readStyle( const QDomNode &node, QString &errorMessage, QgsReadWriteContext &context )
{
return readSymbology( node, errorMessage, context );
} //readSymbology
@@ -1408,7 +1408,7 @@ bool QgsRasterLayer::readStyle( const QDomNode &node, QString &errorMessage, con
\note Called by QgsMapLayer::readXml().
*/
bool QgsRasterLayer::readXml( const QDomNode &layer_node, const QgsReadWriteContext &context )
bool QgsRasterLayer::readXml( const QDomNode &layer_node, QgsReadWriteContext &context )
{
QgsDebugMsgLevel( "Entered", 4 );
// Make sure to read the file first so stats etc are initialized properly!
@@ -387,13 +387,13 @@ class CORE_EXPORT QgsRasterLayer : public QgsMapLayer

protected:
//! \brief Read the symbology for the current layer from the Dom node supplied
bool readSymbology( const QDomNode &node, QString &errorMessage, const QgsReadWriteContext &context ) override;
bool readSymbology( const QDomNode &node, QString &errorMessage, QgsReadWriteContext &context ) override;

//! \brief Read the style information for the current layer from the Dom node supplied
bool readStyle( const QDomNode &node, QString &errorMessage, const QgsReadWriteContext &context ) override;
bool readStyle( const QDomNode &node, QString &errorMessage, QgsReadWriteContext &context ) override;

//! \brief Reads layer specific state from project file Dom node
bool readXml( const QDomNode &layer_node, const QgsReadWriteContext &context ) override;
bool readXml( const QDomNode &layer_node, QgsReadWriteContext &context ) override;

//! \brief Write the symbology for the layer into the docment provided
bool writeSymbology( QDomNode &, QDomDocument &doc, QString &errorMessage, const QgsReadWriteContext &context ) const override;
@@ -278,7 +278,8 @@ void TestQgsMapRendererJob::testFourAdjacentTiles()
}

QString errorMsg;
if ( !vectorLayer->readSymbology( qmlDoc.documentElement(), errorMsg, QgsReadWriteContext() ) )
QgsReadWriteContext context = QgsReadWriteContext();
if ( !vectorLayer->readSymbology( qmlDoc.documentElement(), errorMsg, context ) )
{
QFAIL( errorMsg.toLocal8Bit().data() );
}

0 comments on commit 47ab9b8

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