📄 qgsspit.cpp
字号:
PQclear(res); continue; } else { PQclear( res ); } // begin session query = "BEGIN"; res = PQexec( pd, query.toUtf8() ); if ( PQresultStatus( res ) != PGRES_COMMAND_OK ) { QString err = PQresultErrorMessage( res ); QMessageBox::warning( &pro, tr("Import Shapefiles"), error + "\n" + tr("<p>Error while executing the SQL:</p><p>") + query + tr("</p><p>The database said:") + err + "</p>" ); pro.setValue( pro.value() + tblShapefiles->item( i, ColFEATURECOUNT )->text().toInt() ); PQclear(res); continue; } else { PQclear( res ); } query = "SET SEARCH_PATH TO "; if ( tblShapefiles->item( i, ColDBSCHEMA )->text() != "public" ) query += QgsPgUtil::quotedValue( tblShapefiles->item( i, ColDBSCHEMA )->text() ) + ","; query += QgsPgUtil::quotedValue( "public" ); res = PQexec( pd, query.toUtf8() ); if ( PQresultStatus( res ) != PGRES_COMMAND_OK ) { QString err = PQresultErrorMessage( res ); QMessageBox::warning( &pro, tr("Import Shapefiles"), error + "\n" + tr("<p>Error while executing the SQL:</p><p>") + query + tr("</p><p>The database said:") + err + "</p>" ); pro.setValue( pro.value() + tblShapefiles->item( i, ColFEATURECOUNT )->text().toInt() ); PQclear(res); continue; } else { PQclear( res ); } if ( rel_exists1 || rel_exists2 ) { QMessageBox::StandardButton del_confirm = QMessageBox::warning( this, tr("Import Shapefiles - Relation Exists"), tr("The Shapefile:" ) + "\n" + tblShapefiles->item( i, 0 )->text() + "\n" + tr("will use [") + tblShapefiles->item( i, ColDBRELATIONNAME )->text() + tr("] relation for its data,") + "\n" + tr("which already exists and possibly contains data.") + "\n" + tr("To avoid data loss change the \"DB Relation Name\"") + "\n" + tr("for this Shapefile in the main dialog file list.") + "\n\n" + tr("Do you want to overwrite the [") + tblShapefiles->item( i, ColDBRELATIONNAME )->text() + tr("] relation?"), QMessageBox::Ok | QMessageBox::Cancel ); if ( del_confirm == QMessageBox::Ok ) { if ( rel_exists2 ) { query = QString("DROP TABLE %1") .arg( QgsPgUtil::quotedIdentifier( tblShapefiles->item( i, ColDBRELATIONNAME )->text() ) ); res = PQexec( pd, query.toUtf8() ); if ( PQresultStatus( res ) != PGRES_COMMAND_OK ) { QString err = PQresultErrorMessage( res ); QMessageBox::warning( &pro, tr("Import Shapefiles"), error + "\n" + tr("<p>Error while executing the SQL:</p><p>") + query + tr("</p><p>The database said:") + err + "</p>" ); pro.setValue( pro.value() + tblShapefiles->item( i, ColFEATURECOUNT )->text().toInt() ); PQclear(res); continue; } else { PQclear( res ); } } if ( rel_exists1 ) { query = QString("SELECT f_geometry_column FROM geometry_columns WHERE f_table_schema=%1 AND f_table_name=%2") .arg( QgsPgUtil::quotedValue( tblShapefiles->item( i, ColDBSCHEMA )->text()) ) .arg( QgsPgUtil::quotedValue( tblShapefiles->item( i, ColDBRELATIONNAME )->text()) ); QStringList columns; res = PQexec( pd, query.toUtf8() ); if( PQresultStatus( res ) != PGRES_TUPLES_OK ) { for(int i=0; i<PQntuples(res); i++) columns.append( PQgetvalue(res, i, 0) ); } PQclear(res); for(int i=0; i<columns.size(); i++) { query = QString("SELECT DropGeometryColumn(%1,%2,%3)") .arg( QgsPgUtil::quotedValue( tblShapefiles->item( i, ColDBSCHEMA )->text() ) ) .arg( QgsPgUtil::quotedValue( tblShapefiles->item( i, ColDBRELATIONNAME )->text() ) ) .arg( QgsPgUtil::quotedValue( columns[i] ) ); res = PQexec( pd, query.toUtf8() ); if ( PQresultStatus( res ) != PGRES_COMMAND_OK ) { QString err = PQresultErrorMessage( res ); QMessageBox::warning( &pro, tr("Import Shapefiles"), error + "\n" + tr("<p>Error while executing the SQL:</p><p>") + query + tr("</p><p>The database said:") + err + "</p>" ); pro.setValue( pro.value() + tblShapefiles->item( i, ColFEATURECOUNT )->text().toInt() ); } PQclear(res); } } } else { query = "ROLLBACK"; res = PQexec( pd, query.toUtf8() ); if ( PQresultStatus( res ) != PGRES_COMMAND_OK ) { QString err = PQresultErrorMessage( res ); QMessageBox::warning( &pro, tr("Import Shapefiles"), error + "\n" + tr("<p>Error while executing the SQL:</p><p>") + query + tr("</p><p>The database said:") + err + "</p>" ); } PQclear(res); pro.setValue( pro.value() + tblShapefiles->item( i, 2 )->text().toInt() ); continue; } } // importing file here int temp_progress = pro.value(); canceled = false; QString dbname = settings.readEntry( gl_key + connName + "/database" ); QString schema = tblShapefiles->item( i, ColDBSCHEMA )->text(); QString srid = QString( "%1" ).arg( spinSrid->value() ); QString errorText; bool layerInserted = fileList[i]->insertLayer(dbname, schema, txtPrimaryKeyName->text(), txtGeomName->text(), srid, pd, pro, canceled, errorText ); if ( layerInserted && !canceled ) { // if file has been imported successfully query = "COMMIT"; res = PQexec( pd, query.toUtf8() ); if ( PQresultStatus( res ) != PGRES_COMMAND_OK ) { QString err = PQresultErrorMessage( res ); QMessageBox::warning( &pro, tr("Import Shapefiles"), error + "\n" + tr("<p>Error while executing the SQL:</p><p>") + query + tr("</p><p>The database said:") + err + "</p>" ); PQclear(res); continue; } PQclear( res ); // remove file for ( int j = 0; j < tblShapefiles->rowCount(); j++ ) { if ( tblShapefiles->item( j, ColFILENAME )->text() == QString( fileList[ i ] ->getName() ) ) { tblShapefiles->selectRow( j ); removeFile(); i--; break; } } successes++; } else if ( !canceled ) { // if problem importing file occured pro.setValue( temp_progress + tblShapefiles->item( i, ColFEATURECOUNT )->text().toInt() ); QString errTxt = error + "\n" + errorText; QMessageBox::warning( this, tr("Import Shapefiles"), errTxt ); query = "ROLLBACK"; res = PQexec( pd, query.toUtf8() ); if ( PQresultStatus( res ) != PGRES_COMMAND_OK ) { QString err = PQresultErrorMessage( res ); QMessageBox::warning( &pro, tr("Import Shapefiles"), error + "\n" + tr("<p>Error while executing the SQL:</p><p>") + query + tr("</p><p>The database said:") + err + "</p>" ); } PQclear( res ); } else { // if import was actually canceled break; } } PQfinish( pd ); if(successes==count) accept(); else QMessageBox::information( &pro, tr("Import Shapefiles"), QString( tr("%1 of %2 shapefiles could not be imported.") ).arg(count-successes).arg(count) ); }}void QgsSpit::editShapefile(int row, int col, int button, const QPoint& mousePos){ // FIXME Is this necessary any more? /* if (ColFEATURECLASS == col || ColDBRELATIONNAME == col) { tblShapefiles->editCell(row, col, FALSE); } */}QWidget *ShapefileTableDelegate::createEditor(QWidget *parent, const QStyleOptionViewItem &, const QModelIndex & index) const{ switch(index.column()) { case 4: { QComboBox* editor = new QComboBox(parent); editor->setSizeAdjustPolicy(QComboBox::AdjustToContents); editor->installEventFilter(const_cast<ShapefileTableDelegate*>(this)); return editor; break; } case 1: case 3: { QLineEdit* editor = new QLineEdit(parent); editor->installEventFilter(const_cast<ShapefileTableDelegate*>(this)); return editor; break; } } return NULL;}void ShapefileTableDelegate::setEditorData(QWidget *editor, const QModelIndex &index) const{ switch(index.column()) { case 4: { // Create a combobox and populate with the list of schemas QComboBox *comboBox = static_cast<QComboBox*>(editor); comboBox->insertItems(0, mSchemaList); // Get the text from the table and use to set the selected text // in the combo box. QString text = index.model()->data(index, Qt::DisplayRole).toString(); comboBox->setCurrentIndex(mSchemaList.indexOf(text)); break; } case 1: case 3: { QString text = index.model()->data(index, Qt::DisplayRole).toString(); QLineEdit *lineEdit = static_cast<QLineEdit*>(editor); lineEdit->setText(text); break; } }}void ShapefileTableDelegate::setModelData(QWidget *editor, QAbstractItemModel *model, const QModelIndex &index) const{ switch(index.column()) { case 4: { QComboBox *comboBox = static_cast<QComboBox*>(editor); QString text = comboBox->currentText(); model->setData(index, text); break; } case 1: case 3: { QLineEdit *lineEdit = static_cast<QLineEdit*>(editor); QString text = lineEdit->text(); model->setData(index, text); break; } }}void ShapefileTableDelegate::updateEditorGeometry(QWidget *editor, const QStyleOptionViewItem &option, const QModelIndex &/* index */) const{ editor->setGeometry(option.rect);}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -