Skip to content
Permalink
Browse files
update provider metadata after adding new connection in browser
  • Loading branch information
speillet authored and nyalldawson committed Jun 21, 2021
1 parent 94f2599 commit a8640348548db4d78073f4167d4f149c29113e92
@@ -25,6 +25,7 @@
#include "qgsvectorlayer.h"
#include "qgsrasterlayer.h"
#include "qgsgeopackagedataitems.h"
#include "qgsgeopackageproviderconnection.h"
#include "qgsogrutils.h"
#include "qgsproviderregistry.h"
#include "qgssqliteutils.h"
@@ -437,6 +438,9 @@ bool QgsOgrDataCollectionItem::saveConnection( const QString &path, const QStrin
QgsOgrDbConnection connection( connName, ogrDriverName );
connection.setPath( path );
connection.save();
QgsProviderMetadata *providerMetadata = QgsProviderRegistry::instance()->providerMetadata( QStringLiteral( "ogr" ) );
QgsGeoPackageProviderConnection *providerConnection = static_cast<QgsGeoPackageProviderConnection *>( providerMetadata->createConnection( connName ) );
providerMetadata->saveConnection( providerConnection, connName );
return true;
}
}
@@ -21,6 +21,8 @@
#include "qgis.h"
#include "qgsdatasourceuri.h"
#include "qgssettings.h"
#include "qgsprovidermetadata.h"
#include "qgsproviderregistry.h"

#include "qgslogger.h"

@@ -89,6 +91,9 @@ void QgsOgrDbConnection::deleteConnection( const QString &connName, const QStrin
{
QgsSettings settings;
settings.remove( QStringLiteral( "%1/%2" ).arg( connectionsPath( settingsKey ), connName ) );

QgsProviderMetadata *providerMetadata = QgsProviderRegistry::instance()->providerMetadata( QStringLiteral( "ogr" ) );
providerMetadata->deleteConnection( connName );
}

///@endcond
@@ -24,6 +24,8 @@
#include "qgsoracletablemodel.h"
#include "qgssettings.h"
#include "qgsoracleconnpool.h"
#include "qgsprovidermetadata.h"
#include "qgsproviderregistry.h"

#include <QSqlError>

@@ -313,7 +313,8 @@ void QgsOracleConnectionItem::deleteConnection()
QMessageBox::Yes | QMessageBox::No, QMessageBox::No ) != QMessageBox::Yes )
return;

QgsOracleConn::deleteConnection( mName );
QgsProviderMetadata *providerMetadata = QgsProviderRegistry::instance()->providerMetadata( QStringLiteral( "oracle" ) );
providerMetadata->deleteConnection( mName );

// the parent should be updated
if ( mParent )
@@ -21,6 +21,9 @@

#include "qgssettings.h"
#include "qgsoraclenewconnection.h"
#include "qgsprovidermetadata.h"
#include "qgsproviderregistry.h"
#include "qgsoracleproviderconnection.h"
#include "qgsdatasourceuri.h"
#include "qgsoracletablemodel.h"
#include "qgsoracleconnpool.h"
@@ -156,6 +159,10 @@ void QgsOracleNewConnection::accept()
settings.setValue( baseKey + QStringLiteral( "/dbworkspace" ), txtWorkspace->text() );
settings.setValue( baseKey + QStringLiteral( "/schema" ), txtSchema->text() );

QgsProviderMetadata *providerMetadata = QgsProviderRegistry::instance()->providerMetadata( QStringLiteral( "oracle" ) );
QgsOracleProviderConnection *providerConnection = static_cast<QgsOracleProviderConnection *>( providerMetadata->createConnection( txtName->text() ) );
providerMetadata->saveConnection( providerConnection, txtName->text() );

QDialog::accept();
}

@@ -21,6 +21,9 @@
#include <QRegularExpression>

