Skip to content

Commit cf97d7b

Browse files
author
gcontreras
committed
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/qgis@10289 c8812cc2-4d05-0410-92ff-de0c093fc19c
1 parent ab2a069 commit cf97d7b

19 files changed

+2238
-164
lines changed
Lines changed: 72 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -1,58 +1,72 @@
1-
2-
/** canonical manager of data providers
3-
4-
This is a Singleton class that manages data provider access.
5-
*/
6-
class QgsProviderRegistry
7-
{
8-
%TypeHeaderCode
9-
#include <qgsproviderregistry.h>
10-
%End
11-
12-
public:
13-
14-
/** means of accessing canonical single instance */
15-
static QgsProviderRegistry* instance(QString pluginPath = QString::null);
16-
17-
/** Virtual dectructor */
18-
virtual ~QgsProviderRegistry();
19-
20-
QString library(const QString & providerKey) const;
21-
22-
QString pluginList(bool asHtml = false) const;
23-
24-
/** return library directory where plugins are found */
25-
const QDir & libraryDirectory() const;
26-
27-
void setLibraryDirectory(const QDir & path);
28-
29-
QgsDataProvider * getProvider( const QString & providerKey,
30-
const QString & dataSource );
31-
32-
/** Return list of available providers by their keys */
33-
QStringList providerList() const;
34-
35-
/** Return metadata of the provider or NULL if not found */
36-
const QgsProviderMetadata* providerMetadata(const QString& providerKey) const;
37-
38-
/** return vector file filter string
39-
40-
Returns a string suitable for a QFileDialog of vector file formats
41-
supported by all data providers.
42-
43-
This walks through all data providers appending calls to their
44-
fileVectorFilters to a string, which is then returned.
45-
46-
@note
47-
48-
It'd be nice to eventually be raster/vector neutral.
49-
*/
50-
virtual QString fileVectorFilters() const;
51-
52-
private:
53-
54-
/** ctor private since instance() creates it */
55-
QgsProviderRegistry(QString pluginPath) /Default/ ;
56-
57-
}; // class QgsProviderRegistry
58-
1+
2+
/** canonical manager of data providers
3+
4+
This is a Singleton class that manages data provider access.
5+
*/
6+
class QgsProviderRegistry
7+
{
8+
%TypeHeaderCode
9+
#include <qgsproviderregistry.h>
10+
%End
11+
12+
public:
13+
14+
/** means of accessing canonical single instance */
15+
static QgsProviderRegistry* instance(QString pluginPath = QString::null);
16+
17+
/** Virtual dectructor */
18+
virtual ~QgsProviderRegistry();
19+
20+
QString library(const QString & providerKey) const;
21+
22+
QString pluginList(bool asHtml = false) const;
23+
24+
/** return library directory where plugins are found */
25+
const QDir & libraryDirectory() const;
26+
27+
void setLibraryDirectory(const QDir & path);
28+
29+
QgsDataProvider * getProvider( const QString & providerKey,
30+
const QString & dataSource );
31+
32+
/** Return list of available providers by their keys */
33+
QStringList providerList() const;
34+
35+
/** Return metadata of the provider or NULL if not found */
36+
const QgsProviderMetadata* providerMetadata(const QString& providerKey) const;
37+
38+
/** return vector file filter string
39+
40+
Returns a string suitable for a QFileDialog of vector file formats
41+
supported by all data providers.
42+
43+
This walks through all data providers appending calls to their
44+
fileVectorFilters to a string, which is then returned.
45+
46+
@note
47+
48+
It'd be nice to eventually be raster/vector neutral.
49+
*/
50+
virtual QString fileVectorFilters() const;
51+
/** return a string containing the available database drivers
52+
* @note this method was added in QGIS 1.1
53+
*/
54+
virtual QString databaseDrivers() const;
55+
/** return a string containing the available directory drivers
56+
* @note this method was added in QGIS 1.1
57+
*/
58+
virtual QString directoryDrivers() const;
59+
/** return a string containing the available protocol drivers
60+
* @note this method was added in QGIS 1.1
61+
*/
62+
virtual QString protocolDrivers() const;
63+
64+
65+
66+
private:
67+
68+
/** ctor private since instance() creates it */
69+
QgsProviderRegistry(QString pluginPath) /Default/ ;
70+
71+
}; // class QgsProviderRegistry
72+
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
<h3>Open Vector Layer Dialog</h3>
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
<h3>New OGR Database Connection Dialog</h3>
Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,15 @@
1-
151694916_en_US QgsBookmark
2-
32338213_en_US QgsCopyrightLabelPluginGui
3-
361087368_en_US QgsProjectProperties
4-
308026563_en_US QgsNewHttpConnection
5-
689216579_en_US QgsIdentifyResults
6-
710979116_en_US QgsServerSourceSelect
7-
929865718_en_US QgsNewConnection
8-
939347163_en_US QgsDbSourceSelect
9-
687883780_en_US QgsMeasure
10-
1033030847_en_US QgsDelimitedTextPluginGui
11-
863656587_en_US QgsMapserverExport
12-
94000531_en_US QgsVectorLayerProperties
13-
985715179_en_US QgsComposer
1+
151694916_en_US QgsBookmark
2+
32338213_en_US QgsCopyrightLabelPluginGui
3+
361087368_en_US QgsProjectProperties
4+
308026563_en_US QgsNewHttpConnection
5+
689216579_en_US QgsIdentifyResults
6+
710979116_en_US QgsServerSourceSelect
7+
929865718_en_US QgsNewConnection
8+
939347163_en_US QgsDbSourceSelect
9+
687883780_en_US QgsMeasure
10+
1033030847_en_US QgsDelimitedTextPluginGui
11+
863656587_en_US QgsMapserverExport
12+
94000531_en_US QgsVectorLayerProperties
13+
985715179_en_US QgsComposer
14+
63428984_en_US QgsNewOgrConnection
15+
348772824_en_US QgsOpenVectorLayerDialog

