Skip to content
Permalink
Browse files
Adding the native MSSQL provider
  • Loading branch information
szekerest committed Mar 23, 2012
1 parent a2ee769 commit d212ca7f7174a2063f245e31e27f2848387c1df0
Show file tree
Hide file tree
Showing 25 changed files with 5,411 additions and 1 deletion.
@@ -191,6 +191,9 @@ IF (SPATIALITE_FOUND)
SET (HAVE_SPATIALITE TRUE)
ENDIF (SPATIALITE_FOUND)

# following variable is used in qgsconfig.h
SET (HAVE_MSSQL TRUE)

#############################################################
# search for Qt4
SET(QT_MIN_VERSION 4.4.0)
@@ -31,6 +31,8 @@

#cmakedefine HAVE_SPATIALITE

#cmakedefine HAVE_MSSQL

#cmakedefine HAVE_PYTHON

#endif
@@ -49,6 +49,7 @@ Richard Kostecky
Robert Szczepanek
Stefanie Tellex
Steven Mizuno
Tamas Szekeres
Tom Russo
Tyler Mitchell
Vita Cizek
@@ -363,8 +363,10 @@
<file>themes/gis/mIconSpatialite.png</file>
<file>themes/gis/mIconRaster.png</file>
<file>themes/gis/mIconPostgis.png</file>
<file>themes/gis/mIconMssql.png</file>
<file>themes/gis/mIconConnect.png</file>
<file>themes/gis/mIconDbSchema.png</file>
<file>themes/default/mActionAddMssqlLayer.png</file>
</qresource>
<qresource prefix="/images/tips">
<file alias="symbol_levels.png">qgis_tips/symbol_levels.png</file>
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@@ -860,6 +860,7 @@ void QgisApp::createActions()
connect( mActionAddRasterLayer, SIGNAL( triggered() ), this, SLOT( addRasterLayer() ) );
connect( mActionAddPgLayer, SIGNAL( triggered() ), this, SLOT( addDatabaseLayer() ) );
connect( mActionAddSpatiaLiteLayer, SIGNAL( triggered() ), this, SLOT( addSpatiaLiteLayer() ) );
connect( mActionAddMssqlLayer, SIGNAL( triggered() ), this, SLOT( addMssqlLayer() ) );
connect( mActionAddWmsLayer, SIGNAL( triggered() ), this, SLOT( addWmsLayer() ) );
connect( mActionAddWfsLayer, SIGNAL( triggered() ), this, SLOT( addWfsLayer() ) );
connect( mActionOpenTable, SIGNAL( triggered() ), this, SLOT( attributeTable() ) );
@@ -950,6 +951,11 @@ void QgisApp::createActions()
mActionAddPgLayer = NULL;
#endif

#ifndef HAVE_MSSQL
delete mActionAddMssqlLayer;
mActionAddMssqlLayer = NULL;
#endif

}

#include "qgsstylev2.h"
@@ -1471,6 +1477,9 @@ void QgisApp::setTheme( QString theThemeName )
#ifdef HAVE_SPATIALITE
mActionNewSpatialiteLayer->setIcon( getThemeIcon( "/mActionNewVectorLayer.png" ) );
mActionAddSpatiaLiteLayer->setIcon( getThemeIcon( "/mActionAddSpatiaLiteLayer.png" ) );
#endif
#ifdef HAVE_MSSQL
mActionAddMssqlLayer->setIcon( getThemeIcon( "/mActionAddMssqlLayer.png" ) );
#endif
mActionRemoveLayer->setIcon( getThemeIcon( "/mActionRemoveLayer.png" ) );
mActionSetLayerCRS->setIcon( getThemeIcon( "/mActionSetLayerCRS.png" ) );
@@ -2515,6 +2524,31 @@ void QgisApp::addSpatiaLiteLayer()
} // QgisApp::addSpatiaLiteLayer()
#endif

#ifndef HAVE_MSSQL
void QgisApp::addMssqlLayer() {}
#else
void QgisApp::addMssqlLayer()
{
if ( mMapCanvas && mMapCanvas->isDrawing() )
{
return;
}

// show the MS SQL dialog
QDialog *dbs = dynamic_cast<QDialog*>( QgsProviderRegistry::instance()->selectWidget( QString( "mssql" ), this ) );
if ( !dbs )
{
QMessageBox::warning( this, tr( "MSSQL" ), tr( "Cannot get MS SQL select dialog from provider." ) );
return;
}
connect( dbs , SIGNAL( addDatabaseLayers( QStringList const &, QString const & ) ),
this , SLOT( addDatabaseLayers( QStringList const &, QString const & ) ) );
dbs->exec();
delete dbs;

} // QgisApp::addMssqlLayer()
#endif

