Skip to content

Commit

Permalink
[Geometry checker] Don't allow setting output layer equal to input layer
Browse files Browse the repository at this point in the history
  • Loading branch information
manisandro committed Jan 19, 2016
1 parent b2a1273 commit 4827cbc
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 9 deletions.
19 changes: 13 additions & 6 deletions src/plugins/geometry_checker/ui/qgsgeometrycheckersetuptab.cpp
Expand Up @@ -64,7 +64,7 @@ QgsGeometryCheckerSetupTab::QgsGeometryCheckerSetupTab( QgisInterface* iface , Q


updateLayers(); updateLayers();


Q_FOREACH ( const QgsGeometryCheckFactory* factory, QgsGeometryCheckFactoryRegistry::getCheckFactories() ) Q_FOREACH( const QgsGeometryCheckFactory* factory, QgsGeometryCheckFactoryRegistry::getCheckFactories() )
{ {
factory->restorePrevious( ui ); factory->restorePrevious( ui );
} }
Expand All @@ -83,7 +83,7 @@ void QgsGeometryCheckerSetupTab::updateLayers()
// Collect layers // Collect layers
QgsMapLayer* currentLayer = mIface->mapCanvas()->currentLayer(); QgsMapLayer* currentLayer = mIface->mapCanvas()->currentLayer();
int currIdx = -1; int currIdx = -1;
Q_FOREACH ( QgsMapLayer* layer, QgsMapLayerRegistry::instance()->mapLayers() ) Q_FOREACH( QgsMapLayer* layer, QgsMapLayerRegistry::instance()->mapLayers() )
{ {
if ( qobject_cast<QgsVectorLayer*>( layer ) ) if ( qobject_cast<QgsVectorLayer*>( layer ) )
{ {
Expand Down Expand Up @@ -117,7 +117,7 @@ void QgsGeometryCheckerSetupTab::validateInput()
int nApplicable = 0; int nApplicable = 0;
if ( layer ) if ( layer )
{ {
Q_FOREACH ( const QgsGeometryCheckFactory* factory, QgsGeometryCheckFactoryRegistry::getCheckFactories() ) Q_FOREACH( const QgsGeometryCheckFactory* factory, QgsGeometryCheckFactoryRegistry::getCheckFactories() )
{ {
nApplicable += factory->checkApplicability( ui, layer->geometryType() ); nApplicable += factory->checkApplicability( ui, layer->geometryType() );
} }
Expand All @@ -130,7 +130,7 @@ void QgsGeometryCheckerSetupTab::selectOutputFile()
{ {
QString filterString = QgsVectorFileWriter::filterForDriver( "ESRI Shapefile" ); QString filterString = QgsVectorFileWriter::filterForDriver( "ESRI Shapefile" );
QMap<QString, QString> filterFormatMap = QgsVectorFileWriter::supportedFiltersAndFormats(); QMap<QString, QString> filterFormatMap = QgsVectorFileWriter::supportedFiltersAndFormats();
Q_FOREACH ( const QString& filter, filterFormatMap.keys() ) Q_FOREACH( const QString& filter, filterFormatMap.keys() )
{ {
QString driverName = filterFormatMap.value( filter ); QString driverName = filterFormatMap.value( filter );
if ( driverName != "ESRI Shapefile" ) // Default entry, first in list (see above) if ( driverName != "ESRI Shapefile" ) // Default entry, first in list (see above)
Expand Down Expand Up @@ -172,6 +172,13 @@ void QgsGeometryCheckerSetupTab::runChecks()
if ( !layer ) if ( !layer )
return; return;


if ( ui.radioButtonOutputNew->isChecked() &&
layer->dataProvider()->dataSourceUri().startsWith( ui.lineEditOutput->text() ) )
{
QMessageBox::critical( this, tr( "Invalid Output Layer" ), tr( "The chosen output layer is the same as the input layer." ) );
return;
}

if ( layer->isEditable() ) if ( layer->isEditable() )
{ {
QMessageBox::critical( this, tr( "Editable Input Layer" ), tr( "The input layer is not allowed to be in editing mode." ) ); QMessageBox::critical( this, tr( "Editable Input Layer" ), tr( "The input layer is not allowed to be in editing mode." ) );
Expand All @@ -194,7 +201,7 @@ void QgsGeometryCheckerSetupTab::runChecks()


// Remove existing layer with same uri // Remove existing layer with same uri
QStringList toRemove; QStringList toRemove;
Q_FOREACH ( QgsMapLayer* maplayer, QgsMapLayerRegistry::instance()->mapLayers() ) Q_FOREACH( QgsMapLayer* maplayer, QgsMapLayerRegistry::instance()->mapLayers() )
{ {
if ( dynamic_cast<QgsVectorLayer*>( maplayer ) && if ( dynamic_cast<QgsVectorLayer*>( maplayer ) &&
static_cast<QgsVectorLayer*>( maplayer )->dataProvider()->dataSourceUri().startsWith( filename ) ) static_cast<QgsVectorLayer*>( maplayer )->dataProvider()->dataSourceUri().startsWith( filename ) )
Expand Down Expand Up @@ -269,7 +276,7 @@ void QgsGeometryCheckerSetupTab::runChecks()


QList<QgsGeometryCheck*> checks; QList<QgsGeometryCheck*> checks;
double mapToLayer = 1. / mIface->mapCanvas()->mapSettings().layerToMapUnits( layer ); double mapToLayer = 1. / mIface->mapCanvas()->mapSettings().layerToMapUnits( layer );
Q_FOREACH ( const QgsGeometryCheckFactory* factory, QgsGeometryCheckFactoryRegistry::getCheckFactories() ) Q_FOREACH( const QgsGeometryCheckFactory* factory, QgsGeometryCheckFactoryRegistry::getCheckFactories() )
{ {
QgsGeometryCheck* check = factory->createInstance( featurePool, ui, mapToLayer ); QgsGeometryCheck* check = factory->createInstance( featurePool, ui, mapToLayer );
if ( check ) if ( check )
Expand Down
14 changes: 11 additions & 3 deletions src/plugins/geometry_snapper/qgsgeometrysnapperdialog.cpp
Expand Up @@ -72,7 +72,7 @@ void QgsGeometrySnapperDialog::updateLayers()
QgsMapLayer* currentLayer = mIface->mapCanvas()->currentLayer(); QgsMapLayer* currentLayer = mIface->mapCanvas()->currentLayer();
int curInputIdx = -1; int curInputIdx = -1;
int curReferenceIdx = -1; int curReferenceIdx = -1;
Q_FOREACH ( QgsMapLayer* layer, QgsMapLayerRegistry::instance()->mapLayers() ) Q_FOREACH( QgsMapLayer* layer, QgsMapLayerRegistry::instance()->mapLayers() )
{ {
if ( qobject_cast<QgsVectorLayer*>( layer ) ) if ( qobject_cast<QgsVectorLayer*>( layer ) )
{ {
Expand Down Expand Up @@ -142,7 +142,7 @@ void QgsGeometrySnapperDialog::selectOutputFile()
{ {
QString filterString = QgsVectorFileWriter::filterForDriver( "ESRI Shapefile" ); QString filterString = QgsVectorFileWriter::filterForDriver( "ESRI Shapefile" );
QMap<QString, QString> filterFormatMap = QgsVectorFileWriter::supportedFiltersAndFormats(); QMap<QString, QString> filterFormatMap = QgsVectorFileWriter::supportedFiltersAndFormats();
Q_FOREACH ( const QString& filter, filterFormatMap.keys() ) Q_FOREACH( const QString& filter, filterFormatMap.keys() )
{ {
QString driverName = filterFormatMap.value( filter ); QString driverName = filterFormatMap.value( filter );
if ( driverName != "ESRI Shapefile" ) // Default entry, first in list (see above) if ( driverName != "ESRI Shapefile" ) // Default entry, first in list (see above)
Expand Down Expand Up @@ -187,6 +187,14 @@ void QgsGeometrySnapperDialog::run()
return; return;
} }


if ( radioButtonOutputNew->isChecked() &&
( layer->dataProvider()->dataSourceUri().startsWith( lineEditOutput->text() ) ||
referenceLayer->dataProvider()->dataSourceUri().startsWith( lineEditOutput->text() ) ) )
{
QMessageBox::critical( this, tr( "Invalid Output Layer" ), tr( "The chosen output layer is the same as an input layer." ) );
return;
}

bool selectedOnly = checkBoxInputSelectedOnly->isChecked(); bool selectedOnly = checkBoxInputSelectedOnly->isChecked();


/** Duplicate if necessary **/ /** Duplicate if necessary **/
Expand All @@ -196,7 +204,7 @@ void QgsGeometrySnapperDialog::run()


// Remove existing layer with same uri // Remove existing layer with same uri
QStringList toRemove; QStringList toRemove;
Q_FOREACH ( QgsMapLayer* maplayer, QgsMapLayerRegistry::instance()->mapLayers() ) Q_FOREACH( QgsMapLayer* maplayer, QgsMapLayerRegistry::instance()->mapLayers() )
{ {
if ( dynamic_cast<QgsVectorLayer*>( maplayer ) && if ( dynamic_cast<QgsVectorLayer*>( maplayer ) &&
static_cast<QgsVectorLayer*>( maplayer )->dataProvider()->dataSourceUri().startsWith( filename ) ) static_cast<QgsVectorLayer*>( maplayer )->dataProvider()->dataSourceUri().startsWith( filename ) )
Expand Down

0 comments on commit 4827cbc

Please sign in to comment.