[QGIS Commit] r10457 - in trunk/qgis: python/core src/app
src/app/ogr src/core
svn_qgis at osgeo.org
svn_qgis at osgeo.org
Fri Apr 3 00:01:19 EDT 2009
Author: gcontreras
Date: 2009-04-03 00:01:19 -0400 (Fri, 03 Apr 2009)
New Revision: 10457
Modified:
trunk/qgis/python/core/qgsdatasourceuri.sip
trunk/qgis/src/app/ogr/qgsogrhelperfunctions.cpp
trunk/qgis/src/app/ogr/qgsogrhelperfunctions.h
trunk/qgis/src/app/ogr/qgsopenvectorlayerdialog.cpp
trunk/qgis/src/app/ogr/qgsopenvectorlayerdialog.h
trunk/qgis/src/app/qgisapp.cpp
trunk/qgis/src/app/qgisapp.h
trunk/qgis/src/core/qgsdatasourceuri.cpp
trunk/qgis/src/core/qgsdatasourceuri.h
trunk/qgis/src/core/qgsmaplayer.cpp
Log:
Changes to remove password from ogr database uris in legend and setting port 5151 as default for sde connections.
Modified: trunk/qgis/python/core/qgsdatasourceuri.sip
===================================================================
--- trunk/qgis/python/core/qgsdatasourceuri.sip 2009-04-02 21:32:13 UTC (rev 10456)
+++ trunk/qgis/python/core/qgsdatasourceuri.sip 2009-04-03 04:01:19 UTC (rev 10457)
@@ -1,53 +1,58 @@
-/**
-\struct QgsDataSourceURI
-\brief Structure for storing the component parts of a PostgreSQL/RDBMS datasource URI.
-
- This structure stores the database connection information, including host, database,
- user name, password, schema, password, and sql where clause
- */
-class QgsDataSourceURI
-{
-%TypeHeaderCode
-#include <qgsdatasourceuri.h>
-%End
-
-public:
- enum SSLmode { SSLprefer, SSLdisable, SSLallow, SSLrequire };
-
- //! default constructor
- QgsDataSourceURI();
-
- //! constructor which parses input URI
- QgsDataSourceURI(QString uri);
-
- //! connection info
- QString connectionInfo() const;
-
- //! complete uri
- QString uri() const;
-
- //! quoted table name
- QString quotedTablename() const;
-
- //! Set all connection related members at once
- void setConnection(const QString& aHost,
- const QString& aPort,
- const QString& aDatabase,
- const QString& aUsername,
- const QString& aPassword,
- SSLmode sslmode );
-
- //! Set all data source related members at once
- void setDataSource(const QString& aSchema,
- const QString& aTable,
- const QString& aGeometryColumn,
- const QString& aSql = QString());
-
- QString username() const;
- QString schema() const;
- QString table() const;
- QString sql() const;
- QString geometryColumn() const;
-
- void setSql(QString sql);
-};
+/**
+\struct QgsDataSourceURI
+\brief Structure for storing the component parts of a PostgreSQL/RDBMS datasource URI.
+
+ This structure stores the database connection information, including host, database,
+ user name, password, schema, password, and sql where clause
+ */
+class QgsDataSourceURI
+{
+%TypeHeaderCode
+#include <qgsdatasourceuri.h>
+%End
+
+public:
+ enum SSLmode { SSLprefer, SSLdisable, SSLallow, SSLrequire };
+
+ //! default constructor
+ QgsDataSourceURI();
+
+ //! constructor which parses input URI
+ QgsDataSourceURI(QString uri);
+
+ //! connection info
+ QString connectionInfo() const;
+
+ //! complete uri
+ QString uri() const;
+
+ //! quoted table name
+ QString quotedTablename() const;
+
+ //! Set all connection related members at once
+ void setConnection(const QString& aHost,
+ const QString& aPort,
+ const QString& aDatabase,
+ const QString& aUsername,
+ const QString& aPassword,
+ SSLmode sslmode );
+
+ //! Set all data source related members at once
+ void setDataSource(const QString& aSchema,
+ const QString& aTable,
+ const QString& aGeometryColumn,
+ const QString& aSql = QString());
+
+ /** Removes password from uris
+ * @note this method was added in QGIS 1.1
+ */
+ static QString removePassword( const QString& aUri);
+
+ QString username() const;
+ QString schema() const;
+ QString table() const;
+ QString sql() const;
+ QString geometryColumn() const;
+
+ void setSql(QString sql);
+};
Modified: trunk/qgis/src/app/ogr/qgsogrhelperfunctions.cpp
===================================================================
--- trunk/qgis/src/app/ogr/qgsogrhelperfunctions.cpp 2009-04-02 21:32:13 UTC (rev 10456)
+++ trunk/qgis/src/app/ogr/qgsogrhelperfunctions.cpp 2009-04-03 04:01:19 UTC (rev 10457)
@@ -1,103 +1,105 @@
-/***************************************************************************
- qgsogrhelperfunctions.cpp
- helper functions to create ogr uris for database and protocol drivers
- -------------------
- begin : Mon Jan 2 2009
- copyright : (C) 2009 by Godofredo Contreras Nava
- email : frdcn at hotmail.com
- ***************************************************************************/
-
-/***************************************************************************
- * *
- * This program is free software; you can redistribute it and/or modify *
- * it under the terms of the GNU General Public License as published by *
- * the Free Software Foundation; either version 2 of the License, or *
- * (at your option) any later version. *
- * *
- ***************************************************************************/
-/* $Id:$ */
-
-#include "qgsogrhelperfunctions.h"
-#include "qgslogger.h"
-
-QString createDatabaseURI( QString connectionType, QString host, QString database, QString port, QString user, QString password )
-{
- QString uri = "";
-
- if ( connectionType == "ESRI Personal GeoDatabase" )
- {
- uri = "PGeo:" + database;
- }
- else if ( connectionType == "ESRI ArcSDE" )
- {
- //not tested
- uri = "SDE:" + host + "," + database + "," + user + "," + password;
- }
- else if ( connectionType == "Informix DataBlade" )
- {
- //not tested
- uri = "IDB:dbname=" + database + " server=" + host
- + " user=" + user
- + " pass=" + password;
-
- }
- else if ( connectionType == "INGRES" )
- {
- //not tested
- uri = "@driver=ingres,dbname=" + database + ",userid=" + user + ",password=" + password;
- }
- else if ( connectionType == "MySQL" )
- {
- uri = "MySQL:" + database + ",host=" + host
- + ",port=" + port + ",user=" + user
- + ",password=" + password + "";
- }
- else if ( connectionType == "Oracle Spatial" )
- {
- uri = "OCI:" + user + "/" + password
- + "@" + host + "/" + database;
- }
- else if ( connectionType == "ODBC" )
- {
- if ( !user.isEmpty() )
- {
- if ( password.isEmpty() )
- {
- uri = "ODBC:" + user + "@" + database;
- }
- else
- {
- uri = "ODBC:" + user + "/" + password + "@" + database;
- }
-
- }
- else
- {
- uri = "ODBC:" + database;
- }
- }
- else if ( connectionType == "OGDI Vectors" )
- {
- }
- else if ( connectionType == "PostgreSQL" )
- {
- uri = "PG:dbname='" + database + "' host='" + host
- + "' port='" + port + "' user='" + user
- + "' password='" + password + "'";
-
- }
- QgsDebugMsg( "Connection type is=" + connectionType + " and uri=" + uri );
- return uri;
-}
-
-
-QString createProtocolURI( QString type, QString url )
-{
- QString uri = "";
- if ( type == "GeoJSON" )
- {
- uri = url;
- }
- QgsDebugMsg( "Connection type is=" + type + " and uri=" + uri );
- return uri;
-}
+/***************************************************************************
+ qgsogrhelperfunctions.cpp
+ helper functions to create ogr uris for database and protocol drivers
+ -------------------
+ begin : Mon Jan 2 2009
+ copyright : (C) 2009 by Godofredo Contreras Nava
+ email : frdcn at hotmail.com
+ ***************************************************************************/
+
+/***************************************************************************
+ * *
+ * This program is free software; you can redistribute it and/or modify *
+ * it under the terms of the GNU General Public License as published by *
+ * the Free Software Foundation; either version 2 of the License, or *
+ * (at your option) any later version. *
+ * *
+ ***************************************************************************/
+/* $Id:$ */
+
+#include "qgsogrhelperfunctions.h"
+#include "qgslogger.h"
+#include <QRegExp>
+
+QString createDatabaseURI( QString connectionType, QString host, QString database, QString port, QString user, QString password )
+{
+ QString uri = "";
+ //todo:add default ports for all kind of databases
+ if (connectionType=="ESRI Personal GeoDatabase")
+ {
+ uri="PGeo:"+database;
+ }
+ else if (connectionType=="ESRI ArcSDE")
+ {
+ if (port.isNull()||port.isEmpty())
+ port="5151";
+ uri="SDE:"+host+",PORT:"+port+","+database+","+user+","+password;
+ }
+ else if (connectionType=="Informix DataBlade")
+ {
+ //not tested
+ uri="IDB:dbname="+database+" server="+host
+ +" user="+user
+ +" pass="+password+" ";
+
+ }
+ else if (connectionType=="INGRES")
+ {
+ //not tested
+ uri="@driver=ingres,dbname="+database+",userid="+user+", password="+password+" ";
+ }
+ else if (connectionType=="MySQL")
+ {
+ uri="MySQL:"+database+",host="+host
+ +",port="+port+",user="+user
+ +", password="+password+" ";
+ }
+ else if (connectionType=="Oracle Spatial")
+ {
+ uri="OCI:"+user+"/"+password
+ +"@"+host+"/"+database;
+ }
+ else if (connectionType=="ODBC")
+ {
+ if(!user.isEmpty())
+ {
+ if(password.isEmpty())
+ {
+ uri="ODBC:"+user+"@"+database;
+ }
+ else
+ {
+ uri="ODBC:"+user+"/"+password+"@"+database;
+ }
+
+ }
+ else
+ {
+ uri="ODBC:"+database;
+ }
+ }
+ else if (connectionType=="OGDI Vectors")
+ {
+ }
+ else if (connectionType=="PostgreSQL")
+ {
+ uri="PG:dbname='"+database+"' host='"+host
+ +"' port='"+port+"' user='"+user
+ +"' password='"+password+"' ";
+
+ }
+ QgsDebugMsg("Connection type is="+connectionType+" and uri="+uri);
+ return uri;
+}
+
+
+QString createProtocolURI( QString type, QString url )
+{
+ QString uri = "";
+ if ( type == "GeoJSON" )
+ {
+ uri = url;
+ }
+ QgsDebugMsg( "Connection type is=" + type + " and uri=" + uri );
+ return uri;
+}
Modified: trunk/qgis/src/app/ogr/qgsogrhelperfunctions.h
===================================================================
--- trunk/qgis/src/app/ogr/qgsogrhelperfunctions.h 2009-04-02 21:32:13 UTC (rev 10456)
+++ trunk/qgis/src/app/ogr/qgsogrhelperfunctions.h 2009-04-03 04:01:19 UTC (rev 10457)
@@ -1,23 +1,26 @@
-/***************************************************************************
- qgsogrhelperfunctions.h
- helper functions to create ogr uris for database and protocol drivers
- -------------------
- begin : Mon Jan 2 2009
- copyright : (C) 2009 by Godofredo Contreras Nava
- email : frdcn at hotmail.com
- ***************************************************************************/
-
-/***************************************************************************
- * *
- * This program is free software; you can redistribute it and/or modify *
- * it under the terms of the GNU General Public License as published by *
- * the Free Software Foundation; either version 2 of the License, or *
- * (at your option) any later version. *
- * *
- ***************************************************************************/
-/* $Id:$ */
-
-#include <QString>
-
-QString createDatabaseURI( QString connectionType, QString host, QString database, QString port, QString user, QString password );
-QString createProtocolURI( QString type, QString url );
\ No newline at end of file
+/***************************************************************************
+ qgsogrhelperfunctions.h
+ helper functions to create ogr uris for database and protocol drivers
+ -------------------
+ begin : Mon Jan 2 2009
+ copyright : (C) 2009 by Godofredo Contreras Nava
+ email : frdcn at hotmail.com
+ ***************************************************************************/
+
+/***************************************************************************
+ * *
+ * This program is free software; you can redistribute it and/or modify *
+ * it under the terms of the GNU General Public License as published by *
+ * the Free Software Foundation; either version 2 of the License, or *
+ * (at your option) any later version. *
+ * *
+ ***************************************************************************/
+/* $Id:$ */
+
+#include <QString>
+
+/* Create database uri from connection parameters */
+QString createDatabaseURI(QString connectionType, QString host, QString database, QString port, QString user, QString password);
+
+/* Create protocol uri from connection parameters */
+QString createProtocolURI(QString type, QString url);
Modified: trunk/qgis/src/app/ogr/qgsopenvectorlayerdialog.cpp
===================================================================
--- trunk/qgis/src/app/ogr/qgsopenvectorlayerdialog.cpp 2009-04-02 21:32:13 UTC (rev 10456)
+++ trunk/qgis/src/app/ogr/qgsopenvectorlayerdialog.cpp 2009-04-03 04:01:19 UTC (rev 10457)
@@ -1,500 +1,512 @@
-/***************************************************************************
- qgsopenvectorlayerdialog.cpp
- Dialog to select the type and source for ogr vectors, supports
- file, database, directory and protocol sources.
- -------------------
- begin : Mon Jan 2 2009
- copyright : (C) 2009 by Godofredo Contreras Nava
- email : frdcn at hotmail.com
- ***************************************************************************/
-
-/***************************************************************************
- * *
- * This program is free software; you can redistribute it and/or modify *
- * it under the terms of the GNU General Public License as published by *
- * the Free Software Foundation; either version 2 of the License, or *
- * (at your option) any later version. *
- * *
- ***************************************************************************/
-/* $Id:$ */
-#include <QSettings>
-#include <QFileDialog>
-#include <QMessageBox>
-#include <QInputDialog>
-#include <QTextCodec>
-#include "qgslogger.h"
-#include "qgsencodingfiledialog.h"
-#include "qgsopenvectorlayerdialog.h"
-#include <ogr_api.h>
-#include "qgsproviderregistry.h"
-#include "qgsnewogrconnection.h"
-#include "qgsogrhelperfunctions.h"
-#include "qgscontexthelp.h"
-
-QgsOpenVectorLayerDialog::QgsOpenVectorLayerDialog( QWidget* parent, Qt::WFlags fl )
- : QDialog( parent, fl )
-{
- setupUi( this );
- cmbDatabaseTypes->blockSignals( true );
- cmbConnections->blockSignals( true );
- radioSrcFile->setChecked( true );
- //set encoding
- cmbEncodings->setItemText( cmbEncodings->currentIndex(), QString( QTextCodec::codecForLocale()->name() ) );
-
- //add database drivers
- mVectorFileFilter = QgsProviderRegistry::instance()->fileVectorFilters();
- QgsDebugMsg( "Database drivers :" + QgsProviderRegistry::instance()->databaseDrivers() );
- QStringList dbDrivers = QgsProviderRegistry::instance()->databaseDrivers().split( ";" );
-
- for ( int i = 0;i < dbDrivers.count();i++ )
- {
- QString dbDriver = dbDrivers.at( i );
- if (( !dbDriver.isEmpty() ) && ( !dbDriver.isNull() ) )
- cmbDatabaseTypes->addItem( dbDriver.split( "," ).at( 0 ) );
- }
-
- //add directory drivers
- QStringList dirDrivers = QgsProviderRegistry::instance()->directoryDrivers().split( ";" );
- for ( int i = 0;i < dirDrivers.count();i++ )
- {
- QString dirDriver = dirDrivers.at( i );
- if (( !dirDriver.isEmpty() ) && ( !dirDriver.isNull() ) )
- cmbDirectoryTypes->addItem( dirDriver.split( "," ).at( 0 ) );
- }
-
- //add protocol drivers
- QStringList proDrivers = QgsProviderRegistry::instance()->protocolDrivers().split( ";" );
- for ( int i = 0;i < proDrivers.count();i++ )
- {
- QString proDriver = proDrivers.at( i );
- if (( !proDriver.isEmpty() ) && ( !proDriver.isNull() ) )
- cmbProtocolTypes->addItem( proDriver.split( "," ).at( 0 ) );
- }
- cmbDatabaseTypes->blockSignals( false );
- cmbConnections->blockSignals( false );
-}
-
-QgsOpenVectorLayerDialog::~QgsOpenVectorLayerDialog()
-{
-}
-
-QStringList QgsOpenVectorLayerDialog::openFile()
-{
-
- QStringList selectedFiles;
- QgsDebugMsg( "Vector file filters: " + mVectorFileFilter );
- QString enc;
- QString title = tr( "Open an OGR Supported Vector Layer" );
- openFilesRememberingFilter( "lastVectorFileFilter", mVectorFileFilter, selectedFiles,
- title );
- mEnc = enc;
- return selectedFiles;
-}
-
-QString QgsOpenVectorLayerDialog::openDirectory()
-{
- QSettings settings;
-
- bool haveLastUsedDir = settings.contains( "/UI/LastUsedDirectory" );
- QString lastUsedDir = settings.value( "/UI/LastUsedDirectory",
- QVariant( QString::null ) ).toString();
- if ( !haveLastUsedDir )
- lastUsedDir = "";
-
- QString path = QFileDialog::getExistingDirectory( this,
- tr( "Open Directory" ), lastUsedDir,
- QFileDialog::ShowDirsOnly | QFileDialog::DontResolveSymlinks );
-
- settings.setValue( "/UI/LastUsedDirectory", path );
- //process path if it is grass
- if ( cmbDirectoryTypes->currentText() == "Grass Vector" )
- {
-#ifdef WIN32
- //replace backslashes with forward slashes
- path.replace( "\\", "/" );
-#endif
- path = path + "/head";
- }
- return path;
-}
-
-QStringList QgsOpenVectorLayerDialog::dataSources()
-{
- return mDataSources;
-}
-
-QString QgsOpenVectorLayerDialog::encoding()
-{
- return cmbEncodings->currentText();
-}
-
-void QgsOpenVectorLayerDialog::helpInfo()
-{
- QgsContextHelp::run( context_id );
-}
-
-void QgsOpenVectorLayerDialog::addNewConnection()
-{
- QgsNewOgrConnection *nc = new QgsNewOgrConnection( this );
- if ( nc->exec() )
- {
- populateConnectionList();
- }
-}
-
-void QgsOpenVectorLayerDialog::editConnection()
-{
- QgsNewOgrConnection *nc = new QgsNewOgrConnection( this, cmbDatabaseTypes->currentText(), cmbConnections->currentText() );
-
- if ( nc->exec() )
- {
- nc->saveConnection();
- }
-}
-
-void QgsOpenVectorLayerDialog::deleteConnection()
-{
- QSettings settings;
- QString key = "/" + cmbDatabaseTypes->currentText() + "/connections/" + cmbConnections->currentText();
- QString msg = tr( "Are you sure you want to remove the %1 connection and all associated settings?" )
- .arg( cmbConnections->currentText() );
- QMessageBox::StandardButton result = QMessageBox::information( this, tr( "Confirm Delete" ), msg, QMessageBox::Ok | QMessageBox::Cancel );
- if ( result == QMessageBox::Ok )
- {
- settings.remove( key + "/host" );
- settings.remove( key + "/database" );
- settings.remove( key + "/username" );
- settings.remove( key + "/password" );
- settings.remove( key + "/port" );
- settings.remove( key + "/save" );
- settings.remove( key );
- cmbConnections->removeItem( cmbConnections->currentIndex() ); // populateConnectionList();
- setConnectionListPosition();
- }
-}
-
-void QgsOpenVectorLayerDialog::populateConnectionList()
-{
- QSettings settings;
- settings.beginGroup( "/" + cmbDatabaseTypes->currentText() + "/connections" );
- QStringList keys = settings.childGroups();
- QStringList::Iterator it = keys.begin();
- cmbConnections->clear();
- while ( it != keys.end() )
- {
- cmbConnections->addItem( *it );
- ++it;
- }
- settings.endGroup();
- setConnectionListPosition();
-}
-
-void QgsOpenVectorLayerDialog::setConnectionListPosition()
-{
- QSettings settings;
- // If possible, set the item currently displayed database
-
- QString toSelect = settings.value( "/" + cmbDatabaseTypes->currentText() + "/connections/selected" ).toString();
- // Does toSelect exist in cmbConnections?
- bool set = false;
- for ( int i = 0; i < cmbConnections->count(); ++i )
- if ( cmbConnections->itemText( i ) == toSelect )
- {
- cmbConnections->setCurrentIndex( i );
- set = true;
- break;
- }
- // If we couldn't find the stored item, but there are some,
- // default to the last item (this makes some sense when deleting
- // items as it allows the user to repeatidly click on delete to
- // remove a whole lot of items).
- if ( !set && cmbConnections->count() > 0 )
- {
- // If toSelect is null, then the selected connection wasn't found
- // by QSettings, which probably means that this is the first time
- // the user has used qgis with database connections, so default to
- // the first in the list of connetions. Otherwise default to the last.
- if ( toSelect.isNull() )
- cmbConnections->setCurrentIndex( 0 );
- else
- cmbConnections->setCurrentIndex( cmbConnections->count() - 1 );
- }
-}
-
-void QgsOpenVectorLayerDialog::setConnectionTypeListPosition()
-{
- QSettings settings;
-
- QString toSelect = settings.value( "/ogr/connections/selectedtype" ).toString();
- bool set = false;
- for ( int i = 0; i < cmbDatabaseTypes->count(); ++i )
- if ( cmbDatabaseTypes->itemText( i ) == toSelect )
- {
- cmbDatabaseTypes->setCurrentIndex( i );
- set = true;
- break;
- }
-}
-
-void QgsOpenVectorLayerDialog::setSelectedConnectionType()
-{
- QSettings settings;
- QString baseKey = "/ogr/connections/";
- settings.setValue( baseKey + "selectedtype", cmbDatabaseTypes->currentText() );
- QgsDebugMsg( "Setting selected type to" + cmbDatabaseTypes->currentText() );
-}
-
-void QgsOpenVectorLayerDialog::setSelectedConnection()
-{
- QSettings settings;
- settings.setValue( "/" + cmbDatabaseTypes->currentText() + "/connections/selected", cmbConnections->currentText() );
- QgsDebugMsg( "Setting selected connection to " + cmbConnections->currentText() );
-}
-
-
-void QgsOpenVectorLayerDialog::on_buttonSelectSrc_clicked()
-{
- QSettings settings;
- QString filepath;
-
- mDataSources.clear();
-
- if ( radioSrcFile->isChecked() )
- {
- //file
-
- //mType="file";
- mDataSources = openFile();
- filepath = "";
- for ( int i = 0;i < mDataSources.count();i++ )
- filepath += mDataSources.at( i ) + ";";
- inputSrcDataset->setText( filepath );
- }
- else if ( radioSrcDirectory->isChecked() )
- {
-
- filepath = openDirectory();
- mDataSources.append( filepath );
- inputSrcDataset->setText( filepath );
- //mType="directory";
- }
- else if ( radioSrcDatabase->isChecked() )
- {
- //mType="database";
- //src = inputSrcDataset->text();
- }
- else
- {
- Q_ASSERT( !"SHOULD NEVER GET HERE" );
- }
-
-
-
-}
-
-/**
- Open files, preferring to have the default file selector be the
- last one used, if any; also, prefer to start in the last directory
- associated with filterName.
-
- @param filterName the name of the filter; used for persistent store
- key
- @param filters the file filters used for QFileDialog
-
- @param selectedFiles string list of selected files; will be empty
- if none selected
- @param title the title for the dialog
- @note
-
- Stores persistent settings under /UI/. The sub-keys will be
- filterName and filterName + "Dir".
-
- Opens dialog on last directory associated with the filter name, or
- the current working directory if this is the first time invoked
- with the current filter name.
-
-*/
-void QgsOpenVectorLayerDialog::openFilesRememberingFilter( QString const &filterName,
- QString const &filters, QStringList & selectedFiles, QString &title )
-{
-
- bool haveLastUsedFilter = false; // by default, there is no last
- // used filter
-
- QSettings settings; // where we keep last used filter in
-
- // persistant state
-
- haveLastUsedFilter = settings.contains( "/UI/" + filterName );
- QString lastUsedFilter = settings.value( "/UI/" + filterName,
- QVariant( QString::null ) ).toString();
-
- QString lastUsedDir = settings.value( "/UI/" + filterName + "Dir", "." ).toString();
-
- //QString lastUsedEncoding = settings.value( "/UI/encoding" ).toString();
-
- QgsDebugMsg( "Opening file dialog with filters: " + filters );
-
- QFileDialog* openFileDialog = new QFileDialog( 0,
- title, lastUsedDir, filters );
-
- // allow for selection of more than one file
- openFileDialog->setFileMode( QFileDialog::ExistingFiles );
-
- if ( haveLastUsedFilter ) // set the filter to the last one used
- {
- openFileDialog->selectFilter( lastUsedFilter );
- }
-
- if ( openFileDialog->exec() == QDialog::Accepted )
- {
- selectedFiles = openFileDialog->selectedFiles();
- //enc = openFileDialog->encoding();
- // Fix by Tim - getting the dirPath from the dialog
- // directly truncates the last node in the dir path.
- // This is a workaround for that
- QString myFirstFileName = selectedFiles.first();
- QFileInfo myFI( myFirstFileName );
- QString myPath = myFI.path();
-
- QgsDebugMsg( "Writing last used dir: " + myPath );
-
- settings.setValue( "/UI/" + filterName, openFileDialog->selectedFilter() );
- settings.setValue( "/UI/" + filterName + "Dir", myPath );
- //settings.setValue( "/UI/encoding", openFileDialog->encoding() );
- }
-
- delete openFileDialog;
-
-} // openFilesRememberingFilter_
-
-//********************auto connected slots *****************/
-void QgsOpenVectorLayerDialog::on_buttonBox_accepted()
-{
- QgsDebugMsg( "dialog button accepted" );
- if ( radioSrcDatabase->isChecked() )
- {
- mDataSources.clear();
- QSettings settings;
- QString baseKey = "/" + cmbDatabaseTypes->currentText() + "/connections/";
- baseKey += cmbConnections->currentText();
- QString host = settings.value( baseKey + "/host" ).toString();
- QString database = settings.value( baseKey + "/database" ).toString();
- QString port = settings.value( baseKey + "/port" ).toString();
- QString user = settings.value( baseKey + "/username" ).toString();
- QString pass = settings.value( baseKey + "/password" ).toString();
- bool makeConnection = false;
- if ( pass.isEmpty() )
- pass = QInputDialog::getText( this, tr( "Password for " ) + user,
- tr( "Please enter your password:" ),
- QLineEdit::Password, QString::null, &makeConnection );
- if ( makeConnection || ( !pass.isEmpty() ) )
- mDataSources.append( createDatabaseURI(
- cmbDatabaseTypes->currentText(),
- host,
- database,
- port,
- user,
- pass
- ) );
- }
- else if ( radioSrcProtocol->isChecked() )
- {
- mDataSources.clear();
- mDataSources.append( createProtocolURI(
- cmbProtocolTypes->currentText(),
- protocolURI->text()
- ) );
- }
- accept();
-}
-
-void QgsOpenVectorLayerDialog::on_btnHelp_clicked()
-{
- helpInfo();
-}
-
-void QgsOpenVectorLayerDialog::on_radioSrcFile_toggled( bool checked )
-{
- if ( checked )
- {
- labelDirectoryType->hide();
- cmbDirectoryTypes->hide();
- fileGroupBox->show();
- dbGroupBox->hide();
- protocolGroupBox->hide();
- layout()->setSizeConstraint( QLayout::SetFixedSize );
- }
-}
-
-void QgsOpenVectorLayerDialog::on_radioSrcDirectory_toggled( bool checked )
-{
- if ( checked )
- {
- labelDirectoryType->show();
- cmbDirectoryTypes->show();
- fileGroupBox->show();
- dbGroupBox->hide();
- protocolGroupBox->hide();
- layout()->setSizeConstraint( QLayout::SetFixedSize );
- }
-}
-
-void QgsOpenVectorLayerDialog::on_radioSrcDatabase_toggled( bool checked )
-{
- if ( checked )
- {
- layout()->blockSignals( true );
- fileGroupBox->hide();
- protocolGroupBox->hide();
- dbGroupBox->show();
- layout()->blockSignals( false );
- layout()->setSizeConstraint( QLayout::SetFixedSize );
- setConnectionTypeListPosition();
- populateConnectionList();
- setConnectionListPosition();
- }
-}
-
-void QgsOpenVectorLayerDialog::on_radioSrcProtocol_toggled( bool checked )
-{
- if ( checked )
- {
- fileGroupBox->hide();
- dbGroupBox->hide();
- protocolGroupBox->show();
- layout()->setSizeConstraint( QLayout::SetFixedSize );
- }
-}
-
-// Slot for adding a new connection
-void QgsOpenVectorLayerDialog::on_btnNew_clicked()
-{
- addNewConnection();
-}
-// Slot for deleting an existing connection
-void QgsOpenVectorLayerDialog::on_btnDelete_clicked()
-{
- deleteConnection();
-}
-
-
-// Slot for editing a connection
-void QgsOpenVectorLayerDialog::on_btnEdit_clicked()
-{
- editConnection();
-}
-
-void QgsOpenVectorLayerDialog::on_cmbDatabaseTypes_currentIndexChanged( const QString & text )
-{
- populateConnectionList();
- setSelectedConnectionType();
-}
-
-void QgsOpenVectorLayerDialog::on_cmbConnections_currentIndexChanged( const QString & text )
-{
- setSelectedConnection();
-}
-//********************end auto connected slots *****************/
-
-
+/***************************************************************************
+ qgsopenvectorlayerdialog.cpp
+ Dialog to select the type and source for ogr vectors, supports
+ file, database, directory and protocol sources.
+ -------------------
+ begin : Mon Jan 2 2009
+ copyright : (C) 2009 by Godofredo Contreras Nava
+ email : frdcn at hotmail.com
+ ***************************************************************************/
+
+/***************************************************************************
+ * *
+ * This program is free software; you can redistribute it and/or modify *
+ * it under the terms of the GNU General Public License as published by *
+ * the Free Software Foundation; either version 2 of the License, or *
+ * (at your option) any later version. *
+ * *
+ ***************************************************************************/
+/* $Id:$ */
+#include <QSettings>
+#include <QFileDialog>
+#include <QMessageBox>
+#include <QInputDialog>
+#include <QTextCodec>
+#include "qgslogger.h"
+#include "qgsencodingfiledialog.h"
+#include "qgsopenvectorlayerdialog.h"
+#include <ogr_api.h>
+#include "qgsproviderregistry.h"
+#include "qgsnewogrconnection.h"
+#include "qgsogrhelperfunctions.h"
+#include "qgscontexthelp.h"
+
+QgsOpenVectorLayerDialog::QgsOpenVectorLayerDialog( QWidget* parent, Qt::WFlags fl )
+ : QDialog( parent, fl )
+{
+ setupUi( this );
+ cmbDatabaseTypes->blockSignals( true );
+ cmbConnections->blockSignals( true );
+ radioSrcFile->setChecked( true );
+ mDataSourceType="file";
+ //set encoding
+ cmbEncodings->setItemText( cmbEncodings->currentIndex(), QString( QTextCodec::codecForLocale()->name() ) );
+
+ //add database drivers
+ mVectorFileFilter = QgsProviderRegistry::instance()->fileVectorFilters();
+ QgsDebugMsg( "Database drivers :" + QgsProviderRegistry::instance()->databaseDrivers() );
+ QStringList dbDrivers = QgsProviderRegistry::instance()->databaseDrivers().split( ";" );
+
+ for ( int i = 0;i < dbDrivers.count();i++ )
+ {
+ QString dbDriver = dbDrivers.at( i );
+ if (( !dbDriver.isEmpty() ) && ( !dbDriver.isNull() ) )
+ cmbDatabaseTypes->addItem( dbDriver.split( "," ).at( 0 ) );
+ }
+
+ //add directory drivers
+ QStringList dirDrivers = QgsProviderRegistry::instance()->directoryDrivers().split( ";" );
+ for ( int i = 0;i < dirDrivers.count();i++ )
+ {
+ QString dirDriver = dirDrivers.at( i );
+ if (( !dirDriver.isEmpty() ) && ( !dirDriver.isNull() ) )
+ cmbDirectoryTypes->addItem( dirDriver.split( "," ).at( 0 ) );
+ }
+
+ //add protocol drivers
+ QStringList proDrivers = QgsProviderRegistry::instance()->protocolDrivers().split( ";" );
+ for ( int i = 0;i < proDrivers.count();i++ )
+ {
+ QString proDriver = proDrivers.at( i );
+ if (( !proDriver.isEmpty() ) && ( !proDriver.isNull() ) )
+ cmbProtocolTypes->addItem( proDriver.split( "," ).at( 0 ) );
+ }
+ cmbDatabaseTypes->blockSignals( false );
+ cmbConnections->blockSignals( false );
+}
+
+QgsOpenVectorLayerDialog::~QgsOpenVectorLayerDialog()
+{
+}
+
+QStringList QgsOpenVectorLayerDialog::openFile()
+{
+
+ QStringList selectedFiles;
+ QgsDebugMsg( "Vector file filters: " + mVectorFileFilter );
+ QString enc;
+ QString title = tr( "Open an OGR Supported Vector Layer" );
+ openFilesRememberingFilter( "lastVectorFileFilter", mVectorFileFilter, selectedFiles,
+ title );
+ mEnc = enc;
+ return selectedFiles;
+}
+
+QString QgsOpenVectorLayerDialog::openDirectory()
+{
+ QSettings settings;
+
+ bool haveLastUsedDir = settings.contains( "/UI/LastUsedDirectory" );
+ QString lastUsedDir = settings.value( "/UI/LastUsedDirectory",
+ QVariant( QString::null ) ).toString();
+ if ( !haveLastUsedDir )
+ lastUsedDir = "";
+
+ QString path = QFileDialog::getExistingDirectory( this,
+ tr( "Open Directory" ), lastUsedDir,
+ QFileDialog::ShowDirsOnly | QFileDialog::DontResolveSymlinks );
+
+ settings.setValue( "/UI/LastUsedDirectory", path );
+ //process path if it is grass
+ if ( cmbDirectoryTypes->currentText() == "Grass Vector" )
+ {
+#ifdef WIN32
+ //replace backslashes with forward slashes
+ path.replace( "\\", "/" );
+#endif
+ path = path + "/head";
+ }
+ return path;
+}
+
+QStringList QgsOpenVectorLayerDialog::dataSources()
+{
+ return mDataSources;
+}
+
+QString QgsOpenVectorLayerDialog::encoding()
+{
+ return cmbEncodings->currentText();
+}
+
+void QgsOpenVectorLayerDialog::helpInfo()
+{
+ QgsContextHelp::run( context_id );
+}
+
+QString QgsOpenVectorLayerDialog::dataSourceType()
+{
+ return mDataSourceType;
+}
+
+void QgsOpenVectorLayerDialog::addNewConnection()
+{
+ QgsNewOgrConnection *nc = new QgsNewOgrConnection( this );
+ if ( nc->exec() )
+ {
+ populateConnectionList();
+ }
+}
+
+void QgsOpenVectorLayerDialog::editConnection()
+{
+ QgsNewOgrConnection *nc = new QgsNewOgrConnection( this, cmbDatabaseTypes->currentText(), cmbConnections->currentText() );
+
+ if ( nc->exec() )
+ {
+ nc->saveConnection();
+ }
+}
+
+void QgsOpenVectorLayerDialog::deleteConnection()
+{
+ QSettings settings;
+ QString key = "/" + cmbDatabaseTypes->currentText() + "/connections/" + cmbConnections->currentText();
+ QString msg = tr( "Are you sure you want to remove the %1 connection and all associated settings?" )
+ .arg( cmbConnections->currentText() );
+ QMessageBox::StandardButton result = QMessageBox::information( this, tr( "Confirm Delete" ), msg, QMessageBox::Ok | QMessageBox::Cancel );
+ if ( result == QMessageBox::Ok )
+ {
+ settings.remove( key + "/host" );
+ settings.remove( key + "/database" );
+ settings.remove( key + "/username" );
+ settings.remove( key + "/password" );
+ settings.remove( key + "/port" );
+ settings.remove( key + "/save" );
+ settings.remove( key );
+ cmbConnections->removeItem( cmbConnections->currentIndex() ); // populateConnectionList();
+ setConnectionListPosition();
+ }
+}
+
+void QgsOpenVectorLayerDialog::populateConnectionList()
+{
+ QSettings settings;
+ settings.beginGroup( "/" + cmbDatabaseTypes->currentText() + "/connections" );
+ QStringList keys = settings.childGroups();
+ QStringList::Iterator it = keys.begin();
+ cmbConnections->clear();
+ while ( it != keys.end() )
+ {
+ cmbConnections->addItem( *it );
+ ++it;
+ }
+ settings.endGroup();
+ setConnectionListPosition();
+}
+
+void QgsOpenVectorLayerDialog::setConnectionListPosition()
+{
+ QSettings settings;
+ // If possible, set the item currently displayed database
+
+ QString toSelect = settings.value( "/" + cmbDatabaseTypes->currentText() + "/connections/selected" ).toString();
+ // Does toSelect exist in cmbConnections?
+ bool set = false;
+ for ( int i = 0; i < cmbConnections->count(); ++i )
+ if ( cmbConnections->itemText( i ) == toSelect )
+ {
+ cmbConnections->setCurrentIndex( i );
+ set = true;
+ break;
+ }
+ // If we couldn't find the stored item, but there are some,
+ // default to the last item (this makes some sense when deleting
+ // items as it allows the user to repeatidly click on delete to
+ // remove a whole lot of items).
+ if ( !set && cmbConnections->count() > 0 )
+ {
+ // If toSelect is null, then the selected connection wasn't found
+ // by QSettings, which probably means that this is the first time
+ // the user has used qgis with database connections, so default to
+ // the first in the list of connetions. Otherwise default to the last.
+ if ( toSelect.isNull() )
+ cmbConnections->setCurrentIndex( 0 );
+ else
+ cmbConnections->setCurrentIndex( cmbConnections->count() - 1 );
+ }
+}
+
+void QgsOpenVectorLayerDialog::setConnectionTypeListPosition()
+{
+ QSettings settings;
+
+ QString toSelect = settings.value( "/ogr/connections/selectedtype" ).toString();
+ bool set = false;
+ for ( int i = 0; i < cmbDatabaseTypes->count(); ++i )
+ if ( cmbDatabaseTypes->itemText( i ) == toSelect )
+ {
+ cmbDatabaseTypes->setCurrentIndex( i );
+ set = true;
+ break;
+ }
+}
+
+void QgsOpenVectorLayerDialog::setSelectedConnectionType()
+{
+ QSettings settings;
+ QString baseKey = "/ogr/connections/";
+ settings.setValue( baseKey + "selectedtype", cmbDatabaseTypes->currentText() );
+ QgsDebugMsg( "Setting selected type to" + cmbDatabaseTypes->currentText() );
+}
+
+void QgsOpenVectorLayerDialog::setSelectedConnection()
+{
+ QSettings settings;
+ settings.setValue( "/" + cmbDatabaseTypes->currentText() + "/connections/selected", cmbConnections->currentText() );
+ QgsDebugMsg( "Setting selected connection to " + cmbConnections->currentText() );
+}
+
+
+void QgsOpenVectorLayerDialog::on_buttonSelectSrc_clicked()
+{
+ QSettings settings;
+ QString filepath;
+
+ mDataSources.clear();
+
+ if ( radioSrcFile->isChecked() )
+ {
+ //file
+
+ //mType="file";
+ mDataSources = openFile();
+ filepath = "";
+ for ( int i = 0;i < mDataSources.count();i++ )
+ filepath += mDataSources.at( i ) + ";";
+ inputSrcDataset->setText( filepath );
+ }
+ else if ( radioSrcDirectory->isChecked() )
+ {
+
+ filepath = openDirectory();
+ mDataSources.append( filepath );
+ inputSrcDataset->setText( filepath );
+ //mType="directory";
+ }
+ else if ( radioSrcDatabase->isChecked() )
+ {
+ //mType="database";
+ //src = inputSrcDataset->text();
+ }
+ else
+ {
+ Q_ASSERT( !"SHOULD NEVER GET HERE" );
+ }
+
+
+
+}
+
+/**
+ Open files, preferring to have the default file selector be the
+ last one used, if any; also, prefer to start in the last directory
+ associated with filterName.
+
+ @param filterName the name of the filter; used for persistent store
+ key
+ @param filters the file filters used for QFileDialog
+
+ @param selectedFiles string list of selected files; will be empty
+ if none selected
+ @param title the title for the dialog
+ @note
+
+ Stores persistent settings under /UI/. The sub-keys will be
+ filterName and filterName + "Dir".
+
+ Opens dialog on last directory associated with the filter name, or
+ the current working directory if this is the first time invoked
+ with the current filter name.
+
+*/
+void QgsOpenVectorLayerDialog::openFilesRememberingFilter( QString const &filterName,
+ QString const &filters, QStringList & selectedFiles, QString &title )
+{
+
+ bool haveLastUsedFilter = false; // by default, there is no last
+ // used filter
+
+ QSettings settings; // where we keep last used filter in
+
+ // persistant state
+
+ haveLastUsedFilter = settings.contains( "/UI/" + filterName );
+ QString lastUsedFilter = settings.value( "/UI/" + filterName,
+ QVariant( QString::null ) ).toString();
+
+ QString lastUsedDir = settings.value( "/UI/" + filterName + "Dir", "." ).toString();
+
+ //QString lastUsedEncoding = settings.value( "/UI/encoding" ).toString();
+
+ QgsDebugMsg( "Opening file dialog with filters: " + filters );
+
+ QFileDialog* openFileDialog = new QFileDialog( 0,
+ title, lastUsedDir, filters );
+
+ // allow for selection of more than one file
+ openFileDialog->setFileMode( QFileDialog::ExistingFiles );
+
+ if ( haveLastUsedFilter ) // set the filter to the last one used
+ {
+ openFileDialog->selectFilter( lastUsedFilter );
+ }
+
+ if ( openFileDialog->exec() == QDialog::Accepted )
+ {
+ selectedFiles = openFileDialog->selectedFiles();
+ //enc = openFileDialog->encoding();
+ // Fix by Tim - getting the dirPath from the dialog
+ // directly truncates the last node in the dir path.
+ // This is a workaround for that
+ QString myFirstFileName = selectedFiles.first();
+ QFileInfo myFI( myFirstFileName );
+ QString myPath = myFI.path();
+
+ QgsDebugMsg( "Writing last used dir: " + myPath );
+
+ settings.setValue( "/UI/" + filterName, openFileDialog->selectedFilter() );
+ settings.setValue( "/UI/" + filterName + "Dir", myPath );
+ //settings.setValue( "/UI/encoding", openFileDialog->encoding() );
+ }
+
+ delete openFileDialog;
+
+} // openFilesRememberingFilter_
+
+
+
+//********************auto connected slots *****************/
+void QgsOpenVectorLayerDialog::on_buttonBox_accepted()
+{
+ QgsDebugMsg( "dialog button accepted" );
+ if ( radioSrcDatabase->isChecked() )
+ {
+ mDataSources.clear();
+ QSettings settings;
+ QString baseKey = "/" + cmbDatabaseTypes->currentText() + "/connections/";
+ baseKey += cmbConnections->currentText();
+ QString host = settings.value( baseKey + "/host" ).toString();
+ QString database = settings.value( baseKey + "/database" ).toString();
+ QString port = settings.value( baseKey + "/port" ).toString();
+ QString user = settings.value( baseKey + "/username" ).toString();
+ QString pass = settings.value( baseKey + "/password" ).toString();
+ bool makeConnection = false;
+ if ( pass.isEmpty() )
+ pass = QInputDialog::getText( this, tr( "Password for " ) + user,
+ tr( "Please enter your password:" ),
+ QLineEdit::Password, QString::null, &makeConnection );
+ if ( makeConnection || ( !pass.isEmpty() ) )
+ mDataSources.append( createDatabaseURI(
+ cmbDatabaseTypes->currentText(),
+ host,
+ database,
+ port,
+ user,
+ pass
+ ) );
+ }
+ else if ( radioSrcProtocol->isChecked() )
+ {
+ mDataSources.clear();
+ mDataSources.append( createProtocolURI(
+ cmbProtocolTypes->currentText(),
+ protocolURI->text()
+ ) );
+ }
+ accept();
+}
+
+void QgsOpenVectorLayerDialog::on_btnHelp_clicked()
+{
+ helpInfo();
+}
+
+void QgsOpenVectorLayerDialog::on_radioSrcFile_toggled( bool checked )
+{
+ if ( checked )
+ {
+ labelDirectoryType->hide();
+ cmbDirectoryTypes->hide();
+ fileGroupBox->show();
+ dbGroupBox->hide();
+ protocolGroupBox->hide();
+ layout()->setSizeConstraint( QLayout::SetFixedSize );
+ mDataSourceType="file";
+ }
+}
+
+void QgsOpenVectorLayerDialog::on_radioSrcDirectory_toggled( bool checked )
+{
+ if ( checked )
+ {
+ labelDirectoryType->show();
+ cmbDirectoryTypes->show();
+ fileGroupBox->show();
+ dbGroupBox->hide();
+ protocolGroupBox->hide();
+ layout()->setSizeConstraint( QLayout::SetFixedSize );
+ mDataSourceType="directory";
+ }
+}
+
+void QgsOpenVectorLayerDialog::on_radioSrcDatabase_toggled( bool checked )
+{
+ if ( checked )
+ {
+ layout()->blockSignals( true );
+ fileGroupBox->hide();
+ protocolGroupBox->hide();
+ dbGroupBox->show();
+ layout()->blockSignals( false );
+ layout()->setSizeConstraint( QLayout::SetFixedSize );
+ setConnectionTypeListPosition();
+ populateConnectionList();
+ setConnectionListPosition();
+ mDataSourceType="database";
+ }
+}
+
+void QgsOpenVectorLayerDialog::on_radioSrcProtocol_toggled( bool checked )
+{
+ if ( checked )
+ {
+ fileGroupBox->hide();
+ dbGroupBox->hide();
+ protocolGroupBox->show();
+ layout()->setSizeConstraint( QLayout::SetFixedSize );
+ mDataSourceType="protocol";
+ }
+}
+
+// Slot for adding a new connection
+void QgsOpenVectorLayerDialog::on_btnNew_clicked()
+{
+ addNewConnection();
+}
+// Slot for deleting an existing connection
+void QgsOpenVectorLayerDialog::on_btnDelete_clicked()
+{
+ deleteConnection();
+}
+
+
+// Slot for editing a connection
+void QgsOpenVectorLayerDialog::on_btnEdit_clicked()
+{
+ editConnection();
+}
+
+void QgsOpenVectorLayerDialog::on_cmbDatabaseTypes_currentIndexChanged( const QString & text )
+{
+ populateConnectionList();
+ setSelectedConnectionType();
+}
+
+void QgsOpenVectorLayerDialog::on_cmbConnections_currentIndexChanged( const QString & text )
+{
+ setSelectedConnection();
+}
+//********************end auto connected slots *****************/
+
+
Modified: trunk/qgis/src/app/ogr/qgsopenvectorlayerdialog.h
===================================================================
--- trunk/qgis/src/app/ogr/qgsopenvectorlayerdialog.h 2009-04-02 21:32:13 UTC (rev 10456)
+++ trunk/qgis/src/app/ogr/qgsopenvectorlayerdialog.h 2009-04-03 04:01:19 UTC (rev 10457)
@@ -1,94 +1,97 @@
-/***************************************************************************
- qgsopenvectorlayerdialog.h
- Dialog to select the type and source for ogr vectors, supports
- file, database, directory and protocol sources.
- -------------------
- begin : Mon Jan 2 2009
- copyright : (C) 2009 by Godofredo Contreras Nava
- email : frdcn at hotmail.com
- ***************************************************************************/
-
-/***************************************************************************
- * *
- * This program is free software; you can redistribute it and/or modify *
- * it under the terms of the GNU General Public License as published by *
- * the Free Software Foundation; either version 2 of the License, or *
- * (at your option) any later version. *
- * *
- ***************************************************************************/
-/* $Id:$ */
-#ifndef QGSOPENVECTORLAYERDIALOG_H
-#define QGSOPENVECTORLAYERDIALOG_H
-
-
-#include <ui_qgsopenvectorlayerdialogbase.h>
-#include <QDialog>
-
-/**
- * Class for a dialog to select the type and source for ogr vectors, supports
- * file, database, directory and protocol sources.
- */
-class QgsOpenVectorLayerDialog : public QDialog, private Ui::QgsOpenVectorLayerDialogBase
-{
- Q_OBJECT
-
- public:
- QgsOpenVectorLayerDialog( QWidget* parent = 0, Qt::WFlags fl = 0 );
- ~QgsOpenVectorLayerDialog();
- //! Opens a dialog to select a file datasource*/
- QStringList openFile();
- //! Opens a dialog to select a directory datasource*/
- QString openDirectory();
- //! Returns a list of selected datasources*/
- QStringList dataSources();
- //! Returns the encoding selected for user*/
- QString encoding();
- //! Display the context help
- void helpInfo();
- private:
- //! Shows a dialog remembering the last directory and filter selected */
- void openFilesRememberingFilter( QString const &filterName,
- QString const &filters, QStringList & selectedFiles, QString &title );
- //! Stores the file vector filters */
- QString mVectorFileFilter;
- //! Stores the selected datasources */
- QStringList mDataSources;
- //! Stores the user selected encoding
- QString mEnc;
-
- static const int context_id = 348772824;
-
-
- private slots:
- //! Opens the create connection dialog to build a new connection
- void addNewConnection();
- //! Opens a dialog to edit an existing connection
- void editConnection();
- //! Deletes the selected connection
- void deleteConnection();
- //! Populate the connection list combo box
- void populateConnectionList();
- //! Sets the actual position in connection list
- void setConnectionListPosition();
- //! Sets the actual position in types connection list
- void setConnectionTypeListPosition();
- //! Sets the selected connection type
- void setSelectedConnectionType();
- //! Sets the selected connection
- void setSelectedConnection();
-
- void on_buttonBox_accepted();
- void on_btnHelp_clicked();
- void on_buttonSelectSrc_clicked();
- void on_radioSrcFile_toggled( bool checked );
- void on_radioSrcDirectory_toggled( bool checked );
- void on_radioSrcDatabase_toggled( bool checked );
- void on_radioSrcProtocol_toggled( bool checked );
- void on_btnNew_clicked();
- void on_btnEdit_clicked();
- void on_btnDelete_clicked();
- void on_cmbDatabaseTypes_currentIndexChanged( const QString & text );
- void on_cmbConnections_currentIndexChanged( const QString & text );
-};
-
-#endif // QGSOPENVECTORDIALOG_H
+/***************************************************************************
+ qgsopenvectorlayerdialog.h
+ Dialog to select the type and source for ogr vectors, supports
+ file, database, directory and protocol sources.
+ -------------------
+ begin : Mon Jan 2 2009
+ copyright : (C) 2009 by Godofredo Contreras Nava
+ email : frdcn at hotmail.com
+ ***************************************************************************/
+
+/***************************************************************************
+ * *
+ * This program is free software; you can redistribute it and/or modify *
+ * it under the terms of the GNU General Public License as published by *
+ * the Free Software Foundation; either version 2 of the License, or *
+ * (at your option) any later version. *
+ * *
+ ***************************************************************************/
+/* $Id:$ */
+#ifndef QGSOPENVECTORLAYERDIALOG_H
+#define QGSOPENVECTORLAYERDIALOG_H
+
+
+#include <ui_qgsopenvectorlayerdialogbase.h>
+#include <QDialog>
+
+/**
+ * Class for a dialog to select the type and source for ogr vectors, supports
+ * file, database, directory and protocol sources.
+ */
+class QgsOpenVectorLayerDialog : public QDialog, private Ui::QgsOpenVectorLayerDialogBase
+{
+ Q_OBJECT
+
+ public:
+ QgsOpenVectorLayerDialog( QWidget* parent = 0, Qt::WFlags fl = 0 );
+ ~QgsOpenVectorLayerDialog();
+ //! Opens a dialog to select a file datasource*/
+ QStringList openFile();
+ //! Opens a dialog to select a directory datasource*/
+ QString openDirectory();
+ //! Returns a list of selected datasources*/
+ QStringList dataSources();
+ //! Returns the encoding selected for user*/
+ QString encoding();
+ //! Display the context help
+ void helpInfo();
+ //! Returns the connection type
+ QString dataSourceType();
+ private:
+ //! Shows a dialog remembering the last directory and filter selected */
+ void openFilesRememberingFilter( QString const &filterName,
+ QString const &filters, QStringList & selectedFiles, QString &title );
+ //! Stores the file vector filters */
+ QString mVectorFileFilter;
+ //! Stores the selected datasources */
+ QStringList mDataSources;
+ //! Stores the user selected encoding
+ QString mEnc;
+ //! Stores the datasource type
+ QString mDataSourceType;
+ static const int context_id = 348772824;
+
+
+ private slots:
+ //! Opens the create connection dialog to build a new connection
+ void addNewConnection();
+ //! Opens a dialog to edit an existing connection
+ void editConnection();
+ //! Deletes the selected connection
+ void deleteConnection();
+ //! Populate the connection list combo box
+ void populateConnectionList();
+ //! Sets the actual position in connection list
+ void setConnectionListPosition();
+ //! Sets the actual position in types connection list
+ void setConnectionTypeListPosition();
+ //! Sets the selected connection type
+ void setSelectedConnectionType();
+ //! Sets the selected connection
+ void setSelectedConnection();
+
+ void on_buttonBox_accepted();
+ void on_btnHelp_clicked();
+ void on_buttonSelectSrc_clicked();
+ void on_radioSrcFile_toggled( bool checked );
+ void on_radioSrcDirectory_toggled( bool checked );
+ void on_radioSrcDatabase_toggled( bool checked );
+ void on_radioSrcProtocol_toggled( bool checked );
+ void on_btnNew_clicked();
+ void on_btnEdit_clicked();
+ void on_btnDelete_clicked();
+ void on_cmbDatabaseTypes_currentIndexChanged( const QString & text );
+ void on_cmbConnections_currentIndexChanged( const QString & text );
+};
+
+#endif // QGSOPENVECTORDIALOG_H
Modified: trunk/qgis/src/app/qgisapp.cpp
===================================================================
--- trunk/qgis/src/app/qgisapp.cpp 2009-04-02 21:32:13 UTC (rev 10456)
+++ trunk/qgis/src/app/qgisapp.cpp 2009-04-03 04:01:19 UTC (rev 10457)
@@ -2163,9 +2163,9 @@
// no files were selected, so just bail
mMapCanvas->freeze( false );
return;
- }
- else
- addVectorLayers( selectedSources, enc );
+ }
+ else
+ addVectorLayers( selectedSources, enc, ovl->dataSourceType() );
}
delete ovl;
@@ -2174,16 +2174,30 @@
}
-bool QgisApp::addVectorLayers( QStringList const & theLayerQStringList, const QString& enc )
+bool QgisApp::addVectorLayers( QStringList const & theLayerQStringList, const QString& enc, const QString dataSourceType )
{
-
+
for ( QStringList::ConstIterator it = theLayerQStringList.begin();
it != theLayerQStringList.end();
++it )
{
- QFileInfo fi( *it );
- QString base = fi.completeBaseName();
+ QString base;
+ if(dataSourceType=="file")
+ {
+ QFileInfo fi( *it );
+ base = fi.completeBaseName();
+ }
+ else if(dataSourceType=="database")
+ {
+ base=*it;
+ }
+ else //directory //protocol
+ {
+ QFileInfo fi( *it );
+ base = fi.completeBaseName();
+ }
+
QgsDebugMsg( "completeBaseName: " + base );
// create the layer
@@ -2317,7 +2331,7 @@
{
composedURI = uri + "|layerindex=" + list.at( i );
}
- addVectorLayer( composedURI, fileName + ":" + list.at( i ), "ogr" );
+ addVectorLayer( composedURI, list.at( i ), "ogr" );
}
}
@@ -3028,7 +3042,8 @@
//then add the layer to the view
QStringList fileNames;
fileNames.append( fileName );
- addVectorLayers( fileNames, enc );
+ //todo: the last parameter will change accordingly to layer type
+ addVectorLayers( fileNames, enc, "file" );
}
void QgisApp::fileOpen()
Modified: trunk/qgis/src/app/qgisapp.h
===================================================================
--- trunk/qgis/src/app/qgisapp.h 2009-04-02 21:32:13 UTC (rev 10456)
+++ trunk/qgis/src/app/qgisapp.h 2009-04-03 04:01:19 UTC (rev 10457)
@@ -83,9 +83,10 @@
/** \brief overloaded vesion of the privat addLayer method that takes a list of
* file names instead of prompting user with a dialog.
@param enc encoding type for the layer
+ @param dataSourceType type of ogr datasource
@returns true if successfully added layer
*/
- bool addVectorLayers( QStringList const & theLayerQStringList, const QString& enc );
+ bool addVectorLayers( QStringList const & theLayerQStringList, const QString& enc, const QString dataSourceType );
/** overloaded vesion of the private addRasterLayer()
Method that takes a list of file names instead of prompting
Modified: trunk/qgis/src/core/qgsdatasourceuri.cpp
===================================================================
--- trunk/qgis/src/core/qgsdatasourceuri.cpp 2009-04-02 21:32:13 UTC (rev 10456)
+++ trunk/qgis/src/core/qgsdatasourceuri.cpp 2009-04-03 04:01:19 UTC (rev 10457)
@@ -1,363 +1,395 @@
-/***************************************************************************
- qgsdatasourceuri.h - Structure to contain the component parts
- of a data source URI
- -------------------
- begin : Dec 5, 2004
- copyright : (C) 2004 by Gary E.Sherman
- email : sherman at mrcc.com
- ***************************************************************************/
-
-/***************************************************************************
- * *
- * This program is free software; you can redistribute it and/or modify *
- * it under the terms of the GNU General Public License as published by *
- * the Free Software Foundation; either version 2 of the License, or *
- * (at your option) any later version. *
- * *
- ***************************************************************************/
-/* $Id: qgsdatasourceuri.h 5839 2006-09-19 18:04:21Z wonder $ */
-
-#include "qgsdatasourceuri.h"
-#include "qgslogger.h"
-
-#include <QStringList>
-#include <QRegExp>
-
-QgsDataSourceURI::QgsDataSourceURI() : mSSLmode(SSLprefer)
-{
- // do nothing
-}
-
-QgsDataSourceURI::QgsDataSourceURI( QString uri ) : mSSLmode(SSLprefer)
-{
- int i = 0;
- while ( i < uri.length() )
- {
- skipBlanks( uri, i );
-
- if ( uri[i] == '=' )
- {
- QgsDebugMsg( "parameter name expected before =" );
- i++;
- continue;
- }
-
- int start = i;
-
- while ( i < uri.length() && uri[i] != '=' && !uri[i].isSpace() )
- i++;
-
- QString pname = uri.mid( start, i - start );
-
- skipBlanks( uri, i );
-
- if ( uri[i] != '=' )
- {
- QgsDebugMsg( "= expected after parameter name" );
- return;
- }
-
- i++;
-
- if ( pname == "sql" )
- {
- // rest of line is a sql where clause
- skipBlanks( uri, i );
- mSql = uri.mid( i );
- break;
- }
- else
- {
- QString pval = getValue( uri, i );
-
- if ( pname == "table" )
- {
- if ( uri[i] == '.' )
- {
- i++;
-
- mSchema = pval;
- mTable = getValue( uri, i );
- }
- else
- {
- mSchema = "";
- mTable = pval;
- }
-
- if ( uri[i] == '(' )
- {
- i++;
-
- int start = i;
- QString col;
- while ( i < uri.length() && uri[i] != ')' )
- i++;
-
- if ( i == uri.length() )
- {
- QgsDebugMsg( "closing parenthesis missing" );
- }
-
- mGeometryColumn = uri.mid( start, i - start );
-
- i++;
- }
- }
- else if ( pname == "service" )
- {
- QgsDebugMsg( "service keyword ignored" );
- }
- else if ( pname == "user" )
- {
- mUsername = pval;
- }
- else if ( pname == "password" )
- {
- mPassword = pval;
- }
- else if ( pname == "connect_timeout" )
- {
- QgsDebugMsg( "connection timeout ignored" );
- }
- else if ( pname == "dbname" )
- {
- mDatabase = pval;
- }
- else if ( pname == "host" )
- {
- mHost = pval;
- }
- else if ( pname == "hostaddr" )
- {
- QgsDebugMsg( "database host ip address ignored" );
- }
- else if ( pname == "port" )
- {
- mPort = pval;
- }
- else if ( pname == "tty" )
- {
- QgsDebugMsg( "backend debug tty ignored" );
- }
- else if ( pname == "options" )
- {
- QgsDebugMsg( "backend debug options ignored" );
- }
- else if ( pname == "sslmode" )
- {
- if( pval == "disable" )
- mSSLmode = SSLdisable;
- else if( pval == "allow" )
- mSSLmode = SSLallow;
- else if( pval == "prefer" )
- mSSLmode = SSLprefer;
- else if( pval == "require" )
- mSSLmode = SSLrequire;
- }
- else if ( pname == "requiressl" )
- {
- if( pval == "0" )
- mSSLmode = SSLdisable;
- else
- mSSLmode = SSLprefer;
- }
- else if ( pname == "krbsrvname" )
- {
- QgsDebugMsg( "kerberos server name ignored" );
- }
- else if ( pname == "gsslib" )
- {
- QgsDebugMsg( "gsslib ignored" );
- }
- else
- {
- QgsDebugMsg( "invalid connection option \"" + pname + "\" ignored" );
- }
- }
- }
-}
-
-QString QgsDataSourceURI::username() const
-{
- return mUsername;
-}
-
-QString QgsDataSourceURI::schema() const
-{
- return mSchema;
-}
-
-QString QgsDataSourceURI::table() const
-{
- return mTable;
-}
-
-QString QgsDataSourceURI::sql() const
-{
- return mSql;
-}
-
-QString QgsDataSourceURI::geometryColumn() const
-{
- return mGeometryColumn;
-}
-
-void QgsDataSourceURI::setSql( QString sql )
-{
- mSql = sql;
-}
-
-void QgsDataSourceURI::clearSchema()
-{
- mSchema = "";
-}
-
-void QgsDataSourceURI::skipBlanks( const QString &uri, int &i )
-{
- // skip space before value
- while ( i < uri.length() && uri[i].isSpace() )
- i++;
-}
-
-QString QgsDataSourceURI::getValue( const QString &uri, int &i )
-{
- skipBlanks( uri, i );
-
- // Get the parameter value
- QString pval;
- if ( uri[i] == '\'' || uri[i] == '"' )
- {
- QChar delim = uri[i];
-
- i++;
-
- // value is quoted
- for ( ;; )
- {
- if ( i == uri.length() )
- {
- QgsDebugMsg( "unterminated quoted string in connection info string" );
- return pval;
- }
-
- if ( uri[i] == '\\' )
- {
- i++;
- if ( i == uri.length() )
- continue;
- }
- else if ( uri[i] == delim )
- {
- i++;
- break;
- }
-
- pval += uri[i++];
- }
- }
- else
- {
- // value is not quoted
- while ( i < uri.length() )
- {
- if ( uri[i].isSpace() )
- {
- // end of value
- break;
- }
-
- if ( uri[i] == '\\' )
- {
- i++;
- if ( i == uri.length() )
- break;
- }
-
- pval += uri[i++];
- }
- }
-
- skipBlanks( uri, i );
-
- return pval;
-}
-
-QString QgsDataSourceURI::connectionInfo() const
-{
- QString connectionInfo = "dbname='" + mDatabase + "'";
-
- if ( mHost != "" )
- {
- connectionInfo += " host=" + mHost;
- if ( mPort != "" )
- connectionInfo += " port=" + mPort;
- }
-
- if ( mUsername != "" )
- {
- connectionInfo += " user='" + mUsername + "'"; //needs to be escaped
-
- if ( mPassword != "" )
- {
- QString p = mPassword;
- p.replace( '\\', "\\\\" );
- p.replace( '\'', "\\'" );
- connectionInfo += " password='" + p + "'";
- }
- }
-
- if ( mSSLmode == SSLdisable )
- connectionInfo += " sslmode=disable";
- else if ( mSSLmode == SSLallow )
- connectionInfo += " sslmode=allow";
- else if ( mSSLmode == SSLrequire )
- connectionInfo += " sslmode=require";
- else if ( mSSLmode == SSLprefer )
- connectionInfo += " sslmode=prefer";
-
- return connectionInfo;
-}
-
-QString QgsDataSourceURI::uri() const
-{
- return connectionInfo()
- + QString( " table=%1 (%2) sql=%3" )
- .arg( quotedTablename() )
- .arg( mGeometryColumn )
- .arg( mSql );
-}
-
-QString QgsDataSourceURI::quotedTablename() const
-{
- if ( mSchema != "" )
- return QString( "\"%1\".\"%2\"" ).arg( mSchema ).arg( mTable );
- else
- return QString( "\"%1\"" ).arg( mTable );
-}
-
-void QgsDataSourceURI::setConnection( const QString &host,
- const QString &port,
- const QString &database,
- const QString &username,
- const QString &password,
- SSLmode sslmode )
-{
- mHost = host;
- mDatabase = database;
- mPort = port;
- mUsername = username;
- mPassword = password;
- mSSLmode = sslmode;
-}
-
-void QgsDataSourceURI::setDataSource( const QString &schema,
- const QString &table,
- const QString &geometryColumn,
- const QString &sql )
-{
- mSchema = schema;
- mTable = table;
- mGeometryColumn = geometryColumn;
- mSql = sql;
-}
+/***************************************************************************
+ qgsdatasourceuri.h - Structure to contain the component parts
+ of a data source URI
+ -------------------
+ begin : Dec 5, 2004
+ copyright : (C) 2004 by Gary E.Sherman
+ email : sherman at mrcc.com
+ ***************************************************************************/
+
+/***************************************************************************
+ * *
+ * This program is free software; you can redistribute it and/or modify *
+ * it under the terms of the GNU General Public License as published by *
+ * the Free Software Foundation; either version 2 of the License, or *
+ * (at your option) any later version. *
+ * *
+ ***************************************************************************/
+/* $Id: qgsdatasourceuri.h 5839 2006-09-19 18:04:21Z wonder $ */
+
+#include "qgsdatasourceuri.h"
+#include "qgslogger.h"
+
+#include <QStringList>
+#include <QRegExp>
+
+QgsDataSourceURI::QgsDataSourceURI() : mSSLmode(SSLprefer)
+{
+ // do nothing
+}
+
+QgsDataSourceURI::QgsDataSourceURI( QString uri ) : mSSLmode(SSLprefer)
+{
+ int i = 0;
+ while ( i < uri.length() )
+ {
+ skipBlanks( uri, i );
+
+ if ( uri[i] == '=' )
+ {
+ QgsDebugMsg( "parameter name expected before =" );
+ i++;
+ continue;
+ }
+
+ int start = i;
+
+ while ( i < uri.length() && uri[i] != '=' && !uri[i].isSpace() )
+ i++;
+
+ QString pname = uri.mid( start, i - start );
+
+ skipBlanks( uri, i );
+
+ if ( uri[i] != '=' )
+ {
+ QgsDebugMsg( "= expected after parameter name" );
+ return;
+ }
+
+ i++;
+
+ if ( pname == "sql" )
+ {
+ // rest of line is a sql where clause
+ skipBlanks( uri, i );
+ mSql = uri.mid( i );
+ break;
+ }
+ else
+ {
+ QString pval = getValue( uri, i );
+
+ if ( pname == "table" )
+ {
+ if ( uri[i] == '.' )
+ {
+ i++;
+
+ mSchema = pval;
+ mTable = getValue( uri, i );
+ }
+ else
+ {
+ mSchema = "";
+ mTable = pval;
+ }
+
+ if ( uri[i] == '(' )
+ {
+ i++;
+
+ int start = i;
+ QString col;
+ while ( i < uri.length() && uri[i] != ')' )
+ i++;
+
+ if ( i == uri.length() )
+ {
+ QgsDebugMsg( "closing parenthesis missing" );
+ }
+
+ mGeometryColumn = uri.mid( start, i - start );
+
+ i++;
+ }
+ }
+ else if ( pname == "service" )
+ {
+ QgsDebugMsg( "service keyword ignored" );
+ }
+ else if ( pname == "user" )
+ {
+ mUsername = pval;
+ }
+ else if ( pname == "password" )
+ {
+ mPassword = pval;
+ }
+ else if ( pname == "connect_timeout" )
+ {
+ QgsDebugMsg( "connection timeout ignored" );
+ }
+ else if ( pname == "dbname" )
+ {
+ mDatabase = pval;
+ }
+ else if ( pname == "host" )
+ {
+ mHost = pval;
+ }
+ else if ( pname == "hostaddr" )
+ {
+ QgsDebugMsg( "database host ip address ignored" );
+ }
+ else if ( pname == "port" )
+ {
+ mPort = pval;
+ }
+ else if ( pname == "tty" )
+ {
+ QgsDebugMsg( "backend debug tty ignored" );
+ }
+ else if ( pname == "options" )
+ {
+ QgsDebugMsg( "backend debug options ignored" );
+ }
+ else if ( pname == "sslmode" )
+ {
+ if( pval == "disable" )
+ mSSLmode = SSLdisable;
+ else if( pval == "allow" )
+ mSSLmode = SSLallow;
+ else if( pval == "prefer" )
+ mSSLmode = SSLprefer;
+ else if( pval == "require" )
+ mSSLmode = SSLrequire;
+ }
+ else if ( pname == "requiressl" )
+ {
+ if( pval == "0" )
+ mSSLmode = SSLdisable;
+ else
+ mSSLmode = SSLprefer;
+ }
+ else if ( pname == "krbsrvname" )
+ {
+ QgsDebugMsg( "kerberos server name ignored" );
+ }
+ else if ( pname == "gsslib" )
+ {
+ QgsDebugMsg( "gsslib ignored" );
+ }
+ else
+ {
+ QgsDebugMsg( "invalid connection option \"" + pname + "\" ignored" );
+ }
+ }
+ }
+}
+
+QString QgsDataSourceURI::removePassword( const QString& aUri)
+{
+ QRegExp regexp;
+ regexp.setMinimal( true );
+ QString safeName( aUri );
+ //this works for postgres, ingres, mysql,
+ if((aUri.contains("PG:"))
+ ||(aUri.contains("driver=ingres"))
+ ||(aUri.contains("MySQL:")))
+ {
+ regexp.setPattern( " password=.* " );
+ safeName.replace( regexp, " " );
+ }
+ else if (aUri.contains("IDB:"))
+ {
+ regexp.setPattern( " pass=.* " );
+ safeName.replace( regexp, " " );
+ }
+ else if ((aUri.contains("OCI:"))
+ ||(aUri.contains("ODBC:")))
+ {
+ regexp.setPattern( "/.*@" );
+ safeName.replace( regexp, "/@" );
+ }
+ else if (aUri.contains("SDE:"))
+ {
+ QStringList strlist=aUri.split(",");
+ safeName=strlist[0]+","+strlist[1]+","+strlist[2]+","+strlist[3];
+ }
+ return safeName;
+}
+
+QString QgsDataSourceURI::username() const
+{
+ return mUsername;
+}
+
+QString QgsDataSourceURI::schema() const
+{
+ return mSchema;
+}
+
+QString QgsDataSourceURI::table() const
+{
+ return mTable;
+}
+
+QString QgsDataSourceURI::sql() const
+{
+ return mSql;
+}
+
+QString QgsDataSourceURI::geometryColumn() const
+{
+ return mGeometryColumn;
+}
+
+void QgsDataSourceURI::setSql( QString sql )
+{
+ mSql = sql;
+}
+
+void QgsDataSourceURI::clearSchema()
+{
+ mSchema = "";
+}
+
+void QgsDataSourceURI::skipBlanks( const QString &uri, int &i )
+{
+ // skip space before value
+ while ( i < uri.length() && uri[i].isSpace() )
+ i++;
+}
+
+QString QgsDataSourceURI::getValue( const QString &uri, int &i )
+{
+ skipBlanks( uri, i );
+
+ // Get the parameter value
+ QString pval;
+ if ( uri[i] == '\'' || uri[i] == '"' )
+ {
+ QChar delim = uri[i];
+
+ i++;
+
+ // value is quoted
+ for ( ;; )
+ {
+ if ( i == uri.length() )
+ {
+ QgsDebugMsg( "unterminated quoted string in connection info string" );
+ return pval;
+ }
+
+ if ( uri[i] == '\\' )
+ {
+ i++;
+ if ( i == uri.length() )
+ continue;
+ }
+ else if ( uri[i] == delim )
+ {
+ i++;
+ break;
+ }
+
+ pval += uri[i++];
+ }
+ }
+ else
+ {
+ // value is not quoted
+ while ( i < uri.length() )
+ {
+ if ( uri[i].isSpace() )
+ {
+ // end of value
+ break;
+ }
+
+ if ( uri[i] == '\\' )
+ {
+ i++;
+ if ( i == uri.length() )
+ break;
+ }
+
+ pval += uri[i++];
+ }
+ }
+
+ skipBlanks( uri, i );
+
+ return pval;
+}
+
+QString QgsDataSourceURI::connectionInfo() const
+{
+ QString connectionInfo = "dbname='" + mDatabase + "'";
+
+ if ( mHost != "" )
+ {
+ connectionInfo += " host=" + mHost;
+ if ( mPort != "" )
+ connectionInfo += " port=" + mPort;
+ }
+
+ if ( mUsername != "" )
+ {
+ connectionInfo += " user='" + mUsername + "'"; //needs to be escaped
+
+ if ( mPassword != "" )
+ {
+ QString p = mPassword;
+ p.replace( '\\', "\\\\" );
+ p.replace( '\'', "\\'" );
+ connectionInfo += " password='" + p + "'";
+ }
+ }
+
+ if ( mSSLmode == SSLdisable )
+ connectionInfo += " sslmode=disable";
+ else if ( mSSLmode == SSLallow )
+ connectionInfo += " sslmode=allow";
+ else if ( mSSLmode == SSLrequire )
+ connectionInfo += " sslmode=require";
+ else if ( mSSLmode == SSLprefer )
+ connectionInfo += " sslmode=prefer";
+
+ return connectionInfo;
+}
+
+QString QgsDataSourceURI::uri() const
+{
+ return connectionInfo()
+ + QString( " table=%1 (%2) sql=%3" )
+ .arg( quotedTablename() )
+ .arg( mGeometryColumn )
+ .arg( mSql );
+}
+
+QString QgsDataSourceURI::quotedTablename() const
+{
+ if ( mSchema != "" )
+ return QString( "\"%1\".\"%2\"" ).arg( mSchema ).arg( mTable );
+ else
+ return QString( "\"%1\"" ).arg( mTable );
+}
+
+void QgsDataSourceURI::setConnection( const QString &host,
+ const QString &port,
+ const QString &database,
+ const QString &username,
+ const QString &password,
+ SSLmode sslmode )
+{
+ mHost = host;
+ mDatabase = database;
+ mPort = port;
+ mUsername = username;
+ mPassword = password;
+ mSSLmode = sslmode;
+}
+
+void QgsDataSourceURI::setDataSource( const QString &schema,
+ const QString &table,
+ const QString &geometryColumn,
+ const QString &sql )
+{
+ mSchema = schema;
+ mTable = table;
+ mGeometryColumn = geometryColumn;
+ mSql = sql;
+}
Modified: trunk/qgis/src/core/qgsdatasourceuri.h
===================================================================
--- trunk/qgis/src/core/qgsdatasourceuri.h 2009-04-02 21:32:13 UTC (rev 10456)
+++ trunk/qgis/src/core/qgsdatasourceuri.h 2009-04-03 04:01:19 UTC (rev 10457)
@@ -61,6 +61,8 @@
const QString& aGeometryColumn,
const QString& aSql = QString() );
+ //! Removes password element from uris
+ static QString removePassword( const QString& aUri);
QString username() const;
QString schema() const;
Modified: trunk/qgis/src/core/qgsmaplayer.cpp
===================================================================
--- trunk/qgis/src/core/qgsmaplayer.cpp 2009-04-02 21:32:13 UTC (rev 10456)
+++ trunk/qgis/src/core/qgsmaplayer.cpp 2009-04-03 04:01:19 UTC (rev 10457)
@@ -39,6 +39,7 @@
#include "qgsapplication.h"
#include "qgsproject.h"
#include "qgslogger.h"
+#include "qgsdatasourceuri.h"
QgsMapLayer::QgsMapLayer( QgsMapLayer::LayerType type,
QString lyrname,
@@ -112,10 +113,8 @@
{
// Redo this every time we're asked for it, as we don't know if
// dataSource has changed.
- static QRegExp regexp( " password=.* " );
- regexp.setMinimal( true );
- QString safeName( mDataSource );
- return safeName.replace( regexp, " " );
+ QString safeName=QgsDataSourceURI::removePassword(mDataSource);
+ return safeName;
}
QString const & QgsMapLayer::source() const
More information about the QGIS-commit
mailing list