Skip to content

Commit 75811a3

Browse files
author
esseffe
committedMar 24, 2009
supporting the SpatiaLite Data Provider
2009-04-24 Sandro Furieri <a.furieri@lqt.it> git-svn-id: http://svn.osgeo.org/qgis/trunk/qgis@10414 c8812cc2-4d05-0410-92ff-de0c093fc19c

18 files changed

+3523
-0
lines changed
 

‎CMakeLists.txt

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,12 @@ IF (WITH_POSTGRESQL)
5050
SET (POSTGRESQL_PREFIX "" CACHE PATH "Path to POSTGRESQL base directory")
5151
ENDIF (WITH_POSTGRESQL)
5252

53+
# try to configure and build SPATIALITE support
54+
SET (WITH_SPATIALITE TRUE CACHE BOOL "Determines whether SPATIALITE support should be built")
55+
IF (WITH_SPATIALITE)
56+
SET (SPATIALITE_PREFIX "" CACHE PATH "Path to SPATIALITE base directory")
57+
ENDIF (WITH_SPATIALITE)
58+
5359
# try to configure and build python bindings by default
5460
SET (WITH_BINDINGS TRUE CACHE BOOL "Determines whether python bindings should be built")
5561
IF (WITH_BINDINGS)
@@ -118,6 +124,9 @@ FIND_PACKAGE(GSL) # Georeferencer
118124
IF (WITH_GRASS)
119125
FIND_PACKAGE(GRASS) # GRASS plugin
120126
ENDIF (WITH_GRASS)
127+
IF (WITH_SPATIALITE)
128+
FIND_PACKAGE(SPATIALITE) # SPATIALITE provider
129+
ENDIF (WITH_SPATIALITE)
121130

122131
IF (WITH_BINDINGS)
123132
# python support:
@@ -136,6 +145,10 @@ IF (POSTGRES_FOUND)
136145
SET (HAVE_POSTGRESQL TRUE)
137146
ENDIF (POSTGRES_FOUND)
138147

148+
IF (SPATIALITE_FOUND)
149+
# following variable is used in qgsconfig.h
150+
SET (HAVE_SPATIALITE TRUE)
151+
ENDIF (SPATIALITE_FOUND)
139152

140153
#############################################################
141154
# search for Qt4

‎cmake/FindSPATIALITE.cmake

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
2+
# CMake module to search for SpatiaLite library
3+
#
4+
# If it's found it sets SPATIALITE_FOUND to TRUE
5+
# and following variables are set:
6+
# SPATIALITE_INCLUDE_DIR
7+
# SPATIALITE_LIBRARY
8+
9+
10+
# FIND_PATH and FIND_LIBRARY normally search standard locations
11+
# before the specified paths. To search non-standard paths first,
12+
# FIND_* is invoked first with specified paths and NO_DEFAULT_PATH
13+
# and then again with no specified paths to search the default
14+
# locations. When an earlier FIND_* succeeds, subsequent FIND_*s
15+
# searching for the same item do nothing.
16+
FIND_PATH(SPATIALITE_INCLUDE_DIR spatialite.h
17+
"$ENV{LIB_DIR}/include"
18+
"$ENV{LIB_DIR}/include/spatialite"
19+
#mingw
20+
c:/msys/local/include
21+
NO_DEFAULT_PATH
22+
)
23+
FIND_PATH(SPATIALITE_INCLUDE_DIR spatialite.h)
24+
25+
FIND_LIBRARY(SPATIALITE_LIBRARY NAMES spatialite PATHS
26+
"$ENV{LIB_DIR}/lib"
27+
#mingw
28+
c:/msys/local/lib
29+
NO_DEFAULT_PATH
30+
)
31+
FIND_LIBRARY(SPATIALITE_LIBRARY NAMES spatialite)
32+
33+
IF (SPATIALITE_INCLUDE_DIR AND SPATIALITE_LIBRARY)
34+
SET(SPATIALITE_FOUND TRUE)
35+
ENDIF (SPATIALITE_INCLUDE_DIR AND SPATIALITE_LIBRARY)
36+
37+
38+
IF (SPATIALITE_FOUND)
39+
40+
IF (NOT SPATIALITE_FIND_QUIETLY)
41+
MESSAGE(STATUS "Found SpatiaLite: ${SPATIALITE_LIBRARY}")
42+
ENDIF (NOT SPATIALITE_FIND_QUIETLY)
43+
44+
ELSE (SPATIALITE_FOUND)
45+
46+
IF (SPATIALITE_FIND_REQUIRED)
47+
MESSAGE(FATAL_ERROR "Could not find SpatiaLite")
48+
ENDIF (SPATIALITE_FIND_REQUIRED)
49+
50+
ENDIF (SPATIALITE_FOUND)

‎cmake_templates/qgsconfig.h.in

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@
2525

2626
#cmakedefine HAVE_POSTGRESQL
2727

28+
#cmakedefine HAVE_SPATIALITE
29+
2830
#cmakedefine HAVE_PYTHON
2931

3032
#endif
Loading

