QGIS API Documentation  2.10.1-Pisa
 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() ? mLayerName->currentLayer()->id() : QString() );
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  cfg.insert( "UseCompleter", mUseCompleter->isChecked() );
43 
44  return cfg;
45 }
46 
48 {
49  QgsVectorLayer* lyr = qobject_cast<QgsVectorLayer*>( QgsMapLayerRegistry::instance()->mapLayer( config.value( "Layer" ).toString() ) );
50  mLayerName->setLayer( lyr );
51  mKeyColumn->setField( config.value( "Key" ).toString() );
52  mValueColumn->setField( config.value( "Value" ).toString() );
53  mAllowMulti->setChecked( config.value( "AllowMulti" ).toBool() );
54  mAllowNull->setChecked( config.value( "AllowNull" ).toBool() );
55  mOrderByValue->setChecked( config.value( "OrderByValue" ).toBool() );
56  mFilterExpression->setPlainText( config.value( "FilterExpression" ).toString() );
57  mUseCompleter->setChecked( config.value( "UseCompleter" ).toBool() );
58 }
59 
61 {
62  QgsVectorLayer *vl = qobject_cast<QgsVectorLayer*>( mLayerName->currentLayer() );
63  if ( !vl )
64  return;
65 
66  QgsExpressionBuilderDialog dlg( vl, mFilterExpression->toPlainText(), this );
67  dlg.setWindowTitle( tr( "Edit filter expression" ) );
68 
69  if ( dlg.exec() == QDialog::Accepted )
70  {
71  mFilterExpression->setText( dlg.expressionBuilder()->expressionText() );
72  }
73 }
Base class for all map layer types.
Definition: qgsmaplayer.h:49
void setupUi(QWidget *widget)
This class should be subclassed for every configurable editor widget type.
QgsEditorWidgetConfig config() override
Create a configuration from the current GUI state.
QString tr(const char *sourceText, const char *disambiguation, int n)
static QgsMapLayerRegistry * instance()
Returns the instance pointer, creating the object on the first call.
QgsValueRelationConfigDlg(QgsVectorLayer *vl, int fieldIdx, QWidget *parent=0)
void setWindowTitle(const QString &)
QgsMapLayer * mapLayer(QString theLayerId)
Retrieve a pointer to a loaded layer by id.
iterator insert(const Key &key, const T &value)
bool connect(const QObject *sender, const char *signal, const QObject *receiver, const char *method, Qt::ConnectionType type)
Represents a vector layer which manages a vector based data sets.
A generic dialog for building expression strings.
const T value(const Key &key) const
void setConfig(const QgsEditorWidgetConfig &config) override
Update the configuration widget to represent the given configuration.