Skip to content
Permalink
Browse files

disable maptool if editing stopped or dialog closed + fix deactivated…

… map tool
  • Loading branch information
3nids committed Sep 17, 2014
1 parent 05524d7 commit 1c3b0ea19a53bdddc25b7de453fdc682076b39b6
@@ -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() ) );
@@ -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 );
@@ -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;
@@ -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 )
@@ -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 );
}
@@ -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;
}

@@ -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 );
@@ -169,7 +169,6 @@ void QgsMapToolIdentify::activate()

void QgsMapToolIdentify::deactivate()
{

QgsMapTool::deactivate();
}

@@ -15,6 +15,7 @@

#include <QMouseEvent>

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

@@ -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 )
@@ -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.
You can’t perform that action at this time.