‎src/app/CMakeLists.txt

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@ SET(QGIS_APP_SRCS
1515
qgscustomprojectiondialog.cpp
1616
qgsdbfilterproxymodel.cpp
1717
qgsdbtablemodel.cpp
18+
qgsspatialitefilterproxymodel.cpp
19+
qgsspatialitetablemodel.cpp
1820
qgsdelattrdialog.cpp
1921
qgsgeomtypedialog.cpp
2022
qgsgraduatedsymboldialog.cpp
@@ -135,6 +137,7 @@ SET (QGIS_APP_MOC_HDRS
135137
qgsuniquevaluedialog.h
136138
qgsvectorlayerproperties.h
137139
qgsdbtablemodel.h
140+
qgsspatialitetablemodel.h
138141

139142
composer/qgscomposer.h
140143
composer/qgscomposeritemwidget.h
@@ -175,6 +178,15 @@ IF (POSTGRES_FOUND)
175178
)
176179
ENDIF (POSTGRES_FOUND)
177180

181+
IF (SPATIALITE_FOUND)
182+
SET (QGIS_APP_SRCS ${QGIS_APP_SRCS}
183+
qgsspatialitesourceselect.cpp
184+
)
185+
SET (QGIS_APP_MOC_HDRS ${QGIS_APP_MOC_HDRS}
186+
qgsspatialitesourceselect.h
187+
)
188+
ENDIF (SPATIALITE_FOUND)
189+
178190

179191
QT4_WRAP_CPP(QGIS_APP_MOC_SRCS ${QGIS_APP_MOC_HDRS})
180192

@@ -227,6 +239,10 @@ IF (POSTGRES_FOUND)
227239
INCLUDE_DIRECTORIES(${POSTGRES_INCLUDE_DIR})
228240
ENDIF (POSTGRES_FOUND)
229241

242+
IF (SPATIALITE_FOUND)
243+
INCLUDE_DIRECTORIES(${SPATIALITE_INCLUDE_DIR})
244+
ENDIF (SPATIALITE_FOUND)
245+
230246
#############
231247

232248
IF (WIN32)
@@ -269,6 +285,10 @@ IF (POSTGRES_FOUND)
269285
TARGET_LINK_LIBRARIES (qgis ${POSTGRES_LIBRARY})
270286
ENDIF (POSTGRES_FOUND)
271287

288+
IF (SPATIALITE_FOUND)
289+
TARGET_LINK_LIBRARIES (qgis ${SPATIALITE_LIBRARY})
290+
ENDIF (SPATIALITE_FOUND)
291+
272292
IF (APPLE)
273293
# For Mac OS X, the executable must be at the root of the bundle's executable folder
274294
INSTALL(TARGETS qgis RUNTIME DESTINATION ${CMAKE_INSTALL_PREFIX})

‎src/app/qgisapp.cpp

Lines changed: 110 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -175,6 +175,9 @@
175175
#ifdef HAVE_POSTGRESQL
176176
#include "qgsdbsourceselect.h"
177177
#endif
178+
#ifdef HAVE_SPATIALITE
179+
#include "qgsspatialitesourceselect.h"
180+
#endif
178181

179182
#include "qgspythondialog.h"
180183
#include "qgspythonutils.h"
@@ -776,6 +779,18 @@ void QgisApp::createActions()
776779
//#endif
777780
connect( mActionAddPgLayer, SIGNAL( triggered() ), this, SLOT( addDatabaseLayer() ) );
778781

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+
779794
mActionAddWmsLayer = new QAction( getThemeIcon( "mActionAddWmsLayer.png" ), tr( "Add WMS Layer..." ), this );
780795
mActionAddWmsLayer->setShortcut( tr( "W", "Add a Web Mapping Server Layer" ) );
781796
mActionAddWmsLayer->setStatusTip( tr( "Add a Web Mapping Server Layer" ) );
@@ -1109,6 +1124,9 @@ void QgisApp::createMenus()
11091124
mLayerMenu->addAction( mActionAddRasterLayer );
11101125
#ifdef HAVE_POSTGRESQL
11111126
mLayerMenu->addAction( mActionAddPgLayer );
1127+
#endif
1128+
#ifdef HAVE_SPATIALITE
1129+
mLayerMenu->addAction( mActionAddSpatiaLiteLayer );
11121130
#endif
11131131
mLayerMenu->addAction( mActionAddWmsLayer );
11141132
mActionLayerSeparator1 = mLayerMenu->addSeparator();
@@ -1207,6 +1225,9 @@ void QgisApp::createToolBars()
12071225
mFileToolBar->addAction( mActionAddRasterLayer );
12081226
#ifdef HAVE_POSTGRESQL
12091227
mFileToolBar->addAction( mActionAddPgLayer );
1228+
#endif
1229+
#ifdef HAVE_SPATIALITE
1230+
mFileToolBar->addAction( mActionAddSpatiaLiteLayer );
12101231
#endif
12111232
mFileToolBar->addAction( mActionAddWmsLayer );
12121233
mToolbarMenu->addAction( mFileToolBar->toggleViewAction() );
@@ -1432,6 +1453,7 @@ void QgisApp::setTheme( QString theThemeName )
14321453
mActionAddOgrLayer->setIcon( getThemeIcon( "/mActionAddOgrLayer.png" ) );
14331454
mActionAddRasterLayer->setIcon( getThemeIcon( "/mActionAddRasterLayer.png" ) );
14341455
mActionAddPgLayer->setIcon( getThemeIcon( "/mActionAddLayer.png" ) );
1456+
mActionAddSpatiaLiteLayer->setIcon( getThemeIcon( "/mActionAddSpatiaLiteLayer.png" ) );
14351457
mActionRemoveLayer->setIcon( getThemeIcon( "/mActionRemoveLayer.png" ) );
14361458
mActionNewVectorLayer->setIcon( getThemeIcon( "/mActionNewVectorLayer.png" ) );
14371459
mActionAddAllToOverview->setIcon( getThemeIcon( "/mActionAddAllToOverview.png" ) );
@@ -1794,6 +1816,13 @@ void QgisApp::about()
17941816
#else
17951817

17961818
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." );
17971826
#endif
17981827
versionString += tr( "\nThis binary was compiled against Qt %1,"
17991828
"and is currently running against Qt %2" )
@@ -2384,6 +2413,87 @@ void QgisApp::addDatabaseLayer()
23842413
#endif
23852414

23862415

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+
23872497
void QgisApp::addWmsLayer()
23882498
{
23892499
if ( mMapCanvas && mMapCanvas->isDrawing() )

‎src/app/qgisapp.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -246,6 +246,7 @@ class QgisApp : public QMainWindow
246246
QAction *actionAddOgrLayer() { return mActionAddOgrLayer; }
247247
QAction *actionAddRasterLayer() { return mActionAddRasterLayer; }
248248
QAction *actionAddPgLayer() { return mActionAddPgLayer; }
249+
QAction *actionAddSpatiaLiteLayer() { return mActionAddSpatiaLiteLayer; };
249250
QAction *actionAddWmsLayer() { return mActionAddWmsLayer; }
250251
QAction *actionLayerSeparator1() { return mActionLayerSeparator1; }
251252
QAction *actionOpenTable() { return mActionOpenTable; }
@@ -369,6 +370,10 @@ class QgisApp : public QMainWindow
369370
//#ifdef HAVE_POSTGRESQL
370371
//! Add a databaselayer to the map
371372
void addDatabaseLayer();
373+
//#endif
374+
//#ifdef HAVE_SPATIALITE
375+
//! Add a SpatiaLite layer to the map
376+
void addSpatiaLiteLayer();
372377
//#endif
373378
/** toggles whether the current selected layer is in overview or not */
374379
void isInOverview();
@@ -717,6 +722,7 @@ class QgisApp : public QMainWindow
717722
QAction *mActionAddOgrLayer;
718723
QAction *mActionAddRasterLayer;
719724
QAction *mActionAddPgLayer;
725+
QAction *mActionAddSpatiaLiteLayer;
720726
QAction *mActionAddWmsLayer;
721727
QAction *mActionLayerSeparator1;
722728
QAction *mActionOpenTable;
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
/***************************************************************************
2+
qgsspatialitefilterproxymodel.cpp - description
3+
-------------------------
4+
begin : Dec 2008
5+
copyright : (C) 2008 by Sandro Furieri
6+
email : a.furieri@lqt.it
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+
18+
#include "qgsspatialitefilterproxymodel.h"
19+
20+
QgsSpatiaLiteFilterProxyModel::QgsSpatiaLiteFilterProxyModel(QObject * parent):QSortFilterProxyModel(parent)
21+
{
22+
23+
}
24+
25+
QgsSpatiaLiteFilterProxyModel::~QgsSpatiaLiteFilterProxyModel()
26+
{
27+
28+
}
29+
30+
bool QgsSpatiaLiteFilterProxyModel::filterAcceptsRow(int row, const QModelIndex & source_parent) const
31+
{
32+
//if parent is valid, we have a toplevel item that should be always shown
33+
if (!source_parent.isValid())
34+
{
35+
return true;
36+
}
37+
//else we have a row that describes a table and that
38+
//should be tested using the given wildcard/regexp
39+
return QSortFilterProxyModel::filterAcceptsRow(row, source_parent);
40+
}
41+
42+
void QgsSpatiaLiteFilterProxyModel::_setFilterWildcard(const QString & pattern)
43+
{
44+
QSortFilterProxyModel::setFilterWildcard(pattern);
45+
emit layoutChanged();
46+
}
47+
48+
void QgsSpatiaLiteFilterProxyModel::_setFilterRegExp(const QString & pattern)
49+
{
50+
QSortFilterProxyModel::setFilterRegExp(pattern);
51+
emit layoutChanged();
52+
}
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
/***************************************************************************
2+
qgsspatialitefilterproxymodel.h - description
3+
-----------------------
4+
begin : Dec 2008
5+
copyright : (C) 2008 by Sandro Furieri
6+
email : a.furieri@lqt.it
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+
18+
#ifndef QGSSPATIALITEFILTERPROXYMODEL_H
19+
#define QGSSPATIALITEFILTERPROXYMODEL_H
20+
21+
#include <QSortFilterProxyModel>
22+
23+
/**A class that implements a custom filter and can be used
24+
as a proxy for QgsSpatiaLiteTableModel*/
25+
class QgsSpatiaLiteFilterProxyModel:public QSortFilterProxyModel
26+
{
27+
public:
28+
QgsSpatiaLiteFilterProxyModel(QObject * parent = 0);
29+
~QgsSpatiaLiteFilterProxyModel();
30+
/**Calls QSortFilterProxyModel::setFilterWildcard and triggers update*/
31+
void _setFilterWildcard(const QString & pattern);
32+
/**Calls QSortFilterProxyModel::setFilterRegExp and triggers update*/
33+
void _setFilterRegExp(const QString & pattern);
34+
35+
protected:
36+
virtual bool filterAcceptsRow(int row, const QModelIndex & source_parent) const;
37+
};
38+
39+
#endif

‎src/app/qgsspatialitesourceselect.cpp

Lines changed: 622 additions & 0 deletions
Large diffs are not rendered by default.

‎src/app/qgsspatialitesourceselect.h

Lines changed: 137 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,137 @@
1+
/***************************************************************************
2+
qgspatialitesourceselect.h - description
3+
-------------------
4+
begin : Dec 2008
5+
copyright : (C) 2008 by Sandro Furieri
6+
email : a.furieri@lqt.it
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+
#ifndef QGSSPATIALITESOURCESELECT_H
18+
#define QGSSPATIALITESOURCESELECT_H
19+
#include "ui_qgsspatialitesourceselectbase.h"
20+
21+
#include "qgisgui.h"
22+
#include "qgsspatialitefilterproxymodel.h"
23+
#include "qgsspatialitetablemodel.h"
24+
25+
extern "C"
26+
{
27+
#include <spatialite/sqlite3.h>
28+
}
29+
30+
#include <QThread>
31+
32+
#include <vector>
33+
#include <list>
34+
#include <utility>
35+
36+
#include <QMap>
37+
#include <QPair>
38+
#include <QIcon>
39+
#include <QFileDialog>
40+
41+
class QStringList;
42+
class QTableWidgetItem;
43+
class QgisApp;
44+
45+
/*! \class QgsSpatiaLiteSourceSelect
46+
* \brief Dialog to create connections and add tables from SpatiaLite.
47+
*
48+
* This dialog allows the user to define and save connection information
49+
* for SpatiaLite/SQLite databases. The user can then connect and add
50+
* tables from the database to the map canvas.
51+
*/
52+
class QgsSpatiaLiteSourceSelect:public QDialog, private Ui::QgsSpatiaLiteSourceSelectBase
53+
{
54+
Q_OBJECT public:
55+
56+
//! Constructor
57+
QgsSpatiaLiteSourceSelect(QgisApp * app, Qt::WFlags fl = QgisGui::ModalDialogFlags);
58+
//! Destructor
59+
~QgsSpatiaLiteSourceSelect()
60+
{
61+
;
62+
}
63+
//! Opens the create connection dialog to build a new connection
64+
void addNewConnection();
65+
//! Deletes the selected connection
66+
void deleteConnection();
67+
//! Populate the connection list combo box
68+
void populateConnectionList();
69+
//! Determines the tables the user selected and closes the dialog
70+
void addTables();
71+
//! String list containing the selected tables
72+
QStringList selectedTables();
73+
//! Connection info (DB-path)
74+
QString connectionInfo();
75+
// Store the selected database
76+
void dbChanged();
77+
78+
public slots:
79+
/*! Connects to the database using the stored connection parameters.
80+
* Once connected, available layers are displayed.
81+
*/
82+
void on_btnConnect_clicked();
83+
void on_btnAdd_clicked();
84+
void on_btnNew_clicked();
85+
void on_btnDelete_clicked();
86+
void on_mSearchOptionsButton_clicked();
87+
void on_mSearchTableEdit_textChanged(const QString & text);
88+
void on_mSearchColumnComboBox_currentIndexChanged(const QString & text);
89+
void on_mSearchModeComboBox_currentIndexChanged(const QString & text);
90+
void on_btnHelp_clicked();
91+
void on_cmbConnections_activated(int);
92+
void setLayerType(QString table, QString column, QString type);
93+
//!Sets a new regular expression to the model
94+
void setSearchExpression(const QString & regexp);
95+
96+
private:
97+
enum columns
98+
{
99+
dbssType = 0,
100+
dbssDetail,
101+
dbssSql,
102+
dbssColumns,
103+
};
104+
105+
typedef std::pair < QString, QString > geomPair;
106+
typedef std::list < geomPair > geomCol;
107+
108+
/**Inserts information about the spatial tables into mTableModel*/
109+
bool getTableInfo(sqlite3 * handle);
110+
111+
// SpatiaLite DB open / close
112+
sqlite3 *openSpatiaLiteDb(const char *path);
113+
void closeSpatiaLiteDb(sqlite3 * handle);
114+
115+
// Set the position of the database connection list to the last
116+
// used one.
117+
void setConnectionListPosition();
118+
// Show the context help for the dialog
119+
void showHelp();
120+
// Combine the table and column data into a single string
121+
// useful for display to the user
122+
QString fullDescription(QString table, QString column, QString type);
123+
// The column labels
124+
QStringList mColumnLabels;
125+
QString mSqlitePath;
126+
QStringList m_selectedTables;
127+
// Storage for the range of layer type icons
128+
QMap < QString, QPair < QString, QIcon > >mLayerIcons;
129+
//! Pointer to the qgis application mainwindow
130+
QgisApp *qgisApp;
131+
static const int context_id = 250632828;
132+
//! Model that acts as datasource for mTableTreeWidget
133+
QgsSpatiaLiteTableModel mTableModel;
134+
QgsSpatiaLiteFilterProxyModel mProxyModel;
135+
};
136+
137+
#endif // QGSSPATIALITESOURCESELECT_H

‎src/app/qgsspatialitetablemodel.cpp

Lines changed: 204 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,204 @@
1+
/***************************************************************************
2+
qgsspatialitetablemodel.cpp - description
3+
-------------------
4+
begin : Dec 2008
5+
copyright : (C) 2008 by Sandro Furieri
6+
email : a.furieri@lqt.it
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+
18+
#include "qgsspatialitetablemodel.h"
19+
#include "qgsapplication.h"
20+
#include "qgisapp.h"
21+
22+
QgsSpatiaLiteTableModel::QgsSpatiaLiteTableModel():QStandardItemModel(), mTableCount(0)
23+
{
24+
QStringList headerLabels;
25+
headerLabels << tr("Table");
26+
headerLabels << tr("Type");
27+
headerLabels << tr("Geometry column");
28+
setHorizontalHeaderLabels(headerLabels);
29+
}
30+
31+
QgsSpatiaLiteTableModel::~QgsSpatiaLiteTableModel()
32+
{
33+
34+
}
35+
36+
void QgsSpatiaLiteTableModel::addTableEntry(QString type, QString tableName, QString geometryColName)
37+
{
38+
//is there already a root item ?
39+
QStandardItem *dbItem;
40+
QList < QStandardItem * >dbItems = findItems(mSqliteDb, Qt::MatchExactly, 0);
41+
42+
//there is already an item
43+
if (dbItems.size() > 0)
44+
{
45+
dbItem = dbItems.at(0);
46+
} else //create a new toplevel item
47+
{
48+
dbItem = new QStandardItem(mSqliteDb);
49+
dbItem->setFlags(Qt::ItemIsEnabled);
50+
invisibleRootItem()->setChild(invisibleRootItem()->rowCount(), dbItem);
51+
}
52+
53+
//path to icon for specified type
54+
QString typeName;
55+
56+
QGis::WkbType wkbType = qgisTypeFromDbType(type);
57+
QIcon iconFile = iconForType(wkbType);
58+
59+
QList < QStandardItem * >childItemList;
60+
QStandardItem *typeItem = new QStandardItem(QIcon(iconFile), type);
61+
typeItem->setFlags(Qt::ItemIsEnabled | Qt::ItemIsSelectable);
62+
QStandardItem *tableItem = new QStandardItem(tableName);
63+
tableItem->setFlags(Qt::ItemIsEnabled | Qt::ItemIsSelectable);
64+
QStandardItem *geomItem = new QStandardItem(geometryColName);
65+
geomItem->setFlags(Qt::ItemIsEnabled | Qt::ItemIsSelectable);
66+
67+
68+
childItemList.push_back(tableItem);
69+
childItemList.push_back(typeItem);
70+
childItemList.push_back(geomItem);
71+
72+
dbItem->appendRow(childItemList);
73+
++mTableCount;
74+
}
75+
76+
void QgsSpatiaLiteTableModel::setGeometryTypesForTable(const QString & table, const QString & attribute, const QString & type)
77+
{
78+
bool typeIsEmpty = type.isEmpty(); //true means the table has no valid geometry entry and the item for this table should be removed
79+
QStringList typeList = type.split(",");
80+
81+
//find schema item and table item
82+
QStandardItem *dbItem;
83+
QList < QStandardItem * >dbItems = findItems(mSqliteDb, Qt::MatchExactly, 0);
84+
85+
if (dbItems.size() < 1)
86+
{
87+
return;
88+
}
89+
dbItem = dbItems.at(0);
90+
int numChildren = dbItem->rowCount();
91+
92+
QModelIndex currentChildIndex;
93+
QModelIndex currentTableIndex;
94+
QModelIndex currentTypeIndex;
95+
QModelIndex currentGeomColumnIndex;
96+
97+
for (int i = 0; i < numChildren; ++i)
98+
{
99+
currentChildIndex = indexFromItem(dbItem->child(i, 0));
100+
if (!currentChildIndex.isValid())
101+
{
102+
continue;
103+
}
104+
currentTableIndex = currentChildIndex.sibling(i, 1);
105+
currentTypeIndex = currentChildIndex.sibling(i, 2);
106+
currentGeomColumnIndex = currentChildIndex.sibling(i, 3);
107+
QString geomColText = itemFromIndex(currentGeomColumnIndex)->text();
108+
109+
if (!currentTypeIndex.isValid() || !currentTableIndex.isValid() || !currentGeomColumnIndex.isValid())
110+
{
111+
continue;
112+
}
113+
114+
if (itemFromIndex(currentTableIndex)->text() == table &&
115+
(geomColText == attribute || geomColText.startsWith(attribute + " AS ")))
116+
{
117+
if (typeIsEmpty)
118+
{
119+
removeRow(i, indexFromItem(dbItem));
120+
return;
121+
}
122+
123+
QGis::WkbType wkbType = qgisTypeFromDbType(typeList.at(0));
124+
QIcon myIcon = iconForType(wkbType);
125+
itemFromIndex(currentTypeIndex)->setText(typeList.at(0)); //todo: add other rows
126+
itemFromIndex(currentTypeIndex)->setIcon(myIcon);
127+
if (!geomColText.contains(" AS "))
128+
{
129+
itemFromIndex(currentGeomColumnIndex)->setText(geomColText + " AS " + typeList.at(0));
130+
}
131+
132+
for (int j = 1; j < typeList.size(); ++j)
133+
{
134+
//todo: add correct type
135+
addTableEntry(typeList.at(j), table, geomColText + " AS " + typeList.at(j));
136+
}
137+
}
138+
}
139+
}
140+
141+
QIcon QgsSpatiaLiteTableModel::iconForType(QGis::WkbType type) const
142+
{
143+
if (type == QGis::WKBPoint || type == QGis::WKBPoint25D || type == QGis::WKBMultiPoint || type == QGis::WKBMultiPoint25D)
144+
{
145+
return QgisApp::getThemeIcon("/mIconPointLayer.png");
146+
} else if (type == QGis::WKBLineString || type == QGis::WKBLineString25D || type == QGis::WKBMultiLineString
147+
|| type == QGis::WKBMultiLineString25D)
148+
{
149+
return QgisApp::getThemeIcon("/mIconLineLayer.png");
150+
} else if (type == QGis::WKBPolygon || type == QGis::WKBPolygon25D || type == QGis::WKBMultiPolygon
151+
|| type == QGis::WKBMultiPolygon25D)
152+
{
153+
return QgisApp::getThemeIcon("/mIconPolygonLayer.png");
154+
} else
155+
return QIcon();
156+
}
157+
158+
QString QgsSpatiaLiteTableModel::displayStringForType(QGis::WkbType type) const
159+
{
160+
if (type == QGis::WKBPoint || type == QGis::WKBPoint25D)
161+
{
162+
return tr("Point");
163+
} else if (type == QGis::WKBMultiPoint || type == QGis::WKBMultiPoint25D)
164+
{
165+
return tr("Multipoint");
166+
} else if (type == QGis::WKBLineString || type == QGis::WKBLineString25D)
167+
{
168+
return tr("Line");
169+
} else if (type == QGis::WKBMultiLineString || type == QGis::WKBMultiLineString25D)
170+
{
171+
return tr("Multiline");
172+
} else if (type == QGis::WKBPolygon || type == QGis::WKBPolygon25D)
173+
{
174+
return tr("Polygon");
175+
} else if (type == QGis::WKBMultiPolygon || type == QGis::WKBMultiPolygon25D)
176+
{
177+
return tr("Multipolygon");
178+
}
179+
return "Unknown";
180+
}
181+
182+
QGis::WkbType QgsSpatiaLiteTableModel::qgisTypeFromDbType(const QString & dbType) const
183+
{
184+
if (dbType == "POINT")
185+
{
186+
return QGis::WKBPoint;
187+
} else if (dbType == "MULTIPOINT")
188+
{
189+
return QGis::WKBMultiPoint;
190+
} else if (dbType == "LINESTRING")
191+
{
192+
return QGis::WKBLineString;
193+
} else if (dbType == "MULTILINESTRING")
194+
{
195+
return QGis::WKBMultiLineString;
196+
} else if (dbType == "POLYGON")
197+
{
198+
return QGis::WKBPolygon;
199+
} else if (dbType == "MULTIPOLYGON")
200+
{
201+
return QGis::WKBMultiPolygon;
202+
}
203+
return QGis::WKBUnknown;
204+
}

‎src/app/qgsspatialitetablemodel.h

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
/***************************************************************************
2+
qgsspatialitetablemodel.h - description
3+
-------------------
4+
begin : Dec 2008
5+
copyright : (C) 2008 by Sandro Furieri
6+
email : a.furieri@lqt.it
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+
18+
#include <QStandardItemModel>
19+
class QIcon;
20+
#include "qgis.h"
21+
22+
/**A model that holds the tables of a database in a hierarchy where the
23+
SQLite DB is the root elements that contain the individual tables as children.
24+
The tables have the following columns: Type, Tablename, Geometry Column*/
25+
class QgsSpatiaLiteTableModel:public QStandardItemModel
26+
{
27+
Q_OBJECT public:
28+
29+
QgsSpatiaLiteTableModel();
30+
~QgsSpatiaLiteTableModel();
31+
/**Adds entry for one database table to the model*/
32+
void addTableEntry(QString type, QString tableName, QString geometryColName);
33+
/**Sets one or more geometry types to a row. In case of several types, additional rows are inserted.
34+
This is for tables where the type is dectected later by thread*/
35+
void setGeometryTypesForTable(const QString & table, const QString & attribute, const QString & type);
36+
/**Returns the number of tables in the model*/
37+
int tableCount() const
38+
{
39+
return mTableCount;
40+
}
41+
/** Sets the SQLite DB full path*/
42+
void setSqliteDb(const QString & dbName)
43+
{
44+
mSqliteDb = dbName;
45+
}
46+
47+
private:
48+
/**Number of tables in the model*/
49+
int mTableCount;
50+
QString mSqliteDb;
51+
52+
QIcon iconForType(QGis::WkbType type) const;
53+
QString displayStringForType(QGis::WkbType type) const;
54+
/**Returns qgis wkbtype from database typename*/
55+
QGis::WkbType qgisTypeFromDbType(const QString & dbType) const;
56+
};

‎src/providers/CMakeLists.txt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,10 @@ IF (POSTGRES_FOUND)
55
SUBDIRS (postgres)
66
ENDIF (POSTGRES_FOUND)
77

8+
IF (SPATIALITE_FOUND)
9+
SUBDIRS (spatialite)
10+
ENDIF (SPATIALITE_FOUND)
11+
812
IF (EXPAT_FOUND)
913
SUBDIRS (gpx wfs)
1014
ENDIF (EXPAT_FOUND)
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
2+
########################################################
3+
# Files
4+
5+
SET(SPATIALITE_SRCS qgsspatialiteprovider.cpp)
6+
7+
SET(SPATIALITE_MOC_HDRS qgsspatialiteprovider.h)
8+
9+
10+
########################################################
11+
# Build
12+
13+
QT4_WRAP_CPP(SPATIALITE_MOC_SRCS ${SPATIALITE_MOC_HDRS})
14+
15+
INCLUDE_DIRECTORIES(
16+
../../core
17+
${SPATIALITE_INCLUDE_DIR}
18+
${SPATIALITE_INCLUDE_DIR}
19+
)
20+
21+
ADD_LIBRARY (spatialiteprovider MODULE ${SPATIALITE_SRCS} ${SPATIALITE_MOC_SRCS})
22+
23+
TARGET_LINK_LIBRARIES(spatialiteprovider
24+
${QT_QTCORE_LIBRARY}
25+
${QT_QTXML_LIBRARY}
26+
${SPATIALITE_LIBRARY}
27+
qgis_core
28+
)
29+
30+
31+
########################################################
32+
# Install
33+
34+
INSTALL(TARGETS spatialiteprovider
35+
RUNTIME DESTINATION ${QGIS_PLUGIN_DIR}
36+
LIBRARY DESTINATION ${QGIS_PLUGIN_DIR})

‎src/providers/spatialite/qgsspatialiteprovider.cpp

Lines changed: 1564 additions & 0 deletions
Large diffs are not rendered by default.
Lines changed: 364 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,364 @@
1+
/***************************************************************************
2+
qgsspatialiteprovider.h Data provider for SpatiaLite DBMS
3+
begin : Dec 2008
4+
copyright : (C) 2008 Sandro Furieri
5+
email : a.furieri@lqt.it
6+
***************************************************************************/
7+
8+
/***************************************************************************
9+
* *
10+
* This program is free software; you can redistribute it and/or modify *
11+
* it under the terms of the GNU General Public License as published by *
12+
* the Free Software Foundation; either version 2 of the License, or *
13+
* (at your option) any later version. *
14+
* *
15+
***************************************************************************/
16+
17+
extern "C"
18+
{
19+
#include <spatialite/sqlite3.h>
20+
#include <spatialite/gaiageo.h>
21+
#include <spatialite.h>
22+
}
23+
24+
#include "qgsvectordataprovider.h"
25+
#include "qgsrectangle.h"
26+
#include <list>
27+
#include <queue>
28+
#include <fstream>
29+
#include <set>
30+
31+
class QgsFeature;
32+
class QgsField;
33+
34+
#include "qgsdatasourceuri.h"
35+
36+
/**
37+
\class QgsSpatiaLiteProvider
38+
\brief Data provider for SQLite/SpatiaLite layers.
39+
40+
This provider implements the
41+
interface defined in the QgsDataProvider class to provide access to spatial
42+
data residing in a SQLite/SpatiaLite enabled database.
43+
*/
44+
class QgsSpatiaLiteProvider:public QgsVectorDataProvider
45+
{
46+
Q_OBJECT public:
47+
/**
48+
* Constructor of the vector provider
49+
* @param uri uniform resource locator (URI) for a dataset
50+
*/
51+
QgsSpatiaLiteProvider(QString const &uri = "");
52+
53+
//! Destructor
54+
virtual ~ QgsSpatiaLiteProvider();
55+
56+
/**
57+
* Returns the permanent storage type for this layer as a friendly name.
58+
*/
59+
virtual QString storageType() const;
60+
61+
/*! Get the QgsCoordinateReferenceSystem for this layer
62+
* @note Must be reimplemented by each provider.
63+
* If the provider isn't capable of returning
64+
* its projection an empty srs will be return, ti will return 0
65+
*/
66+
virtual QgsCoordinateReferenceSystem crs();
67+
68+
/** Select features based on a bounding rectangle. Features can be retrieved with calls to nextFeature.
69+
* @param fetchAttributes list of attributes which should be fetched
70+
* @param rect spatial filter
71+
* @param fetchGeometry true if the feature geometry should be fetched
72+
* @param useIntersect true if an accurate intersection test should be used,
73+
* false if a test based on bounding box is sufficient
74+
*/
75+
virtual bool featureAtId(int featureId,
76+
QgsFeature & feature, bool fetchGeometry = true, QgsAttributeList fetchAttributes = QgsAttributeList());
77+
/** Select features based on a bounding rectangle. Features can be retrieved with calls to nextFeature.
78+
* @param fetchAttributes list of attributes which should be fetched
79+
* @param rect spatial filter
80+
* @param fetchGeometry true if the feature geometry should be fetched
81+
* @param useIntersect true if an accurate intersection test should be used,
82+
* false if a test based on bounding box is sufficient
83+
*/
84+
virtual void select(QgsAttributeList fetchAttributes = QgsAttributeList(),
85+
QgsRectangle rect = QgsRectangle(), bool fetchGeometry = true, bool useIntersect = false);
86+
87+
/**
88+
* Get the next feature resulting from a select operation.
89+
* @param feature feature which will receive data from the provider
90+
* @return true when there was a feature to fetch, false when end was hit
91+
*/
92+
virtual bool nextFeature(QgsFeature & feature);
93+
94+
/** Get the feature type. This corresponds to
95+
* WKBPoint,
96+
* WKBLineString,
97+
* WKBPolygon,
98+
* WKBMultiPoint,
99+
* WKBMultiLineString or
100+
* WKBMultiPolygon
101+
* as defined in qgis.h
102+
*/
103+
QGis::WkbType geometryType() const;
104+
105+
/** return the number of layers for the current data source
106+
107+
@note
108+
109+
Should this be subLayerCount() instead?
110+
*/
111+
size_t layerCount() const;
112+
113+
/**
114+
* Get the number of features in the layer
115+
*/
116+
long featureCount() const;
117+
118+
/**
119+
* Get the number of fields in the layer
120+
*/
121+
uint fieldCount() const;
122+
123+
/** Return the extent for this data layer
124+
*/
125+
virtual QgsRectangle extent();
126+
127+
/** * Get the name of the primary key for the layer
128+
*/
129+
QString getPrimaryKey();
130+
131+
/**
132+
* Get the field information for the layer
133+
* @return vector of QgsField objects
134+
*/
135+
const QgsFieldMap & fields() const;
136+
137+
/** Reset the layer - for a PostgreSQL layer, this means clearing the PQresult
138+
* pointer, setting it to 0 and reloading the field list
139+
*/
140+
void rewind();
141+
142+
/** Returns the minimum value of an attribute
143+
* @param index the index of the attribute */
144+
QVariant minimumValue(int index);
145+
146+
/** Returns the maximum value of an attribute
147+
* @param index the index of the attribute */
148+
QVariant maximumValue(int index);
149+
150+
/** Return the unique values of an attribute
151+
* @param index the index of the attribute
152+
* @param values reference to the list of unique values */
153+
virtual void uniqueValues(int index, QList < QVariant > &uniqueValues);
154+
155+
/**Returns true if layer is valid
156+
*/
157+
bool isValid();
158+
159+
/**Adds a list of features
160+
@return true in case of success and false in case of failure*/
161+
bool addFeatures(QgsFeatureList & flist);
162+
163+
/**Deletes a list of features
164+
@param id list of feature ids
165+
@return true in case of success and false in case of failure*/
166+
bool deleteFeatures(const QgsFeatureIds & id);
167+
168+
/**Adds new attributes
169+
@param name map with attribute name as key and type as value
170+
@return true in case of success and false in case of failure*/
171+
bool addAttributes(const QgsNewAttributesMap & name);
172+
173+
/**Changes attribute values of existing features
174+
@param attr_map a map containing the new attributes. The integer is the feature id,
175+
the first QString is the attribute name and the second one is the new attribute value
176+
@return true in case of success and false in case of failure*/
177+
bool changeAttributeValues(const QgsChangedAttributesMap & attr_map);
178+
179+
/**
180+
Changes geometries of existing features
181+
@param geometry_map A std::map containing the feature IDs to change the geometries of.
182+
the second map parameter being the new geometries themselves
183+
@return true in case of success and false in case of failure
184+
*/
185+
bool changeGeometryValues(QgsGeometryMap & geometry_map);
186+
187+
/**Returns a bitmask containing the supported capabilities*/
188+
int capabilities() const;
189+
190+
/** The SpatiaLite provider does its own transforms so we return
191+
* true for the following three functions to indicate that transforms
192+
* should not be handled by the QgsCoordinateTransform object. See the
193+
* documentation on QgsVectorDataProvider for details on these functions.
194+
*/
195+
// XXX For now we have disabled native transforms in the SpatiaLite
196+
// (following the PostgreSQL provider example)
197+
bool supportsNativeTransform()
198+
{
199+
return false;
200+
}
201+
202+
/** return a provider name
203+
204+
Essentially just returns the provider key. Should be used to build file
205+
dialogs so that providers can be shown with their supported types. Thus
206+
if more than one provider supports a given format, the user is able to
207+
select a specific provider to open that file.
208+
209+
@note
210+
211+
Instead of being pure virtual, might be better to generalize this
212+
behavior and presume that none of the sub-classes are going to do
213+
anything strange with regards to their name or description?
214+
215+
*/
216+
QString name() const;
217+
218+
/** return description
219+
220+
Return a terse string describing what the provider is.
221+
222+
@note
223+
224+
Instead of being pure virtual, might be better to generalize this
225+
behavior and presume that none of the sub-classes are going to do
226+
anything strange with regards to their name or description?
227+
228+
*/
229+
QString description() const;
230+
231+
signals:
232+
/**
233+
* This is emitted whenever the worker thread has fully calculated the
234+
* PostGIS extents for this layer, and its event has been received by this
235+
* provider.
236+
*/
237+
void fullExtentCalculated();
238+
239+
/**
240+
* This is emitted when this provider is satisfied that all objects
241+
* have had a chance to adjust themselves after they'd been notified that
242+
* the full extent is available.
243+
*
244+
* \note It currently isn't being emitted because we don't have an easy way
245+
* for the overview canvas to only be repainted. In the meantime
246+
* we are satisfied for the overview to reflect the new extent
247+
* when the user adjusts the extent of the main map canvas.
248+
*/
249+
void repaintRequested();
250+
251+
private:
252+
/** loads fields from input file to member attributeFields */
253+
void loadFields();
254+
255+
QgsFieldMap attributeFields;
256+
/**
257+
* Flag indicating if the layer data source is a valid SpatiaLite layer
258+
*/
259+
bool valid;
260+
/**
261+
* DB full path
262+
*/
263+
QString mSqlitePath;
264+
/**
265+
* Name of the table with no schema
266+
*/
267+
QString mTableName;
268+
/**
269+
* Name of the primary key column in the table
270+
*/
271+
QString primaryKey;
272+
/**
273+
* Name of the geometry column in the table
274+
*/
275+
QString geometryColumn;
276+
/**
277+
* Geometry type
278+
*/
279+
QGis::WkbType geomType;
280+
/**
281+
* SQLite handle
282+
*/
283+
sqlite3 *sqliteHandle;
284+
/**
285+
* SQLite statement handle
286+
*/
287+
sqlite3_stmt *sqliteStatement;
288+
/**
289+
* Spatial reference id of the layer
290+
*/
291+
int mSrid;
292+
/**
293+
* proj4text
294+
*/
295+
QString mProj4text;
296+
/**
297+
* Rectangle that contains the extent (bounding box) of the layer
298+
*/
299+
QgsRectangle layerExtent;
300+
301+
/**
302+
* Number of features in the layer
303+
*/
304+
long numberFeatures;
305+
/**
306+
* this Geometry is supported by an R*Tree spatial index
307+
*/
308+
bool spatialIndexRTree;
309+
/**
310+
* this Geometry is supported by an MBR cache spatial index
311+
*/
312+
bool spatialIndexMbrCache;
313+
314+
int enabledCapabilities;
315+
316+
const QgsField & field(int index) const;
317+
318+
/**
319+
* internal utility functions used to handle common SQLite tasks
320+
*/
321+
//void sqliteOpen();
322+
void closeDb();
323+
QString quotedValue(QString value) const;
324+
bool getGeometryDetails();
325+
bool getTableSummary();
326+
327+
public:
328+
class SqliteHandles
329+
{
330+
//
331+
// a class allowing to reuse the same sqlite handle for more layers
332+
//
333+
public:
334+
SqliteHandles(sqlite3 * handle):
335+
ref(1), sqlite_handle(handle)
336+
{
337+
}
338+
339+
sqlite3 *handle()
340+
{
341+
return sqlite_handle;
342+
}
343+
344+
//
345+
// libsqlite3 wrapper
346+
//
347+
void sqliteClose();
348+
349+
static SqliteHandles *openDb(const QString & dbPath);
350+
static void closeDb(SqliteHandles * &handle);
351+
static void closeDb(QMap < QString, SqliteHandles * >&handlesRO, SqliteHandles * &handle);
352+
353+
private:
354+
int ref;
355+
sqlite3 *sqlite_handle;
356+
357+
static QMap < QString, SqliteHandles * >handles;
358+
};
359+
360+
/**
361+
* sqlite3 handles pointer
362+
*/
363+
SqliteHandles *handle;
364+
};
Lines changed: 244 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,244 @@
1+
<ui version="4.0" >
2+
<class>QgsSpatiaLiteSourceSelectBase</class>
3+
<widget class="QDialog" name="QgsSpatiaLiteSourceSelectBase" >
4+
<property name="geometry" >
5+
<rect>
6+
<x>0</x>
7+
<y>0</y>
8+
<width>472</width>
9+
<height>687</height>
10+
</rect>
11+
</property>
12+
<property name="windowTitle" >
13+
<string>Add SpatiaLite Table(s)</string>
14+
</property>
15+
<property name="windowIcon" >
16+
<iconset/>
17+
</property>
18+
<property name="sizeGripEnabled" >
19+
<bool>true</bool>
20+
</property>
21+
<property name="modal" >
22+
<bool>true</bool>
23+
</property>
24+
<layout class="QGridLayout" >
25+
<property name="margin" >
26+
<number>9</number>
27+
</property>
28+
<property name="spacing" >
29+
<number>6</number>
30+
</property>
31+
<item row="2" column="0" >
32+
<spacer>
33+
<property name="orientation" >
34+
<enum>Qt::Horizontal</enum>
35+
</property>
36+
<property name="sizeHint" >
37+
<size>
38+
<width>271</width>
39+
<height>20</height>
40+
</size>
41+
</property>
42+
</spacer>
43+
</item>
44+
<item row="1" column="0" colspan="2" >
45+
<widget class="QTreeView" name="mTablesTreeView" >
46+
<property name="selectionMode" >
47+
<enum>QAbstractItemView::MultiSelection</enum>
48+
</property>
49+
</widget>
50+
</item>
51+
<item row="0" column="0" colspan="2" >
52+
<widget class="QGroupBox" name="groupBox" >
53+
<property name="title" >
54+
<string>SpatiaLite DBs</string>
55+
</property>
56+
<layout class="QGridLayout" >
57+
<property name="margin" >
58+
<number>11</number>
59+
</property>
60+
<property name="spacing" >
61+
<number>6</number>
62+
</property>
63+
<item row="1" column="2" >
64+
<widget class="QPushButton" name="btnDelete" >
65+
<property name="text" >
66+
<string>Delete</string>
67+
</property>
68+
</widget>
69+
</item>
70+
<item row="1" column="1" >
71+
<widget class="QPushButton" name="btnNew" >
72+
<property name="text" >
73+
<string>New</string>
74+
</property>
75+
</widget>
76+
</item>
77+
<item row="1" column="0" >
78+
<widget class="QPushButton" name="btnConnect" >
79+
<property name="text" >
80+
<string>Connect</string>
81+
</property>
82+
</widget>
83+
</item>
84+
<item row="0" column="0" colspan="3" >
85+
<widget class="QComboBox" name="cmbConnections" />
86+
</item>
87+
</layout>
88+
</widget>
89+
</item>
90+
<item row="4" column="0" colspan="2" >
91+
<layout class="QHBoxLayout" >
92+
<property name="margin" >
93+
<number>11</number>
94+
</property>
95+
<property name="spacing" >
96+
<number>6</number>
97+
</property>
98+
<item>
99+
<widget class="QPushButton" name="btnHelp" >
100+
<property name="enabled" >
101+
<bool>true</bool>
102+
</property>
103+
<property name="text" >
104+
<string>Help</string>
105+
</property>
106+
<property name="shortcut" >
107+
<string>F1</string>
108+
</property>
109+
<property name="autoDefault" >
110+
<bool>true</bool>
111+
</property>
112+
</widget>
113+
</item>
114+
<item>
115+
<spacer>
116+
<property name="orientation" >
117+
<enum>Qt::Horizontal</enum>
118+
</property>
119+
<property name="sizeType" >
120+
<enum>QSizePolicy::Expanding</enum>
121+
</property>
122+
<property name="sizeHint" >
123+
<size>
124+
<width>141</width>
125+
<height>21</height>
126+
</size>
127+
</property>
128+
</spacer>
129+
</item>
130+
<item>
131+
<widget class="QPushButton" name="btnAdd" >
132+
<property name="text" >
133+
<string>Add</string>
134+
</property>
135+
<property name="shortcut" >
136+
<string/>
137+
</property>
138+
<property name="autoDefault" >
139+
<bool>true</bool>
140+
</property>
141+
<property name="default" >
142+
<bool>true</bool>
143+
</property>
144+
</widget>
145+
</item>
146+
<item>
147+
<widget class="QPushButton" name="btnCancel" >
148+
<property name="text" >
149+
<string>Close</string>
150+
</property>
151+
<property name="shortcut" >
152+
<string/>
153+
</property>
154+
<property name="autoDefault" >
155+
<bool>true</bool>
156+
</property>
157+
</widget>
158+
</item>
159+
</layout>
160+
</item>
161+
<item row="3" column="0" colspan="2" >
162+
<widget class="QGroupBox" name="mSearchGroupBox" >
163+
<property name="title" >
164+
<string/>
165+
</property>
166+
<layout class="QGridLayout" >
167+
<property name="margin" >
168+
<number>9</number>
169+
</property>
170+
<property name="spacing" >
171+
<number>6</number>
172+
</property>
173+
<item row="0" column="0" >
174+
<widget class="QLabel" name="mSearchLabel" >
175+
<property name="text" >
176+
<string>Search:</string>
177+
</property>
178+
</widget>
179+
</item>
180+
<item row="2" column="0" colspan="2" >
181+
<widget class="QLabel" name="mSearchModeLabel" >
182+
<property name="text" >
183+
<string>Search mode:</string>
184+
</property>
185+
</widget>
186+
</item>
187+
<item row="2" column="2" >
188+
<widget class="QComboBox" name="mSearchModeComboBox" />
189+
</item>
190+
<item row="1" column="0" colspan="2" >
191+
<widget class="QLabel" name="mSearchColumnsLabel" >
192+
<property name="text" >
193+
<string>Search in columns:</string>
194+
</property>
195+
</widget>
196+
</item>
197+
<item row="1" column="2" >
198+
<widget class="QComboBox" name="mSearchColumnComboBox" />
199+
</item>
200+
<item row="0" column="1" colspan="2" >
201+
<widget class="QLineEdit" name="mSearchTableEdit" />
202+
</item>
203+
</layout>
204+
</widget>
205+
</item>
206+
<item row="2" column="1" >
207+
<widget class="QPushButton" name="mSearchOptionsButton" >
208+
<property name="text" >
209+
<string>Search options...</string>
210+
</property>
211+
</widget>
212+
</item>
213+
</layout>
214+
</widget>
215+
<layoutdefault spacing="6" margin="11" />
216+
<tabstops>
217+
<tabstop>cmbConnections</tabstop>
218+
<tabstop>btnConnect</tabstop>
219+
<tabstop>btnNew</tabstop>
220+
<tabstop>btnDelete</tabstop>
221+
<tabstop>btnHelp</tabstop>
222+
<tabstop>btnAdd</tabstop>
223+
<tabstop>btnCancel</tabstop>
224+
</tabstops>
225+
<resources/>
226+
<connections>
227+
<connection>
228+
<sender>btnCancel</sender>
229+
<signal>clicked()</signal>
230+
<receiver>QgsSpatiaLiteSourceSelectBase</receiver>
231+
<slot>reject()</slot>
232+
<hints>
233+
<hint type="sourcelabel" >
234+
<x>404</x>
235+
<y>446</y>
236+
</hint>
237+
<hint type="destinationlabel" >
238+
<x>229</x>
239+
<y>236</y>
240+
</hint>
241+
</hints>
242+
</connection>
243+
</connections>
244+
</ui>

0 commit comments

Comments
 (0)
Please sign in to comment.