Skip to content
Permalink
Browse files

Merge pull request #36427 from signedav/ressource_expression

[Server] Expression override for online resource in service capabilities
  • Loading branch information
m-kuhn committed May 15, 2020
2 parents ad3c1cd + 54739e0 commit bf485ec59a5cc6057ce778bca931f6f9e2f65018
@@ -55,6 +55,13 @@ open within the main QGIS application.
AvoidIntersectionsLayers,
};

enum DataDefinedServerProperty
{
NoProperty,
AllProperties,
WMSOnlineResource,
};

static QgsProject *instance();
%Docstring
Returns the QgsProject singleton instance
@@ -419,7 +426,6 @@ implying a hierarchy of keys and corresponding values
double readDoubleEntry( const QString &scope, const QString &key, double def = 0, bool *ok = 0 ) const;
bool readBoolEntry( const QString &scope, const QString &key, bool def = false, bool *ok = 0 ) const;


bool removeEntry( const QString &scope, const QString &key );
%Docstring
Remove the given key
@@ -1716,6 +1722,22 @@ Registers the objects that require translation into the ``translationContext``.
So there can be created a ts file with these values.

.. versionadded:: 3.4
%End

void setDataDefinedServerProperties( const QgsPropertyCollection &properties );
%Docstring
Sets the data defined properties used for overrides in user defined server
parameters to ``properties``

.. versionadded:: 3.14
%End

QgsPropertyCollection dataDefinedServerProperties() const;
%Docstring
Returns the data defined properties used for overrides in user defined server
parameters

