QGIS API Documentation  2.17.0-Master (dfeb663)
Classes | Public Member Functions | Static Public Member Functions | Protected Member Functions | List of all members
QgsRelation Class Reference

#include <qgsrelation.h>

Classes

class  FieldPair
 Defines a relation between matching fields of the two involved tables of a relation. More...
 

Public Member Functions

 QgsRelation ()
 Default constructor. More...
 
void addFieldPair (const QString &referencingField, const QString &referencedField)
 Add a field pairs which is part of this relation The first element of each pair are the field names of the foreign key. More...
 
void addFieldPair (const FieldPair &fieldPair)
 Add a field pairs which is part of this relation The first element of each pair are the field names of the foreign key. More...
 
QList< FieldPairfieldPairs () const
 Returns the field pairs which form this relation The first element of each pair are the field names of the foreign key. More...
 
QgsFeature getReferencedFeature (const QgsFeature &feature) const
 Creates a request to return the feature on the referenced (parent) layer which is referenced by the provided feature. More...
 
QgsFeatureRequest getReferencedFeatureRequest (const QgsAttributes &attributes) const
 Creates a request to return the feature on the referenced (parent) layer which is referenced by the provided feature. More...
 
QgsFeatureRequest getReferencedFeatureRequest (const QgsFeature &feature) const
 Creates a request to return the feature on the referenced (parent) layer which is referenced by the provided feature. More...
 
QgsFeatureIterator getRelatedFeatures (const QgsFeature &feature) const
 Creates an iterator which returns all the features on the referencing (child) layer which have a foreign key pointing to the provided feature. More...
 
QString getRelatedFeaturesFilter (const QgsFeature &feature) const
 Returns a filter expression which returns all the features on the referencing (child) layer which have a foreign key pointing to the provided feature. More...
 
QgsFeatureRequest getRelatedFeaturesRequest (const QgsFeature &feature) const
 Creates a request to return all the features on the referencing (child) layer which have a foreign key pointing to the provided feature. More...
 
QString id () const
 A (project-wide) unique id for this relation. More...
 
bool isValid () const
 Returns the validity of this relation. More...
 
QString name () const
 Returns a human readable name for this relation. More...
 
QgsAttributeList referencedFields () const
 Returns a list of attributes used to form the referenced fields (most likely primary key) on the referenced (parent) layer. More...
 
QgsVectorLayerreferencedLayer () const
 Access the referenced (parent) layer. More...
 
QString referencedLayerId () const
 Access the referenced (parent) layer's id. More...
 
QgsAttributeList referencingFields () const
 Returns a list of attributes used to form the referencing fields (foreign key) on the referencing (child) layer. More...
 
QgsVectorLayerreferencingLayer () const
 Access the referencing (child) layer This is the layer which has the field(s) which point to another layer. More...
 
QString referencingLayerId () const
 Access the referencing (child) layer's id This is the layer which has the field(s) which point to another layer. More...
 
void setReferencedLayer (const QString &id)
 Set the referenced (parent) layer id. More...
 
void setReferencingLayer (const QString &id)
 Set the referencing (child) layer id. More...
 
void setRelationId (const QString &id)
 Set a name for this relation. More...
 
void setRelationName (const QString &name)
 Set a name for this relation. More...
 
void writeXML (QDomNode &node, QDomDocument &doc) const
 Writes a relation to an XML structure. More...
 

Static Public Member Functions

static QgsRelation createFromXML (const QDomNode &node)
 Creates a relation from an XML structure. More...
 

Protected Member Functions

void updateRelationStatus ()
 Updates the validity status of this relation. More...
 

Detailed Description

Definition at line 31 of file qgsrelation.h.

Constructor & Destructor Documentation

§ QgsRelation()

QgsRelation::QgsRelation ( )

Default constructor.

Creates an invalid relation.

Definition at line 23 of file qgsrelation.cpp.

Member Function Documentation

§ addFieldPair() [1/2]

void QgsRelation::addFieldPair ( const QString referencingField,
const QString referencedField 
)

Add a field pairs which is part of this relation The first element of each pair are the field names of the foreign key.

The second element of each pair are the field names of the matching primary key.

Parameters
referencingFieldThe field name on the referencing (child) layer (FK)
referencedFieldThe field name on the referenced (parent) layer (PK)

Definition at line 137 of file qgsrelation.cpp.

§ addFieldPair() [2/2]

void QgsRelation::addFieldPair ( const FieldPair fieldPair)

Add a field pairs which is part of this relation The first element of each pair are the field names of the foreign key.

The second element of each pair are the field names of the matching primary key.

Parameters
fieldPairA pair of two strings
Note
not available in python bindings

Definition at line 143 of file qgsrelation.cpp.

§ createFromXML()

QgsRelation QgsRelation::createFromXML ( const QDomNode node)
static

Creates a relation from an XML structure.

Used for reading .qgs projects.

Parameters
nodeThe dom node containing the relation information
Returns
A relation

Definition at line 30 of file qgsrelation.cpp.

§ fieldPairs()

QList< QgsRelation::FieldPair > QgsRelation::fieldPairs ( ) const

Returns the field pairs which form this relation The first element of each pair are the field names of the foreign key.

The second element of each pair are the field names of the matching primary key.

Returns
The fields forming the relation

Definition at line 264 of file qgsrelation.cpp.

§ getReferencedFeature()

QgsFeature QgsRelation::getReferencedFeature ( const QgsFeature feature) const

Creates a request to return the feature on the referenced (parent) layer which is referenced by the provided feature.

Parameters
featureA feature from the referencing (child) layer
Returns
A request the referenced feature

Definition at line 225 of file qgsrelation.cpp.

