mirror of
https://github.com/qgis/QGIS.git
synced 2025-03-23 00:05:43 -04:00
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:
parent
7b199ed4a9
commit
9799cd8394
@ -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 );
|
||||
}
|
||||
@ -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();
|
||||
}
|
||||
@ -13386,10 +13388,9 @@ 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();
|
||||
@ -13397,8 +13398,7 @@ QgsFeature QgisApp::duplicateFeatureDigitized( QgsMapLayer *mlayer, const QgsFea
|
||||
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 );
|
||||
@ -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;
|
||||
}
|
||||
);
|
||||
|
||||
QMetaObject::Connection *connDigitizingAborted = new QMetaObject::Connection();
|
||||
*connDigitizingAborted = connect( digiFeature, static_cast<void ( QgsMapToolDigitizeFeature::* )()>( &QgsMapToolDigitizeFeature::deactivate ), this, [this, layer, feature, connDigitizingFinished, digiFeature]()
|
||||
{
|
||||
delete digiFeature;
|
||||
}
|
||||
);
|
||||
);
|
||||
|
||||
connect( digitizeFeature, static_cast<void ( QgsMapToolDigitizeFeature::* )()>( &QgsMapToolDigitizeFeature::digitizingFinalized ), this, [this, digitizeFeature]()
|
||||
{
|
||||
mMapCanvas->unsetMapTool( digitizeFeature );
|
||||
}
|
||||
);
|
||||
|
||||
connect( digitizeFeature, static_cast<void ( QgsMapToolDigitizeFeature::* )()>( &QgsMapToolDigitizeFeature::digitizingAborted ), this, [this, digitizeFeature]()
|
||||
{
|
||||
delete digitizeFeature;
|
||||
}
|
||||
);
|
||||
|
||||
return QgsFeature();
|
||||
}
|
||||
|
@ -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 *
|
||||
@ -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()
|
||||
@ -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;
|
||||
@ -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();
|
||||
}
|
||||
}
|
||||
|
||||
@ -303,6 +315,8 @@ void QgsMapToolDigitizeFeature::cadCanvasReleaseEvent( QgsMapMouseEvent *e )
|
||||
digitized( f.get() );
|
||||
|
||||
stopCapturing();
|
||||
|
||||
emit digitizingFinalized();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -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 *
|
||||
@ -24,7 +24,7 @@ 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;
|
||||
@ -32,9 +32,12 @@ class APP_EXPORT QgsMapToolDigitizeFeature : public QgsMapToolCapture
|
||||
virtual void digitized( QgsFeature *f );
|
||||
|
||||
virtual void activate() override;
|
||||
virtual void deactivate() override;
|
||||
|
||||
signals:
|
||||
void digitizingFinished( const QgsFeature & );
|
||||
void digitizingFinalized( );
|
||||
void digitizingAborted( );
|
||||
|
||||
protected:
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user