QGIS API Documentation  2.8.6-Wien
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 
28 QgsEditorWidgetWrapper* QgsRelationReferenceFactory::create( QgsVectorLayer* vl, int fieldIdx, QWidget* editor, QWidget* parent ) const
29 {
30  return new QgsRelationReferenceWidgetWrapper( vl, fieldIdx, editor, mCanvas, mMessageBar, parent );
31 }
32 
34 {
35  return new QgsRelationReferenceConfigDlg( vl, fieldIdx, parent );
36 }
37 
38 QgsEditorWidgetConfig QgsRelationReferenceFactory::readConfig( const QDomElement& configElement, QgsVectorLayer* layer, int fieldIdx )
39 {
40  Q_UNUSED( layer );
41  Q_UNUSED( fieldIdx );
42  QMap<QString, QVariant> cfg;
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  return cfg;
52 }
53 
54 void QgsRelationReferenceFactory::writeConfig( const QgsEditorWidgetConfig& config, QDomElement& configElement, QDomDocument& doc, const QgsVectorLayer* layer, int fieldIdx )
55 {
56  Q_UNUSED( doc );
57  Q_UNUSED( layer );
58  Q_UNUSED( fieldIdx );
59 
60  configElement.setAttribute( "AllowNULL", config["AllowNULL"].toBool() );
61  configElement.setAttribute( "OrderByValue", config["OrderByValue"].toBool() );
62  configElement.setAttribute( "ShowForm", config["ShowForm"].toBool() );
63  configElement.setAttribute( "Relation", config["Relation"].toString() );
64  configElement.setAttribute( "MapIdentification", config["MapIdentification"].toBool() );
65  configElement.setAttribute( "ReadOnly", config["ReadOnly"].toBool() );
66 }
virtual QgsEditorConfigWidget * configWidget(QgsVectorLayer *vl, int fieldIdx, QWidget *parent) const override
Override this in your implementation.
This class should be subclassed for every configurable editor widget type.
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
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(QString name, QgsMapCanvas *canvas, QgsMessageBar *messageBar)
QMap< QString, QVariant > QgsEditorWidgetConfig
Holds a set of configuration parameters for a editor widget wrapper.
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.