Skip to content

Commit 9799cd8

Browse files
committed
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
1 parent 7b199ed commit 9799cd8

File tree

3 files changed

+49
-28
lines changed

3 files changed

+49
-28
lines changed

src/app/qgisapp.cpp

+22-18
Original file line numberDiff line numberDiff line change
@@ -13348,7 +13348,8 @@ QgsFeature QgisApp::duplicateFeatures( QgsMapLayer *mlayer, const QgsFeature &fe
1334813348
}
1334913349
else
1335013350
{
13351-
for ( const QgsFeature &f : layer->selectedFeatures() )
13351+
const auto selectedFeatures = layer->selectedFeatures();
13352+
for ( const QgsFeature &f : selectedFeatures )
1335213353
{
1335313354
featureList.append( f );
1335413355
}
@@ -13365,13 +13366,14 @@ QgsFeature QgisApp::duplicateFeatures( QgsMapLayer *mlayer, const QgsFeature &fe
1336513366
QgsVectorLayerUtils::duplicateFeature( layer, f, QgsProject::instance(), 0, duplicateFeatureContext );
1336613367
featureCount += 1;
1336713368

13368-
for ( QgsVectorLayer *chl : duplicateFeatureContext.layers() )
13369+
const auto duplicatedFeatureContextLayers = duplicateFeatureContext.layers();
13370+
for ( QgsVectorLayer *chl : duplicatedFeatureContextLayers )
1336913371
{
13370-
childrenInfo += ( tr( "%1 children on layer %2 duplicated" ).arg( duplicateFeatureContext.duplicatedFeatures( chl ).size() ).arg( chl->name() ) );
13372+
childrenInfo += ( tr( "%1 children on layer %2 duplicated" ).arg( QString::number( duplicateFeatureContext.duplicatedFeatures( chl ).size() ), chl->name() ) );
1337113373
}
1337213374
}
1337313375

13374-
messageBar()->pushMessage( tr( "%1 features on layer %2 duplicated\n%3" ).arg( featureCount ).arg( layer->name() ).arg( childrenInfo ), QgsMessageBar::SUCCESS, 5 );
13376+
messageBar()->pushMessage( tr( "%1 features on layer %2 duplicated\n%3" ).arg( QString::number( featureCount ), layer->name(), childrenInfo ), QgsMessageBar::SUCCESS, 5 );
1337513377

1337613378
return QgsFeature();
1337713379
}
@@ -13386,19 +13388,17 @@ QgsFeature QgisApp::duplicateFeatureDigitized( QgsMapLayer *mlayer, const QgsFea
1338613388

1338713389
layer->startEditing();
1338813390

13389-
QgsMapToolDigitizeFeature *digiFeature = nullptr;
13390-
digiFeature = new QgsMapToolDigitizeFeature( mMapCanvas, QgsMapToolCapture::CaptureNone );
13391+
QgsMapToolDigitizeFeature *digitizeFeature = new QgsMapToolDigitizeFeature( mMapCanvas, QgsMapToolCapture::CaptureNone );
1339113392

13392-
mMapCanvas->setMapTool( digiFeature );
13393+
mMapCanvas->setMapTool( digitizeFeature );
1339313394
mMapCanvas->window()->raise();
1339413395
mMapCanvas->activateWindow();
1339513396
mMapCanvas->setFocus();
1339613397

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

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

1341213412
QString childrenInfo;
13413-
for ( QgsVectorLayer *chl : duplicateFeatureContext.layers() )
13413+
const auto duplicateFeatureContextLayers = duplicateFeatureContext.layers();
13414+
for ( QgsVectorLayer *chl : duplicateFeatureContextLayers )
1341413415
{
1341513416
childrenInfo += ( tr( "%1 children on layer %2 duplicated" ).arg( duplicateFeatureContext.duplicatedFeatures( chl ).size() ).arg( chl->name() ) );
1341613417
}
1341713418

1341813419
messageBar()->pushMessage( tr( "Feature on layer %2 duplicated\n%3" ).arg( layer->name() ).arg( childrenInfo ), QgsMessageBar::SUCCESS, 5 );
13419-
mMapCanvas->unsetMapTool( digiFeature );
13420-
//disconnect( *connDigitizingFinished );
13421-
//delete digiFeature;
13420+
13421+
}
13422+
);
13423+
13424+
connect( digitizeFeature, static_cast<void ( QgsMapToolDigitizeFeature::* )()>( &QgsMapToolDigitizeFeature::digitizingFinalized ), this, [this, digitizeFeature]()
13425+
{
13426+
mMapCanvas->unsetMapTool( digitizeFeature );
1342213427
}
13423-
);
13428+
);
1342413429

