Navigation Menu

Skip to content

Commit

Permalink
Add support for adding custom properties to providers
Browse files Browse the repository at this point in the history
  • Loading branch information
m-kuhn committed Jun 3, 2016
1 parent f871544 commit 000eb07
Show file tree
Hide file tree
Showing 5 changed files with 132 additions and 0 deletions.
45 changes: 45 additions & 0 deletions python/core/qgsdataprovider.sip
Expand Up @@ -33,6 +33,19 @@ class QgsDataProvider : QObject
Net
};

/**
* Properties are used to pass custom configuration options into data providers.
* This enum defines a list of custom properties which can be used on different
* providers. It depends on the provider, which properties are supported.
* In addition to these default properties, providers can add their custom properties
* starting from CustomData.
*/
enum ProviderProperty
{
EvaluateDefaultValues, //!< Evaluate default values on provider side when calling QgsVectorDataProvider::defaultValue( int index ) rather than on commit.
CustomData = 3000 //!< Custom properties for 3rd party providers or very provider-specific properties which are not expected to be of interest for other providers can be added starting from this value up.
};

QgsDataProvider( const QString & uri = "" );

/**
Expand Down Expand Up @@ -264,6 +277,38 @@ class QgsDataProvider : QObject
*/
virtual bool leaveUpdateMode();

/**
* Allows setting arbitrary properties on the provider.
* It depends on the provider which properties are supported.
*
* @note added in 2.16
*/
void setProviderProperty( ProviderProperty property, const QVariant& value );

/**
* Allows setting arbitrary properties on the provider.
* It depends on the provider which properties are supported.
*
* @note added in 2.16
*/
// void setProviderProperty( int property, const QVariant& value );

/**
* Get the current value of a certain provider property.
* It depends on the provider which properties are supported.
*
* @note added in 2.16
*/
QVariant providerProperty( ProviderProperty property, const QVariant& defaultValue = QVariant() ) const;

/**
* Get the current value of a certain provider property.
* It depends on the provider which properties are supported.
*
* @note added in 2.16
*/
// QVariant providerProperty( int property , const QVariant& defaultValue ) const;

signals:

/**
Expand Down
1 change: 1 addition & 0 deletions src/core/CMakeLists.txt
Expand Up @@ -102,6 +102,7 @@ SET(QGIS_CORE_SRCS
qgsdataitemprovider.cpp
qgsdataitemproviderregistry.cpp
qgsdatasourceuri.cpp
qgsdataprovider.cpp
qgsdatetimestatisticalsummary.cpp
qgsdatumtransformstore.cpp
qgsdbfilterproxymodel.cpp
Expand Down
38 changes: 38 additions & 0 deletions src/core/qgsdataprovider.cpp
@@ -0,0 +1,38 @@
/***************************************************************************
qgsdataprovider.cpp - DataProvider Interface
--------------------------------------
Date : May 2016
Copyright : (C) 2016 by Matthias Kuhn
email : matthias@opengis.ch
***************************************************************************
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
***************************************************************************/

#include "qgsdataprovider.h"


void QgsDataProvider::setProviderProperty( QgsDataProvider::ProviderProperty property, const QVariant& value )
{
mProviderProperties.insert( property, value );
}

void QgsDataProvider::setProviderProperty( int property, const QVariant& value )
{
mProviderProperties.insert( property, value );
}

QVariant QgsDataProvider::providerProperty( QgsDataProvider::ProviderProperty property, const QVariant& defaultValue ) const
{
return mProviderProperties.value( property, defaultValue );
}

QVariant QgsDataProvider::providerProperty( int property, const QVariant& defaultValue = QVariant() ) const
{
return mProviderProperties.value( property, defaultValue );
}

47 changes: 47 additions & 0 deletions src/core/qgsdataprovider.h
Expand Up @@ -61,6 +61,19 @@ class CORE_EXPORT QgsDataProvider : public QObject
Net = 1 << 3 // Internet source
};

/**
* Properties are used to pass custom configuration options into data providers.
* This enum defines a list of custom properties which can be used on different
* providers. It depends on the provider, which properties are supported.
* In addition to these default properties, providers can add their custom properties
* starting from CustomData.
*/
enum ProviderProperty
{
EvaluateDefaultValues, //!< Evaluate default values on provider side when calling QgsVectorDataProvider::defaultValue( int index ) rather than on commit.
CustomData = 3000 //!< Custom properties for 3rd party providers or very provider-specific properties which are not expected to be of interest for other providers can be added starting from this value up.
};

QgsDataProvider( QString const & uri = "" )
: mDataSourceURI( uri )
{}
Expand Down Expand Up @@ -352,6 +365,38 @@ class CORE_EXPORT QgsDataProvider : public QObject
*/
virtual bool leaveUpdateMode() { return true; }

/**
* Allows setting arbitrary properties on the provider.
* It depends on the provider which properties are supported.
*
* @note added in 2.16
*/
void setProviderProperty( ProviderProperty property, const QVariant& value );

/**
* Allows setting arbitrary properties on the provider.
* It depends on the provider which properties are supported.
*
* @note added in 2.16
*/
void setProviderProperty( int property, const QVariant& value );

/**
* Get the current value of a certain provider property.
* It depends on the provider which properties are supported.
*
* @note added in 2.16
*/
QVariant providerProperty( ProviderProperty property, const QVariant& defaultValue = QVariant() ) const;

/**
* Get the current value of a certain provider property.
* It depends on the provider which properties are supported.
*
* @note added in 2.16
*/
QVariant providerProperty( int property , const QVariant& defaultValue ) const;

signals:

/**
Expand Down Expand Up @@ -398,6 +443,8 @@ class CORE_EXPORT QgsDataProvider : public QObject
* This could be a file, database, or server address.
*/
QString mDataSourceURI;

QMap< int, QVariant > mProviderProperties;
};


Expand Down
1 change: 1 addition & 0 deletions src/core/qgsvectordataprovider.h
Expand Up @@ -168,6 +168,7 @@ class CORE_EXPORT QgsVectorDataProvider : public QgsDataProvider
* @return map of fields
* @see QgsFields
*/
// TODO QGIS 3: return by value
virtual const QgsFields &fields() const = 0;

/**
Expand Down

0 comments on commit 000eb07

Please sign in to comment.