Skip to content
Permalink
Browse files

do not send event to adv. digit. when no selection

  • Loading branch information
3nids committed Sep 11, 2015
1 parent 29d5f92 commit 69e53df66b3df49ba04ecd5f17a21bc58b0bf1b5
Showing with 56 additions and 15 deletions.
  1. +49 −14 src/app/qgsmaptooladdpart.cpp
  2. +7 −0 src/app/qgsmaptooladdpart.h
  3. +0 −1 src/gui/qgsmaptoolcapture.cpp
@@ -36,6 +36,18 @@ QgsMapToolAddPart::~QgsMapToolAddPart()
{
}

void QgsMapToolAddPart::canvasReleaseEvent( QgsMapMouseEvent * e )
{
if ( checkSelection() )
{
QgsMapToolAdvancedDigitizing::canvasReleaseEvent( e );
}
else
{
cadDockWidget()->clear();
}
}

void QgsMapToolAddPart::cadCanvasReleaseEvent( QgsMapMouseEvent * e )
{
//check if we operate on a vector layer
@@ -52,21 +64,8 @@ void QgsMapToolAddPart::cadCanvasReleaseEvent( QgsMapMouseEvent * e )
return;
}

//inform user at the begin of the digitising action that the island tool only works if exactly one feature is selected
int nSelectedFeatures = vlayer->selectedFeatureCount();
QString selectionErrorMsg;
if ( nSelectedFeatures < 1 )
{
selectionErrorMsg = tr( "No feature selected. Please select a feature with the selection tool or in the attribute table" );
}
else if ( nSelectedFeatures > 1 )
{
selectionErrorMsg = tr( "Several features are selected. Please select only one feature to which an part should be added." );
}

if ( !selectionErrorMsg.isEmpty() )
if ( !checkSelection() )
{
emit messageEmitted( tr( "Could not add part. %1" ).arg( selectionErrorMsg ), QgsMessageBar::WARNING );
stopCapturing();
return;
}
@@ -225,3 +224,39 @@ void QgsMapToolAddPart::cadCanvasReleaseEvent( QgsMapMouseEvent * e )
emit messageEmitted( errorMessage, QgsMessageBar::WARNING );
vlayer->destroyEditCommand();
}

void QgsMapToolAddPart::activate()
{
checkSelection();
QgsMapToolCapture::activate();
}

bool QgsMapToolAddPart::checkSelection()
{
//check if we operate on a vector layer
QgsVectorLayer *vlayer = currentVectorLayer();
if ( !vlayer )
{
notifyNotVectorLayer();
return false;
}

//inform user at the begin of the digitising action that the island tool only works if exactly one feature is selected
int nSelectedFeatures = vlayer->selectedFeatureCount();
QString selectionErrorMsg;
if ( nSelectedFeatures < 1 )
{
selectionErrorMsg = tr( "No feature selected. Please select a feature with the selection tool or in the attribute table" );
}
else if ( nSelectedFeatures > 1 )
{
selectionErrorMsg = tr( "Several features are selected. Please select only one feature to which an part should be added." );
}

if ( !selectionErrorMsg.isEmpty() )
{
emit messageEmitted( tr( "Could not add part. %1" ).arg( selectionErrorMsg ), QgsMessageBar::WARNING );
}

return selectionErrorMsg.isEmpty();
}
@@ -23,5 +23,12 @@ class APP_EXPORT QgsMapToolAddPart : public QgsMapToolCapture
public:
QgsMapToolAddPart( QgsMapCanvas* canvas );
virtual ~QgsMapToolAddPart();
void canvasReleaseEvent( QgsMapMouseEvent * e ) override;
void cadCanvasReleaseEvent( QgsMapMouseEvent * e ) override;

void activate();

private:
/** Check if there is any feature selected */
bool checkSelection();
};
@@ -372,7 +372,6 @@ void QgsMapToolCapture::stopCapturing()

mCapturing = false;
mCaptureCurve.clear();
mCanvas->refresh();
}

void QgsMapToolCapture::deleteTempRubberBand()

0 comments on commit 69e53df

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