@@ -100,6 +100,7 @@ QgsRelationReferenceWidget::QgsRelationReferenceWidget( QWidget* parent )
100
100
// map identification button
101
101
mMapIdentificationButton = new QToolButton ( this );
102
102
mMapIdentificationAction = new QAction ( QgsApplication::getThemeIcon ( " /mActionMapIdentification.svg" ), tr ( " Select on map" ), this );
103
+ mMapIdentificationAction ->setCheckable ( true );
103
104
mMapIdentificationButton ->addAction ( mMapIdentificationAction );
104
105
mMapIdentificationButton ->setDefaultAction ( mMapIdentificationAction );
105
106
connect ( mMapIdentificationButton , SIGNAL ( triggered ( QAction* ) ), this , SLOT ( mapIdentification () ) );
@@ -182,6 +183,9 @@ void QgsRelationReferenceWidget::setRelation( QgsRelation relation, bool allowNu
182
183
183
184
void QgsRelationReferenceWidget::setRelationEditable ( bool editable )
184
185
{
186
+ if ( !editable )
187
+ unsetMapTool ();
188
+
185
189
mComboBox ->setEnabled ( editable );
186
190
mMapIdentificationButton ->setEnabled ( editable );
187
191
mRemoveFKButton ->setEnabled ( editable );
@@ -272,20 +276,6 @@ void QgsRelationReferenceWidget::deleteForeignKey()
272
276
emit foreignKeyChanged ( QVariant ( QVariant::Int ) );
273
277
}
274
278
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
-
289
279
QgsFeature QgsRelationReferenceWidget::relatedFeature ()
290
280
{
291
281
QgsFeature f;
@@ -330,6 +320,11 @@ void QgsRelationReferenceWidget::setEditorContext( QgsAttributeEditorContext con
330
320
mEditorContext = context;
331
321
mCanvas = canvas;
332
322
mMessageBar = messageBar;
323
+
324
+ if ( mMapTool )
325
+ delete mMapTool ;
326
+ mMapTool = new QgsMapToolIdentifyFeature ( mCanvas );
327
+ mMapTool ->setAction ( mMapIdentificationAction );
333
328
}
334
329
335
330
void QgsRelationReferenceWidget::setEmbedForm ( bool display )
@@ -518,19 +513,22 @@ void QgsRelationReferenceWidget::mapIdentification()
518
513
if ( !mCanvas )
519
514
return ;
520
515
521
- mMapTool = new QgsMapToolIdentifyFeature ( mCanvas , mReferencedLayer );
522
- mMapTool ->setAction ( mMapIdentificationAction );
516
+ mMapTool ->setLayer ( mReferencedLayer );
523
517
mCanvas ->setMapTool ( mMapTool );
518
+
524
519
mWindowWidget = window ();
520
+ connect ( mWindowWidget , SIGNAL ( destroyed () ), this , SLOT ( unsetMapTool () ) );
521
+
525
522
mCanvas ->raise ();
523
+ mCanvas ->activateWindow ();
526
524
527
525
connect ( mMapTool , SIGNAL ( featureIdentified ( QgsFeature ) ), this , SLOT ( featureIdentified ( const QgsFeature ) ) );
528
526
connect ( mMapTool , SIGNAL ( deactivated () ), this , SLOT ( mapToolDeactivated () ) );
529
527
530
528
if ( mMessageBar )
531
529
{
532
530
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 () );
534
532
mMessageBarItem = QgsMessageBar::createMessage ( title, msg );
535
533
mMessageBar ->pushItem ( mMessageBarItem );
536
534
}
@@ -576,12 +574,31 @@ void QgsRelationReferenceWidget::featureIdentified( const QgsFeature& feature )
576
574
updateAttributeEditorFrame ( feature );
577
575
emit foreignKeyChanged ( foreignKey () );
578
576
579
- // deactivate map tool if activate
577
+ unsetMapTool ();
578
+ }
579
+
580
+ void QgsRelationReferenceWidget::unsetMapTool ()
581
+ {
582
+ // deactivate map tool if activated
580
583
if ( mCanvas && mMapTool )
581
584
{
585
+ /* this will call mapToolDeactivated */
582
586
mCanvas ->unsetMapTool ( mMapTool );
583
587
}
588
+ }
584
589
590
+ void QgsRelationReferenceWidget::mapToolDeactivated ()
591
+ {
585
592
if ( mWindowWidget )
593
+ {
586
594
mWindowWidget ->raise ();
595
+ mWindowWidget ->activateWindow ();
596
+ }
597
+
598
+ if ( mMessageBar && mMessageBarItem )
599
+ {
600
+ mMessageBar ->popWidget ( mMessageBarItem );
601
+ }
602
+ mMessageBarItem = NULL ;
587
603
}
604
+
0 commit comments