Skip to content

Commit bd3f77a

Browse files
committedJul 12, 2011
add QgsDataItem to the postgres provider
1 parent 7647d82 commit bd3f77a

16 files changed

+290
-72
lines changed
 

‎src/app/CMakeLists.txt

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,6 @@ SET (QGIS_APP_MOC_HDRS
152152
qgscontinuouscolordialog.h
153153
qgscustomization.h
154154
qgscustomprojectiondialog.h
155-
qgsdbtablemodel.h
156155
qgsdelattrdialog.h
157156
qgsdisplayangle.h
158157
qgsembedlayerdialog.h
@@ -277,15 +276,6 @@ IF (POSTGRES_FOUND)
277276
IF(HAVE_PGCONFIG)
278277
ADD_DEFINITIONS(-DHAVE_PGCONFIG=1)
279278
ENDIF(HAVE_PGCONFIG)
280-
281-
SET (QGIS_APP_SRCS ${QGIS_APP_SRCS}
282-
postgres/qgspgsourceselect.cpp
283-
postgres/qgspgnewconnection.cpp
284-
)
285-
SET (QGIS_APP_MOC_HDRS ${QGIS_APP_MOC_HDRS}
286-
postgres/qgspgsourceselect.h
287-
postgres/qgspgnewconnection.h
288-
)
289279
ENDIF (POSTGRES_FOUND)
290280

291281
IF (HAVE_SPATIALITE)

‎src/app/qgisapp.cpp

Lines changed: 58 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -225,7 +225,7 @@
225225
// Conditional Includes
226226
//
227227
#ifdef HAVE_POSTGRESQL
228-
#include "postgres/qgspgsourceselect.h"
228+
#include "../providers/postgres/qgspgsourceselect.h"
229229
#ifdef HAVE_PGCONFIG
230230
#include <pg_config.h>
231231
#else
@@ -2322,58 +2322,75 @@ void QgisApp::addDatabaseLayer()
23222322
{
23232323
return;
23242324
}
2325+
// Fudge for now
2326+
QgsDebugMsg( "about to addRasterLayer" );
23252327

2326-
// only supports postgis layers at present
2327-
// show the postgis dialog
2328-
2329-
QgsPgSourceSelect *dbs = new QgsPgSourceSelect( this );
2328+
// TODO: QDialog for now, switch to QWidget in future
2329+
QDialog *pgs = dynamic_cast<QDialog*>( QgsProviderRegistry::instance()->selectWidget( QString( "postgres" ), this ) );
2330+
if ( !pgs )
2331+
{
2332+
QMessageBox::warning( this, tr( "PostgreSQL" ), tr( "Cannot get PostgreSQL select dialog from provider." ) );
2333+
return;
2334+
}
2335+
connect( pgs , SIGNAL( addDatabaseLayers( QStringList const &, QString const & ) ),
2336+
this , SLOT( addDatabaseLayers( QStringList const &, QString const & ) ) );
2337+
pgs->exec();
2338+
delete pgs;
2339+
} // QgisApp::addDatabaseLayer()
2340+
#endif
23302341

