Skip to content

Commit 8a1220c

Browse files
committed
[Releation reference widget] use separate button for remove action
1 parent 3bb5f43 commit 8a1220c

File tree

2 files changed

+39
-44
lines changed

2 files changed

+39
-44
lines changed

src/gui/editorwidgets/qgsrelationreferencewidget.cpp

+36-42
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ QgsRelationReferenceWidget::QgsRelationReferenceWidget( QWidget* parent )
6363

6464
QHBoxLayout* editLayout = new QHBoxLayout();
6565
editLayout->setContentsMargins( 0, 0, 0, 0 );
66+
editLayout->setSpacing( 2 );
6667

6768
// combobox (for non-geometric relation)
6869
mComboBox = new QComboBox( this );
@@ -96,15 +97,20 @@ QgsRelationReferenceWidget::QgsRelationReferenceWidget( QWidget* parent )
9697

9798
// map identification button
9899
mMapIdentificationButton = new QToolButton( this );
99-
mMapIdentificationButton->setPopupMode( QToolButton::MenuButtonPopup );
100100
mMapIdentificationAction = new QAction( QgsApplication::getThemeIcon( "/mActionMapIdentification.svg" ), tr( "Select on map" ), this );
101101
mMapIdentificationButton->addAction( mMapIdentificationAction );
102-
mRemoveFeatureAction = new QAction( QgsApplication::getThemeIcon( "/mActionRemove.svg" ), tr( "No selection" ), this );
103-
mMapIdentificationButton->addAction( mRemoveFeatureAction );
104102
mMapIdentificationButton->setDefaultAction( mMapIdentificationAction );
105-
connect( mMapIdentificationButton, SIGNAL( triggered( QAction* ) ), this, SLOT( mapIdentificationTriggered( QAction* ) ) );
103+
connect( mMapIdentificationButton, SIGNAL( triggered( QAction* ) ), this, SLOT( mapIdentification() ) );
106104
editLayout->addWidget( mMapIdentificationButton );
107105

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+
108114
// spacer
109115
editLayout->addItem( new QSpacerItem( 0, 0, QSizePolicy::Expanding ) );
110116

@@ -134,15 +140,7 @@ QgsRelationReferenceWidget::~QgsRelationReferenceWidget()
134140
void QgsRelationReferenceWidget::setRelation( QgsRelation relation, bool allowNullValue )
135141
{
136142
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 );
146144

147145
if ( relation.isValid() )
148146
{
@@ -184,6 +182,7 @@ void QgsRelationReferenceWidget::setRelationEditable( bool editable )
184182
mLineEdit->setEnabled( editable );
185183
mComboBox->setEnabled( editable );
186184
mMapIdentificationButton->setEnabled( editable );
185+
mRemoveFKButton->setEnabled( editable );
187186
}
188187

189188
void QgsRelationReferenceWidget::setForeignKey( const QVariant& value )
@@ -234,6 +233,7 @@ void QgsRelationReferenceWidget::setForeignKey( const QVariant& value )
234233
}
235234
}
236235

236+
mRemoveFKButton->setEnabled( true );
237237
highlightFeature( f );
238238
updateAttributeEditorFrame( f );
239239
emit foreignKeyChanged( foreignKey() );
@@ -264,7 +264,7 @@ void QgsRelationReferenceWidget::deleteForeignKey()
264264
mComboBox->setCurrentIndex( -1 );
265265
}
266266
}
267-
267+
mRemoveFKButton->setEnabled( false );
268268
updateAttributeEditorFrame( QgsFeature() );
269269
emit foreignKeyChanged( QVariant( QVariant::Int ) );
270270
}
@@ -339,6 +339,7 @@ void QgsRelationReferenceWidget::setReadOnlySelector( bool readOnly )
339339
{
340340
mComboBox->setHidden( readOnly );
341341
mLineEdit->setVisible( readOnly );
342+
mRemoveFKButton->setVisible( mAllowNull && readOnly );
342343
mReadOnlySelector = readOnly;
343344
}
344345

@@ -497,38 +498,30 @@ void QgsRelationReferenceWidget::deleteHighlight()
497498
mHighlight = NULL;
498499
}
499500

500-
void QgsRelationReferenceWidget::mapIdentificationTriggered( QAction* action )
501+
void QgsRelationReferenceWidget::mapIdentification()
501502
{
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;
511505

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;
517511

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() ) );
524518

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 );
532525
}
533526
}
534527

@@ -567,6 +560,7 @@ void QgsRelationReferenceWidget::featureIdentified( const QgsFeature& feature )
567560
mComboBox->setCurrentIndex( mComboBox->findData( feature.attribute( mFkeyFieldIdx ) ) );
568561
}
569562

563+
mRemoveFKButton->setEnabled( true );
570564
highlightFeature( feature );
571565
updateAttributeEditorFrame( feature );
572566
emit foreignKeyChanged( foreignKey() );

src/gui/editorwidgets/qgsrelationreferencewidget.h

+3-2
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ class GUI_EXPORT QgsRelationReferenceWidget : public QWidget
7979
void highlightActionTriggered( QAction* action );
8080
void deleteHighlight();
8181
void openForm();
82-
void mapIdentificationTriggered( QAction* action );
82+
void mapIdentification();
8383
void comboReferenceChanged( int index );
8484
void deleteForeignKey();
8585
void featureIdentified( const QgsFeature& feature );
@@ -119,14 +119,15 @@ class GUI_EXPORT QgsRelationReferenceWidget : public QWidget
119119
QVBoxLayout* mTopLayout;
120120
QHash<QgsFeatureId, QVariant> mFidFkMap; // Mapping from feature id => foreign key
121121
QToolButton* mMapIdentificationButton;
122+
QToolButton* mRemoveFKButton;
122123
QToolButton* mOpenFormButton;
123124
QToolButton* mHighlightFeatureButton;
124125
QAction* mHighlightFeatureAction;
125126
QAction* mScaleHighlightFeatureAction;
126127
QAction* mPanHighlightFeatureAction;
127128
QAction* mOpenFormAction;
128129
QAction* mMapIdentificationAction;
129-
QAction* mRemoveFeatureAction;
130+
QAction* mRemoveFKAction;
130131
QComboBox* mComboBox;
131132
QgsCollapsibleGroupBox* mAttributeEditorFrame;
132133
QVBoxLayout* mAttributeEditorLayout;

0 commit comments

Comments
 (0)