Skip to content

Commit

Permalink
refresh postgres schema in browser after import
Browse files Browse the repository at this point in the history
  • Loading branch information
blazek committed Jun 29, 2017
1 parent 797bd16 commit dcf2816
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 4 deletions.
17 changes: 14 additions & 3 deletions src/providers/postgres/qgspostgresdataitems.cpp
Expand Up @@ -152,6 +152,17 @@ void QgsPGConnectionItem::refreshConnection()
refresh();
}

void QgsPGConnectionItem::refreshSchema( const QString &schema )
{
Q_FOREACH ( QgsDataItem *child, mChildren )
{
if ( child->name() == schema || schema.isEmpty() )
{
child->refresh();
}
}
}

void QgsPGConnectionItem::createSchema()
{
QString schemaName = QInputDialog::getText( nullptr, tr( "Create Schema" ), tr( "Schema name:" ) );
Expand Down Expand Up @@ -229,7 +240,7 @@ bool QgsPGConnectionItem::handleDrop( const QMimeData *data, const QString &toSc
{
// this is gross - TODO - find a way to get access to messageBar from data items
QMessageBox::information( nullptr, tr( "Import to PostGIS database" ), tr( "Import was successful." ) );
refresh();
refreshSchema( toSchema );
} );

// when an error occurs:
Expand All @@ -242,7 +253,7 @@ bool QgsPGConnectionItem::handleDrop( const QMimeData *data, const QString &toSc
output->setMessage( tr( "Failed to import some layers!\n\n" ) + errorMessage, QgsMessageOutput::MessageText );
output->showMessage();
}
refresh();
refreshSchema( toSchema );
} );

QgsApplication::taskManager()->addTask( exportTask.release() );
Expand Down Expand Up @@ -448,11 +459,11 @@ QgsPGSchemaItem::QgsPGSchemaItem( QgsDataItem *parent, const QString &connection

QVector<QgsDataItem *> QgsPGSchemaItem::createChildren()
{

QVector<QgsDataItem *>items;

QgsDataSourceUri uri = QgsPostgresConn::connUri( mConnectionName );
QgsPostgresConn *conn = QgsPostgresConnPool::instance()->acquireConnection( uri.connectionInfo( false ) );

if ( !conn )
{
items.append( new QgsErrorItem( this, tr( "Connection failed" ), mPath + "/error" ) );
Expand Down
3 changes: 2 additions & 1 deletion src/providers/postgres/qgspostgresdataitems.h
Expand Up @@ -70,8 +70,9 @@ class QgsPGConnectionItem : public QgsDataCollectionItem
void editConnection();
void deleteConnection();
void refreshConnection();
// refresh specified schema or all schemas if schema name is empty
void refreshSchema( const QString &schema );
void createSchema();

};

class QgsPGSchemaItem : public QgsDataCollectionItem
Expand Down

0 comments on commit dcf2816

Please sign in to comment.