void QgisApp::addWmsLayer()
{
if ( mMapCanvas && mMapCanvas->isDrawing() )
@@ -502,6 +502,10 @@ class QgisApp : public QMainWindow, private Ui::MainWindow
//! Add a SpatiaLite layer to the map
void addSpatiaLiteLayer();
//#endif
//#ifdef HAVE_MSSQL
//! Add a SpatiaLite layer to the map
void addMssqlLayer();
//#endif
/** toggles whether the current selected layer is in overview or not */
void isInOverview();
//! Slot to show the map coordinate position of the mouse cursor
@@ -108,6 +108,9 @@ void QgsManageConnectionsDialog::doExportImport()
case PostGIS:
doc = savePgConnections( items );
break;
case MSSQL:
doc = saveMssqlConnections( items );
break;
}

QFile file( mFileName );
@@ -161,6 +164,9 @@ void QgsManageConnectionsDialog::doExportImport()
case PostGIS:
loadPgConnections( doc, items );
break;
case MSSQL:
loadMssqlConnections( doc, items );
break;
}
// clear connections list and close window
listConnections->clear();
@@ -187,6 +193,9 @@ bool QgsManageConnectionsDialog::populateConnections()
case PostGIS:
settings.beginGroup( "/PostgreSQL/connections" );
break;
case MSSQL:
settings.beginGroup( "/MSSQL/connections" );
break;
}
QStringList keys = settings.childGroups();
QStringList::Iterator it = keys.begin();
@@ -256,6 +265,15 @@ bool QgsManageConnectionsDialog::populateConnections()
return false;
}
break;

case MSSQL:
if ( root.tagName() != "qgsMssqlConnections" )
{
QMessageBox::information( this, tr( "Loading connections" ),
tr( "The file is not an MSSQL connections exchange file." ) );
return false;
}
break;
}

QDomElement child = root.firstChildElement();
@@ -363,6 +381,47 @@ QDomDocument QgsManageConnectionsDialog::savePgConnections( const QStringList &c
return doc;
}

QDomDocument QgsManageConnectionsDialog::saveMssqlConnections( const QStringList &connections )
{
QDomDocument doc( "connections" );
QDomElement root = doc.createElement( "qgsMssqlConnections" );
root.setAttribute( "version", "1.0" );
doc.appendChild( root );

QSettings settings;
QString path;
for ( int i = 0; i < connections.count(); ++i )
{
path = "/MSSQL/connections/" + connections[ i ];
QDomElement el = doc.createElement( "mssql" );
el.setAttribute( "name", connections[ i ] );
el.setAttribute( "host", settings.value( path + "/host", "" ).toString() );
el.setAttribute( "port", settings.value( path + "/port", "" ).toString() );
el.setAttribute( "database", settings.value( path + "/database", "" ).toString() );
el.setAttribute( "service", settings.value( path + "/service", "" ).toString() );
el.setAttribute( "sslmode", settings.value( path + "/sslmode", "1" ).toString() );
el.setAttribute( "estimatedMetadata", settings.value( path + "/estimatedMetadata", "0" ).toString() );

el.setAttribute( "saveUsername", settings.value( path + "/saveUsername", "false" ).toString() );

if ( settings.value( path + "/saveUsername", "false" ).toString() == "true" )
{
el.setAttribute( "username", settings.value( path + "/username", "" ).toString() );
}

el.setAttribute( "savePassword", settings.value( path + "/savePassword", "false" ).toString() );

if ( settings.value( path + "/savePassword", "false" ).toString() == "true" )
{
el.setAttribute( "password", settings.value( path + "/password", "" ).toString() );
}

root.appendChild( el );
}

return doc;
}

void QgsManageConnectionsDialog::loadWMSConnections( const QDomDocument &doc, const QStringList &items )
{
QDomElement root = doc.documentElement();
@@ -616,6 +675,96 @@ void QgsManageConnectionsDialog::loadPgConnections( const QDomDocument &doc, con
}
}

