Skip to content

Commit

Permalink
do not send event to adv. digit. when no selection
Browse files Browse the repository at this point in the history
  • Loading branch information
3nids committed Sep 11, 2015
1 parent 29d5f92 commit 69e53df
Show file tree
Hide file tree
Showing 3 changed files with 56 additions and 15 deletions.
63 changes: 49 additions & 14 deletions src/app/qgsmaptooladdpart.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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;
}
Expand Down Expand Up @@ -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();
}
7 changes: 7 additions & 0 deletions src/app/qgsmaptooladdpart.h
Original file line number Diff line number Diff line change
Expand Up @@ -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();
};
1 change: 0 additions & 1 deletion src/gui/qgsmaptoolcapture.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -372,7 +372,6 @@ void QgsMapToolCapture::stopCapturing()

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

void QgsMapToolCapture::deleteTempRubberBand()
Expand Down

0 comments on commit 69e53df

Please sign in to comment.