Skip to content
Permalink
Browse files

[needs-docs] Relation Reference Widget: Add option to show/hide the O…

…pen Form Button

The option was already available in the API (QgsRelationReferenceWidget->setOpenFormButtonVisible), but couldn't be used from QgsEditorWidgetSetup nor from the config dialog. For the former, a 'ShowOpenFormButton' key is added, whereas for the latter, a new checkbox is available.

Being able to hide the Open Form Button is helpful when configuring lookup tables, where a single combo box should be shown in the edit form with no additional buttons.
  • Loading branch information
gacarrillor committed Jul 30, 2017
1 parent 45fc00a commit 91e39a7a9562b07b05cfedf33abf11fa0f5fc268
@@ -44,6 +44,7 @@ QgsRelationReferenceConfigDlg::QgsRelationReferenceConfigDlg( QgsVectorLayer *vl
connect( mCbxAllowNull, &QAbstractButton::toggled, this, &QgsEditorConfigWidget::changed );
connect( mCbxOrderByValue, &QAbstractButton::toggled, this, &QgsEditorConfigWidget::changed );
connect( mCbxShowForm, &QAbstractButton::toggled, this, &QgsEditorConfigWidget::changed );
connect( mCbxShowOpenFormButton, &QAbstractButton::toggled, this, &QgsEditorConfigWidget::changed );
connect( mCbxMapIdentification, &QAbstractButton::toggled, this, &QgsEditorConfigWidget::changed );
connect( mCbxReadOnly, &QAbstractButton::toggled, this, &QgsEditorConfigWidget::changed );
connect( mComboRelation, static_cast<void ( QComboBox::* )( int )>( &QComboBox::currentIndexChanged ), this, &QgsEditorConfigWidget::changed );
@@ -59,6 +60,7 @@ void QgsRelationReferenceConfigDlg::setConfig( const QVariantMap &config )
mCbxAllowNull->setChecked( config.value( QStringLiteral( "AllowNULL" ), false ).toBool() );
mCbxOrderByValue->setChecked( config.value( QStringLiteral( "OrderByValue" ), false ).toBool() );
mCbxShowForm->setChecked( config.value( QStringLiteral( "ShowForm" ), false ).toBool() );
mCbxShowOpenFormButton->setChecked( config.value( QStringLiteral( "ShowOpenFormButton" ), true ).toBool() );

if ( config.contains( QStringLiteral( "Relation" ) ) )
{
@@ -121,6 +123,7 @@ QVariantMap QgsRelationReferenceConfigDlg::config()
myConfig.insert( QStringLiteral( "AllowNULL" ), mCbxAllowNull->isChecked() );
myConfig.insert( QStringLiteral( "OrderByValue" ), mCbxOrderByValue->isChecked() );
myConfig.insert( QStringLiteral( "ShowForm" ), mCbxShowForm->isChecked() );
myConfig.insert( QStringLiteral( "ShowOpenFormButton" ), mCbxShowOpenFormButton->isChecked() );
myConfig.insert( QStringLiteral( "MapIdentification" ), mCbxMapIdentification->isEnabled() && mCbxMapIdentification->isChecked() );
myConfig.insert( QStringLiteral( "ReadOnly" ), mCbxReadOnly->isChecked() );
myConfig.insert( QStringLiteral( "Relation" ), mComboRelation->currentData() );
@@ -50,11 +50,13 @@ void QgsRelationReferenceWidgetWrapper::initWidget( QWidget *editor )
bool mapIdent = config( QStringLiteral( "MapIdentification" ), false ).toBool();
bool readOnlyWidget = config( QStringLiteral( "ReadOnly" ), false ).toBool();
bool orderByValue = config( QStringLiteral( "OrderByValue" ), false ).toBool();
bool showOpenFormButton = config( QStringLiteral( "ShowOpenFormButton" ), true ).toBool();

mWidget->setEmbedForm( showForm );
mWidget->setReadOnlySelector( readOnlyWidget );
mWidget->setAllowMapIdentification( mapIdent );
mWidget->setOrderByValue( orderByValue );
mWidget->setOpenFormButtonVisible( showOpenFormButton );
if ( config( QStringLiteral( "FilterFields" ), QVariant() ).isValid() )
{
mWidget->setFilterFields( config( QStringLiteral( "FilterFields" ) ).toStringList() );
@@ -21,6 +21,13 @@
</property>
</widget>
</item>
<item row="5" column="0" colspan="2">
<widget class="QCheckBox" name="mCbxShowOpenFormButton">
<property name="text">
<string>Show open form button</string>
</property>
</widget>
</item>
<item row="1" column="1">
<widget class="QComboBox" name="mComboRelation"/>
</item>
@@ -31,7 +38,7 @@
</property>
</widget>
</item>
<item row="6" column="0" colspan="2">
<item row="7" column="0" colspan="2">
<widget class="QCheckBox" name="mCbxReadOnly">
<property name="text">
<string>Use a read-only line edit instead of a combobox</string>
@@ -59,7 +66,7 @@
</property>
</widget>
</item>
<item row="5" column="0" colspan="2">
<item row="6" column="0" colspan="2">
<widget class="QCheckBox" name="mCbxMapIdentification">
<property name="text">
<string>On map identification (for geometric layers only)</string>
@@ -73,7 +80,7 @@
</property>
</widget>
</item>
<item row="8" column="0" colspan="2">
<item row="9" column="0" colspan="2">
<widget class="QgsCollapsibleGroupBox" name="mFilterGroupBox">
<property name="title">
<string>Filters</string>
@@ -152,7 +159,7 @@
</layout>
</widget>
</item>
<item row="7" column="0" colspan="2">
<item row="8" column="0" colspan="2">
<widget class="QCheckBox" name="mCbxAllowAddFeatures">
<property name="text">
<string>Allow adding new features</string>
@@ -181,6 +188,7 @@
<tabstop>mCbxAllowNull</tabstop>
<tabstop>mCbxOrderByValue</tabstop>
<tabstop>mCbxShowForm</tabstop>
<tabstop>mCbxShowOpenFormButton</tabstop>
<tabstop>mCbxMapIdentification</tabstop>
<tabstop>mCbxReadOnly</tabstop>
<tabstop>mCbxAllowAddFeatures</tabstop>

0 comments on commit 91e39a7

Please sign in to comment.
You can’t perform that action at this time.