src/app/CMakeLists.txt

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,10 @@ SET(QGIS_APP_SRCS
7878
legend/qgslegendsymbologygroup.cpp
7979
legend/qgslegendsymbologyitem.cpp
8080
legend/qgslegendvectorsymbologyitem.cpp
81+
82+
ogr/qgsogrhelperfunctions.cpp
83+
ogr/qgsopenvectorlayerdialog.cpp
84+
ogr/qgsnewogrconnection.cpp
8185
)
8286

8387

@@ -141,6 +145,10 @@ SET (QGIS_APP_MOC_HDRS
141145
legend/qgslegend.h
142146
legend/qgslegendlayer.h
143147
legend/qgslegendlayerfile.h
148+
149+
150+
ogr/qgsopenvectorlayerdialog.h
151+
ogr/qgsnewogrconnection.h
144152
)
145153

146154
IF (POSTGRES_FOUND)
Lines changed: 145 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,145 @@
1+
/***************************************************************************
2+
qgsnewogrconnection.cpp - description
3+
-------------------
4+
begin : Mon Jan 2 2009
5+
copyright : (C) 2009 by Godofredo Contreras Nava
6+
email : frdcn at hotmail.com
7+
***************************************************************************/
8+
9+
/***************************************************************************
10+
* *
11+
* This program is free software; you can redistribute it and/or modify *
12+
* it under the terms of the GNU General Public License as published by *
13+
* the Free Software Foundation; either version 2 of the License, or *
14+
* (at your option) any later version. *
15+
* *
16+
***************************************************************************/
17+
/* $Id: $ */
18+
#include <iostream>
19+
20+
#include <QSettings>
21+
#include <QMessageBox>
22+
#include <QInputDialog>
23+
24+
#include "qgsnewogrconnection.h"
25+
#include "qgscontexthelp.h"
26+
#include "qgslogger.h"
27+
#include "qgsproviderregistry.h"
28+
#include "qgsogrhelperfunctions.h"
29+
#include <ogr_api.h>
30+
#include <cpl_error.h>
31+
32+
33+
QgsNewOgrConnection::QgsNewOgrConnection( QWidget *parent,const QString& connType, const QString& connName, Qt::WFlags fl )
34+
: QDialog( parent, fl )
35+
{
36+
setupUi( this );
37+
//add database drivers
38+
QStringList dbDrivers=QgsProviderRegistry::instance()->databaseDrivers().split(";");
39+
for(int i=0;i<dbDrivers.count();i++)
40+
{
41+
QString dbDrive=dbDrivers.at(i);
42+
cmbDatabaseTypes->addItem(dbDrive.split(",").at(0));
43+
}
44+
txtName->setEnabled(true);
45+
cmbDatabaseTypes->setEnabled(true);
46+
if ( !connName.isEmpty() )
47+
{
48+
// populate the dialog with the information stored for the connection
49+
// populate the fields with the stored setting parameters
50+
QSettings settings;
51+
QString key = "/"+connType+"/connections/" + connName;
52+
txtHost->setText( settings.value( key + "/host" ).toString() );
53+
txtDatabase->setText( settings.value( key + "/database" ).toString() );
54+
QString port = settings.value( key + "/port" ).toString();
55+
txtPort->setText( port );
56+
txtUsername->setText( settings.value( key + "/username" ).toString() );
57+
if ( settings.value( key + "/save" ).toString() == "true" )
58+
{
59+
txtPassword->setText( settings.value( key + "/password" ).toString() );
60+
chkStorePassword->setChecked( true );
61+
}
62+
cmbDatabaseTypes->setCurrentIndex(cmbDatabaseTypes->findText(connType));
63+
txtName->setText( connName );
64+
txtName->setEnabled(false);
65+
cmbDatabaseTypes->setEnabled(false);
66+
}
67+
}
68+
69+
QgsNewOgrConnection::~QgsNewOgrConnection()
70+
{
71+
}
72+
73+
void QgsNewOgrConnection::testConnection()
74+
{
75+
QString uri;
76+
uri=createDatabaseURI(cmbDatabaseTypes->currentText(), txtHost->text(),
77+
txtDatabase->text(), txtPort->text(),
78+
txtUsername->text(), txtPassword->text() );
79+
QgsDebugMsg( "Connecting using uri = " + uri );
80+
OGRRegisterAll();
81+
OGRDataSourceH poDS;
82+
OGRSFDriverH pahDriver;
83+
CPLErrorReset();
84+
poDS = OGROpen( QFile::encodeName( uri ).constData(), FALSE, &pahDriver );
85+
if( poDS == NULL )
86+
{
87+
QMessageBox::information( this, tr( "Test connection" ), tr( "Connection failed - Check settings and try again.\n\nExtended error information:\n%1" ).arg( CPLGetLastErrorMsg() ) );
88+
}
89+
else
90+
{
91+
QMessageBox::information( this, tr( "Test connection" ), tr( "Connection to %1 was successful" ).arg( uri ) );
92+
}
93+
OGRReleaseDataSource(poDS);
94+
}
95+
96+
void QgsNewOgrConnection::saveConnection()
97+
{
98+
QSettings settings;
99+
QString baseKey = "/"+cmbDatabaseTypes->currentText()+"/connections/";
100+
settings.setValue( baseKey + "selected", txtName->text() );
101+
baseKey += txtName->text();
102+
settings.setValue( baseKey + "/host", txtHost->text() );
103+
settings.setValue( baseKey + "/database", txtDatabase->text() );
104+
settings.setValue( baseKey + "/port", txtPort->text() );
105+
settings.setValue( baseKey + "/username", txtUsername->text() );
106+
settings.setValue( baseKey + "/password", chkStorePassword->isChecked() ? txtPassword->text() : "" );
107+
settings.setValue( baseKey + "/save", chkStorePassword->isChecked() ? "true" : "false" );
108+
accept();
109+
}
110+
111+
void QgsNewOgrConnection::helpInfo()
112+
{
113+
QgsContextHelp::run( context_id );
114+
}
115+
116+
/** Autoconnected SLOTS **/
117+
void QgsNewOgrConnection::on_btnOk_clicked()
118+
{
119+
saveConnection();
120+
}
121+
122+
void QgsNewOgrConnection::on_btnHelp_clicked()
123+
{
124+
helpInfo();
125+
}
126+
127+
void QgsNewOgrConnection::on_btnConnect_clicked()
128+
{
129+
testConnection();
130+
}
131+
132+
void QgsNewOgrConnection::on_btnCancel_clicked()
133+
{
134+
reject();
135+
}
136+
/** end Autoconnected SLOTS **/
137+
138+
139+
140+
141+
142+
143+
144+
145+