§ getReferencedFeatureRequest() [1/2]

QgsFeatureRequest QgsRelation::getReferencedFeatureRequest ( const QgsAttributes attributes) const

Creates a request to return the feature on the referenced (parent) layer which is referenced by the provided feature.

Parameters
attributesAn attribute vector containing the foreign key
Returns
A request the referenced feature
Note
not available in python bindings

Definition at line 188 of file qgsrelation.cpp.

§ getReferencedFeatureRequest() [2/2]

QgsFeatureRequest QgsRelation::getReferencedFeatureRequest ( const QgsFeature feature) const

Creates a request to return the feature on the referenced (parent) layer which is referenced by the provided feature.

Parameters
featureA feature from the referencing (child) layer
Returns
A request the referenced feature

Definition at line 220 of file qgsrelation.cpp.

§ getRelatedFeatures()

QgsFeatureIterator QgsRelation::getRelatedFeatures ( const QgsFeature feature) const

Creates an iterator which returns all the features on the referencing (child) layer which have a foreign key pointing to the provided feature.

Parameters
featureA feature from the referenced (parent) layer
Returns
An iterator with all the referenced features
See also
getRelatedFeaturesRequest()
getRelatedFeaturesFilter()

Definition at line 149 of file qgsrelation.cpp.

§ getRelatedFeaturesFilter()

QString QgsRelation::getRelatedFeaturesFilter ( const QgsFeature feature) const

Returns a filter expression which returns all the features on the referencing (child) layer which have a foreign key pointing to the provided feature.

Parameters
featureA feature from the referenced (parent) layer
Returns
expression filter string for all the referencing features
Note
added in QGIS 2.16
See also
getRelatedFeatures()
getRelatedFeaturesRequest()

Definition at line 164 of file qgsrelation.cpp.

§ getRelatedFeaturesRequest()

QgsFeatureRequest QgsRelation::getRelatedFeaturesRequest ( const QgsFeature feature) const

Creates a request to return all the features on the referencing (child) layer which have a foreign key pointing to the provided feature.

Parameters
featureA feature from the referenced (parent) layer
Returns
A request for all the referencing features
See also
getRelatedFeatures()
getRelatedFeaturesFilter()

Definition at line 154 of file qgsrelation.cpp.

§ id()

QString QgsRelation::id ( ) const

A (project-wide) unique id for this relation.

Returns
The id

Definition at line 239 of file qgsrelation.cpp.

§ isValid()

bool QgsRelation::isValid ( ) const

Returns the validity of this relation.

Don't use the information if it's not valid.

Returns
true if the relation is valid

Definition at line 292 of file qgsrelation.cpp.

§ name()

QString QgsRelation::name ( ) const

Returns a human readable name for this relation.

Mostly used as title for the children.

See also
id()
Returns
A name

Definition at line 234 of file qgsrelation.cpp.

§ referencedFields()

QgsAttributeList QgsRelation::referencedFields ( ) const

Returns a list of attributes used to form the referenced fields (most likely primary key) on the referenced (parent) layer.

Returns
A list of attributes

Definition at line 269 of file qgsrelation.cpp.

§ referencedLayer()

QgsVectorLayer * QgsRelation::referencedLayer ( ) const

Access the referenced (parent) layer.

Returns
referenced layer

Definition at line 259 of file qgsrelation.cpp.

§ referencedLayerId()

QString QgsRelation::referencedLayerId ( ) const

Access the referenced (parent) layer's id.

Returns
The id of the referenced layer

Definition at line 254 of file qgsrelation.cpp.

§ referencingFields()

QgsAttributeList QgsRelation::referencingFields ( ) const

Returns a list of attributes used to form the referencing fields (foreign key) on the referencing (child) layer.

Returns
A list of attributes

Definition at line 280 of file qgsrelation.cpp.

§ referencingLayer()

QgsVectorLayer * QgsRelation::referencingLayer ( ) const

Access the referencing (child) layer This is the layer which has the field(s) which point to another layer.

Returns
The referencing layer

Definition at line 249 of file qgsrelation.cpp.

§ referencingLayerId()

QString QgsRelation::referencingLayerId ( ) const

Access the referencing (child) layer's id This is the layer which has the field(s) which point to another layer.

Returns
The id of the referencing layer

Definition at line 244 of file qgsrelation.cpp.

§ setReferencedLayer()

void QgsRelation::setReferencedLayer ( const QString id)

Set the referenced (parent) layer id.

This layer will be searched in the registry.

Parameters
id

Definition at line 130 of file qgsrelation.cpp.

§ setReferencingLayer()

void QgsRelation::setReferencingLayer ( const QString id)

Set the referencing (child) layer id.

This layer will be searched in the registry.

Parameters
id

Definition at line 123 of file qgsrelation.cpp.

§ setRelationId()

void QgsRelation::setRelationId ( const QString id)

Set a name for this relation.

Parameters
id

Definition at line 111 of file qgsrelation.cpp.

§ setRelationName()

void QgsRelation::setRelationName ( const QString name)

Set a name for this relation.

Parameters
name

Definition at line 118 of file qgsrelation.cpp.

§ updateRelationStatus()

void QgsRelation::updateRelationStatus ( )
protected

Updates the validity status of this relation.

Will be called internally whenever a member is changed.

Definition at line 297 of file qgsrelation.cpp.

§ writeXML()

void QgsRelation::writeXML ( QDomNode node,
QDomDocument doc 
) const

Writes a relation to an XML structure.

Used for saving .qgs projects

Parameters
nodeThe parent node in which the relation will be created
docThe document in which the relation will be saved

Definition at line 92 of file qgsrelation.cpp.


The documentation for this class was generated from the following files: