Skip to content
Permalink
Browse files

[FEATURE] postgres provider: allow copying tables from one schema to …

…an other
  • Loading branch information
jef-n committed Sep 11, 2015
1 parent 69e53df commit fd2ad1329ae2238d64287fb527a7043bc5f73cf7
@@ -359,6 +359,11 @@ void QgsDataSourceURI::clearSchema()
mSchema = "";
}

void QgsDataSourceURI::setSchema( QString schema )
{
mSchema = schema;
}

QString QgsDataSourceURI::escape( const QString &theVal, QChar delim = '\'' ) const
{
QString val = theVal;
@@ -547,9 +552,9 @@ QString QgsDataSourceURI::uri() const
QByteArray QgsDataSourceURI::encodedUri() const
{
QUrl url;
Q_FOREACH ( const QString& key, mParams.uniqueKeys() )
Q_FOREACH( const QString& key, mParams.uniqueKeys() )
{
Q_FOREACH ( const QString& value, mParams.values( key ) )
Q_FOREACH( const QString& value, mParams.values( key ) )
{
url.addQueryItem( key, value );
}
@@ -563,7 +568,7 @@ void QgsDataSourceURI::setEncodedUri( const QByteArray & uri )
QUrl url;
url.setEncodedQuery( uri );
QPair<QString, QString> item;
Q_FOREACH ( item, url.queryItems() )
Q_FOREACH( item, url.queryItems() )
{
mParams.insertMulti( item.first, item.second );
}
@@ -659,7 +664,7 @@ void QgsDataSourceURI::setParam( const QString &key, const QString &value )

void QgsDataSourceURI::setParam( const QString &key, const QStringList &value )
{
Q_FOREACH ( const QString& val, value )
Q_FOREACH( const QString& val, value )
{
mParams.insertMulti( key, val );
}
@@ -131,6 +131,11 @@ class CORE_EXPORT QgsDataSourceURI
bool selectAtIdDisabled() const;

void clearSchema();

//! set the table schema
// @note added in 2.11
void setSchema( QString schema );

void setSql( QString sql );

QString host() const;
@@ -71,7 +71,7 @@ QVector<QgsDataItem*> QgsPGConnectionItem::createChildren()
return items;
}

Q_FOREACH ( const QgsPostgresSchemaProperty& schema, schemas )
Q_FOREACH( const QgsPostgresSchemaProperty& schema, schemas )
{
QgsPGSchemaItem * schemaItem = new QgsPGSchemaItem( this, mName, schema.name, mPath + "/" + schema.name );
if ( !schema.description.isEmpty() )
@@ -187,6 +187,11 @@ void QgsPGConnectionItem::createSchema()
}

bool QgsPGConnectionItem::handleDrop( const QMimeData * data, Qt::DropAction )
{
return handleDrop( data, QString::null );
}

bool QgsPGConnectionItem::handleDrop( const QMimeData * data, QString toSchema )
{
if ( !QgsMimeDataUtils::isUriList( data ) )
return false;
@@ -204,7 +209,7 @@ bool QgsPGConnectionItem::handleDrop( const QMimeData * data, Qt::DropAction )
QStringList importResults;
bool hasError = false;
QgsMimeDataUtils::UriList lst = QgsMimeDataUtils::decodeUriList( data );
Q_FOREACH ( const QgsMimeDataUtils::Uri& u, lst )
Q_FOREACH( const QgsMimeDataUtils::Uri& u, lst )
{
if ( u.layerType != "vector" )
{
@@ -220,6 +225,12 @@ bool QgsPGConnectionItem::handleDrop( const QMimeData * data, Qt::DropAction )
{
uri.setDataSource( QString(), u.name, "geom" );
QgsDebugMsg( "URI " + uri.uri() );

if ( !toSchema.isNull() )
{
uri.setSchema( toSchema );
}

QgsVectorLayerImport::ImportError err;
QString importError;
err = QgsVectorLayerImport::importLayer( srcLayer, uri.uri(), "postgres", &srcLayer->crs(), false, &importError, false, 0, progress );
@@ -473,7 +484,7 @@ QVector<QgsDataItem*> QgsPGSchemaItem::createChildren()
}

bool dontResolveType = QgsPostgresConn::dontResolveType( mConnectionName );
Q_FOREACH ( QgsPostgresLayerProperty layerProperty, layerProperties )
Q_FOREACH( QgsPostgresLayerProperty layerProperty, layerProperties )
{
if ( layerProperty.schemaName != mName )
continue;
@@ -661,6 +672,15 @@ QgsPGLayerItem *QgsPGSchemaItem::createLayer( QgsPostgresLayerProperty layerProp
return layerItem;
}

bool QgsPGSchemaItem::handleDrop( const QMimeData * data, Qt::DropAction )
{
QgsPGConnectionItem *conn = qobject_cast<QgsPGConnectionItem *>( parent() );
if ( !conn )
return 0;

return conn->handleDrop( data, mName );
}

// ---------------------------------------------------------------------------
QgsPGRootItem::QgsPGRootItem( QgsDataItem* parent, QString name, QString path )
: QgsDataCollectionItem( parent, name, path )
@@ -677,7 +697,7 @@ QgsPGRootItem::~QgsPGRootItem()
QVector<QgsDataItem*> QgsPGRootItem::createChildren()
{
QVector<QgsDataItem*> connections;
Q_FOREACH ( const QString& connName, QgsPostgresConn::connectionList() )
Q_FOREACH( const QString& connName, QgsPostgresConn::connectionList() )
{
connections << new QgsPGConnectionItem( this, connName, mPath + "/" + connName );
}
@@ -63,6 +63,8 @@ class QgsPGConnectionItem : public QgsDataCollectionItem
virtual bool acceptDrop() override { return true; }
virtual bool handleDrop( const QMimeData * data, Qt::DropAction action ) override;

bool handleDrop( const QMimeData * data, QString toSchema );

signals:
void addGeometryColumn( QgsPostgresLayerProperty );

@@ -84,6 +86,9 @@ class QgsPGSchemaItem : public QgsDataCollectionItem
QVector<QgsDataItem*> createChildren() override;
virtual QList<QAction*> actions() override;

virtual bool acceptDrop() override { return true; }
virtual bool handleDrop( const QMimeData * data, Qt::DropAction action ) override;

public slots:
void deleteSchema();
void renameSchema();

0 comments on commit fd2ad13

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