QGIS API Documentation  2.10.1-Pisa
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
qgsrelationreferencefactory.cpp
Go to the documentation of this file.
1 /***************************************************************************
2  qgsrelationreferencefactory.cpp
3  --------------------------------------
4  Date : 29.5.2013
5  Copyright : (C) 2013 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 
20 
22  : QgsEditorWidgetFactory( name )
23  , mCanvas( canvas )
24  , mMessageBar( messageBar )
25 {
26 }
27 
29 {
30  return new QgsRelationReferenceWidgetWrapper( vl, fieldIdx, editor, mCanvas, mMessageBar, parent );
31 }
32 
34 {
35  return new QgsRelationReferenceConfigDlg( vl, fieldIdx, parent );
36 }
37 
39 {
40  Q_UNUSED( layer );
41  Q_UNUSED( fieldIdx );
43 
44  cfg.insert( "AllowNULL", configElement.attribute( "AllowNULL" ) == "1" );
45  cfg.insert( "OrderByValue", configElement.attribute( "OrderByValue" ) == "1" );
46  cfg.insert( "ShowForm", configElement.attribute( "ShowForm" ) == "1" );
47  cfg.insert( "Relation", configElement.attribute( "Relation" ) );
48  cfg.insert( "MapIdentification", configElement.attribute( "MapIdentification" ) == "1" );
49  cfg.insert( "ReadOnly", configElement.attribute( "ReadOnly" ) == "1" );
50 
51  QDomNode filterNode = configElement.elementsByTagName( "FilterFields" ).at( 0 );
52  if ( !filterNode.isNull() )
53  {
54  QStringList filterFields;
55  QDomNodeList fieldNodes = filterNode.toElement().elementsByTagName( "field" );
56  for ( int i = 0; i < fieldNodes.size(); i++ )
57  {
58  QDomElement fieldElement = fieldNodes.at( i ).toElement();
59  filterFields << fieldElement.attribute( "name" );
60  }
61  cfg.insert( "FilterFields", filterFields );
62 
63  cfg.insert( "ChainFilters", filterNode.toElement().attribute( "ChainFilters" ) == "1" );
64  }
65  return cfg;
66 }
67 
68 void QgsRelationReferenceFactory::writeConfig( const QgsEditorWidgetConfig& config, QDomElement& configElement, QDomDocument& doc, const QgsVectorLayer* layer, int fieldIdx )
69 {
70  Q_UNUSED( doc );
71  Q_UNUSED( layer );
72  Q_UNUSED( fieldIdx );
73 
74  configElement.setAttribute( "AllowNULL", config["AllowNULL"].toBool() );
75  configElement.setAttribute( "OrderByValue", config["OrderByValue"].toBool() );
76  configElement.setAttribute( "ShowForm", config["ShowForm"].toBool() );
77  configElement.setAttribute( "Relation", config["Relation"].toString() );
78  configElement.setAttribute( "MapIdentification", config["MapIdentification"].toBool() );
79  configElement.setAttribute( "ReadOnly", config["ReadOnly"].toBool() );
80 
81  if ( config.contains( "FilterFields" ) )
82  {
83  QDomElement filterFields = doc.createElement( "FilterFields" );
84 
85  Q_FOREACH ( const QString& field, config["FilterFields"].toStringList() )
86  {
87  QDomElement fieldElem = doc.createElement( "field" );
88  fieldElem.setAttribute( "name", field );
89  filterFields.appendChild( fieldElem );
90  }
91  configElement.appendChild( filterFields );
92 
93  filterFields.setAttribute( "ChainFilters", config["ChainFilters"].toBool() );
94  }
95 }
virtual QgsEditorConfigWidget * configWidget(QgsVectorLayer *vl, int fieldIdx, QWidget *parent) const override
Override this in your implementation.
QDomNodeList elementsByTagName(const QString &tagname) const
bool contains(const Key &key) const
This class should be subclassed for every configurable editor widget type.
QDomNode appendChild(const QDomNode &newChild)
QString attribute(const QString &name, const QString &defValue) const
Manages an editor widget Widget and wrapper share the same parent.
A bar for displaying non-blocking messages to the user.
Definition: qgsmessagebar.h:42
virtual void writeConfig(const QgsEditorWidgetConfig &config, QDomElement &configElement, QDomDocument &doc, const QgsVectorLayer *layer, int fieldIdx) override
Serialize your configuration and save it in a xml doc.
Map canvas is a class for displaying all GIS data types on a canvas.
Definition: qgsmapcanvas.h:105
QDomElement toElement() const
void setAttribute(const QString &name, const QString &value)
Every attribute editor widget needs a factory, which inherits this class.
virtual QgsEditorWidgetConfig readConfig(const QDomElement &configElement, QgsVectorLayer *layer, int fieldIdx) override
Read the config from an XML file and map it to a proper QgsEditorWidgetConfig.
bool isNull() const
QgsRelationReferenceFactory(QString name, QgsMapCanvas *canvas, QgsMessageBar *messageBar)
iterator insert(const Key &key, const T &value)
int size() const
QDomElement createElement(const QString &tagName)
Represents a vector layer which manages a vector based data sets.
virtual QgsEditorWidgetWrapper * create(QgsVectorLayer *vl, int fieldIdx, QWidget *editor, QWidget *parent) const override
Override this in your implementation.
QDomNode at(int index) const