Skip to content
Permalink
Browse files

improved signal/slot and flexible layer handling

two signals now digitizingCompleted and digitizingFinished using deleteLater() for no conflicts
the addFeature is using the currentLayer. when the duplicatedigitized-action has a given layer it uses the given. otherwise the current. the given will be set as current and on decativation of the digitizing it's set back.
  • Loading branch information
signedav committed Dec 18, 2017
1 parent 1295efc commit 0b050307975c2e8f11385b5dc7006ed16e587644
@@ -96,6 +96,10 @@ Clean a temporary rubberband
convenient method to clean members
%End

public slots:
void setCurrentLayer( QgsMapLayer *layer );


protected:

int nextPoint( const QgsPoint &mapPoint, QgsPoint &layerPoint );
@@ -1382,7 +1382,6 @@ QgisApp::~QgisApp()
delete mMapTools.mRegularPolygonCenterPoint;
delete mMapTools.mRegularPolygonCenterCorner;
delete mMapTools.mAddFeature;
delete mMapTools.mDigitizeFeature;
delete mpMaptip;

delete mpGpsWidget;
@@ -3299,7 +3298,6 @@ void QgisApp::createCanvasTools()
mMapTools.mAnnotation->setAction( mActionAnnotation );
mMapTools.mAddFeature = new QgsMapToolAddFeature( mMapCanvas, QgsMapToolCapture::CaptureNone );
mMapTools.mAddFeature->setAction( mActionAddFeature );
mMapTools.mDigitizeFeature = new QgsMapToolDigitizeFeature( mMapCanvas, QgsMapToolCapture::CaptureNone );
mMapTools.mCircularStringCurvePoint = new QgsMapToolCircularStringCurvePoint( mMapTools.mAddFeature, mMapCanvas );
mMapTools.mCircularStringCurvePoint->setAction( mActionCircularStringCurvePoint );
mMapTools.mCircularStringRadius = new QgsMapToolCircularStringRadius( mMapTools.mAddFeature, mMapCanvas );
@@ -13388,17 +13386,17 @@ QgsFeature QgisApp::duplicateFeatureDigitized( QgsMapLayer *mlayer, const QgsFea

layer->startEditing();

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

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

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

connect( digitizeFeature, static_cast<void ( QgsMapToolDigitizeFeature::* )( const QgsFeature & )>( &QgsMapToolDigitizeFeature::digitizingFinished ), this, [this, layer, feature, digitizeFeature]( const QgsFeature & digitizedFeature )
connect( digitizeFeature, static_cast<void ( QgsMapToolDigitizeFeature::* )( const QgsFeature & )>( &QgsMapToolDigitizeFeature::digitizingCompleted ), this, [this, layer, feature, digitizeFeature]( const QgsFeature & digitizedFeature )
{
QString msg = tr( "Duplicate digitized" );
messageBar()->pushMessage( msg, QgsMessageBar::INFO, 1 );
@@ -13418,18 +13416,13 @@ 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 );

}
);

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]()
connect( digitizeFeature, static_cast<void ( QgsMapToolDigitizeFeature::* )()>( &QgsMapToolDigitizeFeature::digitizingFinished ), this, [this, digitizeFeature]()
{
delete digitizeFeature;
digitizeFeature->deleteLater();
}
);

@@ -1941,7 +1941,6 @@ class APP_EXPORT QgisApp : public QMainWindow, private Ui::MainWindow
QgsMapTool *mMeasureArea = nullptr;
QgsMapTool *mMeasureAngle = nullptr;
QgsMapToolAddFeature *mAddFeature = nullptr;
QgsMapToolDigitizeFeature *mDigitizeFeature = nullptr;
QgsMapTool *mCircularStringCurvePoint = nullptr;
QgsMapTool *mCircularStringRadius = nullptr;
QgsMapTool *mCircle2Points = nullptr;
@@ -37,7 +37,7 @@
#include <QSettings>

