@@ -63,6 +63,7 @@ QgsRelationReferenceWidget::QgsRelationReferenceWidget( QWidget* parent )
63
63
64
64
QHBoxLayout* editLayout = new QHBoxLayout ();
65
65
editLayout->setContentsMargins ( 0 , 0 , 0 , 0 );
66
+ editLayout->setSpacing ( 2 );
66
67
67
68
// combobox (for non-geometric relation)
68
69
mComboBox = new QComboBox ( this );
@@ -96,15 +97,20 @@ QgsRelationReferenceWidget::QgsRelationReferenceWidget( QWidget* parent )
96
97
97
98
// map identification button
98
99
mMapIdentificationButton = new QToolButton ( this );
99
- mMapIdentificationButton ->setPopupMode ( QToolButton::MenuButtonPopup );
100
100
mMapIdentificationAction = new QAction ( QgsApplication::getThemeIcon ( " /mActionMapIdentification.svg" ), tr ( " Select on map" ), this );
101
101
mMapIdentificationButton ->addAction ( mMapIdentificationAction );
102
- mRemoveFeatureAction = new QAction ( QgsApplication::getThemeIcon ( " /mActionRemove.svg" ), tr ( " No selection" ), this );
103
- mMapIdentificationButton ->addAction ( mRemoveFeatureAction );
104
102
mMapIdentificationButton ->setDefaultAction ( mMapIdentificationAction );
105
- connect ( mMapIdentificationButton , SIGNAL ( triggered ( QAction* ) ), this , SLOT ( mapIdentificationTriggered ( QAction* ) ) );
103
+ connect ( mMapIdentificationButton , SIGNAL ( triggered ( QAction* ) ), this , SLOT ( mapIdentification ( ) ) );
106
104
editLayout->addWidget ( mMapIdentificationButton );
107
105
106
+ // remove foreign key button
107
+ mRemoveFKButton = new QToolButton ( this );
108
+ mRemoveFKAction = new QAction ( QgsApplication::getThemeIcon ( " /mActionRemove.svg" ), tr ( " No selection" ), this );
109
+ mRemoveFKButton ->addAction ( mRemoveFKAction );
110
+ mRemoveFKButton ->setDefaultAction ( mRemoveFKAction );
111
+ connect ( mRemoveFKButton , SIGNAL ( triggered ( QAction* ) ), this , SLOT ( deleteForeignKey () ) );
112
+ editLayout->addWidget ( mRemoveFKButton );
113
+
108
114
// spacer
109
115
editLayout->addItem ( new QSpacerItem ( 0 , 0 , QSizePolicy::Expanding ) );
110
116
@@ -134,15 +140,7 @@ QgsRelationReferenceWidget::~QgsRelationReferenceWidget()
134
140
void QgsRelationReferenceWidget::setRelation ( QgsRelation relation, bool allowNullValue )
135
141
{
136
142
mAllowNull = allowNullValue;
137
- if ( !allowNullValue && mMapIdentificationButton ->actions ().contains ( mRemoveFeatureAction ) )
138
- {
139
- mMapIdentificationButton ->removeAction ( mRemoveFeatureAction );
140
- }
141
- else if ( allowNullValue && !mMapIdentificationButton ->actions ().contains ( mRemoveFeatureAction ) )
142
- {
143
- mMapIdentificationButton ->addAction ( mRemoveFeatureAction );
144
- }
145
- mMapIdentificationButton ->setPopupMode ( allowNullValue ? QToolButton::MenuButtonPopup : QToolButton::DelayedPopup );
143
+ mRemoveFKButton ->setVisible ( allowNullValue && mReadOnlySelector );
146
144
147
145
if ( relation .isValid () )
148
146
{
@@ -184,6 +182,7 @@ void QgsRelationReferenceWidget::setRelationEditable( bool editable )
184
182
mLineEdit ->setEnabled ( editable );
185
183
mComboBox ->setEnabled ( editable );
186
184
mMapIdentificationButton ->setEnabled ( editable );
185
+ mRemoveFKButton ->setEnabled ( editable );
187
186
}
188
187
189
188
void QgsRelationReferenceWidget::setForeignKey ( const QVariant& value )
@@ -234,6 +233,7 @@ void QgsRelationReferenceWidget::setForeignKey( const QVariant& value )
234
233
}
235
234
}
236
235
236
+ mRemoveFKButton ->setEnabled ( true );
237
237
highlightFeature ( f );
238
238
updateAttributeEditorFrame ( f );
239
239
emit foreignKeyChanged ( foreignKey () );
@@ -264,7 +264,7 @@ void QgsRelationReferenceWidget::deleteForeignKey()
264
264
mComboBox ->setCurrentIndex ( -1 );
265
265
}
266
266
}
267
-
267
+ mRemoveFKButton -> setEnabled ( false );
268
268
updateAttributeEditorFrame ( QgsFeature () );
269
269
emit foreignKeyChanged ( QVariant ( QVariant::Int ) );
270
270
}
@@ -339,6 +339,7 @@ void QgsRelationReferenceWidget::setReadOnlySelector( bool readOnly )
339
339
{
340
340
mComboBox ->setHidden ( readOnly );
341
341
mLineEdit ->setVisible ( readOnly );
342
+ mRemoveFKButton ->setVisible ( mAllowNull && readOnly );
342
343
mReadOnlySelector = readOnly;
343
344
}
344
345
@@ -497,38 +498,30 @@ void QgsRelationReferenceWidget::deleteHighlight()
497
498
mHighlight = NULL ;
498
499
}
499
500
500
- void QgsRelationReferenceWidget::mapIdentificationTriggered ( QAction* action )
501
+ void QgsRelationReferenceWidget::mapIdentification ( )
501
502
{
502
- if ( action == mRemoveFeatureAction )
503
- {
504
- deleteForeignKey ();
505
- }
506
-
507
- else if ( action == mMapIdentificationAction )
508
- {
509
- if ( !mReferencedLayer )
510
- return ;
503
+ if ( !mReferencedLayer )
504
+ return ;
511
505
512
- const QgsVectorLayerTools* tools = mEditorContext .vectorLayerTools ();
513
- if ( !tools )
514
- return ;
515
- if ( !mCanvas )
516
- return ;
506
+ const QgsVectorLayerTools* tools = mEditorContext .vectorLayerTools ();
507
+ if ( !tools )
508
+ return ;
509
+ if ( !mCanvas )
510
+ return ;
517
511
518
- mMapTool = new QgsMapToolIdentifyFeature ( mReferencedLayer , mCanvas );
519
- mCanvas ->setMapTool ( mMapTool );
520
- mWindowWidget = window ();
521
- mWindowWidget ->hide ();
522
- connect ( mMapTool , SIGNAL ( featureIdentified ( QgsFeature ) ), this , SLOT ( featureIdentified ( const QgsFeature ) ) );
523
- connect ( mMapTool , SIGNAL ( deactivated () ), this , SLOT ( mapToolDeactivated () ) );
512
+ mMapTool = new QgsMapToolIdentifyFeature ( mReferencedLayer , mCanvas );
513
+ mCanvas ->setMapTool ( mMapTool );
514
+ mWindowWidget = window ();
515
+ mWindowWidget ->hide ();
516
+ connect ( mMapTool , SIGNAL ( featureIdentified ( QgsFeature ) ), this , SLOT ( featureIdentified ( const QgsFeature ) ) );
517
+ connect ( mMapTool , SIGNAL ( deactivated () ), this , SLOT ( mapToolDeactivated () ) );
524
518
525
- if ( mMessageBar )
526
- {
527
- QString title = QString ( " Relation %1 for %2." ).arg ( mRelationName ).arg ( mReferencingLayer ->name () );
528
- QString msg = tr ( " identify a feature of %1 to be associated. Press <ESC> to cancel." ).arg ( mReferencedLayer ->name () );
529
- mMessageBarItem = QgsMessageBar::createMessage ( title, msg );
530
- mMessageBar ->pushItem ( mMessageBarItem );
531
- }
519
+ if ( mMessageBar )
520
+ {
521
+ QString title = QString ( " Relation %1 for %2." ).arg ( mRelationName ).arg ( mReferencingLayer ->name () );
522
+ QString msg = tr ( " identify a feature of %1 to be associated. Press <ESC> to cancel." ).arg ( mReferencedLayer ->name () );
523
+ mMessageBarItem = QgsMessageBar::createMessage ( title, msg );
524
+ mMessageBar ->pushItem ( mMessageBarItem );
532
525
}
533
526
}
534
527
@@ -567,6 +560,7 @@ void QgsRelationReferenceWidget::featureIdentified( const QgsFeature& feature )
567
560
mComboBox ->setCurrentIndex ( mComboBox ->findData ( feature.attribute ( mFkeyFieldIdx ) ) );
568
561
}
569
562
563
+ mRemoveFKButton ->setEnabled ( true );
570
564
highlightFeature ( feature );
571
565
updateAttributeEditorFrame ( feature );
572
566
emit foreignKeyChanged ( foreignKey () );
0 commit comments