QGIS API Documentation  2.14.0-Essen
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 at opengis 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  filterFields.reserve( fieldNodes.size() );
57  for ( int i = 0; i < fieldNodes.size(); i++ )
58  {
59  QDomElement fieldElement = fieldNodes.at( i ).toElement();
60  filterFields << fieldElement.attribute( "name" );
61  }
62  cfg.insert( "FilterFields", filterFields );
63 
64  cfg.insert( "ChainFilters", filterNode.toElement().attribute( "ChainFilters" ) == "1" );
65  }
66  return cfg;
67 }
68 
69 void QgsRelationReferenceFactory::writeConfig( const QgsEditorWidgetConfig& config, QDomElement& configElement, QDomDocument& doc, const QgsVectorLayer* layer, int fieldIdx )
70 {
71  Q_UNUSED( doc );
72  Q_UNUSED( layer );
73  Q_UNUSED( fieldIdx );
74 
75  configElement.setAttribute( "AllowNULL", config["AllowNULL"].toBool() );
76  configElement.setAttribute( "OrderByValue", config["OrderByValue"].toBool() );
77  configElement.setAttribute( "ShowForm", config["ShowForm"].toBool() );
78  configElement.setAttribute( "Relation", config["Relation"].toString() );
79  configElement.setAttribute( "MapIdentification", config["MapIdentification"].toBool() );
80  configElement.setAttribute( "ReadOnly", config["ReadOnly"].toBool() );
81 
82  if ( config.contains( "FilterFields" ) )
83  {
84  QDomElement filterFields = doc.createElement( "FilterFields" );
85 
86  Q_FOREACH ( const QString& field, config["FilterFields"].toStringList() )
87  {
88  QDomElement fieldElem = doc.createElement( "field" );
89  fieldElem.setAttribute( "name", field );
90  filterFields.appendChild( fieldElem );
91  }
92  configElement.appendChild( filterFields );
93 
94  filterFields.setAttribute( "ChainFilters", config["ChainFilters"].toBool() );
95  }
96 }
97 
99 {
101  map.insert( QgsRelationReferenceWidget::staticMetaObject.className(), 10 );
102  return map;
103 }
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.
void reserve(int alloc)
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
virtual QMap< const char *, int > supportedWidgetTypes() override
Returns a list of widget types which this editor widget supports.
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.
QgsRelationReferenceFactory(const QString &name, QgsMapCanvas *canvas, QgsMessageBar *messageBar)
bool isNull() const
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