Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
disable maptool if editing stopped or dialog closed + fix deactivated…
… map tool
  • Loading branch information
3nids committed Sep 17, 2014
1 parent 05524d7 commit 1c3b0ea
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 21 deletions.
53 changes: 35 additions & 18 deletions src/gui/editorwidgets/qgsrelationreferencewidget.cpp
Expand Up @@ -100,6 +100,7 @@ QgsRelationReferenceWidget::QgsRelationReferenceWidget( QWidget* parent )
// map identification button
mMapIdentificationButton = new QToolButton( this );
mMapIdentificationAction = new QAction( QgsApplication::getThemeIcon( "/mActionMapIdentification.svg" ), tr( "Select on map" ), this );
mMapIdentificationAction->setCheckable( true );
mMapIdentificationButton->addAction( mMapIdentificationAction );
mMapIdentificationButton->setDefaultAction( mMapIdentificationAction );
connect( mMapIdentificationButton, SIGNAL( triggered( QAction* ) ), this, SLOT( mapIdentification() ) );
Expand Down Expand Up @@ -182,6 +183,9 @@ void QgsRelationReferenceWidget::setRelation( QgsRelation relation, bool allowNu

void QgsRelationReferenceWidget::setRelationEditable( bool editable )
{
if ( !editable )
unsetMapTool();

mComboBox->setEnabled( editable );
mMapIdentificationButton->setEnabled( editable );
mRemoveFKButton->setEnabled( editable );
Expand Down Expand Up @@ -272,20 +276,6 @@ void QgsRelationReferenceWidget::deleteForeignKey()
emit foreignKeyChanged( QVariant( QVariant::Int ) );
}

void QgsRelationReferenceWidget::mapToolDeactivated()
{
if ( mWindowWidget )
{
mWindowWidget->raise();
}

if ( mMessageBar && mMessageBarItem )
{
mMessageBar->popWidget( mMessageBarItem );
}
mMessageBarItem = NULL;
}

QgsFeature QgsRelationReferenceWidget::relatedFeature()
{
QgsFeature f;
Expand Down Expand Up @@ -330,6 +320,11 @@ void QgsRelationReferenceWidget::setEditorContext( QgsAttributeEditorContext con
mEditorContext = context;
mCanvas = canvas;
mMessageBar = messageBar;

if ( mMapTool )
delete mMapTool;
mMapTool = new QgsMapToolIdentifyFeature( mCanvas );
mMapTool->setAction( mMapIdentificationAction );
}

void QgsRelationReferenceWidget::setEmbedForm( bool display )
Expand Down Expand Up @@ -518,19 +513,22 @@ void QgsRelationReferenceWidget::mapIdentification()
if ( !mCanvas )
return;

mMapTool = new QgsMapToolIdentifyFeature( mCanvas, mReferencedLayer );
mMapTool->setAction( mMapIdentificationAction );
mMapTool->setLayer( mReferencedLayer );
mCanvas->setMapTool( mMapTool );

mWindowWidget = window();
connect( mWindowWidget, SIGNAL( destroyed() ), this, SLOT( unsetMapTool() ) );

mCanvas->raise();
mCanvas->activateWindow();

connect( mMapTool, SIGNAL( featureIdentified( QgsFeature ) ), this, SLOT( featureIdentified( const QgsFeature ) ) );
connect( mMapTool, SIGNAL( deactivated() ), this, SLOT( mapToolDeactivated() ) );

if ( mMessageBar )
{
QString title = QString( "Relation %1 for %2." ).arg( mRelationName ).arg( mReferencingLayer->name() );
QString msg = tr( "identify a feature of %1 to be associated. Press <ESC> to cancel." ).arg( mReferencedLayer->name() );
QString msg = tr( "Identify a feature of %1 to be associated. Press <ESC> to cancel." ).arg( mReferencedLayer->name() );
mMessageBarItem = QgsMessageBar::createMessage( title, msg );
mMessageBar->pushItem( mMessageBarItem );
}
Expand Down Expand Up @@ -576,12 +574,31 @@ void QgsRelationReferenceWidget::featureIdentified( const QgsFeature& feature )
updateAttributeEditorFrame( feature );
emit foreignKeyChanged( foreignKey() );

// deactivate map tool if activate
unsetMapTool();
}

void QgsRelationReferenceWidget::unsetMapTool()
{
// deactivate map tool if activated
if ( mCanvas && mMapTool )
{
/* this will call mapToolDeactivated */
mCanvas->unsetMapTool( mMapTool );
}
}

void QgsRelationReferenceWidget::mapToolDeactivated()
{
if ( mWindowWidget )
{
mWindowWidget->raise();
mWindowWidget->activateWindow();
}

if ( mMessageBar && mMessageBarItem )
{
mMessageBar->popWidget( mMessageBarItem );
}
mMessageBarItem = NULL;
}

2 changes: 1 addition & 1 deletion src/gui/editorwidgets/qgsrelationreferencewidget.h
Expand Up @@ -95,9 +95,9 @@ class GUI_EXPORT QgsRelationReferenceWidget : public QWidget
void comboReferenceChanged( int index );
void deleteForeignKey();
void featureIdentified( const QgsFeature& feature );
void unsetMapTool();
void mapToolDeactivated();


private:
QgsFeature relatedFeature();
void highlightFeature( QgsFeature f = QgsFeature(), CanvasExtent canvasExtent = Fixed );
Expand Down
1 change: 0 additions & 1 deletion src/gui/qgsmaptoolidentify.cpp
Expand Up @@ -169,7 +169,6 @@ void QgsMapToolIdentify::activate()

void QgsMapToolIdentify::deactivate()
{

QgsMapTool::deactivate();
}

Expand Down
6 changes: 5 additions & 1 deletion src/gui/qgsmaptoolidentifyfeature.cpp
Expand Up @@ -15,6 +15,7 @@

#include <QMouseEvent>

#include "qgscursors.h"
#include "qgsmaptoolidentifyfeature.h"
#include "qgsmapcanvas.h"

Expand All @@ -23,6 +24,9 @@ QgsMapToolIdentifyFeature::QgsMapToolIdentifyFeature( QgsMapCanvas* canvas, QgsV
, mCanvas( canvas )
, mLayer( vl )
{
// set cursor
QPixmap cursorPixmap = QPixmap(( const char ** ) cross_hair_cursor );
mCursor = QCursor( cursorPixmap, 1, 1 );
}

void QgsMapToolIdentifyFeature::canvasReleaseEvent( QMouseEvent* e )
Expand All @@ -44,6 +48,6 @@ void QgsMapToolIdentifyFeature::keyPressEvent( QKeyEvent* e )
{
if ( e->key() == Qt::Key_Escape )
{
deactivate();
mCanvas->unsetMapTool( this );
}
}

0 comments on commit 1c3b0ea

Please sign in to comment.