24 : mReferencingLayer( nullptr )
25 , mReferencedLayer( nullptr )
34 if ( elem.
tagName() !=
"relation" )
51 if ( !referencingLayer )
60 if ( !referencedLayer )
73 relation.mRelationId =
id;
74 relation.mRelationName =
name;
77 for (
int i = 0; i < references.
size(); ++i )
84 relation.
addFieldPair( referencingField, referencedField );
97 elem.
setAttribute(
"referencingLayer", mReferencingLayerId );
98 elem.
setAttribute(
"referencedLayer", mReferencedLayerId );
100 Q_FOREACH (
const FieldPair& fields, mFieldPairs )
103 referenceElem.
setAttribute(
"referencingField", fields.first );
104 referenceElem.
setAttribute(
"referencedField", fields.second );
120 mRelationName =
name;
125 mReferencingLayerId =
id;
132 mReferencedLayerId =
id;
139 mFieldPairs <<
FieldPair( referencingField, referencedField );
145 mFieldPairs << fieldPair;
174 return conditions.
join(
" AND " );
191 myRequest.setFilterExpression( conditions.
join(
" AND " ) );
212 return mRelationName;
222 return mReferencingLayerId;
227 return mReferencingLayer;
232 return mReferencedLayerId;
237 return mReferencedLayer;
249 Q_FOREACH (
const FieldPair& pair, mFieldPairs )
260 Q_FOREACH (
const FieldPair& pair, mFieldPairs )
277 mReferencingLayer = qobject_cast<
QgsVectorLayer*>( mapLayers[mReferencingLayerId] );
278 mReferencedLayer = qobject_cast<
QgsVectorLayer*>( mapLayers[mReferencedLayerId] );
285 if ( !mReferencedLayer || !mReferencingLayer )
291 if ( mFieldPairs.count() < 1 )
296 Q_FOREACH (
const FieldPair& fieldPair, mFieldPairs )
299 || -1 == mReferencedLayer->fieldNameIndex( fieldPair.second ) )
Wrapper for iterator of features from vector data provider or vector layer.
QDomNodeList elementsByTagName(const QString &tagname) const
bool isValid() const
Returns the validity of this relation.
Base class for all map layer types.
QgsAttributes attributes() const
Returns the feature's attributes.
QgsAttributeList referencingFields() const
Returns a list of attributes used to form the referencing fields (foreign key) on the referencing (ch...
QDomNode appendChild(const QDomNode &newChild)
QString attribute(const QString &name, const QString &defValue) const
static void warning(const QString &msg)
Goes to qWarning.
QgsFeatureIterator getFeatures(const QgsFeatureRequest &request=QgsFeatureRequest())
Query the provider for features specified in request.
void setReferencingLayer(const QString &id)
Set the referencing (child) layer id.
QgsRelation()
Default constructor.
void writeXML(QDomNode &node, QDomDocument &doc) const
Writes a relation to an XML structure.
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 o...
QMap< QString, QgsMapLayer * > mapLayers() const
Returns a map of all registered layers by layer ID.
static QgsRelation createFromXML(const QDomNode &node)
Creates a relation from an XML structure.
QString join(const QString &separator) const
The feature class encapsulates a single feature including its id, geometry and a list of field/values...
QgsMapLayer::LayerType type() const
Get the type of the layer.
QString id() const
A (project-wide) unique id for this relation.
QgsFields fields() const
Returns the list of fields of this layer.
QDomElement toElement() const
QgsAttributeList referencedFields() const
Returns a list of attributes used to form the referenced fields (most likely primary key) on the refe...
QgsFeatureRequest & setFilterExpression(const QString &expression)
Set the filter expression.
QgsFeatureRequest getReferencedFeatureRequest(const QgsAttributes &attributes) const
Creates a request to return the feature on the referenced (parent) layer which is referenced by the p...
Defines a relation between matching fields of the two involved tables of a relation.
void setAttribute(const QString &name, const QString &value)
void setRelationName(const QString &name)
Set a name for this relation.
This class wraps a request for features to a vector layer (or directly its vector data provider)...
QgsFeatureRequest getRelatedFeaturesRequest(const QgsFeature &feature) const
Creates a request to return all the features on the referencing (child) layer which have a foreign ke...
static QString createFieldEqualityExpression(const QString &fieldName, const QVariant &value)
Create an expression allowing to evaluate if a field is equal to a value.
void setReferencedLayer(const QString &id)
Set the referenced (parent) layer id.
QList< FieldPair > fieldPairs() const
Returns the field pairs which form this relation The first element of each pair are the field names o...
QgsVectorLayer * referencedLayer() const
Access the referenced (parent) layer.
QgsFeatureIterator getRelatedFeatures(const QgsFeature &feature) const
Creates an iterator which returns all the features on the referencing (child) layer which have a fore...
QString referencingLayerId() const
Access the referencing (child) layer's id This is the layer which has the field(s) which point to ano...
const T & at(int i) const
QgsVectorLayer * referencingLayer() const
Access the referencing (child) layer This is the layer which has the field(s) which point to another ...
int indexFromName(const QString &name) const
Look up field's index from name. Returns -1 on error.
QString getRelatedFeaturesFilter(const QgsFeature &feature) const
Returns a filter expression which returns all the features on the referencing (child) layer which hav...
static QgsMapLayerRegistry * instance()
Returns the instance pointer, creating the object on the first call.
void setRelationId(const QString &id)
Set a name for this relation.
QString translate(const char *context, const char *sourceText, const char *disambiguation, Encoding encoding)
QString referencedField() const
Get the name of the referenced (parent) field.
QDomElement createElement(const QString &tagName)
bool nextFeature(QgsFeature &f)
QgsFeature getReferencedFeature(const QgsFeature &feature) const
Creates a request to return the feature on the referenced (parent) layer which is referenced by the p...
Represents a vector layer which manages a vector based data sets.
QVariant attribute(const QString &name) const
Lookup attribute value from attribute name.
QString referencedLayerId() const
Access the referenced (parent) layer's id.
QString referencingField() const
Get the name of the referencing (child) field.
int fieldNameIndex(const QString &fieldName) const
Returns the index of a field name or -1 if the field does not exist.
QString name() const
Returns a human readable name for this relation.
void updateRelationStatus()
Updates the validity status of this relation.
QDomNode at(int index) const