Skip to content
Permalink
Browse files

[FEATURE] PostGIS connections and layer now available from browser

Merge of one part of Giuseppe's Summer of Code work
  • Loading branch information
wonder-sk committed Sep 6, 2011
2 parents cfedf09 + f932140 commit 49e4e998c63705b6a97ce85903f9a2cf09996c60
@@ -19,8 +19,6 @@ SET(QGIS_APP_SRCS
qgsconfigureshortcutsdialog.cpp
qgscustomization.cpp
qgscustomprojectiondialog.cpp
qgsdbfilterproxymodel.cpp
qgsdbtablemodel.cpp
qgsdecorationcopyright.cpp
qgsdecorationcopyrightdialog.cpp
qgsdecorationnortharrow.cpp
@@ -158,7 +156,6 @@ SET (QGIS_APP_MOC_HDRS
qgscontinuouscolordialog.h
qgscustomization.h
qgscustomprojectiondialog.h
qgsdbtablemodel.h
qgsdecorationcopyright.h
qgsdecorationcopyrightdialog.h
qgsdecorationnortharrow.h
@@ -322,15 +319,6 @@ IF (POSTGRES_FOUND)
IF(HAVE_PGCONFIG)
ADD_DEFINITIONS(-DHAVE_PGCONFIG=1)
ENDIF(HAVE_PGCONFIG)

SET (QGIS_APP_SRCS ${QGIS_APP_SRCS}
postgres/qgspgsourceselect.cpp
postgres/qgspgnewconnection.cpp
)
SET (QGIS_APP_MOC_HDRS ${QGIS_APP_MOC_HDRS}
postgres/qgspgsourceselect.h
postgres/qgspgnewconnection.h
)
ENDIF (POSTGRES_FOUND)

IF (HAVE_SPATIALITE)
@@ -228,7 +228,7 @@
// Conditional Includes
//
#ifdef HAVE_POSTGRESQL
#include "postgres/qgspgsourceselect.h"
#include "../providers/postgres/qgspgsourceselect.h"
#ifdef HAVE_PGCONFIG
#include <pg_config.h>
#else
@@ -2363,58 +2363,75 @@ void QgisApp::addDatabaseLayer()
{
return;
}
// Fudge for now
QgsDebugMsg( "about to addRasterLayer" );

// only supports postgis layers at present
// show the postgis dialog

QgsPgSourceSelect *dbs = new QgsPgSourceSelect( this );
// TODO: QDialog for now, switch to QWidget in future
QDialog *pgs = dynamic_cast<QDialog*>( QgsProviderRegistry::instance()->selectWidget( QString( "postgres" ), this ) );
if ( !pgs )
{
QMessageBox::warning( this, tr( "PostgreSQL" ), tr( "Cannot get PostgreSQL select dialog from provider." ) );
return;
}
connect( pgs , SIGNAL( addDatabaseLayers( QStringList const &, QString const & ) ),
this , SLOT( addDatabaseLayers( QStringList const &, QString const & ) ) );
pgs->exec();
delete pgs;
} // QgisApp::addDatabaseLayer()
#endif

mMapCanvas->freeze();
void QgisApp::addDatabaseLayers( QStringList const & layerPathList, QString const & providerKey )
{
if ( mMapCanvas && mMapCanvas->isDrawing() )
{
return;
}

if ( dbs->exec() )
if ( layerPathList.empty() )
{
// Let render() do its own cursor management
// QApplication::setOverrideCursor(Qt::WaitCursor);
// no layers to add so bail out, but
// allow mMapCanvas to handle events
// first
mMapCanvas->freeze( false );
return;
}

mMapCanvas->freeze( true );

// repaint the canvas if it was covered by the dialog
QApplication::setOverrideCursor(Qt::WaitCursor);

// add files to the map canvas
QStringList tables = dbs->selectedTables();
foreach( QString layerPath, layerPathList )
{
// create the layer
QgsDataSourceURI uri( layerPath );

QApplication::setOverrideCursor( Qt::WaitCursor );
QgsVectorLayer *layer = new QgsVectorLayer( uri.uri(), uri.table(), providerKey );
Q_CHECK_PTR( layer );

// for each selected table, connect to the database, parse the Wkt geometry,
// and build a canvasitem for it
// readWKB(connectionInfo,tables);
QStringList::Iterator it = tables.begin();
while ( it != tables.end() )
if ( ! layer )
{
// create the layer
//qWarning("creating layer");
QgsDataSourceURI uri( *it );
QgsVectorLayer *layer = new QgsVectorLayer( uri.uri(), uri.table(), "postgres" );
if ( layer->isValid() )
{
// register this layer with the central layers registry
QgsMapLayerRegistry::instance()->addMapLayer( layer );
}
else
{
QgsDebugMsg(( *it ) + " is an invalid layer - not loaded" );
QMessageBox::critical( this, tr( "Invalid Layer" ), tr( "%1 is an invalid layer and cannot be loaded." ).arg( *it ) );
delete layer;
}
//qWarning("incrementing iterator");
++it;
}
mMapCanvas->freeze( false );
QApplication::restoreOverrideCursor();

QApplication::restoreOverrideCursor();
// XXX insert meaningful whine to the user here
return;
}

statusBar()->showMessage( mMapCanvas->extent().toString( 2 ) );
if ( layer->isValid() )
{
// register this layer with the central layers registry
QgsMapLayerRegistry::instance()->addMapLayer( layer );
}
else
{
QgsDebugMsg(( layerPath ) + " is an invalid layer - not loaded" );
QMessageBox::critical( this, tr( "Invalid Layer" ), tr( "%1 is an invalid layer and cannot be loaded." ).arg( layerPath ) );
delete layer;
}
//qWarning("incrementing iterator");
}

delete dbs;
statusBar()->showMessage( mMapCanvas->extent().toString( 2 ) );

// update UI
qApp->processEvents();
@@ -2423,11 +2440,8 @@ void QgisApp::addDatabaseLayer()
mMapCanvas->freeze( false );
mMapCanvas->refresh();

// Let render() do its own cursor management
// QApplication::restoreOverrideCursor();

} // QgisApp::addDatabaseLayer()
#endif
QApplication::restoreOverrideCursor();
}


