Skip to content
Permalink
Browse files

Generic implementation of OGR file DB connection

  • Loading branch information
elpaso committed Sep 8, 2017
1 parent 1a9fa28 commit ce3d644e74ff65217c7117dbb1350ad2cb45e611
Showing with 40 additions and 36 deletions.
  1. +25 −21 src/providers/ogr/qgsogrdbconnection.cpp
  2. +15 −15 src/providers/ogr/qgsogrdbconnection.h
@@ -1,5 +1,5 @@
/***************************************************************************
qgsgeopackageconnection.cpp - selector for geopackage
qgsogrdbconnection.cpp
-------------------
begin : August 2017
copyright : (C) 2017 by Alessandro Pasotti
@@ -18,72 +18,76 @@
#include "qgis.h"
#include "qgsdatasourceuri.h"
#include "qgssettings.h"
#include "qgsgeopackageconnection.h"
#include "qgsogrdbconnection.h"
#include "qgslogger.h"
#include <QInputDialog>
#include <QMessageBox>

const QString QgsGeoPackageConnection::SETTINGS_PREFIX = QStringLiteral( "providers/geopackage" );


QgsGeoPackageConnection::QgsGeoPackageConnection( const QString &connName )
QgsOgrDbConnection::QgsOgrDbConnection( const QString &connName, const QString &settingsKey )
: mConnName( connName )
{
mSettingsKey = settingsKey ;
QgsSettings settings;

QString key = QStringLiteral( "%1/%2/path" ).arg( connectionsPath( ), mConnName );
QString key = QStringLiteral( "%1/%2/path" ).arg( connectionsPath( settingsKey ), mConnName );
mPath = settings.value( key ).toString();
}

QgsGeoPackageConnection::~QgsGeoPackageConnection()
QgsOgrDbConnection::~QgsOgrDbConnection()
{

}

QgsDataSourceUri QgsGeoPackageConnection::uri()
QgsDataSourceUri QgsOgrDbConnection::uri()
{
QgsDataSourceUri uri;
uri.setEncodedUri( mPath );
return uri;
}

void QgsGeoPackageConnection::setPath( const QString &path )
void QgsOgrDbConnection::setPath( const QString &path )
{
mPath = path;
}

void QgsGeoPackageConnection::save( )
void QgsOgrDbConnection::save( )
{
QgsSettings settings;
settings.setValue( QStringLiteral( "%1/%2/path" ).arg( connectionsPath( ), mConnName ), mPath );
settings.setValue( QStringLiteral( "%1/%2/path" ).arg( connectionsPath( mSettingsKey ), mConnName ), mPath );
}

QString QgsOgrDbConnection::fullKey( const QString &settingsKey )
{
return QStringLiteral( "providers/ogr/%1" ).arg( settingsKey );
}

QString QgsGeoPackageConnection::connectionsPath()
QString QgsOgrDbConnection::connectionsPath( const QString &settingsKey )
{
return QStringLiteral( "%1/connections" ).arg( SETTINGS_PREFIX );
return QStringLiteral( "%1/connections" ).arg( fullKey( settingsKey ) );
}

QStringList QgsGeoPackageConnection::connectionList()
const QStringList QgsOgrDbConnection::connectionList( const QString &settingsKey )
{
QgsSettings settings;
settings.beginGroup( connectionsPath( ) );
settings.beginGroup( connectionsPath( settingsKey ) );
return settings.childGroups();
}

QString QgsGeoPackageConnection::selectedConnection()
QString QgsOgrDbConnection::selectedConnection( const QString &settingsKey )
{
QgsSettings settings;
return settings.value( QStringLiteral( "%1/selected" ).arg( SETTINGS_PREFIX ) ).toString();
return settings.value( QStringLiteral( "%1/selected" ).arg( connectionsPath( settingsKey ) ) ).toString();
}

void QgsGeoPackageConnection::setSelectedConnection( const QString &name )
void QgsOgrDbConnection::setSelectedConnection( const QString &connName, const QString &settingsKey )
{
QgsSettings settings;
settings.setValue( QStringLiteral( "%1/selected" ).arg( SETTINGS_PREFIX ), name );
settings.setValue( QStringLiteral( "%1/selected" ).arg( connectionsPath( settingsKey ) ), connName );
}

void QgsGeoPackageConnection::deleteConnection( const QString &name )
void QgsOgrDbConnection::deleteConnection( const QString &connName, const QString &settingsKey )
{
QgsSettings settings;
settings.remove( QStringLiteral( "%1/%2" ).arg( connectionsPath(), name ) );
settings.remove( QStringLiteral( "%1/%2" ).arg( connectionsPath( settingsKey ), connName ) );
}
@@ -1,5 +1,5 @@
/***************************************************************************
qgsgeopackageconnection.h - GeoPackage connection
qgsogrdbconnection.h - QgsOgrDbConnection
-------------------
begin : August 2017
copyright : (C) 2017 by Alessandro Pasotti
@@ -15,30 +15,30 @@
* *
***************************************************************************/

#ifndef QGSGEOPACKAGECONNECTION_H
#define QGSGEOPACKAGECONNECTION_H
#ifndef QGSGOGRDBSCONNECTION_H
#define QGSGOGRDBSCONNECTION_H

#include "qgsdatasourceuri.h"

#include <QStringList>

/*!
* \brief Connections management
* \brief Generic OGR DB Connections management
*/
class QgsGeoPackageConnection : public QObject
class QgsOgrDbConnection : public QObject
{
Q_OBJECT

public:
//! Constructor
explicit QgsGeoPackageConnection( const QString &connName );
explicit QgsOgrDbConnection( const QString &connName, const QString &settingsKey );

~QgsGeoPackageConnection();
~QgsOgrDbConnection();

static QStringList connectionList();
static void deleteConnection( const QString &name );
static QString selectedConnection();
static void setSelectedConnection( const QString &name );
static const QStringList connectionList( const QString &settingsKey );
static void deleteConnection( const QString &connName, const QString &settingsKey );
static QString selectedConnection( const QString &settingsKey );
static void setSelectedConnection( const QString &connName, const QString &settingsKey );

public:
//! Return the uri
@@ -52,14 +52,14 @@ class QgsGeoPackageConnection : public QObject
void setPath( const QString &path );
//! Store the connection data in the settings
void save();
const static QString SETTINGS_PREFIX;

private:

static QString connectionsPath( );
static QString fullKey( const QString &settingsKey );
static QString connectionsPath( const QString &settingsKey );
QString mConnName;
QString mPath;
QString mSettingsKey;

};

#endif // QGSGEOPACKAGECONNECTION_H
#endif // QGSGOGRDBSCONNECTION_H

0 comments on commit ce3d644

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