Skip to content
Permalink
Browse files

Merge pull request #2688 from manisandro/geom_checker_fixes

Geom checker fixes
  • Loading branch information
manisandro committed Jan 19, 2016
2 parents 472fa9b + 47aeb59 commit f27ab9a571da565b0169497d635d6c9244d95276
@@ -1606,7 +1606,7 @@ bool QgsVectorFileWriter::driverMetadata( const QString& driverName, QgsVectorFi

for ( ; it != sDriverMetadata.constEnd(); ++it )
{
if ( it.key().startsWith( driverName ) )
if ( it.key().startsWith( driverName ) || it.value().longName.startsWith( driverName ) )
{
driverMetadata = it.value();
return true;
@@ -33,10 +33,8 @@ void QgsGeometryDuplicateNodesCheck::collectErrors( QList<QgsGeometryCheckError*
{
QgsPointV2 pi = geom->vertexAt( QgsVertexId( iPart, iRing, iVert ) );
QgsPointV2 pj = geom->vertexAt( QgsVertexId( iPart, iRing, jVert ) );
QgsDebugMsg( QString( "(%1,%2) (%3,%4) d = %5, tol = %6" ).arg( pi.x(), 0, 'f', 6 ).arg( pi.y(), 0, 'f', 6 ).arg( pj.x(), 0, 'f', 6 ).arg( pj.y(), 0, 'f', 6 ).arg( QgsGeometryUtils::sqrDistance2D( pi, pj ) ).arg( QgsGeometryCheckPrecision::tolerance(), 0, 'f', 16 ) );
if ( QgsGeometryUtils::sqrDistance2D( pi, pj ) < QgsGeometryCheckPrecision::tolerance() * QgsGeometryCheckPrecision::tolerance() )
{
QgsDebugMsg( "Duplicate" );
errors.append( new QgsGeometryCheckError( this, featureid, pj, QgsVertexId( iPart, iRing, jVert ) ) );
}
}
@@ -74,7 +74,8 @@ void QgsGeometryTypeCheck::fixError( QgsGeometryCheckError* error, int method, i
changes[newFeature.id()].append( Change( ChangeFeature, ChangeAdded ) );
}
// Recycle feature for part 0
feature.setGeometry( new QgsGeometry( QgsGeomUtils::getGeomPart( geom, 0 ) ) );
feature.setGeometry( new QgsGeometry( QgsGeomUtils::getGeomPart( geom, 0 )->clone() ) );
mFeaturePool->updateFeature( feature );
changes[feature.id()].append( Change( ChangeFeature, ChangeChanged ) );
}
// Check if corresponding multi type is allowed
@@ -401,6 +401,11 @@ void QgsGeometryCheckerResultTab::onSelectionChanged( const QItemSelection &newS
{
highlightErrors();
}
else
{
qDeleteAll( mCurrentRubberBands );
mCurrentRubberBands.clear();
}
ui.pushButtonOpenAttributeTable->setEnabled( !newSel.isEmpty() );
}

@@ -81,21 +81,25 @@ void QgsGeometryCheckerSetupTab::updateLayers()
ui.comboBoxInputLayer->clear();

// Collect layers
QgsMapLayer* currentLayer = mIface->mapCanvas()->currentLayer();
// Don't switch current layer if dialog is visible to avoid confusing the user
QgsMapLayer* currentLayer = isVisible() ? 0 : mIface->mapCanvas()->currentLayer();
int currIdx = -1;
int idx = 0;
Q_FOREACH ( QgsMapLayer* layer, QgsMapLayerRegistry::instance()->mapLayers() )
{
QgsDebugMsg( QString( "Adding layer, have %1 in list" ).arg( ui.comboBoxInputLayer->count() ) );
if ( qobject_cast<QgsVectorLayer*>( layer ) )
{
ui.comboBoxInputLayer->addItem( layer->name(), layer->id() );
if ( layer->name() == prevLayer )
{
currIdx = ui.comboBoxInputLayer->count() - 1;
currIdx = idx;
}
else if ( currIdx == -1 && layer == currentLayer )
{
currIdx = ui.comboBoxInputLayer->count() - 1;
currIdx = idx;
}
++idx;
}
}
ui.comboBoxInputLayer->setCurrentIndex( qMax( 0, currIdx ) );
@@ -172,6 +176,13 @@ void QgsGeometryCheckerSetupTab::runChecks()
if ( !layer )
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() )
{
QMessageBox::critical( this, tr( "Editable Input Layer" ), tr( "The input layer is not allowed to be in editing mode." ) );
@@ -207,10 +218,11 @@ void QgsGeometryCheckerSetupTab::runChecks()
QgsMapLayerRegistry::instance()->removeMapLayers( toRemove );
}

QgsVectorFileWriter::WriterError err = QgsVectorFileWriter::writeAsVectorFormat( layer, filename, layer->dataProvider()->encoding(), &layer->crs(), mOutputDriverName, selectedOnly );
QString errMsg;
QgsVectorFileWriter::WriterError err = QgsVectorFileWriter::writeAsVectorFormat( layer, filename, layer->dataProvider()->encoding(), &layer->crs(), mOutputDriverName, selectedOnly, &errMsg );
if ( err != QgsVectorFileWriter::NoError )
{
QMessageBox::critical( this, tr( "Layer Creation Failed" ), tr( "Failed to create the output layer." ) );
QMessageBox::critical( this, tr( "Layer Creation Failed" ), tr( "Failed to create the output layer: %1" ).arg( errMsg ) );
mRunButton->setEnabled( true );
ui.labelStatus->hide();
unsetCursor();
@@ -301,6 +313,7 @@ void QgsGeometryCheckerSetupTab::runChecks()
connect( checker, SIGNAL( progressValue( int ) ), ui.progressBar, SLOT( setValue( int ) ) );
connect( &futureWatcher, SIGNAL( finished() ), &evLoop, SLOT( quit() ) );
connect( mAbortButton, SIGNAL( clicked() ), &futureWatcher, SLOT( cancel() ) );
connect( mAbortButton, SIGNAL( clicked() ), this, SLOT( showCancelFeedback() ) );

int maxSteps = 0;
futureWatcher.setFuture( checker->execute( &maxSteps ) );
@@ -309,12 +322,22 @@ void QgsGeometryCheckerSetupTab::runChecks()

/** Restore window **/
unsetCursor();
mAbortButton->setEnabled( true );
ui.buttonBox->removeButton( mAbortButton );
mRunButton->setEnabled( true );
mRunButton->show();
ui.progressBar->hide();
ui.labelStatus->hide();
ui.widgetInputs->setEnabled( true );

/** Show result **/
emit checkerFinished( !futureWatcher.isCanceled() );
}

void QgsGeometryCheckerSetupTab::showCancelFeedback()
{
mAbortButton->setEnabled( false );
ui.labelStatus->setText( tr( "<b>Waiting for running checks to finish...</b>" ) );
ui.labelStatus->show();
ui.progressBar->hide() ;
}
@@ -53,6 +53,7 @@ class QgsGeometryCheckerSetupTab : public QWidget
void updateLayers();
void validateInput();
void selectOutputFile();
void showCancelFeedback();
};

#endif // QGS_GEOMETRY_CHECKER_SETUP_TAB_H
@@ -69,9 +69,11 @@ void QgsGeometrySnapperDialog::updateLayers()
comboBoxReferenceLayer->clear();

// Collect layers
QgsMapLayer* currentLayer = mIface->mapCanvas()->currentLayer();
// Don't switch current layer if dialog is visible to avoid confusing the user
QgsMapLayer* currentLayer = isVisible() ? 0 : mIface->mapCanvas()->currentLayer();
int curInputIdx = -1;
int curReferenceIdx = -1;
int idx = 0;
Q_FOREACH ( QgsMapLayer* layer, QgsMapLayerRegistry::instance()->mapLayers() )
{
if ( qobject_cast<QgsVectorLayer*>( layer ) )
@@ -83,17 +85,18 @@ void QgsGeometrySnapperDialog::updateLayers()
comboBoxReferenceLayer->addItem( layer->name(), layer->id() );
if ( layer->name() == curInput )
{
curInputIdx = comboBoxInputLayer->count() - 1;
curInputIdx = idx;
}
else if ( curInputIdx == -1 && layer == currentLayer )
{
curInputIdx = comboBoxInputLayer->count() - 1;
curInputIdx = idx;
}

if ( layer->name() == curReference )
{
curReferenceIdx = comboBoxReferenceLayer->count() - 1;
curReferenceIdx = idx;
}
++idx;
}
}
}
@@ -187,6 +190,14 @@ void QgsGeometrySnapperDialog::run()
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();