#ifndef HAVE_SPATIALITE
@@ -466,6 +466,8 @@ class QgisApp : public QMainWindow, private Ui::MainWindow
//! Add a databaselayer to the map
void addDatabaseLayer();
//#endif
//! Add a list of database layers to the map
void addDatabaseLayers( QStringList const & layerPathList, QString const & providerKey );
//#ifdef HAVE_SPATIALITE
//! Add a SpatiaLite layer to the map
void addSpatiaLiteLayer();
@@ -51,6 +51,8 @@ SET(QGIS_CORE_SRCS
qgscrscache.cpp
qgsdatasourceuri.cpp
qgsdataitem.cpp
qgsdbfilterproxymodel.cpp
qgsdbtablemodel.cpp
qgsdiagram.cpp
qgsdiagramrendererv2.cpp
qgsdistancearea.cpp
@@ -228,6 +230,7 @@ SET(QGIS_CORE_MOC_HDRS
qgscontexthelp.h
qgscoordinatetransform.h
qgsdataitem.h
qgsdbtablemodel.h
qgsdataprovider.h
qgshttptransaction.h
qgsmaplayer.h
File renamed without changes.
File renamed without changes.
@@ -16,8 +16,7 @@
***************************************************************************/

#include "qgsdbtablemodel.h"
#include "qgsapplication.h"
#include "qgisapp.h"
#include "qgsdataitem.h"

QgsDbTableModel::QgsDbTableModel(): QStandardItemModel(), mTableCount( 0 )
{
@@ -224,15 +223,15 @@ QIcon QgsDbTableModel::iconForType( QGis::WkbType type ) const
{
if ( type == QGis::WKBPoint || type == QGis::WKBPoint25D || type == QGis::WKBMultiPoint || type == QGis::WKBMultiPoint25D )
{
return QgisApp::getThemeIcon( "/mIconPointLayer.png" );
return QIcon( QgsDataItem::getThemePixmap( "/mIconPointLayer.png" ) );
}
else if ( type == QGis::WKBLineString || type == QGis::WKBLineString25D || type == QGis::WKBMultiLineString || type == QGis::WKBMultiLineString25D )
{
return QgisApp::getThemeIcon( "/mIconLineLayer.png" );
return QIcon( QgsDataItem::getThemePixmap( "/mIconLineLayer.png" ) );
}
else if ( type == QGis::WKBPolygon || type == QGis::WKBPolygon25D || type == QGis::WKBMultiPolygon || type == QGis::WKBMultiPolygon25D )
{
return QgisApp::getThemeIcon( "/mIconPolygonLayer.png" );
return QIcon( QgsDataItem::getThemePixmap( "/mIconPolygonLayer.png" ) );
}
else return QIcon();
}
File renamed without changes.
@@ -4,7 +4,7 @@

SET (SPIT_SRCS
qgsspit.cpp
../../app/postgres/qgspgnewconnection.cpp
../../providers/postgres/qgspgnewconnection.cpp
qgspgutil.cpp
qgsshapefile.cpp
)
@@ -29,7 +29,7 @@ SET (SPIT_UIS
SET (SPIT_EXE_MOC_HDRS
qgsspit.h
qgsshapefile.h
../../app/postgres/qgspgnewconnection.h
../../providers/postgres/qgspgnewconnection.h
)

SET (SPIT_PLUGIN_MOC_HDRS
@@ -57,7 +57,7 @@ INCLUDE_DIRECTORIES(
../../gui
../../ui
../../app
../../app/postgres
../../providers/postgres
..
${POSTGRES_INCLUDE_DIR}
${GDAL_INCLUDE_DIR}
@@ -2,19 +2,33 @@
########################################################
# Files

SET(PG_SRCS qgspostgresprovider.cpp)
SET(PG_MOC_HDRS qgspostgresprovider.h)
SET(PG_SRCS
qgspostgresprovider.cpp
qgspostgresconnection.cpp
qgspgsourceselect.cpp
qgspgnewconnection.cpp
)
SET(PG_MOC_HDRS
qgspostgresprovider.h
qgspostgresconnection.h
qgspgsourceselect.h
qgspgnewconnection.h
)


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

QT4_WRAP_CPP(PG_MOC_SRCS ${PG_MOC_HDRS})

INCLUDE_DIRECTORIES (
INCLUDE_DIRECTORIES(
../../core
${POSTGRES_INCLUDE_DIR}
${GEOS_INCLUDE_DIR}
../../core
../../gui
../../app
${CMAKE_CURRENT_BINARY_DIR}/../../ui
)

ADD_LIBRARY (postgresprovider MODULE ${PG_SRCS} ${PG_MOC_SRCS})
File renamed without changes.
File renamed without changes.

0 comments on commit 49e4e99

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