Skip to content
Permalink
Browse files

[FEATURE] import a layer from canvas into a PG database

  • Loading branch information
brushtyler committed Aug 23, 2011
1 parent 7a2a328 commit 00d74980758a870415fdab17f7c7c673df5a6f59
@@ -60,6 +60,18 @@ class QgsProviderRegistry
* @note this method was added in QGIS 1.1
*/
virtual QString protocolDrivers() const;

/** allows to import a vector layer using the provider
* @note this method was added in QGIS 1.8
*/
int importVector( QgsVectorLayer* layer,
const QString& providerKey,
const QString& uri,
const QgsCoordinateReferenceSystem *destCRS,
bool onlySelected = FALSE,
QString *errorMessage /Out/ = 0,
bool skipAttributeCreation = FALSE
) const;



@@ -30,6 +30,7 @@
#include "qgslogger.h"
#include "qgsmessageoutput.h"
#include "qgsprovidermetadata.h"
#include "qgsvectorlayer.h"


// typedefs for provider plugin functions of interest
@@ -42,6 +43,12 @@ typedef QString directoryDrivers_t();
typedef QString protocolDrivers_t();
//typedef int dataCapabilities_t();
//typedef QgsDataItem * dataItem_t(QString);
typedef int importVector_t(QgsVectorLayer* layer,
const QString& uri,
const QgsCoordinateReferenceSystem *destCRS,
bool onlySelected = false,
QString *errorMessage = 0,
bool skipAttributeCreation = false);

QgsProviderRegistry *QgsProviderRegistry::_instance = 0;

@@ -468,7 +475,7 @@ void * QgsProviderRegistry::function( QString const & providerKey,
return 0;
}

QLibrary *QgsProviderRegistry::providerLibrary( QString const & providerKey )
QLibrary *QgsProviderRegistry::providerLibrary( QString const & providerKey ) const
{
QString lib = library( providerKey );

@@ -531,3 +538,34 @@ QgsProviderRegistry::openVector( QString const & dataSource, QString const & pro
return getProvider( providerKey, dataSource );
} // QgsProviderRegistry::openVector
*/


int QgsProviderRegistry::importVector( QgsVectorLayer* layer,
const QString& providerKey,
const QString& uri,
const QgsCoordinateReferenceSystem *destCRS,
bool onlySelected,
QString *errorMessage,
bool skipAttributeCreation
) const
{
QLibrary *myLib = providerLibrary( providerKey );
if ( !myLib )
{
if ( errorMessage )
*errorMessage = QObject::tr( "unable to load %1 provider" ).arg( providerKey );
return -1;
}

importVector_t * pImport = ( importVector_t * ) cast_to_fptr( myLib->resolve( "importVector" ) );
if ( !pImport )
{
delete myLib;
if ( errorMessage )
*errorMessage = QObject::tr( "provider %1 has no importVector feature" ).arg( providerKey );
return -2;
}

delete myLib;
return pImport( layer, uri, destCRS, onlySelected, errorMessage, skipAttributeCreation );
}
@@ -28,7 +28,8 @@

class QgsDataProvider;
class QgsProviderMetadata;

class QgsVectorLayer;
class QgsCoordinateReferenceSystem;


/** \ingroup core
@@ -78,7 +79,7 @@ class CORE_EXPORT QgsProviderRegistry
void *function( const QString & providerKey,
const QString & functionName );

QLibrary *providerLibrary( const QString & providerKey );
QLibrary *providerLibrary( const QString & providerKey ) const;

/** Return list of available providers by their keys */
QStringList providerList() const;
@@ -139,6 +140,16 @@ class CORE_EXPORT QgsProviderRegistry
/** type for data provider metadata associative container */
typedef std::map<QString, QgsProviderMetadata*> Providers;

/** allows to import a vector layer using the provider */
int importVector( QgsVectorLayer* layer,
const QString& providerKey,
const QString& uri,
const QgsCoordinateReferenceSystem *destCRS,
bool onlySelected = false,
QString *errorMessage = 0,
bool skipAttributeCreation = false
) const;

private:

/** ctor private since instance() creates it */

0 comments on commit 00d7498

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