mirror of
https://github.com/qgis/QGIS.git
synced 2025-04-15 00:04:00 -04:00
Merged the source select UIs for both PG and SL to allow to use a subset query loading a SL layer
git-svn-id: http://svn.osgeo.org/qgis/trunk@15214 c8812cc2-4d05-0410-92ff-de0c093fc19c
This commit is contained in:
parent
6b68070ca7
commit
05c7708240
@ -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)
|
||||
|
||||
|
@ -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
|
||||
|
||||
|
@ -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 <spatialite.h>
|
||||
}
|
||||
#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
|
||||
|
@ -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();
|
||||
}
|
@ -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 <QSortFilterProxyModel>
|
||||
|
||||
/**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
|
@ -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 <QInputDialog>
|
||||
#include <QMessageBox>
|
||||
@ -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;
|
||||
}
|
@ -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;
|
||||
};
|
||||
|
@ -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 ), "" );
|
||||
}
|
||||
}
|
||||
}
|
@ -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 );
|
@ -1,12 +1,12 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<ui version="4.0">
|
||||
<class>QgsPgSourceSelectBase</class>
|
||||
<widget class="QDialog" name="QgsPgSourceSelectBase">
|
||||
<class>QgsDbSourceSelectBase</class>
|
||||
<widget class="QDialog" name="QgsDbSourceSelectBase">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>362</width>
|
||||
<width>406</width>
|
||||
<height>476</height>
|
||||
</rect>
|
||||
</property>
|
||||
@ -26,48 +26,46 @@
|
||||
</property>
|
||||
<layout class="QVBoxLayout" name="verticalLayout">
|
||||
<item>
|
||||
<widget class="QGroupBox" name="groupBox">
|
||||
<widget class="QGroupBox" name="connectionsGroupBox">
|
||||
<property name="title">
|
||||
<string>PostgreSQL Connections</string>
|
||||
<string>Connections</string>
|
||||
</property>
|
||||
<layout class="QGridLayout">
|
||||
<property name="margin">
|
||||
<number>11</number>
|
||||
</property>
|
||||
<property name="spacing">
|
||||
<number>6</number>
|
||||
</property>
|
||||
<item row="2" column="3">
|
||||
<widget class="QPushButton" name="btnDelete">
|
||||
<property name="text">
|
||||
<string>Delete</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="2" column="2">
|
||||
<widget class="QPushButton" name="btnEdit">
|
||||
<property name="text">
|
||||
<string>Edit</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="2" column="1">
|
||||
<widget class="QPushButton" name="btnNew">
|
||||
<property name="text">
|
||||
<string>New</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="2" column="0">
|
||||
<widget class="QPushButton" name="btnConnect">
|
||||
<property name="text">
|
||||
<string>Connect</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="0" column="0" colspan="4">
|
||||
<layout class="QGridLayout" name="gridLayout">
|
||||
<item row="0" column="0">
|
||||
<widget class="QComboBox" name="cmbConnections"/>
|
||||
</item>
|
||||
<item row="1" column="0">
|
||||
<layout class="QHBoxLayout" name="horizontalLayout">
|
||||
<item>
|
||||
<widget class="QPushButton" name="btnConnect">
|
||||
<property name="text">
|
||||
<string>Connect</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QPushButton" name="btnNew">
|
||||
<property name="text">
|
||||
<string>New</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QPushButton" name="btnEdit">
|
||||
<property name="text">
|
||||
<string>Edit</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QPushButton" name="btnDelete">
|
||||
<property name="text">
|
||||
<string>Delete</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
</item>
|
||||
@ -201,7 +199,7 @@
|
||||
<connection>
|
||||
<sender>buttonBox</sender>
|
||||
<signal>rejected()</signal>
|
||||
<receiver>QgsPgSourceSelectBase</receiver>
|
||||
<receiver>QgsDbSourceSelectBase</receiver>
|
||||
<slot>reject()</slot>
|
||||
<hints>
|
||||
<hint type="sourcelabel">
|
@ -1,195 +0,0 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<ui version="4.0">
|
||||
<class>QgsSpatiaLiteSourceSelectBase</class>
|
||||
<widget class="QDialog" name="QgsSpatiaLiteSourceSelectBase">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>419</width>
|
||||
<height>452</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="windowTitle">
|
||||
<string>Add SpatiaLite Table(s)</string>
|
||||
</property>
|
||||
<property name="windowIcon">
|
||||
<iconset>
|
||||
<normaloff/>
|
||||
</iconset>
|
||||
</property>
|
||||
<property name="sizeGripEnabled">
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
<property name="modal">
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
<layout class="QGridLayout">
|
||||
<property name="margin">
|
||||
<number>9</number>
|
||||
</property>
|
||||
<property name="spacing">
|
||||
<number>6</number>
|
||||
</property>
|
||||
<item row="2" column="0">
|
||||
<spacer>
|
||||
<property name="orientation">
|
||||
<enum>Qt::Horizontal</enum>
|
||||
</property>
|
||||
<property name="sizeHint" stdset="0">
|
||||
<size>
|
||||
<width>271</width>
|
||||
<height>20</height>
|
||||
</size>
|
||||
</property>
|
||||
</spacer>
|
||||
</item>
|
||||
<item row="1" column="0" colspan="2">
|
||||
<widget class="QTreeView" name="mTablesTreeView">
|
||||
<property name="selectionMode">
|
||||
<enum>QAbstractItemView::MultiSelection</enum>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="0" column="0" colspan="2">
|
||||
<widget class="QGroupBox" name="groupBox">
|
||||
<property name="title">
|
||||
<string>SpatiaLite Databases</string>
|
||||
</property>
|
||||
<layout class="QGridLayout">
|
||||
<property name="margin">
|
||||
<number>11</number>
|
||||
</property>
|
||||
<property name="spacing">
|
||||
<number>6</number>
|
||||
</property>
|
||||
<item row="1" column="2">
|
||||
<widget class="QPushButton" name="btnDelete">
|
||||
<property name="text">
|
||||
<string>Delete</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="1" column="1">
|
||||
<widget class="QPushButton" name="btnNew">
|
||||
<property name="text">
|
||||
<string>New</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="1" column="0">
|
||||
<widget class="QPushButton" name="btnConnect">
|
||||
<property name="text">
|
||||
<string>Connect</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="0" column="0" colspan="3">
|
||||
<widget class="QComboBox" name="cmbConnections"/>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="3" column="0" colspan="2">
|
||||
<widget class="QGroupBox" name="mSearchGroupBox">
|
||||
<property name="title">
|
||||
<string/>
|
||||
</property>
|
||||
<layout class="QGridLayout">
|
||||
<property name="margin">
|
||||
<number>9</number>
|
||||
</property>
|
||||
<property name="spacing">
|
||||
<number>6</number>
|
||||
</property>
|
||||
<item row="0" column="0">
|
||||
<widget class="QLabel" name="mSearchLabel">
|
||||
<property name="text">
|
||||
<string>Search</string>
|
||||
</property>
|
||||
<property name="buddy">
|
||||
<cstring>mSearchTableEdit</cstring>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="2" column="0" colspan="2">
|
||||
<widget class="QLabel" name="mSearchModeLabel">
|
||||
<property name="text">
|
||||
<string>Search mode</string>
|
||||
</property>
|
||||
<property name="buddy">
|
||||
<cstring>mSearchModeComboBox</cstring>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="2" column="2">
|
||||
<widget class="QComboBox" name="mSearchModeComboBox"/>
|
||||
</item>
|
||||
<item row="1" column="0" colspan="2">
|
||||
<widget class="QLabel" name="mSearchColumnsLabel">
|
||||
<property name="text">
|
||||
<string>Search in columns</string>
|
||||
</property>
|
||||
<property name="buddy">
|
||||
<cstring>mSearchColumnComboBox</cstring>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="1" column="2">
|
||||
<widget class="QComboBox" name="mSearchColumnComboBox"/>
|
||||
</item>
|
||||
<item row="0" column="1" colspan="2">
|
||||
<widget class="QLineEdit" name="mSearchTableEdit"/>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="2" column="1">
|
||||
<widget class="QPushButton" name="mSearchOptionsButton">
|
||||
<property name="text">
|
||||
<string>Search options...</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="4" column="0" colspan="2">
|
||||
<widget class="QDialogButtonBox" name="buttonBox">
|
||||
<property name="standardButtons">
|
||||
<set>QDialogButtonBox::Close|QDialogButtonBox::Help</set>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
<layoutdefault spacing="6" margin="11"/>
|
||||
<tabstops>
|
||||
<tabstop>cmbConnections</tabstop>
|
||||
<tabstop>btnConnect</tabstop>
|
||||
<tabstop>btnNew</tabstop>
|
||||
<tabstop>btnDelete</tabstop>
|
||||
<tabstop>mTablesTreeView</tabstop>
|
||||
<tabstop>mSearchOptionsButton</tabstop>
|
||||
<tabstop>mSearchTableEdit</tabstop>
|
||||
<tabstop>mSearchColumnComboBox</tabstop>
|
||||
<tabstop>mSearchModeComboBox</tabstop>
|
||||
<tabstop>buttonBox</tabstop>
|
||||
</tabstops>
|
||||
<resources/>
|
||||
<connections>
|
||||
<connection>
|
||||
<sender>buttonBox</sender>
|
||||
<signal>rejected()</signal>
|
||||
<receiver>QgsSpatiaLiteSourceSelectBase</receiver>
|
||||
<slot>reject()</slot>
|
||||
<hints>
|
||||
<hint type="sourcelabel">
|
||||
<x>630</x>
|
||||
<y>663</y>
|
||||
</hint>
|
||||
<hint type="destinationlabel">
|
||||
<x>666</x>
|
||||
<y>562</y>
|
||||
</hint>
|
||||
</hints>
|
||||
</connection>
|
||||
</connections>
|
||||
</ui>
|
Loading…
x
Reference in New Issue
Block a user