-
-
Notifications
You must be signed in to change notification settings - Fork 3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Changes in openvector dialog to support all drivers available in ogr …
…including database and protocol drivers git-svn-id: http://svn.osgeo.org/qgis/trunk@10289 c8812cc2-4d05-0410-92ff-de0c093fc19c
- Loading branch information
gcontreras
committed
Mar 18, 2009
1 parent
975d2d4
commit 5083264
Showing
19 changed files
with
2,238 additions
and
164 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,58 +1,72 @@ | ||
|
||
/** canonical manager of data providers | ||
|
||
This is a Singleton class that manages data provider access. | ||
*/ | ||
class QgsProviderRegistry | ||
{ | ||
%TypeHeaderCode | ||
#include <qgsproviderregistry.h> | ||
%End | ||
|
||
public: | ||
|
||
/** means of accessing canonical single instance */ | ||
static QgsProviderRegistry* instance(QString pluginPath = QString::null); | ||
|
||
/** Virtual dectructor */ | ||
virtual ~QgsProviderRegistry(); | ||
|
||
QString library(const QString & providerKey) const; | ||
|
||
QString pluginList(bool asHtml = false) const; | ||
|
||
/** return library directory where plugins are found */ | ||
const QDir & libraryDirectory() const; | ||
|
||
void setLibraryDirectory(const QDir & path); | ||
|
||
QgsDataProvider * getProvider( const QString & providerKey, | ||
const QString & dataSource ); | ||
|
||
/** Return list of available providers by their keys */ | ||
QStringList providerList() const; | ||
|
||
/** Return metadata of the provider or NULL if not found */ | ||
const QgsProviderMetadata* providerMetadata(const QString& providerKey) const; | ||
|
||
/** return vector file filter string | ||
|
||
Returns a string suitable for a QFileDialog of vector file formats | ||
supported by all data providers. | ||
|
||
This walks through all data providers appending calls to their | ||
fileVectorFilters to a string, which is then returned. | ||
|
||
@note | ||
|
||
It'd be nice to eventually be raster/vector neutral. | ||
*/ | ||
virtual QString fileVectorFilters() const; | ||
|
||
private: | ||
|
||
/** ctor private since instance() creates it */ | ||
QgsProviderRegistry(QString pluginPath) /Default/ ; | ||
|
||
}; // class QgsProviderRegistry | ||
|
||
|
||
/** canonical manager of data providers | ||
|
||
This is a Singleton class that manages data provider access. | ||
*/ | ||
class QgsProviderRegistry | ||
{ | ||
%TypeHeaderCode | ||
#include <qgsproviderregistry.h> | ||
%End | ||
|
||
public: | ||
|
||
/** means of accessing canonical single instance */ | ||
static QgsProviderRegistry* instance(QString pluginPath = QString::null); | ||
|
||
/** Virtual dectructor */ | ||
virtual ~QgsProviderRegistry(); | ||
|
||
QString library(const QString & providerKey) const; | ||
|
||
QString pluginList(bool asHtml = false) const; | ||
|
||
/** return library directory where plugins are found */ | ||
const QDir & libraryDirectory() const; | ||
|
||
void setLibraryDirectory(const QDir & path); | ||
|
||
QgsDataProvider * getProvider( const QString & providerKey, | ||
const QString & dataSource ); | ||
|
||
/** Return list of available providers by their keys */ | ||
QStringList providerList() const; | ||
|
||
/** Return metadata of the provider or NULL if not found */ | ||
const QgsProviderMetadata* providerMetadata(const QString& providerKey) const; | ||
|
||
/** return vector file filter string | ||
|
||
Returns a string suitable for a QFileDialog of vector file formats | ||
supported by all data providers. | ||
|
||
This walks through all data providers appending calls to their | ||
fileVectorFilters to a string, which is then returned. | ||
|
||
@note | ||
|
||
It'd be nice to eventually be raster/vector neutral. | ||
*/ | ||
virtual QString fileVectorFilters() const; | ||
/** return a string containing the available database drivers | ||
* @note this method was added in QGIS 1.1 | ||
*/ | ||
virtual QString databaseDrivers() const; | ||
/** return a string containing the available directory drivers | ||
* @note this method was added in QGIS 1.1 | ||
*/ | ||
virtual QString directoryDrivers() const; | ||
/** return a string containing the available protocol drivers | ||
* @note this method was added in QGIS 1.1 | ||
*/ | ||
virtual QString protocolDrivers() const; | ||
|
||
|
||
|
||
private: | ||
|
||
/** ctor private since instance() creates it */ | ||
QgsProviderRegistry(QString pluginPath) /Default/ ; | ||
|
||
}; // class QgsProviderRegistry | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
<h3>Open Vector Layer Dialog</h3> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
<h3>New OGR Database Connection Dialog</h3> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,15 @@ | ||
151694916_en_US QgsBookmark | ||
32338213_en_US QgsCopyrightLabelPluginGui | ||
361087368_en_US QgsProjectProperties | ||
308026563_en_US QgsNewHttpConnection | ||
689216579_en_US QgsIdentifyResults | ||
710979116_en_US QgsServerSourceSelect | ||
929865718_en_US QgsNewConnection | ||
939347163_en_US QgsDbSourceSelect | ||
687883780_en_US QgsMeasure | ||
1033030847_en_US QgsDelimitedTextPluginGui | ||
863656587_en_US QgsMapserverExport | ||
94000531_en_US QgsVectorLayerProperties | ||
985715179_en_US QgsComposer | ||
151694916_en_US QgsBookmark | ||
32338213_en_US QgsCopyrightLabelPluginGui | ||
361087368_en_US QgsProjectProperties | ||
308026563_en_US QgsNewHttpConnection | ||
689216579_en_US QgsIdentifyResults | ||
710979116_en_US QgsServerSourceSelect | ||
929865718_en_US QgsNewConnection | ||
939347163_en_US QgsDbSourceSelect | ||
687883780_en_US QgsMeasure | ||
1033030847_en_US QgsDelimitedTextPluginGui | ||
863656587_en_US QgsMapserverExport | ||
94000531_en_US QgsVectorLayerProperties | ||
985715179_en_US QgsComposer | ||
63428984_en_US QgsNewOgrConnection | ||
348772824_en_US QgsOpenVectorLayerDialog |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,145 @@ | ||
/*************************************************************************** | ||
qgsnewogrconnection.cpp - description | ||
------------------- | ||
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 <iostream> | ||
|
||
#include <QSettings> | ||
#include <QMessageBox> | ||
#include <QInputDialog> | ||
|
||
#include "qgsnewogrconnection.h" | ||
#include "qgscontexthelp.h" | ||
#include "qgslogger.h" | ||
#include "qgsproviderregistry.h" | ||
#include "qgsogrhelperfunctions.h" | ||
#include <ogr_api.h> | ||
#include <cpl_error.h> | ||
|
||
|
||
QgsNewOgrConnection::QgsNewOgrConnection( QWidget *parent,const QString& connType, const QString& connName, Qt::WFlags fl ) | ||
: QDialog( parent, fl ) | ||
{ | ||
setupUi( this ); | ||
//add database drivers | ||
QStringList dbDrivers=QgsProviderRegistry::instance()->databaseDrivers().split(";"); | ||
for(int i=0;i<dbDrivers.count();i++) | ||
{ | ||
QString dbDrive=dbDrivers.at(i); | ||
cmbDatabaseTypes->addItem(dbDrive.split(",").at(0)); | ||
} | ||
txtName->setEnabled(true); | ||
cmbDatabaseTypes->setEnabled(true); | ||
if ( !connName.isEmpty() ) | ||
{ | ||
// populate the dialog with the information stored for the connection | ||
// populate the fields with the stored setting parameters | ||
QSettings settings; | ||
QString key = "/"+connType+"/connections/" + connName; | ||
txtHost->setText( settings.value( key + "/host" ).toString() ); | ||
txtDatabase->setText( settings.value( key + "/database" ).toString() ); | ||
QString port = settings.value( key + "/port" ).toString(); | ||
txtPort->setText( port ); | ||
txtUsername->setText( settings.value( key + "/username" ).toString() ); | ||
if ( settings.value( key + "/save" ).toString() == "true" ) | ||
{ | ||
txtPassword->setText( settings.value( key + "/password" ).toString() ); | ||
chkStorePassword->setChecked( true ); | ||
} | ||
cmbDatabaseTypes->setCurrentIndex(cmbDatabaseTypes->findText(connType)); | ||
txtName->setText( connName ); | ||
txtName->setEnabled(false); | ||
cmbDatabaseTypes->setEnabled(false); | ||
} | ||
} | ||
|
||
QgsNewOgrConnection::~QgsNewOgrConnection() | ||
{ | ||
} | ||
|
||
void QgsNewOgrConnection::testConnection() | ||
{ | ||
QString uri; | ||
uri=createDatabaseURI(cmbDatabaseTypes->currentText(), txtHost->text(), | ||
txtDatabase->text(), txtPort->text(), | ||
txtUsername->text(), txtPassword->text() ); | ||
QgsDebugMsg( "Connecting using uri = " + uri ); | ||
OGRRegisterAll(); | ||
OGRDataSourceH poDS; | ||
OGRSFDriverH pahDriver; | ||
CPLErrorReset(); | ||
poDS = OGROpen( QFile::encodeName( uri ).constData(), FALSE, &pahDriver ); | ||
if( poDS == NULL ) | ||
{ | ||
QMessageBox::information( this, tr( "Test connection" ), tr( "Connection failed - Check settings and try again.\n\nExtended error information:\n%1" ).arg( CPLGetLastErrorMsg() ) ); | ||
} | ||
else | ||
{ | ||
QMessageBox::information( this, tr( "Test connection" ), tr( "Connection to %1 was successful" ).arg( uri ) ); | ||
} | ||
OGRReleaseDataSource(poDS); | ||
} | ||
|
||
void QgsNewOgrConnection::saveConnection() | ||
{ | ||
QSettings settings; | ||
QString baseKey = "/"+cmbDatabaseTypes->currentText()+"/connections/"; | ||
settings.setValue( baseKey + "selected", txtName->text() ); | ||
baseKey += txtName->text(); | ||
settings.setValue( baseKey + "/host", txtHost->text() ); | ||
settings.setValue( baseKey + "/database", txtDatabase->text() ); | ||
settings.setValue( baseKey + "/port", txtPort->text() ); | ||
settings.setValue( baseKey + "/username", txtUsername->text() ); | ||
settings.setValue( baseKey + "/password", chkStorePassword->isChecked() ? txtPassword->text() : "" ); | ||
settings.setValue( baseKey + "/save", chkStorePassword->isChecked() ? "true" : "false" ); | ||
accept(); | ||
} | ||
|
||
void QgsNewOgrConnection::helpInfo() | ||
{ | ||
QgsContextHelp::run( context_id ); | ||
} | ||
|
||
/** Autoconnected SLOTS **/ | ||
void QgsNewOgrConnection::on_btnOk_clicked() | ||
{ | ||
saveConnection(); | ||
} | ||
|
||
void QgsNewOgrConnection::on_btnHelp_clicked() | ||
{ | ||
helpInfo(); | ||
} | ||
|
||
void QgsNewOgrConnection::on_btnConnect_clicked() | ||
{ | ||
testConnection(); | ||
} | ||
|
||
void QgsNewOgrConnection::on_btnCancel_clicked() | ||
{ | ||
reject(); | ||
} | ||
/** end Autoconnected SLOTS **/ | ||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
/*************************************************************************** | ||
qgsnewogrconnection.h - description | ||
------------------- | ||
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 QGSNEWOGRCONNECTION_H | ||
#define QGSNEWOGRCONNECTION_H | ||
#include "ui_qgsnewogrconnectionbase.h" | ||
#include "qgisgui.h" | ||
|
||
/*! \class QgsNewOgrConnection | ||
* \brief Dialog to allow the user to define, test and save connection | ||
* information for OGR databases | ||
*/ | ||
class QgsNewOgrConnection : public QDialog, private Ui::QgsNewOgrConnectionBase | ||
{ | ||
Q_OBJECT | ||
public: | ||
//! Constructor | ||
QgsNewOgrConnection( QWidget *parent = 0, const QString& connType = QString::null, const QString& connName = QString::null, Qt::WFlags fl = QgisGui::ModalDialogFlags ); | ||
//! Destructor | ||
~QgsNewOgrConnection(); | ||
//! Tests the connection using the parameters supplied | ||
void testConnection(); | ||
//! Saves the connection to ~/.qt/qgisrc | ||
void saveConnection(); | ||
//! Display the context help | ||
void helpInfo(); | ||
public slots: | ||
void on_btnOk_clicked(); | ||
void on_btnCancel_clicked(); | ||
void on_btnHelp_clicked(); | ||
void on_btnConnect_clicked(); | ||
private: | ||
static const int context_id = 63428984; | ||
}; | ||
|
||
#endif // QGSNEWOGRCONNECTIONBASE_H |
Oops, something went wrong.