working upload - new signals in digitizefeature

digitizingFinished -> digitizing made - feature can be duplicated now
digitizingFinalized -> and everything else done - MapTool can be deactivated
digitizingAborted -> it's deactivated (because of cancel or everything done does not matter) - object can be deleted
This commit is contained in:
David 2017-12-11 09:30:46 +01:00
parent 7b199ed4a9
commit 9799cd8394
3 changed files with 51 additions and 30 deletions

View File

@ -13348,7 +13348,8 @@ QgsFeature QgisApp::duplicateFeatures( QgsMapLayer *mlayer, const QgsFeature &fe
} }
else else
{ {
for ( const QgsFeature &f : layer->selectedFeatures() ) const auto selectedFeatures = layer->selectedFeatures();
for ( const QgsFeature &f : selectedFeatures )
{ {
featureList.append( f ); featureList.append( f );
} }
@ -13365,13 +13366,14 @@ QgsFeature QgisApp::duplicateFeatures( QgsMapLayer *mlayer, const QgsFeature &fe
QgsVectorLayerUtils::duplicateFeature( layer, f, QgsProject::instance(), 0, duplicateFeatureContext ); QgsVectorLayerUtils::duplicateFeature( layer, f, QgsProject::instance(), 0, duplicateFeatureContext );
featureCount += 1; featureCount += 1;
for ( QgsVectorLayer *chl : duplicateFeatureContext.layers() ) const auto duplicatedFeatureContextLayers = duplicateFeatureContext.layers();
for ( QgsVectorLayer *chl : duplicatedFeatureContextLayers )
{ {
childrenInfo += ( tr( "%1 children on layer %2 duplicated" ).arg( duplicateFeatureContext.duplicatedFeatures( chl ).size() ).arg( chl->name() ) ); childrenInfo += ( tr( "%1 children on layer %2 duplicated" ).arg( QString::number( duplicateFeatureContext.duplicatedFeatures( chl ).size() ), chl->name() ) );
} }
} }
messageBar()->pushMessage( tr( "%1 features on layer %2 duplicated\n%3" ).arg( featureCount ).arg( layer->name() ).arg( childrenInfo ), QgsMessageBar::SUCCESS, 5 ); messageBar()->pushMessage( tr( "%1 features on layer %2 duplicated\n%3" ).arg( QString::number( featureCount ), layer->name(), childrenInfo ), QgsMessageBar::SUCCESS, 5 );
return QgsFeature(); return QgsFeature();
} }
@ -13386,10 +13388,9 @@ QgsFeature QgisApp::duplicateFeatureDigitized( QgsMapLayer *mlayer, const QgsFea
layer->startEditing(); layer->startEditing();
QgsMapToolDigitizeFeature *digiFeature = nullptr; QgsMapToolDigitizeFeature *digitizeFeature = new QgsMapToolDigitizeFeature( mMapCanvas, QgsMapToolCapture::CaptureNone );
digiFeature = new QgsMapToolDigitizeFeature( mMapCanvas, QgsMapToolCapture::CaptureNone );
mMapCanvas->setMapTool( digiFeature ); mMapCanvas->setMapTool( digitizeFeature );
mMapCanvas->window()->raise(); mMapCanvas->window()->raise();
mMapCanvas->activateWindow(); mMapCanvas->activateWindow();
mMapCanvas->setFocus(); mMapCanvas->setFocus();
@ -13397,8 +13398,7 @@ QgsFeature QgisApp::duplicateFeatureDigitized( QgsMapLayer *mlayer, const QgsFea
QString msg = tr( "Digitize the duplicate, please." ).arg( layer->name() ); QString msg = tr( "Digitize the duplicate, please." ).arg( layer->name() );
messageBar()->pushMessage( msg, QgsMessageBar::INFO, 3 ); messageBar()->pushMessage( msg, QgsMessageBar::INFO, 3 );
QMetaObject::Connection *connDigitizingFinished = new QMetaObject::Connection(); connect( digitizeFeature, static_cast<void ( QgsMapToolDigitizeFeature::* )( const QgsFeature & )>( &QgsMapToolDigitizeFeature::digitizingFinished ), this, [this, layer, feature, digitizeFeature]( 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" ); QString msg = tr( "Duplicate digitized" );
messageBar()->pushMessage( msg, QgsMessageBar::INFO, 1 ); messageBar()->pushMessage( msg, QgsMessageBar::INFO, 1 );
@ -13410,22 +13410,26 @@ QgsFeature QgisApp::duplicateFeatureDigitized( QgsMapLayer *mlayer, const QgsFea
QgsVectorLayerUtils::duplicateFeature( layer, newFeature, QgsProject::instance(), 0, duplicateFeatureContext ); QgsVectorLayerUtils::duplicateFeature( layer, newFeature, QgsProject::instance(), 0, duplicateFeatureContext );
QString childrenInfo; QString childrenInfo;
for ( QgsVectorLayer *chl : duplicateFeatureContext.layers() ) const auto duplicateFeatureContextLayers = duplicateFeatureContext.layers();
for ( QgsVectorLayer *chl : duplicateFeatureContextLayers )
{ {
childrenInfo += ( tr( "%1 children on layer %2 duplicated" ).arg( duplicateFeatureContext.duplicatedFeatures( chl ).size() ).arg( chl->name() ) ); childrenInfo += ( tr( "%1 children on layer %2 duplicated" ).arg( duplicateFeatureContext.duplicatedFeatures( chl ).size() ).arg( chl->name() ) );
} }
messageBar()->pushMessage( tr( "Feature on layer %2 duplicated\n%3" ).arg( layer->name() ).arg( childrenInfo ), QgsMessageBar::SUCCESS, 5 ); messageBar()->pushMessage( tr( "Feature on layer %2 duplicated\n%3" ).arg( layer->name() ).arg( childrenInfo ), QgsMessageBar::SUCCESS, 5 );
mMapCanvas->unsetMapTool( digiFeature );
//disconnect( *connDigitizingFinished );
//delete digiFeature;
} }
); );
QMetaObject::Connection *connDigitizingAborted = new QMetaObject::Connection(); connect( digitizeFeature, static_cast<void ( QgsMapToolDigitizeFeature::* )()>( &QgsMapToolDigitizeFeature::digitizingFinalized ), this, [this, digitizeFeature]()
*connDigitizingAborted = connect( digiFeature, static_cast<void ( QgsMapToolDigitizeFeature::* )()>( &QgsMapToolDigitizeFeature::deactivate ), this, [this, layer, feature, connDigitizingFinished, digiFeature]()
{ {
delete digiFeature; mMapCanvas->unsetMapTool( digitizeFeature );
}
);
connect( digitizeFeature, static_cast<void ( QgsMapToolDigitizeFeature::* )()>( &QgsMapToolDigitizeFeature::digitizingAborted ), this, [this, digitizeFeature]()
{
delete digitizeFeature;
} }
); );

View File

@ -1,10 +1,10 @@
/*************************************************************************** /***************************************************************************
qgsmaptooldigitizefeature- %{Cpp:License:ClassName} qgsmaptooldigitizefeature.cpp
--------------------- ---------------------
begin : 7.12.2017 begin : 7.12.2017
copyright : (C) 2017 by david copyright : (C) 2017 by David Signer
email : [your-email-here] email : david@opengis.ch
*************************************************************************** ***************************************************************************
* * * *
* This program is free software; you can redistribute it and/or modify * * This program is free software; you can redistribute it and/or modify *
@ -41,14 +41,14 @@ QgsMapToolDigitizeFeature::QgsMapToolDigitizeFeature( QgsMapCanvas *canvas, Capt
: QgsMapToolCapture( canvas, QgisApp::instance()->cadDockWidget(), mode ) : QgsMapToolCapture( canvas, QgisApp::instance()->cadDockWidget(), mode )
, mCheckGeometryType( true ) , mCheckGeometryType( true )
{ {
mToolName = tr( "Add feature" ); mToolName = tr( "Digitize feature" );
connect( QgisApp::instance(), &QgisApp::newProject, this, &QgsMapToolDigitizeFeature::stopCapturing ); connect( QgisApp::instance(), &QgisApp::newProject, this, &QgsMapToolDigitizeFeature::stopCapturing );
connect( QgisApp::instance(), &QgisApp::projectRead, this, &QgsMapToolDigitizeFeature::stopCapturing ); connect( QgisApp::instance(), &QgisApp::projectRead, this, &QgsMapToolDigitizeFeature::stopCapturing );
} }
void QgsMapToolDigitizeFeature::digitized( QgsFeature *f ) void QgsMapToolDigitizeFeature::digitized( QgsFeature *f )
{ {
emit digitizingFinished( static_cast< const QgsFeature & > ( *f ) ); emit digitizingFinished( static_cast< const QgsFeature & >( *f ) );
} }
void QgsMapToolDigitizeFeature::activate() void QgsMapToolDigitizeFeature::activate()
@ -58,12 +58,22 @@ void QgsMapToolDigitizeFeature::activate()
{ {
QgsFeature f; QgsFeature f;
digitized( &f ); digitized( &f );
emit digitizingFinalized();
return; return;
} }
//refresh the layer, with the current layer - so capturemode will be set at activate
canvas()->setCurrentLayer( canvas()->currentLayer() );
QgsMapToolCapture::activate(); QgsMapToolCapture::activate();
} }
void QgsMapToolDigitizeFeature::deactivate()
{
QgsMapToolCapture::deactivate();
emit digitizingAborted();
}
bool QgsMapToolDigitizeFeature::checkGeometryType() const bool QgsMapToolDigitizeFeature::checkGeometryType() const
{ {
return mCheckGeometryType; return mCheckGeometryType;
@ -182,6 +192,8 @@ void QgsMapToolDigitizeFeature::cadCanvasReleaseEvent( QgsMapMouseEvent *e )
// we are done with digitizing for now so instruct advanced digitizing dock to reset its CAD points // we are done with digitizing for now so instruct advanced digitizing dock to reset its CAD points
cadDockWidget()->clearPoints(); cadDockWidget()->clearPoints();
emit digitizingFinalized();
} }
} }
@ -303,6 +315,8 @@ void QgsMapToolDigitizeFeature::cadCanvasReleaseEvent( QgsMapMouseEvent *e )
digitized( f.get() ); digitized( f.get() );
stopCapturing(); stopCapturing();
emit digitizingFinalized();
} }
} }
} }

View File

@ -1,10 +1,10 @@
/*************************************************************************** /***************************************************************************
qgsmaptooldigitizegeometry - %{Cpp:License:ClassName} qgsmaptooldigitizegeometry.h
--------------------- ---------------------
begin : 7.12.2017 begin : 7.12.2017
copyright : (C) 2017 by david copyright : (C) 2017 by David Signer
email : [your-email-here] email : david@opengis.ch
*************************************************************************** ***************************************************************************
* * * *
* This program is free software; you can redistribute it and/or modify * * This program is free software; you can redistribute it and/or modify *
@ -24,7 +24,7 @@ class APP_EXPORT QgsMapToolDigitizeFeature : public QgsMapToolCapture
{ {
Q_OBJECT Q_OBJECT
public: public:
//! \since QGIS 2.12 //! \since QGIS 3.2
QgsMapToolDigitizeFeature( QgsMapCanvas *canvas, CaptureMode mode ); QgsMapToolDigitizeFeature( QgsMapCanvas *canvas, CaptureMode mode );
void cadCanvasReleaseEvent( QgsMapMouseEvent *e ) override; void cadCanvasReleaseEvent( QgsMapMouseEvent *e ) override;
@ -32,9 +32,12 @@ class APP_EXPORT QgsMapToolDigitizeFeature : public QgsMapToolCapture
virtual void digitized( QgsFeature *f ); virtual void digitized( QgsFeature *f );
virtual void activate() override; virtual void activate() override;
virtual void deactivate() override;
signals: signals:
void digitizingFinished( const QgsFeature & ); void digitizingFinished( const QgsFeature & );
void digitizingFinalized( );
void digitizingAborted( );
protected: protected: