Skip to content

Commit 4827cbc

Browse files
committedJan 19, 2016
[Geometry checker] Don't allow setting output layer equal to input layer
1 parent b2a1273 commit 4827cbc

File tree

2 files changed

+24
-9
lines changed

2 files changed

+24
-9
lines changed
 

‎src/plugins/geometry_checker/ui/qgsgeometrycheckersetuptab.cpp

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ QgsGeometryCheckerSetupTab::QgsGeometryCheckerSetupTab( QgisInterface* iface , Q
6464

6565
updateLayers();
6666

67-
Q_FOREACH ( const QgsGeometryCheckFactory* factory, QgsGeometryCheckFactoryRegistry::getCheckFactories() )
67+
Q_FOREACH( const QgsGeometryCheckFactory* factory, QgsGeometryCheckFactoryRegistry::getCheckFactories() )
6868
{
6969
factory->restorePrevious( ui );
7070
}
@@ -83,7 +83,7 @@ void QgsGeometryCheckerSetupTab::updateLayers()
8383
// Collect layers
8484
QgsMapLayer* currentLayer = mIface->mapCanvas()->currentLayer();
8585
int currIdx = -1;
86-
Q_FOREACH ( QgsMapLayer* layer, QgsMapLayerRegistry::instance()->mapLayers() )
86+
Q_FOREACH( QgsMapLayer* layer, QgsMapLayerRegistry::instance()->mapLayers() )
8787
{
8888
if ( qobject_cast<QgsVectorLayer*>( layer ) )
8989
{
@@ -117,7 +117,7 @@ void QgsGeometryCheckerSetupTab::validateInput()
117117
int nApplicable = 0;
118118
if ( layer )
119119
{
120-
Q_FOREACH ( const QgsGeometryCheckFactory* factory, QgsGeometryCheckFactoryRegistry::getCheckFactories() )
120+
Q_FOREACH( const QgsGeometryCheckFactory* factory, QgsGeometryCheckFactoryRegistry::getCheckFactories() )
121121
{
122122
nApplicable += factory->checkApplicability( ui, layer->geometryType() );
123123
}
@@ -130,7 +130,7 @@ void QgsGeometryCheckerSetupTab::selectOutputFile()
130130
{
131131
QString filterString = QgsVectorFileWriter::filterForDriver( "ESRI Shapefile" );
132132
QMap<QString, QString> filterFormatMap = QgsVectorFileWriter::supportedFiltersAndFormats();
133-
Q_FOREACH ( const QString& filter, filterFormatMap.keys() )
133+
Q_FOREACH( const QString& filter, filterFormatMap.keys() )
134134
{
135135
QString driverName = filterFormatMap.value( filter );
136136
if ( driverName != "ESRI Shapefile" ) // Default entry, first in list (see above)
@@ -172,6 +172,13 @@ void QgsGeometryCheckerSetupTab::runChecks()
172172
if ( !layer )
173173
return;
174174

175+
if ( ui.radioButtonOutputNew->isChecked() &&
176+
layer->dataProvider()->dataSourceUri().startsWith( ui.lineEditOutput->text() ) )
177+
{
178+
QMessageBox::critical( this, tr( "Invalid Output Layer" ), tr( "The chosen output layer is the same as the input layer." ) );
179+
return;
180+
}
181+
175182
if ( layer->isEditable() )
176183
{
177184
QMessageBox::critical( this, tr( "Editable Input Layer" ), tr( "The input layer is not allowed to be in editing mode." ) );
@@ -194,7 +201,7 @@ void QgsGeometryCheckerSetupTab::runChecks()
194201

195202
// Remove existing layer with same uri
196203
QStringList toRemove;
197-
Q_FOREACH ( QgsMapLayer* maplayer, QgsMapLayerRegistry::instance()->mapLayers() )
204+
Q_FOREACH( QgsMapLayer* maplayer, QgsMapLayerRegistry::instance()->mapLayers() )
198205
{
199206
if ( dynamic_cast<QgsVectorLayer*>( maplayer ) &&
200207
static_cast<QgsVectorLayer*>( maplayer )->dataProvider()->dataSourceUri().startsWith( filename ) )
@@ -269,7 +276,7 @@ void QgsGeometryCheckerSetupTab::runChecks()
269276

270277
QList<QgsGeometryCheck*> checks;
271278
double mapToLayer = 1. / mIface->mapCanvas()->mapSettings().layerToMapUnits( layer );
272-
Q_FOREACH ( const QgsGeometryCheckFactory* factory, QgsGeometryCheckFactoryRegistry::getCheckFactories() )
279+
Q_FOREACH( const QgsGeometryCheckFactory* factory, QgsGeometryCheckFactoryRegistry::getCheckFactories() )
273280
{
274281
QgsGeometryCheck* check = factory->createInstance( featurePool, ui, mapToLayer );
275282
if ( check )

‎src/plugins/geometry_snapper/qgsgeometrysnapperdialog.cpp

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ void QgsGeometrySnapperDialog::updateLayers()
7272
QgsMapLayer* currentLayer = mIface->mapCanvas()->currentLayer();
7373
int curInputIdx = -1;
7474
int curReferenceIdx = -1;
75-
Q_FOREACH ( QgsMapLayer* layer, QgsMapLayerRegistry::instance()->mapLayers() )
75+
Q_FOREACH( QgsMapLayer* layer, QgsMapLayerRegistry::instance()->mapLayers() )
7676
{
7777
if ( qobject_cast<QgsVectorLayer*>( layer ) )
7878
{
@@ -142,7 +142,7 @@ void QgsGeometrySnapperDialog::selectOutputFile()
142142
{
143143
QString filterString = QgsVectorFileWriter::filterForDriver( "ESRI Shapefile" );
144144
QMap<QString, QString> filterFormatMap = QgsVectorFileWriter::supportedFiltersAndFormats();
145-
Q_FOREACH ( const QString& filter, filterFormatMap.keys() )
145+
Q_FOREACH( const QString& filter, filterFormatMap.keys() )
146146
{
147147
QString driverName = filterFormatMap.value( filter );
148148
if ( driverName != "ESRI Shapefile" ) // Default entry, first in list (see above)
@@ -187,6 +187,14 @@ void QgsGeometrySnapperDialog::run()
187187
return;
188188
}
189189

190+
if ( radioButtonOutputNew->isChecked() &&
191+
( layer->dataProvider()->dataSourceUri().startsWith( lineEditOutput->text() ) ||
192+
referenceLayer->dataProvider()->dataSourceUri().startsWith( lineEditOutput->text() ) ) )
193+
{
194+
QMessageBox::critical( this, tr( "Invalid Output Layer" ), tr( "The chosen output layer is the same as an input layer." ) );
195+
return;
196+
}
197+
190198
bool selectedOnly = checkBoxInputSelectedOnly->isChecked();
191199

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

197205
// Remove existing layer with same uri
198206
QStringList toRemove;
199-
Q_FOREACH ( QgsMapLayer* maplayer, QgsMapLayerRegistry::instance()->mapLayers() )
207+
Q_FOREACH( QgsMapLayer* maplayer, QgsMapLayerRegistry::instance()->mapLayers() )
200208
{
201209
if ( dynamic_cast<QgsVectorLayer*>( maplayer ) &&
202210
static_cast<QgsVectorLayer*>( maplayer )->dataProvider()->dataSourceUri().startsWith( filename ) )

0 commit comments

Comments
 (0)
Please sign in to comment.