Skip to content
Permalink
Browse files

[relations] Preview expression from relation reference field config d…

…ialog

Fix #9538
  • Loading branch information
m-kuhn committed Feb 18, 2014
1 parent 517b859 commit 5e21c55d2b6358da0a8b61beb490ea0dd5f26a0c
@@ -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,28 +7,45 @@
<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">
<string>Display expression</string>
</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="1" column="1">
<widget class="QComboBox" name="mComboRelation"/>
</item>
<item row="3" column="0" colspan="2">
<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>

0 comments on commit 5e21c55

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