mirror of
https://github.com/qgis/QGIS.git
synced 2025-03-01 00:46:20 -05:00
[relations] Preview expression from relation reference field config dialog
Fix #9538
This commit is contained in:
parent
517b85937e
commit
5e21c55d2b
@ -20,6 +20,7 @@
|
||||
#include "qgsproject.h"
|
||||
#include "qgsrelationmanager.h"
|
||||
#include "qgsvectorlayer.h"
|
||||
#include "qgsexpressionbuilderdialog.h"
|
||||
|
||||
QgsRelReferenceConfigDlg::QgsRelReferenceConfigDlg( QgsVectorLayer* vl, int fieldIdx, QWidget* parent )
|
||||
: QgsEditorConfigWidget( vl, fieldIdx, parent )
|
||||
@ -28,13 +29,14 @@ QgsRelReferenceConfigDlg::QgsRelReferenceConfigDlg( QgsVectorLayer* vl, int fiel
|
||||
|
||||
foreach ( const QgsRelation& relation, vl->referencingRelations( fieldIdx ) )
|
||||
{
|
||||
QgsField fld = relation.fieldPairs().first().second;
|
||||
mComboRelation->addItem( QString( "%1 (%2)" ).arg( relation.id(), relation.referencedLayerId() ), relation.id() );
|
||||
if ( relation.referencedLayer() )
|
||||
{
|
||||
mTxtDisplayExpression->setText( relation.referencedLayer()->displayExpression() );
|
||||
}
|
||||
}
|
||||
|
||||
connect( mPbnPreviewExpression, SIGNAL( clicked() ), this, SLOT( previewExpressionBuilder() ) );
|
||||
}
|
||||
|
||||
void QgsRelReferenceConfigDlg::setConfig( const QMap<QString, QVariant>& config )
|
||||
@ -74,5 +76,28 @@ QgsEditorWidgetConfig QgsRelReferenceConfigDlg::config()
|
||||
myConfig.insert( "ShowForm", mCbxShowForm->isChecked() );
|
||||
myConfig.insert( "Relation", mComboRelation->itemData( mComboRelation->currentIndex() ) );
|
||||
|
||||
QString relName = mComboRelation->itemData( mComboRelation->currentIndex() ).toString();
|
||||
QgsRelation relation = QgsProject::instance()->relationManager()->relation( relName );
|
||||
|
||||
if ( relation.isValid() )
|
||||
{
|
||||
relation.referencedLayer()->setDisplayExpression( mTxtDisplayExpression->text() );
|
||||
}
|
||||
|
||||
return myConfig;
|
||||
}
|
||||
|
||||
void QgsRelReferenceConfigDlg::previewExpressionBuilder()
|
||||
{
|
||||
QString relName = mComboRelation->itemData( mComboRelation->currentIndex() ).toString();
|
||||
QgsRelation relation = QgsProject::instance()->relationManager()->relation( relName );
|
||||
|
||||
// Show expression builder
|
||||
QgsExpressionBuilderDialog dlg( relation.referencedLayer(), mTxtDisplayExpression->text() , this );
|
||||
dlg.setWindowTitle( tr( "Preview Expression" ) );
|
||||
|
||||
if ( dlg.exec() == QDialog::Accepted )
|
||||
{
|
||||
mTxtDisplayExpression->setText( dlg.expressionText() );
|
||||
}
|
||||
}
|
||||
|
@ -30,6 +30,8 @@ class GUI_EXPORT QgsRelReferenceConfigDlg : public QgsEditorConfigWidget, privat
|
||||
|
||||
private slots:
|
||||
void on_mComboRelation_indexChanged( int idx );
|
||||
void previewExpressionBuilder();
|
||||
|
||||
};
|
||||
|
||||
#endif // QGSRELREFERENCECONFIGDLGBASE_H
|
||||
|
@ -7,13 +7,16 @@
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>400</width>
|
||||
<height>175</height>
|
||||
<height>176</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="windowTitle">
|
||||
<string>Dialog</string>
|
||||
</property>
|
||||
<layout class="QFormLayout" name="formLayout">
|
||||
<property name="fieldGrowthPolicy">
|
||||
<enum>QFormLayout::AllNonFixedFieldsGrow</enum>
|
||||
</property>
|
||||
<item row="0" column="0">
|
||||
<widget class="QLabel" name="label">
|
||||
<property name="text">
|
||||
@ -21,14 +24,28 @@
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="2" column="0" colspan="2">
|
||||
<widget class="QCheckBox" name="mCbxAllowNull">
|
||||
<property name="text">
|
||||
<string>Allow NULL value</string>
|
||||
</property>
|
||||
</widget>
|
||||
<item row="0" column="1">
|
||||
<layout class="QHBoxLayout" name="horizontalLayout">
|
||||
<item>
|
||||
<widget class="QLineEdit" name="mTxtDisplayExpression"/>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QToolButton" name="mPbnPreviewExpression">
|
||||
<property name="text">
|
||||
<string>Expression Builder</string>
|
||||
</property>
|
||||
<property name="icon">
|
||||
<iconset resource="../../../images/images.qrc">
|
||||
<normaloff>:/images/themes/default/mIconExpressionEditorOpen.svg</normaloff>:/images/themes/default/mIconExpressionEditorOpen.svg</iconset>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
<item row="3" column="0" colspan="2">
|
||||
<item row="1" column="1">
|
||||
<widget class="QComboBox" name="mComboRelation"/>
|
||||
</item>
|
||||
<item row="7" column="0">
|
||||
<widget class="QCheckBox" name="mCbxShowForm">
|
||||
<property name="text">
|
||||
<string>Show embedded form</string>
|
||||
@ -42,14 +59,17 @@
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="1" column="1">
|
||||
<widget class="QComboBox" name="mComboRelation"/>
|
||||
</item>
|
||||
<item row="0" column="1">
|
||||
<widget class="QLineEdit" name="mTxtDisplayExpression"/>
|
||||
<item row="6" column="0">
|
||||
<widget class="QCheckBox" name="mCbxAllowNull">
|
||||
<property name="text">
|
||||
<string>Allow NULL value</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
<resources/>
|
||||
<resources>
|
||||
<include location="../../../images/images.qrc"/>
|
||||
</resources>
|
||||
<connections/>
|
||||
</ui>
|
||||
|
Loading…
x
Reference in New Issue
Block a user