|
175 | 175 | #ifdef HAVE_POSTGRESQL |
176 | 176 | #include "qgsdbsourceselect.h" |
177 | 177 | #endif |
| 178 | +#ifdef HAVE_SPATIALITE |
| 179 | +#include "qgsspatialitesourceselect.h" |
| 180 | +#endif |
178 | 181 |
|
179 | 182 | #include "qgspythondialog.h" |
180 | 183 | #include "qgspythonutils.h" |
@@ -776,6 +779,18 @@ void QgisApp::createActions() |
776 | 779 | //#endif |
777 | 780 | connect( mActionAddPgLayer, SIGNAL( triggered() ), this, SLOT( addDatabaseLayer() ) ); |
778 | 781 |
|
| 782 | + mActionAddSpatiaLiteLayer = new QAction( getThemeIcon( "mActionAddSpatiaLiteLayer.png" ), tr( "Add SpatiaLite Layer..." ), this ); |
| 783 | + mActionAddSpatiaLiteLayer->setShortcut( tr( "L", "Add a SpatiaLite Layer" ) ); |
| 784 | + mActionAddSpatiaLiteLayer->setStatusTip( tr( "Add a SpatiaLite Layer" ) ); |
| 785 | + connect( mActionAddSpatiaLiteLayer, SIGNAL( triggered() ), this, SLOT( addSpatiaLiteLayer() ) ); |
| 786 | +//#ifdef HAVE_SPATIALITE |
| 787 | + // QgsDebugMsg("HAVE_SPATIALITE is defined"); |
| 788 | +// assert(0); |
| 789 | +//#else |
| 790 | + // QgsDebugMsg("HAVE_SPATIALITE not defined"); |
| 791 | +// assert(0); |
| 792 | +//#endif |
| 793 | + |
779 | 794 | mActionAddWmsLayer = new QAction( getThemeIcon( "mActionAddWmsLayer.png" ), tr( "Add WMS Layer..." ), this ); |
780 | 795 | mActionAddWmsLayer->setShortcut( tr( "W", "Add a Web Mapping Server Layer" ) ); |
781 | 796 | mActionAddWmsLayer->setStatusTip( tr( "Add a Web Mapping Server Layer" ) ); |
@@ -1109,6 +1124,9 @@ void QgisApp::createMenus() |
1109 | 1124 | mLayerMenu->addAction( mActionAddRasterLayer ); |
1110 | 1125 | #ifdef HAVE_POSTGRESQL |
1111 | 1126 | mLayerMenu->addAction( mActionAddPgLayer ); |
| 1127 | +#endif |
| 1128 | +#ifdef HAVE_SPATIALITE |
| 1129 | + mLayerMenu->addAction( mActionAddSpatiaLiteLayer ); |
1112 | 1130 | #endif |
1113 | 1131 | mLayerMenu->addAction( mActionAddWmsLayer ); |
1114 | 1132 | mActionLayerSeparator1 = mLayerMenu->addSeparator(); |
@@ -1207,6 +1225,9 @@ void QgisApp::createToolBars() |
1207 | 1225 | mFileToolBar->addAction( mActionAddRasterLayer ); |
1208 | 1226 | #ifdef HAVE_POSTGRESQL |
1209 | 1227 | mFileToolBar->addAction( mActionAddPgLayer ); |
| 1228 | +#endif |
| 1229 | +#ifdef HAVE_SPATIALITE |
| 1230 | + mFileToolBar->addAction( mActionAddSpatiaLiteLayer ); |
1210 | 1231 | #endif |
1211 | 1232 | mFileToolBar->addAction( mActionAddWmsLayer ); |
1212 | 1233 | mToolbarMenu->addAction( mFileToolBar->toggleViewAction() ); |
@@ -1432,6 +1453,7 @@ void QgisApp::setTheme( QString theThemeName ) |
1432 | 1453 | mActionAddOgrLayer->setIcon( getThemeIcon( "/mActionAddOgrLayer.png" ) ); |
1433 | 1454 | mActionAddRasterLayer->setIcon( getThemeIcon( "/mActionAddRasterLayer.png" ) ); |
1434 | 1455 | mActionAddPgLayer->setIcon( getThemeIcon( "/mActionAddLayer.png" ) ); |
| 1456 | + mActionAddSpatiaLiteLayer->setIcon( getThemeIcon( "/mActionAddSpatiaLiteLayer.png" ) ); |
1435 | 1457 | mActionRemoveLayer->setIcon( getThemeIcon( "/mActionRemoveLayer.png" ) ); |
1436 | 1458 | mActionNewVectorLayer->setIcon( getThemeIcon( "/mActionNewVectorLayer.png" ) ); |
1437 | 1459 | mActionAddAllToOverview->setIcon( getThemeIcon( "/mActionAddAllToOverview.png" ) ); |
@@ -1794,6 +1816,13 @@ void QgisApp::about() |
1794 | 1816 | #else |
1795 | 1817 |
|
1796 | 1818 | versionString += tr( " This copy of QGIS has been built without PostgreSQL support." ); |
| 1819 | +#endif |
| 1820 | +#ifdef HAVE_SPATIALITE |
| 1821 | + |
| 1822 | + versionString += tr( "\nThis copy of QGIS has been built with SpatiaLite support." ); |
| 1823 | +#else |
| 1824 | + |
| 1825 | + versionString += tr( "\nThis copy of QGIS has been built without SpatiaLite support." ); |
1797 | 1826 | #endif |
1798 | 1827 | versionString += tr( "\nThis binary was compiled against Qt %1," |
1799 | 1828 | "and is currently running against Qt %2" ) |
@@ -2384,6 +2413,87 @@ void QgisApp::addDatabaseLayer() |
2384 | 2413 | #endif |
2385 | 2414 |
|
2386 | 2415 |
|
| 2416 | +#ifndef HAVE_SPATIALITE |
| 2417 | +void QgisApp::addSpatiaLiteLayer() {} |
| 2418 | +#else |
| 2419 | +void QgisApp::addSpatiaLiteLayer() |
| 2420 | +{ |
| 2421 | + if(mMapCanvas && mMapCanvas->isDrawing()) |
| 2422 | + { |
| 2423 | + return; |
| 2424 | + } |
| 2425 | + |
| 2426 | + // show the SpatiaLite dialog |
| 2427 | + |
| 2428 | + QgsSpatiaLiteSourceSelect *dbs = new QgsSpatiaLiteSourceSelect( this ); |
| 2429 | + |
| 2430 | + mMapCanvas->freeze(); |
| 2431 | + |
| 2432 | + if (dbs->exec()) |
| 2433 | + { |
| 2434 | +// Let render() do its own cursor management |
| 2435 | +// QApplication::setOverrideCursor(Qt::WaitCursor); |
| 2436 | + |
| 2437 | + |
| 2438 | + // repaint the canvas if it was covered by the dialog |
| 2439 | + |
| 2440 | + // add files to the map canvas |
| 2441 | + QStringList tables = dbs->selectedTables(); |
| 2442 | + |
| 2443 | + QApplication::setOverrideCursor(Qt::WaitCursor); |
| 2444 | + |
| 2445 | + QString connectionInfo = dbs->connectionInfo(); |
| 2446 | + // for each selected table, connect to the database and build a canvasitem for it |
| 2447 | + QStringList::Iterator it = tables.begin(); |
| 2448 | + while (it != tables.end()) |
| 2449 | + { |
| 2450 | + |
| 2451 | + // normalizing the layer name |
| 2452 | + QString layername = *it; |
| 2453 | + layername = layername.mid(1); |
| 2454 | + int idx = layername.indexOf( "\" (" ); |
| 2455 | + if (idx > 0) |
| 2456 | + layername.truncate(idx); |
| 2457 | + |
| 2458 | + // create the layer |
| 2459 | + //qWarning("creating layer"); |
| 2460 | + QgsVectorLayer *layer = new QgsVectorLayer( "dbname='" + connectionInfo + "' table=" + *it + ")", layername, "spatialite" ); |
| 2461 | + if ( layer->isValid() ) |
| 2462 | + { |
| 2463 | + // register this layer with the central layers registry |
| 2464 | + QgsMapLayerRegistry::instance()->addMapLayer( layer ); |
| 2465 | + // notify the project we've made a change |
| 2466 | + QgsProject::instance()->dirty( true ); |
| 2467 | + } |
| 2468 | + else |
| 2469 | + { |
| 2470 | + QgsDebugMsg( (*it) + " is an invalid layer - not loaded" ); |
| 2471 | + QMessageBox::critical( this, tr( "Invalid Layer" ), tr( "%1 is an invalid layer and cannot be loaded." ).arg( *it ) ); |
| 2472 | + delete layer; |
| 2473 | + } |
| 2474 | + //qWarning("incrementing iterator"); |
| 2475 | + ++it; |
| 2476 | + } |
| 2477 | + |
| 2478 | + QApplication::restoreOverrideCursor(); |
| 2479 | + |
| 2480 | + statusBar()->showMessage( mMapCanvas->extent().toString( 2 ) ); |
| 2481 | + } |
| 2482 | + delete dbs; |
| 2483 | + |
| 2484 | + // update UI |
| 2485 | + qApp->processEvents(); |
| 2486 | + |
| 2487 | + // draw the map |
| 2488 | + mMapCanvas->freeze( false ); |
| 2489 | + mMapCanvas->refresh(); |
| 2490 | + |
| 2491 | +// Let render() do its own cursor management |
| 2492 | +// QApplication::restoreOverrideCursor(); |
| 2493 | + |
| 2494 | +} // QgisApp::addSpatiaLiteLayer() |
| 2495 | +#endif |
| 2496 | + |
2387 | 2497 | void QgisApp::addWmsLayer() |
2388 | 2498 | { |
2389 | 2499 | if ( mMapCanvas && mMapCanvas->isDrawing() ) |
|
0 commit comments