QgsMapToolAddFeature::QgsMapToolAddFeature( QgsMapCanvas *canvas, CaptureMode mode )
: QgsMapToolDigitizeFeature( canvas, mode )
: QgsMapToolDigitizeFeature( canvas, canvas->currentLayer(), mode )
, mCheckGeometryType( true )
{
mToolName = tr( "Add feature" );
@@ -55,10 +55,10 @@ bool QgsMapToolAddFeature::addFeature( QgsVectorLayer *vlayer, QgsFeature *f, bo
return res;
}

void QgsMapToolAddFeature::digitized( QgsFeature *f )
void QgsMapToolAddFeature::digitized( const QgsFeature *f )
{
QgsVectorLayer *vlayer = currentVectorLayer();
bool res = addFeature( vlayer, f, false );
bool res = addFeature( vlayer, const_cast<QgsFeature *>( f ), false );

if ( res && ( mode() == CaptureLine || mode() == CapturePolygon ) )
{
@@ -25,7 +25,7 @@ class APP_EXPORT QgsMapToolAddFeature : public QgsMapToolDigitizeFeature

bool addFeature( QgsVectorLayer *vlayer, QgsFeature *f, bool showModal = true );

void digitized( QgsFeature *f ) override;
void digitized( const QgsFeature *f ) override;

protected:

@@ -37,41 +37,53 @@
#include <QMouseEvent>
#include <QSettings>

QgsMapToolDigitizeFeature::QgsMapToolDigitizeFeature( QgsMapCanvas *canvas, CaptureMode mode )
QgsMapToolDigitizeFeature::QgsMapToolDigitizeFeature( QgsMapCanvas *canvas, QgsMapLayer *layer, CaptureMode mode )
: QgsMapToolCapture( canvas, QgisApp::instance()->cadDockWidget(), mode )
, mCheckGeometryType( true )
{
mLayer = layer;
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 )
void QgsMapToolDigitizeFeature::digitized( const QgsFeature *f )
{
emit digitizingFinished( static_cast< const QgsFeature & >( *f ) );
emit digitizingCompleted( static_cast< const QgsFeature & >( *f ) );
}

void QgsMapToolDigitizeFeature::activate()
{
QgsVectorLayer *vlayer = currentVectorLayer();
QgsVectorLayer *vlayer = qobject_cast<QgsVectorLayer *>( mLayer );
if ( !vlayer )
vlayer = currentVectorLayer();

if ( vlayer && vlayer->geometryType() == QgsWkbTypes::NullGeometry )
{
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() );
if ( mLayer )
{
//remember current layer
mCurrentLayer = mCanvas->currentLayer();
//set the layer with the given
mCanvas->setCurrentLayer( mLayer );
}

QgsMapToolCapture::activate();
}

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

if ( mCurrentLayer )
//set the layer back to the one remembered
mCanvas->setCurrentLayer( mCurrentLayer );
emit digitizingFinished();
}

bool QgsMapToolDigitizeFeature::checkGeometryType() const
@@ -86,7 +98,11 @@ void QgsMapToolDigitizeFeature::setCheckGeometryType( bool checkGeometryType )

void QgsMapToolDigitizeFeature::cadCanvasReleaseEvent( QgsMapMouseEvent *e )
{
QgsVectorLayer *vlayer = currentVectorLayer();
QgsVectorLayer *vlayer = qobject_cast<QgsVectorLayer *>( mLayer );

if ( !vlayer )
//if no given layer take the current from canvas
vlayer = currentVectorLayer();

if ( !vlayer )
{
@@ -123,8 +139,6 @@ void QgsMapToolDigitizeFeature::cadCanvasReleaseEvent( QgsMapMouseEvent *e )
return;
}



QgsPointXY savePoint; //point in layer coordinates
try
{
@@ -192,8 +206,6 @@ void QgsMapToolDigitizeFeature::cadCanvasReleaseEvent( QgsMapMouseEvent *e )

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

emit digitizingFinalized();
}
}

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

stopCapturing();

emit digitizingFinalized();
}
}
}
@@ -25,19 +25,18 @@ class APP_EXPORT QgsMapToolDigitizeFeature : public QgsMapToolCapture
Q_OBJECT
public:
//! \since QGIS 3.2
QgsMapToolDigitizeFeature( QgsMapCanvas *canvas, CaptureMode mode );
QgsMapToolDigitizeFeature( QgsMapCanvas *canvas, QgsMapLayer *layer, CaptureMode mode );

void cadCanvasReleaseEvent( QgsMapMouseEvent *e ) override;

virtual void digitized( QgsFeature *f );
virtual void digitized( const QgsFeature *f );

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

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

protected:

@@ -55,6 +54,16 @@ class APP_EXPORT QgsMapToolDigitizeFeature : public QgsMapToolCapture

private:

/**
* individual layer per digitizing session
* \since QGIS 3.0 */
QgsMapLayer *mLayer = nullptr;

/**
* layer used before digitizing session
* \since QGIS 3.0 */
QgsMapLayer *mCurrentLayer = nullptr;

/**
* Check if CaptureMode matches layer type. Default is true.
* \since QGIS 2.12 */
@@ -53,7 +53,7 @@ QgsMapToolCapture::QgsMapToolCapture( QgsMapCanvas *canvas, QgsAdvancedDigitizin
setCursor( QgsApplication::getThemeCursor( QgsApplication::Cursor::CapturePoint ) );

connect( canvas, &QgsMapCanvas::currentLayerChanged,
this, &QgsMapToolCapture::currentLayerChanged );
this, &QgsMapToolCapture::setCurrentLayer );
}

QgsMapToolCapture::~QgsMapToolCapture()
@@ -95,7 +95,7 @@ void QgsMapToolCapture::validationFinished()
}
}

void QgsMapToolCapture::currentLayerChanged( QgsMapLayer *layer )
void QgsMapToolCapture::setCurrentLayer( QgsMapLayer *layer )
{
if ( !mCaptureModeFromLayer )
return;
@@ -111,9 +111,11 @@ class GUI_EXPORT QgsMapToolCapture : public QgsMapToolAdvancedDigitizing

private slots:
void validationFinished();
void currentLayerChanged( QgsMapLayer *layer );
void addError( QgsGeometry::Error );

public slots:
void setCurrentLayer( QgsMapLayer *layer );


protected:

0 comments on commit 0b05030

Please sign in to comment.
You can’t perform that action at this time.