src/app/ogr/qgsnewogrconnection.h

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
/***************************************************************************
2+
qgsnewogrconnection.h - description
3+
-------------------
4+
begin : Mon Jan 2 2009
5+
copyright : (C) 2009 by Godofredo Contreras Nava
6+
email : frdcn at hotmail.com
7+
***************************************************************************/
8+
9+
/***************************************************************************
10+
* *
11+
* This program is free software; you can redistribute it and/or modify *
12+
* it under the terms of the GNU General Public License as published by *
13+
* the Free Software Foundation; either version 2 of the License, or *
14+
* (at your option) any later version. *
15+
* *
16+
***************************************************************************/
17+
/* $Id:$ */
18+
19+
#ifndef QGSNEWOGRCONNECTION_H
20+
#define QGSNEWOGRCONNECTION_H
21+
#include "ui_qgsnewogrconnectionbase.h"
22+
#include "qgisgui.h"
23+
24+
/*! \class QgsNewOgrConnection
25+
* \brief Dialog to allow the user to define, test and save connection
26+
* information for OGR databases
27+
*/
28+
class QgsNewOgrConnection : public QDialog, private Ui::QgsNewOgrConnectionBase
29+
{
30+
Q_OBJECT
31+
public:
32+
//! Constructor
33+
QgsNewOgrConnection( QWidget *parent = 0, const QString& connType = QString::null, const QString& connName = QString::null, Qt::WFlags fl = QgisGui::ModalDialogFlags );
34+
//! Destructor
35+
~QgsNewOgrConnection();
36+
//! Tests the connection using the parameters supplied
37+
void testConnection();
38+
//! Saves the connection to ~/.qt/qgisrc
39+
void saveConnection();
40+
//! Display the context help
41+
void helpInfo();
42+
public slots:
43+
void on_btnOk_clicked();
44+
void on_btnCancel_clicked();
45+
void on_btnHelp_clicked();
46+
void on_btnConnect_clicked();
47+
private:
48+
static const int context_id = 63428984;
49+
};
50+
51+
#endif // QGSNEWOGRCONNECTIONBASE_H

0 commit comments

Comments
 (0)