Skip to content

Commit

Permalink
working upload - new signals in digitizefeature
Browse files Browse the repository at this point in the history
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
  • Loading branch information
signedav committed Dec 20, 2017
1 parent 7b199ed commit 9799cd8
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 28 deletions.
40 changes: 22 additions & 18 deletions src/app/qgisapp.cpp
Expand Up @@ -13348,7 +13348,8 @@ QgsFeature QgisApp::duplicateFeatures( QgsMapLayer *mlayer, const QgsFeature &fe
}
else
{
for ( const QgsFeature &f : layer->selectedFeatures() )
const auto selectedFeatures = layer->selectedFeatures();
for ( const QgsFeature &f : selectedFeatures )
{
featureList.append( f );
}
Expand All @@ -13365,13 +13366,14 @@ QgsFeature QgisApp::duplicateFeatures( QgsMapLayer *mlayer, const QgsFeature &fe
QgsVectorLayerUtils::duplicateFeature( layer, f, QgsProject::instance(), 0, duplicateFeatureContext );
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();
}
Expand All @@ -13386,19 +13388,17 @@ QgsFeature QgisApp::duplicateFeatureDigitized( QgsMapLayer *mlayer, const QgsFea

layer->startEditing();

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

mMapCanvas->setMapTool( digiFeature );
mMapCanvas->setMapTool( digitizeFeature );
mMapCanvas->window()->raise();
mMapCanvas->activateWindow();
mMapCanvas->setFocus();

QString msg = tr( "Digitize the duplicate, please." ).arg( layer->name() );
messageBar()->pushMessage( msg, QgsMessageBar::INFO, 3 );

QMetaObject::Connection *connDigitizingFinished = new QMetaObject::Connection();
*connDigitizingFinished = connect( digiFeature, static_cast<void ( QgsMapToolDigitizeFeature::* )( const QgsFeature & )>( &QgsMapToolDigitizeFeature::digitizingFinished ), this, [this, layer, feature, connDigitizingFinished, digiFeature]( const QgsFeature & digitizedFeature )
connect( digitizeFeature, static_cast<void ( QgsMapToolDigitizeFeature::* )( const QgsFeature & )>( &QgsMapToolDigitizeFeature::digitizingFinished ), this, [this, layer, feature, digitizeFeature]( const QgsFeature & digitizedFeature )
{
QString msg = tr( "Duplicate digitized" );
messageBar()->pushMessage( msg, QgsMessageBar::INFO, 1 );
Expand All @@ -13410,24 +13410,28 @@ QgsFeature QgisApp::duplicateFeatureDigitized( QgsMapLayer *mlayer, const QgsFea
QgsVectorLayerUtils::duplicateFeature( layer, newFeature, QgsProject::instance(), 0, duplicateFeatureContext );

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() ) );
}

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;

}
);

connect( digitizeFeature, static_cast<void ( QgsMapToolDigitizeFeature::* )()>( &QgsMapToolDigitizeFeature::digitizingFinalized ), this, [this, digitizeFeature]()
{
mMapCanvas->unsetMapTool( digitizeFeature );
}
);
);

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

return QgsFeature();
}
Expand Down
26 changes: 20 additions & 6 deletions src/app/qgsmaptooldigitizefeature.cpp
@@ -1,10 +1,10 @@
/***************************************************************************
qgsmaptooldigitizefeature- %{Cpp:License:ClassName}
qgsmaptooldigitizefeature.cpp
---------------------
begin : 7.12.2017
copyright : (C) 2017 by david
email : [your-email-here]
copyright : (C) 2017 by David Signer
email : david@opengis.ch
***************************************************************************
* *
* This program is free software; you can redistribute it and/or modify *
Expand Down Expand Up @@ -41,14 +41,14 @@ QgsMapToolDigitizeFeature::QgsMapToolDigitizeFeature( QgsMapCanvas *canvas, Capt
: QgsMapToolCapture( canvas, QgisApp::instance()->cadDockWidget(), mode )
, mCheckGeometryType( true )
{
mToolName = tr( "Add feature" );
mToolName = tr( "Digitize feature" );
connect( QgisApp::instance(), &QgisApp::newProject, this, &QgsMapToolDigitizeFeature::stopCapturing );
connect( QgisApp::instance(), &QgisApp::projectRead, this, &QgsMapToolDigitizeFeature::stopCapturing );
}

void QgsMapToolDigitizeFeature::digitized( QgsFeature *f )
{
emit digitizingFinished( static_cast< const QgsFeature & > ( *f ) );
emit digitizingFinished( static_cast< const QgsFeature & >( *f ) );
}

void QgsMapToolDigitizeFeature::activate()
Expand All @@ -58,12 +58,22 @@ void QgsMapToolDigitizeFeature::activate()
{
QgsFeature f;
digitized( &f );
emit digitizingFinalized();
return;
}

//refresh the layer, with the current layer - so capturemode will be set at activate
canvas()->setCurrentLayer( canvas()->currentLayer() );

QgsMapToolCapture::activate();
}

void QgsMapToolDigitizeFeature::deactivate()
{
QgsMapToolCapture::deactivate();
emit digitizingAborted();
}

bool QgsMapToolDigitizeFeature::checkGeometryType() const
{
return mCheckGeometryType;
Expand Down Expand Up @@ -178,10 +188,12 @@ void QgsMapToolDigitizeFeature::cadCanvasReleaseEvent( QgsMapMouseEvent *e )
f.setGeometry( g );
f.setValid( true );

digitized( &f );
digitized( &f );

// we are done with digitizing for now so instruct advanced digitizing dock to reset its CAD points
cadDockWidget()->clearPoints();

emit digitizingFinalized();
}
}

Expand Down Expand Up @@ -303,6 +315,8 @@ void QgsMapToolDigitizeFeature::cadCanvasReleaseEvent( QgsMapMouseEvent *e )
digitized( f.get() );

stopCapturing();

emit digitizingFinalized();
}
}
}
11 changes: 7 additions & 4 deletions src/app/qgsmaptooldigitizefeature.h
@@ -1,10 +1,10 @@
/***************************************************************************
qgsmaptooldigitizegeometry - %{Cpp:License:ClassName}
qgsmaptooldigitizegeometry.h
---------------------
begin : 7.12.2017
copyright : (C) 2017 by david
email : [your-email-here]
copyright : (C) 2017 by David Signer
email : david@opengis.ch
***************************************************************************
* *
* This program is free software; you can redistribute it and/or modify *
Expand All @@ -24,17 +24,20 @@ class APP_EXPORT QgsMapToolDigitizeFeature : public QgsMapToolCapture
{
Q_OBJECT
public:
//! \since QGIS 2.12
//! \since QGIS 3.2
QgsMapToolDigitizeFeature( QgsMapCanvas *canvas, CaptureMode mode );

void cadCanvasReleaseEvent( QgsMapMouseEvent *e ) override;

virtual void digitized( QgsFeature *f );

virtual void activate() override;
virtual void deactivate() override;

signals:
void digitizingFinished( const QgsFeature & );
void digitizingFinalized( );
void digitizingAborted( );

protected:

Expand Down

0 comments on commit 9799cd8

Please sign in to comment.