Skip to content

Commit

Permalink
initialize map tool in function
Browse files Browse the repository at this point in the history
  • Loading branch information
signedav committed Dec 20, 2017
1 parent 3b3d304 commit 7b199ed
Showing 1 changed file with 16 additions and 4 deletions.
20 changes: 16 additions & 4 deletions src/app/qgisapp.cpp
Expand Up @@ -13385,7 +13385,11 @@ QgsFeature QgisApp::duplicateFeatureDigitized( QgsMapLayer *mlayer, const QgsFea
QgsVectorLayer *layer = qobject_cast<QgsVectorLayer *>( mlayer );

layer->startEditing();
mMapCanvas->setMapTool( mMapTools.mDigitizeFeature );

QgsMapToolDigitizeFeature *digiFeature = nullptr;
digiFeature = new QgsMapToolDigitizeFeature( mMapCanvas, QgsMapToolCapture::CaptureNone );

mMapCanvas->setMapTool( digiFeature );
mMapCanvas->window()->raise();
mMapCanvas->activateWindow();
mMapCanvas->setFocus();
Expand All @@ -13394,7 +13398,7 @@ QgsFeature QgisApp::duplicateFeatureDigitized( QgsMapLayer *mlayer, const QgsFea
messageBar()->pushMessage( msg, QgsMessageBar::INFO, 3 );

QMetaObject::Connection *connDigitizingFinished = new QMetaObject::Connection();
*connDigitizingFinished = connect( mMapTools.mDigitizeFeature, static_cast<void ( QgsMapToolDigitizeFeature::* )( const QgsFeature & )>( &QgsMapToolDigitizeFeature::digitizingFinished ), this, [this, layer, feature, connDigitizingFinished]( const QgsFeature & digitizedFeature )
*connDigitizingFinished = connect( digiFeature, static_cast<void ( QgsMapToolDigitizeFeature::* )( const QgsFeature & )>( &QgsMapToolDigitizeFeature::digitizingFinished ), this, [this, layer, feature, connDigitizingFinished, digiFeature]( const QgsFeature & digitizedFeature )
{
QString msg = tr( "Duplicate digitized" );
messageBar()->pushMessage( msg, QgsMessageBar::INFO, 1 );
Expand All @@ -13412,11 +13416,19 @@ QgsFeature QgisApp::duplicateFeatureDigitized( QgsMapLayer *mlayer, const QgsFea
}

messageBar()->pushMessage( tr( "Feature on layer %2 duplicated\n%3" ).arg( layer->name() ).arg( childrenInfo ), QgsMessageBar::SUCCESS, 5 );
mMapCanvas->unsetMapTool( mMapTools.mDigitizeFeature );
disconnect( *connDigitizingFinished );
mMapCanvas->unsetMapTool( digiFeature );
//disconnect( *connDigitizingFinished );
//delete digiFeature;
}
);

QMetaObject::Connection *connDigitizingAborted = new QMetaObject::Connection();
*connDigitizingAborted = connect( digiFeature, static_cast<void ( QgsMapToolDigitizeFeature::* )()>( &QgsMapToolDigitizeFeature::deactivate ), this, [this, layer, feature, connDigitizingFinished, digiFeature]()
{
delete digiFeature;
}
);

return QgsFeature();
}

0 comments on commit 7b199ed

Please sign in to comment.