#include "qgspgnewconnection.h"
#include "qgsprovidermetadata.h"
#include "qgsproviderregistry.h"
#include "qgspostgresproviderconnection.h"
#include "qgsauthmanager.h"
#include "qgsdatasourceuri.h"
#include "qgspostgresconn.h"
@@ -174,6 +177,10 @@ void QgsPgNewConnection::accept()
// remove old save setting
settings.remove( baseKey + "/save" );

QgsProviderMetadata *providerMetadata = QgsProviderRegistry::instance()->providerMetadata( QStringLiteral( "postgres" ) );
QgsPostgresProviderConnection *providerConnection = static_cast<QgsPostgresProviderConnection *>( providerMetadata->createConnection( txtName->text() ) );
providerMetadata->saveConnection( providerConnection, txtName->text() );

QDialog::accept();
}

@@ -331,7 +331,8 @@ void QgsPgSourceSelect::btnDelete_clicked()
if ( QMessageBox::Yes != QMessageBox::question( this, tr( "Confirm Delete" ), msg, QMessageBox::Yes | QMessageBox::No ) )
return;

QgsPostgresConn::deleteConnection( cmbConnections->currentText() );
QgsPostgresProviderMetadata md = QgsPostgresProviderMetadata();
md.deleteConnection( cmbConnections->currentText() );

populateConnectionList();
emit connectionsChanged();
@@ -219,7 +219,9 @@ void QgsPostgresDataItemGuiProvider::deleteConnection( QgsDataItem *item )
QMessageBox::Yes | QMessageBox::No, QMessageBox::No ) != QMessageBox::Yes )
return;

QgsPostgresConn::deleteConnection( item->name() );
QgsProviderMetadata *md = QgsProviderRegistry::instance()->providerMetadata( QStringLiteral( "postgres" ) );
md->deleteConnection( item->name() );

// the parent should be updated
if ( item->parent() )
item->parent()->refreshConnections();
@@ -17,6 +17,8 @@
#include "qgsspatialiteconnection.h"
#include "qgsspatialitedataitems.h"
#include "qgsspatialitesourceselect.h"
#include "qgsproviderregistry.h"
#include "qgsprovidermetadata.h"

#include "qgsapplication.h"
#include "qgsmessageoutput.h"
@@ -134,7 +136,9 @@ void QgsSpatiaLiteDataItemGuiProvider::deleteConnection( QgsDataItem *item )
QMessageBox::Yes | QMessageBox::No, QMessageBox::No ) != QMessageBox::Yes )
return;

QgsSpatiaLiteConnection::deleteConnection( item->name() );
QgsProviderMetadata *providerMetadata = QgsProviderRegistry::instance()->providerMetadata( QStringLiteral( "spatialite" ) );
providerMetadata->deleteConnection( item->name() );

// the parent should be updated
item->parent()->refreshConnections();
}
@@ -28,6 +28,8 @@ email : a.furieri@lqt.it
#include "qgsproviderregistry.h"
#include "qgsproject.h"
#include "qgsgui.h"
#include "qgsprovidermetadata.h"
#include "qgsspatialiteproviderconnection.h"

#include <QInputDialog>
#include <QMessageBox>
@@ -312,6 +314,11 @@ bool QgsSpatiaLiteSourceSelect::newConnection( QWidget *parent )
// inserting this SQLite DB path
settings.setValue( baseKey + "selected", savedName );
settings.setValue( baseKey + savedName + "/sqlitepath", myFI.canonicalFilePath() );

QgsProviderMetadata *providerMetadata = QgsProviderRegistry::instance()->providerMetadata( QStringLiteral( "spatialite" ) );
QgsSpatiaLiteProviderConnection *providerConnection = static_cast<QgsSpatiaLiteProviderConnection *>( providerMetadata->createConnection( savedName ) );
providerMetadata->saveConnection( providerConnection, savedName );

return true;
}

0 comments on commit a864034

Please sign in to comment.