Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
WMSOnlineResource can be defined by an expression. This means it's st…
…ored as a QgsProperty.

Functions to read and write QgsProperty.
  • Loading branch information
signedav committed May 13, 2020
1 parent 7bbfe5a commit 0e4b6b8
Show file tree
Hide file tree
Showing 5 changed files with 210 additions and 146 deletions.
13 changes: 13 additions & 0 deletions python/core/auto_generated/qgsproject.sip.in
Expand Up @@ -401,6 +401,18 @@ Write a string list entry to the project file.
Keys are '/'-delimited entries, implying
a hierarchy of keys and corresponding values

.. note::

The key string must be valid xml tag names in order to be saved to the file.
%End

bool writeEntry( const QString &scope, const QString &key, const QgsProperty &value );
%Docstring
Write a QgsProperty entry to the project file.

Keys are '/'-delimited entries, implying
a hierarchy of keys and corresponding values

.. note::

The key string must be valid xml tag names in order to be saved to the file.
Expand All @@ -418,6 +430,7 @@ implying a hierarchy of keys and corresponding values
int readNumEntry( const QString &scope, const QString &key, int def = 0, bool *ok = 0 ) const;
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;
QgsProperty readPropertyEntry( const QString &scope, const QString &key, QgsProperty def = QgsProperty(), bool *ok = 0 ) const;


bool removeEntry( const QString &scope, const QString &key );
Expand Down
2 changes: 2 additions & 0 deletions src/app/qgsprojectproperties.cpp
Expand Up @@ -442,6 +442,7 @@ QgsProjectProperties::QgsProjectProperties( QgsMapCanvas *mapCanvas, QWidget *pa
mWMSContactPhone->setText( QgsProject::instance()->readEntry( QStringLiteral( "WMSContactPhone" ), QStringLiteral( "/" ), QString() ) );
mWMSAbstract->setPlainText( QgsProject::instance()->readEntry( QStringLiteral( "WMSServiceAbstract" ), QStringLiteral( "/" ), QString() ) );
mWMSOnlineResourceLineEdit->setText( QgsProject::instance()->readEntry( QStringLiteral( "WMSOnlineResource" ), QStringLiteral( "/" ), QString() ) );
mWMSOnlineResourceExpressionButton->setToProperty( QgsProject::instance()->readPropertyEntry( "WMSOnlineResourceExpression", "/" ) );
mWMSUrlLineEdit->setText( QgsProject::instance()->readEntry( QStringLiteral( "WMSUrl" ), QStringLiteral( "/" ), QString() ) );
mWMSKeywordList->setText( QgsProject::instance()->readListEntry( QStringLiteral( "WMSKeywordList" ), QStringLiteral( "/" ) ).join( QStringLiteral( ", " ) ) );

Expand Down Expand Up @@ -1170,6 +1171,7 @@ void QgsProjectProperties::apply()
QgsProject::instance()->writeEntry( QStringLiteral( "WMSContactPhone" ), QStringLiteral( "/" ), mWMSContactPhone->text() );
QgsProject::instance()->writeEntry( QStringLiteral( "WMSServiceAbstract" ), QStringLiteral( "/" ), mWMSAbstract->toPlainText() );
QgsProject::instance()->writeEntry( QStringLiteral( "WMSOnlineResource" ), QStringLiteral( "/" ), mWMSOnlineResourceLineEdit->text() );
QgsProject::instance()->writeEntry( QStringLiteral( "WMSOnlineResourceExpression" ), QStringLiteral( "/" ), mWMSOnlineResourceExpressionButton->toProperty() );
QgsProject::instance()->writeEntry( QStringLiteral( "WMSUrl" ), QStringLiteral( "/" ), mWMSUrlLineEdit->text() );

// WMS Contact Position
Expand Down
30 changes: 30 additions & 0 deletions src/core/qgsproject.cpp
Expand Up @@ -2359,6 +2359,17 @@ bool QgsProject::writeEntry( const QString &scope, const QString &key, const QSt
return success;
}

bool QgsProject::writeEntry( const QString &scope, const QString &key, const QgsProperty &value )
{
bool propertiesModified;
bool success = addKey_( scope, key, &mProperties, value.toVariant(), propertiesModified );

if ( propertiesModified )
setDirty( true );

return success;
}

QStringList QgsProject::readListEntry( const QString &scope,
const QString &key,
const QStringList &def,
Expand Down Expand Up @@ -2477,6 +2488,25 @@ bool QgsProject::readBoolEntry( const QString &scope, const QString &key, bool d
return def;
}

QgsProperty QgsProject::readPropertyEntry( const QString &scope, const QString &key, QgsProperty def, bool *ok ) const
{
QgsProjectProperty *property = findKey_( scope, key, mProperties );

if ( property )
{
QgsProperty qgsproperty;
QVariant value = property->value();
bool loaded = qgsproperty.loadVariant( value );
if ( ok )
*ok = loaded;

if ( loaded )
return qgsproperty;
}

return def;
}


bool QgsProject::removeEntry( const QString &scope, const QString &key )
{
Expand Down
11 changes: 11 additions & 0 deletions src/core/qgsproject.h
Expand Up @@ -423,6 +423,16 @@ class CORE_EXPORT QgsProject : public QObject, public QgsExpressionContextGenera
*/
bool writeEntry( const QString &scope, const QString &key, const QStringList &value );

/**
* Write a QgsProperty entry to the project file.
*
* Keys are '/'-delimited entries, implying
* a hierarchy of keys and corresponding values
*
* \note The key string must be valid xml tag names in order to be saved to the file.
*/
bool writeEntry( const QString &scope, const QString &key, const QgsProperty &value );

/**
* Key value accessors
*
Expand All @@ -435,6 +445,7 @@ class CORE_EXPORT QgsProject : public QObject, public QgsExpressionContextGenera
int readNumEntry( const QString &scope, const QString &key, int def = 0, bool *ok = nullptr ) const;
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;
QgsProperty readPropertyEntry( const QString &scope, const QString &key, QgsProperty def = QgsProperty(), bool *ok = nullptr ) const;


//! Remove the given key
Expand Down

0 comments on commit 0e4b6b8

Please sign in to comment.