/** Duplicate if necessary **/
@@ -209,10 +220,11 @@ void QgsGeometrySnapperDialog::run()
QgsMapLayerRegistry::instance()->removeMapLayers( toRemove );
}

QgsVectorFileWriter::WriterError err = QgsVectorFileWriter::writeAsVectorFormat( layer, filename, layer->dataProvider()->encoding(), &layer->crs(), mOutputDriverName, selectedOnly );
QString errMsg;
QgsVectorFileWriter::WriterError err = QgsVectorFileWriter::writeAsVectorFormat( layer, filename, layer->dataProvider()->encoding(), &layer->crs(), mOutputDriverName, selectedOnly, &errMsg );
if ( err != QgsVectorFileWriter::NoError )
{
QMessageBox::critical( this, tr( "Layer Creation Failed" ), tr( "Failed to create the output layer." ) );
QMessageBox::critical( this, tr( "Layer Creation Failed" ), tr( "Failed to create the output layer: %1" ).arg( errMsg ) );
return;
}
QgsVectorLayer* newlayer = new QgsVectorLayer( filename, QFileInfo( filename ).completeBaseName(), "ogr" );
@@ -302,6 +314,6 @@ void QgsGeometrySnapperDialog::run()
{
QMessageBox::warning( this, tr( "Errors occurred" ), tr( "<p>The following errors occured:</p><ul><li>%1</li></ul>" ).arg( snapper.getErrors().join( "</li><li>" ) ) );
}
hide();
hide() ;
}

0 comments on commit f27ab9a

Please sign in to comment.
You can’t perform that action at this time.