2331-
mMapCanvas->freeze();
2342+
void QgisApp::addDatabaseLayers( QStringList const & layerPathList, QString const & providerKey )
2343+
{
2344+
if ( mMapCanvas && mMapCanvas->isDrawing() )
2345+
{
2346+
return;
2347+
}
23322348

2333-
if ( dbs->exec() )
2349+
if ( layerPathList.empty() )
23342350
{
2335-
// Let render() do its own cursor management
2336-
// QApplication::setOverrideCursor(Qt::WaitCursor);
2351+
// no layers to add so bail out, but
2352+
// allow mMapCanvas to handle events
2353+
// first
2354+
mMapCanvas->freeze( false );
2355+
return;
2356+
}
23372357

2358+
mMapCanvas->freeze( true );
23382359

2339-
// repaint the canvas if it was covered by the dialog
2360+
QApplication::setOverrideCursor(Qt::WaitCursor);
23402361

2341-
// add files to the map canvas
2342-
QStringList tables = dbs->selectedTables();
2362+
foreach( QString layerPath, layerPathList )
2363+
{
2364+
// create the layer
2365+
QgsDataSourceURI uri( layerPath );
23432366

2344-
QApplication::setOverrideCursor( Qt::WaitCursor );
2367+
QgsVectorLayer *layer = new QgsVectorLayer( uri.uri(), uri.table(), providerKey );
2368+
Q_CHECK_PTR( layer );
23452369

2346-
// for each selected table, connect to the database, parse the Wkt geometry,
2347-
// and build a canvasitem for it
2348-
// readWKB(connectionInfo,tables);
2349-
QStringList::Iterator it = tables.begin();
2350-
while ( it != tables.end() )
2370+
if ( ! layer )
23512371
{
2352-
// create the layer
2353-
//qWarning("creating layer");
2354-
QgsDataSourceURI uri( *it );
2355-
QgsVectorLayer *layer = new QgsVectorLayer( uri.uri(), uri.table(), "postgres" );
2356-
if ( layer->isValid() )
2357-
{
2358-
// register this layer with the central layers registry
2359-
QgsMapLayerRegistry::instance()->addMapLayer( layer );
2360-
}
2361-
else
2362-
{
2363-
QgsDebugMsg(( *it ) + " is an invalid layer - not loaded" );
2364-
QMessageBox::critical( this, tr( "Invalid Layer" ), tr( "%1 is an invalid layer and cannot be loaded." ).arg( *it ) );
2365-
delete layer;
2366-
}
2367-
//qWarning("incrementing iterator");
2368-
++it;
2369-
}
2372+
mMapCanvas->freeze( false );
2373+
QApplication::restoreOverrideCursor();
23702374

2371-
QApplication::restoreOverrideCursor();
2375+
// XXX insert meaningful whine to the user here
2376+
return;
2377+
}
23722378

2373-
statusBar()->showMessage( mMapCanvas->extent().toString( 2 ) );
2379+
if ( layer->isValid() )
2380+
{
2381+
// register this layer with the central layers registry
2382+
QgsMapLayerRegistry::instance()->addMapLayer( layer );
2383+
}
2384+
else
2385+
{
2386+
QgsDebugMsg(( layerPath ) + " is an invalid layer - not loaded" );
2387+
QMessageBox::critical( this, tr( "Invalid Layer" ), tr( "%1 is an invalid layer and cannot be loaded." ).arg( layerPath ) );
2388+
delete layer;
2389+
}
2390+
//qWarning("incrementing iterator");
23742391
}
23752392

2376-
delete dbs;
2393+
statusBar()->showMessage( mMapCanvas->extent().toString( 2 ) );
23772394

23782395
// update UI
23792396
qApp->processEvents();
@@ -2382,11 +2399,8 @@ void QgisApp::addDatabaseLayer()
23822399
mMapCanvas->freeze( false );
23832400
mMapCanvas->refresh();
23842401

2385-
// Let render() do its own cursor management
2386-
// QApplication::restoreOverrideCursor();
2387-
2388-
} // QgisApp::addDatabaseLayer()
2389-
#endif
2402+
QApplication::restoreOverrideCursor();
2403+
}
23902404

23912405

23922406
#ifndef HAVE_SPATIALITE

‎src/app/qgisapp.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -460,6 +460,8 @@ class QgisApp : public QMainWindow, private Ui::MainWindow
460460
//! Add a databaselayer to the map
461461
void addDatabaseLayer();
462462
//#endif
463+
//! Add a list of database layers to the map
464+
void addDatabaseLayers( QStringList const & layerPathList, QString const & providerKey );
463465
//#ifdef HAVE_SPATIALITE
464466
//! Add a SpatiaLite layer to the map
465467
void addSpatiaLiteLayer();

