void SaSourceSelect::setSql( const QModelIndex &index ) { if ( !index.parent().isValid() ) { SaDebugMsg( "schema item found" ); return; } QgsVectorLayer *vlayer = new QgsVectorLayer( layerURI( mProxyModel.mapToSource( index ) ), "querybuilder", "sqlanywhere" ); if ( !vlayer->isValid() ) { delete vlayer; return; } // create a query builder object SaQueryBuilder *qb = new SaQueryBuilder( vlayer, this ); if ( qb->exec() ) { mTableModel.setSql( mProxyModel.mapToSource( index ), qb->sql() ); } delete qb; delete vlayer; }
// Slot for performing action when the Add button is clicked void SaSourceSelect::addTables() { mSelectedTables.clear(); QItemSelection selection = mTablesTreeView->selectionModel()->selection(); QModelIndexList selectedIndices = selection.indexes(); QModelIndexList::const_iterator selected_it = selectedIndices.constBegin(); for ( ; selected_it != selectedIndices.constEnd(); ++selected_it ) { if ( !selected_it->parent().isValid() || selected_it->column() > 0 ) { //top level items only contain the schema names continue; } mSelectedTables << layerURI( mProxyModel.mapToSource( *selected_it ) ); } if ( mSelectedTables.empty() ) { QMessageBox::information( this, tr( "Select Table" ), tr( "You must select a table in order to add a layer." ) ); } else { accept(); } }
void QgsSpatiaLiteSourceSelect::addTables() { m_selectedTables.clear(); typedef QMap < int, bool >schemaInfo; QMap < QString, schemaInfo > dbInfo; QItemSelection selection = mTablesTreeView->selectionModel()->selection(); QModelIndexList selectedIndices = selection.indexes(); QStandardItem *currentItem = 0; QModelIndexList::const_iterator selected_it = selectedIndices.constBegin(); for ( ; selected_it != selectedIndices.constEnd(); ++selected_it ) { if ( !selected_it->parent().isValid() ) { //top level items only contain the schema names continue; } currentItem = mTableModel.itemFromIndex( mProxyModel.mapToSource( *selected_it ) ); if ( !currentItem ) { continue; } QString currentSchemaName = currentItem->parent()->text(); int currentRow = currentItem->row(); if ( !dbInfo[currentSchemaName].contains( currentRow ) ) { dbInfo[currentSchemaName][currentRow] = true; m_selectedTables << layerURI( mProxyModel.mapToSource( *selected_it ) ); } } if ( m_selectedTables.empty() ) { QMessageBox::information( this, tr( "Select Table" ), tr( "You must select a table in order to add a Layer." ) ); } else { accept(); } }
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; }