13425-
QMetaObject::Connection *connDigitizingAborted = new QMetaObject::Connection();
13426-
*connDigitizingAborted = connect( digiFeature, static_cast<void ( QgsMapToolDigitizeFeature::* )()>( &QgsMapToolDigitizeFeature::deactivate ), this, [this, layer, feature, connDigitizingFinished, digiFeature]()
13430+
connect( digitizeFeature, static_cast<void ( QgsMapToolDigitizeFeature::* )()>( &QgsMapToolDigitizeFeature::digitizingAborted ), this, [this, digitizeFeature]()
1342713431
{
13428-
delete digiFeature;
13432+
delete digitizeFeature;
1342913433
}
13430-
);
13434+
);
1343113435

1343213436
return QgsFeature();
1343313437
}

src/app/qgsmaptooldigitizefeature.cpp

+20-6
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
/***************************************************************************
2-
qgsmaptooldigitizefeature- %{Cpp:License:ClassName}
2+
qgsmaptooldigitizefeature.cpp
33
44
---------------------
55
begin : 7.12.2017
6-
copyright : (C) 2017 by david
7-
email : [your-email-here]
6+
copyright : (C) 2017 by David Signer
7+
email : david@opengis.ch
88
***************************************************************************
99
* *
1010
* This program is free software; you can redistribute it and/or modify *
@@ -41,14 +41,14 @@ QgsMapToolDigitizeFeature::QgsMapToolDigitizeFeature( QgsMapCanvas *canvas, Capt
4141
: QgsMapToolCapture( canvas, QgisApp::instance()->cadDockWidget(), mode )
4242
, mCheckGeometryType( true )
4343
{
44-
mToolName = tr( "Add feature" );
44+
mToolName = tr( "Digitize feature" );
4545
connect( QgisApp::instance(), &QgisApp::newProject, this, &QgsMapToolDigitizeFeature::stopCapturing );
4646
connect( QgisApp::instance(), &QgisApp::projectRead, this, &QgsMapToolDigitizeFeature::stopCapturing );
4747
}
4848

4949
void QgsMapToolDigitizeFeature::digitized( QgsFeature *f )
5050
{
51-
emit digitizingFinished( static_cast< const QgsFeature & > ( *f ) );
51+
emit digitizingFinished( static_cast< const QgsFeature & >( *f ) );
5252
}
5353

5454
void QgsMapToolDigitizeFeature::activate()
@@ -58,12 +58,22 @@ void QgsMapToolDigitizeFeature::activate()
5858
{
5959
QgsFeature f;
6060
digitized( &f );
61+
emit digitizingFinalized();
6162
return;
6263
}
6364

65+
//refresh the layer, with the current layer - so capturemode will be set at activate
66+
canvas()->setCurrentLayer( canvas()->currentLayer() );
67+
6468
QgsMapToolCapture::activate();
6569
}
6670

71+
void QgsMapToolDigitizeFeature::deactivate()
72+
{
73+
QgsMapToolCapture::deactivate();
74+
emit digitizingAborted();
75+
}
76+
6777
bool QgsMapToolDigitizeFeature::checkGeometryType() const
6878
{
6979
return mCheckGeometryType;
@@ -178,10 +188,12 @@ void QgsMapToolDigitizeFeature::cadCanvasReleaseEvent( QgsMapMouseEvent *e )
178188
f.setGeometry( g );
179189
f.setValid( true );
180190

181-
digitized( &f );
191+
digitized( &f );
182192

183193
// we are done with digitizing for now so instruct advanced digitizing dock to reset its CAD points
184194
cadDockWidget()->clearPoints();
195+
196+
emit digitizingFinalized();
185197
}
186198
}
187199

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

305317
stopCapturing();
318+
319+
emit digitizingFinalized();
306320
}
307321
}
308322
}

src/app/qgsmaptooldigitizefeature.h

+7-4
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
/***************************************************************************
2-
qgsmaptooldigitizegeometry - %{Cpp:License:ClassName}
2+
qgsmaptooldigitizegeometry.h
33
44
---------------------
55
begin : 7.12.2017
6-
copyright : (C) 2017 by david
7-
email : [your-email-here]
6+
copyright : (C) 2017 by David Signer
7+
email : david@opengis.ch
88
***************************************************************************
99
* *
1010
* This program is free software; you can redistribute it and/or modify *
@@ -24,17 +24,20 @@ class APP_EXPORT QgsMapToolDigitizeFeature : public QgsMapToolCapture
2424
{
2525
Q_OBJECT
2626
public:
27-
//! \since QGIS 2.12
27+
//! \since QGIS 3.2
2828
QgsMapToolDigitizeFeature( QgsMapCanvas *canvas, CaptureMode mode );
2929

3030
void cadCanvasReleaseEvent( QgsMapMouseEvent *e ) override;
3131

3232
virtual void digitized( QgsFeature *f );
3333

3434
virtual void activate() override;
35+
virtual void deactivate() override;
3536

3637
signals:
3738
void digitizingFinished( const QgsFeature & );
39+
void digitizingFinalized( );
40+
void digitizingAborted( );
3841

3942
protected:
4043

0 commit comments

Comments
 (0)