diff --git a/src/app/CMakeLists.txt b/src/app/CMakeLists.txt index 3d34901751f..ba46a8142e3 100644 --- a/src/app/CMakeLists.txt +++ b/src/app/CMakeLists.txt @@ -301,17 +301,16 @@ ENDIF (POSTGRES_FOUND) IF (HAVE_SPATIALITE) SET (QGIS_APP_SRCS ${QGIS_APP_SRCS} - qgsspatialitesourceselect.cpp - qgsnewspatialitelayerdialog.cpp - qgsspatialitesridsdialog.cpp - qgsspatialitefilterproxymodel.cpp - qgsspatialitetablemodel.cpp + spatialite/qgsspatialitesourceselect.cpp + spatialite/qgsnewspatialitelayerdialog.cpp + spatialite/qgsspatialitesridsdialog.cpp + spatialite/qgsspatialitetablemodel.cpp ) SET (QGIS_APP_MOC_HDRS ${QGIS_APP_MOC_HDRS} - qgsspatialitesourceselect.h - qgsnewspatialitelayerdialog.h - qgsspatialitesridsdialog.h - qgsspatialitetablemodel.h + spatialite/qgsspatialitesourceselect.h + spatialite/qgsnewspatialitelayerdialog.h + spatialite/qgsspatialitesridsdialog.h + spatialite/qgsspatialitetablemodel.h ) ENDIF (HAVE_SPATIALITE) diff --git a/src/app/postgres/qgspgsourceselect.h b/src/app/postgres/qgspgsourceselect.h index 7e8c5212a52..00fa7552e65 100644 --- a/src/app/postgres/qgspgsourceselect.h +++ b/src/app/postgres/qgspgsourceselect.h @@ -17,7 +17,7 @@ /* $Id$ */ #ifndef QGSPGSOURCESELECT_H #define QGSPGSOURCESELECT_H -#include "ui_qgspgsourceselectbase.h" +#include "ui_qgsdbsourceselectbase.h" #include "qgisgui.h" #include "qgsdbfilterproxymodel.h" #include "qgsdbtablemodel.h" @@ -99,7 +99,7 @@ class QgsPgSourceSelectDelegate : public QItemDelegate * for PostGIS enabled PostgreSQL databases. The user can then connect and add * tables from the database to the map canvas. */ -class QgsPgSourceSelect : public QDialog, private Ui::QgsPgSourceSelectBase +class QgsPgSourceSelect : public QDialog, private Ui::QgsDbSourceSelectBase { Q_OBJECT diff --git a/src/app/qgisapp.cpp b/src/app/qgisapp.cpp index 26032161243..930fd51988f 100644 --- a/src/app/qgisapp.cpp +++ b/src/app/qgisapp.cpp @@ -112,6 +112,7 @@ #include "qgscredentialdialog.h" #include "qgscursors.h" #include "qgscustomprojectiondialog.h" +#include "qgsdatasourceuri.h" #include "qgsencodingfiledialog.h" #include "qgsexception.h" #include "qgsfeature.h" @@ -235,8 +236,8 @@ extern "C" { #include } -#include "qgsspatialitesourceselect.h" -#include "qgsnewspatialitelayerdialog.h" +#include "spatialite/qgsspatialitesourceselect.h" +#include "spatialite/qgsnewspatialitelayerdialog.h" #endif #include "qgspythonutils.h" @@ -3025,17 +3026,16 @@ void QgisApp::addDatabaseLayer() QApplication::setOverrideCursor( Qt::WaitCursor ); - QString connectionInfo = dbs->connectionInfo(); // 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() ) { - // create the layer //qWarning("creating layer"); - QgsVectorLayer *layer = new QgsVectorLayer( connectionInfo + " " + *it, *it, "postgres" ); + QgsDataSourceURI uri( *it ); + QgsVectorLayer *layer = new QgsVectorLayer( uri.uri(), uri.table(), "postgres" ); if ( layer->isValid() ) { // register this layer with the central layers registry @@ -3101,20 +3101,13 @@ void QgisApp::addSpatiaLiteLayer() QApplication::setOverrideCursor( Qt::WaitCursor ); - QString connectionInfo = dbs->connectionInfo(); // for each selected table, connect to the database and build a canvasitem for it QStringList::Iterator it = tables.begin(); while ( it != tables.end() ) { - // normalizing the layer name - QString layername = *it; - layername = layername.mid( 1 ); - int idx = layername.indexOf( "\" (" ); - if ( idx > 0 ) - layername.truncate( idx ); - // create the layer - QgsVectorLayer *layer = new QgsVectorLayer( "dbname='" + connectionInfo + "' table=" + *it + ") sql=", layername, "spatialite" ); + QgsDataSourceURI uri( *it ); + QgsVectorLayer *layer = new QgsVectorLayer( uri.uri(), uri.table(), "spatialite" ); if ( layer->isValid() ) { // register this layer with the central layers registry diff --git a/src/app/qgsspatialitefilterproxymodel.cpp b/src/app/qgsspatialitefilterproxymodel.cpp deleted file mode 100644 index 80d0e96405b..00000000000 --- a/src/app/qgsspatialitefilterproxymodel.cpp +++ /dev/null @@ -1,52 +0,0 @@ -/*************************************************************************** - qgsspatialitefilterproxymodel.cpp - description - ------------------------- - begin : Dec 2008 - copyright : (C) 2008 by Sandro Furieri - email : a.furieri@lqt.it - ***************************************************************************/ - -/*************************************************************************** - * * - * This program is free software; you can redistribute it and/or modify * - * it under the terms of the GNU General Public License as published by * - * the Free Software Foundation; either version 2 of the License, or * - * (at your option) any later version. * - * * - ***************************************************************************/ - -#include "qgsspatialitefilterproxymodel.h" - -QgsSpatiaLiteFilterProxyModel::QgsSpatiaLiteFilterProxyModel( QObject * parent ): QSortFilterProxyModel( parent ) -{ - -} - -QgsSpatiaLiteFilterProxyModel::~QgsSpatiaLiteFilterProxyModel() -{ - -} - -bool QgsSpatiaLiteFilterProxyModel::filterAcceptsRow( int row, const QModelIndex & source_parent ) const -{ - //if parent is valid, we have a toplevel item that should be always shown - if ( !source_parent.isValid() ) - { - return true; - } - //else we have a row that describes a table and that - //should be tested using the given wildcard/regexp - return QSortFilterProxyModel::filterAcceptsRow( row, source_parent ); -} - -void QgsSpatiaLiteFilterProxyModel::_setFilterWildcard( const QString & pattern ) -{ - QSortFilterProxyModel::setFilterWildcard( pattern ); - emit layoutChanged(); -} - -void QgsSpatiaLiteFilterProxyModel::_setFilterRegExp( const QString & pattern ) -{ - QSortFilterProxyModel::setFilterRegExp( pattern ); - emit layoutChanged(); -} diff --git a/src/app/qgsspatialitefilterproxymodel.h b/src/app/qgsspatialitefilterproxymodel.h deleted file mode 100644 index b62bf3c09a4..00000000000 --- a/src/app/qgsspatialitefilterproxymodel.h +++ /dev/null @@ -1,39 +0,0 @@ -/*************************************************************************** - qgsspatialitefilterproxymodel.h - description - ----------------------- - begin : Dec 2008 - copyright : (C) 2008 by Sandro Furieri - email : a.furieri@lqt.it - ***************************************************************************/ - -/*************************************************************************** - * * - * This program is free software; you can redistribute it and/or modify * - * it under the terms of the GNU General Public License as published by * - * the Free Software Foundation; either version 2 of the License, or * - * (at your option) any later version. * - * * - ***************************************************************************/ - -#ifndef QGSSPATIALITEFILTERPROXYMODEL_H -#define QGSSPATIALITEFILTERPROXYMODEL_H - -#include - -/**A class that implements a custom filter and can be used - as a proxy for QgsSpatiaLiteTableModel*/ -class QgsSpatiaLiteFilterProxyModel: public QSortFilterProxyModel -{ - public: - QgsSpatiaLiteFilterProxyModel( QObject * parent = 0 ); - ~QgsSpatiaLiteFilterProxyModel(); - /**Calls QSortFilterProxyModel::setFilterWildcard and triggers update*/ - void _setFilterWildcard( const QString & pattern ); - /**Calls QSortFilterProxyModel::setFilterRegExp and triggers update*/ - void _setFilterRegExp( const QString & pattern ); - - protected: - virtual bool filterAcceptsRow( int row, const QModelIndex & source_parent ) const; -}; - -#endif diff --git a/src/app/qgsnewspatialitelayerdialog.cpp b/src/app/spatialite/qgsnewspatialitelayerdialog.cpp similarity index 100% rename from src/app/qgsnewspatialitelayerdialog.cpp rename to src/app/spatialite/qgsnewspatialitelayerdialog.cpp diff --git a/src/app/qgsnewspatialitelayerdialog.h b/src/app/spatialite/qgsnewspatialitelayerdialog.h similarity index 100% rename from src/app/qgsnewspatialitelayerdialog.h rename to src/app/spatialite/qgsnewspatialitelayerdialog.h diff --git a/src/app/qgsspatialitesourceselect.cpp b/src/app/spatialite/qgsspatialitesourceselect.cpp similarity index 86% rename from src/app/qgsspatialitesourceselect.cpp rename to src/app/spatialite/qgsspatialitesourceselect.cpp index d29dce1eb5b..7e8f1e105af 100644 --- a/src/app/qgsspatialitesourceselect.cpp +++ b/src/app/spatialite/qgsspatialitesourceselect.cpp @@ -22,6 +22,9 @@ email : a.furieri@lqt.it #include "qgslogger.h" #include "qgsapplication.h" #include "qgscontexthelp.h" +#include "qgsquerybuilder.h" +#include "qgsdatasourceuri.h" +#include "qgsvectorlayer.h" #include #include @@ -40,6 +43,9 @@ QgsSpatiaLiteSourceSelect::QgsSpatiaLiteSourceSelect( QgisApp * app, Qt::WFlags QDialog( app, fl ), qgisApp( app ) { setupUi( this ); + setWindowTitle( tr( "Add SpatiaLite Table(s)" ) ); + connectionsGroupBox->setTitle( tr( "Databases" ) ); + btnEdit->hide(); // hide the edit button mAddButton = new QPushButton( tr( "&Add" ) ); buttonBox->addButton( mAddButton, QDialogButtonBox::ActionRole ); @@ -55,6 +61,7 @@ QgsSpatiaLiteSourceSelect::QgsSpatiaLiteSourceSelect( QgisApp * app, Qt::WFlags mSearchColumnComboBox->addItem( tr( "Table" ) ); mSearchColumnComboBox->addItem( tr( "Type" ) ); mSearchColumnComboBox->addItem( tr( "Geometry column" ) ); + mSearchColumnComboBox->addItem( tr( "Sql" ) ); mProxyModel.setParent( this ); mProxyModel.setFilterKeyColumn( -1 ); @@ -64,11 +71,19 @@ QgsSpatiaLiteSourceSelect::QgsSpatiaLiteSourceSelect( QgisApp * app, Qt::WFlags mTablesTreeView->setModel( &mProxyModel ); mTablesTreeView->setSortingEnabled( true ); - mSearchGroupBox->hide(); - //for Qt < 4.3.2, passing -1 to include all model columns //in search does not seem to work mSearchColumnComboBox->setCurrentIndex( 1 ); + + //hide the search options by default + //they will be shown when the user ticks + //the search options group box + mSearchLabel->setVisible( false ); + mSearchColumnComboBox->setVisible( false ); + mSearchColumnsLabel->setVisible( false ); + mSearchModeComboBox->setVisible( false ); + mSearchModeLabel->setVisible( false ); + mSearchTableEdit->setVisible( false ); } // Slot for performing action when the Add button is clicked @@ -85,16 +100,19 @@ void QgsSpatiaLiteSourceSelect::on_cmbConnections_activated( int ) dbChanged(); } -void QgsSpatiaLiteSourceSelect::on_mSearchOptionsButton_clicked() +void QgsSpatiaLiteSourceSelect::on_btnBuildQuery_clicked() { - if ( mSearchGroupBox->isVisible() ) - { - mSearchGroupBox->hide(); - } - else - { - mSearchGroupBox->show(); - } + setSql( mTablesTreeView->currentIndex() ); +} + +void QgsSpatiaLiteSourceSelect::on_mTablesTreeView_clicked( const QModelIndex &index ) +{ + btnBuildQuery->setEnabled( index.parent().isValid() ); +} + +void QgsSpatiaLiteSourceSelect::on_mTablesTreeView_doubleClicked( const QModelIndex &index ) +{ + setSql( index ); } void QgsSpatiaLiteSourceSelect::on_mSearchTableEdit_textChanged( const QString & text ) @@ -127,6 +145,10 @@ void QgsSpatiaLiteSourceSelect::on_mSearchColumnComboBox_currentIndexChanged( co { mProxyModel.setFilterKeyColumn( 2 ); } + else if ( text == tr( "Sql" ) ) + { + mProxyModel.setFilterKeyColumn( 3 ); + } } void QgsSpatiaLiteSourceSelect::on_mSearchModeComboBox_currentIndexChanged( const QString & text ) @@ -327,6 +349,48 @@ void QgsSpatiaLiteSourceSelect::on_btnNew_clicked() populateConnectionList(); } +QString QgsSpatiaLiteSourceSelect::layerURI( const QModelIndex &index ) +{ + QString tableName = mTableModel.itemFromIndex( index.sibling( index.row(), 0 ) )->text(); + QString geomColumnName = mTableModel.itemFromIndex( index.sibling( index.row(), 2 ) )->text(); + QString sql = mTableModel.itemFromIndex( index.sibling( index.row(), 3 ) )->text(); + + if ( geomColumnName.contains( " AS " ) ) + { + int a = geomColumnName.indexOf( " AS " ); + QString typeName = geomColumnName.mid( a + 4 ); //only the type name + geomColumnName = geomColumnName.left( a ); //only the geom column name + QString geomFilter; + + if ( typeName == "POINT" ) + { + geomFilter = QString( "geometrytype(\"%1\") IN ('POINT','MULTIPOINT')" ).arg( geomColumnName ); + } + else if ( typeName == "LINESTRING" ) + { + geomFilter = QString( "geometrytype(\"%1\") IN ('LINESTRING','MULTILINESTRING')" ).arg( geomColumnName ); + } + else if ( typeName == "POLYGON" ) + { + geomFilter = QString( "geometrytype(\"%1\") IN ('POLYGON','MULTIPOLYGON')" ).arg( geomColumnName ); + } + + if ( !geomFilter.isEmpty() && !sql.contains( geomFilter ) ) + { + if ( !sql.isEmpty() ) + { + sql += " AND "; + } + + sql += geomFilter; + } + } + + QgsDataSourceURI uri( connectionInfo() ); + uri.setDataSource( "", tableName, geomColumnName, sql, "" ); + return uri.uri(); +} + // Slot for deleting an existing connection void QgsSpatiaLiteSourceSelect::on_btnDelete_clicked() { @@ -353,7 +417,7 @@ void QgsSpatiaLiteSourceSelect::addTables() { m_selectedTables.clear(); - typedef QMap < int, QVector < QString > >schemaInfo; + typedef QMap < int, bool >schemaInfo; QMap < QString, schemaInfo > dbInfo; QItemSelection selection = mTablesTreeView->selectionModel()->selection(); @@ -377,32 +441,10 @@ void QgsSpatiaLiteSourceSelect::addTables() QString currentSchemaName = currentItem->parent()->text(); int currentRow = currentItem->row(); - int currentColumn = currentItem->column(); - - if ( dbInfo[currentSchemaName][currentRow].size() == 0 ) + if ( !dbInfo[currentSchemaName].contains( currentRow ) ) { - dbInfo[currentSchemaName][currentRow].resize( 5 ); - } - - dbInfo[currentSchemaName][currentRow][currentColumn] = currentItem->text(); - } - - //now traverse all the schemas and table infos - QString tableName, geomColumnName; - QString query; - - QMap < QString, schemaInfo >::const_iterator schema_it = dbInfo.constBegin(); - for ( ; schema_it != dbInfo.constEnd(); ++schema_it ) - { - schemaInfo scheme = schema_it.value(); - schemaInfo::const_iterator entry_it = scheme.constBegin(); - for ( ; entry_it != scheme.constEnd(); ++entry_it ) - { - tableName = entry_it->at( 0 ); - geomColumnName = entry_it->at( 2 ); - - query = "\"" + tableName + "\" (" + geomColumnName; - m_selectedTables.push_back( query ); + dbInfo[currentSchemaName][currentRow] = true; + m_selectedTables << layerURI( mProxyModel.mapToSource( *selected_it ) ); } } @@ -475,7 +517,31 @@ QStringList QgsSpatiaLiteSourceSelect::selectedTables() QString QgsSpatiaLiteSourceSelect::connectionInfo() { - return mSqlitePath; + return QString( "dbname='%1'" ).arg( QString( mSqlitePath ).replace( "'", "\\'" ) ); +} + +void QgsSpatiaLiteSourceSelect::setSql( const QModelIndex &index ) +{ + QModelIndex idx = mProxyModel.mapToSource( index ); + QString tableName = mTableModel.itemFromIndex( idx.sibling( idx.row(), 0 ) )->text(); + + QgsVectorLayer *vlayer = new QgsVectorLayer( layerURI( idx ), tableName, "spatialite" ); + + if ( !vlayer->isValid() ) + { + delete vlayer; + return; + } + + // create a query builder object + QgsQueryBuilder *gb = new QgsQueryBuilder( vlayer, this ); + if ( gb->exec() ) + { + mTableModel.setSql( mProxyModel.mapToSource( index ), gb->sql() ); + } + + delete gb; + delete vlayer; } bool QgsSpatiaLiteSourceSelect::getTableInfo( sqlite3 * handle ) @@ -515,7 +581,7 @@ bool QgsSpatiaLiteSourceSelect::getTableInfo( sqlite3 * handle ) if ( isDeclaredHidden( handle, tableName, column ) ) continue; - mTableModel.addTableEntry( type, tableName, column ); + mTableModel.addTableEntry( type, tableName, column, "" ); } ok = true; } @@ -542,7 +608,7 @@ bool QgsSpatiaLiteSourceSelect::getTableInfo( sqlite3 * handle ) if ( isDeclaredHidden( handle, tableName, column ) ) continue; - mTableModel.addTableEntry( type, tableName, column ); + mTableModel.addTableEntry( type, tableName, column, "" ); } ok = true; } @@ -569,7 +635,7 @@ bool QgsSpatiaLiteSourceSelect::getTableInfo( sqlite3 * handle ) if ( isDeclaredHidden( handle, tableName, column ) ) continue; - mTableModel.addTableEntry( type, tableName, column ); + mTableModel.addTableEntry( type, tableName, column, "" ); } ok = true; } diff --git a/src/app/qgsspatialitesourceselect.h b/src/app/spatialite/qgsspatialitesourceselect.h similarity index 92% rename from src/app/qgsspatialitesourceselect.h rename to src/app/spatialite/qgsspatialitesourceselect.h index e73b3b02779..6ea70bb81b2 100644 --- a/src/app/qgsspatialitesourceselect.h +++ b/src/app/spatialite/qgsspatialitesourceselect.h @@ -16,10 +16,9 @@ ***************************************************************************/ #ifndef QGSSPATIALITESOURCESELECT_H #define QGSSPATIALITESOURCESELECT_H -#include "ui_qgsspatialitesourceselectbase.h" - +#include "ui_qgsdbsourceselectbase.h" #include "qgisgui.h" -#include "qgsspatialitefilterproxymodel.h" +#include "qgsdbfilterproxymodel.h" #include "qgsspatialitetablemodel.h" #include "qgscontexthelp.h" @@ -51,7 +50,7 @@ class QPushButton; * for SpatiaLite/SQLite databases. The user can then connect and add * tables from the database to the map canvas. */ -class QgsSpatiaLiteSourceSelect: public QDialog, private Ui::QgsSpatiaLiteSourceSelectBase +class QgsSpatiaLiteSourceSelect: public QDialog, private Ui::QgsDbSourceSelectBase { Q_OBJECT @@ -80,14 +79,17 @@ class QgsSpatiaLiteSourceSelect: public QDialog, private Ui::QgsSpatiaLiteSource void addClicked(); //! Opens the create connection dialog to build a new connection void on_btnNew_clicked(); + void on_btnBuildQuery_clicked(); //! Deletes the selected connection void on_btnDelete_clicked(); - void on_mSearchOptionsButton_clicked(); void on_mSearchTableEdit_textChanged( const QString & text ); void on_mSearchColumnComboBox_currentIndexChanged( const QString & text ); void on_mSearchModeComboBox_currentIndexChanged( const QString & text ); + void setSql( const QModelIndex& index ); void on_cmbConnections_activated( int ); void setLayerType( QString table, QString column, QString type ); + void on_mTablesTreeView_clicked( const QModelIndex &index ); + void on_mTablesTreeView_doubleClicked( const QModelIndex &index ); //!Sets a new regular expression to the model void setSearchExpression( const QString & regexp ); @@ -146,8 +148,9 @@ class QgsSpatiaLiteSourceSelect: public QDialog, private Ui::QgsSpatiaLiteSource QgisApp *qgisApp; //! Model that acts as datasource for mTableTreeWidget QgsSpatiaLiteTableModel mTableModel; - QgsSpatiaLiteFilterProxyModel mProxyModel; + QgsDbFilterProxyModel mProxyModel; + QString layerURI( const QModelIndex &index ); QPushButton *mAddButton; }; diff --git a/src/app/qgsspatialitesridsdialog.cpp b/src/app/spatialite/qgsspatialitesridsdialog.cpp similarity index 100% rename from src/app/qgsspatialitesridsdialog.cpp rename to src/app/spatialite/qgsspatialitesridsdialog.cpp diff --git a/src/app/qgsspatialitesridsdialog.h b/src/app/spatialite/qgsspatialitesridsdialog.h similarity index 100% rename from src/app/qgsspatialitesridsdialog.h rename to src/app/spatialite/qgsspatialitesridsdialog.h diff --git a/src/app/qgsspatialitetablemodel.cpp b/src/app/spatialite/qgsspatialitetablemodel.cpp similarity index 89% rename from src/app/qgsspatialitetablemodel.cpp rename to src/app/spatialite/qgsspatialitetablemodel.cpp index f9cd8dc844c..3dbff025d50 100644 --- a/src/app/qgsspatialitetablemodel.cpp +++ b/src/app/spatialite/qgsspatialitetablemodel.cpp @@ -25,6 +25,7 @@ QgsSpatiaLiteTableModel::QgsSpatiaLiteTableModel(): QStandardItemModel(), mTable headerLabels << tr( "Table" ); headerLabels << tr( "Type" ); headerLabels << tr( "Geometry column" ); + headerLabels << tr( "Sql" ); setHorizontalHeaderLabels( headerLabels ); } @@ -33,7 +34,7 @@ QgsSpatiaLiteTableModel::~QgsSpatiaLiteTableModel() } -void QgsSpatiaLiteTableModel::addTableEntry( QString type, QString tableName, QString geometryColName ) +void QgsSpatiaLiteTableModel::addTableEntry( QString type, QString tableName, QString geometryColName, QString sql ) { //is there already a root item ? QStandardItem *dbItem; @@ -64,16 +65,42 @@ void QgsSpatiaLiteTableModel::addTableEntry( QString type, QString tableName, QS tableItem->setFlags( Qt::ItemIsEnabled | Qt::ItemIsSelectable ); QStandardItem *geomItem = new QStandardItem( geometryColName ); geomItem->setFlags( Qt::ItemIsEnabled | Qt::ItemIsSelectable ); + QStandardItem* sqlItem = new QStandardItem( sql ); + sqlItem->setFlags( Qt::ItemIsEnabled | Qt::ItemIsSelectable | Qt::ItemIsEditable ); childItemList.push_back( tableItem ); childItemList.push_back( typeItem ); childItemList.push_back( geomItem ); + childItemList.push_back( sqlItem ); dbItem->appendRow( childItemList ); ++mTableCount; } +void QgsSpatiaLiteTableModel::setSql( const QModelIndex &index, const QString &sql ) +{ + if ( !index.isValid() || !index.parent().isValid() ) + { + return; + } + + //find out table name + QModelIndex tableSibling = index.sibling( index.row(), 0 ); + QModelIndex geomSibling = index.sibling( index.row(), 2 ); + + if ( !tableSibling.isValid() || !geomSibling.isValid() ) + { + return; + } + + QModelIndex sqlIndex = index.sibling( index.row(), 3 ); + if ( sqlIndex.isValid() ) + { + itemFromIndex( sqlIndex )->setText( sql ); + } +} + void QgsSpatiaLiteTableModel::setGeometryTypesForTable( const QString & table, const QString & attribute, const QString & type ) { bool typeIsEmpty = type.isEmpty(); //true means the table has no valid geometry entry and the item for this table should be removed @@ -133,7 +160,7 @@ void QgsSpatiaLiteTableModel::setGeometryTypesForTable( const QString & table, c for ( int j = 1; j < typeList.size(); ++j ) { //todo: add correct type - addTableEntry( typeList.at( j ), table, geomColText + " AS " + typeList.at( j ) ); + addTableEntry( typeList.at( j ), table, geomColText + " AS " + typeList.at( j ), "" ); } } } diff --git a/src/app/qgsspatialitetablemodel.h b/src/app/spatialite/qgsspatialitetablemodel.h similarity index 93% rename from src/app/qgsspatialitetablemodel.h rename to src/app/spatialite/qgsspatialitetablemodel.h index d109fa17fe3..1afdd1934e0 100644 --- a/src/app/qgsspatialitetablemodel.h +++ b/src/app/spatialite/qgsspatialitetablemodel.h @@ -29,7 +29,9 @@ class QgsSpatiaLiteTableModel: public QStandardItemModel QgsSpatiaLiteTableModel(); ~QgsSpatiaLiteTableModel(); /**Adds entry for one database table to the model*/ - void addTableEntry( QString type, QString tableName, QString geometryColName ); + void addTableEntry( QString type, QString tableName, QString geometryColName, QString sql ); + /**Sets an sql statement that belongs to a cell specified by a model index*/ + void setSql( const QModelIndex& index, const QString& sql ); /**Sets one or more geometry types to a row. In case of several types, additional rows are inserted. This is for tables where the type is dectected later by thread*/ void setGeometryTypesForTable( const QString & table, const QString & attribute, const QString & type ); diff --git a/src/ui/qgspgsourceselectbase.ui b/src/ui/qgsdbsourceselectbase.ui similarity index 84% rename from src/ui/qgspgsourceselectbase.ui rename to src/ui/qgsdbsourceselectbase.ui index bd10b89f3b4..64d28853189 100644 --- a/src/ui/qgspgsourceselectbase.ui +++ b/src/ui/qgsdbsourceselectbase.ui @@ -1,12 +1,12 @@ - QgsPgSourceSelectBase - + QgsDbSourceSelectBase + 0 0 - 362 + 406 476 @@ -26,48 +26,46 @@ - + - PostgreSQL Connections + Connections - - - 11 - - - 6 - - - - - Delete - - - - - - - Edit - - - - - - - New - - - - - - - Connect - - - - + + + + + + + + Connect + + + + + + + New + + + + + + + Edit + + + + + + + Delete + + + + + @@ -201,7 +199,7 @@ buttonBox rejected() - QgsPgSourceSelectBase + QgsDbSourceSelectBase reject() diff --git a/src/ui/qgsspatialitesourceselectbase.ui b/src/ui/qgsspatialitesourceselectbase.ui deleted file mode 100644 index 50e8b96bf22..00000000000 --- a/src/ui/qgsspatialitesourceselectbase.ui +++ /dev/null @@ -1,195 +0,0 @@ - - - QgsSpatiaLiteSourceSelectBase - - - - 0 - 0 - 419 - 452 - - - - Add SpatiaLite Table(s) - - - - - - - - true - - - true - - - - 9 - - - 6 - - - - - Qt::Horizontal - - - - 271 - 20 - - - - - - - - QAbstractItemView::MultiSelection - - - - - - - SpatiaLite Databases - - - - 11 - - - 6 - - - - - Delete - - - - - - - New - - - - - - - Connect - - - - - - - - - - - - - - - - - 9 - - - 6 - - - - - Search - - - mSearchTableEdit - - - - - - - Search mode - - - mSearchModeComboBox - - - - - - - - - - Search in columns - - - mSearchColumnComboBox - - - - - - - - - - - - - - - - Search options... - - - - - - - QDialogButtonBox::Close|QDialogButtonBox::Help - - - - - - - - cmbConnections - btnConnect - btnNew - btnDelete - mTablesTreeView - mSearchOptionsButton - mSearchTableEdit - mSearchColumnComboBox - mSearchModeComboBox - buttonBox - - - - - buttonBox - rejected() - QgsSpatiaLiteSourceSelectBase - reject() - - - 630 - 663 - - - 666 - 562 - - - - -