‎src/core/CMakeLists.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,8 @@ SET(QGIS_CORE_SRCS
4949
qgscoordinatetransform.cpp
5050
qgsdatasourceuri.cpp
5151
qgsdataitem.cpp
52+
qgsdbfilterproxymodel.cpp
53+
qgsdbtablemodel.cpp
5254
qgsdiagram.cpp
5355
qgsdiagramrendererv2.cpp
5456
qgsdistancearea.cpp
@@ -225,6 +227,7 @@ SET(QGIS_CORE_MOC_HDRS
225227
qgscontexthelp.h
226228
qgscoordinatetransform.h
227229
qgsdataitem.h
230+
qgsdbtablemodel.h
228231
qgsdataprovider.h
229232
qgshttptransaction.h
230233
qgsmaplayer.h
File renamed without changes.

‎src/app/qgsdbtablemodel.cpp renamed to ‎src/core/qgsdbtablemodel.cpp

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,7 @@
1616
***************************************************************************/
1717

1818
#include "qgsdbtablemodel.h"
19-
#include "qgsapplication.h"
20-
#include "qgisapp.h"
19+
#include "qgsdataitem.h"
2120

2221
QgsDbTableModel::QgsDbTableModel(): QStandardItemModel(), mTableCount( 0 )
2322
{
@@ -224,15 +223,15 @@ QIcon QgsDbTableModel::iconForType( QGis::WkbType type ) const
224223
{
225224
if ( type == QGis::WKBPoint || type == QGis::WKBPoint25D || type == QGis::WKBMultiPoint || type == QGis::WKBMultiPoint25D )
226225
{
227-
return QgisApp::getThemeIcon( "/mIconPointLayer.png" );
226+
return QIcon( QgsDataItem::getThemePixmap( "/mIconPointLayer.png" ) );
228227
}
229228
else if ( type == QGis::WKBLineString || type == QGis::WKBLineString25D || type == QGis::WKBMultiLineString || type == QGis::WKBMultiLineString25D )
230229
{
231-
return QgisApp::getThemeIcon( "/mIconLineLayer.png" );
230+
return QIcon( QgsDataItem::getThemePixmap( "/mIconLineLayer.png" ) );
232231
}
233232
else if ( type == QGis::WKBPolygon || type == QGis::WKBPolygon25D || type == QGis::WKBMultiPolygon || type == QGis::WKBMultiPolygon25D )
234233
{
235-
return QgisApp::getThemeIcon( "/mIconPolygonLayer.png" );
234+
return QIcon( QgsDataItem::getThemePixmap( "/mIconPolygonLayer.png" ) );
236235
}
237236
else return QIcon();
238237
}
File renamed without changes.

‎src/plugins/spit/CMakeLists.txt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
SET (SPIT_SRCS
66
qgsspit.cpp
7-
../../app/postgres/qgspgnewconnection.cpp
7+
../../providers/postgres/qgspgnewconnection.cpp
88
qgspgutil.cpp
99
qgsshapefile.cpp
1010
)
@@ -29,7 +29,7 @@ SET (SPIT_UIS
2929
SET (SPIT_EXE_MOC_HDRS
3030
qgsspit.h
3131
qgsshapefile.h
32-
../../app/postgres/qgspgnewconnection.h
32+
../../providers/postgres/qgspgnewconnection.h
3333
)
3434

3535
SET (SPIT_PLUGIN_MOC_HDRS
@@ -57,7 +57,7 @@ INCLUDE_DIRECTORIES(
5757
../../gui
5858
../../ui
5959
../../app
60-
../../app/postgres
60+
../../providers/postgres
6161
..
6262
${POSTGRES_INCLUDE_DIR}
6363
${GDAL_INCLUDE_DIR}

‎src/providers/postgres/CMakeLists.txt

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,14 @@
55
SET(PG_SRCS
66
qgspostgresprovider.cpp
77
qgspostgresconnection.cpp
8-
../../app/postgres/qgspgsourceselect.cpp
8+
qgspgsourceselect.cpp
9+
qgspgnewconnection.cpp
910
)
1011
SET(PG_MOC_HDRS
1112
qgspostgresprovider.h
1213
qgspostgresconnection.h
13-
../../app/postgres/qgspgsourceselect.h
14+
qgspgsourceselect.h
15+
qgspgnewconnection.h
1416
)
1517

1618

@@ -26,7 +28,6 @@ INCLUDE_DIRECTORIES(
2628
../../core
2729
../../gui
2830
../../app
29-
../../app/postgres
3031
${CMAKE_CURRENT_BINARY_DIR}/../../ui
3132
)
3233

‎src/app/postgres/qgspgsourceselect.h renamed to ‎src/providers/postgres/qgspgsourceselect.h

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,11 @@ class QgsPgSourceSelect : public QDialog, private Ui::QgsDbSourceSelectBase
116116
//! Connection info (database, host, user, password)
117117
QString connectionInfo();
118118

119+
signals:
120+
void addDatabaseLayers( QStringList const & layerPathList,
121+
QString const & providerKey );
122+
void connectionsChanged();
123+
119124
public slots:
120125
//! Determines the tables the user selected and closes the dialog
121126
void addTables();
@@ -155,12 +160,6 @@ class QgsPgSourceSelect : public QDialog, private Ui::QgsDbSourceSelectBase
155160
typedef QPair<QString, QString> geomPair;
156161
typedef QList<geomPair> geomCol;
157162

158-
/**Inserts information about the spatial tables into mTableModel*/
159-
bool getTableInfo( PGconn *pg, bool searchGeometryColumnsOnly, bool searchPublicOnly, bool allowGeometrylessTables );
160-
161-
/** get primary key candidates (all int4 columns) */
162-
QStringList pkCandidates( PGconn *pg, QString schemaName, QString viewName );
163-
164163
// queue another query for the thread
165164
void addSearchGeometryColumn( const QString &schema, const QString &table, const QString &column );
166165

@@ -180,7 +179,6 @@ class QgsPgSourceSelect : public QDialog, private Ui::QgsDbSourceSelectBase
180179
bool mUseEstimatedMetadata;
181180
// Storage for the range of layer type icons
182181
QMap<QString, QPair<QString, QIcon> > mLayerIcons;
183-
PGconn *pd;
184182

185183
//! Model that acts as datasource for mTableTreeWidget
186184
QgsDbTableModel mTableModel;

0 commit comments

Comments
 (0)