QGIS API Documentation  2.8.6-Wien
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 }
Base class for all map layer types.
Definition: qgsmaplayer.h:49
This class should be subclassed for every configurable editor widget type.
QgsEditorWidgetConfig config() override
Create a configuration from the current GUI state.
static QgsMapLayerRegistry * instance()
Definition: qgssingleton.h:23
QgsValueRelationConfigDlg(QgsVectorLayer *vl, int fieldIdx, QWidget *parent=0)
QMap< QString, QVariant > QgsEditorWidgetConfig
Holds a set of configuration parameters for a editor widget wrapper.
QgsMapLayer * mapLayer(QString theLayerId)
Retrieve a pointer to a loaded layer by id.
Represents a vector layer which manages a vector based data sets.
A generic dialog for building expression strings.
void setConfig(const QgsEditorWidgetConfig &config) override
Update the configuration widget to represent the given configuration.
#define tr(sourceText)