.. versionadded:: 3.14
%End

};
@@ -445,6 +445,9 @@ QgsProjectProperties::QgsProjectProperties( QgsMapCanvas *mapCanvas, QWidget *pa
mWMSUrlLineEdit->setText( QgsProject::instance()->readEntry( QStringLiteral( "WMSUrl" ), QStringLiteral( "/" ), QString() ) );
mWMSKeywordList->setText( QgsProject::instance()->readListEntry( QStringLiteral( "WMSKeywordList" ), QStringLiteral( "/" ) ).join( QStringLiteral( ", " ) ) );

mWMSOnlineResourceExpressionButton->registerExpressionContextGenerator( this );
mWMSOnlineResourceExpressionButton->setToProperty( QgsProject::instance()->dataDefinedServerProperties().property( QgsProject::DataDefinedServerProperty::WMSOnlineResource ) );

// WMS Name validator
QValidator *shortNameValidator = new QRegExpValidator( QgsApplication::shortNameRegExp(), this );
mWMSName->setValidator( shortNameValidator );
@@ -994,6 +997,16 @@ void QgsProjectProperties::setSelectedCrs( const QgsCoordinateReferenceSystem &c
crsChanged( projectionSelector->crs() );
}

QgsExpressionContext QgsProjectProperties::createExpressionContext() const
{
QgsExpressionContext context;
context
<< QgsExpressionContextUtils::globalScope()
<< QgsExpressionContextUtils::projectScope( QgsProject::instance() );

return context;
}

void QgsProjectProperties::apply()
{
mMapCanvas->enableMapTileRendering( mMapTileRenderingCheckBox->isChecked() );
@@ -1172,6 +1185,10 @@ void QgsProjectProperties::apply()
QgsProject::instance()->writeEntry( QStringLiteral( "WMSOnlineResource" ), QStringLiteral( "/" ), mWMSOnlineResourceLineEdit->text() );
QgsProject::instance()->writeEntry( QStringLiteral( "WMSUrl" ), QStringLiteral( "/" ), mWMSUrlLineEdit->text() );

QgsPropertyCollection propertyCollection = QgsProject::instance()->dataDefinedServerProperties();
propertyCollection.setProperty( QgsProject::DataDefinedServerProperty::WMSOnlineResource, mWMSOnlineResourceExpressionButton->toProperty() );
QgsProject::instance()->setDataDefinedServerProperties( propertyCollection );

// WMS Contact Position
int contactPositionIndex = mWMSContactPositionCb->currentIndex();
QString contactPositionText = mWMSContactPositionCb->currentText();
@@ -42,7 +42,7 @@ class QgsBearingNumericFormat;
\note actual state is stored in QgsProject singleton instance
*/
class APP_EXPORT QgsProjectProperties : public QgsOptionsDialogBase, private Ui::QgsProjectPropertiesBase
class APP_EXPORT QgsProjectProperties : public QgsOptionsDialogBase, private Ui::QgsProjectPropertiesBase, public QgsExpressionContextGenerator
{
Q_OBJECT

@@ -65,6 +65,7 @@ class APP_EXPORT QgsProjectProperties : public QgsOptionsDialogBase, private Ui:
*/
void setSelectedCrs( const QgsCoordinateReferenceSystem &crs );

QgsExpressionContext createExpressionContext() const override;
public slots:

/**
@@ -593,6 +593,16 @@ void QgsProject::registerTranslatableObjects( QgsTranslationContext *translation
}
}

void QgsProject::setDataDefinedServerProperties( const QgsPropertyCollection &properties )
{
mDataDefinedServerProperties = properties;
}

QgsPropertyCollection QgsProject::dataDefinedServerProperties() const
{
return mDataDefinedServerProperties;
}

void QgsProject::setFileName( const QString &name )
{
if ( name == mFile.fileName() )
@@ -883,6 +893,26 @@ void _getProperties( const QDomDocument &doc, QgsProjectPropertyKey &project_pro
}
}

/**
Returns the data defined server properties collection found in "doc" to "dataDefinedServerProperties".
\param doc xml document
\param dataDefinedServerProperties property collection of the server overrides
\since QGIS 3.14
**/
QgsPropertyCollection getDataDefinedServerProperties( const QDomDocument &doc, const QgsPropertiesDefinition &dataDefinedServerPropertyDefinitions )
{
QgsPropertyCollection ddServerProperties;
// Read data defined server properties
QDomElement ddElem = doc.documentElement().firstChildElement( QStringLiteral( "dataDefinedServerProperties" ) );
if ( !ddElem.isNull() )
{
if ( !ddServerProperties.readXml( ddElem, dataDefinedServerPropertyDefinitions ) )
{
QgsDebugMsg( QStringLiteral( "dataDefinedServerProperties.readXml() failed" ) );
}
}
return ddServerProperties;
}

/**
Get the project title
@@ -1278,6 +1308,9 @@ bool QgsProject::readProjectFile( const QString &filename, QgsProject::ReadFlags
// now get any properties
_getProperties( *doc, mProperties );

// now get the data defined server properties
mDataDefinedServerProperties = getDataDefinedServerProperties( *doc, dataDefinedServerPropertyDefinitions() );

QgsDebugMsgLevel( QString::number( mProperties.count() ) + " properties read", 2 );

#if 0
@@ -2198,6 +2231,10 @@ bool QgsProject::writeProjectFile( const QString &filename )
mProperties.writeXml( QStringLiteral( "properties" ), qgisNode, *doc );
}

QDomElement ddElem = doc->createElement( QStringLiteral( "dataDefinedServerProperties" ) );
mDataDefinedServerProperties.writeXml( ddElem, dataDefinedServerPropertyDefinitions() );
qgisNode.appendChild( ddElem );

mMapThemeCollection->writeXml( *doc );

mTransformContext.writeXml( qgisNode, context );
@@ -2477,7 +2514,6 @@ bool QgsProject::readBoolEntry( const QString &scope, const QString &key, bool d
return def;
}


bool QgsProject::removeEntry( const QString &scope, const QString &key )
{
if ( findKey_( scope, key, mProperties ) )
@@ -3365,6 +3401,18 @@ bool QgsProject::saveAuxiliaryStorage( const QString &filename )
}
}

QgsPropertiesDefinition &QgsProject::dataDefinedServerPropertyDefinitions()
{
static QgsPropertiesDefinition sPropertyDefinitions
{
{
QgsProject::DataDefinedServerProperty::WMSOnlineResource,
QgsPropertyDefinition( "WMSOnlineResource", QObject::tr( "WMS Online Resource" ), QgsPropertyDefinition::String )
},
};
return sPropertyDefinitions;
}

const QgsAuxiliaryStorage *QgsProject::auxiliaryStorage() const
{
return mAuxiliaryStorage.get();
@@ -144,6 +144,21 @@ class CORE_EXPORT QgsProject : public QObject, public QgsExpressionContextGenera
};
Q_ENUM( AvoidIntersectionsMode )

/**
* Data defined properties.
* Overrides of user defined server parameters are stored in a
* property collection and they can be retrieved using the
* indexes specified in this enum.
*
* \since QGIS 3.14
*/
enum DataDefinedServerProperty
{
NoProperty = 0, //!< No property
AllProperties = 1, //!< All properties for item
WMSOnlineResource = 2, //!< Alias
};

//! Returns the QgsProject singleton instance
static QgsProject *instance();

@@ -436,7 +451,6 @@ class CORE_EXPORT QgsProject : public QObject, public QgsExpressionContextGenera
double readDoubleEntry( const QString &scope, const QString &key, double def = 0, bool *ok = nullptr ) const;
bool readBoolEntry( const QString &scope, const QString &key, bool def = false, bool *ok = nullptr ) const;


//! Remove the given key
bool removeEntry( const QString &scope, const QString &key );

@@ -1742,6 +1756,22 @@ class CORE_EXPORT QgsProject : public QObject, public QgsExpressionContextGenera
*/
void registerTranslatableObjects( QgsTranslationContext *translationContext );

/**
* Sets the data defined properties used for overrides in user defined server
* parameters to \a properties
*
* \since QGIS 3.14
*/
void setDataDefinedServerProperties( const QgsPropertyCollection &properties );

/**
* Returns the data defined properties used for overrides in user defined server
* parameters
*
* \since QGIS 3.14
*/
QgsPropertyCollection dataDefinedServerProperties() const;

private slots:
void onMapLayersAdded( const QList<QgsMapLayer *> &layers );
void onMapLayersRemoved( const QList<QgsMapLayer *> &layers );
@@ -1820,6 +1850,9 @@ class CORE_EXPORT QgsProject : public QObject, public QgsExpressionContextGenera
//! Save auxiliary storage to database
bool saveAuxiliaryStorage( const QString &filename = QString() );

//! Returns the property definition used for a data defined server property
static QgsPropertiesDefinition &dataDefinedServerPropertyDefinitions();

std::unique_ptr< QgsMapLayerStore > mLayerStore;

QString mErrorMessage;
@@ -1889,6 +1922,8 @@ class CORE_EXPORT QgsProject : public QObject, public QgsExpressionContextGenera
int mDirtyBlockCount = 0;
bool mTrustLayerMetadata = false;

QgsPropertyCollection mDataDefinedServerProperties;

QgsCoordinateTransformContext mTransformContext;

QgsProjectMetadata mMetadata;
@@ -218,7 +218,6 @@ bool QgsProjectPropertyValue::readXml( const QDomNode &keyNode )
value_ = QVariant( subkeyElement.text() ).toULongLong();
break;
#endif

default :
QgsDebugMsg( QStringLiteral( "unsupported value type %1 .. not properly translated to QVariant" ).arg( typeString ) );
}
@@ -65,7 +65,16 @@ QStringList QgsServerProjectUtils::owsServiceKeywords( const QgsProject &project

QString QgsServerProjectUtils::owsServiceOnlineResource( const QgsProject &project )
{
return project.readEntry( QStringLiteral( "WMSOnlineResource" ), QStringLiteral( "/" ) );
QString wmsOnlineResource = project.readEntry( QStringLiteral( "WMSOnlineResource" ), QStringLiteral( "/" ) );

QgsProperty wmsOnlineResourceProperty = project.dataDefinedServerProperties().property( QgsProject::DataDefinedServerProperty::WMSOnlineResource );
if ( wmsOnlineResourceProperty.isActive() && ! wmsOnlineResourceProperty.expressionString().isEmpty() )
{
QgsExpressionContext context = project.createExpressionContext();
return wmsOnlineResourceProperty.valueAsString( context, wmsOnlineResource );
}

return wmsOnlineResource;
}

QString QgsServerProjectUtils::owsServiceContactOrganization( const QgsProject &project )

0 comments on commit bf485ec

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