QGIS API Documentation  2.8.2-Wien
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
qgsvaluerelationconfigdlg.cpp
Go to the documentation of this file.
1 /***************************************************************************
2  qgsvaluerelationconfigdlg.cpp
3  --------------------------------------
4  Date : 5.1.2014
5  Copyright : (C) 2014 Matthias Kuhn
6  Email : matthias dot kuhn at gmx dot ch
7  ***************************************************************************
8  * *
9  * This program is free software; you can redistribute it and/or modify *
10  * it under the terms of the GNU General Public License as published by *
11  * the Free Software Foundation; either version 2 of the License, or *
12  * (at your option) any later version. *
13  * *
14  ***************************************************************************/
15 
17 #include "qgsmaplayerregistry.h"
18 #include "qgsvectorlayer.h"
20 
22  : QgsEditorConfigWidget( vl, fieldIdx, parent )
23 {
24  setupUi( this );
25  mLayerName->setFilters( QgsMapLayerProxyModel::VectorLayer );
26  connect( mLayerName, SIGNAL( layerChanged( QgsMapLayer* ) ), mKeyColumn, SLOT( setLayer( QgsMapLayer* ) ) );
27  connect( mLayerName, SIGNAL( layerChanged( QgsMapLayer* ) ), mValueColumn, SLOT( setLayer( QgsMapLayer* ) ) );
28  connect( mEditExpression, SIGNAL( clicked() ), this, SLOT( editExpression() ) );
29 }
30 
32 {
34 
35  cfg.insert( "Layer", mLayerName->currentLayer()->id() );
36  cfg.insert( "Key", mKeyColumn->currentField() );
37  cfg.insert( "Value", mValueColumn->currentField() );
38  cfg.insert( "AllowMulti", mAllowMulti->isChecked() );
39  cfg.insert( "AllowNull", mAllowNull->isChecked() );
40  cfg.insert( "OrderByValue", mOrderByValue->isChecked() );
41  cfg.insert( "FilterExpression", mFilterExpression->toPlainText() );
42 
43  return cfg;
44 }
45 
47 {
48  QgsVectorLayer* lyr = qobject_cast<QgsVectorLayer*>( QgsMapLayerRegistry::instance()->mapLayer( config.value( "Layer" ).toString() ) );
49  mLayerName->setLayer( lyr );
50  mKeyColumn->setField( config.value( "Key" ).toString() );
51  mValueColumn->setField( config.value( "Value" ).toString() );
52  mAllowMulti->setChecked( config.value( "AllowMulti" ).toBool() );
53  mAllowNull->setChecked( config.value( "AllowNull" ).toBool() );
54  mOrderByValue->setChecked( config.value( "OrderByValue" ).toBool() );
55  mFilterExpression->setPlainText( config.value( "FilterExpression" ).toString() );
56 }
57 
59 {
60  QgsVectorLayer *vl = qobject_cast<QgsVectorLayer*>( mLayerName->currentLayer() );
61  if ( !vl )
62  return;
63 
64  QgsExpressionBuilderDialog dlg( vl, mFilterExpression->toPlainText(), this );
65  dlg.setWindowTitle( tr( "Edit filter expression" ) );
66 
67  if ( dlg.exec() == QDialog::Accepted )
68  {
69  mFilterExpression->setText( dlg.expressionBuilder()->expressionText() );
70  }
71 }