Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
[QgsRelationReferenceWidget] correctly enable/disable set null button…
…, do not disable line edit (already read only), make openForm and mapIdentification public, more documentation
  • Loading branch information
3nids committed Sep 17, 2014
1 parent 21c81d6 commit 096d941
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 6 deletions.
10 changes: 10 additions & 0 deletions python/gui/editorwidgets/qgsrelationreferencewidget.sip
Expand Up @@ -29,18 +29,28 @@ class QgsRelationReferenceWidget : QWidget

void setEditorContext( QgsAttributeEditorContext context, QgsMapCanvas* canvas, QgsMessageBar* messageBar );

//! determines if the form of the related feature will be shown
bool embedForm();
void setEmbedForm( bool display );

//! determines if the foreign key is shown in a combox box or a read-only line edit
bool readOnlySelector();
void setReadOnlySelector( bool readOnly );

//! determines if the widge offers the possibility to select the related feature on the map (using a dedicated map tool)
bool allowMapIdentification();
void setAllowMapIdentification( bool allowMapIdentification );

//! determines the open form button is visible in the widget
bool openFormButtonVisible();
void setOpenFormButtonVisible( bool openFormButtonVisible );

public slots:
//! open the form of the related feature in a new dialog
void openForm();
//! activate the map tool to select the related feature on the map
void mapIdentification();

protected:
virtual void showEvent( QShowEvent* e );

Expand Down
9 changes: 5 additions & 4 deletions src/gui/editorwidgets/qgsrelationreferencewidget.cpp
Expand Up @@ -52,6 +52,7 @@ QgsRelationReferenceWidget::QgsRelationReferenceWidget( QWidget* parent )
, mReferencingLayer( NULL )
, mWindowWidget( NULL )
, mShown( false )
, mIsEditable( true )
, mEmbedForm( false )
, mReadOnlySelector( false )
, mAllowMapIdentification( false )
Expand Down Expand Up @@ -181,10 +182,10 @@ void QgsRelationReferenceWidget::setRelation( QgsRelation relation, bool allowNu

void QgsRelationReferenceWidget::setRelationEditable( bool editable )
{
mLineEdit->setEnabled( editable );
mComboBox->setEnabled( editable );
mMapIdentificationButton->setEnabled( editable );
mRemoveFKButton->setEnabled( editable );
mIsEditable = editable;
}

void QgsRelationReferenceWidget::setForeignKey( const QVariant& value )
Expand Down Expand Up @@ -235,7 +236,7 @@ void QgsRelationReferenceWidget::setForeignKey( const QVariant& value )
}
}

mRemoveFKButton->setEnabled( true );
mRemoveFKButton->setEnabled( mIsEditable );
highlightFeature( f );
updateAttributeEditorFrame( f );
emit foreignKeyChanged( foreignKey() );
Expand Down Expand Up @@ -508,7 +509,7 @@ void QgsRelationReferenceWidget::deleteHighlight()

void QgsRelationReferenceWidget::mapIdentification()
{
if ( !mReferencedLayer )
if ( !mAllowMapIdentification || !mReferencedLayer )
return;

const QgsVectorLayerTools* tools = mEditorContext.vectorLayerTools();
Expand Down Expand Up @@ -570,7 +571,7 @@ void QgsRelationReferenceWidget::featureIdentified( const QgsFeature& feature )
mComboBox->setCurrentIndex( mComboBox->findData( feature.attribute( mFkeyFieldIdx ) ) );
}

mRemoveFKButton->setEnabled( true );
mRemoveFKButton->setEnabled( mIsEditable );
highlightFeature( feature );
updateAttributeEditorFrame( feature );
emit foreignKeyChanged( foreignKey() );
Expand Down
13 changes: 11 additions & 2 deletions src/gui/editorwidgets/qgsrelationreferencewidget.h
Expand Up @@ -59,18 +59,28 @@ class GUI_EXPORT QgsRelationReferenceWidget : public QWidget

void setEditorContext( QgsAttributeEditorContext context, QgsMapCanvas* canvas, QgsMessageBar* messageBar );

//! determines if the form of the related feature will be shown
bool embedForm() {return mEmbedForm;}
void setEmbedForm( bool display );

//! determines if the foreign key is shown in a combox box or a read-only line edit
bool readOnlySelector() {return mReadOnlySelector;}
void setReadOnlySelector( bool readOnly );

//! determines if the widge offers the possibility to select the related feature on the map (using a dedicated map tool)
bool allowMapIdentification() {return mAllowMapIdentification;}
void setAllowMapIdentification( bool allowMapIdentification );

//! determines the open form button is visible in the widget
bool openFormButtonVisible() {return mOpenFormButtonVisible;}
void setOpenFormButtonVisible( bool openFormButtonVisible );

public slots:
//! open the form of the related feature in a new dialog
void openForm();
//! activate the map tool to select the related feature on the map
void mapIdentification();

protected:
virtual void showEvent( QShowEvent* e );

Expand All @@ -82,8 +92,6 @@ class GUI_EXPORT QgsRelationReferenceWidget : public QWidget
private slots:
void highlightActionTriggered( QAction* action );
void deleteHighlight();
void openForm();
void mapIdentification();
void comboReferenceChanged( int index );
void deleteForeignKey();
void featureIdentified( const QgsFeature& feature );
Expand Down Expand Up @@ -113,6 +121,7 @@ class GUI_EXPORT QgsRelationReferenceWidget : public QWidget
QWidget* mWindowWidget;
bool mShown;
QgsRelation mRelation;
bool mIsEditable;

// Q_PROPERTY
bool mEmbedForm;
Expand Down

0 comments on commit 096d941

Please sign in to comment.