void QgsManageConnectionsDialog::loadMssqlConnections( const QDomDocument &doc, const QStringList &items )
{
QDomElement root = doc.documentElement();
if ( root.tagName() != "qgsMssqlConnections" )
{
QMessageBox::information( this,
tr( "Loading connections" ),
tr( "The file is not an PostGIS connections exchange file." ) );
return;
}

QString connectionName;
QSettings settings;
settings.beginGroup( "/MSSQL/connections" );
QStringList keys = settings.childGroups();
settings.endGroup();
QDomElement child = root.firstChildElement();
bool prompt = true;
bool overwrite = true;

while ( !child.isNull() )
{
connectionName = child.attribute( "name" );
if ( !items.contains( connectionName ) )
{
child = child.nextSiblingElement();
continue;
}

// check for duplicates
if ( keys.contains( connectionName ) && prompt )
{
int res = QMessageBox::warning( this,
tr( "Loading connections" ),
tr( "Connection with name '%1' already exists. Overwrite?" )
.arg( connectionName ),
QMessageBox::Yes | QMessageBox::YesToAll | QMessageBox::No | QMessageBox::NoToAll | QMessageBox::Cancel );
switch ( res )
{
case QMessageBox::Cancel:
return;
case QMessageBox::No:
child = child.nextSiblingElement();
continue;
case QMessageBox::Yes:
overwrite = true;
break;
case QMessageBox::YesToAll:
prompt = false;
overwrite = true;
break;
case QMessageBox::NoToAll:
prompt = false;
overwrite = false;
break;
}
}

if ( keys.contains( connectionName ) && !overwrite )
{
child = child.nextSiblingElement();
continue;
}

//no dups detected or overwrite is allowed
settings.beginGroup( "/MSSQL/connections/" + connectionName );

settings.setValue( "/host", child.attribute( "host" ) );
settings.setValue( "/port", child.attribute( "port" ) );
settings.setValue( "/database", child.attribute( "database" ) );
if ( child.hasAttribute( "service" ) )
{
settings.setValue( "/service", child.attribute( "service" ) );
}
else
{
settings.setValue( "/service", "" );
}
settings.setValue( "/sslmode", child.attribute( "sslmode" ) );
settings.setValue( "/estimatedMetadata", child.attribute( "estimatedMetadata" ) );
settings.setValue( "/saveUsername", child.attribute( "saveUsername" ) );
settings.setValue( "/username", child.attribute( "username" ) );
settings.setValue( "/savePassword", child.attribute( "savePassword" ) );
settings.setValue( "/password", child.attribute( "password" ) );
settings.endGroup();

child = child.nextSiblingElement();
}
}

void QgsManageConnectionsDialog::selectAll()
{
listConnections->selectAll();
@@ -38,6 +38,7 @@ class GUI_EXPORT QgsManageConnectionsDialog : public QDialog, private Ui::QgsMan
WMS,
PostGIS,
WFS,
MSSQL,
};

// constructor
@@ -55,9 +56,11 @@ class GUI_EXPORT QgsManageConnectionsDialog : public QDialog, private Ui::QgsMan
QDomDocument saveWMSConnections( const QStringList &connections );
QDomDocument saveWFSConnections( const QStringList &connections );
QDomDocument savePgConnections( const QStringList & connections );
QDomDocument saveMssqlConnections( const QStringList & connections );
void loadWMSConnections( const QDomDocument &doc, const QStringList &items );
void loadWFSConnections( const QDomDocument &doc, const QStringList &items );
void loadPgConnections( const QDomDocument &doc, const QStringList &items );
void loadMssqlConnections( const QDomDocument &doc, const QStringList &items );

QString mFileName;
Mode mDialogMode;
@@ -9,6 +9,7 @@ ADD_SUBDIRECTORY(delimitedtext)
ADD_SUBDIRECTORY(osm)
ADD_SUBDIRECTORY(sqlanywhere)
ADD_SUBDIRECTORY(gdal)
ADD_SUBDIRECTORY(mssql)

IF (POSTGRES_FOUND)
ADD_SUBDIRECTORY(postgres)
@@ -0,0 +1,35 @@

SET (MSSQL_SRCS qgsmssqlprovider.cpp qgsmssqlgeometryparser.cpp qgsmssqlsourceselect.cpp qgsmssqltablemodel.cpp qgsmssqlnewconnection.cpp qgsmssqldataitems.cpp)

SET (MSSQL_MOC_HDRS qgsmssqlprovider.h qgsmssqlsourceselect.h qgsmssqltablemodel.h qgsmssqlnewconnection.h qgsmssqldataitems.h)

########################################################
# Build

QT4_WRAP_CPP(MSSQL_MOC_SRCS ${MSSQL_MOC_HDRS})

INCLUDE_DIRECTORIES(
.
../../core
${GDAL_INCLUDE_DIR}
${GEOS_INCLUDE_DIR}
${QT_INCLUDE_DIR}
../../gui
${CMAKE_CURRENT_BINARY_DIR}/../../ui
)


ADD_LIBRARY(mssqlprovider MODULE ${MSSQL_SRCS} ${MSSQL_MOC_SRCS})

TARGET_LINK_LIBRARIES(mssqlprovider
qgis_core
qgis_gui
${QT_QTSQL_LIBRARY}
)
########################################################
# Install

INSTALL (TARGETS mssqlprovider
RUNTIME DESTINATION ${QGIS_PLUGIN_DIR}
LIBRARY DESTINATION ${QGIS_PLUGIN_DIR})

0 comments on commit d212ca7

Please sign in to comment.