Skip to content
Permalink
Browse files

Add support for adding custom properties to providers

  • Loading branch information
m-kuhn committed May 28, 2016
1 parent f871544 commit 000eb072b0b56d8047e1e26de468561669710cca
@@ -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 = "" );

/**
@@ -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:

/**
@@ -102,6 +102,7 @@ SET(QGIS_CORE_SRCS
qgsdataitemprovider.cpp
qgsdataitemproviderregistry.cpp
qgsdatasourceuri.cpp
qgsdataprovider.cpp
qgsdatetimestatisticalsummary.cpp
qgsdatumtransformstore.cpp
qgsdbfilterproxymodel.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 );
}

@@ -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 )
{}
@@ -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:

/**
@@ -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;
};


@@ -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;

/**

0 comments on commit 000eb07

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