Skip to content

Commit 1c3b0ea

Browse files
committedSep 17, 2014
disable maptool if editing stopped or dialog closed + fix deactivated map tool
1 parent 05524d7 commit 1c3b0ea

File tree

4 files changed

+41
-21
lines changed

4 files changed

+41
-21
lines changed
 

‎src/gui/editorwidgets/qgsrelationreferencewidget.cpp

Lines changed: 35 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,7 @@ QgsRelationReferenceWidget::QgsRelationReferenceWidget( QWidget* parent )
100100
// map identification button
101101
mMapIdentificationButton = new QToolButton( this );
102102
mMapIdentificationAction = new QAction( QgsApplication::getThemeIcon( "/mActionMapIdentification.svg" ), tr( "Select on map" ), this );
103+
mMapIdentificationAction->setCheckable( true );
103104
mMapIdentificationButton->addAction( mMapIdentificationAction );
104105
mMapIdentificationButton->setDefaultAction( mMapIdentificationAction );
105106
connect( mMapIdentificationButton, SIGNAL( triggered( QAction* ) ), this, SLOT( mapIdentification() ) );
@@ -182,6 +183,9 @@ void QgsRelationReferenceWidget::setRelation( QgsRelation relation, bool allowNu
182183

183184
void QgsRelationReferenceWidget::setRelationEditable( bool editable )
184185
{
186+
if ( !editable )
187+
unsetMapTool();
188+
185189
mComboBox->setEnabled( editable );
186190
mMapIdentificationButton->setEnabled( editable );
187191
mRemoveFKButton->setEnabled( editable );
@@ -272,20 +276,6 @@ void QgsRelationReferenceWidget::deleteForeignKey()
272276
emit foreignKeyChanged( QVariant( QVariant::Int ) );
273277
}
274278

275-
void QgsRelationReferenceWidget::mapToolDeactivated()
276-
{
277-
if ( mWindowWidget )
278-
{
279-
mWindowWidget->raise();
280-
}
281-
282-
if ( mMessageBar && mMessageBarItem )
283-
{
284-
mMessageBar->popWidget( mMessageBarItem );
285-
}
286-
mMessageBarItem = NULL;
287-
}
288-
289279
QgsFeature QgsRelationReferenceWidget::relatedFeature()
290280
{
291281
QgsFeature f;
@@ -330,6 +320,11 @@ void QgsRelationReferenceWidget::setEditorContext( QgsAttributeEditorContext con
330320
mEditorContext = context;
331321
mCanvas = canvas;
332322
mMessageBar = messageBar;
323+
324+
if ( mMapTool )
325+
delete mMapTool;
326+
mMapTool = new QgsMapToolIdentifyFeature( mCanvas );
327+
mMapTool->setAction( mMapIdentificationAction );
333328
}
334329

335330
void QgsRelationReferenceWidget::setEmbedForm( bool display )
@@ -518,19 +513,22 @@ void QgsRelationReferenceWidget::mapIdentification()
518513
if ( !mCanvas )
519514
return;
520515

521-
mMapTool = new QgsMapToolIdentifyFeature( mCanvas, mReferencedLayer );
522-
mMapTool->setAction( mMapIdentificationAction );
516+
mMapTool->setLayer( mReferencedLayer );
523517
mCanvas->setMapTool( mMapTool );
518+
524519
mWindowWidget = window();
520+
connect( mWindowWidget, SIGNAL( destroyed() ), this, SLOT( unsetMapTool() ) );
521+
525522
mCanvas->raise();
523+
mCanvas->activateWindow();
526524

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

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

579-
// deactivate map tool if activate
577+
unsetMapTool();
578+
}
579+
580+
void QgsRelationReferenceWidget::unsetMapTool()
581+
{
582+
// deactivate map tool if activated
580583
if ( mCanvas && mMapTool )
581584
{
585+
/* this will call mapToolDeactivated */
582586
mCanvas->unsetMapTool( mMapTool );
583587
}
588+
}
584589

590+
void QgsRelationReferenceWidget::mapToolDeactivated()
591+
{
585592
if ( mWindowWidget )
593+
{
586594
mWindowWidget->raise();
595+
mWindowWidget->activateWindow();
596+
}
597+
598+
if ( mMessageBar && mMessageBarItem )
599+
{
600+
mMessageBar->popWidget( mMessageBarItem );
601+
}
602+
mMessageBarItem = NULL;
587603
}
604+

‎src/gui/editorwidgets/qgsrelationreferencewidget.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,9 +95,9 @@ class GUI_EXPORT QgsRelationReferenceWidget : public QWidget
9595
void comboReferenceChanged( int index );
9696
void deleteForeignKey();
9797
void featureIdentified( const QgsFeature& feature );
98+
void unsetMapTool();
9899
void mapToolDeactivated();
99100

100-
101101
private:
102102
QgsFeature relatedFeature();
103103
void highlightFeature( QgsFeature f = QgsFeature(), CanvasExtent canvasExtent = Fixed );

‎src/gui/qgsmaptoolidentify.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -169,7 +169,6 @@ void QgsMapToolIdentify::activate()
169169

170170
void QgsMapToolIdentify::deactivate()
171171
{
172-
173172
QgsMapTool::deactivate();
174173
}
175174

‎src/gui/qgsmaptoolidentifyfeature.cpp

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515

1616
#include <QMouseEvent>
1717

18+
#include "qgscursors.h"
1819
#include "qgsmaptoolidentifyfeature.h"
1920
#include "qgsmapcanvas.h"
2021

@@ -23,6 +24,9 @@ QgsMapToolIdentifyFeature::QgsMapToolIdentifyFeature( QgsMapCanvas* canvas, QgsV
2324
, mCanvas( canvas )
2425
, mLayer( vl )
2526
{
27+
// set cursor
28+
QPixmap cursorPixmap = QPixmap(( const char ** ) cross_hair_cursor );
29+
mCursor = QCursor( cursorPixmap, 1, 1 );
2630
}
2731

2832
void QgsMapToolIdentifyFeature::canvasReleaseEvent( QMouseEvent* e )
@@ -44,6 +48,6 @@ void QgsMapToolIdentifyFeature::keyPressEvent( QKeyEvent* e )
4448
{
4549
if ( e->key() == Qt::Key_Escape )
4650
{
47-
deactivate();
51+
mCanvas->unsetMapTool( this );
4852
}
4953
}

0 commit comments

Comments
 (0)