Skip to content

Commit dcf2816

Browse files
committed
refresh postgres schema in browser after import
1 parent 797bd16 commit dcf2816

File tree

2 files changed

+16
-4
lines changed

2 files changed

+16
-4
lines changed

src/providers/postgres/qgspostgresdataitems.cpp

+14-3
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,17 @@ void QgsPGConnectionItem::refreshConnection()
152152
refresh();
153153
}
154154

155+
void QgsPGConnectionItem::refreshSchema( const QString &schema )
156+
{
157+
Q_FOREACH ( QgsDataItem *child, mChildren )
158+
{
159+
if ( child->name() == schema || schema.isEmpty() )
160+
{
161+
child->refresh();
162+
}
163+
}
164+
}
165+
155166
void QgsPGConnectionItem::createSchema()
156167
{
157168
QString schemaName = QInputDialog::getText( nullptr, tr( "Create Schema" ), tr( "Schema name:" ) );
@@ -229,7 +240,7 @@ bool QgsPGConnectionItem::handleDrop( const QMimeData *data, const QString &toSc
229240
{
230241
// this is gross - TODO - find a way to get access to messageBar from data items
231242
QMessageBox::information( nullptr, tr( "Import to PostGIS database" ), tr( "Import was successful." ) );
232-
refresh();
243+
refreshSchema( toSchema );
233244
} );
234245

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

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

449460
QVector<QgsDataItem *> QgsPGSchemaItem::createChildren()
450461
{
451-
452462
QVector<QgsDataItem *>items;
453463

454464
QgsDataSourceUri uri = QgsPostgresConn::connUri( mConnectionName );
455465
QgsPostgresConn *conn = QgsPostgresConnPool::instance()->acquireConnection( uri.connectionInfo( false ) );
466+
456467
if ( !conn )
457468
{
458469
items.append( new QgsErrorItem( this, tr( "Connection failed" ), mPath + "/error" ) );

src/providers/postgres/qgspostgresdataitems.h

+2-1
Original file line numberDiff line numberDiff line change
@@ -70,8 +70,9 @@ class QgsPGConnectionItem : public QgsDataCollectionItem
7070
void editConnection();
7171
void deleteConnection();
7272
void refreshConnection();
73+
// refresh specified schema or all schemas if schema name is empty
74+
void refreshSchema( const QString &schema );
7375
void createSchema();
74-
7576
};
7677

7778
class QgsPGSchemaItem : public QgsDataCollectionItem

0 commit comments

Comments
 (0)